diff --git a/lib/dns/forward.c b/lib/dns/forward.c index 0be252f3ac..f48a3dc076 100644 --- a/lib/dns/forward.c +++ b/lib/dns/forward.c @@ -168,8 +168,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_findname_ancestor(&qpr, name, NULL, NULL, NULL, &pval, - NULL); + result = dns_qp_lookup(&qpr, name, NULL, 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 f38eee37ac..cb92d4f78d 100644 --- a/lib/dns/include/dns/qp.h +++ b/lib/dns/include/dns/qp.h @@ -235,10 +235,10 @@ typedef struct dns_qpiter { /*% * A QP chain holds references to each populated node between the root and - * a given leaf. It is used internally by `dns_qp_findname_ancestor()` to - * return a partial match if the specific name requested is not found; - * optionally it can be passed back to the caller so that individual nodes - * can be accessed. + * a given leaf. It is used internally by `dns_qp_lookup()` to return a + * partial match if the specific name requested is not found; optionally it + * can be passed back to the caller so that individual nodes can be + * accessed. */ typedef struct dns_qpchain { unsigned int magic; @@ -527,24 +527,33 @@ dns_qp_getname(dns_qpreadable_t qpr, const dns_name_t *name, void **pval_r, */ isc_result_t -dns_qp_findname_ancestor(dns_qpreadable_t qpr, const dns_name_t *name, - dns_name_t *foundname, dns_name_t *predecessor, - dns_qpchain_t *chain, void **pval_r, uint32_t *ival_r); +dns_qp_lookup(dns_qpreadable_t qpr, const dns_name_t *name, + dns_name_t *foundname, dns_name_t *predecessor, + dns_qpchain_t *chain, void **pval_r, uint32_t *ival_r); /*%< - * Find a leaf in a qp-trie that is an ancestor domain of, or equal to, the - * given DNS name. + * Look up a leaf in a qp-trie that is equal to, or an ancestor domain of, + * 'name'. * - * If 'foundname' is not NULL, it is updated to contain the name found. - * - * If 'predecessor' is not NULL, it is updated to contain the DNSSEC - * predecessor of the searched-for name. + * If 'foundname' is not NULL, it will be updated to contain the name + * that was found (if any). The return code, ISC_R_SUCCESS or + * DNS_R_PARTIALMATCH, indicates whether the name found is name that + * was requested, or an ancestor. If the result is ISC_R_NOTFOUND, + * 'foundname' will not be updated. * * If 'chain' is not NULL, it is updated to contain a QP chain with * references to the populated nodes in the tree between the root and - * the name found. + * the name that was found. If the return code is DNS_R_PARTIALMATCH + * then the chain terminates at the closest ancestor found; if it is + * ISC_R_SUCCESS then it terminates at the name that was requested. + * If the result is ISC_R_NOTFOUND, 'chain' will not be updated. * - * The leaf values are assigned to whichever of `*pval_r` and `*ival_r` - * are not null, unless the return value is ISC_R_NOTFOUND. + * If 'predecessor' is not NULL, it will be updated to contain the + * closest predecessor of the searched-for name that exists in the + * trie. + * + * The leaf data for the node that was found will be assigned to + * whichever of `*pval_r` and `*ival_r` are not NULL, unless the + * return value is ISC_R_NOTFOUND. * * Requires: * \li `qpr` is a pointer to a readable qp-trie diff --git a/lib/dns/keytable.c b/lib/dns/keytable.c index e8ce21fa19..7284140951 100644 --- a/lib/dns/keytable.c +++ b/lib/dns/keytable.c @@ -518,8 +518,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_findname_ancestor(&qpr, name, NULL, NULL, NULL, &pval, - NULL); + result = dns_qp_lookup(&qpr, name, NULL, NULL, NULL, &pval, NULL); keynode = pval; if (result == ISC_R_SUCCESS || result == DNS_R_PARTIALMATCH) { @@ -548,8 +547,7 @@ dns_keytable_issecuredomain(dns_keytable_t *keytable, const dns_name_t *name, REQUIRE(wantdnssecp != NULL); dns_qpmulti_query(keytable->table, &qpr); - result = dns_qp_findname_ancestor(&qpr, name, NULL, NULL, NULL, &pval, - NULL); + result = dns_qp_lookup(&qpr, name, NULL, 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 60fa9a97f0..f2b3232726 100644 --- a/lib/dns/nametree.c +++ b/lib/dns/nametree.c @@ -289,8 +289,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_findname_ancestor(&qpr, name, found, NULL, NULL, - (void **)&node, NULL); + result = dns_qp_lookup(&qpr, name, found, NULL, NULL, (void **)&node, + NULL); if (result == ISC_R_SUCCESS || result == DNS_R_PARTIALMATCH) { switch (nametree->type) { case DNS_NAMETREE_BOOL: diff --git a/lib/dns/nta.c b/lib/dns/nta.c index c86b0ebf7b..060fa6c32d 100644 --- a/lib/dns/nta.c +++ b/lib/dns/nta.c @@ -413,8 +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_findname_ancestor(&qpr, name, NULL, NULL, NULL, &pval, - NULL); + result = dns_qp_lookup(&qpr, name, NULL, NULL, NULL, &pval, NULL); nta = pval; switch (result) { diff --git a/lib/dns/qp.c b/lib/dns/qp.c index c554c85d23..4bc75414c9 100644 --- a/lib/dns/qp.c +++ b/lib/dns/qp.c @@ -2012,10 +2012,9 @@ prevleaf(dns_qpiter_t *it) { } isc_result_t -dns_qp_findname_ancestor(dns_qpreadable_t qpr, const dns_name_t *name, - dns_name_t *foundname, dns_name_t *predecessor, - dns_qpchain_t *chain, void **pval_r, - uint32_t *ival_r) { +dns_qp_lookup(dns_qpreadable_t qpr, const dns_name_t *name, + dns_name_t *foundname, dns_name_t *predecessor, + 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/zt.c b/lib/dns/zt.c index 147e6fc830..7f1b416023 100644 --- a/lib/dns/zt.c +++ b/lib/dns/zt.c @@ -178,8 +178,7 @@ dns_zt_find(dns_zt_t *zt, const dns_name_t *name, dns_ztfind_t options, dns_qpmulti_query(zt->multi, &qpr); - result = dns_qp_findname_ancestor(&qpr, name, NULL, NULL, &chain, &pval, - NULL); + result = dns_qp_lookup(&qpr, name, NULL, NULL, &chain, &pval, NULL); if (exactopts == DNS_ZTFIND_EXACT && result == DNS_R_PARTIALMATCH) { result = ISC_R_NOTFOUND; } else if (exactopts == DNS_ZTFIND_NOEXACT && result == ISC_R_SUCCESS) { diff --git a/tests/bench/qplookups.c b/tests/bench/qplookups.c index fd50ad37ca..be85825ec3 100644 --- a/tests/bench/qplookups.c +++ b/tests/bench/qplookups.c @@ -250,12 +250,11 @@ main(int argc, char **argv) { start = isc_time_monotonic(); for (i = 0; i < n; i++) { name = dns_fixedname_name(&items[i]); - dns_qp_findname_ancestor(qp, name, 0, NULL, NULL, NULL, NULL); + dns_qp_lookup(qp, name, 0, NULL, NULL, NULL, NULL); } stop = isc_time_monotonic(); - snprintf(buf, sizeof(buf), - "look up %zd names (dns_qp_findname_ancestor):", n); + snprintf(buf, sizeof(buf), "look up %zd names (dns_qp_lookup):", n); printf("%-57s%7.3fsec\n", buf, (stop - start) / (double)NS_PER_SEC); start = isc_time_monotonic(); @@ -276,12 +275,12 @@ main(int argc, char **argv) { ++search->ndata[1]; } - dns_qp_findname_ancestor(qp, search, 0, NULL, NULL, NULL, NULL); + dns_qp_lookup(qp, search, 0, NULL, NULL, NULL, NULL); } stop = isc_time_monotonic(); snprintf(buf, sizeof(buf), - "look up %zd wrong names (dns_qp_findname_ancestor):", n); + "look up %zd wrong names (dns_qp_lookup):", n); printf("%-57s%7.3fsec\n", buf, (stop - start) / (double)NS_PER_SEC); isc_mem_cput(mctx, items, n, sizeof(dns_fixedname_t)); diff --git a/tests/dns/qp_test.c b/tests/dns/qp_test.c index 6c83f8f365..c0c399085f 100644 --- a/tests/dns/qp_test.c +++ b/tests/dns/qp_test.c @@ -349,8 +349,8 @@ check_partialmatch(dns_qp_t *qp, struct check_partialmatch check[]) { void *pval = NULL; dns_test_namefromstring(check[i].query, &fn1); - result = dns_qp_findname_ancestor(qp, name, foundname, NULL, - NULL, &pval, NULL); + result = dns_qp_lookup(qp, name, foundname, NULL, NULL, &pval, + NULL); #if 0 fprintf(stderr, "%s %s (expected %s) " @@ -496,8 +496,8 @@ check_qpchain(dns_qp_t *qp, struct check_qpchain check[]) { dns_qpchain_init(qp, &chain); dns_test_namefromstring(check[i].query, &fn1); - result = dns_qp_findname_ancestor(qp, name, NULL, NULL, &chain, - NULL, NULL); + result = dns_qp_lookup(qp, name, NULL, NULL, &chain, NULL, + NULL); #if 0 fprintf(stderr, "%s %s (expected %s), " @@ -574,8 +574,7 @@ check_predecessors(dns_qp_t *qp, struct check_predecessors check[]) { char *predname = NULL; dns_test_namefromstring(check[i].query, &fn1); - result = dns_qp_findname_ancestor(qp, name, NULL, pred, NULL, - NULL, NULL); + result = dns_qp_lookup(qp, name, NULL, pred, NULL, NULL, NULL); #if 0 fprintf(stderr, "%s: expected %s got %s\n", check[i].query, isc_result_totext(check[i].result),