From: Diego Fronza Date: Sat, 28 Nov 2020 21:10:35 +0000 (-0300) Subject: Added dns_view_staleanswerenabled() function X-Git-Tag: v9.17.10~24^2~11 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=74840ec50befe691261b46e4f919448587f993b7;p=thirdparty%2Fbind9.git Added dns_view_staleanswerenabled() function Since it takes a couple lines of code to check whether stale answers are enabled for a given view, code was extracted out to a proper function. --- diff --git a/lib/dns/include/dns/view.h b/lib/dns/include/dns/view.h index ff72c8b758f..1da372a89a7 100644 --- a/lib/dns/include/dns/view.h +++ b/lib/dns/include/dns/view.h @@ -1343,6 +1343,15 @@ dns_view_setviewrevert(dns_view_t *view); *\li 'view' to be valid. */ +bool +dns_view_staleanswerenabled(dns_view_t *view); +/*%< + * Check if stale answers are enabled for this view. + * + * Requires: + *\li 'view' to be valid. + */ + ISC_LANG_ENDDECLS #endif /* DNS_VIEW_H */ diff --git a/lib/dns/view.c b/lib/dns/view.c index 42c17dc6dae..3572cec04a7 100644 --- a/lib/dns/view.c +++ b/lib/dns/view.c @@ -2518,3 +2518,25 @@ dns_view_setviewrevert(dns_view_t *view) { dns_zt_setviewrevert(zonetable); } } + +bool +dns_view_staleanswerenabled(dns_view_t *view) { + uint32_t stale_ttl = 0; + bool result = false; + + REQUIRE(DNS_VIEW_VALID(view)); + + if (dns_db_getservestalettl(view->cachedb, &stale_ttl) != ISC_R_SUCCESS) + { + return (false); + } + if (stale_ttl > 0) { + if (view->staleanswersok == dns_stale_answer_yes) { + result = true; + } else if (view->staleanswersok == dns_stale_answer_conf) { + result = view->staleanswersenable; + } + } + + return (result); +} diff --git a/lib/dns/win32/libdns.def.in b/lib/dns/win32/libdns.def.in index c9b4e1fe800..917484d1ec1 100644 --- a/lib/dns/win32/libdns.def.in +++ b/lib/dns/win32/libdns.def.in @@ -1147,6 +1147,7 @@ dns_view_setrootdelonly dns_view_setviewcommit dns_view_setviewrevert dns_view_simplefind +dns_view_staleanswerenabled dns_view_thaw dns_view_untrust dns_view_weakattach diff --git a/lib/ns/query.c b/lib/ns/query.c index ae0a7bef4b6..a8712f3a993 100644 --- a/lib/ns/query.c +++ b/lib/ns/query.c @@ -5581,7 +5581,6 @@ query_lookup(query_ctx_t *qctx) { dns_clientinfo_t ci; dns_name_t *rpzqname = NULL; unsigned int dboptions; - dns_ttl_t stale_ttl = 0; dns_ttl_t stale_refresh = 0; bool dbfind_stale = false; @@ -5644,18 +5643,9 @@ query_lookup(query_ctx_t *qctx) { (void)dns_db_getservestalerefresh(qctx->client->view->cachedb, &stale_refresh); - (void)dns_db_getservestalettl(qctx->client->view->cachedb, &stale_ttl); - if (stale_refresh > 0) { - if (qctx->client->view->staleanswersok == dns_stale_answer_yes) - { - dboptions |= DNS_DBFIND_STALEENABLED; - } else if (qctx->client->view->staleanswersok == - dns_stale_answer_conf) { - if (qctx->client->view->staleanswersenable && - stale_ttl > 0) { - dboptions |= DNS_DBFIND_STALEENABLED; - } - } + if (stale_refresh > 0 && + dns_view_staleanswerenabled(qctx->client->view)) { + dboptions |= DNS_DBFIND_STALEENABLED; } result = dns_db_findext(qctx->db, rpzqname, qctx->version, qctx->type,