Skip to contentSkip to conversation

tcp: completely support active reset

PATCH Superseded Jason Xing 2 participants 11 messages Jul 30, 2024 – Jul 31, 2024

Subsystems (3)

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Jason Xing

author
#0 lore raw

cover tcp: completely support active reset

From: Jason Xing <[email protected]>

This time the patch series finally covers all the cases in the active reset logic. After this, we can know the related exact reason(s).

Jason Xing (6):
tcp: rstreason: introduce SK_RST_REASON_TCP_ABORT_ON_CLOSE for active
reset
tcp: rstreason: introduce SK_RST_REASON_TCP_ABORT_ON_LINGER for active
reset
tcp: rstreason: introduce SK_RST_REASON_TCP_ABORT_ON_MEMORY for active
reset
tcp: rstreason: introduce SK_RST_REASON_TCP_STATE for active reset
tcp: rstreason: introduce SK_RST_REASON_TCP_TIMEOUT for active reset
tcp: rstreason: let it work finally in tcp_send_active_reset()

 include/net/rstreason.h | 31 +++++++++++++++++++++++++++++++
 net/ipv4/tcp.c          | 10 +++++-----
 net/ipv4/tcp_output.c   |  2 +-
 net/ipv4/tcp_timer.c    |  6 +++---
 4 files changed, 40 insertions(+), 9 deletions(-)
Signature · 1 line
2.37.3
author
#1 lore raw

PATCH 1/6 tcp: rstreason: introduce SK_RST_REASON_TCP_ABORT_ON_CLOSE for active reset

From: Jason Xing <[email protected]>

Introducing a new type TCP_ABORT_ON_CLOSE for tcp reset reason to handle the case where more data is unread in closing phase.

---
 include/net/rstreason.h | 6 ++++++
 net/ipv4/tcp.c          | 2 +-
 2 files changed, 7 insertions(+), 1 deletion(-)
include/net/rstreason.h +6 -0
index 2575c85d7f7a..fa6bfd0d7d69 100644
@@ -17,6 +17,7 @@
 	FN(TCP_ABORT_ON_DATA)		\
 	FN(TCP_TIMEWAIT_SOCKET)		\
 	FN(INVALID_SYN)			\
+	FN(TCP_ABORT_ON_CLOSE)		\
 	FN(MPTCP_RST_EUNSPEC)		\
 	FN(MPTCP_RST_EMPTCP)		\
 	FN(MPTCP_RST_ERESOURCE)		\
