unbound-dhcp-leases-bridge: Find existing leases to remove all data

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
This commit is contained in:
Michael Tremer
2024-05-10 17:20:30 +01:00
parent 0e1ae247e7
commit 92e8358d46

View File

@@ -231,8 +231,12 @@ class UnboundDHCPLeasesBridge(object):
elif event in ("release", "expiry"):
address = message.get("ADDRESS")
# Create a new lease
lease = Lease(address, {})
# Find the lease
lease = self._find_lease(address)
if not lease:
log.warning("Could not find lease for %s" % address)
return
# Remove the lease
self.unbound.remove_lease(lease)
@@ -282,6 +286,17 @@ class UnboundDHCPLeasesBridge(object):
# Store the lease
self.leases.add(lease)
def _find_lease(self, ipaddr):
"""
Returns the lease with the specified IP address
"""
if not isinstance(ipaddr, ipaddress.IPv4Address):
ipaddr = ipaddress.IPv4Address(ipaddr)
for lease in self.leases:
if lease.ipaddr == ipaddr:
return lease
def read_static_hosts(self):
log.info("Reading static hosts from %s" % self.hosts_file)