mirror of
https://github.com/vincentmli/bpfire.git
synced 2026-04-09 18:45:54 +02:00
unbound: Correctly format PTR records
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
This commit is contained in:
@@ -49,6 +49,20 @@ def setup_logging(loglevel=logging.INFO):
|
||||
|
||||
log = logging.getLogger("dhcp")
|
||||
|
||||
def ip_address_to_reverse_pointer(address):
|
||||
parts = address.split(".")
|
||||
parts.reverse()
|
||||
|
||||
return "%s.in-addr.arpa" % ".".join(parts)
|
||||
|
||||
def reverse_pointer_to_ip_address(rr):
|
||||
parts = rr.split(".")
|
||||
|
||||
# Only take IP address part
|
||||
parts = reversed(parts[0:4])
|
||||
|
||||
return ".".join(parts)
|
||||
|
||||
class UnboundDHCPLeasesBridge(object):
|
||||
def __init__(self, dhcp_leases_file, unbound_leases_file):
|
||||
self.leases_file = dhcp_leases_file
|
||||
@@ -301,7 +315,8 @@ class Lease(object):
|
||||
(self.fqdn, "%s" % LOCAL_TTL, "IN A", self.ipaddr),
|
||||
|
||||
# Reverse record
|
||||
(self.ipaddr, "%s" % LOCAL_TTL, "IN PTR", self.fqdn),
|
||||
(ip_address_to_reverse_pointer(self.ipaddr), "%s" % LOCAL_TTL,
|
||||
"IN PTR", self.fqdn),
|
||||
]
|
||||
|
||||
|
||||
@@ -333,7 +348,7 @@ class UnboundConfigWriter(object):
|
||||
if record_type == "A":
|
||||
ret[hostname] = content
|
||||
elif record_type == "PTR":
|
||||
ret[content] = hostname
|
||||
ret[content] = reverse_pointer_to_ip_address(hostname)
|
||||
|
||||
return ret
|
||||
|
||||
|
||||
Reference in New Issue
Block a user