Skip to main content

XskSocket

Struct XskSocket 

Source
pub struct XskSocket { /* private fields */ }
Expand description

AF_XDP socket with three-tier opportunistic fallback engine.

Implementations§

Source§

impl XskSocket

Source

pub fn bind_opportunistic( ifname: &str, queue_id: u32, umem: &UmemPool, ) -> Result<Self>

Attempts opportunistic binding of an AF_XDP socket.

Fallback order:

  1. Zero-Copy mode (XskBindMode::ZeroCopy)
  2. Copy mode (XskBindMode::Copy)
  3. Portable recvmmsg fallback (XskBindMode::FallbackRecvmmsg)

If running unprivileged or kernel lacks AF_XDP, cleanly returns FallbackRecvmmsg.

Source

pub fn fallback() -> Self

Creates a fallback socket instance in FallbackRecvmmsg mode without an active AF_XDP socket.

Source

pub fn mode(&self) -> XskBindMode

The active bind mode of this socket (ZeroCopy, Copy, or FallbackRecvmmsg).

Source

pub fn fd(&self) -> RawFd

The raw file descriptor of the underlying AF_XDP socket, or -1 in fallback mode.

Source

pub fn rx_ring_mut(&mut self) -> &mut RxRing

Mutable reference to the socket’s RX ring buffer.

Source

pub fn tx_ring_mut(&mut self) -> &mut TxRing

Mutable reference to the socket’s TX ring buffer.

Source

pub fn rx_ring(&self) -> &RxRing

Immutable reference to the socket’s RX ring buffer.

Source

pub fn tx_ring(&self) -> &TxRing

Immutable reference to the socket’s TX ring buffer.

Source

pub fn filter(&self) -> Option<&XdpRedirectFilter>

Reference to the attached eBPF redirect filter, if active.

Source

pub fn filter_mut(&mut self) -> Option<&mut XdpRedirectFilter>

Mutable reference to the attached eBPF redirect filter, if active.

Source

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.

Source

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.

Source

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.

Source

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.

Trait Implementations§

Source§

impl Drop for XskSocket

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.