Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge branch 'tcp-__tcp_close-changes'

Eric Dumazet says:

====================
tcp: __tcp_close() changes

First patch fixes a rare bug.

Second patch adds a corresponding packetdrill test.

Third patch is a small optimization.
====================

Link: https://patch.msgid.link/20250903084720.1168904-1-edumazet@google.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

+39 -6
+7 -6
net/ipv4/tcp.c
··· 3099 3099 3100 3100 void __tcp_close(struct sock *sk, long timeout) 3101 3101 { 3102 + bool data_was_unread = false; 3102 3103 struct sk_buff *skb; 3103 - int data_was_unread = 0; 3104 3104 int state; 3105 3105 3106 3106 WRITE_ONCE(sk->sk_shutdown, SHUTDOWN_MASK); ··· 3118 3118 * descriptor close, not protocol-sourced closes, because the 3119 3119 * reader process may not have drained the data yet! 3120 3120 */ 3121 - while ((skb = __skb_dequeue(&sk->sk_receive_queue)) != NULL) { 3122 - u32 len = TCP_SKB_CB(skb)->end_seq - TCP_SKB_CB(skb)->seq; 3121 + while ((skb = skb_peek(&sk->sk_receive_queue)) != NULL) { 3122 + u32 end_seq = TCP_SKB_CB(skb)->end_seq; 3123 3123 3124 3124 if (TCP_SKB_CB(skb)->tcp_flags & TCPHDR_FIN) 3125 - len--; 3126 - data_was_unread += len; 3127 - __kfree_skb(skb); 3125 + end_seq--; 3126 + if (after(end_seq, tcp_sk(sk)->copied_seq)) 3127 + data_was_unread = true; 3128 + tcp_eat_recv_skb(sk, skb); 3128 3129 } 3129 3130 3130 3131 /* If socket has been already reset (e.g. in tcp_reset()) - kill it. */
+32
tools/testing/selftests/net/packetdrill/tcp_close_no_rst.pkt
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + 3 + --mss=1000 4 + 5 + `./defaults.sh` 6 + 7 + // Initialize 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 + +0 < S 0:0(0) win 32792 <mss 1000,sackOK,nop,nop> 14 + +0 > S. 0:0(0) ack 1 <mss 1460,nop,nop,sackOK> 15 + +.1 < . 1:1(0) ack 1 win 32792 16 + 17 + 18 + +0 accept(3, ..., ...) = 4 19 + +0 < . 1:1001(1000) ack 1 win 32792 20 + +0 > . 1:1(0) ack 1001 21 + +0 read(4, ..., 1000) = 1000 22 + 23 + // resend the payload + a FIN 24 + +0 < F. 1:1001(1000) ack 1 win 32792 25 + // Why do we have a delay and no dsack ? 26 + +0~+.04 > . 1:1(0) ack 1002 27 + 28 + +0 close(4) = 0 29 + 30 + // According to RFC 2525, section 2.17 31 + // we should _not_ send an RST here, because there was no data to consume. 32 + +0 > F. 1:1(0) ack 1002