diff --git a/AGHTechDoc.md b/AGHTechDoc.md index 5a3b001c958..61013995941 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 1fe9dfb263c..51b510ff9d4 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 c2c94061f25..cc13914d824 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 "": + // + + case "parallel": + s.conf.AllServers = true - if js.Exists("parallel_requests") { - s.conf.AllServers = req.ParallelRequests + case "fastest_addr": + s.conf.FastestAddr = true + } } s.Unlock() diff --git a/go.mod b/go.mod index c5530c142b0..a67e87474a7 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 4a7131a3c61..38971352c10 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 304c8dc59aa..a4066b7eff3 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