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§
- Async
Device - An async TUN device wrapper around a
DeviceImpl. - Device
Builder - A builder for configuring a TUN interface.
- Device
Impl - A TUN device using the TUN/TAP Linux driver.
- GROTable
- Generic Receive Offload (GRO) table for managing packet coalescing.
- Virtio
NetHdr - Virtio network header for offload support.
Enums§
- Error
- An error from a TUN operation that can combine device I/O and packet offload processing.
- Offload
Error - 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§
- Expand
Buffer - A trait for buffers that can be expanded and resized for offload operations.
- ToIpv4
Address - Trait for converting various types into an IPv4 address.
- ToIpv4
Netmask - Trait for converting various types into an IPv4 netmask (prefix length).
- ToIpv6
Address - Trait for converting various types into an IPv6 address.
- ToIpv6
Netmask - 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.