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