From: Steven Barth Date: Wed, 15 Jul 2015 06:56:53 +0000 (+0200) Subject: router: fixup RA lifetime calculation X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=9f96f988e2c3a0519bef59535e15ad9c176aa254;p=oweals%2Fodhcpd.git router: fixup RA lifetime calculation --- diff --git a/src/router.c b/src/router.c index 51fd954..bbde03f 100644 --- a/src/router.c +++ b/src/router.c @@ -331,7 +331,7 @@ static uint64_t send_router_advert(struct interface *iface, const struct in6_add if (iface->dns_cnt > 0) { dns_addr = iface->dns; dns_cnt = iface->dns_cnt; - dns_time = 2 * MaxRtrAdvInterval; + dns_time = 0; } if (!dns_addr || IN6_IS_ADDR_UNSPECIFIED(dns_addr)) @@ -376,7 +376,6 @@ static uint64_t send_router_advert(struct interface *iface, const struct in6_add search->len = search_len ? ((sizeof(*search) + search_padded) / 8) : 0; search->pad = 0; search->pad2 = 0; - search->lifetime = htonl(2 * MaxRtrAdvInterval);; memcpy(search->name, search_domain, search_len); memset(&search->name[search_len], 0, search_padded - search_len); @@ -428,7 +427,7 @@ static uint64_t send_router_advert(struct interface *iface, const struct in6_add if (maxival < 4000 || maxival > MaxRtrAdvInterval * 1000) maxival = MaxRtrAdvInterval * 1000; - if (minvalid < maxival / 3) { + if (maxival > minvalid / 3) { maxival = minvalid / 3; if (maxival < 4000) @@ -439,6 +438,11 @@ static uint64_t send_router_advert(struct interface *iface, const struct in6_add if (adv.h.nd_ra_router_lifetime) adv.h.nd_ra_router_lifetime = htons(maxvalid / 1000); + search->lifetime = htonl((maxival * 3) / 1000); + + if (!dns.lifetime) + dns.lifetime = search->lifetime; + odhcpd_urandom(&msecs, sizeof(msecs)); msecs = (labs(msecs) % (maxival - minival)) + minival; diff --git a/src/router.h b/src/router.h index db8ab9d..720490d 100644 --- a/src/router.h +++ b/src/router.h @@ -30,8 +30,8 @@ struct icmpv6_opt { (void*)(opt + opt->len) <= (void*)(end); opt += opt->len) -#define MaxRtrAdvInterval 1800 #define MaxValidTime 65535 +#define MaxRtrAdvInterval (MaxValidTime / 3) #define ND_RA_FLAG_PROXY 0x4 #define ND_RA_PREF_HIGH (1 << 3)