Commit 214a09dd authored by Vitezslav Kriz's avatar Vitezslav Kriz

rrcache: mangle TTL in first answer when using cache.min_ttl

Issue #127.

Answer is mangled first and then copied to cache.
parent d8fed142
Pipeline #8305 canceled with stages
in 78 minutes and 5 seconds
......@@ -271,7 +271,6 @@ struct rrcache_baton
struct kr_query *qry;
struct kr_cache *cache;
unsigned timestamp;
uint32_t min_ttl;
};
static int commit_rrsig(struct rrcache_baton *baton, uint8_t rank, uint8_t flags, knot_rrset_t *rr)
......@@ -288,14 +287,6 @@ static int commit_rr(const char *key, void *val, void *data)
{
knot_rrset_t *rr = val;
struct rrcache_baton *baton = data;
/* Ensure minimum TTL */
knot_rdata_t *rd = rr->rrs.data;
for (uint16_t i = 0; i < rr->rrs.rr_count; ++i) {
if (knot_rdata_ttl(rd) < baton->min_ttl) {
knot_rdata_set_ttl(rd, baton->min_ttl);
}
rd = kr_rdataset_next(rd);
}
/* Save RRSIG in a special cache. */
uint8_t rank = KEY_FLAG_RANK(key);
......@@ -343,7 +334,6 @@ static int stash_commit(map_t *stash, struct kr_query *qry, struct kr_cache *cac
.qry = qry,
.cache = cache,
.timestamp = qry->timestamp.tv_sec,
.min_ttl = MAX(DEFAULT_MINTTL, cache->ttl_min),
};
return map_walk(stash, &commit_rr, &baton);
}
......@@ -370,6 +360,8 @@ static int stash_selected(struct kr_request *req, knot_pkt_t *pkt, map_t *stash,
if (!arr->len) {
return kr_ok();
}
uint32_t min_ttl = MAX(DEFAULT_MINTTL, req->ctx->cache.ttl_min);
/* uncached entries are located at the end */
for (ssize_t i = arr->len - 1; i >= 0; --i) {
ranked_rr_array_entry_t *entry = arr->at[i];
......@@ -379,7 +371,17 @@ static int stash_selected(struct kr_request *req, knot_pkt_t *pkt, map_t *stash,
if (entry->cached) {
continue;
}
const knot_rrset_t *rr = entry->rr;
knot_rrset_t *rr = entry->rr;
/* Ensure minimum TTL */
knot_rdata_t *rd = rr->rrs.data;
for (uint16_t i = 0; i < rr->rrs.rr_count; ++i) {
if (knot_rdata_ttl(rd) < min_ttl) {
knot_rdata_set_ttl(rd, min_ttl);
}
rd = kr_rdataset_next(rd);
}
/* Skip NSEC3 RRs and their signatures. We don't use them this way.
* They would be stored under the hashed name, etc. */
if (kr_rrset_type_maysig(rr) == KNOT_RRTYPE_NSEC3) {
......
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