DNS hosts: Support returning RCode (#4681)

This commit is contained in:
j2rong4cn 2025-07-23 18:11:43 +08:00 committed by GitHub
parent f90fae22aa
commit 923b5d7229
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 76 additions and 18 deletions

View file

@ -204,7 +204,12 @@ func (s *DNS) LookupIP(domain string, option dns.IPOption) ([]net.IP, uint32, er
}
// Static host lookup
switch addrs := s.hosts.Lookup(domain, option); {
switch addrs, err := s.hosts.Lookup(domain, option); {
case err != nil:
if go_errors.Is(err, dns.ErrEmptyResponse) {
return nil, 0, dns.ErrEmptyResponse
}
return nil, 0, errors.New("returning nil for domain ", domain).Base(err)
case addrs == nil: // Domain not recorded in static host
break
case len(addrs) == 0: // Domain recorded, but no valid IP returned (e.g. IPv4 address with only IPv6 enabled)