From 8bc76072162e5208a33e834b5ca15d60d9197ca6 Mon Sep 17 00:00:00 2001 From: Roy Marples Date: Tue, 25 Jun 2024 11:40:14 +0100 Subject: [PATCH] DHCP6: Don't remove delegated prefix addresses on start 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 | 2 +- src/ipv6.c | 27 +++++++++++++++++++-------- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/src/dhcp6.c b/src/dhcp6.c index 76a6719b..0f1ba25f 100644 --- a/src/dhcp6.c +++ b/src/dhcp6.c @@ -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; } diff --git a/src/ipv6.c b/src/ipv6.c index 022e82a0..c08f0ee5 100644 --- a/src/ipv6.c +++ b/src/ipv6.c @@ -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; -- 2.47.2