plugin/cache: preserve AD when storing cache entries (#8438)

This commit is contained in:
Sueun Cho
2026-08-15 12:28:20 +09:00
committed by GitHub
parent ab7a8880a4
commit 29ef323f82
3 changed files with 141 additions and 14 deletions

17
plugin/cache/cache.go vendored
View File

@@ -348,11 +348,14 @@ var prefetchAddr = &net.TCPAddr{}
// short-circuits after caching when w.prefetch is true, and the nil-safe
// overrides below make the remaining dns.ResponseWriter methods well-defined.
func newPrefetchResponseWriter(server string, req *dns.Msg, do, cd bool, c *Cache) *ResponseWriter {
req = req.Copy()
req.AuthenticatedData = true
cw := &ResponseWriter{
Cache: c,
server: server,
do: do,
cd: cd,
ad: true,
prefetch: true,
remoteAddr: prefetchAddr,
}
@@ -435,13 +438,6 @@ func (w *ResponseWriter) WriteMsg(res *dns.Msg) error {
res.Ns = filterRRSlice(res.Ns, ttl, false)
res.Extra = filterRRSlice(res.Extra, ttl, false)
if !w.do && !w.ad {
// unset AD bit if requester is not OK with DNSSEC
// But retain AD bit if requester set the AD bit in the request, per RFC6840 5.7-5.8
res.AuthenticatedData = false
}
w.lastResponse = res.Copy()
if hasKey && duration > 0 {
if w.state.Match(res) {
w.set(res, key, mt, duration)
@@ -453,6 +449,13 @@ func (w *ResponseWriter) WriteMsg(res *dns.Msg) error {
}
}
if !w.do && !w.ad {
// unset AD bit if requester is not OK with DNSSEC
// But retain AD bit if requester set the AD bit in the request, per RFC6840 5.7-5.8
res.AuthenticatedData = false
}
w.lastResponse = res.Copy()
if w.prefetch {
return nil
}