]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
Prefix Delegation: build routes after all addresses delegated
authorRoy Marples <roy@marples.name>
Mon, 15 May 2017 12:10:17 +0000 (13:10 +0100)
committerRoy Marples <roy@marples.name>
Mon, 15 May 2017 12:10:37 +0000 (13:10 +0100)
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

src/dhcp6.c

index a8bbd8dd82a03f303411b10172897f98a8f13d52..15fd9069ff9e4169352fd1986e0049078654b1a4 100644 (file)
@@ -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