Skip to content

Commit 7a6c02f

Browse files
committed
Merge: selftests/net: packetdrill: backport latest upstream tests
MR: https://gitlab.com/redhat/centos-stream/src/kernel/centos-stream-10/-/merge_requests/799 JIRA: https://issues.redhat.com/browse/RHEL-88651 Signed-off-by: Hangbin Liu <haliu@redhat.com> Merged-by: Julio Faracco <jfaracco@redhat.com>
2 parents 3046c99 + ee8902e commit 7a6c02f

File tree

44 files changed

+1878
-7
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+1878
-7
lines changed

tools/testing/selftests/kselftest/ktap_helpers.sh

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
KTAP_TESTNO=1
88
KTAP_CNT_PASS=0
99
KTAP_CNT_FAIL=0
10+
KTAP_CNT_XFAIL=0
1011
KTAP_CNT_SKIP=0
1112

1213
KSFT_PASS=0
@@ -69,6 +70,16 @@ ktap_test_skip() {
6970
KTAP_CNT_SKIP=$((KTAP_CNT_SKIP+1))
7071
}
7172

73+
ktap_test_xfail() {
74+
description="$1"
75+
76+
result="ok"
77+
directive="XFAIL"
78+
__ktap_test "$result" "$description" "$directive"
79+
80+
KTAP_CNT_XFAIL=$((KTAP_CNT_XFAIL+1))
81+
}
82+
7283
ktap_test_fail() {
7384
description="$1"
7485

@@ -99,13 +110,13 @@ ktap_exit_fail_msg() {
99110
ktap_finished() {
100111
ktap_print_totals
101112

102-
if [ $((KTAP_CNT_PASS + KTAP_CNT_SKIP)) -eq "$KSFT_NUM_TESTS" ]; then
113+
if [ $((KTAP_CNT_PASS + KTAP_CNT_SKIP + KTAP_CNT_XFAIL)) -eq "$KSFT_NUM_TESTS" ]; then
103114
exit "$KSFT_PASS"
104115
else
105116
exit "$KSFT_FAIL"
106117
fi
107118
}
108119

109120
ktap_print_totals() {
110-
echo "# Totals: pass:$KTAP_CNT_PASS fail:$KTAP_CNT_FAIL xfail:0 xpass:0 skip:$KTAP_CNT_SKIP error:0"
121+
echo "# Totals: pass:$KTAP_CNT_PASS fail:$KTAP_CNT_FAIL xfail:$KTAP_CNT_XFAIL xpass:0 skip:$KTAP_CNT_SKIP error:0"
111122
}

tools/testing/selftests/net/packetdrill/ksft_runner.sh

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,24 +23,40 @@ if [ $# -ne 1 ]; then
2323
ktap_exit_fail_msg "usage: $0 <script>"
2424
exit "$KSFT_FAIL"
2525
fi
26-
script="$1"
26+
script="$(basename $1)"
2727

2828
if [ -z "$(which packetdrill)" ]; then
2929
ktap_skip_all "packetdrill not found in PATH"
3030
exit "$KSFT_SKIP"
3131
fi
3232

3333
declare -a optargs
34+
failfunc=ktap_test_fail
35+
3436
if [[ -n "${KSFT_MACHINE_SLOW}" ]]; then
3537
optargs+=('--tolerance_usecs=14000')
38+
39+
# xfail tests that are known flaky with dbg config, not fixable.
40+
# still run them for coverage (and expect 100% pass without dbg).
41+
declare -ar xfail_list=(
42+
"tcp_eor_no-coalesce-retrans.pkt"
43+
"tcp_fast_recovery_prr-ss.*.pkt"
44+
"tcp_slow_start_slow-start-after-win-update.pkt"
45+
"tcp_timestamping.*.pkt"
46+
"tcp_user_timeout_user-timeout-probe.pkt"
47+
"tcp_zerocopy_epoll_.*.pkt"
48+
"tcp_tcp_info_tcp-info-.*-limited.pkt"
49+
)
50+
readonly xfail_regex="^($(printf '%s|' "${xfail_list[@]}"))$"
51+
[[ "$script" =~ ${xfail_regex} ]] && failfunc=ktap_test_xfail
3652
fi
3753

3854
ktap_print_header
3955
ktap_set_plan 2
4056

41-
unshare -n packetdrill ${ipv4_args[@]} ${optargs[@]} $(basename $script) > /dev/null \
42-
&& ktap_test_pass "ipv4" || ktap_test_fail "ipv4"
43-
unshare -n packetdrill ${ipv6_args[@]} ${optargs[@]} $(basename $script) > /dev/null \
44-
&& ktap_test_pass "ipv6" || ktap_test_fail "ipv6"
57+
unshare -n packetdrill ${ipv4_args[@]} ${optargs[@]} $script > /dev/null \
58+
&& ktap_test_pass "ipv4" || $failfunc "ipv4"
59+
unshare -n packetdrill ${ipv6_args[@]} ${optargs[@]} $script > /dev/null \
60+
&& ktap_test_pass "ipv6" || $failfunc "ipv6"
4561

4662
ktap_finished
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
// Test for blocking accept.
3+
4+
`./defaults.sh`
5+
6+
// Establish a connection.
7+
0 socket(..., SOCK_STREAM, IPPROTO_TCP) = 3
8+
+0 setsockopt(3, SOL_SOCKET, SO_REUSEADDR, [1], 4) = 0
9+
+0 bind(3, ..., ...) = 0
10+
+0 listen(3, 1) = 0
11+
+0...0.200 accept(3, ..., ...) = 4
12+
13+
+.1 < S 0:0(0) win 32792 <mss 1000,nop,wscale 7>
14+
+0 > S. 0:0(0) ack 1 <mss 1460,nop,wscale 8>
15+
+.1 < . 1:1(0) ack 1 win 257
16+
17+
+.1 write(4, ..., 2000) = 2000
18+
+0 > P. 1:2001(2000) ack 1
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
// Test for blocking connect.
3+
4+
`./defaults.sh`
5+
6+
// Establish a connection.
7+
0 socket(..., SOCK_STREAM, IPPROTO_TCP) = 3
8+
9+
+.1...0.200 connect(3, ..., ...) = 0
10+
11+
+0 > S 0:0(0) <mss 1460,sackOK,TS val 100 ecr 0,nop,wscale 8>
12+
+.1 < S. 0:0(0) ack 1 win 5792 <mss 1460,nop,wscale 2,nop,nop,sackOK>
13+
+0 > . 1:1(0) ack 1
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
// Test for blocking read.
3+
--tolerance_usecs=10000
4+
5+
`./defaults.sh`
6+
7+
// Establish a connection.
8+
0 socket(..., SOCK_STREAM, IPPROTO_TCP) = 3
9+
+0 setsockopt(3, SOL_SOCKET, SO_REUSEADDR, [1], 4) = 0
10+
+0 bind(3, ..., ...) = 0
11+
+0 listen(3, 1) = 0
12+
13+
+.1 < S 0:0(0) win 32792 <mss 1000,nop,wscale 7>
14+
+0 > S. 0:0(0) ack 1 <mss 1460,nop,wscale 8>
15+
+.1 < . 1:1(0) ack 1 win 257
16+
+0 accept(3, ..., ...) = 4
17+
18+
+0...0.100 read(4, ..., 2000) = 2000
19+
+.1 < P. 1:2001(2000) ack 1 win 257
20+
+0 > . 1:1(0) ack 2001
21+
22+
+.1...0.200 read(4, ..., 2000) = 2000
23+
+.1 < P. 2001:4001(2000) ack 1 win 257
24+
+0 > . 1:1(0) ack 4001
25+
26+
+.1 < P. 4001:6001(2000) ack 1 win 257
27+
+0 > . 1:1(0) ack 6001
28+
+0...0.000 read(4, ..., 1000) = 1000
29+
+0...0.000 read(4, ..., 1000) = 1000
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
// Test for blocking write.
3+
--tolerance_usecs=10000
4+
5+
`./defaults.sh
6+
./set_sysctls.py /proc/sys/net/ipv4/tcp_min_tso_segs=10
7+
`
8+
9+
// Establish a connection.
10+
0 socket(..., SOCK_STREAM, IPPROTO_TCP) = 3
11+
+0 setsockopt(3, SOL_SOCKET, SO_REUSEADDR, [1], 4) = 0
12+
+0 bind(3, ..., ...) = 0
13+
+0 listen(3, 1) = 0
14+
15+
+.1 < S 0:0(0) win 50000 <mss 1000,nop,wscale 0>
16+
+0 > S. 0:0(0) ack 1 <mss 1460,nop,wscale 8>
17+
+.1 < . 1:1(0) ack 1 win 50000
18+
+0 accept(3, ..., ...) = 4
19+
20+
// Kernel doubles our value -> sk->sk_sndbuf is set to 42000
21+
+0 setsockopt(4, SOL_SOCKET, SO_SNDBUF, [21000], 4) = 0
22+
+0 getsockopt(4, SOL_SOCKET, SO_SNDBUF, [42000], [4]) = 0
23+
24+
// A write of 60000 does not block.
25+
+0...0.300 write(4, ..., 61000) = 61000 // this write() blocks
26+
27+
+.1 < . 1:1(0) ack 10001 win 50000
28+
29+
+.1 < . 1:1(0) ack 30001 win 50000
30+
31+
// This ACK should wakeup the write(). An ACK of 35001 does not.
32+
+.1 < . 1:1(0) ack 36001 win 50000
33+
34+
// Reset to sysctls defaults.
35+
`/tmp/sysctl_restore_${PPID}.sh`
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
// Test basic connection teardown where local process closes first:
3+
// the local process calls close() first, so we send a FIN, and receive an ACK.
4+
// Then we receive a FIN and ACK it.
5+
6+
`./defaults.sh`
7+
8+
0 socket(..., SOCK_STREAM, IPPROTO_TCP) = 3
9+
+.01...0.011 connect(3, ..., ...) = 0
10+
+0 > S 0:0(0) <...>
11+
+0 < S. 0:0(0) ack 1 win 32768 <mss 1000,nop,wscale 6,nop,nop,sackOK>
12+
+0 > . 1:1(0) ack 1
13+
14+
+0 write(3, ..., 1000) = 1000
15+
+0 > P. 1:1001(1000) ack 1
16+
+0 < . 1:1(0) ack 1001 win 257
17+
18+
+0 close(3) = 0
19+
+0 > F. 1001:1001(0) ack 1
20+
+0 < . 1:1(0) ack 1002 win 257
21+
22+
+0 < F. 1:1(0) ack 1002 win 257
23+
+0 > . 1002:1002(0) ack 2
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
// Test to make sure no RST is being sent when close()
3+
// is called on a socket with SYN_SENT state.
4+
5+
`./defaults.sh`
6+
7+
0 socket(..., SOCK_STREAM, IPPROTO_TCP) = 3
8+
+0 fcntl(3, F_SETFL, O_RDWR|O_NONBLOCK) = 0
9+
10+
+0 connect(3, ..., ...) = -1 EINPROGRESS (Operation now in progress)
11+
+0 > S 0:0(0) <...>
12+
13+
// Application decideds to close the socket in SYN_SENT state
14+
// Make sure no RST is sent after close().
15+
+0 close(3) = 0
16+
17+
// Receive syn-ack to trigger the send side packet examination:
18+
// If a RESET were sent right after close(), it would have failed with
19+
// a mismatched timestamp.
20+
+.1 < S. 0:0(0) ack 1 win 32000 <mss 1460,nop,wscale 7>
21+
+0 > R 1:1(0)
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
// Verify behavior for the sequence: remote side sends FIN, then we close().
3+
// Since the remote side (client) closes first, we test our LAST_ACK code path.
4+
5+
`./defaults.sh`
6+
7+
// Initialize a server socket.
8+
0 socket(..., SOCK_STREAM, IPPROTO_TCP) = 3
9+
+0 setsockopt(3, SOL_SOCKET, SO_REUSEADDR, [1], 4) = 0
10+
+0 bind(3, ..., ...) = 0
11+
+0 listen(3, 1) = 0
12+
13+
+0 < S 0:0(0) win 32792 <mss 1000,sackOK,nop,nop,nop,wscale 7>
14+
+0 > S. 0:0(0) ack 1 <mss 1460,nop,nop,sackOK,nop,wscale 8>
15+
+0 < . 1:1(0) ack 1 win 257
16+
17+
+0 accept(3, ..., ...) = 4
18+
19+
// Client closes first.
20+
+.01 < F. 1:1(0) ack 1 win 257
21+
+0 > . 1:1(0) ack 2
22+
23+
// App notices that client closed.
24+
+0 read(4, ..., 1000) = 0
25+
26+
// Then we close.
27+
+.01 close(4) = 0
28+
+0 > F. 1:1(0) ack 2
29+
30+
// Client ACKs our FIN.
31+
+.01 < . 2:2(0) ack 2 win 257
32+
33+
// Verify that we send RST in response to any incoming segments
34+
// (because the kernel no longer has any record of this socket).
35+
+.01 < . 2:2(0) ack 2 win 257
36+
+0 > R 2:2(0)
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
// Test ECN: verify that Linux TCP ECN sending code uses ECT0 (not ECT1).
3+
//
4+
`./defaults.sh
5+
sysctl -q net.ipv4.tcp_ecn=1 # fully enabled
6+
`
7+
8+
// Initialize connection
9+
0 socket(..., SOCK_STREAM, IPPROTO_TCP) = 4
10+
11+
// ECN handshake: send EW flags in SYN packet, E flag in SYN-ACK response
12+
+.002 ... 0.004 connect(4, ..., ...) = 0
13+
14+
+0 > SEW 0:0(0) <mss 1460,sackOK,TS val 100 ecr 0,nop,wscale 8>
15+
+.002 < SE. 0:0(0) ack 1 win 32767 <mss 1000,nop,wscale 6,nop,nop,sackOK>
16+
+0 > . 1:1(0) ack 1
17+
18+
// Write 1 MSS.
19+
+.002 write(4, ..., 1000) = 1000
20+
// Send 1 MSS with ect0.
21+
+0 > [ect0] P. 1:1001(1000) ack 1

0 commit comments

Comments
 (0)