summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Breunig <christian@breunig.cc>2024-01-11 06:47:28 +0100
committerGitHub <noreply@github.com>2024-01-11 06:47:28 +0100
commitd0dcbfa475fae4817b0bc4d0718ecf65eae85270 (patch)
tree8b9ed5ad8e9043c1651189b39dc9307c1e6e7adf
parent68bacdc20c10566671ce809e9668ca27666bca22 (diff)
parentb68def8d50688eb429328892437647860f9fc6c1 (diff)
downloadvyos-1x-d0dcbfa475fae4817b0bc4d0718ecf65eae85270.tar.gz
vyos-1x-d0dcbfa475fae4817b0bc4d0718ecf65eae85270.zip
Merge pull request #2794 from sarthurdev/T5787_sagitta
dhcp: T5787: Prevent duplicate IP addresses on static mappings (backport)
-rwxr-xr-xsmoketest/scripts/cli/test_service_dhcp-server.py7
-rwxr-xr-xsrc/conf_mode/service_dhcp-server.py6
2 files changed, 13 insertions, 0 deletions
diff --git a/smoketest/scripts/cli/test_service_dhcp-server.py b/smoketest/scripts/cli/test_service_dhcp-server.py
index 093e43494..91ae901cd 100755
--- a/smoketest/scripts/cli/test_service_dhcp-server.py
+++ b/smoketest/scripts/cli/test_service_dhcp-server.py
@@ -202,6 +202,13 @@ class TestServiceDHCPServer(VyOSUnitTestSHIM.TestCase):
self.cli_set(pool + ['static-mapping', client, 'ip-address', inc_ip(subnet, client_base)])
client_base += 1
+ # cannot have mappings with duplicate IP addresses
+ with self.assertRaises(ConfigSessionError):
+ self.cli_set(pool + ['static-mapping', 'dupe1', 'mac', '00:50:00:00:00:01'])
+ self.cli_set(pool + ['static-mapping', 'dupe1', 'ip-address', inc_ip(subnet, 10)])
+ self.cli_commit()
+ self.cli_delete(pool + ['static-mapping', 'dupe1'])
+
# commit changes
self.cli_commit()
diff --git a/src/conf_mode/service_dhcp-server.py b/src/conf_mode/service_dhcp-server.py
index ac7d95632..8d849b1e6 100755
--- a/src/conf_mode/service_dhcp-server.py
+++ b/src/conf_mode/service_dhcp-server.py
@@ -214,6 +214,7 @@ def verify(dhcp):
if 'static_mapping' in subnet_config:
# Static mappings require just a MAC address (will use an IP from the dynamic pool if IP is not set)
+ used_ips = []
for mapping, mapping_config in subnet_config['static_mapping'].items():
if 'ip_address' in mapping_config:
if ip_address(mapping_config['ip_address']) not in ip_network(subnet):
@@ -224,6 +225,11 @@ def verify(dhcp):
raise ConfigError(f'MAC address required for static mapping "{mapping}"\n' \
f'within shared-network "{network}, {subnet}"!')
+ if mapping_config['ip_address'] in used_ips:
+ raise ConfigError(f'Configured IP address for static mapping "{mapping}" exists on another static mapping')
+
+ used_ips.append(mapping_config['ip_address'])
+
# There must be one subnet connected to a listen interface.
# This only counts if the network itself is not disabled!
if 'disable' not in network_config: