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 /src | |
| 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 'src')
| -rw-r--r-- | src/tests/test_configverify.py | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/src/tests/test_configverify.py b/src/tests/test_configverify.py new file mode 100644 index 000000000..1066e52e2 --- /dev/null +++ b/src/tests/test_configverify.py @@ -0,0 +1,76 @@ +# Copyright VyOS maintainers and contributors <maintainers@vyos.io> +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 2 or later as +# published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + + +from unittest import TestCase +from vyos import ConfigError +from vyos.config import ConfigDict +from vyos.configverify import verify_mirror_redirect + + +class TestVerifyMirrorRedirect(TestCase): + # CLI "interfaces" tree, carried by the dictionaries returned from + # Config.get_config_dict() in their interfaces_root attribute + interfaces_root = { + 'dummy': {'dum4711': {}, 'dum4712': {'netns': 'NS4711'}}, + 'ethernet': { + 'eth0': {}, + 'eth1': {'vif': {'100': {'address': ['192.0.2.1/24']}}}, + }, + 'tunnel': {'tun4711': {'encapsulation': 'gre'}}, + # "tun4712" is a WireGuard peer name here, not an interface + 'wireguard': {'wg4711': {'peer': {'tun4712': {'address': '192.0.2.2'}}}}, + } + + def _config(self, ifname, **options): + config = ConfigDict({'ifname': ifname, **options}) + config.interfaces_root = self.interfaces_root + return config + + def test_target_in_kernel(self): + verify_mirror_redirect(self._config('eth0', mirror={'ingress': 'lo'})) + verify_mirror_redirect(self._config('eth0', redirect='lo')) + + def test_target_defined_on_cli_only(self): + # T6393: target defined on the CLI but not (yet) created in the kernel + verify_mirror_redirect( + self._config('eth0', mirror={'ingress': 'tun4711', 'egress': 'dum4711'}) + ) + verify_mirror_redirect(self._config('eth0', redirect='tun4711')) + verify_mirror_redirect(self._config('eth0.100', mirror={'ingress': 'tun4711'})) + + def test_target_missing(self): + with self.assertRaisesRegex(ConfigError, 'mirror interface "tun4712"'): + verify_mirror_redirect(self._config('eth0', mirror={'ingress': 'tun4712'})) + with self.assertRaisesRegex(ConfigError, 'redirect interface "tun4712"'): + verify_mirror_redirect(self._config('eth0', redirect='tun4712')) + # VLAN target defined on the CLI but not existing in the kernel + with self.assertRaises(ConfigError): + verify_mirror_redirect(self._config('eth0', mirror={'egress': 'eth1.100'})) + # a target in another netns is out of reach for tc(8) + with self.assertRaisesRegex(ConfigError, 'network namespace'): + verify_mirror_redirect(self._config('eth0', mirror={'ingress': 'dum4712'})) + # without any knowledge of the CLI the kernel is the only reference + with self.assertRaises(ConfigError): + verify_mirror_redirect({'ifname': 'eth0', 'mirror': {'ingress': 'tun4711'}}) + + def test_mirror_to_self(self): + with self.assertRaises(ConfigError): + verify_mirror_redirect(self._config('eth0', mirror={'ingress': 'eth0'})) + + def test_mirror_and_redirect_exclusive(self): + with self.assertRaises(ConfigError): + verify_mirror_redirect( + self._config('eth0', mirror={'ingress': 'lo'}, redirect='lo') + ) |
