xref: /linux/include/net/dropreason-core.h (revision 4e94ddfe2aab72139acb8d5372fac9e6c3f3e383)
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
3 #ifndef _LINUX_DROPREASON_CORE_H
4 #define _LINUX_DROPREASON_CORE_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_AUTH_HDR)		\
24 	FN(TCP_MD5NOTFOUND)		\
25 	FN(TCP_MD5UNEXPECTED)		\
26 	FN(TCP_MD5FAILURE)		\
27 	FN(TCP_AONOTFOUND)		\
28 	FN(TCP_AOUNEXPECTED)		\
29 	FN(TCP_AOKEYNOTFOUND)		\
30 	FN(TCP_AOFAILURE)		\
31 	FN(SOCKET_BACKLOG)		\
32 	FN(TCP_FLAGS)			\
33 	FN(TCP_ZEROWINDOW)		\
34 	FN(TCP_OLD_DATA)		\
35 	FN(TCP_OVERWINDOW)		\
36 	FN(TCP_OFOMERGE)		\
37 	FN(TCP_RFC7323_PAWS)		\
38 	FN(TCP_OLD_SEQUENCE)		\
39 	FN(TCP_INVALID_SEQUENCE)	\
40 	FN(TCP_RESET)			\
41 	FN(TCP_INVALID_SYN)		\
42 	FN(TCP_CLOSE)			\
43 	FN(TCP_FASTOPEN)		\
44 	FN(TCP_OLD_ACK)			\
45 	FN(TCP_TOO_OLD_ACK)		\
46 	FN(TCP_ACK_UNSENT_DATA)		\
47 	FN(TCP_OFO_QUEUE_PRUNE)		\
48 	FN(TCP_OFO_DROP)		\
49 	FN(IP_OUTNOROUTES)		\
50 	FN(BPF_CGROUP_EGRESS)		\
51 	FN(IPV6DISABLED)		\
52 	FN(NEIGH_CREATEFAIL)		\
53 	FN(NEIGH_FAILED)		\
54 	FN(NEIGH_QUEUEFULL)		\
55 	FN(NEIGH_DEAD)			\
56 	FN(TC_EGRESS)			\
57 	FN(QDISC_DROP)			\
58 	FN(CPU_BACKLOG)			\
59 	FN(XDP)				\
60 	FN(TC_INGRESS)			\
61 	FN(UNHANDLED_PROTO)		\
62 	FN(SKB_CSUM)			\
63 	FN(SKB_GSO_SEG)			\
64 	FN(SKB_UCOPY_FAULT)		\
65 	FN(DEV_HDR)			\
66 	FN(DEV_READY)			\
67 	FN(FULL_RING)			\
68 	FN(NOMEM)			\
69 	FN(HDR_TRUNC)			\
70 	FN(TAP_FILTER)			\
71 	FN(TAP_TXFILTER)		\
72 	FN(ICMP_CSUM)			\
73 	FN(INVALID_PROTO)		\
74 	FN(IP_INADDRERRORS)		\
75 	FN(IP_INNOROUTES)		\
76 	FN(PKT_TOO_BIG)			\
77 	FN(DUP_FRAG)			\
78 	FN(FRAG_REASM_TIMEOUT)		\
79 	FN(FRAG_TOO_FAR)		\
80 	FN(TCP_MINTTL)			\
81 	FN(IPV6_BAD_EXTHDR)		\
82 	FN(IPV6_NDISC_FRAG)		\
83 	FN(IPV6_NDISC_HOP_LIMIT)	\
84 	FN(IPV6_NDISC_BAD_CODE)		\
85 	FN(IPV6_NDISC_BAD_OPTIONS)	\
86 	FN(IPV6_NDISC_NS_OTHERHOST)	\
87 	FN(QUEUE_PURGE)			\
88 	FN(TC_ERROR)			\
89 	FNe(MAX)
90 
91 /**
92  * enum skb_drop_reason - the reasons of skb drops
93  *
94  * The reason of skb drop, which is used in kfree_skb_reason().
95  */
96 enum skb_drop_reason {
97 	/**
98 	 * @SKB_NOT_DROPPED_YET: skb is not dropped yet (used for no-drop case)
99 	 */
100 	SKB_NOT_DROPPED_YET = 0,
101 	/** @SKB_CONSUMED: packet has been consumed */
102 	SKB_CONSUMED,
103 	/** @SKB_DROP_REASON_NOT_SPECIFIED: drop reason is not specified */
104 	SKB_DROP_REASON_NOT_SPECIFIED,
105 	/** @SKB_DROP_REASON_NO_SOCKET: socket not found */
106 	SKB_DROP_REASON_NO_SOCKET,
107 	/** @SKB_DROP_REASON_PKT_TOO_SMALL: packet size is too small */
108 	SKB_DROP_REASON_PKT_TOO_SMALL,
109 	/** @SKB_DROP_REASON_TCP_CSUM: TCP checksum error */
110 	SKB_DROP_REASON_TCP_CSUM,
111 	/** @SKB_DROP_REASON_SOCKET_FILTER: dropped by socket filter */
112 	SKB_DROP_REASON_SOCKET_FILTER,
113 	/** @SKB_DROP_REASON_UDP_CSUM: UDP checksum error */
114 	SKB_DROP_REASON_UDP_CSUM,
115 	/** @SKB_DROP_REASON_NETFILTER_DROP: dropped by netfilter */
116 	SKB_DROP_REASON_NETFILTER_DROP,
117 	/**
118 	 * @SKB_DROP_REASON_OTHERHOST: packet don't belong to current host
119 	 * (interface is in promisc mode)
120 	 */
121 	SKB_DROP_REASON_OTHERHOST,
122 	/** @SKB_DROP_REASON_IP_CSUM: IP checksum error */
123 	SKB_DROP_REASON_IP_CSUM,
124 	/**
125 	 * @SKB_DROP_REASON_IP_INHDR: there is something wrong with IP header (see
126 	 * IPSTATS_MIB_INHDRERRORS)
127 	 */
128 	SKB_DROP_REASON_IP_INHDR,
129 	/**
130 	 * @SKB_DROP_REASON_IP_RPFILTER: IP rpfilter validate failed. see the
131 	 * document for rp_filter in ip-sysctl.rst for more information
132 	 */
133 	SKB_DROP_REASON_IP_RPFILTER,
134 	/**
135 	 * @SKB_DROP_REASON_UNICAST_IN_L2_MULTICAST: destination address of L2 is
136 	 * multicast, but L3 is unicast.
137 	 */
138 	SKB_DROP_REASON_UNICAST_IN_L2_MULTICAST,
139 	/** @SKB_DROP_REASON_XFRM_POLICY: xfrm policy check failed */
140 	SKB_DROP_REASON_XFRM_POLICY,
141 	/** @SKB_DROP_REASON_IP_NOPROTO: no support for IP protocol */
142 	SKB_DROP_REASON_IP_NOPROTO,
143 	/** @SKB_DROP_REASON_SOCKET_RCVBUFF: socket receive buff is full */
144 	SKB_DROP_REASON_SOCKET_RCVBUFF,
145 	/**
146 	 * @SKB_DROP_REASON_PROTO_MEM: proto memory limition, such as udp packet
147 	 * drop out of udp_memory_allocated.
148 	 */
149 	SKB_DROP_REASON_PROTO_MEM,
150 	/**
151 	 * @SKB_DROP_REASON_TCP_AUTH_HDR: TCP-MD5 or TCP-AO hashes are met
152 	 * twice or set incorrectly.
153 	 */
154 	SKB_DROP_REASON_TCP_AUTH_HDR,
155 	/**
156 	 * @SKB_DROP_REASON_TCP_MD5NOTFOUND: no MD5 hash and one expected,
157 	 * corresponding to LINUX_MIB_TCPMD5NOTFOUND
158 	 */
159 	SKB_DROP_REASON_TCP_MD5NOTFOUND,
160 	/**
161 	 * @SKB_DROP_REASON_TCP_MD5UNEXPECTED: MD5 hash and we're not expecting
162 	 * one, corresponding to LINUX_MIB_TCPMD5UNEXPECTED
163 	 */
164 	SKB_DROP_REASON_TCP_MD5UNEXPECTED,
165 	/**
166 	 * @SKB_DROP_REASON_TCP_MD5FAILURE: MD5 hash and its wrong, corresponding
167 	 * to LINUX_MIB_TCPMD5FAILURE
168 	 */
169 	SKB_DROP_REASON_TCP_MD5FAILURE,
170 	/**
171 	 * @SKB_DROP_REASON_TCP_AONOTFOUND: no TCP-AO hash and one was expected,
172 	 * corresponding to LINUX_MIB_TCPAOREQUIRED
173 	 */
174 	SKB_DROP_REASON_TCP_AONOTFOUND,
175 	/**
176 	 * @SKB_DROP_REASON_TCP_AOUNEXPECTED: TCP-AO hash is present and it
177 	 * was not expected, corresponding to LINUX_MIB_TCPAOKEYNOTFOUND
178 	 */
179 	SKB_DROP_REASON_TCP_AOUNEXPECTED,
180 	/**
181 	 * @SKB_DROP_REASON_TCP_AOKEYNOTFOUND: TCP-AO key is unknown,
182 	 * corresponding to LINUX_MIB_TCPAOKEYNOTFOUND
183 	 */
184 	SKB_DROP_REASON_TCP_AOKEYNOTFOUND,
185 	/**
186 	 * @SKB_DROP_REASON_TCP_AOFAILURE: TCP-AO hash is wrong,
187 	 * corresponding to LINUX_MIB_TCPAOBAD
188 	 */
189 	SKB_DROP_REASON_TCP_AOFAILURE,
190 	/**
191 	 * @SKB_DROP_REASON_SOCKET_BACKLOG: failed to add skb to socket backlog (
192 	 * see LINUX_MIB_TCPBACKLOGDROP)
193 	 */
194 	SKB_DROP_REASON_SOCKET_BACKLOG,
195 	/** @SKB_DROP_REASON_TCP_FLAGS: TCP flags invalid */
196 	SKB_DROP_REASON_TCP_FLAGS,
197 	/**
198 	 * @SKB_DROP_REASON_TCP_ZEROWINDOW: TCP receive window size is zero,
199 	 * see LINUX_MIB_TCPZEROWINDOWDROP
200 	 */
201 	SKB_DROP_REASON_TCP_ZEROWINDOW,
202 	/**
203 	 * @SKB_DROP_REASON_TCP_OLD_DATA: the TCP data reveived is already
204 	 * received before (spurious retrans may happened), see
205 	 * LINUX_MIB_DELAYEDACKLOST
206 	 */
207 	SKB_DROP_REASON_TCP_OLD_DATA,
208 	/**
209 	 * @SKB_DROP_REASON_TCP_OVERWINDOW: the TCP data is out of window,
210 	 * the seq of the first byte exceed the right edges of receive
211 	 * window
212 	 */
213 	SKB_DROP_REASON_TCP_OVERWINDOW,
214 	/**
215 	 * @SKB_DROP_REASON_TCP_OFOMERGE: the data of skb is already in the ofo
216 	 * queue, corresponding to LINUX_MIB_TCPOFOMERGE
217 	 */
218 	SKB_DROP_REASON_TCP_OFOMERGE,
219 	/**
220 	 * @SKB_DROP_REASON_TCP_RFC7323_PAWS: PAWS check, corresponding to
221 	 * LINUX_MIB_PAWSESTABREJECTED
222 	 */
223 	SKB_DROP_REASON_TCP_RFC7323_PAWS,
224 	/** @SKB_DROP_REASON_TCP_OLD_SEQUENCE: Old SEQ field (duplicate packet) */
225 	SKB_DROP_REASON_TCP_OLD_SEQUENCE,
226 	/** @SKB_DROP_REASON_TCP_INVALID_SEQUENCE: Not acceptable SEQ field */
227 	SKB_DROP_REASON_TCP_INVALID_SEQUENCE,
228 	/** @SKB_DROP_REASON_TCP_RESET: Invalid RST packet */
229 	SKB_DROP_REASON_TCP_RESET,
230 	/**
231 	 * @SKB_DROP_REASON_TCP_INVALID_SYN: Incoming packet has unexpected
232 	 * SYN flag
233 	 */
234 	SKB_DROP_REASON_TCP_INVALID_SYN,
235 	/** @SKB_DROP_REASON_TCP_CLOSE: TCP socket in CLOSE state */
236 	SKB_DROP_REASON_TCP_CLOSE,
237 	/** @SKB_DROP_REASON_TCP_FASTOPEN: dropped by FASTOPEN request socket */
238 	SKB_DROP_REASON_TCP_FASTOPEN,
239 	/** @SKB_DROP_REASON_TCP_OLD_ACK: TCP ACK is old, but in window */
240 	SKB_DROP_REASON_TCP_OLD_ACK,
241 	/** @SKB_DROP_REASON_TCP_TOO_OLD_ACK: TCP ACK is too old */
242 	SKB_DROP_REASON_TCP_TOO_OLD_ACK,
243 	/**
244 	 * @SKB_DROP_REASON_TCP_ACK_UNSENT_DATA: TCP ACK for data we haven't
245 	 * sent yet
246 	 */
247 	SKB_DROP_REASON_TCP_ACK_UNSENT_DATA,
248 	/** @SKB_DROP_REASON_TCP_OFO_QUEUE_PRUNE: pruned from TCP OFO queue */
249 	SKB_DROP_REASON_TCP_OFO_QUEUE_PRUNE,
250 	/** @SKB_DROP_REASON_TCP_OFO_DROP: data already in receive queue */
251 	SKB_DROP_REASON_TCP_OFO_DROP,
252 	/** @SKB_DROP_REASON_IP_OUTNOROUTES: route lookup failed */
253 	SKB_DROP_REASON_IP_OUTNOROUTES,
254 	/**
255 	 * @SKB_DROP_REASON_BPF_CGROUP_EGRESS: dropped by BPF_PROG_TYPE_CGROUP_SKB
256 	 * eBPF program
257 	 */
258 	SKB_DROP_REASON_BPF_CGROUP_EGRESS,
259 	/** @SKB_DROP_REASON_IPV6DISABLED: IPv6 is disabled on the device */
260 	SKB_DROP_REASON_IPV6DISABLED,
261 	/** @SKB_DROP_REASON_NEIGH_CREATEFAIL: failed to create neigh entry */
262 	SKB_DROP_REASON_NEIGH_CREATEFAIL,
263 	/** @SKB_DROP_REASON_NEIGH_FAILED: neigh entry in failed state */
264 	SKB_DROP_REASON_NEIGH_FAILED,
265 	/** @SKB_DROP_REASON_NEIGH_QUEUEFULL: arp_queue for neigh entry is full */
266 	SKB_DROP_REASON_NEIGH_QUEUEFULL,
267 	/** @SKB_DROP_REASON_NEIGH_DEAD: neigh entry is dead */
268 	SKB_DROP_REASON_NEIGH_DEAD,
269 	/** @SKB_DROP_REASON_TC_EGRESS: dropped in TC egress HOOK */
270 	SKB_DROP_REASON_TC_EGRESS,
271 	/**
272 	 * @SKB_DROP_REASON_QDISC_DROP: dropped by qdisc when packet outputting (
273 	 * failed to enqueue to current qdisc)
274 	 */
275 	SKB_DROP_REASON_QDISC_DROP,
276 	/**
277 	 * @SKB_DROP_REASON_CPU_BACKLOG: failed to enqueue the skb to the per CPU
278 	 * backlog queue. This can be caused by backlog queue full (see
279 	 * netdev_max_backlog in net.rst) or RPS flow limit
280 	 */
281 	SKB_DROP_REASON_CPU_BACKLOG,
282 	/** @SKB_DROP_REASON_XDP: dropped by XDP in input path */
283 	SKB_DROP_REASON_XDP,
284 	/** @SKB_DROP_REASON_TC_INGRESS: dropped in TC ingress HOOK */
285 	SKB_DROP_REASON_TC_INGRESS,
286 	/** @SKB_DROP_REASON_UNHANDLED_PROTO: protocol not implemented or not supported */
287 	SKB_DROP_REASON_UNHANDLED_PROTO,
288 	/** @SKB_DROP_REASON_SKB_CSUM: sk_buff checksum computation error */
289 	SKB_DROP_REASON_SKB_CSUM,
290 	/** @SKB_DROP_REASON_SKB_GSO_SEG: gso segmentation error */
291 	SKB_DROP_REASON_SKB_GSO_SEG,
292 	/**
293 	 * @SKB_DROP_REASON_SKB_UCOPY_FAULT: failed to copy data from user space,
294 	 * e.g., via zerocopy_sg_from_iter() or skb_orphan_frags_rx()
295 	 */
296 	SKB_DROP_REASON_SKB_UCOPY_FAULT,
297 	/** @SKB_DROP_REASON_DEV_HDR: device driver specific header/metadata is invalid */
298 	SKB_DROP_REASON_DEV_HDR,
299 	/**
300 	 * @SKB_DROP_REASON_DEV_READY: the device is not ready to xmit/recv due to
301 	 * any of its data structure that is not up/ready/initialized,
302 	 * e.g., the IFF_UP is not set, or driver specific tun->tfiles[txq]
303 	 * is not initialized
304 	 */
305 	SKB_DROP_REASON_DEV_READY,
306 	/** @SKB_DROP_REASON_FULL_RING: ring buffer is full */
307 	SKB_DROP_REASON_FULL_RING,
308 	/** @SKB_DROP_REASON_NOMEM: error due to OOM */
309 	SKB_DROP_REASON_NOMEM,
310 	/**
311 	 * @SKB_DROP_REASON_HDR_TRUNC: failed to trunc/extract the header from
312 	 * networking data, e.g., failed to pull the protocol header from
313 	 * frags via pskb_may_pull()
314 	 */
315 	SKB_DROP_REASON_HDR_TRUNC,
316 	/**
317 	 * @SKB_DROP_REASON_TAP_FILTER: dropped by (ebpf) filter directly attached
318 	 * to tun/tap, e.g., via TUNSETFILTEREBPF
319 	 */
320 	SKB_DROP_REASON_TAP_FILTER,
321 	/**
322 	 * @SKB_DROP_REASON_TAP_TXFILTER: dropped by tx filter implemented at
323 	 * tun/tap, e.g., check_filter()
324 	 */
325 	SKB_DROP_REASON_TAP_TXFILTER,
326 	/** @SKB_DROP_REASON_ICMP_CSUM: ICMP checksum error */
327 	SKB_DROP_REASON_ICMP_CSUM,
328 	/**
329 	 * @SKB_DROP_REASON_INVALID_PROTO: the packet doesn't follow RFC 2211,
330 	 * such as a broadcasts ICMP_TIMESTAMP
331 	 */
332 	SKB_DROP_REASON_INVALID_PROTO,
333 	/**
334 	 * @SKB_DROP_REASON_IP_INADDRERRORS: host unreachable, corresponding to
335 	 * IPSTATS_MIB_INADDRERRORS
336 	 */
337 	SKB_DROP_REASON_IP_INADDRERRORS,
338 	/**
339 	 * @SKB_DROP_REASON_IP_INNOROUTES: network unreachable, corresponding to
340 	 * IPSTATS_MIB_INADDRERRORS
341 	 */
342 	SKB_DROP_REASON_IP_INNOROUTES,
343 	/**
344 	 * @SKB_DROP_REASON_PKT_TOO_BIG: packet size is too big (maybe exceed the
345 	 * MTU)
346 	 */
347 	SKB_DROP_REASON_PKT_TOO_BIG,
348 	/** @SKB_DROP_REASON_DUP_FRAG: duplicate fragment */
349 	SKB_DROP_REASON_DUP_FRAG,
350 	/** @SKB_DROP_REASON_FRAG_REASM_TIMEOUT: fragment reassembly timeout */
351 	SKB_DROP_REASON_FRAG_REASM_TIMEOUT,
352 	/**
353 	 * @SKB_DROP_REASON_FRAG_TOO_FAR: ipv4 fragment too far.
354 	 * (/proc/sys/net/ipv4/ipfrag_max_dist)
355 	 */
356 	SKB_DROP_REASON_FRAG_TOO_FAR,
357 	/**
358 	 * @SKB_DROP_REASON_TCP_MINTTL: ipv4 ttl or ipv6 hoplimit below
359 	 * the threshold (IP_MINTTL or IPV6_MINHOPCOUNT).
360 	 */
361 	SKB_DROP_REASON_TCP_MINTTL,
362 	/** @SKB_DROP_REASON_IPV6_BAD_EXTHDR: Bad IPv6 extension header. */
363 	SKB_DROP_REASON_IPV6_BAD_EXTHDR,
364 	/** @SKB_DROP_REASON_IPV6_NDISC_FRAG: invalid frag (suppress_frag_ndisc). */
365 	SKB_DROP_REASON_IPV6_NDISC_FRAG,
366 	/** @SKB_DROP_REASON_IPV6_NDISC_HOP_LIMIT: invalid hop limit. */
367 	SKB_DROP_REASON_IPV6_NDISC_HOP_LIMIT,
368 	/** @SKB_DROP_REASON_IPV6_NDISC_BAD_CODE: invalid NDISC icmp6 code. */
369 	SKB_DROP_REASON_IPV6_NDISC_BAD_CODE,
370 	/** @SKB_DROP_REASON_IPV6_NDISC_BAD_OPTIONS: invalid NDISC options. */
371 	SKB_DROP_REASON_IPV6_NDISC_BAD_OPTIONS,
372 	/**
373 	 * @SKB_DROP_REASON_IPV6_NDISC_NS_OTHERHOST: NEIGHBOUR SOLICITATION
374 	 * for another host.
375 	 */
376 	SKB_DROP_REASON_IPV6_NDISC_NS_OTHERHOST,
377 	/** @SKB_DROP_REASON_QUEUE_PURGE: bulk free. */
378 	SKB_DROP_REASON_QUEUE_PURGE,
379 	/** @SKB_DROP_REASON_TC_ERROR: generic internal tc error. */
380 	SKB_DROP_REASON_TC_ERROR,
381 	/**
382 	 * @SKB_DROP_REASON_MAX: the maximum of core drop reasons, which
383 	 * shouldn't be used as a real 'reason' - only for tracing code gen
384 	 */
385 	SKB_DROP_REASON_MAX,
386 
387 	/**
388 	 * @SKB_DROP_REASON_SUBSYS_MASK: subsystem mask in drop reasons,
389 	 * see &enum skb_drop_reason_subsys
390 	 */
391 	SKB_DROP_REASON_SUBSYS_MASK = 0xffff0000,
392 };
393 
394 #define SKB_DROP_REASON_SUBSYS_SHIFT	16
395 
396 #define SKB_DR_INIT(name, reason)				\
397 	enum skb_drop_reason name = SKB_DROP_REASON_##reason
398 #define SKB_DR(name)						\
399 	SKB_DR_INIT(name, NOT_SPECIFIED)
400 #define SKB_DR_SET(name, reason)				\
401 	(name = SKB_DROP_REASON_##reason)
402 #define SKB_DR_OR(name, reason)					\
403 	do {							\
404 		if (name == SKB_DROP_REASON_NOT_SPECIFIED ||	\
405 		    name == SKB_NOT_DROPPED_YET)		\
406 			SKB_DR_SET(name, reason);		\
407 	} while (0)
408 
409 #endif
410