From 02fa7fbe2e8e7aea3717adadc62303caf7a2662d Mon Sep 17 00:00:00 2001 From: Cuong Manh Le Date: Sat, 29 Apr 2023 00:16:14 +0700 Subject: [PATCH] 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. --- resolver.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/resolver.go b/resolver.go index 084281c..f2a8424 100644 --- a/resolver.go +++ b/resolver.go @@ -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)