From 4a663f2b25d8c2ffa9987095d432f44006d1e12a Mon Sep 17 00:00:00 2001 From: mzz2017 Date: Tue, 4 Feb 2020 18:44:58 +0800 Subject: [PATCH] fix(#2211): problem that AAAA query returns A result --- .gitignore | 1 + app/dns/dohdns.go | 9 ++++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 07d4fbe9..5297469b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ *.DS_Store bazel-* +.idea \ No newline at end of file diff --git a/app/dns/dohdns.go b/app/dns/dohdns.go index 61237ba8..c2a959d1 100644 --- a/app/dns/dohdns.go +++ b/app/dns/dohdns.go @@ -185,7 +185,6 @@ func (s *DoHNameServer) Cleanup() error { func (s *DoHNameServer) updateIP(req *dnsRequest, ipRec *IPRecord) { elapsed := time.Since(req.start) - newError(s.name, " got answere: ", req.domain, " ", req.reqType, " -> ", ipRec.IP, " ", elapsed).AtInfo().WriteToLog() s.Lock() rec := s.ips[req.domain] @@ -198,11 +197,19 @@ func (s *DoHNameServer) updateIP(req *dnsRequest, ipRec *IPRecord) { updated = true } case dnsmessage.TypeAAAA: + addr := make([]net.Address, 0) + for _, ip := range ipRec.IP { + if len(ip.IP()) == net.IPv6len { + addr = append(addr, ip) + } + } + ipRec.IP = addr if isNewer(rec.AAAA, ipRec) { rec.AAAA = ipRec updated = true } } + newError(s.name, " got answere: ", req.domain, " ", req.reqType, " -> ", ipRec.IP, " ", elapsed).AtInfo().WriteToLog() if updated { s.ips[req.domain] = rec