Fix: resolver dial context options

This commit is contained in:
gVisor bot 2021-11-12 11:05:02 +08:00
parent 24cadc4b3e
commit 46e51bfc86
2 changed files with 10 additions and 8 deletions

View File

@ -48,15 +48,16 @@ func (c *client) ExchangeContext(ctx context.Context, m *D.Msg) (*D.Msg, error)
network = "tcp" network = "tcp"
} }
options := []dialer.Option{}
if c.iface != "" {
options = append(options, dialer.WithInterface(c.iface))
}
var conn net.Conn var conn net.Conn
if c.proxyAdapter == "" { 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...) conn, err = dialer.DialContext(ctx, network, net.JoinHostPort(ip.String(), c.port), options...)
} else { } 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 { if err != nil {

View File

@ -8,6 +8,7 @@ import (
"time" "time"
"github.com/Dreamacro/clash/common/cache" "github.com/Dreamacro/clash/common/cache"
"github.com/Dreamacro/clash/component/dialer"
C "github.com/Dreamacro/clash/constant" C "github.com/Dreamacro/clash/constant"
"github.com/Dreamacro/clash/log" "github.com/Dreamacro/clash/log"
"github.com/Dreamacro/clash/tunnel" "github.com/Dreamacro/clash/tunnel"
@ -128,7 +129,7 @@ func (wpc *wrapPacketConn) RemoteAddr() net.Addr {
return wpc.rAddr 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] adapter, ok := tunnel.Proxies()[adapterName]
if !ok { if !ok {
return nil, fmt.Errorf("proxy adapter [%s] not found", adapterName) 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 { if networkType == C.UDP {
packetConn, err := adapter.ListenPacketContext(ctx, metadata) packetConn, err := adapter.ListenPacketContext(ctx, metadata, opts...)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -167,5 +168,5 @@ func dialContextWithProxyAdapter(ctx context.Context, adapterName string, networ
}, nil }, nil
} }
return adapter.DialContext(ctx, metadata) return adapter.DialContext(ctx, metadata, opts...)
} }