xref: /openbmc/linux/include/net/dropreason.h (revision a266ef69)
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
3 #ifndef _LINUX_DROPREASON_H
4 #define _LINUX_DROPREASON_H
5 
6 #define DEFINE_DROP_REASON(FN, FNe)	\
7 	FN(NOT_SPECIFIED)		\
8 	FN(NO_SOCKET)			\
9 	FN(PKT_TOO_SMALL)		\
10 	FN(TCP_CSUM)			\
11 	FN(SOCKET_FILTER)		\
12 	FN(UDP_CSUM)			\
13 	FN(NETFILTER_DROP)		\
14 	FN(OTHERHOST)			\
15 	FN(IP_CSUM)			\
16 	FN(IP_INHDR)			\
17 	FN(IP_RPFILTER)			\
18 	FN(UNICAST_IN_L2_MULTICAST)	\
19 	FN(XFRM_POLICY)			\
20 	FN(IP_NOPROTO)			\
21 	FN(SOCKET_RCVBUFF)		\
22 	FN(PROTO_MEM)			\
23 	FN(TCP_MD5NOTFOUND)		\
24 	FN(TCP_MD5UNEXPECTED)		\
25 	FN(TCP_MD5FAILURE)		\
26 	FN(SOCKET_BACKLOG)		\
27 	FN(TCP_FLAGS)			\
28 	FN(TCP_ZEROWINDOW)		\
29 	FN(TCP_OLD_DATA)		\
30 	FN(TCP_OVERWINDOW)		\
31 	FN(TCP_OFOMERGE)		\
32 	FN(TCP_RFC7323_PAWS)		\
33 	FN(TCP_INVALID_SEQUENCE)	\
34 	FN(TCP_RESET)			\
35 	FN(TCP_INVALID_SYN)		\
36 	FN(TCP_CLOSE)			\
37 	FN(TCP_FASTOPEN)		\
38 	FN(TCP_OLD_ACK)			\
39 	FN(TCP_TOO_OLD_ACK)		\
40 	FN(TCP_ACK_UNSENT_DATA)		\
41 	FN(TCP_OFO_QUEUE_PRUNE)		\
42 	FN(TCP_OFO_DROP)		\
43 	FN(IP_OUTNOROUTES)		\
44 	FN(BPF_CGROUP_EGRESS)		\
45 	FN(IPV6DISABLED)		\
46 	FN(NEIGH_CREATEFAIL)		\
47 	FN(NEIGH_FAILED)		\
48 	FN(NEIGH_QUEUEFULL)		\
49 	FN(NEIGH_DEAD)			\
50 	FN(TC_EGRESS)			\
51 	FN(QDISC_DROP)			\
52 	FN(CPU_BACKLOG)			\
53 	FN(XDP)				\
54 	FN(TC_INGRESS)			\
55 	FN(UNHANDLED_PROTO)		\
56 	FN(SKB_CSUM)			\
57 	FN(SKB_GSO_SEG)			\
58 	FN(SKB_UCOPY_FAULT)		\
59 	FN(DEV_HDR)			\
60 	FN(DEV_READY)			\
61 	FN(FULL_RING)			\
62 	FN(NOMEM)			\
63 	FN(HDR_TRUNC)			\
64 	FN(TAP_FILTER)			\
65 	FN(TAP_TXFILTER)		\
66 	FN(ICMP_CSUM)			\
67 	FN(INVALID_PROTO)		\
68 	FN(IP_INADDRERRORS)		\
69 	FN(IP_INNOROUTES)		\
70 	FN(PKT_TOO_BIG)			\
71 	FN(DUP_FRAG)			\
72 	FN(FRAG_REASM_TIMEOUT)		\
73 	FN(FRAG_TOO_FAR)		\
74 	FNe(MAX)
75 
76 /**
77  * enum skb_drop_reason - the reasons of skb drops
78  *
79  * The reason of skb drop, which is used in kfree_skb_reason().
80  */
81 enum skb_drop_reason {
82 	/**
83 	 * @SKB_NOT_DROPPED_YET: skb is not dropped yet (used for no-drop case)
84 	 */
85 	SKB_NOT_DROPPED_YET = 0,
86 	/** @SKB_CONSUMED: packet has been consumed */
87 	SKB_CONSUMED,
88 	/** @SKB_DROP_REASON_NOT_SPECIFIED: drop reason is not specified */
89 	SKB_DROP_REASON_NOT_SPECIFIED,
90 	/** @SKB_DROP_REASON_NO_SOCKET: socket not found */
91 	SKB_DROP_REASON_NO_SOCKET,
92 	/** @SKB_DROP_REASON_PKT_TOO_SMALL: packet size is too small */
93 	SKB_DROP_REASON_PKT_TOO_SMALL,
94 	/** @SKB_DROP_REASON_TCP_CSUM: TCP checksum error */
95 	SKB_DROP_REASON_TCP_CSUM,
96 	/** @SKB_DROP_REASON_SOCKET_FILTER: dropped by socket filter */
97 	SKB_DROP_REASON_SOCKET_FILTER,
98 	/** @SKB_DROP_REASON_UDP_CSUM: UDP checksum error */
99 	SKB_DROP_REASON_UDP_CSUM,
100 	/** @SKB_DROP_REASON_NETFILTER_DROP: dropped by netfilter */
101 	SKB_DROP_REASON_NETFILTER_DROP,
102 	/**
103 	 * @SKB_DROP_REASON_OTHERHOST: packet don't belong to current host
104 	 * (interface is in promisc mode)
105 	 */
106 	SKB_DROP_REASON_OTHERHOST,
107 	/** @SKB_DROP_REASON_IP_CSUM: IP checksum error */
108 	SKB_DROP_REASON_IP_CSUM,
109 	/**
110 	 * @SKB_DROP_REASON_IP_INHDR: there is something wrong with IP header (see
111 	 * IPSTATS_MIB_INHDRERRORS)
112 	 */
113 	SKB_DROP_REASON_IP_INHDR,
114 	/**
115 	 * @SKB_DROP_REASON_IP_RPFILTER: IP rpfilter validate failed. see the
116 	 * document for rp_filter in ip-sysctl.rst for more information
117 	 */
118 	SKB_DROP_REASON_IP_RPFILTER,
119 	/**
120 	 * @SKB_DROP_REASON_UNICAST_IN_L2_MULTICAST: destination address of L2 is
121 	 * multicast, but L3 is unicast.
122 	 */
123 	SKB_DROP_REASON_UNICAST_IN_L2_MULTICAST,
124 	/** @SKB_DROP_REASON_XFRM_POLICY: xfrm policy check failed */
125 	SKB_DROP_REASON_XFRM_POLICY,
126 	/** @SKB_DROP_REASON_IP_NOPROTO: no support for IP protocol */
127 	SKB_DROP_REASON_IP_NOPROTO,
128 	/** @SKB_DROP_REASON_SOCKET_RCVBUFF: socket receive buff is full */
129 	SKB_DROP_REASON_SOCKET_RCVBUFF,
130 	/**
131 	 * @SKB_DROP_REASON_PROTO_MEM: proto memory limition, such as udp packet
132 	 * drop out of udp_memory_allocated.
133 	 */
134 	SKB_DROP_REASON_PROTO_MEM,
135 	/**
136 	 * @SKB_DROP_REASON_TCP_MD5NOTFOUND: no MD5 hash and one expected,
137 	 * corresponding to LINUX_MIB_TCPMD5NOTFOUND
138 	 */
139 	SKB_DROP_REASON_TCP_MD5NOTFOUND,
140 	/**
141 	 * @SKB_DROP_REASON_TCP_MD5UNEXPECTED: MD5 hash and we're not expecting
142 	 * one, corresponding to LINUX_MIB_TCPMD5UNEXPECTED
143 	 */
144 	SKB_DROP_REASON_TCP_MD5UNEXPECTED,
145 	/**
146 	 * @SKB_DROP_REASON_TCP_MD5FAILURE: MD5 hash and its wrong, corresponding
147 	 * to LINUX_MIB_TCPMD5FAILURE
148 	 */
149 	SKB_DROP_REASON_TCP_MD5FAILURE,
150 	/**
151 	 * @SKB_DROP_REASON_SOCKET_BACKLOG: failed to add skb to socket backlog (
152 	 * see LINUX_MIB_TCPBACKLOGDROP)
153 	 */
154 	SKB_DROP_REASON_SOCKET_BACKLOG,
155 	/** @SKB_DROP_REASON_TCP_FLAGS: TCP flags invalid */
156 	SKB_DROP_REASON_TCP_FLAGS,
157 	/**
158 	 * @SKB_DROP_REASON_TCP_ZEROWINDOW: TCP receive window size is zero,
159 	 * see LINUX_MIB_TCPZEROWINDOWDROP
160 	 */
161 	SKB_DROP_REASON_TCP_ZEROWINDOW,
162 	/**
163 	 * @SKB_DROP_REASON_TCP_OLD_DATA: the TCP data reveived is already
164 	 * received before (spurious retrans may happened), see
165 	 * LINUX_MIB_DELAYEDACKLOST
166 	 */
167 	SKB_DROP_REASON_TCP_OLD_DATA,
168 	/**
169 	 * @SKB_DROP_REASON_TCP_OVERWINDOW: the TCP data is out of window,
170 	 * the seq of the first byte exceed the right edges of receive
171 	 * window
172 	 */
173 	SKB_DROP_REASON_TCP_OVERWINDOW,
174 	/**
175 	 * @SKB_DROP_REASON_TCP_OFOMERGE: the data of skb is already in the ofo
176 	 * queue, corresponding to LINUX_MIB_TCPOFOMERGE
177 	 */
178 	SKB_DROP_REASON_TCP_OFOMERGE,
179 	/**
180 	 * @SKB_DROP_REASON_TCP_RFC7323_PAWS: PAWS check, corresponding to
181 	 * LINUX_MIB_PAWSESTABREJECTED
182 	 */
183 	SKB_DROP_REASON_TCP_RFC7323_PAWS,
184 	/** @SKB_DROP_REASON_TCP_INVALID_SEQUENCE: Not acceptable SEQ field */
185 	SKB_DROP_REASON_TCP_INVALID_SEQUENCE,
186 	/** @SKB_DROP_REASON_TCP_RESET: Invalid RST packet */
187 	SKB_DROP_REASON_TCP_RESET,
188 	/**
189 	 * @SKB_DROP_REASON_TCP_INVALID_SYN: Incoming packet has unexpected
190 	 * SYN flag
191 	 */
192 	SKB_DROP_REASON_TCP_INVALID_SYN,
193 	/** @SKB_DROP_REASON_TCP_CLOSE: TCP socket in CLOSE state */
194 	SKB_DROP_REASON_TCP_CLOSE,
195 	/** @SKB_DROP_REASON_TCP_FASTOPEN: dropped by FASTOPEN request socket */
196 	SKB_DROP_REASON_TCP_FASTOPEN,
197 	/** @SKB_DROP_REASON_TCP_OLD_ACK: TCP ACK is old, but in window */
198 	SKB_DROP_REASON_TCP_OLD_ACK,
199 	/** @SKB_DROP_REASON_TCP_TOO_OLD_ACK: TCP ACK is too old */
200 	SKB_DROP_REASON_TCP_TOO_OLD_ACK,
201 	/**
202 	 * @SKB_DROP_REASON_TCP_ACK_UNSENT_DATA: TCP ACK for data we haven't
203 	 * sent yet
204 	 */
205 	SKB_DROP_REASON_TCP_ACK_UNSENT_DATA,
206 	/** @SKB_DROP_REASON_TCP_OFO_QUEUE_PRUNE: pruned from TCP OFO queue */
207 	SKB_DROP_REASON_TCP_OFO_QUEUE_PRUNE,
208 	/** @SKB_DROP_REASON_TCP_OFO_DROP: data already in receive queue */
209 	SKB_DROP_REASON_TCP_OFO_DROP,
210 	/** @SKB_DROP_REASON_IP_OUTNOROUTES: route lookup failed */
211 	SKB_DROP_REASON_IP_OUTNOROUTES,
212 	/**
213 	 * @SKB_DROP_REASON_BPF_CGROUP_EGRESS: dropped by BPF_PROG_TYPE_CGROUP_SKB
214 	 * eBPF program
215 	 */
216 	SKB_DROP_REASON_BPF_CGROUP_EGRESS,
217 	/** @SKB_DROP_REASON_IPV6DISABLED: IPv6 is disabled on the device */
218 	SKB_DROP_REASON_IPV6DISABLED,
219 	/** @SKB_DROP_REASON_NEIGH_CREATEFAIL: failed to create neigh entry */
220 	SKB_DROP_REASON_NEIGH_CREATEFAIL,
221 	/** @SKB_DROP_REASON_NEIGH_FAILED: neigh entry in failed state */
222 	SKB_DROP_REASON_NEIGH_FAILED,
223 	/** @SKB_DROP_REASON_NEIGH_QUEUEFULL: arp_queue for neigh entry is full */
224 	SKB_DROP_REASON_NEIGH_QUEUEFULL,
225 	/** @SKB_DROP_REASON_NEIGH_DEAD: neigh entry is dead */
226 	SKB_DROP_REASON_NEIGH_DEAD,
227 	/** @SKB_DROP_REASON_TC_EGRESS: dropped in TC egress HOOK */
228 	SKB_DROP_REASON_TC_EGRESS,
229 	/**
230 	 * @SKB_DROP_REASON_QDISC_DROP: dropped by qdisc when packet outputting (
231 	 * failed to enqueue to current qdisc)
232 	 */
233 	SKB_DROP_REASON_QDISC_DROP,
234 	/**
235 	 * @SKB_DROP_REASON_CPU_BACKLOG: failed to enqueue the skb to the per CPU
236 	 * backlog queue. This can be caused by backlog queue full (see
237 	 * netdev_max_backlog in net.rst) or RPS flow limit
238 	 */
239 	SKB_DROP_REASON_CPU_BACKLOG,
240 	/** @SKB_DROP_REASON_XDP: dropped by XDP in input path */
241 	SKB_DROP_REASON_XDP,
242 	/** @SKB_DROP_REASON_TC_INGRESS: dropped in TC ingress HOOK */
243 	SKB_DROP_REASON_TC_INGRESS,
244 	/** @SKB_DROP_REASON_UNHANDLED_PROTO: protocol not implemented or not supported */
245 	SKB_DROP_REASON_UNHANDLED_PROTO,
246 	/** @SKB_DROP_REASON_SKB_CSUM: sk_buff checksum computation error */
247 	SKB_DROP_REASON_SKB_CSUM,
248 	/** @SKB_DROP_REASON_SKB_GSO_SEG: gso segmentation error */
249 	SKB_DROP_REASON_SKB_GSO_SEG,
250 	/**
251 	 * @SKB_DROP_REASON_SKB_UCOPY_FAULT: failed to copy data from user space,
252 	 * e.g., via zerocopy_sg_from_iter() or skb_orphan_frags_rx()
253 	 */
254 	SKB_DROP_REASON_SKB_UCOPY_FAULT,
255 	/** @SKB_DROP_REASON_DEV_HDR: device driver specific header/metadata is invalid */
256 	SKB_DROP_REASON_DEV_HDR,
257 	/**
258 	 * @SKB_DROP_REASON_DEV_READY: the device is not ready to xmit/recv due to
259 	 * any of its data structure that is not up/ready/initialized,
260 	 * e.g., the IFF_UP is not set, or driver specific tun->tfiles[txq]
261 	 * is not initialized
262 	 */
263 	SKB_DROP_REASON_DEV_READY,
264 	/** @SKB_DROP_REASON_FULL_RING: ring buffer is full */
265 	SKB_DROP_REASON_FULL_RING,
266 	/** @SKB_DROP_REASON_NOMEM: error due to OOM */
267 	SKB_DROP_REASON_NOMEM,
268 	/**
269 	 * @SKB_DROP_REASON_HDR_TRUNC: failed to trunc/extract the header from
270 	 * networking data, e.g., failed to pull the protocol header from
271 	 * frags via pskb_may_pull()
272 	 */
273 	SKB_DROP_REASON_HDR_TRUNC,
274 	/**
275 	 * @SKB_DROP_REASON_TAP_FILTER: dropped by (ebpf) filter directly attached
276 	 * to tun/tap, e.g., via TUNSETFILTEREBPF
277 	 */
278 	SKB_DROP_REASON_TAP_FILTER,
279 	/**
280 	 * @SKB_DROP_REASON_TAP_TXFILTER: dropped by tx filter implemented at
281 	 * tun/tap, e.g., check_filter()
282 	 */
283 	SKB_DROP_REASON_TAP_TXFILTER,
284 	/** @SKB_DROP_REASON_ICMP_CSUM: ICMP checksum error */
285 	SKB_DROP_REASON_ICMP_CSUM,
286 	/**
287 	 * @SKB_DROP_REASON_INVALID_PROTO: the packet doesn't follow RFC 2211,
288 	 * such as a broadcasts ICMP_TIMESTAMP
289 	 */
290 	SKB_DROP_REASON_INVALID_PROTO,
291 	/**
292 	 * @SKB_DROP_REASON_IP_INADDRERRORS: host unreachable, corresponding to
293 	 * IPSTATS_MIB_INADDRERRORS
294 	 */
295 	SKB_DROP_REASON_IP_INADDRERRORS,
296 	/**
297 	 * @SKB_DROP_REASON_IP_INNOROUTES: network unreachable, corresponding to
298 	 * IPSTATS_MIB_INADDRERRORS
299 	 */
300 	SKB_DROP_REASON_IP_INNOROUTES,
301 	/**
302 	 * @SKB_DROP_REASON_PKT_TOO_BIG: packet size is too big (maybe exceed the
303 	 * MTU)
304 	 */
305 	SKB_DROP_REASON_PKT_TOO_BIG,
306 	/** @SKB_DROP_REASON_DUP_FRAG: duplicate fragment */
307 	SKB_DROP_REASON_DUP_FRAG,
308 	/** @SKB_DROP_REASON_FRAG_REASM_TIMEOUT: fragment reassembly timeout */
309 	SKB_DROP_REASON_FRAG_REASM_TIMEOUT,
310 	/**
311 	 * @SKB_DROP_REASON_FRAG_TOO_FAR: ipv4 fragment too far.
312 	 * (/proc/sys/net/ipv4/ipfrag_max_dist)
313 	 */
314 	SKB_DROP_REASON_FRAG_TOO_FAR,
315 	/**
316 	 * @SKB_DROP_REASON_MAX: the maximum of drop reason, which shouldn't be
317 	 * used as a real 'reason'
318 	 */
319 	SKB_DROP_REASON_MAX,
320 };
321 
322 #define SKB_DR_INIT(name, reason)				\
323 	enum skb_drop_reason name = SKB_DROP_REASON_##reason
324 #define SKB_DR(name)						\
325 	SKB_DR_INIT(name, NOT_SPECIFIED)
326 #define SKB_DR_SET(name, reason)				\
327 	(name = SKB_DROP_REASON_##reason)
328 #define SKB_DR_OR(name, reason)					\
329 	do {							\
330 		if (name == SKB_DROP_REASON_NOT_SPECIFIED ||	\
331 		    name == SKB_NOT_DROPPED_YET)		\
332 			SKB_DR_SET(name, reason);		\
333 	} while (0)
334 
335 extern const char * const drop_reasons[];
336 
337 #endif
338