]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
For IPv4, override any existing address when adding it.
authorRoy Marples <roy@marples.name>
Thu, 22 Mar 2018 18:22:04 +0000 (18:22 +0000)
committerRoy Marples <roy@marples.name>
Thu, 22 Mar 2018 18:22:04 +0000 (18:22 +0000)
When deleting stale addresses, report our pid as the deletor.

src/ipv4.c
src/ipv6.c

index 4ba13d53b8e9e57510666e826c9f9245f89e063e..d40b3f632566f2e72b9cf8a35f08c7d7fec9efc0 100644 (file)
@@ -589,6 +589,7 @@ ipv4_addaddr(struct interface *ifp, const struct in_addr *addr,
 {
        struct ipv4_state *state;
        struct ipv4_addr *ia;
+       bool is_new = false;
 #ifdef ALIAS_ADDR
        int replaced, blank;
        struct ipv4_addr *replaced_ia;
@@ -607,18 +608,23 @@ ipv4_addaddr(struct interface *ifp, const struct in_addr *addr,
                }
        }
 
-       if ((ia = malloc(sizeof(*ia))) == NULL) {
-               logerr(__func__);
-               return NULL;
+       ia = ipv4_iffindaddr(ifp, addr, NULL);
+       if (ia == NULL) {
+               ia = malloc(sizeof(*ia));
+               if (ia == NULL) {
+                       logerr(__func__);
+                       return NULL;
+               }
+               ia->iface = ifp;
+               ia->addr = *addr;
+#ifdef IN_IFF_TENTATIVE
+               ia->addr_flags = IN_IFF_TENTATIVE;
+#endif
+               is_new = true;
        }
 
-       ia->iface = ifp;
-       ia->addr = *addr;
        ia->mask = *mask;
        ia->brd = *bcast;
-#ifdef IN_IFF_TENTATIVE
-       ia->addr_flags = IN_IFF_TENTATIVE;
-#endif
        snprintf(ia->saddr, sizeof(ia->saddr), "%s/%d",
            inet_ntoa(*addr), inet_ntocidr(*mask));
 
@@ -650,7 +656,8 @@ ipv4_addaddr(struct interface *ifp, const struct in_addr *addr,
        }
 #endif
 
-       TAILQ_INSERT_TAIL(&state->addrs, ia, next);
+       if (is_new)
+               TAILQ_INSERT_TAIL(&state->addrs, ia, next);
        return ia;
 }
 
@@ -787,10 +794,11 @@ ipv4_deletestaleaddrs(struct interface *ifp)
                return;
 
        TAILQ_FOREACH_SAFE(ia, &state->addrs, next, ia1) {
-               if (ia->flags & IPV4_AF_STALE)
-                       ipv4_handleifa(ifp->ctx, RTM_DELADDR,
-                           ifp->ctx->ifaces, ifp->name,
-                           &ia->addr, &ia->mask, &ia->brd, 0, 0);
+               if (!(ia->flags & IPV4_AF_STALE))
+                       continue;
+               ipv4_handleifa(ifp->ctx, RTM_DELADDR,
+                   ifp->ctx->ifaces, ifp->name,
+                   &ia->addr, &ia->mask, &ia->brd, 0, getpid());
        }
 }
 
@@ -805,6 +813,12 @@ ipv4_handleifa(struct dhcpcd_ctx *ctx,
        struct ipv4_addr *ia;
        bool ia_is_new;
 
+#if 0
+       logdebugx("%s: %s %s/%d %d", ifname,
+           cmd == RTM_NEWADDR ? "RTM_NEWADDR" : cmd == RTM_DELADDR ? "RTM_DELADDR" : "???",
+           inet_ntoa(*addr), inet_ntocidr(*mask), addrflags);
+#endif
+
        if (ifs == NULL)
                ifs = ctx->ifaces;
        if (ifs == NULL) {
index b88757afbf0e49f185ee2074cbb74b75b09cddb2..82cf71b656e217103223ddf604b56d2122b55cd8 100644 (file)
@@ -2124,7 +2124,7 @@ ipv6_deletestaleaddrs(struct interface *ifp)
                if (ia->flags & IPV6_AF_STALE)
                        ipv6_handleifa(ifp->ctx, RTM_DELADDR,
                            ifp->ctx->ifaces, ifp->name,
-                           &ia->addr, ia->prefix_len, 0, 0);
+                           &ia->addr, ia->prefix_len, 0, getpid());
        }
 }