diff --git a/dnsforward/querylog.go b/dnsforward/querylog.go index 65af8b74..d449990d 100644 --- a/dnsforward/querylog.go +++ b/dnsforward/querylog.go @@ -34,7 +34,7 @@ var ( type logEntry struct { Question []byte Answer []byte `json:",omitempty"` // sometimes empty answers happen like binerdunt.top or rev2.globalrootservers.net - Result *dnsfilter.Result + Result dnsfilter.Result Time time.Time Elapsed time.Duration IP string @@ -61,11 +61,15 @@ func logRequest(question *dns.Msg, answer *dns.Msg, result *dnsfilter.Result, el } } + if result == nil { + result = &dnsfilter.Result{} + } + now := time.Now() entry := logEntry{ Question: q, Answer: a, - Result: result, + Result: *result, Time: now, Elapsed: elapsed, IP: ip, diff --git a/dnsforward/querylog_top.go b/dnsforward/querylog_top.go index 9191171f..b78dea79 100644 --- a/dnsforward/querylog_top.go +++ b/dnsforward/querylog_top.go @@ -168,7 +168,7 @@ func (r *dayTop) addEntry(entry *logEntry, q *dns.Msg, now time.Time) error { return err } - if entry.Result != nil && entry.Result.IsFiltered { + if entry.Result.IsFiltered { err := runningTop.hours[hour].incrementBlocked(hostname) if err != nil { log.Printf("Failed to increment value: %s", err) diff --git a/dnsforward/stats.go b/dnsforward/stats.go index fead555b..9cfe5f58 100644 --- a/dnsforward/stats.go +++ b/dnsforward/stats.go @@ -193,27 +193,25 @@ func (h *histogram) Observe(value float64) { // ----- func incrementCounters(entry *logEntry) { requests.IncWithTime(entry.Time) - if entry.Result != nil { - if entry.Result.IsFiltered { - filtered.IncWithTime(entry.Time) - } + if entry.Result.IsFiltered { + filtered.IncWithTime(entry.Time) + } - switch entry.Result.Reason { - case dnsfilter.NotFilteredWhiteList: - whitelisted.IncWithTime(entry.Time) - case dnsfilter.NotFilteredError: - errorsTotal.IncWithTime(entry.Time) - case dnsfilter.FilteredBlackList: - filteredLists.IncWithTime(entry.Time) - case dnsfilter.FilteredSafeBrowsing: - filteredSafebrowsing.IncWithTime(entry.Time) - case dnsfilter.FilteredParental: - filteredParental.IncWithTime(entry.Time) - case dnsfilter.FilteredInvalid: - // do nothing - case dnsfilter.FilteredSafeSearch: - safesearch.IncWithTime(entry.Time) - } + switch entry.Result.Reason { + case dnsfilter.NotFilteredWhiteList: + whitelisted.IncWithTime(entry.Time) + case dnsfilter.NotFilteredError: + errorsTotal.IncWithTime(entry.Time) + case dnsfilter.FilteredBlackList: + filteredLists.IncWithTime(entry.Time) + case dnsfilter.FilteredSafeBrowsing: + filteredSafebrowsing.IncWithTime(entry.Time) + case dnsfilter.FilteredParental: + filteredParental.IncWithTime(entry.Time) + case dnsfilter.FilteredInvalid: + // do nothing + case dnsfilter.FilteredSafeSearch: + safesearch.IncWithTime(entry.Time) } elapsedTime.ObserveWithTime(entry.Elapsed.Seconds(), entry.Time) }