[PR #6461] [MERGED] fix(amneziawg): honor inbound listen when binding UDP socket #6282

Closed
opened 2026-11-02 04:07:39 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/MHSanaei/3x-ui/pull/6461
Author: @mrchatam
Created: 9/11/2026
Status: ✅ Merged
Merged: 9/12/2026
Merged by: @MHSanaei

Base: main ← Head: fix/amneziawg-listen-bind


📝 Commits (3)

  • b97fdfb fix(amneziawg): honor inbound listen when binding UDP socket
  • 1addc08 fix(amneziawg): fall back to wildcard when listen is unusable
  • 922fa32 fix(amneziawg): use ListenConfig.ListenPacket for noctx

📊 Changes

10 files changed (+379 additions, -17 deletions)

View changed files

📝 internal/amneziawg/instance.go (+1 -0)
📝 internal/amneziawg/instance_test.go (+4 -1)
📝 internal/amneziawg/types.go (+5 -2)
📝 internal/amneziawgnet/client_device.go (+2 -1)
📝 internal/amneziawgnet/device.go (+2 -1)
📝 internal/amneziawgnet/manager.go (+4 -4)
➕ internal/amneziawgnet/pinned_bind.go (+188 -0)
➕ internal/amneziawgnet/pinned_bind_test.go (+160 -0)
📝 internal/amneziawgnet/resolving_bind.go (+4 -4)
📝 internal/amneziawgnet/resolving_bind_test.go (+9 -4)

📄 Description

Summary

  • AmneziaWG inbounds ignored listen and always bound 0.0.0.0/:: via awgconn.NewDefaultBind(), so multi-IP hosts replied from the primary address and clients connecting to a secondary IP never completed the handshake.
  • Carry Inbound.Listen on amneziawg.Instance, open a pinnedBind for non-wildcard listen values (empty / 0.0.0.0 / :: keep the default bind), and include listen in addressFingerprint so edits rebuild the Device instead of hot-applying an unchangeable Bind.

Test plan

  • go test ./internal/amneziawg/ ./internal/amneziawgnet/
  • Create AmneziaWG inbound with listen: SECONDARY_IP, add a client, confirm ss -lunp shows the socket bound to that address only
  • Client handshake to SECONDARY_IP:port completes; replies source from SECONDARY_IP
  • Empty / 0.0.0.0 listen still binds all addresses as before
  • Editing listen rebuilds the device (fingerprint change)

Fixes #6367


🔄 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/MHSanaei/3x-ui/pull/6461 **Author:** [@mrchatam](https://github.com/mrchatam) **Created:** 9/11/2026 **Status:** ✅ Merged **Merged:** 9/12/2026 **Merged by:** [@MHSanaei](https://github.com/MHSanaei) **Base:** `main` ← **Head:** `fix/amneziawg-listen-bind` --- ### 📝 Commits (3) - [`b97fdfb`](https://github.com/MHSanaei/3x-ui/commit/b97fdfb962eed9b76a3e79f016a42edf62f2890b) fix(amneziawg): honor inbound listen when binding UDP socket - [`1addc08`](https://github.com/MHSanaei/3x-ui/commit/1addc0804a86ecd9bb5ac8f1f5b873ff0700c035) fix(amneziawg): fall back to wildcard when listen is unusable - [`922fa32`](https://github.com/MHSanaei/3x-ui/commit/922fa32dd76baaa2407d925554a97f18551ecf33) fix(amneziawg): use ListenConfig.ListenPacket for noctx ### 📊 Changes **10 files changed** (+379 additions, -17 deletions) <details> <summary>View changed files</summary> 📝 `internal/amneziawg/instance.go` (+1 -0) 📝 `internal/amneziawg/instance_test.go` (+4 -1) 📝 `internal/amneziawg/types.go` (+5 -2) 📝 `internal/amneziawgnet/client_device.go` (+2 -1) 📝 `internal/amneziawgnet/device.go` (+2 -1) 📝 `internal/amneziawgnet/manager.go` (+4 -4) ➕ `internal/amneziawgnet/pinned_bind.go` (+188 -0) ➕ `internal/amneziawgnet/pinned_bind_test.go` (+160 -0) 📝 `internal/amneziawgnet/resolving_bind.go` (+4 -4) 📝 `internal/amneziawgnet/resolving_bind_test.go` (+9 -4) </details> ### 📄 Description ## Summary - AmneziaWG inbounds ignored `listen` and always bound `0.0.0.0`/`::` via `awgconn.NewDefaultBind()`, so multi-IP hosts replied from the primary address and clients connecting to a secondary IP never completed the handshake. - Carry `Inbound.Listen` on `amneziawg.Instance`, open a `pinnedBind` for non-wildcard listen values (empty / `0.0.0.0` / `::` keep the default bind), and include listen in `addressFingerprint` so edits rebuild the Device instead of hot-applying an unchangeable Bind. ## Test plan - [x] `go test ./internal/amneziawg/ ./internal/amneziawgnet/` - [ ] Create AmneziaWG inbound with `listen: SECONDARY_IP`, add a client, confirm `ss -lunp` shows the socket bound to that address only - [ ] Client handshake to `SECONDARY_IP:port` completes; replies source from `SECONDARY_IP` - [ ] Empty / `0.0.0.0` listen still binds all addresses as before - [ ] Editing listen rebuilds the device (fingerprint change) Fixes #6367 --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-02 04:07:39 +07:00
Sign in to join this conversation.
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
MHSanaei/3x-ui#6282
No description provided.