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