tools/testing/selftests/bpf/xsk.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/xsk.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/bpf/xsk.c- Extension
.c- Size
- 17269 bytes
- Lines
- 782
- Domain
- Support Tooling And Documentation
- Bucket
- tools
- Inferred role
- Support Tooling And Documentation: implementation source
- Status
- source implementation candidate
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
errno.hstdlib.hstring.hunistd.harpa/inet.hasm/barrier.hlinux/compiler.hlinux/ethtool.hlinux/filter.hlinux/if_ether.hlinux/if_link.hlinux/if_packet.hlinux/if_xdp.hlinux/kernel.hlinux/list.hlinux/netlink.hlinux/rtnetlink.hlinux/sockios.hnet/if.hsys/ioctl.hsys/mman.hsys/socket.hsys/types.hbpf/bpf.hbpf/libbpf.hxsk.hbpf_util.h
Detected Declarations
struct xsk_umemstruct xsk_ctxstruct xsk_socketstruct nl_mtu_reqfunction xsk_umem__fdfunction xsk_socket__fdfunction xsk_page_alignedfunction xsk_set_umem_configfunction xsk_set_xdp_socket_configfunction xsk_get_mmap_offsetsfunction xsk_create_umem_ringsfunction xsk_umem__createfunction xsk_is_in_modefunction netlink_recvmsgfunction alloc_iovfunction netlink_recvfunction xsk_set_mtufunction xsk_attach_xdp_programfunction xsk_detach_xdp_programfunction xsk_clear_xskmapfunction xsk_update_xskmapfunction list_for_each_entryfunction xsk_put_ctxfunction xsk_socket__create_sharedfunction xsk_socket__createfunction xsk_umem__deletefunction xsk_socket__delete
Annotated Snippet
struct xsk_umem {
struct xsk_ring_prod *fill_save;
struct xsk_ring_cons *comp_save;
char *umem_area;
struct xsk_umem_config config;
int fd;
int refcount;
struct list_head ctx_list;
bool rx_ring_setup_done;
bool tx_ring_setup_done;
};
struct xsk_ctx {
struct xsk_ring_prod *fill;
struct xsk_ring_cons *comp;
__u32 queue_id;
struct xsk_umem *umem;
int refcount;
int ifindex;
struct list_head list;
};
struct xsk_socket {
struct xsk_ring_cons *rx;
struct xsk_ring_prod *tx;
struct xsk_ctx *ctx;
struct xsk_socket_config config;
int fd;
};
struct nl_mtu_req {
struct nlmsghdr nh;
struct ifinfomsg msg;
char buf[512];
};
int xsk_umem__fd(const struct xsk_umem *umem)
{
return umem ? umem->fd : -EINVAL;
}
int xsk_socket__fd(const struct xsk_socket *xsk)
{
return xsk ? xsk->fd : -EINVAL;
}
static bool xsk_page_aligned(void *buffer)
{
unsigned long addr = (unsigned long)buffer;
return !(addr & (getpagesize() - 1));
}
static void xsk_set_umem_config(struct xsk_umem_config *cfg,
const struct xsk_umem_config *usr_cfg)
{
if (!usr_cfg) {
cfg->fill_size = XSK_RING_PROD__DEFAULT_NUM_DESCS;
cfg->comp_size = XSK_RING_CONS__DEFAULT_NUM_DESCS;
cfg->frame_size = XSK_UMEM__DEFAULT_FRAME_SIZE;
cfg->frame_headroom = XSK_UMEM__DEFAULT_FRAME_HEADROOM;
cfg->flags = XSK_UMEM__DEFAULT_FLAGS;
cfg->tx_metadata_len = 0;
return;
}
cfg->fill_size = usr_cfg->fill_size;
cfg->comp_size = usr_cfg->comp_size;
cfg->frame_size = usr_cfg->frame_size;
cfg->frame_headroom = usr_cfg->frame_headroom;
cfg->flags = usr_cfg->flags;
cfg->tx_metadata_len = usr_cfg->tx_metadata_len;
}
static int xsk_set_xdp_socket_config(struct xsk_socket_config *cfg,
const struct xsk_socket_config *usr_cfg)
{
if (!usr_cfg) {
cfg->rx_size = XSK_RING_CONS__DEFAULT_NUM_DESCS;
cfg->tx_size = XSK_RING_PROD__DEFAULT_NUM_DESCS;
cfg->bind_flags = 0;
return 0;
}
cfg->rx_size = usr_cfg->rx_size;
cfg->tx_size = usr_cfg->tx_size;
cfg->bind_flags = usr_cfg->bind_flags;
return 0;
}
Annotation
- Immediate include surface: `errno.h`, `stdlib.h`, `string.h`, `unistd.h`, `arpa/inet.h`, `asm/barrier.h`, `linux/compiler.h`, `linux/ethtool.h`.
- Detected declarations: `struct xsk_umem`, `struct xsk_ctx`, `struct xsk_socket`, `struct nl_mtu_req`, `function xsk_umem__fd`, `function xsk_socket__fd`, `function xsk_page_aligned`, `function xsk_set_umem_config`, `function xsk_set_xdp_socket_config`, `function xsk_get_mmap_offsets`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.