Browse Source

dhcp-server: only add dhcp range if te_prefix is subprefix of site_prefix

Karsten Böddeker 7 years ago
parent
commit
17e84b204f
2 changed files with 9 additions and 2 deletions
  1. 5 0
      _modules/ffho_net.py
  2. 4 2
      dhcp-server/dhcpd.conf

+ 5 - 0
_modules/ffho_net.py

@@ -1151,3 +1151,8 @@ def cidr_to_dotted_mask (prefix):
 	from ipcalc import Network
 
 	return str (Network (prefix).netmask ())
+
+def is_subprefix (prefix, subprefix):
+	from ipcalc import Network
+
+	return subprefix in Network(prefix)

+ 4 - 2
dhcp-server/dhcpd.conf

@@ -33,9 +33,11 @@ subnet {{ site_prefix.split ('/')[0] }} netmask {{ salt['ffho_net.cidr_to_dotted
 
 		# Range(s) of IPs to lease to clients
   {%- for prefix in te_prefixes|sort %}
-    {%- set prefix_config = te_prefixes.get (prefix) %}
-    {%- if 'dhcp_range' in prefix_config %}
+    {%- if salt['ffho_net.is_subprefix'] (site_prefix, prefix) %}
+      {%- set prefix_config = te_prefixes.get (prefix) %}
+      {%- if 'dhcp_range' in prefix_config %}
 		range {{ prefix_config.get ('dhcp_range') }};
+      {%- endif %}
     {%- endif %}
   {%- endfor %}
 	}