Repository navigation
Conversation
|
A note on how this relates to DNS Policies ( A DNS policy is keyed by the client: it redirects every DNS query from This include is keyed by the policy's domains: dnsmasq forwards only those lookups to the resolver of the interface the policy routes them through, pinned to that interface. Every other lookup keeps the normal upstreams. The answers still pass through dnsmasq, so the sets fill as before, and they now match where the traffic actually goes (a geo-routed CDN answers for the tunnel's exit, not for the WAN). So they complement each other: one picks the resolver a device uses for everything, the other makes a routed domain resolve where its traffic leaves. I deliberately didn't derive the resolver from the interface, as |
|
Thanks for this, and for the clear write-up, especially the comparison with 1. Validate the map entries. The resolver string reaches two places that each read their whole configuration in one go, so one typo takes down far more than the feature. Checked on OpenWrt 25.12:
A user file's nft lines are installed as part of pbr's own ruleset, so the first case stops pbr starting, and the second leaves the LAN without DNS. Please accept only an IPv4/IPv6 address with an optional 2. Use the interface's device, not its name. The map key matches the policy's 3. Document it. Please add a short section to the 1.2.4 README in docs.mossdef.org: what the map is for, how it differs from With those three in, I'm happy to merge. Your offer to build it in as a per-interface option is appreciated, but a user file is the right size for this. |
…rface Geo-located CDNs answer according to where the resolver is, and dnsmasq adds whatever it receives to the policy's nftset. A domain routed via a tunnel can therefore get addresses that suit a different location, because the lookup itself went out another way. This user file maps interfaces to a resolver that is reached through them, such as a VPN provider's in-tunnel DNS. For every enabled policy on a mapped interface it adds server=/<domain>/<resolver>@<interface> to the dnsmasq nftset file. dnsmasq binds the query to that interface, so resolution follows the policy when domains move between policies, and fails rather than leaks when the interface is down. Domains on unmapped interfaces are not affected. The map is empty by default. A warning is logged when /etc/config/dhcp has its own server= entry for a policy domain, since dnsmasq would use both. Signed-off-by: yitzhaq <17812841+yitzhaq@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
dnsmasq pins a server=...@<interface> query with IP_UNICAST_IF, which only steers the first route lookup. If an output policy then marks the query, for example a catch-all that sends the router's own traffic through a tunnel, the mark change in mangle_output makes the kernel reroute it by routing table, and the pin is lost: the lookup leaves by the catch-all's interface (or wherever main routes the resolver), so geo-located answers are wrong again. Insert a rule at the head of pbr_output that returns, unmarked, the queries to each mapped resolver that are already routed out of their mapped interface. They then leave exactly where dnsmasq pinned them. IPv4 and IPv6 resolvers get their own rule, and a resolver given as addr#port uses that port. Signed-off-by: yitzhaq <17812841+yitzhaq@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A resolver entry reaches both pbr's ruleset and the dnsmasq file, and each is read as a whole: a malformed address made nft reject the whole ruleset, or stopped dnsmasq from starting. Accept only an IPv4/IPv6 address with an optional #port, and skip anything else with a warning, so a mistake costs only that interface's pinning. The map is keyed by the interface name used in policies, but dnsmasq's @ pin and nft's oifname both need the device. They differ for anything but WireGuard (a proto none OpenVPN interface would give @VPNclient instead of @tun0, which dnsmasq accepts and then never matches). Look up each interface's l3_device from netifd, and skip, with a warning, an interface that has none when the service runs. Also state the ordering the file relies on: it runs after the policies are processed and before pbr compares the dnsmasq file. The uci test mock now loads a package on foreach, as libuci does, so a user file can be tested with its own cursor. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thanks for the careful review. All three are in, plus a rebase onto current 1. Map entries are validated. A value must be an IPv4/IPv6 address (checked with 2. The device, not the name. Each mapped interface's 3. Docs and ordering. The docs are in mossdef-org/docs.mossdef.org#44: a bullet in the list of provided files, and a section covering what the map is for, how it differs from Tests. New
Against the previous version of the file, 10 of the 16 fail. To test it, I had to make the uci mock's Live. I dry-ran the new file on my router (OpenWrt 24.10), against the real uci and ubus and with my seven WireGuard entries:
One gap I'd offer to close, if you want it: a domain policy with |
|
Thanks, this is a thorough update, and the extra tests are very welcome. I tested
tcpdump also shows the queries leaving through the tunnel from the tunnel's address, with nothing on the WAN device. One thing left before merging. The file writes Two optional points, neither of which holds up the merge. I found both by reading the code and did not test them:
Tor: thanks for the offer, but I'd like to leave it out and keep this file to its one job. With the newline fixed, I'm happy to merge this together with the docs PR. We are busy getting 1.2.4 into OpenWrt at the moment, so it may take some time before I get to that. |
…domain A policy's name goes into the comment after each server= line. A newline in it started a line of its own, so a name could add a live dnsmasq directive, or a junk line that stops dnsmasq. Replace control characters in the name with a space. The /etc/config/dhcp warning only looked at the first domain of an entry naming several, such as server=/a.example/b.example/1.1.1.1. Check them all. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thanks for testing it this thoroughly, including the injection.
Against the previous commit, the 3 new checks fail; with this one, 18/18 pass. Suite 76/76 and Understood on Tor, and no rush on the merge. Good luck with 1.2.4 in OpenWrt. |
Problem. Geo-located CDNs (BBC, SVT, DR, Netflix and similar) answer according to where the resolver is. dnsmasq adds whatever it receives to the policy's nftset. So a domain routed out of a UK tunnel can still get addresses chosen for the router's home country, because its lookup went out the default way. One workaround could be to pin addresses by hand, or to add
server=lines that then have to be kept in sync with the policies separately.This PR adds a user file with a small map of interface → resolver reachable through that interface, for example a VPN provider's in-tunnel DNS. For every enabled policy on a mapped interface, it appends the following line to the dnsmasq nftset file:
IP_UNICAST_IF, which only steers the first route lookup. If an output policy marks the query (for example a catch-all that sends the router's own traffic through a tunnel), the mark change inmangle_outputmakes the kernel reroute it by routing table and the pin is lost. The file therefore also inserts one rule at the head ofpbr_outputthat returns, unmarked, the queries to each mapped resolver that are already routed out of their mapped interface (separate IPv4/IPv6 rules;addr#portresolvers use that port).dnsoption was considered and rejected:proto none) do not expose their pushed DNS to netifd;dnsoption may be set locally to point at LAN resolvers, which would create a loop./etc/config/dhcphas its ownserver=entry for a policy domain, because dnsmasq would use both servers and the answers would mix.It relies on the include running after the policies are processed and before pbr's dnsmasq hash comparison. That is the current order in
start_service, so a change triggers the existing dnsmasq restart.Tested on OpenWrt 24.10 with pbr 1.2.3-r71, using several WireGuard tunnels from two providers whose in-tunnel resolvers use the same address on every tunnel:
whoami.akamai.netper tunnel.dnsmasq --test, and the generated nft rules passnft -c.0.0.0.0/0, queries left via the catch-all's tunnel until thepbr_outputrule was added; with it, each mapped resolver's queries leave via their own tunnel again (tcpdump).This is offered as a user file because that is the smallest change. If you would rather have it built in, for example as a per-interface or per-policy
resolveroption emitted next to thenftset=lines, I'm happy to rework it that way.🤖 Generated with Claude Code