summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorSteven Barth <steven@midlink.org>2015-07-15 08:56:53 +0200
committerSteven Barth <steven@midlink.org>2015-07-15 08:56:53 +0200
commit9f96f988e2c3a0519bef59535e15ad9c176aa254 (patch)
tree1a801107124e810509b93658efcc9f4177a82693
parentd0ca3022a4041e7232587b024ebfaadbe2c095cc (diff)
router: fixup RA lifetime calculation
-rw-r--r--src/router.c10
-rw-r--r--src/router.h2
2 files changed, 8 insertions, 4 deletions
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)