WG Mesh

How an Atlas VM packet finds its host

eBPF, WireGuard, and NDP inside one region

One address per VM

The address fdaa:1:0:2::3 written in full as fdaa:0001:0000:0002:0000:0000:0000:0003. Braces mark the fdaa prefix, the 16-bit region 1, the 32-bit tenant 2, and the 64-bit VM ID 3. The hooks compare the tenant field.

A VM address names the VM, not the host

  • Atlas picks a host when it creates a VM
  • A migration keeps the address and changes the host
  • Every other host must still find the VM before it can send to it

WG Mesh does not keep a central map. A host that does not know asks the network, and the owner answers.

Four steps, each built on the last

  1. Normal VMs: find a host, tunnel, repair after a move, keep tenants apart
  2. Privileged VMs: tenant-0 services that may reach every tenant
  3. Gateway VMs: carry traffic for addresses outside the mesh
  4. IPv6 router: a gateway VM that gives each VM a public IPv6 address
1 · Normal VMs

Three layers, one packet

Two hosts. VM A on host 1 sends to VM B on host 2. The VM hook adds an outer IPv6 header for host 2, WireGuard encrypts it and sends it as UDP over the provider private network, and host 2 decrypts and unwraps it for VM B. The packet strip shows the headers at each step.

Watch the packet strip. An orange cell is the header that the last step added.

1 · Normal VMs

Four hooks, one set of maps

One host runs four tc eBPF hooks that share pinned maps: the VM hook on each VM interface, the WireGuard hook on wg0, the uplink hook on the private uplink to other hosts, and the public hook on the public interface to the provider router.

tc eBPF programs from one object. No daemon. The atlas-wg-mesh CLI loads them and writes the maps.

1 · Normal VMs

The maps a normal VM uses

Map Holds Written by
local_vms VM address → local interface vm sync
remote_vms VM address → host fdab address · LRU, 262,144 entries uplink hook, from NDP
peer_list peer IPv4, MAC, fdab address peers sync
discovery_limits lookup tokens per VM interface VM hook

No timers. A remote_vms entry lives until LRU eviction or a valid NOT_HERE.

1 · Normal VMs

The VM hook, in order

  1. Drop anything sent to fdab::/16
  2. Drop a source address that the VM does not own
  3. Drop another tenant
  4. Same host: let Linux deliver
  5. Known remote host: tunnel through WireGuard
  6. Unknown host: turn the packet into an NDP lookup

Privileged and gateway VMs add rules later. This order stays.

1 · Normal VMs

Same host: Linux delivers

VM A and VM C of tenant 2 run on host 1. The VM hook checks the packet, sees that VM C is local, and lets Linux deliver it through the host route. No tunnel and no WireGuard.

The packet does not change. In a test this path moved 14.3 Gbit/s.

1 · Normal VMs

Known host: check and wrap

VM A sends to VM B. The VM hook on host 1 checks the packet, finds VM B at fdab::2 in remote_vms, and adds an outer IPv6 header for host 2.

Next header 41 means IPv6 inside IPv6. The outer addresses are the two hosts.

1 · Normal VMs

Known host: WireGuard carries it

WireGuard on host 1 encrypts the tunnel packet and sends it as UDP over the private network to host 2.

Metal applies the WireGuard peers and keys. WG Mesh only picks the host.

1 · Normal VMs

Known host: unwrap and deliver

Host 2 decrypts the packet. Its WireGuard hook finds VM B in local_vms, removes the outer header, and Linux delivers the packet to VM B.

The receiving host checks the tenant again. VM B sees the packet exactly as VM A sent it.

1 · Normal VMs

First contact: the packet becomes a question

Host 1 has no location for VM B. The VM hook replaces the packet with a neighbor solicitation that asks who has fdaa:1:0:2::7, and sends it on the private uplink. The data is lost.

Each VM interface may start 10 lookups a second, with a burst of 50.

1 · Normal VMs

First contact: the owner answers

Host 2 has a proxy NDP entry for VM B, so Linux answers at once with host 2 uplink MAC.

configure sets proxy_delay to 0. Linux would otherwise wait up to 0.8 s.

1 · Normal VMs

First contact: remember the answer

The uplink hook on host 1 maps the answering MAC to host 2 through peer_list and stores VM B at fdab::2 in remote_vms. The retry goes through WireGuard.

One packet is lost. In a test, a new VM was reachable about 5 ms after vm sync.

1 · Normal VMs

No multicast? Send a copy to each peer

In unicast mode the uplink egress hook on host 1 wraps the neighbor solicitation in IPv4 protocol 41 and sends one copy to each peer. The ingress hook on each peer accepts it only from a peer address and unwraps it.

