xdp.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /* include/net/xdp.h
  3. *
  4. * Copyright (c) 2017 Jesper Dangaard Brouer, Red Hat Inc.
  5. */
  6. #ifndef __LINUX_NET_XDP_H__
  7. #define __LINUX_NET_XDP_H__
  8. #include <linux/bitfield.h>
  9. #include <linux/filter.h>
  10. #include <linux/netdevice.h>
  11. #include <linux/skbuff.h> /* skb_shared_info */
  12. /**
  13. * DOC: XDP RX-queue information
  14. *
  15. * The XDP RX-queue info (xdp_rxq_info) is associated with the driver
  16. * level RX-ring queues. It is information that is specific to how
  17. * the driver has configured a given RX-ring queue.
  18. *
  19. * Each xdp_buff frame received in the driver carries a (pointer)
  20. * reference to this xdp_rxq_info structure. This provides the XDP
  21. * data-path read-access to RX-info for both kernel and bpf-side
  22. * (limited subset).
  23. *
  24. * For now, direct access is only safe while running in NAPI/softirq
  25. * context. Contents are read-mostly and must not be updated during
  26. * driver NAPI/softirq poll.
  27. *
  28. * The driver usage API is a register and unregister API.
  29. *
  30. * The struct is not directly tied to the XDP prog. A new XDP prog
  31. * can be attached as long as it doesn't change the underlying
  32. * RX-ring. If the RX-ring does change significantly, the NIC driver
  33. * naturally needs to stop the RX-ring before purging and reallocating
  34. * memory. In that process the driver MUST call unregister (which
  35. * also applies for driver shutdown and unload). The register API is
  36. * also mandatory during RX-ring setup.
  37. */
  38. enum xdp_mem_type {
  39. MEM_TYPE_PAGE_SHARED = 0, /* Split-page refcnt based model */
  40. MEM_TYPE_PAGE_ORDER0, /* Orig XDP full page model */
  41. MEM_TYPE_PAGE_POOL,
  42. MEM_TYPE_XSK_BUFF_POOL,
  43. MEM_TYPE_MAX,
  44. };
  45. /* XDP flags for ndo_xdp_xmit */
  46. #define XDP_XMIT_FLUSH (1U << 0) /* doorbell signal consumer */
  47. #define XDP_XMIT_FLAGS_MASK XDP_XMIT_FLUSH
  48. struct xdp_mem_info {
  49. u32 type; /* enum xdp_mem_type, but known size type */
  50. u32 id;
  51. };
  52. struct page_pool;
  53. struct xdp_rxq_info {
  54. struct net_device *dev;
  55. u32 queue_index;
  56. u32 reg_state;
  57. struct xdp_mem_info mem;
  58. unsigned int napi_id;
  59. u32 frag_size;
  60. } ____cacheline_aligned; /* perf critical, avoid false-sharing */
  61. struct xdp_txq_info {
  62. struct net_device *dev;
  63. };
  64. enum xdp_buff_flags {
  65. XDP_FLAGS_HAS_FRAGS = BIT(0), /* non-linear xdp buff */
  66. XDP_FLAGS_FRAGS_PF_MEMALLOC = BIT(1), /* xdp paged memory is under
  67. * pressure
  68. */
  69. };
  70. struct xdp_buff {
  71. void *data;
  72. void *data_end;
  73. void *data_meta;
  74. void *data_hard_start;
  75. struct xdp_rxq_info *rxq;
  76. struct xdp_txq_info *txq;
  77. u32 frame_sz; /* frame size to deduce data_hard_end/reserved tailroom*/
  78. u32 flags; /* supported values defined in xdp_buff_flags */
  79. };
  80. static __always_inline bool xdp_buff_has_frags(struct xdp_buff *xdp)
  81. {
  82. return !!(xdp->flags & XDP_FLAGS_HAS_FRAGS);
  83. }
  84. static __always_inline void xdp_buff_set_frags_flag(struct xdp_buff *xdp)
  85. {
  86. xdp->flags |= XDP_FLAGS_HAS_FRAGS;
  87. }
  88. static __always_inline void xdp_buff_clear_frags_flag(struct xdp_buff *xdp)
  89. {
  90. xdp->flags &= ~XDP_FLAGS_HAS_FRAGS;
  91. }
  92. static __always_inline bool xdp_buff_is_frag_pfmemalloc(struct xdp_buff *xdp)
  93. {
  94. return !!(xdp->flags & XDP_FLAGS_FRAGS_PF_MEMALLOC);
  95. }
  96. static __always_inline void xdp_buff_set_frag_pfmemalloc(struct xdp_buff *xdp)
  97. {
  98. xdp->flags |= XDP_FLAGS_FRAGS_PF_MEMALLOC;
  99. }
  100. static __always_inline void
  101. xdp_init_buff(struct xdp_buff *xdp, u32 frame_sz, struct xdp_rxq_info *rxq)
  102. {
  103. xdp->frame_sz = frame_sz;
  104. xdp->rxq = rxq;
  105. xdp->flags = 0;
  106. }
  107. static __always_inline void
  108. xdp_prepare_buff(struct xdp_buff *xdp, unsigned char *hard_start,
  109. int headroom, int data_len, const bool meta_valid)
  110. {
  111. unsigned char *data = hard_start + headroom;
  112. xdp->data_hard_start = hard_start;
  113. xdp->data = data;
  114. xdp->data_end = data + data_len;
  115. xdp->data_meta = meta_valid ? data : data + 1;
  116. }
  117. /* Reserve memory area at end-of data area.
  118. *
  119. * This macro reserves tailroom in the XDP buffer by limiting the
  120. * XDP/BPF data access to data_hard_end. Notice same area (and size)
  121. * is used for XDP_PASS, when constructing the SKB via build_skb().
  122. */
  123. #define xdp_data_hard_end(xdp) \
  124. ((xdp)->data_hard_start + (xdp)->frame_sz - \
  125. SKB_DATA_ALIGN(sizeof(struct skb_shared_info)))
  126. static inline struct skb_shared_info *
  127. xdp_get_shared_info_from_buff(struct xdp_buff *xdp)
  128. {
  129. return (struct skb_shared_info *)xdp_data_hard_end(xdp);
  130. }
  131. static __always_inline unsigned int xdp_get_buff_len(struct xdp_buff *xdp)
  132. {
  133. unsigned int len = xdp->data_end - xdp->data;
  134. struct skb_shared_info *sinfo;
  135. if (likely(!xdp_buff_has_frags(xdp)))
  136. goto out;
  137. sinfo = xdp_get_shared_info_from_buff(xdp);
  138. len += sinfo->xdp_frags_size;
  139. out:
  140. return len;
  141. }
  142. struct xdp_frame {
  143. void *data;
  144. u16 len;
  145. u16 headroom;
  146. u32 metasize; /* uses lower 8-bits */
  147. /* Lifetime of xdp_rxq_info is limited to NAPI/enqueue time,
  148. * while mem info is valid on remote CPU.
  149. */
  150. struct xdp_mem_info mem;
  151. struct net_device *dev_rx; /* used by cpumap */
  152. u32 frame_sz;
  153. u32 flags; /* supported values defined in xdp_buff_flags */
  154. };
  155. static __always_inline bool xdp_frame_has_frags(struct xdp_frame *frame)
  156. {
  157. return !!(frame->flags & XDP_FLAGS_HAS_FRAGS);
  158. }
  159. static __always_inline bool xdp_frame_is_frag_pfmemalloc(struct xdp_frame *frame)
  160. {
  161. return !!(frame->flags & XDP_FLAGS_FRAGS_PF_MEMALLOC);
  162. }
  163. #define XDP_BULK_QUEUE_SIZE 16
  164. struct xdp_frame_bulk {
  165. int count;
  166. void *xa;
  167. void *q[XDP_BULK_QUEUE_SIZE];
  168. };
  169. static __always_inline void xdp_frame_bulk_init(struct xdp_frame_bulk *bq)
  170. {
  171. /* bq->count will be zero'ed when bq->xa gets updated */
  172. bq->xa = NULL;
  173. }
  174. static inline struct skb_shared_info *
  175. xdp_get_shared_info_from_frame(struct xdp_frame *frame)
  176. {
  177. void *data_hard_start = frame->data - frame->headroom - sizeof(*frame);
  178. return (struct skb_shared_info *)(data_hard_start + frame->frame_sz -
  179. SKB_DATA_ALIGN(sizeof(struct skb_shared_info)));
  180. }
  181. struct xdp_cpumap_stats {
  182. unsigned int redirect;
  183. unsigned int pass;
  184. unsigned int drop;
  185. };
  186. /* Clear kernel pointers in xdp_frame */
  187. static inline void xdp_scrub_frame(struct xdp_frame *frame)
  188. {
  189. frame->data = NULL;
  190. frame->dev_rx = NULL;
  191. }
  192. static inline void
  193. xdp_update_skb_shared_info(struct sk_buff *skb, u8 nr_frags,
  194. unsigned int size, unsigned int truesize,
  195. bool pfmemalloc)
  196. {
  197. skb_shinfo(skb)->nr_frags = nr_frags;
  198. skb->len += size;
  199. skb->data_len += size;
  200. skb->truesize += truesize;
  201. skb->pfmemalloc |= pfmemalloc;
  202. }
  203. /* Avoids inlining WARN macro in fast-path */
  204. void xdp_warn(const char *msg, const char *func, const int line);
  205. #define XDP_WARN(msg) xdp_warn(msg, __func__, __LINE__)
  206. struct xdp_frame *xdp_convert_zc_to_xdp_frame(struct xdp_buff *xdp);
  207. struct sk_buff *__xdp_build_skb_from_frame(struct xdp_frame *xdpf,
  208. struct sk_buff *skb,
  209. struct net_device *dev);
  210. struct sk_buff *xdp_build_skb_from_frame(struct xdp_frame *xdpf,
  211. struct net_device *dev);
  212. int xdp_alloc_skb_bulk(void **skbs, int n_skb, gfp_t gfp);
  213. struct xdp_frame *xdpf_clone(struct xdp_frame *xdpf);
  214. static inline
  215. void xdp_convert_frame_to_buff(struct xdp_frame *frame, struct xdp_buff *xdp)
  216. {
  217. xdp->data_hard_start = frame->data - frame->headroom - sizeof(*frame);
  218. xdp->data = frame->data;
  219. xdp->data_end = frame->data + frame->len;
  220. xdp->data_meta = frame->data - frame->metasize;
  221. xdp->frame_sz = frame->frame_sz;
  222. xdp->flags = frame->flags;
  223. }
  224. static inline
  225. int xdp_update_frame_from_buff(struct xdp_buff *xdp,
  226. struct xdp_frame *xdp_frame)
  227. {
  228. int metasize, headroom;
  229. /* Assure headroom is available for storing info */
  230. headroom = xdp->data - xdp->data_hard_start;
  231. metasize = xdp->data - xdp->data_meta;
  232. metasize = metasize > 0 ? metasize : 0;
  233. if (unlikely((headroom - metasize) < sizeof(*xdp_frame)))
  234. return -ENOSPC;
  235. /* Catch if driver didn't reserve tailroom for skb_shared_info */
  236. if (unlikely(xdp->data_end > xdp_data_hard_end(xdp))) {
  237. XDP_WARN("Driver BUG: missing reserved tailroom");
  238. return -ENOSPC;
  239. }
  240. xdp_frame->data = xdp->data;
  241. xdp_frame->len = xdp->data_end - xdp->data;
  242. xdp_frame->headroom = headroom - sizeof(*xdp_frame);
  243. xdp_frame->metasize = metasize;
  244. xdp_frame->frame_sz = xdp->frame_sz;
  245. xdp_frame->flags = xdp->flags;
  246. return 0;
  247. }
  248. /* Convert xdp_buff to xdp_frame */
  249. static inline
  250. struct xdp_frame *xdp_convert_buff_to_frame(struct xdp_buff *xdp)
  251. {
  252. struct xdp_frame *xdp_frame;
  253. if (xdp->rxq->mem.type == MEM_TYPE_XSK_BUFF_POOL)
  254. return xdp_convert_zc_to_xdp_frame(xdp);
  255. /* Store info in top of packet */
  256. xdp_frame = xdp->data_hard_start;
  257. if (unlikely(xdp_update_frame_from_buff(xdp, xdp_frame) < 0))
  258. return NULL;
  259. /* rxq only valid until napi_schedule ends, convert to xdp_mem_info */
  260. xdp_frame->mem = xdp->rxq->mem;
  261. return xdp_frame;
  262. }
  263. void __xdp_return(void *data, struct xdp_mem_info *mem, bool napi_direct,
  264. struct xdp_buff *xdp);
  265. void xdp_return_frame(struct xdp_frame *xdpf);
  266. void xdp_return_frame_rx_napi(struct xdp_frame *xdpf);
  267. void xdp_return_buff(struct xdp_buff *xdp);
  268. void xdp_flush_frame_bulk(struct xdp_frame_bulk *bq);
  269. void xdp_return_frame_bulk(struct xdp_frame *xdpf,
  270. struct xdp_frame_bulk *bq);
  271. static __always_inline unsigned int xdp_get_frame_len(struct xdp_frame *xdpf)
  272. {
  273. struct skb_shared_info *sinfo;
  274. unsigned int len = xdpf->len;
  275. if (likely(!xdp_frame_has_frags(xdpf)))
  276. goto out;
  277. sinfo = xdp_get_shared_info_from_frame(xdpf);
  278. len += sinfo->xdp_frags_size;
  279. out:
  280. return len;
  281. }
  282. int __xdp_rxq_info_reg(struct xdp_rxq_info *xdp_rxq,
  283. struct net_device *dev, u32 queue_index,
  284. unsigned int napi_id, u32 frag_size);
  285. static inline int
  286. xdp_rxq_info_reg(struct xdp_rxq_info *xdp_rxq,
  287. struct net_device *dev, u32 queue_index,
  288. unsigned int napi_id)
  289. {
  290. return __xdp_rxq_info_reg(xdp_rxq, dev, queue_index, napi_id, 0);
  291. }
  292. void xdp_rxq_info_unreg(struct xdp_rxq_info *xdp_rxq);
  293. void xdp_rxq_info_unused(struct xdp_rxq_info *xdp_rxq);
  294. bool xdp_rxq_info_is_reg(struct xdp_rxq_info *xdp_rxq);
  295. int xdp_rxq_info_reg_mem_model(struct xdp_rxq_info *xdp_rxq,
  296. enum xdp_mem_type type, void *allocator);
  297. void xdp_rxq_info_unreg_mem_model(struct xdp_rxq_info *xdp_rxq);
  298. int xdp_reg_mem_model(struct xdp_mem_info *mem,
  299. enum xdp_mem_type type, void *allocator);
  300. void xdp_unreg_mem_model(struct xdp_mem_info *mem);
  301. /* Drivers not supporting XDP metadata can use this helper, which
  302. * rejects any room expansion for metadata as a result.
  303. */
  304. static __always_inline void
  305. xdp_set_data_meta_invalid(struct xdp_buff *xdp)
  306. {
  307. xdp->data_meta = xdp->data + 1;
  308. }
  309. static __always_inline bool
  310. xdp_data_meta_unsupported(const struct xdp_buff *xdp)
  311. {
  312. return unlikely(xdp->data_meta > xdp->data);
  313. }
  314. static inline bool xdp_metalen_invalid(unsigned long metalen)
  315. {
  316. unsigned long meta_max;
  317. meta_max = type_max(typeof_member(struct skb_shared_info, meta_len));
  318. BUILD_BUG_ON(!__builtin_constant_p(meta_max));
  319. return !IS_ALIGNED(metalen, sizeof(u32)) || metalen > meta_max;
  320. }
  321. struct xdp_attachment_info {
  322. struct bpf_prog *prog;
  323. u32 flags;
  324. };
  325. struct netdev_bpf;
  326. void xdp_attachment_setup(struct xdp_attachment_info *info,
  327. struct netdev_bpf *bpf);
  328. #define DEV_MAP_BULK_SIZE XDP_BULK_QUEUE_SIZE
  329. /* Define the relationship between xdp-rx-metadata kfunc and
  330. * various other entities:
  331. * - xdp_rx_metadata enum
  332. * - netdev netlink enum (Documentation/netlink/specs/netdev.yaml)
  333. * - kfunc name
  334. * - xdp_metadata_ops field
  335. */
  336. #define XDP_METADATA_KFUNC_xxx \
  337. XDP_METADATA_KFUNC(XDP_METADATA_KFUNC_RX_TIMESTAMP, \
  338. NETDEV_XDP_RX_METADATA_TIMESTAMP, \
  339. bpf_xdp_metadata_rx_timestamp, \
  340. xmo_rx_timestamp) \
  341. XDP_METADATA_KFUNC(XDP_METADATA_KFUNC_RX_HASH, \
  342. NETDEV_XDP_RX_METADATA_HASH, \
  343. bpf_xdp_metadata_rx_hash, \
  344. xmo_rx_hash) \
  345. XDP_METADATA_KFUNC(XDP_METADATA_KFUNC_RX_VLAN_TAG, \
  346. NETDEV_XDP_RX_METADATA_VLAN_TAG, \
  347. bpf_xdp_metadata_rx_vlan_tag, \
  348. xmo_rx_vlan_tag) \
  349. enum xdp_rx_metadata {
  350. #define XDP_METADATA_KFUNC(name, _, __, ___) name,
  351. XDP_METADATA_KFUNC_xxx
  352. #undef XDP_METADATA_KFUNC
  353. MAX_XDP_METADATA_KFUNC,
  354. };
  355. enum xdp_rss_hash_type {
  356. /* First part: Individual bits for L3/L4 types */
  357. XDP_RSS_L3_IPV4 = BIT(0),
  358. XDP_RSS_L3_IPV6 = BIT(1),
  359. /* The fixed (L3) IPv4 and IPv6 headers can both be followed by
  360. * variable/dynamic headers, IPv4 called Options and IPv6 called
  361. * Extension Headers. HW RSS type can contain this info.
  362. */
  363. XDP_RSS_L3_DYNHDR = BIT(2),
  364. /* When RSS hash covers L4 then drivers MUST set XDP_RSS_L4 bit in
  365. * addition to the protocol specific bit. This ease interaction with
  366. * SKBs and avoids reserving a fixed mask for future L4 protocol bits.
  367. */
  368. XDP_RSS_L4 = BIT(3), /* L4 based hash, proto can be unknown */
  369. XDP_RSS_L4_TCP = BIT(4),
  370. XDP_RSS_L4_UDP = BIT(5),
  371. XDP_RSS_L4_SCTP = BIT(6),
  372. XDP_RSS_L4_IPSEC = BIT(7), /* L4 based hash include IPSEC SPI */
  373. XDP_RSS_L4_ICMP = BIT(8),
  374. /* Second part: RSS hash type combinations used for driver HW mapping */
  375. XDP_RSS_TYPE_NONE = 0,
  376. XDP_RSS_TYPE_L2 = XDP_RSS_TYPE_NONE,
  377. XDP_RSS_TYPE_L3_IPV4 = XDP_RSS_L3_IPV4,
  378. XDP_RSS_TYPE_L3_IPV6 = XDP_RSS_L3_IPV6,
  379. XDP_RSS_TYPE_L3_IPV4_OPT = XDP_RSS_L3_IPV4 | XDP_RSS_L3_DYNHDR,
  380. XDP_RSS_TYPE_L3_IPV6_EX = XDP_RSS_L3_IPV6 | XDP_RSS_L3_DYNHDR,
  381. XDP_RSS_TYPE_L4_ANY = XDP_RSS_L4,
  382. XDP_RSS_TYPE_L4_IPV4_TCP = XDP_RSS_L3_IPV4 | XDP_RSS_L4 | XDP_RSS_L4_TCP,
  383. XDP_RSS_TYPE_L4_IPV4_UDP = XDP_RSS_L3_IPV4 | XDP_RSS_L4 | XDP_RSS_L4_UDP,
  384. XDP_RSS_TYPE_L4_IPV4_SCTP = XDP_RSS_L3_IPV4 | XDP_RSS_L4 | XDP_RSS_L4_SCTP,
  385. XDP_RSS_TYPE_L4_IPV4_IPSEC = XDP_RSS_L3_IPV4 | XDP_RSS_L4 | XDP_RSS_L4_IPSEC,
  386. XDP_RSS_TYPE_L4_IPV4_ICMP = XDP_RSS_L3_IPV4 | XDP_RSS_L4 | XDP_RSS_L4_ICMP,
  387. XDP_RSS_TYPE_L4_IPV6_TCP = XDP_RSS_L3_IPV6 | XDP_RSS_L4 | XDP_RSS_L4_TCP,
  388. XDP_RSS_TYPE_L4_IPV6_UDP = XDP_RSS_L3_IPV6 | XDP_RSS_L4 | XDP_RSS_L4_UDP,
  389. XDP_RSS_TYPE_L4_IPV6_SCTP = XDP_RSS_L3_IPV6 | XDP_RSS_L4 | XDP_RSS_L4_SCTP,
  390. XDP_RSS_TYPE_L4_IPV6_IPSEC = XDP_RSS_L3_IPV6 | XDP_RSS_L4 | XDP_RSS_L4_IPSEC,
  391. XDP_RSS_TYPE_L4_IPV6_ICMP = XDP_RSS_L3_IPV6 | XDP_RSS_L4 | XDP_RSS_L4_ICMP,
  392. XDP_RSS_TYPE_L4_IPV6_TCP_EX = XDP_RSS_TYPE_L4_IPV6_TCP | XDP_RSS_L3_DYNHDR,
  393. XDP_RSS_TYPE_L4_IPV6_UDP_EX = XDP_RSS_TYPE_L4_IPV6_UDP | XDP_RSS_L3_DYNHDR,
  394. XDP_RSS_TYPE_L4_IPV6_SCTP_EX = XDP_RSS_TYPE_L4_IPV6_SCTP | XDP_RSS_L3_DYNHDR,
  395. };
  396. struct xdp_metadata_ops {
  397. int (*xmo_rx_timestamp)(const struct xdp_md *ctx, u64 *timestamp);
  398. int (*xmo_rx_hash)(const struct xdp_md *ctx, u32 *hash,
  399. enum xdp_rss_hash_type *rss_type);
  400. int (*xmo_rx_vlan_tag)(const struct xdp_md *ctx, __be16 *vlan_proto,
  401. u16 *vlan_tci);
  402. };
  403. #ifdef CONFIG_NET
  404. u32 bpf_xdp_metadata_kfunc_id(int id);
  405. bool bpf_dev_bound_kfunc_id(u32 btf_id);
  406. void xdp_set_features_flag(struct net_device *dev, xdp_features_t val);
  407. void xdp_features_set_redirect_target(struct net_device *dev, bool support_sg);
  408. void xdp_features_clear_redirect_target(struct net_device *dev);
  409. #else
  410. static inline u32 bpf_xdp_metadata_kfunc_id(int id) { return 0; }
  411. static inline bool bpf_dev_bound_kfunc_id(u32 btf_id) { return false; }
  412. static inline void
  413. xdp_set_features_flag(struct net_device *dev, xdp_features_t val)
  414. {
  415. }
  416. static inline void
  417. xdp_features_set_redirect_target(struct net_device *dev, bool support_sg)
  418. {
  419. }
  420. static inline void
  421. xdp_features_clear_redirect_target(struct net_device *dev)
  422. {
  423. }
  424. #endif
  425. static inline void xdp_clear_features_flag(struct net_device *dev)
  426. {
  427. xdp_set_features_flag(dev, 0);
  428. }
  429. static __always_inline u32 bpf_prog_run_xdp(const struct bpf_prog *prog,
  430. struct xdp_buff *xdp)
  431. {
  432. /* Driver XDP hooks are invoked within a single NAPI poll cycle and thus
  433. * under local_bh_disable(), which provides the needed RCU protection
  434. * for accessing map entries.
  435. */
  436. u32 act = __bpf_prog_run(prog, xdp, BPF_DISPATCHER_FUNC(xdp));
  437. if (static_branch_unlikely(&bpf_master_redirect_enabled_key)) {
  438. if (act == XDP_TX && netif_is_bond_slave(xdp->rxq->dev))
  439. act = xdp_master_redirect(xdp);
  440. }
  441. return act;
  442. }
  443. #endif /* __LINUX_NET_XDP_H__ */