From 100f193a6a093a2416890af213b383f3e0940a55 Mon Sep 17 00:00:00 2001 From: gVisor bot Date: Mon, 13 Feb 2023 22:06:09 +0800 Subject: [PATCH] fix: tun udp with 4in6 ip --- tunnel/connection.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/tunnel/connection.go b/tunnel/connection.go index c63bab78..d8bd26c9 100644 --- a/tunnel/connection.go +++ b/tunnel/connection.go @@ -44,11 +44,12 @@ func handleUDPToLocal(packet C.UDPPacket, pc net.PacketConn, key string, oAddr, } fromUDPAddr := from.(*net.UDPAddr) - if fAddr.IsValid() { - fromAddr, _ := netip.AddrFromSlice(fromUDPAddr.IP) - fromAddr.Unmap() - if oAddr == fromAddr { - fromUDPAddr.IP = fAddr.AsSlice() + fromUDPAddr = &(*fromUDPAddr) // make a copy + if fromAddr, ok := netip.AddrFromSlice(fromUDPAddr.IP); ok { + if fAddr.IsValid() && (oAddr.Unmap() == fromAddr.Unmap()) { + fromUDPAddr.IP = fAddr.Unmap().AsSlice() + } else { + fromUDPAddr.IP = fromAddr.Unmap().AsSlice() } }