]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
Some systems mark a host route using RTF_HOST and some use an
authorRoy Marples <roy@marples.name>
Sun, 15 Jul 2018 13:20:16 +0000 (14:20 +0100)
committerRoy Marples <roy@marples.name>
Sun, 15 Jul 2018 13:20:16 +0000 (14:20 +0100)
all-ones netmask.

For the former, only test netmask for equality if both routes
lack the RTF_HOST marking.

src/route.c

index 09545cdc0c290ded9c3b333f115d2d1e105a2048..8dc8639217bda275b7587320f923ca1a127bbe00 100644 (file)
 #include "route.h"
 #include "sa.h"
 
+/*
+ * On some systems, host routes have no need for a netmask.
+ * However DHCP specifies host routes using an all-ones netmask.
+ * This handy function allows easy comparison when the two
+ * differ.
+ */
+static int
+rt_cmp_netmask(const struct rt *rt1, const struct rt *rt2)
+{
+
+       if (rt1->rt_flags & RTF_HOST && rt2->rt_flags & RTF_HOST)
+               return 0;
+       return sa_cmp(&rt1->rt_netmask, &rt2->rt_netmask);
+}
+
 void
 rt_init(struct dhcpcd_ctx *ctx)
 {
@@ -63,14 +78,12 @@ rt_desc(const char *cmd, const struct rt *rt)
 
        assert(cmd != NULL);
        assert(rt != NULL);
-       assert(rt->rt_ifp != NULL);
 
-       ifname = rt->rt_ifp->name;
        sa_addrtop(&rt->rt_dest, dest, sizeof(dest));
        prefix = sa_toprefix(&rt->rt_netmask);
        sa_addrtop(&rt->rt_gateway, gateway, sizeof(gateway));
-
        gateway_unspec = sa_is_unspecified(&rt->rt_gateway);
+       ifname = rt->rt_ifp == NULL ? "(null)" : rt->rt_ifp->name;
 
        if (rt->rt_flags & RTF_HOST) {
                if (gateway_unspec)
@@ -236,7 +249,7 @@ rt_find(struct rt_head *rts, const struct rt *f)
                    (f->rt_ifp == NULL ||
                    rt->rt_ifp->metric == f->rt_ifp->metric) &&
 #endif
-                   sa_cmp(&rt->rt_netmask, &f->rt_netmask) == 0)
+                   rt_cmp_netmask(f, rt) == 0)
                        return rt;
        }
        return NULL;
@@ -345,7 +358,7 @@ rt_add(struct rt *nrt, struct rt *ort)
            ort->rt_metric == nrt->rt_metric &&
 #endif
            sa_cmp(&ort->rt_dest, &nrt->rt_dest) == 0 &&
-           sa_cmp(&ort->rt_netmask, &nrt->rt_netmask) == 0 &&
+           rt_cmp_netmask(ort, nrt) == 0 &&
            sa_cmp(&ort->rt_gateway, &nrt->rt_gateway) == 0)
        {
                if (ort->rt_mtu == nrt->rt_mtu)