Repository navigation
Add fwmark option to route DoH queries via policy routing - #2
Merged
MelvinTo merged 1 commit intoOct 8, 2026
Merged
Conversation
caixingcheng
force-pushed
the
feature/9369-doh-outgoing-interface
branch
from
September 28, 2026 07:52
d8a586a to
6ca1862
Compare
caixingcheng
force-pushed
the
feature/9369-doh-outgoing-interface
branch
3 times, most recently
from
September 28, 2026 08:22
5c50bb5 to
f84403f
Compare
caixingcheng
force-pushed
the
feature/9369-doh-outgoing-interface
branch
from
September 28, 2026 08:46
f84403f to
0a43a60
Compare
Set a Linux fwmark (SO_MARK) on the sockets used for DoH queries, including HTTP/3, so policy routing rules can steer them - e.g. to send DoH through a VPN client instead of the default route. Setting SO_MARK requires CAP_NET_ADMIN and only applies on Linux; it is a no-op elsewhere, and is not applied when a SOCKS proxy is configured, since that replaces the dialer and leaves no socket of ours to mark. The mark is not a setting. It is read from Redis on the dial path, at most every 5 seconds, through a fixed key holding the name of the key that holds the mark: whoever owns the route publishes it under its own stable key and points the indirection at it. A mark that changes while the proxy runs - a VPN client restarting with a different routing table id - is therefore picked up without a restart, and nothing about the route ever reaches the configuration file, so selecting a client, switching between clients or turning one off does not rewrite it either. This is how the unbound build on the same device already reads its own mark, down to the key indirection, the refresh interval and the choice it makes when the mark is unavailable: the socket is left unmarked and the query follows the default route rather than failing. A VPN client selection steers both services the same way, and the decision about what should happen when that route is gone stays in one place, with the killSwitch handling above them, instead of being made differently by each service. Having no mark at all is the normal state when no client is selected, so it is told apart from a mark that was asked for and could not be resolved: the first is logged at debug level, the second warns. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
caixingcheng
force-pushed
the
feature/9369-doh-outgoing-interface
branch
from
September 28, 2026 09:02
0a43a60 to
64661a6
Compare
jasonlyc
approved these changes
Sep 28, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Set a Linux fwmark (SO_MARK) on the sockets used for DoH queries, including HTTP/3, so policy routing rules can steer them - e.g. to send DoH through a VPN client instead of the default route.
This matches how Firewalla already does VPN client policy routing (one ip rule per client, keyed on a stable per-profile mark), which means Virtual WAN Groups and kill-switch (an unreachable fallback route in that client's table) work for free, without dnscrypt-proxy having to re-resolve an interface address on every dial.
Setting SO_MARK requires CAP_NET_ADMIN and only applies on Linux; it is a no-op elsewhere. The mark is cleared when a SOCKS/HTTP proxy is configured, so every dial site inherits that guarantee rather than each one having to check. Failures report which mark could not be set and that CAP_NET_ADMIN is required, instead of a bare EPERM.
Only DoH queries are marked: DNSCrypt-protocol servers, anonymized DNS relays, forwarding rules and bootstrap/netprobe lookups keep using the default route.
Implements the dnscrypt-proxy side of firewalla/firecommit#9369.