[PATCH net v2 6/6] selftests: drv-net: Add VLAN test

From: Ovidiu Panait

Date: Fri Aug 21 2026 - 13:13:24 EST


Add a test that validates ping traffic over VLAN interfaces. It aims
to catch drivers which mishandle hardware VLAN tag stripping, in
particular QinQ.

Three VLAN configurations are covered, each with hardware VLAN stripping
enabled and disabled:
- a single 802.1q VLAN interface
- a single 802.1ad VLAN interface
- an 802.1q VLAN stacked on top of an 802.1ad interface

NETIF=end1 LOCAL_V4=172.16.0.2 REMOTE_V4=172.16.0.3 \
REMOTE_TYPE=ssh REMOTE_ARGS=root@172.16.0.3 \
run_kselftest.sh -t drivers/net:vlan.py
TAP version 13
1..1
# timeout set to 360
# selftests: drivers/net: vlan.py
# # Interface: end0, driver: st_gmac
# TAP version 13
# 1..6
# ok 1 vlan.test.8021q_hw
# ok 2 vlan.test.8021q_sw
# ok 3 vlan.test.8021ad_hw
# ok 4 vlan.test.8021ad_sw
# ok 5 vlan.test.qinq_hw
# ok 6 vlan.test.qinq_sw
# # Totals: pass:6 fail:0 xfail:0 xpass:0 skip:0 error:0
ok 1 selftests: drivers/net: vlan.py
# Totals: pass:1 fail:0 xfail:0 xpass:0 skip:0 error:0

Signed-off-by: Ovidiu Panait <ovidiu.panait.rb@xxxxxxxxxxx>
---
v2 changes:
- New patch.

tools/testing/selftests/drivers/net/Makefile | 1 +
tools/testing/selftests/drivers/net/vlan.py | 100 +++++++++++++++++++
2 files changed, 101 insertions(+)
create mode 100755 tools/testing/selftests/drivers/net/vlan.py

diff --git a/tools/testing/selftests/drivers/net/Makefile b/tools/testing/selftests/drivers/net/Makefile
index d5bf4cb638a8..56c1dc16f8e9 100644
--- a/tools/testing/selftests/drivers/net/Makefile
+++ b/tools/testing/selftests/drivers/net/Makefile
@@ -24,6 +24,7 @@ TEST_PROGS := \
shaper.py \
so_txtime.py \
stats.py \
+ vlan.py \
xdp.py \
# end of TEST_PROGS

diff --git a/tools/testing/selftests/drivers/net/vlan.py b/tools/testing/selftests/drivers/net/vlan.py
new file mode 100755
index 000000000000..82822a4b7bb5
--- /dev/null
+++ b/tools/testing/selftests/drivers/net/vlan.py
@@ -0,0 +1,100 @@
+#!/usr/bin/env python3
+# SPDX-License-Identifier: GPL-2.0
+
+"""
+VLAN tests.
+
+Validates that ping traffic is sent and received correctly over 802.1q
+and 802.1ad VLAN interfaces, with hardware VLAN stripping enabled and
+disabled.
+
+Test cases:
+ - 8021q_hw: Traffic over a single 802.1q VLAN, HW stripping on
+ - 8021q_sw: Traffic over a single 802.1q VLAN, HW stripping off
+ - 8021ad_hw: Traffic over a single 802.1ad VLAN, HW stripping on
+ - 8021ad_sw: Traffic over a single 802.1ad VLAN, HW stripping off
+ - qinq_hw: Traffic over an 802.1q VLAN stacked on an 802.1ad VLAN,
+ HW stripping on
+ - qinq_sw: Traffic over an 802.1q VLAN stacked on an 802.1ad VLAN,
+ HW stripping off
+"""
+
+import os
+from lib.py import ksft_run, ksft_exit
+from lib.py import NetDrvEpEnv
+from lib.py import cmd, defer, ethtool, ip, set_ethtool_feat
+from lib.py import ksft_variants, KsftNamedVariant
+
+OUTER_DEV = f"vlout{os.getpid()}"
+INNER_DEV = f"vlin{os.getpid()}"
+
+OUTER_VID = 100
+INNER_VID = 200
+
+LOCAL_IP = "198.51.100.1"
+REMOTE_IP = "198.51.100.2"
+
+
+def _vlan_add(base, name, proto, vid, host=None):
+ """Create a VLAN device on top of base and bring it up."""
+
+ ip(f"link add link {base} name {name} type vlan proto {proto} id {vid}",
+ host=host)
+ defer(ip, f"link del {name}", host=host)
+ ip(f"link set {name} up", host=host)
+
+
+def _vlan_setup(base, addr, outer_proto, inner_proto, host=None):
+ """Create VLAN interfaces on base and set an IP on the innermost one."""
+
+ _vlan_add(base, OUTER_DEV, outer_proto, OUTER_VID, host=host)
+ if inner_proto:
+ _vlan_add(OUTER_DEV, INNER_DEV, inner_proto, INNER_VID, host=host)
+
+ dev = INNER_DEV if inner_proto else OUTER_DEV
+ ip(f"addr add {addr}/24 dev {dev}", host=host)
+
+
+def _setup(cfg, outer_proto, inner_proto, hw_strip):
+ """Configure VLAN stripping and create the VLAN interfaces."""
+
+ feat = ethtool(f"-k {cfg.ifname}", json=True)[0]
+ set_ethtool_feat(cfg.ifname, feat, {"rx-vlan-offload": hw_strip})
+
+ _vlan_setup(cfg.ifname, LOCAL_IP, outer_proto, inner_proto)
+ _vlan_setup(cfg.remote_ifname, REMOTE_IP, outer_proto, inner_proto,
+ host=cfg.remote)
+
+
+def _vlan_variants():
+ """Generator that yields the VLAN protocols and the stripping mode."""
+
+ yield KsftNamedVariant("8021q_hw", "802.1q", None, True)
+ yield KsftNamedVariant("8021q_sw", "802.1q", None, False)
+ yield KsftNamedVariant("8021ad_hw", "802.1ad", None, True)
+ yield KsftNamedVariant("8021ad_sw", "802.1ad", None, False)
+ yield KsftNamedVariant("qinq_hw", "802.1ad", "802.1q", True)
+ yield KsftNamedVariant("qinq_sw", "802.1ad", "802.1q", False)
+
+
+@ksft_variants(_vlan_variants())
+def test(cfg, outer_proto, inner_proto, hw_strip):
+ """Run a single VLAN test"""
+
+ cfg.require_ipver("4")
+
+ _setup(cfg, outer_proto, inner_proto, hw_strip)
+
+ cmd(f"ping -c 1 -W 5 {REMOTE_IP}")
+
+
+def main() -> None:
+ """ Ksft boiler plate main """
+
+ with NetDrvEpEnv(__file__) as cfg:
+ ksft_run(cases=[test], args=(cfg, ))
+ ksft_exit()
+
+
+if __name__ == "__main__":
+ main()
--
2.34.1