Skip to content
Commits on Source (1)
  • Dimitry Kolyshev's avatar
    Pull request: proxy: wildcard default · 72d1f052
    Dimitry Kolyshev authored
    Merge in DNS/dnsproxy from 4503-upstream-conf-1 to master
    
    Squashed commit of the following:
    
    commit 959fc034
    Author: Dimitry Kolyshev <dkolyshev@adguard.com>
    Date:   Wed May 18 13:17:32 2022 +0200
    
        proxy: imp code
    
    commit 43f458b0
    Author: Dimitry Kolyshev <dkolyshev@adguard.com>
    Date:   Wed May 18 11:46:48 2022 +0200
    
        proxy: imp code
    
    commit bfec0ac0
    Author: Dimitry Kolyshev <dkolyshev@adguard.com>
    Date:   Tue May 17 12:52:27 2022 +0200
    
        proxy: wildcard default
    72d1f052
......@@ -58,8 +58,15 @@ func ParseUpstreamsConfig(upstreamConfig []string, options *upstream.Options) (*
// # excludes more specific domain from reserved upstreams querying
if u == "#" && len(hosts) > 0 {
for _, host := range hosts {
domainReservedUpstreams[host] = nil
specifiedDomainUpstreams[host] = nil
if strings.HasPrefix(host, "*.") {
host = host[len("*."):]
subdomainsOnlyExclusions.Add(host)
subdomainsOnlyUpstreams[host] = nil
} else {
domainReservedUpstreams[host] = nil
specifiedDomainUpstreams[host] = nil
}
}
} else {
dnsUpstream, ok := upstreamsIndex[u]
......
......@@ -158,6 +158,47 @@ func TestGetUpstreamsForDomain_sub_wildcards(t *testing.T) {
}
}
func TestGetUpstreamsForDomain_default_wildcards(t *testing.T) {
conf := []string{
"127.0.0.1:5301",
"[/example.org/]127.0.0.1:5302",
"[/*.example.org/]127.0.0.1:5303",
"[/www.example.org/]127.0.0.1:5304",
"[/*.www.example.org/]#",
}
uconf, err := ParseUpstreamsConfig(conf, nil)
require.NoError(t, err)
testCases := []struct {
name string
in string
want []string
}{{
name: "domain",
in: "example.org.",
want: []string{"127.0.0.1:5302"},
}, {
name: "sub_wildcard",
in: "sub.example.org.",
want: []string{"127.0.0.1:5303"},
}, {
name: "spec_sub",
in: "www.example.org.",
want: []string{"127.0.0.1:5304"},
}, {
name: "def_wildcard",
in: "abc.www.example.org.",
want: []string{"127.0.0.1:5301"},
}}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
assertUpstreamsForDomain(t, uconf, tc.in, tc.want)
})
}
}
func BenchmarkGetUpstreamsForDomain(b *testing.B) {
upstreams := []string{
"[/google.com/local/]4.3.2.1",
......