Skip to content

dns: add ISP DNS unblock helper - #171

Merged
Cd1s merged 4 commits into
mainfrom
feat/dns-unblock
Oct 25, 2026
Merged

Cd1s merged 4 commits into
mainfrom
feat/dns-unblock

Conversation

@Cd1s

@Cd1s Cd1s commented Oct 25, 2026 •

Copy link
Copy Markdown
Owner

What

Add global ISP DNS unblock support under dns.unblock: a sing-box 1.14+ helper (mr-dns-unblock, 127.0.0.2:53) evaluates ISP or manual DNS responses and retries configured block-page, private sinkhole, and empty A/AAAA/HTTPS responses through Cloudflare, Google, Quad9, or a custom trusted resolver.

dnsmasq reads /run/mini-router/resolv-lan.conf: the helper when it is healthy, the ISP resolvers when it is not. mr-mon (only mr-mon; the WAN hooks rewrite the file when a lease changes but do not probe periodically) probes every ~5 s with two results in a row to switch, so a stopped, hung or restarted helper is recovered in about 10 s without restarting dnsmasq. Docs: docs/modules/dns.md (dns.unblock), docs/modules/mon.md.

Why

Some operators return a block page address, private sinkhole, or no answer for blocked domains. The hand-managed helper depended on cron-updated single-resolver state and could take LAN DNS down when it stopped. This keeps normal ISP answers and existing split/parental/sovereignty behavior while making the fallback visible, validated, supervised, and recoverable.

Third review (R3-1…R3-6, R3-8) — what changed in this round

Rebased on main 749d8ea (#169 + #172); the one conflict, writeResolv in mr/hooks.go, keeps main's DNS64 sync once.

# Problem Fix Test
R3-1 After a boot (or a helper restart with a stale state) the first probe rewrote the seeded resolv-lan.conf to the ISP resolvers for ~5 s the state machine starts from the mode the file is really in; probe counters start over TestDNSUnblockHealthHelperFileWithoutStateStaysHelper, …HelperRestartedWhileStateSaysDirect; lab 11 after reboot the monitor's first probe leaves the seeded helper alone (fails when the old initial state is put back)
R3-2 Going back to the helper kept the block page dnsmasq cached while it forwarded to the ISP (min-cache-ttl) switching back (or finding the helper in the file) runs rc-service dnsmasq reload and rc-service mr-proxy-dns reload (SIGHUP: cache dropped, no restart); going to the ISP does not flush. mr-proxy-dns gets a reload command. …SignalsDnsmasqOnlyWhenSwitchingToHelper, …AdoptingHelperFlushesOnce; lab 11 cached block page is dropped when dnsmasq goes back to the helper (blocked.test has TTL 300)
R3-3 mon-collect changed for every router: a trap that delayed TERM, a sleep 5 loop, a probe every 5 s forever after the feature was turned off the loop runs only with --dns-unblock (MON_DNS_UNBLOCK=1 in conf.d/mr-mon, rendered only while the feature is on, so toggling it restarts mr-mon); every wait of that run is cmd & wait $!; turning the feature off removes gen/dns-unblock.json and the runtime files (module Orphans) TestDNSUnblockMonSamplerFlagOnlyWhenEnabled (conf.d is byte-identical to main without the feature), TestDNSUnblockOrphans; tools/ci.d/mon.sh runs the sampler with and without the flag in dash and busybox ash; lab 11 mr-mon stop leaves no process…, disabling removes…, after disabling mr-mon has no probe loop
R3-4 needed a rebase done —
R3-5 dns.unblock.port could only be 53 key removed (struct, validation, panel default) TestDNSUnblockHasNoPortKey
R3-6 docs said WAN hooks probe only mr-mon probes; cache behaviour, DNS64 clients bypassing the helper, what disabling removes are documented —
R3-8 lab fragment switched dns.upstream: dot to isp examples/lab.d/30-dns.yaml is main's again; tools/ci.d/dns.sh renders a copy of the lab config with unblock on and runs sing-box check / dnsmasq --test on it. Scenario 10 is main's except that the ISP address follows the lab id (it was fixed to 10.1.1.1, i.e. lab id 1). —

R3-9 (a second probe name) is left as is: a trade-off, not needed for this PR.

Found by the lab, not by unit tests: supervise-daemon dnsmasq --signal HUP does not work outside the service's own script ("the first argument is dnsmasq and must be local"), so the first version of R3-2 sent nothing. rc-service … reload is what Alpine's dnsmasq script itself uses.

Verification

  • sh tools/ci.sh — ALL CHECKS PASSED (gofmt, vet, go test ./..., shellcheck, module checks incl. the new dns.sh unblock lane and mon.sh loop lane).
  • Lab ID 8, 11-dns-unblock: 26/26 TAP checks ok (output below); 10-proxy-nat46-dns64 (proxy: add built-in NAT46 and managed DNS64 #169): 2/2 ok.
  • rc-service mr-mon stop / restart in the Alpine lab VM (busybox ash 1.37): no mon-collect, sleep or unblock-health process left right after the command returns or 1 s later.
  • Screenshots (panel unchanged apart from the removed port default) at runs/2026-10-25-minirouter-nat46-dns/feat-dns-unblock/: dns-unblock-off-360.png and dns-unblock-on-360.png.
Lab ID 8 TAP output (head 59275bc)
# 11-dns-unblock
ok 1 - install.sh completes on the DHCP WAN
ok 2 - blocked.test uses trusted DNS
ok 3 - private.test uses trusted DNS
ok 4 - empty answer retries trusted NXDOMAIN
ok 5 - empty answer remains NXDOMAIN when both resolvers have no address
ok 6 - reboot keeps DHCP and dnsmasq alive
ok 7 - after reboot the monitor's first probe leaves the seeded helper alone
ok 8 - DHCP is available after reboot
ok 9 - unblock works after reboot
ok 10 - suspend helper
ok 11 - helper suspend falls back to ISP within 15 seconds
ok 12 - direct ISP answer for blocked.test is the block page
ok 13 - resume helper
ok 14 - dnsmasq goes back to the helper within 15 seconds
ok 15 - cached block page is dropped when dnsmasq goes back to the helper
ok 16 - apply preserves helper upstream
ok 17 - apply keeps unblock active
ok 18 - UDP trusted query is intercepted by ISP port-53 hijack
ok 19 - TLS path is not affected by UDP port-53 hijack
ok 20 - manual mode uses helper
ok 21 - manual mode falls back after helper stop
ok 22 - manual mode direct fallback resolves
ok 23 - mr-mon stop leaves no process of the probe loop behind
ok 24 - disabling restores the ISP block-page answer
ok 25 - disabling removes the helper config and the runtime files
ok 26 - after disabling mr-mon has no probe loop
1..26

# 10-proxy-nat46-dns64
ok 1 - ISP DNS serves the A record
ok 2 - built-in DNS64 synthesizes the AAAA record
1..2

Automatic probing and recommendations (mr dns unblock detect) remain a follow-up PR.

Closes #170

Cd1s and others added 4 commits October 26, 2026 00:40
…he on the way back, mon loop only when enabled

R3-1  the health state machine starts from the mode resolv-lan.conf is really in (boot: the init script has
      seeded the helper and there is no state yet; helper restart: the state may still say direct). The first
      probe no longer rewrites a good file to the ISP resolvers for one interval.
R3-2  going back to the helper (file written, or found in the file) reloads dnsmasq and mr-proxy-dns
      (rc-service ... reload = SIGHUP: cache dropped, no restart); mr-proxy-dns gets the reload command.
      Going to the ISP does not flush. The monitor logs every switch it makes.
R3-3  mr-mon runs the 5 s probe loop only with --dns-unblock (MON_DNS_UNBLOCK=1 in conf.d/mr-mon, rendered only
      while the feature is on); without it mon-collect is main's. Every wait of the flagged run is `cmd & wait $!`,
      so TERM ends the loop and its children at once. Switching the feature off removes gen/dns-unblock.json
      and the runtime files (module Orphans).
R3-5  dns.unblock.port is gone (the helper is always 127.0.0.2:53), from the struct, validation, panel default.
R3-6  docs: only mr-mon probes periodically, the cache behaviour, DNS64 clients bypass the helper, what
      disabling removes.
R3-8  examples/lab.d/30-dns.yaml is main's again (dot); CI checks a copy of the lab config with unblock on.
      Scenario 10 is main's except that the ISP address follows the lab id.
Lab 11: blocked.test has a TTL of 300, the cached block page must be gone after the switch back; after the reboot
      the monitor's first probe must not switch the seeded helper (no retry); mr-mon stop leaves nothing; disabling
      removes the files.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@Cd1s
Cd1s force-pushed the feat/dns-unblock branch from 28a82a9 to 59275bc Compare October 25, 2026 17:31
@Cd1s
Cd1s merged commit 44288f0 into main Oct 25, 2026
2 checks passed
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.

dns: add ISP DNS unblock helper

1 participant