Skip to content

Commit

Permalink
Fix queryStrategy ignored
Browse files Browse the repository at this point in the history
  • Loading branch information
nekohasekai committed Sep 23, 2021
1 parent 70c796b commit 1749ab0
Showing 1 changed file with 19 additions and 21 deletions.
40 changes: 19 additions & 21 deletions app/dns/dns.go
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 1749ab0

Please sign in to comment.