From 32e52ce1eda7ddaa24e107a2f01e7a13a7552bcf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=96=E7=95=8C?= Date: Tue, 11 Mar 2025 14:12:59 +0800 Subject: [PATCH] Fix udp nat for fakeip --- route/conn.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/route/conn.go b/route/conn.go index 75c67a38..7b9f4a63 100644 --- a/route/conn.go +++ b/route/conn.go @@ -149,16 +149,15 @@ func (m *ConnectionManager) NewPacketConnection(ctx context.Context, this N.Dial } else { originDestination = metadata.Destination } - if metadata.Destination != M.SocksaddrFrom(destinationAddress, metadata.Destination.Port) { + if natConn, loaded := common.Cast[bufio.NATPacketConn](conn); loaded { + natConn.UpdateDestination(destinationAddress) + } else if metadata.Destination != M.SocksaddrFrom(destinationAddress, metadata.Destination.Port) { if metadata.UDPDisableDomainUnmapping { remotePacketConn = bufio.NewUnidirectionalNATPacketConn(bufio.NewPacketConn(remotePacketConn), M.SocksaddrFrom(destinationAddress, metadata.Destination.Port), originDestination) } else { remotePacketConn = bufio.NewNATPacketConn(bufio.NewPacketConn(remotePacketConn), M.SocksaddrFrom(destinationAddress, metadata.Destination.Port), originDestination) } } - if natConn, loaded := common.Cast[bufio.NATPacketConn](conn); loaded { - natConn.UpdateDestination(destinationAddress) - } } else if metadata.RouteOriginalDestination.IsValid() && metadata.RouteOriginalDestination != metadata.Destination { remotePacketConn = bufio.NewDestinationNATPacketConn(bufio.NewPacketConn(remotePacketConn), metadata.Destination, metadata.RouteOriginalDestination) }