]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
IPv4LL: Harden the noconfigure option.
authorRoy Marples <roy@marples.name>
Thu, 1 Aug 2024 22:57:39 +0000 (23:57 +0100)
committerRoy Marples <roy@marples.name>
Thu, 1 Aug 2024 22:57:39 +0000 (23:57 +0100)
This path should not be hit with the prior patch, but just in-case
harden the logic incase we don't have the address added.

src/ipv4ll.c

index 5b2c48bb14d9725db36dcdd5dabb378c4ee75ab0..1ea17c4366d768835d9b35e8efd94b53de9e3499 100644 (file)
@@ -230,11 +230,20 @@ ipv4ll_not_found(struct interface *ifp)
 #endif
                loginfox("%s: using IPv4LL address %s",
                  ifp->name, inet_ntoa(state->pickedaddr));
-       if (!(ifp->options->options & DHCPCD_CONFIGURE))
-               goto run;
        if (ia == NULL) {
-               if (ifp->ctx->options & DHCPCD_TEST)
-                       goto test;
+               if (ifp->ctx->options & DHCPCD_TEST) {
+                       ia = malloc(sizeof(*ia));
+                       if (ia == NULL) {
+                               logerr(__func__);
+                               return;
+                       }
+                       ia->iface = ifp;
+                       ia->addr = state->pickedaddr;
+               } else if (!(ifp->options->options & DHCPCD_CONFIGURE)) {
+                       logwarnx("%s: refusing to add IPv4LL address %s",
+                           ifp->name, inet_ntoa(state->pickedaddr));
+                       return;
+               }
                ia = ipv4_addaddr(ifp, &state->pickedaddr,
                    &inaddr_llmask, &inaddr_llbcast,
                    DHCP_INFINITE_LIFETIME, DHCP_INFINITE_LIFETIME);
@@ -247,7 +256,6 @@ ipv4ll_not_found(struct interface *ifp)
        logdebugx("%s: DAD completed for %s", ifp->name, ia->saddr);
 #endif
 
-test:
        state->addr = ia;
        state->down = false;
        if (ifp->ctx->options & DHCPCD_TEST) {
@@ -256,7 +264,7 @@ test:
                return;
        }
        rt_build(ifp->ctx, AF_INET);
-run:
+
        astate = arp_announceaddr(ifp->ctx, &ia->addr);
        if (astate != NULL)
                astate->announced_cb = ipv4ll_announced_arp;