chore: 调整dns interface与adapter部分

This commit is contained in:
gVisor bot 2022-06-05 12:52:29 +08:00
parent 301796755d
commit b128d1d48d
4 changed files with 16 additions and 26 deletions

View file

@ -4,6 +4,7 @@ import (
"context"
"crypto/tls"
"fmt"
"github.com/Dreamacro/clash/tunnel"
"go.uber.org/atomic"
"net"
"net/netip"
@ -55,14 +56,16 @@ func (c *client) ExchangeContext(ctx context.Context, m *D.Msg) (*D.Msg, error)
}
var conn net.Conn
if c.proxyAdapter != "" {
conn, err = dialContextWithProxyAdapter(ctx, c.proxyAdapter, network, ip, c.port, options...)
if err == errProxyNotFound {
options = append(options[:0], dialer.WithInterface(c.proxyAdapter), dialer.WithRoutingMark(0))
if c.proxyAdapter == "" {
conn, err = dialer.DialContext(ctx, network, net.JoinHostPort(ip.String(), c.port), options...)
} else {
_, ok := tunnel.Proxies()[c.proxyAdapter]
if ok {
conn, err = dialContextWithProxyAdapter(ctx, c.proxyAdapter, network, ip, c.port, options...)
} else {
options = append(options, dialer.WithInterface(c.proxyAdapter))
conn, err = dialer.DialContext(ctx, network, net.JoinHostPort(ip.String(), c.port), options...)
}
} else {
conn, err = dialer.DialContext(ctx, network, net.JoinHostPort(ip.String(), c.port), options...)
}
if err != nil {

View file

@ -97,17 +97,11 @@ func newDoHClient(url string, r *Resolver, proxyAdapter string) *dohClient {
return nil, err
}
if proxyAdapter != "" {
var conn net.Conn
conn, err = dialContextWithProxyAdapter(ctx, proxyAdapter, "tcp", ip, port)
if err == errProxyNotFound {
options := []dialer.Option{dialer.WithInterface(proxyAdapter), dialer.WithRoutingMark(0)}
conn, err = dialer.DialContext(ctx, "tcp", net.JoinHostPort(ip.String(), port), options...)
}
return conn, err
if proxyAdapter == "" {
return dialer.DialContext(ctx, "tcp", net.JoinHostPort(ip.String(), port))
} else {
return dialContextWithProxyAdapter(ctx, proxyAdapter, "tcp", ip, port)
}
return dialer.DialContext(ctx, "tcp", net.JoinHostPort(ip.String(), port))
},
},
}

View file

@ -168,19 +168,15 @@ func (dc *quicClient) openSession() (quic.Connection, error) {
}
} else {
conn, err := dialContextWithProxyAdapter(context.Background(), dc.proxyAdapter, "udp", ip, port)
if err == errProxyNotFound {
options := []dialer.Option{dialer.WithInterface(dc.proxyAdapter), dialer.WithRoutingMark(0)}
conn, err = dialContextWithProxyAdapter(context.Background(), dc.proxyAdapter, "udp", ip, port, options...)
if err != nil {
return nil, err
}
} else {
if err != nil {
return nil, err
}
wrapConn, ok := conn.(*wrapPacketConn)
if !ok {
return nil, fmt.Errorf("quio create packet failed")
}
udp = wrapConn
}

View file

@ -3,7 +3,6 @@ package dns
import (
"context"
"crypto/tls"
"errors"
"fmt"
"net"
"net/netip"
@ -20,8 +19,6 @@ import (
D "github.com/miekg/dns"
)
var errProxyNotFound = errors.New("proxy adapter not found")
func putMsgToCache(c *cache.LruCache[string, *D.Msg], key string, msg *D.Msg) {
var ttl uint32
switch {