[PR #210] conn: fix truncated IPv6 destination after an IPv4 send #208

Open
opened 2026-11-08 06:06:23 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/amnezia-vpn/amneziawg-go/pull/210
Author: @und3f1ned
Created: 11/7/2026
Status: 🔄 Open

Base: master ← Head: fix/ipv6-send-truncated-dst


📝 Commits (1)

  • 9e05616 conn: fix truncated IPv6 destination after an IPv4 send

📊 Changes

1 file changed (+6 additions, -2 deletions)

View changed files

📝 conn/bind_std.go (+6 -2)

📄 Description

Problem

On a dual-stack server, StdNetBind.Send sends replies to IPv6 peers to a truncated address — the first 4 bytes of the peer address, the rest zero (or stale) — as soon as IPv4 peers are also sending traffic. The IPv6 peer's handshake never completes: e.g. an initiation from 2001:db8:1:2::3 is answered to 2001:db8::.

Cause

ua comes from udpAddrPool. The IPv4 branch reslices ua.IP to 4 bytes, and the address goes back to the pool that way. The IPv6 branch then runs copy(ua.IP, as16[:]) before ua.IP = ua.IP[:16], so copy writes only len(ua.IP) = 4 bytes.

Without IPv4 traffic the pooled address keeps its 16-byte length and IPv6 works, so the failure depends on load. The same code is in WireGuard/wireguard-go master.

Fix

Restore the slice length before copying, in both branches.

Testing

  • Reproduced with v3.1.20260828 in Docker: a server with one IPv4 peer under continuous ping and one IPv6 peer. With the unpatched binary the server logs Sending handshake response for the IPv6 peer, but tcpdump shows the response going to <first 4 bytes>:: and the handshake never completes. With the patch the IPv6 handshake completes and traffic flows.
  • Running in production on a dual-stack server with IPv4 routers and an iOS client (AmneziaVPN 5.1.0.6) over IPv6.
  • gofmt, go vet ./conn/, go build ./... and go test ./conn/... pass (Go 1.25.12).

🤖 Generated with Claude Code


🔄 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-go/pull/210 **Author:** [@und3f1ned](https://github.com/und3f1ned) **Created:** 11/7/2026 **Status:** 🔄 Open **Base:** `master` ← **Head:** `fix/ipv6-send-truncated-dst` --- ### 📝 Commits (1) - [`9e05616`](https://github.com/amnezia-vpn/amneziawg-go/commit/9e05616f105d05a752e203a45bfa6882840ec5bb) conn: fix truncated IPv6 destination after an IPv4 send ### 📊 Changes **1 file changed** (+6 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `conn/bind_std.go` (+6 -2) </details> ### 📄 Description ## Problem On a dual-stack server, `StdNetBind.Send` sends replies to IPv6 peers to a truncated address — the first 4 bytes of the peer address, the rest zero (or stale) — as soon as IPv4 peers are also sending traffic. The IPv6 peer's handshake never completes: e.g. an initiation from `2001:db8:1:2::3` is answered to `2001:db8::`. ## Cause `ua` comes from `udpAddrPool`. The IPv4 branch reslices `ua.IP` to 4 bytes, and the address goes back to the pool that way. The IPv6 branch then runs `copy(ua.IP, as16[:])` **before** `ua.IP = ua.IP[:16]`, so `copy` writes only `len(ua.IP)` = 4 bytes. Without IPv4 traffic the pooled address keeps its 16-byte length and IPv6 works, so the failure depends on load. The same code is in WireGuard/wireguard-go `master`. ## Fix Restore the slice length before copying, in both branches. ## Testing - Reproduced with `v3.1.20260828` in Docker: a server with one IPv4 peer under continuous ping and one IPv6 peer. With the unpatched binary the server logs `Sending handshake response` for the IPv6 peer, but tcpdump shows the response going to `<first 4 bytes>::` and the handshake never completes. With the patch the IPv6 handshake completes and traffic flows. - Running in production on a dual-stack server with IPv4 routers and an iOS client (AmneziaVPN 5.1.0.6) over IPv6. - `gofmt`, `go vet ./conn/`, `go build ./...` and `go test ./conn/...` pass (Go 1.25.12). 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <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-go#208
No description provided.