Skip to content

Commit

Permalink
cherry-pick: 1730 bogus cidr
Browse files Browse the repository at this point in the history
Merge in DNS/adguard-home from 1730-bogus-cidr to master

Closes #1730.

Squashed commit of the following:

commit 0be5425
Author: Eugene Burkov <E.Burkov@AdGuard.COM>
Date:   Tue Jan 25 18:50:01 2022 +0300

    all: imp log of changes

commit 59fb7a8
Author: Eugene Burkov <E.Burkov@AdGuard.COM>
Date:   Tue Jan 25 18:46:34 2022 +0300

    all: log changes

commit 9206b13
Author: Eugene Burkov <E.Burkov@AdGuard.COM>
Date:   Tue Jan 25 18:41:26 2022 +0300

    all: upd dnsproxy
  • Loading branch information
EugeneOne1 authored and ainar-g committed Jun 2, 2022
1 parent d98d96d commit 9d75f72
Show file tree
Hide file tree
Showing 9 changed files with 160 additions and 180 deletions.
50 changes: 26 additions & 24 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,66 +3,68 @@ module github.com/AdguardTeam/AdGuardHome
go 1.17

require (
github.com/AdguardTeam/dnsproxy v0.41.4
github.com/AdguardTeam/dnsproxy v0.43.0
github.com/AdguardTeam/golibs v0.10.8
github.com/AdguardTeam/urlfilter v0.15.2
github.com/AdguardTeam/urlfilter v0.16.0
github.com/NYTimes/gziphandler v1.1.1
github.com/ameshkov/dnscrypt/v2 v2.2.3
github.com/digineo/go-ipset/v2 v2.2.1
github.com/fsnotify/fsnotify v1.5.1
github.com/dimfeld/httptreemux/v5 v5.4.0
github.com/fsnotify/fsnotify v1.5.4
github.com/go-ping/ping v0.0.0-20211130115550-779d1e919534
github.com/google/go-cmp v0.5.6
github.com/google/go-cmp v0.5.7
github.com/google/gopacket v1.1.19
github.com/google/renameio v1.0.1
github.com/insomniacslk/dhcp v0.0.0-20211214070828-5297eed8f489
github.com/kardianos/service v1.2.0
github.com/lucas-clemente/quic-go v0.25.0
github.com/mdlayher/ethernet v0.0.0-20190606142754-0394541c37b7
github.com/mdlayher/netlink v1.5.0
github.com/insomniacslk/dhcp v0.0.0-20220405050111-12fbdcb11b41
github.com/kardianos/service v1.2.1
github.com/lucas-clemente/quic-go v0.27.1
github.com/mdlayher/ethernet v0.0.0-20220221185849-529eae5b6118
github.com/mdlayher/netlink v1.6.0
// TODO(a.garipov): This package is deprecated; find a new one or use
// our own code for that.
github.com/mdlayher/raw v0.0.0-20211126142749-4eae47f3d54b
github.com/miekg/dns v1.1.48
github.com/satori/go.uuid v1.2.0
github.com/stretchr/testify v1.7.0
github.com/ti-mo/netfilter v0.4.0
go.etcd.io/bbolt v1.3.6
golang.org/x/crypto v0.0.0-20211215153901-e495a2d5b3d3
golang.org/x/net v0.0.0-20220403103023-749bd193bc2b
golang.org/x/sys v0.0.0-20220406163625-3f8b81556e12
golang.org/x/crypto v0.0.0-20220411220226-7b82a4e95df4
golang.org/x/net v0.0.0-20220425223048-2871e0cb64e4
golang.org/x/sys v0.0.0-20220422013727-9388b58f7150
gopkg.in/natefinch/lumberjack.v2 v2.0.0
gopkg.in/yaml.v2 v2.4.0
howett.net/plist v1.0.0
)

require (
github.com/BurntSushi/toml v0.4.1 // indirect
github.com/BurntSushi/toml v1.1.0 // indirect
github.com/aead/chacha20 v0.0.0-20180709150244-8b13a72661da // indirect
github.com/aead/poly1305 v0.0.0-20180717145839-3fee0db0b635 // indirect
github.com/ameshkov/dnsstamps v1.0.3 // indirect
github.com/beefsack/go-rate v0.0.0-20200827232406-6cde80facd47 // indirect
github.com/beefsack/go-rate v0.0.0-20220214233405-116f4ca011a0 // indirect
github.com/cheekybits/genny v1.0.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/josharian/native v0.0.0-20200817173448-b6b71def0850 // indirect
github.com/marten-seemann/qtls-go1-16 v0.1.4 // indirect
github.com/marten-seemann/qtls-go1-17 v0.1.0 // indirect
github.com/marten-seemann/qtls-go1-18 v0.1.0-beta.1 // indirect
github.com/mdlayher/socket v0.1.1 // indirect
github.com/josharian/native v1.0.0 // indirect
github.com/marten-seemann/qtls-go1-16 v0.1.5 // indirect
github.com/marten-seemann/qtls-go1-17 v0.1.1 // indirect
github.com/marten-seemann/qtls-go1-18 v0.1.1 // indirect
github.com/mdlayher/socket v0.2.3 // indirect
github.com/nxadm/tail v1.4.8 // indirect
github.com/onsi/ginkgo v1.16.5 // indirect
github.com/patrickmn/go-cache v2.1.0+incompatible // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/stretchr/objx v0.1.1 // indirect
github.com/u-root/uio v0.0.0-20210528151154-e40b768296a7 // indirect
golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3 // indirect
github.com/u-root/uio v0.0.0-20220204230159-dac05f7d2cb4 // indirect
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 // indirect
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect
golang.org/x/text v0.3.7 // indirect
golang.org/x/tools v0.1.10 // indirect
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
golang.org/x/tools v0.1.11-0.20220426200323-dcaea06afc12 // indirect
golang.org/x/xerrors v0.0.0-20220411194840-2f41105eb62f // indirect
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
honnef.co/go/tools v0.2.2 // indirect
)

