From: Roy Marples Date: Mon, 15 May 2017 12:10:17 +0000 (+0100) Subject: Prefix Delegation: build routes after all addresses delegated X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=eb07222e57c959fdd5a359cc6e7fbb14d5bd922f;p=thirdparty%2Fdhcpcd.git Prefix Delegation: build routes after all addresses delegated Summary: When addresses are delegated the routing for them needs to be managed. But this can be done after all addresses have been added because DaD will cause the scripts to be run shortly after adding all of them. The only problem with this approach is when dhcpcd is restarted and adds a delegation which already exists. In this case, dhcpcd will log it added the route after it ran the hook script. This is of course incorrect because the route should already be there and working - assuming dhcpcd is the sole changer of the route. Fixes T117 because rebuilding the routes inside the enumeration of interfaces may change the order of interfaces and thus break the enumeration. Test Plan: Setup dhcpcd to request delegation to many interfaces. Once delegation is assigned, drop and restore carrier on the upstream interface. Observe dhcpcd assigns delegations to all interfaces with carriers. Reviewers: sthen Reviewed By: sthen Maniphest Tasks: T117 Differential Revision: https://dev.marples.name/D112 --- diff --git a/src/dhcp6.c b/src/dhcp6.c index a8bbd8dd..15fd9069 100644 --- a/src/dhcp6.c +++ b/src/dhcp6.c @@ -2671,11 +2671,26 @@ dhcp6_delegate_prefix(struct interface *ifp) if (k && !carrier_warned) { ifd_state = D6_STATE(ifd); ipv6_addaddrs(&ifd_state->addrs); - if_initrt(ifd->ctx, AF_INET6); - rt_build(ifd->ctx, AF_INET6); + /* + * Can't add routes here because that will trigger + * interface sorting which may break the current + * enumeration. + * This doesn't really matter thanks to DaD because + * calling the script will be delayed and routes + * will get re-built if needed first. + * This only cause minor confusion when dhcpcd is + * restarted and confirms a lease where prior delegation + * has already been assigned, because it will log it + * added routes after the script has run. + * The routes should still be there and fine though. + */ dhcp6_script_try_run(ifd, 1); } } + + /* Now all addresses have been added, rebuild the routing table. */ + if_initrt(ifp->ctx, AF_INET6); + rt_build(ifp->ctx, AF_INET6); } static void