mirror of https://github.com/v2ray/v2ray-core
fix logic for adding localhost dns
parent
fa7ce36aa8
commit
1cc3a4832d
|
@ -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(),
|
||||||
|
|
|
@ -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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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()
|
||||||
|
|
Loading…
Reference in New Issue