Skip to content

Commit

Permalink
UPSTREAM: 6354: openshift: Fix OCPBUGS-15755
Browse files Browse the repository at this point in the history
plugin/cache: key cache on Checking Disabled (CD) bit (coredns#6354)

* plugin/cache: key cache on Checking Disabled (CD) bit

Key the cache on CD bit, which effectively separates the entries for
queries with CD disabled or enabled.

Signed-off-by: Grant Spence <gspence@redhat.com>
  • Loading branch information
gcs278 committed Dec 4, 2023
1 parent 68ef945 commit 59f7d2f
Show file tree
Hide file tree
Showing 5 changed files with 509 additions and 276 deletions.
16 changes: 12 additions & 4 deletions plugin/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func New() *Cache {
// key returns key under which we store the item, -1 will be returned if we don't store the message.
// Currently we do not cache Truncated, errors zone transfers or dynamic update messages.
// qname holds the already lowercased qname.
func key(qname string, m *dns.Msg, t response.Type, do bool) (bool, uint64) {
func key(qname string, m *dns.Msg, t response.Type, do, cd bool) (bool, uint64) {
// We don't store truncated responses.
if m.Truncated {
return false, 0
Expand All @@ -89,13 +89,13 @@ func key(qname string, m *dns.Msg, t response.Type, do bool) (bool, uint64) {
return false, 0
}

return true, hash(qname, m.Question[0].Qtype, do)
return true, hash(qname, m.Question[0].Qtype, do, cd)
}

var one = []byte("1")
var zero = []byte("0")

func hash(qname string, qtype uint16, do bool) uint64 {
func hash(qname string, qtype uint16, do, cd bool) uint64 {
h := fnv.New64()

if do {
Expand All @@ -104,6 +104,12 @@ func hash(qname string, qtype uint16, do bool) uint64 {
h.Write(zero)
}

if cd {
h.Write(one)
} else {
h.Write(zero)
}

h.Write([]byte{byte(qtype >> 8)})
h.Write([]byte{byte(qtype)})
h.Write([]byte(qname))
Expand All @@ -129,6 +135,7 @@ type ResponseWriter struct {
server string // Server handling the request.

do bool // When true the original request had the DO bit set.
cd bool // When true the original request had the CD bit set.
ad bool // When true the original request had the AD bit set.
prefetch bool // When true write nothing back to the client.
remoteAddr net.Addr
Expand Down Expand Up @@ -159,6 +166,7 @@ func newPrefetchResponseWriter(server string, state request.Request, c *Cache) *
state: state,
server: server,
do: state.Do(),
cd: state.Req.CheckingDisabled,
prefetch: true,
remoteAddr: addr,
}
Expand All @@ -177,7 +185,7 @@ func (w *ResponseWriter) WriteMsg(res *dns.Msg) error {
mt, _ := response.Typify(res, w.now().UTC())

// key returns empty string for anything we don't want to cache.
hasKey, key := key(w.state.Name(), res, mt, w.do)
hasKey, key := key(w.state.Name(), res, mt, w.do, w.cd)

msgTTL := dnsutil.MinimalTTL(res, mt)
var duration time.Duration
Expand Down

0 comments on commit 59f7d2f

Please sign in to comment.