]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
DHCP: Set INFORM state only when we are about to inform
authorRoy Marples <roy@marples.name>
Thu, 14 Oct 2021 05:31:11 +0000 (06:31 +0100)
committerRoy Marples <roy@marples.name>
Thu, 14 Oct 2021 05:31:11 +0000 (06:31 +0100)
As we may not find an address right away.
While here, tidy up and comment code about deriving the address
when none is specified for inform and static setups.

src/dhcp.c

index 5c38bbeb2fe55f88b1485a0f16109bbb1ff762a8..bfd4012739da8bdc5045139315ee60e710126364 100644 (file)
@@ -2039,7 +2039,6 @@ dhcp_finish_dad(struct interface *ifp, struct in_addr *ia)
                dhcp_inform(ifp);
 }
 
-
 static bool
 dhcp_addr_duplicated(struct interface *ifp, struct in_addr *ia)
 {
@@ -2573,7 +2572,6 @@ dhcp_inform(struct interface *ifp)
        state = D_STATE(ifp);
        ifo = ifp->options;
 
-       state->state = DHS_INFORM;
        free(state->offer);
        state->offer = NULL;
        state->offer_len = 0;
@@ -2614,6 +2612,7 @@ dhcp_inform(struct interface *ifp)
                }
        }
 
+       state->state = DHS_INFORM;
        state->addr = ia;
        state->offer_len = dhcp_message_new(&state->offer,
            &ia->addr, &ia->mask);
@@ -4269,37 +4268,38 @@ dhcp_handleifa(int cmd, struct ipv4_addr *ia, pid_t pid)
        }
 #endif
 
+       /* If we have requested a specific address, return now.
+        * The below code is only for when inform or static has been
+        * requested without a specific address. */
+       if (ifo->req_addr.s_addr != INADDR_ANY)
+               return ia;
+
+       /* Only inform if we are NOT in the inform state or bound. */
        if (ifo->options & DHCPCD_INFORM) {
                if (state->state != DHS_INFORM && state->state != DHS_BOUND)
                        dhcp_inform(ifp);
                return ia;
        }
 
+       /* Static and inform are mutually exclusive. If not static, return. */
        if (!(ifo->options & DHCPCD_STATIC))
                return ia;
-       if (ifo->req_addr.s_addr != INADDR_ANY)
-               return ia;
 
        free(state->old);
        state->old = state->new;
        state->new_len = dhcp_message_new(&state->new, &ia->addr, &ia->mask);
        if (state->new == NULL)
                return ia;
+
        if (ifp->flags & IFF_POINTOPOINT) {
                for (i = 1; i < 255; i++)
                        if (i != DHO_ROUTER && has_option_mask(ifo->dstmask,i))
                                dhcp_message_add_addr(state->new, i, ia->brd);
        }
+
        state->reason = "STATIC";
        rt_build(ifp->ctx, AF_INET);
        script_runreason(ifp, state->reason);
-       if (ifo->options & DHCPCD_INFORM) {
-               state->state = DHS_INFORM;
-               dhcp_new_xid(ifp);
-               state->lease.server.s_addr = INADDR_ANY;
-               state->addr = ia;
-               dhcp_inform(ifp);
-       }
 
        return ia;
 }