[GH-ISSUE #3374] macOS: NAT64-synthesized IPv6 endpoint passed to wireguard-go without brackets → IPC error -22, AmneziaWG can't connect (DNS64 networks) #3235

Open
opened 2026-11-07 17:57:59 +07:00 by bsakaguchi · 1 comment
Owner

Originally created by @Arty-Ant on GitHub (Nov 2, 2026).
Original GitHub issue: https://github.com/amnezia-vpn/amnezia-client/issues/3374

Describe the bug
On macOS, when an AmneziaWG server is added by hostname (A record only, no AAAA) and the Mac is on a network with DNS64/NAT64 (e.g. mobile hotspot of a Russian mobile operator), the hostname resolves to a NAT64-synthesized address 64:ff9b::/96. The macOS daemon then passes it to wireguard-go as endpoint=<ipv6>:<port> without square brackets, wireguard-go rejects it with IPC error -22, peer creation fails and the connection is immediately dropped (the GUI may sit in "Preparing"/"Connecting").

The same server added by IPv4 literal works on the same network. Android client works with the hostname on the same network. Same root cause as the Linux issue #2607, but on macOS and triggered by NAT64 synthesis rather than a real AAAA record.

Root cause (from source, dev @ 7f9b7db)
client/platforms/macos/daemon/wireguardutilsmacos.cpp, WireguardUtilsMacos::updatePeer():

if (!config.m_serverIpv4AddrIn.isNull()) {
    out << "endpoint=" << config.m_serverIpv4AddrIn << ":";      // <- holds 64:ff9b::… here, no brackets
} else if (!config.m_serverIpv6AddrIn.isNull()) {
    out << "endpoint=[" << config.m_serverIpv6AddrIn << "]:";

The resolved hostname result ends up in m_serverIpv4AddrIn even when it is an IPv6 (NAT64) address. Suggested fix: bracket the address whenever it contains : (or put IPv6 results into m_serverIpv6AddrIn), and/or prefer A records when resolving the endpoint host.

To Reproduce

  1. Add a self-hosted AmneziaWG server by hostname that has only an A record (e.g. relay.example.net → 203.0.113.10).
  2. Connect the Mac to a DNS64/NAT64 network (mobile hotspot).
  3. Click Connect → immediately disconnected.

Service log (/private/var/log/AmneziaVPN/AmneziaVPN-service.log, key/addresses anonymized)

MacosRouteMonitor : Adding exclusion route for 64:ff9b::cb00:710a/128
WireguardUtilsMacos : Configuring peer <pubkey> via 64:ff9b::cb00:710a
WireguardGo : ERROR: (utun4) IPC error -22: failed to set endpoint 64:ff9b::cb00:710a:5275: invalid ip:port "64:ff9b::cb00:710a:5275", IPv6 addresses must be surrounded by square brackets
WireguardUtilsMacos : Peer configuration failed: Unknown error: -22
Daemon : Peer creation failed.
DaemonLocalServerConnection : Failed to activate the interface

Expected behavior
Connection succeeds (bracketed endpoint [64:ff9b::cb00:710a]:5275), or the client uses the A record.

Environment

  • AmneziaVPN 5.0.3.0 (de93650), macOS Sequoia 15.7.5 (x86_64)
  • Protocol: AmneziaWG, self-hosted server added via hostname
Originally created by @Arty-Ant on GitHub (Nov 2, 2026). Original GitHub issue: https://github.com/amnezia-vpn/amnezia-client/issues/3374 **Describe the bug** On macOS, when an AmneziaWG server is added by **hostname** (A record only, no AAAA) and the Mac is on a network with **DNS64/NAT64** (e.g. mobile hotspot of a Russian mobile operator), the hostname resolves to a NAT64-synthesized address `64:ff9b::/96`. The macOS daemon then passes it to wireguard-go as `endpoint=<ipv6>:<port>` **without square brackets**, wireguard-go rejects it with IPC error -22, peer creation fails and the connection is immediately dropped (the GUI may sit in "Preparing"/"Connecting"). The same server added by **IPv4 literal** works on the same network. Android client works with the hostname on the same network. Same root cause as the Linux issue #2607, but on macOS and triggered by NAT64 synthesis rather than a real AAAA record. **Root cause (from source, dev @ 7f9b7db)** `client/platforms/macos/daemon/wireguardutilsmacos.cpp`, `WireguardUtilsMacos::updatePeer()`: ```cpp if (!config.m_serverIpv4AddrIn.isNull()) { out << "endpoint=" << config.m_serverIpv4AddrIn << ":"; // <- holds 64:ff9b::… here, no brackets } else if (!config.m_serverIpv6AddrIn.isNull()) { out << "endpoint=[" << config.m_serverIpv6AddrIn << "]:"; ``` The resolved hostname result ends up in `m_serverIpv4AddrIn` even when it is an IPv6 (NAT64) address. Suggested fix: bracket the address whenever it contains `:` (or put IPv6 results into `m_serverIpv6AddrIn`), and/or prefer A records when resolving the endpoint host. **To Reproduce** 1. Add a self-hosted AmneziaWG server by hostname that has only an A record (e.g. `relay.example.net` → `203.0.113.10`). 2. Connect the Mac to a DNS64/NAT64 network (mobile hotspot). 3. Click Connect → immediately disconnected. **Service log** (`/private/var/log/AmneziaVPN/AmneziaVPN-service.log`, key/addresses anonymized) ``` MacosRouteMonitor : Adding exclusion route for 64:ff9b::cb00:710a/128 WireguardUtilsMacos : Configuring peer <pubkey> via 64:ff9b::cb00:710a WireguardGo : ERROR: (utun4) IPC error -22: failed to set endpoint 64:ff9b::cb00:710a:5275: invalid ip:port "64:ff9b::cb00:710a:5275", IPv6 addresses must be surrounded by square brackets WireguardUtilsMacos : Peer configuration failed: Unknown error: -22 Daemon : Peer creation failed. DaemonLocalServerConnection : Failed to activate the interface ``` **Expected behavior** Connection succeeds (bracketed endpoint `[64:ff9b::cb00:710a]:5275`), or the client uses the A record. **Environment** - AmneziaVPN 5.0.3.0 (de93650), macOS Sequoia 15.7.5 (x86_64) - Protocol: AmneziaWG, self-hosted server added via hostname
Author
Owner

@icntswm commented on GitHub (Nov 5, 2026):

I can reproduce the same missing-brackets error on macOS, including with a literal IPv6 endpoint rather than a hostname or a DNS64-synthesized address.

Environment:

  • AmneziaVPN 5.0.3.0 (de93650, as reported in the log)
  • macOS Tahoe 26.6.2, arm64
  • Self-hosted AmneziaWG, configuration imported from a .conf file

The imported file has a correctly bracketed endpoint, for example:

Endpoint = [2001:db8:1234:5678::]:34541

The address above is a documentation placeholder. The service nevertheless passes the real address to the backend without brackets, producing:

IPC error -22: failed to set endpoint 2001:db8:1234:5678:::34541: invalid ip:port "2001:db8:1234:5678:::34541", IPv6 addresses must be surrounded by square brackets
Peer configuration failed: Unknown error: -22
Peer creation failed.
Failed to activate the interface

The UI briefly starts connecting and immediately returns to disconnected. Importing the correctly formatted file as a new profile does not help.

IPv6 was initially disabled for Wi-Fi on this Mac. After enabling automatic IPv6 configuration, a direct TCP connection to the server over IPv6 succeeded, but the app still failed with the error above. The same server and profile then worked on this Mac using the bundled amneziawg-go backend with command-line tools (amneziawg-tools and the Darwin quick script), bypassing the app's peer configuration path. The server also works over IPv6 from Android.

This suggests the issue also affects literal IPv6 endpoints, not only DNS64/NAT64 resolution.

<!-- gh-comment-id:6646464687 --> @icntswm commented on GitHub (Nov 5, 2026): I can reproduce the same missing-brackets error on macOS, including with a literal IPv6 endpoint rather than a hostname or a DNS64-synthesized address. Environment: - AmneziaVPN 5.0.3.0 (`de93650`, as reported in the log) - macOS Tahoe 26.6.2, arm64 - Self-hosted AmneziaWG, configuration imported from a `.conf` file The imported file has a correctly bracketed endpoint, for example: ```ini Endpoint = [2001:db8:1234:5678::]:34541 ``` The address above is a documentation placeholder. The service nevertheless passes the real address to the backend without brackets, producing: ```text IPC error -22: failed to set endpoint 2001:db8:1234:5678:::34541: invalid ip:port "2001:db8:1234:5678:::34541", IPv6 addresses must be surrounded by square brackets Peer configuration failed: Unknown error: -22 Peer creation failed. Failed to activate the interface ``` The UI briefly starts connecting and immediately returns to disconnected. Importing the correctly formatted file as a new profile does not help. IPv6 was initially disabled for Wi-Fi on this Mac. After enabling automatic IPv6 configuration, a direct TCP connection to the server over IPv6 succeeded, but the app still failed with the error above. The same server and profile then worked on this Mac using the bundled `amneziawg-go` backend with command-line tools (`amneziawg-tools` and the Darwin quick script), bypassing the app's peer configuration path. The server also works over IPv6 from Android. This suggests the issue also affects literal IPv6 endpoints, not only DNS64/NAT64 resolution.
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#3235
No description provided.