From: Michael Tremer <michael.tremer@ipfire.org>
To: development@lists.ipfire.org
Subject: [PATCH 3/4] unbound-dhcp-leases-bridge: Don't overwrite static leases
Date: Mon, 21 Oct 2024 16:38:48 +0000 [thread overview]
Message-ID: <20241021163849.1265183-3-michael.tremer@ipfire.org> (raw)
In-Reply-To: <20241021163849.1265183-1-michael.tremer@ipfire.org>
[-- Attachment #1: Type: text/plain, Size: 1745 bytes --]
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(a)ipfire.org>
---
config/unbound/unbound-dhcp-leases-bridge | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/config/unbound/unbound-dhcp-leases-bridge b/config/unbound/unbound-dhcp-leases-bridge
index 2cbdaa004..66ea28054 100644
--- a/config/unbound/unbound-dhcp-leases-bridge
+++ b/config/unbound/unbound-dhcp-leases-bridge
@@ -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)
--
2.39.5
next prev parent reply other threads:[~2024-10-21 16:38 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-21 16:38 [PATCH 1/4] unbound-dhcp-leases-bridge: Don't export expired leases to Unbound Michael Tremer
2024-10-21 16:38 ` [PATCH 2/4] unbound-dhcp-leases-bridge: Fix typo Michael Tremer
2024-10-21 16:44 ` Bernhard Bitsch
2024-10-21 16:38 ` Michael Tremer [this message]
2024-10-21 16:47 ` [PATCH 3/4] unbound-dhcp-leases-bridge: Don't overwrite static leases Bernhard Bitsch
2024-10-21 16:38 ` [PATCH 4/4] unbound-dhcp-leases-bridge: Fix expiry check on leases Michael Tremer
2024-10-21 16:42 ` [PATCH 1/4] unbound-dhcp-leases-bridge: Don't export expired leases to Unbound Bernhard Bitsch
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20241021163849.1265183-3-michael.tremer@ipfire.org \
--to=michael.tremer@ipfire.org \
--cc=development@lists.ipfire.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox