Skip to content

Commit

Permalink
DHCP: Fix deleting expired leased addresses
Browse files Browse the repository at this point in the history
  • Loading branch information
rsmarples committed Sep 11, 2024
1 parent d0fef9f commit aa1cd7e
Showing 1 changed file with 7 additions and 28 deletions.
35 changes: 7 additions & 28 deletions src/ipv4.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit aa1cd7e

Please sign in to comment.