fix(amneziawg): drop a removed client's flows before its address is reused

Removing or re-keying a client reconfigured the device in place but left
its TCP and UDP flows standing, and withdrawing a port forward stopped
only new connections. The next client given the same tunnel address
inherited those flows: it could read what outside hosts sent to the
former client and write back into those connections.

After an in-place reconfigure, every stack endpoint and UDP relay
session pinned to an address whose peer was removed or changed is
aborted, and closing a port forward cuts the connections it is relaying.
This commit is contained in:
MHSanaei
2026-10-31 15:10:32 +01:00
parent 0ea11e1643
commit ac896a9f95
6 changed files with 195 additions and 16 deletions
+14
View File
@@ -226,6 +226,20 @@ func enablePromiscuousRouting(gstack *stack.Stack) {
gstack.SetSpoofing(1, true)
}
// endpointRemoteAddr returns the address ep is connected to; false for an
// endpoint that has none (listening, unconnected).
func endpointRemoteAddr(ep stack.TransportEndpoint) (netip.Addr, bool) {
tep, ok := ep.(tcpip.Endpoint)
if !ok {
return netip.Addr{}, false
}
info, ok := tep.Info().(*stack.TransportEndpointInfo)
if !ok || info.ID.RemoteAddress.Len() == 0 {
return netip.Addr{}, false
}
return addrFromTcpip(info.ID.RemoteAddress), true
}
// addrFromTcpip converts a gVisor tcpip.Address to netip.Addr.
func addrFromTcpip(a tcpip.Address) netip.Addr {
if a.Len() == 4 {