From aa1cd7e88e8d60152a9c4d5eb5e2755d0814db66 Mon Sep 17 00:00:00 2001 From: Roy Marples Date: Wed, 11 Sep 2024 11:47:22 +0100 Subject: [PATCH] DHCP: Fix deleting expired leased addresses --- src/ipv4.c | 35 +++++++---------------------------- 1 file changed, 7 insertions(+), 28 deletions(-) diff --git a/src/ipv4.c b/src/ipv4.c index 6586f1dd..4cd24a7d 100644 --- a/src/ipv4.c +++ b/src/ipv4.c @@ -560,28 +560,6 @@ ipv4_deladdr(struct ipv4_addr *addr, int keeparp) return r; } -static int -delete_address(struct interface *ifp) -{ - int r; - struct if_options *ifo; - struct dhcp_state *state; - - state = D_STATE(ifp); - ifo = ifp->options; - /* The lease could have been added, but the address deleted - * by a 3rd party. */ - if (state->addr == NULL || - ifo->options & DHCPCD_INFORM || - (ifo->options & DHCPCD_STATIC && ifo->req_addr.s_addr == 0)) - return 0; -#ifdef ARP - arp_freeaddr(ifp, &state->addr->addr); -#endif - r = ipv4_deladdr(state->addr, 0); - return r; -} - struct ipv4_state * ipv4_getstate(struct interface *ifp) { @@ -766,7 +744,7 @@ ipv4_applyaddr(void *arg) struct dhcp_state *state = D_STATE(ifp); struct dhcp_lease *lease; struct if_options *ifo = ifp->options; - struct ipv4_addr *ia; + struct ipv4_addr *ia, *old_ia; if (state == NULL) return NULL; @@ -777,7 +755,7 @@ ipv4_applyaddr(void *arg) (DHCPCD_EXITING | DHCPCD_PERSISTENT)) { if (state->added) { - delete_address(ifp); + ipv4_deladdr(state->addr, 0); rt_build(ifp->ctx, AF_INET); #ifdef ARP /* Announce the preferred address to @@ -791,6 +769,9 @@ ipv4_applyaddr(void *arg) return NULL; } + /* ipv4_dadaddr() will overwrite this, we need it to purge later */ + old_ia = state->addr; + ia = ipv4_iffindaddr(ifp, &lease->addr, NULL); /* If the netmask or broadcast is different, re-add the addresss. * If IP addresses do not have lifetimes, there is a very real chance @@ -833,10 +814,8 @@ ipv4_applyaddr(void *arg) #endif /* Delete the old address if different */ - if (state->addr && - state->addr->addr.s_addr != lease->addr.s_addr && - ipv4_iffindaddr(ifp, &lease->addr, NULL)) - delete_address(ifp); + if (old_ia && old_ia->addr.s_addr != lease->addr.s_addr) + ipv4_deladdr(old_ia, 0); state->addr = ia; state->added = STATE_ADDED;