Mercurial > hg > dhcpcd
changeset 3050:c9230341ee79 draft
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.
| author | Roy Marples <roy@marples.name> |
|---|---|
| date | Thu, 26 Mar 2015 22:26:38 +0000 |
| parents | 9191ae3744eb |
| children | 90ffbe9c2cfd |
| files | ipv4.c ipv6.c |
| diffstat | 2 files changed, 31 insertions(+), 21 deletions(-) [+] |
line wrap: on
line diff
--- a/ipv4.c Thu Mar 26 22:25:26 2015 +0000 +++ b/ipv4.c Thu Mar 26 22:26:38 2015 +0000 @@ -370,9 +370,6 @@ 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 @@ #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
--- a/ipv6.c Thu Mar 26 22:25:26 2015 +0000 +++ b/ipv6.c Thu Mar 26 22:26:38 2015 +0000 @@ -1819,9 +1819,6 @@ 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 @@ #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
