summaryrefslogtreecommitdiff
path: root/src/conf_mode
diff options
context:
space:
mode:
authorDaniil Baturin <daniil@vyos.io>2025-10-21 15:15:18 +0100
committerGitHub <noreply@github.com>2025-10-21 15:15:18 +0100
commit33099a929ad51b980b77d7427bbb89cd71a560b6 (patch)
tree12d7a2a95d8e42b7788ed81435d923a870f73577 /src/conf_mode
parentfd8794f36b487ba2102cc50437056e93eb62f7f3 (diff)
parentd290b2661f0d71168a4d6b16691f48b7fb741a4c (diff)
downloadvyos-1x-33099a929ad51b980b77d7427bbb89cd71a560b6.tar.gz
vyos-1x-33099a929ad51b980b77d7427bbb89cd71a560b6.zip
Merge pull request #4783 from hedrok/T5942-failover-dhcp-gateway
T5942: Make failover support dhcp-interface
Diffstat (limited to 'src/conf_mode')
-rwxr-xr-xsrc/conf_mode/protocols_failover.py84
1 files changed, 53 insertions, 31 deletions
diff --git a/src/conf_mode/protocols_failover.py b/src/conf_mode/protocols_failover.py
index 956c060f4..752bd6011 100755
--- a/src/conf_mode/protocols_failover.py
+++ b/src/conf_mode/protocols_failover.py
@@ -85,38 +85,60 @@ def verify(failover):
if 'route' not in failover:
raise ConfigError(f'Failover "route" is mandatory!')
+ def _verify_route_item(item_config, item_description, interface_mandatory):
+ if interface_mandatory and 'interface' not in item_config:
+ raise ConfigError(
+ f'Interface for route "{route}" {item_description} is mandatory!'
+ )
+
+ if not item_config.get('check'):
+ raise ConfigError(f'Check target for {item_description} is mandatory!')
+
+ if 'target' not in item_config['check']:
+ raise ConfigError(f'Check target for {item_description} is mandatory!')
+
+ check_type = item_config['check']['type']
+ if check_type == 'tcp' and 'port' not in item_config['check']:
+ raise ConfigError(
+ f'Check port for {item_description} and type TCP is mandatory!'
+ )
+
+ errors = {
+ 'icmp': {},
+ 'tcp': {
+ 'interface': 'Check target "interface" option does nothing for type TCP. Use "vrf" if needed',
+ },
+ 'arp': {
+ 'vrf': 'Check target "vrf" option is incompatible with type ARP, use "interface" option if needed',
+ },
+ }
+
+ for target, target_config in item_config['check']['target'].items():
+ for key, msg in errors[check_type].items():
+ if key in target_config:
+ raise ConfigError(msg)
+
for route, route_config in failover['route'].items():
- if not route_config.get('next_hop'):
- raise ConfigError(f'Next-hop for "{route}" is mandatory!')
-
- for next_hop, next_hop_config in route_config.get('next_hop').items():
- if 'interface' not in next_hop_config:
- raise ConfigError(f'Interface for route "{route}" next-hop "{next_hop}" is mandatory!')
-
- if not next_hop_config.get('check'):
- raise ConfigError(f'Check target for next-hop "{next_hop}" is mandatory!')
-
- if 'target' not in next_hop_config['check']:
- raise ConfigError(f'Check target for next-hop "{next_hop}" is mandatory!')
-
- check_type = next_hop_config['check']['type']
- if check_type == 'tcp' and 'port' not in next_hop_config['check']:
- raise ConfigError(f'Check port for next-hop "{next_hop}" and type TCP is mandatory!')
-
- errors = {
- 'icmp': {},
- 'tcp': {
- 'interface': 'Check target "interface" option does nothing for type TCP. Use "vrf" if needed',
- },
- 'arp': {
- 'vrf': 'Check target "vrf" option is incompatible with type ARP, use "interface" option if needed',
- },
- }
-
- for target, target_config in next_hop_config['check']['target'].items():
- for key, msg in errors[check_type].items():
- if key in target_config:
- raise ConfigError(msg)
+ if not route_config.get('next_hop') and not route_config.get('dhcp_interface'):
+ raise ConfigError(
+ f'Either next-hop or dhcp-interface for "{route}" is mandatory!'
+ )
+
+ if route_config.get('next_hop'):
+ for next_hop, next_hop_config in route_config.get('next_hop').items():
+ _verify_route_item(
+ next_hop_config, f'next-hop "{next_hop}"', interface_mandatory=True
+ )
+
+ if route_config.get('dhcp_interface'):
+ for dhcp_interface, dhcp_interface_config in route_config.get(
+ 'dhcp_interface'
+ ).items():
+ _verify_route_item(
+ dhcp_interface_config,
+ f'dhcp-interface "{dhcp_interface}"',
+ interface_mandatory=False,
+ )
return None