Commit 1e42f73f authored by Willem de Bruijn's avatar Willem de Bruijn Committed by Jakub Kicinski
Browse files

selftests/net: packetdrill: import tcp/zerocopy



Same as initial tests, import verbatim from
github.com/google/packetdrill, aside from:

- update `source ./defaults.sh` path to adjust for flat dir
- add SPDX headers
- remove author statements if any
- drop blank lines at EOF (new)

Also import set_sysctls.py, which many scripts depend on to set
sysctls and then restore them later. This is no longer strictly needed
for namespacified sysctl. But not all sysctls are namespacified, and
doesn't hurt if they are.

Signed-off-by: default avatarWillem de Bruijn <willemb@google.com>
Acked-by: default avatarMatthieu Baerts (NGI0) <matttbe@kernel.org>
Link: https://patch.msgid.link/20240912005317.1253001-3-willemdebruijn.kernel@gmail.com


Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent cded7e04
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -2,6 +2,7 @@

TEST_INCLUDES := ksft_runner.sh \
		 defaults.sh \
		 set_sysctls.py \
		 ../../kselftest/ktap_helpers.sh

TEST_PROGS := $(wildcard *.pkt)
+38 −0
Original line number Diff line number Diff line
#!/usr/bin/env python3
# SPDX-License-Identifier: GPL-2.0

"""Sets sysctl values and writes a file that restores them.

The arguments are of the form "<proc-file>=<val>" separated by spaces.
The program first reads the current value of the proc-file and creates
a shell script named "/tmp/sysctl_restore_${PACKETDRILL_PID}.sh" which
restores the values when executed. It then sets the new values.

PACKETDRILL_PID is set by packetdrill to the pid of itself, so a .pkt
file could restore sysctls by running `/tmp/sysctl_restore_${PPID}.sh`
at the end.
"""

import os
import subprocess
import sys

filename = '/tmp/sysctl_restore_%s.sh' % os.environ['PACKETDRILL_PID']

# Open file for restoring sysctl values
restore_file = open(filename, 'w')
print('#!/bin/bash', file=restore_file)

for a in sys.argv[1:]:
  sysctl = a.split('=')
  # sysctl[0] contains the proc-file name, sysctl[1] the new value

  # read current value and add restore command to file
  cur_val = subprocess.check_output(['cat', sysctl[0]], universal_newlines=True)
  print('echo "%s" > %s' % (cur_val.strip(), sysctl[0]), file=restore_file)

  # set new value
  cmd = 'echo "%s" > %s' % (sysctl[1], sysctl[0])
  os.system(cmd)

os.system('chmod u+x %s' % filename)
+55 −0
Original line number Diff line number Diff line
// SPDX-License-Identifier: GPL-2.0
// basic zerocopy test:
//
// send a packet with MSG_ZEROCOPY and receive the notification ID
// repeat and verify IDs are consecutive

`./defaults.sh`

    0 socket(..., SOCK_STREAM, IPPROTO_TCP) = 3
   +0 setsockopt(3, SOL_SOCKET, SO_REUSEADDR, [1], 4) = 0
   +0 setsockopt(3, SOL_SOCKET, SO_ZEROCOPY, [1], 4) = 0
   +0 bind(3, ..., ...) = 0
   +0 listen(3, 1) = 0

   +0 < S 0:0(0) win 32792 <mss 1000,sackOK,nop,nop,nop,wscale 7>
   +0 > S. 0:0(0) ack 1 <mss 1460,nop,nop,sackOK,nop,wscale 8>
   +0 < . 1:1(0) ack 1 win 257

   +0 accept(3, ..., ...) = 4

   +0 send(4, ..., 4000, MSG_ZEROCOPY) = 4000
   +0 > P. 1:4001(4000) ack 1
   +0 < . 1:1(0) ack 4001 win 257

   +0 recvmsg(4, {msg_name(...)=...,
                  msg_iov(1)=[{...,0}],
                  msg_flags=MSG_ERRQUEUE,
                  msg_control=[
                        {cmsg_level=CMSG_LEVEL_IP,
                         cmsg_type=CMSG_TYPE_RECVERR,
                         cmsg_data={ee_errno=0,
                                    ee_origin=SO_EE_ORIGIN_ZEROCOPY,
                                    ee_type=0,
                                    ee_code=SO_EE_CODE_ZEROCOPY_COPIED,
                                    ee_info=0,
                                    ee_data=0}}
                   ]}, MSG_ERRQUEUE) = 0

   +0 send(4, ..., 4000, MSG_ZEROCOPY) = 4000
   +0 > P. 4001:8001(4000) ack 1
   +0 < . 1:1(0) ack 8001 win 257

   +0 recvmsg(4, {msg_name(...)=...,
                  msg_iov(1)=[{...,0}],
                  msg_flags=MSG_ERRQUEUE,
                  msg_control=[
                        {cmsg_level=CMSG_LEVEL_IP,
                         cmsg_type=CMSG_TYPE_RECVERR,
                         cmsg_data={ee_errno=0,
                                    ee_origin=SO_EE_ORIGIN_ZEROCOPY,
                                    ee_type=0,
                                    ee_code=SO_EE_CODE_ZEROCOPY_COPIED,
                                    ee_info=1,
                                    ee_data=1}}
                   ]}, MSG_ERRQUEUE) = 0
