From 6e9535cc32f779dd527ec2c218a27aa0dec0724d Mon Sep 17 00:00:00 2001 From: Roy Marples Date: Thu, 14 Oct 2021 06:31:11 +0100 Subject: [PATCH] DHCP: Set INFORM state only when we are about to inform 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 | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/dhcp.c b/src/dhcp.c index 5c38bbeb..bfd40127 100644 --- a/src/dhcp.c +++ b/src/dhcp.c @@ -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; } -- 2.47.2