summaryrefslogtreecommitdiff
path: root/src/conf_mode
diff options
context:
space:
mode:
authorChristian Breunig <christian@breunig.cc>2024-01-19 20:11:50 +0100
committerGitHub <noreply@github.com>2024-01-19 20:11:50 +0100
commit9bde591e387ff64ce300f966c758195e87f618a6 (patch)
treeb65dfbad41fe5a1287666ef383afea3af7d12fa6 /src/conf_mode
parent5c6d4b17d90cdfdf1541d81fb081575c54b168a7 (diff)
parentc7b6484dc975cbbe9c916a8d51f5b87728625502 (diff)
downloadvyos-1x-9bde591e387ff64ce300f966c758195e87f618a6.tar.gz
vyos-1x-9bde591e387ff64ce300f966c758195e87f618a6.zip
Merge pull request #2853 from c-po/sagitta
dhcp: T5952: validate duplicate MAC and IP address in static-mappings incl. smoketests
Diffstat (limited to 'src/conf_mode')
-rwxr-xr-xsrc/conf_mode/service_dhcp-server.py11
1 files changed, 8 insertions, 3 deletions
diff --git a/src/conf_mode/service_dhcp-server.py b/src/conf_mode/service_dhcp-server.py
index 8d849b1e6..6eed2129b 100755
--- a/src/conf_mode/service_dhcp-server.py
+++ b/src/conf_mode/service_dhcp-server.py
@@ -1,6 +1,6 @@
#!/usr/bin/env python3
#
-# Copyright (C) 2018-2023 VyOS maintainers and contributors
+# Copyright (C) 2018-2024 VyOS maintainers and contributors
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 or later as
@@ -215,6 +215,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 = []
+ used_mac = []
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):
@@ -226,10 +227,14 @@ def verify(dhcp):
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')
-
+ raise ConfigError(f'Configured IP address for static mapping "{mapping}" already exists on another static mapping')
used_ips.append(mapping_config['ip_address'])
+ if 'mac_address' in mapping_config:
+ if mapping_config['mac_address'] in used_mac:
+ raise ConfigError(f'Configured MAC address for static mapping "{mapping}" already exists on another static mapping')
+ used_mac.append(mapping_config['mac_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: