]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
inet6: Apply the best RA which is still valid.
authorRoy Marples <roy@marples.name>
Wed, 29 Apr 2020 14:32:15 +0000 (15:32 +0100)
committerRoy Marples <roy@marples.name>
Wed, 29 Apr 2020 14:32:15 +0000 (15:32 +0100)
If there is no such RA, then apply some defaults.

src/ipv6nd.c

index 99e92aaf7844b274daebb85bbaed06f0ff9f79cb..fc84d3f58c5ca5f66dc6ba62f3ec4b80c2b33982 100644 (file)
@@ -634,18 +634,26 @@ ipv6nd_sortrouters(struct dhcpcd_ctx *ctx)
 }
 
 static void
-ipv6nd_applyra(struct dhcpcd_ctx *ctx, struct interface *ifp)
+ipv6nd_applyra(struct interface *ifp)
 {
        struct ra *rap;
        struct rs_state *state = RS_STATE(ifp);
 
-       TAILQ_FOREACH(rap, ctx->ra_routers, next) {
-               if (rap->iface == ifp)
+       struct ra defra = {
+               .iface = ifp,
+               .hoplimit = IPV6_DEFHLIM ,
+               .reachable = REACHABLE_TIME,
+               .retrans = RETRANS_TIMER,
+       };
+
+       TAILQ_FOREACH(rap, ifp->ctx->ra_routers, next) {
+               if (rap->iface == ifp && rap->lifetime != 0)
                        break;
        }
 
+       /* If we have no Router Advertisement, then set default values. */
        if (rap == NULL)
-               return;
+               rap = &defra;
 
        state->retrans = rap->retrans;
        if (if_applyra(rap) == -1 && errno != ENOENT)
@@ -687,7 +695,7 @@ ipv6nd_neighbour(struct dhcpcd_ctx *ctx, struct in6_addr *addr, bool reachable)
 
        /* See if we can install a reachable default router. */
        ipv6nd_sortrouters(ctx);
-       ipv6nd_applyra(ctx, rap->iface);
+       ipv6nd_applyra(rap->iface);
        rt_build(ctx, AF_INET6);
 
        if (reachable)
@@ -1441,7 +1449,7 @@ ipv6nd_handlera(struct dhcpcd_ctx *ctx,
                script_runreason(ifp, "TEST");
                goto handle_flag;
        }
-       ipv6nd_applyra(ifp->ctx, ifp);
+       ipv6nd_applyra(ifp);
        ipv6_addaddrs(&rap->addrs);
 #ifdef IPV6_MANAGETEMPADDR
        ipv6_addtempaddrs(ifp, &rap->acquired);
@@ -1835,6 +1843,8 @@ ipv6nd_expirera(void *arg)
        if (expired) {
                logwarnx("%s: part of a Router Advertisement expired",
                    ifp->name);
+               ipv6nd_sortrouters(ifp->ctx);
+               ipv6nd_applyra(ifp);
                rt_build(ifp->ctx, AF_INET6);
                script_runreason(ifp, "ROUTERADVERT");
        }
@@ -1857,6 +1867,7 @@ ipv6nd_drop(struct interface *ifp)
                }
        }
        if (expired) {
+               ipv6nd_applyra(ifp);
                rt_build(ifp->ctx, AF_INET6);
                if ((ifp->options->options & DHCPCD_NODROP) != DHCPCD_NODROP)
                        script_runreason(ifp, "ROUTERADVERT");