[change] config, control, openapi: fix issues from reviw
This commit is contained in:
parent
ceaa1e4ebf
commit
f2e547a54e
|
@ -60,7 +60,7 @@ type dnsConfig struct {
|
||||||
UpstreamDNS []string `yaml:"upstream_dns"`
|
UpstreamDNS []string `yaml:"upstream_dns"`
|
||||||
}
|
}
|
||||||
|
|
||||||
var defaultDNS = []string{"tls://1.1.1.1", "tls://1.0.0.1"}
|
var defaultDNS = []string{"https://dns.adguard.com/dns-query", "https://dns.cloudflare.com/dns-query"}
|
||||||
var defaultBootstrap = []string{"1.1.1.1"}
|
var defaultBootstrap = []string{"1.1.1.1"}
|
||||||
|
|
||||||
type tlsConfigSettings struct {
|
type tlsConfigSettings struct {
|
||||||
|
|
30
control.go
30
control.go
|
@ -327,20 +327,18 @@ func handleSetUpstreamConfig(w http.ResponseWriter, r *http.Request) {
|
||||||
config.DNS.UpstreamDNS = newconfig.Upstreams
|
config.DNS.UpstreamDNS = newconfig.Upstreams
|
||||||
}
|
}
|
||||||
|
|
||||||
// bootstrap servers are plain DNS only. We should remove tls:// https:// and sdns:// hosts from slice
|
// bootstrap servers are plain DNS only. We should return http error if there are tls:// https:// or sdns:// hosts in slice
|
||||||
bootstraps := []string{}
|
|
||||||
for _, host := range newconfig.BootstrapDNS {
|
for _, host := range newconfig.BootstrapDNS {
|
||||||
err := checkBootstrapDNS(host)
|
err := checkBootstrapDNS(host)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Tracef("%s can not be used as bootstrap DNS cause: %s", host, err)
|
httpError(w, http.StatusBadRequest, "%s can not be used as bootstrap dns cause: %s", host, err)
|
||||||
continue
|
return
|
||||||
}
|
}
|
||||||
bootstraps = append(bootstraps, host)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
config.DNS.BootstrapDNS = defaultBootstrap
|
config.DNS.BootstrapDNS = defaultBootstrap
|
||||||
if len(bootstraps) > 0 {
|
if len(newconfig.BootstrapDNS) > 0 {
|
||||||
config.DNS.BootstrapDNS = bootstraps
|
config.DNS.BootstrapDNS = newconfig.BootstrapDNS
|
||||||
}
|
}
|
||||||
|
|
||||||
config.DNS.AllServers = newconfig.AllServers
|
config.DNS.AllServers = newconfig.AllServers
|
||||||
|
@ -361,22 +359,22 @@ func checkBootstrapDNS(host string) error {
|
||||||
|
|
||||||
func handleTestUpstreamDNS(w http.ResponseWriter, r *http.Request) {
|
func handleTestUpstreamDNS(w http.ResponseWriter, r *http.Request) {
|
||||||
log.Tracef("%s %v", r.Method, r.URL)
|
log.Tracef("%s %v", r.Method, r.URL)
|
||||||
hosts := []string{}
|
upstreamConfig := upstreamConfig{}
|
||||||
err := json.NewDecoder(r.Body).Decode(&hosts)
|
err := json.NewDecoder(r.Body).Decode(&upstreamConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
httpError(w, http.StatusBadRequest, "Failed to read request body: %s", err)
|
httpError(w, http.StatusBadRequest, "Failed to read request body: %s", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(hosts) == 0 {
|
if len(upstreamConfig.Upstreams) == 0 {
|
||||||
httpError(w, http.StatusBadRequest, "No servers specified")
|
httpError(w, http.StatusBadRequest, "No servers specified")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
result := map[string]string{}
|
result := map[string]string{}
|
||||||
|
|
||||||
for _, host := range hosts {
|
for _, host := range upstreamConfig.Upstreams {
|
||||||
err = checkDNS(host)
|
err = checkDNS(host, upstreamConfig.BootstrapDNS)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Info("%v", err)
|
log.Info("%v", err)
|
||||||
result[host] = err.Error()
|
result[host] = err.Error()
|
||||||
|
@ -398,9 +396,13 @@ func handleTestUpstreamDNS(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func checkDNS(input string) error {
|
func checkDNS(input string, bootstrap []string) error {
|
||||||
|
if len(bootstrap) == 0 {
|
||||||
|
bootstrap = defaultBootstrap
|
||||||
|
}
|
||||||
|
|
||||||
log.Debug("Checking if DNS %s works...", input)
|
log.Debug("Checking if DNS %s works...", input)
|
||||||
u, err := upstream.AddressToUpstream(input, upstream.Options{Timeout: dnsforward.DefaultTimeout})
|
u, err := upstream.AddressToUpstream(input, upstream.Options{Bootstrap: bootstrap, Timeout: dnsforward.DefaultTimeout})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to choose upstream for %s: %s", input, err)
|
return fmt.Errorf("failed to choose upstream for %s: %s", input, err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -111,15 +111,15 @@ paths:
|
||||||
tags:
|
tags:
|
||||||
- global
|
- global
|
||||||
operationId: testUpstreamDNS
|
operationId: testUpstreamDNS
|
||||||
summary: "Test upstream DNS"
|
summary: "Test upstream configuration"
|
||||||
consumes:
|
consumes:
|
||||||
- application/json
|
- application/json
|
||||||
parameters:
|
parameters:
|
||||||
- in: "body"
|
- in: "body"
|
||||||
name: "body"
|
name: "body"
|
||||||
description: "Upstream servers to be tested"
|
description: "Upstream configuration to be tested"
|
||||||
schema:
|
schema:
|
||||||
$ref: "#/definitions/TestUpstreams"
|
$ref: "#/definitions/UpstreamsConfig"
|
||||||
responses:
|
responses:
|
||||||
200:
|
200:
|
||||||
description: 'Status of testing each requested server, with "OK" meaning that server works, any other text means an error.'
|
description: 'Status of testing each requested server, with "OK" meaning that server works, any other text means an error.'
|
||||||
|
@ -814,20 +814,6 @@ definitions:
|
||||||
all_servers:
|
all_servers:
|
||||||
type: "boolean"
|
type: "boolean"
|
||||||
description: "If true, parallel queries to all configured upstream servers are enabled"
|
description: "If true, parallel queries to all configured upstream servers are enabled"
|
||||||
TestUpstreams:
|
|
||||||
type: "object"
|
|
||||||
description: "Upstream servers to be tested"
|
|
||||||
required:
|
|
||||||
- "upstream_dns"
|
|
||||||
properties:
|
|
||||||
upstream_dns:
|
|
||||||
type: "array"
|
|
||||||
description: 'Upstream servers, port is optional after colon'
|
|
||||||
items:
|
|
||||||
type: "string"
|
|
||||||
example:
|
|
||||||
- "tls://1.1.1.1"
|
|
||||||
- "tls://1.0.0.1"
|
|
||||||
Filter:
|
Filter:
|
||||||
type: "object"
|
type: "object"
|
||||||
description: "Filter subscription info"
|
description: "Filter subscription info"
|
||||||
|
|
Loading…
Reference in New Issue