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