From: David Härdeman Date: Fri, 26 Sep 2025 17:22:34 +0000 (+0200) Subject: dhcpv4: allow lease takeover (bugfix) X-Git-Url: http://git.openwrt.org/?a=commitdiff_plain;h=bc9f9d93d4d6b8feb7b19235d7f0371480fc679d;p=project%2Fodhcpd.git dhcpv4: allow lease takeover (bugfix) 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 --- 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;