]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
If we have route metrics and the kernel claims our new route exists and
authorRoy Marples <roy@marples.name>
Thu, 26 Mar 2015 22:26:38 +0000 (22:26 +0000)
committerRoy Marples <roy@marples.name>
Thu, 26 Mar 2015 22:26:38 +0000 (22:26 +0000)
we have an old route to delete, we have to delete the old route and then
add the new route.

ipv4.c
ipv6.c

diff --git a/ipv4.c b/ipv4.c
index 195201103bd7db57523725a022cfafa8446afc03..17d226690cd5de9d24b6a2f335e1da86910ec296 100644 (file)
--- a/ipv4.c
+++ b/ipv4.c
@@ -370,9 +370,6 @@ ipv4_handlert(struct dhcpcd_ctx *ctx, int cmd, struct rt *rt)
 static int
 nc_route(struct rt *ort, struct rt *nrt)
 {
-#ifdef HAVE_ROUTE_METRIC
-       int retval;
-#endif
 
        /* Don't set default routes if not asked to */
        if (nrt->dest.s_addr == 0 &&
@@ -405,21 +402,29 @@ nc_route(struct rt *ort, struct rt *nrt)
 #ifdef HAVE_ROUTE_METRIC
        /* With route metrics, we can safely add the new route before
         * deleting the old route. */
-       if ((retval = if_route(RTM_ADD, nrt))  == -1)
-               logger(nrt->iface->ctx, LOG_ERR, "if_route (ADD): %m");
-       if (ort && if_route(RTM_DELETE, ort) == -1 && errno != ESRCH)
-               logger(nrt->iface->ctx, LOG_ERR, "if_route (DEL): %m");
-       return retval;
-#else
+       if (if_route(RTM_ADD, nrt)  == 0) {
+               if (ort && if_route(RTM_DELETE, ort) == -1 && errno != ESRCH)
+                       logger(nrt->iface->ctx, LOG_ERR, "if_route (DEL): %m");
+               return 0;
+       }
+
+       /* If the kernel claims the route exists we need to rip out the
+        * old one first. */
+       if (errno != EEXIST || ort == NULL)
+               goto logerr;
+#endif
+
        /* 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 (if_route(RTM_ADD, nrt) == 0)
                return 0;
+#ifdef HAVE_ROUTE_METRIC
+logerr:
+#endif
        logger(nrt->iface->ctx, LOG_ERR, "if_route (ADD): %m");
        return -1;
-#endif
 }
 
 static int
diff --git a/ipv6.c b/ipv6.c
index 2187c4612c7c3a6064f83b489bde5bc684b0598e..966b516ce3d145dd3c13fb262636c809a75ac764 100644 (file)
--- a/ipv6.c
+++ b/ipv6.c
@@ -1819,9 +1819,6 @@ ipv6_handlert(struct dhcpcd_ctx *ctx, int cmd, struct rt6 *rt)
 static int
 nc_route(struct rt6 *ort, struct rt6 *nrt)
 {
-#ifdef HAVE_ROUTE_METRIC
-       int retval;
-#endif
 
        /* Don't set default routes if not asked to */
        if (IN6_IS_ADDR_UNSPECIFIED(&nrt->dest) &&
@@ -1846,22 +1843,30 @@ nc_route(struct rt6 *ort, struct rt6 *nrt)
 #ifdef HAVE_ROUTE_METRIC
        /* With route metrics, we can safely add the new route before
         * deleting the old route. */
-       if ((retval = if_route6(RTM_ADD, nrt)) == -1)
-               logger(nrt->iface->ctx, LOG_ERR, "if_route6 (ADD): %m");
-       if (ort && if_route6(RTM_DELETE, ort) == -1 &&
-           errno != ESRCH)
-               logger(nrt->iface->ctx, LOG_ERR, "if_route6 (DEL): %m");
-       return retval;
-#else
+       if (if_route6(RTM_ADD, nrt) == 0) {
+               if (ort && if_route6(RTM_DELETE, ort) == -1 &&
+                   errno != ESRCH)
+                       logger(nrt->iface->ctx, LOG_ERR, "if_route6 (DEL): %m");
+               return 0;
+       }
+
+       /* If the kernel claims the route exists we need to rip out the
+        * old one first. */
+       if (errno != EEXIST || ort == NULL)
+               goto logerr;
+#endif
+
        /* No route metrics, we need to delete the old route before
         * adding the new one. */
        if (ort && if_route6(RTM_DELETE, ort) == -1 && errno != ESRCH)
                logger(nrt->iface->ctx, LOG_ERR, "if_route6: %m");
        if (if_route6(RTM_ADD, nrt) == 0)
                return 0;
+#ifdef HAVE_ROUTE_METRIC
+logerr:
+#endif
        logger(nrt->iface->ctx, LOG_ERR, "if_route6 (ADD): %m");
        return -1;
-#endif
 }
 
 static int