Skip to main content

Crate quincy_tun

Crate quincy_tun 

Source
Expand description

§quincy-tun

Cross-platform async TUN library for Quincy.

Forked from tun-rs and trimmed to the exact surface Quincy needs: an async (tokio) TUN device with optional GSO/GRO offload on Linux.

§Supported platforms

Linux, macOS, Windows, FreeBSD, Android, iOS.

§Quick start

use quincy_tun::DeviceBuilder;

let dev = DeviceBuilder::new()
    .ipv4("10.0.0.1", 24, None)
    .build_async()?;

let mut buf = vec![0u8; 65536];
loop {
    let len = dev.recv(&mut buf).await?;
    dev.send(&buf[..len]).await?;
}

§Linux offload (GSO/GRO)

On Linux, enable TSO/GSO for a 3-4x throughput boost:

use quincy_tun::{DeviceBuilder, GROTable, IDEAL_BATCH_SIZE, VIRTIO_NET_HDR_LEN};

let dev = DeviceBuilder::new()
    .ipv4("10.0.0.1", 24, None)
    .offload(true)
    .build_async()?;

let mut original_buffer = vec![0u8; VIRTIO_NET_HDR_LEN + 65535];
let mut bufs = vec![vec![0u8; 1500]; IDEAL_BATCH_SIZE];
let mut sizes = vec![0; IDEAL_BATCH_SIZE];
let mut gro_table = GROTable::default();

let num = dev.recv_multiple(&mut original_buffer, &mut bufs, &mut sizes, 0).await?;

Structs§

AsyncDevice
An async TUN device wrapper around a DeviceImpl.
DeviceBuilder
A builder for configuring a TUN interface.
DeviceImpl
A TUN device using the TUN/TAP Linux driver.
GROTable
Generic Receive Offload (GRO) table for managing packet coalescing.
VirtioNetHdr
Virtio network header for offload support.

Enums§

Error
An error from a TUN operation that can combine device I/O and packet offload processing.
OffloadError
A semantic error produced while processing Linux GSO/GRO packet data.

Constants§

IDEAL_BATCH_SIZE
Recommended batch size for packet operations with offload.
VIRTIO_NET_HDR_GSO_NONE
GSO type: Not a GSO frame (normal packet).
VIRTIO_NET_HDR_GSO_TCPV4
GSO type: IPv4 TCP segmentation (TSO - TCP Segmentation Offload).
VIRTIO_NET_HDR_GSO_TCPV6
GSO type: IPv6 TCP segmentation (TSO).
VIRTIO_NET_HDR_GSO_UDP_L4
GSO type: UDP segmentation for IPv4 and IPv6 (USO - UDP Segmentation Offload).
VIRTIO_NET_HDR_LEN
Size of the virtio network header in bytes (12 bytes).

Traits§

ExpandBuffer
A trait for buffers that can be expanded and resized for offload operations.
ToIpv4Address
Trait for converting various types into an IPv4 address.
ToIpv4Netmask
Trait for converting various types into an IPv4 netmask (prefix length).
ToIpv6Address
Trait for converting various types into an IPv6 address.
ToIpv6Netmask
Trait for converting various types into an IPv6 netmask (prefix length).

Functions§

checksum
Returns the final 16-bit RFC 1071 internet checksum.
checksum_no_fold
RFC 1071 checksum accumulator over b, without folding to 16 bits.
gso_split
Split a GSO (Generic Segmentation Offload) packet into multiple smaller packets.
handle_gro
Processes received packets and applies Generic Receive Offload (GRO) coalescing.

Type Aliases§

Result
A result from an operation that can fail with Error.