cacheWorks returns true if the cache works for the given context. If not, it returns false and logs the reason why.
(dctx *DNSContext)
| 784 | // cacheWorks returns true if the cache works for the given context. If not, it |
| 785 | // returns false and logs the reason why. |
| 786 | func (p *Proxy) cacheWorks(dctx *DNSContext) (ok bool) { |
| 787 | var reason string |
| 788 | switch { |
| 789 | case dctx.CustomUpstreamConfig != nil && dctx.CustomUpstreamConfig.cache == nil: |
| 790 | // If custom upstreams are used but the custom upstream cache is |
| 791 | // disabled, return false to prevent storing results in the global |
| 792 | // cache. |
| 793 | // |
| 794 | // See https://github.com/AdguardTeam/dnsproxy/issues/169. |
| 795 | reason = "custom upstreams cache is not configured" |
| 796 | case p.cache == nil && |
| 797 | (dctx.CustomUpstreamConfig == nil || dctx.CustomUpstreamConfig.cache == nil): |
| 798 | reason = "caching disabled: neither global cache nor custom upstreams cache is configured" |
| 799 | case dctx.RequestedPrivateRDNS != netip.Prefix{}: |
| 800 | // Don't cache the requests intended for local upstream servers, those |
| 801 | // should be fast enough as is. |
| 802 | reason = "requested address is private" |
| 803 | case dctx.Req.CheckingDisabled: |
| 804 | // Also don't lookup the cache for responses with DNSSEC checking |
| 805 | // disabled since only validated responses are cached and those may be |
| 806 | // not the desired result for user specifying CD flag. |
| 807 | reason = "dnssec check disabled" |
| 808 | default: |
| 809 | return true |
| 810 | } |
| 811 | |
| 812 | p.logger.Debug("not caching", "reason", reason) |
| 813 | |
| 814 | return false |
| 815 | } |
| 816 | |
| 817 | // processECS adds EDNS Client Subnet data into the request from d. |
| 818 | func (dctx *DNSContext) processECS(cliIP net.IP, l *slog.Logger) { |