fix logic for adding localhost dns

pull/1435/head
Darien Raymond 2018-11-22 16:29:09 +01:00
parent fa7ce36aa8
commit 1cc3a4832d
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169
3 changed files with 12 additions and 1 deletions

View File

@ -13,6 +13,7 @@ type IPOption struct {
} }
type NameServerInterface interface { type NameServerInterface interface {
Name() string
QueryIP(ctx context.Context, domain string, option IPOption) ([]net.IP, error) QueryIP(ctx context.Context, domain string, option IPOption) ([]net.IP, error)
} }
@ -36,6 +37,10 @@ func (s *localNameServer) QueryIP(ctx context.Context, domain string, option IPO
return nil, newError("neither IPv4 nor IPv6 is enabled") return nil, newError("neither IPv4 nor IPv6 is enabled")
} }
func (s *localNameServer) Name() string {
return "localhost"
}
func NewLocalNameServer() *localNameServer { func NewLocalNameServer() *localNameServer {
return &localNameServer{ return &localNameServer{
client: localdns.New(), client: localdns.New(),

View File

@ -94,7 +94,7 @@ func New(ctx context.Context, config *Config) (*Server, error) {
server.domainIndexMap = domainIndexMap server.domainIndexMap = domainIndexMap
} }
if len(config.NameServers) == 0 { if len(server.servers) == 0 {
server.servers = append(server.servers, NewLocalNameServer()) server.servers = append(server.servers, NewLocalNameServer())
} }
@ -162,6 +162,7 @@ func (s *Server) lookupIPInternal(domain string, option IPOption) ([]net.IP, err
return ips, nil return ips, nil
} }
if err != nil { if err != nil {
newError("failed to lookup ip for domain ", domain, " at server ", ns.Name()).Base(err).WriteToLog()
lastErr = err lastErr = err
} }
} }
@ -173,6 +174,7 @@ func (s *Server) lookupIPInternal(domain string, option IPOption) ([]net.IP, err
return ips, nil return ips, nil
} }
if err != nil { if err != nil {
newError("failed to lookup ip for domain ", domain, " at server ", server.Name()).Base(err).WriteToLog()
lastErr = err lastErr = err
} }
} }

View File

@ -57,6 +57,10 @@ func NewClassicNameServer(address net.Destination, dispatcher routing.Dispatcher
return s return s
} }
func (s *ClassicNameServer) Name() string {
return s.address.String()
}
func (s *ClassicNameServer) Cleanup() error { func (s *ClassicNameServer) Cleanup() error {
now := time.Now() now := time.Now()
s.Lock() s.Lock()