Fix: dhcp client should request special interface

This commit is contained in:
gVisor bot 2021-10-05 13:31:19 +08:00
parent 7f798f26ed
commit a50a642f01
4 changed files with 21 additions and 11 deletions

View file

@ -18,6 +18,7 @@ type client struct {
r *Resolver
port string
host string
iface string
}
func (c *client) Exchange(m *D.Msg) (*D.Msg, error) {
@ -45,7 +46,11 @@ func (c *client) ExchangeContext(ctx context.Context, m *D.Msg) (*D.Msg, error)
network = "tcp"
}
conn, err := dialer.DialContext(ctx, network, net.JoinHostPort(ip.String(), c.port))
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...)
if err != nil {
return nil, err
}

View file

@ -68,8 +68,11 @@ func (d *dhcpClient) resolve(ctx context.Context) (*Resolver, error) {
dns, err := dhcp.ResolveDNSFromDHCP(ctx, d.ifaceName)
if err == nil {
nameserver := make([]NameServer, 0, len(dns))
for _, d := range dns {
nameserver = append(nameserver, NameServer{Addr: net.JoinHostPort(d.String(), "53")})
for _, item := range dns {
nameserver = append(nameserver, NameServer{
Addr: net.JoinHostPort(item.String(), "53"),
Interface: d.ifaceName,
})
}
res = NewResolver(Config{

View file

@ -304,6 +304,7 @@ func (r *Resolver) asyncExchange(ctx context.Context, client []dnsClient, msg *D
type NameServer struct {
Net string
Addr string
Interface string
}
type FallbackFilter struct {

View file

@ -140,6 +140,7 @@ func transform(servers []NameServer, resolver *Resolver) []dnsClient {
},
port: port,
host: host,
iface: s.Interface,
r: resolver,
})
}