Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge branch 'net-extend-drop-reasons'

Johannes Berg says:

====================
net: extend drop reasons

Here's v4 of the extended drop reasons, with fixes to kernel-doc
and checkpatch.
====================

Link: https://lore.kernel.org/r/20230419125254.20789-1-johannes@sipsolutions.net
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

+609 -413
+1 -1
include/linux/netdevice.h
··· 52 52 #include <linux/rbtree.h> 53 53 #include <net/net_trackers.h> 54 54 #include <net/net_debug.h> 55 - #include <net/dropreason.h> 55 + #include <net/dropreason-core.h> 56 56 57 57 struct netpoll_info; 58 58 struct device;
+1 -1
include/linux/skbuff.h
··· 37 37 #include <linux/netfilter/nf_conntrack_common.h> 38 38 #endif 39 39 #include <net/net_debug.h> 40 - #include <net/dropreason.h> 40 + #include <net/dropreason-core.h> 41 41 42 42 /** 43 43 * DOC: skb checksums
+370
include/net/dropreason-core.h
··· 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_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 + /** 338 + * @SKB_DROP_REASON_IPV6_NDISC_NS_OTHERHOST: NEIGHBOUR SOLICITATION 339 + * for another host. 340 + */ 341 + SKB_DROP_REASON_IPV6_NDISC_NS_OTHERHOST, 342 + /** 343 + * @SKB_DROP_REASON_MAX: the maximum of core drop reasons, which 344 + * shouldn't be used as a real 'reason' - only for tracing code gen 345 + */ 346 + SKB_DROP_REASON_MAX, 347 + 348 + /** 349 + * @SKB_DROP_REASON_SUBSYS_MASK: subsystem mask in drop reasons, 350 + * see &enum skb_drop_reason_subsys 351 + */ 352 + SKB_DROP_REASON_SUBSYS_MASK = 0xffff0000, 353 + }; 354 + 355 + #define SKB_DROP_REASON_SUBSYS_SHIFT 16 356 + 357 + #define SKB_DR_INIT(name, reason) \ 358 + enum skb_drop_reason name = SKB_DROP_REASON_##reason 359 + #define SKB_DR(name) \ 360 + SKB_DR_INIT(name, NOT_SPECIFIED) 361 + #define SKB_DR_SET(name, reason) \ 362 + (name = SKB_DROP_REASON_##reason) 363 + #define SKB_DR_OR(name, reason) \ 364 + do { \ 365 + if (name == SKB_DROP_REASON_NOT_SPECIFIED || \ 366 + name == SKB_NOT_DROPPED_YET) \ 367 + SKB_DR_SET(name, reason); \ 368 + } while (0) 369 + 370 + #endif
+27 -347
include/net/dropreason.h
··· 2 2 3 3 #ifndef _LINUX_DROPREASON_H 4 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) 5 + #include <net/dropreason-core.h> 82 6 83 7 /** 84 - * enum skb_drop_reason - the reasons of skb drops 85 - * 86 - * The reason of skb drop, which is used in kfree_skb_reason(). 8 + * enum skb_drop_reason_subsys - subsystem tag for (extended) drop reasons 87 9 */ 88 - enum skb_drop_reason { 10 + enum skb_drop_reason_subsys { 11 + /** @SKB_DROP_REASON_SUBSYS_CORE: core drop reasons defined above */ 12 + SKB_DROP_REASON_SUBSYS_CORE, 13 + 89 14 /** 90 - * @SKB_NOT_DROPPED_YET: skb is not dropped yet (used for no-drop case) 15 + * @SKB_DROP_REASON_SUBSYS_MAC80211_UNUSABLE: mac80211 drop reasons 16 + * for unusable frames, see net/mac80211/drop.h 91 17 */ 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, 18 + SKB_DROP_REASON_SUBSYS_MAC80211_UNUSABLE, 19 + 109 20 /** 110 - * @SKB_DROP_REASON_OTHERHOST: packet don't belong to current host 111 - * (interface is in promisc mode) 21 + * @SKB_DROP_REASON_SUBSYS_MAC80211_MONITOR: mac80211 drop reasons 22 + * for frames still going to monitor, see net/mac80211/drop.h 112 23 */ 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, 24 + SKB_DROP_REASON_SUBSYS_MAC80211_MONITOR, 25 + 26 + /** @SKB_DROP_REASON_SUBSYS_NUM: number of subsystems defined */ 27 + SKB_DROP_REASON_SUBSYS_NUM 346 28 }; 347 29 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) 30 + struct drop_reason_list { 31 + const char * const *reasons; 32 + size_t n_reasons; 33 + }; 360 34 361 - extern const char * const drop_reasons[]; 35 + /* Note: due to dynamic registrations, access must be under RCU */ 36 + extern const struct drop_reason_list __rcu * 37 + drop_reasons_by_subsys[SKB_DROP_REASON_SUBSYS_NUM]; 38 + 39 + void drop_reasons_register_subsys(enum skb_drop_reason_subsys subsys, 40 + const struct drop_reason_list *list); 41 + void drop_reasons_unregister_subsys(enum skb_drop_reason_subsys subsys); 362 42 363 43 #endif
+1 -1
include/net/inet_frag.h
··· 7 7 #include <linux/in6.h> 8 8 #include <linux/rbtree_types.h> 9 9 #include <linux/refcount.h> 10 - #include <net/dropreason.h> 10 + #include <net/dropreason-core.h> 11 11 12 12 /* Per netns frag queues directory */ 13 13 struct fqdir {
+24 -9
net/core/drop_monitor.c
··· 21 21 #include <linux/workqueue.h> 22 22 #include <linux/netlink.h> 23 23 #include <linux/net_dropmon.h> 24 + #include <linux/bitfield.h> 24 25 #include <linux/percpu.h> 25 26 #include <linux/timer.h> 26 27 #include <linux/bitops.h> ··· 30 29 #include <net/genetlink.h> 31 30 #include <net/netevent.h> 32 31 #include <net/flow_offload.h> 32 + #include <net/dropreason.h> 33 33 #include <net/devlink.h> 34 34 35 35 #include <trace/events/skb.h> ··· 506 504 if (!nskb) 507 505 return; 508 506 509 - if (unlikely(reason >= SKB_DROP_REASON_MAX || reason <= 0)) 510 - reason = SKB_DROP_REASON_NOT_SPECIFIED; 511 507 cb = NET_DM_SKB_CB(nskb); 512 508 cb->reason = reason; 513 509 cb->pc = location; ··· 552 552 } 553 553 554 554 #define NET_DM_MAX_SYMBOL_LEN 40 555 + #define NET_DM_MAX_REASON_LEN 50 555 556 556 - static size_t net_dm_packet_report_size(size_t payload_len, 557 - enum skb_drop_reason reason) 557 + static size_t net_dm_packet_report_size(size_t payload_len) 558 558 { 559 559 size_t size; 560 560 ··· 576 576 /* NET_DM_ATTR_PROTO */ 577 577 nla_total_size(sizeof(u16)) + 578 578 /* NET_DM_ATTR_REASON */ 579 - nla_total_size(strlen(drop_reasons[reason]) + 1) + 579 + nla_total_size(NET_DM_MAX_REASON_LEN + 1) + 580 580 /* NET_DM_ATTR_PAYLOAD */ 581 581 nla_total_size(payload_len); 582 582 } ··· 610 610 size_t payload_len) 611 611 { 612 612 struct net_dm_skb_cb *cb = NET_DM_SKB_CB(skb); 613 + const struct drop_reason_list *list = NULL; 614 + unsigned int subsys, subsys_reason; 613 615 char buf[NET_DM_MAX_SYMBOL_LEN]; 614 616 struct nlattr *attr; 615 617 void *hdr; ··· 629 627 NET_DM_ATTR_PAD)) 630 628 goto nla_put_failure; 631 629 630 + rcu_read_lock(); 631 + subsys = u32_get_bits(cb->reason, SKB_DROP_REASON_SUBSYS_MASK); 632 + if (subsys < SKB_DROP_REASON_SUBSYS_NUM) 633 + list = rcu_dereference(drop_reasons_by_subsys[subsys]); 634 + subsys_reason = cb->reason & ~SKB_DROP_REASON_SUBSYS_MASK; 635 + if (!list || 636 + subsys_reason >= list->n_reasons || 637 + !list->reasons[subsys_reason] || 638 + strlen(list->reasons[subsys_reason]) > NET_DM_MAX_REASON_LEN) { 639 + list = rcu_dereference(drop_reasons_by_subsys[SKB_DROP_REASON_SUBSYS_CORE]); 640 + subsys_reason = SKB_DROP_REASON_NOT_SPECIFIED; 641 + } 632 642 if (nla_put_string(msg, NET_DM_ATTR_REASON, 633 - drop_reasons[cb->reason])) 643 + list->reasons[subsys_reason])) { 644 + rcu_read_unlock(); 634 645 goto nla_put_failure; 646 + } 647 + rcu_read_unlock(); 635 648 636 649 snprintf(buf, sizeof(buf), "%pS", cb->pc); 637 650 if (nla_put_string(msg, NET_DM_ATTR_SYMBOL, buf)) ··· 704 687 if (net_dm_trunc_len) 705 688 payload_len = min_t(size_t, net_dm_trunc_len, payload_len); 706 689 707 - msg = nlmsg_new(net_dm_packet_report_size(payload_len, 708 - NET_DM_SKB_CB(skb)->reason), 709 - GFP_KERNEL); 690 + msg = nlmsg_new(net_dm_packet_report_size(payload_len), GFP_KERNEL); 710 691 if (!msg) 711 692 goto out; 712 693
+56 -3
net/core/skbuff.c
··· 58 58 #include <linux/scatterlist.h> 59 59 #include <linux/errqueue.h> 60 60 #include <linux/prefetch.h> 61 + #include <linux/bitfield.h> 61 62 #include <linux/if_vlan.h> 62 63 #include <linux/mpls.h> 63 64 #include <linux/kcov.h> ··· 73 72 #include <net/mptcp.h> 74 73 #include <net/mctp.h> 75 74 #include <net/page_pool.h> 75 + #include <net/dropreason.h> 76 76 77 77 #include <linux/uaccess.h> 78 78 #include <trace/events/skb.h> ··· 124 122 125 123 #undef FN 126 124 #define FN(reason) [SKB_DROP_REASON_##reason] = #reason, 127 - const char * const drop_reasons[] = { 125 + static const char * const drop_reasons[] = { 128 126 [SKB_CONSUMED] = "CONSUMED", 129 127 DEFINE_DROP_REASON(FN, FN) 130 128 }; 131 - EXPORT_SYMBOL(drop_reasons); 129 + 130 + static const struct drop_reason_list drop_reasons_core = { 131 + .reasons = drop_reasons, 132 + .n_reasons = ARRAY_SIZE(drop_reasons), 133 + }; 134 + 135 + const struct drop_reason_list __rcu * 136 + drop_reasons_by_subsys[SKB_DROP_REASON_SUBSYS_NUM] = { 137 + [SKB_DROP_REASON_SUBSYS_CORE] = RCU_INITIALIZER(&drop_reasons_core), 138 + }; 139 + EXPORT_SYMBOL(drop_reasons_by_subsys); 140 + 141 + /** 142 + * drop_reasons_register_subsys - register another drop reason subsystem 143 + * @subsys: the subsystem to register, must not be the core 144 + * @list: the list of drop reasons within the subsystem, must point to 145 + * a statically initialized list 146 + */ 147 + void drop_reasons_register_subsys(enum skb_drop_reason_subsys subsys, 148 + const struct drop_reason_list *list) 149 + { 150 + if (WARN(subsys <= SKB_DROP_REASON_SUBSYS_CORE || 151 + subsys >= ARRAY_SIZE(drop_reasons_by_subsys), 152 + "invalid subsystem %d\n", subsys)) 153 + return; 154 + 155 + /* must point to statically allocated memory, so INIT is OK */ 156 + RCU_INIT_POINTER(drop_reasons_by_subsys[subsys], list); 157 + } 158 + EXPORT_SYMBOL_GPL(drop_reasons_register_subsys); 159 + 160 + /** 161 + * drop_reasons_unregister_subsys - unregister a drop reason subsystem 162 + * @subsys: the subsystem to remove, must not be the core 163 + * 164 + * Note: This will synchronize_rcu() to ensure no users when it returns. 165 + */ 166 + void drop_reasons_unregister_subsys(enum skb_drop_reason_subsys subsys) 167 + { 168 + if (WARN(subsys <= SKB_DROP_REASON_SUBSYS_CORE || 169 + subsys >= ARRAY_SIZE(drop_reasons_by_subsys), 170 + "invalid subsystem %d\n", subsys)) 171 + return; 172 + 173 + RCU_INIT_POINTER(drop_reasons_by_subsys[subsys], NULL); 174 + 175 + synchronize_rcu(); 176 + } 177 + EXPORT_SYMBOL_GPL(drop_reasons_unregister_subsys); 132 178 133 179 /** 134 180 * skb_panic - private function for out-of-line support ··· 1036 986 if (unlikely(!skb_unref(skb))) 1037 987 return false; 1038 988 1039 - DEBUG_NET_WARN_ON_ONCE(reason <= 0 || reason >= SKB_DROP_REASON_MAX); 989 + DEBUG_NET_WARN_ON_ONCE(reason == SKB_NOT_DROPPED_YET || 990 + u32_get_bits(reason, 991 + SKB_DROP_REASON_SUBSYS_MASK) >= 992 + SKB_DROP_REASON_SUBSYS_NUM); 1040 993 1041 994 if (reason == SKB_CONSUMED) 1042 995 trace_consume_skb(skb, __builtin_return_address(0));
+56
net/mac80211/drop.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0-only */ 2 + /* 3 + * mac80211 drop reason list 4 + * 5 + * Copyright (C) 2023 Intel Corporation 6 + */ 7 + 8 + #ifndef MAC80211_DROP_H 9 + #define MAC80211_DROP_H 10 + #include <net/dropreason.h> 11 + 12 + typedef unsigned int __bitwise ieee80211_rx_result; 13 + 14 + #define MAC80211_DROP_REASONS_MONITOR(R) \ 15 + R(RX_DROP_M_UNEXPECTED_4ADDR_FRAME) \ 16 + R(RX_DROP_M_BAD_BCN_KEYIDX) \ 17 + R(RX_DROP_M_BAD_MGMT_KEYIDX) \ 18 + /* this line for the trailing \ - add before this */ 19 + 20 + #define MAC80211_DROP_REASONS_UNUSABLE(R) \ 21 + R(RX_DROP_U_MIC_FAIL) \ 22 + R(RX_DROP_U_REPLAY) \ 23 + R(RX_DROP_U_BAD_MMIE) \ 24 + /* this line for the trailing \ - add before this */ 25 + 26 + /* having two enums allows for checking ieee80211_rx_result use with sparse */ 27 + enum ___mac80211_drop_reason { 28 + /* if we get to the end of handlers with RX_CONTINUE this will be the reason */ 29 + ___RX_CONTINUE = SKB_CONSUMED, 30 + 31 + /* this never gets used as an argument to kfree_skb_reason() */ 32 + ___RX_QUEUED = SKB_NOT_DROPPED_YET, 33 + 34 + #define ENUM(x) ___ ## x, 35 + ___RX_DROP_MONITOR = SKB_DROP_REASON_SUBSYS_MAC80211_MONITOR << 36 + SKB_DROP_REASON_SUBSYS_SHIFT, 37 + MAC80211_DROP_REASONS_MONITOR(ENUM) 38 + 39 + ___RX_DROP_UNUSABLE = SKB_DROP_REASON_SUBSYS_MAC80211_UNUSABLE << 40 + SKB_DROP_REASON_SUBSYS_SHIFT, 41 + MAC80211_DROP_REASONS_UNUSABLE(ENUM) 42 + #undef ENUM 43 + }; 44 + 45 + enum mac80211_drop_reason { 46 + RX_CONTINUE = (__force ieee80211_rx_result)___RX_CONTINUE, 47 + RX_QUEUED = (__force ieee80211_rx_result)___RX_QUEUED, 48 + RX_DROP_MONITOR = (__force ieee80211_rx_result)___RX_DROP_MONITOR, 49 + RX_DROP_UNUSABLE = (__force ieee80211_rx_result)___RX_DROP_UNUSABLE, 50 + #define DEF(x) x = (__force ieee80211_rx_result)___ ## x, 51 + MAC80211_DROP_REASONS_MONITOR(DEF) 52 + MAC80211_DROP_REASONS_UNUSABLE(DEF) 53 + #undef DEF 54 + }; 55 + 56 + #endif /* MAC80211_DROP_H */
+1 -7
net/mac80211/ieee80211_i.h
··· 33 33 #include "key.h" 34 34 #include "sta_info.h" 35 35 #include "debug.h" 36 + #include "drop.h" 36 37 37 38 extern const struct cfg80211_ops mac80211_config_ops; 38 39 ··· 170 169 171 170 unsigned int flags; 172 171 }; 173 - 174 - 175 - typedef unsigned __bitwise ieee80211_rx_result; 176 - #define RX_CONTINUE ((__force ieee80211_rx_result) 0u) 177 - #define RX_DROP_UNUSABLE ((__force ieee80211_rx_result) 1u) 178 - #define RX_DROP_MONITOR ((__force ieee80211_rx_result) 2u) 179 - #define RX_QUEUED ((__force ieee80211_rx_result) 3u) 180 172 181 173 /** 182 174 * enum ieee80211_packet_rx_flags - packet RX flags
+31
net/mac80211/main.c
··· 22 22 #include <linux/bitmap.h> 23 23 #include <linux/inetdevice.h> 24 24 #include <net/net_namespace.h> 25 + #include <net/dropreason.h> 25 26 #include <net/cfg80211.h> 26 27 #include <net/addrconf.h> 27 28 ··· 1543 1542 } 1544 1543 EXPORT_SYMBOL(ieee80211_free_hw); 1545 1544 1545 + static const char * const drop_reasons_monitor[] = { 1546 + #define V(x) #x, 1547 + [0] = "RX_DROP_MONITOR", 1548 + MAC80211_DROP_REASONS_MONITOR(V) 1549 + }; 1550 + 1551 + static struct drop_reason_list drop_reason_list_monitor = { 1552 + .reasons = drop_reasons_monitor, 1553 + .n_reasons = ARRAY_SIZE(drop_reasons_monitor), 1554 + }; 1555 + 1556 + static const char * const drop_reasons_unusable[] = { 1557 + [0] = "RX_DROP_UNUSABLE", 1558 + MAC80211_DROP_REASONS_UNUSABLE(V) 1559 + #undef V 1560 + }; 1561 + 1562 + static struct drop_reason_list drop_reason_list_unusable = { 1563 + .reasons = drop_reasons_unusable, 1564 + .n_reasons = ARRAY_SIZE(drop_reasons_unusable), 1565 + }; 1566 + 1546 1567 static int __init ieee80211_init(void) 1547 1568 { 1548 1569 struct sk_buff *skb; ··· 1582 1559 if (ret) 1583 1560 goto err_netdev; 1584 1561 1562 + drop_reasons_register_subsys(SKB_DROP_REASON_SUBSYS_MAC80211_MONITOR, 1563 + &drop_reason_list_monitor); 1564 + drop_reasons_register_subsys(SKB_DROP_REASON_SUBSYS_MAC80211_UNUSABLE, 1565 + &drop_reason_list_unusable); 1566 + 1585 1567 return 0; 1586 1568 err_netdev: 1587 1569 rc80211_minstrel_exit(); ··· 1601 1573 ieee80211s_stop(); 1602 1574 1603 1575 ieee80211_iface_exit(); 1576 + 1577 + drop_reasons_unregister_subsys(SKB_DROP_REASON_SUBSYS_MAC80211_MONITOR); 1578 + drop_reasons_unregister_subsys(SKB_DROP_REASON_SUBSYS_MAC80211_UNUSABLE); 1604 1579 1605 1580 rcu_barrier(); 1606 1581 }
+29 -32
net/mac80211/rx.c
··· 1826 1826 cfg80211_rx_unexpected_4addr_frame( 1827 1827 rx->sdata->dev, sta->sta.addr, 1828 1828 GFP_ATOMIC); 1829 - return RX_DROP_MONITOR; 1829 + return RX_DROP_M_UNEXPECTED_4ADDR_FRAME; 1830 1830 } 1831 1831 /* 1832 1832 * Update counter and free packet here to avoid ··· 1961 1961 cfg80211_rx_unprot_mlme_mgmt(rx->sdata->dev, 1962 1962 skb->data, 1963 1963 skb->len); 1964 - return RX_DROP_MONITOR; /* unexpected BIP keyidx */ 1964 + return RX_DROP_M_BAD_BCN_KEYIDX; 1965 1965 } 1966 1966 1967 1967 rx->key = ieee80211_rx_get_bigtk(rx, mmie_keyidx); ··· 1975 1975 1976 1976 if (mmie_keyidx < NUM_DEFAULT_KEYS || 1977 1977 mmie_keyidx >= NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS) 1978 - return RX_DROP_MONITOR; /* unexpected BIP keyidx */ 1978 + return RX_DROP_M_BAD_MGMT_KEYIDX; /* unexpected BIP keyidx */ 1979 1979 if (rx->link_sta) { 1980 1980 if (ieee80211_is_group_privacy_action(skb) && 1981 1981 test_sta_flag(rx->sta, WLAN_STA_MFP)) ··· 3960 3960 } 3961 3961 3962 3962 static void ieee80211_rx_cooked_monitor(struct ieee80211_rx_data *rx, 3963 - struct ieee80211_rate *rate) 3963 + struct ieee80211_rate *rate, 3964 + ieee80211_rx_result reason) 3964 3965 { 3965 3966 struct ieee80211_sub_if_data *sdata; 3966 3967 struct ieee80211_local *local = rx->local; ··· 4025 4024 } 4026 4025 4027 4026 out_free_skb: 4028 - dev_kfree_skb(skb); 4027 + kfree_skb_reason(skb, (__force u32)reason); 4029 4028 } 4030 4029 4031 4030 static void ieee80211_rx_handlers_result(struct ieee80211_rx_data *rx, 4032 4031 ieee80211_rx_result res) 4033 4032 { 4034 - switch (res) { 4035 - case RX_DROP_MONITOR: 4036 - I802_DEBUG_INC(rx->sdata->local->rx_handlers_drop); 4037 - if (rx->sta) 4038 - rx->link_sta->rx_stats.dropped++; 4039 - fallthrough; 4040 - case RX_CONTINUE: { 4041 - struct ieee80211_rate *rate = NULL; 4042 - struct ieee80211_supported_band *sband; 4043 - struct ieee80211_rx_status *status; 4033 + struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb); 4034 + struct ieee80211_supported_band *sband; 4035 + struct ieee80211_rate *rate = NULL; 4044 4036 4045 - status = IEEE80211_SKB_RXCB((rx->skb)); 4046 - 4047 - sband = rx->local->hw.wiphy->bands[status->band]; 4048 - if (status->encoding == RX_ENC_LEGACY) 4049 - rate = &sband->bitrates[status->rate_idx]; 4050 - 4051 - ieee80211_rx_cooked_monitor(rx, rate); 4052 - break; 4053 - } 4054 - case RX_DROP_UNUSABLE: 4055 - I802_DEBUG_INC(rx->sdata->local->rx_handlers_drop); 4056 - if (rx->sta) 4057 - rx->link_sta->rx_stats.dropped++; 4058 - dev_kfree_skb(rx->skb); 4059 - break; 4060 - case RX_QUEUED: 4037 + if (res == RX_QUEUED) { 4061 4038 I802_DEBUG_INC(rx->sdata->local->rx_handlers_queued); 4062 - break; 4039 + return; 4063 4040 } 4041 + 4042 + if (res != RX_CONTINUE) { 4043 + I802_DEBUG_INC(rx->sdata->local->rx_handlers_drop); 4044 + if (rx->sta) 4045 + rx->link_sta->rx_stats.dropped++; 4046 + } 4047 + 4048 + if (u32_get_bits((__force u32)res, SKB_DROP_REASON_SUBSYS_MASK) == 4049 + SKB_DROP_REASON_SUBSYS_MAC80211_UNUSABLE) { 4050 + kfree_skb_reason(rx->skb, (__force u32)res); 4051 + return; 4052 + } 4053 + 4054 + sband = rx->local->hw.wiphy->bands[status->band]; 4055 + if (status->encoding == RX_ENC_LEGACY) 4056 + rate = &sband->bitrates[status->rate_idx]; 4057 + 4058 + ieee80211_rx_cooked_monitor(rx, rate, res); 4064 4059 } 4065 4060 4066 4061 static void ieee80211_rx_handlers(struct ieee80211_rx_data *rx,
+12 -12
net/mac80211/wpa.c
··· 550 550 if (res < 0 || 551 551 (!res && !(status->flag & RX_FLAG_ALLOW_SAME_PN))) { 552 552 key->u.ccmp.replays++; 553 - return RX_DROP_UNUSABLE; 553 + return RX_DROP_U_REPLAY; 554 554 } 555 555 556 556 if (!(status->flag & RX_FLAG_DECRYPTED)) { ··· 564 564 skb->data + hdrlen + IEEE80211_CCMP_HDR_LEN, 565 565 data_len, 566 566 skb->data + skb->len - mic_len)) 567 - return RX_DROP_UNUSABLE; 567 + return RX_DROP_U_MIC_FAIL; 568 568 } 569 569 570 570 memcpy(key->u.ccmp.rx_pn[queue], pn, IEEE80211_CCMP_PN_LEN); ··· 746 746 if (res < 0 || 747 747 (!res && !(status->flag & RX_FLAG_ALLOW_SAME_PN))) { 748 748 key->u.gcmp.replays++; 749 - return RX_DROP_UNUSABLE; 749 + return RX_DROP_U_REPLAY; 750 750 } 751 751 752 752 if (!(status->flag & RX_FLAG_DECRYPTED)) { ··· 761 761 data_len, 762 762 skb->data + skb->len - 763 763 IEEE80211_GCMP_MIC_LEN)) 764 - return RX_DROP_UNUSABLE; 764 + return RX_DROP_U_MIC_FAIL; 765 765 } 766 766 767 767 memcpy(key->u.gcmp.rx_pn[queue], pn, IEEE80211_GCMP_PN_LEN); ··· 930 930 (skb->data + skb->len - sizeof(*mmie)); 931 931 if (mmie->element_id != WLAN_EID_MMIE || 932 932 mmie->length != sizeof(*mmie) - 2) 933 - return RX_DROP_UNUSABLE; /* Invalid MMIE */ 933 + return RX_DROP_U_BAD_MMIE; /* Invalid MMIE */ 934 934 935 935 bip_ipn_swap(ipn, mmie->sequence_number); 936 936 937 937 if (memcmp(ipn, key->u.aes_cmac.rx_pn, 6) <= 0) { 938 938 key->u.aes_cmac.replays++; 939 - return RX_DROP_UNUSABLE; 939 + return RX_DROP_U_REPLAY; 940 940 } 941 941 942 942 if (!(status->flag & RX_FLAG_DECRYPTED)) { ··· 946 946 skb->data + 24, skb->len - 24, mic); 947 947 if (crypto_memneq(mic, mmie->mic, sizeof(mmie->mic))) { 948 948 key->u.aes_cmac.icverrors++; 949 - return RX_DROP_UNUSABLE; 949 + return RX_DROP_U_MIC_FAIL; 950 950 } 951 951 } 952 952 ··· 986 986 987 987 if (memcmp(ipn, key->u.aes_cmac.rx_pn, 6) <= 0) { 988 988 key->u.aes_cmac.replays++; 989 - return RX_DROP_UNUSABLE; 989 + return RX_DROP_U_REPLAY; 990 990 } 991 991 992 992 if (!(status->flag & RX_FLAG_DECRYPTED)) { ··· 996 996 skb->data + 24, skb->len - 24, mic); 997 997 if (crypto_memneq(mic, mmie->mic, sizeof(mmie->mic))) { 998 998 key->u.aes_cmac.icverrors++; 999 - return RX_DROP_UNUSABLE; 999 + return RX_DROP_U_MIC_FAIL; 1000 1000 } 1001 1001 } 1002 1002 ··· 1079 1079 (skb->data + skb->len - sizeof(*mmie)); 1080 1080 if (mmie->element_id != WLAN_EID_MMIE || 1081 1081 mmie->length != sizeof(*mmie) - 2) 1082 - return RX_DROP_UNUSABLE; /* Invalid MMIE */ 1082 + return RX_DROP_U_BAD_MMIE; /* Invalid MMIE */ 1083 1083 1084 1084 bip_ipn_swap(ipn, mmie->sequence_number); 1085 1085 1086 1086 if (memcmp(ipn, key->u.aes_gmac.rx_pn, 6) <= 0) { 1087 1087 key->u.aes_gmac.replays++; 1088 - return RX_DROP_UNUSABLE; 1088 + return RX_DROP_U_REPLAY; 1089 1089 } 1090 1090 1091 1091 if (!(status->flag & RX_FLAG_DECRYPTED)) { ··· 1104 1104 crypto_memneq(mic, mmie->mic, sizeof(mmie->mic))) { 1105 1105 key->u.aes_gmac.icverrors++; 1106 1106 kfree(mic); 1107 - return RX_DROP_UNUSABLE; 1107 + return RX_DROP_U_MIC_FAIL; 1108 1108 } 1109 1109 kfree(mic); 1110 1110 }