Skip to contentSkip to conversation

macsec: Add support for VLAN filtering in offload mode

PATCH Superseded Cosmin Ratiu 3 participants 13 messages Mar 23 – Mar 25

Subsystems (5)

v5 of 8 Superseded Latest is v8 →

lore
Share & tools
lore
#0 lore raw

v5 cover macsec: Add support for VLAN filtering in offload mode

This short series adds support for VLANs in macsec devices when offload mode is enabled. This allows VLAN netdevs on top of macsec netdevs to function, which accidentally used to be the case in the past, but was broken. This series adds back proper support.

As part of this, the existing nsim-only macsec offload tests were translated to Python so they can run against real HW and new traffic-based tests were added for VLAN filter propagation, since there's currently no uAPI to check VLAN filters.

---

V5:
- Merged tests and macsec lib in a single file.
- Fixed Python linter issues.
- Added CONFIG_MACSEC to tools/testing/selftests/drivers/net/config

V4:
- Migrated nsim-only macsec tests to Python, usable against real hw.
- Ran these tests against both nsim and mlx5.
- Gave up on nsim patches since the tests no longer use them.

V3: https://lore.kernel.org/netdev/[email protected]/t/#u
- Moved back to net.
- Added proper rollback support for VLAN filters in case of failure.
- Added VLAN as a requirement for the new macsec tests.

V2: https://lore.kernel.org/netdev/[email protected]/
- Sent to net-next instead of net because of apparent complexity.
- Changed VLAN filtering to only function in offload mode.
- Added tests.

V1: https://lore.kernel.org/netdev/[email protected]/

Cosmin Ratiu (3):
selftests: Migrate nsim-only MACsec tests to Python
selftests: Add MACsec VLAN propagation traffic test
macsec: Support VLAN-filtering lower devices

 drivers/net/macsec.c                          |  44 ++-
 tools/testing/selftests/drivers/net/Makefile  |   1 +
 tools/testing/selftests/drivers/net/config    |   1 +
 tools/testing/selftests/drivers/net/macsec.py | 305 ++++++++++++++++++
 .../selftests/drivers/net/netdevsim/Makefile  |   1 -
 .../drivers/net/netdevsim/macsec-offload.sh   | 117 -------
 6 files changed, 346 insertions(+), 123 deletions(-)
 create mode 100755 tools/testing/selftests/drivers/net/macsec.py
 delete mode 100755 tools/testing/selftests/drivers/net/netdevsim/macsec-offload.sh
Signature · 1 line
2.53.0
#1 lore raw

PATCH v5 1/3 selftests: Migrate nsim-only MACsec tests to Python

Move MACsec offload API and ethtool feature tests from tools/testing/selftests/drivers/net/netdevsim/macsec-offload.sh to tools/testing/selftests/drivers/net/macsec.py using the NetDrvEnv framework so tests can run against both netdevsim (default) and real hardware (NETIF=ethX). As some real hardware requires macsec to use encryption, add that to the tests.

Netdevsim-specific limit checks (max SecY, max RX SC) were moved into separate test cases to avoid failures on real hardware.

Finally, MACSEC was added as a config option to drivers/net/config.

---
 tools/testing/selftests/drivers/net/Makefile  |   1 +
 tools/testing/selftests/drivers/net/config    |   1 +
 tools/testing/selftests/drivers/net/macsec.py | 179 ++++++++++++++++++
 .../selftests/drivers/net/netdevsim/Makefile  |   1 -
 .../drivers/net/netdevsim/macsec-offload.sh   | 117 ------------
 5 files changed, 181 insertions(+), 118 deletions(-)
 create mode 100755 tools/testing/selftests/drivers/net/macsec.py
 delete mode 100755 tools/testing/selftests/drivers/net/netdevsim/macsec-offload.sh
tools/testing/selftests/drivers/net/Makefile +1 -0
index 8154d6d429d3..5e045dde0273 100644
@@ -13,6 +13,7 @@ TEST_GEN_FILES := \
 TEST_PROGS := \
 	gro.py \
 	hds.py \
