From: Roy Marples Date: Sat, 14 Mar 2015 00:40:17 +0000 (+0000) Subject: Detect RTF_REJECT routes. X-Git-Tag: v6.8.0~24 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ed1327fc09cd05479f9efa516ff3fd6b6a32e8e5;p=thirdparty%2Fdhcpcd.git Detect RTF_REJECT routes. --- diff --git a/if-bsd.c b/if-bsd.c index 805ad9cf..d21f6161 100644 --- 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) { /* diff --git a/if-linux.c b/if-linux.c index 87439189..f5ea84c3 100644 --- a/if-linux.c +++ b/if-linux.c @@ -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 544d6feb..5e0cf108 100644 --- 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 7969c410..a2d87f68 100644 --- 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; }