Fixes calculation of t1 and/or t2 values in case t1 and /or t2 is 0 and preferred lifetime send by the DHCPv6 server is smaller than 300 in the IA. It lines up the renew/rebind behavior as described in RFC3315 paragraph 22.4 as the current implementation can send a renew/rebind if the IA valid lifetime is already expired
Signed-off-by: Hans Dedecker <dedec...@telenet.be> --- src/dhcpv6.c | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/src/dhcpv6.c b/src/dhcpv6.c index 64c0cb4..5cfa88e 100644 --- a/src/dhcpv6.c +++ b/src/dhcpv6.c @@ -46,7 +46,7 @@ static bool dhcpv6_response_is_valid(const void *buf, ssize_t len, const uint8_t transaction[3], enum dhcpv6_msg type); -static uint32_t dhcpv6_parse_ia(void *opt, void *end); +static uint32_t dhcpv6_parse_ia(void *opt, void *end, uint32_t *preferred); static reply_handler dhcpv6_handle_reply; static reply_handler dhcpv6_handle_advert; @@ -708,6 +708,7 @@ static int dhcpv6_handle_reply(enum dhcpv6_msg orig, struct dhcpv6_ia_hdr *ia_hdr = (void*)(&odata[-4]); uint32_t l_t1 = ntohl(ia_hdr->t1); uint32_t l_t2 = ntohl(ia_hdr->t2); + uint32_t preferred; // Test ID and T1-T2 validity if (ia_hdr->iaid != 1 || l_t2 < l_t1) @@ -726,13 +727,23 @@ static int dhcpv6_handle_reply(enum dhcpv6_msg orig, if (error) continue; - uint32_t n = dhcpv6_parse_ia(&ia_hdr[1], odata + olen); + uint32_t n = dhcpv6_parse_ia(&ia_hdr[1], odata + olen, &preferred); - if (!l_t1) - l_t1 = 300; + if (!l_t2) { + l_t2 = preferred; + if (l_t2 != UINT32_MAX) + l_t2 = preferred*0.8; + } + + if (!l_t1) { + l_t1 = preferred; + if (l_t1 != UINT32_MAX) + l_t1 = preferred/2; + + if (l_t1 > l_t2) + l_t1 = l_t2; + } - if (!l_t2) - l_t2 = 600; if (n < t3) t3 = n; @@ -794,7 +805,7 @@ static int dhcpv6_handle_reply(enum dhcpv6_msg orig, } -static uint32_t dhcpv6_parse_ia(void *opt, void *end) +static uint32_t dhcpv6_parse_ia(void *opt, void *end, uint32_t *preferred) { uint32_t timeout = UINT32_MAX; // Minimum timeout uint16_t otype, olen; @@ -803,6 +814,8 @@ static uint32_t dhcpv6_parse_ia(void *opt, void *end) struct odhcp6c_entry entry = {IN6ADDR_ANY_INIT, 0, 0, IN6ADDR_ANY_INIT, 0, 0}; + *preferred = UINT32_MAX; + // Update address IA dhcpv6_for_each_option(opt, end, otype, olen, odata) { if (otype == DHCPV6_OPT_IA_PREFIX) { @@ -882,6 +895,9 @@ static uint32_t dhcpv6_parse_ia(void *opt, void *end) if (entry.valid > 0 && timeout > entry.valid) timeout = entry.valid; + + if (entry.preferred > 0 && *preferred > entry.preferred) + *preferred = entry.preferred; } return timeout; -- 1.8.1.4 _______________________________________________ openwrt-devel mailing list openwrt-devel@lists.openwrt.org https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel