Skip to content

wireguard: refresh FQDN peer endpoints on handshake retry - #4366

Open
tinymins wants to merge 1 commit into
SagerNet:stablefrom
tinymins:fix/wireguard-ddns-refresh
Open

wireguard: refresh FQDN peer endpoints on handshake retry#4366
tinymins wants to merge 1 commit into
SagerNet:stablefrom
tinymins:fix/wireguard-ddns-refresh

Conversation

@tinymins

Copy link
Copy Markdown

WireGuard peer endpoint domains are currently resolved only during startup. When a DDNS record changes, the device keeps sending handshakes to the stale address until sing-box is restarted.

This change listens for wireguard-go handshake retry events and then:

  • performs a fresh DNS lookup with the configured resolver and cache disabled;
  • updates changed peer endpoints in place through minimal UAPI update_only commands;
  • coalesces concurrent events and limits refreshes to one every 10 seconds;
  • keeps literal-IP peers and healthy/idle tunnels unchanged.

FQDN peers no longer use the fixed-remote connected bind optimization, so an updated address takes effect without recreating the WireGuard device or TUN.

This supersedes the approach in #3486: refreshes are driven by actual WireGuard handshake failure rather than generic connection errors, and cached DNS answers are explicitly bypassed.

Tests:

  • go test -race ./transport/wireguard ./protocol/wireguard
  • go test -tags "$(cat release/DEFAULT_BUILD_TAGS_OTHERS)" -ldflags "$(cat release/LDFLAGS)" ./...
  • Windows amd64 build with release/DEFAULT_BUILD_TAGS_WINDOWS
  • Windows sing-box check against the production configuration

@tinymins
tinymins marked this pull request as ready for review July 30, 2026 14:17
@nekohasekai
nekohasekai force-pushed the stable branch 3 times, most recently from 5415bf0 to 17ec3c7 Compare August 3, 2026 11:20
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.

1 participant