@@ -84,6 +85,11 @@ enum sk_rst_reason {
 	 * an error, send a reset"
 	 */
 	SK_RST_REASON_INVALID_SYN,
+	/**
+	 * @SK_RST_REASON_TCP_ABORT_ON_CLOSE: abort on close
+	 * corresponding to LINUX_MIB_TCPABORTONCLOSE
+	 */
+	SK_RST_REASON_TCP_ABORT_ON_CLOSE,
 
 	/* Copy from include/uapi/linux/mptcp.h.
 	 * These reset fields will not be changed since they adhere to
net/ipv4/tcp.c +1 -1
index e03a342c9162..2e010add0317 100644
@@ -2833,7 +2833,7 @@ void __tcp_close(struct sock *sk, long timeout)
 		NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPABORTONCLOSE);
 		tcp_set_state(sk, TCP_CLOSE);
 		tcp_send_active_reset(sk, sk->sk_allocation,
-				      SK_RST_REASON_NOT_SPECIFIED);
+				      SK_RST_REASON_TCP_ABORT_ON_CLOSE);
 	} else if (sock_flag(sk, SOCK_LINGER) && !sk->sk_lingertime) {
 		/* Check zero linger _after_ checking for unread data. */
 		sk->sk_prot->disconnect(sk, 0);
Signature · 1 line
2.37.3
author
#2 lore raw

PATCH 2/6 tcp: rstreason: introduce SK_RST_REASON_TCP_ABORT_ON_LINGER for active reset

In reply to Jason Xing

From: Jason Xing <[email protected]>

Introducing a new type TCP_ABORT_ON_LINGER for tcp reset reason to handle negative linger value case.

---
 include/net/rstreason.h | 6 ++++++
 net/ipv4/tcp.c          | 2 +-
 2 files changed, 7 insertions(+), 1 deletion(-)
include/net/rstreason.h +6 -0
index fa6bfd0d7d69..fbbaeb969e6a 100644
@@ -18,6 +18,7 @@
 	FN(TCP_TIMEWAIT_SOCKET)		\
 	FN(INVALID_SYN)			\
 	FN(TCP_ABORT_ON_CLOSE)		\
+	FN(TCP_ABORT_ON_LINGER)		\
 	FN(MPTCP_RST_EUNSPEC)		\
 	FN(MPTCP_RST_EMPTCP)		\
 	FN(MPTCP_RST_ERESOURCE)		\
@@ -90,6 +91,11 @@ enum sk_rst_reason {
 	 * corresponding to LINUX_MIB_TCPABORTONCLOSE
 	 */
 	SK_RST_REASON_TCP_ABORT_ON_CLOSE,
+	/**
+	 * @SK_RST_REASON_TCP_ABORT_ON_LINGER: abort on linger
+	 * corresponding to LINUX_MIB_TCPABORTONLINGER
+	 */
+	SK_RST_REASON_TCP_ABORT_ON_LINGER,
 
 	/* Copy from include/uapi/linux/mptcp.h.
 	 * These reset fields will not be changed since they adhere to
net/ipv4/tcp.c +1 -1
index 2e010add0317..5b0f1d1fc697 100644
@@ -2908,7 +2908,7 @@ void __tcp_close(struct sock *sk, long timeout)
 		if (READ_ONCE(tp->linger2) < 0) {
 			tcp_set_state(sk, TCP_CLOSE);
 			tcp_send_active_reset(sk, GFP_ATOMIC,
-					      SK_RST_REASON_NOT_SPECIFIED);
+					      SK_RST_REASON_TCP_ABORT_ON_LINGER);
 			__NET_INC_STATS(sock_net(sk),
 					LINUX_MIB_TCPABORTONLINGER);
 		} else {
Signature · 1 line
2.37.3
author
#3 lore raw

PATCH 3/6 tcp: rstreason: introduce SK_RST_REASON_TCP_ABORT_ON_MEMORY for active reset

In reply to Jason Xing

From: Jason Xing <[email protected]>

Introducing a new type TCP_ABORT_ON_MEMORY for tcp reset reason to handle out of memory case.

---
 include/net/rstreason.h | 6 ++++++
 net/ipv4/tcp.c          | 2 +-
 net/ipv4/tcp_timer.c    | 2 +-
 3 files changed, 8 insertions(+), 2 deletions(-)
include/net/rstreason.h +6 -0
index fbbaeb969e6a..eef658da8952 100644
@@ -19,6 +19,7 @@
 	FN(INVALID_SYN)			\
 	FN(TCP_ABORT_ON_CLOSE)		\
 	FN(TCP_ABORT_ON_LINGER)		\
+	FN(TCP_ABORT_ON_MEMORY)		\
 	FN(MPTCP_RST_EUNSPEC)		\
 	FN(MPTCP_RST_EMPTCP)		\
 	FN(MPTCP_RST_ERESOURCE)		\
@@ -96,6 +97,11 @@ enum sk_rst_reason {
 	 * corresponding to LINUX_MIB_TCPABORTONLINGER
 	 */
 	SK_RST_REASON_TCP_ABORT_ON_LINGER,
+	/**
+	 * @SK_RST_REASON_TCP_ABORT_ON_MEMORY: abort on memory
+	 * corresponding to LINUX_MIB_TCPABORTONMEMORY
+	 */
+	SK_RST_REASON_TCP_ABORT_ON_MEMORY,
 
 	/* Copy from include/uapi/linux/mptcp.h.
 	 * These reset fields will not be changed since they adhere to
net/ipv4/tcp.c +1 -1
index 5b0f1d1fc697..fd928c447ce8 100644
@@ -2927,7 +2927,7 @@ void __tcp_close(struct sock *sk, long timeout)
 		if (tcp_check_oom(sk, 0)) {
 			tcp_set_state(sk, TCP_CLOSE);
 			tcp_send_active_reset(sk, GFP_ATOMIC,
-					      SK_RST_REASON_NOT_SPECIFIED);
+					      SK_RST_REASON_TCP_ABORT_ON_MEMORY);
 			__NET_INC_STATS(sock_net(sk),
 					LINUX_MIB_TCPABORTONMEMORY);
 		} else if (!check_net(sock_net(sk))) {
net/ipv4/tcp_timer.c +1 -1
index 4d40615dc8fc..0fba4a4fb988 100644
@@ -125,7 +125,7 @@ static int tcp_out_of_resources(struct sock *sk, bool do_reset)
 			do_reset = true;
 		if (do_reset)
 			tcp_send_active_reset(sk, GFP_ATOMIC,
-					      SK_RST_REASON_NOT_SPECIFIED);
+					      SK_RST_REASON_TCP_ABORT_ON_MEMORY);
 		tcp_done(sk);
 		__NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPABORTONMEMORY);
 		return 1;
Signature · 1 line
2.37.3
author
#4 lore raw

PATCH 4/6 tcp: rstreason: introduce SK_RST_REASON_TCP_STATE for active reset

In reply to Jason Xing

From: Jason Xing <[email protected]>

Introducing a new type TCP_STATE to handle some reset conditions appearing in RFC 793 due to its socket state.

---
 include/net/rstreason.h | 6 ++++++
 net/ipv4/tcp.c          | 4 ++--
 net/ipv4/tcp_timer.c    | 2 +-
 3 files changed, 9 insertions(+), 3 deletions(-)
include/net/rstreason.h +6 -0
index eef658da8952..fecaa57f1634 100644
@@ -20,6 +20,7 @@
 	FN(TCP_ABORT_ON_CLOSE)		\
 	FN(TCP_ABORT_ON_LINGER)		\
 	FN(TCP_ABORT_ON_MEMORY)		\
+	FN(TCP_STATE)			\
 	FN(MPTCP_RST_EUNSPEC)		\
 	FN(MPTCP_RST_EMPTCP)		\
 	FN(MPTCP_RST_ERESOURCE)		\
@@ -102,6 +103,11 @@ enum sk_rst_reason {
 	 * corresponding to LINUX_MIB_TCPABORTONMEMORY
 	 */
 	SK_RST_REASON_TCP_ABORT_ON_MEMORY,
+	/**
+	 * @SK_RST_REASON_TCP_STATE: abort on tcp state
+	 * Please see RFC 793 for all possible reset conditions
+	 */
+	SK_RST_REASON_TCP_STATE,
 
 	/* Copy from include/uapi/linux/mptcp.h.
 	 * These reset fields will not be changed since they adhere to
net/ipv4/tcp.c +2 -2
index fd928c447ce8..64a49cb714e1 100644
@@ -3031,7 +3031,7 @@ int tcp_disconnect(struct sock *sk, int flags)
 		/* The last check adjusts for discrepancy of Linux wrt. RFC
 		 * states
 		 */
-		tcp_send_active_reset(sk, gfp_any(), SK_RST_REASON_NOT_SPECIFIED);
+		tcp_send_active_reset(sk, gfp_any(), SK_RST_REASON_TCP_STATE);
 		WRITE_ONCE(sk->sk_err, ECONNRESET);
 	} else if (old_state == TCP_SYN_SENT)
 		WRITE_ONCE(sk->sk_err, ECONNRESET);
@@ -4649,7 +4649,7 @@ int tcp_abort(struct sock *sk, int err)
 	if (!sock_flag(sk, SOCK_DEAD)) {
 		if (tcp_need_reset(sk->sk_state))
 			tcp_send_active_reset(sk, GFP_ATOMIC,
-					      SK_RST_REASON_NOT_SPECIFIED);
+					      SK_RST_REASON_TCP_STATE);
 		tcp_done_with_error(sk, err);
 	}
 
