afxdp

package
v0.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 5, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package afxdp implements pktkit.L2Device over Linux AF_XDP sockets, providing kernel-bypass Ethernet frame I/O via shared memory ring buffers.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoBuffers = errors.New("afxdp: no free TX buffers")
	ErrClosed    = errors.New("afxdp: device closed")
)

Errors returned by Device operations.

Functions

This section is empty.

Types

type Config

type Config struct {
	// Interface is the network interface name (e.g. "eth0").
	Interface string

	// QueueID is the NIC hardware queue to bind to (usually 0).
	QueueID int

	// RingSize is the size of each ring buffer (must be a power of 2).
	// Default: 2048.
	RingSize int

	// FrameSize is the size of each UMEM frame in bytes.
	// Default: 4096.
	FrameSize int

	// NumFrames is the total number of UMEM frames.
	// Default: 4096. Half are used for RX, half for TX.
	NumFrames int

	// Copy forces XDP_COPY mode. By default the driver tries zero-copy
	// first and falls back to copy mode if the NIC doesn't support it.
	Copy bool

	// XSKMapFD, if > 0, uses an existing XSKMAP instead of loading a
	// BPF program automatically. The caller is responsible for loading
	// their own XDP program and creating the map.
	XSKMapFD int

	// Flags are additional XDP socket bind flags (e.g. unix.XDP_USE_NEED_WAKEUP).
	Flags uint16
}

Config configures an AF_XDP device.

type Device

type Device struct {
	// contains filtered or unexported fields
}

Device is an L2 network device backed by a Linux AF_XDP socket. It implements pktkit.L2Device.

func New

func New(cfg Config) (*Device, error)

New creates a new AF_XDP device bound to the given interface and queue. It sets up UMEM, ring buffers, and optionally loads a minimal XDP BPF program.

func (*Device) Close

func (d *Device) Close() error

Close shuts down the device, unmaps memory, and detaches BPF.

func (*Device) Done

func (d *Device) Done() <-chan struct{}

Done returns a channel that is closed when the device is shut down.

func (*Device) HWAddr

func (d *Device) HWAddr() net.HardwareAddr

HWAddr returns the hardware (MAC) address of the underlying interface.

func (*Device) Send

func (d *Device) Send(f pktkit.Frame) error

Send transmits an Ethernet frame via the AF_XDP socket.

func (*Device) SetHandler

func (d *Device) SetHandler(h func(pktkit.Frame) error)

SetHandler sets the callback invoked for each received Ethernet frame.

func (*Device) Statistics

func (d *Device) Statistics() (unix.XDPStatistics, error)

Statistics returns AF_XDP socket statistics.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL