plugin/pkg/response: classify nxdomain without soa as denial (#8199)

Signed-off-by: houyuwushang <liuluoqianqiu@outlook.com>
This commit is contained in:
houyuwushang
2026-07-06 13:48:51 +08:00
committed by GitHub
parent 31559f43e8
commit 6662dd58ea
5 changed files with 93 additions and 2 deletions

View File

@@ -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
}

View File

@@ -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{