Skip to content

Commit 5920f15

Browse files
q2venkuba-moo
authored andcommitted
selftest: packetdrill: Import opt34/reset-* tests.
This imports the non-experimental version of opt34/reset-*.pkt. | Child | RST | sk_err | ---------------------------------+---------+-------------------------------+---------+ reset-after-accept.pkt | TFO | after accept(), SYN_RECV | read() | reset-close-with-unread-data.pkt | TFO | after accept(), SYN_RECV | write() | reset-before-accept.pkt | TFO | before accept(), SYN_RECV | read() | reset-non-tfo-socket.pkt | non-TFO | before accept(), ESTABLISHED | write() | The first 3 files test scenarios where a SYN_RECV socket receives RST before/after accept() and data in SYN must be read() without error, but the following read() or fist write() will return ECONNRESET. The last test is similar but with non-TFO socket. Signed-off-by: Kuniyuki Iwashima <kuniyu@google.com> Reviewed-by: Willem de Bruijn <willemb@google.com> Link: https://patch.msgid.link/20250927213022.1850048-10-kuniyu@google.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent a8b1750 commit 5920f15

4 files changed

Lines changed: 138 additions & 0 deletions
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
//
3+
// Send a RST to a TFO socket after it has been accepted.
4+
//
5+
// First read() will return all the data and this is consistent
6+
// with the non-TFO case. Second read will return -1
7+
8+
`./defaults.sh`
9+
10+
0 socket(..., SOCK_STREAM|SOCK_NONBLOCK, 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+
+0 setsockopt(3, SOL_TCP, TCP_FASTOPEN, [1], 4) = 0
15+
16+
+0 < S 0:10(10) win 32792 <mss 1460,sackOK,nop,nop,FO TFO_COOKIE,nop,nop>
17+
+0 > S. 0:0(0) ack 11 <mss 1460,nop,nop,sackOK>
18+
19+
+0 accept(3, ..., ...) = 4
20+
+0 %{ assert (tcpi_options & TCPI_OPT_SYN_DATA) != 0, tcpi_options }%
21+
+0 %{ assert tcpi_state == TCP_SYN_RECV, tcpi_state }%
22+
23+
// 1st read will return the data from SYN.
24+
// tcp_reset() sets sk->sk_err to ECONNRESET for SYN_RECV.
25+
+0 < R. 11:11(0) win 32792
26+
+0 %{ assert tcpi_state == TCP_CLOSE, tcpi_state }%
27+
28+
// This one w/o ACK bit will cause the same effect.
29+
// +0 < R 11:11(0) win 32792
30+
// See Step 2 in tcp_validate_incoming().
31+
32+
// found_ok_skb in tcp_recvmsg_locked()
33+
+0 read(4, ..., 512) = 10
34+
35+
// !copied && sk->sk_err -> sock_error(sk)
36+
+0 read(4, ..., 512) = -1 ECONNRESET (Connection reset by peer)
37+
+0 close(4) = 0
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
//
3+
// Send a RST to a TFO socket before it is accepted.
4+
//
5+
// The socket won't go away and after it's accepted the data
6+
// in the SYN pkt can still be read. But that's about all that
7+
// the acceptor can do with the socket.
8+
9+
`./defaults.sh`
10+
11+
0 socket(..., SOCK_STREAM|SOCK_NONBLOCK, IPPROTO_TCP) = 3
12+
+0 setsockopt(3, SOL_SOCKET, SO_REUSEADDR, [1], 4) = 0
13+
+0 bind(3, ..., ...) = 0
14+
+0 listen(3, 1) = 0
15+
+0 setsockopt(3, SOL_TCP, TCP_FASTOPEN, [1], 4) = 0
16+
17+
+0 < S 0:10(10) win 32792 <mss 1460,sackOK,nop,nop,nop,wscale 7,FO TFO_COOKIE,nop,nop>
18+
+0 > S. 0:0(0) ack 11 <mss 1460,nop,nop,sackOK,nop,wscale 8>
19+
20+
// 1st read will return the data from SYN.
21+
+0 < R. 11:11(0) win 257
22+
23+
// This one w/o ACK bit will cause the same effect.
24+
// +0 < R 11:11(0) win 257
25+
26+
+0 accept(3, ..., ...) = 4
27+
+0 %{ assert (tcpi_options & TCPI_OPT_SYN_DATA) != 0, tcpi_options }%
28+
+0 %{ assert tcpi_state == TCP_CLOSE, tcpi_state }%
29+
30+
+0 read(4, ..., 512) = 10
31+
+0 read(4, ..., 512) = -1 ECONNRESET (Connection reset by peer)
32+
+0 close(4) = 0
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
//
3+
// Send a RST to a TFO socket after it is accepted.
4+
//
5+
// The socket will change to TCP_CLOSE state with pending data so
6+
// write() will fail. Pending data can be still be read and close()
7+
// won't trigger RST if data is not read
8+
//
9+
// 565b7b2d2e63 ("tcp: do not send reset to already closed sockets")
10+
// https://lore.kernel.org/netdev/4C1A2502.1030502@openvz.org/
11+
12+
`./defaults.sh`
13+
14+
0 socket(..., SOCK_STREAM|SOCK_NONBLOCK, IPPROTO_TCP) = 3
15+
+0 setsockopt(3, SOL_SOCKET, SO_REUSEADDR, [1], 4) = 0
16+
+0 bind(3, ..., ...) = 0
17+
+0 listen(3, 1) = 0
18+
+0 setsockopt(3, SOL_TCP, TCP_FASTOPEN, [1], 4) = 0
19+
20+
+0 < S 0:10(10) win 32792 <mss 1460,sackOK,nop,nop, FO TFO_COOKIE,nop,nop>
21+
+0 > S. 0:0(0) ack 11 <mss 1460,nop,nop,sackOK>
22+
23+
+0 accept(3, ..., ...) = 4
24+
+0 %{ assert (tcpi_options & TCPI_OPT_SYN_DATA) != 0, tcpi_options }%
25+
+0 %{ assert tcpi_state == TCP_SYN_RECV, tcpi_state }%
26+
27+
// tcp_done() sets sk->sk_state to TCP_CLOSE and clears tp->fastopen_rsk
28+
+0 < R. 11:11(0) win 32792
29+
+0 %{ assert tcpi_state == TCP_CLOSE, tcpi_state }%
30+
31+
+0 write(4, ..., 100) = -1 ECONNRESET(Connection reset by peer)
32+
+0 close(4) = 0
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
//
3+
// Send a RST to a fully established socket with pending data before
4+
// it is accepted.
5+
//
6+
// The socket with pending data won't go away and can still be accepted
7+
// with data read. But it will be in TCP_CLOSE state.
8+
9+
`./defaults.sh`
10+
11+
0 socket(..., SOCK_STREAM|SOCK_NONBLOCK, IPPROTO_TCP) = 3
12+
+0 setsockopt(3, SOL_SOCKET, SO_REUSEADDR, [1], 4) = 0
13+
+0 bind(3, ..., ...) = 0
14+
+0 listen(3, 1) = 0
15+
+0 setsockopt(3, SOL_TCP, TCP_FASTOPEN, [1], 4) = 0
16+
17+
// Invalid cookie, so accept() fails.
18+
+0 < S 0:10(10) win 32792 <mss 1460,sackOK,nop,nop,FO aaaaaaaaaaaaaaaa,nop,nop>
19+
+0 > S. 0:0(0) ack 1 <mss 1460,nop,nop,sackOK, FO TFO_COOKIE,nop,nop>
20+
21+
+0 accept(3, ..., ...) = -1 EAGAIN (Resource temporarily unavailable)
22+
23+
// Complete 3WHS and send data and RST
24+
+0 < . 1:1(0) ack 1 win 32792
25+
+0 < . 1:11(10) ack 1 win 32792
26+
+0 < R. 11:11(0) win 32792
27+
28+
// A valid reset won't make the fully-established socket go away.
29+
// It's just that the acceptor will get a dead, unusable socket
30+
// in TCP_CLOSE state.
31+
+0 accept(3, ..., ...) = 4
32+
+0 %{ assert (tcpi_options & TCPI_OPT_SYN_DATA) == 0, tcpi_options }%
33+
+0 %{ assert tcpi_state == TCP_CLOSE, tcpi_state }%
34+
35+
+0 write(4, ..., 100) = -1 ECONNRESET(Connection reset by peer)
36+
+0 read(4, ..., 512) = 10
37+
+0 read(4, ..., 512) = 0

0 commit comments

Comments
 (0)