[PR #3382] feat(split-tunneling): wildcard site entries, resolved by observing DNS #3270

Open
opened 2026-11-07 17:58:50 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/amnezia-vpn/amnezia-client/pull/3382
Author: @MimoJanra
Created: 11/2/2026
Status: 🔄 Open

Base: dev ← Head: feat/wildcard-split-tunneling


📝 Commits (3)

  • 13fd3eb feat(split-tunneling): a DNS forwarder that resolves wildcard site entries
  • 3170c59 feat(split-tunneling): accept a wildcard site entry and carry it to the daemon
  • 1e67d71 feat(split-tunneling): install and withdraw the routes a wildcard produces

📊 Changes

29 files changed (+2631 additions, -24 deletions)

View changed files

📝 client/cmake/sources.cmake (+2 -0)
📝 client/core/controllers/ipSplitTunnelingController.cpp (+17 -3)
📝 client/core/utils/constants/configKeys.h (+1 -0)
📝 client/daemon/daemon.cpp (+187 -0)
📝 client/daemon/daemon.h (+29 -4)
➕ client/daemon/dnswildcardrouter.cpp (+1003 -0)
➕ client/daemon/dnswildcardrouter.h (+154 -0)
📝 client/daemon/interfaceconfig.h (+1 -0)
➕ client/daemon/wildcardroutetable.cpp (+98 -0)
➕ client/daemon/wildcardroutetable.h (+51 -0)
➕ client/daemon/wildcardsite.cpp (+170 -0)
➕ client/daemon/wildcardsite.h (+34 -0)
📝 client/mozilla/localsocketcontroller.cpp (+10 -0)
📝 client/platforms/linux/daemon/linuxdaemon.h (+13 -1)
📝 client/platforms/linux/daemon/wireguardutilslinux.cpp (+64 -1)
📝 client/platforms/linux/daemon/wireguardutilslinux.h (+11 -2)
📝 client/platforms/macos/daemon/macosdaemon.h (+13 -0)
📝 client/platforms/macos/daemon/wireguardutilsmacos.cpp (+65 -0)
📝 client/platforms/macos/daemon/wireguardutilsmacos.h (+11 -0)
📝 client/platforms/windows/daemon/windowsdaemon.cpp (+28 -0)

...and 9 more files

📄 Description

Fixes #1607.

Why a wildcard cannot simply be added to the list

Site split tunnelling selects by destination address, because that is all a
routing table has. The addresses behind *.discord.gg are not knowable when the
entry is typed, and a CDN keeps changing them, so there is nothing to install.
Entering a domain already works by resolving it once and storing the answer, but
a wildcard cannot be resolved at all: there is no query that returns every name
below a label.

The only place where the name still exists is the DNS exchange itself. This
change puts a forwarder where the system already sends its queries, relays them
to the real resolvers, and installs an exclusion route for the addresses of the
answers whose name matches a pattern, while the answer is still on its way back
to the application.

What is in it

Three commits, each one reviewable on its own:

  1. The forwarder, the shared definition of a wildcard, and the route table.
    No caller yet.
  2. The UI and configuration path: storing a pattern, and carrying it to the
    daemon.
  3. The daemon and the platform work: installing, permitting and withdrawing
    what is learned.

Trusting an answer

What the forwarder reports becomes a route in a privileged daemon, so a reply is
believed only when all of this holds: it arrived from the resolver the query was
sent to, on a socket connected to it; the transaction id and the question match
the query; the response bit is set, the opcode is zero, there is no error, and
the answer is not truncated. Addresses are taken only from records whose owner is
the queried name or a name reached from it through the CNAMEs of that same
message, and each address inherits the shortest TTL along that path. Everything
else is handed to the application untouched and reported to nobody.

A query no resolver answers is failed over across the configured resolvers and
then answered with SERVFAIL, rather than left to time out, because the system can
no longer fall back on its own once this is its resolver.

Names are never flattened

A DNS label may legally contain a dot. Names coming off the wire are kept as a
list of labels and compared label by label, so a single label whose bytes read
x.example.com does not pass for a name below example.com. Patterns are stored
canonically: lower case, no trailing dot, the base put through IDNA, and a path,
white space or an empty label refused at the point of entry. *.пример.рф is
stored as *.xn--e1afmkfd.xn--p1ai, which is the form that actually arrives.

Routes do not outlive their justification

A learned address is held by a route table with the TTL of the answer, clamped to
a usable range, expiring on a monotonic tick so a clock change cannot extend it.
There is a ceiling on how many routes one pattern can create, and the tunnel's own
addresses, its gateway and the server endpoint can never be routed around it.

Firewall and route together

With the kill switch on, the platform allow lists are built once from the static
excluded addresses. An address routed out of the tunnel later would meet the
blocking rule and go nowhere. The permit and the route are therefore installed in
the same operation and withdrawn in the same operation.

The forwarder's own endpoint is permitted the same way, on UDP and TCP. If that
permit cannot be installed the observer is stopped, because telling the system to
resolve through an address it is then forbidden to reach takes DNS down with it.

Where it listens, and why not loopback

The forwarder binds the tunnel's own address. An interface's resolver is queried
from that interface, and 127.0.0.1 is not an address of the tunnel adapter: on
Windows the query is dropped by the strong host check or encapsulated into the
tunnel, and a socket on loopback never sees it.

Lifecycle

The observer is reconciled with the configuration on every activation and on a
server switch, not started once. An empty pattern list stops it. A list that has
not changed leaves it running along with everything it has learned. A changed one
restarts it and withdraws what the previous server's answers justified.

An activation that fails after the observer started restores the resolvers and
releases the port. Learned routes are withdrawn before anything in deactivation
that can fail.

Scope and limitations

These are deliberate, and stated here rather than discovered later:

  • Desktop daemon, bypass mode only. The iOS network extension and the Android
    VpnService are untouched. In the "only these sites via VPN" mode a pattern is
    refused with an explanation instead of being stored and ignored.
  • DoH and DoT are not covered. An application with its own encrypted resolver
    does not use the system one, and no DNS-based scheme can match it.
  • A shared CDN address exempts everything else on it. This is a limit of
    bypassing by address; no amount of parsing removes it.
  • *.example.com covers example.com as well. This is wider than RFC 4592
    and is what a split tunnelling entry is expected to do; it is documented next to
    the matcher.
  • All queries go through the forwarder while it runs. Directing only the
    configured suffixes at it (NRPT on Windows, a routing domain in
    systemd-resolved, a scoped resolver on macOS) would narrow that, and belongs in
    a change of its own.

Testing

Built with MSVC 2022 and Qt 6.10.1: AmneziaVPN-service, test_common and
test_dns_wildcard_router all compile, and the test binary reports 40 passed, 0
failed.

The tests are adversarial rather than happy path: a forged transaction id, a
mismatched question, a truncated answer, a CNAME whose data cannot hold its
target, a record owned by an unrelated name, a lying section count, an extended
error hidden in an OPT record, a compression pointer loop, a frame split across
reads and two frames in one, a label containing a dot, TTL expiry, the capacity
ceiling and the reserved addresses.

Two of them drive the real forwarder over real sockets against a fake resolver,
including the case where the header says NOERROR and only an OPT record disagrees.
A test that calls the helpers alone cannot tell whether the product calls them
too, which is how that one was missed in the first place.

Not verified: the Linux and macOS firewall hooks are not compiled by a Windows
build. They mirror the Windows implementation and need a build on those platforms
before anyone relies on them. Marked as such in both headers.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/amnezia-vpn/amnezia-client/pull/3382 **Author:** [@MimoJanra](https://github.com/MimoJanra) **Created:** 11/2/2026 **Status:** 🔄 Open **Base:** `dev` ← **Head:** `feat/wildcard-split-tunneling` --- ### 📝 Commits (3) - [`13fd3eb`](https://github.com/amnezia-vpn/amnezia-client/commit/13fd3ebd90fd53c202894c35de028b554e0714f6) feat(split-tunneling): a DNS forwarder that resolves wildcard site entries - [`3170c59`](https://github.com/amnezia-vpn/amnezia-client/commit/3170c592a16958ef1e578d77e5b8051e8a58454a) feat(split-tunneling): accept a wildcard site entry and carry it to the daemon - [`1e67d71`](https://github.com/amnezia-vpn/amnezia-client/commit/1e67d71951ceb412b8006525627afa94613f651e) feat(split-tunneling): install and withdraw the routes a wildcard produces ### 📊 Changes **29 files changed** (+2631 additions, -24 deletions) <details> <summary>View changed files</summary> 📝 `client/cmake/sources.cmake` (+2 -0) 📝 `client/core/controllers/ipSplitTunnelingController.cpp` (+17 -3) 📝 `client/core/utils/constants/configKeys.h` (+1 -0) 📝 `client/daemon/daemon.cpp` (+187 -0) 📝 `client/daemon/daemon.h` (+29 -4) ➕ `client/daemon/dnswildcardrouter.cpp` (+1003 -0) ➕ `client/daemon/dnswildcardrouter.h` (+154 -0) 📝 `client/daemon/interfaceconfig.h` (+1 -0) ➕ `client/daemon/wildcardroutetable.cpp` (+98 -0) ➕ `client/daemon/wildcardroutetable.h` (+51 -0) ➕ `client/daemon/wildcardsite.cpp` (+170 -0) ➕ `client/daemon/wildcardsite.h` (+34 -0) 📝 `client/mozilla/localsocketcontroller.cpp` (+10 -0) 📝 `client/platforms/linux/daemon/linuxdaemon.h` (+13 -1) 📝 `client/platforms/linux/daemon/wireguardutilslinux.cpp` (+64 -1) 📝 `client/platforms/linux/daemon/wireguardutilslinux.h` (+11 -2) 📝 `client/platforms/macos/daemon/macosdaemon.h` (+13 -0) 📝 `client/platforms/macos/daemon/wireguardutilsmacos.cpp` (+65 -0) 📝 `client/platforms/macos/daemon/wireguardutilsmacos.h` (+11 -0) 📝 `client/platforms/windows/daemon/windowsdaemon.cpp` (+28 -0) _...and 9 more files_ </details> ### 📄 Description Fixes #1607. ## Why a wildcard cannot simply be added to the list Site split tunnelling selects by destination address, because that is all a routing table has. The addresses behind `*.discord.gg` are not knowable when the entry is typed, and a CDN keeps changing them, so there is nothing to install. Entering a domain already works by resolving it once and storing the answer, but a wildcard cannot be resolved at all: there is no query that returns every name below a label. The only place where the name still exists is the DNS exchange itself. This change puts a forwarder where the system already sends its queries, relays them to the real resolvers, and installs an exclusion route for the addresses of the answers whose name matches a pattern, while the answer is still on its way back to the application. ## What is in it Three commits, each one reviewable on its own: 1. **The forwarder, the shared definition of a wildcard, and the route table.** No caller yet. 2. **The UI and configuration path**: storing a pattern, and carrying it to the daemon. 3. **The daemon and the platform work**: installing, permitting and withdrawing what is learned. ### Trusting an answer What the forwarder reports becomes a route in a privileged daemon, so a reply is believed only when all of this holds: it arrived from the resolver the query was sent to, on a socket connected to it; the transaction id and the question match the query; the response bit is set, the opcode is zero, there is no error, and the answer is not truncated. Addresses are taken only from records whose owner is the queried name or a name reached from it through the CNAMEs of that same message, and each address inherits the shortest TTL along that path. Everything else is handed to the application untouched and reported to nobody. A query no resolver answers is failed over across the configured resolvers and then answered with SERVFAIL, rather than left to time out, because the system can no longer fall back on its own once this is its resolver. ### Names are never flattened A DNS label may legally contain a dot. Names coming off the wire are kept as a list of labels and compared label by label, so a single label whose bytes read `x.example.com` does not pass for a name below `example.com`. Patterns are stored canonically: lower case, no trailing dot, the base put through IDNA, and a path, white space or an empty label refused at the point of entry. `*.пример.рф` is stored as `*.xn--e1afmkfd.xn--p1ai`, which is the form that actually arrives. ### Routes do not outlive their justification A learned address is held by a route table with the TTL of the answer, clamped to a usable range, expiring on a monotonic tick so a clock change cannot extend it. There is a ceiling on how many routes one pattern can create, and the tunnel's own addresses, its gateway and the server endpoint can never be routed around it. ### Firewall and route together With the kill switch on, the platform allow lists are built once from the static excluded addresses. An address routed out of the tunnel later would meet the blocking rule and go nowhere. The permit and the route are therefore installed in the same operation and withdrawn in the same operation. The forwarder's own endpoint is permitted the same way, on UDP and TCP. If that permit cannot be installed the observer is stopped, because telling the system to resolve through an address it is then forbidden to reach takes DNS down with it. ### Where it listens, and why not loopback The forwarder binds the tunnel's own address. An interface's resolver is queried from that interface, and `127.0.0.1` is not an address of the tunnel adapter: on Windows the query is dropped by the strong host check or encapsulated into the tunnel, and a socket on loopback never sees it. ## Lifecycle The observer is reconciled with the configuration on every activation and on a server switch, not started once. An empty pattern list stops it. A list that has not changed leaves it running along with everything it has learned. A changed one restarts it and withdraws what the previous server's answers justified. An activation that fails after the observer started restores the resolvers and releases the port. Learned routes are withdrawn before anything in deactivation that can fail. ## Scope and limitations These are deliberate, and stated here rather than discovered later: - **Desktop daemon, bypass mode only.** The iOS network extension and the Android VpnService are untouched. In the "only these sites via VPN" mode a pattern is refused with an explanation instead of being stored and ignored. - **DoH and DoT are not covered.** An application with its own encrypted resolver does not use the system one, and no DNS-based scheme can match it. - **A shared CDN address exempts everything else on it.** This is a limit of bypassing by address; no amount of parsing removes it. - **`*.example.com` covers `example.com` as well.** This is wider than RFC 4592 and is what a split tunnelling entry is expected to do; it is documented next to the matcher. - **All queries go through the forwarder while it runs.** Directing only the configured suffixes at it (NRPT on Windows, a routing domain in systemd-resolved, a scoped resolver on macOS) would narrow that, and belongs in a change of its own. ## Testing Built with MSVC 2022 and Qt 6.10.1: `AmneziaVPN-service`, `test_common` and `test_dns_wildcard_router` all compile, and the test binary reports 40 passed, 0 failed. The tests are adversarial rather than happy path: a forged transaction id, a mismatched question, a truncated answer, a CNAME whose data cannot hold its target, a record owned by an unrelated name, a lying section count, an extended error hidden in an OPT record, a compression pointer loop, a frame split across reads and two frames in one, a label containing a dot, TTL expiry, the capacity ceiling and the reserved addresses. Two of them drive the real forwarder over real sockets against a fake resolver, including the case where the header says NOERROR and only an OPT record disagrees. A test that calls the helpers alone cannot tell whether the product calls them too, which is how that one was missed in the first place. **Not verified:** the Linux and macOS firewall hooks are not compiled by a Windows build. They mirror the Windows implementation and need a build on those platforms before anyone relies on them. Marked as such in both headers. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No labels
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
amnezia-vpn/amnezia-client#3270
No description provided.