]> git.decadent.org.uk Git - odhcp6c.git/commitdiff
Honor T1 and T2 from server better
authorSteven Barth <steven@midlink.org>
Tue, 21 May 2013 10:10:37 +0000 (12:10 +0200)
committerSteven Barth <steven@midlink.org>
Tue, 21 May 2013 10:10:37 +0000 (12:10 +0200)
src/dhcpv6.c

index cfa5a407f1408f2d6d03a452121fac9e16ee66c3..ed6b8f868a67accdad22418e34cfc369204f5347 100644 (file)
@@ -371,9 +371,9 @@ int dhcpv6_request(enum dhcpv6_msg type)
        else if (type == DHCPV6_MSG_UNKNOWN)
                timeout = t1;
        else if (type == DHCPV6_MSG_RENEW)
-               timeout = t2 - t1;
+               timeout = (t2 > t1) ? t2 - t1 : 0;
        else if (type == DHCPV6_MSG_REBIND)
-               timeout = t3 - t2;
+               timeout = (t3 > t2) ? t3 - t2 : 0;
 
        if (timeout == 0)
                return -1;
@@ -726,29 +726,23 @@ static int dhcpv6_handle_reply(enum dhcpv6_msg orig,
                        if (error)
                                continue;
 
-                       // Update times
-                       if (l_t1 > 0 && t1 > l_t1)
-                               t1 = l_t1;
-
-                       if (l_t2 > 0 && t2 > l_t2)
-                               t2 = l_t2;
-
                        uint32_t n = dhcpv6_parse_ia(&ia_hdr[1], odata + olen);
 
-                       if (n < t1)
-                               t1 = n;
+                       if (!l_t1)
+                               l_t1 = 300;
 
-                       if (n < t2)
-                               t2 = n;
+                       if (!l_t2)
+                               l_t2 = 600;
 
                        if (n < t3)
                                t3 = n;
 
-                       if (t2 >= t3)
-                               t2 = 8 * t3 / 10;
+                       // Update times
+                       if (l_t1 > 0 && t1 > l_t1)
+                               t1 = l_t1;
 
-                       if (t1 >= t2)
-                               t1 = 5 * t2 / 8;
+                       if (l_t2 > 0 && t2 > l_t2)
+                               t2 = l_t2;
 
                } else if (otype == DHCPV6_OPT_DNS_SERVERS) {
                        if (olen % 16 == 0)