+	macsec.py \
 	napi_id.py \
 	napi_threaded.py \
 	netpoll_basic.py \
tools/testing/selftests/drivers/net/config +1 -0
index 77ccf83d87e0..d4b31a317c09 100644
@@ -3,6 +3,7 @@ CONFIG_DEBUG_INFO_BTF=y
 CONFIG_DEBUG_INFO_BTF_MODULES=n
 CONFIG_INET_PSP=y
 CONFIG_IPV6=y
+CONFIG_MACSEC=m
 CONFIG_NETCONSOLE=m
 CONFIG_NETCONSOLE_DYNAMIC=y
 CONFIG_NETCONSOLE_EXTENDED_LOG=y
tools/testing/selftests/drivers/net/macsec.py new file +179 -0

179 lines not on this page · raw message

tools/testing/selftests/drivers/net/netdevsim/Makefile +0 -1
index 1a228c5430f5..9808c2fbae9e 100644
@@ -11,7 +11,6 @@ TEST_PROGS := \
 	fib.sh \
 	fib_notifications.sh \
 	hw_stats_l3.sh \
-	macsec-offload.sh \
 	nexthop.sh \
 	peer.sh \
 	psample.sh \
tools/testing/selftests/drivers/net/netdevsim/macsec-offload.sh deleted +0 -117

117 lines not on this page · raw message

Signature · 1 line
2.53.0
#2 lore raw

PATCH v5 2/3 selftests: Add MACsec VLAN propagation traffic test

In reply to Cosmin Ratiu

Add macsec_traffic.py using NetDrvEpEnv to verify VLAN filter propagation through offloaded macsec devices via actual traffic.

Test creates macsec tunnels with matching SAs on both endpoints, stacks VLANs on top, and verifies connectivity with ping. Covers:
- Offloaded macsec with VLAN (filters propagate to HW)
- Software macsec with VLAN (no HW filter propagation)
- Toggle offload on/off and verify traffic still works

On netdevsim this is a smoke test (stub offload, no real encryption). On real hardware this validates actual VLAN filter propagation.

---
 tools/testing/selftests/drivers/net/macsec.py | 126 ++++++++++++++++++
 1 file changed, 126 insertions(+)
tools/testing/selftests/drivers/net/macsec.py +126 -0
index a17b9f7ef584..68915caca7fd 100755
@@ -6,10 +6,14 @@
 import os
 
 from lib.py import ksft_run, ksft_exit, ksft_eq, ksft_raises
+from lib.py import ksft_variants, KsftNamedVariant
 from lib.py import CmdExitFailure, KsftSkipEx
 from lib.py import NetDrvEpEnv
 from lib.py import cmd, ip, defer, ethtool
 
+MACSEC_KEY = "12345678901234567890123456789012"
+MACSEC_VLAN_VID = 10
+
 # Unique prefix per run to avoid collisions in the shared netns.
 # Keep it short: IFNAMSIZ is 16 (incl. NUL), and VLAN names append ".<vid>".
 MACSEC_PFX = f"ms{os.getpid()}_"
@@ -25,6 +29,16 @@ def _get_macsec_offload(dev):
     return info.get("linkinfo", {}).get("info_data", {}).get("offload")
 
 
+def _require_ip_macsec(cfg):
+    """SKIP if iproute2 on local or remote lacks 'ip macsec' support."""
+    for host in [None, cfg.remote]:
+        out = cmd("ip macsec help", fail=False, host=host)
+        if "macsec" not in out.stdout + out.stderr:
+            where = "remote" if host else "local"
+            raise KsftSkipEx(f"iproute2 too old on {where},"
+                             " missing macsec support")
+
+
 def _require_ip_macsec_offload():
     """SKIP if local iproute2 doesn't understand 'ip macsec offload'."""
     out = cmd("ip macsec help", fail=False)
@@ -44,6 +58,78 @@ def _require_macsec_offload(cfg):
         raise KsftSkipEx("macsec-hw-offload not supported")
 
 
