]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
cache: make expiring TTL threshold compile time configurable
authorMarek Vavruša <mvavrusa@cloudflare.com>
Tue, 7 Aug 2018 00:08:13 +0000 (17:08 -0700)
committerMarek Vavruša <mvavrusa@cloudflare.com>
Fri, 7 Sep 2018 17:45:21 +0000 (10:45 -0700)
By default the decayed TTL is considered as 'expiring' when it
is in the last 1% of its lifetime, or  shorter than 5 seconds.

lib/cache/impl.h
lib/defines.h

index cdcaaf84472bbea50a29949be035ed3c1bba120e..635790d1a6b22ba803c39fcd328710b4b0924ce0 100644 (file)
@@ -291,10 +291,13 @@ int answer_from_pkt(kr_layer_t *ctx, knot_pkt_t *pkt, uint16_t type,
 
 
 /** Record is expiring if it has less than 1% TTL (or less than 5s) */
-static inline bool is_expiring(uint32_t orig_ttl, uint32_t new_ttl)
+static inline bool is_expiring(uint32_t orig_ttl, uint32_t decayed_ttl)
 {
-       int64_t nttl = new_ttl; /* avoid potential over/under-flow */
-       return 100 * (nttl - 5) < orig_ttl;
+       if (decayed_ttl < 5) {
+               return true;
+       }
+
+       return decayed_ttl <= (orig_ttl * KR_CACHE_EXPIRING_THRESHOLD) / 100;
 }
 
 /** Returns signed result so you can inspect how much stale the RR is.
index 521f4c04b1e3fd0919760f499520b8ff14d0a996..b16d0db49959a5d9f77bd88dd39cf0367a5cf6b1 100644 (file)
@@ -78,6 +78,9 @@ static inline int KR_COLD kr_error(int x) {
 #define KR_EDNS_PAYLOAD 4096 /* Default UDP payload (max unfragmented UDP is 1452B) */
 #define KR_CACHE_DEFAULT_TTL_MIN (5) /* avoid bursts of queries */
 #define KR_CACHE_DEFAULT_TTL_MAX (6 * 24 * 3600) /* 6 days, like the root NS TTL */
+#ifndef KR_CACHE_EXPIRING_THRESHOLD
+#define KR_CACHE_EXPIRING_THRESHOLD 1 /* When decayed TTL is in its last N%, it's considered expiring. */
+#endif
 
 #define KR_DNAME_STR_MAXLEN (KNOT_DNAME_TXT_MAXLEN + 1)
 #define KR_RRTYPE_STR_MAXLEN (16 + 1)