Skip to content

This page may contain unreviewed machine generated text. Use with care.

Pages

A site behind each node

Carrying traffic between the LANs behind 2 nodes: the announcements, forwarding, routes back and a check.

This page carries traffic between 2 sites, the LAN behind node A, example/alpha, and the LAN behind node B, example/bravo. It starts from the 2 NixOS hosts in quick start, with cap.table, that hold a session and announce their own addresses, 203.0.113.10 and 203.0.113.11. Both read the trust document for 2 nodes. Site A is 198.51.100.0/25 on A's link lan0, where A holds 198.51.100.1, and site B is 198.51.100.128/25 on B's lan0, where B holds 198.51.100.129. Both lie outside the overlay, 203.0.113.0/24. A site inside the overlay also takes the exemption a gateway's site shows.

Announcing each site

Each node adds its site's prefix to cap.route.announce, beside its own address. On node A:

[cap.route]
announce = ["203.0.113.10/32", "198.51.100.0/25"]

Node B announces 203.0.113.11/32 and 198.51.100.128/25. Each node then holds the other's site in its kernel table as a route out of the tun, and its own site as a throw, which hands a lookup toward its own LAN on to the rules after it, as what it installs gives.

Forwarding on each node

A packet the mesh carries to a site ends at that site's node, which writes it to its tun, and the host forwards it to the LAN by its own routes, as what a node announces gives. Each node therefore forwards IPv4 between its links, a setting the daemon never writes:

sudo sysctl -w net.ipv4.ip_forward=1

On NixOS:

boot.kernel.sysctl."net.ipv4.ip_forward" = 1;

ip-sysctl describes the setting. The host's own firewall and its reverse path filtering see each forwarded packet as well, and the daemon leaves both as they are, as forwarded traffic describes.

Routing back through each node

A host of site A reaches site B through node A, and a host of site B answers through node B. Where the node is its LAN's default router this holds already. Elsewhere the LAN's router takes a route to the other site through the node, such as 198.51.100.128/25 via 198.51.100.1 at site A.

On the node, a packet from its LAN toward the other site meets the policy rules the reconciler writes: main's routes longer than /0 at 5410, then the mesh's table at 5420, which holds the other site's prefix out of the tun, as policy rules on Linux list. A route of main longer than /0 that covers the other site takes the packet first. The packet enters the mesh from a source inside a prefix this node announces, which the entry chain passes and the forwarding decision takes as this node's own.

A site whose LAN cannot route the other site through its node can have the node translate the sources of the flows the mesh brings in instead, with cap.egress advertising the site in place of cap.route, as exit nodes and subnet routers describes.

Checking it

On node A, list the routes and follow a packet from a host of site A to a host of site B as it arrives on lan0. On node B, follow the same packet as it arrives through A's session:

sudo ranet3 routes
sudo ranet3 debug route 198.51.100.10 198.51.100.130 --iif lan0
sudo ranet3 debug route 198.51.100.10 198.51.100.130 --peer example/alpha

routes lists 198.51.100.128/25 once B's announcement arrives. On A, debug route follows the packet through the kernel's lookup into the tun and through the mesh's checks of what it reads off the tun. On B it follows the packet through the mesh's decision and the kernel's lookup out of lan0. On either node it names forwarding off or reverse path filtering where the kernel refuses the packet for either. It sends no packet and reads no nftables chain, as debugging describes, so the host's firewall stays out of its answer. The reply follows the same way with the 2 addresses swapped, with --iif lan0 on B and --peer example/bravo on A.

Then, from the host of site A:

ping -c 3 198.51.100.130

The echo and its reply cross both nodes' forwarding, firewalls and LAN routes as well as the mesh, so a reply shows the whole path in place.