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