1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
//! Cross-platform L3 TUN device + privilege/route helpers.
//!
//! The overlay data plane (`l3.rs`) is written against one small surface and never
//! sees OS specifics: the `Tun` type (`open`/`name`/`recv`/`send`, moving raw IP
//! packets), `add_route` (point the overlay prefix at the device), and the
//! privilege helpers (`ensure_net_admin_for_l3`, `ensure_hosts_writable`). Each OS
//! supplies a backend that implements exactly that surface:
//!
//! - Linux (`linux`): `/dev/net/tun` + `TUNSETIFF` ioctl, iproute2, CAP_NET_ADMIN.
//! - macOS (`macos`): `utun` via a PF_SYSTEM control socket, `ifconfig`/`route`, root.
//! - Windows (`windows`): Wintun (`wintun.dll`), the IP Helper API, Administrator.
//!
//! `recv`/`send` always exchange bare IP packets with `l3.rs`; any per-OS framing
//! (macOS prepends a 4-byte address-family header, Linux with IFF_NO_PI does not)
//! is added/stripped inside the backend so the overlay logic stays portable.
/// The overlay's packet endpoint, abstracted so `l3.rs` is agnostic to HOW bare IP
/// packets reach the wire. `KernelTun` (below) is the privileged backend that hands
/// packets to the OS stack via a kernel TUN; a userspace smoltcp `NetstackTun`
/// (added later) implements the same surface with ZERO privilege. `recv` yields an
/// OUTBOUND packet the local stack wants sent to a peer (l3.rs routes it by dest IP
/// to that peer's datagram transport); `send` injects a peer's INBOUND packet into
/// the local stack. Byte-exact bare IP in both directions (per-OS framing, e.g.
/// macOS's 4-byte AF header, is added/stripped inside the backend).
// Userspace (zero-privilege) overlay backend. Platform-independent (pure smoltcp,
// no OS device). Selected by l3.rs when there is no kernel TUN.
pub use ;
pub use ;
pub use ;
pub use ;