]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
layer/rrcache: minttl 5s default
authorMarek Vavruša <marek.vavrusa@nic.cz>
Sat, 18 Jul 2015 22:55:48 +0000 (00:55 +0200)
committerMarek Vavruša <marek.vavrusa@nic.cz>
Sat, 18 Jul 2015 23:24:00 +0000 (01:24 +0200)
lib/layer/rrcache.c

index adc77a8ab1a8500cef0f5fdc818910fb83ea933c..65b0596a5ff85d1c99c0195e46b0476de5068d67 100644 (file)
@@ -26,6 +26,7 @@
 #include "lib/module.h"
 
 #define DEBUG_MSG(fmt...) QRDEBUG(kr_rplan_current(rplan), " rc ",  fmt)
+#define DEFAULT_MINTTL (5) /* Short-time "no data" retention to avoid bursts */
 
 static int begin(knot_layer_t *ctx, void *module_param)
 {
@@ -125,15 +126,22 @@ struct stash_baton
 {
        struct kr_cache_txn *txn;
        unsigned timestamp;
+       uint32_t min_ttl;
 };
 
 static int commit_rr(const char *key, void *val, void *data)
 {
        knot_rrset_t *rr = val;
        struct stash_baton *baton = data;
-       if (knot_rrset_ttl(rr) < 1) {
-               return kr_ok(); /* Ignore cache busters */
+       /* 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);
        }
+
        /* Check if already cached */
        /** @todo This should check if less trusted data is in the cache,
                  for that the cache would need to trace data trust level.
@@ -154,7 +162,8 @@ static int stash_commit(map_t *stash, unsigned timestamp, struct kr_cache_txn *t
 {
        struct stash_baton baton = {
                .txn = txn,
-               .timestamp = timestamp
+               .timestamp = timestamp,
+               .min_ttl = DEFAULT_MINTTL
        };
        return map_walk(stash, &commit_rr, &baton);
 }