mirror of
https://github.com/coredns/coredns.git
synced 2026-07-10 17:50:12 -04:00
plugin/pkg/response: classify nxdomain without soa as denial (#8199)
Signed-off-by: houyuwushang <liuluoqianqiu@outlook.com>
This commit is contained in:
@@ -13,7 +13,7 @@ type Type int
|
||||
const (
|
||||
// NoError indicates a positive reply
|
||||
NoError Type = iota
|
||||
// NameError is a NXDOMAIN in header, SOA in auth.
|
||||
// NameError is an NXDOMAIN in the header.
|
||||
NameError
|
||||
// ServerError is a set of errors we want to cache, for now it contains SERVFAIL and NOTIMPL.
|
||||
ServerError
|
||||
@@ -89,6 +89,9 @@ func Typify(m *dns.Msg, t time.Time) (Type, *dns.OPT) {
|
||||
if len(m.Answer) > 0 && m.Rcode == dns.RcodeSuccess {
|
||||
return NoError, opt
|
||||
}
|
||||
if len(m.Answer) > 0 && m.Rcode == dns.RcodeNameError {
|
||||
return OtherError, opt
|
||||
}
|
||||
|
||||
soa := false
|
||||
ns := 0
|
||||
@@ -105,7 +108,7 @@ func Typify(m *dns.Msg, t time.Time) (Type, *dns.OPT) {
|
||||
if soa && m.Rcode == dns.RcodeSuccess {
|
||||
return NoData, opt
|
||||
}
|
||||
if soa && m.Rcode == dns.RcodeNameError {
|
||||
if m.Rcode == dns.RcodeNameError {
|
||||
return NameError, opt
|
||||
}
|
||||
|
||||
|
||||
@@ -70,6 +70,17 @@ func TestTypifyRefused(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestTypifyNameErrorWithoutSOA(t *testing.T) {
|
||||
m := new(dns.Msg)
|
||||
m.SetQuestion("1.1.168.192.in-addr.arpa.", dns.TypePTR)
|
||||
m.Rcode = dns.RcodeNameError
|
||||
|
||||
mt, _ := Typify(m, time.Now().UTC())
|
||||
if mt != NameError {
|
||||
t.Errorf("NXDOMAIN message not typified as NameError, got %s", mt)
|
||||
}
|
||||
}
|
||||
|
||||
func delegationMsg() *dns.Msg {
|
||||
return &dns.Msg{
|
||||
Ns: []dns.RR{
|
||||
|
||||
Reference in New Issue
Block a user