From db9bae416285b396ab84e6c00b96ce32c4793e4f Mon Sep 17 00:00:00 2001 From: Michael Bridgen Date: Wed, 14 Jan 2015 16:43:47 +0000 Subject: [PATCH 1/2] Use the fallback for reverse lookups too I considered a couple of different factorings, that is * Implementing the fallback as a Lookup * Having a server struct that held the resolv.conf and methods for handling queries but ultimately, this is simple and works. --- nameserver/server.go | 8 ++++---- nameserver/server_test.go | 11 ++++++++++- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/nameserver/server.go b/nameserver/server.go index f123da57..20fa94c5 100644 --- a/nameserver/server.go +++ b/nameserver/server.go @@ -51,6 +51,7 @@ func queryHandler(lookups []Lookup) dns.HandlerFunc { } func rdnsHandler(lookups []Lookup) dns.HandlerFunc { + fallback := notUsHandler() return func(w dns.ResponseWriter, r *dns.Msg) { q := r.Question[0] Debug.Printf("Reverse query: %+v", q) @@ -62,13 +63,12 @@ func rdnsHandler(lookups []Lookup) dns.HandlerFunc { return } } - Info.Printf("[dns msgid %d] No results for type %s query %s", - r.MsgHdr.Id, dns.TypeToString[q.Qtype], q.Name) + fallback(w, r) + return } else { Warning.Printf("[dns msgid %d] Unexpected reverse query type %s: %+v", r.MsgHdr.Id, dns.TypeToString[q.Qtype], q) } - w.WriteMsg(makeDNSFailResponse(r)) } } @@ -80,7 +80,7 @@ func notUsHandler() dns.HandlerFunc { checkFatal(err) return func(w dns.ResponseWriter, r *dns.Msg) { q := r.Question[0] - Debug.Printf("[dns msgid %d] Non-local query: %+v", r.MsgHdr.Id, q) + Debug.Printf("[dns msgid %d] Fallback query: %+v", r.MsgHdr.Id, q) for _, server := range config.Servers { reply, err := dns.Exchange(r, fmt.Sprintf("%s:%s", server, config.Port)) if err != nil { diff --git a/nameserver/server_test.go b/nameserver/server_test.go index 8ad62f06..f38c510b 100644 --- a/nameserver/server_test.go +++ b/nameserver/server_test.go @@ -78,5 +78,14 @@ func TestDNSServer(t *testing.T) { t.Fatal("Number of answers > 0") } - // Not testing MDNS functionality of server here (yet) + m.SetQuestion("8.8.8.8.in-addr.arpa.", dns.TypePTR) + r, _, err = c.Exchange(m, dnsAddr) + wt.AssertNoErr(t, err) + wt.AssertStatus(t, r.Rcode, dns.RcodeSuccess, "DNS success response code") + if !(len(r.Answer) > 0) { + t.Fatal("Number of answers > 0") + } + + // Not testing MDNS functionality of server here (yet), since it + // needs two servers, each listening on its own address } From 5c3fe86be72ccb5c4c91ab8fa70bde274980a95e Mon Sep 17 00:00:00 2001 From: Michael Bridgen Date: Wed, 14 Jan 2015 17:02:17 +0000 Subject: [PATCH 2/2] Include testing non-weave reverse queries in DNS smoke tests Pro-tip: Do not put weaveDNS on the same subnet as the fallback DNS server. --- test/210_dns_multicast_test.sh | 7 +++++-- test/300_fallback_dns_test.sh | 5 ++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/test/210_dns_multicast_test.sh b/test/210_dns_multicast_test.sh index 59218552..8afedfb3 100755 --- a/test/210_dns_multicast_test.sh +++ b/test/210_dns_multicast_test.sh @@ -16,8 +16,8 @@ done run_on $HOST1 sudo $WEAVE launch run_on $HOST2 sudo $WEAVE launch $HOST1 -run_on $HOST1 sudo $WEAVE launch-dns 10.0.0.2/8 -run_on $HOST2 sudo $WEAVE launch-dns 10.0.0.3/8 +run_on $HOST1 sudo $WEAVE launch-dns 10.3.3.2/24 -debug +run_on $HOST2 sudo $WEAVE launch-dns 10.3.3.3/24 -debug run_on $HOST2 sudo $WEAVE run $C2/24 -t --name=c2 -h seetwo.weave.local ubuntu run_on $HOST1 sudo $WEAVE run --with-dns $C1/24 --name=c1 -t aanand/docker-dnsutils /bin/sh @@ -28,4 +28,7 @@ assert "echo $ok" "$C2" ok=$(docker -H tcp://$HOST1:2375 exec -i c1 dig +short -x $C2) assert "echo $ok" "seetwo.weave.local." +ok=$(docker -H tcp://$HOST1:2375 exec -i c1 dig +short -x 8.8.8.8) +assert "test -n \"$ok\" && echo pass" "pass" + end_suite diff --git a/test/300_fallback_dns_test.sh b/test/300_fallback_dns_test.sh index 679d621a..808bc6e3 100755 --- a/test/300_fallback_dns_test.sh +++ b/test/300_fallback_dns_test.sh @@ -5,7 +5,7 @@ start_suite "Resolve a non-weave address" run_on $HOST1 sudo $WEAVE stop-dns || true -run_on $HOST1 sudo $WEAVE launch-dns 10.0.0.2 +run_on $HOST1 sudo $WEAVE launch-dns 10.2.6.2 -debug docker_on $HOST1 rm -f c1 || true run_on $HOST1 sudo $WEAVE run --with-dns 10.1.1.5/24 --name=c1 -t aanand/docker-dnsutils /bin/sh @@ -13,4 +13,7 @@ run_on $HOST1 sudo $WEAVE run --with-dns 10.1.1.5/24 --name=c1 -t aanand/docker- ok=$(docker -H tcp://$HOST1:2375 exec -i c1 dig +short -t MX weave.works) assert "test -n \"$ok\" && echo pass" "pass" +ok=$(docker -H tcp://$HOST1:2375 exec -i c1 dig +short -x 8.8.8.8) +assert "test -n \"$ok\" && echo pass" "pass" + end_suite