]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
Detect RTF_REJECT routes.
authorRoy Marples <roy@marples.name>
Sat, 14 Mar 2015 00:40:17 +0000 (00:40 +0000)
committerRoy Marples <roy@marples.name>
Sat, 14 Mar 2015 00:40:17 +0000 (00:40 +0000)
if-bsd.c
if-linux.c
ipv4.c
ipv6.c

index 805ad9cfd975856593239bdedabd2bfd3d3d260c..d21f61618ef44b16fd392300362e999a47849973 100644 (file)
--- a/if-bsd.c
+++ b/if-bsd.c
@@ -510,6 +510,7 @@ if_copyrt(struct dhcpcd_ctx *ctx, struct rt *rt, struct rt_msghdr *rtm)
 
        get_addrs(rtm->rtm_addrs, cp, rti_info);
        memset(rt, 0, sizeof(*rt));
+       rt->flags = rtm->rtm_flags;
        COPYOUT(rt->dest, rti_info[RTAX_DST]);
        if (rtm->rtm_addrs & RTA_NETMASK)
                COPYOUT(rt->net, rti_info[RTAX_NETMASK]);
@@ -823,6 +824,7 @@ if_copyrt6(struct dhcpcd_ctx *ctx, struct rt6 *rt, struct rt_msghdr *rtm)
 
        get_addrs(rtm->rtm_addrs, cp, rti_info);
        memset(rt, 0, sizeof(*rt));
+       rt->flags = rtm->rtm_flags;
        COPYOUT6(rt->dest, rti_info[RTAX_DST]);
        if (rtm->rtm_addrs & RTA_NETMASK) {
                /*
index 874391895c887f8e8d82a97c6166115ca4e455fb..f5ea84c3ea8ee5c48bddf44787e94db6de4a0ce7 100644 (file)
@@ -469,6 +469,10 @@ if_copyrt6(struct dhcpcd_ctx *ctx, struct rt6 *rt, struct nlmsghdr *nlm)
                return -1;
 
        memset(rt, 0, sizeof(*rt));
+       ipv6_mask(&rt->net, rtm->rtm_dst_len);
+       if (rtm->rtm_type == RTN_UNREACHABLE)
+               rt->flags = RTF_REJECT;
+
        rta = (struct rtattr *)RTM_RTA(rtm);
        len = RTM_PAYLOAD(nlm);
        while (RTA_OK(rta, len)) {
@@ -492,7 +496,6 @@ if_copyrt6(struct dhcpcd_ctx *ctx, struct rt6 *rt, struct nlmsghdr *nlm)
                rta = RTA_NEXT(rta, len);
        }
 
-       ipv6_mask(&rt->net, rtm->rtm_dst_len);
        return 0;
 }
 #endif
@@ -1551,7 +1554,6 @@ if_route6(unsigned char cmd, const struct rt6 *rt)
                        add_attr_32(&nlm.hdr, sizeof(nlm),
                            RTA_PRIORITY, rt->metric);
        }
-
        if (cmd == RTM_ADD && rt->mtu) {
                char metricsbuf[32];
                struct rtattr *metrics = (void *)metricsbuf;
diff --git a/ipv4.c b/ipv4.c
index 544d6febca1dac4f6766466f5187d5a137c3cb67..5e0cf108ae8c9923756bd0052ebcacdcfdf3c05a 100644 (file)
--- a/ipv4.c
+++ b/ipv4.c
@@ -377,11 +377,13 @@ nc_route(struct rt *ort, struct rt *nrt)
 
        if (ort == NULL) {
                ort = ipv4_findrt(nrt->iface->ctx, nrt, 0);
-               if (ort && ort->iface == nrt->iface &&
+               if (ort &&
+                   ((ort->flags & RTF_REJECT && nrt->flags & RTF_REJECT) ||
+                    (ort->iface == nrt->iface &&
 #ifdef HAVE_ROUTE_METRIC
                    ort->metric == nrt->metric &&
 #endif
-                   ort->gate.s_addr == nrt->gate.s_addr)
+                   IN6_ARE_ADDR_EQUAL(&ort->gate, &nrt->gate))))
                        return 0;
        } else if (ort->flags & STATE_FAKE && !(nrt->flags & STATE_FAKE) &&
            ort->iface == nrt->iface &&
diff --git a/ipv6.c b/ipv6.c
index 7969c4103947989dec934c33c5889640bdc9a4d3..a2d87f6841370630653aa21b80056f050015e282 100644 (file)
--- a/ipv6.c
+++ b/ipv6.c
@@ -1740,12 +1740,13 @@ ipv6_findrt(struct dhcpcd_ctx *ctx, const struct rt6 *rt, int flags)
 
        TAILQ_FOREACH(r, &ctx->ipv6->kroutes, next) {
                if (IN6_ARE_ADDR_EQUAL(&rt->dest, &r->dest) &&
-                   (!flags || rt->iface == r->iface) &&
 #ifdef HAVE_ROUTE_METRIC
-                   rt->iface == r->iface &&
+                   (rt->iface == r->iface ||
+                   (rt->flags & RTF_REJECT && r->flags & RTF_REJECT)) &&
                    (!flags || rt->metric == r->metric) &&
 #else
-                   (!flags || rt->iface == r->iface) &&
+                   (!flags || rt->iface == r->iface ||
+                   (rt->flags & RTF_REJECT && r->flags & RTF_REJECT)) &&
 #endif
                    IN6_ARE_ADDR_EQUAL(&rt->net, &r->net))
                        return r;
@@ -1819,11 +1820,13 @@ nc_route(struct rt6 *ort, struct rt6 *nrt)
 
        if (ort == NULL) {
                ort = ipv6_findrt(nrt->iface->ctx, nrt, 0);
-               if (ort && ort->iface == nrt->iface &&
+               if (ort &&
+                   ((ort->flags & RTF_REJECT && nrt->flags & RTF_REJECT) ||
+                    (ort->iface == nrt->iface &&
 #ifdef HAVE_ROUTE_METRIC
                    ort->metric == nrt->metric &&
 #endif
-                   IN6_ARE_ADDR_EQUAL(&ort->gate, &nrt->gate))
+                   IN6_ARE_ADDR_EQUAL(&ort->gate, &nrt->gate))))
                        return 0;
        }