* querylog: don't return entries without Question data
This commit is contained in:
parent
ec5c5e8109
commit
0d4e95b36d
|
@ -124,12 +124,14 @@ func (l *queryLog) Add(question *dns.Msg, answer *dns.Msg, result *dnsfilter.Res
|
||||||
var err error
|
var err error
|
||||||
ip := getIPString(addr)
|
ip := getIPString(addr)
|
||||||
|
|
||||||
if question != nil {
|
if question == nil {
|
||||||
q, err = question.Pack()
|
return
|
||||||
if err != nil {
|
}
|
||||||
log.Printf("failed to pack question for querylog: %s", err)
|
|
||||||
return
|
q, err = question.Pack()
|
||||||
}
|
if err != nil {
|
||||||
|
log.Printf("failed to pack question for querylog: %s", err)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if answer != nil {
|
if answer != nil {
|
||||||
|
@ -333,19 +335,23 @@ func (l *queryLog) getData(params getDataParams) []map[string]interface{} {
|
||||||
var q *dns.Msg
|
var q *dns.Msg
|
||||||
var a *dns.Msg
|
var a *dns.Msg
|
||||||
|
|
||||||
if len(entry.Question) > 0 {
|
if len(entry.Question) == 0 {
|
||||||
q = new(dns.Msg)
|
continue
|
||||||
if err := q.Unpack(entry.Question); err != nil {
|
|
||||||
// ignore, log and move on
|
|
||||||
log.Printf("Failed to unpack dns message question: %s", err)
|
|
||||||
q = nil
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
q = new(dns.Msg)
|
||||||
|
if err := q.Unpack(entry.Question); err != nil {
|
||||||
|
log.Tracef("q.Unpack(): %s", err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if len(q.Question) != 1 {
|
||||||
|
log.Tracef("len(q.Question) != 1")
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
if len(entry.Answer) > 0 {
|
if len(entry.Answer) > 0 {
|
||||||
a = new(dns.Msg)
|
a = new(dns.Msg)
|
||||||
if err := a.Unpack(entry.Answer); err != nil {
|
if err := a.Unpack(entry.Answer); err != nil {
|
||||||
// ignore, log and move on
|
log.Debug("Failed to unpack dns message answer: %s", err)
|
||||||
log.Printf("Failed to unpack dns message question: %s", err)
|
|
||||||
a = nil
|
a = nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -356,12 +362,10 @@ func (l *queryLog) getData(params getDataParams) []map[string]interface{} {
|
||||||
"time": entry.Time.Format(time.RFC3339Nano),
|
"time": entry.Time.Format(time.RFC3339Nano),
|
||||||
"client": entry.IP,
|
"client": entry.IP,
|
||||||
}
|
}
|
||||||
if q != nil {
|
jsonEntry["question"] = map[string]interface{}{
|
||||||
jsonEntry["question"] = map[string]interface{}{
|
"host": strings.ToLower(strings.TrimSuffix(q.Question[0].Name, ".")),
|
||||||
"host": strings.ToLower(strings.TrimSuffix(q.Question[0].Name, ".")),
|
"type": dns.Type(q.Question[0].Qtype).String(),
|
||||||
"type": dns.Type(q.Question[0].Qtype).String(),
|
"class": dns.Class(q.Question[0].Qclass).String(),
|
||||||
"class": dns.Class(q.Question[0].Qclass).String(),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if a != nil {
|
if a != nil {
|
||||||
|
|
Loading…
Reference in New Issue