Pull request: all: custom autohost tlds
Updates #2393. Squashed commit of the following: commit 87034134e240480938cdeec14d6b44294bf6442c Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Thu Mar 25 15:48:46 2021 +0300 dnsforward: fix commit abf3a1ce8ed7a148d1cc631007fb0422f6da4ae6 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Thu Mar 25 15:21:11 2021 +0300 dnsforward: imp code, validation commit fac389bdafc093ce17a7e0831166b89293b550be Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Thu Mar 25 14:54:45 2021 +0300 all: add validation, imp docs, tests commit 21b4532afe59f3b89383cb330c9a7d49ec124b6e Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed Mar 24 19:09:43 2021 +0300 all: custom autohost tlds
This commit is contained in:
@@ -93,6 +93,11 @@ 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"`
|
||||
|
||||
// AutohostTLD is the top-level domain used for known internal hosts.
|
||||
// For example, a machine called "myhost" can be addressed as
|
||||
// "myhost.lan" when AutohostTLD is "lan".
|
||||
AutohostTLD string `yaml:"autohost_tld"`
|
||||
}
|
||||
|
||||
type tlsConfigSettings struct {
|
||||
@@ -144,6 +149,7 @@ var config = configuration{
|
||||
},
|
||||
FilteringEnabled: true, // whether or not use filter lists
|
||||
FiltersUpdateIntervalHours: 24,
|
||||
AutohostTLD: "lan",
|
||||
},
|
||||
TLS: tlsConfigSettings{
|
||||
PortHTTPS: 443,
|
||||
|
||||
@@ -61,18 +61,27 @@ func initDNSServer() error {
|
||||
Context.dnsFilter = dnsfilter.New(&filterConf, nil)
|
||||
|
||||
p := dnsforward.DNSCreateParams{
|
||||
DNSFilter: Context.dnsFilter,
|
||||
Stats: Context.stats,
|
||||
QueryLog: Context.queryLog,
|
||||
DNSFilter: Context.dnsFilter,
|
||||
Stats: Context.stats,
|
||||
QueryLog: Context.queryLog,
|
||||
AutohostTLD: config.DNS.AutohostTLD,
|
||||
}
|
||||
if Context.dhcpServer != nil {
|
||||
p.DHCPServer = Context.dhcpServer
|
||||
}
|
||||
Context.dnsServer = dnsforward.NewServer(p)
|
||||
|
||||
Context.dnsServer, err = dnsforward.NewServer(p)
|
||||
if err != nil {
|
||||
closeDNSServer()
|
||||
|
||||
return fmt.Errorf("dnsforward.NewServer: %w", err)
|
||||
}
|
||||
|
||||
Context.clients.dnsServer = Context.dnsServer
|
||||
dnsConfig, err := generateServerConfig()
|
||||
if err != nil {
|
||||
closeDNSServer()
|
||||
|
||||
return fmt.Errorf("generateServerConfig: %w", err)
|
||||
}
|
||||
|
||||
|
||||
@@ -6,15 +6,23 @@ import (
|
||||
|
||||
"github.com/AdguardTeam/AdGuardHome/internal/dnsforward"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func prepareTestDNSServer() error {
|
||||
func prepareTestDNSServer(t *testing.T) {
|
||||
t.Helper()
|
||||
|
||||
config.DNS.Port = 1234
|
||||
Context.dnsServer = dnsforward.NewServer(dnsforward.DNSCreateParams{})
|
||||
|
||||
var err error
|
||||
Context.dnsServer, err = dnsforward.NewServer(dnsforward.DNSCreateParams{})
|
||||
require.NoError(t, err)
|
||||
|
||||
conf := &dnsforward.ServerConfig{}
|
||||
conf.UpstreamDNS = []string{"8.8.8.8"}
|
||||
|
||||
return Context.dnsServer.Prepare(conf)
|
||||
err = Context.dnsServer.Prepare(conf)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
// TODO(e.burkov): It's kind of complicated to get rid of network access in this
|
||||
@@ -22,12 +30,15 @@ func prepareTestDNSServer() error {
|
||||
// the server, so it becomes hard to simulate handling of request from test even
|
||||
// with substituted upstream. However, it must be done.
|
||||
func TestWhois(t *testing.T) {
|
||||
assert.Nil(t, prepareTestDNSServer())
|
||||
prepareTestDNSServer(t)
|
||||
|
||||
w := Whois{timeoutMsec: 5000}
|
||||
resp, err := w.queryAll(context.Background(), "8.8.8.8")
|
||||
assert.Nil(t, err)
|
||||
assert.NoError(t, err)
|
||||
|
||||
m := whoisParse(resp)
|
||||
require.NotEmpty(t, m)
|
||||
|
||||
assert.Equal(t, "Google LLC", m["orgname"])
|
||||
assert.Equal(t, "US", m["country"])
|
||||
assert.Equal(t, "Mountain View", m["city"])
|
||||
|
||||
Reference in New Issue
Block a user