mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-11-11 07:34:59 +03:00
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:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user