Skip to content

Commit edefba6

Browse files
JasonXingdavem330
authored andcommitted
tcp: rstreason: introduce SK_RST_REASON_TCP_STATE for active reset
Introducing a new type TCP_STATE to handle some reset conditions appearing in RFC 793 due to its socket state. Actually, we can look into RFC 9293 which has no discrepancy about this part. Signed-off-by: Jason Xing <[email protected]> Reviewed-by: Eric Dumazet <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 8407994 commit edefba6

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

include/net/rstreason.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
FN(TCP_ABORT_ON_CLOSE) \
2121
FN(TCP_ABORT_ON_LINGER) \
2222
FN(TCP_ABORT_ON_MEMORY) \
23+
FN(TCP_STATE) \
2324
FN(MPTCP_RST_EUNSPEC) \
2425
FN(MPTCP_RST_EMPTCP) \
2526
FN(MPTCP_RST_ERESOURCE) \
@@ -102,6 +103,11 @@ enum sk_rst_reason {
102103
* corresponding to LINUX_MIB_TCPABORTONMEMORY
103104
*/
104105
SK_RST_REASON_TCP_ABORT_ON_MEMORY,
106+
/**
107+
* @SK_RST_REASON_TCP_STATE: abort on tcp state
108+
* Please see RFC 9293 for all possible reset conditions
109+
*/
110+
SK_RST_REASON_TCP_STATE,
105111

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

net/ipv4/tcp.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3025,9 +3025,11 @@ int tcp_disconnect(struct sock *sk, int flags)
30253025
inet_csk_listen_stop(sk);
30263026
} else if (unlikely(tp->repair)) {
30273027
WRITE_ONCE(sk->sk_err, ECONNABORTED);
3028-
} else if (tcp_need_reset(old_state) ||
3029-
(tp->snd_nxt != tp->write_seq &&
3030-
(1 << old_state) & (TCPF_CLOSING | TCPF_LAST_ACK))) {
3028+
} else if (tcp_need_reset(old_state)) {
3029+
tcp_send_active_reset(sk, gfp_any(), SK_RST_REASON_TCP_STATE);
3030+
WRITE_ONCE(sk->sk_err, ECONNRESET);
3031+
} else if (tp->snd_nxt != tp->write_seq &&
3032+
(1 << old_state) & (TCPF_CLOSING | TCPF_LAST_ACK)) {
30313033
/* The last check adjusts for discrepancy of Linux wrt. RFC
30323034
* states
30333035
*/
@@ -4649,7 +4651,7 @@ int tcp_abort(struct sock *sk, int err)
46494651
if (!sock_flag(sk, SOCK_DEAD)) {
46504652
if (tcp_need_reset(sk->sk_state))
46514653
tcp_send_active_reset(sk, GFP_ATOMIC,
4652-
SK_RST_REASON_NOT_SPECIFIED);
4654+
SK_RST_REASON_TCP_STATE);
46534655
tcp_done_with_error(sk, err);
46544656
}
46554657

net/ipv4/tcp_timer.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -779,7 +779,7 @@ static void tcp_keepalive_timer (struct timer_list *t)
779779
goto out;
780780
}
781781
}
782-
tcp_send_active_reset(sk, GFP_ATOMIC, SK_RST_REASON_NOT_SPECIFIED);
782+
tcp_send_active_reset(sk, GFP_ATOMIC, SK_RST_REASON_TCP_STATE);
783783
goto death;
784784
}
785785

0 commit comments

Comments
 (0)