From: Roy Marples Date: Tue, 3 Mar 2015 17:38:35 +0000 (+0000) Subject: Remove RTM_GET code as we now read all kernel routes before building our own. X-Git-Tag: v6.8.0~65 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=678c7bd122a55e69afbeba86a28ee24f218aa0f5;p=thirdparty%2Fdhcpcd.git Remove RTM_GET code as we now read all kernel routes before building our own. --- diff --git a/if-bsd.c b/if-bsd.c index 268e6b3e..7f1d6720 100644 --- a/if-bsd.c +++ b/if-bsd.c @@ -538,7 +538,7 @@ if_copyrt(struct dhcpcd_ctx *ctx, struct rt *rt, struct rt_msghdr *rtm) } int -if_route(unsigned char cmd, const struct rt *rt, struct rt *srt) +if_route(unsigned char cmd, const struct rt *rt) { const struct dhcp_state *state; union sockunion { @@ -632,9 +632,8 @@ if_route(unsigned char cmd, const struct rt *rt, struct rt *srt) if (rtm.hdr.rtm_flags & RTF_STATIC) rtm.hdr.rtm_flags |= RTF_GATEWAY; } - if (((cmd == RTM_ADD || cmd == RTM_CHANGE) && - !(rtm.hdr.rtm_flags & RTF_GATEWAY)) || - cmd == RTM_GET) + if ((cmd == RTM_ADD || cmd == RTM_CHANGE) && + !(rtm.hdr.rtm_flags & RTF_GATEWAY)) rtm.hdr.rtm_addrs |= RTA_IFA | RTA_IFP; ADDADDR(&rt->dest); @@ -674,16 +673,6 @@ if_route(unsigned char cmd, const struct rt *rt, struct rt *srt) rtm.hdr.rtm_msglen = (unsigned short)(bp - (char *)&rtm); retval = write(s, &rtm, rtm.hdr.rtm_msglen) == -1 ? -1 : 0; - - if (cmd == RTM_GET && retval == 0) { - retval = read(s, &rtm, sizeof(rtm)); - if (retval < (int)sizeof(struct rt_msghdr) || - retval < rtm.hdr.rtm_msglen) - retval = -1; - else - retval = if_copyrt(rt->iface->ctx, srt, &rtm.hdr); - } - close(s); return retval; } @@ -905,7 +894,7 @@ if_copyrt6(struct dhcpcd_ctx *ctx, struct rt6 *rt, struct rt_msghdr *rtm) } int -if_route6(unsigned char cmd, const struct rt6 *rt, struct rt6 *srt) +if_route6(unsigned char cmd, const struct rt6 *rt) { union sockunion { struct sockaddr sa; @@ -964,8 +953,7 @@ if_route6(unsigned char cmd, const struct rt6 *rt, struct rt6 *srt) if (cmd == RTM_ADD) rtm.hdr.rtm_addrs |= RTA_GATEWAY; - if (cmd == RTM_GET || - (cmd == RTM_ADD && !(rtm.hdr.rtm_flags & RTF_REJECT))) + if (cmd == RTM_ADD && !(rtm.hdr.rtm_flags & RTF_REJECT)) rtm.hdr.rtm_addrs |= RTA_IFP | RTA_IFA; ADDADDR(&rt->dest); @@ -1010,16 +998,6 @@ if_route6(unsigned char cmd, const struct rt6 *rt, struct rt6 *srt) rtm.hdr.rtm_msglen = (unsigned short)(bp - (char *)&rtm); retval = write(s, &rtm, rtm.hdr.rtm_msglen) == -1 ? -1 : 0; - - if (cmd == RTM_GET && retval == 0) { - retval = read(s, &rtm, sizeof(rtm)); - if (retval < (int)sizeof(struct rt_msghdr) || - retval < rtm.hdr.rtm_msglen) - retval = -1; - else - retval = if_copyrt6(rt->iface->ctx, srt, &rtm.hdr); - } - close(s); return retval; } diff --git a/if.h b/if.h index e105a0cc..fb2aa19c 100644 --- a/if.h +++ b/if.h @@ -124,7 +124,7 @@ int if_address(const struct interface *, #define if_deladdress(ifp, addr, net) \ if_address(ifp, addr, net, NULL, -1) -int if_route(unsigned char, const struct rt *rt, struct rt *); +int if_route(unsigned char, const struct rt *rt); int if_initrt(struct interface *); #endif @@ -145,7 +145,7 @@ int if_address6(const struct ipv6_addr *, int); int if_addrflags6(const struct in6_addr *, const struct interface *); int if_getlifetime6(struct ipv6_addr *); -int if_route6(unsigned char, const struct rt6 *rt, struct rt6 *); +int if_route6(unsigned char, const struct rt6 *rt); int if_initrt6(struct interface *); #else #define if_checkipv6(a, b, c) (-1) diff --git a/ipv4.c b/ipv4.c index 3fd3b570..de7e1e4a 100644 --- a/ipv4.c +++ b/ipv4.c @@ -436,17 +436,17 @@ 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, NULL)) == -1) + if ((retval = if_route(RTM_ADD, nrt)) == -1) syslog(LOG_ERR, "if_route (ADD): %m"); - if (ort && if_route(RTM_DELETE, ort, NULL) == -1 && errno != ESRCH) + if (ort && if_route(RTM_DELETE, ort) == -1 && errno != ESRCH) syslog(LOG_ERR, "if_route (DEL): %m"); return retval; #else /* No route metrics, we need to delete the old route before * adding the new one. */ - if (ort && if_route(RTM_DELETE, ort, NULL) == -1 && errno != ESRCH) + if (ort && if_route(RTM_DELETE, ort) == -1 && errno != ESRCH) syslog(LOG_ERR, "if_route (DEL): %m"); - if (if_route(RTM_ADD, nrt, NULL) == 0) + if (if_route(RTM_ADD, nrt) == 0) return 0; syslog(LOG_ERR, "if_route (ADD): %m"); return -1; @@ -459,7 +459,7 @@ d_route(struct rt *rt) int retval; desc_route("deleting", rt); - retval = if_route(RTM_DELETE, rt, NULL); + retval = if_route(RTM_DELETE, rt); if (retval != 0 && errno != ENOENT && errno != ESRCH) syslog(LOG_ERR,"%s: if_delroute: %m", rt->iface->name); return retval; diff --git a/ipv6.c b/ipv6.c index 0aa3b694..8bf8ec35 100644 --- a/ipv6.c +++ b/ipv6.c @@ -1829,18 +1829,18 @@ 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, NULL)) == -1) + if ((retval = if_route6(RTM_ADD, nrt)) == -1) syslog(LOG_ERR, "if_route6 (ADD): %m"); - if (ort && if_route6(RTM_DELETE, ort, NULL) == -1 && + if (ort && if_route6(RTM_DELETE, ort) == -1 && errno != ESRCH) syslog(LOG_ERR, "if_route6 (DEL): %m"); return retval; #else /* No route metrics, we need to delete the old route before * adding the new one. */ - if (ort && if_route6(RTM_DELETE, ort, NULL) == -1 && errno != ESRCH) + if (ort && if_route6(RTM_DELETE, ort) == -1 && errno != ESRCH) syslog(LOG_ERR, "if_route6: %m"); - if (if_route6(RTM_ADD, nrt, NULL) == 0) + if (if_route6(RTM_ADD, nrt) == 0) return 0; syslog(LOG_ERR, "if_route6 (ADD): %m"); return -1; @@ -1853,7 +1853,7 @@ d_route(struct rt6 *rt) int retval; desc_route("deleting", rt); - retval = if_route6(RTM_DELETE, rt, NULL); + retval = if_route6(RTM_DELETE, rt); if (retval != 0 && errno != ENOENT && errno != ESRCH) syslog(LOG_ERR,"%s: if_delroute6: %m", rt->iface->name); return retval;