Log errors arising from reading resolv.conf
This commit is contained in:
1 parent
f8ac27a6cc
commit
7c47a8ffb7
3 files changed
+17
-9
No files matched your search
+13
-6
@@ -28,7 +28,7 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Upstream interface {
|
type Upstream interface {
|
||||||
Config() *dns.ClientConfig
|
Config() (*dns.ClientConfig, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewUpstream(resolvConf, filterAddress string) Upstream {
|
func NewUpstream(resolvConf, filterAddress string) Upstream {
|
||||||
@@ -48,27 +48,31 @@ type upstream struct {
|
|||||||
lastModified time.Time
|
lastModified time.Time
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *upstream) Config() *dns.ClientConfig {
|
func (u *upstream) Config() (*dns.ClientConfig, error) {
|
||||||
u.Lock()
|
u.Lock()
|
||||||
defer u.Unlock()
|
defer u.Unlock()
|
||||||
|
|
||||||
// If we checked less than five seconds ago return what we already have
|
// If we checked less than five seconds ago return what we already have
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
if now.Sub(u.lastStat) < 5*time.Second {
|
if now.Sub(u.lastStat) < 5*time.Second {
|
||||||
return u.cachedConfig
|
return u.cachedConfig, nil
|
||||||
}
|
}
|
||||||
u.lastStat = now
|
u.lastStat = now
|
||||||
|
|
||||||
// Reread file if it has changed
|
// Reread file if it has changed
|
||||||
if fi, err := os.Stat(u.resolvConf); err == nil && fi.ModTime() != u.lastModified {
|
if fi, err := os.Stat(u.resolvConf); err != nil {
|
||||||
|
return u.cachedConfig, err
|
||||||
|
} else if fi.ModTime() != u.lastModified {
|
||||||
if config, err := dns.ClientConfigFromFile(u.resolvConf); err == nil {
|
if config, err := dns.ClientConfigFromFile(u.resolvConf); err == nil {
|
||||||
config.Servers = filter(config.Servers, u.filterAddress)
|
config.Servers = filter(config.Servers, u.filterAddress)
|
||||||
u.lastModified = fi.ModTime()
|
u.lastModified = fi.ModTime()
|
||||||
u.cachedConfig = config
|
u.cachedConfig = config
|
||||||
|
} else {
|
||||||
|
return u.cachedConfig, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return u.cachedConfig
|
return u.cachedConfig, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func filter(ss []string, s string) []string {
|
func filter(ss []string, s string) []string {
|
||||||
@@ -257,7 +261,10 @@ func (h *handler) handleRecursive(w dns.ResponseWriter, req *dns.Msg) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
upstreamConfig := h.upstream.Config()
|
upstreamConfig, err := h.upstream.Config()
|
||||||
|
if err != nil {
|
||||||
|
h.ns.errorf("unable to read upstream config: %s", err)
|
||||||
|
}
|
||||||
for _, server := range upstreamConfig.Servers {
|
for _, server := range upstreamConfig.Servers {
|
||||||
reqCopy := req.Copy()
|
reqCopy := req.Copy()
|
||||||
reqCopy.Id = dns.Id()
|
reqCopy.Id = dns.Id()
|
||||||
|
|||||||
@@ -19,8 +19,8 @@ type mockUpstream struct {
|
|||||||
config *dns.ClientConfig
|
config *dns.ClientConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
func (mu *mockUpstream) Config() *dns.ClientConfig {
|
func (mu *mockUpstream) Config() (*dns.ClientConfig, error) {
|
||||||
return mu.config
|
return mu.config, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func startServer(t *testing.T, upstream *dns.ClientConfig) (*DNSServer, *Nameserver, int, int) {
|
func startServer(t *testing.T, upstream *dns.ClientConfig) (*DNSServer, *Nameserver, int, int) {
|
||||||
|
|||||||
@@ -36,9 +36,10 @@ func NewStatus(ns *Nameserver, dnsServer *DNSServer) *Status {
|
|||||||
entry.Tombstone})
|
entry.Tombstone})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
upstreamConfig, _ := dnsServer.upstream.Config()
|
||||||
return &Status{
|
return &Status{
|
||||||
dnsServer.domain,
|
dnsServer.domain,
|
||||||
dnsServer.upstream.Config().Servers,
|
upstreamConfig.Servers,
|
||||||
dnsServer.address,
|
dnsServer.address,
|
||||||
dnsServer.ttl,
|
dnsServer.ttl,
|
||||||
entryStatusSlice}
|
entryStatusSlice}
|
||||||
|
|||||||
Reference in new issue
Block a user