+def _get_mac(ifname, host=None):
+    """Gets MAC address of an interface."""
+    dev = ip(f"-d link show dev {ifname}", json=True, host=host)
+    return dev[0]["address"]
+
+
+def _setup_macsec_sa(cfg, name):
+    """Adds matching TX/RX SAs on both ends."""
+    local_mac = _get_mac(name)
+    remote_mac = _get_mac(name, host=cfg.remote)
+
+    ip(f"macsec add {name} tx sa 0 pn 1 on key 01 {MACSEC_KEY}")
+    ip(f"macsec add {name} rx port 1 address {remote_mac}")
+    ip(f"macsec add {name} rx port 1 address {remote_mac} "
+       f"sa 0 pn 1 on key 02 {MACSEC_KEY}")
+
+    ip(f"macsec add {name} tx sa 0 pn 1 on key 02 {MACSEC_KEY}",
+       host=cfg.remote)
+    ip(f"macsec add {name} rx port 1 address {local_mac}", host=cfg.remote)
+    ip(f"macsec add {name} rx port 1 address {local_mac} "
+       f"sa 0 pn 1 on key 01 {MACSEC_KEY}", host=cfg.remote)
+
+
+def _setup_macsec_devs(cfg, name, offload):
+    """Creates macsec devices on both ends.
+
+    Only the local device gets HW offload; the remote always uses software
+    MACsec since it may not support offload at all.
+    """
+    offload_arg = "mac" if offload else "off"
+
+    ip(f"link add link {cfg.ifname} {name} "
+       f"type macsec encrypt on offload {offload_arg}")
+    defer(ip, f"link del {name}")
+    ip(f"link add link {cfg.remote_ifname} {name} "
+       f"type macsec encrypt on", host=cfg.remote)
+    defer(ip, f"link del {name}", host=cfg.remote)
+
+
+def _set_offload(name, offload):
+    """Sets offload on the local macsec device only."""
+    offload_arg = "mac" if offload else "off"
+
+    ip(f"link set {name} type macsec encrypt on offload {offload_arg}")
+
+
+def _setup_vlans(cfg, name, vid):
+    """Adds VLANs on top of existing macsec devs."""
+    vlan_name = f"{name}.{vid}"
+
+    ip(f"link add link {name} {vlan_name} type vlan id {vid}")
+    defer(ip, f"link del {vlan_name}")
+    ip(f"link add link {name} {vlan_name} type vlan id {vid}", host=cfg.remote)
+    defer(ip, f"link del {vlan_name}", host=cfg.remote)
+
+
+def _setup_vlan_ips(cfg, name, vid):
+    """Adds VLANs and IPs and brings up the macsec + VLAN devices."""
+    local_ip = "198.51.100.1"
+    remote_ip = "198.51.100.2"
+    vlan_name = f"{name}.{vid}"
+
+    ip(f"addr add {local_ip}/24 dev {vlan_name}")
+    ip(f"addr add {remote_ip}/24 dev {vlan_name}", host=cfg.remote)
+    ip(f"link set {name} up")
+    ip(f"link set {name} up", host=cfg.remote)
+    ip(f"link set {vlan_name} up")
+    ip(f"link set {vlan_name} up", host=cfg.remote)
+
+    return vlan_name, remote_ip
+
+
 def test_offload_api(cfg) -> None:
     """MACsec offload API: create SecY, add SA/rx, toggle offload."""
 
@@ -164,6 +250,44 @@ def test_offload_state(cfg) -> None:
             "offload enabled after create: should be mac")
 
 
