aboutsummaryrefslogtreecommitdiff
path: root/networking/udhcp/dhcpc.c
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2021-06-02 15:51:50 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2021-06-02 15:51:50 +0200
commit949e9621d10faada3bb55a4aa206df44e7d39ae8 (patch)
tree63778eac77dc9b9fb6f30410a581d87f7ae2b707 /networking/udhcp/dhcpc.c
parent698cdef538f51bb85b68d591b1e42eb6b04d891c (diff)
downloadbusybox-w32-949e9621d10faada3bb55a4aa206df44e7d39ae8.tar.gz
busybox-w32-949e9621d10faada3bb55a4aa206df44e7d39ae8.tar.bz2
busybox-w32-949e9621d10faada3bb55a4aa206df44e7d39ae8.zip
udhcpc: get rid of client_data.fqdn field
function old new delta attach_option 253 276 +23 udhcpc_main 2582 2588 +6 udhcpc6_main 2579 2571 -8 add_client_options 175 158 -17 udhcp_insert_new_option 169 138 -31 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 2/3 up/down: 29/-56) Total: -27 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'networking/udhcp/dhcpc.c')
-rw-r--r--networking/udhcp/dhcpc.c71
1 files changed, 32 insertions, 39 deletions
diff --git a/networking/udhcp/dhcpc.c b/networking/udhcp/dhcpc.c
index 16228f048..ab669d2b5 100644
--- a/networking/udhcp/dhcpc.c
+++ b/networking/udhcp/dhcpc.c
@@ -609,7 +609,7 @@ static void init_packet(struct dhcp_packet *packet, char type)
609 secs = client_data.last_secs - client_data.first_secs; 609 secs = client_data.last_secs - client_data.first_secs;
610 packet->secs = (secs < 0xffff) ? htons(secs) : 0xffff; 610 packet->secs = (secs < 0xffff) ? htons(secs) : 0xffff;
611 611
612 memcpy(packet->chaddr, client_data_client_mac, 6); 612 memcpy(packet->chaddr, client_data.client_mac, 6);
613} 613}
614 614
615static void add_client_options(struct dhcp_packet *packet) 615static void add_client_options(struct dhcp_packet *packet)
@@ -635,9 +635,6 @@ static void add_client_options(struct dhcp_packet *packet)
635 packet->options[end + OPT_DATA + len] = DHCP_END; 635 packet->options[end + OPT_DATA + len] = DHCP_END;
636 } 636 }
637 637
638 if (client_data.fqdn)
639 udhcp_add_binary_option(packet, client_data.fqdn);
640
641 /* Request broadcast replies if we have no IP addr */ 638 /* Request broadcast replies if we have no IP addr */
642 if ((option_mask32 & OPT_B) && packet->ciaddr == 0) 639 if ((option_mask32 & OPT_B) && packet->ciaddr == 0)
643 packet->flags |= htons(BROADCAST_FLAG); 640 packet->flags |= htons(BROADCAST_FLAG);
@@ -715,7 +712,6 @@ static NOINLINE int send_discover(uint32_t xid, uint32_t requested)
715 udhcp_add_simple_option(&packet, DHCP_REQUESTED_IP, requested); 712 udhcp_add_simple_option(&packet, DHCP_REQUESTED_IP, requested);
716 713
717 /* Add options: maxsize, 714 /* Add options: maxsize,
718 * optionally: fqdn, client-id,
719 * "param req" option according to -O, options specified with -x 715 * "param req" option according to -O, options specified with -x
720 */ 716 */
721 add_client_options(&packet); 717 add_client_options(&packet);
@@ -759,7 +755,6 @@ static NOINLINE int send_select(uint32_t xid, uint32_t server, uint32_t requeste
759 udhcp_add_simple_option(&packet, DHCP_SERVER_ID, server); 755 udhcp_add_simple_option(&packet, DHCP_SERVER_ID, server);
760 756
761 /* Add options: maxsize, 757 /* Add options: maxsize,
762 * optionally: fqdn, client-id,
763 * "param req" option according to -O, and options specified with -x 758 * "param req" option according to -O, and options specified with -x
764 */ 759 */
765 add_client_options(&packet); 760 add_client_options(&packet);
@@ -804,7 +799,6 @@ static NOINLINE int send_renew(uint32_t xid, uint32_t server, uint32_t ciaddr)
804 packet.ciaddr = ciaddr; 799 packet.ciaddr = ciaddr;
805 800
806 /* Add options: maxsize, 801 /* Add options: maxsize,
807 * optionally: fqdn, client-id,
808 * "param req" option according to -O, and options specified with -x 802 * "param req" option according to -O, and options specified with -x
809 */ 803 */
810 add_client_options(&packet); 804 add_client_options(&packet);
@@ -1154,17 +1148,6 @@ static void perform_release(uint32_t server_addr, uint32_t requested_ip)
1154 client_data.state = RELEASED; 1148 client_data.state = RELEASED;
1155} 1149}
1156 1150
1157static uint8_t* alloc_dhcp_option(int code, const char *str, int extra)
1158{
1159 uint8_t *storage;
1160 int len = strnlen(str, 255);
1161 storage = xzalloc(len + extra + OPT_DATA);
1162 storage[OPT_CODE] = code;
1163 storage[OPT_LEN] = len + extra;
1164 memcpy(storage + extra + OPT_DATA, str, len);
1165 return storage;
1166}
1167
1168#if BB_MMU 1151#if BB_MMU
1169static void client_background(void) 1152static void client_background(void)
1170{ 1153{
@@ -1284,8 +1267,13 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv)
1284 IF_UDHCP_VERBOSE(, &dhcp_verbose) 1267 IF_UDHCP_VERBOSE(, &dhcp_verbose)
1285 ); 1268 );
1286 if (opt & OPT_F) { 1269 if (opt & OPT_F) {
1270 char *p;
1271 unsigned len;
1287 /* FQDN option format: [0x51][len][flags][0][0]<fqdn> */ 1272 /* FQDN option format: [0x51][len][flags][0][0]<fqdn> */
1288 client_data.fqdn = alloc_dhcp_option(DHCP_FQDN, str_F, 3); 1273 len = strlen(str_F);
1274 p = udhcp_insert_new_option(
1275 &client_data.options, DHCP_FQDN,
1276 len + 3, /*dhcp6:*/ 0);
1289 /* Flag bits: 0000NEOS 1277 /* Flag bits: 0000NEOS
1290 * S: 1 = Client requests server to update A RR in DNS as well as PTR 1278 * S: 1 = Client requests server to update A RR in DNS as well as PTR
1291 * O: 1 = Server indicates to client that DNS has been updated regardless 1279 * O: 1 = Server indicates to client that DNS has been updated regardless
@@ -1294,9 +1282,10 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv)
1294 * N: 1 = Client requests server to not update DNS (S must be 0 then) 1282 * N: 1 = Client requests server to not update DNS (S must be 0 then)
1295 * Two [0] bytes which follow are deprecated and must be 0. 1283 * Two [0] bytes which follow are deprecated and must be 0.
1296 */ 1284 */
1297 client_data.fqdn[OPT_DATA + 0] = 0x1; 1285 p[OPT_DATA + 0] = 0x1;
1298 /*client_data.fqdn[OPT_DATA + 1] = 0; - xzalloc did it */ 1286 /*p[OPT_DATA + 1] = 0; - xzalloc did it */
1299 /*client_data.fqdn[OPT_DATA + 2] = 0; */ 1287 /*p[OPT_DATA + 2] = 0; */
1288 memcpy(p + OPT_DATA + 3, str_F, len); /* do not store NUL byte */
1300 } 1289 }
1301 if (opt & OPT_r) 1290 if (opt & OPT_r)
1302 requested_ip = inet_addr(str_r); 1291 requested_ip = inet_addr(str_r);
@@ -1333,31 +1322,35 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv)
1333 free(optstr); 1322 free(optstr);
1334 } 1323 }
1335 if (str_V[0] != '\0') { 1324 if (str_V[0] != '\0') {
1325 char *p;
1326 unsigned len;
1336 //msg added 2021-06 1327 //msg added 2021-06
1337 bb_error_msg("option -V VENDOR is deprecated, use -x vendor:VENDOR"); 1328 bb_error_msg("option -V VENDOR is deprecated, use -x vendor:VENDOR");
1338 udhcp_insert_new_option( 1329 len = strlen(str_V);
1330 p = udhcp_insert_new_option(
1339 &client_data.options, DHCP_VENDOR, 1331 &client_data.options, DHCP_VENDOR,
1340 str_V, strlen(str_V), /*dhcp6:*/ 0); 1332 len, /*dhcp6:*/ 0);
1333 memcpy(p + OPT_DATA, str_V, len); /* do not store NUL byte */
1334 }
1335
1336 clientid_mac_ptr = NULL;
1337 if (!(opt & OPT_C) && !udhcp_find_option(client_data.options, DHCP_CLIENT_ID)) {
1338 /* not suppressed and not set, create default client ID */
1339 clientid_mac_ptr = udhcp_insert_new_option(
1340 &client_data.options, DHCP_CLIENT_ID,
1341 1 + 6, /*dhcp6:*/ 0);
1342 clientid_mac_ptr[OPT_DATA] = 1; /* type: ethernet */
1343 clientid_mac_ptr += OPT_DATA + 1; /* skip option code, len, ethernet */
1341 } 1344 }
1342 1345
1343 if (udhcp_read_interface(client_data.interface, 1346 if (udhcp_read_interface(client_data.interface,
1344 &client_data.ifindex, 1347 &client_data.ifindex,
1345 NULL, 1348 NULL,
1346 client_data_client_mac) 1349 client_data.client_mac)
1347 ) { 1350 ) {
1348 return 1; 1351 return 1;
1349 } 1352 }
1350 1353
1351 clientid_mac_ptr = NULL;
1352 if (!(opt & OPT_C) && !udhcp_find_option(client_data.options, DHCP_CLIENT_ID)) {
1353 /* not suppressed and not set, set the default client ID */
1354 client_data_client_mac[-1] = 1; /* type: ethernet */
1355 clientid_mac_ptr = udhcp_insert_new_option(
1356 &client_data.options, DHCP_CLIENT_ID,
1357 client_data_client_mac - 1, 1 + 6, /*dhcp6:*/ 0);
1358 clientid_mac_ptr += 3; /* skip option code, len, ethernet */
1359 }
1360
1361#if !BB_MMU 1354#if !BB_MMU
1362 /* on NOMMU reexec (i.e., background) early */ 1355 /* on NOMMU reexec (i.e., background) early */
1363 if (!(opt & OPT_f)) { 1356 if (!(opt & OPT_f)) {
@@ -1443,12 +1436,12 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv)
1443 if (udhcp_read_interface(client_data.interface, 1436 if (udhcp_read_interface(client_data.interface,
1444 &client_data.ifindex, 1437 &client_data.ifindex,
1445 NULL, 1438 NULL,
1446 client_data_client_mac) 1439 client_data.client_mac)
1447 ) { 1440 ) {
1448 goto ret0; /* iface is gone? */ 1441 goto ret0; /* iface is gone? */
1449 } 1442 }
1450 if (clientid_mac_ptr) 1443 if (clientid_mac_ptr)
1451 memcpy(clientid_mac_ptr, client_data_client_mac, 6); 1444 memcpy(clientid_mac_ptr, client_data.client_mac, 6);
1452 1445
1453 switch (client_data.state) { 1446 switch (client_data.state) {
1454 case INIT_SELECTING: 1447 case INIT_SELECTING:
@@ -1643,7 +1636,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv)
1643 1636
1644 /* Ignore packets that aren't for us */ 1637 /* Ignore packets that aren't for us */
1645 if (packet.hlen != 6 1638 if (packet.hlen != 6
1646 || memcmp(packet.chaddr, client_data_client_mac, 6) != 0 1639 || memcmp(packet.chaddr, client_data.client_mac, 6) != 0
1647 ) { 1640 ) {
1648//FIXME: need to also check that last 10 bytes are zero 1641//FIXME: need to also check that last 10 bytes are zero
1649 log1("chaddr does not match%s", ", ignoring packet"); // log2? 1642 log1("chaddr does not match%s", ", ignoring packet"); // log2?
@@ -1755,7 +1748,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv)
1755 if (!arpping(requested_ip, 1748 if (!arpping(requested_ip,
1756 NULL, 1749 NULL,
1757 (uint32_t) 0, 1750 (uint32_t) 0,
1758 client_data_client_mac, 1751 client_data.client_mac,
1759 client_data.interface, 1752 client_data.interface,
1760 arpping_ms) 1753 arpping_ms)
1761 ) { 1754 ) {