Expand description
Cross-platform Rust library for TUN/TAP tunnel interfaces, designed to compose with the rest of the Lattice networking stack.
Start with Tunnel::connect (available with the default tun-rs
feature) to open a device:
use tunnel_lattice::{DeviceConfig, DeviceKind, Result, Tunnel};
fn main() -> Result<()> {
let tunnel = Tunnel::connect();
let device = tunnel.open(DeviceConfig::new(DeviceKind::Tun).with_mtu(1500))?;
let mut buf = vec![0u8; 1500];
let len = device.recv(&mut buf)?;
println!("{} bytes", len);
Ok(())
}This crate carries no OS-addressing responsibility — it creates and
configures the virtual interface and transfers packets on it; IP address
assignment on the resulting interface is net-lattice’s job (see the
net-lattice crate in the sibling Lattice ecosystem).
§Feature flags
tun-rs(default): selectstunnel-lattice-backend-tunrs, implemented on top of the cross-platformtun-rscrate. This is a Cargo feature rather than atarget_oscfg gate so a future alternative backend can sit alongside it instead of replacing it — see the workspaceARCHITECTURE.md, “Backend replacement plan.”async-io/tokio: mutually exclusive, matchingtun-rs’s own two async backends (enabling both is a compile error). Either one addsHandle::packet_stream, afutures::Streamof received packets. Uses a backend’s native async I/O path when it reportsCapability::NATIVE_ASYNC; otherwise falls back totunnel-lattice-async’s thread-based adapter. No async runtime is forced on a caller that enables neither feature.packet_streamis referenced here as plain text, not an intra-doc link, because it only exists under these features and this crate’s defaultcargo docbuild (no features beyondtun-rs) cannot resolve it.
Structs§
- Capability
- Runtime-dependent backend features that cannot be expressed through Rust trait implementation alone.
- Device
- An observed, already-open TUN/TAP device.
- Device
Config - Desired intent for creating a new TUN/TAP device.
- Device
Config Patch - A patch requesting a change to an already-open
Device’s MTU or administrative state. - Handle
- An open TUN/TAP device.
- Tunnel
- A connected backend for creating and operating TUN/TAP devices.
Enums§
- Admin
State - The administrative state of a device, as observed from the backend.
- Desired
Admin State - The administrative state requested for a
DeviceConfigPatch. - Device
Kind - Whether a device presents Ethernet-framed (TAP) or raw IP (TUN) packets.
- Error
- The single error type surfaced across the Tunnel Lattice workspace.
Traits§
- Capability
Provider - Reports which runtime-dependent
Capabilityflags the connected device currently has available. - Connected
Device - An open device handle bound to this facade’s concrete model types.
- Multi
Queue Provider - Duplicates an open device’s queue for use from another thread, when the
backend and the running kernel support hardware-scheduled multiple
queues on one device (Linux
IFF_MULTI_QUEUE). - Persistent
Device - Marks an open device to survive process exit, so a later process requesting the same name can attach to it instead of creating a new one.