diff options
author | Steven Barth <steven@midlink.org> | 2013-01-21 08:45:16 +0100 |
---|---|---|
committer | Steven Barth <steven@midlink.org> | 2013-01-21 08:45:16 +0100 |
commit | 770741e98f2569ec0b00251ba9bf17a92e89221e (patch) | |
tree | a7202844708fb783654e37112635d4ea13c829fe | |
parent | 673d079b108815d5eff0547910d3d48189c0a114 (diff) | |
download | odhcp6c-770741e98f2569ec0b00251ba9bf17a92e89221e.tar.gz |
Fix calculation of preferred and valid times
-rw-r--r-- | src/dhcpv6.c | 12 | ||||
-rw-r--r-- | src/odhcp6c.h | 2 | ||||
-rw-r--r-- | src/rtnetlink.c | 4 |
3 files changed, 11 insertions, 7 deletions
diff --git a/src/dhcpv6.c b/src/dhcpv6.c index 93433d4..28fad50 100644 --- a/src/dhcpv6.c +++ b/src/dhcpv6.c @@ -614,20 +614,24 @@ static int dhcpv6_handle_reply(_unused enum dhcpv6_msg orig, dhcpv6_for_each_option(ia_pd, ia_pd + ia_pd_len, otype, olen, odata) { struct dhcpv6_ia_prefix *p = (void*)&odata[-4]; uint32_t valid = ntohl(p->valid); - p->valid = (valid < elapsed) ? 0 : htonl(valid - elapsed); + if (valid != UINT32_MAX) + p->valid = (valid < elapsed) ? 0 : htonl(valid - elapsed); uint32_t pref = ntohl(p->preferred); - p->preferred = (pref < elapsed) ? 0 : htonl(pref - elapsed); + if (pref != UINT32_MAX) + p->preferred = (pref < elapsed) ? 0 : htonl(pref - elapsed); } // Decrease valid and preferred lifetime of addresses dhcpv6_for_each_option(ia_na, ia_na + ia_na_len, otype, olen, odata) { struct dhcpv6_ia_addr *p = (void*)&odata[-4]; uint32_t valid = ntohl(p->valid); - p->valid = (valid < elapsed) ? 0 : htonl(valid - elapsed); + if (valid != UINT32_MAX) + p->valid = (valid < elapsed) ? 0 : htonl(valid - elapsed); uint32_t pref = ntohl(p->preferred); - p->preferred = (pref < elapsed) ? 0 : htonl(pref - elapsed); + if (pref != UINT32_MAX) + p->preferred = (pref < elapsed) ? 0 : htonl(pref - elapsed); } // Parse and find all matching IAs diff --git a/src/odhcp6c.h b/src/odhcp6c.h index 04a32ec..1a5aabc 100644 --- a/src/odhcp6c.h +++ b/src/odhcp6c.h @@ -195,7 +195,7 @@ void dhcpv6_remove_addrs(void); int init_rtnetlink(void); int set_rtnetlink_addr(int ifindex, const struct in6_addr *addr, - time_t pref, time_t valid); + uint32_t pref, uint32_t valid); int script_init(const char *path, const char *ifname); ssize_t script_unhexlify(uint8_t *dst, size_t len, const char *src); diff --git a/src/rtnetlink.c b/src/rtnetlink.c index d15ae13..6017aab 100644 --- a/src/rtnetlink.c +++ b/src/rtnetlink.c @@ -43,12 +43,12 @@ int init_rtnetlink(void) // CRUD addresses to interface int set_rtnetlink_addr(int ifindex, const struct in6_addr *addr, - time_t pref, time_t valid) + uint32_t pref, uint32_t valid) { int flags = NLM_F_REQUEST | NLM_F_ACK; int cmd = RTM_DELADDR; - if (valid > 0) { + if (valid) { flags |= NLM_F_CREATE | NLM_F_REPLACE; cmd = RTM_NEWADDR; } |