Skip to content
Snippets Groups Projects
Commit 7f493786 authored by Marek Vavruša's avatar Marek Vavruša
Browse files

lib/cache: properly cache meta types and RRSIG queries

parent 15f4e488
No related branches found
No related tags found
No related merge requests found
......@@ -173,10 +173,11 @@ static int stash(knot_layer_t *ctx, knot_pkt_t *pkt)
if (!knot_wire_get_aa(pkt->wire) || knot_pkt_qclass(pkt) != KNOT_CLASS_IN) {
return ctx->state;
}
const bool is_any = knot_pkt_qtype(pkt) == KNOT_RRTYPE_ANY;
/* Cache only NODATA/NXDOMAIN or metatype/RRSIG answers. */
const uint16_t qtype = knot_pkt_qtype(pkt);
const bool is_eligible = (knot_rrtype_is_metatype(qtype) || qtype == KNOT_RRTYPE_RRSIG);
int pkt_class = kr_response_classify(pkt);
/* Cache only NODATA/NXDOMAIN or ANY answers. */
if (!((pkt_class & (PKT_NODATA|PKT_NXDOMAIN)) || is_any)) {
if (!(is_eligible || (pkt_class & (PKT_NODATA|PKT_NXDOMAIN)))) {
return ctx->state;
}
uint32_t ttl = packet_ttl(pkt);
......@@ -190,7 +191,6 @@ static int stash(knot_layer_t *ctx, knot_pkt_t *pkt)
return ctx->state; /* Couldn't acquire cache, ignore. */
}
const knot_dname_t *qname = knot_pkt_qname(pkt);
uint16_t qtype = knot_pkt_qtype(pkt);
namedb_val_t data = { pkt->wire, pkt->size };
struct kr_cache_entry header = {
.timestamp = qry->timestamp.tv_sec,
......
......@@ -282,9 +282,14 @@ static int stash(knot_layer_t *ctx, knot_pkt_t *pkt)
if (!qry || ctx->state & KNOT_STATE_FAIL) {
return ctx->state;
}
/* Cache only positive answers. */
if (qry->flags & QUERY_CACHED || knot_wire_get_rcode(pkt->wire) != KNOT_RCODE_NOERROR) {
/* Do not cache truncated answers. */
if (knot_wire_get_tc(pkt->wire)) {
return ctx->state;
}
/* Cache only positive answers, not meta types or RRSIG. */
const uint16_t qtype = knot_pkt_qtype(pkt);
const bool is_eligible = !(knot_rrtype_is_metatype(qtype) || qtype == KNOT_RRTYPE_RRSIG);
if (qry->flags & QUERY_CACHED || knot_wire_get_rcode(pkt->wire) != KNOT_RCODE_NOERROR || !is_eligible) {
return ctx->state;
}
/* Stash in-bailiwick data from the AUTHORITY and ANSWER. */
......@@ -306,7 +311,7 @@ static int stash(knot_layer_t *ctx, knot_pkt_t *pkt)
stash_ds(qry, pkt, &stash, rplan->pool);
}
/* Cache stashed records */
if (ret == 0) {
if (ret == 0 && stash.root != NULL) {
/* Open write transaction */
struct kr_cache *cache = &req->ctx->cache;
struct kr_cache_txn txn;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment