Pull request: all: less annoying pkg names
Merge in DNS/adguard-home from imp-naming to master Squashed commit of the following: commit d9e75c37af9a738384393735c141a41406d22eeb Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Thu May 13 15:52:14 2021 +0300 all: less annoying pkg names
This commit is contained in:
parent
42ec9cae76
commit
7f2f8de922
|
@ -14,8 +14,8 @@
|
||||||
/build2/*
|
/build2/*
|
||||||
/data/
|
/data/
|
||||||
/dist/
|
/dist/
|
||||||
/dnsfilter/tests/dnsfilter.TestLotsOfRules*.pprof
|
/filtering/tests/filtering.TestLotsOfRules*.pprof
|
||||||
/dnsfilter/tests/top-1m.csv
|
/filtering/tests/top-1m.csv
|
||||||
/launchpad_credentials
|
/launchpad_credentials
|
||||||
/querylog.json*
|
/querylog.json*
|
||||||
/snapcraft_login
|
/snapcraft_login
|
||||||
|
|
|
@ -317,7 +317,7 @@ Here is a link to AdGuard Home project: https://crowdin.com/project/adguard-appl
|
||||||
Here's what you can also do to contribute:
|
Here's what you can also do to contribute:
|
||||||
|
|
||||||
1. [Look for issues](https://github.com/AdguardTeam/AdGuardHome/issues?q=is%3Aissue+is%3Aopen+label%3A%22help+wanted%22+) marked as "help wanted".
|
1. [Look for issues](https://github.com/AdguardTeam/AdGuardHome/issues?q=is%3Aissue+is%3Aopen+label%3A%22help+wanted%22+) marked as "help wanted".
|
||||||
2. Actualize the list of *Blocked services*. It it can be found in [dnsfilter/blocked.go](https://github.com/AdguardTeam/AdGuardHome/blob/master/internal/dnsfilter/blocked.go).
|
2. Actualize the list of *Blocked services*. It it can be found in [filtering/blocked.go](https://github.com/AdguardTeam/AdGuardHome/blob/master/internal/filtering/blocked.go).
|
||||||
3. Actualize the list of known *trackers*. It it can be found in [client/src/helpers/trackers/adguard.json](https://github.com/AdguardTeam/AdGuardHome/blob/master/client/src/helpers/trackers/adguard.json).
|
3. Actualize the list of known *trackers*. It it can be found in [client/src/helpers/trackers/adguard.json](https://github.com/AdguardTeam/AdGuardHome/blob/master/client/src/helpers/trackers/adguard.json).
|
||||||
4. Actualize the list of vetted *blocklists*. It it can be found in [client/src/helpers/filters/filters.json](https://github.com/AdguardTeam/AdGuardHome/blob/master/client/src/helpers/filters/filters.json).
|
4. Actualize the list of vetted *blocklists*. It it can be found in [client/src/helpers/filters/filters.json](https://github.com/AdguardTeam/AdGuardHome/blob/master/client/src/helpers/filters/filters.json).
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,7 @@ module.exports = {
|
||||||
"",
|
"",
|
||||||
"ui",
|
"ui",
|
||||||
"global",
|
"global",
|
||||||
"dnsfilter",
|
"filtering",
|
||||||
"home",
|
"home",
|
||||||
"dnsforward",
|
"dnsforward",
|
||||||
"dhcpd",
|
"dhcpd",
|
||||||
|
|
|
@ -11,7 +11,7 @@ import (
|
||||||
"sort"
|
"sort"
|
||||||
|
|
||||||
"github.com/AdguardTeam/AdGuardHome/internal/aghstrings"
|
"github.com/AdguardTeam/AdGuardHome/internal/aghstrings"
|
||||||
"github.com/AdguardTeam/AdGuardHome/internal/dnsfilter"
|
"github.com/AdguardTeam/AdGuardHome/internal/filtering"
|
||||||
"github.com/AdguardTeam/dnsproxy/proxy"
|
"github.com/AdguardTeam/dnsproxy/proxy"
|
||||||
"github.com/AdguardTeam/dnsproxy/upstream"
|
"github.com/AdguardTeam/dnsproxy/upstream"
|
||||||
"github.com/AdguardTeam/golibs/log"
|
"github.com/AdguardTeam/golibs/log"
|
||||||
|
@ -25,7 +25,7 @@ type FilteringConfig struct {
|
||||||
// --
|
// --
|
||||||
|
|
||||||
// FilterHandler is an optional additional filtering callback.
|
// FilterHandler is an optional additional filtering callback.
|
||||||
FilterHandler func(clientAddr net.IP, clientID string, settings *dnsfilter.FilteringSettings) `yaml:"-"`
|
FilterHandler func(clientAddr net.IP, clientID string, settings *filtering.Settings) `yaml:"-"`
|
||||||
|
|
||||||
// GetCustomUpstreamByClient - a callback function that returns upstreams configuration
|
// GetCustomUpstreamByClient - a callback function that returns upstreams configuration
|
||||||
// based on the client IP address. Returns nil if there are no custom upstreams for the client
|
// based on the client IP address. Returns nil if there are no custom upstreams for the client
|
||||||
|
@ -36,7 +36,7 @@ type FilteringConfig struct {
|
||||||
// Protection configuration
|
// Protection configuration
|
||||||
// --
|
// --
|
||||||
|
|
||||||
ProtectionEnabled bool `yaml:"protection_enabled"` // whether or not use any of dnsfilter features
|
ProtectionEnabled bool `yaml:"protection_enabled"` // whether or not use any of filtering features
|
||||||
BlockingMode string `yaml:"blocking_mode"` // mode how to answer filtered requests
|
BlockingMode string `yaml:"blocking_mode"` // mode how to answer filtered requests
|
||||||
BlockingIPv4 net.IP `yaml:"blocking_ipv4"` // IP address to be returned for a blocked A request
|
BlockingIPv4 net.IP `yaml:"blocking_ipv4"` // IP address to be returned for a blocked A request
|
||||||
BlockingIPv6 net.IP `yaml:"blocking_ipv6"` // IP address to be returned for a blocked AAAA request
|
BlockingIPv6 net.IP `yaml:"blocking_ipv6"` // IP address to be returned for a blocked AAAA request
|
||||||
|
|
|
@ -7,7 +7,7 @@ import (
|
||||||
|
|
||||||
"github.com/AdguardTeam/AdGuardHome/internal/aghnet"
|
"github.com/AdguardTeam/AdGuardHome/internal/aghnet"
|
||||||
"github.com/AdguardTeam/AdGuardHome/internal/dhcpd"
|
"github.com/AdguardTeam/AdGuardHome/internal/dhcpd"
|
||||||
"github.com/AdguardTeam/AdGuardHome/internal/dnsfilter"
|
"github.com/AdguardTeam/AdGuardHome/internal/filtering"
|
||||||
"github.com/AdguardTeam/dnsproxy/proxy"
|
"github.com/AdguardTeam/dnsproxy/proxy"
|
||||||
"github.com/AdguardTeam/golibs/log"
|
"github.com/AdguardTeam/golibs/log"
|
||||||
"github.com/miekg/dns"
|
"github.com/miekg/dns"
|
||||||
|
@ -20,9 +20,9 @@ type dnsContext struct {
|
||||||
srv *Server
|
srv *Server
|
||||||
proxyCtx *proxy.DNSContext
|
proxyCtx *proxy.DNSContext
|
||||||
// setts are the filtering settings for the client.
|
// setts are the filtering settings for the client.
|
||||||
setts *dnsfilter.FilteringSettings
|
setts *filtering.Settings
|
||||||
startTime time.Time
|
startTime time.Time
|
||||||
result *dnsfilter.Result
|
result *filtering.Result
|
||||||
// origResp is the response received from upstream. It is set when the
|
// origResp is the response received from upstream. It is set when the
|
||||||
// response is modified by filters.
|
// response is modified by filters.
|
||||||
origResp *dns.Msg
|
origResp *dns.Msg
|
||||||
|
@ -70,7 +70,7 @@ func (s *Server) handleDNSRequest(_ *proxy.Proxy, d *proxy.DNSContext) error {
|
||||||
ctx := &dnsContext{
|
ctx := &dnsContext{
|
||||||
srv: s,
|
srv: s,
|
||||||
proxyCtx: d,
|
proxyCtx: d,
|
||||||
result: &dnsfilter.Result{},
|
result: &filtering.Result{},
|
||||||
startTime: time.Now(),
|
startTime: time.Now(),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -564,8 +564,8 @@ func processFilteringAfterResponse(ctx *dnsContext) (rc resultCode) {
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
switch res.Reason {
|
switch res.Reason {
|
||||||
case dnsfilter.Rewritten,
|
case filtering.Rewritten,
|
||||||
dnsfilter.RewrittenRule:
|
filtering.RewrittenRule:
|
||||||
|
|
||||||
if len(ctx.origQuestion.Name) == 0 {
|
if len(ctx.origQuestion.Name) == 0 {
|
||||||
// origQuestion is set in case we get only CNAME without IP from rewrites table
|
// origQuestion is set in case we get only CNAME without IP from rewrites table
|
||||||
|
@ -582,7 +582,7 @@ func processFilteringAfterResponse(ctx *dnsContext) (rc resultCode) {
|
||||||
d.Res.Answer = answer
|
d.Res.Answer = answer
|
||||||
}
|
}
|
||||||
|
|
||||||
case dnsfilter.NotFilteredAllowList:
|
case filtering.NotFilteredAllowList:
|
||||||
// nothing
|
// nothing
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
@ -599,7 +599,7 @@ func processFilteringAfterResponse(ctx *dnsContext) (rc resultCode) {
|
||||||
if ctx.result != nil {
|
if ctx.result != nil {
|
||||||
ctx.origResp = origResp2 // matched by response
|
ctx.origResp = origResp2 // matched by response
|
||||||
} else {
|
} else {
|
||||||
ctx.result = &dnsfilter.Result{}
|
ctx.result = &filtering.Result{}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@ import (
|
||||||
|
|
||||||
"github.com/AdguardTeam/AdGuardHome/internal/aghnet"
|
"github.com/AdguardTeam/AdGuardHome/internal/aghnet"
|
||||||
"github.com/AdguardTeam/AdGuardHome/internal/aghtest"
|
"github.com/AdguardTeam/AdGuardHome/internal/aghtest"
|
||||||
"github.com/AdguardTeam/AdGuardHome/internal/dnsfilter"
|
"github.com/AdguardTeam/AdGuardHome/internal/filtering"
|
||||||
"github.com/AdguardTeam/dnsproxy/proxy"
|
"github.com/AdguardTeam/dnsproxy/proxy"
|
||||||
"github.com/AdguardTeam/dnsproxy/upstream"
|
"github.com/AdguardTeam/dnsproxy/upstream"
|
||||||
"github.com/miekg/dns"
|
"github.com/miekg/dns"
|
||||||
|
@ -267,7 +267,7 @@ func TestLocalRestriction(t *testing.T) {
|
||||||
"1.1.168.192.in-addr.arpa.": {"some.local-client."},
|
"1.1.168.192.in-addr.arpa.": {"some.local-client."},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
s := createTestServer(t, &dnsfilter.Config{}, ServerConfig{
|
s := createTestServer(t, &filtering.Config{}, ServerConfig{
|
||||||
UDPListenAddrs: []*net.UDPAddr{{}},
|
UDPListenAddrs: []*net.UDPAddr{{}},
|
||||||
TCPListenAddrs: []*net.TCPAddr{{}},
|
TCPListenAddrs: []*net.TCPAddr{{}},
|
||||||
}, ups)
|
}, ups)
|
||||||
|
|
|
@ -16,7 +16,7 @@ import (
|
||||||
"github.com/AdguardTeam/AdGuardHome/internal/aghnet"
|
"github.com/AdguardTeam/AdGuardHome/internal/aghnet"
|
||||||
"github.com/AdguardTeam/AdGuardHome/internal/aghstrings"
|
"github.com/AdguardTeam/AdGuardHome/internal/aghstrings"
|
||||||
"github.com/AdguardTeam/AdGuardHome/internal/dhcpd"
|
"github.com/AdguardTeam/AdGuardHome/internal/dhcpd"
|
||||||
"github.com/AdguardTeam/AdGuardHome/internal/dnsfilter"
|
"github.com/AdguardTeam/AdGuardHome/internal/filtering"
|
||||||
"github.com/AdguardTeam/AdGuardHome/internal/querylog"
|
"github.com/AdguardTeam/AdGuardHome/internal/querylog"
|
||||||
"github.com/AdguardTeam/AdGuardHome/internal/stats"
|
"github.com/AdguardTeam/AdGuardHome/internal/stats"
|
||||||
"github.com/AdguardTeam/dnsproxy/proxy"
|
"github.com/AdguardTeam/dnsproxy/proxy"
|
||||||
|
@ -64,7 +64,7 @@ type ipToHostTable = map[string]string
|
||||||
// The zero Server is empty and ready for use.
|
// The zero Server is empty and ready for use.
|
||||||
type Server struct {
|
type Server struct {
|
||||||
dnsProxy *proxy.Proxy // DNS proxy instance
|
dnsProxy *proxy.Proxy // DNS proxy instance
|
||||||
dnsFilter *dnsfilter.DNSFilter // DNS filter instance
|
dnsFilter *filtering.DNSFilter // DNS filter instance
|
||||||
dhcpServer dhcpd.ServerInterface // DHCP server instance (optional)
|
dhcpServer dhcpd.ServerInterface // DHCP server instance (optional)
|
||||||
queryLog querylog.QueryLog // Query log instance
|
queryLog querylog.QueryLog // Query log instance
|
||||||
stats stats.Stats
|
stats stats.Stats
|
||||||
|
@ -102,7 +102,7 @@ const defaultLocalDomainSuffix = ".lan."
|
||||||
|
|
||||||
// DNSCreateParams are parameters to create a new server.
|
// DNSCreateParams are parameters to create a new server.
|
||||||
type DNSCreateParams struct {
|
type DNSCreateParams struct {
|
||||||
DNSFilter *dnsfilter.DNSFilter
|
DNSFilter *filtering.DNSFilter
|
||||||
Stats stats.Stats
|
Stats stats.Stats
|
||||||
QueryLog querylog.QueryLog
|
QueryLog querylog.QueryLog
|
||||||
DHCPServer dhcpd.ServerInterface
|
DHCPServer dhcpd.ServerInterface
|
||||||
|
|
|
@ -21,7 +21,7 @@ import (
|
||||||
"github.com/AdguardTeam/AdGuardHome/internal/aghnet"
|
"github.com/AdguardTeam/AdGuardHome/internal/aghnet"
|
||||||
"github.com/AdguardTeam/AdGuardHome/internal/aghtest"
|
"github.com/AdguardTeam/AdGuardHome/internal/aghtest"
|
||||||
"github.com/AdguardTeam/AdGuardHome/internal/dhcpd"
|
"github.com/AdguardTeam/AdGuardHome/internal/dhcpd"
|
||||||
"github.com/AdguardTeam/AdGuardHome/internal/dnsfilter"
|
"github.com/AdguardTeam/AdGuardHome/internal/filtering"
|
||||||
"github.com/AdguardTeam/dnsproxy/proxy"
|
"github.com/AdguardTeam/dnsproxy/proxy"
|
||||||
"github.com/AdguardTeam/dnsproxy/upstream"
|
"github.com/AdguardTeam/dnsproxy/upstream"
|
||||||
"github.com/miekg/dns"
|
"github.com/miekg/dns"
|
||||||
|
@ -52,7 +52,7 @@ func startDeferStop(t *testing.T, s *Server) {
|
||||||
|
|
||||||
func createTestServer(
|
func createTestServer(
|
||||||
t *testing.T,
|
t *testing.T,
|
||||||
filterConf *dnsfilter.Config,
|
filterConf *filtering.Config,
|
||||||
forwardConf ServerConfig,
|
forwardConf ServerConfig,
|
||||||
localUps upstream.Upstream,
|
localUps upstream.Upstream,
|
||||||
) (s *Server) {
|
) (s *Server) {
|
||||||
|
@ -63,11 +63,11 @@ func createTestServer(
|
||||||
127.0.0.1 host.example.org
|
127.0.0.1 host.example.org
|
||||||
@@||whitelist.example.org^
|
@@||whitelist.example.org^
|
||||||
||127.0.0.255`
|
||127.0.0.255`
|
||||||
filters := []dnsfilter.Filter{{
|
filters := []filtering.Filter{{
|
||||||
ID: 0, Data: []byte(rules),
|
ID: 0, Data: []byte(rules),
|
||||||
}}
|
}}
|
||||||
|
|
||||||
f := dnsfilter.New(filterConf, filters)
|
f := filtering.New(filterConf, filters)
|
||||||
|
|
||||||
snd, err := aghnet.NewSubnetDetector()
|
snd, err := aghnet.NewSubnetDetector()
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
@ -145,7 +145,7 @@ func createTestTLS(t *testing.T, tlsConf TLSConfig) (s *Server, certPem []byte)
|
||||||
var keyPem []byte
|
var keyPem []byte
|
||||||
_, certPem, keyPem = createServerTLSConfig(t)
|
_, certPem, keyPem = createServerTLSConfig(t)
|
||||||
|
|
||||||
s = createTestServer(t, &dnsfilter.Config{}, ServerConfig{
|
s = createTestServer(t, &filtering.Config{}, ServerConfig{
|
||||||
UDPListenAddrs: []*net.UDPAddr{{}},
|
UDPListenAddrs: []*net.UDPAddr{{}},
|
||||||
TCPListenAddrs: []*net.TCPAddr{{}},
|
TCPListenAddrs: []*net.TCPAddr{{}},
|
||||||
}, nil)
|
}, nil)
|
||||||
|
@ -241,7 +241,7 @@ func sendTestMessages(t *testing.T, conn *dns.Conn) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestServer(t *testing.T) {
|
func TestServer(t *testing.T) {
|
||||||
s := createTestServer(t, &dnsfilter.Config{}, ServerConfig{
|
s := createTestServer(t, &filtering.Config{}, ServerConfig{
|
||||||
UDPListenAddrs: []*net.UDPAddr{{}},
|
UDPListenAddrs: []*net.UDPAddr{{}},
|
||||||
TCPListenAddrs: []*net.TCPAddr{{}},
|
TCPListenAddrs: []*net.TCPAddr{{}},
|
||||||
}, nil)
|
}, nil)
|
||||||
|
@ -279,7 +279,7 @@ func TestServer(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestServerWithProtectionDisabled(t *testing.T) {
|
func TestServerWithProtectionDisabled(t *testing.T) {
|
||||||
s := createTestServer(t, &dnsfilter.Config{}, ServerConfig{
|
s := createTestServer(t, &filtering.Config{}, ServerConfig{
|
||||||
UDPListenAddrs: []*net.UDPAddr{{}},
|
UDPListenAddrs: []*net.UDPAddr{{}},
|
||||||
TCPListenAddrs: []*net.TCPAddr{{}},
|
TCPListenAddrs: []*net.TCPAddr{{}},
|
||||||
}, nil)
|
}, nil)
|
||||||
|
@ -362,7 +362,7 @@ func TestDoQServer(t *testing.T) {
|
||||||
func TestServerRace(t *testing.T) {
|
func TestServerRace(t *testing.T) {
|
||||||
t.Skip("TODO(e.burkov): inspect the golibs/cache package for locks")
|
t.Skip("TODO(e.burkov): inspect the golibs/cache package for locks")
|
||||||
|
|
||||||
filterConf := &dnsfilter.Config{
|
filterConf := &filtering.Config{
|
||||||
SafeBrowsingEnabled: true,
|
SafeBrowsingEnabled: true,
|
||||||
SafeBrowsingCacheSize: 1000,
|
SafeBrowsingCacheSize: 1000,
|
||||||
SafeSearchEnabled: true,
|
SafeSearchEnabled: true,
|
||||||
|
@ -399,7 +399,7 @@ func TestServerRace(t *testing.T) {
|
||||||
|
|
||||||
func TestSafeSearch(t *testing.T) {
|
func TestSafeSearch(t *testing.T) {
|
||||||
resolver := &aghtest.TestResolver{}
|
resolver := &aghtest.TestResolver{}
|
||||||
filterConf := &dnsfilter.Config{
|
filterConf := &filtering.Config{
|
||||||
SafeSearchEnabled: true,
|
SafeSearchEnabled: true,
|
||||||
SafeSearchCacheSize: 1000,
|
SafeSearchCacheSize: 1000,
|
||||||
CacheTime: 30,
|
CacheTime: 30,
|
||||||
|
@ -462,7 +462,7 @@ func TestSafeSearch(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestInvalidRequest(t *testing.T) {
|
func TestInvalidRequest(t *testing.T) {
|
||||||
s := createTestServer(t, &dnsfilter.Config{}, ServerConfig{
|
s := createTestServer(t, &filtering.Config{}, ServerConfig{
|
||||||
UDPListenAddrs: []*net.UDPAddr{{}},
|
UDPListenAddrs: []*net.UDPAddr{{}},
|
||||||
TCPListenAddrs: []*net.TCPAddr{{}},
|
TCPListenAddrs: []*net.TCPAddr{{}},
|
||||||
}, nil)
|
}, nil)
|
||||||
|
@ -493,7 +493,7 @@ func TestBlockedRequest(t *testing.T) {
|
||||||
ProtectionEnabled: true,
|
ProtectionEnabled: true,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
s := createTestServer(t, &dnsfilter.Config{}, forwardConf, nil)
|
s := createTestServer(t, &filtering.Config{}, forwardConf, nil)
|
||||||
startDeferStop(t, s)
|
startDeferStop(t, s)
|
||||||
|
|
||||||
addr := s.dnsProxy.Addr(proxy.ProtoUDP)
|
addr := s.dnsProxy.Addr(proxy.ProtoUDP)
|
||||||
|
@ -518,7 +518,7 @@ func TestServerCustomClientUpstream(t *testing.T) {
|
||||||
ProtectionEnabled: true,
|
ProtectionEnabled: true,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
s := createTestServer(t, &dnsfilter.Config{}, forwardConf, nil)
|
s := createTestServer(t, &filtering.Config{}, forwardConf, nil)
|
||||||
s.conf.GetCustomUpstreamByClient = func(_ string) *proxy.UpstreamConfig {
|
s.conf.GetCustomUpstreamByClient = func(_ string) *proxy.UpstreamConfig {
|
||||||
return &proxy.UpstreamConfig{
|
return &proxy.UpstreamConfig{
|
||||||
Upstreams: []upstream.Upstream{
|
Upstreams: []upstream.Upstream{
|
||||||
|
@ -560,7 +560,7 @@ var testIPv4 = map[string][]net.IP{
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestBlockCNAMEProtectionEnabled(t *testing.T) {
|
func TestBlockCNAMEProtectionEnabled(t *testing.T) {
|
||||||
s := createTestServer(t, &dnsfilter.Config{}, ServerConfig{
|
s := createTestServer(t, &filtering.Config{}, ServerConfig{
|
||||||
UDPListenAddrs: []*net.UDPAddr{{}},
|
UDPListenAddrs: []*net.UDPAddr{{}},
|
||||||
TCPListenAddrs: []*net.TCPAddr{{}},
|
TCPListenAddrs: []*net.TCPAddr{{}},
|
||||||
}, nil)
|
}, nil)
|
||||||
|
@ -595,7 +595,7 @@ func TestBlockCNAME(t *testing.T) {
|
||||||
ProtectionEnabled: true,
|
ProtectionEnabled: true,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
s := createTestServer(t, &dnsfilter.Config{}, forwardConf, nil)
|
s := createTestServer(t, &filtering.Config{}, forwardConf, nil)
|
||||||
s.conf.UpstreamConfig.Upstreams = []upstream.Upstream{
|
s.conf.UpstreamConfig.Upstreams = []upstream.Upstream{
|
||||||
&aghtest.TestUpstream{
|
&aghtest.TestUpstream{
|
||||||
CName: testCNAMEs,
|
CName: testCNAMEs,
|
||||||
|
@ -652,12 +652,12 @@ func TestClientRulesForCNAMEMatching(t *testing.T) {
|
||||||
TCPListenAddrs: []*net.TCPAddr{{}},
|
TCPListenAddrs: []*net.TCPAddr{{}},
|
||||||
FilteringConfig: FilteringConfig{
|
FilteringConfig: FilteringConfig{
|
||||||
ProtectionEnabled: true,
|
ProtectionEnabled: true,
|
||||||
FilterHandler: func(_ net.IP, _ string, settings *dnsfilter.FilteringSettings) {
|
FilterHandler: func(_ net.IP, _ string, settings *filtering.Settings) {
|
||||||
settings.FilteringEnabled = false
|
settings.FilteringEnabled = false
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
s := createTestServer(t, &dnsfilter.Config{}, forwardConf, nil)
|
s := createTestServer(t, &filtering.Config{}, forwardConf, nil)
|
||||||
s.conf.UpstreamConfig.Upstreams = []upstream.Upstream{
|
s.conf.UpstreamConfig.Upstreams = []upstream.Upstream{
|
||||||
&aghtest.TestUpstream{
|
&aghtest.TestUpstream{
|
||||||
CName: testCNAMEs,
|
CName: testCNAMEs,
|
||||||
|
@ -698,7 +698,7 @@ func TestNullBlockedRequest(t *testing.T) {
|
||||||
BlockingMode: "null_ip",
|
BlockingMode: "null_ip",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
s := createTestServer(t, &dnsfilter.Config{}, forwardConf, nil)
|
s := createTestServer(t, &filtering.Config{}, forwardConf, nil)
|
||||||
startDeferStop(t, s)
|
startDeferStop(t, s)
|
||||||
addr := s.dnsProxy.Addr(proxy.ProtoUDP)
|
addr := s.dnsProxy.Addr(proxy.ProtoUDP)
|
||||||
|
|
||||||
|
@ -725,7 +725,7 @@ func TestNullBlockedRequest(t *testing.T) {
|
||||||
|
|
||||||
func TestBlockedCustomIP(t *testing.T) {
|
func TestBlockedCustomIP(t *testing.T) {
|
||||||
rules := "||nxdomain.example.org^\n||null.example.org^\n127.0.0.1 host.example.org\n@@||whitelist.example.org^\n||127.0.0.255\n"
|
rules := "||nxdomain.example.org^\n||null.example.org^\n127.0.0.1 host.example.org\n@@||whitelist.example.org^\n||127.0.0.255\n"
|
||||||
filters := []dnsfilter.Filter{{
|
filters := []filtering.Filter{{
|
||||||
ID: 0,
|
ID: 0,
|
||||||
Data: []byte(rules),
|
Data: []byte(rules),
|
||||||
}}
|
}}
|
||||||
|
@ -737,7 +737,7 @@ func TestBlockedCustomIP(t *testing.T) {
|
||||||
var s *Server
|
var s *Server
|
||||||
s, err = NewServer(DNSCreateParams{
|
s, err = NewServer(DNSCreateParams{
|
||||||
DHCPServer: &testDHCP{},
|
DHCPServer: &testDHCP{},
|
||||||
DNSFilter: dnsfilter.New(&dnsfilter.Config{}, filters),
|
DNSFilter: filtering.New(&filtering.Config{}, filters),
|
||||||
SubnetDetector: snd,
|
SubnetDetector: snd,
|
||||||
})
|
})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
@ -798,7 +798,7 @@ func TestBlockedByHosts(t *testing.T) {
|
||||||
ProtectionEnabled: true,
|
ProtectionEnabled: true,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
s := createTestServer(t, &dnsfilter.Config{}, forwardConf, nil)
|
s := createTestServer(t, &filtering.Config{}, forwardConf, nil)
|
||||||
startDeferStop(t, s)
|
startDeferStop(t, s)
|
||||||
addr := s.dnsProxy.Addr(proxy.ProtoUDP)
|
addr := s.dnsProxy.Addr(proxy.ProtoUDP)
|
||||||
|
|
||||||
|
@ -822,7 +822,7 @@ func TestBlockedBySafeBrowsing(t *testing.T) {
|
||||||
}
|
}
|
||||||
ans4, _ := (&aghtest.TestResolver{}).HostToIPs(hostname)
|
ans4, _ := (&aghtest.TestResolver{}).HostToIPs(hostname)
|
||||||
|
|
||||||
filterConf := &dnsfilter.Config{
|
filterConf := &filtering.Config{
|
||||||
SafeBrowsingEnabled: true,
|
SafeBrowsingEnabled: true,
|
||||||
}
|
}
|
||||||
forwardConf := ServerConfig{
|
forwardConf := ServerConfig{
|
||||||
|
@ -851,8 +851,8 @@ func TestBlockedBySafeBrowsing(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRewrite(t *testing.T) {
|
func TestRewrite(t *testing.T) {
|
||||||
c := &dnsfilter.Config{
|
c := &filtering.Config{
|
||||||
Rewrites: []dnsfilter.RewriteEntry{{
|
Rewrites: []filtering.RewriteEntry{{
|
||||||
Domain: "test.com",
|
Domain: "test.com",
|
||||||
Answer: "1.2.3.4",
|
Answer: "1.2.3.4",
|
||||||
Type: dns.TypeA,
|
Type: dns.TypeA,
|
||||||
|
@ -866,7 +866,7 @@ func TestRewrite(t *testing.T) {
|
||||||
Type: dns.TypeCNAME,
|
Type: dns.TypeCNAME,
|
||||||
}},
|
}},
|
||||||
}
|
}
|
||||||
f := dnsfilter.New(c, nil)
|
f := filtering.New(c, nil)
|
||||||
|
|
||||||
snd, err := aghnet.NewSubnetDetector()
|
snd, err := aghnet.NewSubnetDetector()
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
@ -1038,7 +1038,7 @@ func TestPTRResponseFromDHCPLeases(t *testing.T) {
|
||||||
|
|
||||||
var s *Server
|
var s *Server
|
||||||
s, err = NewServer(DNSCreateParams{
|
s, err = NewServer(DNSCreateParams{
|
||||||
DNSFilter: dnsfilter.New(&dnsfilter.Config{}, nil),
|
DNSFilter: filtering.New(&filtering.Config{}, nil),
|
||||||
DHCPServer: &testDHCP{},
|
DHCPServer: &testDHCP{},
|
||||||
SubnetDetector: snd,
|
SubnetDetector: snd,
|
||||||
})
|
})
|
||||||
|
@ -1076,7 +1076,7 @@ func TestPTRResponseFromDHCPLeases(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPTRResponseFromHosts(t *testing.T) {
|
func TestPTRResponseFromHosts(t *testing.T) {
|
||||||
c := dnsfilter.Config{
|
c := filtering.Config{
|
||||||
EtcHosts: &aghnet.EtcHostsContainer{},
|
EtcHosts: &aghnet.EtcHostsContainer{},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1102,7 +1102,7 @@ func TestPTRResponseFromHosts(t *testing.T) {
|
||||||
var s *Server
|
var s *Server
|
||||||
s, err = NewServer(DNSCreateParams{
|
s, err = NewServer(DNSCreateParams{
|
||||||
DHCPServer: &testDHCP{},
|
DHCPServer: &testDHCP{},
|
||||||
DNSFilter: dnsfilter.New(&c, nil),
|
DNSFilter: filtering.New(&c, nil),
|
||||||
SubnetDetector: snd,
|
SubnetDetector: snd,
|
||||||
})
|
})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
|
@ -5,7 +5,7 @@ import (
|
||||||
"net"
|
"net"
|
||||||
|
|
||||||
"github.com/AdguardTeam/AdGuardHome/internal/agherr"
|
"github.com/AdguardTeam/AdGuardHome/internal/agherr"
|
||||||
"github.com/AdguardTeam/AdGuardHome/internal/dnsfilter"
|
"github.com/AdguardTeam/AdGuardHome/internal/filtering"
|
||||||
"github.com/AdguardTeam/dnsproxy/proxy"
|
"github.com/AdguardTeam/dnsproxy/proxy"
|
||||||
"github.com/AdguardTeam/golibs/log"
|
"github.com/AdguardTeam/golibs/log"
|
||||||
"github.com/AdguardTeam/urlfilter/rules"
|
"github.com/AdguardTeam/urlfilter/rules"
|
||||||
|
@ -79,7 +79,7 @@ func (s *Server) filterDNSRewriteResponse(req *dns.Msg, rr rules.RRType, v rules
|
||||||
|
|
||||||
// filterDNSRewrite handles dnsrewrite filters. It constructs a DNS
|
// filterDNSRewrite handles dnsrewrite filters. It constructs a DNS
|
||||||
// response and sets it into d.Res.
|
// response and sets it into d.Res.
|
||||||
func (s *Server) filterDNSRewrite(req *dns.Msg, res dnsfilter.Result, d *proxy.DNSContext) (err error) {
|
func (s *Server) filterDNSRewrite(req *dns.Msg, res filtering.Result, d *proxy.DNSContext) (err error) {
|
||||||
resp := s.makeResponse(req)
|
resp := s.makeResponse(req)
|
||||||
dnsrr := res.DNSRewriteResult
|
dnsrr := res.DNSRewriteResult
|
||||||
if dnsrr == nil {
|
if dnsrr == nil {
|
||||||
|
|
|
@ -4,7 +4,7 @@ import (
|
||||||
"net"
|
"net"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/AdguardTeam/AdGuardHome/internal/dnsfilter"
|
"github.com/AdguardTeam/AdGuardHome/internal/filtering"
|
||||||
"github.com/AdguardTeam/dnsproxy/proxy"
|
"github.com/AdguardTeam/dnsproxy/proxy"
|
||||||
"github.com/AdguardTeam/urlfilter/rules"
|
"github.com/AdguardTeam/urlfilter/rules"
|
||||||
"github.com/miekg/dns"
|
"github.com/miekg/dns"
|
||||||
|
@ -42,12 +42,12 @@ func TestServer_FilterDNSRewrite(t *testing.T) {
|
||||||
}},
|
}},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
makeRes := func(rcode rules.RCode, rr rules.RRType, v rules.RRValue) (res dnsfilter.Result) {
|
makeRes := func(rcode rules.RCode, rr rules.RRType, v rules.RRValue) (res filtering.Result) {
|
||||||
resp := dnsfilter.DNSRewriteResultResponse{
|
resp := filtering.DNSRewriteResultResponse{
|
||||||
rr: []rules.RRValue{v},
|
rr: []rules.RRValue{v},
|
||||||
}
|
}
|
||||||
return dnsfilter.Result{
|
return filtering.Result{
|
||||||
DNSRewriteResult: &dnsfilter.DNSRewriteResult{
|
DNSRewriteResult: &filtering.DNSRewriteResult{
|
||||||
RCode: rcode,
|
RCode: rcode,
|
||||||
Response: resp,
|
Response: resp,
|
||||||
},
|
},
|
||||||
|
|
|
@ -4,7 +4,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/AdguardTeam/AdGuardHome/internal/dnsfilter"
|
"github.com/AdguardTeam/AdGuardHome/internal/filtering"
|
||||||
"github.com/AdguardTeam/dnsproxy/proxy"
|
"github.com/AdguardTeam/dnsproxy/proxy"
|
||||||
"github.com/AdguardTeam/golibs/log"
|
"github.com/AdguardTeam/golibs/log"
|
||||||
|
|
||||||
|
@ -36,7 +36,7 @@ func (s *Server) beforeRequestHandler(_ *proxy.Proxy, d *proxy.DNSContext) (bool
|
||||||
|
|
||||||
// getClientRequestFilteringSettings looks up client filtering settings using
|
// getClientRequestFilteringSettings looks up client filtering settings using
|
||||||
// the client's IP address and ID, if any, from ctx.
|
// the client's IP address and ID, if any, from ctx.
|
||||||
func (s *Server) getClientRequestFilteringSettings(ctx *dnsContext) *dnsfilter.FilteringSettings {
|
func (s *Server) getClientRequestFilteringSettings(ctx *dnsContext) *filtering.Settings {
|
||||||
setts := s.dnsFilter.GetConfig()
|
setts := s.dnsFilter.GetConfig()
|
||||||
setts.FilteringEnabled = true
|
setts.FilteringEnabled = true
|
||||||
if s.conf.FilterHandler != nil {
|
if s.conf.FilterHandler != nil {
|
||||||
|
@ -48,18 +48,18 @@ func (s *Server) getClientRequestFilteringSettings(ctx *dnsContext) *dnsfilter.F
|
||||||
|
|
||||||
// filterDNSRequest applies the dnsFilter and sets d.Res if the request was
|
// filterDNSRequest applies the dnsFilter and sets d.Res if the request was
|
||||||
// filtered.
|
// filtered.
|
||||||
func (s *Server) filterDNSRequest(ctx *dnsContext) (*dnsfilter.Result, error) {
|
func (s *Server) filterDNSRequest(ctx *dnsContext) (*filtering.Result, error) {
|
||||||
d := ctx.proxyCtx
|
d := ctx.proxyCtx
|
||||||
req := d.Req
|
req := d.Req
|
||||||
host := strings.TrimSuffix(req.Question[0].Name, ".")
|
host := strings.TrimSuffix(req.Question[0].Name, ".")
|
||||||
res, err := s.dnsFilter.CheckHost(host, req.Question[0].Qtype, ctx.setts)
|
res, err := s.dnsFilter.CheckHost(host, req.Question[0].Qtype, ctx.setts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// Return immediately if there's an error
|
// Return immediately if there's an error
|
||||||
return nil, fmt.Errorf("dnsfilter failed to check host %q: %w", host, err)
|
return nil, fmt.Errorf("filtering failed to check host %q: %w", host, err)
|
||||||
} else if res.IsFiltered {
|
} else if res.IsFiltered {
|
||||||
log.Tracef("Host %s is filtered, reason - %q, matched rule: %q", host, res.Reason, res.Rules[0].Text)
|
log.Tracef("Host %s is filtered, reason - %q, matched rule: %q", host, res.Reason, res.Rules[0].Text)
|
||||||
d.Res = s.genDNSFilterMessage(d, &res)
|
d.Res = s.genDNSFilterMessage(d, &res)
|
||||||
} else if res.Reason.In(dnsfilter.Rewritten, dnsfilter.RewrittenRule) &&
|
} else if res.Reason.In(filtering.Rewritten, filtering.RewrittenRule) &&
|
||||||
res.CanonName != "" &&
|
res.CanonName != "" &&
|
||||||
len(res.IPList) == 0 {
|
len(res.IPList) == 0 {
|
||||||
// Resolve the new canonical name, not the original host
|
// Resolve the new canonical name, not the original host
|
||||||
|
@ -67,7 +67,7 @@ func (s *Server) filterDNSRequest(ctx *dnsContext) (*dnsfilter.Result, error) {
|
||||||
// processFilteringAfterResponse.
|
// processFilteringAfterResponse.
|
||||||
ctx.origQuestion = req.Question[0]
|
ctx.origQuestion = req.Question[0]
|
||||||
req.Question[0].Name = dns.Fqdn(res.CanonName)
|
req.Question[0].Name = dns.Fqdn(res.CanonName)
|
||||||
} else if res.Reason == dnsfilter.RewrittenAutoHosts && len(res.ReverseHosts) != 0 {
|
} else if res.Reason == filtering.RewrittenAutoHosts && len(res.ReverseHosts) != 0 {
|
||||||
resp := s.makeResponse(req)
|
resp := s.makeResponse(req)
|
||||||
for _, h := range res.ReverseHosts {
|
for _, h := range res.ReverseHosts {
|
||||||
hdr := dns.RR_Header{
|
hdr := dns.RR_Header{
|
||||||
|
@ -86,7 +86,7 @@ func (s *Server) filterDNSRequest(ctx *dnsContext) (*dnsfilter.Result, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
d.Res = resp
|
d.Res = resp
|
||||||
} else if res.Reason.In(dnsfilter.Rewritten, dnsfilter.RewrittenAutoHosts) {
|
} else if res.Reason.In(filtering.Rewritten, filtering.RewrittenAutoHosts) {
|
||||||
resp := s.makeResponse(req)
|
resp := s.makeResponse(req)
|
||||||
|
|
||||||
name := host
|
name := host
|
||||||
|
@ -108,7 +108,7 @@ func (s *Server) filterDNSRequest(ctx *dnsContext) (*dnsfilter.Result, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
d.Res = resp
|
d.Res = resp
|
||||||
} else if res.Reason == dnsfilter.RewrittenRule {
|
} else if res.Reason == filtering.RewrittenRule {
|
||||||
err = s.filterDNSRewrite(req, res, d)
|
err = s.filterDNSRewrite(req, res, d)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -120,7 +120,7 @@ func (s *Server) filterDNSRequest(ctx *dnsContext) (*dnsfilter.Result, error) {
|
||||||
|
|
||||||
// If response contains CNAME, A or AAAA records, we apply filtering to each canonical host name or IP address.
|
// If response contains CNAME, A or AAAA records, we apply filtering to each canonical host name or IP address.
|
||||||
// If this is a match, we set a new response in d.Res and return.
|
// If this is a match, we set a new response in d.Res and return.
|
||||||
func (s *Server) filterDNSResponse(ctx *dnsContext) (*dnsfilter.Result, error) {
|
func (s *Server) filterDNSResponse(ctx *dnsContext) (*filtering.Result, error) {
|
||||||
d := ctx.proxyCtx
|
d := ctx.proxyCtx
|
||||||
for _, a := range d.Res.Answer {
|
for _, a := range d.Res.Answer {
|
||||||
host := ""
|
host := ""
|
||||||
|
|
|
@ -12,7 +12,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/AdguardTeam/AdGuardHome/internal/dnsfilter"
|
"github.com/AdguardTeam/AdGuardHome/internal/filtering"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
@ -34,7 +34,7 @@ func loadTestData(t *testing.T, casesFileName string, cases interface{}) {
|
||||||
const jsonExt = ".json"
|
const jsonExt = ".json"
|
||||||
|
|
||||||
func TestDNSForwardHTTTP_handleGetConfig(t *testing.T) {
|
func TestDNSForwardHTTTP_handleGetConfig(t *testing.T) {
|
||||||
filterConf := &dnsfilter.Config{
|
filterConf := &filtering.Config{
|
||||||
SafeBrowsingEnabled: true,
|
SafeBrowsingEnabled: true,
|
||||||
SafeBrowsingCacheSize: 1000,
|
SafeBrowsingCacheSize: 1000,
|
||||||
SafeSearchEnabled: true,
|
SafeSearchEnabled: true,
|
||||||
|
@ -107,7 +107,7 @@ func TestDNSForwardHTTTP_handleGetConfig(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDNSForwardHTTTP_handleSetConfig(t *testing.T) {
|
func TestDNSForwardHTTTP_handleSetConfig(t *testing.T) {
|
||||||
filterConf := &dnsfilter.Config{
|
filterConf := &filtering.Config{
|
||||||
SafeBrowsingEnabled: true,
|
SafeBrowsingEnabled: true,
|
||||||
SafeBrowsingCacheSize: 1000,
|
SafeBrowsingCacheSize: 1000,
|
||||||
SafeSearchEnabled: true,
|
SafeSearchEnabled: true,
|
||||||
|
|
|
@ -4,7 +4,7 @@ import (
|
||||||
"net"
|
"net"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/AdguardTeam/AdGuardHome/internal/dnsfilter"
|
"github.com/AdguardTeam/AdGuardHome/internal/filtering"
|
||||||
"github.com/AdguardTeam/dnsproxy/proxy"
|
"github.com/AdguardTeam/dnsproxy/proxy"
|
||||||
"github.com/AdguardTeam/golibs/log"
|
"github.com/AdguardTeam/golibs/log"
|
||||||
"github.com/AdguardTeam/urlfilter/rules"
|
"github.com/AdguardTeam/urlfilter/rules"
|
||||||
|
@ -27,7 +27,7 @@ func (s *Server) makeResponse(req *dns.Msg) (resp *dns.Msg) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// genDNSFilterMessage generates a DNS message corresponding to the filtering result
|
// genDNSFilterMessage generates a DNS message corresponding to the filtering result
|
||||||
func (s *Server) genDNSFilterMessage(d *proxy.DNSContext, result *dnsfilter.Result) *dns.Msg {
|
func (s *Server) genDNSFilterMessage(d *proxy.DNSContext, result *filtering.Result) *dns.Msg {
|
||||||
m := d.Req
|
m := d.Req
|
||||||
|
|
||||||
if m.Question[0].Qtype != dns.TypeA && m.Question[0].Qtype != dns.TypeAAAA {
|
if m.Question[0].Qtype != dns.TypeA && m.Question[0].Qtype != dns.TypeAAAA {
|
||||||
|
@ -38,15 +38,15 @@ func (s *Server) genDNSFilterMessage(d *proxy.DNSContext, result *dnsfilter.Resu
|
||||||
}
|
}
|
||||||
|
|
||||||
switch result.Reason {
|
switch result.Reason {
|
||||||
case dnsfilter.FilteredSafeBrowsing:
|
case filtering.FilteredSafeBrowsing:
|
||||||
return s.genBlockedHost(m, s.conf.SafeBrowsingBlockHost, d)
|
return s.genBlockedHost(m, s.conf.SafeBrowsingBlockHost, d)
|
||||||
case dnsfilter.FilteredParental:
|
case filtering.FilteredParental:
|
||||||
return s.genBlockedHost(m, s.conf.ParentalBlockHost, d)
|
return s.genBlockedHost(m, s.conf.ParentalBlockHost, d)
|
||||||
default:
|
default:
|
||||||
// If the query was filtered by "Safe search", dnsfilter also must return
|
// If the query was filtered by "Safe search", filtering also must return
|
||||||
// the IP address that must be used in response.
|
// the IP address that must be used in response.
|
||||||
// In this case regardless of the filtering method, we should return it
|
// In this case regardless of the filtering method, we should return it
|
||||||
if result.Reason == dnsfilter.FilteredSafeSearch &&
|
if result.Reason == filtering.FilteredSafeSearch &&
|
||||||
len(result.Rules) > 0 &&
|
len(result.Rules) > 0 &&
|
||||||
result.Rules[0].IP != nil {
|
result.Rules[0].IP != nil {
|
||||||
return s.genResponseWithIP(m, result.Rules[0].IP)
|
return s.genResponseWithIP(m, result.Rules[0].IP)
|
||||||
|
|
|
@ -4,7 +4,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/AdguardTeam/AdGuardHome/internal/dnsfilter"
|
"github.com/AdguardTeam/AdGuardHome/internal/filtering"
|
||||||
"github.com/AdguardTeam/AdGuardHome/internal/querylog"
|
"github.com/AdguardTeam/AdGuardHome/internal/querylog"
|
||||||
"github.com/AdguardTeam/AdGuardHome/internal/stats"
|
"github.com/AdguardTeam/AdGuardHome/internal/stats"
|
||||||
"github.com/AdguardTeam/dnsproxy/proxy"
|
"github.com/AdguardTeam/dnsproxy/proxy"
|
||||||
|
@ -66,7 +66,7 @@ func processQueryLogsAndStats(ctx *dnsContext) (rc resultCode) {
|
||||||
return resultCodeSuccess
|
return resultCodeSuccess
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) updateStats(ctx *dnsContext, elapsed time.Duration, res dnsfilter.Result) {
|
func (s *Server) updateStats(ctx *dnsContext, elapsed time.Duration, res filtering.Result) {
|
||||||
if s.stats == nil {
|
if s.stats == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -86,17 +86,17 @@ func (s *Server) updateStats(ctx *dnsContext, elapsed time.Duration, res dnsfilt
|
||||||
e.Result = stats.RNotFiltered
|
e.Result = stats.RNotFiltered
|
||||||
|
|
||||||
switch res.Reason {
|
switch res.Reason {
|
||||||
case dnsfilter.FilteredSafeBrowsing:
|
case filtering.FilteredSafeBrowsing:
|
||||||
e.Result = stats.RSafeBrowsing
|
e.Result = stats.RSafeBrowsing
|
||||||
case dnsfilter.FilteredParental:
|
case filtering.FilteredParental:
|
||||||
e.Result = stats.RParental
|
e.Result = stats.RParental
|
||||||
case dnsfilter.FilteredSafeSearch:
|
case filtering.FilteredSafeSearch:
|
||||||
e.Result = stats.RSafeSearch
|
e.Result = stats.RSafeSearch
|
||||||
case dnsfilter.FilteredBlockList:
|
case filtering.FilteredBlockList:
|
||||||
fallthrough
|
fallthrough
|
||||||
case dnsfilter.FilteredInvalid:
|
case filtering.FilteredInvalid:
|
||||||
fallthrough
|
fallthrough
|
||||||
case dnsfilter.FilteredBlockedService:
|
case filtering.FilteredBlockedService:
|
||||||
e.Result = stats.RFiltered
|
e.Result = stats.RFiltered
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/AdguardTeam/AdGuardHome/internal/dnsfilter"
|
"github.com/AdguardTeam/AdGuardHome/internal/filtering"
|
||||||
"github.com/AdguardTeam/AdGuardHome/internal/querylog"
|
"github.com/AdguardTeam/AdGuardHome/internal/querylog"
|
||||||
"github.com/AdguardTeam/AdGuardHome/internal/stats"
|
"github.com/AdguardTeam/AdGuardHome/internal/stats"
|
||||||
"github.com/AdguardTeam/dnsproxy/proxy"
|
"github.com/AdguardTeam/dnsproxy/proxy"
|
||||||
|
@ -52,7 +52,7 @@ func TestProcessQueryLogsAndStats(t *testing.T) {
|
||||||
wantLogProto querylog.ClientProto
|
wantLogProto querylog.ClientProto
|
||||||
wantStatClient string
|
wantStatClient string
|
||||||
wantCode resultCode
|
wantCode resultCode
|
||||||
reason dnsfilter.Reason
|
reason filtering.Reason
|
||||||
wantStatResult stats.Result
|
wantStatResult stats.Result
|
||||||
}{{
|
}{{
|
||||||
name: "success_udp",
|
name: "success_udp",
|
||||||
|
@ -62,7 +62,7 @@ func TestProcessQueryLogsAndStats(t *testing.T) {
|
||||||
wantLogProto: "",
|
wantLogProto: "",
|
||||||
wantStatClient: "1.2.3.4",
|
wantStatClient: "1.2.3.4",
|
||||||
wantCode: resultCodeSuccess,
|
wantCode: resultCodeSuccess,
|
||||||
reason: dnsfilter.NotFilteredNotFound,
|
reason: filtering.NotFilteredNotFound,
|
||||||
wantStatResult: stats.RNotFiltered,
|
wantStatResult: stats.RNotFiltered,
|
||||||
}, {
|
}, {
|
||||||
name: "success_tls_client_id",
|
name: "success_tls_client_id",
|
||||||
|
@ -72,7 +72,7 @@ func TestProcessQueryLogsAndStats(t *testing.T) {
|
||||||
wantLogProto: querylog.ClientProtoDOT,
|
wantLogProto: querylog.ClientProtoDOT,
|
||||||
wantStatClient: "cli42",
|
wantStatClient: "cli42",
|
||||||
wantCode: resultCodeSuccess,
|
wantCode: resultCodeSuccess,
|
||||||
reason: dnsfilter.NotFilteredNotFound,
|
reason: filtering.NotFilteredNotFound,
|
||||||
wantStatResult: stats.RNotFiltered,
|
wantStatResult: stats.RNotFiltered,
|
||||||
}, {
|
}, {
|
||||||
name: "success_tls",
|
name: "success_tls",
|
||||||
|
@ -82,7 +82,7 @@ func TestProcessQueryLogsAndStats(t *testing.T) {
|
||||||
wantLogProto: querylog.ClientProtoDOT,
|
wantLogProto: querylog.ClientProtoDOT,
|
||||||
wantStatClient: "1.2.3.4",
|
wantStatClient: "1.2.3.4",
|
||||||
wantCode: resultCodeSuccess,
|
wantCode: resultCodeSuccess,
|
||||||
reason: dnsfilter.NotFilteredNotFound,
|
reason: filtering.NotFilteredNotFound,
|
||||||
wantStatResult: stats.RNotFiltered,
|
wantStatResult: stats.RNotFiltered,
|
||||||
}, {
|
}, {
|
||||||
name: "success_quic",
|
name: "success_quic",
|
||||||
|
@ -92,7 +92,7 @@ func TestProcessQueryLogsAndStats(t *testing.T) {
|
||||||
wantLogProto: querylog.ClientProtoDOQ,
|
wantLogProto: querylog.ClientProtoDOQ,
|
||||||
wantStatClient: "1.2.3.4",
|
wantStatClient: "1.2.3.4",
|
||||||
wantCode: resultCodeSuccess,
|
wantCode: resultCodeSuccess,
|
||||||
reason: dnsfilter.NotFilteredNotFound,
|
reason: filtering.NotFilteredNotFound,
|
||||||
wantStatResult: stats.RNotFiltered,
|
wantStatResult: stats.RNotFiltered,
|
||||||
}, {
|
}, {
|
||||||
name: "success_https",
|
name: "success_https",
|
||||||
|
@ -102,7 +102,7 @@ func TestProcessQueryLogsAndStats(t *testing.T) {
|
||||||
wantLogProto: querylog.ClientProtoDOH,
|
wantLogProto: querylog.ClientProtoDOH,
|
||||||
wantStatClient: "1.2.3.4",
|
wantStatClient: "1.2.3.4",
|
||||||
wantCode: resultCodeSuccess,
|
wantCode: resultCodeSuccess,
|
||||||
reason: dnsfilter.NotFilteredNotFound,
|
reason: filtering.NotFilteredNotFound,
|
||||||
wantStatResult: stats.RNotFiltered,
|
wantStatResult: stats.RNotFiltered,
|
||||||
}, {
|
}, {
|
||||||
name: "success_dnscrypt",
|
name: "success_dnscrypt",
|
||||||
|
@ -112,7 +112,7 @@ func TestProcessQueryLogsAndStats(t *testing.T) {
|
||||||
wantLogProto: querylog.ClientProtoDNSCrypt,
|
wantLogProto: querylog.ClientProtoDNSCrypt,
|
||||||
wantStatClient: "1.2.3.4",
|
wantStatClient: "1.2.3.4",
|
||||||
wantCode: resultCodeSuccess,
|
wantCode: resultCodeSuccess,
|
||||||
reason: dnsfilter.NotFilteredNotFound,
|
reason: filtering.NotFilteredNotFound,
|
||||||
wantStatResult: stats.RNotFiltered,
|
wantStatResult: stats.RNotFiltered,
|
||||||
}, {
|
}, {
|
||||||
name: "success_udp_filtered",
|
name: "success_udp_filtered",
|
||||||
|
@ -122,7 +122,7 @@ func TestProcessQueryLogsAndStats(t *testing.T) {
|
||||||
wantLogProto: "",
|
wantLogProto: "",
|
||||||
wantStatClient: "1.2.3.4",
|
wantStatClient: "1.2.3.4",
|
||||||
wantCode: resultCodeSuccess,
|
wantCode: resultCodeSuccess,
|
||||||
reason: dnsfilter.FilteredBlockList,
|
reason: filtering.FilteredBlockList,
|
||||||
wantStatResult: stats.RFiltered,
|
wantStatResult: stats.RFiltered,
|
||||||
}, {
|
}, {
|
||||||
name: "success_udp_sb",
|
name: "success_udp_sb",
|
||||||
|
@ -132,7 +132,7 @@ func TestProcessQueryLogsAndStats(t *testing.T) {
|
||||||
wantLogProto: "",
|
wantLogProto: "",
|
||||||
wantStatClient: "1.2.3.4",
|
wantStatClient: "1.2.3.4",
|
||||||
wantCode: resultCodeSuccess,
|
wantCode: resultCodeSuccess,
|
||||||
reason: dnsfilter.FilteredSafeBrowsing,
|
reason: filtering.FilteredSafeBrowsing,
|
||||||
wantStatResult: stats.RSafeBrowsing,
|
wantStatResult: stats.RSafeBrowsing,
|
||||||
}, {
|
}, {
|
||||||
name: "success_udp_ss",
|
name: "success_udp_ss",
|
||||||
|
@ -142,7 +142,7 @@ func TestProcessQueryLogsAndStats(t *testing.T) {
|
||||||
wantLogProto: "",
|
wantLogProto: "",
|
||||||
wantStatClient: "1.2.3.4",
|
wantStatClient: "1.2.3.4",
|
||||||
wantCode: resultCodeSuccess,
|
wantCode: resultCodeSuccess,
|
||||||
reason: dnsfilter.FilteredSafeSearch,
|
reason: filtering.FilteredSafeSearch,
|
||||||
wantStatResult: stats.RSafeSearch,
|
wantStatResult: stats.RSafeSearch,
|
||||||
}, {
|
}, {
|
||||||
name: "success_udp_pc",
|
name: "success_udp_pc",
|
||||||
|
@ -152,7 +152,7 @@ func TestProcessQueryLogsAndStats(t *testing.T) {
|
||||||
wantLogProto: "",
|
wantLogProto: "",
|
||||||
wantStatClient: "1.2.3.4",
|
wantStatClient: "1.2.3.4",
|
||||||
wantCode: resultCodeSuccess,
|
wantCode: resultCodeSuccess,
|
||||||
reason: dnsfilter.FilteredParental,
|
reason: filtering.FilteredParental,
|
||||||
wantStatResult: stats.RParental,
|
wantStatResult: stats.RParental,
|
||||||
}}
|
}}
|
||||||
|
|
||||||
|
@ -183,7 +183,7 @@ func TestProcessQueryLogsAndStats(t *testing.T) {
|
||||||
},
|
},
|
||||||
proxyCtx: pctx,
|
proxyCtx: pctx,
|
||||||
startTime: time.Now(),
|
startTime: time.Now(),
|
||||||
result: &dnsfilter.Result{
|
result: &filtering.Result{
|
||||||
Reason: tc.reason,
|
Reason: tc.reason,
|
||||||
},
|
},
|
||||||
clientID: tc.clientID,
|
clientID: tc.clientID,
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
Example use:
|
Example use:
|
||||||
```bash
|
```bash
|
||||||
[ -z "$GOPATH" ] && export GOPATH=$HOME/go
|
[ -z "$GOPATH" ] && export GOPATH=$HOME/go
|
||||||
go get -d github.com/AdguardTeam/AdGuardHome/dnsfilter
|
go get -d github.com/AdguardTeam/AdGuardHome/filtering
|
||||||
```
|
```
|
||||||
|
|
||||||
Create file filter.go
|
Create file filter.go
|
||||||
|
@ -11,12 +11,12 @@ Create file filter.go
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/AdguardTeam/AdGuardHome/dnsfilter"
|
"github.com/AdguardTeam/AdGuardHome/filtering"
|
||||||
"log"
|
"log"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
filter := dnsfilter.New()
|
filter := filtering.New()
|
||||||
filter.AddRule("||dou*ck.net^")
|
filter.AddRule("||dou*ck.net^")
|
||||||
host := "www.doubleclick.net"
|
host := "www.doubleclick.net"
|
||||||
res, err := filter.CheckHost(host)
|
res, err := filter.CheckHost(host)
|
||||||
|
@ -48,12 +48,12 @@ You can also enable checking against AdGuard's SafeBrowsing:
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/AdguardTeam/AdGuardHome/dnsfilter"
|
"github.com/AdguardTeam/AdGuardHome/filtering"
|
||||||
"log"
|
"log"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
filter := dnsfilter.New()
|
filter := filtering.New()
|
||||||
filter.EnableSafeBrowsing()
|
filter.EnableSafeBrowsing()
|
||||||
host := "wmconvirus.narod.ru" // hostname for testing safebrowsing
|
host := "wmconvirus.narod.ru" // hostname for testing safebrowsing
|
||||||
res, err := filter.CheckHost(host)
|
res, err := filter.CheckHost(host)
|
|
@ -1,4 +1,4 @@
|
||||||
package dnsfilter
|
package filtering
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
@ -254,7 +254,7 @@ func BlockedSvcKnown(s string) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
// ApplyBlockedServices - set blocked services settings for this DNS request
|
// ApplyBlockedServices - set blocked services settings for this DNS request
|
||||||
func (d *DNSFilter) ApplyBlockedServices(setts *FilteringSettings, list []string, global bool) {
|
func (d *DNSFilter) ApplyBlockedServices(setts *Settings, list []string, global bool) {
|
||||||
setts.ServicesRules = []ServiceEntry{}
|
setts.ServicesRules = []ServiceEntry{}
|
||||||
if global {
|
if global {
|
||||||
d.confLock.RLock()
|
d.confLock.RLock()
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
//go:build ignore
|
//go:build ignore
|
||||||
|
|
||||||
package dnsfilter
|
package filtering
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
@ -16,7 +16,7 @@ import (
|
||||||
// client/src/components/ui/Icons.js
|
// client/src/components/ui/Icons.js
|
||||||
//
|
//
|
||||||
// Usage:
|
// Usage:
|
||||||
// 1. go run ./internal/dnsfilter/blocked_test.go
|
// 1. go run ./internal/filtering/blocked_test.go
|
||||||
// 2. Use the output to replace `SERVICES` array in "client/src/helpers/constants.js".
|
// 2. Use the output to replace `SERVICES` array in "client/src/helpers/constants.js".
|
||||||
// 3. You'll need to enter services names manually.
|
// 3. You'll need to enter services names manually.
|
||||||
// 4. Don't forget to add missing icons to "client/src/components/ui/Icons.js".
|
// 4. Don't forget to add missing icons to "client/src/components/ui/Icons.js".
|
|
@ -1,4 +1,4 @@
|
||||||
package dnsfilter
|
package filtering
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/AdguardTeam/urlfilter/rules"
|
"github.com/AdguardTeam/urlfilter/rules"
|
|
@ -1,4 +1,4 @@
|
||||||
package dnsfilter
|
package filtering
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net"
|
"net"
|
||||||
|
@ -47,7 +47,7 @@ func TestDNSFilter_CheckHostRules_dnsrewrite(t *testing.T) {
|
||||||
`
|
`
|
||||||
|
|
||||||
f := newForTest(nil, []Filter{{ID: 0, Data: []byte(text)}})
|
f := newForTest(nil, []Filter{{ID: 0, Data: []byte(text)}})
|
||||||
setts := &FilteringSettings{
|
setts := &Settings{
|
||||||
FilteringEnabled: true,
|
FilteringEnabled: true,
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
// Package dnsfilter implements a DNS request and response filter.
|
// Package filtering implements a DNS request and response filter.
|
||||||
package dnsfilter
|
package filtering
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
@ -29,8 +29,8 @@ type ServiceEntry struct {
|
||||||
Rules []*rules.NetworkRule
|
Rules []*rules.NetworkRule
|
||||||
}
|
}
|
||||||
|
|
||||||
// FilteringSettings are custom filtering settings for a client.
|
// Settings are custom filtering settings for a client.
|
||||||
type FilteringSettings struct {
|
type Settings struct {
|
||||||
ClientName string
|
ClientName string
|
||||||
ClientIP net.IP
|
ClientIP net.IP
|
||||||
ClientTags []string
|
ClientTags []string
|
||||||
|
@ -101,7 +101,7 @@ type filtersInitializerParams struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type hostChecker struct {
|
type hostChecker struct {
|
||||||
check func(host string, qtype uint16, setts *FilteringSettings) (res Result, err error)
|
check func(host string, qtype uint16, setts *Settings) (res Result, err error)
|
||||||
name string
|
name string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -224,8 +224,8 @@ func (r Reason) In(reasons ...Reason) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetConfig - get configuration
|
// GetConfig - get configuration
|
||||||
func (d *DNSFilter) GetConfig() FilteringSettings {
|
func (d *DNSFilter) GetConfig() Settings {
|
||||||
c := FilteringSettings{}
|
c := Settings{}
|
||||||
// d.confLock.RLock()
|
// d.confLock.RLock()
|
||||||
c.SafeSearchEnabled = d.Config.SafeSearchEnabled
|
c.SafeSearchEnabled = d.Config.SafeSearchEnabled
|
||||||
c.SafeBrowsingEnabled = d.Config.SafeBrowsingEnabled
|
c.SafeBrowsingEnabled = d.Config.SafeBrowsingEnabled
|
||||||
|
@ -304,14 +304,14 @@ func (d *DNSFilter) reset() {
|
||||||
if d.rulesStorage != nil {
|
if d.rulesStorage != nil {
|
||||||
err = d.rulesStorage.Close()
|
err = d.rulesStorage.Close()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("dnsfilter: rulesStorage.Close: %s", err)
|
log.Error("filtering: rulesStorage.Close: %s", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if d.rulesStorageAllow != nil {
|
if d.rulesStorageAllow != nil {
|
||||||
err = d.rulesStorageAllow.Close()
|
err = d.rulesStorageAllow.Close()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("dnsfilter: rulesStorageAllow.Close: %s", err)
|
log.Error("filtering: rulesStorageAllow.Close: %s", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -322,7 +322,7 @@ type dnsFilterContext struct {
|
||||||
safeSearchCache cache.Cache
|
safeSearchCache cache.Cache
|
||||||
}
|
}
|
||||||
|
|
||||||
var gctx dnsFilterContext // global dnsfilter context
|
var gctx dnsFilterContext
|
||||||
|
|
||||||
// ResultRule contains information about applied rules.
|
// ResultRule contains information about applied rules.
|
||||||
type ResultRule struct {
|
type ResultRule struct {
|
||||||
|
@ -380,7 +380,7 @@ func (r Reason) Matched() bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
// CheckHostRules tries to match the host against filtering rules only.
|
// CheckHostRules tries to match the host against filtering rules only.
|
||||||
func (d *DNSFilter) CheckHostRules(host string, qtype uint16, setts *FilteringSettings) (Result, error) {
|
func (d *DNSFilter) CheckHostRules(host string, qtype uint16, setts *Settings) (Result, error) {
|
||||||
if !setts.FilteringEnabled {
|
if !setts.FilteringEnabled {
|
||||||
return Result{}, nil
|
return Result{}, nil
|
||||||
}
|
}
|
||||||
|
@ -393,7 +393,7 @@ func (d *DNSFilter) CheckHostRules(host string, qtype uint16, setts *FilteringSe
|
||||||
func (d *DNSFilter) CheckHost(
|
func (d *DNSFilter) CheckHost(
|
||||||
host string,
|
host string,
|
||||||
qtype uint16,
|
qtype uint16,
|
||||||
setts *FilteringSettings,
|
setts *Settings,
|
||||||
) (res Result, err error) {
|
) (res Result, err error) {
|
||||||
// Sometimes clients try to resolve ".", which is a request to get root
|
// Sometimes clients try to resolve ".", which is a request to get root
|
||||||
// servers.
|
// servers.
|
||||||
|
@ -427,7 +427,7 @@ func (d *DNSFilter) CheckHost(
|
||||||
func (d *DNSFilter) checkEtcHosts(
|
func (d *DNSFilter) checkEtcHosts(
|
||||||
host string,
|
host string,
|
||||||
qtype uint16,
|
qtype uint16,
|
||||||
_ *FilteringSettings,
|
_ *Settings,
|
||||||
) (res Result, err error) {
|
) (res Result, err error) {
|
||||||
if d.Config.EtcHosts == nil {
|
if d.Config.EtcHosts == nil {
|
||||||
return Result{}, nil
|
return Result{}, nil
|
||||||
|
@ -523,7 +523,7 @@ func (d *DNSFilter) processRewrites(host string, qtype uint16) (res Result) {
|
||||||
func matchBlockedServicesRules(
|
func matchBlockedServicesRules(
|
||||||
host string,
|
host string,
|
||||||
_ uint16,
|
_ uint16,
|
||||||
setts *FilteringSettings,
|
setts *Settings,
|
||||||
) (res Result, err error) {
|
) (res Result, err error) {
|
||||||
svcs := setts.ServicesRules
|
svcs := setts.ServicesRules
|
||||||
if len(svcs) == 0 {
|
if len(svcs) == 0 {
|
||||||
|
@ -715,7 +715,7 @@ func (d *DNSFilter) matchHostProcessDNSResult(
|
||||||
func (d *DNSFilter) matchHost(
|
func (d *DNSFilter) matchHost(
|
||||||
host string,
|
host string,
|
||||||
qtype uint16,
|
qtype uint16,
|
||||||
setts *FilteringSettings,
|
setts *Settings,
|
||||||
) (res Result, err error) {
|
) (res Result, err error) {
|
||||||
if !setts.FilteringEnabled {
|
if !setts.FilteringEnabled {
|
||||||
return Result{}, nil
|
return Result{}, nil
|
||||||
|
@ -851,7 +851,7 @@ func New(c *Config, blockFilters []Filter) *DNSFilter {
|
||||||
|
|
||||||
err := d.initSecurityServices()
|
err := d.initSecurityServices()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("dnsfilter: initialize services: %s", err)
|
log.Error("filtering: initialize services: %s", err)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package dnsfilter
|
package filtering
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
@ -21,7 +21,7 @@ func TestMain(m *testing.M) {
|
||||||
aghtest.DiscardLogOutput(m)
|
aghtest.DiscardLogOutput(m)
|
||||||
}
|
}
|
||||||
|
|
||||||
var setts FilteringSettings
|
var setts Settings
|
||||||
|
|
||||||
// Helpers.
|
// Helpers.
|
||||||
|
|
||||||
|
@ -38,7 +38,7 @@ func purgeCaches() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func newForTest(c *Config, filters []Filter) *DNSFilter {
|
func newForTest(c *Config, filters []Filter) *DNSFilter {
|
||||||
setts = FilteringSettings{
|
setts = Settings{
|
||||||
FilteringEnabled: true,
|
FilteringEnabled: true,
|
||||||
}
|
}
|
||||||
setts.FilteringEnabled = true
|
setts.FilteringEnabled = true
|
||||||
|
@ -699,7 +699,7 @@ func TestWhitelist(t *testing.T) {
|
||||||
|
|
||||||
// Client Settings.
|
// Client Settings.
|
||||||
|
|
||||||
func applyClientSettings(setts *FilteringSettings) {
|
func applyClientSettings(setts *Settings) {
|
||||||
setts.FilteringEnabled = false
|
setts.FilteringEnabled = false
|
||||||
setts.ParentalEnabled = false
|
setts.ParentalEnabled = false
|
||||||
setts.SafeBrowsingEnabled = true
|
setts.SafeBrowsingEnabled = true
|
|
@ -1,6 +1,6 @@
|
||||||
// DNS Rewrites
|
// DNS Rewrites
|
||||||
|
|
||||||
package dnsfilter
|
package filtering
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
|
@ -1,4 +1,4 @@
|
||||||
package dnsfilter
|
package filtering
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net"
|
"net"
|
|
@ -1,4 +1,4 @@
|
||||||
package dnsfilter
|
package filtering
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
@ -304,7 +304,7 @@ func check(c *sbCtx, r Result, u upstream.Upstream) (Result, error) {
|
||||||
func (d *DNSFilter) checkSafeBrowsing(
|
func (d *DNSFilter) checkSafeBrowsing(
|
||||||
host string,
|
host string,
|
||||||
_ uint16,
|
_ uint16,
|
||||||
setts *FilteringSettings,
|
setts *Settings,
|
||||||
) (res Result, err error) {
|
) (res Result, err error) {
|
||||||
if !setts.SafeBrowsingEnabled {
|
if !setts.SafeBrowsingEnabled {
|
||||||
return Result{}, nil
|
return Result{}, nil
|
||||||
|
@ -337,7 +337,7 @@ func (d *DNSFilter) checkSafeBrowsing(
|
||||||
func (d *DNSFilter) checkParental(
|
func (d *DNSFilter) checkParental(
|
||||||
host string,
|
host string,
|
||||||
_ uint16,
|
_ uint16,
|
||||||
setts *FilteringSettings,
|
setts *Settings,
|
||||||
) (res Result, err error) {
|
) (res Result, err error) {
|
||||||
if !setts.ParentalEnabled {
|
if !setts.ParentalEnabled {
|
||||||
return Result{}, nil
|
return Result{}, nil
|
|
@ -1,4 +1,4 @@
|
||||||
package dnsfilter
|
package filtering
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/sha256"
|
"crypto/sha256"
|
||||||
|
@ -116,7 +116,7 @@ func TestSBPC_checkErrorUpstream(t *testing.T) {
|
||||||
d.SetSafeBrowsingUpstream(ups)
|
d.SetSafeBrowsingUpstream(ups)
|
||||||
d.SetParentalUpstream(ups)
|
d.SetParentalUpstream(ups)
|
||||||
|
|
||||||
setts := &FilteringSettings{
|
setts := &Settings{
|
||||||
SafeBrowsingEnabled: true,
|
SafeBrowsingEnabled: true,
|
||||||
ParentalEnabled: true,
|
ParentalEnabled: true,
|
||||||
}
|
}
|
||||||
|
@ -134,7 +134,7 @@ func TestSBPC(t *testing.T) {
|
||||||
|
|
||||||
const hostname = "example.org"
|
const hostname = "example.org"
|
||||||
|
|
||||||
setts := &FilteringSettings{
|
setts := &Settings{
|
||||||
SafeBrowsingEnabled: true,
|
SafeBrowsingEnabled: true,
|
||||||
ParentalEnabled: true,
|
ParentalEnabled: true,
|
||||||
}
|
}
|
||||||
|
@ -142,7 +142,7 @@ func TestSBPC(t *testing.T) {
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
name string
|
name string
|
||||||
block bool
|
block bool
|
||||||
testFunc func(host string, _ uint16, _ *FilteringSettings) (res Result, err error)
|
testFunc func(host string, _ uint16, _ *Settings) (res Result, err error)
|
||||||
testCache cache.Cache
|
testCache cache.Cache
|
||||||
}{{
|
}{{
|
||||||
name: "sb_no_block",
|
name: "sb_no_block",
|
|
@ -1,4 +1,4 @@
|
||||||
package dnsfilter
|
package filtering
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
@ -72,7 +72,7 @@ func (d *DNSFilter) SafeSearchDomain(host string) (string, bool) {
|
||||||
func (d *DNSFilter) checkSafeSearch(
|
func (d *DNSFilter) checkSafeSearch(
|
||||||
host string,
|
host string,
|
||||||
_ uint16,
|
_ uint16,
|
||||||
setts *FilteringSettings,
|
setts *Settings,
|
||||||
) (res Result, err error) {
|
) (res Result, err error) {
|
||||||
if !setts.SafeSearchEnabled {
|
if !setts.SafeSearchEnabled {
|
||||||
return Result{}, nil
|
return Result{}, nil
|
|
@ -15,8 +15,8 @@ import (
|
||||||
"github.com/AdguardTeam/AdGuardHome/internal/aghnet"
|
"github.com/AdguardTeam/AdGuardHome/internal/aghnet"
|
||||||
"github.com/AdguardTeam/AdGuardHome/internal/aghstrings"
|
"github.com/AdguardTeam/AdGuardHome/internal/aghstrings"
|
||||||
"github.com/AdguardTeam/AdGuardHome/internal/dhcpd"
|
"github.com/AdguardTeam/AdGuardHome/internal/dhcpd"
|
||||||
"github.com/AdguardTeam/AdGuardHome/internal/dnsfilter"
|
|
||||||
"github.com/AdguardTeam/AdGuardHome/internal/dnsforward"
|
"github.com/AdguardTeam/AdGuardHome/internal/dnsforward"
|
||||||
|
"github.com/AdguardTeam/AdGuardHome/internal/filtering"
|
||||||
"github.com/AdguardTeam/AdGuardHome/internal/querylog"
|
"github.com/AdguardTeam/AdGuardHome/internal/querylog"
|
||||||
"github.com/AdguardTeam/dnsproxy/proxy"
|
"github.com/AdguardTeam/dnsproxy/proxy"
|
||||||
"github.com/AdguardTeam/dnsproxy/upstream"
|
"github.com/AdguardTeam/dnsproxy/upstream"
|
||||||
|
@ -181,7 +181,7 @@ func (clients *clientsContainer) addFromConfig(objects []clientObject) {
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, s := range cy.BlockedServices {
|
for _, s := range cy.BlockedServices {
|
||||||
if !dnsfilter.BlockedSvcKnown(s) {
|
if !filtering.BlockedSvcKnown(s) {
|
||||||
log.Debug("clients: skipping unknown blocked-service %q", s)
|
log.Debug("clients: skipping unknown blocked-service %q", s)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,8 +9,8 @@ import (
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/AdguardTeam/AdGuardHome/internal/dhcpd"
|
"github.com/AdguardTeam/AdGuardHome/internal/dhcpd"
|
||||||
"github.com/AdguardTeam/AdGuardHome/internal/dnsfilter"
|
|
||||||
"github.com/AdguardTeam/AdGuardHome/internal/dnsforward"
|
"github.com/AdguardTeam/AdGuardHome/internal/dnsforward"
|
||||||
|
"github.com/AdguardTeam/AdGuardHome/internal/filtering"
|
||||||
"github.com/AdguardTeam/AdGuardHome/internal/querylog"
|
"github.com/AdguardTeam/AdGuardHome/internal/querylog"
|
||||||
"github.com/AdguardTeam/AdGuardHome/internal/stats"
|
"github.com/AdguardTeam/AdGuardHome/internal/stats"
|
||||||
"github.com/AdguardTeam/AdGuardHome/internal/version"
|
"github.com/AdguardTeam/AdGuardHome/internal/version"
|
||||||
|
@ -98,7 +98,7 @@ type dnsConfig struct {
|
||||||
|
|
||||||
FilteringEnabled bool `yaml:"filtering_enabled"` // whether or not use filter lists
|
FilteringEnabled bool `yaml:"filtering_enabled"` // whether or not use filter lists
|
||||||
FiltersUpdateIntervalHours uint32 `yaml:"filters_update_interval"` // time period to update filters (in hours)
|
FiltersUpdateIntervalHours uint32 `yaml:"filters_update_interval"` // time period to update filters (in hours)
|
||||||
DnsfilterConf dnsfilter.Config `yaml:",inline"`
|
DnsfilterConf filtering.Config `yaml:",inline"`
|
||||||
|
|
||||||
// LocalDomainName is the domain name used for known internal hosts.
|
// LocalDomainName is the domain name used for known internal hosts.
|
||||||
// For example, a machine called "myhost" can be addressed as
|
// For example, a machine called "myhost" can be addressed as
|
||||||
|
@ -149,7 +149,7 @@ var config = configuration{
|
||||||
Port: 53,
|
Port: 53,
|
||||||
StatsInterval: 1,
|
StatsInterval: 1,
|
||||||
FilteringConfig: dnsforward.FilteringConfig{
|
FilteringConfig: dnsforward.FilteringConfig{
|
||||||
ProtectionEnabled: true, // whether or not use any of dnsfilter features
|
ProtectionEnabled: true, // whether or not use any of filtering features
|
||||||
BlockingMode: "default", // mode how to answer filtered requests
|
BlockingMode: "default", // mode how to answer filtered requests
|
||||||
BlockedResponseTTL: 10, // in seconds
|
BlockedResponseTTL: 10, // in seconds
|
||||||
Ratelimit: 20,
|
Ratelimit: 20,
|
||||||
|
@ -306,7 +306,7 @@ func (c *configuration) write() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
if Context.dnsFilter != nil {
|
if Context.dnsFilter != nil {
|
||||||
c := dnsfilter.Config{}
|
c := filtering.Config{}
|
||||||
Context.dnsFilter.WriteDiskConfig(&c)
|
Context.dnsFilter.WriteDiskConfig(&c)
|
||||||
config.DNS.DnsfilterConf = c
|
config.DNS.DnsfilterConf = c
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,8 +9,8 @@ import (
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"github.com/AdguardTeam/AdGuardHome/internal/agherr"
|
"github.com/AdguardTeam/AdGuardHome/internal/agherr"
|
||||||
"github.com/AdguardTeam/AdGuardHome/internal/dnsfilter"
|
|
||||||
"github.com/AdguardTeam/AdGuardHome/internal/dnsforward"
|
"github.com/AdguardTeam/AdGuardHome/internal/dnsforward"
|
||||||
|
"github.com/AdguardTeam/AdGuardHome/internal/filtering"
|
||||||
"github.com/AdguardTeam/AdGuardHome/internal/querylog"
|
"github.com/AdguardTeam/AdGuardHome/internal/querylog"
|
||||||
"github.com/AdguardTeam/AdGuardHome/internal/stats"
|
"github.com/AdguardTeam/AdGuardHome/internal/stats"
|
||||||
"github.com/AdguardTeam/dnsproxy/proxy"
|
"github.com/AdguardTeam/dnsproxy/proxy"
|
||||||
|
@ -60,7 +60,7 @@ func initDNSServer() error {
|
||||||
filterConf.EtcHosts = Context.etcHosts
|
filterConf.EtcHosts = Context.etcHosts
|
||||||
filterConf.ConfigModified = onConfigModified
|
filterConf.ConfigModified = onConfigModified
|
||||||
filterConf.HTTPRegister = httpRegister
|
filterConf.HTTPRegister = httpRegister
|
||||||
Context.dnsFilter = dnsfilter.New(&filterConf, nil)
|
Context.dnsFilter = filtering.New(&filterConf, nil)
|
||||||
|
|
||||||
p := dnsforward.DNSCreateParams{
|
p := dnsforward.DNSCreateParams{
|
||||||
DNSFilter: Context.dnsFilter,
|
DNSFilter: Context.dnsFilter,
|
||||||
|
@ -282,7 +282,7 @@ func getDNSEncryption() (de dnsEncryption) {
|
||||||
|
|
||||||
// applyAdditionalFiltering adds additional client information and settings if
|
// applyAdditionalFiltering adds additional client information and settings if
|
||||||
// the client has them.
|
// the client has them.
|
||||||
func applyAdditionalFiltering(clientAddr net.IP, clientID string, setts *dnsfilter.FilteringSettings) {
|
func applyAdditionalFiltering(clientAddr net.IP, clientID string, setts *filtering.Settings) {
|
||||||
Context.dnsFilter.ApplyBlockedServices(setts, nil, true)
|
Context.dnsFilter.ApplyBlockedServices(setts, nil, true)
|
||||||
|
|
||||||
if clientAddr == nil {
|
if clientAddr == nil {
|
||||||
|
|
|
@ -16,7 +16,7 @@ import (
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/AdguardTeam/AdGuardHome/internal/dnsfilter"
|
"github.com/AdguardTeam/AdGuardHome/internal/filtering"
|
||||||
"github.com/AdguardTeam/golibs/log"
|
"github.com/AdguardTeam/golibs/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -57,9 +57,9 @@ func (f *Filtering) Close() {
|
||||||
|
|
||||||
func defaultFilters() []filter {
|
func defaultFilters() []filter {
|
||||||
return []filter{
|
return []filter{
|
||||||
{Filter: dnsfilter.Filter{ID: 1}, Enabled: true, URL: "https://adguardteam.github.io/AdGuardSDNSFilter/Filters/filter.txt", Name: "AdGuard DNS filter"},
|
{Filter: filtering.Filter{ID: 1}, Enabled: true, URL: "https://adguardteam.github.io/AdGuardSDNSFilter/Filters/filter.txt", Name: "AdGuard DNS filter"},
|
||||||
{Filter: dnsfilter.Filter{ID: 2}, Enabled: false, URL: "https://adaway.org/hosts.txt", Name: "AdAway Default Blocklist"},
|
{Filter: filtering.Filter{ID: 2}, Enabled: false, URL: "https://adaway.org/hosts.txt", Name: "AdAway Default Blocklist"},
|
||||||
{Filter: dnsfilter.Filter{ID: 4}, Enabled: false, URL: "https://www.malwaredomainlist.com/hostslist/hosts.txt", Name: "MalwareDomainList.com Hosts List"},
|
{Filter: filtering.Filter{ID: 4}, Enabled: false, URL: "https://www.malwaredomainlist.com/hostslist/hosts.txt", Name: "MalwareDomainList.com Hosts List"},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -73,7 +73,7 @@ type filter struct {
|
||||||
checksum uint32 // checksum of the file data
|
checksum uint32 // checksum of the file data
|
||||||
white bool
|
white bool
|
||||||
|
|
||||||
dnsfilter.Filter `yaml:",inline"`
|
filtering.Filter `yaml:",inline"`
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -376,9 +376,9 @@ const (
|
||||||
// . If filter data has changed:
|
// . If filter data has changed:
|
||||||
// . rename the temporary file (<temp> -> 1.txt)
|
// . rename the temporary file (<temp> -> 1.txt)
|
||||||
// Note that this method works only on UNIX.
|
// Note that this method works only on UNIX.
|
||||||
// On Windows we don't pass files to dnsfilter - we pass the whole data.
|
// On Windows we don't pass files to filtering - we pass the whole data.
|
||||||
// . Pass new filters to dnsfilter object - it analyzes new data while the old filters are still active
|
// . Pass new filters to filtering object - it analyzes new data while the old filters are still active
|
||||||
// . dnsfilter activates new filters
|
// . filtering activates new filters
|
||||||
//
|
//
|
||||||
// Return the number of updated filters
|
// Return the number of updated filters
|
||||||
// Return TRUE - there was a network error and nothing could be updated
|
// Return TRUE - there was a network error and nothing could be updated
|
||||||
|
@ -664,8 +664,8 @@ func (filter *filter) Path() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func enableFilters(async bool) {
|
func enableFilters(async bool) {
|
||||||
var whiteFilters []dnsfilter.Filter
|
var whiteFilters []filtering.Filter
|
||||||
filters := []dnsfilter.Filter{{
|
filters := []filtering.Filter{{
|
||||||
Data: []byte(strings.Join(config.UserRules, "\n")),
|
Data: []byte(strings.Join(config.UserRules, "\n")),
|
||||||
}}
|
}}
|
||||||
|
|
||||||
|
@ -674,7 +674,7 @@ func enableFilters(async bool) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
filters = append(filters, dnsfilter.Filter{
|
filters = append(filters, filtering.Filter{
|
||||||
ID: filter.ID,
|
ID: filter.ID,
|
||||||
FilePath: filter.Path(),
|
FilePath: filter.Path(),
|
||||||
})
|
})
|
||||||
|
@ -684,7 +684,7 @@ func enableFilters(async bool) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
whiteFilters = append(whiteFilters, dnsfilter.Filter{
|
whiteFilters = append(whiteFilters, filtering.Filter{
|
||||||
ID: filter.ID,
|
ID: filter.ID,
|
||||||
FilePath: filter.Path(),
|
FilePath: filter.Path(),
|
||||||
})
|
})
|
||||||
|
|
|
@ -25,8 +25,8 @@ import (
|
||||||
"github.com/AdguardTeam/AdGuardHome/internal/aghnet"
|
"github.com/AdguardTeam/AdGuardHome/internal/aghnet"
|
||||||
"github.com/AdguardTeam/AdGuardHome/internal/aghos"
|
"github.com/AdguardTeam/AdGuardHome/internal/aghos"
|
||||||
"github.com/AdguardTeam/AdGuardHome/internal/dhcpd"
|
"github.com/AdguardTeam/AdGuardHome/internal/dhcpd"
|
||||||
"github.com/AdguardTeam/AdGuardHome/internal/dnsfilter"
|
|
||||||
"github.com/AdguardTeam/AdGuardHome/internal/dnsforward"
|
"github.com/AdguardTeam/AdGuardHome/internal/dnsforward"
|
||||||
|
"github.com/AdguardTeam/AdGuardHome/internal/filtering"
|
||||||
"github.com/AdguardTeam/AdGuardHome/internal/querylog"
|
"github.com/AdguardTeam/AdGuardHome/internal/querylog"
|
||||||
"github.com/AdguardTeam/AdGuardHome/internal/stats"
|
"github.com/AdguardTeam/AdGuardHome/internal/stats"
|
||||||
"github.com/AdguardTeam/AdGuardHome/internal/updater"
|
"github.com/AdguardTeam/AdGuardHome/internal/updater"
|
||||||
|
@ -51,7 +51,7 @@ type homeContext struct {
|
||||||
dnsServer *dnsforward.Server // DNS module
|
dnsServer *dnsforward.Server // DNS module
|
||||||
rdns *RDNS // rDNS module
|
rdns *RDNS // rDNS module
|
||||||
whois *Whois // WHOIS module
|
whois *Whois // WHOIS module
|
||||||
dnsFilter *dnsfilter.DNSFilter // DNS filtering module
|
dnsFilter *filtering.DNSFilter // DNS filtering module
|
||||||
dhcpServer *dhcpd.Server // DHCP module
|
dhcpServer *dhcpd.Server // DHCP module
|
||||||
auth *Auth // HTTP authentication module
|
auth *Auth // HTTP authentication module
|
||||||
filters Filtering // DNS filtering module
|
filters Filtering // DNS filtering module
|
||||||
|
@ -291,10 +291,10 @@ func run(args options, clientBuildFS fs.FS) {
|
||||||
|
|
||||||
setupContext(args)
|
setupContext(args)
|
||||||
|
|
||||||
// clients package uses dnsfilter package's static data (dnsfilter.BlockedSvcKnown()),
|
// clients package uses filtering package's static data (filtering.BlockedSvcKnown()),
|
||||||
// so we have to initialize dnsfilter's static data first,
|
// so we have to initialize filtering's static data first,
|
||||||
// but also avoid relying on automatic Go init() function
|
// but also avoid relying on automatic Go init() function
|
||||||
dnsfilter.InitModule()
|
filtering.InitModule()
|
||||||
|
|
||||||
setupConfig(args)
|
setupConfig(args)
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/AdguardTeam/AdGuardHome/internal/dnsfilter"
|
"github.com/AdguardTeam/AdGuardHome/internal/filtering"
|
||||||
"github.com/AdguardTeam/golibs/log"
|
"github.com/AdguardTeam/golibs/log"
|
||||||
"github.com/AdguardTeam/urlfilter/rules"
|
"github.com/AdguardTeam/urlfilter/rules"
|
||||||
"github.com/miekg/dns"
|
"github.com/miekg/dns"
|
||||||
|
@ -138,7 +138,7 @@ var resultHandlers = map[string]logEntryHandler{
|
||||||
|
|
||||||
l := len(ent.Result.Rules)
|
l := len(ent.Result.Rules)
|
||||||
if l == 0 {
|
if l == 0 {
|
||||||
ent.Result.Rules = []*dnsfilter.ResultRule{{}}
|
ent.Result.Rules = []*filtering.ResultRule{{}}
|
||||||
l++
|
l++
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -159,7 +159,7 @@ var resultHandlers = map[string]logEntryHandler{
|
||||||
|
|
||||||
l := len(ent.Result.Rules)
|
l := len(ent.Result.Rules)
|
||||||
if l == 0 {
|
if l == 0 {
|
||||||
ent.Result.Rules = []*dnsfilter.ResultRule{{}}
|
ent.Result.Rules = []*filtering.ResultRule{{}}
|
||||||
l++
|
l++
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -176,7 +176,7 @@ var resultHandlers = map[string]logEntryHandler{
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
ent.Result.Reason = dnsfilter.Reason(i)
|
ent.Result.Reason = filtering.Reason(i)
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
"ServiceName": func(t json.Token, ent *logEntry) error {
|
"ServiceName": func(t json.Token, ent *logEntry) error {
|
||||||
|
@ -214,7 +214,7 @@ func decodeResultRuleKey(key string, i int, dec *json.Decoder, ent *logEntry) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(ent.Result.Rules) < i+1 {
|
if len(ent.Result.Rules) < i+1 {
|
||||||
ent.Result.Rules = append(ent.Result.Rules, &dnsfilter.ResultRule{})
|
ent.Result.Rules = append(ent.Result.Rules, &filtering.ResultRule{})
|
||||||
}
|
}
|
||||||
|
|
||||||
if n, ok := vToken.(json.Number); ok {
|
if n, ok := vToken.(json.Number); ok {
|
||||||
|
@ -231,7 +231,7 @@ func decodeResultRuleKey(key string, i int, dec *json.Decoder, ent *logEntry) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(ent.Result.Rules) < i+1 {
|
if len(ent.Result.Rules) < i+1 {
|
||||||
ent.Result.Rules = append(ent.Result.Rules, &dnsfilter.ResultRule{})
|
ent.Result.Rules = append(ent.Result.Rules, &filtering.ResultRule{})
|
||||||
}
|
}
|
||||||
|
|
||||||
if ipStr, ok := vToken.(string); ok {
|
if ipStr, ok := vToken.(string); ok {
|
||||||
|
@ -248,7 +248,7 @@ func decodeResultRuleKey(key string, i int, dec *json.Decoder, ent *logEntry) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(ent.Result.Rules) < i+1 {
|
if len(ent.Result.Rules) < i+1 {
|
||||||
ent.Result.Rules = append(ent.Result.Rules, &dnsfilter.ResultRule{})
|
ent.Result.Rules = append(ent.Result.Rules, &filtering.ResultRule{})
|
||||||
}
|
}
|
||||||
|
|
||||||
if s, ok := vToken.(string); ok {
|
if s, ok := vToken.(string); ok {
|
||||||
|
@ -391,7 +391,7 @@ func decodeResultDNSRewriteResultKey(key string, dec *json.Decoder, ent *logEntr
|
||||||
}
|
}
|
||||||
|
|
||||||
if ent.Result.DNSRewriteResult == nil {
|
if ent.Result.DNSRewriteResult == nil {
|
||||||
ent.Result.DNSRewriteResult = &dnsfilter.DNSRewriteResult{}
|
ent.Result.DNSRewriteResult = &filtering.DNSRewriteResult{}
|
||||||
}
|
}
|
||||||
|
|
||||||
if n, ok := vToken.(json.Number); ok {
|
if n, ok := vToken.(json.Number); ok {
|
||||||
|
@ -400,11 +400,11 @@ func decodeResultDNSRewriteResultKey(key string, dec *json.Decoder, ent *logEntr
|
||||||
}
|
}
|
||||||
case "Response":
|
case "Response":
|
||||||
if ent.Result.DNSRewriteResult == nil {
|
if ent.Result.DNSRewriteResult == nil {
|
||||||
ent.Result.DNSRewriteResult = &dnsfilter.DNSRewriteResult{}
|
ent.Result.DNSRewriteResult = &filtering.DNSRewriteResult{}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ent.Result.DNSRewriteResult.Response == nil {
|
if ent.Result.DNSRewriteResult.Response == nil {
|
||||||
ent.Result.DNSRewriteResult.Response = dnsfilter.DNSRewriteResultResponse{}
|
ent.Result.DNSRewriteResult.Response = filtering.DNSRewriteResultResponse{}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(a.garipov): I give up. This whole file is a mess.
|
// TODO(a.garipov): I give up. This whole file is a mess.
|
||||||
|
|
|
@ -9,7 +9,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/AdguardTeam/AdGuardHome/internal/aghtest"
|
"github.com/AdguardTeam/AdGuardHome/internal/aghtest"
|
||||||
"github.com/AdguardTeam/AdGuardHome/internal/dnsfilter"
|
"github.com/AdguardTeam/AdGuardHome/internal/filtering"
|
||||||
"github.com/AdguardTeam/golibs/log"
|
"github.com/AdguardTeam/golibs/log"
|
||||||
"github.com/AdguardTeam/urlfilter/rules"
|
"github.com/AdguardTeam/urlfilter/rules"
|
||||||
"github.com/miekg/dns"
|
"github.com/miekg/dns"
|
||||||
|
@ -56,12 +56,12 @@ func TestDecodeLogEntry(t *testing.T) {
|
||||||
ClientID: "cli42",
|
ClientID: "cli42",
|
||||||
ClientProto: "",
|
ClientProto: "",
|
||||||
Answer: ans,
|
Answer: ans,
|
||||||
Result: dnsfilter.Result{
|
Result: filtering.Result{
|
||||||
IsFiltered: true,
|
IsFiltered: true,
|
||||||
Reason: dnsfilter.FilteredBlockList,
|
Reason: filtering.FilteredBlockList,
|
||||||
ReverseHosts: []string{"example.net"},
|
ReverseHosts: []string{"example.net"},
|
||||||
IPList: []net.IP{net.IPv4(127, 0, 0, 2)},
|
IPList: []net.IP{net.IPv4(127, 0, 0, 2)},
|
||||||
Rules: []*dnsfilter.ResultRule{{
|
Rules: []*filtering.ResultRule{{
|
||||||
FilterListID: 42,
|
FilterListID: 42,
|
||||||
Text: "||an.yandex.ru",
|
Text: "||an.yandex.ru",
|
||||||
IP: net.IPv4(127, 0, 0, 2),
|
IP: net.IPv4(127, 0, 0, 2),
|
||||||
|
@ -72,9 +72,9 @@ func TestDecodeLogEntry(t *testing.T) {
|
||||||
}},
|
}},
|
||||||
CanonName: "example.com",
|
CanonName: "example.com",
|
||||||
ServiceName: "example.org",
|
ServiceName: "example.org",
|
||||||
DNSRewriteResult: &dnsfilter.DNSRewriteResult{
|
DNSRewriteResult: &filtering.DNSRewriteResult{
|
||||||
RCode: dns.RcodeSuccess,
|
RCode: dns.RcodeSuccess,
|
||||||
Response: dnsfilter.DNSRewriteResultResponse{
|
Response: filtering.DNSRewriteResultResponse{
|
||||||
dns.TypeA: []rules.RRValue{net.IPv4(127, 0, 0, 2)},
|
dns.TypeA: []rules.RRValue{net.IPv4(127, 0, 0, 2)},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
|
@ -7,7 +7,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/AdguardTeam/AdGuardHome/internal/dnsfilter"
|
"github.com/AdguardTeam/AdGuardHome/internal/filtering"
|
||||||
"github.com/AdguardTeam/golibs/log"
|
"github.com/AdguardTeam/golibs/log"
|
||||||
"github.com/miekg/dns"
|
"github.com/miekg/dns"
|
||||||
)
|
)
|
||||||
|
@ -129,7 +129,7 @@ func (l *queryLog) logEntryToJSONEntry(entry *logEntry) (jsonEntry jobject) {
|
||||||
return jsonEntry
|
return jsonEntry
|
||||||
}
|
}
|
||||||
|
|
||||||
func resultRulesToJSONRules(rules []*dnsfilter.ResultRule) (jsonRules []jobject) {
|
func resultRulesToJSONRules(rules []*filtering.ResultRule) (jsonRules []jobject) {
|
||||||
jsonRules = make([]jobject, len(rules))
|
jsonRules = make([]jobject, len(rules))
|
||||||
for i, r := range rules {
|
for i, r := range rules {
|
||||||
jsonRules[i] = jobject{
|
jsonRules[i] = jobject{
|
||||||
|
|
|
@ -10,7 +10,7 @@ import (
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/AdguardTeam/AdGuardHome/internal/dnsfilter"
|
"github.com/AdguardTeam/AdGuardHome/internal/filtering"
|
||||||
"github.com/AdguardTeam/golibs/log"
|
"github.com/AdguardTeam/golibs/log"
|
||||||
"github.com/miekg/dns"
|
"github.com/miekg/dns"
|
||||||
)
|
)
|
||||||
|
@ -84,7 +84,7 @@ type logEntry struct {
|
||||||
Answer []byte `json:",omitempty"` // sometimes empty answers happen like binerdunt.top or rev2.globalrootservers.net
|
Answer []byte `json:",omitempty"` // sometimes empty answers happen like binerdunt.top or rev2.globalrootservers.net
|
||||||
OrigAnswer []byte `json:",omitempty"`
|
OrigAnswer []byte `json:",omitempty"`
|
||||||
|
|
||||||
Result dnsfilter.Result
|
Result filtering.Result
|
||||||
Elapsed time.Duration
|
Elapsed time.Duration
|
||||||
Upstream string `json:",omitempty"` // if empty, means it was cached
|
Upstream string `json:",omitempty"` // if empty, means it was cached
|
||||||
}
|
}
|
||||||
|
@ -147,7 +147,7 @@ func (l *queryLog) Add(params AddParams) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if params.Result == nil {
|
if params.Result == nil {
|
||||||
params.Result = &dnsfilter.Result{}
|
params.Result = &filtering.Result{}
|
||||||
}
|
}
|
||||||
|
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
|
|
|
@ -9,7 +9,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/AdguardTeam/AdGuardHome/internal/aghtest"
|
"github.com/AdguardTeam/AdGuardHome/internal/aghtest"
|
||||||
"github.com/AdguardTeam/AdGuardHome/internal/dnsfilter"
|
"github.com/AdguardTeam/AdGuardHome/internal/filtering"
|
||||||
"github.com/AdguardTeam/dnsproxy/proxyutil"
|
"github.com/AdguardTeam/dnsproxy/proxyutil"
|
||||||
"github.com/miekg/dns"
|
"github.com/miekg/dns"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
@ -267,11 +267,11 @@ func addEntry(l *queryLog, host string, answerStr, client net.IP) {
|
||||||
A: answerStr,
|
A: answerStr,
|
||||||
}},
|
}},
|
||||||
}
|
}
|
||||||
res := dnsfilter.Result{
|
res := filtering.Result{
|
||||||
IsFiltered: true,
|
IsFiltered: true,
|
||||||
Reason: dnsfilter.Rewritten,
|
Reason: filtering.Rewritten,
|
||||||
ServiceName: "SomeService",
|
ServiceName: "SomeService",
|
||||||
Rules: []*dnsfilter.ResultRule{{
|
Rules: []*filtering.ResultRule{{
|
||||||
FilterListID: 1,
|
FilterListID: 1,
|
||||||
Text: "SomeRule",
|
Text: "SomeRule",
|
||||||
}},
|
}},
|
||||||
|
|
|
@ -7,7 +7,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/AdguardTeam/AdGuardHome/internal/agherr"
|
"github.com/AdguardTeam/AdGuardHome/internal/agherr"
|
||||||
"github.com/AdguardTeam/AdGuardHome/internal/dnsfilter"
|
"github.com/AdguardTeam/AdGuardHome/internal/filtering"
|
||||||
"github.com/AdguardTeam/golibs/log"
|
"github.com/AdguardTeam/golibs/log"
|
||||||
"github.com/miekg/dns"
|
"github.com/miekg/dns"
|
||||||
)
|
)
|
||||||
|
@ -66,7 +66,7 @@ type AddParams struct {
|
||||||
Question *dns.Msg
|
Question *dns.Msg
|
||||||
Answer *dns.Msg // The response we sent to the client (optional)
|
Answer *dns.Msg // The response we sent to the client (optional)
|
||||||
OrigAnswer *dns.Msg // The response from an upstream server (optional)
|
OrigAnswer *dns.Msg // The response from an upstream server (optional)
|
||||||
Result *dnsfilter.Result // Filtering result (optional)
|
Result *filtering.Result // Filtering result (optional)
|
||||||
Elapsed time.Duration // Time spent for processing the request
|
Elapsed time.Duration // Time spent for processing the request
|
||||||
ClientID string
|
ClientID string
|
||||||
ClientIP net.IP
|
ClientIP net.IP
|
||||||
|
|
|
@ -5,7 +5,7 @@ import (
|
||||||
"unicode"
|
"unicode"
|
||||||
"unicode/utf8"
|
"unicode/utf8"
|
||||||
|
|
||||||
"github.com/AdguardTeam/AdGuardHome/internal/dnsfilter"
|
"github.com/AdguardTeam/AdGuardHome/internal/filtering"
|
||||||
)
|
)
|
||||||
|
|
||||||
type criterionType int
|
type criterionType int
|
||||||
|
@ -168,7 +168,7 @@ func (c *searchCriterion) ctDomainOrClientCase(e *logEntry) bool {
|
||||||
return c.ctDomainOrClientCaseNonStrict(term, clientID, name, host, ip)
|
return c.ctDomainOrClientCaseNonStrict(term, clientID, name, host, ip)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *searchCriterion) ctFilteringStatusCase(res dnsfilter.Result) bool {
|
func (c *searchCriterion) ctFilteringStatusCase(res filtering.Result) bool {
|
||||||
switch c.value {
|
switch c.value {
|
||||||
case filteringStatusAll:
|
case filteringStatusAll:
|
||||||
return true
|
return true
|
||||||
|
@ -176,43 +176,43 @@ func (c *searchCriterion) ctFilteringStatusCase(res dnsfilter.Result) bool {
|
||||||
case filteringStatusFiltered:
|
case filteringStatusFiltered:
|
||||||
return res.IsFiltered ||
|
return res.IsFiltered ||
|
||||||
res.Reason.In(
|
res.Reason.In(
|
||||||
dnsfilter.NotFilteredAllowList,
|
filtering.NotFilteredAllowList,
|
||||||
dnsfilter.Rewritten,
|
filtering.Rewritten,
|
||||||
dnsfilter.RewrittenAutoHosts,
|
filtering.RewrittenAutoHosts,
|
||||||
dnsfilter.RewrittenRule,
|
filtering.RewrittenRule,
|
||||||
)
|
)
|
||||||
|
|
||||||
case filteringStatusBlocked:
|
case filteringStatusBlocked:
|
||||||
return res.IsFiltered &&
|
return res.IsFiltered &&
|
||||||
res.Reason.In(dnsfilter.FilteredBlockList, dnsfilter.FilteredBlockedService)
|
res.Reason.In(filtering.FilteredBlockList, filtering.FilteredBlockedService)
|
||||||
|
|
||||||
case filteringStatusBlockedService:
|
case filteringStatusBlockedService:
|
||||||
return res.IsFiltered && res.Reason == dnsfilter.FilteredBlockedService
|
return res.IsFiltered && res.Reason == filtering.FilteredBlockedService
|
||||||
|
|
||||||
case filteringStatusBlockedParental:
|
case filteringStatusBlockedParental:
|
||||||
return res.IsFiltered && res.Reason == dnsfilter.FilteredParental
|
return res.IsFiltered && res.Reason == filtering.FilteredParental
|
||||||
|
|
||||||
case filteringStatusBlockedSafebrowsing:
|
case filteringStatusBlockedSafebrowsing:
|
||||||
return res.IsFiltered && res.Reason == dnsfilter.FilteredSafeBrowsing
|
return res.IsFiltered && res.Reason == filtering.FilteredSafeBrowsing
|
||||||
|
|
||||||
case filteringStatusWhitelisted:
|
case filteringStatusWhitelisted:
|
||||||
return res.Reason == dnsfilter.NotFilteredAllowList
|
return res.Reason == filtering.NotFilteredAllowList
|
||||||
|
|
||||||
case filteringStatusRewritten:
|
case filteringStatusRewritten:
|
||||||
return res.Reason.In(
|
return res.Reason.In(
|
||||||
dnsfilter.Rewritten,
|
filtering.Rewritten,
|
||||||
dnsfilter.RewrittenAutoHosts,
|
filtering.RewrittenAutoHosts,
|
||||||
dnsfilter.RewrittenRule,
|
filtering.RewrittenRule,
|
||||||
)
|
)
|
||||||
|
|
||||||
case filteringStatusSafeSearch:
|
case filteringStatusSafeSearch:
|
||||||
return res.IsFiltered && res.Reason == dnsfilter.FilteredSafeSearch
|
return res.IsFiltered && res.Reason == filtering.FilteredSafeSearch
|
||||||
|
|
||||||
case filteringStatusProcessed:
|
case filteringStatusProcessed:
|
||||||
return !res.Reason.In(
|
return !res.Reason.In(
|
||||||
dnsfilter.FilteredBlockList,
|
filtering.FilteredBlockList,
|
||||||
dnsfilter.FilteredBlockedService,
|
filtering.FilteredBlockedService,
|
||||||
dnsfilter.NotFilteredAllowList,
|
filtering.NotFilteredAllowList,
|
||||||
)
|
)
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|
Loading…
Reference in New Issue