]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
Optimise adding and changing ipv6 routes.
authorRoy Marples <roy@marples.name>
Fri, 24 May 2013 08:06:57 +0000 (08:06 +0000)
committerRoy Marples <roy@marples.name>
Fri, 24 May 2013 08:06:57 +0000 (08:06 +0000)
ipv4.c
ipv6.c

diff --git a/ipv4.c b/ipv4.c
index d937a0bef0022319cede8df39fb0b74f0f59578b..3afbb73f198e82c4f8a1c8917f4dbf2aaee01f19 100644 (file)
--- a/ipv4.c
+++ b/ipv4.c
@@ -266,7 +266,8 @@ nc_route(int add, struct rt *ort, struct rt *nrt)
                return -1;
 
        desc_route(add ? "adding" : "changing", nrt);
-       /* We delete and add the route so that we can change metric.
+       /* We delete and add the route so that we can change metric and
+        * prefer the interface.
         * This also has the nice side effect of flushing ARP entries so
         * we don't have to do that manually. */
        ipv4_deleteroute(ort);
diff --git a/ipv6.c b/ipv6.c
index a3100d1ddfd7268d0273899c0bc6bdc3c6524c30..57b475d402bdd3532df5f06ca584f2793b1df90c 100644 (file)
--- a/ipv6.c
+++ b/ipv6.c
@@ -493,29 +493,10 @@ desc_route(const char *cmd, const struct rt6 *rt)
                    dest, ipv6_prefixlen(&rt->net), gate);
 }
 
+#define n_route(a)      nc_route(1, a, a)
+#define c_route(a, b)   nc_route(0, a, b)
 static int
-n_route(struct rt6 *rt)
-{
-
-       /* Don't set default routes if not asked to */
-       if (IN6_IS_ADDR_UNSPECIFIED(&rt->dest) &&
-           IN6_IS_ADDR_UNSPECIFIED(&rt->net) &&
-           !(rt->iface->options->options & DHCPCD_GATEWAY))
-               return -1;
-
-       /* Delete the route first as it could exist prior to dhcpcd running
-        * and we need to ensure it leaves via our preffered interface */
-       del_route6(rt);
-       desc_route("adding", rt);
-       if (!add_route6(rt))
-               return 0;
-
-       syslog(LOG_ERR, "%s: add_route: %m", rt->iface->name);
-       return -1;
-}
-
-static int
-c_route(struct rt6 *ort, struct rt6 *nrt)
+nc_route(int add, struct rt6 *ort, struct rt6 *nrt)
 {
 
        /* Don't set default routes if not asked to */
@@ -524,14 +505,13 @@ c_route(struct rt6 *ort, struct rt6 *nrt)
            !(nrt->iface->options->options & DHCPCD_GATEWAY))
                return -1;
 
-       desc_route("changing", nrt);
-       /* We delete and add the route so that we can change metric.
-        * This also has the nice side effect of flushing ARP entries so
-        * we don't have to do that manually. */
+       desc_route(add ? "adding" : "changing", nrt);
+       /* We delete and add the route so that we can change metric and
+        * prefer the interface. */
        del_route6(ort);
        if (!add_route6(nrt))
                return 0;
-       syslog(LOG_ERR, "%s: add_route: %m", nrt->iface->name);
+       syslog(LOG_ERR, "%s: add_route6: %m", nrt->iface->name);
        return -1;
 }
 
@@ -543,7 +523,7 @@ d_route(struct rt6 *rt)
        desc_route("deleting", rt);
        retval = del_route6(rt);
        if (retval != 0 && errno != ENOENT && errno != ESRCH)
-               syslog(LOG_ERR,"%s: del_route: %m", rt->iface->name);
+               syslog(LOG_ERR,"%s: del_route6: %m", rt->iface->name);
        return retval;
 }