From 9854913e23cf21363a931640cc9994c169969c88 Mon Sep 17 00:00:00 2001 From: Christian Breunig Date: Thu, 5 Nov 2026 23:19:26 +0100 Subject: interfaces: T6393: install mirror and redirect filters for VLAN targets A VLAN sub-interface used as mirror or redirect target (e.g. bond0.10) was only accepted if it already existed in the Kernel. The configuration committed at runtime, but at boot the source interface is committed before the VLAN is created - verify failed and the whole source interface was rolled back, as reported for tunnel targets. A VLAN target is now also accepted if its parent interface has the vif, vif-s or vif-c configured on the CLI. VLAN sub-interfaces learn which interfaces mirror or redirect into them and install their filters once created, as other interfaces already do. Add a config load test mirroring and redirecting into tunnel and bond VLAN targets, which are committed after the ethernet sources. --- python/vyos/configdict.py | 13 +++++++++++++ python/vyos/configverify.py | 18 +++++++++++++++--- 2 files changed, 28 insertions(+), 3 deletions(-) (limited to 'python') diff --git a/python/vyos/configdict.py b/python/vyos/configdict.py index d52a3940e..8c311616c 100644 --- a/python/vyos/configdict.py +++ b/python/vyos/configdict.py @@ -604,6 +604,10 @@ def get_interface_dict(config, base, ifname='', recursive_defaults=True, with_pk bridge = is_member(config, f'{ifname}.{vif}', 'bridge') if bridge: dict['vif'][vif].update({'is_bridge_member' : bridge}) + # Check if it is a monitor interface + mirror = is_mirror_intf(config, f'{ifname}.{vif}') + if mirror: dict['vif'][vif].update({'is_mirror_intf' : mirror}) + # Check if any DHCP options changed which require a client restart dhcp = is_node_changed(config, base + [ifname, 'vif', vif, 'dhcp-options']) if dhcp: dict['vif'][vif].update({'dhcp_options_changed' : {}}) @@ -634,6 +638,10 @@ def get_interface_dict(config, base, ifname='', recursive_defaults=True, with_pk bridge = is_member(config, f'{ifname}.{vif_s}', 'bridge') if bridge: dict['vif_s'][vif_s].update({'is_bridge_member' : bridge}) + # Check if it is a monitor interface + mirror = is_mirror_intf(config, f'{ifname}.{vif_s}') + if mirror: dict['vif_s'][vif_s].update({'is_mirror_intf' : mirror}) + # Check if any DHCP options changed which require a client restart dhcp = is_node_changed(config, base + [ifname, 'vif-s', vif_s, 'dhcp-options']) if dhcp: dict['vif_s'][vif_s].update({'dhcp_options_changed' : {}}) @@ -666,6 +674,11 @@ def get_interface_dict(config, base, ifname='', recursive_defaults=True, with_pk if bridge: dict['vif_s'][vif_s]['vif_c'][vif_c].update( {'is_bridge_member' : bridge}) + # Check if it is a monitor interface + mirror = is_mirror_intf(config, f'{ifname}.{vif_s}.{vif_c}') + if mirror: dict['vif_s'][vif_s]['vif_c'][vif_c].update( + {'is_mirror_intf' : mirror}) + # Check if any DHCP options changed which require a client restart dhcp = is_node_changed(config, base + [ifname, 'vif-s', vif_s, 'vif-c', vif_c, 'dhcp-options']) if dhcp: dict['vif_s'][vif_s]['vif_c'][vif_c].update({'dhcp_options_changed' : {}}) diff --git a/python/vyos/configverify.py b/python/vyos/configverify.py index 0c2e2f62b..714f544f0 100644 --- a/python/vyos/configverify.py +++ b/python/vyos/configverify.py @@ -188,18 +188,30 @@ def verify_mirror_redirect(config): # limitation from the past raise ConfigError('Cannot use QoS together with mirror!') + def vlan_configured(interface, vlan): + # vif or vif-s, or a vif-c below a vif-s + if len(vlan) == 1: + return (('vif' in interface and vlan[0] in interface['vif']) or + ('vif-s' in interface and vlan[0] in interface['vif-s'])) + if len(vlan) == 2 and 'vif-s' in interface and vlan[0] in interface['vif-s']: + vif_s = interface['vif-s'][vlan[0]] + return 'vif-c' in vif_s and vlan[1] in vif_s['vif-c'] + return False + 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 + ifname, *vlan = target.split('.') for interfaces in getattr(config, 'interfaces_root', {}).values(): - if target in interfaces: - if 'netns' in interfaces[target]: + if ifname in interfaces: + if 'netns' in interfaces[ifname]: raise ConfigError( f'Requested {kind} interface "{target}" is in a ' 'network namespace!' ) - return + if not vlan or vlan_configured(interfaces[ifname], vlan): + return if not interface_exists(target): raise ConfigError(f'Requested {kind} interface "{target}" does not exist!') -- cgit v1.2.3