bind9/lib/dns
Diego Fronza 4827ad0ec4 Add stale-refresh-time option
Before this update, BIND would attempt to do a full recursive resolution
process for each query received if the requested rrset had its ttl
expired. If the resolution fails for any reason, only then BIND would
check for stale rrset in cache (if 'stale-cache-enable' and
'stale-answer-enable' is on).

The problem with this approach is that if an authoritative server is
unreachable or is failing to respond, it is very unlikely that the
problem will be fixed in the next seconds.

A better approach to improve performance in those cases, is to mark the
moment in which a resolution failed, and if new queries arrive for that
same rrset, try to respond directly from the stale cache, and do that
for a window of time configured via 'stale-refresh-time'.

Only when this interval expires we then try to do a normal refresh of
the rrset.

The logic behind this commit is as following:

- In query.c / query_gotanswer(), if the test of 'result' variable falls
  to the default case, an error is assumed to have happened, and a call
  to 'query_usestale()' is made to check if serving of stale rrset is
  enabled in configuration.

- If serving of stale answers is enabled, a flag will be turned on in
  the query context to look for stale records:
  query.c:6839
  qctx->client->query.dboptions |= DNS_DBFIND_STALEOK;

- A call to query_lookup() will be made again, inside it a call to
  'dns_db_findext()' is made, which in turn will invoke rbdb.c /
  cache_find().

- In rbtdb.c / cache_find() the important bits of this change is the
  call to 'check_stale_header()', which is a function that yields true
  if we should skip the stale entry, or false if we should consider it.

- In check_stale_header() we now check if the DNS_DBFIND_STALEOK option
  is set, if that is the case we know that this new search for stale
  records was made due to a failure in a normal resolution, so we keep
  track of the time in which the failured occured in rbtdb.c:4559:
  header->last_refresh_fail_ts = search->now;

- In check_stale_header(), if DNS_DBFIND_STALEOK is not set, then we
  know this is a normal lookup, if the record is stale and the query
  time is between last failure time + stale-refresh-time window, then
  we return false so cache_find() knows it can consider this stale
  rrset entry to return as a response.

The last additions are two new methods to the database interface:
- setservestale_refresh
- getservestale_refresh

