From b01fe5d36487d2336c7393976c84e6f68ccf582d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=96=E7=95=8C?= Date: Sun, 2 Feb 2025 23:17:31 +0800 Subject: [PATCH] Fix override address --- route/conn.go | 6 ++++++ route/route.go | 2 +- route/rule/rule_action.go | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/route/conn.go b/route/conn.go index 0ffbbd6a..85986922 100644 --- a/route/conn.go +++ b/route/conn.go @@ -191,6 +191,12 @@ func (m *ConnectionManager) NewPacketConnection(ctx context.Context, this N.Dial if natConn, loaded := common.Cast[bufio.NATPacketConn](conn); loaded { natConn.UpdateDestination(destinationAddress) } + } else if metadata.RouteOriginalDestination.IsValid() && metadata.RouteOriginalDestination != metadata.Destination { + if metadata.UDPDisableDomainUnmapping { + remotePacketConn = bufio.NewUnidirectionalNATPacketConn(bufio.NewPacketConn(remotePacketConn), metadata.Destination, metadata.RouteOriginalDestination) + } else { + remotePacketConn = bufio.NewNATPacketConn(bufio.NewPacketConn(remotePacketConn), metadata.Destination, metadata.RouteOriginalDestination) + } } var udpTimeout time.Duration if metadata.UDPTimeout > 0 { diff --git a/route/route.go b/route/route.go index b791964d..808479b1 100644 --- a/route/route.go +++ b/route/route.go @@ -597,7 +597,7 @@ func (r *Router) actionSniff( return } } else { - if !metadata.Destination.Addr.IsGlobalUnicast() { + if !metadata.Destination.Addr.IsGlobalUnicast() && !metadata.RouteOriginalDestination.IsValid() { metadata.Destination = destination } if len(packetBuffers) > 0 { diff --git a/route/rule/rule_action.go b/route/rule/rule_action.go index 8e5cbd53..b4a47bf1 100644 --- a/route/rule/rule_action.go +++ b/route/rule/rule_action.go @@ -168,7 +168,7 @@ func (r *RuleActionRouteOptions) Type() string { func (r *RuleActionRouteOptions) Descriptions() []string { var descriptions []string if r.OverrideAddress.IsValid() { - descriptions = append(descriptions, F.ToString("override-address=", r.OverrideAddress.String())) + descriptions = append(descriptions, F.ToString("override-address=", r.OverrideAddress.AddrString())) } if r.OverridePort > 0 { descriptions = append(descriptions, F.ToString("override-port=", r.OverridePort))