Crate xdpsock[−][src]
xdpsock
A rust interface for AF_XDP sockets using libbpf.
use xdpsock::{ socket::{BindFlags, SocketConfig, SocketConfigBuilder, XdpFlags}, umem::{UmemConfig, UmemConfigBuilder}, xsk::Xsk2, }; // Configuration let umem_config = UmemConfigBuilder::new() .frame_count(8192) .comp_queue_size(4096) .fill_queue_size(4096) .build() .unwrap(); let socket_config = SocketConfigBuilder::new() .tx_queue_size(4096) .rx_queue_size(4096) .bind_flags(BindFlags::XDP_COPY) // Check your driver to see if you can use ZERO_COPY .xdp_flags(XdpFlags::XDP_FLAGS_SKB_MODE) // Check your driver to see if you can use DRV_MODE .build() .unwrap(); let n_tx_frames = umem_config.frame_count() / 2; let ifname = "veth0"; let mut xsk = Xsk2::new(&ifname, 0, umem_config, socket_config, n_tx_frames as usize); // Sending a packet let pkt: Vec<u8> = vec![]; xsk.send(&pkt); // Receiving a packet let (recvd_pkt, len) = xsk.recv().expect("failed to recv");
Modules
socket | |
umem | |
xsk |
Structs
BindFlags | AF_XDP Configuration flags |
CompQueue | Used to transfer ownership of UMEM frames from kernel-space to user-space. |
FillQueue | Used to transfer ownership of UMEM frames from user-space to kernel-space. |
Frame | Describes a UMEM frame’s address and size of its current contents. |
LibbpfFlags | |
RxQueue | The receiving side of an AF_XDP socket. |
Socket | An AF_XDP socket. |
SocketConfig | Config for a Socket. |
SocketConfigBuilder | Builder for SocketConfig. |
TxQueue | The transmitting side of an AF_XDP socket. |
Umem | A region of virtual contiguous memory divided into equal-sized frames. It provides the underlying working memory for an AF_XDP socket. |
UmemBuilder | Initial step for building a UMEM. This creates the underlying
|
UmemConfig | Config for a Umem instance. |
UmemConfigBuilder | Builder for UmemConfig for a UmemConfig. |
XdpFlags | AF_XDP Configuration flags |
Enums
AccessError | UMEM access errors |
DataError | Data related errors |
WriteError | Errors that may occur when writing data to the UMEM. |