Those were added so rbtdb can be aware of the value set in configuration
option, since in that level we have no access to the view object.
2020-11-11 12:53:23 -03:00
..
include Add stale-refresh-time option 2020-11-11 12:53:23 -03:00
rdata update all copyright headers to eliminate the typo 2020-09-14 16:20:40 -07:00
tests use netmgr for xfrin 2020-11-09 13:45:43 +01:00
win32 Add stale-refresh-time option 2020-11-11 12:53:23 -03:00
.gitignore 4394. [func] Add rndc command "dnstap-reopen" to close and 2016-06-24 09:37:04 +10:00
acl.c update all copyright headers to eliminate the typo 2020-09-14 16:20:40 -07:00
adb.c Simplify the EDNS buffer size logic for DNS Flag Day 2020 2020-10-05 16:21:21 +02:00
api Update library API versions 2020-10-22 08:54:32 +02:00
badcache.c update all copyright headers to eliminate the typo 2020-09-14 16:20:40 -07:00
byaddr.c update all copyright headers to eliminate the typo 2020-09-14 16:20:40 -07:00
cache.c Add stale-refresh-time option 2020-11-11 12:53:23 -03:00
callbacks.c update all copyright headers to eliminate the typo 2020-09-14 16:20:40 -07:00
catz.c update all copyright headers to eliminate the typo 2020-09-14 16:20:40 -07:00
client.c The dns_message_create() cannot fail, change the return to void 2020-09-29 08:22:08 +02:00
clientinfo.c update all copyright headers to eliminate the typo 2020-09-14 16:20:40 -07:00
compress.c update all copyright headers to eliminate the typo 2020-09-14 16:20:40 -07:00
db.c Add stale-refresh-time option 2020-11-11 12:53:23 -03:00
dbiterator.c update all copyright headers to eliminate the typo 2020-09-14 16:20:40 -07:00
diff.c update all copyright headers to eliminate the typo 2020-09-14 16:20:40 -07:00
dispatch.c Hold qid->lock when calling deref_portentry() as 2020-10-23 13:49:41 +00:00
dlz.c update all copyright headers to eliminate the typo 2020-09-14 16:20:40 -07:00
dns64.c update all copyright headers to eliminate the typo 2020-09-14 16:20:40 -07:00
dnsrps.c Add stale-refresh-time option 2020-11-11 12:53:23 -03:00
dnssec.c update all copyright headers to eliminate the typo 2020-09-14 16:20:40 -07:00
dnstap.c The dns_message_create() cannot fail, change the return to void 2020-09-29 08:22:08 +02:00
dnstap.proto fix spelling errors reported by Fossies. 2020-02-21 15:05:08 +11:00
ds.c update all copyright headers to eliminate the typo 2020-09-14 16:20:40 -07:00
dst_api.c update all copyright headers to eliminate the typo 2020-09-14 16:20:40 -07:00
dst_internal.h update all copyright headers to eliminate the typo 2020-09-14 16:20:40 -07:00
dst_openssl.h update all copyright headers to eliminate the typo 2020-09-14 16:20:40 -07:00
dst_parse.c update all copyright headers to eliminate the typo 2020-09-14 16:20:40 -07:00
dst_parse.h update all copyright headers to eliminate the typo 2020-09-14 16:20:40 -07:00
dst_pkcs11.h update all copyright headers to eliminate the typo 2020-09-14 16:20:40 -07:00
dst_result.c update all copyright headers to eliminate the typo 2020-09-14 16:20:40 -07:00
dyndb.c Use libuv's shared library handling capabilities 2020-10-28 15:48:58 +01:00
ecs.c update all copyright headers to eliminate the typo 2020-09-14 16:20:40 -07:00
fixedname.c update all copyright headers to eliminate the typo 2020-09-14 16:20:40 -07:00
forward.c update all copyright headers to eliminate the typo 2020-09-14 16:20:40 -07:00
gen-unix.h update all copyright headers to eliminate the typo 2020-09-14 16:20:40 -07:00
gen-win32.h update all copyright headers to eliminate the typo 2020-09-14 16:20:40 -07:00
gen.c update all copyright headers to eliminate the typo 2020-09-14 16:20:40 -07:00
geoip2.c update all copyright headers to eliminate the typo 2020-09-14 16:20:40 -07:00
gssapi_link.c update all copyright headers to eliminate the typo 2020-09-14 16:20:40 -07:00
gssapictx.c update all copyright headers to eliminate the typo 2020-09-14 16:20:40 -07:00
hmac_link.c update all copyright headers to eliminate the typo 2020-09-14 16:20:40 -07:00
ipkeylist.c update all copyright headers to eliminate the typo 2020-09-14 16:20:40 -07:00
iptable.c update all copyright headers to eliminate the typo 2020-09-14 16:20:40 -07:00
journal.c update all copyright headers to eliminate the typo 2020-09-14 16:20:40 -07:00
kasp.c Fix kasp min key size bug 2020-10-02 09:20:40 +02:00
key.c update all copyright headers to eliminate the typo 2020-09-14 16:20:40 -07:00
keydata.c update all copyright headers to eliminate the typo 2020-09-14 16:20:40 -07:00
keymgr.c Use explicit result codes for 'rndc dnssec' cmd 2020-10-05 10:53:46 +02:00
keytable.c Add missing rwlock calls when access keynode.initial and keynode.managed 2020-10-01 17:26:09 +10:00
lib.c update all copyright headers to eliminate the typo 2020-09-14 16:20:40 -07:00
log.c update all copyright headers to eliminate the typo 2020-09-14 16:20:40 -07:00
lookup.c update all copyright headers to eliminate the typo 2020-09-14 16:20:40 -07:00
Makefile.am Use libuv's shared library handling capabilities 2020-10-28 15:48:58 +01:00
master.c update all copyright headers to eliminate the typo 2020-09-14 16:20:40 -07:00
masterdump.c rndc dumpdb -expired: print when RRsets expired 2020-09-23 16:09:26 +02:00
message.c Check that sig0 name is the root. 2020-09-30 13:24:29 +00:00
name.c update all copyright headers to eliminate the typo 2020-09-14 16:20:40 -07:00
ncache.c update all copyright headers to eliminate the typo 2020-09-14 16:20:40 -07:00
nsec.c update all copyright headers to eliminate the typo 2020-09-14 16:20:40 -07:00
nsec3.c update all copyright headers to eliminate the typo 2020-09-14 16:20:40 -07:00
nta.c Call nta_detach() before dns_view_weakdetach() so view is available. 2020-11-03 12:29:04 +00:00
openssl_link.c update all copyright headers to eliminate the typo 2020-09-14 16:20:40 -07:00
openssldh_link.c update all copyright headers to eliminate the typo 2020-09-14 16:20:40 -07:00
opensslecdsa_link.c update all copyright headers to eliminate the typo 2020-09-14 16:20:40 -07:00
openssleddsa_link.c update all copyright headers to eliminate the typo 2020-09-14 16:20:40 -07:00
opensslrsa_link.c update all copyright headers to eliminate the typo 2020-09-14 16:20:40 -07:00
order.c Allow "order none" in "rrset-order" rules 2020-10-02 08:41:43 +02:00
peer.c update all copyright headers to eliminate the typo 2020-09-14 16:20:40 -07:00
pkcs11.c update all copyright headers to eliminate the typo 2020-09-14 16:20:40 -07:00
pkcs11ecdsa_link.c update all copyright headers to eliminate the typo 2020-09-14 16:20:40 -07:00
pkcs11eddsa_link.c update all copyright headers to eliminate the typo 2020-09-14 16:20:40 -07:00
pkcs11rsa_link.c update all copyright headers to eliminate the typo 2020-09-14 16:20:40 -07:00
private.c update all copyright headers to eliminate the typo 2020-09-14 16:20:40 -07:00
rbt.c Fix build with DEBUG defined (-DDEBUG) 2020-11-06 12:20:41 +02:00
rbtdb.c Add stale-refresh-time option 2020-11-11 12:53:23 -03:00
rbtdb.h update all copyright headers to eliminate the typo 2020-09-14 16:20:40 -07:00
rcode.c update all copyright headers to eliminate the typo 2020-09-14 16:20:40 -07:00
rdata.c update all copyright headers to eliminate the typo 2020-09-14 16:20:40 -07:00
rdatalist.c update all copyright headers to eliminate the typo 2020-09-14 16:20:40 -07:00
rdatalist_p.h update all copyright headers to eliminate the typo 2020-09-14 16:20:40 -07:00
rdataset.c update all copyright headers to eliminate the typo 2020-09-14 16:20:40 -07:00
rdatasetiter.c update all copyright headers to eliminate the typo 2020-09-14 16:20:40 -07:00
rdataslab.c update all copyright headers to eliminate the typo 2020-09-14 16:20:40 -07:00
request.c update all copyright headers to eliminate the typo 2020-09-14 16:20:40 -07:00
resolver.c remove fctx:id field 2020-11-06 01:54:44 +00:00
result.c Use explicit result codes for 'rndc dnssec' cmd 2020-10-05 10:53:46 +02:00
rootns.c update all copyright headers to eliminate the typo 2020-09-14 16:20:40 -07:00
rpz.c Fix updating summary RPZ DB for mixed-case RPZs 2020-09-21 09:28:36 +02:00
rriterator.c update all copyright headers to eliminate the typo 2020-09-14 16:20:40 -07:00
rrl.c update all copyright headers to eliminate the typo 2020-09-14 16:20:40 -07:00
sdb.c Add stale-refresh-time option 2020-11-11 12:53:23 -03:00
sdlz.c Add stale-refresh-time option 2020-11-11 12:53:23 -03:00
soa.c update all copyright headers to eliminate the typo 2020-09-14 16:20:40 -07:00
ssu.c update all copyright headers to eliminate the typo 2020-09-14 16:20:40 -07:00
ssu_external.c update all copyright headers to eliminate the typo 2020-09-14 16:20:40 -07:00
stats.c Update comments to have binary notation 2020-09-29 10:36:07 +10:00
tcpmsg.c update all copyright headers to eliminate the typo 2020-09-14 16:20:40 -07:00
time.c update all copyright headers to eliminate the typo 2020-09-14 16:20:40 -07:00
timer.c update all copyright headers to eliminate the typo 2020-09-14 16:20:40 -07:00
tkey.c update all copyright headers to eliminate the typo 2020-09-14 16:20:40 -07:00
tsec.c update all copyright headers to eliminate the typo 2020-09-14 16:20:40 -07:00
tsig.c update all copyright headers to eliminate the typo 2020-09-14 16:20:40 -07:00
tsig_p.h update all copyright headers to eliminate the typo 2020-09-14 16:20:40 -07:00
ttl.c update all copyright headers to eliminate the typo 2020-09-14 16:20:40 -07:00
update.c update all copyright headers to eliminate the typo 2020-09-14 16:20:40 -07:00
validator.c Handle DNS_R_NCACHENXRRSET in fetch_callback_{dnskey,validator}() 2020-10-30 00:17:24 +11:00
view.c Address lock order inversions. 2020-09-23 01:13:28 +00:00
xfrin.c address some possible shutdown races in xfrin 2020-11-09 12:33:37 -08:00
zone.c Lock zone before calling zone_namerd_tostr() 2020-11-10 15:56:13 +11:00
zone_p.h update all copyright headers to eliminate the typo 2020-09-14 16:20:40 -07:00
zonekey.c update all copyright headers to eliminate the typo 2020-09-14 16:20:40 -07:00
zoneverify.c update all copyright headers to eliminate the typo 2020-09-14 16:20:40 -07:00
zt.c update all copyright headers to eliminate the typo 2020-09-14 16:20:40 -07:00