mirror of
https://github.com/coredns/coredns.git
synced 2025-10-28 00:34:24 -04:00
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
This commit is contained in:
committed by
John Belamaric
parent
58006cf847
commit
6f152dd8fd
@@ -59,7 +59,9 @@ func (h Hosts) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (
|
|||||||
if h.Fallthrough {
|
if h.Fallthrough {
|
||||||
return middleware.NextOrFailure(h.Name(), h.Next, ctx, w, r)
|
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)
|
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
|
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.
|
// Name implements the middleware.Handle interface.
|
||||||
func (h Hosts) Name() string { return "hosts" }
|
func (h Hosts) Name() string { return "hosts" }
|
||||||
|
|
||||||
|
|||||||
@@ -78,6 +78,14 @@ var hostsTestCases = []test.Case{
|
|||||||
test.PTR("1.0.0.127.in-addr.arpa. 3600 PTR localhost.domain."),
|
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 = `
|
const hostsExample = `
|
||||||
|
|||||||
Reference in New Issue
Block a user