Module socket

Source
Expand description

§XDP Socket Implementation

§Purpose

This file implements the Socket struct, which provides a high-level interface for interacting with XDP sockets. It supports both sending (TX) and receiving (RX) of packets with high performance through zero-copy data transfers.

§How it works

The Socket utilizes two main components for its operation: a UMEM (Userspace Memory) region and associated rings for communication with the kernel. The UMEM is a memory-mapped area shared between the userspace application and the kernel, which allows for zero-copy packet processing.

  • For sending packets (TX), the application writes packet data directly into frames within the UMEM and then pushes descriptors to the TX ring, signaling the kernel to send them.
  • For receiving packets (RX), the application provides the kernel with descriptors pointing to free frames in the UMEM via the Fill ring. The kernel writes incoming packet data into these frames and notifies the application through the RX ring.

§Main components

  • Socket<const t:_Direction>: The primary struct representing an XDP socket. It is generic over the direction (TX or RX) to provide a type-safe API for each use case.
  • Ring<T>: A generic ring buffer implementation that is used for the TX/RX rings and the Fill/Completion rings for UMEM.
  • Inner: A struct that holds the owned file descriptor for the XDP socket and the memory-mapped UMEM region.
  • TxSocket and RxSocket: Type aliases for Socket<true> and Socket<false> respectively, providing a more intuitive API for users.

Structs§

Socket
A high-level interface for an AF_XDP socket.

Enums§

RingError
An error that can occur during ring operations.

Constants§

_RX
Constant representing the Receive (RX) direction.
_TX
Constant representing the Transmit (TX) direction.

Type Aliases§

RxSocket
A type alias for a socket configured for receiving packets.
TxSocket
A type alias for a socket configured for sending packets.
_Direction
A boolean flag indicating the direction of the socket (true for TX, false for RX).