fix: dns specified interface does not change

This commit is contained in:
Skyxim 2022-04-28 22:40:06 +08:00
parent e2409f9639
commit bbbe371ea9
3 changed files with 7 additions and 5 deletions

View File

@ -689,7 +689,7 @@ func parseNameServer(servers []string) ([]dns.NameServer, error) {
Net: dnsNetType,
Addr: addr,
ProxyAdapter: u.Fragment,
Interface: dialer.DefaultInterface.Load(),
Interface: dialer.DefaultInterface,
},
)
}

View File

@ -4,6 +4,7 @@ import (
"context"
"crypto/tls"
"fmt"
"go.uber.org/atomic"
"net"
"net/netip"
"strings"
@ -19,7 +20,7 @@ type client struct {
r *Resolver
port string
host string
iface string
iface *atomic.String
proxyAdapter string
}
@ -49,8 +50,8 @@ func (c *client) ExchangeContext(ctx context.Context, m *D.Msg) (*D.Msg, error)
}
options := []dialer.Option{}
if c.iface != "" {
options = append(options, dialer.WithInterface(c.iface))
if c.iface != nil && c.iface.Load() != "" {
options = append(options, dialer.WithInterface(c.iface.Load()))
}
var conn net.Conn

View File

@ -4,6 +4,7 @@ import (
"context"
"errors"
"fmt"
"go.uber.org/atomic"
"math/rand"
"net/netip"
"strings"
@ -356,7 +357,7 @@ func (r *Resolver) HasProxyServer() bool {
type NameServer struct {
Net string
Addr string
Interface string
Interface *atomic.String
ProxyAdapter string
}