]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
When deleting routes, delete the stored kernel route as well.
authorRoy Marples <roy@marples.name>
Fri, 2 Sep 2016 13:10:39 +0000 (13:10 +0000)
committerRoy Marples <roy@marples.name>
Fri, 2 Sep 2016 13:10:39 +0000 (13:10 +0000)
This enables IPv4LL default routes to be re-added if a DHCP lease expires.

ipv4.c

diff --git a/ipv4.c b/ipv4.c
index 1f56dab9e85421196164f2622b70d66342a61ffc..0bd3ceb8f77c47e343721cfff68bfd8bdc3c7811 100644 (file)
--- a/ipv4.c
+++ b/ipv4.c
@@ -392,6 +392,19 @@ ipv4_handlert(struct dhcpcd_ctx *ctx, int cmd, const struct rt *rt, int flags)
        return flags ? 0 : ipv4ll_handlert(ctx, cmd, rt);
 }
 
+static void
+d_kroute(struct rt *rt)
+{
+       struct dhcpcd_ctx *ctx;
+
+       ctx = rt->iface->ctx;
+       rt = ipv4_findrt(ctx, rt, 1);
+       if (rt != NULL) {
+               TAILQ_REMOVE(ctx->ipv4_kroutes, rt, next);
+               free(rt);
+       }
+}
+
 #define n_route(a)      nc_route(NULL, a)
 #define c_route(a, b)   nc_route(a, b)
 static int
@@ -469,8 +482,12 @@ nc_route(struct rt *ort, struct rt *nrt)
 
        /* No route metrics, we need to delete the old route before
         * adding the new one. */
-       if (ort && if_route(RTM_DELETE, ort) == -1 && errno != ESRCH)
-               logger(nrt->iface->ctx, LOG_ERR, "if_route (DEL): %m");
+       if (ort) {
+               if (if_route(RTM_DELETE, ort) == -1 && errno != ESRCH)
+                       logger(nrt->iface->ctx, LOG_ERR, "if_route (DEL): %m");
+               else
+                       d_kroute(ort);
+       }
        if (if_route(RTM_ADD, nrt) != -1)
                return 0;
 #ifdef HAVE_ROUTE_METRIC
@@ -490,6 +507,10 @@ d_route(struct rt *rt)
        if (retval == -1 && errno != ENOENT && errno != ESRCH)
                logger(rt->iface->ctx, LOG_ERR,
                    "%s: if_delroute: %m", rt->iface->name);
+       /* Remove the route from our kernel table so we can add a
+        * IPv4LL default route if possible. */
+       else
+               d_kroute(rt);
        return retval;
 }