Skip to content

Commit

Permalink
Return DNS no-error with empty answer if we have a matching name
Browse files Browse the repository at this point in the history
but the query is for a record type we don't support.
  • Loading branch information
bboreham committed May 3, 2016
1 parent be3b0aa commit 85b1542
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
8 changes: 6 additions & 2 deletions nameserver/dns.go
Expand Up @@ -134,7 +134,7 @@ func (d *DNSServer) createMux(client *dns.Client, defaultMaxResponseSize int) *d

func (h *handler) handleLocal(w dns.ResponseWriter, req *dns.Msg) {
h.ns.debugf("local request: %+v", *req)
if len(req.Question) != 1 || req.Question[0].Qtype != dns.TypeA {
if len(req.Question) != 1 {
h.nameError(w, req)
return
}
Expand All @@ -149,6 +149,10 @@ func (h *handler) handleLocal(w dns.ResponseWriter, req *dns.Msg) {
h.nameError(w, req)
return
}
// Per RFC4074, if we have an A but AAAA was requested, return 'no error' and empty answer section
if req.Question[0].Qtype != dns.TypeA {
h.respond(w, h.makeResponse(req, nil))
}

header := dns.RR_Header{
Name: req.Question[0].Name,
Expand Down Expand Up @@ -204,7 +208,7 @@ func (h *handler) handleRecursive(w dns.ResponseWriter, req *dns.Msg) {
h.ns.debugf("recursive request: %+v", *req)

// Resolve unqualified names locally
if len(req.Question) == 1 && req.Question[0].Qtype == dns.TypeA {
if len(req.Question) == 1 {
hostname := dns.Fqdn(req.Question[0].Name)
if strings.Count(hostname, ".") == 1 {
h.handleLocal(w, req)
Expand Down
5 changes: 2 additions & 3 deletions test/250_dns_negative_test.sh
Expand Up @@ -7,9 +7,8 @@ start_suite "Negative DNS queries"
weave_on $HOST1 launch
start_container_with_dns $HOST1 --name c1

# unsupported query types, unknown names, and unknown domains should
# all trigger NXDOMAIN
assert_raises "exec_on $HOST1 c1 dig MX c1.weave.local | grep -q 'status: NXDOMAIN'"
# unsupported query types, unknown names, and unknown domains
assert_raises "exec_on $HOST1 c1 dig MX c1.weave.local | grep -q 'status: NOERROR'"
assert_raises "exec_on $HOST1 c1 dig A xx.weave.local | grep -q 'status: NXDOMAIN'"
assert_raises "exec_on $HOST1 c1 dig A xx.invalid | grep -q 'status: NXDOMAIN'"

Expand Down

0 comments on commit 85b1542

Please sign in to comment.