+41 −0
Original line number Diff line number Diff line
// SPDX-License-Identifier: GPL-2.0
// batch zerocopy test:
//
// send multiple packets, then read one range of all notifications.

`./defaults.sh`

    0 socket(..., SOCK_STREAM, IPPROTO_TCP) = 3
   +0 setsockopt(3, SOL_SOCKET, SO_REUSEADDR, [1], 4) = 0
   +0 setsockopt(3, SOL_SOCKET, SO_ZEROCOPY, [1], 4) = 0
   +0 bind(3, ..., ...) = 0
   +0 listen(3, 1) = 0

   +0 < S 0:0(0) win 32792 <mss 1000,sackOK,nop,nop,nop,wscale 7>
   +0 > S. 0:0(0) ack 1 <mss 1460,nop,nop,sackOK,nop,wscale 8>
   +0 < . 1:1(0) ack 1 win 257

   +0 accept(3, ..., ...) = 4
   +0 setsockopt(4, SOL_SOCKET, SO_MARK, [666], 4) = 0

   +0 send(4, ..., 4000, MSG_ZEROCOPY) = 4000
   +0 > P. 1:4001(4000) ack 1
   +0 < . 1:1(0) ack 4001 win 257

   +0 send(4, ..., 4000, MSG_ZEROCOPY) = 4000
   +0 > P. 4001:8001(4000) ack 1
   +0 < . 1:1(0) ack 8001 win 257

   +0 recvmsg(4, {msg_name(...)=...,
                  msg_iov(1)=[{...,0}],
                  msg_flags=MSG_ERRQUEUE,
                  msg_control=[
                        {cmsg_level=CMSG_LEVEL_IP,
                         cmsg_type=CMSG_TYPE_RECVERR,
                         cmsg_data={ee_errno=0,
                                    ee_origin=SO_EE_ORIGIN_ZEROCOPY,
                                    ee_type=0,
                                    ee_code=SO_EE_CODE_ZEROCOPY_COPIED,
                                    ee_info=0,
                                    ee_data=1}}
                  ]}, MSG_ERRQUEUE) = 0
+30 −0
Original line number Diff line number Diff line
// SPDX-License-Identifier: GPL-2.0
// Minimal client-side zerocopy test

`./defaults.sh`

    0 socket(..., SOCK_STREAM, IPPROTO_TCP) = 4
   +0 setsockopt(4, SOL_SOCKET, SO_ZEROCOPY, [1], 4) = 0
   +0...0 connect(4, ..., ...) = 0

   +0 > S 0:0(0) <mss 1460,sackOK,TS val 0 ecr 0,nop,wscale 8>
   +0 < S. 0:0(0) ack 1 win 32792 <mss 1000,sackOK,nop,nop,nop,wscale 7>
   +0 > . 1:1(0) ack 1

   +0 send(4, ..., 4000, MSG_ZEROCOPY) = 4000
   +0 > P. 1:4001(4000) ack 1
   +0 < . 1:1(0) ack 4001 win 257

   +0 recvmsg(4, {msg_name(...)=...,
                  msg_iov(1)=[{...,0}],
                  msg_flags=MSG_ERRQUEUE,
                  msg_control=[
                        {cmsg_level=CMSG_LEVEL_IP,
                         cmsg_type=CMSG_TYPE_RECVERR,
                         cmsg_data={ee_errno=0,
                                    ee_origin=SO_EE_ORIGIN_ZEROCOPY,
                                    ee_type=0,
                                    ee_code=SO_EE_CODE_ZEROCOPY_COPIED,
                                    ee_info=0,
                                    ee_data=0}}
                   ]}, MSG_ERRQUEUE) = 0
Loading