Browse Source

fix logic for adding localhost dns

Darien Raymond 7 years ago
parent
commit
1cc3a4832d
3 changed files with 12 additions and 1 deletions
  1. 5 0
      app/dns/nameserver.go
  2. 3 1
      app/dns/server.go
  3. 4 0
      app/dns/udpns.go

+ 5 - 0
app/dns/nameserver.go

@@ -13,6 +13,7 @@ type IPOption struct {
 }
 
 type NameServerInterface interface {
+	Name() string
 	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")
 }
 
+func (s *localNameServer) Name() string {
+	return "localhost"
+}
+
 func NewLocalNameServer() *localNameServer {
 	return &localNameServer{
 		client: localdns.New(),

+ 3 - 1
app/dns/server.go

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

+ 4 - 0
app/dns/udpns.go

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