2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-30 05:57:52 +00:00

Refactor check_stale_header() function

The check_stale_header() function now updates header_prev directly
so it doesn't have to be handled in the outer loop; it's always
set to the correct value of the previous header in the chain.
This commit is contained in:
Ondřej Surý 2025-02-02 19:21:44 +01:00 committed by Evan Hunt
parent b24981ea02
commit 53d9ef5bd0

View File

@ -1196,9 +1196,12 @@ static bool
check_stale_header(qpcnode_t *node, dns_slabheader_t *header,
isc_rwlocktype_t *nlocktypep, isc_rwlock_t *nlock,
qpc_search_t *search, dns_slabheader_t **header_prev) {
if (!ACTIVE(header, search->now)) {
dns_ttl_t stale = header->expire +
STALE_TTL(header, search->qpdb);
if (ACTIVE(header, search->now)) {
*header_prev = header;
return false;
}
isc_stdtime_t stale = header->expire + STALE_TTL(header, search->qpdb);
/*
* If this data is in the stale window keep it and if
* DNS_DBFIND_STALEOK is not set we tell the caller to
@ -1207,8 +1210,7 @@ check_stale_header(qpcnode_t *node, dns_slabheader_t *header,
*/
DNS_SLABHEADER_CLRATTR(header, DNS_SLABHEADERATTR_STALE_WINDOW);
if (!ZEROTTL(header) && KEEPSTALE(search->qpdb) &&
stale > search->now)
if (!ZEROTTL(header) && KEEPSTALE(search->qpdb) && stale > search->now)
{
mark(header, DNS_SLABHEADERATTR_STALE);
*header_prev = header;
@ -1219,11 +1221,9 @@ check_stale_header(qpcnode_t *node, dns_slabheader_t *header,
* failed.
*/
if ((search->options & DNS_DBFIND_STALESTART) != 0) {
atomic_store_release(
&header->last_refresh_fail_ts,
atomic_store_release(&header->last_refresh_fail_ts,
search->now);
} else if ((search->options &
DNS_DBFIND_STALEENABLED) != 0 &&
} else if ((search->options & DNS_DBFIND_STALEENABLED) != 0 &&
search->now <
(atomic_load_acquire(
&header->last_refresh_fail_ts) +
@ -1235,13 +1235,10 @@ check_stale_header(qpcnode_t *node, dns_slabheader_t *header,
* then don't skip this stale entry but use it
* instead.
*/
DNS_SLABHEADER_SETATTR(
header,
DNS_SLABHEADER_SETATTR(header,
DNS_SLABHEADERATTR_STALE_WINDOW);
return false;
} else if ((search->options &
DNS_DBFIND_STALETIMEOUT) != 0)
{
} else if ((search->options & DNS_DBFIND_STALETIMEOUT) != 0) {
/*
* We want stale RRset due to timeout, so we
* don't skip it.
@ -1286,8 +1283,6 @@ check_stale_header(qpcnode_t *node, dns_slabheader_t *header,
}
return true;
}
return false;
}
static isc_result_t
check_zonecut(qpcnode_t *node, void *arg DNS__DB_FLARG) {
@ -1312,19 +1307,17 @@ check_zonecut(qpcnode_t *node, void *arg DNS__DB_FLARG) {
if (check_stale_header(node, header, &nlocktype, nlock, search,
&header_prev))
{
/* Do nothing. */
} else if (header->type == dns_rdatatype_dname &&
EXISTS(header) && !ANCIENT(header))
continue;
}
if (header->type == dns_rdatatype_dname && EXISTS(header) &&
!ANCIENT(header))
{
dname_header = header;
header_prev = header;
} else if (header->type == DNS_SIGTYPE(dns_rdatatype_dname) &&
EXISTS(header) && !ANCIENT(header))
{
sigdname_header = header;
header_prev = header;
} else {
header_prev = header;
}
}
@ -1387,8 +1380,10 @@ find_deepest_zonecut(qpc_search_t *search, qpcnode_t *node,
if (check_stale_header(node, header, &nlocktype, nlock,
search, &header_prev))
{
/* Do nothing. */
} else if (EXISTS(header) && !ANCIENT(header)) {
continue;
}
if (EXISTS(header) && !ANCIENT(header)) {
/*
* We've found an extant rdataset. See if
* we're interested in it.
@ -1406,9 +1401,6 @@ find_deepest_zonecut(qpc_search_t *search, qpcnode_t *node,
break;
}
}
header_prev = header;
} else {
header_prev = header;
}
}
@ -1533,8 +1525,8 @@ find_coveringnsec(qpc_search_t *search, const dns_name_t *name,
{
continue;
}
if (!EXISTS(header) || DNS_TYPEPAIR_TYPE(header->type) == 0) {
header_prev = header;
continue;
}
if (header->type == matchtype) {
@ -1548,7 +1540,6 @@ find_coveringnsec(qpc_search_t *search, const dns_name_t *name,
break;
}
}
header_prev = header;
}
if (found != NULL) {
bindrdataset(search->qpdb, node, found, search->now, nlocktype,
@ -1724,8 +1715,10 @@ qpcache_find(dns_db_t *db, const dns_name_t *name, dns_dbversion_t *version,
if (check_stale_header(node, header, &nlocktype, nlock, &search,
&header_prev))
{
/* Do nothing. */
} else if (EXISTS(header) && !ANCIENT(header)) {
continue;
}
if (EXISTS(header) && !ANCIENT(header)) {
/*
* We now know that there is at least one active
* non-stale rdataset at this node.
@ -1811,9 +1804,6 @@ qpcache_find(dns_db_t *db, const dns_name_t *name, dns_dbversion_t *version,
*/
cnamesig = header;
}
header_prev = header;
} else {
header_prev = header;
}
}
@ -2110,7 +2100,10 @@ qpcache_findzonecut(dns_db_t *db, const dns_name_t *name, unsigned int options,
*/
break;
}
} else if (EXISTS(header) && !ANCIENT(header)) {
continue;
}
if (EXISTS(header) && !ANCIENT(header)) {
if (header->type == dns_rdatatype_ns) {
found = header;
if (foundsig != NULL) {
@ -2124,9 +2117,6 @@ qpcache_findzonecut(dns_db_t *db, const dns_name_t *name, unsigned int options,
break;
}
}
header_prev = header;
} else {
header_prev = header;
}
}