From: Roy Marples Date: Wed, 23 Nov 2011 20:30:24 +0000 (+0000) Subject: Store the assigned metric against the route. X-Git-Tag: v5.5.0~17 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cef1585bc40f604264a6bd2314fa785cd7e7aa2b;p=thirdparty%2Fdhcpcd.git Store the assigned metric against the route. This allows us to change the route metric via dhcpcd -n --metric $val $if --- diff --git a/configure.c b/configure.c index 2003268f..f7e72026 100644 --- a/configure.c +++ b/configure.c @@ -63,7 +63,6 @@ static struct rt *routes; - static int exec_script(char *const *argv, char *const *env) { @@ -471,10 +470,8 @@ c_route(struct rt *ort, struct rt *nrt, const struct interface *iface) /* We delete and add the route so that we can change metric. * This also has the nice side effect of flushing ARP entries so * we don't have to do that manually. */ - del_route(ort->iface, &ort->dest, &ort->net, &ort->gate, - ort->iface->metric); - if (!add_route(iface, &nrt->dest, &nrt->net, &nrt->gate, - iface->metric)) + del_route(ort->iface, &ort->dest, &ort->net, &ort->gate, ort->metric); + if (!add_route(iface, &nrt->dest, &nrt->net, &nrt->gate, nrt->metric)) return 0; syslog(LOG_ERR, "%s: add_route: %m", iface->name); return -1; @@ -661,6 +658,7 @@ build_routes(void) dnr = add_destination_route(dnr, ifp); for (rt = dnr; rt && (rtn = rt->next, 1); lrt = rt, rt = rtn) { rt->iface = ifp; + rt->metric = ifp->metric; /* Is this route already in our table? */ if ((find_route(nrs, rt, NULL, NULL)) != NULL) continue; @@ -669,7 +667,8 @@ build_routes(void) if ((or = find_route(routes, rt, &rtl, NULL))) { if (or->iface != ifp || or->src.s_addr != ifp->addr.s_addr || - rt->gate.s_addr != or->gate.s_addr) + rt->gate.s_addr != or->gate.s_addr || + rt->metric != or->metric) { if (c_route(or, rt, ifp) != 0) continue; diff --git a/net.h b/net.h index 814cbeb7..9d83e213 100644 --- a/net.h +++ b/net.h @@ -84,6 +84,7 @@ struct rt { struct in_addr net; struct in_addr gate; const struct interface *iface; + int metric; struct in_addr src; struct rt *next; };