diff options
author | Simon Kelley <simon@thekelleys.org.uk> | 2022-09-16 12:07:01 +0100 |
---|---|---|
committer | Simon Kelley <simon@thekelleys.org.uk> | 2022-09-16 12:44:04 +0100 |
commit | 9403664616ab8ce9d735b254056be79cf14eeb31 (patch) | |
tree | e77f339b1057e64470ce2def510ce4266cad43e6 | |
parent | f32498465dfb1f885c83b52576f5afa6f701e211 (diff) | |
download | dnsmasq-9403664616ab8ce9d735b254056be79cf14eeb31.tar.gz |
Optimise cache code when stale caching in use.
Exclude DNSSEC entries from stale caching.
-rw-r--r-- | src/cache.c | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/src/cache.c b/src/cache.c index 6e039d5..4ca04fd 100644 --- a/src/cache.c +++ b/src/cache.c @@ -374,8 +374,9 @@ static int is_outdated_cname_pointer(struct crec *crecp) static int is_expired(time_t now, struct crec *crecp) { - /* Don't dump expired entries if we're using them, cache becomes strictly LRU in that case. */ - if (option_bool(OPT_STALE_CACHE)) + /* Don't dump expired entries if we're using them, cache becomes strictly LRU in that case. + Never use expired DS or DNSKEY entries. */ + if (option_bool(OPT_STALE_CACHE) && !(crecp->flags & (F_DS | F_DNSKEY))) return 0; if (crecp->flags & F_IMMORTAL) @@ -557,7 +558,7 @@ static struct crec *really_insert(char *name, union all_addr *addr, unsigned sho { struct crec *new, *target_crec = NULL; union bigname *big_name = NULL; - int freed_all = flags & F_REVERSE; + int freed_all = (flags & F_REVERSE); int free_avail = 0; unsigned int target_uid; @@ -632,8 +633,12 @@ static struct crec *really_insert(char *name, union all_addr *addr, unsigned sho { /* For DNSSEC records, uid holds class. */ free_avail = 1; /* Must be free space now. */ + + /* condition valid when stale-caching */ + if (difftime(now, new->ttd) < 0) + daemon->metrics[METRIC_DNS_CACHE_LIVE_FREED]++; + cache_scan_free(cache_get_name(new), &new->addr, new->uid, now, new->flags, NULL, NULL); - daemon->metrics[METRIC_DNS_CACHE_LIVE_FREED]++; } else { |