15cb2cb3cSJason Xing /* SPDX-License-Identifier: GPL-2.0-or-later */
25cb2cb3cSJason Xing
35cb2cb3cSJason Xing #ifndef _LINUX_RSTREASON_H
45cb2cb3cSJason Xing #define _LINUX_RSTREASON_H
55cb2cb3cSJason Xing #include <net/dropreason-core.h>
65cb2cb3cSJason Xing #include <uapi/linux/mptcp.h>
75cb2cb3cSJason Xing
85cb2cb3cSJason Xing #define DEFINE_RST_REASON(FN, FNe) \
95cb2cb3cSJason Xing FN(NOT_SPECIFIED) \
105cb2cb3cSJason Xing FN(NO_SOCKET) \
112b9669d6SJason Xing FN(TCP_INVALID_ACK_SEQUENCE) \
122b9669d6SJason Xing FN(TCP_RFC7323_PAWS) \
13459a2b37SJason Xing FN(TCP_TOO_OLD_ACK) \
14459a2b37SJason Xing FN(TCP_ACK_UNSENT_DATA) \
15f6d5e2ccSJason Xing FN(TCP_FLAGS) \
16f6d5e2ccSJason Xing FN(TCP_OLD_ACK) \
17f6d5e2ccSJason Xing FN(TCP_ABORT_ON_DATA) \
1822a32557SJason Xing FN(TCP_TIMEWAIT_SOCKET) \
1911f46ea9SJason Xing FN(INVALID_SYN) \
2090c36325SJason Xing FN(TCP_ABORT_ON_CLOSE) \
21edc92b48SJason Xing FN(TCP_ABORT_ON_LINGER) \
228407994fSJason Xing FN(TCP_ABORT_ON_MEMORY) \
23edefba66SJason Xing FN(TCP_STATE) \
240a399892SJason Xing FN(TCP_KEEPALIVE_TIMEOUT) \
25*c026c656SJason Xing FN(TCP_DISCONNECT_WITH_DATA) \
265cb2cb3cSJason Xing FN(MPTCP_RST_EUNSPEC) \
275cb2cb3cSJason Xing FN(MPTCP_RST_EMPTCP) \
285cb2cb3cSJason Xing FN(MPTCP_RST_ERESOURCE) \
295cb2cb3cSJason Xing FN(MPTCP_RST_EPROHIBIT) \
305cb2cb3cSJason Xing FN(MPTCP_RST_EWQ2BIG) \
315cb2cb3cSJason Xing FN(MPTCP_RST_EBADPERF) \
325cb2cb3cSJason Xing FN(MPTCP_RST_EMIDDLEBOX) \
335cb2cb3cSJason Xing FN(ERROR) \
345cb2cb3cSJason Xing FNe(MAX)
355cb2cb3cSJason Xing
365cb2cb3cSJason Xing /**
375cb2cb3cSJason Xing * enum sk_rst_reason - the reasons of socket reset
385cb2cb3cSJason Xing *
395cb2cb3cSJason Xing * The reasons of sk reset, which are used in DCCP/TCP/MPTCP protocols.
405cb2cb3cSJason Xing *
415cb2cb3cSJason Xing * There are three parts in order:
425cb2cb3cSJason Xing * 1) skb drop reasons: relying on drop reasons for such as passive reset
435cb2cb3cSJason Xing * 2) independent reset reasons: such as active reset reasons
445cb2cb3cSJason Xing * 3) reset reasons in MPTCP: only for MPTCP use
455cb2cb3cSJason Xing */
465cb2cb3cSJason Xing enum sk_rst_reason {
475cb2cb3cSJason Xing /* Refer to include/net/dropreason-core.h
485cb2cb3cSJason Xing * Rely on skb drop reasons because it indicates exactly why RST
495cb2cb3cSJason Xing * could happen.
505cb2cb3cSJason Xing */
515cb2cb3cSJason Xing /** @SK_RST_REASON_NOT_SPECIFIED: reset reason is not specified */
525cb2cb3cSJason Xing SK_RST_REASON_NOT_SPECIFIED,
535cb2cb3cSJason Xing /** @SK_RST_REASON_NO_SOCKET: no valid socket that can be used */
545cb2cb3cSJason Xing SK_RST_REASON_NO_SOCKET,
552b9669d6SJason Xing /**
562b9669d6SJason Xing * @SK_RST_REASON_TCP_INVALID_ACK_SEQUENCE: Not acceptable ACK SEQ
572b9669d6SJason Xing * field because ack sequence is not in the window between snd_una
582b9669d6SJason Xing * and snd_nxt
592b9669d6SJason Xing */
602b9669d6SJason Xing SK_RST_REASON_TCP_INVALID_ACK_SEQUENCE,
612b9669d6SJason Xing /**
622b9669d6SJason Xing * @SK_RST_REASON_TCP_RFC7323_PAWS: PAWS check, corresponding to
632b9669d6SJason Xing * LINUX_MIB_PAWSESTABREJECTED, LINUX_MIB_PAWSACTIVEREJECTED
642b9669d6SJason Xing */
652b9669d6SJason Xing SK_RST_REASON_TCP_RFC7323_PAWS,
66459a2b37SJason Xing /** @SK_RST_REASON_TCP_TOO_OLD_ACK: TCP ACK is too old */
67459a2b37SJason Xing SK_RST_REASON_TCP_TOO_OLD_ACK,
68459a2b37SJason Xing /**
69459a2b37SJason Xing * @SK_RST_REASON_TCP_ACK_UNSENT_DATA: TCP ACK for data we haven't
70459a2b37SJason Xing * sent yet
71459a2b37SJason Xing */
72459a2b37SJason Xing SK_RST_REASON_TCP_ACK_UNSENT_DATA,
73f6d5e2ccSJason Xing /** @SK_RST_REASON_TCP_FLAGS: TCP flags invalid */
74f6d5e2ccSJason Xing SK_RST_REASON_TCP_FLAGS,
75f6d5e2ccSJason Xing /** @SK_RST_REASON_TCP_OLD_ACK: TCP ACK is old, but in window */
76f6d5e2ccSJason Xing SK_RST_REASON_TCP_OLD_ACK,
77f6d5e2ccSJason Xing /**
78f6d5e2ccSJason Xing * @SK_RST_REASON_TCP_ABORT_ON_DATA: abort on data
79f6d5e2ccSJason Xing * corresponding to LINUX_MIB_TCPABORTONDATA
80f6d5e2ccSJason Xing */
81f6d5e2ccSJason Xing SK_RST_REASON_TCP_ABORT_ON_DATA,
825cb2cb3cSJason Xing
8322a32557SJason Xing /* Here start with the independent reasons */
8422a32557SJason Xing /** @SK_RST_REASON_TCP_TIMEWAIT_SOCKET: happen on the timewait socket */
8522a32557SJason Xing SK_RST_REASON_TCP_TIMEWAIT_SOCKET,
8611f46ea9SJason Xing /**
8711f46ea9SJason Xing * @SK_RST_REASON_INVALID_SYN: receive bad syn packet
8811f46ea9SJason Xing * RFC 793 says if the state is not CLOSED/LISTEN/SYN-SENT then
8911f46ea9SJason Xing * "fourth, check the SYN bit,...If the SYN is in the window it is
9011f46ea9SJason Xing * an error, send a reset"
9111f46ea9SJason Xing */
9211f46ea9SJason Xing SK_RST_REASON_INVALID_SYN,
9390c36325SJason Xing /**
9490c36325SJason Xing * @SK_RST_REASON_TCP_ABORT_ON_CLOSE: abort on close
9590c36325SJason Xing * corresponding to LINUX_MIB_TCPABORTONCLOSE
9690c36325SJason Xing */
9790c36325SJason Xing SK_RST_REASON_TCP_ABORT_ON_CLOSE,
98edc92b48SJason Xing /**
99edc92b48SJason Xing * @SK_RST_REASON_TCP_ABORT_ON_LINGER: abort on linger
100edc92b48SJason Xing * corresponding to LINUX_MIB_TCPABORTONLINGER
101edc92b48SJason Xing */
102edc92b48SJason Xing SK_RST_REASON_TCP_ABORT_ON_LINGER,
1038407994fSJason Xing /**
1048407994fSJason Xing * @SK_RST_REASON_TCP_ABORT_ON_MEMORY: abort on memory
1058407994fSJason Xing * corresponding to LINUX_MIB_TCPABORTONMEMORY
1068407994fSJason Xing */
1078407994fSJason Xing SK_RST_REASON_TCP_ABORT_ON_MEMORY,
108edefba66SJason Xing /**
109edefba66SJason Xing * @SK_RST_REASON_TCP_STATE: abort on tcp state
110edefba66SJason Xing * Please see RFC 9293 for all possible reset conditions
111edefba66SJason Xing */
112edefba66SJason Xing SK_RST_REASON_TCP_STATE,
1130a399892SJason Xing /**
1140a399892SJason Xing * @SK_RST_REASON_TCP_KEEPALIVE_TIMEOUT: time to timeout
1150a399892SJason Xing * When we have already run out of all the chances, which means
1160a399892SJason Xing * keepalive timeout, we have to reset the connection
1170a399892SJason Xing */
1180a399892SJason Xing SK_RST_REASON_TCP_KEEPALIVE_TIMEOUT,
119*c026c656SJason Xing /**
120*c026c656SJason Xing * @SK_RST_REASON_TCP_DISCONNECT_WITH_DATA: disconnect when write
121*c026c656SJason Xing * queue is not empty
122*c026c656SJason Xing * It means user has written data into the write queue when doing
123*c026c656SJason Xing * disconnecting, so we have to send an RST.
124*c026c656SJason Xing */
125*c026c656SJason Xing SK_RST_REASON_TCP_DISCONNECT_WITH_DATA,
12622a32557SJason Xing
1275cb2cb3cSJason Xing /* Copy from include/uapi/linux/mptcp.h.
1285cb2cb3cSJason Xing * These reset fields will not be changed since they adhere to
1295cb2cb3cSJason Xing * RFC 8684. So do not touch them. I'm going to list each definition
1305cb2cb3cSJason Xing * of them respectively.
1315cb2cb3cSJason Xing */
1325cb2cb3cSJason Xing /**
1335cb2cb3cSJason Xing * @SK_RST_REASON_MPTCP_RST_EUNSPEC: Unspecified error.
1345cb2cb3cSJason Xing * This is the default error; it implies that the subflow is no
1355cb2cb3cSJason Xing * longer available. The presence of this option shows that the
1365cb2cb3cSJason Xing * RST was generated by an MPTCP-aware device.
1375cb2cb3cSJason Xing */
1385cb2cb3cSJason Xing SK_RST_REASON_MPTCP_RST_EUNSPEC,
1395cb2cb3cSJason Xing /**
1405cb2cb3cSJason Xing * @SK_RST_REASON_MPTCP_RST_EMPTCP: MPTCP-specific error.
1415cb2cb3cSJason Xing * An error has been detected in the processing of MPTCP options.
1425cb2cb3cSJason Xing * This is the usual reason code to return in the cases where a RST
1435cb2cb3cSJason Xing * is being sent to close a subflow because of an invalid response.
1445cb2cb3cSJason Xing */
1455cb2cb3cSJason Xing SK_RST_REASON_MPTCP_RST_EMPTCP,
1465cb2cb3cSJason Xing /**
1475cb2cb3cSJason Xing * @SK_RST_REASON_MPTCP_RST_ERESOURCE: Lack of resources.
1485cb2cb3cSJason Xing * This code indicates that the sending host does not have enough
1495cb2cb3cSJason Xing * resources to support the terminated subflow.
1505cb2cb3cSJason Xing */
1515cb2cb3cSJason Xing SK_RST_REASON_MPTCP_RST_ERESOURCE,
1525cb2cb3cSJason Xing /**
1535cb2cb3cSJason Xing * @SK_RST_REASON_MPTCP_RST_EPROHIBIT: Administratively prohibited.
1545cb2cb3cSJason Xing * This code indicates that the requested subflow is prohibited by
1555cb2cb3cSJason Xing * the policies of the sending host.
1565cb2cb3cSJason Xing */
1575cb2cb3cSJason Xing SK_RST_REASON_MPTCP_RST_EPROHIBIT,
1585cb2cb3cSJason Xing /**
1595cb2cb3cSJason Xing * @SK_RST_REASON_MPTCP_RST_EWQ2BIG: Too much outstanding data.
1605cb2cb3cSJason Xing * This code indicates that there is an excessive amount of data
1615cb2cb3cSJason Xing * that needs to be transmitted over the terminated subflow while
1625cb2cb3cSJason Xing * having already been acknowledged over one or more other subflows.
1635cb2cb3cSJason Xing * This may occur if a path has been unavailable for a short period
1645cb2cb3cSJason Xing * and it is more efficient to reset and start again than it is to
1655cb2cb3cSJason Xing * retransmit the queued data.
1665cb2cb3cSJason Xing */
1675cb2cb3cSJason Xing SK_RST_REASON_MPTCP_RST_EWQ2BIG,
1685cb2cb3cSJason Xing /**
1695cb2cb3cSJason Xing * @SK_RST_REASON_MPTCP_RST_EBADPERF: Unacceptable performance.
1705cb2cb3cSJason Xing * This code indicates that the performance of this subflow was
1715cb2cb3cSJason Xing * too low compared to the other subflows of this Multipath TCP
1725cb2cb3cSJason Xing * connection.
1735cb2cb3cSJason Xing */
1745cb2cb3cSJason Xing SK_RST_REASON_MPTCP_RST_EBADPERF,
1755cb2cb3cSJason Xing /**
1765cb2cb3cSJason Xing * @SK_RST_REASON_MPTCP_RST_EMIDDLEBOX: Middlebox interference.
1775cb2cb3cSJason Xing * Middlebox interference has been detected over this subflow,
1785cb2cb3cSJason Xing * making MPTCP signaling invalid. For example, this may be sent
1795cb2cb3cSJason Xing * if the checksum does not validate.
1805cb2cb3cSJason Xing */
1815cb2cb3cSJason Xing SK_RST_REASON_MPTCP_RST_EMIDDLEBOX,
1825cb2cb3cSJason Xing
1835cb2cb3cSJason Xing /** @SK_RST_REASON_ERROR: unexpected error happens */
1845cb2cb3cSJason Xing SK_RST_REASON_ERROR,
1855cb2cb3cSJason Xing
1865cb2cb3cSJason Xing /**
1875cb2cb3cSJason Xing * @SK_RST_REASON_MAX: Maximum of socket reset reasons.
1885cb2cb3cSJason Xing * It shouldn't be used as a real 'reason'.
1895cb2cb3cSJason Xing */
1905cb2cb3cSJason Xing SK_RST_REASON_MAX,
1915cb2cb3cSJason Xing };
192120391efSJason Xing
193120391efSJason Xing /* Convert skb drop reasons to enum sk_rst_reason type */
194120391efSJason Xing static inline enum sk_rst_reason
sk_rst_convert_drop_reason(enum skb_drop_reason reason)195120391efSJason Xing sk_rst_convert_drop_reason(enum skb_drop_reason reason)
196120391efSJason Xing {
197120391efSJason Xing switch (reason) {
198120391efSJason Xing case SKB_DROP_REASON_NOT_SPECIFIED:
199120391efSJason Xing return SK_RST_REASON_NOT_SPECIFIED;
200120391efSJason Xing case SKB_DROP_REASON_NO_SOCKET:
201120391efSJason Xing return SK_RST_REASON_NO_SOCKET;
2022b9669d6SJason Xing case SKB_DROP_REASON_TCP_INVALID_ACK_SEQUENCE:
2032b9669d6SJason Xing return SK_RST_REASON_TCP_INVALID_ACK_SEQUENCE;
2042b9669d6SJason Xing case SKB_DROP_REASON_TCP_RFC7323_PAWS:
2052b9669d6SJason Xing return SK_RST_REASON_TCP_RFC7323_PAWS;
206459a2b37SJason Xing case SKB_DROP_REASON_TCP_TOO_OLD_ACK:
207459a2b37SJason Xing return SK_RST_REASON_TCP_TOO_OLD_ACK;
208459a2b37SJason Xing case SKB_DROP_REASON_TCP_ACK_UNSENT_DATA:
209459a2b37SJason Xing return SK_RST_REASON_TCP_ACK_UNSENT_DATA;
210f6d5e2ccSJason Xing case SKB_DROP_REASON_TCP_FLAGS:
211f6d5e2ccSJason Xing return SK_RST_REASON_TCP_FLAGS;
212f6d5e2ccSJason Xing case SKB_DROP_REASON_TCP_OLD_ACK:
213f6d5e2ccSJason Xing return SK_RST_REASON_TCP_OLD_ACK;
214f6d5e2ccSJason Xing case SKB_DROP_REASON_TCP_ABORT_ON_DATA:
215f6d5e2ccSJason Xing return SK_RST_REASON_TCP_ABORT_ON_DATA;
216120391efSJason Xing default:
217120391efSJason Xing /* If we don't have our own corresponding reason */
218120391efSJason Xing return SK_RST_REASON_NOT_SPECIFIED;
219120391efSJason Xing }
220120391efSJason Xing }
2215cb2cb3cSJason Xing #endif
222