diff options
author | Christian Breunig <christian@breunig.cc> | 2024-04-02 18:32:47 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-02 18:32:47 +0200 |
commit | 1d34bd8cc062573d5c89bc57c1010e131bac75f9 (patch) | |
tree | c5f67c11122a15a6a9136c04c4de49506c899bc3 /python/vyos/configverify.py | |
parent | 7ee2f016878ed29120baa66f8e1d372f97402c96 (diff) | |
parent | e5af1f0905991103b12302892e6f0070bbb7b770 (diff) | |
download | vyos-1x-1d34bd8cc062573d5c89bc57c1010e131bac75f9.tar.gz vyos-1x-1d34bd8cc062573d5c89bc57c1010e131bac75f9.zip |
Merge pull request #3229 from c-po/multi-vrf
T6192: allow binding SSH to multiple VRF instances
Diffstat (limited to 'python/vyos/configverify.py')
-rw-r--r-- | python/vyos/configverify.py | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/python/vyos/configverify.py b/python/vyos/configverify.py index 6508ccdd9..651036bad 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( @@ -206,13 +213,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!') @@ -222,7 +229,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!') @@ -280,6 +287,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() @@ -288,7 +296,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!' |