|
@@ -14,13 +14,19 @@ import (
|
|
|
|
|
|
// LocalNameServer is an wrapper over local DNS feature.
|
|
// LocalNameServer is an wrapper over local DNS feature.
|
|
type LocalNameServer struct {
|
|
type LocalNameServer struct {
|
|
- client *localdns.Client
|
|
|
|
|
|
+ client *localdns.Client
|
|
|
|
+ queryStrategy QueryStrategy
|
|
}
|
|
}
|
|
|
|
|
|
const errEmptyResponse = "No address associated with hostname"
|
|
const errEmptyResponse = "No address associated with hostname"
|
|
|
|
|
|
// QueryIP implements Server.
|
|
// QueryIP implements Server.
|
|
func (s *LocalNameServer) QueryIP(ctx context.Context, domain string, _ net.IP, option dns.IPOption, _ bool) (ips []net.IP, err error) {
|
|
func (s *LocalNameServer) QueryIP(ctx context.Context, domain string, _ net.IP, option dns.IPOption, _ bool) (ips []net.IP, err error) {
|
|
|
|
+ option = ResolveIpOptionOverride(s.queryStrategy, option)
|
|
|
|
+ if !option.IPv4Enable && !option.IPv6Enable {
|
|
|
|
+ return nil, dns.ErrEmptyResponse
|
|
|
|
+ }
|
|
|
|
+
|
|
start := time.Now()
|
|
start := time.Now()
|
|
ips, err = s.client.LookupIP(domain, option)
|
|
ips, err = s.client.LookupIP(domain, option)
|
|
|
|
|
|
@@ -42,14 +48,15 @@ func (s *LocalNameServer) Name() string {
|
|
}
|
|
}
|
|
|
|
|
|
// NewLocalNameServer creates localdns server object for directly lookup in system DNS.
|
|
// NewLocalNameServer creates localdns server object for directly lookup in system DNS.
|
|
-func NewLocalNameServer() *LocalNameServer {
|
|
|
|
|
|
+func NewLocalNameServer(queryStrategy QueryStrategy) *LocalNameServer {
|
|
errors.LogInfo(context.Background(), "DNS: created localhost client")
|
|
errors.LogInfo(context.Background(), "DNS: created localhost client")
|
|
return &LocalNameServer{
|
|
return &LocalNameServer{
|
|
- client: localdns.New(),
|
|
|
|
|
|
+ queryStrategy: queryStrategy,
|
|
|
|
+ client: localdns.New(),
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
// NewLocalDNSClient creates localdns client object for directly lookup in system DNS.
|
|
// NewLocalDNSClient creates localdns client object for directly lookup in system DNS.
|
|
func NewLocalDNSClient() *Client {
|
|
func NewLocalDNSClient() *Client {
|
|
- return &Client{server: NewLocalNameServer()}
|
|
|
|
|
|
+ return &Client{server: NewLocalNameServer(QueryStrategy_USE_IP)}
|
|
}
|
|
}
|