Skip to content

Commit c026c65

Browse files
JasonXingdavem330
authored andcommitted
tcp: rstreason: introduce SK_RST_REASON_TCP_DISCONNECT_WITH_DATA for active reset
When user tries to disconnect a socket and there are more data written into tcp write queue, we should tell users about this reset reason. Signed-off-by: Jason Xing <[email protected]> Reviewed-by: Eric Dumazet <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 0a39989 commit c026c65

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

include/net/rstreason.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
FN(TCP_ABORT_ON_MEMORY) \
2323
FN(TCP_STATE) \
2424
FN(TCP_KEEPALIVE_TIMEOUT) \
25+
FN(TCP_DISCONNECT_WITH_DATA) \
2526
FN(MPTCP_RST_EUNSPEC) \
2627
FN(MPTCP_RST_EMPTCP) \
2728
FN(MPTCP_RST_ERESOURCE) \
@@ -115,6 +116,13 @@ enum sk_rst_reason {
115116
* keepalive timeout, we have to reset the connection
116117
*/
117118
SK_RST_REASON_TCP_KEEPALIVE_TIMEOUT,
119+
/**
120+
* @SK_RST_REASON_TCP_DISCONNECT_WITH_DATA: disconnect when write
121+
* queue is not empty
122+
* It means user has written data into the write queue when doing
123+
* disconnecting, so we have to send an RST.
124+
*/
125+
SK_RST_REASON_TCP_DISCONNECT_WITH_DATA,
118126

119127
/* Copy from include/uapi/linux/mptcp.h.
120128
* These reset fields will not be changed since they adhere to

net/ipv4/tcp.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3033,7 +3033,8 @@ int tcp_disconnect(struct sock *sk, int flags)
30333033
/* The last check adjusts for discrepancy of Linux wrt. RFC
30343034
* states
30353035
*/
3036-
tcp_send_active_reset(sk, gfp_any(), SK_RST_REASON_NOT_SPECIFIED);
3036+
tcp_send_active_reset(sk, gfp_any(),
3037+
SK_RST_REASON_TCP_DISCONNECT_WITH_DATA);
30373038
WRITE_ONCE(sk->sk_err, ECONNRESET);
30383039
} else if (old_state == TCP_SYN_SENT)
30393040
WRITE_ONCE(sk->sk_err, ECONNRESET);

0 commit comments

Comments
 (0)