Plan: multi-tunnel WireGuard mesh
Spread traffic between two hosts over N WireGuard tunnels instead of one. Each flow uses one tunnel, so many flows together can use the full 50 Gbit/s bond.
Why
All traffic between two hosts goes through one WireGuard interface, wg0. One tunnel stops at about 10 Gbit/s, because WireGuard does some per-peer work on one CPU. The bond under it carries 50 Gbit/s.
Tests with temporary interfaces showed that 16 parallel tunnels with distinct ports carry 45 to 49 Gbit/s. This plan uses that design for real traffic.
Goal and limits
- Goal: traffic between two hosts can use both links and many CPUs. The target is more than 30 Gbit/s between two hosts with many flows.
- No change until all hosts are ready: until every host in the region supports tunnels, hosts work as they do today.
- No packet reordering: all packets of one flow use the same tunnel.
- Not a goal: one flow stays at about 10 Gbit/s. One flow cannot use more than one tunnel without reordering. Clients that need more speed must open parallel connections.
What the plan changes
- Tunnel interfaces next to wg0. Each host gets
wg1towgN. They use the same private key and MTU as wg0, and each has its own UDP port. wg0 does not change. - Mesh traffic selects a tunnel for each flow. The eBPF function that adds the outer mesh header also selects the tunnel:
i = inner flow hash % N. It then sends the packet directly towg i. - Host-to-host traffic uses a multipath route. The route to each peer host lists all tunnels, and the kernel selects one by the TCP or UDP flow.
- An explicit port plan. Atlas computes the tunnel ports of each host and sends them to Metal. Each host has its own pattern, so the bond spreads the tunnels over both links.
- One setting controls it. Atlas Settings has a tunnel count, default 16. Atlas sends the tunnel ports only after every host in the region has its tunnels and an upgraded metald. Metal uses the tunnels only when every peer has the same count. Set 0 to go back to wg0.
Scenarios
Each scenario shows the path today and the path with the plan. Green boxes are new or changed.
1. VM to VM on another host changed
Today, the VM hook adds an outer IPv6 header, and Linux routes the packet to wg0. With the plan, the VM hook selects a tunnel from the inner flow and sends the packet to it.
Example. A VM opens two TCP connections to a VM on another host. The first connection hashes to tunnel 3, and the second to tunnel 11. Each connection stays on its tunnel. The two connections use different CPUs and can use different links.
2. Host to a VM on another host, such as object storage changed
A host reaches a VM through the mesh-host veth pair. The host hook adds the outer header with the same function as the VM hook. The VM can only reply to a host, and the VM hook sends the reply with the same function. So both directions select a tunnel, with no extra work.
Limits. One connection stays at about 10 Gbit/s. Object storage clients use parallel connections for multipart uploads and ranged reads, and those connections spread. The storage VM's own network device can be a lower limit than WireGuard. We measure it before we expect more.
3. Host to host changed
Plain host traffic between host WireGuard addresses has no mesh header and does not pass an eBPF hook. Today, the route to each peer host points at wg0. With the plan, the route has one next hop for each tunnel. The kernel hashes the TCP or UDP flow to select one.
The route uses a link-local gateway with onlink, because a WireGuard interface has no real next hop:
ip -6 route replace fdab:…:b/128 \
nexthop via fe80::1 dev wg0 onlink \
nexthop via fe80::1 dev wg1 onlink \
…
sysctl net.ipv6.fib_multipath_hash_policy=1 # hash on the TCP/UDP flow
This path does not depend on eBPF, so host-to-host traffic keeps working when the hooks are detached. Today little bulk traffic uses it, because migration uses the private network with TLS by default. It matters when migration over WireGuard is on, or when new host-to-host transfers use WireGuard.
4. Paths that do not change same
| Traffic | Path | Why it stays |
|---|---|---|
| VM to VM on the same host | Linux local route | No WireGuard on this path. |
| Atlas controller to and from hosts | wg0 | The controller is a peer of wg0 only. Its traffic is small. |
| Migration (default) | private IPv4 with TLS | It already skips WireGuard. |
NOT_HERE replies | the tunnel that received the packet | The reply goes back on packet->ifindex. |
| NDP lookup of an unknown VM | private uplink | It does not use WireGuard. |
5. Tunnel count is not the same on both hosts blocked
Host A has 16 tunnels, and host B has only wg0. If host A sent a flow to wg7, host B would have no wg7 peer, and WireGuard would drop the packet. So Metal fills the tunnel map only when every peer has the same count. Until then, all traffic uses wg0. Atlas sends tunnel ports only after every host reports that its tunnels are ready.
The port plan
The bond selects a link from a hash of the IP addresses and the UDP ports. The hash combines the two ports with XOR. If a tunnel uses the same port on both hosts, the ports cancel out, and all tunnels between two hosts get the same link. The first test showed this: 5 tunnels gave 24.5 Gbit/s on one link.
Illustrative ports. Tunnels 1 and 2 have equal ports, so they take the link that the IP addresses select. Tunnels 0 and 3 differ in the link bit, so they take the other link. The rule below decides which tunnels differ.
A fixed port list on every host has the same problem. If every host uses 51840 + N for tunnel N, tunnel N always has equal ports on both ends. So each host needs its own port pattern.
port(host, N) = base + 4·N + 2·bit(host, N)
bit(host, N) = bit N of a hash of the host's WireGuard public key
The 4·N part gives each tunnel its own port. The 2·bit part changes one bit that the bond hash uses to select the link. Two hosts have different bits for about half of the tunnels, so about half of the tunnels use each link.
Atlas computes the ports and sends them to Metal as data. A unit test applies the kernel bond hash to every host pair and checks that each pair uses both links. On the receive side, the switch selects the link with its own hash. More tunnels make that choice more even.
Alternatives we did not choose
| Option | Why not |
|---|---|
| Linux multipath routes for VM traffic | Possible with an onlink gateway, as in scenario 3. But VM packets carry the outer mesh header, so the kernel hash sees no inner ports. That needs a custom hash policy that we have not verified for IPv6-in-IPv6. The eBPF hook already has the inner flow hash. |
| Host-to-host traffic through the eBPF hook | Host connectivity would then depend on attached hooks. The multipath route works without them. |
| One tunnel with more tuning | Tested: CPU power states, RPS, NAPI budget, real-time NAPI threads, BBR and skb_defer_max. None removed the per-peer limit. |
| wireguard-go | Tested: 7.7 to 8.0 Gbit/s, slower than kernel WireGuard. |
| One port list on every host | Each tunnel then has equal ports on both ends, and the bond puts all tunnels on one link. |
Risks
- Mixed tunnel counts drop traffic. Scenario 5 blocks this: Metal and Atlas turn on tunnels only when all hosts match.
- A WireGuard restart detaches eBPF hooks. This is true for wg0 today, and it is true for every tunnel interface. The attach code must cover all of them.
- The redirect skips the host FORWARD chain. This is safe: the VM firewall runs in the VM namespace before the hook, and the host firewall covers only INPUT.
- The multipath hash setting is host-wide.
fib_multipath_hash_policy=1applies to every IPv6 multipath route on the host. Today the host has no other IPv6 multipath routes. - More peer entries. 16 interfaces with about 100 peers each give about 1,600 peer entries for each host. Keepalives cost about 64 packets per second.
- Interfaces without an address. We expect wg1 to wgN to work without an IPv6 address. We check this in development first.
- Link balance is statistical. The port plan balances the send side. The switch balances the receive side.
Rollout
- Ship. Release WG Mesh, Metal and Atlas together. Hosts work as before until all of them are ready.
- Development. Enable 16 tunnels on three test hosts. Check each scenario: VM to VM, host to VM, host to host, NDP lookup,
NOT_HERErecovery, VM migration and gateway traffic. - Staging. Upgrade metald and configure WireGuard on all hosts, so tunnels turn on. Run iperf between VMs and from hosts to VMs on different hosts with many flows.
- Production, one region at a time. Upgrade Atlas, then upgrade metald and configure WireGuard on each host. Tunnels turn on when the last host is ready.
- Rollback. Set the count to 0. Metal empties the tunnel map and puts back the single-path routes, so traffic uses wg0 again. No restart is necessary.
How we check success
| Check | Pass |
|---|---|
| VM to VM on two hosts, 64 TCP flows | > 30 Gbit/s each way |
| Host to object storage VM on another host, 16 connections | above 10 Gbit/s, or a measured VM device limit |
| Bytes on each bond link during a test | both links carry traffic, split better than 70 / 30 |
| Bytes on each wgN interface | every tunnel carries traffic |
| One flow | about the same as today, no reordering |
| Count set to 0 | traffic returns to wg0 with no connection loss |
| Port plan unit test | every host pair uses both links |
Decisions
| Question | Decision |
|---|---|
| Tunnel count | A setting in Atlas Settings, default 16, the same on every host in the region. |
| Keys | The same private key on all tunnel interfaces. Atlas keeps one public key for each host. |
| Enablement | Region-wide, automatically, after every host is upgraded. No fallback for each peer. |
| Host-to-host route | Ship it in the first release. |