// TODO(a.garipov): Return to the main repo once miekg/dns#1359 is merged.
Expand Down
162 changes: 58 additions & 104 deletions go.sum

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion internal/aghnet/hostscontainer.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ type requestMatcher struct {
//
// It's safe for concurrent use.
func (rm *requestMatcher) MatchRequest(
req urlfilter.DNSRequest,
req *urlfilter.DNSRequest,
) (res *urlfilter.DNSResult, ok bool) {
switch req.DNSType {
case dns.TypeA, dns.TypeAAAA, dns.TypePTR:
Expand Down
36 changes: 18 additions & 18 deletions internal/aghnet/hostscontainer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package aghnet
import (
"io/fs"
"net"
"os"
"path"
"strings"
"sync/atomic"
Expand Down Expand Up @@ -194,7 +193,7 @@ func TestHostsContainer_refresh(t *testing.T) {

// Require the changes are written.
require.Eventually(t, func() bool {
res, ok := hc.MatchRequest(urlfilter.DNSRequest{
res, ok := hc.MatchRequest(&urlfilter.DNSRequest{
Hostname: "hostname",
DNSType: dns.TypeA,
})
Expand All @@ -208,7 +207,7 @@ func TestHostsContainer_refresh(t *testing.T) {

// Require the changes are written.
require.Eventually(t, func() bool {
res, ok := hc.MatchRequest(urlfilter.DNSRequest{
res, ok := hc.MatchRequest(&urlfilter.DNSRequest{
Hostname: "hostname",
DNSType: dns.TypeA,
})
Expand Down Expand Up @@ -281,13 +280,14 @@ func TestHostsContainer_PathsToPatterns(t *testing.T) {
}

func TestHostsContainer_Translate(t *testing.T) {
testdata := os.DirFS("./testdata")
stubWatcher := aghtest.FSWatcher{
OnEvents: func() (e <-chan struct{}) { return nil },
OnAdd: func(name string) (err error) { return nil },
OnClose: func() (err error) { panic("not implemented") },
}

require.NoError(t, fstest.TestFS(testdata, "etc_hosts"))

hc, err := NewHostsContainer(0, testdata, &stubWatcher, "etc_hosts")
require.NoError(t, err)
testutil.CleanupAndRequireSuccess(t, hc.Close)
Expand Down Expand Up @@ -360,12 +360,12 @@ func TestHostsContainer_Translate(t *testing.T) {
func TestHostsContainer(t *testing.T) {
const listID = 1234

testdata := os.DirFS("./testdata")
require.NoError(t, fstest.TestFS(testdata, "etc_hosts"))

testCases := []struct {
want []*rules.DNSRewrite
name string
req urlfilter.DNSRequest
req *urlfilter.DNSRequest
}{{
want: []*rules.DNSRewrite{{
RCode: dns.RcodeSuccess,
Expand All @@ -377,7 +377,7 @@ func TestHostsContainer(t *testing.T) {
RRType: dns.TypeAAAA,
}},
name: "simple",
req: urlfilter.DNSRequest{
req: &urlfilter.DNSRequest{
Hostname: "simplehost",
DNSType: dns.TypeA,
},
Expand All @@ -392,7 +392,7 @@ func TestHostsContainer(t *testing.T) {
RRType: dns.TypeAAAA,
}},
name: "hello_alias",
req: urlfilter.DNSRequest{
req: &urlfilter.DNSRequest{
Hostname: "hello.world",
DNSType: dns.TypeA,
},
Expand All @@ -407,21 +407,21 @@ func TestHostsContainer(t *testing.T) {
RRType: dns.TypeAAAA,
}},
name: "other_line_alias",
req: urlfilter.DNSRequest{
req: &urlfilter.DNSRequest{
Hostname: "hello.world.again",
DNSType: dns.TypeA,
},
}, {
want: []*rules.DNSRewrite{},
name: "hello_subdomain",
req: urlfilter.DNSRequest{
req: &urlfilter.DNSRequest{
Hostname: "say.hello",
DNSType: dns.TypeA,
},
}, {
want: []*rules.DNSRewrite{},
name: "hello_alias_subdomain",
req: urlfilter.DNSRequest{
req: &urlfilter.DNSRequest{
Hostname: "say.hello.world",
DNSType: dns.TypeA,
},
Expand All @@ -436,7 +436,7 @@ func TestHostsContainer(t *testing.T) {
Value: net.ParseIP("::2"),
}},
name: "lots_of_aliases",
req: urlfilter.DNSRequest{
req: &urlfilter.DNSRequest{
Hostname: "for.testing",
DNSType: dns.TypeA,
},
Expand All @@ -447,21 +447,21 @@ func TestHostsContainer(t *testing.T) {
Value: "simplehost.",
}},
name: "reverse",
req: urlfilter.DNSRequest{
req: &urlfilter.DNSRequest{
Hostname: "1.0.0.1.in-addr.arpa",
DNSType: dns.TypePTR,
},
}, {
want: []*rules.DNSRewrite{},
name: "non-existing",
req: urlfilter.DNSRequest{
req: &urlfilter.DNSRequest{
Hostname: "nonexisting",
DNSType: dns.TypeA,
},
}, {
want: nil,
name: "bad_type",
req: urlfilter.DNSRequest{
req: &urlfilter.DNSRequest{
Hostname: "1.0.0.1.in-addr.arpa",
DNSType: dns.TypeSRV,
},
Expand All @@ -476,7 +476,7 @@ func TestHostsContainer(t *testing.T) {
Value: net.ParseIP("::42"),
}},
name: "issue_4216_4_6",
req: urlfilter.DNSRequest{
req: &urlfilter.DNSRequest{
Hostname: "domain",
DNSType: dns.TypeA,
},
Expand All @@ -491,7 +491,7 @@ func TestHostsContainer(t *testing.T) {
Value: net.IPv4(1, 3, 5, 7),
}},
name: "issue_4216_4",
req: urlfilter.DNSRequest{
req: &urlfilter.DNSRequest{
Hostname: "domain4",
DNSType: dns.TypeA,
},
Expand All @@ -506,7 +506,7 @@ func TestHostsContainer(t *testing.T) {
Value: net.ParseIP("::31"),
}},
name: "issue_4216_6",
req: urlfilter.DNSRequest{
req: &urlfilter.DNSRequest{
Hostname: "domain6",
DNSType: dns.TypeAAAA,
},
Expand Down
5 changes: 5 additions & 0 deletions internal/aghnet/net_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package aghnet

import (
"io/fs"
"net"
"os"
"testing"

"github.com/AdguardTeam/AdGuardHome/internal/aghtest"
Expand All @@ -15,6 +17,9 @@ func TestMain(m *testing.M) {
aghtest.DiscardLogOutput(m)
}

// testdata is the filesystem containing data for testing the package.
var testdata fs.FS = os.DirFS("./testdata")

func TestGetInterfaceByIP(t *testing.T) {
ifaces, err := GetValidNetInterfacesForWeb()
require.NoError(t, err)
Expand Down
16 changes: 8 additions & 8 deletions internal/dnsforward/clientid.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func clientIDFromClientServerName(
return "", err
}

return clientID, nil
return strings.ToLower(clientID), nil
}

// clientIDFromDNSContextHTTPS extracts the client's ID from the path of the
Expand Down Expand Up @@ -104,16 +104,16 @@ func clientIDFromDNSContextHTTPS(pctx *proxy.DNSContext) (clientID string, err e
return "", fmt.Errorf("clientid check: %w", err)
}

return clientID, nil
return strings.ToLower(clientID), nil
}

// tlsConn is a narrow interface for *tls.Conn to simplify testing.
type tlsConn interface {
ConnectionState() (cs tls.ConnectionState)
}

// quicSession is a narrow interface for quic.Session to simplify testing.
type quicSession interface {
// quicConnection is a narrow interface for quic.Connection to simplify testing.
type quicConnection interface {
ConnectionState() (cs quic.ConnectionState)
}

Expand Down Expand Up @@ -148,16 +148,16 @@ func (s *Server) clientIDFromDNSContext(pctx *proxy.DNSContext) (clientID string

cliSrvName = tc.ConnectionState().ServerName
case proxy.ProtoQUIC:
qs, ok := pctx.QUICSession.(quicSession)
conn, ok := pctx.QUICConnection.(quicConnection)
if !ok {
return "", fmt.Errorf(
"proxy ctx quic session of proto %s is %T, want quic.Session",
"proxy ctx quic conn of proto %s is %T, want quic.Connection",
proto,
pctx.QUICSession,
pctx.QUICConnection,
)
}

cliSrvName = qs.ConnectionState().TLS.ServerName
cliSrvName = conn.ConnectionState().TLS.ServerName
}

clientID, err = clientIDFromClientServerName(
Expand Down
Loading

0 comments on commit 9d75f72

Please sign in to comment.