]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
Flags fake routes so we can change them when we renew our lease.
authorRoy Marples <roy@marples.name>
Wed, 26 Nov 2014 10:41:32 +0000 (10:41 +0000)
committerRoy Marples <roy@marples.name>
Wed, 26 Nov 2014 10:41:32 +0000 (10:41 +0000)
dhcp.c
ipv4.c
ipv4.h

diff --git a/dhcp.c b/dhcp.c
index 95b56a89dc4e5506fec036bd2a06c717dd025901..cd44eb4908ab3d737693ec280d948c812c00d251 100644 (file)
--- 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 23ddb502992477e521c401286e9b00589879512f..7646ee6be45a5a5d6d991db9951d4701c846efdb 100644 (file)
--- 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 97294ce4fcad42e89e3a4f015dd863799341e248..456d70edd3fe3d48877fdfada3179184c347e72e 100644 (file)
--- 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);