From: Marek VavruĊĦa Date: Tue, 7 Aug 2018 00:08:13 +0000 (-0700) Subject: cache: make expiring TTL threshold compile time configurable X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a9ac327c886f8e11193ad29b1893d2aeef8543ff;p=thirdparty%2Fknot-resolver.git cache: make expiring TTL threshold compile time configurable By default the decayed TTL is considered as 'expiring' when it is in the last 1% of its lifetime, or shorter than 5 seconds. --- diff --git a/lib/cache/impl.h b/lib/cache/impl.h index cdcaaf844..635790d1a 100644 --- a/lib/cache/impl.h +++ b/lib/cache/impl.h @@ -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. diff --git a/lib/defines.h b/lib/defines.h index 521f4c04b..b16d0db49 100644 --- a/lib/defines.h +++ b/lib/defines.h @@ -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)