aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Pat Moroney <pat@moroney.email> 2017-07-20 16:09:15 -0600
committerGravatar John Belamaric <jbelamaric@infoblox.com> 2017-07-20 18:09:15 -0400
commit6f152dd8fdf637f3468386f83351906de7ef2d73 (patch)
tree41d0f7ba5f6c65e591b2f482ca98ed7082f1f911
parent58006cf84700ec42ba851256dd5ca46533ad76c9 (diff)
downloadcoredns-6f152dd8fdf637f3468386f83351906de7ef2d73.tar.gz
coredns-6f152dd8fdf637f3468386f83351906de7ef2d73.tar.zst
coredns-6f152dd8fdf637f3468386f83351906de7ef2d73.zip
hosts middleware should return NoError if other records exist in the zone (#782)
* hosts middleware should return NoError if other records exist in the zone * return RcodeSuccess for hosts queries for non A,AAAA records if the zone exists * return NXDOMAIN instead of REFUSED when zone is not found
-rw-r--r--middleware/hosts/hosts.go26
-rw-r--r--middleware/hosts/hosts_test.go8
2 files changed, 33 insertions, 1 deletions
diff --git a/middleware/hosts/hosts.go b/middleware/hosts/hosts.go
index 0b15fcaf7..68bd41b34 100644
--- a/middleware/hosts/hosts.go
+++ b/middleware/hosts/hosts.go
@@ -59,7 +59,9 @@ func (h Hosts) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (
if h.Fallthrough {
return middleware.NextOrFailure(h.Name(), h.Next, ctx, w, r)
}
- return dns.RcodeRefused, nil
+ if !h.otherRecordsExist(state.QType(), qname) {
+ return dns.RcodeNameError, nil
+ }
}
m := new(dns.Msg)
@@ -73,6 +75,28 @@ func (h Hosts) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (
return dns.RcodeSuccess, nil
}
+func (h Hosts) otherRecordsExist(qtype uint16, qname string) bool {
+ switch qtype {
+ case dns.TypeA:
+ if len(h.LookupStaticHostV6(qname)) > 0 {
+ return true
+ }
+ case dns.TypeAAAA:
+ if len(h.LookupStaticHostV4(qname)) > 0 {
+ return true
+ }
+ default:
+ if len(h.LookupStaticHostV4(qname)) > 0 {
+ return true
+ }
+ if len(h.LookupStaticHostV6(qname)) > 0 {
+ return true
+ }
+ }
+ return false
+
+}
+
// Name implements the middleware.Handle interface.
func (h Hosts) Name() string { return "hosts" }
diff --git a/middleware/hosts/hosts_test.go b/middleware/hosts/hosts_test.go
index 183389e3d..37716623a 100644
--- a/middleware/hosts/hosts_test.go
+++ b/middleware/hosts/hosts_test.go
@@ -78,6 +78,14 @@ var hostsTestCases = []test.Case{
test.PTR("1.0.0.127.in-addr.arpa. 3600 PTR localhost.domain."),
},
},
+ {
+ Qname: "example.org.", Qtype: dns.TypeAAAA,
+ Answer: []dns.RR{},
+ },
+ {
+ Qname: "example.org.", Qtype: dns.TypeMX,
+ Answer: []dns.RR{},
+ },
}
const hostsExample = `