From 14f880761b2cf0d4f7dd9239758d94a40509b6f5 Mon Sep 17 00:00:00 2001 From: Alessio Podda Date: Sun, 23 Nov 2025 14:59:30 +0100 Subject: [PATCH 1/3] Remove unused foundname parameter The `foundname` parameter in dns_qp_lookup is used only in the unit tests. This commit simplifies the API by removing it, and modifying the unit tests to extract the name from pval. --- lib/dns/forward.c | 2 +- lib/dns/include/dns/qp.h | 2 +- lib/dns/keytable.c | 4 ++-- lib/dns/nametree.c | 2 +- lib/dns/nta.c | 2 +- lib/dns/qp.c | 7 ++----- lib/dns/qp_p.h | 3 +++ lib/dns/qpcache.c | 10 +++++----- lib/dns/qpzone.c | 26 +++++++++++++------------- lib/dns/rpz.c | 2 +- lib/dns/zt.c | 2 +- tests/bench/qplookups.c | 4 ++-- tests/dns/qp_test.c | 18 ++++++++++++++---- 13 files changed, 47 insertions(+), 37 deletions(-) diff --git a/lib/dns/forward.c b/lib/dns/forward.c index 14e296ffe1..795d67f644 100644 --- a/lib/dns/forward.c +++ b/lib/dns/forward.c @@ -163,7 +163,7 @@ dns_fwdtable_find(dns_fwdtable_t *fwdtable, const dns_name_t *name, REQUIRE(VALID_FWDTABLE(fwdtable)); dns_qpmulti_query(fwdtable->table, &qpr); - result = dns_qp_lookup(&qpr, name, DNS_DBNAMESPACE_NORMAL, NULL, NULL, + result = dns_qp_lookup(&qpr, name, DNS_DBNAMESPACE_NORMAL, NULL, NULL, &pval, NULL); if (result == ISC_R_SUCCESS || result == DNS_R_PARTIALMATCH) { dns_forwarders_t *fwdrs = pval; diff --git a/lib/dns/include/dns/qp.h b/lib/dns/include/dns/qp.h index 456cf635a2..2ae5b58ce4 100644 --- a/lib/dns/include/dns/qp.h +++ b/lib/dns/include/dns/qp.h @@ -541,7 +541,7 @@ dns_qp_getname(dns_qpreadable_t qpr, const dns_name_t *name, isc_result_t dns_qp_lookup(dns_qpreadable_t qpr, const dns_name_t *name, - dns_namespace_t space, dns_name_t *foundname, dns_qpiter_t *iter, + dns_namespace_t space, dns_qpiter_t *iter, dns_qpchain_t *chain, void **pval_r, uint32_t *ival_r); /*%< * Look up a leaf in a qp-trie that is equal to, or an ancestor domain of, diff --git a/lib/dns/keytable.c b/lib/dns/keytable.c index 1c04b95132..5890ffdcd6 100644 --- a/lib/dns/keytable.c +++ b/lib/dns/keytable.c @@ -511,7 +511,7 @@ dns_keytable_finddeepestmatch(dns_keytable_t *keytable, const dns_name_t *name, REQUIRE(foundname != NULL); dns_qpmulti_query(keytable->table, &qpr); - result = dns_qp_lookup(&qpr, name, DNS_DBNAMESPACE_NORMAL, NULL, NULL, + result = dns_qp_lookup(&qpr, name, DNS_DBNAMESPACE_NORMAL, NULL, NULL, &pval, NULL); keynode = pval; @@ -541,7 +541,7 @@ dns_keytable_issecuredomain(dns_keytable_t *keytable, const dns_name_t *name, REQUIRE(dns_name_isabsolute(name)); dns_qpmulti_query(keytable->table, &qpr); - result = dns_qp_lookup(&qpr, name, DNS_DBNAMESPACE_NORMAL, NULL, NULL, + result = dns_qp_lookup(&qpr, name, DNS_DBNAMESPACE_NORMAL, NULL, NULL, &pval, NULL); if (result == ISC_R_SUCCESS || result == DNS_R_PARTIALMATCH) { keynode = pval; diff --git a/lib/dns/nametree.c b/lib/dns/nametree.c index 7d67bd0c1c..41387bdf67 100644 --- a/lib/dns/nametree.c +++ b/lib/dns/nametree.c @@ -283,7 +283,7 @@ dns_nametree_covered(dns_nametree_t *nametree, const dns_name_t *name, REQUIRE(VALID_NAMETREE(nametree)); dns_qpmulti_query(nametree->table, &qpr); - result = dns_qp_lookup(&qpr, name, DNS_DBNAMESPACE_NORMAL, NULL, NULL, + result = dns_qp_lookup(&qpr, name, DNS_DBNAMESPACE_NORMAL, NULL, NULL, (void **)&node, NULL); if (result == ISC_R_SUCCESS || result == DNS_R_PARTIALMATCH) { if (found != NULL) { diff --git a/lib/dns/nta.c b/lib/dns/nta.c index e2a20faf8b..2ad9c07ea0 100644 --- a/lib/dns/nta.c +++ b/lib/dns/nta.c @@ -413,7 +413,7 @@ dns_ntatable_covered(dns_ntatable_t *ntatable, isc_stdtime_t now, RWLOCK(&ntatable->rwlock, isc_rwlocktype_read); dns_qpmulti_query(ntatable->table, &qpr); - result = dns_qp_lookup(&qpr, name, DNS_DBNAMESPACE_NORMAL, NULL, NULL, + result = dns_qp_lookup(&qpr, name, DNS_DBNAMESPACE_NORMAL, NULL, NULL, &pval, NULL); nta = pval; diff --git a/lib/dns/qp.c b/lib/dns/qp.c index 625e4675b3..091b691e2f 100644 --- a/lib/dns/qp.c +++ b/lib/dns/qp.c @@ -1857,7 +1857,7 @@ dns_qp_deletename(dns_qp_t *qp, const dns_name_t *name, dns_namespace_t space, /*********************************************************************** * chains */ -static void +void maybe_set_name(dns_qpreader_t *qp, dns_qpnode_t *node, dns_name_t *name) { dns_qpkey_t key; size_t len; @@ -2289,7 +2289,7 @@ fix_chain(dns_qpchain_t *chain, size_t offset) { isc_result_t dns_qp_lookup(dns_qpreadable_t qpr, const dns_name_t *name, - dns_namespace_t space, dns_name_t *foundname, dns_qpiter_t *iter, + dns_namespace_t space, dns_qpiter_t *iter, dns_qpchain_t *chain, void **pval_r, uint32_t *ival_r) { dns_qpreader_t *qp = dns_qpreader(qpr); dns_qpkey_t search, found; @@ -2303,7 +2303,6 @@ dns_qp_lookup(dns_qpreadable_t qpr, const dns_name_t *name, bool setiter = true; REQUIRE(QP_VALID(qp)); - REQUIRE(foundname == NULL || ISC_MAGIC_VALID(name, DNS_NAME_MAGIC)); searchlen = dns_qpkey_fromname(search, name, space); @@ -2406,7 +2405,6 @@ dns_qp_lookup(dns_qpreadable_t qpr, const dns_name_t *name, SET_IF_NOT_NULL(pval_r, leaf_pval(n)); SET_IF_NOT_NULL(ival_r, leaf_ival(n)); - maybe_set_name(qp, n, foundname); return result; } @@ -2420,7 +2418,6 @@ dns_qp_lookup(dns_qpreadable_t qpr, const dns_name_t *name, n = chain->chain[len].node; SET_IF_NOT_NULL(pval_r, leaf_pval(n)); SET_IF_NOT_NULL(ival_r, leaf_ival(n)); - maybe_set_name(qp, n, foundname); return DNS_R_PARTIALMATCH; } else { /* diff --git a/lib/dns/qp_p.h b/lib/dns/qp_p.h index ef9f1e3362..51d2be6ea7 100644 --- a/lib/dns/qp_p.h +++ b/lib/dns/qp_p.h @@ -945,6 +945,9 @@ extern uint8_t dns_qp_byte_for_bit[]; /**********************************************************************/ +void +maybe_set_name(dns_qpreader_t *qp, dns_qpnode_t *node, dns_name_t *name); + void dns__qp_initialize(void); void diff --git a/lib/dns/qpcache.c b/lib/dns/qpcache.c index 52ea84506c..92d00a2595 100644 --- a/lib/dns/qpcache.c +++ b/lib/dns/qpcache.c @@ -1485,7 +1485,7 @@ find_coveringnsec(qpc_search_t *search, const dns_name_t *name, * Look for the node in the auxiliary NSEC namespace. */ result = dns_qp_lookup(search->qpdb->tree, name, DNS_DBNAMESPACE_NSEC, - NULL, &iter, NULL, (void **)&node, NULL); + &iter, NULL, (void **)&node, NULL); /* * When DNS_R_PARTIALMATCH or ISC_R_NOTFOUND is returned from * dns_qp_lookup there is potentially a covering NSEC present @@ -1615,7 +1615,7 @@ qpcache_find(dns_db_t *db, const dns_name_t *name, dns_dbversion_t *version, * Search down from the root of the tree. */ result = dns_qp_lookup(search.qpdb->tree, name, DNS_DBNAMESPACE_NORMAL, - NULL, NULL, &search.chain, (void **)&node, NULL); + NULL, &search.chain, (void **)&node, NULL); if (result != ISC_R_NOTFOUND && foundname != NULL) { dns_name_copy(&node->name, foundname); } @@ -2039,7 +2039,7 @@ qpcache_findzonecut(dns_db_t *db, const dns_name_t *name, unsigned int options, * Search down from the root of the tree. */ result = dns_qp_lookup(search.qpdb->tree, name, DNS_DBNAMESPACE_NORMAL, - NULL, NULL, &search.chain, (void **)&node, NULL); + NULL, &search.chain, (void **)&node, NULL); switch (result) { case ISC_R_SUCCESS: @@ -3515,7 +3515,7 @@ resume_iteration(qpc_dbit_t *qpdbiter, bool continuing) { if (continuing && qpdbiter->node != NULL) { isc_result_t result; result = dns_qp_lookup(qpdb->tree, qpdbiter->name, - DNS_DBNAMESPACE_NORMAL, NULL, + DNS_DBNAMESPACE_NORMAL, &qpdbiter->iter, NULL, NULL, NULL); INSIST(result == ISC_R_SUCCESS); } @@ -3618,7 +3618,7 @@ dbiterator_seek(dns_dbiterator_t *iterator, dereference_iter_node(qpdbiter DNS__DB_FLARG_PASS); - result = dns_qp_lookup(qpdb->tree, name, DNS_DBNAMESPACE_NORMAL, NULL, + result = dns_qp_lookup(qpdb->tree, name, DNS_DBNAMESPACE_NORMAL, &qpdbiter->iter, NULL, (void **)&qpdbiter->node, NULL); diff --git a/lib/dns/qpzone.c b/lib/dns/qpzone.c index 1244426124..405a7c5551 100644 --- a/lib/dns/qpzone.c +++ b/lib/dns/qpzone.c @@ -2872,7 +2872,7 @@ find_wildcard(qpz_search_t *search, qpznode_t **nodep, const dns_name_t *qname, } result = dns_qp_lookup(&search->qpr, wname, nspace, - NULL, &wit, NULL, + &wit, NULL, (void **)&wnode, NULL); if (result == ISC_R_SUCCESS) { /* @@ -2954,7 +2954,7 @@ previous_closest_nsec(dns_rdatatype_t type, qpz_search_t *search, */ *firstp = false; result = dns_qp_lookup(&qpr, name, DNS_DBNAMESPACE_NSEC, - NULL, nit, NULL, NULL, NULL); + nit, NULL, NULL, NULL); INSIST(result != ISC_R_NOTFOUND); if (result == ISC_R_SUCCESS) { /* @@ -2992,7 +2992,7 @@ previous_closest_nsec(dns_rdatatype_t type, qpz_search_t *search, *nodep = NULL; result = dns_qp_lookup( - &search->qpr, name, DNS_DBNAMESPACE_NORMAL, NULL, + &search->qpr, name, DNS_DBNAMESPACE_NORMAL, &search->iter, &search->chain, (void **)nodep, NULL); if (result == ISC_R_SUCCESS) { break; @@ -3374,7 +3374,7 @@ qpzone_find(dns_db_t *db, const dns_name_t *name, dns_dbversion_t *version, /* * Search down from the root of the tree. */ - result = dns_qp_lookup(&search.qpr, name, nspace, NULL, &search.iter, + result = dns_qp_lookup(&search.qpr, name, nspace, &search.iter, &search.chain, (void **)&node, NULL); if (result != ISC_R_NOTFOUND) { dns_name_copy(&node->name, foundname); @@ -4179,7 +4179,7 @@ dbiterator_first(dns_dbiterator_t *iterator DNS__DB_FLARG) { * origin node. */ result = dns_qp_lookup(qpdbiter->snap, &qpdb->common.origin, - DNS_DBNAMESPACE_NSEC3, NULL, + DNS_DBNAMESPACE_NSEC3, &qpdbiter->iter, NULL, (void **)&qpdbiter->node, NULL); if (result != ISC_R_SUCCESS || @@ -4269,7 +4269,7 @@ dbiterator_last(dns_dbiterator_t *iterator DNS__DB_FLARG) { * The final non-nsec node is before the the NSEC origin node. */ result = dns_qp_lookup(qpdbiter->snap, &qpdb->common.origin, - DNS_DBNAMESPACE_NSEC, NULL, + DNS_DBNAMESPACE_NSEC, &qpdbiter->iter, NULL, (void **)&qpdbiter->node, NULL); if (result == ISC_R_SUCCESS) { @@ -4324,21 +4324,21 @@ dbiterator_seek(dns_dbiterator_t *iterator, switch (qpdbiter->nsec3mode) { case nsec3only: result = dns_qp_lookup( - qpdbiter->snap, name, DNS_DBNAMESPACE_NSEC3, NULL, + qpdbiter->snap, name, DNS_DBNAMESPACE_NSEC3, &qpdbiter->iter, NULL, (void **)&qpdbiter->node, NULL); break; case nonsec3: result = dns_qp_lookup( - qpdbiter->snap, name, DNS_DBNAMESPACE_NORMAL, NULL, + qpdbiter->snap, name, DNS_DBNAMESPACE_NORMAL, &qpdbiter->iter, NULL, (void **)&qpdbiter->node, NULL); break; case full: result = dns_qp_lookup( - qpdbiter->snap, name, DNS_DBNAMESPACE_NORMAL, NULL, + qpdbiter->snap, name, DNS_DBNAMESPACE_NORMAL, &qpdbiter->iter, NULL, (void **)&qpdbiter->node, NULL); if (result != ISC_R_SUCCESS) { tresult = dns_qp_lookup(qpdbiter->snap, name, - DNS_DBNAMESPACE_NSEC3, NULL, + DNS_DBNAMESPACE_NSEC3, &qpdbiter->iter, NULL, (void **)&qpdbiter->node, NULL); if (tresult == ISC_R_SUCCESS) { @@ -4426,7 +4426,7 @@ dbiterator_prev(dns_dbiterator_t *iterator DNS__DB_FLARG) { INSIST(qpdbiter->node->nspace == DNS_DBNAMESPACE_NSEC); result = dns_qp_lookup(qpdbiter->snap, &qpdb->common.origin, - DNS_DBNAMESPACE_NSEC, NULL, + DNS_DBNAMESPACE_NSEC, &qpdbiter->iter, NULL, (void **)&qpdbiter->node, NULL); @@ -4533,7 +4533,7 @@ dbiterator_next(dns_dbiterator_t *iterator DNS__DB_FLARG) { INSIST(qpdbiter->node->nspace == DNS_DBNAMESPACE_NSEC); result = dns_qp_lookup(qpdbiter->snap, &qpdb->common.origin, - DNS_DBNAMESPACE_NSEC3, NULL, + DNS_DBNAMESPACE_NSEC3, &qpdbiter->iter, NULL, (void **)&qpdbiter->node, NULL); if (result != ISC_R_SUCCESS || @@ -4646,7 +4646,7 @@ qpzone_createiterator(dns_db_t *db, unsigned int options, * seek the NSEC3 origin node. */ result = dns_qp_lookup(iter->snap, &qpdb->common.origin, - DNS_DBNAMESPACE_NSEC3, NULL, &iter->iter, + DNS_DBNAMESPACE_NSEC3, &iter->iter, NULL, NULL, NULL); INSIST(result == ISC_R_SUCCESS); break; diff --git a/lib/dns/rpz.c b/lib/dns/rpz.c index e0e9bbd6d4..3cf30b3608 100644 --- a/lib/dns/rpz.c +++ b/lib/dns/rpz.c @@ -2496,7 +2496,7 @@ dns_rpz_find_name(dns_rpz_zones_t *rpzs, dns_rpz_type_t rpz_type, dns_qpmulti_query(rpzs->table, &qpr); dns_qpchain_init(&qpr, &chain); - result = dns_qp_lookup(&qpr, trig_name, DNS_DBNAMESPACE_NORMAL, NULL, + result = dns_qp_lookup(&qpr, trig_name, DNS_DBNAMESPACE_NORMAL, NULL, &chain, (void **)&data, NULL); switch (result) { case ISC_R_SUCCESS: diff --git a/lib/dns/zt.c b/lib/dns/zt.c index d17c8bae22..758a4eae64 100644 --- a/lib/dns/zt.c +++ b/lib/dns/zt.c @@ -183,7 +183,7 @@ dns_zt_find(dns_zt_t *zt, const dns_name_t *name, dns_ztfind_t options, result = dns_qp_getname(&qpr, name, DNS_DBNAMESPACE_NORMAL, &pval, NULL); } else { - result = dns_qp_lookup(&qpr, name, DNS_DBNAMESPACE_NORMAL, NULL, + result = dns_qp_lookup(&qpr, name, DNS_DBNAMESPACE_NORMAL, NULL, &chain, &pval, NULL); if (exactopts == DNS_ZTFIND_NOEXACT && result == ISC_R_SUCCESS) { diff --git a/tests/bench/qplookups.c b/tests/bench/qplookups.c index 1c142c123b..f83b1846d3 100644 --- a/tests/bench/qplookups.c +++ b/tests/bench/qplookups.c @@ -236,7 +236,7 @@ main(int argc, char **argv) { start = isc_time_monotonic(); for (i = 0; i < n; i++) { name = dns_fixedname_name(&items[i]); - dns_qp_lookup(qp, name, DNS_DBNAMESPACE_NORMAL, NULL, NULL, + dns_qp_lookup(qp, name, DNS_DBNAMESPACE_NORMAL, NULL, NULL, NULL, NULL); } stop = isc_time_monotonic(); @@ -262,7 +262,7 @@ main(int argc, char **argv) { ++search->ndata[1]; } - dns_qp_lookup(qp, search, DNS_DBNAMESPACE_NORMAL, NULL, NULL, + dns_qp_lookup(qp, search, DNS_DBNAMESPACE_NORMAL, NULL, NULL, NULL, NULL); } stop = isc_time_monotonic(); diff --git a/tests/dns/qp_test.c b/tests/dns/qp_test.c index e6729056e9..6bb9d91ce4 100644 --- a/tests/dns/qp_test.c +++ b/tests/dns/qp_test.c @@ -418,11 +418,21 @@ check_partialmatch(dns_qp_t *qp, struct check_partialmatch check[], dns_fixedname_t fn1, fn2; dns_name_t *name = dns_fixedname_initname(&fn1); dns_name_t *foundname = dns_fixedname_initname(&fn2); + dns_qpchain_t chain; void *pval = NULL; dns_test_namefromstring(check[i].query, &fn1); - result = dns_qp_lookup(qp, name, space, foundname, NULL, NULL, - &pval, NULL); + dns_qpchain_init(qp, &chain); + result = dns_qp_lookup(qp, name, space, NULL, + &chain, &pval, NULL); + + /* Extract the found name using maybe_set_name if we found something */ + if (result == ISC_R_SUCCESS || result == DNS_R_PARTIALMATCH) { + if (chain.len > 0) { + dns_qpnode_t *node = chain.chain[chain.len - 1].node; + maybe_set_name((dns_qpreader_t *)qp, node, foundname); + } + } #if 0 fprintf(stderr, "%s%s %s (expected %s) " @@ -584,7 +594,7 @@ check_qpchainiter(dns_qp_t *qp, struct check_qpchain check[], dns_qpchain_init(qp, &chain); dns_test_namefromstring(check[i].query, &fn1); - result = dns_qp_lookup(qp, name, check[i].space, NULL, iter, + result = dns_qp_lookup(qp, name, check[i].space, iter, &chain, NULL, NULL); #if 0 fprintf(stderr, @@ -810,7 +820,7 @@ check_predecessors_withchain(dns_qp_t *qp, struct check_predecessors check[], result = dns_name_tostring(expred, &predstr, isc_g_mctx); assert_int_equal(result, ISC_R_SUCCESS); - result = dns_qp_lookup(qp, name, check[i].space, NULL, &it, + result = dns_qp_lookup(qp, name, check[i].space, &it, chain, NULL, NULL); #if 0 fprintf(stderr, "%s %s: expected %s got %s\n", check[i].query, From 46e25bd0db8e79c9e286aca69d3a97b263bd8370 Mon Sep 17 00:00:00 2001 From: Alessio Podda Date: Mon, 1 Dec 2025 15:12:01 +0100 Subject: [PATCH 2/3] Remove maybe_set_name Outside of unit tests, the name parameter in dns_qpiter_<...> and dns_qpchain_<...> is only used in context where the name can be extracted directly from the underlying node. This commits modifies the signatures of dns_qpiter_<...> and dns_qpchain_<...> not to have a name parameter. Where the name parameter was needed, we now query the node and copy the name directly from it. This allows us to remove maybe_set_name from qp.c. Besides simplifying the API, this leads to a performance speedup for NXDOMAIN handling, as we avoid calling maybe_set_name inside step, and maybe_set_name is very inefficient. A copy of the implementation maybe_set_name is retained for the unit tests. --- lib/dns/include/dns/qp.h | 20 ++++--- lib/dns/keytable.c | 6 +-- lib/dns/nta.c | 6 +-- lib/dns/qp.c | 42 +++++---------- lib/dns/qp_p.h | 2 - lib/dns/qpcache.c | 13 ++--- lib/dns/qpzone.c | 82 ++++++++++++++++++----------- lib/dns/rpz.c | 2 +- lib/dns/zt.c | 4 +- tests/bench/qplookups.c | 5 +- tests/dns/qp_test.c | 111 +++++++++++++++++++++++++++++++-------- 11 files changed, 181 insertions(+), 112 deletions(-) diff --git a/lib/dns/include/dns/qp.h b/lib/dns/include/dns/qp.h index 2ae5b58ce4..00dc461067 100644 --- a/lib/dns/include/dns/qp.h +++ b/lib/dns/include/dns/qp.h @@ -650,17 +650,14 @@ dns_qpiter_init(dns_qpreadable_t qpr, dns_qpiter_t *qpi); */ isc_result_t -dns_qpiter_next(dns_qpiter_t *qpi, dns_name_t *name, void **pval_r, - uint32_t *ival_r); +dns_qpiter_next(dns_qpiter_t *qpi, void **pval_r, uint32_t *ival_r); isc_result_t -dns_qpiter_prev(dns_qpiter_t *qpi, dns_name_t *name, void **pval_r, - uint32_t *ival_r); +dns_qpiter_prev(dns_qpiter_t *qpi, void **pval_r, uint32_t *ival_r); /*%< * Iterate forward/backward through a QP trie in lexicographic order. * * The leaf values are assigned to whichever of `*pval_r` and `*ival_r` - * are not null, unless the return value is ISC_R_NOMORE. Similarly, - * if `name` is not null, it is updated to contain the node name. + * are not null, unless the return value is ISC_R_NOMORE. * * NOTE: see the safety note under `dns_qpiter_init()`. * @@ -682,16 +679,16 @@ dns_qpiter_prev(dns_qpiter_t *qpi, dns_name_t *name, void **pval_r, * \li ISC_R_NOMORE otherwise */ + isc_result_t -dns_qpiter_current(dns_qpiter_t *qpi, dns_name_t *name, void **pval_r, - uint32_t *ival_r); +dns_qpiter_current(dns_qpiter_t *qpi, void **pval_r, uint32_t *ival_r); /*%< - * Sets the values of `name`, `pval_r` and `ival_r` to those at the + * Sets the values of `pval_r` and `ival_r` to those at the * node currently pointed to by `qpi`, but without moving the iterator * in either direction. If the iterator is not currently pointed at a * leaf node, ISC_R_FAILURE is returned. - * Requires: * + * Requires: * \li `qpi` is a pointer to a valid qp iterator * * Returns: @@ -700,6 +697,7 @@ dns_qpiter_current(dns_qpiter_t *qpi, dns_name_t *name, void **pval_r, * at a leaf node */ + void dns_qpchain_init(dns_qpreadable_t qpr, dns_qpchain_t *chain); /*%< @@ -720,7 +718,7 @@ dns_qpchain_length(dns_qpchain_t *chain); */ void -dns_qpchain_node(dns_qpchain_t *chain, unsigned int level, dns_name_t *name, +dns_qpchain_node(dns_qpchain_t *chain, unsigned int level, void **pval_r, uint32_t *ival_r); /*%< * Sets 'name' to the name of the leaf referenced at `chain->stack[level]`. diff --git a/lib/dns/keytable.c b/lib/dns/keytable.c index 5890ffdcd6..04fe2277b7 100644 --- a/lib/dns/keytable.c +++ b/lib/dns/keytable.c @@ -150,7 +150,7 @@ destroy_keytable(dns_keytable_t *keytable) { dns_qpmulti_query(keytable->table, &qpr); dns_qpiter_init(&qpr, &iter); - while (dns_qpiter_next(&iter, NULL, &pval, NULL) == ISC_R_SUCCESS) { + while (dns_qpiter_next(&iter, &pval, NULL) == ISC_R_SUCCESS) { dns_keynode_t *n = pval; dns_keynode_detach(&n); } @@ -648,7 +648,7 @@ dns_keytable_totext(dns_keytable_t *keytable, isc_buffer_t *text) { dns_qpmulti_query(keytable->table, &qpr); dns_qpiter_init(&qpr, &iter); - while (dns_qpiter_next(&iter, NULL, &pval, NULL) == ISC_R_SUCCESS) { + while (dns_qpiter_next(&iter, &pval, NULL) == ISC_R_SUCCESS) { dns_keynode_t *knode = pval; if (knode->dslist != NULL) { result = keynode_dslist_totext(knode, text); @@ -676,7 +676,7 @@ dns_keytable_forall(dns_keytable_t *keytable, dns_qpmulti_query(keytable->table, &qpr); dns_qpiter_init(&qpr, &iter); - while (dns_qpiter_next(&iter, NULL, &pval, NULL) == ISC_R_SUCCESS) { + while (dns_qpiter_next(&iter, &pval, NULL) == ISC_R_SUCCESS) { dns_keynode_t *knode = pval; (*func)(keytable, knode, &knode->name, arg); } diff --git a/lib/dns/nta.c b/lib/dns/nta.c index 2ad9c07ea0..e4cf9ab46d 100644 --- a/lib/dns/nta.c +++ b/lib/dns/nta.c @@ -475,7 +475,7 @@ dns_ntatable_totext(dns_ntatable_t *ntatable, const char *view, dns_qpmulti_query(ntatable->table, &qpr); dns_qpiter_init(&qpr, &iter); - while (dns_qpiter_next(&iter, NULL, &pval, NULL) == ISC_R_SUCCESS) { + while (dns_qpiter_next(&iter, &pval, NULL) == ISC_R_SUCCESS) { dns__nta_t *n = pval; char nbuf[DNS_NAME_FORMATSIZE]; char tbuf[ISC_FORMATHTTPTIMESTAMP_SIZE]; @@ -528,7 +528,7 @@ dns_ntatable_save(dns_ntatable_t *ntatable, FILE *fp) { dns_qpmulti_query(ntatable->table, &qpr); dns_qpiter_init(&qpr, &iter); - while (dns_qpiter_next(&iter, NULL, &pval, NULL) == ISC_R_SUCCESS) { + while (dns_qpiter_next(&iter, &pval, NULL) == ISC_R_SUCCESS) { dns__nta_t *n = pval; isc_buffer_t b; char nbuf[DNS_NAME_FORMATSIZE + 1], tbuf[80]; @@ -614,7 +614,7 @@ dns_ntatable_shutdown(dns_ntatable_t *ntatable) { ntatable->shuttingdown = true; dns_qpiter_init(&qpr, &iter); - while (dns_qpiter_next(&iter, NULL, &pval, NULL) == ISC_R_SUCCESS) { + while (dns_qpiter_next(&iter, &pval, NULL) == ISC_R_SUCCESS) { dns__nta_t *n = pval; dns__nta_shutdown(n); dns__nta_detach(&n); diff --git a/lib/dns/qp.c b/lib/dns/qp.c index 091b691e2f..b38ee5f5c2 100644 --- a/lib/dns/qp.c +++ b/lib/dns/qp.c @@ -1857,20 +1857,6 @@ dns_qp_deletename(dns_qp_t *qp, const dns_name_t *name, dns_namespace_t space, /*********************************************************************** * chains */ -void -maybe_set_name(dns_qpreader_t *qp, dns_qpnode_t *node, dns_name_t *name) { - dns_qpkey_t key; - size_t len; - - if (name == NULL) { - return; - } - - dns_name_reset(name); - len = leaf_qpkey(qp, node, key); - dns_qpkey_toname(key, len, name, NULL); -} - void dns_qpchain_init(dns_qpreadable_t qpr, dns_qpchain_t *chain) { dns_qpreader_t *qp = dns_qpreader(qpr); @@ -1895,7 +1881,7 @@ dns_qpchain_length(dns_qpchain_t *chain) { } void -dns_qpchain_node(dns_qpchain_t *chain, unsigned int level, dns_name_t *name, +dns_qpchain_node(dns_qpchain_t *chain, unsigned int level, void **pval_r, uint32_t *ival_r) { dns_qpnode_t *node = NULL; @@ -1903,7 +1889,6 @@ dns_qpchain_node(dns_qpchain_t *chain, unsigned int level, dns_name_t *name, REQUIRE(level < chain->len); node = chain->chain[level].node; - maybe_set_name(chain->qp, node, name); SET_IF_NOT_NULL(pval_r, leaf_pval(node)); SET_IF_NOT_NULL(ival_r, leaf_ival(node)); } @@ -1956,8 +1941,7 @@ last_twig(dns_qpiter_t *qpi, bool forward) { * a mutable view of the trie which is altered while iterating */ static isc_result_t -iterate(bool forward, dns_qpiter_t *qpi, dns_name_t *name, void **pval_r, - uint32_t *ival_r) { +iterate(bool forward, dns_qpiter_t *qpi, void **pval_r, uint32_t *ival_r) { dns_qpnode_t *node = NULL; bool initial_branch = true; @@ -2032,25 +2016,23 @@ iterate(bool forward, dns_qpiter_t *qpi, dns_name_t *name, void **pval_r, /* we're at a leaf: return its data to the caller */ SET_IF_NOT_NULL(pval_r, leaf_pval(node)); SET_IF_NOT_NULL(ival_r, leaf_ival(node)); - maybe_set_name(qpi->qp, node, name); return ISC_R_SUCCESS; } isc_result_t -dns_qpiter_next(dns_qpiter_t *qpi, dns_name_t *name, void **pval_r, - uint32_t *ival_r) { - return iterate(true, qpi, name, pval_r, ival_r); +dns_qpiter_next(dns_qpiter_t *qpi, void **pval_r, uint32_t *ival_r) { + return iterate(true, qpi, pval_r, ival_r); } isc_result_t -dns_qpiter_prev(dns_qpiter_t *qpi, dns_name_t *name, void **pval_r, - uint32_t *ival_r) { - return iterate(false, qpi, name, pval_r, ival_r); +dns_qpiter_prev(dns_qpiter_t *qpi, void **pval_r, uint32_t *ival_r) { + return iterate(false, qpi, pval_r, ival_r); } + + isc_result_t -dns_qpiter_current(dns_qpiter_t *qpi, dns_name_t *name, void **pval_r, - uint32_t *ival_r) { +dns_qpiter_current(dns_qpiter_t *qpi, void **pval_r, uint32_t *ival_r) { dns_qpnode_t *node = NULL; REQUIRE(QPITER_VALID(qpi)); @@ -2062,10 +2044,10 @@ dns_qpiter_current(dns_qpiter_t *qpi, dns_name_t *name, void **pval_r, SET_IF_NOT_NULL(pval_r, leaf_pval(node)); SET_IF_NOT_NULL(ival_r, leaf_ival(node)); - maybe_set_name(qpi->qp, node, name); return ISC_R_SUCCESS; } + /*********************************************************************** * * search @@ -2131,9 +2113,9 @@ add_link(dns_qpchain_t *chain, dns_qpnode_t *node, size_t offset) { static inline void prevleaf(dns_qpiter_t *it) { - isc_result_t result = dns_qpiter_prev(it, NULL, NULL, NULL); + isc_result_t result = dns_qpiter_prev(it, NULL, NULL); if (result == ISC_R_NOMORE) { - result = dns_qpiter_prev(it, NULL, NULL, NULL); + result = dns_qpiter_prev(it, NULL, NULL); } RUNTIME_CHECK(result == ISC_R_SUCCESS); } diff --git a/lib/dns/qp_p.h b/lib/dns/qp_p.h index 51d2be6ea7..6ce46f3c22 100644 --- a/lib/dns/qp_p.h +++ b/lib/dns/qp_p.h @@ -945,8 +945,6 @@ extern uint8_t dns_qp_byte_for_bit[]; /**********************************************************************/ -void -maybe_set_name(dns_qpreader_t *qp, dns_qpnode_t *node, dns_name_t *name); void dns__qp_initialize(void); diff --git a/lib/dns/qpcache.c b/lib/dns/qpcache.c index 92d00a2595..660d592da1 100644 --- a/lib/dns/qpcache.c +++ b/lib/dns/qpcache.c @@ -1419,7 +1419,7 @@ find_deepest_zonecut(qpc_search_t *search, qpcnode_t *node, isc_rwlock_t *nlock = NULL; isc_rwlocktype_t nlocktype = isc_rwlocktype_none; - dns_qpchain_node(&search->chain, i, NULL, (void **)&node, NULL); + dns_qpchain_node(&search->chain, i, (void **)&node, NULL); nlock = &qpdb->buckets[node->locknum].lock; NODE_RDLOCK(nlock, &nlocktype); @@ -1502,10 +1502,11 @@ find_coveringnsec(qpc_search_t *search, const dns_name_t *name, /* * Extract predecessor from iterator. */ - result = dns_qpiter_current(&iter, predecessor, NULL, NULL); + result = dns_qpiter_current(&iter, (void **)&node, NULL); if (result != ISC_R_SUCCESS) { return ISC_R_NOTFOUND; } + dns_name_copy(&node->name, predecessor); /* * Lookup the predecessor in the normal namespace. @@ -1636,7 +1637,7 @@ qpcache_find(dns_db_t *db, const dns_name_t *name, dns_dbversion_t *version, isc_result_t zcresult; qpcnode_t *encloser = NULL; - dns_qpchain_node(&search.chain, i, NULL, (void **)&encloser, + dns_qpchain_node(&search.chain, i, (void **)&encloser, NULL); zcresult = check_zonecut(encloser, @@ -2071,7 +2072,7 @@ qpcache_findzonecut(dns_db_t *db, const dns_name_t *name, unsigned int options, INSIST(len >= 2); node = NULL; - dns_qpchain_node(&search.chain, len - 2, NULL, + dns_qpchain_node(&search.chain, len - 2, (void **)&node, NULL); search.chain.len = len - 1; } @@ -3566,7 +3567,7 @@ dbiterator_first(dns_dbiterator_t *iterator DNS__DB_FLARG) { dereference_iter_node(qpdbiter DNS__DB_FLARG_PASS); dns_qpiter_init(qpdb->tree, &qpdbiter->iter); - result = dns_qpiter_next(&qpdbiter->iter, NULL, + result = dns_qpiter_next(&qpdbiter->iter, (void **)&qpdbiter->node, NULL); if (result == ISC_R_SUCCESS && @@ -3656,7 +3657,7 @@ dbiterator_next(dns_dbiterator_t *iterator DNS__DB_FLARG) { dereference_iter_node(qpdbiter DNS__DB_FLARG_PASS); - result = dns_qpiter_next(&qpdbiter->iter, NULL, + result = dns_qpiter_next(&qpdbiter->iter, (void **)&qpdbiter->node, NULL); if (result == ISC_R_SUCCESS && diff --git a/lib/dns/qpzone.c b/lib/dns/qpzone.c index 405a7c5551..44a5addfb5 100644 --- a/lib/dns/qpzone.c +++ b/lib/dns/qpzone.c @@ -2684,7 +2684,10 @@ step(qpz_search_t *search, dns_qpiter_t *it, direction_t direction, qpznode_t *node = NULL; isc_result_t result = ISC_R_SUCCESS; - result = dns_qpiter_current(it, nodename, (void **)&node, NULL); + result = dns_qpiter_current(it, (void **)&node, NULL); + if (result == ISC_R_SUCCESS) { + dns_name_copy(&node->name, nodename); + } while (result == ISC_R_SUCCESS) { isc_rwlock_t *nlock = qpzone_get_lock(node); isc_rwlocktype_t nlocktype = isc_rwlocktype_none; @@ -2700,11 +2703,12 @@ step(qpz_search_t *search, dns_qpiter_t *it, direction_t direction, } if (direction == FORWARD) { - result = dns_qpiter_next(it, nodename, (void **)&node, - NULL); + result = dns_qpiter_next(it, (void **)&node, NULL); } else { - result = dns_qpiter_prev(it, nodename, (void **)&node, - NULL); + result = dns_qpiter_prev(it, (void **)&node, NULL); + } + if (result == ISC_R_SUCCESS) { + dns_name_copy(&node->name, nodename); } }; if (result == ISC_R_SUCCESS) { @@ -2730,7 +2734,7 @@ activeempty(qpz_search_t *search, dns_qpiter_t *it, const dns_name_t *current) { * subdomain of the one we were looking for, then we're * at an active empty nonterminal node. */ - isc_result_t result = dns_qpiter_next(it, NULL, NULL, NULL); + isc_result_t result = dns_qpiter_next(it, NULL, NULL); if (result != ISC_R_SUCCESS) { /* An ENT at the end of the zone is impossible */ return false; @@ -2776,7 +2780,7 @@ wildcard_blocked(qpz_search_t *search, const dns_name_t *qname, /* Now reset the iterator and look for a successor with data. */ it = search->iter; - result = dns_qpiter_next(&it, NULL, NULL, NULL); + result = dns_qpiter_next(&it, NULL, NULL); if (result == ISC_R_SUCCESS) { check_next = step(search, &it, FORWARD, next); } @@ -2841,7 +2845,7 @@ find_wildcard(qpz_search_t *search, qpznode_t **nodep, const dns_name_t *qname, isc_rwlocktype_t nlocktype = isc_rwlocktype_none; bool wild, active; - dns_qpchain_node(&search->chain, i, NULL, (void **)&node, NULL); + dns_qpchain_node(&search->chain, i, (void **)&node, NULL); nlock = qpzone_get_lock(node); NODE_RDLOCK(nlock, &nlocktype); @@ -2939,8 +2943,10 @@ previous_closest_nsec(dns_rdatatype_t type, qpz_search_t *search, REQUIRE(type == dns_rdatatype_nsec3 || firstp != NULL); if (type == dns_rdatatype_nsec3) { - result = dns_qpiter_prev(&search->iter, name, (void **)nodep, - NULL); + result = dns_qpiter_prev(&search->iter, (void **)nodep, NULL); + if (result == ISC_R_SUCCESS) { + dns_name_copy(&(*nodep)->name, name); + } return result; } @@ -2955,6 +2961,8 @@ previous_closest_nsec(dns_rdatatype_t type, qpz_search_t *search, *firstp = false; result = dns_qp_lookup(&qpr, name, DNS_DBNAMESPACE_NSEC, nit, NULL, NULL, NULL); + qpznode_t *node = NULL; + INSIST(result != ISC_R_NOTFOUND); if (result == ISC_R_SUCCESS) { /* @@ -2965,7 +2973,10 @@ previous_closest_nsec(dns_rdatatype_t type, qpz_search_t *search, * NSEC record; we want the previous node * in the NSEC tree. */ - result = dns_qpiter_prev(nit, name, NULL, NULL); + result = dns_qpiter_prev(nit, (void **)&node, NULL); + if (result == ISC_R_SUCCESS) { + dns_name_copy(&node->name, name); + } } else if (result == DNS_R_PARTIALMATCH) { /* * This was a partial match, so the @@ -2973,7 +2984,10 @@ previous_closest_nsec(dns_rdatatype_t type, qpz_search_t *search, * node in the NSEC namespace, which is * what we want. */ - dns_qpiter_current(nit, name, NULL, NULL); + isc_result_t iresult = dns_qpiter_current(nit, (void **)&node, NULL); + if (iresult == ISC_R_SUCCESS) { + dns_name_copy(&node->name, name); + } result = ISC_R_SUCCESS; } } else { @@ -2984,7 +2998,11 @@ previous_closest_nsec(dns_rdatatype_t type, qpz_search_t *search, * work; perhaps they lacked signature records. * Keep searching. */ - result = dns_qpiter_prev(nit, name, NULL, NULL); + qpznode_t *tempnode = NULL; + result = dns_qpiter_prev(nit, (void **)&tempnode, NULL); + if (result == ISC_R_SUCCESS) { + dns_name_copy(&tempnode->name, name); + } } if (result != ISC_R_SUCCESS) { break; @@ -3050,10 +3068,11 @@ find_closest_nsec(qpz_search_t *search, dns_dbnode_t **nodep, * then we start using the auxiliary NSEC namespace to find * the next predecessor. */ - result = dns_qpiter_current(&search->iter, name, (void **)&node, NULL); + result = dns_qpiter_current(&search->iter, (void **)&node, NULL); if (result != ISC_R_SUCCESS) { return result; } + dns_name_copy(&node->name, name); again: do { dns_slabheader_t *found = NULL, *foundsig = NULL; @@ -3158,9 +3177,10 @@ again: } while (empty_node && result == ISC_R_SUCCESS); if (result == ISC_R_NOMORE && wraps) { - result = dns_qpiter_prev(&search->iter, name, (void **)&node, + result = dns_qpiter_prev(&search->iter, (void **)&node, NULL); if (result == ISC_R_SUCCESS) { + dns_name_copy(&node->name, name); wraps = false; goto again; } @@ -3395,7 +3415,7 @@ qpzone_find(dns_db_t *db, const dns_name_t *name, dns_dbversion_t *version, qpznode_t *n = NULL; isc_result_t tresult; - dns_qpchain_node(&search.chain, i, NULL, (void **)&n, NULL); + dns_qpchain_node(&search.chain, i, (void **)&n, NULL); tresult = qpzone_check_zonecut(n, &search DNS__DB_FLARG_PASS); if (tresult != DNS_R_CONTINUE) { result = tresult; @@ -3677,7 +3697,7 @@ found: unsigned int len = search.chain.len - 1; if (len > 0) { NODE_UNLOCK(nlock, &nlocktype); - dns_qpchain_node(&search.chain, len - 1, NULL, + dns_qpchain_node(&search.chain, len - 1, (void **)&node, NULL); dns_name_copy(&node->name, foundname); goto partial_match; @@ -4133,7 +4153,7 @@ dbiterator_first(dns_dbiterator_t *iterator DNS__DB_FLARG) { dereference_iter_node(qpdbiter DNS__DB_FLARG_PASS); dns_qpiter_init(qpdbiter->snap, &qpdbiter->iter); - result = dns_qpiter_next(&qpdbiter->iter, NULL, + result = dns_qpiter_next(&qpdbiter->iter, (void **)&qpdbiter->node, NULL); switch (qpdbiter->nsec3mode) { @@ -4154,7 +4174,7 @@ dbiterator_first(dns_dbiterator_t *iterator DNS__DB_FLARG) { if (result == ISC_R_SUCCESS && QPDBITER_NSEC3_ORIGIN_NODE(qpdb, qpdbiter)) { - result = dns_qpiter_next(&qpdbiter->iter, NULL, + result = dns_qpiter_next(&qpdbiter->iter, (void **)&qpdbiter->node, NULL); } @@ -4186,7 +4206,7 @@ dbiterator_first(dns_dbiterator_t *iterator DNS__DB_FLARG) { QPDBITER_NSEC3_ORIGIN_NODE(qpdb, qpdbiter)) { /* skip the NSEC3 origin node (or its predecessor) */ - result = dns_qpiter_next(&qpdbiter->iter, NULL, + result = dns_qpiter_next(&qpdbiter->iter, (void **)&qpdbiter->node, NULL); } @@ -4221,7 +4241,7 @@ dbiterator_last(dns_dbiterator_t *iterator DNS__DB_FLARG) { dereference_iter_node(qpdbiter DNS__DB_FLARG_PASS); dns_qpiter_init(qpdbiter->snap, &qpdbiter->iter); - result = dns_qpiter_prev(&qpdbiter->iter, NULL, + result = dns_qpiter_prev(&qpdbiter->iter, (void **)&qpdbiter->node, NULL); switch (qpdbiter->nsec3mode) { @@ -4245,7 +4265,7 @@ dbiterator_last(dns_dbiterator_t *iterator DNS__DB_FLARG) { if (result == ISC_R_SUCCESS && QPDBITER_NSEC3_ORIGIN_NODE(qpdb, qpdbiter)) { - result = dns_qpiter_prev(&qpdbiter->iter, NULL, + result = dns_qpiter_prev(&qpdbiter->iter, (void **)&qpdbiter->node, NULL); } @@ -4275,7 +4295,7 @@ dbiterator_last(dns_dbiterator_t *iterator DNS__DB_FLARG) { if (result == ISC_R_SUCCESS) { INSIST(QPDBITER_NSEC_ORIGIN_NODE(qpdb, qpdbiter)); /* skip the NSEC origin node */ - result = dns_qpiter_prev(&qpdbiter->iter, NULL, + result = dns_qpiter_prev(&qpdbiter->iter, (void **)&qpdbiter->node, NULL); } else { @@ -4284,7 +4304,7 @@ dbiterator_last(dns_dbiterator_t *iterator DNS__DB_FLARG) { * should point to its predecessor, which is the node we * want. */ - result = dns_qpiter_current(&qpdbiter->iter, NULL, + result = dns_qpiter_current(&qpdbiter->iter, (void **)&qpdbiter->node, NULL); INSIST(result == ISC_R_SUCCESS); @@ -4383,7 +4403,7 @@ dbiterator_prev(dns_dbiterator_t *iterator DNS__DB_FLARG) { node = qpdbiter->node; qpdbiter->node = NULL; - result = dns_qpiter_prev(&qpdbiter->iter, NULL, + result = dns_qpiter_prev(&qpdbiter->iter, (void **)&qpdbiter->node, NULL); switch (qpdbiter->nsec3mode) { @@ -4407,7 +4427,7 @@ dbiterator_prev(dns_dbiterator_t *iterator DNS__DB_FLARG) { if (result == ISC_R_SUCCESS && QPDBITER_NSEC3_ORIGIN_NODE(qpdb, qpdbiter)) { - result = dns_qpiter_prev(&qpdbiter->iter, NULL, + result = dns_qpiter_prev(&qpdbiter->iter, (void **)&qpdbiter->node, NULL); } @@ -4433,7 +4453,7 @@ dbiterator_prev(dns_dbiterator_t *iterator DNS__DB_FLARG) { if (result == ISC_R_SUCCESS) { INSIST(QPDBITER_NSEC_ORIGIN_NODE(qpdb, qpdbiter)); /* skip the NSEC origin node */ - result = dns_qpiter_prev(&qpdbiter->iter, NULL, + result = dns_qpiter_prev(&qpdbiter->iter, (void **)&qpdbiter->node, NULL); } else { @@ -4442,7 +4462,7 @@ dbiterator_prev(dns_dbiterator_t *iterator DNS__DB_FLARG) { * should point to its predecessor, which is the node we * want. */ - result = dns_qpiter_current(&qpdbiter->iter, NULL, + result = dns_qpiter_current(&qpdbiter->iter, (void **)&qpdbiter->node, NULL); INSIST(result == ISC_R_SUCCESS); @@ -4496,7 +4516,7 @@ dbiterator_next(dns_dbiterator_t *iterator DNS__DB_FLARG) { node = qpdbiter->node; qpdbiter->node = NULL; - result = dns_qpiter_next(&qpdbiter->iter, NULL, + result = dns_qpiter_next(&qpdbiter->iter, (void **)&qpdbiter->node, NULL); switch (qpdbiter->nsec3mode) { @@ -4514,7 +4534,7 @@ dbiterator_next(dns_dbiterator_t *iterator DNS__DB_FLARG) { if (result == ISC_R_SUCCESS && QPDBITER_NSEC3_ORIGIN_NODE(qpdb, qpdbiter)) { - result = dns_qpiter_next(&qpdbiter->iter, NULL, + result = dns_qpiter_next(&qpdbiter->iter, (void **)&qpdbiter->node, NULL); } @@ -4540,7 +4560,7 @@ dbiterator_next(dns_dbiterator_t *iterator DNS__DB_FLARG) { QPDBITER_NSEC3_ORIGIN_NODE(qpdb, qpdbiter)) { /* skip the NSEC3 origin node (or its predecessor). */ - result = dns_qpiter_next(&qpdbiter->iter, NULL, + result = dns_qpiter_next(&qpdbiter->iter, (void **)&qpdbiter->node, NULL); } diff --git a/lib/dns/rpz.c b/lib/dns/rpz.c index 3cf30b3608..676917d517 100644 --- a/lib/dns/rpz.c +++ b/lib/dns/rpz.c @@ -2511,7 +2511,7 @@ dns_rpz_find_name(dns_rpz_zones_t *rpzs, dns_rpz_type_t rpz_type, case DNS_R_PARTIALMATCH: i = dns_qpchain_length(&chain); while (i-- > 0) { - dns_qpchain_node(&chain, i, NULL, (void **)&data, NULL); + dns_qpchain_node(&chain, i, (void **)&data, NULL); INSIST(data != NULL); if (rpz_type == DNS_RPZ_TYPE_QNAME) { found_zbits |= data->wild.qname; diff --git a/lib/dns/zt.c b/lib/dns/zt.c index 758a4eae64..831fb7190f 100644 --- a/lib/dns/zt.c +++ b/lib/dns/zt.c @@ -190,7 +190,7 @@ dns_zt_find(dns_zt_t *zt, const dns_name_t *name, dns_ztfind_t options, /* get pval from the previous chain link */ int len = dns_qpchain_length(&chain); if (len >= 2) { - dns_qpchain_node(&chain, len - 2, NULL, &pval, + dns_qpchain_node(&chain, len - 2, &pval, NULL); result = DNS_R_PARTIALMATCH; } else { @@ -527,7 +527,7 @@ dns_zt_apply(dns_zt_t *zt, bool stop, isc_result_t *sub, dns_qpmulti_query(zt->multi, &qpr); dns_qpiter_init(&qpr, &qpi); - while (dns_qpiter_next(&qpi, NULL, &zone, NULL) == ISC_R_SUCCESS) { + while (dns_qpiter_next(&qpi, &zone, NULL) == ISC_R_SUCCESS) { result = action(zone, uap); if (tresult == ISC_R_SUCCESS) { tresult = result; diff --git a/tests/bench/qplookups.c b/tests/bench/qplookups.c index f83b1846d3..4617c1b84d 100644 --- a/tests/bench/qplookups.c +++ b/tests/bench/qplookups.c @@ -212,10 +212,13 @@ main(int argc, char **argv) { start = isc_time_monotonic(); for (i = 0;; i++) { + void *pval = NULL; + uint32_t ival = 0; name = dns_fixedname_initname(&items[i]); - if (dns_qpiter_next(&it, name, NULL, NULL) != ISC_R_SUCCESS) { + if (dns_qpiter_next(&it, &pval, &ival) != ISC_R_SUCCESS) { break; } + name_from_smallname(name, pval, ival); } stop = isc_time_monotonic(); diff --git a/tests/dns/qp_test.c b/tests/dns/qp_test.c index 6bb9d91ce4..03c65be43e 100644 --- a/tests/dns/qp_test.c +++ b/tests/dns/qp_test.c @@ -46,6 +46,70 @@ bool verbose = false; +/* + * Test-only functions for dns_qpiter_*_with_name functionality + */ +static void +maybe_set_name(dns_qpreader_t *qp, void *pval, uint32_t ival, + dns_name_t *name) { + if (name != NULL) { + dns_qpkey_t key; + size_t len; + dns_qpnode_t node = make_leaf(pval, ival); + dns_name_reset(name); + len = leaf_qpkey(qp, &node, key); + dns_qpkey_toname(key, len, name, NULL); + } +} + +static isc_result_t +qpiter_next_with_name(dns_qpiter_t *qpi, dns_name_t *name, void **pval_r, + uint32_t *ival_r) { + isc_result_t result; + void *pval = NULL; + uint32_t ival = 0; + + result = iterate(true, qpi, &pval, &ival); + if (result == ISC_R_SUCCESS) { + SET_IF_NOT_NULL(pval_r, pval); + SET_IF_NOT_NULL(ival_r, ival); + maybe_set_name(qpi->qp, pval, ival, name); + } + return result; +} + +static isc_result_t +qpiter_prev_with_name(dns_qpiter_t *qpi, dns_name_t *name, void **pval_r, + uint32_t *ival_r) { + isc_result_t result; + void *pval = NULL; + uint32_t ival = 0; + + result = iterate(false, qpi, &pval, &ival); + if (result == ISC_R_SUCCESS) { + SET_IF_NOT_NULL(pval_r, pval); + SET_IF_NOT_NULL(ival_r, ival); + maybe_set_name(qpi->qp, pval, ival, name); + } + return result; +} + +static isc_result_t +qpiter_current_with_name(dns_qpiter_t *qpi, dns_name_t *name, void **pval_r, + uint32_t *ival_r) { + isc_result_t result; + void *pval = NULL; + uint32_t ival = 0; + + result = dns_qpiter_current(qpi, &pval, &ival); + if (result == ISC_R_SUCCESS) { + SET_IF_NOT_NULL(pval_r, pval); + SET_IF_NOT_NULL(ival_r, ival); + maybe_set_name(qpi->qp, pval, ival, name); + } + return result; +} + ISC_RUN_TEST_IMPL(qpkey_name) { struct { const char *namestr; @@ -288,7 +352,7 @@ ISC_RUN_TEST_IMPL(qpiter) { /* check that we see only valid items in the correct order */ uint32_t prev = 0; dns_qpiter_init(qp, &qpi); - while (dns_qpiter_next(&qpi, NULL, &pval, &ival) == + while (dns_qpiter_next(&qpi, &pval, &ival) == ISC_R_SUCCESS) { assert_in_range(ival, prev + 1, ITER_ITEMS - 1); @@ -309,7 +373,7 @@ ISC_RUN_TEST_IMPL(qpiter) { /* now iterate backward and check correctness */ n = inserted; - while (dns_qpiter_prev(&qpi, NULL, NULL, &ival) == + while (dns_qpiter_prev(&qpi, NULL, &ival) == ISC_R_SUCCESS) { --n; @@ -317,7 +381,7 @@ ISC_RUN_TEST_IMPL(qpiter) { assert_int_equal(ival, order[n]); /* and check current iterator value as well */ - result = dns_qpiter_current(&qpi, NULL, NULL, &ival); + result = dns_qpiter_current(&qpi, NULL, &ival); assert_int_equal(result, ISC_R_SUCCESS); assert_int_equal(ival, order[n]); } @@ -325,13 +389,13 @@ ISC_RUN_TEST_IMPL(qpiter) { assert_int_equal(n, 0); /* ...and forward again */ - while (dns_qpiter_next(&qpi, NULL, NULL, &ival) == + while (dns_qpiter_next(&qpi, NULL, &ival) == ISC_R_SUCCESS) { assert_int_equal(ival, order[n]); /* and check current iterator value as well */ - result = dns_qpiter_current(&qpi, NULL, NULL, &ival); + result = dns_qpiter_current(&qpi, NULL, &ival); assert_int_equal(result, ISC_R_SUCCESS); assert_int_equal(ival, order[n]); @@ -347,32 +411,32 @@ ISC_RUN_TEST_IMPL(qpiter) { */ if (inserted > 3) { assert_int_equal( - dns_qpiter_next(&qpi, NULL, NULL, &ival), + dns_qpiter_next(&qpi, NULL, &ival), ISC_R_SUCCESS); assert_int_equal(ival, order[0]); assert_int_equal( - dns_qpiter_next(&qpi, NULL, NULL, &ival), + dns_qpiter_next(&qpi, NULL, &ival), ISC_R_SUCCESS); assert_int_equal(ival, order[1]); assert_int_equal( - dns_qpiter_prev(&qpi, NULL, NULL, &ival), + dns_qpiter_prev(&qpi, NULL, &ival), ISC_R_SUCCESS); assert_int_equal(ival, order[0]); assert_int_equal( - dns_qpiter_next(&qpi, NULL, NULL, &ival), + dns_qpiter_next(&qpi, NULL, &ival), ISC_R_SUCCESS); assert_int_equal(ival, order[1]); assert_int_equal( - dns_qpiter_prev(&qpi, NULL, NULL, &ival), + dns_qpiter_prev(&qpi, NULL, &ival), ISC_R_SUCCESS); assert_int_equal(ival, order[0]); assert_int_equal( - dns_qpiter_prev(&qpi, NULL, NULL, &ival), + dns_qpiter_prev(&qpi, NULL, &ival), ISC_R_NOMORE); } } @@ -426,12 +490,12 @@ check_partialmatch(dns_qp_t *qp, struct check_partialmatch check[], result = dns_qp_lookup(qp, name, space, NULL, &chain, &pval, NULL); - /* Extract the found name using maybe_set_name if we found something */ - if (result == ISC_R_SUCCESS || result == DNS_R_PARTIALMATCH) { - if (chain.len > 0) { - dns_qpnode_t *node = chain.chain[chain.len - 1].node; - maybe_set_name((dns_qpreader_t *)qp, node, foundname); - } + /* Extract the found name if we found something */ + if ((result == ISC_R_SUCCESS || result == DNS_R_PARTIALMATCH) && + pval != NULL) + { + maybe_set_name((dns_qpreader_t *)qp, pval, space, + foundname); } #if 0 @@ -612,7 +676,10 @@ check_qpchainiter(dns_qp_t *qp, struct check_qpchain check[], dns_name_t *expected = dns_fixedname_initname(&fn2); dns_name_t *found = dns_fixedname_initname(&fn3); dns_test_namefromstring(check[i].names[j], &fn2); - dns_qpchain_node(&chain, j, found, NULL, NULL); + void *pval = NULL; + uint32_t ival = 0; + dns_qpchain_node(&chain, j, &pval, &ival); + maybe_set_name(chain.qp, pval, ival, found); #if 0 char nb[DNS_NAME_FORMATSIZE]; dns_name_format(found, nb, sizeof(nb)); @@ -839,9 +906,9 @@ check_predecessors_withchain(dns_qp_t *qp, struct check_predecessors check[], * we found an exact match; iterate to find * the predecessor. */ - result = dns_qpiter_prev(&it, pred, NULL, &ival); + result = qpiter_prev_with_name(&it, pred, NULL, &ival); if (result == ISC_R_NOMORE) { - result = dns_qpiter_prev(&it, pred, NULL, + result = qpiter_prev_with_name(&it, pred, NULL, &ival); } } else { @@ -849,7 +916,7 @@ check_predecessors_withchain(dns_qp_t *qp, struct check_predecessors check[], * we didn't find a match, so the iterator should * already be pointed at the predecessor node. */ - result = dns_qpiter_current(&it, pred, NULL, &ival); + result = qpiter_current_with_name(&it, pred, NULL, &ival); } assert_int_equal(result, ISC_R_SUCCESS); @@ -869,7 +936,7 @@ check_predecessors_withchain(dns_qp_t *qp, struct check_predecessors check[], isc_mem_free(isc_g_mctx, predstr); int j = 0; - while (dns_qpiter_next(&it, name, NULL, NULL) == ISC_R_SUCCESS) + while (qpiter_next_with_name(&it, name, NULL, NULL) == ISC_R_SUCCESS) { #if 0 result = dns_name_tostring(name, &namestr, isc_g_mctx); From 4d698ee0e3d944662ce54192eb5ee5a738a272c2 Mon Sep 17 00:00:00 2001 From: Alessio Podda Date: Tue, 9 Dec 2025 17:41:33 +0100 Subject: [PATCH 3/3] Fix formatting after refactor The removal of the foundname and name parameters from various qp.c functions led to formatting issues. Restore the correct formatting via clang-format. --- lib/dns/forward.c | 4 +-- lib/dns/include/dns/qp.h | 10 +++--- lib/dns/keytable.c | 8 ++--- lib/dns/nametree.c | 4 +-- lib/dns/nta.c | 4 +-- lib/dns/qp.c | 11 +++--- lib/dns/qp_p.h | 1 - lib/dns/qpcache.c | 19 +++++----- lib/dns/qpzone.c | 77 +++++++++++++++++++--------------------- lib/dns/rpz.c | 4 +-- lib/dns/zt.c | 7 ++-- tests/bench/qplookups.c | 8 ++--- tests/dns/qp_test.c | 64 ++++++++++++++------------------- 13 files changed, 100 insertions(+), 121 deletions(-) diff --git a/lib/dns/forward.c b/lib/dns/forward.c index 795d67f644..84efbc4772 100644 --- a/lib/dns/forward.c +++ b/lib/dns/forward.c @@ -163,8 +163,8 @@ dns_fwdtable_find(dns_fwdtable_t *fwdtable, const dns_name_t *name, REQUIRE(VALID_FWDTABLE(fwdtable)); dns_qpmulti_query(fwdtable->table, &qpr); - result = dns_qp_lookup(&qpr, name, DNS_DBNAMESPACE_NORMAL, NULL, - NULL, &pval, NULL); + result = dns_qp_lookup(&qpr, name, DNS_DBNAMESPACE_NORMAL, NULL, NULL, + &pval, NULL); if (result == ISC_R_SUCCESS || result == DNS_R_PARTIALMATCH) { dns_forwarders_t *fwdrs = pval; *forwardersp = fwdrs; diff --git a/lib/dns/include/dns/qp.h b/lib/dns/include/dns/qp.h index 00dc461067..b88451a64d 100644 --- a/lib/dns/include/dns/qp.h +++ b/lib/dns/include/dns/qp.h @@ -541,8 +541,8 @@ dns_qp_getname(dns_qpreadable_t qpr, const dns_name_t *name, isc_result_t dns_qp_lookup(dns_qpreadable_t qpr, const dns_name_t *name, - dns_namespace_t space, dns_qpiter_t *iter, - dns_qpchain_t *chain, void **pval_r, uint32_t *ival_r); + dns_namespace_t space, dns_qpiter_t *iter, dns_qpchain_t *chain, + void **pval_r, uint32_t *ival_r); /*%< * Look up a leaf in a qp-trie that is equal to, or an ancestor domain of, * 'name' in the namespace 'space'. @@ -679,7 +679,6 @@ dns_qpiter_prev(dns_qpiter_t *qpi, void **pval_r, uint32_t *ival_r); * \li ISC_R_NOMORE otherwise */ - isc_result_t dns_qpiter_current(dns_qpiter_t *qpi, void **pval_r, uint32_t *ival_r); /*%< @@ -697,7 +696,6 @@ dns_qpiter_current(dns_qpiter_t *qpi, void **pval_r, uint32_t *ival_r); * at a leaf node */ - void dns_qpchain_init(dns_qpreadable_t qpr, dns_qpchain_t *chain); /*%< @@ -718,8 +716,8 @@ dns_qpchain_length(dns_qpchain_t *chain); */ void -dns_qpchain_node(dns_qpchain_t *chain, unsigned int level, - void **pval_r, uint32_t *ival_r); +dns_qpchain_node(dns_qpchain_t *chain, unsigned int level, void **pval_r, + uint32_t *ival_r); /*%< * Sets 'name' to the name of the leaf referenced at `chain->stack[level]`. * diff --git a/lib/dns/keytable.c b/lib/dns/keytable.c index 04fe2277b7..21b9e955e4 100644 --- a/lib/dns/keytable.c +++ b/lib/dns/keytable.c @@ -511,8 +511,8 @@ dns_keytable_finddeepestmatch(dns_keytable_t *keytable, const dns_name_t *name, REQUIRE(foundname != NULL); dns_qpmulti_query(keytable->table, &qpr); - result = dns_qp_lookup(&qpr, name, DNS_DBNAMESPACE_NORMAL, NULL, - NULL, &pval, NULL); + result = dns_qp_lookup(&qpr, name, DNS_DBNAMESPACE_NORMAL, NULL, NULL, + &pval, NULL); keynode = pval; if (result == ISC_R_SUCCESS || result == DNS_R_PARTIALMATCH) { @@ -541,8 +541,8 @@ dns_keytable_issecuredomain(dns_keytable_t *keytable, const dns_name_t *name, REQUIRE(dns_name_isabsolute(name)); dns_qpmulti_query(keytable->table, &qpr); - result = dns_qp_lookup(&qpr, name, DNS_DBNAMESPACE_NORMAL, NULL, - NULL, &pval, NULL); + result = dns_qp_lookup(&qpr, name, DNS_DBNAMESPACE_NORMAL, NULL, NULL, + &pval, NULL); if (result == ISC_R_SUCCESS || result == DNS_R_PARTIALMATCH) { keynode = pval; if (foundname != NULL) { diff --git a/lib/dns/nametree.c b/lib/dns/nametree.c index 41387bdf67..987b0cbeab 100644 --- a/lib/dns/nametree.c +++ b/lib/dns/nametree.c @@ -283,8 +283,8 @@ dns_nametree_covered(dns_nametree_t *nametree, const dns_name_t *name, REQUIRE(VALID_NAMETREE(nametree)); dns_qpmulti_query(nametree->table, &qpr); - result = dns_qp_lookup(&qpr, name, DNS_DBNAMESPACE_NORMAL, NULL, - NULL, (void **)&node, NULL); + result = dns_qp_lookup(&qpr, name, DNS_DBNAMESPACE_NORMAL, NULL, NULL, + (void **)&node, NULL); if (result == ISC_R_SUCCESS || result == DNS_R_PARTIALMATCH) { if (found != NULL) { dns_name_copy(&node->name, found); diff --git a/lib/dns/nta.c b/lib/dns/nta.c index e4cf9ab46d..39c6242e7b 100644 --- a/lib/dns/nta.c +++ b/lib/dns/nta.c @@ -413,8 +413,8 @@ dns_ntatable_covered(dns_ntatable_t *ntatable, isc_stdtime_t now, RWLOCK(&ntatable->rwlock, isc_rwlocktype_read); dns_qpmulti_query(ntatable->table, &qpr); - result = dns_qp_lookup(&qpr, name, DNS_DBNAMESPACE_NORMAL, NULL, - NULL, &pval, NULL); + result = dns_qp_lookup(&qpr, name, DNS_DBNAMESPACE_NORMAL, NULL, NULL, + &pval, NULL); nta = pval; switch (result) { diff --git a/lib/dns/qp.c b/lib/dns/qp.c index b38ee5f5c2..3317514f25 100644 --- a/lib/dns/qp.c +++ b/lib/dns/qp.c @@ -1881,8 +1881,8 @@ dns_qpchain_length(dns_qpchain_t *chain) { } void -dns_qpchain_node(dns_qpchain_t *chain, unsigned int level, - void **pval_r, uint32_t *ival_r) { +dns_qpchain_node(dns_qpchain_t *chain, unsigned int level, void **pval_r, + uint32_t *ival_r) { dns_qpnode_t *node = NULL; REQUIRE(QPCHAIN_VALID(chain)); @@ -2029,8 +2029,6 @@ dns_qpiter_prev(dns_qpiter_t *qpi, void **pval_r, uint32_t *ival_r) { return iterate(false, qpi, pval_r, ival_r); } - - isc_result_t dns_qpiter_current(dns_qpiter_t *qpi, void **pval_r, uint32_t *ival_r) { dns_qpnode_t *node = NULL; @@ -2047,7 +2045,6 @@ dns_qpiter_current(dns_qpiter_t *qpi, void **pval_r, uint32_t *ival_r) { return ISC_R_SUCCESS; } - /*********************************************************************** * * search @@ -2271,8 +2268,8 @@ fix_chain(dns_qpchain_t *chain, size_t offset) { isc_result_t dns_qp_lookup(dns_qpreadable_t qpr, const dns_name_t *name, - dns_namespace_t space, dns_qpiter_t *iter, - dns_qpchain_t *chain, void **pval_r, uint32_t *ival_r) { + dns_namespace_t space, dns_qpiter_t *iter, dns_qpchain_t *chain, + void **pval_r, uint32_t *ival_r) { dns_qpreader_t *qp = dns_qpreader(qpr); dns_qpkey_t search, found; size_t searchlen, foundlen; diff --git a/lib/dns/qp_p.h b/lib/dns/qp_p.h index 6ce46f3c22..ef9f1e3362 100644 --- a/lib/dns/qp_p.h +++ b/lib/dns/qp_p.h @@ -945,7 +945,6 @@ extern uint8_t dns_qp_byte_for_bit[]; /**********************************************************************/ - void dns__qp_initialize(void); void diff --git a/lib/dns/qpcache.c b/lib/dns/qpcache.c index 660d592da1..50218a3e25 100644 --- a/lib/dns/qpcache.c +++ b/lib/dns/qpcache.c @@ -1637,8 +1637,7 @@ qpcache_find(dns_db_t *db, const dns_name_t *name, dns_dbversion_t *version, isc_result_t zcresult; qpcnode_t *encloser = NULL; - dns_qpchain_node(&search.chain, i, (void **)&encloser, - NULL); + dns_qpchain_node(&search.chain, i, (void **)&encloser, NULL); zcresult = check_zonecut(encloser, (void *)&search DNS__DB_FLARG_PASS); @@ -2072,8 +2071,8 @@ qpcache_findzonecut(dns_db_t *db, const dns_name_t *name, unsigned int options, INSIST(len >= 2); node = NULL; - dns_qpchain_node(&search.chain, len - 2, - (void **)&node, NULL); + dns_qpchain_node(&search.chain, len - 2, (void **)&node, + NULL); search.chain.len = len - 1; } @@ -3516,8 +3515,8 @@ resume_iteration(qpc_dbit_t *qpdbiter, bool continuing) { if (continuing && qpdbiter->node != NULL) { isc_result_t result; result = dns_qp_lookup(qpdb->tree, qpdbiter->name, - DNS_DBNAMESPACE_NORMAL, - &qpdbiter->iter, NULL, NULL, NULL); + DNS_DBNAMESPACE_NORMAL, &qpdbiter->iter, + NULL, NULL, NULL); INSIST(result == ISC_R_SUCCESS); } @@ -3567,8 +3566,8 @@ dbiterator_first(dns_dbiterator_t *iterator DNS__DB_FLARG) { dereference_iter_node(qpdbiter DNS__DB_FLARG_PASS); dns_qpiter_init(qpdb->tree, &qpdbiter->iter); - result = dns_qpiter_next(&qpdbiter->iter, - (void **)&qpdbiter->node, NULL); + result = dns_qpiter_next(&qpdbiter->iter, (void **)&qpdbiter->node, + NULL); if (result == ISC_R_SUCCESS && qpdbiter->node->nspace == DNS_DBNAMESPACE_NORMAL) @@ -3657,8 +3656,8 @@ dbiterator_next(dns_dbiterator_t *iterator DNS__DB_FLARG) { dereference_iter_node(qpdbiter DNS__DB_FLARG_PASS); - result = dns_qpiter_next(&qpdbiter->iter, - (void **)&qpdbiter->node, NULL); + result = dns_qpiter_next(&qpdbiter->iter, (void **)&qpdbiter->node, + NULL); if (result == ISC_R_SUCCESS && qpdbiter->node->nspace == DNS_DBNAMESPACE_NORMAL) diff --git a/lib/dns/qpzone.c b/lib/dns/qpzone.c index 44a5addfb5..9a3273ddfd 100644 --- a/lib/dns/qpzone.c +++ b/lib/dns/qpzone.c @@ -2876,8 +2876,8 @@ find_wildcard(qpz_search_t *search, qpznode_t **nodep, const dns_name_t *qname, } result = dns_qp_lookup(&search->qpr, wname, nspace, - &wit, NULL, - (void **)&wnode, NULL); + &wit, NULL, (void **)&wnode, + NULL); if (result == ISC_R_SUCCESS) { /* * We have found the wildcard node. If it @@ -2973,7 +2973,8 @@ previous_closest_nsec(dns_rdatatype_t type, qpz_search_t *search, * NSEC record; we want the previous node * in the NSEC tree. */ - result = dns_qpiter_prev(nit, (void **)&node, NULL); + result = dns_qpiter_prev(nit, (void **)&node, + NULL); if (result == ISC_R_SUCCESS) { dns_name_copy(&node->name, name); } @@ -2984,7 +2985,8 @@ previous_closest_nsec(dns_rdatatype_t type, qpz_search_t *search, * node in the NSEC namespace, which is * what we want. */ - isc_result_t iresult = dns_qpiter_current(nit, (void **)&node, NULL); + isc_result_t iresult = dns_qpiter_current( + nit, (void **)&node, NULL); if (iresult == ISC_R_SUCCESS) { dns_name_copy(&node->name, name); } @@ -3009,9 +3011,9 @@ previous_closest_nsec(dns_rdatatype_t type, qpz_search_t *search, } *nodep = NULL; - result = dns_qp_lookup( - &search->qpr, name, DNS_DBNAMESPACE_NORMAL, - &search->iter, &search->chain, (void **)nodep, NULL); + result = dns_qp_lookup(&search->qpr, name, + DNS_DBNAMESPACE_NORMAL, &search->iter, + &search->chain, (void **)nodep, NULL); if (result == ISC_R_SUCCESS) { break; } @@ -3177,8 +3179,7 @@ again: } while (empty_node && result == ISC_R_SUCCESS); if (result == ISC_R_NOMORE && wraps) { - result = dns_qpiter_prev(&search->iter, (void **)&node, - NULL); + result = dns_qpiter_prev(&search->iter, (void **)&node, NULL); if (result == ISC_R_SUCCESS) { dns_name_copy(&node->name, name); wraps = false; @@ -4153,8 +4154,8 @@ dbiterator_first(dns_dbiterator_t *iterator DNS__DB_FLARG) { dereference_iter_node(qpdbiter DNS__DB_FLARG_PASS); dns_qpiter_init(qpdbiter->snap, &qpdbiter->iter); - result = dns_qpiter_next(&qpdbiter->iter, - (void **)&qpdbiter->node, NULL); + result = dns_qpiter_next(&qpdbiter->iter, (void **)&qpdbiter->node, + NULL); switch (qpdbiter->nsec3mode) { case nonsec3: @@ -4199,9 +4200,8 @@ dbiterator_first(dns_dbiterator_t *iterator DNS__DB_FLARG) { * origin node. */ result = dns_qp_lookup(qpdbiter->snap, &qpdb->common.origin, - DNS_DBNAMESPACE_NSEC3, - &qpdbiter->iter, NULL, - (void **)&qpdbiter->node, NULL); + DNS_DBNAMESPACE_NSEC3, &qpdbiter->iter, + NULL, (void **)&qpdbiter->node, NULL); if (result != ISC_R_SUCCESS || QPDBITER_NSEC3_ORIGIN_NODE(qpdb, qpdbiter)) { @@ -4241,8 +4241,8 @@ dbiterator_last(dns_dbiterator_t *iterator DNS__DB_FLARG) { dereference_iter_node(qpdbiter DNS__DB_FLARG_PASS); dns_qpiter_init(qpdbiter->snap, &qpdbiter->iter); - result = dns_qpiter_prev(&qpdbiter->iter, - (void **)&qpdbiter->node, NULL); + result = dns_qpiter_prev(&qpdbiter->iter, (void **)&qpdbiter->node, + NULL); switch (qpdbiter->nsec3mode) { case nsec3only: @@ -4289,9 +4289,8 @@ dbiterator_last(dns_dbiterator_t *iterator DNS__DB_FLARG) { * The final non-nsec node is before the the NSEC origin node. */ result = dns_qp_lookup(qpdbiter->snap, &qpdb->common.origin, - DNS_DBNAMESPACE_NSEC, - &qpdbiter->iter, NULL, - (void **)&qpdbiter->node, NULL); + DNS_DBNAMESPACE_NSEC, &qpdbiter->iter, + NULL, (void **)&qpdbiter->node, NULL); if (result == ISC_R_SUCCESS) { INSIST(QPDBITER_NSEC_ORIGIN_NODE(qpdb, qpdbiter)); /* skip the NSEC origin node */ @@ -4343,19 +4342,19 @@ dbiterator_seek(dns_dbiterator_t *iterator, switch (qpdbiter->nsec3mode) { case nsec3only: - result = dns_qp_lookup( - qpdbiter->snap, name, DNS_DBNAMESPACE_NSEC3, - &qpdbiter->iter, NULL, (void **)&qpdbiter->node, NULL); + result = dns_qp_lookup(qpdbiter->snap, name, + DNS_DBNAMESPACE_NSEC3, &qpdbiter->iter, + NULL, (void **)&qpdbiter->node, NULL); break; case nonsec3: - result = dns_qp_lookup( - qpdbiter->snap, name, DNS_DBNAMESPACE_NORMAL, - &qpdbiter->iter, NULL, (void **)&qpdbiter->node, NULL); + result = dns_qp_lookup(qpdbiter->snap, name, + DNS_DBNAMESPACE_NORMAL, &qpdbiter->iter, + NULL, (void **)&qpdbiter->node, NULL); break; case full: - result = dns_qp_lookup( - qpdbiter->snap, name, DNS_DBNAMESPACE_NORMAL, - &qpdbiter->iter, NULL, (void **)&qpdbiter->node, NULL); + result = dns_qp_lookup(qpdbiter->snap, name, + DNS_DBNAMESPACE_NORMAL, &qpdbiter->iter, + NULL, (void **)&qpdbiter->node, NULL); if (result != ISC_R_SUCCESS) { tresult = dns_qp_lookup(qpdbiter->snap, name, DNS_DBNAMESPACE_NSEC3, @@ -4403,8 +4402,8 @@ dbiterator_prev(dns_dbiterator_t *iterator DNS__DB_FLARG) { node = qpdbiter->node; qpdbiter->node = NULL; - result = dns_qpiter_prev(&qpdbiter->iter, - (void **)&qpdbiter->node, NULL); + result = dns_qpiter_prev(&qpdbiter->iter, (void **)&qpdbiter->node, + NULL); switch (qpdbiter->nsec3mode) { case nsec3only: @@ -4446,9 +4445,8 @@ dbiterator_prev(dns_dbiterator_t *iterator DNS__DB_FLARG) { INSIST(qpdbiter->node->nspace == DNS_DBNAMESPACE_NSEC); result = dns_qp_lookup(qpdbiter->snap, &qpdb->common.origin, - DNS_DBNAMESPACE_NSEC, - &qpdbiter->iter, NULL, - (void **)&qpdbiter->node, NULL); + DNS_DBNAMESPACE_NSEC, &qpdbiter->iter, + NULL, (void **)&qpdbiter->node, NULL); if (result == ISC_R_SUCCESS) { INSIST(QPDBITER_NSEC_ORIGIN_NODE(qpdb, qpdbiter)); @@ -4516,8 +4514,8 @@ dbiterator_next(dns_dbiterator_t *iterator DNS__DB_FLARG) { node = qpdbiter->node; qpdbiter->node = NULL; - result = dns_qpiter_next(&qpdbiter->iter, - (void **)&qpdbiter->node, NULL); + result = dns_qpiter_next(&qpdbiter->iter, (void **)&qpdbiter->node, + NULL); switch (qpdbiter->nsec3mode) { case nonsec3: @@ -4553,9 +4551,8 @@ dbiterator_next(dns_dbiterator_t *iterator DNS__DB_FLARG) { INSIST(qpdbiter->node->nspace == DNS_DBNAMESPACE_NSEC); result = dns_qp_lookup(qpdbiter->snap, &qpdb->common.origin, - DNS_DBNAMESPACE_NSEC3, - &qpdbiter->iter, NULL, - (void **)&qpdbiter->node, NULL); + DNS_DBNAMESPACE_NSEC3, &qpdbiter->iter, + NULL, (void **)&qpdbiter->node, NULL); if (result != ISC_R_SUCCESS || QPDBITER_NSEC3_ORIGIN_NODE(qpdb, qpdbiter)) { @@ -4666,8 +4663,8 @@ qpzone_createiterator(dns_db_t *db, unsigned int options, * seek the NSEC3 origin node. */ result = dns_qp_lookup(iter->snap, &qpdb->common.origin, - DNS_DBNAMESPACE_NSEC3, &iter->iter, - NULL, NULL, NULL); + DNS_DBNAMESPACE_NSEC3, &iter->iter, NULL, + NULL, NULL); INSIST(result == ISC_R_SUCCESS); break; default: diff --git a/lib/dns/rpz.c b/lib/dns/rpz.c index 676917d517..a7a9408438 100644 --- a/lib/dns/rpz.c +++ b/lib/dns/rpz.c @@ -2496,8 +2496,8 @@ dns_rpz_find_name(dns_rpz_zones_t *rpzs, dns_rpz_type_t rpz_type, dns_qpmulti_query(rpzs->table, &qpr); dns_qpchain_init(&qpr, &chain); - result = dns_qp_lookup(&qpr, trig_name, DNS_DBNAMESPACE_NORMAL, - NULL, &chain, (void **)&data, NULL); + result = dns_qp_lookup(&qpr, trig_name, DNS_DBNAMESPACE_NORMAL, NULL, + &chain, (void **)&data, NULL); switch (result) { case ISC_R_SUCCESS: INSIST(data != NULL); diff --git a/lib/dns/zt.c b/lib/dns/zt.c index 831fb7190f..f946a87da1 100644 --- a/lib/dns/zt.c +++ b/lib/dns/zt.c @@ -183,15 +183,14 @@ dns_zt_find(dns_zt_t *zt, const dns_name_t *name, dns_ztfind_t options, result = dns_qp_getname(&qpr, name, DNS_DBNAMESPACE_NORMAL, &pval, NULL); } else { - result = dns_qp_lookup(&qpr, name, DNS_DBNAMESPACE_NORMAL, - NULL, &chain, &pval, NULL); + result = dns_qp_lookup(&qpr, name, DNS_DBNAMESPACE_NORMAL, NULL, + &chain, &pval, NULL); if (exactopts == DNS_ZTFIND_NOEXACT && result == ISC_R_SUCCESS) { /* get pval from the previous chain link */ int len = dns_qpchain_length(&chain); if (len >= 2) { - dns_qpchain_node(&chain, len - 2, &pval, - NULL); + dns_qpchain_node(&chain, len - 2, &pval, NULL); result = DNS_R_PARTIALMATCH; } else { result = ISC_R_NOTFOUND; diff --git a/tests/bench/qplookups.c b/tests/bench/qplookups.c index 4617c1b84d..b1e19c0952 100644 --- a/tests/bench/qplookups.c +++ b/tests/bench/qplookups.c @@ -239,8 +239,8 @@ main(int argc, char **argv) { start = isc_time_monotonic(); for (i = 0; i < n; i++) { name = dns_fixedname_name(&items[i]); - dns_qp_lookup(qp, name, DNS_DBNAMESPACE_NORMAL, NULL, - NULL, NULL, NULL); + dns_qp_lookup(qp, name, DNS_DBNAMESPACE_NORMAL, NULL, NULL, + NULL, NULL); } stop = isc_time_monotonic(); @@ -265,8 +265,8 @@ main(int argc, char **argv) { ++search->ndata[1]; } - dns_qp_lookup(qp, search, DNS_DBNAMESPACE_NORMAL, NULL, - NULL, NULL, NULL); + dns_qp_lookup(qp, search, DNS_DBNAMESPACE_NORMAL, NULL, NULL, + NULL, NULL); } stop = isc_time_monotonic(); diff --git a/tests/dns/qp_test.c b/tests/dns/qp_test.c index 03c65be43e..fdfa07b8cb 100644 --- a/tests/dns/qp_test.c +++ b/tests/dns/qp_test.c @@ -96,7 +96,7 @@ qpiter_prev_with_name(dns_qpiter_t *qpi, dns_name_t *name, void **pval_r, static isc_result_t qpiter_current_with_name(dns_qpiter_t *qpi, dns_name_t *name, void **pval_r, - uint32_t *ival_r) { + uint32_t *ival_r) { isc_result_t result; void *pval = NULL; uint32_t ival = 0; @@ -352,9 +352,7 @@ ISC_RUN_TEST_IMPL(qpiter) { /* check that we see only valid items in the correct order */ uint32_t prev = 0; dns_qpiter_init(qp, &qpi); - while (dns_qpiter_next(&qpi, &pval, &ival) == - ISC_R_SUCCESS) - { + while (dns_qpiter_next(&qpi, &pval, &ival) == ISC_R_SUCCESS) { assert_in_range(ival, prev + 1, ITER_ITEMS - 1); assert_int_equal(ival, item[ival]); assert_ptr_equal(pval, &item[ival]); @@ -373,9 +371,7 @@ ISC_RUN_TEST_IMPL(qpiter) { /* now iterate backward and check correctness */ n = inserted; - while (dns_qpiter_prev(&qpi, NULL, &ival) == - ISC_R_SUCCESS) - { + while (dns_qpiter_prev(&qpi, NULL, &ival) == ISC_R_SUCCESS) { --n; assert_int_equal(ival, order[n]); @@ -389,9 +385,7 @@ ISC_RUN_TEST_IMPL(qpiter) { assert_int_equal(n, 0); /* ...and forward again */ - while (dns_qpiter_next(&qpi, NULL, &ival) == - ISC_R_SUCCESS) - { + while (dns_qpiter_next(&qpi, NULL, &ival) == ISC_R_SUCCESS) { assert_int_equal(ival, order[n]); /* and check current iterator value as well */ @@ -410,34 +404,28 @@ ISC_RUN_TEST_IMPL(qpiter) { * to confirm we can change directions while iterating. */ if (inserted > 3) { - assert_int_equal( - dns_qpiter_next(&qpi, NULL, &ival), - ISC_R_SUCCESS); + assert_int_equal(dns_qpiter_next(&qpi, NULL, &ival), + ISC_R_SUCCESS); assert_int_equal(ival, order[0]); - assert_int_equal( - dns_qpiter_next(&qpi, NULL, &ival), - ISC_R_SUCCESS); + assert_int_equal(dns_qpiter_next(&qpi, NULL, &ival), + ISC_R_SUCCESS); assert_int_equal(ival, order[1]); - assert_int_equal( - dns_qpiter_prev(&qpi, NULL, &ival), - ISC_R_SUCCESS); + assert_int_equal(dns_qpiter_prev(&qpi, NULL, &ival), + ISC_R_SUCCESS); assert_int_equal(ival, order[0]); - assert_int_equal( - dns_qpiter_next(&qpi, NULL, &ival), - ISC_R_SUCCESS); + assert_int_equal(dns_qpiter_next(&qpi, NULL, &ival), + ISC_R_SUCCESS); assert_int_equal(ival, order[1]); - assert_int_equal( - dns_qpiter_prev(&qpi, NULL, &ival), - ISC_R_SUCCESS); + assert_int_equal(dns_qpiter_prev(&qpi, NULL, &ival), + ISC_R_SUCCESS); assert_int_equal(ival, order[0]); - assert_int_equal( - dns_qpiter_prev(&qpi, NULL, &ival), - ISC_R_NOMORE); + assert_int_equal(dns_qpiter_prev(&qpi, NULL, &ival), + ISC_R_NOMORE); } } @@ -487,8 +475,8 @@ check_partialmatch(dns_qp_t *qp, struct check_partialmatch check[], dns_test_namefromstring(check[i].query, &fn1); dns_qpchain_init(qp, &chain); - result = dns_qp_lookup(qp, name, space, NULL, - &chain, &pval, NULL); + result = dns_qp_lookup(qp, name, space, NULL, &chain, &pval, + NULL); /* Extract the found name if we found something */ if ((result == ISC_R_SUCCESS || result == DNS_R_PARTIALMATCH) && @@ -658,8 +646,8 @@ check_qpchainiter(dns_qp_t *qp, struct check_qpchain check[], dns_qpchain_init(qp, &chain); dns_test_namefromstring(check[i].query, &fn1); - result = dns_qp_lookup(qp, name, check[i].space, iter, - &chain, NULL, NULL); + result = dns_qp_lookup(qp, name, check[i].space, iter, &chain, + NULL, NULL); #if 0 fprintf(stderr, "%s %s (expected %s), " @@ -887,8 +875,8 @@ check_predecessors_withchain(dns_qp_t *qp, struct check_predecessors check[], result = dns_name_tostring(expred, &predstr, isc_g_mctx); assert_int_equal(result, ISC_R_SUCCESS); - result = dns_qp_lookup(qp, name, check[i].space, &it, - chain, NULL, NULL); + result = dns_qp_lookup(qp, name, check[i].space, &it, chain, + NULL, NULL); #if 0 fprintf(stderr, "%s %s: expected %s got %s\n", check[i].query, check[i].space == DNS_DBNAMESPACE_NSEC3 @@ -909,14 +897,15 @@ check_predecessors_withchain(dns_qp_t *qp, struct check_predecessors check[], result = qpiter_prev_with_name(&it, pred, NULL, &ival); if (result == ISC_R_NOMORE) { result = qpiter_prev_with_name(&it, pred, NULL, - &ival); + &ival); } } else { /* * we didn't find a match, so the iterator should * already be pointed at the predecessor node. */ - result = qpiter_current_with_name(&it, pred, NULL, &ival); + result = qpiter_current_with_name(&it, pred, NULL, + &ival); } assert_int_equal(result, ISC_R_SUCCESS); @@ -936,7 +925,8 @@ check_predecessors_withchain(dns_qp_t *qp, struct check_predecessors check[], isc_mem_free(isc_g_mctx, predstr); int j = 0; - while (qpiter_next_with_name(&it, name, NULL, NULL) == ISC_R_SUCCESS) + while (qpiter_next_with_name(&it, name, NULL, NULL) == + ISC_R_SUCCESS) { #if 0 result = dns_name_tostring(name, &namestr, isc_g_mctx);