diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2019-09-24 14:01:00 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2019-09-24 14:01:00 +0200 |
commit | 11e024aa86f23a6dd86cdd58b8890756708cd708 (patch) | |
tree | 818fcf800385a218fab7175dd3e89c1d076c5b18 | |
parent | c58d785b9d0a337ff884002c4cef5283f901c9e4 (diff) | |
download | busybox-w32-11e024aa86f23a6dd86cdd58b8890756708cd708.tar.gz busybox-w32-11e024aa86f23a6dd86cdd58b8890756708cd708.tar.bz2 busybox-w32-11e024aa86f23a6dd86cdd58b8890756708cd708.zip |
udhcpc6: add ELAPSED_TIME option to outgoing packets
function old new delta
init_d6_packet 53 121 +68
udhcpc_main 2577 2582 +5
udhcpc6_main 2593 2597 +4
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 3/0 up/down: 77/0) Total: 77 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | networking/udhcp/d6_dhcpc.c | 18 | ||||
-rw-r--r-- | networking/udhcp/dhcpc.c | 4 | ||||
-rw-r--r-- | networking/udhcp/dhcpc.h | 4 |
3 files changed, 21 insertions, 5 deletions
diff --git a/networking/udhcp/d6_dhcpc.c b/networking/udhcp/d6_dhcpc.c index a426b9933..85c410a7c 100644 --- a/networking/udhcp/d6_dhcpc.c +++ b/networking/udhcp/d6_dhcpc.c | |||
@@ -481,15 +481,31 @@ static ALWAYS_INLINE uint32_t random_xid(void) | |||
481 | /* Initialize the packet with the proper defaults */ | 481 | /* Initialize the packet with the proper defaults */ |
482 | static uint8_t *init_d6_packet(struct d6_packet *packet, char type, uint32_t xid) | 482 | static uint8_t *init_d6_packet(struct d6_packet *packet, char type, uint32_t xid) |
483 | { | 483 | { |
484 | uint8_t *ptr; | ||
484 | struct d6_option *clientid; | 485 | struct d6_option *clientid; |
486 | unsigned secs; | ||
485 | 487 | ||
486 | memset(packet, 0, sizeof(*packet)); | 488 | memset(packet, 0, sizeof(*packet)); |
487 | 489 | ||
488 | packet->d6_xid32 = xid; | 490 | packet->d6_xid32 = xid; |
489 | packet->d6_msg_type = type; | 491 | packet->d6_msg_type = type; |
490 | 492 | ||
493 | /* ELAPSED_TIME option is required to be present by the RFC, | ||
494 | * and some servers do check for its presense. [which?] | ||
495 | */ | ||
496 | ptr = packet->d6_options; /* NB: it is 32-bit aligned */ | ||
497 | *((uint32_t*)ptr) = htonl((D6_OPT_ELAPSED_TIME << 16) + 2); | ||
498 | ptr += 4; | ||
499 | client_data.last_secs = monotonic_sec(); | ||
500 | if (client_data.first_secs == 0) | ||
501 | client_data.first_secs = client_data.last_secs; | ||
502 | secs = client_data.last_secs - client_data.first_secs; | ||
503 | *((uint16_t*)ptr) = (secs < 0xffff) ? htons(secs) : 0xffff; | ||
504 | ptr += 2; | ||
505 | |||
506 | /* add CLIENTID option */ | ||
491 | clientid = (void*)client_data.clientid; | 507 | clientid = (void*)client_data.clientid; |
492 | return mempcpy(packet->d6_options, clientid, clientid->len + 2+2); | 508 | return mempcpy(ptr, clientid, clientid->len + 2+2); |
493 | } | 509 | } |
494 | 510 | ||
495 | static uint8_t *add_d6_client_options(uint8_t *ptr) | 511 | static uint8_t *add_d6_client_options(uint8_t *ptr) |
diff --git a/networking/udhcp/dhcpc.c b/networking/udhcp/dhcpc.c index 656295ff7..5a1f8fd7a 100644 --- a/networking/udhcp/dhcpc.c +++ b/networking/udhcp/dhcpc.c | |||
@@ -606,7 +606,7 @@ static ALWAYS_INLINE uint32_t random_xid(void) | |||
606 | /* Initialize the packet with the proper defaults */ | 606 | /* Initialize the packet with the proper defaults */ |
607 | static void init_packet(struct dhcp_packet *packet, char type) | 607 | static void init_packet(struct dhcp_packet *packet, char type) |
608 | { | 608 | { |
609 | uint16_t secs; | 609 | unsigned secs; |
610 | 610 | ||
611 | /* Fill in: op, htype, hlen, cookie fields; message type option: */ | 611 | /* Fill in: op, htype, hlen, cookie fields; message type option: */ |
612 | udhcp_init_header(packet, type); | 612 | udhcp_init_header(packet, type); |
@@ -617,7 +617,7 @@ static void init_packet(struct dhcp_packet *packet, char type) | |||
617 | if (client_data.first_secs == 0) | 617 | if (client_data.first_secs == 0) |
618 | client_data.first_secs = client_data.last_secs; | 618 | client_data.first_secs = client_data.last_secs; |
619 | secs = client_data.last_secs - client_data.first_secs; | 619 | secs = client_data.last_secs - client_data.first_secs; |
620 | packet->secs = htons(secs); | 620 | packet->secs = (secs < 0xffff) ? htons(secs) : 0xffff; |
621 | 621 | ||
622 | memcpy(packet->chaddr, client_data.client_mac, 6); | 622 | memcpy(packet->chaddr, client_data.client_mac, 6); |
623 | if (client_data.clientid) | 623 | if (client_data.clientid) |
diff --git a/networking/udhcp/dhcpc.h b/networking/udhcp/dhcpc.h index 42fe71a36..b407a6cdb 100644 --- a/networking/udhcp/dhcpc.h +++ b/networking/udhcp/dhcpc.h | |||
@@ -22,8 +22,8 @@ struct client_data_t { | |||
22 | uint8_t *hostname; /* Optional hostname to use */ | 22 | uint8_t *hostname; /* Optional hostname to use */ |
23 | uint8_t *fqdn; /* Optional fully qualified domain name to use */ | 23 | uint8_t *fqdn; /* Optional fully qualified domain name to use */ |
24 | 24 | ||
25 | uint16_t first_secs; | 25 | unsigned first_secs; |
26 | uint16_t last_secs; | 26 | unsigned last_secs; |
27 | 27 | ||
28 | int sockfd; | 28 | int sockfd; |
29 | smallint listen_mode; | 29 | smallint listen_mode; |