Skip to content

Add fwmark option to route DoH queries via policy routing - #2

Merged
MelvinTo merged 1 commit into
firewalla:2.1.18from
caixingcheng:feature/9369-doh-outgoing-interface
Oct 8, 2026
Merged

MelvinTo merged 1 commit into
firewalla:2.1.18from
caixingcheng:feature/9369-doh-outgoing-interface

Conversation

@caixingcheng

Copy link
Copy Markdown

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.

@caixingcheng
caixingcheng force-pushed the feature/9369-doh-outgoing-interface branch from d8a586a to 6ca1862 Compare September 28, 2026 07:52
Comment thread dnscrypt-proxy/mark_linux.go Fixed
@caixingcheng
caixingcheng force-pushed the feature/9369-doh-outgoing-interface branch 3 times, most recently from 5c50bb5 to f84403f Compare September 28, 2026 08:22
Comment thread dnscrypt-proxy/mark_linux.go Fixed
@caixingcheng
caixingcheng force-pushed the feature/9369-doh-outgoing-interface branch from f84403f to 0a43a60 Compare September 28, 2026 08:46
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
caixingcheng force-pushed the feature/9369-doh-outgoing-interface branch from 0a43a60 to 64661a6 Compare September 28, 2026 09:02
@MelvinTo
MelvinTo merged commit 72f552a into firewalla:2.1.18 Oct 8, 2026
3 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.

4 participants