net/ipv4/tcp_timer.c +1 -1
index 0fba4a4fb988..3910f6d8614e 100644
@@ -779,7 +779,7 @@ static void tcp_keepalive_timer (struct timer_list *t)
 				goto out;
 			}
 		}
-		tcp_send_active_reset(sk, GFP_ATOMIC, SK_RST_REASON_NOT_SPECIFIED);
+		tcp_send_active_reset(sk, GFP_ATOMIC, SK_RST_REASON_TCP_STATE);
 		goto death;
 	}
 
Signature · 1 line
2.37.3
#5 lore raw

Re: [PATCH net-next 4/6] tcp: rstreason: introduce SK_RST_REASON_TCP_STATE for active reset

From: Jason Xing <[email protected]>
Date: Tue, 30 Jul 2024 21:35:11 +0800

Quoted 4 lines

From: Jason Xing <[email protected]>

Introducing a new type TCP_STATE to handle some reset conditions appearing in RFC 793 due to its socket state.

Why not RFC 9293 ?
Was there any discrepancy ?

Quoted 21 lines
---
 include/net/rstreason.h | 6 ++++++
 net/ipv4/tcp.c          | 4 ++--
 net/ipv4/tcp_timer.c    | 2 +-
 3 files changed, 9 insertions(+), 3 deletions(-)
