Hi,
On Tue, 2016-06-28 at 14:34 -0700, Feng Wang wrote:
Based on RFC 3315, 22.6, the valid life-time is infinite when its
value is 0xffffffff. In the g_dhcpv6_client_get_timeouts, the expire
data type is time_t. If time_t is uint32, the last_request time plus
0xffffffff will wrapover so that expire time is smaller than current
time. Thus the dhcpv6 will restart immediately(dhcpv6_restart called).
---
gdhcp/client.c | 9 +++++++--
src/dhcpv6.c | 6 +++++-
2 files changed, 12 insertions(+), 3 deletions(-)
diff --git a/gdhcp/client.c b/gdhcp/client.c
index 9012b38..2be3982 100644
--- a/gdhcp/client.c
+++ b/gdhcp/client.c
@@ -835,8 +835,13 @@ int g_dhcpv6_client_get_timeouts(GDHCPClient *dhcp_client,
if (started)
*started = dhcp_client->last_request;
- if (expire)
- *expire = dhcp_client->last_request + dhcp_client->expire;
+ if (expire) {
+ if (dhcp_client->expire == 0xffffffff)
+ /* RFC3315 22.6 infinite valid-lifetime */
+ *expire = 0xffffffff;
+ else
+ *expire = dhcp_client->last_request + dhcp_client->expire;
+ }
Coming back to this, RFC 3315, Section 22.5, indicates that "...If the
"shortest" preferred lifetime is 0xffffffff ("infinity"), the
recommended T1 and T2 values are also 0xffffffff..."
So this all could be made a bit easier by always setting T1, T2 and
expire to 0xffffffff when dhcp->expire is 0xffffffff.
And this would be patch #2.
return 0;
}
diff --git a/src/dhcpv6.c b/src/dhcpv6.c
index 9e21040..cd5733a 100644
--- a/src/dhcpv6.c
+++ b/src/dhcpv6.c
@@ -1195,7 +1195,7 @@ static int check_restart(struct connman_dhcpv6 *dhcp)
NULL, &expired);
current = time(NULL);
- if (current >= expired) {
+ if (current >= expired && expired != 0xffffffff) {
DBG("expired by %d secs", (int)(current - expired));
g_timeout_add(0, dhcpv6_restart, dhcp);
@@ -1442,6 +1442,10 @@ int __connman_dhcpv6_start_renew(struct connman_network *network,
/* RFC 3315, 22.4
* Client can choose the timeout.
*/
+ if (expired == 0xffffffff) {
+ /* RFC 3315, 22.6 infinite valid-lifetime */
+ return 0;
+ }
T1 = (expired - started) / 2;
T2 = (expired - started) / 10 * 8;
}
All instances where T1 and T2 are handled should be checked for
"infinity" as RFC 3315, Section 22.4 also says that "...a client will
never attempt to extend the lifetimes of any addresses in an IA with T1
set to 0xffffffff. A client will never attempt to use a Rebind message
to locate a different server to extend the lifetimes of any addresses
in an IA with T2 set to 0xffffffff...". To get to this behavior, all
usage of T1 and T2 should be checked.
This would be then patch #1.
Cheers,
Patrik