git » dnss » commit 7c1bcc8

dnstogrpc: Style fix for the "use unqualified upstream" conditional

author Alberto Bertogli
2015-10-24 08:00:45 UTC
committer Alberto Bertogli
2015-10-24 15:48:40 UTC
parent d2b7394b619de8bc1f22b7ca418cf8a8341a3fa5

dnstogrpc: Style fix for the "use unqualified upstream" conditional

dnstogrpc/dnstogrpc.go +7 -3

diff --git a/dnstogrpc/dnstogrpc.go b/dnstogrpc/dnstogrpc.go
index 9dac93d..b569fbd 100644
--- a/dnstogrpc/dnstogrpc.go
+++ b/dnstogrpc/dnstogrpc.go
@@ -121,9 +121,13 @@ func (s *Server) Handler(w dns.ResponseWriter, r *dns.Msg) {
 		tr.LazyPrintf(util.QuestionsToString(r.Question))
 	}
 
-	if s.unqUpstream != "" &&
-		len(r.Question) == 1 &&
-		strings.Count(r.Question[0].Name, ".") <= 1 {
+	// Forward to the unqualified upstream server if:
+	//  - We have one configured.
+	//  - There's only one question in the request, to keep things simple.
+	//  - The question is unqualified (only one '.' in the name).
+	useUnqUpstream := s.unqUpstream != "" && len(r.Question) == 1 &&
+		strings.Count(r.Question[0].Name, ".") <= 1
+	if useUnqUpstream {
 		u, err := dns.Exchange(r, s.unqUpstream)
 		if err == nil {
 			tr.LazyPrintf("used unqualified upstream")