pkg/typify: empty messages are OtherError (#1531)
Messages with nothing in them are considered OtherError, they can not serve any purpose for normal clients (i.e. dyn update or notifies might have a use for them). Also update a test in the cache plugin, so that we explicitaly test for this case.
This commit is contained in:
parent
f10627c1d6
commit
fc1d73ffa9
4 changed files with 35 additions and 1 deletions
2
plugin/cache/cache.go
vendored
2
plugin/cache/cache.go
vendored
|
@ -171,7 +171,7 @@ func (w *ResponseWriter) set(m *dns.Msg, key int, mt response.Type, duration tim
|
||||||
case response.OtherError:
|
case response.OtherError:
|
||||||
// don't cache these
|
// don't cache these
|
||||||
default:
|
default:
|
||||||
log.Printf("[WARNING] Caching called with unknown classification: %d", mt)
|
log.Printf("[WARNING] Caching called with unknown typification: %d", mt)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
11
plugin/cache/cache_test.go
vendored
11
plugin/cache/cache_test.go
vendored
|
@ -22,6 +22,7 @@ type cacheTestCase struct {
|
||||||
Authoritative bool
|
Authoritative bool
|
||||||
RecursionAvailable bool
|
RecursionAvailable bool
|
||||||
Truncated bool
|
Truncated bool
|
||||||
|
Response bool
|
||||||
shouldCache bool
|
shouldCache bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -111,6 +112,15 @@ var cacheTestCases = []cacheTestCase{
|
||||||
},
|
},
|
||||||
shouldCache: false,
|
shouldCache: false,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
// Response with only something in the additional, this should not be cached.
|
||||||
|
Response: true,
|
||||||
|
in: test.Case{
|
||||||
|
Qname: "example.org.", Qtype: dns.TypeMX,
|
||||||
|
Extra: []dns.RR{test.MX("example.org. 1800 IN MX 1 mx.example.org.")},
|
||||||
|
},
|
||||||
|
shouldCache: false,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
RecursionAvailable: true, Authoritative: true,
|
RecursionAvailable: true, Authoritative: true,
|
||||||
Case: test.Case{
|
Case: test.Case{
|
||||||
|
@ -140,6 +150,7 @@ func cacheMsg(m *dns.Msg, tc cacheTestCase) *dns.Msg {
|
||||||
m.AuthenticatedData = tc.AuthenticatedData
|
m.AuthenticatedData = tc.AuthenticatedData
|
||||||
m.Authoritative = tc.Authoritative
|
m.Authoritative = tc.Authoritative
|
||||||
m.Rcode = tc.Rcode
|
m.Rcode = tc.Rcode
|
||||||
|
m.Response = tc.Response
|
||||||
m.Truncated = tc.Truncated
|
m.Truncated = tc.Truncated
|
||||||
m.Answer = tc.in.Answer
|
m.Answer = tc.in.Answer
|
||||||
m.Ns = tc.in.Ns
|
m.Ns = tc.in.Ns
|
||||||
|
|
|
@ -55,6 +55,7 @@ func Typify(m *dns.Msg, t time.Time) (Type, *dns.OPT) {
|
||||||
if m == nil {
|
if m == nil {
|
||||||
return OtherError, nil
|
return OtherError, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
opt := m.IsEdns0()
|
opt := m.IsEdns0()
|
||||||
do := false
|
do := false
|
||||||
if opt != nil {
|
if opt != nil {
|
||||||
|
@ -76,6 +77,11 @@ func Typify(m *dns.Msg, t time.Time) (Type, *dns.OPT) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if m.Response && len(m.Answer) == 0 && len(m.Ns) == 0 {
|
||||||
|
// Response with nothing in it, maybe stuff in the additional section, this is not useful.
|
||||||
|
return OtherError, opt
|
||||||
|
}
|
||||||
|
|
||||||
// If our message contains any expired sigs and we care about that, we should return expired
|
// If our message contains any expired sigs and we care about that, we should return expired
|
||||||
if do {
|
if do {
|
||||||
if expired := typifyExpired(m, t); expired {
|
if expired := typifyExpired(m, t); expired {
|
||||||
|
|
|
@ -26,6 +26,23 @@ func TestTypifyDelegation(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestTypifyEmptyMessage(t *testing.T) {
|
||||||
|
m := new(dns.Msg)
|
||||||
|
|
||||||
|
// Normal question, with response = false
|
||||||
|
m.SetQuestion("example.org.", dns.TypeAAAA)
|
||||||
|
mt, _ := Typify(m, time.Now().UTC())
|
||||||
|
if mt != NoError {
|
||||||
|
t.Errorf("message is wrongly typified, expected NoError, got %s", mt)
|
||||||
|
}
|
||||||
|
// In case of a Reponse = true, this weird.
|
||||||
|
m.Response = true
|
||||||
|
mt, _ = Typify(m, time.Now().UTC())
|
||||||
|
if mt != OtherError {
|
||||||
|
t.Errorf("message is wrongly typified, expected OtherError, got %s", mt)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestTypifyRRSIG(t *testing.T) {
|
func TestTypifyRRSIG(t *testing.T) {
|
||||||
now, _ := time.Parse(time.UnixDate, "Fri Apr 21 10:51:21 BST 2017")
|
now, _ := time.Parse(time.UnixDate, "Fri Apr 21 10:51:21 BST 2017")
|
||||||
utc := now.UTC()
|
utc := now.UTC()
|
||||||
|
|
Loading…
Add table
Reference in a new issue