Skip to content

net: handle upstream overlap, modem access, and ISP DNS sources - #138

Merged
Cd1s merged 9 commits into
mainfrom
fix/upstream-same-subnet
Oct 17, 2026
Merged

Cd1s merged 9 commits into
mainfrom
fix/upstream-same-subnet

Conversation

@Cd1s

@Cd1s Cd1s commented Oct 17, 2026 •

Copy link
Copy Markdown
Owner

What

  • Add per-WAN /32 gateway routes in the main and WAN tables, scoped proxy ARP and masquerade for an upstream gateway that overlaps a LAN subnet, with cleanup on WAN changes, LAN renumbering, and removed WAN tables.
  • Add validated wan[].modem.address support for PPPoE physical links: a /32 modem alias, host route, trusted-LAN proxy ARP/forwarding/NAT, and state cleanup. Invalid, public, loopback, multicast, router-address, masked, or non-PPPoE values are rejected.
  • Merge ISP DNS from PPPoE, DHCP option 6, and DHCPv6 without allowing IPv6 lease expiry to remove IPv4 DNS. Keep /run/ppp/resolv.conf as the PPP bootstrap fallback and support dns.fallback for an explicit no-source fallback.
  • Relax the DHCPv6 firewall rule to IPv6-enabled WAN interfaces, UDP source port 547 to destination port 546, and destination fe80::/10.
  • Add runtime netns coverage for boot ordering, ip route get, proxy ARP scope, DHCP firewall reload/cleanup, modem state cleanup, DNS lease behavior, and gateway route cleanup.

This change intentionally spans modules because the behavior crosses runtime hooks and generated artifacts: mr/hooks.go owns WAN leases/routes/events and DHCP hooks; mr/mod_net.go and mr/mod_net_render.go own WAN validation and network rendering; mr/mod_dns.go plus docs/modules/dns.md own ISP DNS rendering; mr/mod_fw_nft.go owns the DHCPv6 and modem firewall rules; mr/mod_sys_doctor.go owns the diagnostics; and mr/mod_proxy_test.go updates the proxy-off regression assertion to allow the independent modem proxy-ARP command.

Why

A DHCP modem can assign a gateway and DNS inside the router LAN subnet, blackholing router DNS and LAN access to the modem. Bridged PPPoE users need the modem management page reachable from trusted LAN. Some BNGs send DHCPv6 replies with non-ULA source addresses. WAN protocol changes and DHCPv6 lease events must not remove still-valid IPv4 ISP DNS.

For existing users with ipv6: true and peerdns: true, ISP-provided IPv6 DNS is now visible to dnsmasq after DHCPv6 reports it; it is kept separately from IPv4 DNS and removed only when the IPv6 lease expires. No public fallback is introduced unless dns.fallback is explicitly configured. /run/ppp/resolv.conf remains available during PPP startup.

Static WAN/LAN subnet overlap remains a validation error as a safety boundary; DHCP overlap is handled at runtime with a host route and single-address proxy ARP.

Verification

  • cd mr && go vet ./...
  • cd mr && go test -count=1 ./...
  • python3 tools/i18n.py check
  • sh tools/ci.sh (ALL CHECKS PASSED)
  • GitHub checks green on the pushed head

Closes #137

@Cd1s

Cd1s commented Oct 17, 2026

Copy link
Copy Markdown
Owner Author

Follow-up after QA review:

  • wan[].modem now uses a /32 alias and /32 route with src, installed after bridge addresses; trusted LAN proxy ARP is installed and stale alias/neighbour state is cleaned.
  • Modem addresses are normalized with net.ParseIP/To4, restricted to private PPPoE management addresses, and never emit raw config text into nft. Guest networks are excluded.
  • WAN leases keep DNS and DNS6 separately; DHCPv6 expiry only clears DNS6, while PPP resolv remains a bootstrap source. DHCP bound/deconfig reload nft when gateway state changes.
  • Added runtime netns checks for route selection, proxy neighbour cleanup, automatic NAT reload, alias ordering, and LAN route preservation.

