Repository navigation
Description
A plan for vivarium's network: a slim router guest for multi-node runs, and what carries a guest's traffic to the internet. Each node of the graph is a measurement, and its result picks the next branch. This body is longer than 20 lines because the graph and the measurement table are the decision.
Where things are today
- East/west (guest to guest): a two-member segment is a direct socketpair. A segment with three or more members,
hub = trueorcapture = truegoes throughLaninnet.py, inside the runner process. No guest sits in the path. Measured on UML: direct 7.0 Gbit/s and hub 3.6 Gbit/s at MTU 1500; both about 25 Gbit/s at MTU 65000 (vivarium: capture and cut a segment on the host, for every backend #1327). - North/south (guest to internet): one passt per guest. krun can use gvproxy instead (
uplink.proxy), and container guests use pasta. A guest can also put vec0 on a segment that a peer guest serves (uplink.segment, vivarium: an out-of-band management network, so guests are provisioned the real way #958). - Control never crosses the guest network (agent channel), so cutting or rerouting any link never costs control of a guest.
- UML memory: free page reporting is a kernel patch already (149M at boot, 553M after a read, 148M unasked). Still open: the store cached twice (A UML guest caches the store twice and never gives the memory back #505).
The idea
A router guest that every guest of a multi-node run connects to:
- mode
uplink: each guest's vec0 is a point-to-point link to the router. The router alone has passt. A forward becomes DNAT on the router. - mode
all: also every segment becomes a star of point-to-point links to the router, which bridges them. Failure labs then get netem, tc and nftables on a real kernel, on every backend, for guests whose kernel vivarium does not build too (RouterOS, SONiC).
Both modes are a topology rewrite in Nix. Every link to the router has two members, so each is a direct socketpair. The runner does not change. If mode all is fast enough, the runner hub can shrink to capture only.
Graph
flowchart TD
M1["M1: router guest cost<br/>host RSS + boot s, UML and container"] --> D1{"cheap enough<br/>to require?"}
M2["M2: throughput<br/>direct / runner hub / via router"] --> D1
D1 -- yes --> R["router mode uplink + all<br/>(needs #858 on a UML router)"]
D1 -- no --> H["keep runner hub<br/>add loss/delay in Lan (#858 comment)"]
R --> B1344["#1344 block/unblock: via router"]
H --> B1344b["#1344 block/unblock: hub per blocked vlan"]
M3["M3: what passt per guest costs<br/>RSS, processes, Gbit/s vs gvproxy"] --> D2{"worth replacing?"}
D2 -- yes --> M4["M4: TSI on krun<br/>port libkrunfw patches to NixOS kernel"]
D2 -- yes --> M5["M5: UML host-socket family<br/>(research)"]
D2 -- no --> K["keep passt; router mode<br/>already cuts it to one"]
R --> D2
Measurements
| node | how | decides |
|---|---|---|
| M1 | smallest forwarding guest: UML with busybox and a static agent (the Python agent needs about 192M), and a container guest. host_memory_kib() and boot seconds, for 1 and 8 ports |
a threshold (proposal: under 64 MiB and 2 s) makes the router a requirement |
| M2 | iperf3, MTU 1500 and 65000, back to back under unshare -rn: direct pair, runner hub, UML router bridge, container router bridge |
whether mode all can replace the runner hub |
| M3 | checks.uplink-iperf, plus RSS and process count of passt for 8 guests |
whether N/S needs a new path at all |
| M4 | size of libkrunfw's TSI patch set against our kernel version; a krun guest with TSI | krun-only option. No ICMP, no raw sockets, no netlink |
| M5 | read arch/um/os-Linux and how hostfs and the vector driver use SIGIO: can a socket family call host socket()/connect() directly? |
guess today; not started before D2 says yes |
Constraints
- Every test runs in the Nix sandbox and on every backend. A requirement must work on UML and container with no KVM. A krun-only path (TSI) is an option, never the requirement.
- macOS has no UML: a router there is a krun guest (vivarium on macOS: the krun backend #1163).
- A forward through the router changes
access.jsonandssh_config.
Related: #958 (out-of-band segment), #858 (UML tc), #505 (UML memory), #1163 (krun on macOS, gvproxy), #1179 (krun vec0 MTU), #1344 (block/unblock), #1327 (hub, capture).
Assisted-By: Claude Opus 5.5
Activity
Lillecarl commentedon Nov 16, 2026
How the user-space proxies carry ICMP, read in source (gvproxy from
/etc/nixpkgs'sgvproxy.src, passt 2026_07_16):socket(AF_INET, SOCK_DGRAM, IPPROTO_ICMP),netIcmp.ListenPacket("udp4", ...)), sends the echo, waits up to 5 s for one reply and writes that reply back into netstack (pkg/services/forwarder/icmp*.go). One socket per request. Every other ICMP type is dropped, and there is no ICMPv6. Windows uses a raw socket instead.icmp.c,util.c:79-86). It also sets the guest's TTL on outgoing UDP (udp.c:1115) and turns the host'sIP_RECVERRerrors back into ICMP for the guest (udp.c:597), so a UDP traceroute works.net.ipv4.ping_group_range(0 2147483647on this host; NixOS sets it through systemd). A new network namespace starts with1 0, which is off.What this means for socket passthrough (M4, M5): a ping socket is only one more datagram socket. A passthrough that forwards
SOCK_DGRAM/IPPROTO_ICMPand passesIP_TTLandIP_RECVERRthrough carries what passt carries, with no TCP/IP stack on the host. libkrun's TSI today forwards TCP and UDP only (docs/networking.md: "ICMP ping sockets ... are not supported").A trap for the router plan: passthrough proxies the guest's own sockets. Packets the router guest forwards or NATs for other guests are not its sockets, so they never reach the passthrough. A router on a passthrough uplink needs a transparent proxy inside it (TPROXY to local sockets), or it keeps a virtio-net or vec uplink.
Assisted-By: Claude Opus 5.5
Lillecarl commentedon Nov 16, 2026
E2: the same router path with a libkrun router (KVM, 2 vCPUs, stock NixOS 6.18 kernel, libkrun's own vsock device). MTU 65000, iperf3 10 s, host load 4-7, runs back to back:
Details:
vivarium/docs/design/router-lab.mdon the local bookmarkexplore/router(not pushed).Assisted-By: Claude Opus 5.5
Lillecarl commentedon Nov 16, 2026
E5: UDP and ICMP echo through the krun router work.
tproxyplus a fwmark and alocalroute. This is not NAT, so the relay keeps its own flow table (30 s idle) instead of conntrack.-u: 600 Mbit/s at 1400 B with 0.1-0.8% loss. 2-5 Gbit/s at 8-32 KB datagrams. The limit is about 70-80 thousand datagrams per second.Also measured since E2:
Open decision: without
/dev/kvmthe router is UML, and at MTU 65000 that is 3-12 times slower than passt (E4).Assisted-By: Claude Opus 5.5
Lillecarl commentedon Nov 16, 2026
E6 and the default case.
Assisted-By: Claude Opus 5.5
Lillecarl commentedon Nov 16, 2026
E7: our own vhost-user vsock device, inside the egress process (
lab/router/egress/src/vsock.rs, bookmarkexplore/router, local).It reads a packet from any descriptor chain. A UML router therefore runs the stock kernel, with no
vsock-linear-tx.patchand no vhost-device-vsock. MTU 65000, one flow, runs back to back:Assisted-By: Claude Opus 5.5
Lillecarl commentedon Nov 16, 2026
E7 correction and two checks.
e7.pysends 169 MB ofseqoutput each way through the device and compares MD5s. Both match. With the host receiver stalled 5 s, the device spilled 219 KB and both still match.max_dgram_qlenand dropped frames.Assisted-By: Claude Opus 5.5
Lillecarl commentedon Nov 16, 2026
E8 (router lab notebook, local bookmark
explore/router): what limits the leg into the guest. MTU 65000, one flow unless noted, pairs back to back at host load about 10.SCHED_BATCH, eight flows into the guest go from 1.2-1.3 to 10.1-10.7 Gbit/s. One flow out of the guest loses about 12%, so it stays opt-in. Its latency is not measured yet.Assisted-By: Claude Opus 5.5
Lillecarl commentedon Nov 16, 2026
E8, continued: UML eight-flow collapse fixed in the relay.
SCHED_BATCHturned out unreliable. Under host load one run collapsed anyway, with 41 ms average and 264 ms maximum pings, so the relay no longer offers it. Instead, the relay now callssched_yield()before a read when its last read was under 64 KiB. The vsock kworker then finishes queuing its batch, so one read takes many packets. Pairs back to back, host load 7-12:The krun router shows no regression. A yield before every read cost one flow into the guest 15-30%, so the yield only follows a short read.
Assisted-By: Claude Opus 5.5
vivarium: router lab, E1 (vsock from UML to the host)
vivarium: router lab, E4 (TCP through router NAT and vsock)
vivarium: router lab, E4 CPU profile
vivarium: router lab, E2 path with a libkrun router
vivarium: router lab, E2 measurements
vivarium: router lab, E2 with a UML client and the router's own CPU time
56 remaining items
Lillecarl commentedon Nov 17, 2026
Decision (User, 2026-11-17): vsock is where the uplink goes.
vivarium.uplink.proxydefaults tovsockfor a NixOS guest on QEMU or krun. The guest runs the router's relay and ruleset in a network namespace behind a vethvec0, and has its own egress on the host. UML, containers and non-NixOS guests keep passt. Anuplink.segmenttakes precedence.Landed so far (main at the 735c1dc lock):
vec0takesvivarium.mtu;checks.lan-vsockandchecks.forward-vsockin CI.Out of a guest, vsock gives 35-39 Gbit/s on QEMU and krun, against passt's 4-20 (
docs/design/router-lab.md).Assisted-By: Claude Opus 5.5
Lillecarl commentedon Nov 17, 2026
Addendum (User, 2026-11-17): gvproxy goes as well. Once vsock and the router are verified on macOS (#1163), both passt and gvproxy are removed. vsock and the router are the only uplinks after that.
Assisted-By: Claude Opus 5.5
vivarium: a NixOS guest on QEMU or krun takes the vsock uplink
Lillecarl commentedon Nov 17, 2026
To investigate (User, 2026-11-17): give container guests the same data path, so pasta, the last passt user, can go.
A container has no vsock, but it needs none. The
vsockuplink already runs the relay in a network namespace behind a veth pair. For a container, the relay would reach the egress over a unix socket bind-mounted into the container, which the egress already serves for krun (path mode). The work is one transport switch in the relay, vsock or unix socket, plus the container launcher's mount.Why the uplink design carries little of passt's risk: the guest's kernel terminates TCP in the namespace and the host's kernel terminates it at the egress. The egress only splices sockets. What vivarium owns is stream shutdown over vsock, the UDP flow table and the ICMP echo relay, not a TCP stack.
Assisted-By: Claude Opus 5.5
vivarium: a forward lists its ports; `ports = "all"` is gone
vivarium: a forward lists its ports; `ports = "all"` is gone
vivarium: uplink-iperf measures vsock, and behind the router
Lillecarl commentedon Nov 17, 2026
Router and vsock on macOS are on main; numbers and the libkrun fixes are in #1163.
ports = "all"is gone: a forward lists its ports, and runtime forwards are #1414.Linux krun with the new libkrun, median of 3 rounds in CI, old / new (Gbit/s): vsock host to guest 7.72 / 7.94, guest to host 12.00 / 11.52; behind the router 4.13 / 6.11 and 5.73 / 7.44. The router path got faster; plain vsock held.
A krun or QEMU run now puts its router on the same backend by default, so a Mac never needs UML for it.
Assisted-By: Claude Opus 5.5
vivarium: libkrun with 1 MiB AF_UNIX buffers on macOS
Lillecarl commentedon Nov 17, 2026
macOS AF_UNIX stream sockets get 8 KiB of buffer each way (
net.local.stream.sendspace), and the sender's buffer limits the flow. libkrun (nixidae/libkrun 5751da95) and the egress now set 1 MiB on their AF_UNIX sockets, on macOS only.One flow, MTU 65000, iperf3 on the host through a forward, median of 3 (host → guest / guest → host):
vsock is now faster than gvproxy in both directions. lan-vsock, forward-vsock, router, lan-router and forward-router pass on krun.
Assisted-By: Claude Opus 5.5
vivarium: a krun run on macOS gets a router guest by default
vivarium: passt and gvproxy are deprecated uplinks
vivarium: passt and gvproxy are deprecated uplinks
vivarium: a check for a guest that is not NixOS behind the router
Lillecarl commentedon Nov 18, 2026
Status 2026-11-18: the router follow-ups are closed. #1521 (the automatic router for every guest), #1522 (container vsock) and #1523 (the router as management switch, and a VRF, relay and DHCP per data network) are done. RouterOS, VyOS and SONiC ask for the router (
checks.routeros-router,checks.vyos-router,checks.sonic-router). What stays open here: macOS (#1163; vsock and router networks unmeasured on a Mac) and the uplink subnet (#379).Assisted-By: Claude Opus 5.5