From eceea72a567c82cc222e1cff1f8ccfdcb5a45498 Mon Sep 17 00:00:00 2001 From: wwqgtxx Date: Wed, 26 Apr 2023 15:57:25 +0800 Subject: [PATCH] fix: tunnel udp panic --- adapter/outbound/singmux.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/adapter/outbound/singmux.go b/adapter/outbound/singmux.go index cf18a6f3..acfdfe99 100644 --- a/adapter/outbound/singmux.go +++ b/adapter/outbound/singmux.go @@ -2,12 +2,14 @@ package outbound import ( "context" + "errors" "net" "runtime" CN "github.com/Dreamacro/clash/common/net" "github.com/Dreamacro/clash/component/dialer" "github.com/Dreamacro/clash/component/proxydialer" + "github.com/Dreamacro/clash/component/resolver" C "github.com/Dreamacro/clash/constant" mux "github.com/sagernet/sing-mux" @@ -73,7 +75,17 @@ func (s *SingMux) ListenPacketContext(ctx context.Context, metadata *C.Metadata, } options := s.base.DialOptions(opts...) s.dialer.dialer = dialer.NewDialer(options...) - pc, err := s.client.ListenPacket(ctx, M.ParseSocksaddr(metadata.RemoteAddress())) + + // sing-mux use stream-oriented udp with a special address, so we need a net.UDPAddr + if !metadata.Resolved() { + ip, err := resolver.ResolveIP(ctx, metadata.Host) + if err != nil { + return nil, errors.New("can't resolve ip") + } + metadata.DstIP = ip + } + + pc, err := s.client.ListenPacket(ctx, M.SocksaddrFromNet(metadata.UDPAddr())) if err != nil { return nil, err }