+@ksft_variants([
+    KsftNamedVariant("offloaded", True),
+    KsftNamedVariant("software", False),
+])
+def test_vlan(cfg, offload) -> None:
+    """Ping through VLAN-over-macsec."""
+
+    _require_ip_macsec(cfg)
+    if offload:
+        _require_macsec_offload(cfg)
+    else:
+        _require_ip_macsec_offload()
+    name = _macsec_name()
+    _setup_macsec_devs(cfg, name, offload=offload)
+    _setup_macsec_sa(cfg, name)
+    _setup_vlans(cfg, name, MACSEC_VLAN_VID)
+    vlan_name, remote_ip = _setup_vlan_ips(cfg, name, MACSEC_VLAN_VID)
+    cmd(f"ping -I {vlan_name} -c 1 -W 5 {remote_ip}")
+
+
+@ksft_variants([
+    KsftNamedVariant("on_to_off", True),
+    KsftNamedVariant("off_to_on", False),
+])
+def test_vlan_toggle(cfg, offload) -> None:
+    """Toggle offload: VLAN filters propagate/remove correctly."""
+
+    _require_ip_macsec(cfg)
+    _require_macsec_offload(cfg)
+    name = _macsec_name()
+    _setup_macsec_devs(cfg, name, offload=offload)
+    _setup_vlans(cfg, name, MACSEC_VLAN_VID)
+    _set_offload(name, offload=not offload)
+    vlan_name, remote_ip = _setup_vlan_ips(cfg, name, MACSEC_VLAN_VID)
+    _setup_macsec_sa(cfg, name)
+    cmd(f"ping -I {vlan_name} -c 1 -W 5 {remote_ip}")
+
+
 def main() -> None:
     """Main program."""
     with NetDrvEpEnv(__file__) as cfg:
@@ -171,6 +295,8 @@ def main() -> None:
                   test_max_secy,
                   test_max_sc,
                   test_offload_state,
+                  test_vlan,
+                  test_vlan_toggle,
                   ], args=(cfg,))
     ksft_exit()
 
Signature · 1 line
2.53.0
#4 lore raw

PATCH v5 3/3 macsec: Support VLAN-filtering lower devices

In reply to Cosmin Ratiu

VLAN-filtering is done through two netdev features (NETIF_F_HW_VLAN_CTAG_FILTER and NETIF_F_HW_VLAN_STAG_FILTER) and two netdev ops (ndo_vlan_rx_add_vid and ndo_vlan_rx_kill_vid).

Implement these and advertise the features if the lower device supports them. This allows proper VLAN filtering to work on top of macsec devices, when the lower device is capable of VLAN filtering. As a concrete example, having this chain of interfaces now works:
vlan_filtering_capable_dev(1) -> macsec_dev(2) -> macsec_vlan_dev(3)

Before the mentioned commit this used to accidentally work because the macsec device (and thus the lower device) was put in promiscuous mode and the VLAN filter was not used. But after commit [1] correctly made the macsec driver expose the IFF_UNICAST_FLT flag, promiscuous mode was no longer used and VLAN filters on dev 1 kicked in. Without support in dev 2 for propagating VLAN filters down, the register_vlan_dev -> vlan_vid_add -> __vlan_vid_add -> vlan_add_rx_filter_info call from dev 3 is silently eaten (because vlan_hw_filter_capable returns false and vlan_add_rx_filter_info silently succeeds).

For macsec, VLAN filters are only relevant for offload, otherwise the VLANs are encrypted and the lower devices don't care about them. So VLAN filters are only passed on to lower devices in offload mode. Flipping between offload modes now needs to offload/unoffload the filters with vlan_{get,drop}_rx_*_filter_info().

To avoid the back-and-forth filter updating during rollback, the setting of macsec->offload is moved after the add/del secy ops. This is safe since none of the code called from those requires macsec->offload.

Fixes 0349659fd72f ("macsec: set IFF_UNICAST_FLT priv flag")
---
 drivers/net/macsec.c | 44 +++++++++++++++++++++++++++++++++++++++-----
 1 file changed, 39 insertions(+), 5 deletions(-)
