Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
1/* SPDX-License-Identifier: GPL-2.0-or-later */
2
3#ifndef _LINUX_RSTREASON_H
4#define _LINUX_RSTREASON_H
5#include <net/dropreason-core.h>
6#include <uapi/linux/mptcp.h>
7
8#define DEFINE_RST_REASON(FN, FNe) \
9 FN(NOT_SPECIFIED) \
10 FN(NO_SOCKET) \
11 FN(TCP_INVALID_ACK_SEQUENCE) \
12 FN(TCP_RFC7323_PAWS) \
13 FN(TCP_TOO_OLD_ACK) \
14 FN(TCP_ACK_UNSENT_DATA) \
15 FN(TCP_FLAGS) \
16 FN(TCP_OLD_ACK) \
17 FN(TCP_ABORT_ON_DATA) \
18 FN(TCP_TIMEWAIT_SOCKET) \
19 FN(INVALID_SYN) \
20 FN(MPTCP_RST_EUNSPEC) \
21 FN(MPTCP_RST_EMPTCP) \
22 FN(MPTCP_RST_ERESOURCE) \
23 FN(MPTCP_RST_EPROHIBIT) \
24 FN(MPTCP_RST_EWQ2BIG) \
25 FN(MPTCP_RST_EBADPERF) \
26 FN(MPTCP_RST_EMIDDLEBOX) \
27 FN(ERROR) \
28 FNe(MAX)
29
30/**
31 * enum sk_rst_reason - the reasons of socket reset
32 *
33 * The reasons of sk reset, which are used in DCCP/TCP/MPTCP protocols.
34 *
35 * There are three parts in order:
36 * 1) skb drop reasons: relying on drop reasons for such as passive reset
37 * 2) independent reset reasons: such as active reset reasons
38 * 3) reset reasons in MPTCP: only for MPTCP use
39 */
40enum sk_rst_reason {
41 /* Refer to include/net/dropreason-core.h
42 * Rely on skb drop reasons because it indicates exactly why RST
43 * could happen.
44 */
45 /** @SK_RST_REASON_NOT_SPECIFIED: reset reason is not specified */
46 SK_RST_REASON_NOT_SPECIFIED,
47 /** @SK_RST_REASON_NO_SOCKET: no valid socket that can be used */
48 SK_RST_REASON_NO_SOCKET,
49 /**
50 * @SK_RST_REASON_TCP_INVALID_ACK_SEQUENCE: Not acceptable ACK SEQ
51 * field because ack sequence is not in the window between snd_una
52 * and snd_nxt
53 */
54 SK_RST_REASON_TCP_INVALID_ACK_SEQUENCE,
55 /**
56 * @SK_RST_REASON_TCP_RFC7323_PAWS: PAWS check, corresponding to
57 * LINUX_MIB_PAWSESTABREJECTED, LINUX_MIB_PAWSACTIVEREJECTED
58 */
59 SK_RST_REASON_TCP_RFC7323_PAWS,
60 /** @SK_RST_REASON_TCP_TOO_OLD_ACK: TCP ACK is too old */
61 SK_RST_REASON_TCP_TOO_OLD_ACK,
62 /**
63 * @SK_RST_REASON_TCP_ACK_UNSENT_DATA: TCP ACK for data we haven't
64 * sent yet
65 */
66 SK_RST_REASON_TCP_ACK_UNSENT_DATA,
67 /** @SK_RST_REASON_TCP_FLAGS: TCP flags invalid */
68 SK_RST_REASON_TCP_FLAGS,
69 /** @SK_RST_REASON_TCP_OLD_ACK: TCP ACK is old, but in window */
70 SK_RST_REASON_TCP_OLD_ACK,
71 /**
72 * @SK_RST_REASON_TCP_ABORT_ON_DATA: abort on data
73 * corresponding to LINUX_MIB_TCPABORTONDATA
74 */
75 SK_RST_REASON_TCP_ABORT_ON_DATA,
76
77 /* Here start with the independent reasons */
78 /** @SK_RST_REASON_TCP_TIMEWAIT_SOCKET: happen on the timewait socket */
79 SK_RST_REASON_TCP_TIMEWAIT_SOCKET,
80 /**
81 * @SK_RST_REASON_INVALID_SYN: receive bad syn packet
82 * RFC 793 says if the state is not CLOSED/LISTEN/SYN-SENT then
83 * "fourth, check the SYN bit,...If the SYN is in the window it is
84 * an error, send a reset"
85 */
86 SK_RST_REASON_INVALID_SYN,
87
88 /* Copy from include/uapi/linux/mptcp.h.
89 * These reset fields will not be changed since they adhere to
90 * RFC 8684. So do not touch them. I'm going to list each definition
91 * of them respectively.
92 */
93 /**
94 * @SK_RST_REASON_MPTCP_RST_EUNSPEC: Unspecified error.
95 * This is the default error; it implies that the subflow is no
96 * longer available. The presence of this option shows that the
97 * RST was generated by an MPTCP-aware device.
98 */
99 SK_RST_REASON_MPTCP_RST_EUNSPEC,
100 /**
101 * @SK_RST_REASON_MPTCP_RST_EMPTCP: MPTCP-specific error.
102 * An error has been detected in the processing of MPTCP options.
103 * This is the usual reason code to return in the cases where a RST
104 * is being sent to close a subflow because of an invalid response.
105 */
106 SK_RST_REASON_MPTCP_RST_EMPTCP,
107 /**
108 * @SK_RST_REASON_MPTCP_RST_ERESOURCE: Lack of resources.
109 * This code indicates that the sending host does not have enough
110 * resources to support the terminated subflow.
111 */
112 SK_RST_REASON_MPTCP_RST_ERESOURCE,
113 /**
114 * @SK_RST_REASON_MPTCP_RST_EPROHIBIT: Administratively prohibited.
115 * This code indicates that the requested subflow is prohibited by
116 * the policies of the sending host.
117 */
118 SK_RST_REASON_MPTCP_RST_EPROHIBIT,
119 /**
120 * @SK_RST_REASON_MPTCP_RST_EWQ2BIG: Too much outstanding data.
121 * This code indicates that there is an excessive amount of data
122 * that needs to be transmitted over the terminated subflow while
123 * having already been acknowledged over one or more other subflows.
124 * This may occur if a path has been unavailable for a short period
125 * and it is more efficient to reset and start again than it is to
126 * retransmit the queued data.
127 */
128 SK_RST_REASON_MPTCP_RST_EWQ2BIG,
129 /**
130 * @SK_RST_REASON_MPTCP_RST_EBADPERF: Unacceptable performance.
131 * This code indicates that the performance of this subflow was
132 * too low compared to the other subflows of this Multipath TCP
133 * connection.
134 */
135 SK_RST_REASON_MPTCP_RST_EBADPERF,
136 /**
137 * @SK_RST_REASON_MPTCP_RST_EMIDDLEBOX: Middlebox interference.
138 * Middlebox interference has been detected over this subflow,
139 * making MPTCP signaling invalid. For example, this may be sent
140 * if the checksum does not validate.
141 */
142 SK_RST_REASON_MPTCP_RST_EMIDDLEBOX,
143
144 /** @SK_RST_REASON_ERROR: unexpected error happens */
145 SK_RST_REASON_ERROR,
146
147 /**
148 * @SK_RST_REASON_MAX: Maximum of socket reset reasons.
149 * It shouldn't be used as a real 'reason'.
150 */
151 SK_RST_REASON_MAX,
152};
153
154/* Convert skb drop reasons to enum sk_rst_reason type */
155static inline enum sk_rst_reason
156sk_rst_convert_drop_reason(enum skb_drop_reason reason)
157{
158 switch (reason) {
159 case SKB_DROP_REASON_NOT_SPECIFIED:
160 return SK_RST_REASON_NOT_SPECIFIED;
161 case SKB_DROP_REASON_NO_SOCKET:
162 return SK_RST_REASON_NO_SOCKET;
163 case SKB_DROP_REASON_TCP_INVALID_ACK_SEQUENCE:
164 return SK_RST_REASON_TCP_INVALID_ACK_SEQUENCE;
165 case SKB_DROP_REASON_TCP_RFC7323_PAWS:
166 return SK_RST_REASON_TCP_RFC7323_PAWS;
167 case SKB_DROP_REASON_TCP_TOO_OLD_ACK:
168 return SK_RST_REASON_TCP_TOO_OLD_ACK;
169 case SKB_DROP_REASON_TCP_ACK_UNSENT_DATA:
170 return SK_RST_REASON_TCP_ACK_UNSENT_DATA;
171 case SKB_DROP_REASON_TCP_FLAGS:
172 return SK_RST_REASON_TCP_FLAGS;
173 case SKB_DROP_REASON_TCP_OLD_ACK:
174 return SK_RST_REASON_TCP_OLD_ACK;
175 case SKB_DROP_REASON_TCP_ABORT_ON_DATA:
176 return SK_RST_REASON_TCP_ABORT_ON_DATA;
177 default:
178 /* If we don't have our own corresponding reason */
179 return SK_RST_REASON_NOT_SPECIFIED;
180 }
181}
182#endif