Merge from #21, Make difference response between SERVFAIL and NXDOMAIN #20

This commit is contained in:
kenshinx 2015-10-30 12:24:22 +08:00
parent 0c1b4738cd
commit fde6624777

View File

@ -45,11 +45,18 @@ func (r *Resolver) Lookup(net string, req *dns.Msg) (message *dns.Msg, err error
logger.Warn("error:%s", err.Error()) logger.Warn("error:%s", err.Error())
return return
} }
// If SERVFAIL happen, should return immediately and try another upstream resolver.
// However, other Error code like NXDOMAIN is an clear response stating
// that it has been verified no such domain existas and ask other resolvers
// would make no sense. See more about #20
if r != nil && r.Rcode != dns.RcodeSuccess { if r != nil && r.Rcode != dns.RcodeSuccess {
logger.Warn("%s failed to get an valid answer on %s", qname, nameserver) logger.Warn("%s failed to get an valid answer on %s", qname, nameserver)
return if r.Rcode == dns.RcodeServerFailure {
return
}
} else {
logger.Debug("%s resolv on %s (%s) ttl: %d", UnFqdn(qname), nameserver, net, rtt)
} }
logger.Debug("%s resolv on %s (%s) ttl: %d", UnFqdn(qname), nameserver, net, rtt)
select { select {
case res <- r: case res <- r:
default: default: