2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-22 01:59:26 +00:00

Add DNS_SLABTOP_FOREACH family of macros

Add family of foreach macros to iterate through the dns_slabtop_t
single-linked lists.
This commit is contained in:
Ondřej Surý 2025-08-21 08:56:29 +02:00
parent 4320bb7203
commit e9f1e2a116
No known key found for this signature in database
GPG Key ID: 2820F37E873DEA41
4 changed files with 42 additions and 44 deletions

View File

@ -79,7 +79,7 @@ PenaltyBreakString: 80
PenaltyExcessCharacter: 100 PenaltyExcessCharacter: 100
Standard: Cpp11 Standard: Cpp11
ContinuationIndentWidth: 8 ContinuationIndentWidth: 8
ForEachMacros: [ 'cds_lfs_for_each', 'cds_lfs_for_each_safe', 'cds_list_for_each_entry_safe', 'ISC_LIST_FOREACH', 'ISC_LIST_FOREACH_SAFE', 'ISC_LIST_FOREACH_REV', 'ISC_LIST_FOREACH_REV_SAFE', 'MSG_SECTION_FOREACH', 'DNS_DBITERATOR_FOREACH', 'DNS_RDATASET_FOREACH', 'DNS_RDATASETITER_FOREACH', 'CFG_LIST_FOREACH' ] ForEachMacros: [ 'cds_lfs_for_each', 'cds_lfs_for_each_safe', 'cds_list_for_each_entry_safe', 'ISC_LIST_FOREACH', 'ISC_LIST_FOREACH_SAFE', 'ISC_LIST_FOREACH_REV', 'ISC_LIST_FOREACH_REV_SAFE', 'MSG_SECTION_FOREACH', 'DNS_DBITERATOR_FOREACH', 'DNS_RDATASET_FOREACH', 'DNS_RDATASETITER_FOREACH', 'CFG_LIST_FOREACH', 'DNS_SLABTOP_FOREACH', 'DNS_SLABTOP_FOREACH_SAFE', 'DNS_SLABTOP_FOREACH_NEXT' ]
RemoveParentheses: ReturnStatement RemoveParentheses: ReturnStatement
RemoveSemicolon: true RemoveSemicolon: true
SpaceBeforeParens: ControlStatementsExceptControlMacros SpaceBeforeParens: ControlStatementsExceptControlMacros

View File

@ -64,6 +64,17 @@ struct dns_slabheader_proof {
dns_rdatatype_t type; dns_rdatatype_t type;
}; };
#define DNS_SLABTOP_FOREACH(node, elt) \
for (elt = (node)->data; elt != NULL; elt = elt->next)
#define DNS_SLABTOP_FOREACH_NEXT(elt, elt_next) \
for (elt = elt_next; elt != NULL; elt = elt->next)
#define DNS_SLABTOP_FOREACH_SAFE(node, elt, elt_next) \
for (elt = (node)->data, elt_next = (elt != NULL) ? elt->next : NULL; \
elt != NULL; \
elt = elt_next, elt_next = (elt != NULL) ? elt->next : NULL)
typedef struct dns_slabtop dns_slabtop_t; typedef struct dns_slabtop dns_slabtop_t;
struct dns_slabtop { struct dns_slabtop {
dns_slabtop_t *next; dns_slabtop_t *next;

View File

@ -565,8 +565,7 @@ clean_cache_node(qpcache_t *qpdb, qpcnode_t *node) {
* Caller must be holding the node lock. * Caller must be holding the node lock.
*/ */
for (top = node->data; top != NULL; top = top_next) { DNS_SLABTOP_FOREACH_SAFE(node, top, top_next) {
top_next = top->next;
clean_stale_headers(top->header); clean_stale_headers(top->header);
/* /*
@ -1289,7 +1288,7 @@ check_zonecut(qpcnode_t *node, void *arg DNS__DB_FLARG) {
/* /*
* Look for a DNAME or RRSIG DNAME rdataset. * Look for a DNAME or RRSIG DNAME rdataset.
*/ */
for (top = node->data; top != NULL; top = top->next) { DNS_SLABTOP_FOREACH(node, top) {
if (check_stale_header(top->header, search)) { if (check_stale_header(top->header, search)) {
continue; continue;
} }
@ -1352,7 +1351,7 @@ find_deepest_zonecut(qpc_search_t *search, qpcnode_t *node,
/* /*
* Look for NS and RRSIG NS rdatasets. * Look for NS and RRSIG NS rdatasets.
*/ */
for (top = node->data; top != NULL; top = top->next) { DNS_SLABTOP_FOREACH(node, top) {
if (check_stale_header(top->header, search)) { if (check_stale_header(top->header, search)) {
continue; continue;
} }
@ -1456,7 +1455,7 @@ find_coveringnsec(qpc_search_t *search, const dns_name_t *name,
nlock = &search->qpdb->buckets[node->locknum].lock; nlock = &search->qpdb->buckets[node->locknum].lock;
NODE_RDLOCK(nlock, &nlocktype); NODE_RDLOCK(nlock, &nlocktype);
for (top = node->data; top != NULL; top = top->next) { DNS_SLABTOP_FOREACH(node, top) {
if (check_stale_header(top->header, search)) { if (check_stale_header(top->header, search)) {
continue; continue;
} }
@ -1657,7 +1656,7 @@ qpcache_find(dns_db_t *db, const dns_name_t *name, dns_dbversion_t *version,
nsecsig = NULL; nsecsig = NULL;
cnamesig = NULL; cnamesig = NULL;
empty_node = true; empty_node = true;
for (top = node->data; top != NULL; top = top->next) { DNS_SLABTOP_FOREACH(node, top) {
if (check_stale_header(top->header, &search)) { if (check_stale_header(top->header, &search)) {
continue; continue;
} }
@ -1924,7 +1923,7 @@ seek_ns_headers(qpc_search_t *search, qpcnode_t *node, dns_dbnode_t **nodep,
NODE_RDLOCK(nlock, &nlocktype); NODE_RDLOCK(nlock, &nlocktype);
for (top = node->data; top != NULL; top = top->next) { DNS_SLABTOP_FOREACH(node, top) {
bool ns = top->typepair == DNS_TYPEPAIR(dns_rdatatype_ns) || bool ns = top->typepair == DNS_TYPEPAIR(dns_rdatatype_ns) ||
top->typepair == DNS_SIGTYPEPAIR(dns_rdatatype_ns); top->typepair == DNS_SIGTYPEPAIR(dns_rdatatype_ns);
if (check_stale_header(top->header, search)) { if (check_stale_header(top->header, search)) {
@ -2095,7 +2094,7 @@ qpcache_findrdataset(dns_db_t *db, dns_dbnode_t *node, dns_dbversion_t *version,
sigpair = !dns_rdatatype_issig(type) ? DNS_SIGTYPEPAIR(type) sigpair = !dns_rdatatype_issig(type) ? DNS_SIGTYPEPAIR(type)
: dns_typepair_none; : dns_typepair_none;
for (top = qpnode->data; top != NULL; top = top->next) { DNS_SLABTOP_FOREACH(qpnode, top) {
if (check_stale_header(top->header, &search)) { if (check_stale_header(top->header, &search)) {
continue; continue;
} }
@ -2586,9 +2585,7 @@ add(qpcache_t *qpdb, qpcnode_t *qpnode, dns_slabheader_t *newheader,
* only rdataset that can be found at this * only rdataset that can be found at this
* node is the negative cache entry. * node is the negative cache entry.
*/ */
for (top = qpnode->data; top != NULL; DNS_SLABTOP_FOREACH(qpnode, top) {
top = top->next)
{
mark_ancient(top->header); mark_ancient(top->header);
} }
goto find_header; goto find_header;
@ -2601,9 +2598,7 @@ add(qpcache_t *qpdb, qpcnode_t *qpnode, dns_slabheader_t *newheader,
* ancient. * ancient.
*/ */
for (top = qpnode->data; top != NULL; DNS_SLABTOP_FOREACH(qpnode, top) {
top = top->next)
{
if (rdtype == if (rdtype ==
DNS_TYPEPAIR_TYPE(top->typepair)) DNS_TYPEPAIR_TYPE(top->typepair))
{ {
@ -2617,7 +2612,7 @@ add(qpcache_t *qpdb, qpcnode_t *qpnode, dns_slabheader_t *newheader,
* Otherwise look for any RRSIGs of the given * Otherwise look for any RRSIGs of the given
* type so they can be marked ancient later. * type so they can be marked ancient later.
*/ */
for (top = qpnode->data; top != NULL; top = top->next) { DNS_SLABTOP_FOREACH(qpnode, top) {
if (top->typepair == sigpair) { if (top->typepair == sigpair) {
sigheader = top->header; sigheader = top->header;
break; break;
@ -2628,7 +2623,7 @@ add(qpcache_t *qpdb, qpcnode_t *qpnode, dns_slabheader_t *newheader,
* We're adding something that isn't a * We're adding something that isn't a
* negative cache entry. * negative cache entry.
*/ */
for (top = qpnode->data; top != NULL; top = top->next) { DNS_SLABTOP_FOREACH(qpnode, top) {
/* /*
* Look for any existing negative cache * Look for any existing negative cache
* entries. * entries.
@ -2684,7 +2679,7 @@ add(qpcache_t *qpdb, qpcnode_t *qpnode, dns_slabheader_t *newheader,
} }
} }
for (top = qpnode->data; top != NULL; top = top->next) { DNS_SLABTOP_FOREACH(qpnode, top) {
if (ACTIVE(top->header, now)) { if (ACTIVE(top->header, now)) {
++ntypes; ++ntypes;
expiretop = top; expiretop = top;
@ -3348,7 +3343,7 @@ rdatasetiter_first(dns_rdatasetiter_t *it DNS__DB_FLARG) {
NODE_RDLOCK(nlock, &nlocktype); NODE_RDLOCK(nlock, &nlocktype);
for (top = qpnode->data; top != NULL; top = top->next) { DNS_SLABTOP_FOREACH(qpnode, top) {
if (EXISTS(top->header) && if (EXISTS(top->header) &&
(EXPIREDOK(iterator) || (EXPIREDOK(iterator) ||
iterator_active(qpdb, iterator, top->header))) iterator_active(qpdb, iterator, top->header)))
@ -3384,7 +3379,7 @@ rdatasetiter_next(dns_rdatasetiter_t *it DNS__DB_FLARG) {
NODE_RDLOCK(nlock, &nlocktype); NODE_RDLOCK(nlock, &nlocktype);
for (top = top->next; top != NULL; top = top->next) { DNS_SLABTOP_FOREACH_NEXT(top, top->next) {
if (EXISTS(top->header) && if (EXISTS(top->header) &&
(EXPIREDOK(iterator) || (EXPIREDOK(iterator) ||
iterator_active(qpdb, iterator, top->header))) iterator_active(qpdb, iterator, top->header)))
@ -3862,9 +3857,7 @@ qpcnode_destroy(qpcnode_t *qpnode) {
dns_slabtop_t *top = NULL, *top_next = NULL; dns_slabtop_t *top = NULL, *top_next = NULL;
qpcache_t *qpdb = qpnode->qpdb; qpcache_t *qpdb = qpnode->qpdb;
for (top = qpnode->data; top != NULL; top = top_next) { DNS_SLABTOP_FOREACH_SAFE(qpnode, top, top_next) {
top_next = top->next;
dns_slabheader_t *down = NULL, *down_next = NULL; dns_slabheader_t *down = NULL, *down_next = NULL;
for (down = top->header; down != NULL; down = down_next) { for (down = top->header; down != NULL; down = down_next) {
down_next = down->down; down_next = down->down;

View File

@ -822,9 +822,7 @@ clean_zone_node(qpznode_t *node, uint32_t least_serial) {
*/ */
REQUIRE(least_serial != 0); REQUIRE(least_serial != 0);
for (top = node->data; top != NULL; top = top_next) { DNS_SLABTOP_FOREACH_SAFE(node, top, top_next) {
top_next = top->next;
INSIST(top->header != NULL); INSIST(top->header != NULL);
/* /*
@ -1293,7 +1291,7 @@ rollback_node(qpznode_t *node, uint32_t serial) {
* 'serial'. When the reference count goes to zero, these rdatasets * 'serial'. When the reference count goes to zero, these rdatasets
* will be cleaned up; until that time, they will be ignored. * will be cleaned up; until that time, they will be ignored.
*/ */
for (top = node->data; top != NULL; top = top->next) { DNS_SLABTOP_FOREACH(node, top) {
dns_slabheader_t *header = top->header; dns_slabheader_t *header = top->header;
if (header->serial == serial) { if (header->serial == serial) {
@ -1587,7 +1585,7 @@ qpzone_findrdataset(dns_db_t *db, dns_dbnode_t *dbnode,
sigpair = dns_typepair_none; sigpair = dns_typepair_none;
} }
for (top = node->data; top != NULL; top = top->next) { DNS_SLABTOP_FOREACH(node, top) {
dns_slabheader_t *header = top->header; dns_slabheader_t *header = top->header;
do { do {
if (header->serial <= serial && !IGNORE(header)) { if (header->serial <= serial && !IGNORE(header)) {
@ -1715,7 +1713,7 @@ cname_and_other(qpznode_t *node, uint32_t serial) {
* ("Other data" is any rdataset whose type is not KEY, NSEC, SIG * ("Other data" is any rdataset whose type is not KEY, NSEC, SIG
* or RRSIG. * or RRSIG.
*/ */
for (top = node->data; top != NULL; top = top->next) { DNS_SLABTOP_FOREACH(node, top) {
dns_slabheader_t *header = top->header; dns_slabheader_t *header = top->header;
rdtype = DNS_TYPEPAIR_TYPE(top->typepair); rdtype = DNS_TYPEPAIR_TYPE(top->typepair);
@ -1842,7 +1840,7 @@ add(qpzonedb_t *qpdb, qpznode_t *node, const dns_name_t *nodename,
} }
ntypes = 0; ntypes = 0;
for (top = node->data; top != NULL; top = top->next) { DNS_SLABTOP_FOREACH(node, top) {
++ntypes; ++ntypes;
if (prio_type(top->typepair)) { if (prio_type(top->typepair)) {
priotop = top; priotop = top;
@ -2677,7 +2675,7 @@ step(qpz_search_t *search, dns_qpiter_t *it, direction_t direction,
dns_slabheader_t *found = NULL; dns_slabheader_t *found = NULL;
NODE_RDLOCK(nlock, &nlocktype); NODE_RDLOCK(nlock, &nlocktype);
for (top = node->data; top != NULL; top = top->next) { DNS_SLABTOP_FOREACH(node, top) {
dns_slabheader_t *header = top->header; dns_slabheader_t *header = top->header;
while (header != NULL && while (header != NULL &&
(IGNORE(header) || (IGNORE(header) ||
@ -2839,7 +2837,7 @@ find_wildcard(qpz_search_t *search, qpznode_t **nodep, const dns_name_t *qname,
* may not need the information, because it simplifies the * may not need the information, because it simplifies the
* locking and code flow. * locking and code flow.
*/ */
for (top = node->data; top != NULL; top = top->next) { DNS_SLABTOP_FOREACH(node, top) {
dns_slabheader_t *header = top->header; dns_slabheader_t *header = top->header;
if (header->serial <= search->serial && if (header->serial <= search->serial &&
!IGNORE(header) && EXISTS(header)) !IGNORE(header) && EXISTS(header))
@ -2879,9 +2877,7 @@ find_wildcard(qpz_search_t *search, qpznode_t **nodep, const dns_name_t *qname,
*/ */
nlock = qpzone_get_lock(wnode); nlock = qpzone_get_lock(wnode);
NODE_RDLOCK(nlock, &nlocktype); NODE_RDLOCK(nlock, &nlocktype);
for (top = wnode->data; top != NULL; DNS_SLABTOP_FOREACH(wnode, top) {
top = top->next)
{
dns_slabheader_t *header = top->header; dns_slabheader_t *header = top->header;
if (header->serial <= search->serial && if (header->serial <= search->serial &&
!IGNORE(header) && EXISTS(header)) !IGNORE(header) && EXISTS(header))
@ -3061,7 +3057,7 @@ again:
isc_rwlock_t *nlock = qpzone_get_lock(node); isc_rwlock_t *nlock = qpzone_get_lock(node);
NODE_RDLOCK(nlock, &nlocktype); NODE_RDLOCK(nlock, &nlocktype);
empty_node = true; empty_node = true;
for (top = node->data; top != NULL; top = top->next) { DNS_SLABTOP_FOREACH(node, top) {
dns_slabheader_t *header = top->header; dns_slabheader_t *header = top->header;
/* /*
* Look for an active, extant NSEC or RRSIG NSEC. * Look for an active, extant NSEC or RRSIG NSEC.
@ -3205,7 +3201,7 @@ qpzone_check_zonecut(qpznode_t *node, void *arg DNS__DB_FLARG) {
/* /*
* Look for an NS or DNAME rdataset active in our version. * Look for an NS or DNAME rdataset active in our version.
*/ */
for (top = node->data; top != NULL; top = top->next) { DNS_SLABTOP_FOREACH(node, top) {
dns_slabheader_t *header = top->header; dns_slabheader_t *header = top->header;
if (top->typepair == DNS_TYPEPAIR(dns_rdatatype_ns) || if (top->typepair == DNS_TYPEPAIR(dns_rdatatype_ns) ||
top->typepair == DNS_TYPEPAIR(dns_rdatatype_dname) || top->typepair == DNS_TYPEPAIR(dns_rdatatype_dname) ||
@ -3536,7 +3532,7 @@ found:
sigpair = DNS_SIGTYPEPAIR(type); sigpair = DNS_SIGTYPEPAIR(type);
empty_node = true; empty_node = true;
for (top = node->data; top != NULL; top = top->next) { DNS_SLABTOP_FOREACH(node, top) {
dns_slabheader_t *header = top->header; dns_slabheader_t *header = top->header;
/* /*
* Look for an active, extant rdataset. * Look for an active, extant rdataset.
@ -4049,7 +4045,7 @@ rdatasetiter_first(dns_rdatasetiter_t *iterator DNS__DB_FLARG) {
NODE_RDLOCK(nlock, &nlocktype); NODE_RDLOCK(nlock, &nlocktype);
for (top = node->data; top != NULL; top = top->next) { DNS_SLABTOP_FOREACH(node, top) {
dns_slabheader_t *header = top->header; dns_slabheader_t *header = top->header;
while (header != NULL && while (header != NULL &&
(IGNORE(header) || header->serial > version->serial)) (IGNORE(header) || header->serial > version->serial))
@ -4094,7 +4090,7 @@ rdatasetiter_next(dns_rdatasetiter_t *iterator DNS__DB_FLARG) {
/* /*
* Find the start of the header chain for the next type. * Find the start of the header chain for the next type.
*/ */
for (top = top->next; top != NULL; top = top->next) { DNS_SLABTOP_FOREACH_NEXT(top, top->next) {
dns_slabheader_t *header = top->header; dns_slabheader_t *header = top->header;
while (header != NULL && while (header != NULL &&
(IGNORE(header) || header->serial > version->serial)) (IGNORE(header) || header->serial > version->serial))
@ -4881,7 +4877,7 @@ qpzone_subtractrdataset(dns_db_t *db, dns_dbnode_t *dbnode,
NODE_WRLOCK(nlock, &nlocktype); NODE_WRLOCK(nlock, &nlocktype);
changed = add_changed(qpdb, newheader, version DNS__DB_FLARG_PASS); changed = add_changed(qpdb, newheader, version DNS__DB_FLARG_PASS);
for (top = node->data; top != NULL; top = top->next) { DNS_SLABTOP_FOREACH(node, top) {
if (top->typepair == newheader->typepair) { if (top->typepair == newheader->typepair) {
break; break;
} }
@ -5435,9 +5431,7 @@ static void
destroy_qpznode(qpznode_t *node) { destroy_qpznode(qpznode_t *node) {
dns_slabtop_t *top = NULL, *top_next = NULL; dns_slabtop_t *top = NULL, *top_next = NULL;
for (top = node->data; top != NULL; top = top_next) { DNS_SLABTOP_FOREACH_SAFE(node, top, top_next) {
top_next = top->next;
dns_slabheader_t *down = NULL, *down_next = NULL; dns_slabheader_t *down = NULL, *down_next = NULL;
for (down = top->header; down != NULL; down = down_next) { for (down = top->header; down != NULL; down = down_next) {
down_next = down->down; down_next = down->down;