diff --git a/app/dns/dns.go b/app/dns/dns.go index 93d248edd2d..20c60876f64 100644 --- a/app/dns/dns.go +++ b/app/dns/dns.go @@ -29,7 +29,7 @@ type DNS struct { disableCache bool disableFallback bool disableFallbackIfMatch bool - ipOption *dns.IPOption + ipOption dns.IPOption hosts *StaticHosts clients []*Client ctx context.Context @@ -60,22 +60,22 @@ func New(ctx context.Context, config *Config) (*DNS, error) { return nil, newError("unexpected client IP length ", len(config.ClientIp)) } - var ipOption *dns.IPOption + var ipOption dns.IPOption switch config.QueryStrategy { case QueryStrategy_USE_IP: - ipOption = &dns.IPOption{ + ipOption = dns.IPOption{ IPv4Enable: true, IPv6Enable: true, FakeEnable: false, } case QueryStrategy_USE_IP4: - ipOption = &dns.IPOption{ + ipOption = dns.IPOption{ IPv4Enable: true, IPv6Enable: false, FakeEnable: false, } case QueryStrategy_USE_IP6: - ipOption = &dns.IPOption{ + ipOption = dns.IPOption{ IPv4Enable: false, IPv6Enable: true, FakeEnable: false, @@ -172,29 +172,27 @@ func (s *DNS) IsOwnLink(ctx context.Context) bool { // LookupIP implements dns.Client. func (s *DNS) LookupIP(domain string) ([]net.IP, error) { - return s.lookupIPInternal(domain, dns.IPOption{ - IPv4Enable: true, - IPv6Enable: true, - FakeEnable: s.ipOption.FakeEnable, - }) + return s.lookupIPInternal(domain, s.ipOption) } // LookupIPv4 implements dns.IPv4Lookup. func (s *DNS) LookupIPv4(domain string) ([]net.IP, error) { - return s.lookupIPInternal(domain, dns.IPOption{ - IPv4Enable: true, - IPv6Enable: false, - FakeEnable: s.ipOption.FakeEnable, - }) + if !s.ipOption.IPv4Enable { + return nil, dns.ErrEmptyResponse + } + o := s.ipOption + o.IPv6Enable = false + return s.lookupIPInternal(domain, o) } // LookupIPv6 implements dns.IPv6Lookup. func (s *DNS) LookupIPv6(domain string) ([]net.IP, error) { - return s.lookupIPInternal(domain, dns.IPOption{ - IPv4Enable: false, - IPv6Enable: true, - FakeEnable: s.ipOption.FakeEnable, - }) + if !s.ipOption.IPv6Enable { + return nil, dns.ErrEmptyResponse + } + o := s.ipOption + o.IPv4Enable = false + return s.lookupIPInternal(domain, o) } func (s *DNS) lookupIPInternal(domain string, option dns.IPOption) ([]net.IP, error) { @@ -245,7 +243,7 @@ func (s *DNS) lookupIPInternal(domain string, option dns.IPOption) ([]net.IP, er // GetIPOption implements ClientWithIPOption. func (s *DNS) GetIPOption() *dns.IPOption { - return s.ipOption + return &s.ipOption } // SetQueryOption implements ClientWithIPOption.