From feec1ad5767b977ce47e6738930c99c22ba0ce9c Mon Sep 17 00:00:00 2001 From: Steven Barth Date: Mon, 20 May 2013 16:27:23 +0200 Subject: [PATCH] Fix IA expiring logic --- src/dhcpv6.c | 10 ++++++---- src/odhcp6c.c | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/dhcpv6.c b/src/dhcpv6.c index d2cd656..9b4247c 100644 --- a/src/dhcpv6.c +++ b/src/dhcpv6.c @@ -667,13 +667,15 @@ static int dhcpv6_handle_reply(enum dhcpv6_msg orig, uint8_t *odata; uint16_t otype, olen; - static time_t last_update = 0; - time_t now = odhcp6c_get_milli_time() / 1000; - - uint32_t elapsed = now - last_update; odhcp6c_expire(); if (orig == DHCPV6_MSG_UNKNOWN) { + static time_t last_update = 0; + time_t now = odhcp6c_get_milli_time() / 1000; + + uint32_t elapsed = (last_update > 0) ? now - last_update : 0; + last_update = now; + t1 -= elapsed; t2 -= elapsed; t3 -= elapsed; diff --git a/src/odhcp6c.c b/src/odhcp6c.c index 274a97a..d70546b 100644 --- a/src/odhcp6c.c +++ b/src/odhcp6c.c @@ -470,7 +470,7 @@ void odhcp6c_expire(void) static time_t last_update = 0; time_t now = odhcp6c_get_milli_time() / 1000; - uint32_t elapsed = now - last_update; + uint32_t elapsed = (last_update > 0) ? now - last_update : 0; last_update = now; odhcp6c_expire_list(STATE_RA_PREFIX, elapsed); -- 2.30.2