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:
Ainar Garipov 2021-05-21 16:15:47 +03:00
parent 42ec9cae76
commit 7f2f8de922
40 changed files with 207 additions and 207 deletions

4
.gitignore vendored
View File

@ -14,8 +14,8 @@
/build2/*
/data/
/dist/
/dnsfilter/tests/dnsfilter.TestLotsOfRules*.pprof
/dnsfilter/tests/top-1m.csv
/filtering/tests/filtering.TestLotsOfRules*.pprof
/filtering/tests/top-1m.csv
/launchpad_credentials
/querylog.json*
/snapcraft_login

View File

@ -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:
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).
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).

View File

@ -18,7 +18,7 @@ module.exports = {
"",
"ui",
"global",
"dnsfilter",
"filtering",
"home",
"dnsforward",
"dhcpd",

View File

@ -11,7 +11,7 @@ import (
"sort"
"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/upstream"
"github.com/AdguardTeam/golibs/log"
@ -25,7 +25,7 @@ type FilteringConfig struct {
// --
// 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
// 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
// --
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
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

View File

@ -7,7 +7,7 @@ import (
"github.com/AdguardTeam/AdGuardHome/internal/aghnet"
"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/golibs/log"
"github.com/miekg/dns"
@ -20,9 +20,9 @@ type dnsContext struct {
srv *Server
proxyCtx *proxy.DNSContext
// setts are the filtering settings for the client.
setts *dnsfilter.FilteringSettings
setts *filtering.Settings
startTime time.Time
result *dnsfilter.Result
result *filtering.Result
// origResp is the response received from upstream. It is set when the
// response is modified by filters.
origResp *dns.Msg
@ -70,7 +70,7 @@ func (s *Server) handleDNSRequest(_ *proxy.Proxy, d *proxy.DNSContext) error {
ctx := &dnsContext{
srv: s,
proxyCtx: d,
result: &dnsfilter.Result{},
result: &filtering.Result{},
startTime: time.Now(),
}
@ -564,8 +564,8 @@ func processFilteringAfterResponse(ctx *dnsContext) (rc resultCode) {
var err error
switch res.Reason {
case dnsfilter.Rewritten,
dnsfilter.RewrittenRule:
case filtering.Rewritten,
filtering.RewrittenRule:
if len(ctx.origQuestion.Name) == 0 {
// 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
}
case dnsfilter.NotFilteredAllowList:
case filtering.NotFilteredAllowList:
// nothing
default:
@ -599,7 +599,7 @@ func processFilteringAfterResponse(ctx *dnsContext) (rc resultCode) {
if ctx.result != nil {
ctx.origResp = origResp2 // matched by response
} else {
ctx.result = &dnsfilter.Result{}
ctx.result = &filtering.Result{}
}
}

View File

@ -6,7 +6,7 @@ import (
"github.com/AdguardTeam/AdGuardHome/internal/aghnet"
"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/upstream"
"github.com/miekg/dns"
@ -267,7 +267,7 @@ func TestLocalRestriction(t *testing.T) {
"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{{}},
TCPListenAddrs: []*net.TCPAddr{{}},
}, ups)

View File

@ -16,7 +16,7 @@ import (
"github.com/AdguardTeam/AdGuardHome/internal/aghnet"
"github.com/AdguardTeam/AdGuardHome/internal/aghstrings"
"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/stats"
"github.com/AdguardTeam/dnsproxy/proxy"
@ -64,7 +64,7 @@ type ipToHostTable = map[string]string
// The zero Server is empty and ready for use.
type Server struct {
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)
queryLog querylog.QueryLog // Query log instance
stats stats.Stats
@ -102,7 +102,7 @@ const defaultLocalDomainSuffix = ".lan."
// DNSCreateParams are parameters to create a new server.
type DNSCreateParams struct {
DNSFilter *dnsfilter.DNSFilter
DNSFilter *filtering.DNSFilter
Stats stats.Stats
QueryLog querylog.QueryLog
DHCPServer dhcpd.ServerInterface

View File

@ -21,7 +21,7 @@ import (
"github.com/AdguardTeam/AdGuardHome/internal/aghnet"
"github.com/AdguardTeam/AdGuardHome/internal/aghtest"
"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/upstream"
"github.com/miekg/dns"
@ -52,7 +52,7 @@ func startDeferStop(t *testing.T, s *Server) {
func createTestServer(
t *testing.T,
filterConf *dnsfilter.Config,
filterConf *filtering.Config,
forwardConf ServerConfig,
localUps upstream.Upstream,
) (s *Server) {
@ -63,11 +63,11 @@ func createTestServer(
127.0.0.1 host.example.org
@@||whitelist.example.org^
||127.0.0.255`
filters := []dnsfilter.Filter{{
filters := []filtering.Filter{{
ID: 0, Data: []byte(rules),
}}
f := dnsfilter.New(filterConf, filters)
f := filtering.New(filterConf, filters)
snd, err := aghnet.NewSubnetDetector()
require.NoError(t, err)
@ -145,7 +145,7 @@ func createTestTLS(t *testing.T, tlsConf TLSConfig) (s *Server, certPem []byte)
var keyPem []byte
_, certPem, keyPem = createServerTLSConfig(t)
s = createTestServer(t, &dnsfilter.Config{}, ServerConfig{
s = createTestServer(t, &filtering.Config{}, ServerConfig{
UDPListenAddrs: []*net.UDPAddr{{}},
TCPListenAddrs: []*net.TCPAddr{{}},
}, nil)
@ -241,7 +241,7 @@ func sendTestMessages(t *testing.T, conn *dns.Conn) {
}
func TestServer(t *testing.T) {
s := createTestServer(t, &dnsfilter.Config{}, ServerConfig{
s := createTestServer(t, &filtering.Config{}, ServerConfig{
UDPListenAddrs: []*net.UDPAddr{{}},
TCPListenAddrs: []*net.TCPAddr{{}},
}, nil)
@ -279,7 +279,7 @@ func TestServer(t *testing.T) {
}
func TestServerWithProtectionDisabled(t *testing.T) {
s := createTestServer(t, &dnsfilter.Config{}, ServerConfig{
s := createTestServer(t, &filtering.Config{}, ServerConfig{
UDPListenAddrs: []*net.UDPAddr{{}},
TCPListenAddrs: []*net.TCPAddr{{}},
}, nil)
@ -362,7 +362,7 @@ func TestDoQServer(t *testing.T) {
func TestServerRace(t *testing.T) {
t.Skip("TODO(e.burkov): inspect the golibs/cache package for locks")
filterConf := &dnsfilter.Config{
filterConf := &filtering.Config{
SafeBrowsingEnabled: true,
SafeBrowsingCacheSize: 1000,
SafeSearchEnabled: true,
@ -399,7 +399,7 @@ func TestServerRace(t *testing.T) {
func TestSafeSearch(t *testing.T) {
resolver := &aghtest.TestResolver{}
filterConf := &dnsfilter.Config{
filterConf := &filtering.Config{
SafeSearchEnabled: true,
SafeSearchCacheSize: 1000,
CacheTime: 30,
@ -462,7 +462,7 @@ func TestSafeSearch(t *testing.T) {
}
func TestInvalidRequest(t *testing.T) {
s := createTestServer(t, &dnsfilter.Config{}, ServerConfig{
s := createTestServer(t, &filtering.Config{}, ServerConfig{
UDPListenAddrs: []*net.UDPAddr{{}},
TCPListenAddrs: []*net.TCPAddr{{}},
}, nil)
@ -493,7 +493,7 @@ func TestBlockedRequest(t *testing.T) {
ProtectionEnabled: true,
},
}
s := createTestServer(t, &dnsfilter.Config{}, forwardConf, nil)
s := createTestServer(t, &filtering.Config{}, forwardConf, nil)
startDeferStop(t, s)
addr := s.dnsProxy.Addr(proxy.ProtoUDP)
@ -518,7 +518,7 @@ func TestServerCustomClientUpstream(t *testing.T) {
ProtectionEnabled: true,
},
}
s := createTestServer(t, &dnsfilter.Config{}, forwardConf, nil)
s := createTestServer(t, &filtering.Config{}, forwardConf, nil)
s.conf.GetCustomUpstreamByClient = func(_ string) *proxy.UpstreamConfig {
return &proxy.UpstreamConfig{
Upstreams: []upstream.Upstream{
@ -560,7 +560,7 @@ var testIPv4 = map[string][]net.IP{
}
func TestBlockCNAMEProtectionEnabled(t *testing.T) {
s := createTestServer(t, &dnsfilter.Config{}, ServerConfig{
s := createTestServer(t, &filtering.Config{}, ServerConfig{
UDPListenAddrs: []*net.UDPAddr{{}},
TCPListenAddrs: []*net.TCPAddr{{}},
}, nil)
@ -595,7 +595,7 @@ func TestBlockCNAME(t *testing.T) {
ProtectionEnabled: true,
},
}
s := createTestServer(t, &dnsfilter.Config{}, forwardConf, nil)
s := createTestServer(t, &filtering.Config{}, forwardConf, nil)
s.conf.UpstreamConfig.Upstreams = []upstream.Upstream{
&aghtest.TestUpstream{
CName: testCNAMEs,
@ -652,12 +652,12 @@ func TestClientRulesForCNAMEMatching(t *testing.T) {
TCPListenAddrs: []*net.TCPAddr{{}},
FilteringConfig: FilteringConfig{
ProtectionEnabled: true,
FilterHandler: func(_ net.IP, _ string, settings *dnsfilter.FilteringSettings) {
FilterHandler: func(_ net.IP, _ string, settings *filtering.Settings) {
settings.FilteringEnabled = false
},
},
}
s := createTestServer(t, &dnsfilter.Config{}, forwardConf, nil)
s := createTestServer(t, &filtering.Config{}, forwardConf, nil)
s.conf.UpstreamConfig.Upstreams = []upstream.Upstream{
&aghtest.TestUpstream{
CName: testCNAMEs,
@ -698,7 +698,7 @@ func TestNullBlockedRequest(t *testing.T) {
BlockingMode: "null_ip",
},
}
s := createTestServer(t, &dnsfilter.Config{}, forwardConf, nil)
s := createTestServer(t, &filtering.Config{}, forwardConf, nil)
startDeferStop(t, s)
addr := s.dnsProxy.Addr(proxy.ProtoUDP)
@ -725,7 +725,7 @@ func TestNullBlockedRequest(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"
filters := []dnsfilter.Filter{{
filters := []filtering.Filter{{
ID: 0,
Data: []byte(rules),
}}
@ -737,7 +737,7 @@ func TestBlockedCustomIP(t *testing.T) {
var s *Server
s, err = NewServer(DNSCreateParams{
DHCPServer: &testDHCP{},
DNSFilter: dnsfilter.New(&dnsfilter.Config{}, filters),
DNSFilter: filtering.New(&filtering.Config{}, filters),
SubnetDetector: snd,
})
require.NoError(t, err)
@ -798,7 +798,7 @@ func TestBlockedByHosts(t *testing.T) {
ProtectionEnabled: true,
},
}
s := createTestServer(t, &dnsfilter.Config{}, forwardConf, nil)
s := createTestServer(t, &filtering.Config{}, forwardConf, nil)
startDeferStop(t, s)
addr := s.dnsProxy.Addr(proxy.ProtoUDP)
@ -822,7 +822,7 @@ func TestBlockedBySafeBrowsing(t *testing.T) {
}
ans4, _ := (&aghtest.TestResolver{}).HostToIPs(hostname)
filterConf := &dnsfilter.Config{
filterConf := &filtering.Config{
SafeBrowsingEnabled: true,
}
forwardConf := ServerConfig{
@ -851,8 +851,8 @@ func TestBlockedBySafeBrowsing(t *testing.T) {
}
func TestRewrite(t *testing.T) {
c := &dnsfilter.Config{
Rewrites: []dnsfilter.RewriteEntry{{
c := &filtering.Config{
Rewrites: []filtering.RewriteEntry{{
Domain: "test.com",
Answer: "1.2.3.4",
Type: dns.TypeA,
@ -866,7 +866,7 @@ func TestRewrite(t *testing.T) {
Type: dns.TypeCNAME,
}},
}
f := dnsfilter.New(c, nil)
f := filtering.New(c, nil)
snd, err := aghnet.NewSubnetDetector()
require.NoError(t, err)
@ -1038,7 +1038,7 @@ func TestPTRResponseFromDHCPLeases(t *testing.T) {
var s *Server
s, err = NewServer(DNSCreateParams{
DNSFilter: dnsfilter.New(&dnsfilter.Config{}, nil),
DNSFilter: filtering.New(&filtering.Config{}, nil),
DHCPServer: &testDHCP{},
SubnetDetector: snd,
})
@ -1076,7 +1076,7 @@ func TestPTRResponseFromDHCPLeases(t *testing.T) {
}
func TestPTRResponseFromHosts(t *testing.T) {
c := dnsfilter.Config{
c := filtering.Config{
EtcHosts: &aghnet.EtcHostsContainer{},
}
@ -1102,7 +1102,7 @@ func TestPTRResponseFromHosts(t *testing.T) {
var s *Server
s, err = NewServer(DNSCreateParams{
DHCPServer: &testDHCP{},
DNSFilter: dnsfilter.New(&c, nil),
DNSFilter: filtering.New(&c, nil),
SubnetDetector: snd,
})
require.NoError(t, err)

View File

@ -5,7 +5,7 @@ import (
"net"
"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/golibs/log"
"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
// 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)
dnsrr := res.DNSRewriteResult
if dnsrr == nil {

View File

@ -4,7 +4,7 @@ import (
"net"
"testing"
"github.com/AdguardTeam/AdGuardHome/internal/dnsfilter"
"github.com/AdguardTeam/AdGuardHome/internal/filtering"
"github.com/AdguardTeam/dnsproxy/proxy"
"github.com/AdguardTeam/urlfilter/rules"
"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) {
resp := dnsfilter.DNSRewriteResultResponse{
makeRes := func(rcode rules.RCode, rr rules.RRType, v rules.RRValue) (res filtering.Result) {
resp := filtering.DNSRewriteResultResponse{
rr: []rules.RRValue{v},
}
return dnsfilter.Result{
DNSRewriteResult: &dnsfilter.DNSRewriteResult{
return filtering.Result{
DNSRewriteResult: &filtering.DNSRewriteResult{
RCode: rcode,
Response: resp,
},

View File

@ -4,7 +4,7 @@ import (
"fmt"
"strings"
"github.com/AdguardTeam/AdGuardHome/internal/dnsfilter"
"github.com/AdguardTeam/AdGuardHome/internal/filtering"
"github.com/AdguardTeam/dnsproxy/proxy"
"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
// 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.FilteringEnabled = true
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
// filtered.
func (s *Server) filterDNSRequest(ctx *dnsContext) (*dnsfilter.Result, error) {
func (s *Server) filterDNSRequest(ctx *dnsContext) (*filtering.Result, error) {
d := ctx.proxyCtx
req := d.Req
host := strings.TrimSuffix(req.Question[0].Name, ".")
res, err := s.dnsFilter.CheckHost(host, req.Question[0].Qtype, ctx.setts)
if err != nil {
// 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 {
log.Tracef("Host %s is filtered, reason - %q, matched rule: %q", host, res.Reason, res.Rules[0].Text)
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 != "" &&
len(res.IPList) == 0 {
// Resolve the new canonical name, not the original host
@ -67,7 +67,7 @@ func (s *Server) filterDNSRequest(ctx *dnsContext) (*dnsfilter.Result, error) {
// processFilteringAfterResponse.
ctx.origQuestion = req.Question[0]
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)
for _, h := range res.ReverseHosts {
hdr := dns.RR_Header{
@ -86,7 +86,7 @@ func (s *Server) filterDNSRequest(ctx *dnsContext) (*dnsfilter.Result, error) {
}
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)
name := host
@ -108,7 +108,7 @@ func (s *Server) filterDNSRequest(ctx *dnsContext) (*dnsfilter.Result, error) {
}
d.Res = resp
} else if res.Reason == dnsfilter.RewrittenRule {
} else if res.Reason == filtering.RewrittenRule {
err = s.filterDNSRewrite(req, res, d)
if err != nil {
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 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
for _, a := range d.Res.Answer {
host := ""

View File

@ -12,7 +12,7 @@ import (
"strings"
"testing"
"github.com/AdguardTeam/AdGuardHome/internal/dnsfilter"
"github.com/AdguardTeam/AdGuardHome/internal/filtering"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
@ -34,7 +34,7 @@ func loadTestData(t *testing.T, casesFileName string, cases interface{}) {
const jsonExt = ".json"
func TestDNSForwardHTTTP_handleGetConfig(t *testing.T) {
filterConf := &dnsfilter.Config{
filterConf := &filtering.Config{
SafeBrowsingEnabled: true,
SafeBrowsingCacheSize: 1000,
SafeSearchEnabled: true,
@ -107,7 +107,7 @@ func TestDNSForwardHTTTP_handleGetConfig(t *testing.T) {
}
func TestDNSForwardHTTTP_handleSetConfig(t *testing.T) {
filterConf := &dnsfilter.Config{
filterConf := &filtering.Config{
SafeBrowsingEnabled: true,
SafeBrowsingCacheSize: 1000,
SafeSearchEnabled: true,

View File

@ -4,7 +4,7 @@ import (
"net"
"time"
"github.com/AdguardTeam/AdGuardHome/internal/dnsfilter"
"github.com/AdguardTeam/AdGuardHome/internal/filtering"
"github.com/AdguardTeam/dnsproxy/proxy"
"github.com/AdguardTeam/golibs/log"
"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
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
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 {
case dnsfilter.FilteredSafeBrowsing:
case filtering.FilteredSafeBrowsing:
return s.genBlockedHost(m, s.conf.SafeBrowsingBlockHost, d)
case dnsfilter.FilteredParental:
case filtering.FilteredParental:
return s.genBlockedHost(m, s.conf.ParentalBlockHost, d)
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.
// 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 &&
result.Rules[0].IP != nil {
return s.genResponseWithIP(m, result.Rules[0].IP)

View File

@ -4,7 +4,7 @@ import (
"strings"
"time"
"github.com/AdguardTeam/AdGuardHome/internal/dnsfilter"
"github.com/AdguardTeam/AdGuardHome/internal/filtering"
"github.com/AdguardTeam/AdGuardHome/internal/querylog"
"github.com/AdguardTeam/AdGuardHome/internal/stats"
"github.com/AdguardTeam/dnsproxy/proxy"
@ -66,7 +66,7 @@ func processQueryLogsAndStats(ctx *dnsContext) (rc resultCode) {
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 {
return
}
@ -86,17 +86,17 @@ func (s *Server) updateStats(ctx *dnsContext, elapsed time.Duration, res dnsfilt
e.Result = stats.RNotFiltered
switch res.Reason {
case dnsfilter.FilteredSafeBrowsing:
case filtering.FilteredSafeBrowsing:
e.Result = stats.RSafeBrowsing
case dnsfilter.FilteredParental:
case filtering.FilteredParental:
e.Result = stats.RParental
case dnsfilter.FilteredSafeSearch:
case filtering.FilteredSafeSearch:
e.Result = stats.RSafeSearch
case dnsfilter.FilteredBlockList:
case filtering.FilteredBlockList:
fallthrough
case dnsfilter.FilteredInvalid:
case filtering.FilteredInvalid:
fallthrough
case dnsfilter.FilteredBlockedService:
case filtering.FilteredBlockedService:
e.Result = stats.RFiltered
}

View File

@ -5,7 +5,7 @@ import (
"testing"
"time"
"github.com/AdguardTeam/AdGuardHome/internal/dnsfilter"
"github.com/AdguardTeam/AdGuardHome/internal/filtering"
"github.com/AdguardTeam/AdGuardHome/internal/querylog"
"github.com/AdguardTeam/AdGuardHome/internal/stats"
"github.com/AdguardTeam/dnsproxy/proxy"
@ -52,7 +52,7 @@ func TestProcessQueryLogsAndStats(t *testing.T) {
wantLogProto querylog.ClientProto
wantStatClient string
wantCode resultCode
reason dnsfilter.Reason
reason filtering.Reason
wantStatResult stats.Result
}{{
name: "success_udp",
@ -62,7 +62,7 @@ func TestProcessQueryLogsAndStats(t *testing.T) {
wantLogProto: "",
wantStatClient: "1.2.3.4",
wantCode: resultCodeSuccess,
reason: dnsfilter.NotFilteredNotFound,
reason: filtering.NotFilteredNotFound,
wantStatResult: stats.RNotFiltered,
}, {
name: "success_tls_client_id",
@ -72,7 +72,7 @@ func TestProcessQueryLogsAndStats(t *testing.T) {
wantLogProto: querylog.ClientProtoDOT,
wantStatClient: "cli42",
wantCode: resultCodeSuccess,
reason: dnsfilter.NotFilteredNotFound,
reason: filtering.NotFilteredNotFound,
wantStatResult: stats.RNotFiltered,
}, {
name: "success_tls",
@ -82,7 +82,7 @@ func TestProcessQueryLogsAndStats(t *testing.T) {
wantLogProto: querylog.ClientProtoDOT,
wantStatClient: "1.2.3.4",
wantCode: resultCodeSuccess,
reason: dnsfilter.NotFilteredNotFound,
reason: filtering.NotFilteredNotFound,
wantStatResult: stats.RNotFiltered,
}, {
name: "success_quic",
@ -92,7 +92,7 @@ func TestProcessQueryLogsAndStats(t *testing.T) {
wantLogProto: querylog.ClientProtoDOQ,
wantStatClient: "1.2.3.4",
wantCode: resultCodeSuccess,
reason: dnsfilter.NotFilteredNotFound,
reason: filtering.NotFilteredNotFound,
wantStatResult: stats.RNotFiltered,
}, {
name: "success_https",
@ -102,7 +102,7 @@ func TestProcessQueryLogsAndStats(t *testing.T) {
wantLogProto: querylog.ClientProtoDOH,
wantStatClient: "1.2.3.4",
wantCode: resultCodeSuccess,
reason: dnsfilter.NotFilteredNotFound,
reason: filtering.NotFilteredNotFound,
wantStatResult: stats.RNotFiltered,
}, {
name: "success_dnscrypt",
@ -112,7 +112,7 @@ func TestProcessQueryLogsAndStats(t *testing.T) {
wantLogProto: querylog.ClientProtoDNSCrypt,
wantStatClient: "1.2.3.4",
wantCode: resultCodeSuccess,
reason: dnsfilter.NotFilteredNotFound,
reason: filtering.NotFilteredNotFound,
wantStatResult: stats.RNotFiltered,
}, {
name: "success_udp_filtered",
@ -122,7 +122,7 @@ func TestProcessQueryLogsAndStats(t *testing.T) {
wantLogProto: "",
wantStatClient: "1.2.3.4",
wantCode: resultCodeSuccess,
reason: dnsfilter.FilteredBlockList,
reason: filtering.FilteredBlockList,
wantStatResult: stats.RFiltered,
}, {
name: "success_udp_sb",
@ -132,7 +132,7 @@ func TestProcessQueryLogsAndStats(t *testing.T) {
wantLogProto: "",
wantStatClient: "1.2.3.4",
wantCode: resultCodeSuccess,
reason: dnsfilter.FilteredSafeBrowsing,
reason: filtering.FilteredSafeBrowsing,
wantStatResult: stats.RSafeBrowsing,
}, {
name: "success_udp_ss",
@ -142,7 +142,7 @@ func TestProcessQueryLogsAndStats(t *testing.T) {
wantLogProto: "",
wantStatClient: "1.2.3.4",
wantCode: resultCodeSuccess,
reason: dnsfilter.FilteredSafeSearch,
reason: filtering.FilteredSafeSearch,
wantStatResult: stats.RSafeSearch,
}, {
name: "success_udp_pc",
@ -152,7 +152,7 @@ func TestProcessQueryLogsAndStats(t *testing.T) {
wantLogProto: "",
wantStatClient: "1.2.3.4",
wantCode: resultCodeSuccess,
reason: dnsfilter.FilteredParental,
reason: filtering.FilteredParental,
wantStatResult: stats.RParental,
}}
@ -183,7 +183,7 @@ func TestProcessQueryLogsAndStats(t *testing.T) {
},
proxyCtx: pctx,
startTime: time.Now(),
result: &dnsfilter.Result{
result: &filtering.Result{
Reason: tc.reason,
},
clientID: tc.clientID,

View File

@ -3,7 +3,7 @@
Example use:
```bash
[ -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
@ -11,12 +11,12 @@ Create file filter.go
package main
import (
"github.com/AdguardTeam/AdGuardHome/dnsfilter"
"github.com/AdguardTeam/AdGuardHome/filtering"
"log"
)
func main() {
filter := dnsfilter.New()
filter := filtering.New()
filter.AddRule("||dou*ck.net^")
host := "www.doubleclick.net"
res, err := filter.CheckHost(host)
@ -48,12 +48,12 @@ You can also enable checking against AdGuard's SafeBrowsing:
package main
import (
"github.com/AdguardTeam/AdGuardHome/dnsfilter"
"github.com/AdguardTeam/AdGuardHome/filtering"
"log"
)
func main() {
filter := dnsfilter.New()
filter := filtering.New()
filter.EnableSafeBrowsing()
host := "wmconvirus.narod.ru" // hostname for testing safebrowsing
res, err := filter.CheckHost(host)

View File

@ -1,4 +1,4 @@
package dnsfilter
package filtering
import (
"encoding/json"
@ -254,7 +254,7 @@ func BlockedSvcKnown(s string) bool {
}
// 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{}
if global {
d.confLock.RLock()

View File

@ -2,7 +2,7 @@
//go:build ignore
package dnsfilter
package filtering
import (
"fmt"
@ -16,7 +16,7 @@ import (
// client/src/components/ui/Icons.js
//
// 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".
// 3. You'll need to enter services names manually.
// 4. Don't forget to add missing icons to "client/src/components/ui/Icons.js".

View File

@ -1,4 +1,4 @@
package dnsfilter
package filtering
import (
"github.com/AdguardTeam/urlfilter/rules"

View File

@ -1,4 +1,4 @@
package dnsfilter
package filtering
import (
"net"
@ -47,7 +47,7 @@ func TestDNSFilter_CheckHostRules_dnsrewrite(t *testing.T) {
`
f := newForTest(nil, []Filter{{ID: 0, Data: []byte(text)}})
setts := &FilteringSettings{
setts := &Settings{
FilteringEnabled: true,
}

View File

@ -1,5 +1,5 @@
// Package dnsfilter implements a DNS request and response filter.
package dnsfilter
// Package filtering implements a DNS request and response filter.
package filtering
import (
"context"
@ -29,8 +29,8 @@ type ServiceEntry struct {
Rules []*rules.NetworkRule
}
// FilteringSettings are custom filtering settings for a client.
type FilteringSettings struct {
// Settings are custom filtering settings for a client.
type Settings struct {
ClientName string
ClientIP net.IP
ClientTags []string
@ -101,7 +101,7 @@ type filtersInitializerParams 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
}
@ -224,8 +224,8 @@ func (r Reason) In(reasons ...Reason) bool {
}
// GetConfig - get configuration
func (d *DNSFilter) GetConfig() FilteringSettings {
c := FilteringSettings{}
func (d *DNSFilter) GetConfig() Settings {
c := Settings{}
// d.confLock.RLock()
c.SafeSearchEnabled = d.Config.SafeSearchEnabled
c.SafeBrowsingEnabled = d.Config.SafeBrowsingEnabled
@ -304,14 +304,14 @@ func (d *DNSFilter) reset() {
if d.rulesStorage != nil {
err = d.rulesStorage.Close()
if err != nil {
log.Error("dnsfilter: rulesStorage.Close: %s", err)
log.Error("filtering: rulesStorage.Close: %s", err)
}
}
if d.rulesStorageAllow != nil {
err = d.rulesStorageAllow.Close()
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
}
var gctx dnsFilterContext // global dnsfilter context
var gctx dnsFilterContext
// ResultRule contains information about applied rules.
type ResultRule struct {
@ -380,7 +380,7 @@ func (r Reason) Matched() bool {
}
// 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 {
return Result{}, nil
}
@ -393,7 +393,7 @@ func (d *DNSFilter) CheckHostRules(host string, qtype uint16, setts *FilteringSe
func (d *DNSFilter) CheckHost(
host string,
qtype uint16,
setts *FilteringSettings,
setts *Settings,
) (res Result, err error) {
// Sometimes clients try to resolve ".", which is a request to get root
// servers.
@ -427,7 +427,7 @@ func (d *DNSFilter) CheckHost(
func (d *DNSFilter) checkEtcHosts(
host string,
qtype uint16,
_ *FilteringSettings,
_ *Settings,
) (res Result, err error) {
if d.Config.EtcHosts == nil {
return Result{}, nil
@ -523,7 +523,7 @@ func (d *DNSFilter) processRewrites(host string, qtype uint16) (res Result) {
func matchBlockedServicesRules(
host string,
_ uint16,
setts *FilteringSettings,
setts *Settings,
) (res Result, err error) {
svcs := setts.ServicesRules
if len(svcs) == 0 {
@ -715,7 +715,7 @@ func (d *DNSFilter) matchHostProcessDNSResult(
func (d *DNSFilter) matchHost(
host string,
qtype uint16,
setts *FilteringSettings,
setts *Settings,
) (res Result, err error) {
if !setts.FilteringEnabled {
return Result{}, nil
@ -851,7 +851,7 @@ func New(c *Config, blockFilters []Filter) *DNSFilter {
err := d.initSecurityServices()
if err != nil {
log.Error("dnsfilter: initialize services: %s", err)
log.Error("filtering: initialize services: %s", err)
return nil
}

View File

@ -1,4 +1,4 @@
package dnsfilter
package filtering
import (
"bytes"
@ -21,7 +21,7 @@ func TestMain(m *testing.M) {
aghtest.DiscardLogOutput(m)
}
var setts FilteringSettings
var setts Settings
// Helpers.
@ -38,7 +38,7 @@ func purgeCaches() {
}
func newForTest(c *Config, filters []Filter) *DNSFilter {
setts = FilteringSettings{
setts = Settings{
FilteringEnabled: true,
}
setts.FilteringEnabled = true
@ -699,7 +699,7 @@ func TestWhitelist(t *testing.T) {
// Client Settings.
func applyClientSettings(setts *FilteringSettings) {
func applyClientSettings(setts *Settings) {
setts.FilteringEnabled = false
setts.ParentalEnabled = false
setts.SafeBrowsingEnabled = true

View File

@ -1,6 +1,6 @@
// DNS Rewrites
package dnsfilter
package filtering
import (
"encoding/json"

View File

@ -1,4 +1,4 @@
package dnsfilter
package filtering
import (
"net"

View File

@ -1,4 +1,4 @@
package dnsfilter
package filtering
import (
"bytes"
@ -304,7 +304,7 @@ func check(c *sbCtx, r Result, u upstream.Upstream) (Result, error) {
func (d *DNSFilter) checkSafeBrowsing(
host string,
_ uint16,
setts *FilteringSettings,
setts *Settings,
) (res Result, err error) {
if !setts.SafeBrowsingEnabled {
return Result{}, nil
@ -337,7 +337,7 @@ func (d *DNSFilter) checkSafeBrowsing(
func (d *DNSFilter) checkParental(
host string,
_ uint16,
setts *FilteringSettings,
setts *Settings,
) (res Result, err error) {
if !setts.ParentalEnabled {
return Result{}, nil

View File

@ -1,4 +1,4 @@
package dnsfilter
package filtering
import (
"crypto/sha256"
@ -116,7 +116,7 @@ func TestSBPC_checkErrorUpstream(t *testing.T) {
d.SetSafeBrowsingUpstream(ups)
d.SetParentalUpstream(ups)
setts := &FilteringSettings{
setts := &Settings{
SafeBrowsingEnabled: true,
ParentalEnabled: true,
}
@ -134,7 +134,7 @@ func TestSBPC(t *testing.T) {
const hostname = "example.org"
setts := &FilteringSettings{
setts := &Settings{
SafeBrowsingEnabled: true,
ParentalEnabled: true,
}
@ -142,7 +142,7 @@ func TestSBPC(t *testing.T) {
testCases := []struct {
name string
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
}{{
name: "sb_no_block",

View File

@ -1,4 +1,4 @@
package dnsfilter
package filtering
import (
"bytes"
@ -72,7 +72,7 @@ func (d *DNSFilter) SafeSearchDomain(host string) (string, bool) {
func (d *DNSFilter) checkSafeSearch(
host string,
_ uint16,
setts *FilteringSettings,
setts *Settings,
) (res Result, err error) {
if !setts.SafeSearchEnabled {
return Result{}, nil

View File

@ -15,8 +15,8 @@ import (
"github.com/AdguardTeam/AdGuardHome/internal/aghnet"
"github.com/AdguardTeam/AdGuardHome/internal/aghstrings"
"github.com/AdguardTeam/AdGuardHome/internal/dhcpd"
"github.com/AdguardTeam/AdGuardHome/internal/dnsfilter"
"github.com/AdguardTeam/AdGuardHome/internal/dnsforward"
"github.com/AdguardTeam/AdGuardHome/internal/filtering"
"github.com/AdguardTeam/AdGuardHome/internal/querylog"
"github.com/AdguardTeam/dnsproxy/proxy"
"github.com/AdguardTeam/dnsproxy/upstream"
@ -181,7 +181,7 @@ func (clients *clientsContainer) addFromConfig(objects []clientObject) {
}
for _, s := range cy.BlockedServices {
if !dnsfilter.BlockedSvcKnown(s) {
if !filtering.BlockedSvcKnown(s) {
log.Debug("clients: skipping unknown blocked-service %q", s)
continue
}

View File

@ -9,8 +9,8 @@ import (
"sync"
"github.com/AdguardTeam/AdGuardHome/internal/dhcpd"
"github.com/AdguardTeam/AdGuardHome/internal/dnsfilter"
"github.com/AdguardTeam/AdGuardHome/internal/dnsforward"
"github.com/AdguardTeam/AdGuardHome/internal/filtering"
"github.com/AdguardTeam/AdGuardHome/internal/querylog"
"github.com/AdguardTeam/AdGuardHome/internal/stats"
"github.com/AdguardTeam/AdGuardHome/internal/version"
@ -98,7 +98,7 @@ type dnsConfig struct {
FilteringEnabled bool `yaml:"filtering_enabled"` // whether or not use filter lists
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.
// For example, a machine called "myhost" can be addressed as
@ -149,7 +149,7 @@ var config = configuration{
Port: 53,
StatsInterval: 1,
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
BlockedResponseTTL: 10, // in seconds
Ratelimit: 20,
@ -306,7 +306,7 @@ func (c *configuration) write() error {
}
if Context.dnsFilter != nil {
c := dnsfilter.Config{}
c := filtering.Config{}
Context.dnsFilter.WriteDiskConfig(&c)
config.DNS.DnsfilterConf = c
}

View File

@ -9,8 +9,8 @@ import (
"strconv"
"github.com/AdguardTeam/AdGuardHome/internal/agherr"
"github.com/AdguardTeam/AdGuardHome/internal/dnsfilter"
"github.com/AdguardTeam/AdGuardHome/internal/dnsforward"
"github.com/AdguardTeam/AdGuardHome/internal/filtering"
"github.com/AdguardTeam/AdGuardHome/internal/querylog"
"github.com/AdguardTeam/AdGuardHome/internal/stats"
"github.com/AdguardTeam/dnsproxy/proxy"
@ -60,7 +60,7 @@ func initDNSServer() error {
filterConf.EtcHosts = Context.etcHosts
filterConf.ConfigModified = onConfigModified
filterConf.HTTPRegister = httpRegister
Context.dnsFilter = dnsfilter.New(&filterConf, nil)
Context.dnsFilter = filtering.New(&filterConf, nil)
p := dnsforward.DNSCreateParams{
DNSFilter: Context.dnsFilter,
@ -282,7 +282,7 @@ func getDNSEncryption() (de dnsEncryption) {
// applyAdditionalFiltering adds additional client information and settings if
// 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)
if clientAddr == nil {

View File

@ -16,7 +16,7 @@ import (
"sync/atomic"
"time"
"github.com/AdguardTeam/AdGuardHome/internal/dnsfilter"
"github.com/AdguardTeam/AdGuardHome/internal/filtering"
"github.com/AdguardTeam/golibs/log"
)
@ -57,9 +57,9 @@ func (f *Filtering) Close() {
func defaultFilters() []filter {
return []filter{
{Filter: dnsfilter.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: dnsfilter.Filter{ID: 4}, Enabled: false, URL: "https://www.malwaredomainlist.com/hostslist/hosts.txt", Name: "MalwareDomainList.com Hosts List"},
{Filter: filtering.Filter{ID: 1}, Enabled: true, URL: "https://adguardteam.github.io/AdGuardSDNSFilter/Filters/filter.txt", Name: "AdGuard DNS filter"},
{Filter: filtering.Filter{ID: 2}, Enabled: false, URL: "https://adaway.org/hosts.txt", Name: "AdAway Default Blocklist"},
{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
white bool
dnsfilter.Filter `yaml:",inline"`
filtering.Filter `yaml:",inline"`
}
const (
@ -376,9 +376,9 @@ const (
// . If filter data has changed:
// . rename the temporary file (<temp> -> 1.txt)
// Note that this method works only on UNIX.
// On Windows we don't pass files to dnsfilter - we pass the whole data.
// . Pass new filters to dnsfilter object - it analyzes new data while the old filters are still active
// . dnsfilter activates new filters
// On Windows we don't pass files to filtering - we pass the whole data.
// . Pass new filters to filtering object - it analyzes new data while the old filters are still active
// . filtering activates new filters
//
// Return the number of updated filters
// 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) {
var whiteFilters []dnsfilter.Filter
filters := []dnsfilter.Filter{{
var whiteFilters []filtering.Filter
filters := []filtering.Filter{{
Data: []byte(strings.Join(config.UserRules, "\n")),
}}
@ -674,7 +674,7 @@ func enableFilters(async bool) {
continue
}
filters = append(filters, dnsfilter.Filter{
filters = append(filters, filtering.Filter{
ID: filter.ID,
FilePath: filter.Path(),
})
@ -684,7 +684,7 @@ func enableFilters(async bool) {
continue
}
whiteFilters = append(whiteFilters, dnsfilter.Filter{
whiteFilters = append(whiteFilters, filtering.Filter{
ID: filter.ID,
FilePath: filter.Path(),
})

View File

@ -25,8 +25,8 @@ import (
"github.com/AdguardTeam/AdGuardHome/internal/aghnet"
"github.com/AdguardTeam/AdGuardHome/internal/aghos"
"github.com/AdguardTeam/AdGuardHome/internal/dhcpd"
"github.com/AdguardTeam/AdGuardHome/internal/dnsfilter"
"github.com/AdguardTeam/AdGuardHome/internal/dnsforward"
"github.com/AdguardTeam/AdGuardHome/internal/filtering"
"github.com/AdguardTeam/AdGuardHome/internal/querylog"
"github.com/AdguardTeam/AdGuardHome/internal/stats"
"github.com/AdguardTeam/AdGuardHome/internal/updater"
@ -51,7 +51,7 @@ type homeContext struct {
dnsServer *dnsforward.Server // DNS module
rdns *RDNS // rDNS module
whois *Whois // WHOIS module
dnsFilter *dnsfilter.DNSFilter // DNS filtering module
dnsFilter *filtering.DNSFilter // DNS filtering module
dhcpServer *dhcpd.Server // DHCP module
auth *Auth // HTTP authentication module
filters Filtering // DNS filtering module
@ -291,10 +291,10 @@ func run(args options, clientBuildFS fs.FS) {
setupContext(args)
// clients package uses dnsfilter package's static data (dnsfilter.BlockedSvcKnown()),
// so we have to initialize dnsfilter's static data first,
// clients package uses filtering package's static data (filtering.BlockedSvcKnown()),
// so we have to initialize filtering's static data first,
// but also avoid relying on automatic Go init() function
dnsfilter.InitModule()
filtering.InitModule()
setupConfig(args)

View File

@ -8,7 +8,7 @@ import (
"strings"
"time"
"github.com/AdguardTeam/AdGuardHome/internal/dnsfilter"
"github.com/AdguardTeam/AdGuardHome/internal/filtering"
"github.com/AdguardTeam/golibs/log"
"github.com/AdguardTeam/urlfilter/rules"
"github.com/miekg/dns"
@ -138,7 +138,7 @@ var resultHandlers = map[string]logEntryHandler{
l := len(ent.Result.Rules)
if l == 0 {
ent.Result.Rules = []*dnsfilter.ResultRule{{}}
ent.Result.Rules = []*filtering.ResultRule{{}}
l++
}
@ -159,7 +159,7 @@ var resultHandlers = map[string]logEntryHandler{
l := len(ent.Result.Rules)
if l == 0 {
ent.Result.Rules = []*dnsfilter.ResultRule{{}}
ent.Result.Rules = []*filtering.ResultRule{{}}
l++
}
@ -176,7 +176,7 @@ var resultHandlers = map[string]logEntryHandler{
if err != nil {
return err
}
ent.Result.Reason = dnsfilter.Reason(i)
ent.Result.Reason = filtering.Reason(i)
return nil
},
"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 {
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 {
@ -231,7 +231,7 @@ func decodeResultRuleKey(key string, i int, dec *json.Decoder, ent *logEntry) {
}
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 {
@ -248,7 +248,7 @@ func decodeResultRuleKey(key string, i int, dec *json.Decoder, ent *logEntry) {
}
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 {
@ -391,7 +391,7 @@ func decodeResultDNSRewriteResultKey(key string, dec *json.Decoder, ent *logEntr
}
if ent.Result.DNSRewriteResult == nil {
ent.Result.DNSRewriteResult = &dnsfilter.DNSRewriteResult{}
ent.Result.DNSRewriteResult = &filtering.DNSRewriteResult{}
}
if n, ok := vToken.(json.Number); ok {
@ -400,11 +400,11 @@ func decodeResultDNSRewriteResultKey(key string, dec *json.Decoder, ent *logEntr
}
case "Response":
if ent.Result.DNSRewriteResult == nil {
ent.Result.DNSRewriteResult = &dnsfilter.DNSRewriteResult{}
ent.Result.DNSRewriteResult = &filtering.DNSRewriteResult{}
}
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.

View File

@ -9,7 +9,7 @@ import (
"time"
"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/urlfilter/rules"
"github.com/miekg/dns"
@ -56,12 +56,12 @@ func TestDecodeLogEntry(t *testing.T) {
ClientID: "cli42",
ClientProto: "",
Answer: ans,
Result: dnsfilter.Result{
Result: filtering.Result{
IsFiltered: true,
Reason: dnsfilter.FilteredBlockList,
Reason: filtering.FilteredBlockList,
ReverseHosts: []string{"example.net"},
IPList: []net.IP{net.IPv4(127, 0, 0, 2)},
Rules: []*dnsfilter.ResultRule{{
Rules: []*filtering.ResultRule{{
FilterListID: 42,
Text: "||an.yandex.ru",
IP: net.IPv4(127, 0, 0, 2),
@ -72,9 +72,9 @@ func TestDecodeLogEntry(t *testing.T) {
}},
CanonName: "example.com",
ServiceName: "example.org",
DNSRewriteResult: &dnsfilter.DNSRewriteResult{
DNSRewriteResult: &filtering.DNSRewriteResult{
RCode: dns.RcodeSuccess,
Response: dnsfilter.DNSRewriteResultResponse{
Response: filtering.DNSRewriteResultResponse{
dns.TypeA: []rules.RRValue{net.IPv4(127, 0, 0, 2)},
},
},

View File

@ -7,7 +7,7 @@ import (
"strings"
"time"
"github.com/AdguardTeam/AdGuardHome/internal/dnsfilter"
"github.com/AdguardTeam/AdGuardHome/internal/filtering"
"github.com/AdguardTeam/golibs/log"
"github.com/miekg/dns"
)
@ -129,7 +129,7 @@ func (l *queryLog) logEntryToJSONEntry(entry *logEntry) (jsonEntry jobject) {
return jsonEntry
}
func resultRulesToJSONRules(rules []*dnsfilter.ResultRule) (jsonRules []jobject) {
func resultRulesToJSONRules(rules []*filtering.ResultRule) (jsonRules []jobject) {
jsonRules = make([]jobject, len(rules))
for i, r := range rules {
jsonRules[i] = jobject{

View File

@ -10,7 +10,7 @@ import (
"sync"
"time"
"github.com/AdguardTeam/AdGuardHome/internal/dnsfilter"
"github.com/AdguardTeam/AdGuardHome/internal/filtering"
"github.com/AdguardTeam/golibs/log"
"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
OrigAnswer []byte `json:",omitempty"`
Result dnsfilter.Result
Result filtering.Result
Elapsed time.Duration
Upstream string `json:",omitempty"` // if empty, means it was cached
}
@ -147,7 +147,7 @@ func (l *queryLog) Add(params AddParams) {
}
if params.Result == nil {
params.Result = &dnsfilter.Result{}
params.Result = &filtering.Result{}
}
now := time.Now()

View File

@ -9,7 +9,7 @@ import (
"time"
"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/miekg/dns"
"github.com/stretchr/testify/assert"
@ -267,11 +267,11 @@ func addEntry(l *queryLog, host string, answerStr, client net.IP) {
A: answerStr,
}},
}
res := dnsfilter.Result{
res := filtering.Result{
IsFiltered: true,
Reason: dnsfilter.Rewritten,
Reason: filtering.Rewritten,
ServiceName: "SomeService",
Rules: []*dnsfilter.ResultRule{{
Rules: []*filtering.ResultRule{{
FilterListID: 1,
Text: "SomeRule",
}},

View File

@ -7,7 +7,7 @@ import (
"time"
"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/miekg/dns"
)
@ -66,7 +66,7 @@ type AddParams struct {
Question *dns.Msg
Answer *dns.Msg // The response we sent to the client (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
ClientID string
ClientIP net.IP

View File

@ -5,7 +5,7 @@ import (
"unicode"
"unicode/utf8"
"github.com/AdguardTeam/AdGuardHome/internal/dnsfilter"
"github.com/AdguardTeam/AdGuardHome/internal/filtering"
)
type criterionType int
@ -168,7 +168,7 @@ func (c *searchCriterion) ctDomainOrClientCase(e *logEntry) bool {
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 {
case filteringStatusAll:
return true
@ -176,43 +176,43 @@ func (c *searchCriterion) ctFilteringStatusCase(res dnsfilter.Result) bool {
case filteringStatusFiltered:
return res.IsFiltered ||
res.Reason.In(
dnsfilter.NotFilteredAllowList,
dnsfilter.Rewritten,
dnsfilter.RewrittenAutoHosts,
dnsfilter.RewrittenRule,
filtering.NotFilteredAllowList,
filtering.Rewritten,
filtering.RewrittenAutoHosts,
filtering.RewrittenRule,
)
case filteringStatusBlocked:
return res.IsFiltered &&
res.Reason.In(dnsfilter.FilteredBlockList, dnsfilter.FilteredBlockedService)
res.Reason.In(filtering.FilteredBlockList, filtering.FilteredBlockedService)
case filteringStatusBlockedService:
return res.IsFiltered && res.Reason == dnsfilter.FilteredBlockedService
return res.IsFiltered && res.Reason == filtering.FilteredBlockedService
case filteringStatusBlockedParental:
return res.IsFiltered && res.Reason == dnsfilter.FilteredParental
return res.IsFiltered && res.Reason == filtering.FilteredParental
case filteringStatusBlockedSafebrowsing:
return res.IsFiltered && res.Reason == dnsfilter.FilteredSafeBrowsing
return res.IsFiltered && res.Reason == filtering.FilteredSafeBrowsing
case filteringStatusWhitelisted:
return res.Reason == dnsfilter.NotFilteredAllowList
return res.Reason == filtering.NotFilteredAllowList
case filteringStatusRewritten:
return res.Reason.In(
dnsfilter.Rewritten,
dnsfilter.RewrittenAutoHosts,
dnsfilter.RewrittenRule,
filtering.Rewritten,
filtering.RewrittenAutoHosts,
filtering.RewrittenRule,
)
case filteringStatusSafeSearch:
return res.IsFiltered && res.Reason == dnsfilter.FilteredSafeSearch
return res.IsFiltered && res.Reason == filtering.FilteredSafeSearch
case filteringStatusProcessed:
return !res.Reason.In(
dnsfilter.FilteredBlockList,
dnsfilter.FilteredBlockedService,
dnsfilter.NotFilteredAllowList,
filtering.FilteredBlockList,
filtering.FilteredBlockedService,
filtering.NotFilteredAllowList,
)
default: