Skip to content

fix(start-wrt): keep VPN DNS in its tunnel and resolve the router's lookups with custom DNS - #4882

Open
Dominion5254 wants to merge 5 commits into
masterfrom
wrt/vpn-dns-storage
Open

Dominion5254 wants to merge 5 commits into
masterfrom
wrt/vpn-dns-storage

Conversation

@Dominion5254

@Dominion5254 Dominion5254 commented Nov 23, 2026 •

Copy link
Copy Markdown
Member

Two DNS fixes for the router's own resolver. The second is needed because the first removes something that was hiding it.

Outbound VPN DNS servers reached over the WAN (closes #4877)

netifd writes every up interface's static dns list into resolv.conf.auto, whatever peerdns says (interface-ip.c gates only protocol-learned servers on it). StartWRT stored each outbound VPN's DNS servers on its WireGuard interface, so they became upstreams of the main dnsmasq and of every profile instance resolving through the ISP, queried in plain DNS over the WAN.

  • A VPN's DNS servers now live on its startwrt.vpn_client section (list dns). dns::vpn_dns_servers reads them there; create and update write them there.
  • Migration MoveVpnDnsOffInterfaces moves existing lists off the interfaces. It copies and strips in two separate writes: one dump_all writes network before startwrt, so a single write could lose the list on power loss.
  • peerdns '0' is no longer written on new VPN interfaces. wireguard.sh has no DNS handling, so it never did anything.

Router's own lookups refused with custom system DNS

Custom system DNS sets peerdns 0 on wan/wan6, which empties resolv.conf.auto. Profile instances forward to SmartDNS, but the main instance, which answers the router's own lookups (time sync, update checks), was left reading the empty file and refused every query. A router with an outbound VPN only resolved through the leak above, so fixing the leak alone would have broken it.

  • With custom system DNS, the main dnsmasq gets noresolv and server 127.0.0.1#5300, the system SmartDNS group. With ISP DNS both are removed, and only when the upstream this code added is present, so a hand-set noresolv or server stays.
  • This lives in rewrite_all_dns_forwarding, so wan.dns-set applies it and the existing startup heal repairs routers already in Custom mode. No new migration.
  • main_dnsmasq() replaces three copies of the main-instance lookup.

Verification

The head, 4802c31, merges master d3f3e0b. Its one conflict was in migrate.rs, where #4828 also appended a migration: RankWanBehindProfiles keeps its 18th place from master and MoveVpnDnsOffInterfaces runs 19th, with both functions unchanged. On 4802c31: make start-wrt-test (1026 startwrt-core, 37 uciedit, all passing), make start-wrt-format-check and check-version.

The previous head, f065f54, added to 1dc618c only a contract-text correction (d51b078) and a clean merge of master 9a68123, a docs-only change.

Tests on 1dc618c: make start-wrt-test (995 startwrt-core, 37 uciedit, all passing) and make start-wrt-format-check. The new heal test fails with rewrite_router_dns_forwarding disabled; the two VPN storage tests fail with the old interface write restored.

K1 bench, VPN DNS storage (run on 36e162e85; 962260d differs from it only in two comment sentences), against a WireGuard server:

  • Old binary: the router itself and an Admin client each sent 2 packets to the VPN resolver outside the tunnel. Fix: 0 and 0. A Guest client routed through the VPN resolved through the tunnel as before.
  • The migration ran on reboot and was a no-op on the next one. VPN create, update, delete and list, and the SmartDNS fallback through the tunnel, all worked.

K1 bench, custom system DNS (1dc618c):

  • Previous binary, Custom mode: nslookup against the router returned REFUSED, including for 0.openwrt.pool.ntp.org.
  • After deploying, with no settings change, the startup heal added the upstream and lookups resolved. A second daemon start and a reboot left /etc/config/dhcp byte-identical.
  • A plain custom server received queries on port 53 only; a DoH one on port 443 only. The ISP resolver received none in either case.
  • Custom DoH with an outbound VPN whose DNS server is 9.9.9.9: the router resolved, with 0 packets to 9.9.9.9.
  • Creating and deleting a VPN-routed profile kept the main instance's notinterface list correct. Switching back to ISP DNS removed noresolv and the upstream, and lookups went to the ISP resolver.
  • After a reboot in Custom mode the time-sync marker was present, and bench.sh smoke passed.

Not exercised: the merged head on a router, a flashed image (both changes are in the binary and its boot-time runner), an inbound VPN peer, and a real VPN handshake in the second bench session (its VPN had an unreachable endpoint; the first session used a live server).

Found while testing and not addressed here: with a DoH custom server, a clock far enough off makes SmartDNS reject the server's certificate, so time sync cannot resolve its servers and the clock does not recover. That predates this change and affects client lookups the same way.

…olver

netifd writes every up interface's static `dns` list into
resolv.conf.auto, whatever `peerdns` says, so each outbound VPN's
servers became upstreams of the main dnsmasq and of ISP-resolving
profile instances, queried in plain DNS over the WAN.

Store a VPN's servers on its startwrt vpn_client section instead and
migrate existing lists off the WireGuard interfaces. The no-op
`peerdns '0'` is no longer written.

Closes #4877
…m DNS

Custom system DNS empties resolv.conf.auto, the main dnsmasq's only
upstream, so the router's own lookups were refused unless an outbound
VPN's servers had leaked into that file.

Forward the main instance to the system SmartDNS group while system DNS
is custom. The startup heal applies it to routers already in that mode.

@helix-white helix-white left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved at 1dc618c35ee3e328e4a89f107022a6c6f08396c5. No blocking correctness findings. git merge-tree reports a clean merge with current master.

CI is not yet green: SDK, Runtime & Script Tests failed in exec.lifecycle.test.ts, with timedOutAfter: null instead of 10. This matches the unrelated test-isolation defect addressed by #4881. StartWRT tests, the riscv64 binary build, shared Rust tests, formatting/lockfiles, and generated-artifact checks remain pending; Prettier, changelog/version validation, and dependency-license checks passed.

  • VPN resolver addresses move from netifd's interface configuration into UciVpnClient.dns, an empty-by-default string list in startwrt.vpn_client. The RPC shapes and profile DNS precedence remain unchanged. Create, update, list, and profile forwarding use that metadata. The boot migration copies before stripping in separate writes, supports replay, and leaves inbound VPN interfaces alone. This removes the resolver addresses from netifd's global resolver input rather than relying on peerdns, which does not suppress static DNS.
  • The router's main dnsmasq now uses the existing system SmartDNS group on loopback port 5300 for custom system DNS. Switching to ISP removes the managed upstream and accompanying noresolv; unrelated explicit upstreams remain. The existing startup repair applies the routing to saved Custom configurations. Shared helpers replace the repeated main-instance lookup and upstream formatting; no additional background machinery is introduced.

Implementation diff: +175 / −105 lines in 4 files (excludes lockfiles, tests, docs, release notes, and changelog).

Recorded author verification includes 995 StartWRT and 37 uciedit tests plus formatting on this head. K1 bench evidence covers elimination of WAN-side VPN-resolver traffic, preserved tunneled resolution against a live WireGuard server, migration replay, custom plain/DoH routing, mode switches, and reboot/startup repair. The live-VPN storage session preceded this head; the later custom-DNS session did not establish a real VPN handshake. A flashed image and inbound VPN peer were not exercised. I performed read-only review, not additional execution. The disclosed custom-DoH clock-bootstrap deadlock remains outside this fix.

Nonblocking documentation mismatch: API_CONTRACT.md:1575–1576 still describes updating the interface's dns option; the implementation now updates VPN metadata. Also preserve the append-only migration ordering when reconciling other pending migrations, including #4840.

Helix-Harness: pi
Helix-Model: openai-codex/gpt-6.1-sol

@Dominion5254

Copy link
Copy Markdown
Member Author

Fixed the stale contract line in d51b078: vpn-client.update is now described as writing the label, target and list dns metadata and the interface mtu option.

The head is f065f54, which also merges master 9a68123 (a docs-only change, no conflicts). Nothing else changed since the approved 1dc618c.

On migration ordering with #4840: understood. Whichever of the two merges second takes the other's entry first and appends its own after it.

@helix-white helix-white left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-approved at f065f54e86ee6fe97256e000247bc4567d72ba03. The contract correction resolves my documentation note. Backend code, tests, and changelog are unchanged from the previously reviewed head; the merged master change affects only the support book. git merge-tree confirms a clean merge with current master. No new findings.

The PR keeps outbound VPN resolver addresses out of netifd's global resolver input by storing them in UciVpnClient.dns, an empty-by-default list in VPN metadata. A replay-safe boot migration copies before stripping the interface entries; inbound VPN interfaces remain untouched. RPC shapes and profile DNS precedence stay unchanged. The router's own Custom-mode lookups use the existing system SmartDNS group, with the existing startup repair applying it to saved configurations. Switching to ISP removes the managed forwarding settings. Shared helpers consolidate main-instance selection and system-upstream formatting.

Implementation diff: +175 / −105 lines in 4 files (excludes lockfiles, tests, docs, release notes, and changelog).

Verification is reused from the unchanged source: the author records 995 StartWRT and 37 uciedit tests plus formatting passing, and K1 bench coverage of WAN-leak elimination, tunneled DNS, migration replay, custom plain/DoH routing, mode switches, and reboots. A flashed image and inbound peer were not exercised; the later custom-DNS bench session had no live VPN handshake. The disclosed DoH clock-bootstrap problem remains outside this fix. This re-review was read-only.

CI for the new head is still running, including StartWRT Tests, Build riscv64 binary, and the remaining automated-test checks. Prettier and dependency-license checks passed. The earlier SDK timeout-test failure is the separate defect addressed by #4881, not a change in this PR.

Helix-Harness: pi
Helix-Model: openai-codex/gpt-6.1-sol

# Conflicts:
#	projects/start-wrt/backend/ctrl/src/migrate.rs

@helix-white helix-white left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-approved at 4802c316bc369f2e65b737af4a0c207ed8f9de31. I checked the merge resolution and current branch-against-master diff. The published migration prefix is preserved: WAN route ranking remains 18th and VPN DNS migration runs 19th. Both migration bodies are unchanged, as are the DNS-specific patches in dns.rs, profiles.rs, and vpn_client.rs. git merge-tree reports a clean merge with current master. No new correctness findings.

The two fixes prevent router/WAN-profile queries from reaching VPN resolvers over the WAN, and restore the router's own resolution with custom system DNS. Static interface DNS bypasses netifd's peerdns suppression, so VPN resolver intent moves out of interface configuration. Custom-mode router forwarding reuses the existing system SmartDNS group on loopback port 5300 and startup repair; switching to ISP removes the managed forwarding settings. Shared helpers consolidate main-instance selection and upstream formatting. Profile DNS precedence stays unchanged.

Implementation diff: +175 / −105 lines in 4 files (excludes lockfiles, tests, docs, release notes, and changelog).

Persisted model

#[derive(Debug, TypedSection)]
#[uci(ty = "vpn_client")]
pub(crate) struct UciVpnClient {
    /// WireGuard interface name (e.g., "wg_proton")
    pub interface: String,
    /// Human-readable label
    pub label: String,
    /// "Internet" or another VPN's label (for chaining)
    pub target: String,
    /// Resolvers reached through the tunnel. netifd gives an interface's own
    /// `dns` list to the router's resolver.
    #[uci(default)]
    pub dns: Vec<String>,
}

This section lives in /etc/config/startwrt. Existing configuration is converted at boot by copying resolver addresses into metadata before removing interface DNS in a separate write. Replay retains the migrated intent; inbound interfaces are untouched. RPC payloads remain compatible.

Verification

The author reports 1026 StartWRT and 37 uciedit tests, formatting, and version validation passing on this merged head. Earlier K1 bench evidence covers WAN-leak elimination, tunneled DNS against a live WireGuard server, migration replay, custom plain/DoH resolution, mode switches, and reboot repair. The merged head itself has not run on the router; a flashed image and inbound peer remain unexercised, and the later custom-DNS session had no live VPN handshake. The disclosed pre-existing DoH clock-bootstrap problem remains outside this fix.

This was read-only review, without additional execution. CI is still pending, including the riscv64 binary build, Prettier, and changelog/version validation, with the remaining automated suites behind their gates; no failed check was reported in the reviewed snapshot.

Helix-Harness: pi
Helix-Model: openai-codex/gpt-6.1-sol

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

2 participants