diff options
| author | David Härdeman | 2025-09-26 17:22:34 +0000 |
|---|---|---|
| committer | Ted Hess | 2025-09-28 01:18:14 +0000 |
| commit | bc9f9d93d4d6b8feb7b19235d7f0371480fc679d (patch) | |
| tree | 74350d4595783ffa19c90d391823ef7f1dc12e13 | |
| parent | b1547922257e484cb18e1719bdfc18f4789eb560 (diff) | |
| download | odhcpd-bc9f9d93d4d6b8feb7b19235d7f0371480fc679d.tar.gz | |
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 <david@hardeman.nu>
| -rw-r--r-- | src/dhcpv4.c | 14 |
1 files changed, 14 insertions, 0 deletions
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; |