aboutsummaryrefslogtreecommitdiff
path: root/networking/udhcp/dhcpc.c
diff options
context:
space:
mode:
Diffstat (limited to 'networking/udhcp/dhcpc.c')
-rw-r--r--networking/udhcp/dhcpc.c78
1 files changed, 32 insertions, 46 deletions
diff --git a/networking/udhcp/dhcpc.c b/networking/udhcp/dhcpc.c
index a06eeaa16..16228f048 100644
--- a/networking/udhcp/dhcpc.c
+++ b/networking/udhcp/dhcpc.c
@@ -55,8 +55,7 @@ struct tpacket_auxdata {
55#if ENABLE_LONG_OPTS 55#if ENABLE_LONG_OPTS
56static const char udhcpc_longopts[] ALIGN1 = 56static const char udhcpc_longopts[] ALIGN1 =
57 "clientid-none\0" No_argument "C" 57 "clientid-none\0" No_argument "C"
58 "vendorclass\0" Required_argument "V" 58 "vendorclass\0" Required_argument "V" //deprecated
59 "hostname\0" Required_argument "H"
60 "fqdn\0" Required_argument "F" 59 "fqdn\0" Required_argument "F"
61 "interface\0" Required_argument "i" 60 "interface\0" Required_argument "i"
62 "now\0" No_argument "n" 61 "now\0" No_argument "n"
@@ -84,27 +83,25 @@ static const char udhcpc_longopts[] ALIGN1 =
84enum { 83enum {
85 OPT_C = 1 << 0, 84 OPT_C = 1 << 0,
86 OPT_V = 1 << 1, 85 OPT_V = 1 << 1,
87 OPT_H = 1 << 2, 86 OPT_F = 1 << 2,
88 OPT_h = 1 << 3, 87 OPT_i = 1 << 3,
89 OPT_F = 1 << 4, 88 OPT_n = 1 << 4,
90 OPT_i = 1 << 5, 89 OPT_p = 1 << 5,
91 OPT_n = 1 << 6, 90 OPT_q = 1 << 6,
92 OPT_p = 1 << 7, 91 OPT_R = 1 << 7,
93 OPT_q = 1 << 8, 92 OPT_r = 1 << 8,
94 OPT_R = 1 << 9, 93 OPT_s = 1 << 9,
95 OPT_r = 1 << 10, 94 OPT_T = 1 << 10,
96 OPT_s = 1 << 11, 95 OPT_t = 1 << 11,
97 OPT_T = 1 << 12, 96 OPT_S = 1 << 12,
98 OPT_t = 1 << 13, 97 OPT_A = 1 << 13,
99 OPT_S = 1 << 14, 98 OPT_O = 1 << 14,
100 OPT_A = 1 << 15, 99 OPT_o = 1 << 15,
101 OPT_O = 1 << 16, 100 OPT_x = 1 << 16,
102 OPT_o = 1 << 17, 101 OPT_f = 1 << 17,
103 OPT_x = 1 << 18, 102 OPT_B = 1 << 18,
104 OPT_f = 1 << 19,
105 OPT_B = 1 << 20,
106/* The rest has variable bit positions, need to be clever */ 103/* The rest has variable bit positions, need to be clever */
107 OPTBIT_B = 20, 104 OPTBIT_B = 18,
108 USE_FOR_MMU( OPTBIT_b,) 105 USE_FOR_MMU( OPTBIT_b,)
109 IF_FEATURE_UDHCPC_ARPING(OPTBIT_a,) 106 IF_FEATURE_UDHCPC_ARPING(OPTBIT_a,)
110 IF_FEATURE_UDHCP_PORT( OPTBIT_P,) 107 IF_FEATURE_UDHCP_PORT( OPTBIT_P,)
@@ -638,10 +635,6 @@ static void add_client_options(struct dhcp_packet *packet)
638 packet->options[end + OPT_DATA + len] = DHCP_END; 635 packet->options[end + OPT_DATA + len] = DHCP_END;
639 } 636 }
640 637
641 if (client_data.vendorclass)
642 udhcp_add_binary_option(packet, client_data.vendorclass);
643 if (client_data.hostname)
644 udhcp_add_binary_option(packet, client_data.hostname);
645 if (client_data.fqdn) 638 if (client_data.fqdn)
646 udhcp_add_binary_option(packet, client_data.fqdn); 639 udhcp_add_binary_option(packet, client_data.fqdn);
647 640
@@ -722,7 +715,7 @@ static NOINLINE int send_discover(uint32_t xid, uint32_t requested)
722 udhcp_add_simple_option(&packet, DHCP_REQUESTED_IP, requested); 715 udhcp_add_simple_option(&packet, DHCP_REQUESTED_IP, requested);
723 716
724 /* Add options: maxsize, 717 /* Add options: maxsize,
725 * optionally: hostname, fqdn, vendorclass, client-id, 718 * optionally: fqdn, client-id,
726 * "param req" option according to -O, options specified with -x 719 * "param req" option according to -O, options specified with -x
727 */ 720 */
728 add_client_options(&packet); 721 add_client_options(&packet);
@@ -766,7 +759,7 @@ static NOINLINE int send_select(uint32_t xid, uint32_t server, uint32_t requeste
766 udhcp_add_simple_option(&packet, DHCP_SERVER_ID, server); 759 udhcp_add_simple_option(&packet, DHCP_SERVER_ID, server);
767 760
768 /* Add options: maxsize, 761 /* Add options: maxsize,
769 * optionally: hostname, fqdn, vendorclass, client-id, 762 * optionally: fqdn, client-id,
770 * "param req" option according to -O, and options specified with -x 763 * "param req" option according to -O, and options specified with -x
771 */ 764 */
772 add_client_options(&packet); 765 add_client_options(&packet);
@@ -811,7 +804,7 @@ static NOINLINE int send_renew(uint32_t xid, uint32_t server, uint32_t ciaddr)
811 packet.ciaddr = ciaddr; 804 packet.ciaddr = ciaddr;
812 805
813 /* Add options: maxsize, 806 /* Add options: maxsize,
814 * optionally: hostname, fqdn, vendorclass, client-id, 807 * optionally: fqdn, client-id,
815 * "param req" option according to -O, and options specified with -x 808 * "param req" option according to -O, and options specified with -x
816 */ 809 */
817 add_client_options(&packet); 810 add_client_options(&packet);
@@ -1236,7 +1229,7 @@ int udhcpc_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
1236int udhcpc_main(int argc UNUSED_PARAM, char **argv) 1229int udhcpc_main(int argc UNUSED_PARAM, char **argv)
1237{ 1230{
1238 uint8_t *message; 1231 uint8_t *message;
1239 const char *str_V, *str_h, *str_F, *str_r; 1232 const char *str_V, *str_F, *str_r;
1240 IF_FEATURE_UDHCPC_ARPING(const char *str_a = "2000";) 1233 IF_FEATURE_UDHCPC_ARPING(const char *str_a = "2000";)
1241 IF_FEATURE_UDHCP_PORT(char *str_P;) 1234 IF_FEATURE_UDHCP_PORT(char *str_P;)
1242 uint8_t *clientid_mac_ptr; 1235 uint8_t *clientid_mac_ptr;
@@ -1272,14 +1265,14 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv)
1272 /* Parse command line */ 1265 /* Parse command line */
1273 opt = getopt32long(argv, "^" 1266 opt = getopt32long(argv, "^"
1274 /* O,x: list; -T,-t,-A take numeric param */ 1267 /* O,x: list; -T,-t,-A take numeric param */
1275 "CV:H:h:F:i:np:qRr:s:T:+t:+SA:+O:*ox:*fB" 1268 "CV:F:i:np:qRr:s:T:+t:+SA:+O:*ox:*fB"
1276 USE_FOR_MMU("b") 1269 USE_FOR_MMU("b")
1277 IF_FEATURE_UDHCPC_ARPING("a::") 1270 IF_FEATURE_UDHCPC_ARPING("a::")
1278 IF_FEATURE_UDHCP_PORT("P:") 1271 IF_FEATURE_UDHCP_PORT("P:")
1279 "v" 1272 "v"
1280 "\0" IF_UDHCP_VERBOSE("vv") /* -v is a counter */ 1273 "\0" IF_UDHCP_VERBOSE("vv") /* -v is a counter */
1281 , udhcpc_longopts 1274 , udhcpc_longopts
1282 , &str_V, &str_h, &str_h, &str_F 1275 , &str_V, &str_F
1283 , &client_data.interface, &client_data.pidfile /* i,p */ 1276 , &client_data.interface, &client_data.pidfile /* i,p */
1284 , &str_r /* r */ 1277 , &str_r /* r */
1285 , &client_data.script /* s */ 1278 , &client_data.script /* s */
@@ -1290,11 +1283,6 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv)
1290 IF_FEATURE_UDHCP_PORT(, &str_P) 1283 IF_FEATURE_UDHCP_PORT(, &str_P)
1291 IF_UDHCP_VERBOSE(, &dhcp_verbose) 1284 IF_UDHCP_VERBOSE(, &dhcp_verbose)
1292 ); 1285 );
1293 if (opt & (OPT_h|OPT_H)) {
1294 //msg added 2011-11
1295 bb_simple_error_msg("option -h NAME is deprecated, use -x hostname:NAME");
1296 client_data.hostname = alloc_dhcp_option(DHCP_HOST_NAME, str_h, 0);
1297 }
1298 if (opt & OPT_F) { 1286 if (opt & OPT_F) {
1299 /* FQDN option format: [0x51][len][flags][0][0]<fqdn> */ 1287 /* FQDN option format: [0x51][len][flags][0][0]<fqdn> */
1300 client_data.fqdn = alloc_dhcp_option(DHCP_FQDN, str_F, 3); 1288 client_data.fqdn = alloc_dhcp_option(DHCP_FQDN, str_F, 3);
@@ -1344,6 +1332,13 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv)
1344 ); 1332 );
1345 free(optstr); 1333 free(optstr);
1346 } 1334 }
1335 if (str_V[0] != '\0') {
1336 //msg added 2021-06
1337 bb_error_msg("option -V VENDOR is deprecated, use -x vendor:VENDOR");
1338 udhcp_insert_new_option(
1339 &client_data.options, DHCP_VENDOR,
1340 str_V, strlen(str_V), /*dhcp6:*/ 0);
1341 }
1347 1342
1348 if (udhcp_read_interface(client_data.interface, 1343 if (udhcp_read_interface(client_data.interface,
1349 &client_data.ifindex, 1344 &client_data.ifindex,
@@ -1362,15 +1357,6 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv)
1362 client_data_client_mac - 1, 1 + 6, /*dhcp6:*/ 0); 1357 client_data_client_mac - 1, 1 + 6, /*dhcp6:*/ 0);
1363 clientid_mac_ptr += 3; /* skip option code, len, ethernet */ 1358 clientid_mac_ptr += 3; /* skip option code, len, ethernet */
1364 } 1359 }
1365 if (str_V[0] != '\0') {
1366 // can drop -V, str_V, client_data.vendorclass,
1367 // but need to add "vendor" to the list of recognized
1368 // string opts for this to work;
1369 // and need to tweak add_client_options() too...
1370 // ...so the question is, should we?
1371 //bb_error_msg("option -V VENDOR is deprecated, use -x vendor:VENDOR");
1372 client_data.vendorclass = alloc_dhcp_option(DHCP_VENDOR, str_V, 0);
1373 }
1374 1360
1375#if !BB_MMU 1361#if !BB_MMU
1376 /* on NOMMU reexec (i.e., background) early */ 1362 /* on NOMMU reexec (i.e., background) early */