Workaround issue with weird DNS server when bootstraping

We see in practice on fresh new VM test, there's a DNS server that
return the answer with record not for the query domain.

To workaround this, filter out the answers not for the query domain.
This commit is contained in:
Cuong Manh Le
2023-04-29 00:16:14 +07:00
committed by Cuong Manh Le
parent 07689954bf
commit 02fa7fbe2e

View File

@@ -140,11 +140,18 @@ func lookupIP(domain string, timeout int, withBootstrapDNS bool) (ips []string)
if timeout > 0 && timeout < timeoutMs {
timeoutMs = timeoutMs
}
questionDomain := dns.Fqdn(domain)
ipFromRecord := func(record dns.RR) string {
switch ar := record.(type) {
case *dns.A:
if ar.Hdr.Name != questionDomain {
return ""
}
return ar.A.String()
case *dns.AAAA:
if ar.Hdr.Name != questionDomain {
return ""
}
return ar.AAAA.String()
}
return ""
@@ -154,7 +161,7 @@ func lookupIP(domain string, timeout int, withBootstrapDNS bool) (ips []string)
ctx, cancel := context.WithTimeout(context.Background(), time.Duration(timeoutMs)*time.Millisecond)
defer cancel()
m := new(dns.Msg)
m.SetQuestion(domain+".", dnsType)
m.SetQuestion(questionDomain, dnsType)
m.RecursionDesired = true
r, err := resolver.Resolve(ctx, m)