summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteven Barth <steven@midlink.org>2013-01-21 08:45:16 +0100
committerSteven Barth <steven@midlink.org>2013-01-21 08:45:16 +0100
commit770741e98f2569ec0b00251ba9bf17a92e89221e (patch)
treea7202844708fb783654e37112635d4ea13c829fe
parent673d079b108815d5eff0547910d3d48189c0a114 (diff)
downloadodhcp6c-770741e98f2569ec0b00251ba9bf17a92e89221e.tar.gz
Fix calculation of preferred and valid times
-rw-r--r--src/dhcpv6.c12
-rw-r--r--src/odhcp6c.h2
-rw-r--r--src/rtnetlink.c4
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;
}