From 12f4ebc6a5b060c2899f4d0d0767c53a580b2b58 Mon Sep 17 00:00:00 2001 From: Simon Zolin Date: Tue, 19 Nov 2019 17:09:54 +0300 Subject: [PATCH 1/2] + querylog: preserve searching compatibility with the previous version --- querylog/querylog_file.go | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/querylog/querylog_file.go b/querylog/querylog_file.go index 1a466813..5f919943 100644 --- a/querylog/querylog_file.go +++ b/querylog/querylog_file.go @@ -406,8 +406,26 @@ func (r *Reader) applySearch(str string) bool { } } + mq := dns.Msg{} + if len(r.search.Domain) != 0 { val := readJSONValue(str, "QH") + if len(val) == 0 { + // pre-v0.99.3 compatibility + val = readJSONValue(str, "Question") + if len(val) == 0 { + return false + } + bval, err := base64.StdEncoding.DecodeString(val) + if err != nil { + return false + } + err = mq.Unpack(bval) + if err != nil { + return false + } + val = strings.TrimSuffix(mq.Question[0].Name, ".") + } if len(val) == 0 { return false } @@ -421,7 +439,26 @@ func (r *Reader) applySearch(str string) bool { if len(r.search.QuestionType) != 0 { val := readJSONValue(str, "QT") if len(val) == 0 { - return false + // pre-v0.99.3 compatibility + if len(mq.Question) == 0 { + val = readJSONValue(str, "Question") + if len(val) == 0 { + return false + } + bval, err := base64.StdEncoding.DecodeString(val) + if err != nil { + return false + } + err = mq.Unpack(bval) + if err != nil { + return false + } + } + ok := false + val, ok = dns.TypeToString[mq.Question[0].Qtype] + if !ok { + return false + } } if val != r.search.QuestionType { return false From a7742a366511e272a8c24dc5fcd1a62759c2bacb Mon Sep 17 00:00:00 2001 From: Simon Zolin Date: Tue, 19 Nov 2019 17:13:12 +0300 Subject: [PATCH 2/2] - querylog: fix linter issue --- querylog/querylog_file.go | 1 + 1 file changed, 1 insertion(+) diff --git a/querylog/querylog_file.go b/querylog/querylog_file.go index 5f919943..14299dfb 100644 --- a/querylog/querylog_file.go +++ b/querylog/querylog_file.go @@ -398,6 +398,7 @@ func readJSONValue(s, name string) string { return s[start:end] } +// nolint (gocyclo) func (r *Reader) applySearch(str string) bool { if r.search.ResponseStatus == responseStatusFiltered { boolVal, ok := readJSONBool(str, "IsFiltered")