Feat: refine find IPs logic for DoH

This commit is contained in:
秋のかえで 2022-04-02 12:44:34 +08:00
parent 2dc4ee2d51
commit 975f78a7ce
No known key found for this signature in database
GPG Key ID: E343534293081E5D
1 changed files with 9 additions and 13 deletions

View File

@ -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.