[change] control: Fix issues from review
This commit is contained in:
parent
acb4a98466
commit
a8812908c1
35
control.go
35
control.go
|
@ -322,44 +322,31 @@ func handleSetUpstreamConfig(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
setDNSServers(newconfig.upstreams, true)
|
config.DNS.UpstreamDNS = defaultDNS
|
||||||
setDNSServers(newconfig.bootstrapDNS, false)
|
if len(newconfig.upstreams) > 0 {
|
||||||
config.DNS.AllServers = newconfig.allServers
|
config.DNS.UpstreamDNS = newconfig.upstreams
|
||||||
httpUpdateConfigReloadDNSReturnOK(w, r)
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// setDNSServers sets upstream and bootstrap DNS servers
|
|
||||||
func setDNSServers(hosts []string, upstreams bool) {
|
|
||||||
// bootstrap servers are plain DNS only. We should remove tls:// https:// and sdns:// hosts from slice
|
// bootstrap servers are plain DNS only. We should remove tls:// https:// and sdns:// hosts from slice
|
||||||
bootstraps := []string{}
|
bootstraps := []string{}
|
||||||
if !upstreams && len(hosts) > 0 {
|
if len(newconfig.bootstrapDNS) > 0 {
|
||||||
for _, host := range hosts {
|
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)
|
log.Tracef("%s can not be used as bootstrap DNS cause: %s", host, err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
hosts = append(bootstraps, host)
|
bootstraps = append(bootstraps, host)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// count of upstream or bootstrap servers
|
|
||||||
count := len(hosts)
|
|
||||||
if !upstreams {
|
|
||||||
count = len(bootstraps)
|
|
||||||
}
|
|
||||||
|
|
||||||
if upstreams {
|
|
||||||
config.DNS.UpstreamDNS = defaultDNS
|
|
||||||
if count != 0 {
|
|
||||||
config.DNS.UpstreamDNS = hosts
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
config.DNS.BootstrapDNS = defaultBootstrap
|
config.DNS.BootstrapDNS = defaultBootstrap
|
||||||
if count != 0 {
|
if len(bootstraps) > 0 {
|
||||||
config.DNS.BootstrapDNS = bootstraps
|
config.DNS.BootstrapDNS = bootstraps
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
config.DNS.AllServers = newconfig.allServers
|
||||||
|
httpUpdateConfigReloadDNSReturnOK(w, r)
|
||||||
}
|
}
|
||||||
|
|
||||||
// checkBootstrapDNS checks if host is plain DNS
|
// checkBootstrapDNS checks if host is plain DNS
|
||||||
|
|
Loading…
Reference in New Issue