Skip to content

parker-sites: use the broker pgw, guard against flip-back after a switch - #69

Merged
awlx merged 2 commits into
parker-release-2026.11from
awlx-parker-switch-guard
Nov 22, 2026
Merged

awlx merged 2 commits into
parker-release-2026.11from
awlx-parker-switch-guard

Conversation

@awlx

@awlx awlx commented Nov 22, 2026 •

Copy link
Copy Markdown
Member

Summary

This change removes the node-side pgw pin. The node now uses the pgw that the config service (broker) sends. The broker is the only authority for pgw selection, rebalancing and drain.

Thank you to the community members who reported the VIE tunnel flapping after the parker7 update.

Changes

  • parker-sites.lua: remove pin() and the /tmp/parker-sites/pgw.<site> override. nodeconfig.sh does not call parker-sites.lua pin anymore.
  • After a pgw switch, the node sends the switch report (GET /api/v3/switch?pubkey&site&pgw) again until the broker confirms it:
    • 200 with the same pgw: confirmed.
    • 409 or 500 or no answer: retry with backoff 3, 6, 12 ... 60 s.
    • Other 4xx: stop.
    • Stop after 1800 s.
  • New guard (parker/switchguard.lua, parker-sites.lua guard): while a switch is not confirmed, or is younger than 300 s, the node does not apply a fetched config that moves the site back to the pgw that it left. In all other cases the node applies the broker answer.
  • parker-sites.lua writes the switch record to /tmp/parker-sites/switch.<site>. A reboot removes it, so after a reboot the node uses the broker pgw.
  • A probe that fails with a local send error (sendto) does not count as a miss for up to 60 s. This prevents pgw rotation during a short local firewall or route change.
  • The status line shows senderrs, report and guard.
  • README: new section "Switch report".
  • Second commit: the IPv6 default routes of parker-sites (main table, table 23 and the per-site tables) now go via the link-local address of the current pgw of the site. Before, they were device-only (default dev wg_cX). wg_cX is NOARP, so a route without a gateway makes each destination its own next hop. The node then added one neighbour entry per destination. On a live node with 97 clients we saw 325 such entries on one tunnel; the kernel limit (gc_thresh3) is 1024. The route follows the pgw on each switch, broker change and failover. The IPv4 default already used via 10.0.0.1 and does not change.

Broker side: freifunkMUC/wgkex adds a hold for reported switches (default 900 s) and the pgw field in the 200 answer. The node also works with the old broker: a 200 without pgw counts as confirmed, and the guard ends after 300 s.

Known limits

  • A site with 2 pgws: if the broker drains the new pgw during the 300 s node hold, the broker names the pgw that the node left. The node follows only after the hold ends (max 300 s).
  • ifup wan causes real probe misses (not send errors). The node switches the pgw once per site. It reports the switch and stays stable. This change does not damp that single switch.

Tests

Route fix (second commit)

Unit tests: tests/switch-guard-test.lua has 4 new checks for the next hop (current pgw, no state, unknown pgw, no address6). 55 checks pass (luajit and lua 5.5). luacheck on the changed files: 0 warnings / 0 errors.

Lab: armsr-armv8 VM u1, live broker and live pgws, light probe traffic only. Image v2026.11.1-parker7+cp6f36d3f-lab, compared with +cp61504cb-lab (the first commit only). Each test includes real internet pings from a client: IPv4 to anycast.ffmuc.net, 1.1.1.1 and 9.9.9.9, and IPv6 to anycast.ffmuc.net, 2606:4700:4700::1111, 2620:fe::fe and www.google.com, from the source address of each site.

