From bc9f9d93d4d6b8feb7b19235d7f0371480fc679d Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20H=C3=A4rdeman?= Date: Fri, 26 Sep 2025 19:22:34 +0200 Subject: [PATCH] dhcpv4: allow lease takeover (bugfix) MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Multiple MAC addresses are supported per static lease (congruent to dnsmasq) Request on different MAC frees any old assignments for a given lease. Signed-off-by: David Härdeman --- src/dhcpv4.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/dhcpv4.c b/src/dhcpv4.c index 1ae7254..5d7e08a 100644 --- a/src/dhcpv4.c +++ b/src/dhcpv4.c @@ -1111,6 +1111,20 @@ dhcpv4_lease(struct interface *iface, enum dhcpv4_msg msg, const uint8_t *mac, struct lease *l = config_find_lease_by_mac(mac); time_t now = odhcpd_time(); + /* + * If we found a static lease cfg, but no old assignment for this + * hwaddr, we need to clear out any old assignments given to other + * hwaddrs in order to take over the IP address. + */ + if (l && !a && (msg == DHCPV4_MSG_DISCOVER || msg == DHCPV4_MSG_REQUEST)) { + struct dhcp_assignment *c, *tmp; + + list_for_each_entry_safe(c, tmp, &l->assignments, lease_list) { + if (c->flags & OAF_DHCPV4 && c->flags & OAF_STATIC) + free_assignment(c); + } + } + if (l && a && a->lease != l) { free_assignment(a); a = NULL; -- 2.30.2