From 975f78a7ce96da899ea8b37c52d7dbf9c7905c98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A7=8B=E3=81=AE=E3=81=8B=E3=81=88=E3=81=A7?= Date: Sat, 2 Apr 2022 12:44:34 +0800 Subject: [PATCH] Feat: refine find IPs logic for DoH --- app/dns/nameserver_doh.go | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/app/dns/nameserver_doh.go b/app/dns/nameserver_doh.go index e7313194e..5e2a63d00 100644 --- a/app/dns/nameserver_doh.go +++ b/app/dns/nameserver_doh.go @@ -297,14 +297,6 @@ func (s *DoHNameServer) findIPsForDomain(domain string, option dns_feature.IPOpt var ips []net.Address var lastErr error - if option.IPv6Enable { - aaaa, err := record.AAAA.getIPs() - if err != nil { - lastErr = err - } - ips = append(ips, aaaa...) - } - if option.IPv4Enable { a, err := record.A.getIPs() if err != nil { @@ -313,6 +305,14 @@ func (s *DoHNameServer) findIPsForDomain(domain string, option dns_feature.IPOpt ips = append(ips, a...) } + if option.IPv6Enable { + aaaa, err := record.AAAA.getIPs() + if err != nil { + lastErr = err + } + ips = append(ips, aaaa...) + } + if len(ips) > 0 { return toNetIP(ips) } @@ -321,11 +321,7 @@ func (s *DoHNameServer) findIPsForDomain(domain string, option dns_feature.IPOpt return nil, lastErr } - if (option.IPv4Enable && record.A != nil) || (option.IPv6Enable && record.AAAA != nil) { - return nil, dns_feature.ErrEmptyResponse - } - - return nil, errRecordNotFound + return nil, dns_feature.ErrEmptyResponse } // QueryIP implements Server.