diff options
Diffstat (limited to 'python')
| -rw-r--r-- | python/vyos/configdict.py | 8 | ||||
| -rw-r--r-- | python/vyos/configverify.py | 24 |
2 files changed, 25 insertions, 7 deletions
diff --git a/python/vyos/configdict.py b/python/vyos/configdict.py index 3353c70be..d52a3940e 100644 --- a/python/vyos/configdict.py +++ b/python/vyos/configdict.py @@ -20,6 +20,7 @@ import os import json from vyos.config import Config +from vyos.config import ConfigDict from vyos.utils.dict import dict_search from vyos.utils.process import cmdl @@ -580,6 +581,9 @@ def get_interface_dict(config, base, ifname='', recursive_defaults=True, with_pk dict['ipv6']['address'].update({'interface_identifier_old': interface_identifier}) for vif, vif_config in dict.get('vif', {}).items(): + # T6393: carry the CLI interfaces tree, see Config.get_config_dict() + dict['vif'][vif] = ConfigDict(vif_config) + dict['vif'][vif].interfaces_root = dict.interfaces_root # Add subinterface name to dictionary dict['vif'][vif].update({'ifname' : f'{ifname}.{vif}'}) @@ -607,6 +611,8 @@ def get_interface_dict(config, base, ifname='', recursive_defaults=True, with_pk if dhcpv6: dict['vif'][vif].update({'dhcpv6_options_changed' : {}}) for vif_s, vif_s_config in dict.get('vif_s', {}).items(): + dict['vif_s'][vif_s] = ConfigDict(vif_s_config) + dict['vif_s'][vif_s].interfaces_root = dict.interfaces_root # Add subinterface name to dictionary dict['vif_s'][vif_s].update({'ifname' : f'{ifname}.{vif_s}'}) @@ -635,6 +641,8 @@ def get_interface_dict(config, base, ifname='', recursive_defaults=True, with_pk if dhcpv6: dict['vif_s'][vif_s].update({'dhcpv6_options_changed' : {}}) for vif_c, vif_c_config in vif_s_config.get('vif_c', {}).items(): + dict['vif_s'][vif_s]['vif_c'][vif_c] = ConfigDict(vif_c_config) + dict['vif_s'][vif_s]['vif_c'][vif_c].interfaces_root = dict.interfaces_root # Add subinterface name to dictionary dict['vif_s'][vif_s]['vif_c'][vif_c].update({'ifname' : f'{ifname}.{vif_s}.{vif_c}'}) diff --git a/python/vyos/configverify.py b/python/vyos/configverify.py index d918c53bb..0c2e2f62b 100644 --- a/python/vyos/configverify.py +++ b/python/vyos/configverify.py @@ -188,21 +188,31 @@ def verify_mirror_redirect(config): # limitation from the past raise ConfigError('Cannot use QoS together with mirror!') + def verify_target(kind, target): + # T6393: interface types are committed in priority order, the target + # may only be defined on the CLI and not (yet) exist in the Kernel. + # tc(8) can not reach a target in another netns + for interfaces in getattr(config, 'interfaces_root', {}).values(): + if target in interfaces: + if 'netns' in interfaces[target]: + raise ConfigError( + f'Requested {kind} interface "{target}" is in a ' + 'network namespace!' + ) + return + if not interface_exists(target): + raise ConfigError(f'Requested {kind} interface "{target}" does not exist!') + if 'mirror' in config: for direction, mirror_interface in config['mirror'].items(): - if not interface_exists(mirror_interface): - raise ConfigError(f'Requested mirror interface "{mirror_interface}" '\ - 'does not exist!') + verify_target('mirror', mirror_interface) if mirror_interface == config['ifname']: raise ConfigError(f'Cannot mirror "{direction}" traffic back '\ 'the originating interface!') if 'redirect' in config: - redirect_ifname = config['redirect'] - if not interface_exists(redirect_ifname): - raise ConfigError(f'Requested redirect interface "{redirect_ifname}" '\ - 'does not exist!') + verify_target('redirect', config['redirect']) def verify_authentication(config): """ |
