wired
libc-free QUIC/HTTP3 SDK in C for x86_64-linux
Loading...
Searching...
No Matches
srvxdpbpf.h File Reference

Shared per-interface BPF objects for the AF_XDP driver: one XSKMAP plus redirect-filter program plus link per ifindex, shared by every per-queue XSK socket (wired_srvxdp). More...

Go to the source code of this file.

Data Structures

struct  wired_srvxdpbpf
 The three kernel objects backing one interface's redirect filter. More...

Macros

#define WIRED_SRVXDPBPF_MAP_ENTRIES   64u
 Max XSKMAP entries = max NIC queues servable per interface.

Functions

i64 wired_srvxdpbpf_open (wired_srvxdpbpf *b, u32 ifindex, u16 port, u32 attach_flags)
 Create the XSKMAP (WIRED_SRVXDPBPF_MAP_ENTRIES slots), build and load the redirect-filter program around it (xdpbpf_prog_build, dport == port), and attach it to the interface with a BPF link.
i64 wired_srvxdpbpf_register (wired_srvxdpbpf *b, u32 queue_id, u32 xsk_fd)
 Point the map's queue_id slot at an XSK socket fd, so frames arriving on that NIC queue are redirected to that socket.
void wired_srvxdpbpf_close (wired_srvxdpbpf *b)
 Close the link, program and map fds in that order (negative fds are skipped) and reset each to -1.

Detailed Description

Shared per-interface BPF objects for the AF_XDP driver: one XSKMAP plus redirect-filter program plus link per ifindex, shared by every per-queue XSK socket (wired_srvxdp).

The kernel allows only one XDP link per interface (a second BPF_LINK_CREATE is -EBUSY), so multi-queue servers open this object once per interface and register each queue's XSK socket into its map; the program already redirects by rx_queue_index.

Function Documentation

◆ wired_srvxdpbpf_close()

void wired_srvxdpbpf_close ( wired_srvxdpbpf * b)

Close the link, program and map fds in that order (negative fds are skipped) and reset each to -1.

Safe to call repeatedly.

Parameters
bshared BPF objects to tear down

◆ wired_srvxdpbpf_open()

i64 wired_srvxdpbpf_open ( wired_srvxdpbpf * b,
u32 ifindex,
u16 port,
u32 attach_flags )

Create the XSKMAP (WIRED_SRVXDPBPF_MAP_ENTRIES slots), build and load the redirect-filter program around it (xdpbpf_prog_build, dport == port), and attach it to the interface with a BPF link.

On any failure, everything already built is closed in reverse order and every fd is left at -1.

Parameters
boutput; all three fds valid on success, -1 on failure
ifindexnetwork interface to attach to
portUDP destination port the filter redirects
attach_flags0 = native XDP, XDP_FLAGS_SKB_MODE(2) = generic/veth
Returns
0 on success, or a negative errno

◆ wired_srvxdpbpf_register()

i64 wired_srvxdpbpf_register ( wired_srvxdpbpf * b,
u32 queue_id,
u32 xsk_fd )

Point the map's queue_id slot at an XSK socket fd, so frames arriving on that NIC queue are redirected to that socket.

Parameters
bopen shared BPF objects for the socket's interface
queue_idNIC RX queue index (key into the XSKMAP)
xsk_fdAF_XDP socket fd bound to that queue
Returns
0 on success, or a negative errno