Skip to content

net: require_public_ip keeps redialing with backoff; a private line falls back to the main route - #175

Merged
Cd1s merged 1 commit into
mainfrom
fix/public-ip-retry
Oct 25, 2026
Merged

Cd1s merged 1 commit into
mainfrom
fix/public-ip-retry

Conversation

@Cd1s

@Cd1s Cd1s commented Oct 25, 2026 •

Copy link
Copy Markdown
Owner

Closes #174

What

  • require_public_ip never gives up. The first four redials wait require_public_ip_gap (default 180 s), after that the wait doubles up to 15 minutes (a configured gap above 15 minutes is kept), and it stays there until the line gets a public address or the option is turned off. Only the line with the private address is redialed; a line with a public address is never touched. State stays in /run/mini-router/require-public-ip.json (a reboot starts over, a public address clears it, mr apply forgets WANs that no longer use the option). The Risk / "stopped" state is gone.
  • A private line is held out of routing. While a require_public_ip PPPoE line holds an RFC1918 / 100.64/10 / 169.254/16 address, wanHealthMap reports it down (like a failed mr-wanmon check, but without needing multiwan): its WAN table loses the default route, its main-table metric is raised, balance mode and DNS ordering skip it. Policy routes with fallback: main (default) therefore use the main route at once (the ppp-up hook does it; the once-a-minute mr wan public-check --cron re-routes any line whose routes do not match, so the worst case is one minute) and go back to the via WAN when it has a public address. fallback: drop is unchanged: still cut off.
  • mr doctor / panel. The "stopped" RISK is replaced by a WARN: has 100.64.x.y (cgnat); waiting for the ISP to release a session slot (...): redial 5 done, next in 6 min. The WAN page shows the same next to the line (public_wait in net.wan / status). One warning event when the fast phase ends.
  • Docs. docs/modules/net.md (new section "PPPoE 公网地址保护", with the AIS concurrent-limit → walled-garden background; the fallback section lists the three reasons a via WAN is unusable), SKILL.md, README, UI help text + English dictionary.
  • Lab. The ISP simulator learns what the incident needs: --cgnat-dials N [--cgnat-mac MAC] (the first N dials of a client land in a walled garden: 100.64.x, up, nothing forwarded; later dials are public), lab.sh isp-walled, --echo (an address in the ISP that answers with the source it saw: through which WAN did the request leave?), and a wire log (pppoe-watch.py: PADI/PADO/PADR/PADS/PADT and LCP terminate seen at the ISP). Scenario 07 is reworked for the new behaviour, 14-policy-fallback-walled is new.

Why

Reproduces and fixes the 2026-10-26 incident: after a reboot three of four lines got CGNAT addresses from the ISP's concurrent-session limit. The guard stopped after four redials (the line then stayed broken until someone fixed it by hand), and the devices pinned to the walled lines by policy_routes had no internet for ~50 minutes because their tables still had a default route.

Existing behaviour that stays: with multiwan the health check already removed the table's default route when pings through the line fail (scenario 14 checks this on main too); what was missing is the line that is up, has an address and is known to be useless.

Verification

Unit tests (cd mr && go test ./...): TestRequirePublicWaitSchedule, TestRequirePublicIPRedialsOnlyThePrivateWANAndNeverStops, TestPublicIPCheckHonoursBackoff, TestRequirePublicIPClockRollbackEndsCooldown, TestPublicIPGuardHoldsPrivateWANOut, TestPublicIPGuardKeepsWanmonVerdict, TestHookPPPPrivateAddressDropsWANTableDefault, TestHookPPPPrivateAddressWithoutOptionStaysRouted, TestPublicIPCheckReroutesWhenGuardStateDiffersFromRoutes, TestFallbackDropRuleUnchangedByGuard, TestDoctorRequiresPublicIPWaitingIsWarn, TestDoctorRequiresPublicIPWaitingTexts, TestDoctorIgnoresStaleRecordWhenGuardDisabled, TestDoctorCGNATHealthHint. With publicIPHeld forced to "" the hold-out tests fail.

Lab (id 8, QEMU Alpine 3.24 + install.sh of this tree):

14-policy-fallback-walled on this branch: 22/22 ok (1m20s). The same scenario against origin/main (MR_LAB_TREE=…) reproduces the incident:

not ok 6 - the walled line's table has no default route
not ok 7 - fallback main: pin-main is online within a minute, through wan
not ok 10 - mr doctor: wan2 is a warning that waits for the ISP, not a risk

(the health-check variant, checks 15-22, passes on both).

07-require-public-ip on this branch: 17/17 ok (~90 s with gap 2 s and a 4 s guest ticker). ISP side dials.log for wan2 (7 walled dials, the 8th public) and the doctor line while waiting:

dial n=1..7 walled=1 addr=100.64.8.11..17, dial n=8 walled=0 addr=203.0.113.11
t(dial 6)-t(dial 5)=4 s, t(7)-t(6)=9 s, t(8)-t(7)=15 s   (waits after redial 4/5/6 = 4/8/16 s)
WARN  wan.wan2  WAN wan2: has 100.64.8.16 (cgnat); waiting for the ISP to release a session slot (...): redial 5 done, next in 2 s

and no frame from wan's MAC at the ISP after wan2 was added. On main the same scenario shows RISK wan.wan2 ... automatic public-IP redial stopped after repeated private addresses (checks 6 and 7 fail).

sh tools/ci.sh (this tree): ALL CHECKS PASSED.

Not in this PR: whether the PPPoE sessions are ended (PADT) at reboot — tracked separately.

🤖 Generated with Claude Code

…te line out of routing (Closes #174)

A PPPoE line behind a walled garden (AIS: a session over the concurrent limit gets 100.64/10, is up and
carries nothing until the old sessions time out) used to stop the automatic redial after four tries, and
policy routes kept sending their devices into it.

- require_public_ip never gives up: the first four redials wait require_public_ip_gap (180 s), then the wait
  doubles up to 15 minutes (a longer configured gap is kept). Only the line with the private address is
  redialed. State stays in /run (a reboot starts over; a public address clears it).
- While a require_public_ip line holds a private / CGNAT address it counts as down for routing: wanHealthMap
  reports it down, so the WAN table loses its default route, the main metric is raised, balance and DNS skip it.
  Policy routes with fallback: main use the main route at once (ppp-up hook) and go back when a public address
  arrives; fallback: drop stays cut off. The once-a-minute check re-routes a line whose routes do not match.
- mr doctor: warn "waiting for the ISP to release a session slot ... redial N done, next in X min" instead of the
  "stopped" risk; the WAN page shows the same; one warning event when the fast phase ends.
- Lab: the ISP simulator gets --cgnat-dials N (walled garden for the first N dials of a client MAC), isp-walled,
  --echo (which WAN did the request leave through), and a wire log (PADI/PADT/LCP terminate seen at the ISP).
  Scenario 07 (two lines, backoff, public line untouched, doctor text) and the new 14 (fallback main/drop, health
  check variant).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@Cd1s
Cd1s force-pushed the fix/public-ip-retry branch from 9adf3fa to 6e6061f Compare October 25, 2026 20:30
@Cd1s
Cd1s merged commit 3f0f942 into main Oct 25, 2026
2 checks passed
@Cd1s
Cd1s deleted the fix/public-ip-retry branch October 25, 2026 20:47
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.

require_public_ip gives up after 4 redials, and policy routes do not fall back when the via WAN is in a CGNAT walled garden

1 participant