From c6efa74a6b8fe277eae579b101f9e4e70ec38823 Mon Sep 17 00:00:00 2001 From: yaling888 <73897884+yaling888@users.noreply.github.com> Date: Fri, 25 Mar 2022 03:42:46 +0800 Subject: [PATCH] Fix: udp 4In6 of tun system stack --- listener/tun/ipstack/system/mars/nat/udp.go | 4 ++-- listener/tun/ipstack/system/stack.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/listener/tun/ipstack/system/mars/nat/udp.go b/listener/tun/ipstack/system/mars/nat/udp.go index b28614a5..4e7a4f9e 100644 --- a/listener/tun/ipstack/system/mars/nat/udp.go +++ b/listener/tun/ipstack/system/mars/nat/udp.go @@ -74,8 +74,8 @@ func (u *UDP) WriteTo(buf []byte, local net.Addr, remote net.Addr) (int, error) srcIP, _ := netip.AddrFromSlice(srcAddr.IP) dstIp, _ := netip.AddrFromSlice(dstAddr.IP) - srcAddrPort := netip.AddrPortFrom(srcIP, uint16(srcAddr.Port)) - dstAddrPort := netip.AddrPortFrom(dstIp, uint16(dstAddr.Port)) + srcAddrPort := netip.AddrPortFrom(srcIP.Unmap(), uint16(srcAddr.Port)) + dstAddrPort := netip.AddrPortFrom(dstIp.Unmap(), uint16(dstAddr.Port)) if !srcAddrPort.Addr().Is4() || !dstAddrPort.Addr().Is4() { return 0, net.InvalidAddrError("invalid ip version") diff --git a/listener/tun/ipstack/system/stack.go b/listener/tun/ipstack/system/stack.go index 01e4c952..ad3f465d 100644 --- a/listener/tun/ipstack/system/stack.go +++ b/listener/tun/ipstack/system/stack.go @@ -176,7 +176,7 @@ func New(device device.Device, dnsHijack []netip.AddrPort, tunAddress netip.Pref local: lAddr, data: raw, writeBack: func(b []byte, addr net.Addr) (int, error) { - return stack.UDP().WriteTo(b, addr, lAddr) + return stack.UDP().WriteTo(b, rAddr, lAddr) }, drop: func() { pool.Put(buf)