Repository navigation
guestnet: add a private userspace network for each VM guest - #20
Merged
Merged
Conversation
bradfitz
force-pushed
the
bradfitz/guestnet_linux
branch
2 times, most recently
from
November 18, 2026 16:20
302300e to
a7aa581
Compare
tomhjp
approved these changes
Nov 20, 2026
tomhjp
left a comment
Member
There was a problem hiding this comment.
Thanks for splitting this up into digestible chunks. It helped to have related files for related changes more easily collected together, and I also learned a ton reviewing this.
tomhjp
reviewed
Nov 20, 2026
bradfitz
force-pushed
the
bradfitz/guestnet_linux
branch
from
November 20, 2026 13:54
a7aa581 to
11b299a
Compare
This starts guestnet, a private userspace network for each VM guest,
which a following commit builds on these. A FrameLink carries raw
Ethernet frames, one per call, between a guest's virtual NIC and us.
- FileLink is a FrameLink over a datagram socket held as an *os.File.
- NewSocketPairLink makes a connected SOCK_DGRAM unix socketpair: one
end for the VMM (macOS's VZFileHandleNetworkDeviceAttachment, or
QEMU's "-netdev dgram"), and a FileLink for us.
- MemLink is an in-memory pair for tests.
Its test comes with the network that uses it, in a following commit.
Updates tailscale/corp#39994
Updates tailscale/corp#51705
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
Change-Id: I9fae04170234d696ddf978ab286abe928b97a380
Log is a fixed-size ring of records with subscribers, for the guest network's per-flow, per-DNS-query and notable event records. Slow subscribers miss records rather than block the network. Updates tailscale/corp#39994 Updates tailscale/corp#51705 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com> Change-Id: I539a6e9dbc4b747ed66596e79879585514ca2587
CI guest VMs on Linux hosts (Firecracker and QEMU) and macOS hosts
currently get their networking from the host's own network stack:
per-slot bridges with iptables NAT and DNAT rules on Linux, and pf rules
on macOS. guestnet does it all in Go instead, the same way on every
platform. That makes our platforms more consistent, removes the need to
manage iptables and pf rules at all, and lets the guest networking code
be shared across platforms. It also gives us more options for how to run
hostlets in the future: a guest that needs no host network configuration
is much easier to run in, say, a Kubernetes pod on EKS, or under a VMM
other than Tart on macOS.
This is the core. A guest's frames all terminate in a gVisor netstack
owned by the guest's Net, so a guest can only reach what we connect it
to, and can't see other guests:
- The gateway, IMDS (169.254.169.254) and DNS (169.254.169.253)
addresses are on our NIC, so gVisor answers ARP and ICMP for them,
and the guest needs no route changes to reach them. ARP for any
other address is dropped: the NIC is promiscuous, and answering a
guest's duplicate-address probe makes it decline its address.
- Each TCP SYN is dispatched by destination to a registered Service (a
guest-facing server, or a forward to a host-side address), or to
egress dialed from the host, subject to a deny list (the tailnet
CGNAT range, loopback and link-local by default). Every flow is
logged.
- The host reaches the guest only by DialGuest; there is no host route
to it.
Every guest gets the same fixed addresses; each has its own L2 domain,
so they don't conflict. DHCP, UDP, DNS and NTP follow in later commits.
guestnettest provides a fake guest stack for tests of code built on it.
Updates tailscale/corp#39994
Updates tailscale/corp#51705
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
Change-Id: I5b359a459ae52218e97cef3b74ecc14a806e0cc7
DHCP is answered from the frame loop with one fixed lease, the same in every slot, so a VM memory snapshot restores anywhere. A request for some other address (a lease carried over from elsewhere) gets a NAK so the client starts over and takes ours. Leased reports the first acknowledged lease. Updates tailscale/corp#39994 Updates tailscale/corp#51705 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com> Change-Id: I1a4ff60af33705202083fb176ead34e6f14289f0
Each UDP flow (a guest source and destination pair) is dispatched like TCP: to egress dialed from the host, subject to the deny list, relaying datagrams until the flow is idle. Multicast and broadcast chatter is dropped silently. Each flow gets its own host socket here; the next commit changes that. Updates tailscale/corp#39994 Updates tailscale/corp#51705 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com> Change-Id: I37e4e11cfcb2900c4b4b63270b834136cb761b91
Giving each UDP flow its own host socket made guestnet a symmetric NAT: one guest port got a different host port for every destination, which makes NAT traversal (Tailscale's own included) much harder. Instead, egress UDP now behaves like a typical home router, an "easy NAT": each guest source address gets one host socket that all its flows share, so it keeps one host address and port whatever the destination (endpoint-independent mapping, RFC 4787), and datagrams reach the guest only from remotes it has sent to (address- and port-dependent filtering). Traffic either way keeps a flow alive. Config.ListenPacket opens those sockets; Dialer is now for TCP only. Updates tailscale/corp#39994 Updates tailscale/corp#51705 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com> Change-Id: I49d3c19755407b47246d73aa6bba5db87cf04ac3
Guest DNS on any port 53, over UDP or TCP and to any address, is answered by a Resolver rather than forwarded, and each query is logged. The default UpstreamResolver forwards to public resolvers over UDP with TCP fallback on truncation; StaticResolver is for tests. A response too big for what the guest accepts over UDP (its EDNS0 payload size, or 512 bytes without EDNS0) is cut to its header and question with the TC bit set, so the guest retries over TCP. Updates tailscale/corp#39994 Updates tailscale/corp#51705 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com> Change-Id: I7eb668b36f361da21835c259af8163d86cf58350
Guest NTP on any port 123 is answered with the host's time, so a guest restored from a memory snapshot can fix its stale clock by syncing against any server. Updates tailscale/corp#39994 Updates tailscale/corp#51705 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com> Change-Id: I2d78c6e36609e32e4161f65351e6ea5b98cb5be1
Egress is dialed from the host, so DenyLocal extends a deny list with the host's own interface addresses, keeping guests away from host listeners on non-loopback addresses (a service on the host's LAN or VPC address, say). Updates tailscale/corp#39994 Updates tailscale/corp#51705 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com> Change-Id: Ia5d4862159747431c02abbffca42126c3b4f7cfd
Firecracker's only network backend is a TAP it opens by name, so it can't be handed a socketpair, and a QEMU guest restored from a memory snapshot taken with a TAP backend needs one again. TAPLink is a FrameLink on the host side of such a TAP: the TAP has no addresses and is on no bridge, and an AF_PACKET socket reads and writes its frames. The host's network stack never handles guest traffic: NewTAPLink adds a tc clsact qdisc to the TAP with a match-all drop filter on its ingress, which drops every guest frame right after the AF_PACKET socket sees it and before any protocol handler does. As defense in depth it also disables IPv6, ARP replies and forwarding on the TAP, and it fails rather than carrying on if it can't do any of that. It configures tc over netlink, with github.com/tailscale/netlink, so no tc binary is needed. It uses PACKET_VNET_HDR because Firecracker enables checksum and segmentation offloads, so guest frames can carry a partial checksum, which TAPLink completes, or be one large TCP segment, which gVisor takes whole. The virtio header is read and written with readv and writev, so it costs no copy and doesn't eat into the frame buffer. With this, guestnet was tested with a modified ciguestlet in the corp repo (separate PR), running Linux guests on Firecracker and FreeBSD, Windows, and Plan 9 guests on QEMU. No testing has been done on macOS yet, but this is based on code that was originally developed and tested on the macOS guestlet/hostlet, so it probably still works there; that's not the goal today. Updates tailscale/corp#39994 Updates tailscale/corp#51705 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com> Change-Id: Ic3bb10b567c562fdbf33facd988687bb4e3f5aca
bradfitz
force-pushed
the
bradfitz/guestnet_linux
branch
from
November 20, 2026 14:48
11b299a to
c23ffcb
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
CI guest VMs on Linux hosts (Firecracker and QEMU) and macOS hosts
currently get their networking from the host's own network stack:
per-slot bridges with iptables NAT and DNAT rules on Linux, and pf rules
on macOS. guestnet does it all in Go instead, the same way on every
platform. That makes our platforms more consistent, removes the need to
manage iptables and pf rules at all, and lets the guest networking code
be shared across platforms. It also gives us more options for how to run
hostlets in the future: a guest that needs no host network configuration
is much easier to run in, say, a Kubernetes pod on EKS, or under a VMM
other than Tart on macOS.
A guest's virtual NIC hands us raw Ethernet frames and they all
terminate in a gVisor netstack owned by the guest's Net, so a guest can
only reach what we connect it to, and can't see other guests:
addresses are on our NIC, so gVisor answers ARP and ICMP for them,
and the guest needs no route or DNS changes to reach them. ARP for
any other address is dropped: the NIC is promiscuous, and answering
the guest's DHCP duplicate-address probe makes it decline its lease.
in every slot, so a VM memory snapshot restores anywhere.
registered Service (a guest-facing server, or a forward to a
host-side address), to DNS (any port 53) or NTP (any port 123)
interception, or to egress dialed from the host, subject to a deny
list. Every flow and DNS query is logged.
route to it.
Frames arrive over one of two links:
VZFileHandleNetworkDeviceAttachment and QEMU's "-netdev dgram".
Firecracker that only open a TAP by name. The TAP has no addresses
and is on no bridge; an AF_PACKET socket reads and writes its
frames. It uses PACKET_VNET_HDR because Firecracker enables
checksum and segmentation offloads, so guest frames can carry a
partial checksum, which TAPLink completes, or be one large TCP
segment, which gVisor takes whole.
Egress UDP behaves like a typical home router, an "easy NAT" for NAT
traversal: each guest source address gets one host socket that all its
flows share, so it keeps one host address and port whatever the
destination (endpoint-independent mapping, RFC 4787), and datagrams
reach the guest only from remotes it has sent to (address- and
port-dependent filtering).
Egress is dialed from the host, so DenyLocal extends a deny list with
the host's own interface addresses, keeping guests away from host
listeners on non-loopback addresses.
guestnettest provides a fake guest stack for tests of code built on it.
Tested with a modified ciguestlet in the corp repo (separate PR),
running Linux guests on Firecracker and FreeBSD, Windows, and Plan 9
guests on QEMU. No testing has been done on macOS yet, but this is based
on code that was originally developed and tested on the macOS
guestlet/hostlet, so it probably still works there; that's not the goal
today.
Updates tailscale/corp#39994
Updates tailscale/corp#51705