include/net/rstreason.h +1 -0
index eef658da8952..fecaa57f1634 100644
@@ -20,6 +20,7 @@
 	FN(TCP_ABORT_ON_CLOSE)		\
 	FN(TCP_ABORT_ON_LINGER)		\
 	FN(TCP_ABORT_ON_MEMORY)		\
+	FN(TCP_STATE)			\
 	FN(MPTCP_RST_EUNSPEC)		\
 	FN(MPTCP_RST_EMPTCP)		\
 	FN(MPTCP_RST_ERESOURCE)		\

include/net/rstreason.h enum sk_rst_reason { · line 110

Quoted 8 lines
include/net/rstreason.h +5 -0
@@ -102,6 +103,11 @@ enum sk_rst_reason {
 	 * corresponding to LINUX_MIB_TCPABORTONMEMORY
 	 */
 	SK_RST_REASON_TCP_ABORT_ON_MEMORY,
+	/**
+	 * @SK_RST_REASON_TCP_STATE: abort on tcp state
+	 * Please see RFC 793 for all possible reset conditions
+	 */
+	SK_RST_REASON_TCP_STATE,

Same here.

author
#6 lore raw

Re: [PATCH net-next 4/6] tcp: rstreason: introduce SK_RST_REASON_TCP_STATE for active reset

Hello Kuniyuki,

Quoted 10 lines · Kuniyuki Iwashima

From: Jason Xing <[email protected]>
Date: Tue, 30 Jul 2024 21:35:11 +0800

Quoted 4 lines

From: Jason Xing <[email protected]>

Introducing a new type TCP_STATE to handle some reset conditions appearing in RFC 793 due to its socket state.

Why not RFC 9293 ?
Was there any discrepancy ?

Thanks for the review.

My intention is to keep consistency with the comment in tcp_need_reset(). I have no strong preference here. Either way is fine with me.

Thanks,
Jason

Quoted 33 lines
Quoted 23 lines
---
 include/net/rstreason.h | 6 ++++++
 net/ipv4/tcp.c          | 4 ++--
 net/ipv4/tcp_timer.c    | 2 +-
 3 files changed, 9 insertions(+), 3 deletions(-)
include/net/rstreason.h +1 -0
index eef658da8952..fecaa57f1634 100644
@@ -20,6 +20,7 @@
      FN(TCP_ABORT_ON_CLOSE)          \
      FN(TCP_ABORT_ON_LINGER)         \
      FN(TCP_ABORT_ON_MEMORY)         \
+     FN(TCP_STATE)                   \
      FN(MPTCP_RST_EUNSPEC)           \
      FN(MPTCP_RST_EMPTCP)            \
      FN(MPTCP_RST_ERESOURCE)         \

include/net/rstreason.h enum sk_rst_reason { · line 110

Quoted 8 lines
include/net/rstreason.h +5 -0
@@ -102,6 +103,11 @@ enum sk_rst_reason {
       * corresponding to LINUX_MIB_TCPABORTONMEMORY
       */
      SK_RST_REASON_TCP_ABORT_ON_MEMORY,
+     /**
+      * @SK_RST_REASON_TCP_STATE: abort on tcp state
+      * Please see RFC 793 for all possible reset conditions
+      */
+     SK_RST_REASON_TCP_STATE,

Same here.

author
#7 lore raw

PATCH 5/6 tcp: rstreason: introduce SK_RST_REASON_TCP_TIMEOUT for active reset

In reply to Jason Xing

From: Jason Xing <[email protected]>

Only when user sets TCP_USER_TIMEOUT option and there is no left chance to proceed, we will send an RST to the other side.

---
 include/net/rstreason.h | 7 +++++++
 net/ipv4/tcp_timer.c    | 2 +-
 2 files changed, 8 insertions(+), 1 deletion(-)
include/net/rstreason.h +7 -0
index fecaa57f1634..ca10aaebd768 100644
@@ -21,6 +21,7 @@
 	FN(TCP_ABORT_ON_LINGER)		\
 	FN(TCP_ABORT_ON_MEMORY)		\
 	FN(TCP_STATE)			\
+	FN(TCP_TIMEOUT)			\
 	FN(MPTCP_RST_EUNSPEC)		\
 	FN(MPTCP_RST_EMPTCP)		\
 	FN(MPTCP_RST_ERESOURCE)		\
@@ -108,6 +109,12 @@ enum sk_rst_reason {
 	 * Please see RFC 793 for all possible reset conditions
 	 */
 	SK_RST_REASON_TCP_STATE,
+	/**
+	 * @SK_RST_REASON_TCP_TIMEOUT: time to timeout
+	 * When user sets TCP_USER_TIMEOUT options and run out of all the
+	 * chance, we have to reset the connection
+	 */
+	SK_RST_REASON_TCP_TIMEOUT,
 
 	/* Copy from include/uapi/linux/mptcp.h.
 	 * These reset fields will not be changed since they adhere to
net/ipv4/tcp_timer.c +1 -1
index 3910f6d8614e..bd403300e4c4 100644
@@ -807,7 +807,7 @@ static void tcp_keepalive_timer (struct timer_list *t)
 		    (user_timeout == 0 &&
 		    icsk->icsk_probes_out >= keepalive_probes(tp))) {
 			tcp_send_active_reset(sk, GFP_ATOMIC,
-					      SK_RST_REASON_NOT_SPECIFIED);
+					      SK_RST_REASON_TCP_TIMEOUT);
 			tcp_write_err(sk);
 			goto out;
 		}
Signature · 1 line
2.37.3
#8 lore raw

Re: [PATCH net-next 5/6] tcp: rstreason: introduce SK_RST_REASON_TCP_TIMEOUT for active reset

From: Jason Xing <[email protected]>
Date: Tue, 30 Jul 2024 21:35:12 +0800

Quoted 24 lines

From: Jason Xing <[email protected]>

Only when user sets TCP_USER_TIMEOUT option and there is no left chance to proceed, we will send an RST to the other side.

---
 include/net/rstreason.h | 7 +++++++
 net/ipv4/tcp_timer.c    | 2 +-
 2 files changed, 8 insertions(+), 1 deletion(-)
include/net/rstreason.h +1 -0
index fecaa57f1634..ca10aaebd768 100644
@@ -21,6 +21,7 @@
 	FN(TCP_ABORT_ON_LINGER)		\
 	FN(TCP_ABORT_ON_MEMORY)		\
 	FN(TCP_STATE)			\
+	FN(TCP_TIMEOUT)			\
 	FN(MPTCP_RST_EUNSPEC)		\
 	FN(MPTCP_RST_EMPTCP)		\
 	FN(MPTCP_RST_ERESOURCE)		\

include/net/rstreason.h enum sk_rst_reason { · line 117

Quoted 9 lines
include/net/rstreason.h +6 -0
@@ -108,6 +109,12 @@ enum sk_rst_reason {
 	 * Please see RFC 793 for all possible reset conditions
 	 */
 	SK_RST_REASON_TCP_STATE,
+	/**
+	 * @SK_RST_REASON_TCP_TIMEOUT: time to timeout
+	 * When user sets TCP_USER_TIMEOUT options and run out of all the
+	 * chance, we have to reset the connection
+	 */
+	SK_RST_REASON_TCP_TIMEOUT,

nit: Maybe SK_RST_REASON_TCP_USER_TIMEOUT ?

It's more user-friendly.

author
#9 lore raw

Re: [PATCH net-next 5/6] tcp: rstreason: introduce SK_RST_REASON_TCP_TIMEOUT for active reset

Quoted 39 lines · Kuniyuki Iwashima

From: Jason Xing <[email protected]>
Date: Tue, 30 Jul 2024 21:35:12 +0800

Quoted 24 lines

From: Jason Xing <[email protected]>

Only when user sets TCP_USER_TIMEOUT option and there is no left chance to proceed, we will send an RST to the other side.

---
 include/net/rstreason.h | 7 +++++++
 net/ipv4/tcp_timer.c    | 2 +-
 2 files changed, 8 insertions(+), 1 deletion(-)
include/net/rstreason.h +1 -0
index fecaa57f1634..ca10aaebd768 100644
@@ -21,6 +21,7 @@
      FN(TCP_ABORT_ON_LINGER)         \
      FN(TCP_ABORT_ON_MEMORY)         \
      FN(TCP_STATE)                   \
+     FN(TCP_TIMEOUT)                 \
      FN(MPTCP_RST_EUNSPEC)           \
      FN(MPTCP_RST_EMPTCP)            \
      FN(MPTCP_RST_ERESOURCE)         \

include/net/rstreason.h enum sk_rst_reason { · line 117

Quoted 9 lines
include/net/rstreason.h +6 -0
@@ -108,6 +109,12 @@ enum sk_rst_reason {
       * Please see RFC 793 for all possible reset conditions
       */
      SK_RST_REASON_TCP_STATE,
+     /**
+      * @SK_RST_REASON_TCP_TIMEOUT: time to timeout
+      * When user sets TCP_USER_TIMEOUT options and run out of all the
+      * chance, we have to reset the connection
+      */
+     SK_RST_REASON_TCP_TIMEOUT,

nit: Maybe SK_RST_REASON_TCP_USER_TIMEOUT ?

Quoted 1 line

It's more user-friendly.

Oh, after you reminding me, I double-check this part and find this changelog is not that right because there is the other case where user doesn't set TCP_USER_TIMEOUT option:
"user_timeout == 0 && icsk->icsk_probes_out >= keepalive_probes(tp)" in tcp_keepalive_timer().

I will correct my comment as well.

I think I can keep SK_RST_REASON_TCP_STATE instead of SK_RST_REASON_TCP_USER_TIMEOUT to show "we already try as many times as we can whether TCP_USER_TIMEOUT option is set or not, but we have to reset".

Thanks,
Jason

author
#10 lore raw

PATCH 6/6 tcp: rstreason: let it work finally in tcp_send_active_reset()

In reply to Jason Xing

From: Jason Xing <[email protected]>

Now it's time to let it work by using the 'reason' parameter in the trace world :)

---
 net/ipv4/tcp_output.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/ipv4/tcp_output.c +1 -1
index 16c48df8df4c..cdd0def14427 100644
@@ -3649,7 +3649,7 @@ void tcp_send_active_reset(struct sock *sk, gfp_t priority,
 	/* skb of trace_tcp_send_reset() keeps the skb that caused RST,
 	 * skb here is different to the troublesome skb, so use NULL
 	 */
-	trace_tcp_send_reset(sk, NULL, SK_RST_REASON_NOT_SPECIFIED);
+	trace_tcp_send_reset(sk, NULL, reason);
 }
 
 /* Send a crossed SYN-ACK during socket establishment.
Signature · 1 line
2.37.3