]> git.ipfire.org Git - people/ms/ipfire-2.x.git/commitdiff
unbound-dhcp-leases-bridge: Find existing leases to remove all data
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 10 May 2024 16:20:30 +0000 (17:20 +0100)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 10 May 2024 16:20:30 +0000 (17:20 +0100)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
config/unbound/unbound-dhcp-leases-bridge

index ec878030696059eafa63eea370d40bb999083a00..43f006e9342970b09032d2de33d5e5256f8c1851 100644 (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)