Test Before (cp61504cb) After (cp6f36d3f)
RT-0/1 neighbour entries after traffic to many destinations wg_c1: 1003 (500 IPv6 + 500 NAT64). wg_c3: 301 (300 from the VIE prefix) wg_c1: 1, wg_c3: 1 (200 IPv6 + 200 NAT64 + 200 from the VIE prefix, rate limit 50/s)
RT-1 routes default dev wg_cX main, table 23, tables 101/102: default via fe80::<pgw> dev wg_cX
RT-2 failover (drop the replies of pgw04 on wg_c3) - Switch to pgw03 after 4 s. Table 102 moves to pgw03. Report confirmed after 3 s. IPv6 pings from the VIE prefix: 118/120 (1.5 s gap). IPv4: 120/120.
RT-3 hold and drain (lab broker) - No flip-back on 3 polls. Drain of pgw03: the node moves to pgw04 at the next poll and the route follows. Pings: 299/300 (1.0 s gap).
RT-4 reboot - No switch record. The routes use the broker pgws. 1 neighbour entry per tunnel. Pings 0 % loss.
RT-5 multi-site source routing - Each site prefix goes out through its own tunnel through the pgw of that site (ip route get, traceroute). NAT64 and DNS64 work for both sites.
RT-6 other route users - noderoute keeps its route (8 cycles, no delete). parker-ra-goodbye, ipv6-ra-filter and has_default_gw6 read only default dev br-client and are not affected.

Real internet pings before and after the fix: 0 % loss, except the short gaps during the switch shown above.

Switch report and guard (first commit)

Unit tests (luajit, LUA_PATH="luasrc/usr/share/lua/?.lua;;"):

  • luajit tests/switch-guard-test.lua: 51 checks pass (guard decide keep/match/expire, backoff, report result parsing for uclient-fetch and busybox, send-error skip).
  • All other tests/*.lua pass.
  • luacheck -q luasrc tests: 0 warnings / 0 errors.

Lab (armsr-armv8 VM, image v2026.11.1-parker7+cp61504cb-lab, a lab fake broker that proxies /config from the live broker, overrides the pgw and implements /api/v3/switch):

Test Result
SG-1 failover: drop replies from pgw04 on wg_c3 Switch to pgw03 after 3 s (3 misses).
SG-1 send error: drop outgoing probes Switch after 60 s (send-error skip).
SG-2 report: broker answers 409, 409, 200 Retries after 3 s and 6 s, then confirmed.
SG-3 broker still names the left pgw (no broker hold) Node keeps the new pgw on 3 polls, logs "keep pgw", follows the broker after 300 s.
SG-3b broker hold 900 s No flip-back on 4 polls after the node hold.
SG-4 broker drains a pgw (no switch record) Node applies the new pgw on the next poll.
SG-5 reboot No switch record, guard off, node uses the broker pgws.
SG-6 firewall reload No send errors, no switch.
SG-6 ifup wan + wan6 1 switch per site, reports confirmed, then stable.

Not tested:

  • No test on live nodes or with the live broker /api/v3/switch. The lab used a fake broker.
  • No test with the wgkex branch broker.
  • Route fix: no test on live nodes. The neighbour count on Unterkunft Garching was only read, not changed.
  • Only the armsr-armv8 target was built.

Remove the node-side pgw pin. The config service selects the pgw of
each site. After a failover switch, report the switch again with
backoff (3 s doubling, max 60 s) until the config service confirms it
(2xx, optional "pgw" in the answer). 4xx other than 409 stops the
report.

While the switch is unconfirmed (max 1800 s) or younger than 300 s, a
fetched config that names the left pgw gets the new pgw. A config that
names another pgw is applied.

A probe that the node cannot send (sendto error, for example during a
firewall reload) is not counted for max 60 s.
@awlx awlx closed this Nov 22, 2026
@awlx awlx reopened this Nov 22, 2026
wg_cX is NOARP. A default route without a gateway makes each
destination its own next hop, so the node adds one neighbour entry per
destination (hundreds on busy nodes, close to gc_thresh3).

Set the IPv6 default routes in the main table, table 23 and the per-site
tables via the address6 of the current pgw of the site. apply() runs on
a pgw change, so the next hop follows the switch.
@awlx
awlx merged commit d72b4a9 into parker-release-2026.11 Nov 22, 2026
9 checks passed
@awlx
awlx deleted the awlx-parker-switch-guard branch November 22, 2026 21:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant