+ DNS: "dns.upstream_dns_file" setting
This commit is contained in:
parent
07db05dd80
commit
dfab6597cd
|
@ -986,6 +986,7 @@ Response:
|
||||||
|
|
||||||
{
|
{
|
||||||
"upstream_dns": ["tls://...", ...],
|
"upstream_dns": ["tls://...", ...],
|
||||||
|
"upstream_dns_file": "",
|
||||||
"bootstrap_dns": ["1.2.3.4", ...],
|
"bootstrap_dns": ["1.2.3.4", ...],
|
||||||
|
|
||||||
"protection_enabled": true | false,
|
"protection_enabled": true | false,
|
||||||
|
@ -1011,6 +1012,7 @@ Request:
|
||||||
|
|
||||||
{
|
{
|
||||||
"upstream_dns": ["tls://...", ...],
|
"upstream_dns": ["tls://...", ...],
|
||||||
|
"upstream_dns_file": "",
|
||||||
"bootstrap_dns": ["1.2.3.4", ...],
|
"bootstrap_dns": ["1.2.3.4", ...],
|
||||||
|
|
||||||
"protection_enabled": true | false,
|
"protection_enabled": true | false,
|
||||||
|
|
|
@ -5,6 +5,7 @@ import (
|
||||||
"crypto/x509"
|
"crypto/x509"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"sort"
|
"sort"
|
||||||
|
@ -13,6 +14,7 @@ import (
|
||||||
"github.com/joomcode/errorx"
|
"github.com/joomcode/errorx"
|
||||||
|
|
||||||
"github.com/AdguardTeam/AdGuardHome/dnsfilter"
|
"github.com/AdguardTeam/AdGuardHome/dnsfilter"
|
||||||
|
"github.com/AdguardTeam/AdGuardHome/util"
|
||||||
"github.com/AdguardTeam/dnsproxy/proxy"
|
"github.com/AdguardTeam/dnsproxy/proxy"
|
||||||
"github.com/AdguardTeam/dnsproxy/upstream"
|
"github.com/AdguardTeam/dnsproxy/upstream"
|
||||||
)
|
)
|
||||||
|
@ -55,10 +57,11 @@ type FilteringConfig struct {
|
||||||
// Upstream DNS servers configuration
|
// Upstream DNS servers configuration
|
||||||
// --
|
// --
|
||||||
|
|
||||||
UpstreamDNS []string `yaml:"upstream_dns"`
|
UpstreamDNS []string `yaml:"upstream_dns"`
|
||||||
BootstrapDNS []string `yaml:"bootstrap_dns"` // a list of bootstrap DNS for DoH and DoT (plain DNS only)
|
UpstreamDNSFileName string `yaml:"upstream_dns_file"`
|
||||||
AllServers bool `yaml:"all_servers"` // if true, parallel queries to all configured upstream servers are enabled
|
BootstrapDNS []string `yaml:"bootstrap_dns"` // a list of bootstrap DNS for DoH and DoT (plain DNS only)
|
||||||
FastestAddr bool `yaml:"fastest_addr"` // use Fastest Address algorithm
|
AllServers bool `yaml:"all_servers"` // if true, parallel queries to all configured upstream servers are enabled
|
||||||
|
FastestAddr bool `yaml:"fastest_addr"` // use Fastest Address algorithm
|
||||||
|
|
||||||
// Access settings
|
// Access settings
|
||||||
// --
|
// --
|
||||||
|
@ -215,7 +218,22 @@ func (s *Server) initDefaultSettings() {
|
||||||
|
|
||||||
// prepareUpstreamSettings - prepares upstream DNS server settings
|
// prepareUpstreamSettings - prepares upstream DNS server settings
|
||||||
func (s *Server) prepareUpstreamSettings() error {
|
func (s *Server) prepareUpstreamSettings() error {
|
||||||
upstreamConfig, err := proxy.ParseUpstreamsConfig(s.conf.UpstreamDNS, s.conf.BootstrapDNS, DefaultTimeout)
|
var upstreams []string
|
||||||
|
if s.conf.UpstreamDNSFileName != "" {
|
||||||
|
data, err := ioutil.ReadFile(s.conf.UpstreamDNSFileName)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
d := string(data)
|
||||||
|
for len(d) != 0 {
|
||||||
|
s := util.SplitNext(&d, '\n')
|
||||||
|
upstreams = append(upstreams, s)
|
||||||
|
}
|
||||||
|
log.Debug("DNS: using %d upstream servers from file %s", len(upstreams), s.conf.UpstreamDNSFileName)
|
||||||
|
} else {
|
||||||
|
upstreams = s.conf.UpstreamDNS
|
||||||
|
}
|
||||||
|
upstreamConfig, err := proxy.ParseUpstreamsConfig(upstreams, s.conf.BootstrapDNS, DefaultTimeout)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("DNS: proxy.ParseUpstreamsConfig: %s", err)
|
return fmt.Errorf("DNS: proxy.ParseUpstreamsConfig: %s", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,8 +22,9 @@ func httpError(r *http.Request, w http.ResponseWriter, code int, format string,
|
||||||
}
|
}
|
||||||
|
|
||||||
type dnsConfigJSON struct {
|
type dnsConfigJSON struct {
|
||||||
Upstreams []string `json:"upstream_dns"`
|
Upstreams []string `json:"upstream_dns"`
|
||||||
Bootstraps []string `json:"bootstrap_dns"`
|
UpstreamsFile string `json:"upstream_dns_file"`
|
||||||
|
Bootstraps []string `json:"bootstrap_dns"`
|
||||||
|
|
||||||
ProtectionEnabled bool `json:"protection_enabled"`
|
ProtectionEnabled bool `json:"protection_enabled"`
|
||||||
RateLimit uint32 `json:"ratelimit"`
|
RateLimit uint32 `json:"ratelimit"`
|
||||||
|
@ -43,6 +44,7 @@ func (s *Server) handleGetConfig(w http.ResponseWriter, r *http.Request) {
|
||||||
resp := dnsConfigJSON{}
|
resp := dnsConfigJSON{}
|
||||||
s.RLock()
|
s.RLock()
|
||||||
resp.Upstreams = stringArrayDup(s.conf.UpstreamDNS)
|
resp.Upstreams = stringArrayDup(s.conf.UpstreamDNS)
|
||||||
|
resp.UpstreamsFile = s.conf.UpstreamDNSFileName
|
||||||
resp.Bootstraps = stringArrayDup(s.conf.BootstrapDNS)
|
resp.Bootstraps = stringArrayDup(s.conf.BootstrapDNS)
|
||||||
|
|
||||||
resp.ProtectionEnabled = s.conf.ProtectionEnabled
|
resp.ProtectionEnabled = s.conf.ProtectionEnabled
|
||||||
|
@ -157,6 +159,11 @@ func (s *Server) handleSetConfig(w http.ResponseWriter, r *http.Request) {
|
||||||
restart = true
|
restart = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if js.Exists("upstream_dns_file") {
|
||||||
|
s.conf.UpstreamDNSFileName = req.UpstreamsFile
|
||||||
|
restart = true
|
||||||
|
}
|
||||||
|
|
||||||
if js.Exists("bootstrap_dns") {
|
if js.Exists("bootstrap_dns") {
|
||||||
s.conf.BootstrapDNS = req.Bootstraps
|
s.conf.BootstrapDNS = req.Bootstraps
|
||||||
restart = true
|
restart = true
|
||||||
|
|
|
@ -997,6 +997,8 @@ components:
|
||||||
example:
|
example:
|
||||||
- tls://1.1.1.1
|
- tls://1.1.1.1
|
||||||
- tls://1.0.0.1
|
- tls://1.0.0.1
|
||||||
|
upstream_dns_file:
|
||||||
|
type: string
|
||||||
protection_enabled:
|
protection_enabled:
|
||||||
type: boolean
|
type: boolean
|
||||||
dhcp_available:
|
dhcp_available:
|
||||||
|
|
Loading…
Reference in New Issue