1 /* SPDX-License-Identifier: GPL-2.0-or-later */
3 #ifndef _LINUX_RSTREASON_H
4 #define _LINUX_RSTREASON_H
5 #include <net/dropreason-core.h>
6 #include <uapi/linux/mptcp.h>
8 #define DEFINE_RST_REASON(FN, FNe) \
11 FN(TCP_INVALID_ACK_SEQUENCE) \
12 FN(TCP_RFC7323_PAWS) \
14 FN(TCP_ACK_UNSENT_DATA) \
17 FN(TCP_ABORT_ON_DATA) \
18 FN(TCP_TIMEWAIT_SOCKET) \
20 FN(TCP_ABORT_ON_CLOSE) \
21 FN(TCP_ABORT_ON_LINGER) \
22 FN(TCP_ABORT_ON_MEMORY) \
24 FN(TCP_KEEPALIVE_TIMEOUT) \
25 FN(TCP_DISCONNECT_WITH_DATA) \
26 FN(MPTCP_RST_EUNSPEC) \
27 FN(MPTCP_RST_EMPTCP) \
28 FN(MPTCP_RST_ERESOURCE) \
29 FN(MPTCP_RST_EPROHIBIT) \
30 FN(MPTCP_RST_EWQ2BIG) \
31 FN(MPTCP_RST_EBADPERF) \
32 FN(MPTCP_RST_EMIDDLEBOX) \
37 * enum sk_rst_reason - the reasons of socket reset
39 * The reasons of sk reset, which are used in DCCP/TCP/MPTCP protocols.
41 * There are three parts in order:
42 * 1) skb drop reasons: relying on drop reasons for such as passive reset
43 * 2) independent reset reasons: such as active reset reasons
44 * 3) reset reasons in MPTCP: only for MPTCP use
47 /* Refer to include/net/dropreason-core.h
48 * Rely on skb drop reasons because it indicates exactly why RST
51 /** @SK_RST_REASON_NOT_SPECIFIED: reset reason is not specified */
52 SK_RST_REASON_NOT_SPECIFIED
,
53 /** @SK_RST_REASON_NO_SOCKET: no valid socket that can be used */
54 SK_RST_REASON_NO_SOCKET
,
56 * @SK_RST_REASON_TCP_INVALID_ACK_SEQUENCE: Not acceptable ACK SEQ
57 * field because ack sequence is not in the window between snd_una
60 SK_RST_REASON_TCP_INVALID_ACK_SEQUENCE
,
62 * @SK_RST_REASON_TCP_RFC7323_PAWS: PAWS check, corresponding to
63 * LINUX_MIB_PAWSESTABREJECTED, LINUX_MIB_PAWSACTIVEREJECTED
65 SK_RST_REASON_TCP_RFC7323_PAWS
,
66 /** @SK_RST_REASON_TCP_TOO_OLD_ACK: TCP ACK is too old */
67 SK_RST_REASON_TCP_TOO_OLD_ACK
,
69 * @SK_RST_REASON_TCP_ACK_UNSENT_DATA: TCP ACK for data we haven't
72 SK_RST_REASON_TCP_ACK_UNSENT_DATA
,
73 /** @SK_RST_REASON_TCP_FLAGS: TCP flags invalid */
74 SK_RST_REASON_TCP_FLAGS
,
75 /** @SK_RST_REASON_TCP_OLD_ACK: TCP ACK is old, but in window */
76 SK_RST_REASON_TCP_OLD_ACK
,
78 * @SK_RST_REASON_TCP_ABORT_ON_DATA: abort on data
79 * corresponding to LINUX_MIB_TCPABORTONDATA
81 SK_RST_REASON_TCP_ABORT_ON_DATA
,
83 /* Here start with the independent reasons */
84 /** @SK_RST_REASON_TCP_TIMEWAIT_SOCKET: happen on the timewait socket */
85 SK_RST_REASON_TCP_TIMEWAIT_SOCKET
,
87 * @SK_RST_REASON_INVALID_SYN: receive bad syn packet
88 * RFC 793 says if the state is not CLOSED/LISTEN/SYN-SENT then
89 * "fourth, check the SYN bit,...If the SYN is in the window it is
90 * an error, send a reset"
92 SK_RST_REASON_INVALID_SYN
,
94 * @SK_RST_REASON_TCP_ABORT_ON_CLOSE: abort on close
95 * corresponding to LINUX_MIB_TCPABORTONCLOSE
97 SK_RST_REASON_TCP_ABORT_ON_CLOSE
,
99 * @SK_RST_REASON_TCP_ABORT_ON_LINGER: abort on linger
100 * corresponding to LINUX_MIB_TCPABORTONLINGER
102 SK_RST_REASON_TCP_ABORT_ON_LINGER
,
104 * @SK_RST_REASON_TCP_ABORT_ON_MEMORY: abort on memory
105 * corresponding to LINUX_MIB_TCPABORTONMEMORY
107 SK_RST_REASON_TCP_ABORT_ON_MEMORY
,
109 * @SK_RST_REASON_TCP_STATE: abort on tcp state
110 * Please see RFC 9293 for all possible reset conditions
112 SK_RST_REASON_TCP_STATE
,
114 * @SK_RST_REASON_TCP_KEEPALIVE_TIMEOUT: time to timeout
115 * When we have already run out of all the chances, which means
116 * keepalive timeout, we have to reset the connection
118 SK_RST_REASON_TCP_KEEPALIVE_TIMEOUT
,
120 * @SK_RST_REASON_TCP_DISCONNECT_WITH_DATA: disconnect when write
122 * It means user has written data into the write queue when doing
123 * disconnecting, so we have to send an RST.
125 SK_RST_REASON_TCP_DISCONNECT_WITH_DATA
,
127 /* Copy from include/uapi/linux/mptcp.h.
128 * These reset fields will not be changed since they adhere to
129 * RFC 8684. So do not touch them. I'm going to list each definition
130 * of them respectively.
133 * @SK_RST_REASON_MPTCP_RST_EUNSPEC: Unspecified error.
134 * This is the default error; it implies that the subflow is no
135 * longer available. The presence of this option shows that the
136 * RST was generated by an MPTCP-aware device.
138 SK_RST_REASON_MPTCP_RST_EUNSPEC
,
140 * @SK_RST_REASON_MPTCP_RST_EMPTCP: MPTCP-specific error.
141 * An error has been detected in the processing of MPTCP options.
142 * This is the usual reason code to return in the cases where a RST
143 * is being sent to close a subflow because of an invalid response.
145 SK_RST_REASON_MPTCP_RST_EMPTCP
,
147 * @SK_RST_REASON_MPTCP_RST_ERESOURCE: Lack of resources.
148 * This code indicates that the sending host does not have enough
149 * resources to support the terminated subflow.
151 SK_RST_REASON_MPTCP_RST_ERESOURCE
,
153 * @SK_RST_REASON_MPTCP_RST_EPROHIBIT: Administratively prohibited.
154 * This code indicates that the requested subflow is prohibited by
155 * the policies of the sending host.
157 SK_RST_REASON_MPTCP_RST_EPROHIBIT
,
159 * @SK_RST_REASON_MPTCP_RST_EWQ2BIG: Too much outstanding data.
160 * This code indicates that there is an excessive amount of data
161 * that needs to be transmitted over the terminated subflow while
162 * having already been acknowledged over one or more other subflows.
163 * This may occur if a path has been unavailable for a short period
164 * and it is more efficient to reset and start again than it is to
165 * retransmit the queued data.
167 SK_RST_REASON_MPTCP_RST_EWQ2BIG
,
169 * @SK_RST_REASON_MPTCP_RST_EBADPERF: Unacceptable performance.
170 * This code indicates that the performance of this subflow was
171 * too low compared to the other subflows of this Multipath TCP
174 SK_RST_REASON_MPTCP_RST_EBADPERF
,
176 * @SK_RST_REASON_MPTCP_RST_EMIDDLEBOX: Middlebox interference.
177 * Middlebox interference has been detected over this subflow,
178 * making MPTCP signaling invalid. For example, this may be sent
179 * if the checksum does not validate.
181 SK_RST_REASON_MPTCP_RST_EMIDDLEBOX
,
183 /** @SK_RST_REASON_ERROR: unexpected error happens */
187 * @SK_RST_REASON_MAX: Maximum of socket reset reasons.
188 * It shouldn't be used as a real 'reason'.
193 /* Convert skb drop reasons to enum sk_rst_reason type */
194 static inline enum sk_rst_reason
195 sk_rst_convert_drop_reason(enum skb_drop_reason reason
)
198 case SKB_DROP_REASON_NOT_SPECIFIED
:
199 return SK_RST_REASON_NOT_SPECIFIED
;
200 case SKB_DROP_REASON_NO_SOCKET
:
201 return SK_RST_REASON_NO_SOCKET
;
202 case SKB_DROP_REASON_TCP_INVALID_ACK_SEQUENCE
:
203 return SK_RST_REASON_TCP_INVALID_ACK_SEQUENCE
;
204 case SKB_DROP_REASON_TCP_RFC7323_PAWS
:
205 return SK_RST_REASON_TCP_RFC7323_PAWS
;
206 case SKB_DROP_REASON_TCP_TOO_OLD_ACK
:
207 return SK_RST_REASON_TCP_TOO_OLD_ACK
;
208 case SKB_DROP_REASON_TCP_ACK_UNSENT_DATA
:
209 return SK_RST_REASON_TCP_ACK_UNSENT_DATA
;
210 case SKB_DROP_REASON_TCP_FLAGS
:
211 return SK_RST_REASON_TCP_FLAGS
;
212 case SKB_DROP_REASON_TCP_OLD_ACK
:
213 return SK_RST_REASON_TCP_OLD_ACK
;
214 case SKB_DROP_REASON_TCP_ABORT_ON_DATA
:
215 return SK_RST_REASON_TCP_ABORT_ON_DATA
;
217 /* If we don't have our own corresponding reason */
218 return SK_RST_REASON_NOT_SPECIFIED
;