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:
@@ -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
|
||||
|
||||
@@ -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{}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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,
|
||||
},
|
||||
|
||||
@@ -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 := ""
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user