Verification: go vet ./..., go test -count=1 ./..., and sh tools/ci.sh all pass (ALL CHECKS PASSED).

@Cd1s

Cd1s commented Oct 17, 2026

Copy link
Copy Markdown
Owner Author

Additional follow-up: overlapping gateway conflicts now suppress proxy ARP with a doctor risk event, and stale WAN gateway host routes are removed from allocated WAN tables. Head 6d43b2e; local Go vet/tests, i18n, and tools/ci.sh all pass; GitHub checks are green.

@Cd1s
Cd1s merged commit a2ad724 into main Oct 17, 2026
2 checks passed
Cd1s added a commit that referenced this pull request Oct 17, 2026
…r rolls back on fresh machines (Closes #145) (#147)

Since #138 network.sh truncates /run/mini-router/modem-aliases and modem-neigh. install.sh's apply
runs network.sh in place before mr-network (which creates the directory) ever started, so the
redirection failed, the script exited and the apply rolled back on every fresh machine.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Cd1s added a commit that referenced this pull request Oct 17, 2026
…s with simulated ISPs (DHCP, PPPoE, DHCPv6-PD) and a LAN client (#149)

* tools/lab: add isolated fresh environment harness

* tools/lab: record A1 verification results

* tools/lab: keep veth pairs inside lab namespaces

* tools/lab: isolate LAN and add guest seed installation

* tools/lab: add ISP slirp PPPoE hooks and live scenarios

* tools/lab: record leakage and ISP milestones

* tools/lab: complete cloud-init guest handoff and fallback LAN services

* tools/lab: fix cloud-init seed YAML and document guest limits

* tools/lab: update A1 continuation report

* tools/lab: seed Alpine router package layer for offline install

* tools/lab: protect host resolver and namespace state

* tools/lab: continue guest install with offline packages

* tools/lab: add A1 handover notes

* tools/lab: run the real install.sh — signed offline apk mirror, virtio agent console, deferred install, PPPoE/PD ISP rework

* tools/lab: lts base, virtio agent console, PPPoE + DHCPv6-PD ISP, lab.sh change, scenarios on lib.sh, A1c report

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* tools/lab: no host daemon config or services, isp --gw, 03 for same-subnet modems after #138

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* tools/lab: README links the product fixes #147 #148

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* tools/lab: review fixes — pinned downloads, image lock, pppd off the host's /run, cleanup on every exit

- the cloud image and the minirootfs are fixed versions with pinned SHA256s (checked against Alpine's
  .sha512 / .sha256); the package chroot is always re-extracted from the verified tarball
- one lock (mr-lab-images/.build.lock) for all shared image initialisation; temp dirs from mktemp;
  loop mounts on fresh mount points, unmounted by the exit trap
- veth pairs are created inside the lab namespaces (ip -n <sw> link add ... peer ... netns <ns>)
- pppoe-server and its pppd run with a private tmpfs /run: no /run/ppp0.pid or pppd2.tdb on the host
- processes are stopped TERM first, KILL after 3 s; isp_stop / ns_del signal everything inside the
  lab namespace, pid files only a process whose name still matches; powercut goes through kill_qemu
- host guard: INT/TERM/HUP run it in dash, symlinks under /etc/ppp, a baseline across commands
  (lab.sh guard-reset); up refuses to run next to host dnsmasq / kea / radvd services
- scenarios: the lab is taken down on any exit (MRLAB_KEEP=1 keeps it), failed setup steps bail out
- README: dependencies (mask services before installing; python3, openssh-client; no socat),
  download trust, host safety

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
@Cd1s Cd1s mentioned this pull request Oct 18, 2026
52 tasks done
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.

net: handle upstream and LAN subnet overlap and DHCPv6 ISP variants

1 participant