diff --git a/clients_test.go b/clients_test.go index 83bb9a6a..1519f45d 100644 --- a/clients_test.go +++ b/clients_test.go @@ -34,7 +34,7 @@ func TestClients(t *testing.T) { IP: "1.2.3.5", Name: "client1", } - b, e = clientAdd(c) + b, _ = clientAdd(c) if b { t.Fatalf("clientAdd - name in use") } @@ -111,7 +111,7 @@ func TestClients(t *testing.T) { // failed add - ip exists b, e = clientAddHost("1.1.1.1", "host", ClientSourceHostsFile) - if b { + if b || e != nil { t.Fatalf("clientAddHost - ip exists") } diff --git a/dhcpd/dhcpd_test.go b/dhcpd/dhcpd_test.go index c7171f29..b5a860fa 100644 --- a/dhcpd/dhcpd_test.go +++ b/dhcpd/dhcpd_test.go @@ -26,6 +26,7 @@ func TestDHCP(t *testing.T) { var lease *Lease var opt dhcp4.Options + s.reset() s.leaseStart = []byte{1, 1, 1, 1} s.leaseStop = []byte{1, 1, 1, 2} s.leaseTime = 5 * time.Second @@ -132,6 +133,7 @@ func TestDB(t *testing.T) { var hw1, hw2 net.HardwareAddr var lease *Lease + s.reset() s.leaseStart = []byte{1, 1, 1, 1} s.leaseStop = []byte{1, 1, 1, 2} s.leaseTime = 5 * time.Second diff --git a/dhcpd/standalone/main.go b/dhcpd/standalone/main.go index 9dd37285..d84e3339 100644 --- a/dhcpd/standalone/main.go +++ b/dhcpd/standalone/main.go @@ -54,7 +54,11 @@ func main() { GatewayIP: "192.168.7.1", } log.Printf("Starting DHCP server") - err = server.Start(&config) + err = server.Init(config) + if err != nil { + panic(err) + } + err = server.Start() if err != nil { panic(err) } @@ -66,12 +70,12 @@ func main() { panic(err) } log.Printf("Starting DHCP server") - err = server.Start(&config) + err = server.Start() if err != nil { panic(err) } log.Printf("Starting DHCP server while it's already running") - err = server.Start(&config) + err = server.Start() if err != nil { panic(err) } diff --git a/dns.go b/dns.go index 0b0fa920..c36d1b40 100644 --- a/dns.go +++ b/dns.go @@ -136,7 +136,7 @@ func asyncRDNSLoop() { delete(dnsctx.rdnsIP, ip) dnsctx.rdnsLock.Unlock() - clientAddHost(ip, host, ClientSourceRDNS) + _, _ = clientAddHost(ip, host, ClientSourceRDNS) } } diff --git a/dns_test.go b/dns_test.go index 6623d1be..7e3b5788 100644 --- a/dns_test.go +++ b/dns_test.go @@ -3,7 +3,9 @@ package main import "testing" func TestResolveRDNS(t *testing.T) { - if r := resolveRDNS("1.1.1.1", "1.1.1.1"); r != "one.one.one.one" { + config.DNS.BindHost = "1.1.1.1" + initDNSServer(".") + if r := resolveRDNS("1.1.1.1"); r != "one.one.one.one" { t.Errorf("resolveRDNS(): %s", r) } } diff --git a/dnsfilter/dnsfilter.go b/dnsfilter/dnsfilter.go index 08604f34..415070ab 100644 --- a/dnsfilter/dnsfilter.go +++ b/dnsfilter/dnsfilter.go @@ -35,17 +35,6 @@ const defaultParentalServer = "pctrl.adguard.com" const defaultParentalURL = "%s://%s/check-parental-control-hash?prefixes=%s&sensitivity=%d" const maxDialCacheSize = 2 // the number of host names for safebrowsing and parental control -// ErrInvalidSyntax is returned by AddRule when the rule is invalid -var ErrInvalidSyntax = errors.New("dnsfilter: invalid rule syntax") - -// ErrAlreadyExists is returned by AddRule when the rule was already added to the filter -var ErrAlreadyExists = errors.New("dnsfilter: rule was already added") - -const shortcutLength = 6 // used for rule search optimization, 6 hits the sweet spot - -const enableFastLookup = true // flag for debugging, must be true in production for faster performance -const enableDelayedCompilation = true // flag for debugging, must be true in production for faster performance - // Custom filtering settings type RequestFilteringSettings struct { FilteringEnabled bool @@ -636,7 +625,10 @@ func searchInDialCache(host string) string { // Add "hostname" -> "IP address" entry to cache func addToDialCache(host, ip string) { - dialCache.Set(host, ip) + err := dialCache.Set(host, ip) + if err != nil { + log.Debug("dialCache.Set: %s", err) + } log.Debug("Added to cache: %s -> %s", host, ip) } diff --git a/dnsfilter/dnsfilter_test.go b/dnsfilter/dnsfilter_test.go index 7488985f..00324471 100644 --- a/dnsfilter/dnsfilter_test.go +++ b/dnsfilter/dnsfilter_test.go @@ -318,10 +318,12 @@ func TestSafeSearchCacheGoogle(t *testing.T) { t.Fatalf("Failed to lookup for %s", safeDomain) } + t.Logf("IP addresses: %v", ips) ip := ips[0] for _, i := range ips { - if len(i) == net.IPv6len && i.To4() != nil { + if i.To4() != nil { ip = i + break } } @@ -331,7 +333,8 @@ func TestSafeSearchCacheGoogle(t *testing.T) { } if result.IP.String() != ip.String() { - t.Fatalf("Wrong IP for %s safesearch: %s", domain, result.IP.String()) + t.Fatalf("Wrong IP for %s safesearch: %s. Should be: %s", + domain, result.IP.String(), ip) } // Check cache diff --git a/dnsforward/dnsforward_test.go b/dnsforward/dnsforward_test.go index 1a38e96b..6d11b611 100644 --- a/dnsforward/dnsforward_test.go +++ b/dnsforward/dnsforward_test.go @@ -15,12 +15,10 @@ import ( "testing" "time" - "github.com/AdguardTeam/dnsproxy/proxy" - - "github.com/stretchr/testify/assert" - "github.com/AdguardTeam/AdGuardHome/dnsfilter" + "github.com/AdguardTeam/dnsproxy/proxy" "github.com/miekg/dns" + "github.com/stretchr/testify/assert" ) const ( @@ -177,7 +175,7 @@ func TestSafeSearch(t *testing.T) { ip := ips[0] for _, i := range ips { - if len(i) == net.IPv6len && i.To4() != nil { + if i.To4() != nil { ip = i break } @@ -460,12 +458,8 @@ func createTestServer(t *testing.T) *Server { s.conf.FilteringConfig.SafeBrowsingEnabled = true s.conf.Filters = make([]dnsfilter.Filter, 0) - rules := []string{ - "||nxdomain.example.org^", - "||null.example.org^", - "127.0.0.1 host.example.org", - } - filter := dnsfilter.Filter{ID: 1, Rules: rules} + rules := "||nxdomain.example.org^\n||null.example.org^\n127.0.0.1 host.example.org\n" + filter := dnsfilter.Filter{ID: 1, Data: []byte(rules)} s.conf.Filters = append(s.conf.Filters, filter) return s }