peers sync --unicast attaches the egress hook. Only discovery changes, not throughput.

1 · Normal VMs

VM moved: the sender still points at host 2

VM B moved from host 2 to host 3. Host 1 missed the announcement and still tunnels to host 2 at fdab::2.

The new host sent an unsolicited advertisement. Most hosts updated at once. Host 1 missed it.

1 · Normal VMs

VM moved: host 2 says NOT_HERE

VM B is not in host 2 local_vms, so host 2 replies NOT_HERE with next header 253 and the VM address. Host 1 checks that the reply came from the stored host and deletes the entry.

Only the host stored in remote_vms can clear an entry. Another host cannot erase a good one.

1 · Normal VMs

VM moved: ask again

Host 1 sends a new lookup on the uplink. Host 3 answers, and host 1 stores VM B at fdab::3.

In a test, 15 moves took 1.5 ms to 10.5 ms, within one 10 ms ping.

1 · Normal VMs

Tenants stay apart

VM A of tenant 2 sends to VM V of tenant abcd on the same host. The VM hook compares the tenant fields, finds that neither side is privileged, and drops the packet.

The orange parts of the addresses are the tenant fields that the hook compares.

2 · Privileged VMs

Privileged VMs

Tenant-0 services that serve every tenant

2 · Privileged VMs

What makes a VM privileged

  • It is a tenant 0 VM, and Atlas lists it in privileged_vms during host sync
  • The tenant rule passes when either side is privileged
  • So a tenant VM can reply to a privileged VM
  • Examples: HTTP proxy, Cargo, IPv6 router

Only Atlas can grant privilege, and only to tenant-0 VMs.

2 · Privileged VMs

A privileged VM crosses tenants

The HTTP proxy is a privileged tenant-0 VM. It reaches VM A of tenant 2 and VM V of tenant abcd, and VM V can reply to it. VM A cannot reach VM V, because neither of them is privileged.

Rule 3 becomes: drop another tenant, unless one side is privileged.

3 · Gateway VMs

Gateway VMs

Traffic for addresses outside the mesh

3 · Gateway VMs

A gateway VM needs two flags

Flag Effect in WG Mesh
Privileged In privileged_vms: passes the tenant rule
Network gateway In gateways: may send a source outside the mesh, and receives gateway tunnels

The gateway's own software forwards, translates, and filters. The mesh carries packets and checks two rules.

3 · Gateway VMs

A gateway route works both ways

VM V:   2000::/3  via  fdaa:1::56      the gateway VM
  • Out: V's packets to that prefix go to the gateway
  • In: an outside source reaches V only if V has a route back to it
  • The key is V's address + the destination, so one trie holds a table per VM

vm sync --route 2000::/3=fdaa:1::56 writes it into gateway_routes.

3 · Gateway VMs

The VM hook, with gateway rules

  1. Drop anything sent to fdab::/16
  2. Outside destination: check the source, then send to the gateway route
  3. Drop a source that the VM does not own. An outside source only from a gateway.
  4. Drop another tenant, unless one side is privileged
  5. Same host: let Linux deliver. An outside source needs a route back.
  6. Known remote host: tunnel through WireGuard
  7. Unknown host: turn the packet into an NDP lookup
3 · Gateway VMs

Out: the VM hook picks the gateway

VM V on host 1 sends to an outside address. Its VM hook finds the longest matching gateway route, 2000::/3 via the gateway VM, and sends a tunnel with next header 254 and the gateway address to host 2.

Next header 254 puts the gateway address first. The destination is outside the mesh, and one host can run several gateways.

3 · Gateway VMs

Out: host 2 hands it to the named gateway

Host 2 reads the gateway address from the tunnel, checks that the gateway is local and a gateway interface, and delivers the packet to it. The gateway software forwards it outside.

If the gateway is not on host 2, host 2 replies NOT_HERE for the gateway address.

3 · Gateway VMs

In: only a gateway may send an outside source

The gateway VM sends a packet with an outside source to VM V. Its VM hook allows the outside source only because the interface is a gateway, and tunnels it to host 1 with next header 41.

A normal VM that sends a source it does not own is dropped at rule 3.

3 · Gateway VMs

In: the route back is the guard

The WireGuard hook on host 1 checks that VM V has a gateway route back to the outside source, 2000::/3 via the gateway, and delivers the packet. Without that route it drops the packet.

No route back, no delivery. So a VM receives outside traffic only through a gateway that it replies through.

3 · Gateway VMs

The gateway tunnel fits the MTU

