* DNS API: new setting "upstream_mode"; remove "fastest_addr", "parallel_requests"

* use dnsproxy v0.29.0

Squashed commit of the following:

commit f18b7231f3f3f84446c0d837855af342f3c971b4
Merge: 501a4e06 dae275e6
Author: Simon Zolin <s.zolin@adguard.com>
Date:   Wed Jun 10 15:24:15 2020 +0300

    Merge remote-tracking branch 'origin/master' into update-dnsproxy

commit 501a4e06ab350e46ff78656141d925de9f2e4996
Author: Simon Zolin <s.zolin@adguard.com>
Date:   Fri Jun 5 12:47:13 2020 +0300

    openapi

commit 3930bd196572924f164ed011629356a0ac0ec631
Author: Simon Zolin <s.zolin@adguard.com>
Date:   Fri Jun 5 12:21:32 2020 +0300

    * DNS API: new setting "upstream_mode"; remove "fastest_addr", "parallel_requests"

    * use dnsproxy v0.29.0
This commit is contained in:
Simon Zolin 2020-06-10 15:33:23 +03:00
parent dae275e6f9
commit a869ec4cbb
6 changed files with 41 additions and 24 deletions

View File

@ -893,8 +893,7 @@ Response:
"edns_cs_enabled": true | false, "edns_cs_enabled": true | false,
"dnssec_enabled": true | false "dnssec_enabled": true | false
"disable_ipv6": true | false, "disable_ipv6": true | false,
"fastest_addr": true | false, // use Fastest Address algorithm "upstream_mode": "" | "parallel" | "fastest_addr"
"parallel_requests": true | false, // send DNS requests to all upstream servers at once
} }
@ -916,8 +915,7 @@ Request:
"edns_cs_enabled": true | false, "edns_cs_enabled": true | false,
"dnssec_enabled": true | false "dnssec_enabled": true | false
"disable_ipv6": true | false, "disable_ipv6": true | false,
"fastest_addr": true | false, // use Fastest Address algorithm "upstream_mode": "" | "parallel" | "fastest_addr"
"parallel_requests": true | false, // send DNS requests to all upstream servers at once
} }
Response: Response:

View File

