* [PATCH net-next v1 0/7] selftests/net: add netkit netns ping test
@ 2025-11-20 3:30 David Wei
2025-11-20 3:30 ` [PATCH net-next v1 1/7] selftests/net: add suffix to ksft_run David Wei
` (6 more replies)
0 siblings, 7 replies; 21+ messages in thread
From: David Wei @ 2025-11-20 3:30 UTC (permalink / raw)
To: netdev
Cc: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, Daniel Borkmann
This patchset is mostly prep work for adding a data path test for netkit
bind queue API used by iou zcrx and AF_XDP.
Using memory providers requires carving out queues, setting up flow
steering, enabling some features. Add a new MemPrvEnv, similar to the
existing NetDrvEnv, that automates the setup of the NETIF under test.
Refactor the existing iou-zcrx.py test to use this.
net_iovs cannot be forwarded through the core, and so bpf is needed to
forward skbs from NETIF to the netns netkit. Add a basic configurable
bpf prog and associated loader that does this.
For a remote to talk to the netns netkit, it needs a publicly routable
IP. Add a new env var LOCAL_PREFIX_V{4,6} that defines such a prefix.
Finally, add a basic ping test that brings everything together.
David Wei (7):
selftests/net: add suffix to ksft_run
selftests/net: add MemPrvEnv env
selftests/net: modify iou-zcrx.py to use MemPrvEnv
selftests/net: add rand_ifname() helper
selftests/net: add bpf skb forwarding program
selftests/net: add LOCAL_PREFIX_V{4,6} env to HW selftests
selftests/net: add a netkit netns ping test
.../testing/selftests/drivers/net/README.rst | 6 +
.../selftests/drivers/net/hw/.gitignore | 3 +
.../testing/selftests/drivers/net/hw/Makefile | 10 +-
.../selftests/drivers/net/hw/iou-zcrx.py | 131 +++---------------
.../drivers/net/hw/lib/py/__init__.py | 10 +-
.../selftests/drivers/net/hw/nk_forward.bpf.c | 49 +++++++
.../selftests/drivers/net/hw/nk_forward.c | 102 ++++++++++++++
.../selftests/drivers/net/hw/nk_netns.py | 89 ++++++++++++
.../selftests/drivers/net/lib/py/__init__.py | 9 +-
.../selftests/drivers/net/lib/py/env.py | 72 +++++++++-
.../testing/selftests/net/lib/py/__init__.py | 5 +-
tools/testing/selftests/net/lib/py/ksft.py | 8 +-
tools/testing/selftests/net/lib/py/utils.py | 7 +
13 files changed, 370 insertions(+), 131 deletions(-)
create mode 100644 tools/testing/selftests/drivers/net/hw/nk_forward.bpf.c
create mode 100644 tools/testing/selftests/drivers/net/hw/nk_forward.c
create mode 100755 tools/testing/selftests/drivers/net/hw/nk_netns.py
--
2.47.3
^ permalink raw reply [flat|nested] 21+ messages in thread
* [PATCH net-next v1 1/7] selftests/net: add suffix to ksft_run
2025-11-20 3:30 [PATCH net-next v1 0/7] selftests/net: add netkit netns ping test David Wei
@ 2025-11-20 3:30 ` David Wei
2025-11-21 3:13 ` Jakub Kicinski
2025-11-20 3:30 ` [PATCH net-next v1 2/7] selftests/net: add MemPrvEnv env David Wei
` (5 subsequent siblings)
6 siblings, 1 reply; 21+ messages in thread
From: David Wei @ 2025-11-20 3:30 UTC (permalink / raw)
To: netdev
Cc: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, Daniel Borkmann
I want to run the same test cases in slightly different environments
(single queue vs RSS context). Add a suffix to ksft_run so it the
different runs have different names.
Signed-off-by: David Wei <dw@davidwei.uk>
---
tools/testing/selftests/net/lib/py/ksft.py | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/tools/testing/selftests/net/lib/py/ksft.py b/tools/testing/selftests/net/lib/py/ksft.py
index 83b1574f7719..e364db7a69f7 100644
--- a/tools/testing/selftests/net/lib/py/ksft.py
+++ b/tools/testing/selftests/net/lib/py/ksft.py
@@ -136,7 +136,7 @@ def ksft_busy_wait(cond, sleep=0.005, deadline=1, comment=""):
time.sleep(sleep)
-def ktap_result(ok, cnt=1, case="", comment=""):
+def ktap_result(ok, cnt=1, case="", comment="", case_sfx=""):
global KSFT_RESULT_ALL
KSFT_RESULT_ALL = KSFT_RESULT_ALL and ok
@@ -147,7 +147,7 @@ def ktap_result(ok, cnt=1, case="", comment=""):
res += str(cnt) + " "
res += KSFT_MAIN_NAME
if case:
- res += "." + str(case.__name__)
+ res += "." + str(case.__name__) + case_sfx
if comment:
res += " # " + comment
print(res, flush=True)
@@ -220,7 +220,7 @@ def _ksft_intr(signum, frame):
ksft_pr(f"Ignoring SIGTERM (cnt: {term_cnt}), already exiting...")
-def ksft_run(cases=None, globs=None, case_pfx=None, args=()):
+def ksft_run(cases=None, globs=None, case_pfx=None, args=(), case_sfx=""):
cases = cases or []
if globs and case_pfx:
@@ -273,7 +273,7 @@ def ksft_run(cases=None, globs=None, case_pfx=None, args=()):
if not cnt_key:
cnt_key = 'pass' if KSFT_RESULT else 'fail'
- ktap_result(KSFT_RESULT, cnt, case, comment=comment)
+ ktap_result(KSFT_RESULT, cnt, case, comment=comment, case_sfx=case_sfx)
totals[cnt_key] += 1
if stop:
--
2.47.3
^ permalink raw reply related [flat|nested] 21+ messages in thread
* [PATCH net-next v1 2/7] selftests/net: add MemPrvEnv env
2025-11-20 3:30 [PATCH net-next v1 0/7] selftests/net: add netkit netns ping test David Wei
2025-11-20 3:30 ` [PATCH net-next v1 1/7] selftests/net: add suffix to ksft_run David Wei
@ 2025-11-20 3:30 ` David Wei
2025-11-21 3:18 ` Jakub Kicinski
2025-11-20 3:30 ` [PATCH net-next v1 3/7] selftests/net: modify iou-zcrx.py to use MemPrvEnv David Wei
` (4 subsequent siblings)
6 siblings, 1 reply; 21+ messages in thread
From: David Wei @ 2025-11-20 3:30 UTC (permalink / raw)
To: netdev
Cc: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, Daniel Borkmann
Memory provider HW selftests (i.e. zcrx, devmem) require setting up a
netdev with e.g. flow steering rules. Add a new MemPrvEnv that sets up
the test env, restoring it to the original state prior to the test. This
also speeds up tests since each individual test case don't need to
repeat the setup/teardown.
Signed-off-by: David Wei <dw@davidwei.uk>
---
.../drivers/net/hw/lib/py/__init__.py | 5 +-
.../selftests/drivers/net/lib/py/__init__.py | 4 +-
.../selftests/drivers/net/lib/py/env.py | 71 ++++++++++++++++++-
3 files changed, 75 insertions(+), 5 deletions(-)
diff --git a/tools/testing/selftests/drivers/net/hw/lib/py/__init__.py b/tools/testing/selftests/drivers/net/hw/lib/py/__init__.py
index fb010a48a5a1..09f120be9075 100644
--- a/tools/testing/selftests/drivers/net/hw/lib/py/__init__.py
+++ b/tools/testing/selftests/drivers/net/hw/lib/py/__init__.py
@@ -29,7 +29,7 @@ try:
from net.lib.py import ksft_eq, ksft_ge, ksft_in, ksft_is, ksft_lt, \
ksft_ne, ksft_not_in, ksft_raises, ksft_true, ksft_gt, ksft_not_none
from drivers.net.lib.py import GenerateTraffic, Remote
- from drivers.net.lib.py import NetDrvEnv, NetDrvEpEnv
+ from drivers.net.lib.py import NetDrvEnv, NetDrvEpEnv, MemPrvEnv
__all__ = ["NetNS", "NetNSEnter", "NetdevSimDev",
"EthtoolFamily", "NetdevFamily", "NetshaperFamily",
@@ -44,7 +44,8 @@ try:
"ksft_eq", "ksft_ge", "ksft_in", "ksft_is", "ksft_lt",
"ksft_ne", "ksft_not_in", "ksft_raises", "ksft_true", "ksft_gt",
"ksft_not_none", "ksft_not_none",
- "NetDrvEnv", "NetDrvEpEnv", "GenerateTraffic", "Remote"]
+ "GenerateTraffic", "Remote",
+ "NetDrvEnv", "NetDrvEpEnv", "MemPrvEnv"]
except ModuleNotFoundError as e:
print("Failed importing `net` library from kernel sources")
print(str(e))
diff --git a/tools/testing/selftests/drivers/net/lib/py/__init__.py b/tools/testing/selftests/drivers/net/lib/py/__init__.py
index b0c6300150fb..dde4e80811c7 100644
--- a/tools/testing/selftests/drivers/net/lib/py/__init__.py
+++ b/tools/testing/selftests/drivers/net/lib/py/__init__.py
@@ -43,11 +43,11 @@ try:
"ksft_ne", "ksft_not_in", "ksft_raises", "ksft_true", "ksft_gt",
"ksft_not_none", "ksft_not_none"]
- from .env import NetDrvEnv, NetDrvEpEnv
+ from .env import NetDrvEnv, NetDrvEpEnv, MemPrvEnv
from .load import GenerateTraffic
from .remote import Remote
- __all__ += ["NetDrvEnv", "NetDrvEpEnv", "GenerateTraffic", "Remote"]
+ __all__ += ["NetDrvEnv", "NetDrvEpEnv", "MemPrvEnv", "GenerateTraffic", "Remote"]
except ModuleNotFoundError as e:
print("Failed importing `net` library from kernel sources")
print(str(e))
diff --git a/tools/testing/selftests/drivers/net/lib/py/env.py b/tools/testing/selftests/drivers/net/lib/py/env.py
index 01be3d9b9720..3e19b57ef5e0 100644
--- a/tools/testing/selftests/drivers/net/lib/py/env.py
+++ b/tools/testing/selftests/drivers/net/lib/py/env.py
@@ -1,12 +1,14 @@
# SPDX-License-Identifier: GPL-2.0
import os
+import re
import time
from pathlib import Path
from lib.py import KsftSkipEx, KsftXfailEx
from lib.py import ksft_setup, wait_file
-from lib.py import cmd, ethtool, ip, CmdExitFailure
+from lib.py import cmd, ethtool, ip, rand_port, CmdExitFailure
from lib.py import NetNS, NetdevSimDev
+from lib.py import EthtoolFamily
from .remote import Remote
@@ -283,3 +285,70 @@ class NetDrvEpEnv(NetDrvEnvBase):
data.get('stats-block-usecs', 0) / 1000 / 1000
time.sleep(self._stats_settle_time)
+
+
+class MemPrvEnv(NetDrvEpEnv):
+ def __init__(self, src_path, rss=False, rss_num=1, **kwargs):
+ super().__init__(src_path, False, **kwargs)
+
+ self.ethnl = EthtoolFamily()
+ self.cleaned_up = False
+
+ channels = self.ethnl.channels_get({'header': {'dev-index': self.ifindex}})
+ self.channels = channels['combined-count']
+ if self.channels < 2:
+ raise KsftSkipEx('Test requires NETIF with at least 2 combined channels')
+
+ if rss and rss_num > self.channels - 1:
+ raise KsftSkipEx(f"Test with {rss_num} queues in RSS context requires NETIF with at least {rss_num + 1} combined channels")
+
+ self.port = rand_port()
+ rings = self.ethnl.rings_get({'header': {'dev-index': self.ifindex}})
+ self.rx_rings = rings['rx']
+ self.hds_thresh = rings.get('hds-thresh', 0)
+ self.ethnl.rings_set({'header': {'dev-index': self.ifindex},
+ 'tcp-data-split': 'enabled',
+ 'hds-thresh': 0,
+ 'rx': 64})
+
+ if rss:
+ self.target_queue = self.channels - rss_num
+ ethtool(f"-X {self.ifname} equal {self.target_queue}")
+ self.rss_ctx_id = self._create_rss_ctx(rss_num)
+ self.rule_id = self._set_rss_flow_rule()
+ else:
+ self.target_queue = self.channels - 1
+ ethtool(f"-X {self.ifname} equal {self.target_queue}")
+ self.rss_ctx_id = None
+ self.rule_id = self._set_flow_rule()
+
+ def __del__(self):
+ if self.cleaned_up:
+ return
+
+ ethtool(f"-N {self.ifname} delete {self.rule_id}")
+ if self.rss_ctx_id:
+ self.ethnl.rss_delete_act({'header': {'dev-index': self.ifindex},
+ 'context': self.rss_ctx_id})
+
+ ethtool(f"-X {self.ifname} default")
+ self.ethnl.rings_set({'header': {'dev-index': self.ifindex},
+ 'tcp-data-split': 'unknown',
+ 'hds-thresh': self.hds_thresh,
+ 'rx': self.rx_rings})
+ self.cleaned_up = True
+
+ def _set_flow_rule(self):
+ output = ethtool(f"-N {self.ifname} flow-type tcp6 dst-port {self.port} action {self.target_queue}").stdout
+ values = re.search(r'ID (\d+)', output).group(1)
+ return int(values)
+
+ def _set_rss_flow_rule(self):
+ output = ethtool(f"-N {self.ifname} flow-type tcp6 dst-port {self.port} context {self.rss_ctx_id}").stdout
+ values = re.search(r'ID (\d+)', output).group(1)
+ return int(values)
+
+ def _create_rss_ctx(self, num):
+ output = ethtool(f"-X {self.ifname} context new start {self.target_queue} equal {num}").stdout
+ values = re.search(r'New RSS context is (\d+)', output).group(1)
+ return int(values)
--
2.47.3
^ permalink raw reply related [flat|nested] 21+ messages in thread
* [PATCH net-next v1 3/7] selftests/net: modify iou-zcrx.py to use MemPrvEnv
2025-11-20 3:30 [PATCH net-next v1 0/7] selftests/net: add netkit netns ping test David Wei
2025-11-20 3:30 ` [PATCH net-next v1 1/7] selftests/net: add suffix to ksft_run David Wei
2025-11-20 3:30 ` [PATCH net-next v1 2/7] selftests/net: add MemPrvEnv env David Wei
@ 2025-11-20 3:30 ` David Wei
2025-11-20 3:30 ` [PATCH net-next v1 4/7] selftests/net: add rand_ifname() helper David Wei
` (3 subsequent siblings)
6 siblings, 0 replies; 21+ messages in thread
From: David Wei @ 2025-11-20 3:30 UTC (permalink / raw)
To: netdev
Cc: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, Daniel Borkmann
Modify iou-zcrx.py to use MemPrvEnv which shortens the test
significantly.
In addition, there's no need to duplicate the test with and without RSS.
Set up two envs to do this. This makes it easier to repeat each test,
with and without RSS.
Signed-off-by: David Wei <dw@davidwei.uk>
---
.../selftests/drivers/net/hw/iou-zcrx.py | 131 +++---------------
1 file changed, 16 insertions(+), 115 deletions(-)
diff --git a/tools/testing/selftests/drivers/net/hw/iou-zcrx.py b/tools/testing/selftests/drivers/net/hw/iou-zcrx.py
index 712c806508b5..4b99ab090b7c 100755
--- a/tools/testing/selftests/drivers/net/hw/iou-zcrx.py
+++ b/tools/testing/selftests/drivers/net/hw/iou-zcrx.py
@@ -1,143 +1,44 @@
#!/usr/bin/env python3
# SPDX-License-Identifier: GPL-2.0
-import re
from os import path
-from lib.py import ksft_run, ksft_exit, KsftSkipEx
-from lib.py import NetDrvEpEnv
-from lib.py import bkg, cmd, defer, ethtool, rand_port, wait_port_listen
-
-
-def _get_current_settings(cfg):
- output = ethtool(f"-g {cfg.ifname}", json=True)[0]
- return (output['rx'], output['hds-thresh'])
-
-
-def _get_combined_channels(cfg):
- output = ethtool(f"-l {cfg.ifname}").stdout
- values = re.findall(r'Combined:\s+(\d+)', output)
- return int(values[1])
-
-
-def _create_rss_ctx(cfg, chan):
- output = ethtool(f"-X {cfg.ifname} context new start {chan} equal 1").stdout
- values = re.search(r'New RSS context is (\d+)', output).group(1)
- ctx_id = int(values)
- return (ctx_id, defer(ethtool, f"-X {cfg.ifname} delete context {ctx_id}"))
-
-
-def _set_flow_rule(cfg, port, chan):
- output = ethtool(f"-N {cfg.ifname} flow-type tcp6 dst-port {port} action {chan}").stdout
- values = re.search(r'ID (\d+)', output).group(1)
- return int(values)
-
-
-def _set_flow_rule_rss(cfg, port, ctx_id):
- output = ethtool(f"-N {cfg.ifname} flow-type tcp6 dst-port {port} context {ctx_id}").stdout
- values = re.search(r'ID (\d+)', output).group(1)
- return int(values)
+from lib.py import ksft_run, ksft_exit
+from lib.py import MemPrvEnv
+from lib.py import bkg, cmd, wait_port_listen
def test_zcrx(cfg) -> None:
cfg.require_ipver('6')
- combined_chans = _get_combined_channels(cfg)
- if combined_chans < 2:
- raise KsftSkipEx('at least 2 combined channels required')
- (rx_ring, hds_thresh) = _get_current_settings(cfg)
- port = rand_port()
-
- ethtool(f"-G {cfg.ifname} tcp-data-split on")
- defer(ethtool, f"-G {cfg.ifname} tcp-data-split auto")
-
- ethtool(f"-G {cfg.ifname} hds-thresh 0")
- defer(ethtool, f"-G {cfg.ifname} hds-thresh {hds_thresh}")
-
- ethtool(f"-G {cfg.ifname} rx 64")
- defer(ethtool, f"-G {cfg.ifname} rx {rx_ring}")
-
- ethtool(f"-X {cfg.ifname} equal {combined_chans - 1}")
- defer(ethtool, f"-X {cfg.ifname} default")
-
- flow_rule_id = _set_flow_rule(cfg, port, combined_chans - 1)
- defer(ethtool, f"-N {cfg.ifname} delete {flow_rule_id}")
-
- rx_cmd = f"{cfg.bin_local} -s -p {port} -i {cfg.ifname} -q {combined_chans - 1}"
- tx_cmd = f"{cfg.bin_remote} -c -h {cfg.addr_v['6']} -p {port} -l 12840"
+ rx_cmd = f"{cfg.bin_local} -s -p {cfg.port} -i {cfg.ifname} -q {cfg.target_queue}"
+ tx_cmd = f"{cfg.bin_remote} -c -h {cfg.addr_v['6']} -p {cfg.port} -l 12840"
with bkg(rx_cmd, exit_wait=True):
- wait_port_listen(port, proto="tcp")
+ wait_port_listen(cfg.port, proto="tcp")
cmd(tx_cmd, host=cfg.remote)
def test_zcrx_oneshot(cfg) -> None:
cfg.require_ipver('6')
- combined_chans = _get_combined_channels(cfg)
- if combined_chans < 2:
- raise KsftSkipEx('at least 2 combined channels required')
- (rx_ring, hds_thresh) = _get_current_settings(cfg)
- port = rand_port()
-
- ethtool(f"-G {cfg.ifname} tcp-data-split on")
- defer(ethtool, f"-G {cfg.ifname} tcp-data-split auto")
-
- ethtool(f"-G {cfg.ifname} hds-thresh 0")
- defer(ethtool, f"-G {cfg.ifname} hds-thresh {hds_thresh}")
-
- ethtool(f"-G {cfg.ifname} rx 64")
- defer(ethtool, f"-G {cfg.ifname} rx {rx_ring}")
-
- ethtool(f"-X {cfg.ifname} equal {combined_chans - 1}")
- defer(ethtool, f"-X {cfg.ifname} default")
-
- flow_rule_id = _set_flow_rule(cfg, port, combined_chans - 1)
- defer(ethtool, f"-N {cfg.ifname} delete {flow_rule_id}")
-
- rx_cmd = f"{cfg.bin_local} -s -p {port} -i {cfg.ifname} -q {combined_chans - 1} -o 4"
- tx_cmd = f"{cfg.bin_remote} -c -h {cfg.addr_v['6']} -p {port} -l 4096 -z 16384"
+ rx_cmd = f"{cfg.bin_local} -s -p {cfg.port} -i {cfg.ifname} -q {cfg.target_queue} -o 4"
+ tx_cmd = f"{cfg.bin_remote} -c -h {cfg.addr_v['6']} -p {cfg.port} -l 4096 -z 16384"
with bkg(rx_cmd, exit_wait=True):
- wait_port_listen(port, proto="tcp")
+ wait_port_listen(cfg.port, proto="tcp")
cmd(tx_cmd, host=cfg.remote)
-def test_zcrx_rss(cfg) -> None:
- cfg.require_ipver('6')
-
- combined_chans = _get_combined_channels(cfg)
- if combined_chans < 2:
- raise KsftSkipEx('at least 2 combined channels required')
- (rx_ring, hds_thresh) = _get_current_settings(cfg)
- port = rand_port()
-
- ethtool(f"-G {cfg.ifname} tcp-data-split on")
- defer(ethtool, f"-G {cfg.ifname} tcp-data-split auto")
-
- ethtool(f"-G {cfg.ifname} hds-thresh 0")
- defer(ethtool, f"-G {cfg.ifname} hds-thresh {hds_thresh}")
-
- ethtool(f"-G {cfg.ifname} rx 64")
- defer(ethtool, f"-G {cfg.ifname} rx {rx_ring}")
-
- ethtool(f"-X {cfg.ifname} equal {combined_chans - 1}")
- defer(ethtool, f"-X {cfg.ifname} default")
-
- (ctx_id, delete_ctx) = _create_rss_ctx(cfg, combined_chans - 1)
- flow_rule_id = _set_flow_rule_rss(cfg, port, ctx_id)
- defer(ethtool, f"-N {cfg.ifname} delete {flow_rule_id}")
-
- rx_cmd = f"{cfg.bin_local} -s -p {port} -i {cfg.ifname} -q {combined_chans - 1}"
- tx_cmd = f"{cfg.bin_remote} -c -h {cfg.addr_v['6']} -p {port} -l 12840"
- with bkg(rx_cmd, exit_wait=True):
- wait_port_listen(port, proto="tcp")
- cmd(tx_cmd, host=cfg.remote)
+def main() -> None:
+ with MemPrvEnv(__file__) as cfg:
+ cfg.bin_local = path.abspath(path.dirname(__file__) + "/../../../drivers/net/hw/iou-zcrx")
+ cfg.bin_remote = cfg.remote.deploy(cfg.bin_local)
+ ksft_run(globs=globals(), case_pfx={"test_"}, args=(cfg,))
-def main() -> None:
- with NetDrvEpEnv(__file__) as cfg:
+ with MemPrvEnv(__file__, rss=True) as cfg:
cfg.bin_local = path.abspath(path.dirname(__file__) + "/../../../drivers/net/hw/iou-zcrx")
cfg.bin_remote = cfg.remote.deploy(cfg.bin_local)
- ksft_run(globs=globals(), case_pfx={"test_"}, args=(cfg, ))
+ ksft_run(globs=globals(), case_pfx={"test_"}, args=(cfg,), case_sfx="_rss")
ksft_exit()
--
2.47.3
^ permalink raw reply related [flat|nested] 21+ messages in thread
* [PATCH net-next v1 4/7] selftests/net: add rand_ifname() helper
2025-11-20 3:30 [PATCH net-next v1 0/7] selftests/net: add netkit netns ping test David Wei
` (2 preceding siblings ...)
2025-11-20 3:30 ` [PATCH net-next v1 3/7] selftests/net: modify iou-zcrx.py to use MemPrvEnv David Wei
@ 2025-11-20 3:30 ` David Wei
2025-11-21 3:19 ` Jakub Kicinski
2025-11-20 3:30 ` [PATCH net-next v1 5/7] selftests/net: add bpf skb forwarding program David Wei
` (2 subsequent siblings)
6 siblings, 1 reply; 21+ messages in thread
From: David Wei @ 2025-11-20 3:30 UTC (permalink / raw)
To: netdev
Cc: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, Daniel Borkmann
For upcoming netkit container datapath selftests I want to generate
randomised ifnames. Add a helper rand_ifname() to do this.
Signed-off-by: David Wei <dw@davidwei.uk>
---
tools/testing/selftests/drivers/net/hw/lib/py/__init__.py | 5 +++--
tools/testing/selftests/drivers/net/lib/py/__init__.py | 5 +++--
tools/testing/selftests/net/lib/py/__init__.py | 5 +++--
tools/testing/selftests/net/lib/py/utils.py | 7 +++++++
4 files changed, 16 insertions(+), 6 deletions(-)
diff --git a/tools/testing/selftests/drivers/net/hw/lib/py/__init__.py b/tools/testing/selftests/drivers/net/hw/lib/py/__init__.py
index 09f120be9075..f2f6d3eccc86 100644
--- a/tools/testing/selftests/drivers/net/hw/lib/py/__init__.py
+++ b/tools/testing/selftests/drivers/net/hw/lib/py/__init__.py
@@ -22,7 +22,8 @@ try:
NlError, RtnlFamily, DevlinkFamily, PSPFamily
from net.lib.py import CmdExitFailure
from net.lib.py import bkg, cmd, bpftool, bpftrace, defer, ethtool, \
- fd_read_timeout, ip, rand_port, wait_port_listen, wait_file
+ fd_read_timeout, ip, rand_port, wait_port_listen, wait_file, \
+ rand_ifname
from net.lib.py import KsftSkipEx, KsftFailEx, KsftXfailEx
from net.lib.py import ksft_disruptive, ksft_exit, ksft_pr, ksft_run, \
ksft_setup
@@ -37,7 +38,7 @@ try:
"CmdExitFailure",
"bkg", "cmd", "bpftool", "bpftrace", "defer", "ethtool",
"fd_read_timeout", "ip", "rand_port",
- "wait_port_listen", "wait_file",
+ "wait_port_listen", "wait_file", "rand_ifname",
"KsftSkipEx", "KsftFailEx", "KsftXfailEx",
"ksft_disruptive", "ksft_exit", "ksft_pr", "ksft_run",
"ksft_setup",
diff --git a/tools/testing/selftests/drivers/net/lib/py/__init__.py b/tools/testing/selftests/drivers/net/lib/py/__init__.py
index dde4e80811c7..8fb75725f558 100644
--- a/tools/testing/selftests/drivers/net/lib/py/__init__.py
+++ b/tools/testing/selftests/drivers/net/lib/py/__init__.py
@@ -22,7 +22,8 @@ try:
NlError, RtnlFamily, DevlinkFamily, PSPFamily
from net.lib.py import CmdExitFailure
from net.lib.py import bkg, cmd, bpftool, bpftrace, defer, ethtool, \
- fd_read_timeout, ip, rand_port, wait_port_listen, wait_file
+ fd_read_timeout, ip, rand_port, wait_port_listen, wait_file, \
+ rand_ifname
from net.lib.py import KsftSkipEx, KsftFailEx, KsftXfailEx
from net.lib.py import ksft_disruptive, ksft_exit, ksft_pr, ksft_run, \
ksft_setup
@@ -35,7 +36,7 @@ try:
"CmdExitFailure",
"bkg", "cmd", "bpftool", "bpftrace", "defer", "ethtool",
"fd_read_timeout", "ip", "rand_port",
- "wait_port_listen", "wait_file",
+ "wait_port_listen", "wait_file", "rand_ifname",
"KsftSkipEx", "KsftFailEx", "KsftXfailEx",
"ksft_disruptive", "ksft_exit", "ksft_pr", "ksft_run",
"ksft_setup",
diff --git a/tools/testing/selftests/net/lib/py/__init__.py b/tools/testing/selftests/net/lib/py/__init__.py
index 97b7cf2b20eb..f16cbc025bf2 100644
--- a/tools/testing/selftests/net/lib/py/__init__.py
+++ b/tools/testing/selftests/net/lib/py/__init__.py
@@ -12,7 +12,8 @@ from .ksft import KsftFailEx, KsftSkipEx, KsftXfailEx, ksft_pr, ksft_eq, \
from .netns import NetNS, NetNSEnter
from .nsim import NetdevSim, NetdevSimDev
from .utils import CmdExitFailure, fd_read_timeout, cmd, bkg, defer, \
- bpftool, ip, ethtool, bpftrace, rand_port, wait_port_listen, wait_file
+ bpftool, ip, ethtool, bpftrace, rand_port, wait_port_listen, wait_file, \
+ rand_ifname
from .ynl import NlError, YnlFamily, EthtoolFamily, NetdevFamily, RtnlFamily, RtnlAddrFamily
from .ynl import NetshaperFamily, DevlinkFamily, PSPFamily
@@ -25,7 +26,7 @@ __all__ = ["KSRC",
"NetNS", "NetNSEnter",
"CmdExitFailure", "fd_read_timeout", "cmd", "bkg", "defer",
"bpftool", "ip", "ethtool", "bpftrace", "rand_port",
- "wait_port_listen", "wait_file",
+ "wait_port_listen", "wait_file", "rand_ifname",
"NetdevSim", "NetdevSimDev",
"NetshaperFamily", "DevlinkFamily", "PSPFamily", "NlError",
"YnlFamily", "EthtoolFamily", "NetdevFamily", "RtnlFamily",
diff --git a/tools/testing/selftests/net/lib/py/utils.py b/tools/testing/selftests/net/lib/py/utils.py
index cb40ecef9456..56546d796f6c 100644
--- a/tools/testing/selftests/net/lib/py/utils.py
+++ b/tools/testing/selftests/net/lib/py/utils.py
@@ -2,9 +2,11 @@
import json as _json
import os
+import random
import re
import select
import socket
+import string
import subprocess
import time
@@ -238,6 +240,11 @@ def rand_port(stype=socket.SOCK_STREAM):
return s.getsockname()[1]
+def rand_ifname():
+ dev = ''.join(random.choice(string.ascii_lowercase) for _ in range(6))
+ return dev + ''.join(random.choice(string.digits) for _ in range(2))
+
+
def wait_port_listen(port, proto="tcp", ns=None, host=None, sleep=0.005, deadline=5):
end = time.monotonic() + deadline
--
2.47.3
^ permalink raw reply related [flat|nested] 21+ messages in thread
* [PATCH net-next v1 5/7] selftests/net: add bpf skb forwarding program
2025-11-20 3:30 [PATCH net-next v1 0/7] selftests/net: add netkit netns ping test David Wei
` (3 preceding siblings ...)
2025-11-20 3:30 ` [PATCH net-next v1 4/7] selftests/net: add rand_ifname() helper David Wei
@ 2025-11-20 3:30 ` David Wei
2025-11-21 3:20 ` Jakub Kicinski
2025-11-20 3:30 ` [PATCH net-next v1 6/7] selftests/net: add LOCAL_PREFIX_V{4,6} env to HW selftests David Wei
2025-11-20 3:30 ` [PATCH net-next v1 7/7] selftests/net: add a netkit netns ping test David Wei
6 siblings, 1 reply; 21+ messages in thread
From: David Wei @ 2025-11-20 3:30 UTC (permalink / raw)
To: netdev
Cc: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, Daniel Borkmann
This is needed for netkit container datapath selftests. Add two things:
1. nk_forward.bpf.c, a bpf program that forwards skbs matching some
IPv6 prefix received on eth0 ifindex to a specified netkit ifindex.
2. nk_forward.c, a C loader program that accepts eth0/netkit ifindex
and IPv6 prefix.
Selftests will load and unload this bpf program via the loader.
Signed-off-by: David Wei <dw@davidwei.uk>
---
.../selftests/drivers/net/hw/.gitignore | 3 +
.../testing/selftests/drivers/net/hw/Makefile | 9 +-
.../selftests/drivers/net/hw/nk_forward.bpf.c | 49 +++++++++
.../selftests/drivers/net/hw/nk_forward.c | 102 ++++++++++++++++++
4 files changed, 162 insertions(+), 1 deletion(-)
create mode 100644 tools/testing/selftests/drivers/net/hw/nk_forward.bpf.c
create mode 100644 tools/testing/selftests/drivers/net/hw/nk_forward.c
diff --git a/tools/testing/selftests/drivers/net/hw/.gitignore b/tools/testing/selftests/drivers/net/hw/.gitignore
index 6942bf575497..ca6947f30561 100644
--- a/tools/testing/selftests/drivers/net/hw/.gitignore
+++ b/tools/testing/selftests/drivers/net/hw/.gitignore
@@ -1,3 +1,6 @@
# SPDX-License-Identifier: GPL-2.0-only
iou-zcrx
ncdevmem
+nk_forward
+*.skel.h
+tools/
diff --git a/tools/testing/selftests/drivers/net/hw/Makefile b/tools/testing/selftests/drivers/net/hw/Makefile
index 8133d1a0051c..855363bc8d48 100644
--- a/tools/testing/selftests/drivers/net/hw/Makefile
+++ b/tools/testing/selftests/drivers/net/hw/Makefile
@@ -1,6 +1,6 @@
# SPDX-License-Identifier: GPL-2.0+ OR MIT
-TEST_GEN_FILES = iou-zcrx
+TEST_GEN_FILES = iou-zcrx nk_forward
TEST_PROGS = \
csum.py \
@@ -55,3 +55,10 @@ include ../../../net/ynl.mk
include ../../../net/bpf.mk
$(OUTPUT)/iou-zcrx: LDLIBS += -luring
+
+$(OUTPUT)/nk_forward: $(OUTPUT)/nk_forward.skel.h $(BPFOBJ)
+$(OUTPUT)/nk_forward: CFLAGS += $(CCINCLUDE) -I$(OUTPUT)
+$(OUTPUT)/nk_forward: LDLIBS += $(BPFOBJ) -lelf -lz
+
+$(OUTPUT)/nk_forward.skel.h: $(OUTPUT)/nk_forward.bpf.o
+ bpftool gen skeleton $< name nk_forward > $@
diff --git a/tools/testing/selftests/drivers/net/hw/nk_forward.bpf.c b/tools/testing/selftests/drivers/net/hw/nk_forward.bpf.c
new file mode 100644
index 000000000000..103b259d288a
--- /dev/null
+++ b/tools/testing/selftests/drivers/net/hw/nk_forward.bpf.c
@@ -0,0 +1,49 @@
+// SPDX-License-Identifier: GPL-2.0
+#include <linux/bpf.h>
+#include <linux/pkt_cls.h>
+#include <linux/if_ether.h>
+#include <linux/ipv6.h>
+#include <linux/in6.h>
+#include <bpf/bpf_endian.h>
+#include <bpf/bpf_helpers.h>
+
+#define TC_ACT_OK 0
+#define ETH_P_IPV6 0x86DD
+
+#define ctx_ptr(field) (void *)(long)(field)
+
+#define v6_p64_equal(a, b) (a.s6_addr32[0] == b.s6_addr32[0] && \
+ a.s6_addr32[1] == b.s6_addr32[1])
+
+volatile __u32 netkit_ifindex;
+volatile __u8 ipv6_prefix[16] __attribute__((aligned(4)));
+
+SEC("tc/ingress")
+int tc_redirect_peer(struct __sk_buff *skb)
+{
+ void *data_end = ctx_ptr(skb->data_end);
+ void *data = ctx_ptr(skb->data);
+ struct in6_addr *peer_addr;
+ struct ipv6hdr *ip6h;
+ struct ethhdr *eth;
+
+ peer_addr = (struct in6_addr *)ipv6_prefix;
+
+ if (skb->protocol != bpf_htons(ETH_P_IPV6))
+ return TC_ACT_OK;
+
+ eth = data;
+ if ((void *)(eth + 1) > data_end)
+ return TC_ACT_OK;
+
+ ip6h = data + sizeof(struct ethhdr);
+ if ((void *)(ip6h + 1) > data_end)
+ return TC_ACT_OK;
+
+ if (!v6_p64_equal(ip6h->daddr, (*peer_addr)))
+ return TC_ACT_OK;
+
+ return bpf_redirect_peer(netkit_ifindex, 0);
+}
+
+char __license[] SEC("license") = "GPL";
diff --git a/tools/testing/selftests/drivers/net/hw/nk_forward.c b/tools/testing/selftests/drivers/net/hw/nk_forward.c
new file mode 100644
index 000000000000..9519d20cd363
--- /dev/null
+++ b/tools/testing/selftests/drivers/net/hw/nk_forward.c
@@ -0,0 +1,102 @@
+// SPDX-License-Identifier: GPL-2.0
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include <unistd.h>
+#include <net/if.h>
+#include <arpa/inet.h>
+#include <netinet/in.h>
+#include <linux/in6.h>
+#include <linux/if_link.h>
+#include <bpf/libbpf.h>
+#include <bpf/bpf.h>
+
+#include "nk_forward.skel.h"
+
+static int libbpf_print_fn(enum libbpf_print_level level, const char *format, va_list args)
+{
+ return vfprintf(stderr, format, args);
+}
+
+static void usage(const char *prog)
+{
+ fprintf(stderr, "Usage: %s -n <netkit_ifindex> -e <eth0_ifindex> -i <ipv6_prefix>\n", prog);
+ fprintf(stderr, " -n netkit interface index\n");
+ fprintf(stderr, " -e eth0 interface index\n");
+ fprintf(stderr, " -i IPv6 prefix to match\n");
+ fprintf(stderr, " -h show this help\n");
+}
+
+int main(int argc, char **argv)
+{
+ unsigned int netkit_ifindex = 0;
+ const char *ipv6_prefix = NULL;
+ unsigned int eth0_ifindex = 0;
+ struct nk_forward *skel;
+ struct in6_addr ip6_addr;
+ struct bpf_link *link;
+ int opt, err, i;
+
+ while ((opt = getopt(argc, argv, "n:e:i:h")) != -1) {
+ switch (opt) {
+ case 'n':
+ netkit_ifindex = atoi(optarg);
+ break;
+ case 'e':
+ eth0_ifindex = atoi(optarg);
+ break;
+ case 'i':
+ ipv6_prefix = optarg;
+ break;
+ case 'h':
+ default:
+ usage(argv[0]);
+ return opt == 'h' ? 0 : 1;
+ }
+ }
+
+ if (!netkit_ifindex || !eth0_ifindex || !ipv6_prefix) {
+ fprintf(stderr, "Error: All options -n, -e, and -i are required\n\n");
+ usage(argv[0]);
+ return 1;
+ }
+
+ if (inet_pton(AF_INET6, ipv6_prefix, &ip6_addr) != 1) {
+ fprintf(stderr, "Error: Invalid IPv6 address: %s\n", ipv6_prefix);
+ return 1;
+ }
+
+ libbpf_set_print(libbpf_print_fn);
+ skel = nk_forward__open();
+ if (!skel) {
+ fprintf(stderr, "Error: Failed to open BPF skeleton\n");
+ return 1;
+ }
+
+ skel->bss->netkit_ifindex = netkit_ifindex;
+ memcpy((void *)&skel->bss->ipv6_prefix, &ip6_addr, sizeof(struct in6_addr));
+
+ err = nk_forward__load(skel);
+ if (err) {
+ fprintf(stderr, "Error: Failed to load BPF skeleton: %d\n", err);
+ goto cleanup;
+ }
+
+ LIBBPF_OPTS(bpf_tcx_opts, opts);
+ link = bpf_program__attach_tcx(skel->progs.tc_redirect_peer, eth0_ifindex, &opts);
+ if (!link) {
+ err = -errno;
+ fprintf(stderr, "Error: Failed to attach TC program to ifindex %u: %s\n",
+ eth0_ifindex, strerror(errno));
+ goto cleanup;
+ }
+
+ while (1)
+ sleep(1);
+
+cleanup:
+ bpf_link__destroy(link);
+ nk_forward__destroy(skel);
+ return err != 0;
+}
--
2.47.3
^ permalink raw reply related [flat|nested] 21+ messages in thread
* [PATCH net-next v1 6/7] selftests/net: add LOCAL_PREFIX_V{4,6} env to HW selftests
2025-11-20 3:30 [PATCH net-next v1 0/7] selftests/net: add netkit netns ping test David Wei
` (4 preceding siblings ...)
2025-11-20 3:30 ` [PATCH net-next v1 5/7] selftests/net: add bpf skb forwarding program David Wei
@ 2025-11-20 3:30 ` David Wei
2025-11-21 3:24 ` Jakub Kicinski
2025-11-20 3:30 ` [PATCH net-next v1 7/7] selftests/net: add a netkit netns ping test David Wei
6 siblings, 1 reply; 21+ messages in thread
From: David Wei @ 2025-11-20 3:30 UTC (permalink / raw)
To: netdev
Cc: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, Daniel Borkmann
Expect netkit container datapath selftests to have a publicly routable
IP prefix to assign to netkit in a container, such that packets will
land on eth0. The bpf skb forward program will then forward such packets
from the host netns to the container netns.
Signed-off-by: David Wei <dw@davidwei.uk>
---
tools/testing/selftests/drivers/net/README.rst | 6 ++++++
tools/testing/selftests/drivers/net/lib/py/env.py | 1 +
2 files changed, 7 insertions(+)
diff --git a/tools/testing/selftests/drivers/net/README.rst b/tools/testing/selftests/drivers/net/README.rst
index eb838ae94844..ea2d3538e228 100644
--- a/tools/testing/selftests/drivers/net/README.rst
+++ b/tools/testing/selftests/drivers/net/README.rst
@@ -62,6 +62,12 @@ LOCAL_V4, LOCAL_V6, REMOTE_V4, REMOTE_V6
Local and remote endpoint IP addresses.
+LOCAL_PREFIX_V6, LOCAL_PREFIX_V6
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+Local IP prefix that is publicly routable. Devices assigned with an address
+using this prefix can directly receive packets from a remote.
+
REMOTE_TYPE
~~~~~~~~~~~
diff --git a/tools/testing/selftests/drivers/net/lib/py/env.py b/tools/testing/selftests/drivers/net/lib/py/env.py
index 3e19b57ef5e0..ee427c2b2647 100644
--- a/tools/testing/selftests/drivers/net/lib/py/env.py
+++ b/tools/testing/selftests/drivers/net/lib/py/env.py
@@ -196,6 +196,7 @@ class NetDrvEpEnv(NetDrvEnvBase):
def _check_env(self):
vars_needed = [
["LOCAL_V4", "LOCAL_V6"],
+ ["LOCAL_PREFIX_V4", "LOCAL_PREFIX_V6"],
["REMOTE_V4", "REMOTE_V6"],
["REMOTE_TYPE"],
["REMOTE_ARGS"]
--
2.47.3
^ permalink raw reply related [flat|nested] 21+ messages in thread
* [PATCH net-next v1 7/7] selftests/net: add a netkit netns ping test
2025-11-20 3:30 [PATCH net-next v1 0/7] selftests/net: add netkit netns ping test David Wei
` (5 preceding siblings ...)
2025-11-20 3:30 ` [PATCH net-next v1 6/7] selftests/net: add LOCAL_PREFIX_V{4,6} env to HW selftests David Wei
@ 2025-11-20 3:30 ` David Wei
6 siblings, 0 replies; 21+ messages in thread
From: David Wei @ 2025-11-20 3:30 UTC (permalink / raw)
To: netdev
Cc: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, Daniel Borkmann
Set up a netkit pair, with one end in a netns. Use LOCAL_PREFIX_V6 and
nk_forward bpf prog to ping from a remote host to the netkit in netns.
Signed-off-by: David Wei <dw@davidwei.uk>
---
.../testing/selftests/drivers/net/hw/Makefile | 1 +
.../selftests/drivers/net/hw/nk_netns.py | 89 +++++++++++++++++++
2 files changed, 90 insertions(+)
create mode 100755 tools/testing/selftests/drivers/net/hw/nk_netns.py
diff --git a/tools/testing/selftests/drivers/net/hw/Makefile b/tools/testing/selftests/drivers/net/hw/Makefile
index 855363bc8d48..dfca39d1b99f 100644
--- a/tools/testing/selftests/drivers/net/hw/Makefile
+++ b/tools/testing/selftests/drivers/net/hw/Makefile
@@ -16,6 +16,7 @@ TEST_PROGS = \
irq.py \
loopback.sh \
nic_timestamp.py \
+ nk_netns.py \
pp_alloc_fail.py \
rss_api.py \
rss_ctx.py \
diff --git a/tools/testing/selftests/drivers/net/hw/nk_netns.py b/tools/testing/selftests/drivers/net/hw/nk_netns.py
new file mode 100755
index 000000000000..43b520ac5757
--- /dev/null
+++ b/tools/testing/selftests/drivers/net/hw/nk_netns.py
@@ -0,0 +1,89 @@
+#!/usr/bin/env python3
+# SPDX-License-Identifier: GPL-2.0
+
+import subprocess
+import time
+from os import path
+from lib.py import ksft_run, ksft_exit, KsftSkipEx, KsftFailEx
+from lib.py import NetNS, MemPrvEnv
+from lib.py import cmd, defer, ip, rand_ifname
+
+
+def attach(bin, netif_ifindex, nk_host_ifindex, ipv6_prefix):
+ cmd = [
+ bin,
+ "-n", str(nk_host_ifindex),
+ "-e", str(netif_ifindex),
+ "-i", ipv6_prefix
+ ]
+ try:
+ proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
+ time.sleep(0.5)
+ if proc.poll() is not None:
+ _, stderr = proc.communicate()
+ raise KsftFailEx(f"Failed to attach nk_forward BPF program: {stderr}")
+ return proc
+ except Exception as e:
+ raise KsftFailEx(f"Failed to attach nk_forward BPF program: {e}")
+
+
+def detach(proc):
+ if proc and proc.poll() is None:
+ try:
+ proc.terminate()
+ proc.wait(timeout=5)
+ except subprocess.TimeoutExpired:
+ proc.kill()
+ proc.wait()
+
+
+def test_netkit_ping(cfg) -> None:
+ cfg.require_ipver("6")
+
+ local_prefix = cfg.env.get("LOCAL_PREFIX_V6")
+ if not local_prefix:
+ raise KsftSkipEx("LOCAL_PREFIX_V6 required")
+
+ local_prefix = local_prefix.rstrip("/64").rstrip("::").rstrip(":")
+ ipv6_prefix = f"{local_prefix}::"
+
+ nk_host_ifname = rand_ifname()
+ nk_guest_ifname = rand_ifname()
+
+ ip(f"link add {nk_host_ifname} type netkit mode l2 forward peer forward {nk_guest_ifname}")
+ nk_host_info = ip(f"-d link show dev {nk_host_ifname}", json=True)[0]
+ nk_host_ifindex = nk_host_info["ifindex"]
+ nk_guest_info = ip(f"-d link show dev {nk_guest_ifname}", json=True)[0]
+ nk_guest_ifindex = nk_guest_info["ifindex"]
+
+ bpf_proc = attach(cfg.nk_forward_bin, cfg.ifindex, nk_host_ifindex, ipv6_prefix)
+ defer(detach, bpf_proc)
+
+ guest_ipv6 = f"{local_prefix}::2:1"
+ ip(f"link set dev {nk_host_ifname} up")
+ ip(f"-6 addr add fe80::1/64 dev {nk_host_ifname} nodad")
+ ip(f"-6 route add {guest_ipv6}/128 via fe80::2 dev {nk_host_ifname}")
+
+ with NetNS() as netns:
+ ip(f"link set dev {nk_guest_ifname} netns {netns.name}")
+
+ ip("link set lo up", ns=netns)
+ ip(f"link set dev {nk_guest_ifname} up", ns=netns)
+ ip(f"-6 addr add fe80::2 dev {nk_guest_ifname}", ns=netns)
+ ip(f"-6 addr add {guest_ipv6} dev {nk_guest_ifname} nodad", ns=netns)
+
+ ip(f"-6 route add default via fe80::1 dev {nk_guest_ifname}", ns=netns)
+
+ cmd(f"ping -c 1 -W5 {guest_ipv6}")
+ cmd(f"ping -c 1 -W5 {cfg.remote_addr_v['6']}", ns=netns)
+
+
+def main() -> None:
+ with MemPrvEnv(__file__) as cfg:
+ cfg.nk_forward_bin = path.abspath(path.dirname(__file__) + "/nk_forward")
+ ksft_run([test_netkit_ping], args=(cfg,))
+ ksft_exit()
+
+
+if __name__ == "__main__":
+ main()
--
2.47.3
^ permalink raw reply related [flat|nested] 21+ messages in thread
* Re: [PATCH net-next v1 1/7] selftests/net: add suffix to ksft_run
2025-11-20 3:30 ` [PATCH net-next v1 1/7] selftests/net: add suffix to ksft_run David Wei
@ 2025-11-21 3:13 ` Jakub Kicinski
2025-11-22 3:28 ` David Wei
0 siblings, 1 reply; 21+ messages in thread
From: Jakub Kicinski @ 2025-11-21 3:13 UTC (permalink / raw)
To: David Wei
Cc: netdev, Andrew Lunn, David S. Miller, Eric Dumazet, Paolo Abeni,
Daniel Borkmann
On Wed, 19 Nov 2025 19:30:10 -0800 David Wei wrote:
> I want to run the same test cases in slightly different environments
> (single queue vs RSS context). Add a suffix to ksft_run so it the
> different runs have different names.
Please TALL at 6ae67f115986734bc, does it help?
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH net-next v1 2/7] selftests/net: add MemPrvEnv env
2025-11-20 3:30 ` [PATCH net-next v1 2/7] selftests/net: add MemPrvEnv env David Wei
@ 2025-11-21 3:18 ` Jakub Kicinski
2025-11-21 17:14 ` David Wei
0 siblings, 1 reply; 21+ messages in thread
From: Jakub Kicinski @ 2025-11-21 3:18 UTC (permalink / raw)
To: David Wei
Cc: netdev, Andrew Lunn, David S. Miller, Eric Dumazet, Paolo Abeni,
Daniel Borkmann
On Wed, 19 Nov 2025 19:30:11 -0800 David Wei wrote:
> Memory provider HW selftests (i.e. zcrx, devmem) require setting up a
> netdev with e.g. flow steering rules. Add a new MemPrvEnv that sets up
> the test env, restoring it to the original state prior to the test. This
> also speeds up tests since each individual test case don't need to
> repeat the setup/teardown.
Hm, this feels a bit too specific to the particular use case.
I think we have a gap in terms of the Env classes for setting up
"a container" tests. Meaning - NetDrvEpEnv + an extra NetNs with
a netkit / veth. init net gets set up to forward traffic to and
from the netkit / veth with BPF or routing. And the container
needs its own IP address from a new set of params.
I think that's the extent of the setup provided by the env.
We can then reuse the env for all "container+offload" cases.
The rest belongs in each test module.
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH net-next v1 4/7] selftests/net: add rand_ifname() helper
2025-11-20 3:30 ` [PATCH net-next v1 4/7] selftests/net: add rand_ifname() helper David Wei
@ 2025-11-21 3:19 ` Jakub Kicinski
2025-11-21 17:19 ` David Wei
0 siblings, 1 reply; 21+ messages in thread
From: Jakub Kicinski @ 2025-11-21 3:19 UTC (permalink / raw)
To: David Wei
Cc: netdev, Andrew Lunn, David S. Miller, Eric Dumazet, Paolo Abeni,
Daniel Borkmann
On Wed, 19 Nov 2025 19:30:13 -0800 David Wei wrote:
> For upcoming netkit container datapath selftests I want to generate
> randomised ifnames. Add a helper rand_ifname() to do this.
The kernel will generate a name automatically, why do we need to create
a specific one?
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH net-next v1 5/7] selftests/net: add bpf skb forwarding program
2025-11-20 3:30 ` [PATCH net-next v1 5/7] selftests/net: add bpf skb forwarding program David Wei
@ 2025-11-21 3:20 ` Jakub Kicinski
2025-11-21 17:40 ` David Wei
0 siblings, 1 reply; 21+ messages in thread
From: Jakub Kicinski @ 2025-11-21 3:20 UTC (permalink / raw)
To: David Wei
Cc: netdev, Andrew Lunn, David S. Miller, Eric Dumazet, Paolo Abeni,
Daniel Borkmann
On Wed, 19 Nov 2025 19:30:14 -0800 David Wei wrote:
> This is needed for netkit container datapath selftests. Add two things:
>
> 1. nk_forward.bpf.c, a bpf program that forwards skbs matching some
> IPv6 prefix received on eth0 ifindex to a specified netkit ifindex.
> 2. nk_forward.c, a C loader program that accepts eth0/netkit ifindex
> and IPv6 prefix.
>
> Selftests will load and unload this bpf program via the loader.
Is the skel stuff necessary? For XDP we populate the map with bpftool.
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH net-next v1 6/7] selftests/net: add LOCAL_PREFIX_V{4,6} env to HW selftests
2025-11-20 3:30 ` [PATCH net-next v1 6/7] selftests/net: add LOCAL_PREFIX_V{4,6} env to HW selftests David Wei
@ 2025-11-21 3:24 ` Jakub Kicinski
2025-11-21 17:19 ` David Wei
0 siblings, 1 reply; 21+ messages in thread
From: Jakub Kicinski @ 2025-11-21 3:24 UTC (permalink / raw)
To: David Wei
Cc: netdev, Andrew Lunn, David S. Miller, Eric Dumazet, Paolo Abeni,
Daniel Borkmann
On Wed, 19 Nov 2025 19:30:15 -0800 David Wei wrote:
> +LOCAL_PREFIX_V6, LOCAL_PREFIX_V6
> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
I suppose one of these was supposed to say 4?
> +Local IP prefix that is publicly routable. Devices assigned with an address
> +using this prefix can directly receive packets from a remote.
How about this:
Local IP prefix/subnet which can be used to allocate extra IP addresses
(for network name spaces behind macvlan, veth, netkit devices).
DUT must be reachable using these addresses from the endpoint.
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH net-next v1 2/7] selftests/net: add MemPrvEnv env
2025-11-21 3:18 ` Jakub Kicinski
@ 2025-11-21 17:14 ` David Wei
2025-11-22 1:41 ` Jakub Kicinski
0 siblings, 1 reply; 21+ messages in thread
From: David Wei @ 2025-11-21 17:14 UTC (permalink / raw)
To: Jakub Kicinski
Cc: netdev, Andrew Lunn, David S. Miller, Eric Dumazet, Paolo Abeni,
Daniel Borkmann
On 2025-11-20 19:18, Jakub Kicinski wrote:
> On Wed, 19 Nov 2025 19:30:11 -0800 David Wei wrote:
>> Memory provider HW selftests (i.e. zcrx, devmem) require setting up a
>> netdev with e.g. flow steering rules. Add a new MemPrvEnv that sets up
>> the test env, restoring it to the original state prior to the test. This
>> also speeds up tests since each individual test case don't need to
>> repeat the setup/teardown.
>
> Hm, this feels a bit too specific to the particular use case.
> I think we have a gap in terms of the Env classes for setting up
> "a container" tests. Meaning - NetDrvEpEnv + an extra NetNs with
> a netkit / veth. init net gets set up to forward traffic to and
> from the netkit / veth with BPF or routing. And the container
> needs its own IP address from a new set of params.
>
> I think that's the extent of the setup provided by the env.
> We can then reuse the env for all "container+offload" cases.
> The rest belongs in each test module.
Got it. You'd like me to basically reverse the current env setup. Move
the netns, netkit/veth setup, bpf forwarding using the new LOCAL_PREFIX
env var etc into the env setup. Move the NIC queue stuff back out into
helpers and call it from the test module.
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH net-next v1 6/7] selftests/net: add LOCAL_PREFIX_V{4,6} env to HW selftests
2025-11-21 3:24 ` Jakub Kicinski
@ 2025-11-21 17:19 ` David Wei
0 siblings, 0 replies; 21+ messages in thread
From: David Wei @ 2025-11-21 17:19 UTC (permalink / raw)
To: Jakub Kicinski
Cc: netdev, Andrew Lunn, David S. Miller, Eric Dumazet, Paolo Abeni,
Daniel Borkmann
On 2025-11-20 19:24, Jakub Kicinski wrote:
> On Wed, 19 Nov 2025 19:30:15 -0800 David Wei wrote:
>> +LOCAL_PREFIX_V6, LOCAL_PREFIX_V6
>> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
> I suppose one of these was supposed to say 4?
Oops, yes. Thanks, will correct.
>
>> +Local IP prefix that is publicly routable. Devices assigned with an address
>> +using this prefix can directly receive packets from a remote.
>
> How about this:
>
> Local IP prefix/subnet which can be used to allocate extra IP addresses
> (for network name spaces behind macvlan, veth, netkit devices).
> DUT must be reachable using these addresses from the endpoint.
Sounds good.
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH net-next v1 4/7] selftests/net: add rand_ifname() helper
2025-11-21 3:19 ` Jakub Kicinski
@ 2025-11-21 17:19 ` David Wei
0 siblings, 0 replies; 21+ messages in thread
From: David Wei @ 2025-11-21 17:19 UTC (permalink / raw)
To: Jakub Kicinski
Cc: netdev, Andrew Lunn, David S. Miller, Eric Dumazet, Paolo Abeni,
Daniel Borkmann
On 2025-11-20 19:19, Jakub Kicinski wrote:
> On Wed, 19 Nov 2025 19:30:13 -0800 David Wei wrote:
>> For upcoming netkit container datapath selftests I want to generate
>> randomised ifnames. Add a helper rand_ifname() to do this.
>
> The kernel will generate a name automatically, why do we need to create
> a specific one?
Hmm, yeah good point. Was overthinking it I think about clashing with
the DUT. Will remove.
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH net-next v1 5/7] selftests/net: add bpf skb forwarding program
2025-11-21 3:20 ` Jakub Kicinski
@ 2025-11-21 17:40 ` David Wei
2025-11-22 1:36 ` Jakub Kicinski
0 siblings, 1 reply; 21+ messages in thread
From: David Wei @ 2025-11-21 17:40 UTC (permalink / raw)
To: Jakub Kicinski
Cc: netdev, Andrew Lunn, David S. Miller, Eric Dumazet, Paolo Abeni,
Daniel Borkmann
On 2025-11-20 19:20, Jakub Kicinski wrote:
> On Wed, 19 Nov 2025 19:30:14 -0800 David Wei wrote:
>> This is needed for netkit container datapath selftests. Add two things:
>>
>> 1. nk_forward.bpf.c, a bpf program that forwards skbs matching some
>> IPv6 prefix received on eth0 ifindex to a specified netkit ifindex.
>> 2. nk_forward.c, a C loader program that accepts eth0/netkit ifindex
>> and IPv6 prefix.
>>
>> Selftests will load and unload this bpf program via the loader.
>
> Is the skel stuff necessary? For XDP we populate the map with bpftool.
I have no idea what I'm doing with bpf and was copying from
libbpf-bootstrap :D I'll use bpftool to attach the bpf prog to tc
ingress + set the vars. If xdp is using bpftool then I presume it is
already a dependency on the DUT?
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH net-next v1 5/7] selftests/net: add bpf skb forwarding program
2025-11-21 17:40 ` David Wei
@ 2025-11-22 1:36 ` Jakub Kicinski
0 siblings, 0 replies; 21+ messages in thread
From: Jakub Kicinski @ 2025-11-22 1:36 UTC (permalink / raw)
To: David Wei
Cc: netdev, Andrew Lunn, David S. Miller, Eric Dumazet, Paolo Abeni,
Daniel Borkmann
On Fri, 21 Nov 2025 09:40:56 -0800 David Wei wrote:
> On 2025-11-20 19:20, Jakub Kicinski wrote:
> > On Wed, 19 Nov 2025 19:30:14 -0800 David Wei wrote:
> >> This is needed for netkit container datapath selftests. Add two things:
> >>
> >> 1. nk_forward.bpf.c, a bpf program that forwards skbs matching some
> >> IPv6 prefix received on eth0 ifindex to a specified netkit ifindex.
> >> 2. nk_forward.c, a C loader program that accepts eth0/netkit ifindex
> >> and IPv6 prefix.
> >>
> >> Selftests will load and unload this bpf program via the loader.
> >
> > Is the skel stuff necessary? For XDP we populate the map with bpftool.
>
> I have no idea what I'm doing with bpf and was copying from
> libbpf-bootstrap :D I'll use bpftool to attach the bpf prog to tc
> ingress + set the vars. If xdp is using bpftool then I presume it is
> already a dependency on the DUT?
Yes, FWIW tools/testing/selftests/drivers/net/xdp.py is what I meant by
XDP
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH net-next v1 2/7] selftests/net: add MemPrvEnv env
2025-11-21 17:14 ` David Wei
@ 2025-11-22 1:41 ` Jakub Kicinski
2025-11-22 2:24 ` David Wei
0 siblings, 1 reply; 21+ messages in thread
From: Jakub Kicinski @ 2025-11-22 1:41 UTC (permalink / raw)
To: David Wei
Cc: netdev, Andrew Lunn, David S. Miller, Eric Dumazet, Paolo Abeni,
Daniel Borkmann
On Fri, 21 Nov 2025 09:14:49 -0800 David Wei wrote:
> On 2025-11-20 19:18, Jakub Kicinski wrote:
> > On Wed, 19 Nov 2025 19:30:11 -0800 David Wei wrote:
> >> Memory provider HW selftests (i.e. zcrx, devmem) require setting up a
> >> netdev with e.g. flow steering rules. Add a new MemPrvEnv that sets up
> >> the test env, restoring it to the original state prior to the test. This
> >> also speeds up tests since each individual test case don't need to
> >> repeat the setup/teardown.
> >
> > Hm, this feels a bit too specific to the particular use case.
> > I think we have a gap in terms of the Env classes for setting up
> > "a container" tests. Meaning - NetDrvEpEnv + an extra NetNs with
> > a netkit / veth. init net gets set up to forward traffic to and
> > from the netkit / veth with BPF or routing. And the container
> > needs its own IP address from a new set of params.
> >
> > I think that's the extent of the setup provided by the env.
> > We can then reuse the env for all "container+offload" cases.
> > The rest belongs in each test module.
>
> Got it. You'd like me to basically reverse the current env setup.
🤔️ not sure
> Move the netns, netkit/veth setup, bpf forwarding using the new
> LOCAL_PREFIX env var etc into the env setup.
Yes to that, I think.
> Move the NIC queue stuff back out into helpers and call it from the
> test module.
Don't go too hard on the helpers, tho. "code reuse" is explicitly
an anti-goal for selftests. I really don't want net/lib/py
to become a framework folks must learn to understand or debug tests.
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH net-next v1 2/7] selftests/net: add MemPrvEnv env
2025-11-22 1:41 ` Jakub Kicinski
@ 2025-11-22 2:24 ` David Wei
0 siblings, 0 replies; 21+ messages in thread
From: David Wei @ 2025-11-22 2:24 UTC (permalink / raw)
To: Jakub Kicinski
Cc: netdev, Andrew Lunn, David S. Miller, Eric Dumazet, Paolo Abeni,
Daniel Borkmann
On 2025-11-21 17:41, Jakub Kicinski wrote:
> On Fri, 21 Nov 2025 09:14:49 -0800 David Wei wrote:
>> On 2025-11-20 19:18, Jakub Kicinski wrote:
>>> On Wed, 19 Nov 2025 19:30:11 -0800 David Wei wrote:
>>>> Memory provider HW selftests (i.e. zcrx, devmem) require setting up a
>>>> netdev with e.g. flow steering rules. Add a new MemPrvEnv that sets up
>>>> the test env, restoring it to the original state prior to the test. This
>>>> also speeds up tests since each individual test case don't need to
>>>> repeat the setup/teardown.
>>>
>>> Hm, this feels a bit too specific to the particular use case.
>>> I think we have a gap in terms of the Env classes for setting up
>>> "a container" tests. Meaning - NetDrvEpEnv + an extra NetNs with
>>> a netkit / veth. init net gets set up to forward traffic to and
>>> from the netkit / veth with BPF or routing. And the container
>>> needs its own IP address from a new set of params.
>>>
>>> I think that's the extent of the setup provided by the env.
>>> We can then reuse the env for all "container+offload" cases.
>>> The rest belongs in each test module.
>>
>> Got it. You'd like me to basically reverse the current env setup.
>
> 🤔️ not sure
>
>> Move the netns, netkit/veth setup, bpf forwarding using the new
>> LOCAL_PREFIX env var etc into the env setup.
>
> Yes to that, I think.
>
>> Move the NIC queue stuff back out into helpers and call it from the
>> test module.
>
> Don't go too hard on the helpers, tho. "code reuse" is explicitly
> an anti-goal for selftests. I really don't want net/lib/py
> to become a framework folks must learn to understand or debug tests.
Okay, understood. I'll use helpers judiciously.
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH net-next v1 1/7] selftests/net: add suffix to ksft_run
2025-11-21 3:13 ` Jakub Kicinski
@ 2025-11-22 3:28 ` David Wei
0 siblings, 0 replies; 21+ messages in thread
From: David Wei @ 2025-11-22 3:28 UTC (permalink / raw)
To: Jakub Kicinski
Cc: netdev, Andrew Lunn, David S. Miller, Eric Dumazet, Paolo Abeni,
Daniel Borkmann
On 2025-11-20 19:13, Jakub Kicinski wrote:
> On Wed, 19 Nov 2025 19:30:10 -0800 David Wei wrote:
>> I want to run the same test cases in slightly different environments
>> (single queue vs RSS context). Add a suffix to ksft_run so it the
>> different runs have different names.
>
> Please TALL at 6ae67f115986734bc, does it help?
Yes. :ChefKiss:
^ permalink raw reply [flat|nested] 21+ messages in thread
end of thread, other threads:[~2025-11-22 3:29 UTC | newest]
Thread overview: 21+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-20 3:30 [PATCH net-next v1 0/7] selftests/net: add netkit netns ping test David Wei
2025-11-20 3:30 ` [PATCH net-next v1 1/7] selftests/net: add suffix to ksft_run David Wei
2025-11-21 3:13 ` Jakub Kicinski
2025-11-22 3:28 ` David Wei
2025-11-20 3:30 ` [PATCH net-next v1 2/7] selftests/net: add MemPrvEnv env David Wei
2025-11-21 3:18 ` Jakub Kicinski
2025-11-21 17:14 ` David Wei
2025-11-22 1:41 ` Jakub Kicinski
2025-11-22 2:24 ` David Wei
2025-11-20 3:30 ` [PATCH net-next v1 3/7] selftests/net: modify iou-zcrx.py to use MemPrvEnv David Wei
2025-11-20 3:30 ` [PATCH net-next v1 4/7] selftests/net: add rand_ifname() helper David Wei
2025-11-21 3:19 ` Jakub Kicinski
2025-11-21 17:19 ` David Wei
2025-11-20 3:30 ` [PATCH net-next v1 5/7] selftests/net: add bpf skb forwarding program David Wei
2025-11-21 3:20 ` Jakub Kicinski
2025-11-21 17:40 ` David Wei
2025-11-22 1:36 ` Jakub Kicinski
2025-11-20 3:30 ` [PATCH net-next v1 6/7] selftests/net: add LOCAL_PREFIX_V{4,6} env to HW selftests David Wei
2025-11-21 3:24 ` Jakub Kicinski
2025-11-21 17:19 ` David Wei
2025-11-20 3:30 ` [PATCH net-next v1 7/7] selftests/net: add a netkit netns ping test David Wei
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).