fix(amneziawg): honor inbound listen when binding UDP socket (#6461)

* fix(amneziawg): honor inbound listen when binding UDP socket

AmneziaWG inbounds ignored the listen field and always opened
awgconn.NewDefaultBind(), so multi-IP hosts replied from the primary
address and handshakes to a secondary IP never completed (#6367).

Carry Inbound.Listen on amneziawg.Instance, open a Bind pinned to that
address (wildcard when empty/0.0.0.0/::), and include listen in
addressFingerprint so edits rebuild the Device.

Fixes #6367

* fix(amneziawg): fall back to wildcard when listen is unusable

Invalid or non-local listen values no longer hard-fail inbound startup;
treat ::0/[::0] as wildcards and normalize listen in the bind fingerprint.

* fix(amneziawg): use ListenConfig.ListenPacket for noctx

---------

Co-authored-by: mrchatam <mrchatam@users.noreply.github.com>
Co-authored-by: mrchatam <287639636+mrchatam@users.noreply.github.com>
This commit is contained in:
authored and GitHub committed 2026-09-12 11:11:02 +02:00 Unverified
1 parent 22763fe8f6
commit 7a41c59494
10 files changed
+379 -17

No files matched your search

+1
View File
@@ -63,6 +63,7 @@ func InstanceFromInbound(ib *model.Inbound) (Instance, bool) {
Tag: ib.Tag,
InterfaceName: interfaceNameForID(ib.Id),
ListenPort: ib.Port,
Listen: ib.Listen,
PrivateKey: server.PrivateKey,
PublicKey: server.PublicKey,
Address: addresses,
+4 -1
View File
@@ -32,7 +32,7 @@ func TestInstanceFromInboundParsesEnabledPeers(t *testing.T) {
{Email: "c@x", Enable: true, PublicKey: "", AllowedIPs: []string{"10.8.1.4/32"}}, // no key: skipped
{Email: "d@x", Enable: true, PublicKey: "pubD", AllowedIPs: nil}, // no address: skipped
})
ib := &model.Inbound{Id: 7, Tag: "awg-tag", Protocol: model.AmneziaWG, Port: 51820, Settings: settings}
ib := &model.Inbound{Id: 7, Tag: "awg-tag", Protocol: model.AmneziaWG, Port: 51820, Listen: "203.0.113.10", Settings: settings}
inst, ok := InstanceFromInbound(ib)
if !ok {
@@ -41,6 +41,9 @@ func TestInstanceFromInboundParsesEnabledPeers(t *testing.T) {
if inst.Id != 7 || inst.Tag != "awg-tag" || inst.ListenPort != 51820 {
t.Fatalf("instance identity not carried over: %+v", inst)
}
if inst.Listen != "203.0.113.10" {
t.Fatalf("Listen = %q, want inbound listen carried through", inst.Listen)
}
if inst.InterfaceName != "awg7" {
t.Fatalf("InterfaceName = %q, want awg7", inst.InterfaceName)
}
+5 -2
View File
@@ -75,8 +75,11 @@ type Instance struct {
Tag string
InterfaceName string
ListenPort int
PrivateKey string
PublicKey string
// Listen is an optional host bind address (e.g. "203.0.113.10").
// Empty/wildcard keeps dual-stack StdNetBind; a real IP pins the UDP socket.
Listen string
PrivateKey string
PublicKey string
// Address holds the interface's own tunnel address(es), e.g. "10.8.1.1/24".
// Carries both the IPv4 and (when enabled) IPv6 server address.
Address []string
Loaded 3 of 10 files, more files were not shown because too many files have changed in this diff. Show more