summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--src/router.c23
1 files changed, 12 insertions, 11 deletions
diff --git a/src/router.c b/src/router.c
index 1a008e1..d7452f5 100644
--- a/src/router.c
+++ b/src/router.c
@@ -39,6 +39,7 @@ static struct odhcpd_event router_event = {{.fd = -1}, handle_icmpv6};
static FILE *fp_route = NULL;
#define RA_IOV_LEN 6
+#define TIME_LEFT(t1, now) ((t1) != UINT32_MAX ? (t1) - (now) : UINT32_MAX)
int init_router(void)
{
@@ -288,15 +289,15 @@ static uint64_t send_router_advert(struct interface *iface, const struct in6_add
}
if (addr->preferred > (uint32_t)now &&
- minvalid > 1000LL * (addr->valid - now))
- minvalid = 1000LL * (addr->valid - now);
+ minvalid > 1000LL * TIME_LEFT(addr->valid, now))
+ minvalid = 1000LL * TIME_LEFT(addr->valid, now);
- if (maxvalid < 1000LL * (addr->valid - now))
- maxvalid = 1000LL * (addr->valid - now);
+ if (maxvalid < 1000LL * TIME_LEFT(addr->valid, now))
+ maxvalid = 1000LL * TIME_LEFT(addr->valid, now);
if (((addr->addr.s6_addr[0] & 0xfe) != 0xfc || iface->default_router)
- && ntohs(adv.h.nd_ra_router_lifetime) < addr->valid - now)
- adv.h.nd_ra_router_lifetime = htons(addr->valid - now);
+ && ntohs(adv.h.nd_ra_router_lifetime) < TIME_LEFT(addr->valid, now))
+ adv.h.nd_ra_router_lifetime = htons(TIME_LEFT(addr->valid, now));
odhcpd_bmemcpy(&p->nd_opt_pi_prefix, &addr->addr,
(iface->ra_advrouter) ? 128 : addr->prefix);
@@ -310,13 +311,13 @@ static uint64_t send_router_advert(struct interface *iface, const struct in6_add
p->nd_opt_pi_flags_reserved |= ND_OPT_PI_FLAG_AUTO;
if (iface->ra_advrouter)
p->nd_opt_pi_flags_reserved |= ND_OPT_PI_FLAG_RADDR;
- p->nd_opt_pi_valid_time = htonl(addr->valid - now);
+ p->nd_opt_pi_valid_time = htonl(TIME_LEFT(addr->valid, now));
if (addr->preferred > (uint32_t)now)
- p->nd_opt_pi_preferred_time = htonl(addr->preferred - now);
+ p->nd_opt_pi_preferred_time = htonl(TIME_LEFT(addr->preferred, now));
- if (addr->preferred - now > dns_time) {
- dns_time = addr->preferred - now;
+ if (TIME_LEFT(addr->preferred, now) > dns_time) {
+ dns_time = TIME_LEFT(addr->preferred, now);
dns_pref = addr->addr;
}
}
@@ -410,7 +411,7 @@ static uint64_t send_router_advert(struct interface *iface, const struct in6_add
routes[routes_cnt].flags |= ND_RA_PREF_LOW;
else if (iface->route_preference > 0)
routes[routes_cnt].flags |= ND_RA_PREF_HIGH;
- routes[routes_cnt].lifetime = htonl(addr->valid - now);
+ routes[routes_cnt].lifetime = htonl(TIME_LEFT(addr->valid, now));
routes[routes_cnt].addr[0] = addr->addr.s6_addr32[0];
routes[routes_cnt].addr[1] = addr->addr.s6_addr32[1];
routes[routes_cnt].addr[2] = 0;