outer IPv6   fdab::1 → fdab::2, next header 254          40 bytes
gateway      fdaa:1::56                                  16 bytes
VM packet    fdaa:1:0:abcd::5 → 2001:db8:ffff::10     ≤ 1380 bytes
                                                      ≤ 1436 bytes
wg0 MTU                                                 1440 bytes
4 · IPv6 router

The IPv6 router

A gateway VM for public IPv6

4 · IPv6 router

Why a router VM

  • Some providers attach a whole IPv6 block to one host
  • A VM that moves to another host cannot take the block with it
  • So the block stays on a router VM, and each VM gets a derived /128
  • The VM keeps its mesh and public addresses when it moves. WG Mesh finds its new host.

The router is a privileged, network gateway VM. Everything from part 3 applies.

4 · IPv6 router

The address bits carry the mapping

The public address 2001:db8:1:2:3:a:bcd0:5 written in full above the mesh address fdaa:1:0:abcd::5. Braces mark the router block /80, a reserved zero, a 24-bit tenant, and a 20-bit VM in the public address, and the fdaa prefix, region, 32-bit tenant, and 64-bit VM ID in the mesh address. Arrows join the tenant fields and the VM fields.

No table and no connection state. A tenant of 2^24 or more, or a VM of 2^20 or more, gets no public address.

4 · IPv6 router

In: the public packet reaches the router

A client sends to the public address 2001:db8:1:2:3:a:bcd0:5. The provider router sends it to host 2, whose public hook answers NDP for the owned prefix, and Linux routes it to the IPv6 router VM.

New in this part: the public hook and owned_prefixes.

4 · IPv6 router

In: the router changes only the destination

The router changes only the destination to the mesh address of VM V and keeps the client source. From here it is the gateway inbound path: the VM hook tunnels it to host 1, and the WireGuard hook checks the return route before it delivers.

Steps 5 and 6 are the gateway inbound path. VM V sees the real client address.

4 · IPv6 router

Out: the reply gets its public source back

VM V replies to the client. The reply takes the gateway outbound path to the router, and the router changes the source from the mesh address to the public address 2001:db8:1:2:3:a:bcd0:5.

Steps 1 to 3 are the gateway outbound path. Step 4 is the router's own translation.

4 · IPv6 router

The router moved: the old host forwards

The router moved from host 2 to host 3. The provider still sends to host 2, whose public hook finds the prefix in moved_prefixes and tunnels the packet to host 3. Host 3 turns it into an unsolicited neighbor advertisement with the override flag, and the provider learns host 3 MAC.

The provider caches host 2's MAC and does not ask again. So host 3 tells it, once a second at most.

4 · IPv6 router

The router moved: the provider learns

The provider now sends the public address straight to host 3, and Linux routes it to the router VM.

The old host forwards for 5 minutes. The first packet can be lost.

Who owns what

Part Owns Does not own
Atlas app VM addresses, host peers and keys, privileged VMs, gateway routes Where a VM runs
Metal WireGuard peers on the host, VM namespace and links, calls to atlas-wg-mesh Packet decisions
WG Mesh Per-packet decisions and learned locations Keys, peers, NAT, DNS, DHCP, guest firewalls
Gateway VM Address translation, forwarding, firewall policy Mesh delivery, the return-route check

Look at a host

atlas-wg-mesh status                        # interfaces, NDP mode, map counts
atlas-wg-mesh inspect fdaa:1:10:20::5       # local, learned host, or unknown
atlas-wg-mesh vm list --json

atlas-wg-mesh vm sync --interface vh-100001 \
  --address fdaa:1:10:20::5 --mtu 1380      # replaces all state of one VM

Private fault? Check WireGuard peers, then the VM namespace, then local_vms and remote_vms.

Measured on two hosts

Path Throughput Average ping
Raw private network 939 Mbit/s 0.28 ms
Host-to-host WireGuard 886 Mbit/s 0.76 ms
VM to VM, two hosts 847 Mbit/s 1.75 ms
VM to VM, one host 14.3 Gbit/s 0.92 ms

Scaleway bare metal, 1 GbE, Firecracker 2 vCPU. iperf3 TCP, one stream, median of 3.

Limits

  • The first packet to a new or moved VM can be lost. Clients retry.
  • NDP trusts the private host network. It does not authenticate hosts by itself.
  • The mesh covers one region. It does not connect regions.
  • NOT_HERE (253) and the gateway tunnel (254) are Atlas formats, not standards.

Read more

WG Mesh design · How VMs reach each other · Gateway VMs · IPv6 router

vm.h · wireguard.h · uplink.h · maps.h

frappe/atlas · all addresses are examples