Skip to content

Commit

Permalink
* DNS API: new setting "upstream_mode"; remove "fastest_addr", "paral…
Browse files Browse the repository at this point in the history
…lel_requests"

* use dnsproxy v0.29.0

Squashed commit of the following:

commit f18b723
Merge: 501a4e0 dae275e
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 501a4e0
Author: Simon Zolin <s.zolin@adguard.com>
Date:   Fri Jun 5 12:47:13 2020 +0300

    openapi

commit 3930bd1
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
  • Loading branch information
szolin committed Jun 10, 2020
1 parent dae275e commit a869ec4
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 24 deletions.
6 changes: 2 additions & 4 deletions AGHTechDoc.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}


Expand All @@ -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:
Expand Down
9 changes: 7 additions & 2 deletions dnsforward/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
33 changes: 24 additions & 9 deletions dnsforward/dnsforward_http.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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)
Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -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=
Expand Down
11 changes: 5 additions & 6 deletions openapi/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a869ec4

Please sign in to comment.