diff options
author | Daniil Baturin <daniil@vyos.io> | 2024-04-03 02:30:00 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-03 02:30:00 +0200 |
commit | df2f99f2db19194ece81141c85e6bbb27cbe24ca (patch) | |
tree | 50a3f92f2423ec700a1f5fa987c7531847bb591a /python/vyos | |
parent | 516235769726e1e270c6a50523559daad528abac (diff) | |
parent | cc208d74567e44d6cffa4fc9fd58bd9bcf050930 (diff) | |
download | vyos-1x-df2f99f2db19194ece81141c85e6bbb27cbe24ca.tar.gz vyos-1x-df2f99f2db19194ece81141c85e6bbb27cbe24ca.zip |
Merge pull request #3235 from vyos/mergify/bp/sagitta/pr-3229
T6192: allow binding SSH to multiple VRF instances (backport #3229)
Diffstat (limited to 'python/vyos')
-rw-r--r-- | python/vyos/configverify.py | 24 | ||||
-rw-r--r-- | python/vyos/template.py | 3 |
2 files changed, 18 insertions, 9 deletions
diff --git a/python/vyos/configverify.py b/python/vyos/configverify.py index 2a5452e7b..300647d21 100644 --- a/python/vyos/configverify.py +++ b/python/vyos/configverify.py @@ -99,10 +99,17 @@ def verify_vrf(config): Common helper function used by interface implementations to perform recurring validation of VRF configuration. """ - from netifaces import interfaces - if 'vrf' in config and config['vrf'] != 'default': - if config['vrf'] not in interfaces(): - raise ConfigError('VRF "{vrf}" does not exist'.format(**config)) + from vyos.utils.network import interface_exists + if 'vrf' in config: + vrfs = config['vrf'] + if isinstance(vrfs, str): + vrfs = [vrfs] + + for vrf in vrfs: + if vrf == 'default': + continue + if not interface_exists(vrf): + raise ConfigError(f'VRF "{vrf}" does not exist!') if 'is_bridge_member' in config: raise ConfigError( @@ -169,13 +176,13 @@ def verify_mirror_redirect(config): It makes no sense to mirror traffic back at yourself! """ - import os + from vyos.utils.network import interface_exists if {'mirror', 'redirect'} <= set(config): raise ConfigError('Mirror and redirect can not be enabled at the same time!') if 'mirror' in config: for direction, mirror_interface in config['mirror'].items(): - if not os.path.exists(f'/sys/class/net/{mirror_interface}'): + if not interface_exists(mirror_interface): raise ConfigError(f'Requested mirror interface "{mirror_interface}" '\ 'does not exist!') @@ -185,7 +192,7 @@ def verify_mirror_redirect(config): if 'redirect' in config: redirect_ifname = config['redirect'] - if not os.path.exists(f'/sys/class/net/{redirect_ifname}'): + if not interface_exists(redirect_ifname): raise ConfigError(f'Requested redirect interface "{redirect_ifname}" '\ 'does not exist!') @@ -243,6 +250,7 @@ def verify_interface_exists(ifname, warning_only=False): from vyos.base import Warning from vyos.configquery import ConfigTreeQuery from vyos.utils.dict import dict_search_recursive + from vyos.utils.network import interface_exists # Check if interface is present in CLI config config = ConfigTreeQuery() @@ -251,7 +259,7 @@ def verify_interface_exists(ifname, warning_only=False): return True # Interface not found on CLI, try Linux Kernel - if os.path.exists(f'/sys/class/net/{ifname}'): + if interface_exists(ifname): return True message = f'Interface "{ifname}" does not exist!' diff --git a/python/vyos/template.py b/python/vyos/template.py index d1b3e8fa8..ffccae9a1 100644 --- a/python/vyos/template.py +++ b/python/vyos/template.py @@ -294,7 +294,8 @@ def network_from_ipv4(address): @register_filter('is_interface') def is_interface(interface): """ Check if parameter is a valid local interface name """ - return os.path.exists(f'/sys/class/net/{interface}') + from vyos.utils.network import interface_exists + return interface_exists(interface) @register_filter('is_ip') def is_ip(addr): |