From a72bd4542321ed0314f262d0c02de49f95688a97 Mon Sep 17 00:00:00 2001 From: fangdingjun Date: Wed, 21 Oct 2015 15:35:46 +0800 Subject: [PATCH] log output upstream dns server reply code --- server.go | 49 +++++++++++++++++++++++++++++-------------------- 1 file changed, 29 insertions(+), 20 deletions(-) diff --git a/server.go b/server.go index a5dfdc2..9a4bcf8 100644 --- a/server.go +++ b/server.go @@ -105,40 +105,49 @@ func handleRoot(w dns.ResponseWriter, r *dns.Msg) { done = 0 for _, sv := range Servers { if sv.match(domain) { - logger.Debug("%s query %s %s %s, forward to %s:%s\n", + + res, err = sv.query(r) + if err != nil { + logger.Error("%s", err) + continue + } + + logger.Debug("%s query %s %s %s, forward to %s:%s, %s\n", w.RemoteAddr(), domain, dns.ClassToString[r.Question[0].Qclass], dns.TypeToString[r.Question[0].Qtype], - sv.Proto, sv.Addr) - res, err = sv.query(r) - if err == nil { - if !in_blacklist(res) && res.Rcode != dns.RcodeServerFailure { - w.WriteMsg(res) - done = 1 - break - } - } else { - logger.Error("%s", err) + sv.Proto, sv.Addr, + dns.RcodeToString[res.Rcode], + ) + + if res.Rcode != dns.RcodeServerFailure && !in_blacklist(res) { + w.WriteMsg(res) + done = 1 + break } } } if done != 1 { res, err = DefaultServer.query(r) - logger.Debug("%s query %s %s %s, use default server %s:%s\n", + if err != nil { + logger.Error("%s", err) + continue + } + + logger.Debug("%s query %s %s %s, use default server %s:%s, %s\n", w.RemoteAddr(), domain, dns.ClassToString[r.Question[0].Qclass], dns.TypeToString[r.Question[0].Qtype], - DefaultServer.Proto, DefaultServer.Addr) - if err == nil { - if !in_blacklist(res) && res.Rcode != dns.RcodeServerFailure { - w.WriteMsg(res) - done = 1 - } - } else { - logger.Error("%s", err) + DefaultServer.Proto, DefaultServer.Addr, + dns.RcodeToString[res.Rcode], + ) + + if res.Rcode != dns.RcodeServerFailure && !in_blacklist(res) { + w.WriteMsg(res) + done = 1 } }