* dns: fail on starting DNS server if upstream servers configuration is incorrect

This commit is contained in:
Simon Zolin 2019-06-25 15:24:37 +03:00
parent 5abf0b5a53
commit dc43ad9910
1 changed files with 13 additions and 7 deletions

View File

@ -171,7 +171,7 @@ func onDNSRequest(d *proxy.DNSContext) {
} }
} }
func generateServerConfig() dnsforward.ServerConfig { func generateServerConfig() (dnsforward.ServerConfig, error) {
filters := []dnsfilter.Filter{} filters := []dnsfilter.Filter{}
userFilter := userFilter() userFilter := userFilter()
filters = append(filters, dnsfilter.Filter{ filters = append(filters, dnsfilter.Filter{
@ -206,14 +206,14 @@ func generateServerConfig() dnsforward.ServerConfig {
upstreamConfig, err := proxy.ParseUpstreamsConfig(config.DNS.UpstreamDNS, config.DNS.BootstrapDNS, dnsforward.DefaultTimeout) upstreamConfig, err := proxy.ParseUpstreamsConfig(config.DNS.UpstreamDNS, config.DNS.BootstrapDNS, dnsforward.DefaultTimeout)
if err != nil { if err != nil {
log.Error("Couldn't get upstreams configuration cause: %s", err) return newconfig, fmt.Errorf("Couldn't get upstreams configuration cause: %s", err)
} }
newconfig.Upstreams = upstreamConfig.Upstreams newconfig.Upstreams = upstreamConfig.Upstreams
newconfig.DomainsReservedUpstreams = upstreamConfig.DomainReservedUpstreams newconfig.DomainsReservedUpstreams = upstreamConfig.DomainReservedUpstreams
newconfig.AllServers = config.DNS.AllServers newconfig.AllServers = config.DNS.AllServers
newconfig.FilterHandler = applyClientSettings newconfig.FilterHandler = applyClientSettings
newconfig.OnDNSRequest = onDNSRequest newconfig.OnDNSRequest = onDNSRequest
return newconfig return newconfig, nil
} }
// If a client has his own settings, apply them // If a client has his own settings, apply them
@ -235,8 +235,11 @@ func startDNSServer() error {
return fmt.Errorf("unable to start forwarding DNS server: Already running") return fmt.Errorf("unable to start forwarding DNS server: Already running")
} }
newconfig := generateServerConfig() newconfig, err := generateServerConfig()
err := dnsServer.Start(&newconfig) if err != nil {
return errorx.Decorate(err, "Couldn't start forwarding DNS server")
}
err = dnsServer.Start(&newconfig)
if err != nil { if err != nil {
return errorx.Decorate(err, "Couldn't start forwarding DNS server") return errorx.Decorate(err, "Couldn't start forwarding DNS server")
} }
@ -254,8 +257,11 @@ func reconfigureDNSServer() error {
return fmt.Errorf("Refusing to reconfigure forwarding DNS server: not running") return fmt.Errorf("Refusing to reconfigure forwarding DNS server: not running")
} }
config := generateServerConfig() config, err := generateServerConfig()
err := dnsServer.Reconfigure(&config) if err != nil {
return errorx.Decorate(err, "Couldn't start forwarding DNS server")
}
err = dnsServer.Reconfigure(&config)
if err != nil { if err != nil {
return errorx.Decorate(err, "Couldn't start forwarding DNS server") return errorx.Decorate(err, "Couldn't start forwarding DNS server")
} }