bind9/lib/ns
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 Cleanup duplicate definitions in query.h 2020-11-10 14:42:47 +00:00
tests use netmgr for xfrin 2020-11-09 13:45:43 +01:00
win32 Add libssl libraries to Windows build 2020-11-09 16:00:28 +01:00
api Update library API versions 2020-10-22 08:54:32 +02:00
client.c Fix a startup/shutdown crash in ns_clientmgr_create 2020-11-10 14:17:05 +01:00
hooks.c Use libuv's shared library handling capabilities 2020-10-28 15:48:58 +01:00
interfacemgr.c Shutdown interface if we can't listen on it to avoid shutdown hang 2020-11-10 14:17:09 +01:00
lib.c update all copyright headers to eliminate the typo 2020-09-14 16:20:40 -07:00
listenlist.c Add DoT support to bind 2020-11-10 14:16:55 +01:00
log.c update all copyright headers to eliminate the typo 2020-09-14 16:20:40 -07:00
Makefile.am Add DoT support to bind 2020-11-10 14:16:55 +01:00
notify.c update all copyright headers to eliminate the typo 2020-09-14 16:20:40 -07:00
query.c Add stale-refresh-time option 2020-11-11 12:53:23 -03:00
server.c Simplify the EDNS buffer size logic for DNS Flag Day 2020 2020-10-05 16:21:21 +02:00
sortlist.c update all copyright headers to eliminate the typo 2020-09-14 16:20:40 -07:00
stats.c update all copyright headers to eliminate the typo 2020-09-14 16:20:40 -07:00
update.c Refactored dns_message_t for using attach/detach semantics 2020-09-29 08:22:08 +02:00
xfrout.c Fix the isc_nm_closedown() to actually close the pending connections 2020-10-22 11:37:16 -07:00