From a869ec4cbb98301e799627a09c2e1902e57aab03 Mon Sep 17 00:00:00 2001 From: Simon Zolin Date: Wed, 10 Jun 2020 15:33:23 +0300 Subject: [PATCH] * 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 Date: Wed Jun 10 15:24:15 2020 +0300 Merge remote-tracking branch 'origin/master' into update-dnsproxy commit 501a4e06ab350e46ff78656141d925de9f2e4996 Author: Simon Zolin Date: Fri Jun 5 12:47:13 2020 +0300 openapi commit 3930bd196572924f164ed011629356a0ac0ec631 Author: Simon Zolin 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 --- AGHTechDoc.md | 6 ++---- dnsforward/config.go | 9 +++++++-- dnsforward/dnsforward_http.go | 33 ++++++++++++++++++++++++--------- go.mod | 2 +- go.sum | 4 ++-- openapi/openapi.yaml | 11 +++++------ 6 files changed, 41 insertions(+), 24 deletions(-) diff --git a/AGHTechDoc.md b/AGHTechDoc.md index 5a3b001c..61013995 100644 --- a/AGHTechDoc.md +++ b/AGHTechDoc.md @@ -893,8 +893,7 @@ Response: "edns_cs_enabled": true | false, "dnssec_enabled": true | false "disable_ipv6": true | false, - "fastest_addr": true | false, // use Fastest Address algorithm - "parallel_requests": true | false, // send DNS requests to all upstream servers at once + "upstream_mode": "" | "parallel" | "fastest_addr" } @@ -916,8 +915,7 @@ Request: "edns_cs_enabled": true | false, "dnssec_enabled": true | false "disable_ipv6": true | false, - "fastest_addr": true | false, // use Fastest Address algorithm - "parallel_requests": true | false, // send DNS requests to all upstream servers at once + "upstream_mode": "" | "parallel" | "fastest_addr" } Response: diff --git a/dnsforward/config.go b/dnsforward/config.go index 1fe9dfb2..51b510ff 100644 --- a/dnsforward/config.go +++ b/dnsforward/config.go @@ -145,9 +145,14 @@ func (s *Server) createProxyConfig() (proxy.Config, error) { UpstreamConfig: s.conf.UpstreamConfig, BeforeRequestHandler: s.beforeRequestHandler, RequestHandler: s.handleDNSRequest, - AllServers: s.conf.AllServers, 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 { diff --git a/dnsforward/dnsforward_http.go b/dnsforward/dnsforward_http.go index c2c94061..cc13914d 100644 --- a/dnsforward/dnsforward_http.go +++ b/dnsforward/dnsforward_http.go @@ -33,8 +33,7 @@ type dnsConfigJSON struct { EDNSCSEnabled bool `json:"edns_cs_enabled"` DNSSECEnabled bool `json:"dnssec_enabled"` DisableIPv6 bool `json:"disable_ipv6"` - FastestAddr bool `json:"fastest_addr"` - ParallelRequests bool `json:"parallel_requests"` + UpstreamMode string `json:"upstream_mode"` } 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.DNSSECEnabled = s.conf.EnableDNSSEC resp.DisableIPv6 = s.conf.AAAADisabled - resp.FastestAddr = s.conf.FastestAddr - resp.ParallelRequests = s.conf.AllServers + if s.conf.FastestAddr { + resp.UpstreamMode = "fastest_addr" + } else if s.conf.AllServers { + resp.UpstreamMode = "parallel" + } s.RUnlock() js, err := json.Marshal(resp) @@ -118,6 +120,12 @@ func (s *Server) handleSetConfig(w http.ResponseWriter, r *http.Request) { 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 s.Lock() @@ -169,12 +177,19 @@ func (s *Server) handleSetConfig(w http.ResponseWriter, r *http.Request) { s.conf.AAAADisabled = req.DisableIPv6 } - if js.Exists("fastest_addr") { - s.conf.FastestAddr = req.FastestAddr - } + if js.Exists("upstream_mode") { + s.conf.FastestAddr = false + s.conf.AllServers = false + switch req.UpstreamMode { + case "": + // - if js.Exists("parallel_requests") { - s.conf.AllServers = req.ParallelRequests + case "parallel": + s.conf.AllServers = true + + case "fastest_addr": + s.conf.FastestAddr = true + } } s.Unlock() diff --git a/go.mod b/go.mod index c5530c14..a67e8747 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/AdguardTeam/AdGuardHome go 1.14 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/urlfilter v0.10.1 github.com/NYTimes/gziphandler v1.1.1 diff --git a/go.sum b/go.sum index 4a7131a3..38971352 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,5 @@ -github.com/AdguardTeam/dnsproxy v0.28.1 h1:WkLjrUcVf/njbTLyL7bNt6e18zQjF2ZYv/HWwL9cMmU= -github.com/AdguardTeam/dnsproxy v0.28.1/go.mod h1:hOYFV9TW+pd5XKYz7KZf2FFD8SvSPqjyGTxUae86s58= +github.com/AdguardTeam/dnsproxy v0.29.0 h1:cHurldpiipPBAH+kgytcg9pkeYjG43KWiVYPbN3rAw4= +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/go.mod h1:skKsDKIBB7kkFflLJBpfGX+G8QFTx0WKUzB6TIgtUj4= github.com/AdguardTeam/golibs v0.4.2 h1:7M28oTZFoFwNmp8eGPb3ImmYbxGaJLyQXeIFVHjME0o= diff --git a/openapi/openapi.yaml b/openapi/openapi.yaml index 304c8dc5..a4066b7e 100644 --- a/openapi/openapi.yaml +++ b/openapi/openapi.yaml @@ -1019,12 +1019,11 @@ components: type: boolean dnssec_enabled: type: boolean - fastest_addr: - type: boolean - parallel_requests: - type: boolean - description: If true, parallel queries to all configured upstream servers are - enabled + upstream_mode: + enum: + - "" + - parallel + - fastest_addr UpstreamsConfig: type: object description: Upstreams configuration