From 3686446919b515cce0b8e248e8440eef2ccafd3f Mon Sep 17 00:00:00 2001 From: yaling888 <73897884+yaling888@users.noreply.github.com> Date: Fri, 12 Nov 2021 11:05:02 +0800 Subject: [PATCH] Fix: resolver dial context options --- dns/client.go | 11 ++++++----- dns/util.go | 7 ++++--- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/dns/client.go b/dns/client.go index 31a09d85..56ff1998 100644 --- a/dns/client.go +++ b/dns/client.go @@ -48,15 +48,16 @@ func (c *client) ExchangeContext(ctx context.Context, m *D.Msg) (*D.Msg, error) network = "tcp" } + options := []dialer.Option{} + if c.iface != "" { + options = append(options, dialer.WithInterface(c.iface)) + } + var conn net.Conn if c.proxyAdapter == "" { - options := []dialer.Option{} - if c.iface != "" { - options = append(options, dialer.WithInterface(c.iface)) - } conn, err = dialer.DialContext(ctx, network, net.JoinHostPort(ip.String(), c.port), options...) } else { - conn, err = dialContextWithProxyAdapter(ctx, c.proxyAdapter, network, ip, c.port) + conn, err = dialContextWithProxyAdapter(ctx, c.proxyAdapter, network, ip, c.port, options...) } if err != nil { diff --git a/dns/util.go b/dns/util.go index fd32b5c6..59eef1de 100644 --- a/dns/util.go +++ b/dns/util.go @@ -8,6 +8,7 @@ import ( "time" "github.com/Dreamacro/clash/common/cache" + "github.com/Dreamacro/clash/component/dialer" C "github.com/Dreamacro/clash/constant" "github.com/Dreamacro/clash/log" "github.com/Dreamacro/clash/tunnel" @@ -128,7 +129,7 @@ func (wpc *wrapPacketConn) RemoteAddr() net.Addr { return wpc.rAddr } -func dialContextWithProxyAdapter(ctx context.Context, adapterName string, network string, dstIP net.IP, port string) (net.Conn, error) { +func dialContextWithProxyAdapter(ctx context.Context, adapterName string, network string, dstIP net.IP, port string, opts ...dialer.Option) (net.Conn, error) { adapter, ok := tunnel.Proxies()[adapterName] if !ok { return nil, fmt.Errorf("proxy adapter [%s] not found", adapterName) @@ -156,7 +157,7 @@ func dialContextWithProxyAdapter(ctx context.Context, adapterName string, networ } if networkType == C.UDP { - packetConn, err := adapter.ListenPacketContext(ctx, metadata) + packetConn, err := adapter.ListenPacketContext(ctx, metadata, opts...) if err != nil { return nil, err } @@ -167,5 +168,5 @@ func dialContextWithProxyAdapter(ctx context.Context, adapterName string, networ }, nil } - return adapter.DialContext(ctx, metadata) + return adapter.DialContext(ctx, metadata, opts...) }