pub struct XskSocket { /* private fields */ }Expand description
AF_XDP socket with three-tier opportunistic fallback engine.
Implementations§
Source§impl XskSocket
impl XskSocket
Sourcepub fn bind_opportunistic(
ifname: &str,
queue_id: u32,
umem: &UmemPool,
) -> Result<Self>
pub fn bind_opportunistic( ifname: &str, queue_id: u32, umem: &UmemPool, ) -> Result<Self>
Attempts opportunistic binding of an AF_XDP socket.
Fallback order:
- Zero-Copy mode (
XskBindMode::ZeroCopy) - Copy mode (
XskBindMode::Copy) - Portable recvmmsg fallback (
XskBindMode::FallbackRecvmmsg)
If running unprivileged or kernel lacks AF_XDP, cleanly returns FallbackRecvmmsg.
Sourcepub fn fallback() -> Self
pub fn fallback() -> Self
Creates a fallback socket instance in FallbackRecvmmsg mode without an active AF_XDP socket.
Sourcepub fn mode(&self) -> XskBindMode
pub fn mode(&self) -> XskBindMode
The active bind mode of this socket (ZeroCopy, Copy, or FallbackRecvmmsg).
Sourcepub fn fd(&self) -> RawFd
pub fn fd(&self) -> RawFd
The raw file descriptor of the underlying AF_XDP socket, or -1 in fallback mode.
Sourcepub fn rx_ring_mut(&mut self) -> &mut RxRing
pub fn rx_ring_mut(&mut self) -> &mut RxRing
Mutable reference to the socket’s RX ring buffer.
Sourcepub fn tx_ring_mut(&mut self) -> &mut TxRing
pub fn tx_ring_mut(&mut self) -> &mut TxRing
Mutable reference to the socket’s TX ring buffer.
Sourcepub fn filter(&self) -> Option<&XdpRedirectFilter>
pub fn filter(&self) -> Option<&XdpRedirectFilter>
Reference to the attached eBPF redirect filter, if active.
Sourcepub fn filter_mut(&mut self) -> Option<&mut XdpRedirectFilter>
pub fn filter_mut(&mut self) -> Option<&mut XdpRedirectFilter>
Mutable reference to the attached eBPF redirect filter, if active.
Sourcepub fn attach_bpf_filter(
&mut self,
ifname: &str,
listen_port: u16,
queue_id: u32,
) -> BpfFilterStatus
pub fn attach_bpf_filter( &mut self, ifname: &str, listen_port: u16, queue_id: u32, ) -> BpfFilterStatus
Opportunistically attaches an eBPF XDP redirect filter steering incoming UDP traffic
for listen_port on ifname into this socket’s RX ring.
Sourcepub fn attach_bpf_filter_multi_queue(
&mut self,
ifname: &str,
listen_port: u16,
queue_fds: &[(u32, RawFd)],
) -> BpfFilterStatus
pub fn attach_bpf_filter_multi_queue( &mut self, ifname: &str, listen_port: u16, queue_fds: &[(u32, RawFd)], ) -> BpfFilterStatus
Opportunistically attaches a multi-queue eBPF XDP redirect filter steering incoming UDP traffic
for listen_port on ifname across multiple RX queues into core-pinned AF_XDP rings.
Sourcepub fn set_bpf_filter_queue_socket(
&mut self,
queue_id: u32,
xsk_fd: RawFd,
) -> Result<()>
pub fn set_bpf_filter_queue_socket( &mut self, queue_id: u32, xsk_fd: RawFd, ) -> Result<()>
Sets or updates the socket file descriptor for a specific queue ID in the attached BPF filter.
Sourcepub fn bind_multi_queue(
ifname: &str,
queue_ids: &[u32],
umem: &UmemPool,
) -> Result<Vec<(u32, Self)>>
pub fn bind_multi_queue( ifname: &str, queue_ids: &[u32], umem: &UmemPool, ) -> Result<Vec<(u32, Self)>>
Binds multiple AF_XDP sockets across queue_ids for the given interface and UMEM pool.
Returns a list of (queue_id, XskSocket) pairs. If binding fails for a queue,
a socket in fallback mode is returned for that queue.