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.

Status: agreed, not built. Measurements: WireGuard multi-tunnel throughput.

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

What the plan changes

  1. Tunnel interfaces next to wg0. Each host gets wg1 to wgN. They use the same private key and MTU as wg0, and each has its own UDP port. wg0 does not change.
  2. 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 to wg i.
  3. 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.
  4. 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.
  5. 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.

Host AHost B Today VM VM hook: add outer header Linux route to wg0 wg0 wg0 VM one tunnel for all flows: about 10 Gbit/s Plan VM VM hook: outer header, select i wg i wg i VM i = flow hash % N

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.

Request: Host A to storage VM on Host B host process mesh-host veth host hook: header, select i wg i wg i storage VM Reply: storage VM on Host B to Host A storage VM VM hook: reply, header, select i wg i wg i host process same function The two directions can use different tunnels. Each direction keeps its order.

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.

Host AHost B Today host process route: peer address dev wg0 wg0 wg0 host process Plan host process multipath route: wg0 … wgN wg i wg i host process 5-tuple hash On Host B, the WireGuard hook passes non-mesh packets to Linux.

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

TrafficPathWhy it stays
VM to VM on the same hostLinux local routeNo WireGuard on this path.
Atlas controller to and from hostswg0The controller is a peer of wg0 only. Its traffic is small.
Migration (default)private IPv4 with TLSIt already skips WireGuard.
NOT_HERE repliesthe tunnel that received the packetThe reply goes back on packet->ifindex.
NDP lookup of an unknown VMprivate uplinkIt 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.

Same port on both ends: the ports cancel out tunnel 0: 51900 ↔ 51900 tunnel 1: 51901 ↔ 51901 tunnel 2: 51902 ↔ 51902 tunnel 3: 51903 ↔ 51903 link 0 (25 Gbit/s) link 1 (25 Gbit/s) fullempty bond0 layer3+4 hash Distinct ports: the tunnels spread tunnel 0: 51842 ↔ 51840 tunnel 1: 51844 ↔ 51844 tunnel 2: 51850 ↔ 51850 tunnel 3: 51854 ↔ 51852 link 0 (25 Gbit/s) link 1 (25 Gbit/s)

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

OptionWhy not
Linux multipath routes for VM trafficPossible 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 hookHost connectivity would then depend on attached hooks. The multipath route works without them.
One tunnel with more tuningTested: CPU power states, RPS, NAPI budget, real-time NAPI threads, BBR and skb_defer_max. None removed the per-peer limit.
wireguard-goTested: 7.7 to 8.0 Gbit/s, slower than kernel WireGuard.
One port list on every hostEach tunnel then has equal ports on both ends, and the bond puts all tunnels on one link.

Risks

Rollout

  1. Ship. Release WG Mesh, Metal and Atlas together. Hosts work as before until all of them are ready.
  2. Development. Enable 16 tunnels on three test hosts. Check each scenario: VM to VM, host to VM, host to host, NDP lookup, NOT_HERE recovery, VM migration and gateway traffic.
  3. 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.
  4. 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.
  5. 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

CheckPass
VM to VM on two hosts, 64 TCP flows> 30 Gbit/s each way
Host to object storage VM on another host, 16 connectionsabove 10 Gbit/s, or a measured VM device limit
Bytes on each bond link during a testboth links carry traffic, split better than 70 / 30
Bytes on each wgN interfaceevery tunnel carries traffic
One flowabout the same as today, no reordering
Count set to 0traffic returns to wg0 with no connection loss
Port plan unit testevery host pair uses both links

Decisions

QuestionDecision
Tunnel countA setting in Atlas Settings, default 16, the same on every host in the region.
KeysThe same private key on all tunnel interfaces. Atlas keeps one public key for each host.
EnablementRegion-wide, automatically, after every host is upgraded. No fallback for each peer.
Host-to-host routeShip it in the first release.