From 4f422dd3bcd2c8b345084cca6cd29a8876b258cc Mon Sep 17 00:00:00 2001 From: Roy Marples Date: Fri, 7 Mar 2014 13:01:20 +0000 Subject: [PATCH] A router with a lifetime of zero is no longer a default router. However, the options it passes do have lifetimes which we should still respect according to RFC4861 section 4.2. --- ipv6.c | 5 +++-- ipv6nd.c | 58 ++++++++++++++++++++++++-------------------------------- 2 files changed, 28 insertions(+), 35 deletions(-) diff --git a/ipv6.c b/ipv6.c index ed5882e0..30b6c056 100644 --- a/ipv6.c +++ b/ipv6.c @@ -942,14 +942,15 @@ ipv6_build_ra_routes(struct ipv6_ctx *ctx, struct rt6_head *dnr, int expired) continue; if (rap->iface->options->options & DHCPCD_IPV6RA_OWN) { TAILQ_FOREACH(addr, &rap->addrs, next) { - if ((addr->flags & IPV6_AF_ONLINK) == 0) + if (addr->prefix_vltime == 0 || + (addr->flags & IPV6_AF_ONLINK) == 0) continue; rt = make_prefix(rap->iface, rap, addr); if (rt) TAILQ_INSERT_TAIL(dnr, rt, next); } } - if (rap->iface->options->options & + if (rap->lifetime && rap->iface->options->options & (DHCPCD_IPV6RA_OWN | DHCPCD_IPV6RA_OWN_DEFAULT)) { rt = make_router(rap); diff --git a/ipv6nd.c b/ipv6nd.c index 7eccdad7..22c5e2c1 100644 --- a/ipv6nd.c +++ b/ipv6nd.c @@ -588,7 +588,7 @@ ipv6nd_dadcallback(void *arg) found = 1; } - if (wascompleted && found && rap->lifetime) { + if (wascompleted && found) { syslog(LOG_DEBUG, "%s: Router Advertisement DAD completed", rap->iface->name); @@ -664,11 +664,6 @@ ipv6nd_handlera(struct ipv6_ctx *ctx, struct interface *ifp, } nd_ra = (struct nd_router_advert *)icp; - /* Don't bother doing anything if we don't know about a router - * expiring */ - if ((rap == NULL || rap->lifetime == 0) - && nd_ra->nd_ra_router_lifetime == 0) - return; /* We don't want to spam the log with the fact we got an RA every * 30 seconds or so, so only spam the log if it's different. */ @@ -980,12 +975,8 @@ ipv6nd_handlera(struct ipv6_ctx *ctx, struct interface *ifp, } ipv6_addaddrs(&rap->addrs); ipv6_buildroutes(ifp->ctx); - - /* We will get run by the expire function */ - if (rap->lifetime) { - if (ipv6nd_scriptrun(rap)) - return; - } + if (ipv6nd_scriptrun(rap)) + return; eloop_timeout_delete(ifp->ctx->eloop, NULL, ifp); eloop_timeout_delete(ifp->ctx->eloop, NULL, rap); /* reachable timer */ @@ -1002,15 +993,13 @@ ipv6nd_handlera(struct ipv6_ctx *ctx, struct interface *ifp, handle_flag: if (rap->flags & ND_RA_FLAG_MANAGED) { - if (rap->lifetime && new_data && - dhcp6_start(ifp, DH6S_INIT) == -1) + if (new_data && dhcp6_start(ifp, DH6S_INIT) == -1) syslog(LOG_ERR, "dhcp6_start: %s: %m", ifp->name); } else if (rap->flags & ND_RA_FLAG_OTHER) { - if (rap->lifetime && new_data && - dhcp6_start(ifp, DH6S_INFORM) == -1) + if (new_data && dhcp6_start(ifp, DH6S_INFORM) == -1) syslog(LOG_ERR, "dhcp6_start: %s: %m", ifp->name); } else { - if (rap->lifetime && new_data) + if (new_data) syslog(LOG_DEBUG, "%s: No DHCPv6 instruction in RA", ifp->name); if (ifp->ctx->options & DHCPCD_TEST) { @@ -1180,23 +1169,26 @@ ipv6nd_expirera(void *arg) TAILQ_FOREACH_SAFE(rap, ifp->ctx->ipv6->ra_routers, next, ran) { if (rap->iface != ifp) continue; - lt.tv_sec = rap->lifetime; - lt.tv_usec = 0; - timeradd(&rap->received, <, &expire); - if (rap->lifetime == 0 || timercmp(&now, &expire, >)) { - valid = 0; - if (!rap->expired) { - syslog(LOG_WARNING, - "%s: %s: router expired", - ifp->name, rap->sfrom); - rap->expired = expired = 1; - ipv6nd_cancelproberouter(rap); + valid = 0; + if (rap->lifetime) { + lt.tv_sec = rap->lifetime; + lt.tv_usec = 0; + timeradd(&rap->received, <, &expire); + if (rap->lifetime == 0 || timercmp(&now, &expire, >)) { + if (!rap->expired) { + syslog(LOG_WARNING, + "%s: %s: router expired", + ifp->name, rap->sfrom); + rap->expired = expired = 1; + ipv6nd_cancelproberouter(rap); + } + } else { + valid = 1; + timersub(&expire, &now, <); + if (!timerisset(&next) || + timercmp(&next, <, >)) + next = lt; } - } else { - valid = 1; - timersub(&expire, &now, <); - if (!timerisset(&next) || timercmp(&next, <, >)) - next = lt; } /* Addresses are expired in ipv6_addaddrs -- 2.47.3