* dns: fail on starting DNS server if upstream servers configuration is incorrect
This commit is contained in:
parent
5abf0b5a53
commit
dc43ad9910
20
home/dns.go
20
home/dns.go
|
@ -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")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue