Skip to content

Commit 413fd63

Browse files
authored
Merge pull request #3499 from Giggum/sagitta
dhcpv6-server: T3493: adds prefix range validation and fixes typos in…
2 parents d702b78 + 4cde0b8 commit 413fd63

File tree

1 file changed

+26
-6
lines changed

1 file changed

+26
-6
lines changed

src/conf_mode/service_dhcpv6-server.py

+26-6
Original file line numberDiff line numberDiff line change
@@ -85,21 +85,21 @@ def verify(dhcpv6):
8585

8686
# Stop address must be greater or equal to start address
8787
if not ip_address(stop) >= ip_address(start):
88-
raise ConfigError(f'address-range stop address "{stop}" must be greater then or equal ' \
88+
raise ConfigError(f'address-range stop address "{stop}" must be greater than or equal ' \
8989
f'to the range start address "{start}"!')
9090

9191
# DHCPv6 range start address must be unique - two ranges can't
9292
# start with the same address - makes no sense
9393
if start in range6_start:
9494
raise ConfigError(f'Conflicting DHCPv6 lease range: '\
95-
f'Pool start address "{start}" defined multipe times!')
95+
f'Pool start address "{start}" defined multiple times!')
9696
range6_start.append(start)
9797

9898
# DHCPv6 range stop address must be unique - two ranges can't
9999
# end with the same address - makes no sense
100100
if stop in range6_stop:
101101
raise ConfigError(f'Conflicting DHCPv6 lease range: '\
102-
f'Pool stop address "{stop}" defined multipe times!')
102+
f'Pool stop address "{stop}" defined multiple times!')
103103
range6_stop.append(stop)
104104

105105
if 'prefix' in subnet_config:
@@ -113,12 +113,32 @@ def verify(dhcpv6):
113113
raise ConfigError('prefix-delegation start address not defined!')
114114

115115
for prefix, prefix_config in subnet_config['prefix_delegation']['start'].items():
116+
prefix_start_addr = prefix
117+
118+
# Prefix start address must be inside network
119+
if not ip_address(prefix_start_addr) in ip_network(subnet):
120+
raise ConfigError(f'Prefix delegation start address '\
121+
f'"{prefix_start_addr}" is not in '\
122+
f'subnet "{subnet}"')
123+
116124
if 'stop' not in prefix_config:
117-
raise ConfigError(f'Stop address of delegated IPv6 prefix range "{prefix}" '\
125+
raise ConfigError(f'Stop address of delegated IPv6 '\
126+
f'prefix range "{prefix}" '\
118127
f'must be configured')
119128

129+
if 'stop' in prefix_config:
130+
prefix_stop_addr = prefix_config['stop']
131+
132+
# Prefix stop address must be inside network
133+
if not (ip_address(prefix_stop_addr) in
134+
ip_network(subnet)):
135+
raise ConfigError(f'Prefix delegation stop '\
136+
f'address "{prefix_stop_addr}" '\
137+
f'is not in subnet "{subnet}"')
138+
120139
if 'prefix_length' not in prefix_config:
121-
raise ConfigError('Length of delegated IPv6 prefix must be configured')
140+
raise ConfigError(f'Length of delegated IPv6 prefix '\
141+
f'must be configured')
122142

123143
# Static mappings don't require anything (but check if IP is in subnet if it's set)
124144
if 'static_mapping' in subnet_config:
@@ -130,7 +150,7 @@ def verify(dhcpv6):
130150

131151
if 'vendor_option' in subnet_config:
132152
if len(dict_search('vendor_option.cisco.tftp_server', subnet_config)) > 2:
133-
raise ConfigError(f'No more then two Cisco tftp-servers should be defined for subnet "{subnet}"!')
153+
raise ConfigError(f'No more than two Cisco tftp-servers should be defined for subnet "{subnet}"!')
134154

135155
# Subnets must be unique
136156
if subnet in subnets:

0 commit comments

Comments
 (0)