From: Roy Marples Date: Thu, 26 Mar 2015 22:26:38 +0000 (+0000) Subject: If we have route metrics and the kernel claims our new route exists and X-Git-Tag: v6.8.1~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a5fc77c0849f2fbfb12ae463f17f04b6faea272c;p=thirdparty%2Fdhcpcd.git If we have route metrics and the kernel claims our new route exists and we have an old route to delete, we have to delete the old route and then add the new route. --- diff --git a/ipv4.c b/ipv4.c index 19520110..17d22669 100644 --- a/ipv4.c +++ b/ipv4.c @@ -370,9 +370,6 @@ ipv4_handlert(struct dhcpcd_ctx *ctx, int cmd, struct rt *rt) static int nc_route(struct rt *ort, struct rt *nrt) { -#ifdef HAVE_ROUTE_METRIC - int retval; -#endif /* Don't set default routes if not asked to */ if (nrt->dest.s_addr == 0 && @@ -405,21 +402,29 @@ 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)) == -1) - logger(nrt->iface->ctx, LOG_ERR, "if_route (ADD): %m"); - if (ort && if_route(RTM_DELETE, ort) == -1 && errno != ESRCH) - logger(nrt->iface->ctx, LOG_ERR, "if_route (DEL): %m"); - return retval; -#else + if (if_route(RTM_ADD, nrt) == 0) { + if (ort && if_route(RTM_DELETE, ort) == -1 && errno != ESRCH) + logger(nrt->iface->ctx, LOG_ERR, "if_route (DEL): %m"); + return 0; + } + + /* If the kernel claims the route exists we need to rip out the + * old one first. */ + if (errno != EEXIST || ort == NULL) + goto logerr; +#endif + /* No route metrics, we need to delete the old route before * adding the new one. */ if (ort && if_route(RTM_DELETE, ort) == -1 && errno != ESRCH) logger(nrt->iface->ctx, LOG_ERR, "if_route (DEL): %m"); if (if_route(RTM_ADD, nrt) == 0) return 0; +#ifdef HAVE_ROUTE_METRIC +logerr: +#endif logger(nrt->iface->ctx, LOG_ERR, "if_route (ADD): %m"); return -1; -#endif } static int diff --git a/ipv6.c b/ipv6.c index 2187c461..966b516c 100644 --- a/ipv6.c +++ b/ipv6.c @@ -1819,9 +1819,6 @@ ipv6_handlert(struct dhcpcd_ctx *ctx, int cmd, struct rt6 *rt) static int nc_route(struct rt6 *ort, struct rt6 *nrt) { -#ifdef HAVE_ROUTE_METRIC - int retval; -#endif /* Don't set default routes if not asked to */ if (IN6_IS_ADDR_UNSPECIFIED(&nrt->dest) && @@ -1846,22 +1843,30 @@ 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)) == -1) - logger(nrt->iface->ctx, LOG_ERR, "if_route6 (ADD): %m"); - if (ort && if_route6(RTM_DELETE, ort) == -1 && - errno != ESRCH) - logger(nrt->iface->ctx, LOG_ERR, "if_route6 (DEL): %m"); - return retval; -#else + if (if_route6(RTM_ADD, nrt) == 0) { + if (ort && if_route6(RTM_DELETE, ort) == -1 && + errno != ESRCH) + logger(nrt->iface->ctx, LOG_ERR, "if_route6 (DEL): %m"); + return 0; + } + + /* If the kernel claims the route exists we need to rip out the + * old one first. */ + if (errno != EEXIST || ort == NULL) + goto logerr; +#endif + /* No route metrics, we need to delete the old route before * adding the new one. */ if (ort && if_route6(RTM_DELETE, ort) == -1 && errno != ESRCH) logger(nrt->iface->ctx, LOG_ERR, "if_route6: %m"); if (if_route6(RTM_ADD, nrt) == 0) return 0; +#ifdef HAVE_ROUTE_METRIC +logerr: +#endif logger(nrt->iface->ctx, LOG_ERR, "if_route6 (ADD): %m"); return -1; -#endif } static int