The script is rereading the ethernet and dhcp settings files for every lease in every update. Since dhcpd does not have a reload mechanism and is just restarted for settings changes, and so this bridge is restarted too, it seems fine just to read these at startup. --- unbound-dhcp-leases-bridge | 69 ++++++++++++++++++++------------------ 1 file changed, 36 insertions(+), 33 deletions(-)
diff --git unbound-dhcp-leases-bridge unbound-dhcp-leases-bridge index 6e22066..814cf0c 100644 --- unbound-dhcp-leases-bridge +++ unbound-dhcp-leases-bridge @@ -329,6 +329,42 @@ class FixLeases(object):
return leases
+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 + +def load_subnets(): + # Load ethernet settings + ethernet_settings = read_settings("/var/ipfire/ethernet/settings") + + # Load DHCP settings + dhcp_settings = 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 + + return subnets + +subnets = load_subnets()
class Lease(object): def __init__(self, ipaddr, properties): @@ -396,25 +432,6 @@ class Lease(object):
@property def domain(self): - # 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 in subnets: @@ -424,20 +441,6 @@ class Lease(object): # 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): if self.hostname: