From 15f3c8223896e0f3a7502f92ae38dfd9407b687f Mon Sep 17 00:00:00 2001 From: Eugene Bujak Date: Thu, 6 Dec 2018 16:55:05 +0300 Subject: [PATCH] dnsforward -- fix panic on ANY request --- dnsforward/querylog_top.go | 2 +- dnsforward/stats.go | 39 ++++++++++++++++++++------------------ 2 files changed, 22 insertions(+), 19 deletions(-) diff --git a/dnsforward/querylog_top.go b/dnsforward/querylog_top.go index b78dea79..9191171f 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.IsFiltered { + if entry.Result != nil && 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 9809e6e7..fead555b 100644 --- a/dnsforward/stats.go +++ b/dnsforward/stats.go @@ -193,24 +193,27 @@ func (h *histogram) Observe(value float64) { // ----- func incrementCounters(entry *logEntry) { requests.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) + if entry.Result != nil { + 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) + } } elapsedTime.ObserveWithTime(entry.Elapsed.Seconds(), entry.Time) }