diff options
| author | ciaens <commits@ciaens.com> | 2026-10-19 14:04:07 +0200 |
|---|---|---|
| committer | Christian Breunig <christian@breunig.cc> | 2026-11-05 23:21:40 +0100 |
| commit | 99271db4a3d75241fe8ccedef0877d7d07e3b96f (patch) | |
| tree | fba379fc82fdff046fe6390729c5413eb1497d5b /python | |
| parent | fc6fa8c6683988d09ed4f53ec69cc7a96ed03a41 (diff) | |
| download | vyos-1x-99271db4a3d75241fe8ccedef0877d7d07e3b96f.tar.gz vyos-1x-99271db4a3d75241fe8ccedef0877d7d07e3b96f.zip | |
interfaces: T6393: accept mirror and redirect targets defined on the CLI
Interface types are committed in priority order (ethernet 318, bridge 319,
bonding 320, ... tunnel 380). verify_mirror_redirect() required the mirror
and redirect target to exist in the Kernel, so "interfaces ethernet eth1
mirror ingress tun0" (or "redirect tun0") could never commit on the first
pass at boot, or when both interfaces are created in the same commit:
VYOS_TAGNODE_VALUE=eth1 .../interfaces_ethernet.py
Requested mirror interface "tun0" does not exist!
Sending reply: ERROR_COMMIT with output
VYOS_TAGNODE_VALUE=tun0 .../interfaces_tunnel.py
Sending reply: SUCCESS with output
The whole ethernet node was rolled back, taking its addresses and everything
on top of them down with it. The tc filter itself is installed by the
target's commit since the previous commit, only verify() blocks.
Also accept a target which is defined on the CLI, at its interface name
position of the interfaces tree that Config.get_config_dict() attaches to
its dictionaries. A target that is neither configured nor existing still
fails the commit with the same error message as before. VLAN sub-interface
targets are only accepted from the Kernel, as nothing would install their
filter later on. VLAN sub-interfaces as sources get the interfaces tree
attached to their own dictionaries in get_interface_dict().
A target placed in a network namespace is out of reach for tc(8) and is
rejected with its own message, also while its device still sits in the
default namespace.
A target whose device is created asynchronously by a daemon (OpenVPN) now
also passes verify at boot; if its device is not up yet when that interface
applies, the filter is installed on the next commit of either side instead
of the source interface being rolled back.
src/tests/test_configverify.py was removed together with its last test case
(T8859) and is re-added with tests for the target verification.
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): """ |
