From: Jason Xing <kerneljasonxing@gmail•com>
To: davem@davemloft•net, edumazet@google•com, kuba@kernel•org,
pabeni@redhat•com, dsahern@kernel•org, kuniyu@amazon•com
Cc: netdev@vger•kernel.org, Jason Xing <kernelxing@tencent•com>
Subject: [PATCH net-next v3 6/7] tcp: rstreason: introduce SK_RST_REASON_TCP_DISCONNECT_WITH_DATA for active reset
Date: Thu, 1 Aug 2024 22:54:43 +0800 [thread overview]
Message-ID: <20240801145444.22988-7-kerneljasonxing@gmail.com> (raw)
In-Reply-To: <20240801145444.22988-1-kerneljasonxing@gmail.com>
From: Jason Xing <kernelxing@tencent•com>
When user tries to disconnect a socket and there are more data written
into tcp write queue, we have to send an RST.
Signed-off-by: Jason Xing <kernelxing@tencent•com>
--
v3
Link: Link: https://lore.kernel.org/all/20240731120955.23542-5-kerneljasonxing@gmail.com/
1. This case is different from previous patch, so we need to write
it into a new patch. (Eric)
---
include/net/rstreason.h | 8 ++++++++
net/ipv4/tcp.c | 3 ++-
2 files changed, 10 insertions(+), 1 deletion(-)
diff --git a/include/net/rstreason.h b/include/net/rstreason.h
index 9c0c46df0e73..69cb2e52b7da 100644
--- a/include/net/rstreason.h
+++ b/include/net/rstreason.h
@@ -22,6 +22,7 @@
FN(TCP_ABORT_ON_MEMORY) \
FN(TCP_STATE) \
FN(TCP_KEEPALIVE_TIMEOUT) \
+ FN(TCP_DISCONNECT_WITH_DATA) \
FN(MPTCP_RST_EUNSPEC) \
FN(MPTCP_RST_EMPTCP) \
FN(MPTCP_RST_ERESOURCE) \
@@ -115,6 +116,13 @@ enum sk_rst_reason {
* keepalive timeout, we have to reset the connection
*/
SK_RST_REASON_TCP_KEEPALIVE_TIMEOUT,
+ /**
+ * @SK_RST_REASON_TCP_DISCONNECT_WITH_DATA: disconnect when write
+ * queue is not empty
+ * It means user has written data into the write queue when doing
+ * disconnecting, so we have to send an RST.
+ */
+ SK_RST_REASON_TCP_DISCONNECT_WITH_DATA,
/* Copy from include/uapi/linux/mptcp.h.
* These reset fields will not be changed since they adhere to
diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
index 24777e48bcc8..8514257f4ecd 100644
--- a/net/ipv4/tcp.c
+++ b/net/ipv4/tcp.c
@@ -3033,7 +3033,8 @@ 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_DISCONNECT_WITH_DATA);
WRITE_ONCE(sk->sk_err, ECONNRESET);
} else if (old_state == TCP_SYN_SENT)
WRITE_ONCE(sk->sk_err, ECONNRESET);
--
2.37.3
next prev parent reply other threads:[~2024-08-01 14:55 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-01 14:54 [PATCH net-next v3 0/7] tcp: completely support active reset Jason Xing
2024-08-01 14:54 ` [PATCH net-next v3 1/7] tcp: rstreason: introduce SK_RST_REASON_TCP_ABORT_ON_CLOSE for " Jason Xing
2024-08-01 14:54 ` [PATCH net-next v3 2/7] tcp: rstreason: introduce SK_RST_REASON_TCP_ABORT_ON_LINGER " Jason Xing
2024-08-01 14:54 ` [PATCH net-next v3 3/7] tcp: rstreason: introduce SK_RST_REASON_TCP_ABORT_ON_MEMORY " Jason Xing
2024-08-01 14:54 ` [PATCH net-next v3 4/7] tcp: rstreason: introduce SK_RST_REASON_TCP_STATE " Jason Xing
2024-08-02 9:41 ` Eric Dumazet
2024-08-02 9:49 ` Jason Xing
2024-08-01 14:54 ` [PATCH net-next v3 5/7] tcp: rstreason: introduce SK_RST_REASON_TCP_KEEPALIVE_TIMEOUT " Jason Xing
2024-08-02 9:35 ` Eric Dumazet
2024-08-02 9:45 ` Jason Xing
2024-08-01 14:54 ` Jason Xing [this message]
2024-08-02 9:32 ` [PATCH net-next v3 6/7] tcp: rstreason: introduce SK_RST_REASON_TCP_DISCONNECT_WITH_DATA " Eric Dumazet
2024-08-01 14:54 ` [PATCH net-next v3 7/7] tcp: rstreason: let it work finally in tcp_send_active_reset() Jason Xing
2024-08-02 9:32 ` Eric Dumazet
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240801145444.22988-7-kerneljasonxing@gmail.com \
--to=kerneljasonxing@gmail$(echo .)com \
--cc=davem@davemloft$(echo .)net \
--cc=dsahern@kernel$(echo .)org \
--cc=edumazet@google$(echo .)com \
--cc=kernelxing@tencent$(echo .)com \
--cc=kuba@kernel$(echo .)org \
--cc=kuniyu@amazon$(echo .)com \
--cc=netdev@vger$(echo .)kernel.org \
--cc=pabeni@redhat$(echo .)com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox