]> git.ipfire.org Git - people/ms/ipfire-2.x.git/commitdiff
unbound-dhcp-leases-bridge: Remove leases to keep the store up to date
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 10 May 2024 16:28:58 +0000 (17:28 +0100)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 10 May 2024 16:28:58 +0000 (17:28 +0100)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
config/unbound/unbound-dhcp-leases-bridge

index 40b6c294343ebedaba3d0184200e668f52d29be2..64a8eef21619bb172fe3eb1bdab158be3a7ccc4e 100644 (file)
@@ -236,6 +236,7 @@ class UnboundDHCPLeasesBridge(object):
 
                                # Remove the old lease first
                                self.unbound.remove_lease(old_lease)
+                               self._remove_lease(old_lease)
 
                        # Apply the lease
                        self.unbound.apply_lease(lease)
@@ -253,6 +254,7 @@ class UnboundDHCPLeasesBridge(object):
 
                        # Remove the lease
                        self.unbound.remove_lease(lease)
+                       self._remove_lease(lease)
 
                # Raise an error if the event is not supported
                else:
@@ -296,6 +298,9 @@ class UnboundDHCPLeasesBridge(object):
                elif not lease.active or lease.expired:
                        return
 
+               # Remove any previous leases
+               self._remove_lease(lease)
+
                # Store the lease
                self.leases.add(lease)
 
@@ -310,6 +315,12 @@ class UnboundDHCPLeasesBridge(object):
                        if lease.ipaddr == ipaddr:
                                return lease
 
+       def _remove_lease(self, lease):
+               try:
+                       self.leases.remove(lease)
+               except KeyError:
+                       pass
+
        def read_static_hosts(self):
                log.info("Reading static hosts from %s" % self.hosts_file)