chore: mix the proxy adapter and interface to dns client

This commit is contained in:
MetaCubeX
2022-06-04 21:18:49 +08:00
parent c045a4f2a7
commit 43d3a0c8ea
6 changed files with 275 additions and 18 deletions

View File

@ -55,10 +55,14 @@ func (c *client) ExchangeContext(ctx context.Context, m *D.Msg) (*D.Msg, error)
}
var conn net.Conn
if c.proxyAdapter == "" {
conn, err = dialer.DialContext(ctx, network, net.JoinHostPort(ip.String(), c.port), options...)
} else {
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))
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 {