Module create_socket

Source
Expand description

§AF_XDP Socket Creation and Configuration

§Purpose

This file contains the logic for creating and configuring AF_XDP sockets. It provides a high-level API to set up sockets for transmit-only, receive-only, or bidirectional packet processing, abstracting away many of the low-level details.

§How it works

It uses libc syscalls to create a raw AF_XDP socket. It then allocates a UMEM (Userspace Memory) region for zero-copy data transfers, configures the necessary rings (TX, RX, Fill, Completion) with appropriate sizes, maps them into memory, and binds the socket to a specific network interface and queue. The logic handles different UMEM and ring configurations based on whether the socket is for TX, RX, or both.

§Main components

  • create_socket(): The core unsafe function that handles the detailed setup logic.
  • create_tx_socket(), create_rx_socket(), create_bi_socket(): Safe public functions that wrap create_socket for specific use cases.
  • setup_umem(): A helper function to allocate and register the UMEM with the kernel.
  • ring_offsets(): A helper to query the kernel for the memory map offsets of the rings.
  • XdpConfig, Direction: Public structs and enums for socket configuration.

Structs§

XdpConfig
Configuration options for creating an AF_XDP socket.

Enums§

Direction
Specifies the direction of an AF_XDP socket.

Functions§

create_bi_socket
Creates a pair of sockets (TxSocket, RxSocket) for bidirectional communication.
create_rx_socket
Creates an RxSocket for receiving packets.
create_socket
Creates one or two sockets for AF_XDP packet processing.
create_tx_socket
Creates a TxSocket for sending packets.
ring_offsets
Retrieves the memory map offsets for the AF_XDP rings from the kernel.
setup_umem
Allocates and registers the UMEM (Userspace Memory) region with the kernel.