[PR #3354] fix(import): preserve single DNS server in WireGuard configs #3221

Open
opened 2026-10-30 04:58:06 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/amnezia-vpn/amnezia-client/pull/3354
Author: @DaMistic727
Created: 10/29/2026
Status: 🔄 Open

Base: dev ← Head: fix/import-single-wireguard-dns


📝 Commits (1)

  • b653349 fix(import): preserve single DNS server in WireGuard configs

📊 Changes

4 files changed (+241 additions, -8 deletions)

View changed files

📝 client/core/controllers/selfhosted/importController.cpp (+17 -7)
📝 client/core/models/selfhosted/nativeServerConfig.cpp (+3 -1)
📝 client/tests/CMakeLists.txt (+10 -0)
➕ client/tests/testWireGuardDnsImport.cpp (+211 -0)

📄 Description

Problem

A native WireGuard/AmneziaWG .conf containing DNS = 10.23.0.53 loses that resolver during import. The connection then receives the application's DNS instead. Retaining only dns1 is insufficient: the existing native-profile fallback also adds the application's secondary resolver when dns2 is absent.

Fixes #3345.

Root cause

extractWireGuardConfig() searches the entire file with a regular expression requiring two IPv4 addresses and literal spacing around =. It can also pick up DNS-like text in comments or another key.

NativeServerConfig::getDnsPair() independently fills both missing fields from application settings.

Changes

  • Read the exact DNS entry from the existing line-parsed configMap.
  • Split comma-separated values, trim whitespace, exclude trailing # comments, and retain the first two valid IPv4 addresses in their original order using the existing Qt-based NetworkUtilities::checkIPv4Format().
  • Preserve an empty secondary DNS for native WG/AWG profiles with a valid explicitly configured primary DNS. Do not duplicate the primary address.
  • Keep the existing fallback for profiles with no valid primary DNS, other native protocols, and nonempty invalid stored secondary DNS values.
  • Register one data-driven Qt Test suite in the existing CMake infrastructure.

No key, route, MTU, Endpoint, protocol-detection, configuration-format, or UI changes.

Regression tests

The tests use the public production ImportController::extractConfigFromData(), real repositories/settings, profile JSON, NativeServerConfig::fromJson(), serialization round-trips, and getDnsPair().

  • 32 import rows: WG and AWG, single/pair DNS, spacing, ordering, absent/empty/invalid/mixed values, comments, another key, extra resolvers, and unsupported IPv6 values.
  • 20 native fallback rows: WireGuard/AWG/AWG2 single/pair/missing/invalid DNS, plus unchanged OpenVPN/Xray behavior.
  • One compatibility test for self-hosted admin/user and API profile fallbacks.
  • Assert DNS fields and preservation of native config, keys, address, port, routes, MTU, keepalive, and WG/AWG detection.
  • Synthetic keys and illustrative addresses only; no server, VPN connection, environment secrets, SSH, or Docker required.

Validation

  • PASSED: Release and Debug component builds on macOS arm64, Qt 6.12.0 / AppleClang 21. The external Qt/CMake harness compiles the complete production importer, native model, real repositories/settings, config models, serializers, IP validator, and pinned qtkeychain dependency. No extracted parser or mocked production model is used.
  • PASSED: new Qt suite, 55 passed / 0 failed / 0 skipped in Release and independently Debug (53 scenarios plus initialization/cleanup).
  • PASSED red → green: the same tests with unmodified upstream/dev importer and native model at 7f9b7db482b8b1662b7466937e578008cbcb716e produce 25 expected failures, including the single-DNS import and secondary fallback cases; the patched sources pass.
  • PASSED: additional external probes using the real desktop InterfaceConfig::toWgConf() and Apple WGConfig plus the pinned WireGuardKit WgQuick parser, for one and two resolvers.
  • PASSED: git diff --check, repository clang-format for the new test and changed production statements, changed-file/branch-isolation checks.
  • NOT RUN: full application build, standard test_common and existing integration import suites (MultipleImportsTest, ConfigFormatVersionTest), and full CTest. Root configuration stops at missing Conan (Could not find CONAN_COMMAND).

Compatibility

With application DNS 1.1.1.1 / 1.0.0.1, an imported single 10.23.0.53 now yields ("10.23.0.53", ""); two imported resolvers retain their order. Without valid imported DNS the application pair is still used.

Android's existing optStringOrNull() skips the empty secondary. Desktop consumers guard empty secondary DNS. The real Apple decoder/parser accepts an empty secondary and produces exactly one DNS server. Platform code is unchanged.

The fallback adjustment is limited to native WG/AWG; it also applies to existing native WG/AWG profiles already storing only a valid primary DNS. No IPv6 support or system-DNS mode is introduced.

#2609 is an open, broader dual-stack IPv4/IPv6 implementation. It already reads a DNS list from configMap; this PR independently applies that approach to the current IPv4 branch, adds IPv4 validation, and addresses the native secondary fallback. It does not take the IPv6, address, endpoint, routing, or platform changes from #2609.

Both PRs touch the old DNS parsing block in extractWireGuardConfig(), so that hunk will need reconciliation if both are merged. This is a narrow bugfix for the current IPv4 implementation, separate from the larger IPv6 work. No separate equivalent PR was found in public open/closed PR searches.

Limitations

No Android device/emulator VPN activation, live DNS traffic capture, Windows/Linux application runtime, or Apple NetworkExtension tunnel was exercised. The Apple and desktop probes validate parsing/serialization, not operating-system tunnel activation. Android empty-secondary handling was inspected in production source.

The external component harness uses linker dead stripping for unused dependencies and does not replace a full app link or the repository's standard test harness. Existing profiles that already lost their DNS on an earlier import must be reimported; discarded data cannot be reconstructed.


🔄 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/3354 **Author:** [@DaMistic727](https://github.com/DaMistic727) **Created:** 10/29/2026 **Status:** 🔄 Open **Base:** `dev` ← **Head:** `fix/import-single-wireguard-dns` --- ### 📝 Commits (1) - [`b653349`](https://github.com/amnezia-vpn/amnezia-client/commit/b65334968962e4a253c86b746cc56f7dd89f7dcd) fix(import): preserve single DNS server in WireGuard configs ### 📊 Changes **4 files changed** (+241 additions, -8 deletions) <details> <summary>View changed files</summary> 📝 `client/core/controllers/selfhosted/importController.cpp` (+17 -7) 📝 `client/core/models/selfhosted/nativeServerConfig.cpp` (+3 -1) 📝 `client/tests/CMakeLists.txt` (+10 -0) ➕ `client/tests/testWireGuardDnsImport.cpp` (+211 -0) </details> ### 📄 Description ## Problem A native WireGuard/AmneziaWG `.conf` containing `DNS = 10.23.0.53` loses that resolver during import. The connection then receives the application's DNS instead. Retaining only `dns1` is insufficient: the existing native-profile fallback also adds the application's secondary resolver when `dns2` is absent. Fixes #3345. ## Root cause `extractWireGuardConfig()` searches the entire file with a regular expression requiring two IPv4 addresses and literal spacing around `=`. It can also pick up DNS-like text in comments or another key. `NativeServerConfig::getDnsPair()` independently fills both missing fields from application settings. ## Changes - Read the exact `DNS` entry from the existing line-parsed `configMap`. - Split comma-separated values, trim whitespace, exclude trailing `#` comments, and retain the first two valid IPv4 addresses in their original order using the existing Qt-based `NetworkUtilities::checkIPv4Format()`. - Preserve an empty secondary DNS for native WG/AWG profiles with a valid explicitly configured primary DNS. Do not duplicate the primary address. - Keep the existing fallback for profiles with no valid primary DNS, other native protocols, and nonempty invalid stored secondary DNS values. - Register one data-driven Qt Test suite in the existing CMake infrastructure. No key, route, MTU, Endpoint, protocol-detection, configuration-format, or UI changes. ## Regression tests The tests use the public production `ImportController::extractConfigFromData()`, real repositories/settings, profile JSON, `NativeServerConfig::fromJson()`, serialization round-trips, and `getDnsPair()`. - 32 import rows: WG and AWG, single/pair DNS, spacing, ordering, absent/empty/invalid/mixed values, comments, another key, extra resolvers, and unsupported IPv6 values. - 20 native fallback rows: WireGuard/AWG/AWG2 single/pair/missing/invalid DNS, plus unchanged OpenVPN/Xray behavior. - One compatibility test for self-hosted admin/user and API profile fallbacks. - Assert DNS fields and preservation of native config, keys, address, port, routes, MTU, keepalive, and WG/AWG detection. - Synthetic keys and illustrative addresses only; no server, VPN connection, environment secrets, SSH, or Docker required. ## Validation - **PASSED:** Release and Debug component builds on macOS arm64, Qt 6.12.0 / AppleClang 21. The external Qt/CMake harness compiles the complete production importer, native model, real repositories/settings, config models, serializers, IP validator, and pinned qtkeychain dependency. No extracted parser or mocked production model is used. - **PASSED:** new Qt suite, 55 passed / 0 failed / 0 skipped in Release and independently Debug (53 scenarios plus initialization/cleanup). - **PASSED red → green:** the same tests with unmodified `upstream/dev` importer and native model at `7f9b7db482b8b1662b7466937e578008cbcb716e` produce 25 expected failures, including the single-DNS import and secondary fallback cases; the patched sources pass. - **PASSED:** additional external probes using the real desktop `InterfaceConfig::toWgConf()` and Apple `WGConfig` plus the pinned WireGuardKit WgQuick parser, for one and two resolvers. - **PASSED:** `git diff --check`, repository clang-format for the new test and changed production statements, changed-file/branch-isolation checks. - **NOT RUN:** full application build, standard `test_common` and existing integration import suites (`MultipleImportsTest`, `ConfigFormatVersionTest`), and full CTest. Root configuration stops at missing Conan (`Could not find CONAN_COMMAND`). ## Compatibility With application DNS `1.1.1.1` / `1.0.0.1`, an imported single `10.23.0.53` now yields `("10.23.0.53", "")`; two imported resolvers retain their order. Without valid imported DNS the application pair is still used. Android's existing `optStringOrNull()` skips the empty secondary. Desktop consumers guard empty secondary DNS. The real Apple decoder/parser accepts an empty secondary and produces exactly one DNS server. Platform code is unchanged. The fallback adjustment is limited to native WG/AWG; it also applies to existing native WG/AWG profiles already storing only a valid primary DNS. No IPv6 support or system-DNS mode is introduced. ## Related work #2609 is an open, broader dual-stack IPv4/IPv6 implementation. It already reads a DNS list from `configMap`; this PR independently applies that approach to the current IPv4 branch, adds IPv4 validation, and addresses the native secondary fallback. It does not take the IPv6, address, endpoint, routing, or platform changes from #2609. Both PRs touch the old DNS parsing block in `extractWireGuardConfig()`, so that hunk will need reconciliation if both are merged. This is a narrow bugfix for the current IPv4 implementation, separate from the larger IPv6 work. No separate equivalent PR was found in public open/closed PR searches. ## Limitations No Android device/emulator VPN activation, live DNS traffic capture, Windows/Linux application runtime, or Apple NetworkExtension tunnel was exercised. The Apple and desktop probes validate parsing/serialization, not operating-system tunnel activation. Android empty-secondary handling was inspected in production source. The external component harness uses linker dead stripping for unused dependencies and does not replace a full app link or the repository's standard test harness. Existing profiles that already lost their DNS on an earlier import must be reimported; discarded data cannot be reconstructed. --- <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#3221
No description provided.