From: Roy Marples Date: Wed, 26 Nov 2014 10:41:32 +0000 (+0000) Subject: Flags fake routes so we can change them when we renew our lease. X-Git-Tag: v6.6.3~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=55b0a9ce4a876f74fc4eda50be9ccb37bea5569f;p=thirdparty%2Fdhcpcd.git Flags fake routes so we can change them when we renew our lease. --- diff --git a/dhcp.c b/dhcp.c index 95b56a89..cd44eb49 100644 --- a/dhcp.c +++ b/dhcp.c @@ -3141,6 +3141,7 @@ dhcp_start1(void *arg) state->addr = state->lease.addr; state->net = state->lease.net; state->added |= STATE_ADDED | STATE_FAKE; + ipv4_sortinterfaces(ifp->ctx); ipv4_buildroutes(ifp->ctx); } else syslog(LOG_ERR, "%s: %m", __func__); diff --git a/ipv4.c b/ipv4.c index 23ddb502..7646ee6b 100644 --- a/ipv4.c +++ b/ipv4.c @@ -230,6 +230,11 @@ ipv4_ifcmp(const struct interface *si, const struct interface *ti) return -1; if (!sis->new && tis->new) return 1; + /* Always prefer proper leases */ + if (!(sis->added & STATE_FAKE) && (sis->added & STATE_FAKE)) + return -1; + if ((sis->added & STATE_FAKE) && !(sis->added & STATE_FAKE)) + return 1; /* If we are either, they neither have a lease, or they both have. * We need to check for IPv4LL and make it non-preferred. */ if (sis->new && tis->new) { @@ -625,10 +630,8 @@ ipv4_buildroutes(struct dhcpcd_ctx *ctx) if ((or = find_route(ctx->ipv4_routes, rt, NULL))) { if (state->added & STATE_FAKE) continue; - ostate = D_CSTATE(or->iface); - if (ostate->added & STATE_FAKE) - goto remroute; - if (or->iface != ifp || + if (or->flags & STATE_FAKE || + or->iface != ifp || or->src.s_addr != state->addr.s_addr || rt->gate.s_addr != or->gate.s_addr || rt->metric != or->metric) @@ -636,7 +639,6 @@ ipv4_buildroutes(struct dhcpcd_ctx *ctx) if (c_route(or, rt) != 0) continue; } -remroute: TAILQ_REMOVE(ctx->ipv4_routes, or, next); free(or); } else { @@ -644,6 +646,9 @@ remroute: n_route(rt) != 0) continue; } + rt->flags = STATE_ADDED; + if (state->added & STATE_FAKE) + rt->flags |= STATE_FAKE; TAILQ_REMOVE(dnr, rt, next); TAILQ_INSERT_TAIL(nrs, rt, next); } diff --git a/ipv4.h b/ipv4.h index 97294ce4..456d70ed 100644 --- a/ipv4.h +++ b/ipv4.h @@ -38,6 +38,7 @@ struct rt { const struct interface *iface; unsigned int metric; struct in_addr src; + uint8_t flags; }; TAILQ_HEAD(rt_head, rt);