]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
rrcache: mangle TTL in first answer when using cache.min_ttl
authorvitas <vitezslav.kriz@nic.cz>
Tue, 11 Jul 2017 08:43:50 +0000 (10:43 +0200)
committervitas <vitezslav.kriz@nic.cz>
Tue, 11 Jul 2017 08:45:43 +0000 (10:45 +0200)
Issue #127.

Answer is mangled first and then copied to cache.

lib/layer/rrcache.c

index fa90b688b7836b6ee79cb8caaaa5e48bb2ae6dc1..d5a5d2bd4e6a3a7f3319e3dae89b6c1907bac375 100644 (file)
@@ -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) {