@ -145,9 +145,14 @@ func (s *Server) createProxyConfig() (proxy.Config, error) {
UpstreamConfig: s.conf.UpstreamConfig, UpstreamConfig: s.conf.UpstreamConfig,
BeforeRequestHandler: s.beforeRequestHandler, BeforeRequestHandler: s.beforeRequestHandler,
RequestHandler: s.handleDNSRequest, RequestHandler: s.handleDNSRequest,
AllServers: s.conf.AllServers,
EnableEDNSClientSubnet: s.conf.EnableEDNSClientSubnet, EnableEDNSClientSubnet: s.conf.EnableEDNSClientSubnet,
FindFastestAddr: s.conf.FastestAddr, }
proxyConfig.UpstreamMode = proxy.UModeLoadBalance
if s.conf.AllServers {
proxyConfig.UpstreamMode = proxy.UModeParallel
} else if s.conf.FastestAddr {
proxyConfig.UpstreamMode = proxy.UModeFastestAddr
} }
if len(s.conf.BogusNXDomain) > 0 { if len(s.conf.BogusNXDomain) > 0 {

View File

@ -33,8 +33,7 @@ type dnsConfigJSON struct {
EDNSCSEnabled bool `json:"edns_cs_enabled"` EDNSCSEnabled bool `json:"edns_cs_enabled"`
DNSSECEnabled bool `json:"dnssec_enabled"` DNSSECEnabled bool `json:"dnssec_enabled"`
DisableIPv6 bool `json:"disable_ipv6"` DisableIPv6 bool `json:"disable_ipv6"`
FastestAddr bool `json:"fastest_addr"` UpstreamMode string `json:"upstream_mode"`
ParallelRequests bool `json:"parallel_requests"`
} }
func (s *Server) handleGetConfig(w http.ResponseWriter, r *http.Request) { func (s *Server) handleGetConfig(w http.ResponseWriter, r *http.Request) {
@ -51,8 +50,11 @@ func (s *Server) handleGetConfig(w http.ResponseWriter, r *http.Request) {
resp.EDNSCSEnabled = s.conf.EnableEDNSClientSubnet resp.EDNSCSEnabled = s.conf.EnableEDNSClientSubnet
resp.DNSSECEnabled = s.conf.EnableDNSSEC resp.DNSSECEnabled = s.conf.EnableDNSSEC
resp.DisableIPv6 = s.conf.AAAADisabled resp.DisableIPv6 = s.conf.AAAADisabled
resp.FastestAddr = s.conf.FastestAddr if s.conf.FastestAddr {
resp.ParallelRequests = s.conf.AllServers resp.UpstreamMode = "fastest_addr"
} else if s.conf.AllServers {
resp.UpstreamMode = "parallel"
}
s.RUnlock() s.RUnlock()
js, err := json.Marshal(resp) js, err := json.Marshal(resp)
@ -118,6 +120,12 @@ func (s *Server) handleSetConfig(w http.ResponseWriter, r *http.Request) {
return return
} }
if js.Exists("upstream_mode") &&
!(req.UpstreamMode == "" || req.UpstreamMode == "fastest_addr" || req.UpstreamMode == "parallel") {
httpError(r, w, http.StatusBadRequest, "upstream_mode: incorrect value")
return
}
restart := false restart := false
s.Lock() s.Lock()
@ -169,12 +177,19 @@ func (s *Server) handleSetConfig(w http.ResponseWriter, r *http.Request) {
s.conf.AAAADisabled = req.DisableIPv6 s.conf.AAAADisabled = req.DisableIPv6
} }
if js.Exists("fastest_addr") { if js.Exists("upstream_mode") {
s.conf.FastestAddr = req.FastestAddr s.conf.FastestAddr = false
} s.conf.AllServers = false
switch req.UpstreamMode {
case "":
//
if js.Exists("parallel_requests") { case "parallel":
s.conf.AllServers = req.ParallelRequests s.conf.AllServers = true
case "fastest_addr":
s.conf.FastestAddr = true
}
} }
s.Unlock() s.Unlock()

2
go.mod
View File

@ -3,7 +3,7 @@ module github.com/AdguardTeam/AdGuardHome
go 1.14 go 1.14
require ( require (
github.com/AdguardTeam/dnsproxy v0.28.1 github.com/AdguardTeam/dnsproxy v0.29.0
github.com/AdguardTeam/golibs v0.4.2 github.com/AdguardTeam/golibs v0.4.2
github.com/AdguardTeam/urlfilter v0.10.1 github.com/AdguardTeam/urlfilter v0.10.1
github.com/NYTimes/gziphandler v1.1.1 github.com/NYTimes/gziphandler v1.1.1

4
go.sum
View File

@ -1,5 +1,5 @@
github.com/AdguardTeam/dnsproxy v0.28.1 h1:WkLjrUcVf/njbTLyL7bNt6e18zQjF2ZYv/HWwL9cMmU= github.com/AdguardTeam/dnsproxy v0.29.0 h1:cHurldpiipPBAH+kgytcg9pkeYjG43KWiVYPbN3rAw4=
github.com/AdguardTeam/dnsproxy v0.28.1/go.mod h1:hOYFV9TW+pd5XKYz7KZf2FFD8SvSPqjyGTxUae86s58= github.com/AdguardTeam/dnsproxy v0.29.0/go.mod h1:hOYFV9TW+pd5XKYz7KZf2FFD8SvSPqjyGTxUae86s58=
github.com/AdguardTeam/golibs v0.4.0 h1:4VX6LoOqFe9p9Gf55BeD8BvJD6M6RDYmgEiHrENE9KU= github.com/AdguardTeam/golibs v0.4.0 h1:4VX6LoOqFe9p9Gf55BeD8BvJD6M6RDYmgEiHrENE9KU=
github.com/AdguardTeam/golibs v0.4.0/go.mod h1:skKsDKIBB7kkFflLJBpfGX+G8QFTx0WKUzB6TIgtUj4= github.com/AdguardTeam/golibs v0.4.0/go.mod h1:skKsDKIBB7kkFflLJBpfGX+G8QFTx0WKUzB6TIgtUj4=
github.com/AdguardTeam/golibs v0.4.2 h1:7M28oTZFoFwNmp8eGPb3ImmYbxGaJLyQXeIFVHjME0o= github.com/AdguardTeam/golibs v0.4.2 h1:7M28oTZFoFwNmp8eGPb3ImmYbxGaJLyQXeIFVHjME0o=

View File

@ -1019,12 +1019,11 @@ components:
type: boolean type: boolean
dnssec_enabled: dnssec_enabled:
type: boolean type: boolean
fastest_addr: upstream_mode:
type: boolean enum:
parallel_requests: - ""
type: boolean - parallel
description: If true, parallel queries to all configured upstream servers are - fastest_addr
enabled
UpstreamsConfig: UpstreamsConfig:
type: object type: object
description: Upstreams configuration description: Upstreams configuration