]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
IPv6: DUPLICATED could be announced by RTM_DELADDR
authorRoy Marples <roy@marples.name>
Fri, 21 Jun 2024 11:58:38 +0000 (12:58 +0100)
committerRoy Marples <roy@marples.name>
Fri, 21 Jun 2024 12:03:06 +0000 (13:03 +0100)
This at least is true on Linux when addresses are not permanent.
As such, update address flags on all paths and run DAD hooks
even for address deletions.

This helps to give reason to the messages that pid 0 has deleted
your newly added address.

src/ipv4.c
src/ipv6.c

index 21063e058aaaebe91a1fd0ab7ce165802019f844..ada821b95c882f8fa4d5b3e37eb5604fca1c1293 100644 (file)
@@ -967,6 +967,7 @@ ipv4_handleifa(struct dhcpcd_ctx *ctx,
                if (mask->s_addr != INADDR_ANY &&
                    mask->s_addr != ia->mask.s_addr)
                        return;
+               ia->addr_flags = addrflags;
                TAILQ_REMOVE(&state->addrs, ia, next);
                break;
        default:
index ce985d4ec5b154bc17a78907dc0f51784bf59001..9fea96b2c01886a82c22fb19eae8cfcd9a4860ed 100644 (file)
@@ -1198,8 +1198,10 @@ ipv6_handleifa(struct dhcpcd_ctx *ctx,
        anyglobal = ipv6_anyglobal(ifp) != NULL;
 
        TAILQ_FOREACH(ia, &state->addrs, next) {
-               if (IN6_ARE_ADDR_EQUAL(&ia->addr, addr))
+               if (IN6_ARE_ADDR_EQUAL(&ia->addr, addr)) {
+                       ia->addr_flags = addrflags;
                        break;
+               }
        }
 
        switch (cmd) {
@@ -1244,49 +1246,50 @@ ipv6_handleifa(struct dhcpcd_ctx *ctx,
                         * generate a new temporary address on
                         * restart. */
                        ia->acquired = ia->created;
+                       ia->addr_flags = addrflags;
                        TAILQ_INSERT_TAIL(&state->addrs, ia, next);
                }
-               ia->addr_flags = addrflags;
                ia->flags &= ~IPV6_AF_STALE;
 #ifdef IPV6_MANAGETEMPADDR
                if (ia->addr_flags & IN6_IFF_TEMPORARY)
                        ia->flags |= IPV6_AF_TEMPORARY;
 #endif
-               if (IN6_IS_ADDR_LINKLOCAL(&ia->addr) || ia->dadcallback) {
-#ifdef IPV6_POLLADDRFLAG
-                       if (ia->addr_flags & IN6_IFF_TENTATIVE) {
-                               eloop_timeout_add_msec(
-                                   ia->iface->ctx->eloop,
-                                   RETRANS_TIMER / 2, ipv6_checkaddrflags, ia);
-                               break;
-                       }
-#endif
 
-                       if (ia->dadcallback)
-                               ia->dadcallback(ia);
-
-                       if (IN6_IS_ADDR_LINKLOCAL(&ia->addr) &&
-                           !(ia->addr_flags & IN6_IFF_NOTUSEABLE))
-                       {
-                               /* Now run any callbacks.
-                                * Typically IPv6RS or DHCPv6 */
-                               while ((cb =
-                                   TAILQ_FIRST(&state->ll_callbacks)))
-                               {
-                                       TAILQ_REMOVE(
-                                           &state->ll_callbacks,
-                                           cb, next);
-                                       cb->callback(cb->arg);
-                                       free(cb);
-                               }
-                       }
+#ifdef IPV6_POLLADDRFLAG
+               if ((IN6_IS_ADDR_LINKLOCAL(&ia->addr) || ia->dadcallback) &&
+                   ia->addr_flags & IN6_IFF_TENTATIVE)
+               {
+                       eloop_timeout_add_msec(
+                           ia->iface->ctx->eloop,
+                           RETRANS_TIMER / 2, ipv6_checkaddrflags, ia);
                }
                break;
+#endif
+       default:
+               return;
        }
 
        if (ia == NULL)
                return;
 
+       if (ia->dadcallback && ((ia->addr_flags &
+           (IN6_IFF_DETACHED | IN6_IFF_TENTATIVE)) == 0 ||
+           ia->addr_flags & IN6_IFF_DUPLICATED))
+               ia->dadcallback(ia);
+
+       if (IN6_IS_ADDR_LINKLOCAL(&ia->addr) &&
+           !(ia->addr_flags & IN6_IFF_NOTUSEABLE))
+       {
+               /* Now run any callbacks.
+                * Typically IPv6RS or DHCPv6 */
+               while ((cb = TAILQ_FIRST(&state->ll_callbacks)))
+               {
+                       TAILQ_REMOVE(&state->ll_callbacks, cb, next);
+                       cb->callback(cb->arg);
+                       free(cb);
+               }
+       }
+
        ctx->options &= ~DHCPCD_RTBUILD;
        ipv6nd_handleifa(cmd, ia, pid);
 #ifdef DHCP6
@@ -1883,10 +1886,13 @@ ipv6_handleifa_addrs(int cmd,
     struct ipv6_addrhead *addrs, const struct ipv6_addr *addr, pid_t pid)
 {
        struct ipv6_addr *ia, *ian;
-       uint8_t found, alldadcompleted;
+       int found = 0, alldadcompleted = 1;
+
+       if (cmd != RTM_NEWADDR && cmd != RTM_DELADDR) {
+               errno = EINVAL;
+               return -1;
+       }
 
-       alldadcompleted = 1;
-       found = 0;
        TAILQ_FOREACH_SAFE(ia, addrs, next, ian) {
                if (!IN6_ARE_ADDR_EQUAL(&addr->addr, &ia->addr)) {
                        if (ia->flags & IPV6_AF_ADDED &&
@@ -1894,8 +1900,25 @@ ipv6_handleifa_addrs(int cmd,
                                alldadcompleted = 0;
                        continue;
                }
-               switch (cmd) {
-               case RTM_DELADDR:
+
+               ia->addr_flags = addr->addr_flags;
+
+               /* Check DAD.
+                * On Linux we can get IN6_IFF_DUPLICATED via RTM_DELADDR. */
+               if (((ia->addr_flags &
+                   (IN6_IFF_DETACHED | IN6_IFF_TENTATIVE)) == 0 ||
+                   ia->addr_flags & IN6_IFF_DUPLICATED) &&
+                   (ia->flags & IPV6_AF_DADCOMPLETED) == 0)
+               {
+                       found++;
+                       if (ia->dadcallback)
+                               ia->dadcallback(ia);
+                       /* We need to set this here in-case the
+                        * dadcallback function checks it */
+                       ia->flags |= IPV6_AF_DADCOMPLETED;
+               }
+
+               if (cmd == RTM_DELADDR) {
                        if (ia->flags & IPV6_AF_ADDED) {
                                logwarnx("%s: pid %d deleted address %s",
                                    ia->iface->name, pid, ia->saddr);
@@ -1906,22 +1929,6 @@ ipv6_handleifa_addrs(int cmd,
                                TAILQ_REMOVE(addrs, ia, next);
                                ipv6_freeaddr(ia);
                        }
-                       break;
-               case RTM_NEWADDR:
-                       ia->addr_flags = addr->addr_flags;
-                       /* Safety - ignore tentative announcements */
-                       if (ia->addr_flags &
-                           (IN6_IFF_DETACHED | IN6_IFF_TENTATIVE))
-                               break;
-                       if ((ia->flags & IPV6_AF_DADCOMPLETED) == 0) {
-                               found++;
-                               if (ia->dadcallback)
-                                       ia->dadcallback(ia);
-                               /* We need to set this here in-case the
-                                * dadcallback function checks it */
-                               ia->flags |= IPV6_AF_DADCOMPLETED;
-                       }
-                       break;
                }
        }