From 770741e98f2569ec0b00251ba9bf17a92e89221e Mon Sep 17 00:00:00 2001 From: Steven Barth Date: Mon, 21 Jan 2013 08:45:16 +0100 Subject: [PATCH] Fix calculation of preferred and valid times --- src/dhcpv6.c | 12 ++++++++---- src/odhcp6c.h | 2 +- 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; } -- 2.30.2