include/net/xdp.h

Source file repositories/reference/linux-study-clean/include/net/xdp.h

File Facts

System
Linux kernel
Corpus path
include/net/xdp.h
Extension
.h
Size
21366 bytes
Lines
706
Domain
Networking Core
Bucket
Sockets, Protocols, Packet Path, And Network Policy
Inferred role
Networking Core: implementation source
Status
source implementation candidate

Why This File Exists

Networking stack implementation surface: socket APIs, protocol dispatch, packet flow, routing, filtering, and network namespaces.

Dependency Surface

Detected Declarations

Annotated Snippet

struct xdp_mem_info {
	u32 type; /* enum xdp_mem_type, but known size type */
	u32 id;
};

struct page_pool;

struct xdp_rxq_info {
	struct net_device *dev;
	u32 queue_index;
	u32 reg_state;
	struct xdp_mem_info mem;
	u32 frag_size;
} ____cacheline_aligned; /* perf critical, avoid false-sharing */

struct xdp_txq_info {
	struct net_device *dev;
};

enum xdp_buff_flags {
	XDP_FLAGS_HAS_FRAGS		= BIT(0), /* non-linear xdp buff */
	XDP_FLAGS_FRAGS_PF_MEMALLOC	= BIT(1), /* xdp paged memory is under
						   * pressure
						   */
	/* frags have unreadable mem, this can't be true for real XDP packets,
	 * but drivers may use XDP helpers to construct Rx pkt state even when
	 * XDP program is not attached.
	 */
	XDP_FLAGS_FRAGS_UNREADABLE	= BIT(2),
};

struct xdp_buff {
	void *data;
	void *data_end;
	void *data_meta;
	void *data_hard_start;
	struct xdp_rxq_info *rxq;
	struct xdp_txq_info *txq;

	union {
		struct {
			/* frame size to deduce data_hard_end/tailroom */
			u32 frame_sz;
			/* supported values defined in xdp_buff_flags */
			u32 flags;
		};

#ifdef __LITTLE_ENDIAN
		/* Used to micro-optimize xdp_init_buff(), don't use directly */
		u64 frame_sz_flags_init;
#endif
	};
};

static __always_inline bool xdp_buff_has_frags(const struct xdp_buff *xdp)
{
	return !!(xdp->flags & XDP_FLAGS_HAS_FRAGS);
}

static __always_inline void xdp_buff_set_frags_flag(struct xdp_buff *xdp)
{
	xdp->flags |= XDP_FLAGS_HAS_FRAGS;
}

static __always_inline void xdp_buff_clear_frags_flag(struct xdp_buff *xdp)
{
	xdp->flags &= ~XDP_FLAGS_HAS_FRAGS;
}

static __always_inline void xdp_buff_set_frag_pfmemalloc(struct xdp_buff *xdp)
{
	xdp->flags |= XDP_FLAGS_FRAGS_PF_MEMALLOC;
}

static __always_inline void xdp_buff_set_frag_unreadable(struct xdp_buff *xdp)
{
	xdp->flags |= XDP_FLAGS_FRAGS_UNREADABLE;
}

static __always_inline u32 xdp_buff_get_skb_flags(const struct xdp_buff *xdp)
{
	return xdp->flags;
}

static __always_inline void xdp_buff_clear_frag_pfmemalloc(struct xdp_buff *xdp)
{
	xdp->flags &= ~XDP_FLAGS_FRAGS_PF_MEMALLOC;
}

static __always_inline void

Annotation

Implementation Notes