Skip to content

Commit

Permalink
Pull request 349: 6744 Fix TLD subdomain
Browse files Browse the repository at this point in the history
Updates AdguardTeam/AdGuardHome#6744.

Squashed commit of the following:

commit d0fe7b6
Author: Eugene Burkov <[email protected]>
Date:   Thu May 2 15:55:50 2024 +0300

    all: imp doc

commit ecc7243
Author: Eugene Burkov <[email protected]>
Date:   Thu May 2 15:18:44 2024 +0300

    proxy: imp code

commit a519594
Author: Eugene Burkov <[email protected]>
Date:   Sat Apr 27 18:12:19 2024 +0300

    all: fix tld exclusions
  • Loading branch information
EugeneOne1 committed May 2, 2024
1 parent e35720f commit 6a9f811
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 18 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -338,11 +338,12 @@ which are sent to `8.8.8.8:53` (along with other requests):
```
Sends requests for `*.host.com` to `1.1.1.1:53` except for `host.com` which is
sent to `8.8.8.8:53` (along with other requests):
sent to `9.9.9.10:53`, and all other requests are sent to `8.8.8.8:53`:
```sh
./dnsproxy\
-u "8.8.8.8:53"
-u "8.8.8.8:53"\
-u "[/host.com/]9.9.9.10:53"\
-u "[/*.host.com/]1.1.1.1:53"
```
Expand Down
17 changes: 9 additions & 8 deletions proxy/upstreams.go
Original file line number Diff line number Diff line change
Expand Up @@ -383,17 +383,18 @@ func (uc *UpstreamConfig) getUpstreamsForDomain(fqdn string) (ups []upstream.Ups
return uc.Upstreams
}

var ok bool
fqdn = strings.ToLower(fqdn)
if strings.Count(fqdn, ".") < 2 {
ups, ok = uc.lookupUpstreams(fqdn)
if ok {
return ups
}
if uc.SubdomainExclusions.Has(fqdn) {
return uc.lookupSubdomainExclusion(fqdn)
}

ups, ok := uc.lookupUpstreams(fqdn)
if ok {
return ups
}

if _, fqdn, _ = strings.Cut(fqdn, "."); fqdn == "" {
fqdn = UnqualifiedNames
} else if uc.SubdomainExclusions.Has(fqdn) {
return uc.lookupSubdomainExclusion(fqdn)
}

for fqdn != "" {
Expand Down
10 changes: 6 additions & 4 deletions proxy/upstreams_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ const (
topLevelDomain = "example"
topLevelFQDN = topLevelDomain + "."

firstLevelDomain = "name." + topLevelDomain
firstLevelFQDN = firstLevelDomain + "."
firstLevelDomain = "name." + topLevelDomain
firstLevelFQDN = firstLevelDomain + "."
wildcardFirstLevelDomain = "*." + topLevelDomain

subDomain = "sub." + firstLevelDomain
subFQDN = subDomain + "."
Expand Down Expand Up @@ -51,6 +52,7 @@ var testUpstreamConfigLines = []string{
generalUpstream,
"[//]" + unqualifiedUpstream,
"[/" + topLevelDomain + "/]" + tldUpstream,
"[/" + wildcardFirstLevelDomain + "/]#",
"[/" + firstLevelDomain + "/]" + domainUpstream,
"[/" + wildcardDomain + "/]" + wildcardUpstream,
"[/" + generalDomain + "/]#",
Expand Down Expand Up @@ -82,7 +84,7 @@ func TestUpstreamConfig_GetUpstreamsForDomain(t *testing.T) {
}, {
name: "unspecified_subdomain",
in: unspecifiedFQDN + topLevelFQDN,
want: []string{tldUpstream},
want: []string{generalUpstream},
}, {
name: "domain",
in: firstLevelFQDN,
Expand Down Expand Up @@ -136,7 +138,7 @@ func TestUpstreamConfig_GetUpstreamsForDS(t *testing.T) {
}, {
name: "unspecified_subdomain",
in: unspecifiedFQDN + topLevelFQDN,
want: []string{tldUpstream},
want: []string{generalUpstream},
}, {
name: "domain",
in: firstLevelFQDN,
Expand Down
2 changes: 1 addition & 1 deletion upstream/dnscrypt_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func startTestDNSCryptServer(

func TestUpstreamDNSCrypt(t *testing.T) {
// AdGuard DNS (DNSCrypt)
address := "sdns://AQIAAAAAAAAAFDE3Ni4xMDMuMTMwLjEzMDo1NDQzINErR_JS3PLCu_iZEIbq95zkSV2LFsigxDIuUso_OQhzIjIuZG5zY3J5cHQuZGVmYXVsdC5uczEuYWRndWFyZC5jb20"
address := "sdns://AQMAAAAAAAAAETk0LjE0MC4xNC4xNDo1NDQzINErR_JS3PLCu_iZEIbq95zkSV2LFsigxDIuUso_OQhzIjIuZG5zY3J5cHQuZGVmYXVsdC5uczEuYWRndWFyZC5jb20"
u, err := AddressToUpstream(address, &Options{Timeout: dialTimeout})
require.NoError(t, err)
testutil.CleanupAndRequireSuccess(t, u.Close)
Expand Down
2 changes: 1 addition & 1 deletion upstream/resolver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func TestNewUpstreamResolver_validity(t *testing.T) {
wantErrMsg: "",
}, {
name: "sdns",
addr: "sdns://AQIAAAAAAAAAFDE3Ni4xMDMuMTMwLjEzMDo1NDQzINErR_JS3PLCu_iZEIbq95zkSV2LFsigxDIuUso_OQhzIjIuZG5zY3J5cHQuZGVmYXVsdC5uczEuYWRndWFyZC5jb20",
addr: "sdns://AQMAAAAAAAAAETk0LjE0MC4xNC4xNDo1NDQzINErR_JS3PLCu_iZEIbq95zkSV2LFsigxDIuUso_OQhzIjIuZG5zY3J5cHQuZGVmYXVsdC5uczEuYWRndWFyZC5jb20",
wantErrMsg: "",
}, {
name: "tcp",
Expand Down
4 changes: 2 additions & 2 deletions upstream/upstream_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,11 @@ func TestUpstreams(t *testing.T) {
}, {
// AdGuard DNS (DNSCrypt)
bootstrap: nil,
address: "sdns://AQIAAAAAAAAAFDE3Ni4xMDMuMTMwLjEzMDo1NDQzINErR_JS3PLCu_iZEIbq95zkSV2LFsigxDIuUso_OQhzIjIuZG5zY3J5cHQuZGVmYXVsdC5uczEuYWRndWFyZC5jb20",
address: "sdns://AQMAAAAAAAAAETk0LjE0MC4xNC4xNDo1NDQzINErR_JS3PLCu_iZEIbq95zkSV2LFsigxDIuUso_OQhzIjIuZG5zY3J5cHQuZGVmYXVsdC5uczEuYWRndWFyZC5jb20",
}, {
// AdGuard Family (DNSCrypt)
bootstrap: googleBoot,
address: "sdns://AQIAAAAAAAAAFDE3Ni4xMDMuMTMwLjEzMjo1NDQzILgxXdexS27jIKRw3C7Wsao5jMnlhvhdRUXWuMm1AFq6ITIuZG5zY3J5cHQuZmFtaWx5Lm5zMS5hZGd1YXJkLmNvbQ",
address: "sdns://AQMAAAAAAAAAETk0LjE0MC4xNC4xNTo1NDQzILgxXdexS27jIKRw3C7Wsao5jMnlhvhdRUXWuMm1AFq6ITIuZG5zY3J5cHQuZmFtaWx5Lm5zMS5hZGd1YXJkLmNvbQ",
}, {
// Cloudflare DNS (DNS-over-HTTPS)
bootstrap: googleBoot,
Expand Down

0 comments on commit 6a9f811

Please sign in to comment.