From d41779cf88983549af7750abf17a5b920c88125d Mon Sep 17 00:00:00 2001
From: Eugene Burkov <e.burkov@adguard.com>
Date: Mon, 22 Nov 2021 17:22:59 +0300
Subject: [PATCH] Pull request: 3851 empty hosts

Merge in DNS/adguard-home from 3851-empty-hosts to master

Updates #3851.

Squashed commit of the following:

commit e09aa8e1029748ba162950b087336fd71677da2d
Author: Eugene Burkov <E.Burkov@AdGuard.COM>
Date:   Mon Nov 22 16:19:08 2021 +0300

    aghnet: imp code

commit c9e45148a68193249c2d7096a15c7fee571ba5bd
Author: Eugene Burkov <E.Burkov@AdGuard.COM>
Date:   Mon Nov 22 15:33:27 2021 +0300

    aghnet: fix hosts container empty engine
---
 internal/aghnet/hostscontainer.go | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/internal/aghnet/hostscontainer.go b/internal/aghnet/hostscontainer.go
index a0b10520..cfa55dd0 100644
--- a/internal/aghnet/hostscontainer.go
+++ b/internal/aghnet/hostscontainer.go
@@ -90,7 +90,6 @@ func NewHostsContainer(
 		engLock:  &sync.RWMutex{},
 		done:     make(chan struct{}, 1),
 		updates:  make(chan *netutil.IPMap, 1),
-		last:     &netutil.IPMap{},
 		fsys:     fsys,
 		w:        w,
 		patterns: patterns,
@@ -347,6 +346,11 @@ func (hp *hostsParser) addPair(ip net.IP, host string) {
 
 // equalSet returns true if the internal hosts table just parsed equals target.
 func (hp *hostsParser) equalSet(target *netutil.IPMap) (ok bool) {
+	if target == nil {
+		// hp.table shouldn't appear nil since it's initialized on each refresh.
+		return target == hp.table
+	}
+
 	if hp.table.Len() != target.Len() {
 		return false
 	}