drivers/net/macsec.c +39 -5
index f6cad0746a02..3bdb6f3fae8e 100644
@@ -2616,14 +2616,22 @@ static int macsec_update_offload(struct net_device *dev, enum macsec_offload off
 	if (!ops)
 		return -EOPNOTSUPP;
 
-	macsec->offload = offload;
-
 	ctx.secy = &macsec->secy;
 	ret = offload == MACSEC_OFFLOAD_OFF ? macsec_offload(ops->mdo_del_secy, &ctx)
 					    : macsec_offload(ops->mdo_add_secy, &ctx);
-	if (ret) {
-		macsec->offload = prev_offload;
+	if (ret)
 		return ret;
+
+	/* Remove VLAN filters when disabling offload. */
+	if (offload == MACSEC_OFFLOAD_OFF) {
+		vlan_drop_rx_ctag_filter_info(dev);
+		vlan_drop_rx_stag_filter_info(dev);
+	}
+	macsec->offload = offload;
+	/* Add VLAN filters when enabling offload. */
+	if (prev_offload == MACSEC_OFFLOAD_OFF) {
+		vlan_get_rx_ctag_filter_info(dev);
+		vlan_get_rx_stag_filter_info(dev);
 	}
 
 	macsec_set_head_tail_room(dev);
@@ -3486,7 +3494,8 @@ static netdev_tx_t macsec_start_xmit(struct sk_buff *skb,
 }
 
 #define MACSEC_FEATURES \
-	(NETIF_F_SG | NETIF_F_HIGHDMA | NETIF_F_FRAGLIST)
+	(NETIF_F_SG | NETIF_F_HIGHDMA | NETIF_F_FRAGLIST | \
+	 NETIF_F_HW_VLAN_STAG_FILTER | NETIF_F_HW_VLAN_CTAG_FILTER)
 
 #define MACSEC_OFFLOAD_FEATURES \
 	(MACSEC_FEATURES | NETIF_F_GSO_SOFTWARE | NETIF_F_SOFT_FEATURES | \
@@ -3707,6 +3716,29 @@ static int macsec_set_mac_address(struct net_device *dev, void *p)
 	return err;
 }
 
+static int macsec_vlan_rx_add_vid(struct net_device *dev,
+				  __be16 proto, u16 vid)
+{
+	struct macsec_dev *macsec = netdev_priv(dev);
+
+	if (!macsec_is_offloaded(macsec))
+		return 0;
+
+	return vlan_vid_add(macsec->real_dev, proto, vid);
+}
+
+static int macsec_vlan_rx_kill_vid(struct net_device *dev,
+				   __be16 proto, u16 vid)
+{
+	struct macsec_dev *macsec = netdev_priv(dev);
+
+	if (!macsec_is_offloaded(macsec))
+		return 0;
+
+	vlan_vid_del(macsec->real_dev, proto, vid);
+	return 0;
+}
+
 static int macsec_change_mtu(struct net_device *dev, int new_mtu)
 {
 	struct macsec_dev *macsec = macsec_priv(dev);
@@ -3748,6 +3780,8 @@ static const struct net_device_ops macsec_netdev_ops = {
 	.ndo_set_rx_mode	= macsec_dev_set_rx_mode,
 	.ndo_change_rx_flags	= macsec_dev_change_rx_flags,
 	.ndo_set_mac_address	= macsec_set_mac_address,
+	.ndo_vlan_rx_add_vid	= macsec_vlan_rx_add_vid,
+	.ndo_vlan_rx_kill_vid	= macsec_vlan_rx_kill_vid,
 	.ndo_start_xmit		= macsec_start_xmit,
 	.ndo_get_stats64	= macsec_get_stats64,
 	.ndo_get_iflink		= macsec_get_iflink,
Signature · 1 line
2.53.0
maintainer
#5 lore raw
In reply to Cosmin Ratiu
Quoted 4 lines · Cosmin Ratiu

V4:
- Migrated nsim-only macsec tests to Python, usable against real hw.
- Ran these tests against both nsim and mlx5.
- Gave up on nsim patches since the tests no longer use them.

Why not? Being able to test without accessing real HW is still useful.

Signature · 1 line
Sabrina
#6 lore raw
Quoted 10 lines · Sabrina Dubroca
Quoted 5 lines · Cosmin Ratiu

V4:
- Migrated nsim-only macsec tests to Python, usable against real hw.
- Ran these tests against both nsim and mlx5.
- Gave up on nsim patches since the tests no longer use them.

Why not? Being able to test without accessing real HW is still useful.

The tests now send macsec traffic over VLANs and nsim, it's just that nsim doesn't deal with VLAN filters at all and there are no stubbed vlan filters in debugfs, since real hw doesn't have that interface.

Cosmin.

maintainer
#7 lore raw
Quoted 8 lines · Cosmin Ratiu
Quoted 7 lines · Sabrina Dubroca
Quoted 5 lines · Cosmin Ratiu

V4:
- Migrated nsim-only macsec tests to Python, usable against real hw.
- Ran these tests against both nsim and mlx5.
- Gave up on nsim patches since the tests no longer use them.

Quoted 6 lines
Quoted 3 lines

Why not? Being able to test without accessing real HW is still useful.

The tests now send macsec traffic over VLANs and nsim, it's just that nsim doesn't deal with VLAN filters at all and there are no stubbed vlan filters in debugfs, since real hw doesn't have that interface.

Since netdevsim doesn't deal with VLAN filters at all, the "tests should be written so that they can run both against ``netdevsim`` and a real device" bit of the docs doesn't fully apply here?

Anyway, I think the original tests had value, even if they're more limited in some ways than traffic tests. HW/driver behavior could be hiding problems in the stack with VLAN propagation, those simpler tests don't have that risk.

Signature · 1 line
Sabrina
maintainer
#3 lore raw

Re: [PATCH net v5 2/3] selftests: Add MACsec VLAN propagation traffic test

In reply to Cosmin Ratiu
Quoted 11 lines · On Mon, 23 Mar 2026 14:36:32 +0200 Cosmin Ratiu wrote:

Add macsec_traffic.py using NetDrvEpEnv to verify VLAN filter propagation through offloaded macsec devices via actual traffic.

Test creates macsec tunnels with matching SAs on both endpoints, stacks VLANs on top, and verifies connectivity with ping. Covers:
- Offloaded macsec with VLAN (filters propagate to HW)
- Software macsec with VLAN (no HW filter propagation)
- Toggle offload on/off and verify traffic still works

On netdevsim this is a smoke test (stub offload, no real encryption). On real hardware this validates actual VLAN filter propagation.

CONFIG_VLAN_8021Q (and possibly other things) are missing from
tools/testing/selftests/drivers/net/config

Signature · 1 line
pw-bot: cr
maintainer
#8 lore raw
In reply to Sabrina Dubroca
Quoted 9 lines · On Mon, 23 Mar 2026 16:02:59 +0100 Sabrina Dubroca wrote:
Quoted 7 lines · Cosmin Ratiu
Quoted 3 lines · Sabrina Dubroca

Why not? Being able to test without accessing real HW is still useful.

The tests now send macsec traffic over VLANs and nsim, it's just that nsim doesn't deal with VLAN filters at all and there are no stubbed vlan filters in debugfs, since real hw doesn't have that interface.

Quoted 8 lines

Since netdevsim doesn't deal with VLAN filters at all, the "tests should be written so that they can run both against ``netdevsim`` and a real device" bit of the docs doesn't fully apply here?

Anyway, I think the original tests had value, even if they're more limited in some ways than traffic tests. HW/driver behavior could be hiding problems in the stack with VLAN propagation, those simpler tests don't have that risk.

To be clear running the HW test without NETIF= should provide similar functionality to what the old tests could do. It's entirely okay to add netdevsim-specific subtests/test cases or asserts.

Is there anything specific that you'd like to be tested? Let's not make this about HW tests vs nsim-only tests.

maintainer
#9 lore raw
Quoted 19 lines · Jakub Kicinski
Quoted 9 lines · On Mon, 23 Mar 2026 16:02:59 +0100 Sabrina Dubroca wrote:
Quoted 7 lines · Cosmin Ratiu
Quoted 3 lines · Sabrina Dubroca

Why not? Being able to test without accessing real HW is still useful.

The tests now send macsec traffic over VLANs and nsim, it's just that nsim doesn't deal with VLAN filters at all and there are no stubbed vlan filters in debugfs, since real hw doesn't have that interface.

Quoted 8 lines

Since netdevsim doesn't deal with VLAN filters at all, the "tests should be written so that they can run both against ``netdevsim`` and a real device" bit of the docs doesn't fully apply here?

Anyway, I think the original tests had value, even if they're more limited in some ways than traffic tests. HW/driver behavior could be hiding problems in the stack with VLAN propagation, those simpler tests don't have that risk.

Quoted 5 lines

To be clear running the HW test without NETIF= should provide similar functionality to what the old tests could do. It's entirely okay to add netdevsim-specific subtests/test cases or asserts.

Is there anything specific that you'd like to be tested?

In v2/v3, nsim was exposing a debugfs file that contained the list of VLAN filters on that interface, and the selftest was grepping through that file to check if the correct entry was added/removed after each operation. I see that as testing the actual propagation of filters, while the traffic tests check the visible behavior of stack+driver+HW, which may not be correlated to actual propagation.

Quoted 1 line

Let's not make this about HW tests vs nsim-only tests.

That was not my intention. But since nsim doesn't currently implement VLAN filters, it seems running the HW test on nsim doesn't test anything at all.

Signature · 1 line
Sabrina
#10 lore raw
Quoted 41 lines · Sabrina Dubroca
Quoted 26 lines · Jakub Kicinski
Quoted 18 lines · On Mon, 23 Mar 2026 16:02:59 +0100 Sabrina Dubroca wrote:
Quoted 11 lines · Cosmin Ratiu
Quoted 4 lines · Sabrina Dubroca

Why not? Being able to test without accessing real HW is still
useful.

The tests now send macsec traffic over VLANs and nsim, it's just that
nsim doesn't deal with VLAN filters at all and there are no stubbed
vlan filters in debugfs, since real hw doesn't have that interface.

Since netdevsim doesn't deal with VLAN filters at all, the "tests should be written so that they can run both against ``netdevsim`` and
a real device" bit of the docs doesn't fully apply here?

Quoted 6 lines

Anyway, I think the original tests had value, even if they're more
limited in some ways than traffic tests. HW/driver behavior could be
hiding problems in the stack with VLAN propagation, those simpler tests don't have that risk.

Quoted 5 lines

To be clear running the HW test without NETIF= should provide similar functionality to what the old tests could do. It's entirely okay to add netdevsim-specific subtests/test cases or asserts.

Is there anything specific that you'd like to be tested?

In v2/v3, nsim was exposing a debugfs file that contained the list of VLAN filters on that interface, and the selftest was grepping through that file to check if the correct entry was added/removed after each operation. I see that as testing the actual propagation of filters, while the traffic tests check the visible behavior of stack+driver+HW,
which may not be correlated to actual propagation.

Quoted 6 lines
Quoted 1 line

Let's not make this about HW tests vs nsim-only tests.

That was not my intention. But since nsim doesn't currently implement VLAN filters, it seems running the HW test on nsim doesn't test anything at all.

The problem with using the nsim-only VLAN filter debugfs is that it's a test-only interface for figuring out a property of the stack. Real HW doesn't have that interface and thus the tests actually have to generate traffic to ensure VLANs are propagated.

The new VLAN tests don't actually ensure anything on nsim, given that it doesn't support VLANs. But on real HW they do - without the last patch, the new tests fail on any hw supporting VLANs and MACsec.

Adding back the nsim debugfs file and test assertions guarded by "if cfg._ns" would ensure filter propagation correctness, but would feel non-Pythonic and a little hacky given that the same assertion can't work on real HW.

So what would you like to happen? Bring back nsim patches + nsim- specific test assertions?

Cosmin.

maintainer
#11 lore raw
Quoted 44 lines · Cosmin Ratiu
Quoted 43 lines · Sabrina Dubroca
Quoted 26 lines · Jakub Kicinski
Quoted 18 lines · On Mon, 23 Mar 2026 16:02:59 +0100 Sabrina Dubroca wrote:
Quoted 11 lines · Cosmin Ratiu
Quoted 4 lines · Sabrina Dubroca

Why not? Being able to test without accessing real HW is still
useful.

The tests now send macsec traffic over VLANs and nsim, it's just that
nsim doesn't deal with VLAN filters at all and there are no stubbed
vlan filters in debugfs, since real hw doesn't have that interface.

Since netdevsim doesn't deal with VLAN filters at all, the "tests should be written so that they can run both against ``netdevsim`` and
a real device" bit of the docs doesn't fully apply here?

Quoted 6 lines

Anyway, I think the original tests had value, even if they're more
limited in some ways than traffic tests. HW/driver behavior could be
hiding problems in the stack with VLAN propagation, those simpler tests don't have that risk.

Quoted 5 lines

To be clear running the HW test without NETIF= should provide similar functionality to what the old tests could do. It's entirely okay to add netdevsim-specific subtests/test cases or asserts.

Is there anything specific that you'd like to be tested?

In v2/v3, nsim was exposing a debugfs file that contained the list of VLAN filters on that interface, and the selftest was grepping through that file to check if the correct entry was added/removed after each operation. I see that as testing the actual propagation of filters, while the traffic tests check the visible behavior of stack+driver+HW,
which may not be correlated to actual propagation.

Quoted 1 line

Let's not make this about HW tests vs nsim-only tests.

Quoted 7 lines
Quoted 4 lines

That was not my intention. But since nsim doesn't currently implement VLAN filters, it seems running the HW test on nsim doesn't test anything at all.

The problem with using the nsim-only VLAN filter debugfs is that it's a test-only interface for figuring out a property of the stack.

That's the whole point of netdevsim.

Quoted 7 lines

Real HW
doesn't have that interface and thus the tests actually have to generate traffic to ensure VLANs are propagated.

The new VLAN tests don't actually ensure anything on nsim, given that it doesn't support VLANs. But on real HW they do - without the last patch, the new tests fail on any hw supporting VLANs and MACsec.

Well, they ensure that something in the stack+driver+HW combination is doing something that lets traffic go through. It's useful, but we can learn something extra from netdevsim.

Quoted 4 lines

Adding back the nsim debugfs file and test assertions guarded by "if cfg._ns" would ensure filter propagation correctness, but would feel non-Pythonic and a little hacky given that the same assertion can't work on real HW.

I think that's fine. The tests are anyway python wrappers around iproute commands, it's neither "Pythonic" nor pretty. Jakub, any objection?

Quoted 2 lines

So what would you like to happen? Bring back nsim patches + nsim- specific test assertions?

Yes, IMO that would be best.

Signature · 1 line
Sabrina
maintainer
#12 lore raw
Quoted 8 lines · On Tue, 24 Mar 2026 16:18:30 +0100 Sabrina Dubroca wrote:
Quoted 4 lines

Adding back the nsim debugfs file and test assertions guarded by "if cfg._ns" would ensure filter propagation correctness, but would feel non-Pythonic and a little hacky given that the same assertion can't work on real HW.

I think that's fine. The tests are anyway python wrappers around iproute commands, it's neither "Pythonic" nor pretty. Jakub, any objection?

No objections, I already added this nasty little piece of code in gro.py

try:
# Disable TSO for local tests
cfg.require_nsim() # will raise KsftXfailEx if not running on nsim

_set_ethtool_feat(cfg.remote_ifname, cfg.remote_feat,
{"tcp-segmentation-offload": False}, host=cfg.remote)
except KsftXfailEx:
pass

I agree with Cosmin that the check feels a bit non-Pythonic. Dunno if the try except ends up being any better tho :S

Let's not use "if cfg._ns" tho, please add a method that will return true / false (or feel free to come up with a cleaner way if you can think of it). We definitely don't want to encourage nsim-only checks, if you add new methods please mention in their documentation that we strongly prefer if the authors can think of a way to prove correctness that would also work on real HW.