]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
DHCP6: Don't remove delegated prefix addresses on start
authorRoy Marples <roy@marples.name>
Tue, 25 Jun 2024 10:40:14 +0000 (11:40 +0100)
committerRoy Marples <roy@marples.name>
Tue, 25 Jun 2024 11:08:45 +0000 (12:08 +0100)
In the event where an interface is first delegated and then
started, we don't want the reading of a lease file to remove the
delegated prefixes or addresses.

As such, we also can't test the actual DHCP6 state when building
routes. Instead, just change the test for a delegated prefix
or not so we can still prefer non delegated routes.

Fixes #333.

src/dhcp6.c
src/ipv6.c

index 76a6719b5c04c1d2f9587951eff18e294560a984..0f1ba25f1285f052a8c60eea0fca999ed77b991c 100644 (file)
@@ -2394,7 +2394,7 @@ dhcp6_findia(struct interface *ifp, struct dhcp6_message *m, size_t l,
        i = e = 0;
        state = D6_STATE(ifp);
        TAILQ_FOREACH(ap, &state->addrs, next) {
-               if (!(ap->flags & IPV6_AF_DELEGATED))
+               if (!(ap->flags & (IPV6_AF_DELEGATED | IPV6_AF_DELEGATEDPFX)))
                        ap->flags |= IPV6_AF_STALE;
        }
 
index 022e82a03597e1ac50d44819c5f89dabcd61d94a..c08f0ee5edb6e73e63deaf83f64864db7d19cbbe 100644 (file)
@@ -2395,19 +2395,30 @@ inet6_dhcproutes(rb_tree_t *routes, struct dhcpcd_ctx *ctx,
 {
        struct interface *ifp;
        const struct dhcp6_state *d6_state;
-       const struct ipv6_addr *addr;
+       const struct ipv6_addr *ia;
        struct rt *rt;
 
        TAILQ_FOREACH(ifp, ctx->ifaces, next) {
                d6_state = D6_CSTATE(ifp);
-               if (d6_state && d6_state->state == dstate) {
-                       TAILQ_FOREACH(addr, &d6_state->addrs, next) {
-                               rt = inet6_makeprefix(ifp, NULL, addr);
-                               if (rt == NULL)
+               if (d6_state == NULL)
+                       continue;
+
+               // Don't test the actual state as we could
+               // be between states with still valid routes
+
+               TAILQ_FOREACH(ia, &d6_state->addrs, next) {
+                       if (dstate == DH6S_DELEGATED) {
+                               // Reject route won't have IPV6_AF_ADDED
+                               if (!(ia->flags & IPV6_AF_DELEGATEDPFX))
                                        continue;
-                               rt->rt_dflags |= RTDF_DHCP;
-                               rt_proto_add(routes, rt);
-                       }
+                       } else if (!(ia->flags & IPV6_AF_ADDED))
+                               continue;
+
+                       rt = inet6_makeprefix(ifp, NULL, ia);
+                       if (rt == NULL)
+                               continue;
+                       rt->rt_dflags |= RTDF_DHCP;
+                       rt_proto_add(routes, rt);
                }
        }
        return 0;