Skip to content

Commit

Permalink
fix: need to check empty ans when prefer ip version
Browse files Browse the repository at this point in the history
  • Loading branch information
mzz2017 committed Apr 29, 2023
1 parent 33ac27d commit 97361f9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
10 changes: 10 additions & 0 deletions control/dns_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,13 @@ func (c *DnsCache) IncludeIp(ip netip.Addr) bool {
}
return false
}

func (c *DnsCache) IncludeAnyIp() bool {
for _, ans := range c.Answers {
switch ans.Body.(type) {
case *dnsmessage.AResource, *dnsmessage.AAAAResource:
return true
}
}
return false
}
2 changes: 1 addition & 1 deletion control/dns_control.go
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ func (c *DnsController) Handle_(dnsMessage *dnsmessage.Message, req *udpRequest)
}
// resp is valid.
cache2 := c.LookupDnsRespCache(qname, qtype2)
if c.qtypePrefer == qtype || cache2 == nil {
if c.qtypePrefer == qtype || cache2 == nil || !cache2.IncludeAnyIp() {
return sendPkt(resp, req.realDst, req.realSrc, req.src, req.lConn, req.lanWanFlag)
} else {
return c.sendReject_(dnsMessage, req)
Expand Down

0 comments on commit 97361f9

Please sign in to comment.