From bf619d858615ebce70e58f931a12bde29ec8ea5e Mon Sep 17 00:00:00 2001 From: wwqgtxx Date: Fri, 22 Sep 2023 23:33:24 +0800 Subject: [PATCH] fix: socks5 udp not working on loopback --- adapter/outbound/direct.go | 3 ++- adapter/outbound/socks5.go | 2 +- dns/util.go | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/adapter/outbound/direct.go b/adapter/outbound/direct.go index 720f96f9..75e999a6 100644 --- a/adapter/outbound/direct.go +++ b/adapter/outbound/direct.go @@ -3,6 +3,7 @@ package outbound import ( "context" "errors" + "net/netip" N "github.com/Dreamacro/clash/common/net" "github.com/Dreamacro/clash/component/dialer" @@ -40,7 +41,7 @@ func (d *Direct) ListenPacketContext(ctx context.Context, metadata *C.Metadata, } metadata.DstIP = ip } - pc, err := dialer.ListenPacket(ctx, dialer.ParseNetwork("udp", metadata.DstIP), "", d.Base.DialOptions(opts...)...) + pc, err := dialer.NewDialer(d.Base.DialOptions(opts...)...).ListenPacket(ctx, "udp", "", netip.AddrPortFrom(metadata.DstIP, metadata.DstPort)) if err != nil { return nil, err } diff --git a/adapter/outbound/socks5.go b/adapter/outbound/socks5.go index d857172e..864500c5 100644 --- a/adapter/outbound/socks5.go +++ b/adapter/outbound/socks5.go @@ -156,7 +156,7 @@ func (ss *Socks5) ListenPacketContext(ctx context.Context, metadata *C.Metadata, bindUDPAddr.IP = serverAddr.IP } - pc, err := dialer.ListenPacket(ctx, dialer.ParseNetwork("udp", bindUDPAddr.AddrPort().Addr()), "", ss.Base.DialOptions(opts...)...) + pc, err := cDialer.ListenPacket(ctx, "udp", "", bindUDPAddr.AddrPort()) if err != nil { return } diff --git a/dns/util.go b/dns/util.go index 08daadbd..29de4e2a 100644 --- a/dns/util.go +++ b/dns/util.go @@ -290,7 +290,7 @@ func listenPacket(ctx context.Context, proxyAdapter C.ProxyAdapter, proxyName st DstPort: uint16(uintPort), } if proxyAdapter == nil { - return dialer.ListenPacket(ctx, dialer.ParseNetwork(network, dstIP), "", opts...) + return dialer.NewDialer(opts...).ListenPacket(ctx, dialer.ParseNetwork(network, dstIP), "", netip.AddrPortFrom(metadata.DstIP, metadata.DstPort)) } if !proxyAdapter.SupportUDP() {