[PR #52] feat: support opt-in DNS SRV endpoint discovery #52

Open
opened 2026-11-07 18:00:13 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/amnezia-vpn/amneziawg-apple/pull/52
Author: @cubatic45
Created: 11/1/2026
Status: 🔄 Open

Base: master ← Head: feat/dns-srv-endpoints


📝 Commits (4)

  • ec0a2fc Add opt-in DNS SRV endpoint discovery and refresh
  • 6eceb25 Use the DNS-SD error constant with its imported Swift type
  • f665aaf Scope resolver tests and add an opt-in live DNS-SD smoke test
  • e7063bc Highlight SRV URLs as service names rather than fixed ports

📊 Changes

13 files changed (+625 additions, -3 deletions)

View changed files

➕ .github/workflows/srv-tests.yml (+38 -0)
📝 README.md (+45 -0)
➕ Scripts/test-srv-highlighter.c (+28 -0)
➕ Scripts/test-srv.py (+26 -0)
📝 Sources/WireGuardApp/Localizable.xcstrings (+1 -1)
📝 Sources/WireGuardApp/UI/macOS/View/highlighter.c (+28 -0)
📝 Sources/WireGuardKit/DNSResolver.swift (+28 -1)
📝 Sources/WireGuardKit/Endpoint.swift (+30 -1)
📝 Sources/WireGuardKit/PacketTunnelSettingsGenerator.swift (+33 -0)
➕ Sources/WireGuardKit/SRVResolver.swift (+129 -0)
📝 Sources/WireGuardKit/WireGuardAdapter.swift (+39 -0)
➕ Tests/WireGuardKitTests/SRVEndpointTests.swift (+194 -0)
📝 WireGuard.xcodeproj/project.pbxproj (+6 -0)

📄 Description

Problem

NAT traversal tools can publish a changing public UDP port through DNS SRV, but the Apple client currently resolves only the address portion of a fixed host:port endpoint. An updated A/AAAA record cannot communicate a changed port, so users must edit the peer configuration when that port changes.

Behavior

Add explicit, opt-in SRV discovery in peer configurations:

Endpoint = srv://_wireguard._udp.vpn.example.com

For example:

_wireguard._udp.vpn.example.com. 300 IN SRV 10 10 9783 endpoint.example.com.
endpoint.example.com.           300 IN A   192.0.2.1

The client discovers the target and UDP port, then uses the existing address resolver. Existing hostname:port, IPv4 and bracketed IPv6 endpoints retain their fixed-port behavior. Configuration export preserves the SRV URL; only a resolved numeric endpoint is sent to the backend.

The implementation:

  • Uses Apple's system DNS-SD API with a five-second bounded SRV query, without adding a third-party resolver or hard-coded DNS server.
  • Orders records by RFC 2782 priority and weight, tries the next record when a target's address lookup fails, and treats a root target (.) as unavailable. It validates the uncompressed SRV RDATA and rejects malformed or ambiguous endpoint URLs.
  • Refreshes explicitly opted-in peers on satisfied network-path updates and approximately every 60 seconds while the backend is running. Resolver caching and DNS TTLs still apply.
  • Keeps the last working endpoint on a refresh error. Unchanged DNS answers do not overwrite endpoint roaming learned by the backend. Changed IP addresses also update the excluded routes; port-only changes do not restart the tunnel.
  • Updates the editor highlighter, English validation message, Xcode source membership and README.

This is an Apple-client configuration extension, not a change to the WireGuard wire protocol or to stock wg-quick. The configured peer public key remains unchanged. DNS must be reachable before connection and during refresh; a DNS server accessible only through a broken tunnel cannot bootstrap discovery. Address-lookup failover is covered; handshake-based target failover is outside this change.

Validation

  • 16 deterministic SRV tests pass on macOS: endpoint parsing/round trips, fixed-endpoint compatibility, malformed/truncated/compressed RDATA, unavailable services, priority/weight ordering, target-address fallback, port changes, retaining cached endpoints on errors, and avoiding unnecessary roaming resets.
  • An additional opt-in live DNS-SD integration test passed on a macOS runner using _sip._udp.sip.linphone.org; it queried SRV through the system resolver and resolved the discovered target and port. Normal CI skips this network-dependent test unless a record name is supplied through workflow_dispatch.
  • The complete WireGuardKit adapter type-checks against both the macOS SDK and the iOS simulator SDK.
  • The C editor-highlighter regression test passes locally with AddressSanitizer/UndefinedBehaviorSanitizer and in macOS CI.
  • No signed iOS/macOS application build or physical-device tunnel test has been performed.

The focused test runner avoids linking the Go backend, so tests do not require Go build artifacts or signing credentials. An initial run of the existing complete test suite also exposed an unrelated failure in HandshakeFreshnessEvaluatorTests.testLatestHandshakeOlderThanCutoffIsNotFresh: the existing implementation ignores cutoffDate, while that test expects it to be enforced. Those upstream files are unchanged; the added workflow runs the focused SRV suite rather than changing handshake semantics in this PR.

CI with the live system-resolver test: https://github.com/cubatic45/amneziawg-apple/actions/runs/41274693303


🔄 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/amneziawg-apple/pull/52 **Author:** [@cubatic45](https://github.com/cubatic45) **Created:** 11/1/2026 **Status:** 🔄 Open **Base:** `master` ← **Head:** `feat/dns-srv-endpoints` --- ### 📝 Commits (4) - [`ec0a2fc`](https://github.com/amnezia-vpn/amneziawg-apple/commit/ec0a2fc72609b7d4dba90d0ae884588021f9ed63) Add opt-in DNS SRV endpoint discovery and refresh - [`6eceb25`](https://github.com/amnezia-vpn/amneziawg-apple/commit/6eceb25b3e4228d19188f46255d93f72ecf26b0e) Use the DNS-SD error constant with its imported Swift type - [`f665aaf`](https://github.com/amnezia-vpn/amneziawg-apple/commit/f665aaf1a4a47a9ef63fb0f8f68c915eee0fe446) Scope resolver tests and add an opt-in live DNS-SD smoke test - [`e7063bc`](https://github.com/amnezia-vpn/amneziawg-apple/commit/e7063bc74340261b186fa7befcb2274f39b0c99e) Highlight SRV URLs as service names rather than fixed ports ### 📊 Changes **13 files changed** (+625 additions, -3 deletions) <details> <summary>View changed files</summary> ➕ `.github/workflows/srv-tests.yml` (+38 -0) 📝 `README.md` (+45 -0) ➕ `Scripts/test-srv-highlighter.c` (+28 -0) ➕ `Scripts/test-srv.py` (+26 -0) 📝 `Sources/WireGuardApp/Localizable.xcstrings` (+1 -1) 📝 `Sources/WireGuardApp/UI/macOS/View/highlighter.c` (+28 -0) 📝 `Sources/WireGuardKit/DNSResolver.swift` (+28 -1) 📝 `Sources/WireGuardKit/Endpoint.swift` (+30 -1) 📝 `Sources/WireGuardKit/PacketTunnelSettingsGenerator.swift` (+33 -0) ➕ `Sources/WireGuardKit/SRVResolver.swift` (+129 -0) 📝 `Sources/WireGuardKit/WireGuardAdapter.swift` (+39 -0) ➕ `Tests/WireGuardKitTests/SRVEndpointTests.swift` (+194 -0) 📝 `WireGuard.xcodeproj/project.pbxproj` (+6 -0) </details> ### 📄 Description ## Problem NAT traversal tools can publish a changing public UDP port through DNS SRV, but the Apple client currently resolves only the address portion of a fixed `host:port` endpoint. An updated A/AAAA record cannot communicate a changed port, so users must edit the peer configuration when that port changes. ## Behavior Add explicit, opt-in SRV discovery in peer configurations: ```ini Endpoint = srv://_wireguard._udp.vpn.example.com ``` For example: ```dns _wireguard._udp.vpn.example.com. 300 IN SRV 10 10 9783 endpoint.example.com. endpoint.example.com. 300 IN A 192.0.2.1 ``` The client discovers the target and UDP port, then uses the existing address resolver. Existing `hostname:port`, IPv4 and bracketed IPv6 endpoints retain their fixed-port behavior. Configuration export preserves the SRV URL; only a resolved numeric endpoint is sent to the backend. The implementation: - Uses Apple's system DNS-SD API with a five-second bounded SRV query, without adding a third-party resolver or hard-coded DNS server. - Orders records by RFC 2782 priority and weight, tries the next record when a target's address lookup fails, and treats a root target (`.`) as unavailable. It validates the uncompressed SRV RDATA and rejects malformed or ambiguous endpoint URLs. - Refreshes explicitly opted-in peers on satisfied network-path updates and approximately every 60 seconds while the backend is running. Resolver caching and DNS TTLs still apply. - Keeps the last working endpoint on a refresh error. Unchanged DNS answers do not overwrite endpoint roaming learned by the backend. Changed IP addresses also update the excluded routes; port-only changes do not restart the tunnel. - Updates the editor highlighter, English validation message, Xcode source membership and README. This is an Apple-client configuration extension, not a change to the WireGuard wire protocol or to stock `wg-quick`. The configured peer public key remains unchanged. DNS must be reachable before connection and during refresh; a DNS server accessible only through a broken tunnel cannot bootstrap discovery. Address-lookup failover is covered; handshake-based target failover is outside this change. ## Validation - 16 deterministic SRV tests pass on macOS: endpoint parsing/round trips, fixed-endpoint compatibility, malformed/truncated/compressed RDATA, unavailable services, priority/weight ordering, target-address fallback, port changes, retaining cached endpoints on errors, and avoiding unnecessary roaming resets. - An additional opt-in live DNS-SD integration test passed on a macOS runner using `_sip._udp.sip.linphone.org`; it queried SRV through the system resolver and resolved the discovered target and port. Normal CI skips this network-dependent test unless a record name is supplied through `workflow_dispatch`. - The complete WireGuardKit adapter type-checks against both the macOS SDK and the iOS simulator SDK. - The C editor-highlighter regression test passes locally with AddressSanitizer/UndefinedBehaviorSanitizer and in macOS CI. - No signed iOS/macOS application build or physical-device tunnel test has been performed. The focused test runner avoids linking the Go backend, so tests do not require Go build artifacts or signing credentials. An initial run of the existing complete test suite also exposed an unrelated failure in `HandshakeFreshnessEvaluatorTests.testLatestHandshakeOlderThanCutoffIsNotFresh`: the existing implementation ignores `cutoffDate`, while that test expects it to be enforced. Those upstream files are unchanged; the added workflow runs the focused SRV suite rather than changing handshake semantics in this PR. CI with the live system-resolver test: https://github.com/cubatic45/amneziawg-apple/actions/runs/41274693303 --- <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/amneziawg-apple#52
No description provided.