Commit 1203fe71 authored by Marek Vavruša's avatar Marek Vavruša

lib/rrcache: handle qname/cname traversal when it fails

parent c0c840a9
......@@ -113,7 +113,9 @@ static void follow_cname_chain(const knot_dname_t **cname, const knot_rrset_t *r
struct kr_query *cur)
{
if (rr->type == KNOT_RRTYPE_CNAME) {
*cname = knot_cname_name(&rr->rrs);
const knot_dname_t *next_cname = knot_cname_name(&rr->rrs);
if (next_cname)
*cname = next_cname;
} else if (rr->type != KNOT_RRTYPE_RRSIG) {
/* Terminate CNAME chain (if not RRSIG). */
*cname = cur->sname;
......
......@@ -182,13 +182,15 @@ static int stash(knot_layer_t *ctx, knot_pkt_t *pkt)
if (ttl == 0) {
return ctx->state; /* No useable TTL, can't cache this. */
}
const knot_dname_t *qname = knot_pkt_qname(pkt);
if (!qname) {
return ctx->state;
}
/* Open write transaction and prepare answer */
struct kr_cache_txn txn;
if (kr_cache_txn_begin(&req->ctx->cache, &txn, 0) != 0) {
return ctx->state; /* Couldn't acquire cache, ignore. */
}
const knot_dname_t *qname = knot_pkt_qname(pkt);
namedb_val_t data = { pkt->wire, pkt->size };
struct kr_cache_entry header = {
.timestamp = qry->timestamp.tv_sec,
......
......@@ -255,7 +255,12 @@ static int stash_authority(struct kr_query *qry, knot_pkt_t *pkt, map_t *stash,
static int stash_answer(struct kr_query *qry, knot_pkt_t *pkt, map_t *stash, mm_ctx_t *pool)
{
const knot_dname_t *cname = knot_pkt_qname(pkt);
/* Work with QNAME, as minimised name data is cacheable. */
const knot_dname_t *cname_begin = knot_pkt_qname(pkt);
if (!cname_begin) {
cname_begin = qry->sname;
}
const knot_dname_t *cname = cname_begin;
const knot_pktsection_t *answer = knot_pkt_section(pkt, KNOT_ANSWER);
for (unsigned i = 0; i < answer->count; ++i) {
/* Stash direct answers (equal to current QNAME/CNAME),
......@@ -269,11 +274,11 @@ static int stash_answer(struct kr_query *qry, knot_pkt_t *pkt, map_t *stash, mm_
/* Follow CNAME chain in current cut (if SECURE). */
if ((qry->flags & QUERY_DNSSEC_WANT) && rr->type == KNOT_RRTYPE_CNAME) {
const knot_dname_t *next_cname = knot_cname_name(&rr->rrs);
if (knot_dname_in(qry->zone_cut.name, next_cname)) {
if (next_cname && knot_dname_in(qry->zone_cut.name, next_cname)) {
cname = next_cname;
}
} else if (rr->type != KNOT_RRTYPE_RRSIG) {
cname = qry->sname;
cname = cname_begin;
}
}
return kr_ok();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment