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 /networking/udhcp/d6_dhcpc.c | |
parent | c58d785b9d0a337ff884002c4cef5283f901c9e4 (diff) |
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>
Diffstat (limited to 'networking/udhcp/d6_dhcpc.c')
-rw-r--r-- | networking/udhcp/d6_dhcpc.c | 18 |
1 files changed, 17 insertions, 1 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) /* Initialize the packet with the proper defaults */ static uint8_t *init_d6_packet(struct d6_packet *packet, char type, uint32_t xid) { + uint8_t *ptr; struct d6_option *clientid; + unsigned secs; memset(packet, 0, sizeof(*packet)); packet->d6_xid32 = xid; packet->d6_msg_type = type; + /* ELAPSED_TIME option is required to be present by the RFC, + * and some servers do check for its presense. [which?] + */ + ptr = packet->d6_options; /* NB: it is 32-bit aligned */ + *((uint32_t*)ptr) = htonl((D6_OPT_ELAPSED_TIME << 16) + 2); + ptr += 4; + client_data.last_secs = monotonic_sec(); + if (client_data.first_secs == 0) + client_data.first_secs = client_data.last_secs; + secs = client_data.last_secs - client_data.first_secs; + *((uint16_t*)ptr) = (secs < 0xffff) ? htons(secs) : 0xffff; + ptr += 2; + + /* add CLIENTID option */ clientid = (void*)client_data.clientid; - return mempcpy(packet->d6_options, clientid, clientid->len + 2+2); + return mempcpy(ptr, clientid, clientid->len + 2+2); } static uint8_t *add_d6_client_options(uint8_t *ptr) |