From: Michael Tremer Date: Wed, 14 Sep 2016 15:29:53 +0000 (+0100) Subject: unbound+DHCP: Read correct DHCP domain name for lease X-Git-Tag: v2.19-core106~88 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=74a5ab67fef3726f1d47bee6181423cd9d18a2c1;p=ipfire-2.x.git unbound+DHCP: Read correct DHCP domain name for lease Signed-off-by: Michael Tremer --- diff --git a/config/unbound/unbound-dhcp-leases-bridge b/config/unbound/unbound-dhcp-leases-bridge index a3e16616ef..f192179ad5 100644 --- a/config/unbound/unbound-dhcp-leases-bridge +++ b/config/unbound/unbound-dhcp-leases-bridge @@ -22,6 +22,7 @@ import argparse import datetime import daemon +import ipaddress import logging import logging.handlers import re @@ -220,7 +221,47 @@ class Lease(object): @property def domain(self): - return "local" # XXX + # Load ethernet settings + ethernet_settings = self.read_settings("/var/ipfire/ethernet/settings") + + # Load DHCP settings + dhcp_settings = self.read_settings("/var/ipfire/dhcp/settings") + + subnets = {} + for zone in ("GREEN", "BLUE"): + if not dhcp_settings.get("ENABLE_%s" % zone) == "on": + continue + + netaddr = ethernet_settings.get("%s_NETADDRESS" % zone) + submask = ethernet_settings.get("%s_NETMASK" % zone) + + subnet = ipaddress.ip_network("%s/%s" % (netaddr, submask)) + domain = dhcp_settings.get("DOMAIN_NAME_%s" % zone) + + subnets[subnet] = domain + + address = ipaddress.ip_address(self.ipaddr) + + for subnet, domain in subnets.items(): + if address in subnet: + return domain + + # Fall back to localdomain if no match could be found + return "localdomain" + + @staticmethod + def read_settings(filename): + settings = {} + + with open(filename) as f: + for line in f.readlines(): + # Remove line-breaks + line = line.rstrip() + + k, v = line.split("=", 1) + settings[k] = v + + return settings @property def fqdn(self):