@@ -14,13 +14,19 @@ import (
1414
1515// LocalNameServer is an wrapper over local DNS feature.
1616type LocalNameServer struct {
17- client * localdns.Client
17+ client * localdns.Client
18+ queryStrategy QueryStrategy
1819}
1920
2021const errEmptyResponse = "No address associated with hostname"
2122
2223// QueryIP implements Server.
2324func (s * LocalNameServer ) QueryIP (ctx context.Context , domain string , _ net.IP , option dns.IPOption , _ bool ) (ips []net.IP , err error ) {
25+ option = ResolveIpOptionOverride (s .queryStrategy , option )
26+ if ! option .IPv4Enable && ! option .IPv6Enable {
27+ return nil , dns .ErrEmptyResponse
28+ }
29+
2430 start := time .Now ()
2531 ips , err = s .client .LookupIP (domain , option )
2632
@@ -42,14 +48,15 @@ func (s *LocalNameServer) Name() string {
4248}
4349
4450// NewLocalNameServer creates localdns server object for directly lookup in system DNS.
45- func NewLocalNameServer () * LocalNameServer {
51+ func NewLocalNameServer (queryStrategy QueryStrategy ) * LocalNameServer {
4652 errors .LogInfo (context .Background (), "DNS: created localhost client" )
4753 return & LocalNameServer {
48- client : localdns .New (),
54+ queryStrategy : queryStrategy ,
55+ client : localdns .New (),
4956 }
5057}
5158
5259// NewLocalDNSClient creates localdns client object for directly lookup in system DNS.
5360func NewLocalDNSClient () * Client {
54- return & Client {server : NewLocalNameServer ()}
61+ return & Client {server : NewLocalNameServer (QueryStrategy_USE_IP )}
5562}
0 commit comments