Merge: + DNS: use rules from /etc/hosts
- fix filtering logic: don't do DNS response check for Rewrite rules
Close #1478
Squashed commit of the following:
commit 1206b94881289ff664b7c8998ea97c1455da1ff8
Merge: c462577a 5fe98474
Author: Simon Zolin <s.zolin@adguard.com>
Date: Fri Mar 20 15:00:25 2020 +0300
Merge remote-tracking branch 'origin/master' into 1478-auto-records
commit c462577ad84754f5b3ea4cd58339838af817fe36
Author: Simon Zolin <s.zolin@adguard.com>
Date: Fri Mar 20 14:33:17 2020 +0300
minor
commit 7e824ba5f432648a976bc4b8076a645ba875ef70
Author: Simon Zolin <s.zolin@adguard.com>
Date: Fri Mar 20 14:29:54 2020 +0300
more tests
commit a22b62136c5cfd84cd0450897aef9e7d2e20585a
Author: Simon Zolin <s.zolin@adguard.com>
Date: Fri Mar 20 14:09:52 2020 +0300
rename, move
commit 9e5ed49ad3c27c57d540edf18b78d29e56afb067
Author: Simon Zolin <s.zolin@adguard.com>
Date: Thu Mar 19 15:33:27 2020 +0300
fix logic - don't do DNS response check for Rewrite rules
commit 6cfabc0348a41883b8bba834626a7e8760b76bf2
Author: Simon Zolin <s.zolin@adguard.com>
Date: Thu Mar 19 11:35:07 2020 +0300
minor
commit 4540aed9327566078e5087d43c30f4e8bffab7b9
Author: Simon Zolin <s.zolin@adguard.com>
Date: Thu Mar 19 11:03:24 2020 +0300
fix
commit 9ddddf7bded812da48613cc07084e360c15ddd0e
Author: Simon Zolin <s.zolin@adguard.com>
Date: Thu Mar 19 10:49:13 2020 +0300
fix
commit c5f8ef745b6f2a768be8a2ab23ad80b01b0aa54f
Author: Simon Zolin <s.zolin@adguard.com>
Date: Thu Mar 19 10:37:26 2020 +0300
fix
commit f4be00947bf0528c9a7cd4f09c4090db444c4694
Author: Simon Zolin <s.zolin@adguard.com>
Date: Mon Mar 16 20:13:00 2020 +0300
+ auto DNS records from /etc/hosts
This commit is contained in:
@@ -10,6 +10,7 @@ import (
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/AdguardTeam/AdGuardHome/util"
|
||||
"github.com/AdguardTeam/dnsproxy/upstream"
|
||||
"github.com/AdguardTeam/golibs/cache"
|
||||
"github.com/AdguardTeam/golibs/log"
|
||||
@@ -53,6 +54,9 @@ type Config struct {
|
||||
// Per-client settings can override this configuration.
|
||||
BlockedServices []string `yaml:"blocked_services"`
|
||||
|
||||
// IP-hostname pairs taken from system configuration (e.g. /etc/hosts) files
|
||||
AutoHosts *util.AutoHosts `yaml:"-"`
|
||||
|
||||
// Called when the configuration is changed by HTTP request
|
||||
ConfigModified func() `yaml:"-"`
|
||||
|
||||
@@ -139,6 +143,9 @@ const (
|
||||
|
||||
// ReasonRewrite - rewrite rule was applied
|
||||
ReasonRewrite
|
||||
|
||||
// RewriteEtcHosts - rewrite by /etc/hosts rule
|
||||
RewriteEtcHosts
|
||||
)
|
||||
|
||||
var reasonNames = []string{
|
||||
@@ -154,6 +161,7 @@ var reasonNames = []string{
|
||||
"FilteredBlockedService",
|
||||
|
||||
"Rewrite",
|
||||
"RewriteEtcHosts",
|
||||
}
|
||||
|
||||
func (r Reason) String() string {
|
||||
@@ -303,6 +311,15 @@ func (d *Dnsfilter) CheckHost(host string, qtype uint16, setts *RequestFiltering
|
||||
return result, nil
|
||||
}
|
||||
|
||||
if d.Config.AutoHosts != nil {
|
||||
ips := d.Config.AutoHosts.Process(host)
|
||||
if ips != nil {
|
||||
result.Reason = RewriteEtcHosts
|
||||
result.IPList = ips
|
||||
return result, nil
|
||||
}
|
||||
}
|
||||
|
||||
// try filter lists first
|
||||
if setts.FilteringEnabled {
|
||||
result, err = d.matchHost(host, qtype, setts.ClientTags)
|
||||
|
||||
@@ -3,6 +3,7 @@ package dnsfilter
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
"os"
|
||||
"path"
|
||||
"runtime"
|
||||
"testing"
|
||||
@@ -621,6 +622,13 @@ func TestRewrites(t *testing.T) {
|
||||
assert.True(t, r.IPList[0].Equal(net.ParseIP("1.2.3.4")))
|
||||
}
|
||||
|
||||
func prepareTestDir() string {
|
||||
const dir = "./agh-test"
|
||||
_ = os.RemoveAll(dir)
|
||||
_ = os.MkdirAll(dir, 0755)
|
||||
return dir
|
||||
}
|
||||
|
||||
// BENCHMARKS
|
||||
|
||||
func BenchmarkSafeBrowsing(b *testing.B) {
|
||||
|
||||
Reference in New Issue
Block a user