Crate net_backend

Crate net_backend 

Source
Expand description

Network backend traits and infrastructure.

This crate defines the abstraction boundary between network frontends (guest-facing devices) and network backends (host-side packet I/O). The key types are:

  • Endpoint — a backend factory. One per NIC, responsible for creating Queue objects when the frontend activates the device.

  • Queue — a single TX/RX data path. Backends implement this to send and receive packets. A device may have multiple queues (RSS).

  • BufferAccess — owned by the frontend, provides access to guest memory receive buffers. Passed by &mut reference to every Queue method that needs it, so the frontend retains exclusive ownership and no internal locking is required.

§Lifecycle

  1. The frontend creates a BufferAccess implementation and one QueueConfig per desired queue (containing just a driver).
  2. It calls Endpoint::get_queues, which returns boxed Queue objects.
  3. The frontend posts initial receive buffers by calling Queue::rx_avail with its BufferAccess.
  4. The main loop polls Queue::poll_ready for backend events, then calls Queue::rx_poll / Queue::tx_avail / Queue::tx_poll to exchange packets—always passing &mut dyn BufferAccess.
  5. On shutdown, queues are dropped and Endpoint::stop is called.

Modules§

loopback
Loopback endpoint implementation, which reflects all transmits back as receives.
null
Null (disconnected) endpoint.
resolve
Resolver-related definitions for networking backends.
tests
Types to help test backends.

Structs§

DisconnectableEndpoint
DisconnectableEndpointCachedState
DisconnectableEndpointControl
MultiQueueSupport
Multi-queue related support.
QueueConfig
Per-queue configuration passed to Endpoint::get_queues.
RssConfig
RxBufferSegment
An individual segment in guest memory of a receive buffer.
RxId
A receive buffer ID.
RxMetadata
Receive packet metadata.
TxFlags
Flags affecting transmit behavior.
TxId
A transmit ID. This may be used by multiple segments at the same time.
TxMetadata
Transmit packet metadata.
TxOffloadSupport
The set of supported transmit offloads.
TxSegment
A transmit packet segment.

Enums§

EndpointAction
L3Protocol
The “L3” protocol: the IP layer.
L4Protocol
The “L4” protocol: the TCP/UDP layer.
RxChecksumState
The receive checksum state for a packet.
TxError
TxSegmentType
The segment type.

Traits§

BackendQueueStats
BufferAccess
Frontend-owned access to guest receive buffers.
Endpoint
A network endpoint — the backend side of a NIC.
Queue
A single TX/RX data path for sending and receiving network packets.

Functions§

linearize
Linearizes the next packet in a list of segments, returning the buffer data and advancing the segment list.
next_packet
Gets the next packet from a list of segments, returning the packet metadata, the segments in the packet, and the remaining segments.
packet_count
Computes the number of packets in segments.