]> git.ipfire.org Git - ipfire-2.x.git/commitdiff
unbound-dhcp-leases-bridge: Don't overwrite static leases
authorMichael Tremer <michael.tremer@ipfire.org>
Mon, 21 Oct 2024 16:38:48 +0000 (16:38 +0000)
committerArne Fitzenreiter <arne_f@ipfire.org>
Tue, 5 Nov 2024 08:12:17 +0000 (09:12 +0100)
When we import all static leases, their remark will be used as hostname
(because WTF?) and might be overwritten if the device is not sending any
or even the same hostname.

This patch avoids that static leases will be modified.

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
Reviewed-by: Bernhard Bitsch <bbitsch@ipfire.org>
Signed-off-by: Arne Fitzenreiter <arne_f@ipfire.org>
config/unbound/unbound-dhcp-leases-bridge

index 2cbdaa004d1dc55e86c887dd622bc35335260505..66ea2805486575876f76be158dedaa1b34f2ccbf 100644 (file)
@@ -216,6 +216,11 @@ class UnboundDHCPLeasesBridge(object):
                        # Find the old lease
                        old_lease = self._find_lease(address)
 
+                       # Don't update fixed leases as they might clear the hostname
+                       if old_lease and old_lease.fixed:
+                               log.debug("Won't update fixed lease %s" % old_lease)
+                               return
+
                        # Create a new lease
                        lease = Lease(address, {
                                "client-hostname" : name,
@@ -581,19 +586,20 @@ class FixLeases(object):
                                        "client-hostname" : hostname,
                                        "starts"          : now.strftime("%w %Y/%m/%d %H:%M:%S"),
                                        "ends"            : "never",
-                               })
+                               }, fixed=True)
                                leases.append(l)
 
                return leases
 
 
 class Lease(object):
-       def __init__(self, ipaddr, properties):
+       def __init__(self, ipaddr, properties, fixed=False):
                if not isinstance(ipaddr, ipaddress.IPv4Address):
                        ipaddr = ipaddress.IPv4Address(ipaddr)
 
                self.ipaddr = ipaddr
                self._properties = properties
+               self.fixed = fixed
 
        def __repr__(self):
                return "<%s for %s (%s)>" % (self.__class__.__name__, self.ipaddr, self.hostname)