Commit c026c656 authored by Jason Xing's avatar Jason Xing Committed by David S. Miller

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: default avatarJason Xing <kernelxing@tencent.com>
Reviewed-by: default avatarEric Dumazet <edumazet@google.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 0a399892
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
FN(TCP_ABORT_ON_MEMORY) \ FN(TCP_ABORT_ON_MEMORY) \
FN(TCP_STATE) \ FN(TCP_STATE) \
FN(TCP_KEEPALIVE_TIMEOUT) \ FN(TCP_KEEPALIVE_TIMEOUT) \
FN(TCP_DISCONNECT_WITH_DATA) \
FN(MPTCP_RST_EUNSPEC) \ FN(MPTCP_RST_EUNSPEC) \
FN(MPTCP_RST_EMPTCP) \ FN(MPTCP_RST_EMPTCP) \
FN(MPTCP_RST_ERESOURCE) \ FN(MPTCP_RST_ERESOURCE) \
...@@ -115,6 +116,13 @@ enum sk_rst_reason { ...@@ -115,6 +116,13 @@ enum sk_rst_reason {
* keepalive timeout, we have to reset the connection * keepalive timeout, we have to reset the connection
*/ */
SK_RST_REASON_TCP_KEEPALIVE_TIMEOUT, 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. /* Copy from include/uapi/linux/mptcp.h.
* These reset fields will not be changed since they adhere to * These reset fields will not be changed since they adhere to
......
...@@ -3033,7 +3033,8 @@ int tcp_disconnect(struct sock *sk, int flags) ...@@ -3033,7 +3033,8 @@ int tcp_disconnect(struct sock *sk, int flags)
/* The last check adjusts for discrepancy of Linux wrt. RFC /* The last check adjusts for discrepancy of Linux wrt. RFC
* states * 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); WRITE_ONCE(sk->sk_err, ECONNRESET);
} else if (old_state == TCP_SYN_SENT) } else if (old_state == TCP_SYN_SENT)
WRITE_ONCE(sk->sk_err, ECONNRESET); WRITE_ONCE(sk->sk_err, ECONNRESET);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment