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, Net: dnsNetType,
Addr: addr, Addr: addr,
ProxyAdapter: u.Fragment, ProxyAdapter: u.Fragment,
Interface: dialer.DefaultInterface.Load(), Interface: dialer.DefaultInterface,
}, },
) )
} }

View File

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

View File

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