psp: add a kselftest suite and netdevsim implementation
Subsystems (4)
v2 cover psp: add a kselftest suite and netdevsim implementation
Add a basic test suite for drivers that support PSP. Also, add a PSP implementation in the netdevsim driver.
The netdevsim implementation does encapsulation and decapsulation of PSP packets, but no crypto.
The tests cover the basic usage of the uapi, and demonstrate key exchange and connection setup. The tests and netdevsim support IPv4 and IPv6. Here is an example run on a system with a CX7 NIC.
TAP version 13
1..28
ok 1 psp.data_basic_send_v0_ip4
ok 2 psp.data_basic_send_v0_ip6
ok 3 psp.data_basic_send_v1_ip4
ok 4 psp.data_basic_send_v1_ip6
ok 5 psp.data_basic_send_v2_ip4 # SKIP ('PSP version not supported', 'hdr0-aes-gmac-128') ok 6 psp.data_basic_send_v2_ip6 # SKIP ('PSP version not supported', 'hdr0-aes-gmac-128') ok 7 psp.data_basic_send_v3_ip4 # SKIP ('PSP version not supported', 'hdr0-aes-gmac-256') ok 8 psp.data_basic_send_v3_ip6 # SKIP ('PSP version not supported', 'hdr0-aes-gmac-256') ok 9 psp.data_mss_adjust_ip4
ok 10 psp.data_mss_adjust_ip6
ok 11 psp.dev_list_devices
ok 12 psp.dev_get_device
ok 13 psp.dev_get_device_bad
ok 14 psp.dev_rotate
ok 15 psp.dev_rotate_spi
ok 16 psp.assoc_basic
ok 17 psp.assoc_bad_dev
ok 18 psp.assoc_sk_only_conn
ok 19 psp.assoc_sk_only_mismatch
ok 20 psp.assoc_sk_only_mismatch_tx
ok 21 psp.assoc_sk_only_unconn
ok 22 psp.assoc_version_mismatch
ok 23 psp.assoc_twice
ok 24 psp.data_send_bad_key
ok 25 psp.data_send_disconnect
ok 26 psp.data_stale_key
ok 27 psp.removal_device_rx # XFAIL Test only works on netdevsim
ok 28 psp.removal_device_bi # XFAIL Test only works on netdevsim
# Totals: pass:22 fail:0 xfail:2 xpass:0 skip:4 error:0
#
# Responder logs (0):
# STDERR:
# Set PSP enable on device 1 to 0x3
# Set PSP enable on device 1 to 0x0
CHANGES:
v2:
- fix pylint warnings
- insert CONFIG_INET_PSP in alphebetical order
- use branch to skip all tests
- fix compilation error when CONFIG_INET_PSP is not set
v1: https://lore.kernel.org/netdev/[email protected]/
Jakub Kicinski (8):
netdevsim: a basic test PSP implementation
selftests: drv-net: base device access API test
selftests: drv-net: add PSP responder
selftests: drv-net: psp: add basic data transfer and key rotation
tests
selftests: drv-net: psp: add association tests
selftests: drv-net: psp: add connection breaking tests
selftests: drv-net: psp: add test for auto-adjusting TCP MSS
selftests: drv-net: psp: add tests for destroying devices
drivers/net/netdevsim/Makefile | 4 + drivers/net/netdevsim/netdev.c | 55 +- drivers/net/netdevsim/netdevsim.h | 33 + drivers/net/netdevsim/psp.c | 234 +++++++ net/core/skbuff.c | 1 + .../testing/selftests/drivers/net/.gitignore | 1 + tools/testing/selftests/drivers/net/Makefile | 10 + tools/testing/selftests/drivers/net/config | 1 + .../drivers/net/hw/lib/py/__init__.py | 4 +- .../selftests/drivers/net/lib/py/__init__.py | 4 +- .../selftests/drivers/net/lib/py/env.py | 5 + tools/testing/selftests/drivers/net/psp.py | 593 ++++++++++++++++++ .../selftests/drivers/net/psp_responder.c | 483 ++++++++++++++ .../testing/selftests/net/lib/py/__init__.py | 2 +- tools/testing/selftests/net/lib/py/ksft.py | 10 + tools/testing/selftests/net/lib/py/ynl.py | 5 + 16 files changed, 1432 insertions(+), 13 deletions(-) create mode 100644 drivers/net/netdevsim/psp.c create mode 100755 tools/testing/selftests/drivers/net/psp.py create mode 100644 tools/testing/selftests/drivers/net/psp_responder.c
Signature · 1 line
2.47.3
PATCH v2 1/8 netdevsim: a basic test PSP implementation
From: Jakub Kicinski <[email protected]>
Provide a PSP implementation for netdevsim.
Use psp_dev_encapsulate() and psp_dev_rcv() to do actual encapsulation and decapsulation on skbs, but perform no encryption or decryption. In order to make encryption with a bad key result in a drop on the peer's rx side, we stash our psd's generation number in the first byte of each key before handing to the peer.
---
Notes:
v2:
- fix compilation error when CONFIG_INET_PSP is not set
drivers/net/netdevsim/Makefile | 4 + drivers/net/netdevsim/netdev.c | 55 ++++++- drivers/net/netdevsim/netdevsim.h | 33 +++++ drivers/net/netdevsim/psp.c | 234 ++++++++++++++++++++++++++++++ net/core/skbuff.c | 1 + 5 files changed, 319 insertions(+), 8 deletions(-) create mode 100644 drivers/net/netdevsim/psp.c
drivers/net/netdevsim/Makefile +4 -0
@@ -18,6 +18,10 @@ ifneq ($(CONFIG_PSAMPLE),) netdevsim-objs += psample.o endif +ifneq ($(CONFIG_INET_PSP),) +netdevsim-objs += psp.o +endif + ifneq ($(CONFIG_MACSEC),) netdevsim-objs += macsec.o endif
drivers/net/netdevsim/netdev.c +47 -8
115 lines not on this page · raw message
drivers/net/netdevsim/netdevsim.h +33 -0
@@ -108,6 +108,12 @@ struct netdevsim {int rq_reset_mode; +struct { +struct psp_dev *dev; +u32 spi; +u32 assoc_cnt; + } psp; +struct nsim_bus_dev *nsim_bus_dev;struct bpf_prog *bpf_offloaded;
@@ -421,6 +427,33 @@ static inline void nsim_macsec_teardown(struct netdevsim *ns) }#endif +#if IS_ENABLED (CONFIG_INET_PSP ) +int nsim_psp_init (struct netdevsim *ns); +void nsim_psp_uninit (struct netdevsim *ns); +bool nsim_tx_skb_is_psp (struct sk_buff *skb); +void nsim_psp_handle_ext (struct sk_buff *skb,struct skb_ext *psp_ext); +enum skb_drop_reason +nsim_do_psp (struct sk_buff *skb,struct netdevsim *ns, +struct netdevsim *peer_ns,struct skb_ext **psp_ext); +#else +static inline int nsim_psp_init (struct netdevsim *ns) {return 0 ; } +static inline void nsim_psp_uninit (struct netdevsim *ns) {} +static inline enum skb_drop_reason +nsim_do_psp (struct sk_buff *skb,struct netdevsim *ns, +struct netdevsim *peer_ns,struct skb_ext **psp_ext) +{ +return 0 ; +} + +static inline bool nsim_tx_skb_is_psp (struct sk_buff *skb) +{ +return false; +} + +static inline void +nsim_psp_handle_ext (struct sk_buff *skb,struct skb_ext *psp_ext) {} +#endif +struct nsim_bus_dev {struct device dev;struct list_head list;
drivers/net/netdevsim/psp.c new file +234 -0
234 lines not on this page · raw message
net/core/skbuff.c +1 -0
@@ -7048,6 +7048,7 @@ void *__skb_ext_set(struct sk_buff *skb, enum skb_ext_id id, skb->active_extensions =1 << id;return skb_ext_get_ptr (ext, id); } +EXPORT_SYMBOL_NS_GPL (__skb_ext_set,"NETDEV_INTERNAL" );/** * skb_ext_add - allocate space for given extension, COW if needed
Signature · 1 line
2.47.3
PATCH v2 2/8 selftests: drv-net: base device access API test
In reply to Daniel ZahkaFrom: Jakub Kicinski <[email protected]>
Simple PSP test to getting info about PSP devices.
---
Notes:
v2:
- insert CONFIG_INET_PSP in alphebetical order
- use branch to skip all tests
tools/testing/selftests/drivers/net/Makefile | 1 + tools/testing/selftests/drivers/net/config | 1 + .../drivers/net/hw/lib/py/__init__.py | 2 +- .../selftests/drivers/net/lib/py/__init__.py | 2 +- tools/testing/selftests/drivers/net/psp.py | 70 +++++++++++++++++++ .../testing/selftests/net/lib/py/__init__.py | 2 +- tools/testing/selftests/net/lib/py/ynl.py | 5 ++ 7 files changed, 80 insertions(+), 3 deletions(-) create mode 100755 tools/testing/selftests/drivers/net/psp.py
tools/testing/selftests/drivers/net/Makefile +1 -0
@@ -19,6 +19,7 @@ TEST_PROGS := \ netcons_sysdata.sh \ netpoll_basic.py \ ping.py \ + psp.py \ queues.py \ stats.py \ shaper.py \
tools/testing/selftests/drivers/net/config +1 -0
@@ -1,3 +1,4 @@ +CONFIG_INET_PSP=y CONFIG_IPV6=y CONFIG_NETDEVSIM=m CONFIG_CONFIGFS_FS=y
tools/testing/selftests/drivers/net/hw/lib/py/__init__.py +1 -1
@@ -13,7 +13,7 @@ try: # Import one by one to avoid pylint false positives from net.lib.py import EthtoolFamily, NetdevFamily, NetshaperFamily, \ - NlError, RtnlFamily, DevlinkFamily + NlError, RtnlFamily, DevlinkFamily, PSPFamily from net.lib.py import CmdExitFailure from net.lib.py import bkg, cmd, defer, ethtool, fd_read_timeout, ip, \ rand_port, tool, wait_port_listen
tools/testing/selftests/drivers/net/lib/py/__init__.py +1 -1
@@ -12,7 +12,7 @@ try: # Import one by one to avoid pylint false positives from net.lib.py import EthtoolFamily, NetdevFamily, NetshaperFamily, \ - NlError, RtnlFamily, DevlinkFamily + 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, tool, wait_port_listen, wait_file
tools/testing/selftests/drivers/net/psp.py new file +70 -0
70 lines not on this page · raw message
tools/testing/selftests/net/lib/py/__init__.py +1 -1
@@ -6,4 +6,4 @@ from .netns import NetNS, NetNSEnter from .nsim import * from .utils import * from .ynl import NlError, YnlFamily, EthtoolFamily, NetdevFamily, RtnlFamily, RtnlAddrFamily -from .ynl import NetshaperFamily, DevlinkFamily +from .ynl import NetshaperFamily, DevlinkFamily, PSPFamily
tools/testing/selftests/net/lib/py/ynl.py +5 -0
@@ -61,3 +61,8 @@ class DevlinkFamily(YnlFamily): def __init__(self, recv_size=0): super().__init__((SPEC_PATH / Path('devlink.yaml')).as_posix(), schema='', recv_size=recv_size) + +class PSPFamily(YnlFamily): + def __init__(self, recv_size=0): + super().__init__((SPEC_PATH / Path('psp.yaml')).as_posix(), + schema='', recv_size=recv_size)
Signature · 1 line
2.47.3
PATCH v2 3/8 selftests: drv-net: add PSP responder
In reply to Daniel ZahkaFrom: Jakub Kicinski <[email protected]>
PSP tests need the remote system to support PSP, and some PSP capable application to exchange data with. Create a simple PSP responder app which we can build and deploy to the remote host. The tests themselves can be written in Python but for ease of deploying the responder is in C (using C YNL).
--- .../testing/selftests/drivers/net/.gitignore | 1 + tools/testing/selftests/drivers/net/Makefile | 9 + .../selftests/drivers/net/psp_responder.c | 483 ++++++++++++++++++ 3 files changed, 493 insertions(+) create mode 100644 tools/testing/selftests/drivers/net/psp_responder.c
tools/testing/selftests/drivers/net/.gitignore +1 -0
@@ -1,2 +1,3 @@ # SPDX-License-Identifier: GPL-2.0-only napi_id_helper +psp_responder
tools/testing/selftests/drivers/net/Makefile +9 -0
@@ -27,4 +27,13 @@ TEST_PROGS := \ xdp.py \ # end of TEST_PROGS +# YNL files, must be before "include ..lib.mk" +YNL_GEN_FILES := psp_responder +TEST_GEN_FILES += $(YNL_GEN_FILES) + include ../../lib.mk + +# YNL build +YNL_GENS := psp + +include ../../net/ynl.mk
tools/testing/selftests/drivers/net/psp_responder.c new file +483 -0
483 lines not on this page · raw message
Signature · 1 line
2.47.3
PATCH v2 4/8 selftests: drv-net: psp: add basic data transfer and key rotation tests
In reply to Daniel ZahkaFrom: Jakub Kicinski <[email protected]>
Add basic tests for sending data over PSP and making sure that key rotation toggles the MSB of the spi.
Deploy PSP responder on the remote end. We also need a healthy dose of common helpers for setting up the connections, assertions and interrogating socket state on the Python side.
--- tools/testing/selftests/drivers/net/psp.py | 195 ++++++++++++++++++++- 1 file changed, 191 insertions(+), 4 deletions(-)
tools/testing/selftests/drivers/net/psp.py +191 -4
@@ -3,9 +3,94 @@ """Test suite for PSP capable drivers.""" +import fcntl +import socket +import struct +import termios +import time + from lib.py import ksft_run, ksft_exit, ksft_pr -from lib.py import ksft_true, ksft_eq +from lib.py import ksft_true, ksft_eq, ksft_ne, ksft_raises, KsftSkipEx from lib.py import NetDrvEpEnv, PSPFamily, NlError +from lib.py import bkg, rand_port, wait_port_listen + + +def _get_outq(s): + one = b'\0' * 4 + outq = fcntl.ioctl(s.fileno(), termios.TIOCOUTQ, one) + return struct.unpack("I", outq)[0] + + +def _send_with_ack(cfg, msg): + cfg.comm_sock.send(msg) + response = cfg.comm_sock.recv(4) + if response != b'ack\0': + raise RuntimeError("Unexpected server response", response) + + +def _remote_read_len(cfg): + cfg.comm_sock.send(b'read len\0') + return int(cfg.comm_sock.recv(1024)[:-1].decode('utf-8')) + + +def _make_psp_conn(cfg, version=0, ipver=None): + _send_with_ack(cfg, b'conn psp\0' + struct.pack('BB', version, version)) + remote_addr = cfg.remote_addr_v[ipver] if ipver else cfg.remote_addr + s = socket.create_connection((remote_addr, cfg.comm_port), ) + return s + + +def _close_conn(cfg, s): + _send_with_ack(cfg, b'data close\0') + s.close() + + +def _close_psp_conn(cfg, s): + _close_conn(cfg, s) + + +def _spi_xchg(s, rx): + s.send(struct.pack('I', rx['spi']) + rx['key']) + tx = s.recv(4 + len(rx['key'])) + return { + 'spi': struct.unpack('I', tx[:4])[0], + 'key': tx[4:] + } + + +def _send_careful(cfg, s, rounds): + data = b'0123456789' * 200 + for i in range(rounds): + n = 0 + retries = 0 + while True: + try: + n += s.send(data[n:], socket.MSG_DONTWAIT) + if n == len(data): + break + except BlockingIOError: + time.sleep(0.05) + + retries += 1 + if retries > 10: + rlen = _remote_read_len(cfg) + outq = _get_outq(s) + report = f'sent: {i * len(data) + n} remote len: {rlen} outq: {outq}' + if retries > 10: + raise RuntimeError(report) + + return len(data) * rounds + + +def _check_data_rx(cfg, exp_len): + read_len = -1 + for _ in range(30): + cfg.comm_sock.send(b'read len\0') + read_len = int(cfg.comm_sock.recv(1024)[:-1].decode('utf-8')) + if read_len == exp_len: + break + time.sleep(0.01) + ksft_eq(read_len, exp_len) # # Test cases
@@ -38,6 +123,75 @@ def dev_get_device_bad(cfg): ksft_true(raised) +def dev_rotate(cfg): + """ Test key rotation """ + rot = cfg.pspnl.key_rotate({"id": cfg.psp_dev_id}) + ksft_eq(rot['id'], cfg.psp_dev_id) + rot = cfg.pspnl.key_rotate({"id": cfg.psp_dev_id}) + ksft_eq(rot['id'], cfg.psp_dev_id) + + +def dev_rotate_spi(cfg): + """ Test key rotation and SPI check """ + top_a = top_b = 0 + with socket.socket(socket.AF_INET6, socket.SOCK_STREAM) as s: + assoc_a = cfg.pspnl.rx_assoc({"version": 0, + "dev-id": cfg.psp_dev_id, + "sock-fd": s.fileno()}) + top_a = assoc_a['rx-key']['spi'] >> 31 + s.close() + rot = cfg.pspnl.key_rotate({"id": cfg.psp_dev_id}) + with socket.socket(socket.AF_INET6, socket.SOCK_STREAM) as s: + ksft_eq(rot['id'], cfg.psp_dev_id) + assoc_b = cfg.pspnl.rx_assoc({"version": 0, + "dev-id": cfg.psp_dev_id, + "sock-fd": s.fileno()}) + top_b = assoc_b['rx-key']['spi'] >> 31 + s.close() + ksft_ne(top_a, top_b) + + +def _data_basic_send(cfg, version, ipver): + """ Test basic data send """ + # Version 0 is required by spec, don't let it skip + if version: + name = cfg.pspnl.consts["version"].entries_by_val[version].name + if name not in cfg.psp_supported_versions: + with socket.socket(socket.AF_INET6, socket.SOCK_STREAM) as s: + with ksft_raises(NlError) as cm: + cfg.pspnl.rx_assoc({"version": version, + "dev-id": cfg.psp_dev_id, + "sock-fd": s.fileno()}) + ksft_eq(cm.exception.nl_msg.error, -95) + raise KsftSkipEx("PSP version not supported", name) + + s = _make_psp_conn(cfg, version, ipver) + + rx_assoc = cfg.pspnl.rx_assoc({"version": version, + "dev-id": cfg.psp_dev_id, + "sock-fd": s.fileno()}) + rx = rx_assoc['rx-key'] + tx = _spi_xchg(s, rx) + + cfg.pspnl.tx_assoc({"dev-id": cfg.psp_dev_id, + "version": version, + "tx-key": tx, + "sock-fd": s.fileno()}) + + data_len = _send_careful(cfg, s, 100) + _check_data_rx(cfg, data_len) + _close_psp_conn(cfg, s) + + +def psp_ip_ver_test_builder(name, test_func, psp_ver, ipver): + """Build test cases for each combo of PSP version and IP version""" + def test_case(cfg): + cfg.require_ipver(ipver) + test_case.__name__ = f"{name}_v{psp_ver}_ip{ipver}" + test_func(cfg, psp_ver, ipver) + return test_case + + def main() -> None: with NetDrvEpEnv(__file__) as cfg: cfg.pspnl = PSPFamily()
@@ -55,14 +209,47 @@ def main() -> None: versions = info['psp-versions-ena'] cfg.pspnl.dev_set({"id": cfg.psp_dev_id, "psp-versions-ena": info['psp-versions-cap']}) + cfg.psp_supported_versions = info['psp-versions-cap'] + + # Set up responder and communication sock + responder = cfg.remote.deploy("psp_responder") + + cfg.comm_port = rand_port() + srv = None + try: + with bkg(responder + f" -p {cfg.comm_port}", host=cfg.remote, exit_wait=True) as srv: + wait_port_listen(cfg.comm_port, host=cfg.remote) + + cfg.comm_sock = socket.create_connection((cfg.remote_addr, + cfg.comm_port), timeout=1) + + cases = [ + psp_ip_ver_test_builder( + "data_basic_send", _data_basic_send, version, ipver + ) + for version in range(0, 4) + for ipver in ("4", "6") + ] if cfg.psp_dev_id is not None: - ksft_run(globs=globals(), case_pfx={"dev_",}, args=(cfg, )) + ksft_run(cases=cases, globs=globals(), case_pfx={"dev_",}, args=(cfg, )) else: ksft_pr("No PSP device found, skipping all tests") - if versions is not None: - cfg.pspnl.dev_set({"id": cfg.psp_dev_id, "psp-versions-ena": versions}) + cfg.comm_sock.send(b"exit\0") + cfg.comm_sock.close() + + if versions is not None: + cfg.pspnl.dev_set({"id": cfg.psp_dev_id, "psp-versions-ena": versions}) + + finally: + if srv and (srv.stdout or srv.stderr): + ksft_pr("") + ksft_pr(f"Responder logs ({srv.ret}):") + if srv and srv.stdout: + ksft_pr("STDOUT:\n# " + srv.stdout.strip().replace("\n", "\n# ")) + if srv and srv.stderr: + ksft_pr("STDERR:\n# " + srv.stderr.strip().replace("\n", "\n# ")) ksft_exit()
Signature · 1 line
2.47.3
PATCH v2 5/8 selftests: drv-net: psp: add association tests
In reply to Daniel ZahkaFrom: Jakub Kicinski <[email protected]>
Add tests for exercising PSP associations for TCP sockets.
--- .../drivers/net/hw/lib/py/__init__.py | 2 +- .../selftests/drivers/net/lib/py/__init__.py | 2 +- tools/testing/selftests/drivers/net/psp.py | 147 +++++++++++++++++- tools/testing/selftests/net/lib/py/ksft.py | 5 + 4 files changed, 152 insertions(+), 4 deletions(-)
tools/testing/selftests/drivers/net/hw/lib/py/__init__.py +1 -1
@@ -22,7 +22,7 @@ try: from net.lib.py import ksft_disruptive, ksft_exit, ksft_pr, ksft_run, \ ksft_setup 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_ne, ksft_not_in, ksft_raises, ksft_true, ksft_gt from net.lib.py import NetNSEnter from drivers.net.lib.py import GenerateTraffic from drivers.net.lib.py import NetDrvEnv, NetDrvEpEnv
tools/testing/selftests/drivers/net/lib/py/__init__.py +1 -1
@@ -21,7 +21,7 @@ try: from net.lib.py import ksft_disruptive, ksft_exit, ksft_pr, ksft_run, \ ksft_setup 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_ne, ksft_not_in, ksft_raises, ksft_true, ksft_gt except ModuleNotFoundError as e: ksft_pr("Failed importing `net` library from kernel sources") ksft_pr(str(e))
tools/testing/selftests/drivers/net/psp.py +145 -2
171 lines not on this page · raw message
tools/testing/selftests/net/lib/py/ksft.py +5 -0
@@ -92,6 +92,11 @@ def ksft_ge(a, b, comment=""): _fail("Check failed", a, "<", b, comment) +def ksft_gt(a, b, comment=""): + if a <= b: + _fail("Check failed", a, "<=", b, comment) + + def ksft_lt(a, b, comment=""): if a >= b: _fail("Check failed", a, ">=", b, comment)
Signature · 1 line
2.47.3
PATCH v2 6/8 selftests: drv-net: psp: add connection breaking tests
In reply to Daniel ZahkaFrom: Jakub Kicinski <[email protected]>
Add test checking conditions which lead to connections breaking. Using bad key or connection gets stuck if device key is rotated twice.
--- tools/testing/selftests/drivers/net/psp.py | 90 +++++++++++++++++++++- 1 file changed, 89 insertions(+), 1 deletion(-)
tools/testing/selftests/drivers/net/psp.py +89 -1
@@ -15,6 +15,10 @@ from lib.py import NetDrvEpEnv, PSPFamily, NlError from lib.py import bkg, rand_port, wait_port_listen +class PSPExceptShortIO(Exception): + pass + + def _get_outq(s): one = b'\0' * 4 outq = fcntl.ioctl(s.fileno(), termios.TIOCOUTQ, one)
@@ -99,6 +103,16 @@ def _check_data_rx(cfg, exp_len): time.sleep(0.01) ksft_eq(read_len, exp_len) + +def _check_data_outq(s, exp_len, force_wait=False): + outq = 0 + for _ in range(10): + outq = _get_outq(s) + if not force_wait and outq == exp_len: + break + time.sleep(0.01) + ksft_eq(outq, exp_len) + # # Test cases #
@@ -324,6 +338,80 @@ def _data_basic_send(cfg, version, ipver): _close_psp_conn(cfg, s) +def __bad_xfer_do(cfg, s, tx, version='hdr0-aes-gcm-128'): + # Make sure we accept the ACK for the SPI before we seal with the bad assoc + _check_data_outq(s, 0) + + cfg.pspnl.tx_assoc({"dev-id": cfg.psp_dev_id, + "version": version, + "tx-key": tx, + "sock-fd": s.fileno()}) + + data_len = _send_careful(cfg, s, 20) + _check_data_outq(s, data_len, force_wait=True) + _check_data_rx(cfg, 0) + _close_psp_conn(cfg, s) + + +def data_send_bad_key(cfg): + """ Test send data with bad key """ + s = _make_psp_conn(cfg) + + rx_assoc = cfg.pspnl.rx_assoc({"version": 0, + "dev-id": cfg.psp_dev_id, + "sock-fd": s.fileno()}) + rx = rx_assoc['rx-key'] + tx = _spi_xchg(s, rx) + tx['key'] = (tx['key'][0] ^ 0xff).to_bytes(1, 'little') + tx['key'][1:] + __bad_xfer_do(cfg, s, tx) + + +def data_send_disconnect(cfg): + """ Test socket close after sending data """ + with _make_psp_conn(cfg) as s: + assoc = cfg.pspnl.rx_assoc({"version": 0, + "sock-fd": s.fileno()}) + tx = _spi_xchg(s, assoc['rx-key']) + cfg.pspnl.tx_assoc({"version": 0, + "tx-key": tx, + "sock-fd": s.fileno()}) + + data_len = _send_careful(cfg, s, 100) + _check_data_rx(cfg, data_len) + + s.shutdown(socket.SHUT_RDWR) + s.close() + + +def data_stale_key(cfg): + """ Test send on a double-rotated key """ + + s = _make_psp_conn(cfg) + try: + rx_assoc = cfg.pspnl.rx_assoc({"version": 0, + "dev-id": cfg.psp_dev_id, + "sock-fd": s.fileno()}) + rx = rx_assoc['rx-key'] + tx = _spi_xchg(s, rx) + + cfg.pspnl.tx_assoc({"dev-id": cfg.psp_dev_id, + "version": 0, + "tx-key": tx, + "sock-fd": s.fileno()}) + + data_len = _send_careful(cfg, s, 100) + _check_data_rx(cfg, data_len) + _check_data_outq(s, 0) + + cfg.pspnl.key_rotate({"id": cfg.psp_dev_id}) + cfg.pspnl.key_rotate({"id": cfg.psp_dev_id}) + + s.send(b'0123456789' * 200) + _check_data_outq(s, 2000, force_wait=True) + finally: + _close_psp_conn(cfg, s) + + def psp_ip_ver_test_builder(name, test_func, psp_ver, ipver): """Build test cases for each combo of PSP version and IP version""" def test_case(cfg):
@@ -374,7 +462,7 @@ def main() -> None: if cfg.psp_dev_id is not None: ksft_run(cases=cases, globs=globals(), - case_pfx={"dev_", "assoc_"}, + case_pfx={"dev_", "data_", "assoc_"}, args=(cfg, )) else: ksft_pr("No PSP device found, skipping all tests")
Signature · 1 line
2.47.3
PATCH v2 7/8 selftests: drv-net: psp: add test for auto-adjusting TCP MSS
In reply to Daniel ZahkaFrom: Jakub Kicinski <[email protected]>
Test TCP MSS getting auto-adjusted. PSP adds an encapsulation overhead of 40B per packet, when used in transport mode without any virtualization cookie or other optional PSP header fields. The kernel should adjust the MSS for a connection after PSP tx state is reached.
--- tools/testing/selftests/drivers/net/psp.py | 50 ++++++++++++++++++++++ 1 file changed, 50 insertions(+)
tools/testing/selftests/drivers/net/psp.py +50 -0
@@ -383,6 +383,43 @@ def data_send_disconnect(cfg): s.close() +def _data_mss_adjust(cfg, ipver): + # First figure out what the MSS would be without any adjustments + s = _make_clr_conn(cfg, ipver) + s.send(b"0123456789abcdef" * 1024) + _check_data_rx(cfg, 16 * 1024) + mss = s.getsockopt(socket.IPPROTO_TCP, socket.TCP_MAXSEG) + _close_conn(cfg, s) + + s = _make_psp_conn(cfg, 0, ipver) + try: + rx_assoc = cfg.pspnl.rx_assoc({"version": 0, + "dev-id": cfg.psp_dev_id, + "sock-fd": s.fileno()}) + rx = rx_assoc['rx-key'] + tx = _spi_xchg(s, rx) + + rxmss = s.getsockopt(socket.IPPROTO_TCP, socket.TCP_MAXSEG) + ksft_eq(mss, rxmss) + + cfg.pspnl.tx_assoc({"dev-id": cfg.psp_dev_id, + "version": 0, + "tx-key": tx, + "sock-fd": s.fileno()}) + + txmss = s.getsockopt(socket.IPPROTO_TCP, socket.TCP_MAXSEG) + ksft_eq(mss, txmss + 40) + + data_len = _send_careful(cfg, s, 100) + _check_data_rx(cfg, data_len) + _check_data_outq(s, 0) + + txmss = s.getsockopt(socket.IPPROTO_TCP, socket.TCP_MAXSEG) + ksft_eq(mss, txmss + 40) + finally: + _close_psp_conn(cfg, s) + + def data_stale_key(cfg): """ Test send on a double-rotated key """
@@ -421,6 +458,15 @@ def psp_ip_ver_test_builder(name, test_func, psp_ver, ipver): return test_case +def ipver_test_builder(name, test_func, ipver): + """Build test cases for each IP version""" + def test_case(cfg): + cfg.require_ipver(ipver) + test_case.__name__ = f"{name}_ip{ipver}" + test_func(cfg, ipver) + return test_case + + def main() -> None: with NetDrvEpEnv(__file__) as cfg: cfg.pspnl = PSPFamily()
@@ -459,6 +505,10 @@ def main() -> None: for version in range(0, 4) for ipver in ("4", "6") ] + cases += [ + ipver_test_builder("data_mss_adjust", _data_mss_adjust, ipver) + for ipver in ("4", "6") + ] if cfg.psp_dev_id is not None: ksft_run(cases=cases, globs=globals(),
Signature · 1 line
2.47.3
PATCH v2 8/8 selftests: drv-net: psp: add tests for destroying devices
In reply to Daniel ZahkaFrom: Jakub Kicinski <[email protected]>
Add tests for making sure device can disappear while associations exist. This is netdevsim-only since destroying real devices is more tricky.
--- .../drivers/net/hw/lib/py/__init__.py | 2 +- .../selftests/drivers/net/lib/py/__init__.py | 2 +- .../selftests/drivers/net/lib/py/env.py | 5 ++ tools/testing/selftests/drivers/net/psp.py | 59 ++++++++++++++++++- tools/testing/selftests/net/lib/py/ksft.py | 5 ++ 5 files changed, 69 insertions(+), 4 deletions(-)
tools/testing/selftests/drivers/net/hw/lib/py/__init__.py +1 -1
@@ -22,7 +22,7 @@ try: from net.lib.py import ksft_disruptive, ksft_exit, ksft_pr, ksft_run, \ ksft_setup 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_ne, ksft_not_in, ksft_raises, ksft_true, ksft_gt, ksft_not_none from net.lib.py import NetNSEnter from drivers.net.lib.py import GenerateTraffic from drivers.net.lib.py import NetDrvEnv, NetDrvEpEnv
tools/testing/selftests/drivers/net/lib/py/__init__.py +1 -1
@@ -21,7 +21,7 @@ try: from net.lib.py import ksft_disruptive, ksft_exit, ksft_pr, ksft_run, \ ksft_setup 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_ne, ksft_not_in, ksft_raises, ksft_true, ksft_gt, ksft_not_none except ModuleNotFoundError as e: ksft_pr("Failed importing `net` library from kernel sources") ksft_pr(str(e))
tools/testing/selftests/drivers/net/lib/py/env.py +5 -0
@@ -7,6 +7,7 @@ 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 NetNS, NetdevSimDev +from lib.py import KsftXfailEx from .remote import Remote
@@ -245,6 +246,10 @@ class NetDrvEpEnv(NetDrvEnvBase): if not self.addr_v[ipver] or not self.remote_addr_v[ipver]: raise KsftSkipEx(f"Test requires IPv{ipver} connectivity") + def require_nsim(self): + if self._ns is None: + raise KsftXfailEx("Test only works on netdevsim") + def _require_cmd(self, comm, key, host=None): cached = self._required_cmd.get(comm, {}) if cached.get(key) is None:
tools/testing/selftests/drivers/net/psp.py +57 -2
77 lines not on this page · raw message
tools/testing/selftests/net/lib/py/ksft.py +5 -0
@@ -72,6 +72,11 @@ def ksft_true(a, comment=""): _fail("Check failed", a, "does not eval to True", comment) +def ksft_not_none(a, comment=""): + if a is None: + _fail("Check failed", a, "is None", comment) + + def ksft_in(a, b, comment=""): if a not in b: _fail("Check failed", a, "not in", b, comment)
Signature · 1 line
2.47.3