From: Alessio Podda Date: Tue, 7 Apr 2026 18:05:44 +0000 (+0200) Subject: fixup! DROP: batch zone insert X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5b96cf9f242c58cb160c7f9052b63e499afa19ed;p=thirdparty%2Fbind9.git fixup! DROP: batch zone insert --- diff --git a/lib/dns/include/dns/nametree.h b/lib/dns/include/dns/nametree.h index 98a230e6bf6..4e4a5cd9c2b 100644 --- a/lib/dns/include/dns/nametree.h +++ b/lib/dns/include/dns/nametree.h @@ -98,6 +98,18 @@ dns_nametree_add(dns_nametree_t *nametree, const dns_name_t *name, *\li Any other result indicates failure. */ +void +dns_nametree_add_batch(dns_nametree_t *nametree, const dns_name_t **names, + unsigned int count, uint32_t value); +/*%< + * Add multiple names to 'nametree' in a single QP transaction. + * + * Requires: + * + *\li 'nametree' points to a valid nametree. + *\li 'names' is non-NULL. + */ + isc_result_t dns_nametree_delete(dns_nametree_t *nametree, const dns_name_t *name); /*%< diff --git a/lib/dns/include/dns/view.h b/lib/dns/include/dns/view.h index 8ef568499b1..c966ed0b7d0 100644 --- a/lib/dns/include/dns/view.h +++ b/lib/dns/include/dns/view.h @@ -1167,6 +1167,18 @@ dns_view_sfd_add(dns_view_t *view, const dns_name_t *name); *\li 'name' to be valid. */ +void +dns_view_sfd_add_batch(dns_view_t *view, const dns_name_t **names, + unsigned int count); +/*%< + * Add multiple names to the synth-from-dnssec namespace tree in a + * single QP transaction. + * + * Requires: + *\li 'view' to be valid. + *\li 'names' to be non-NULL. + */ + void dns_view_sfd_del(dns_view_t *view, const dns_name_t *name); /*%< diff --git a/lib/dns/nametree.c b/lib/dns/nametree.c index 987b0cbeab8..1edad1a857e 100644 --- a/lib/dns/nametree.c +++ b/lib/dns/nametree.c @@ -142,19 +142,13 @@ matchbit(unsigned char *bits, uint32_t val) { return false; } -isc_result_t -dns_nametree_add(dns_nametree_t *nametree, const dns_name_t *name, - uint32_t value) { +static isc_result_t +nametree_add(dns_nametree_t *nametree, dns_qp_t *qp, const dns_name_t *name, + uint32_t value) { isc_result_t result; - dns_qp_t *qp = NULL; uint32_t size, pos, mask, count = 0; dns_ntnode_t *old = NULL, *new = NULL; - REQUIRE(VALID_NAMETREE(nametree)); - REQUIRE(name != NULL); - - dns_qpmulti_write(nametree->table, &qp); - switch (nametree->type) { case DNS_NAMETREE_BOOL: new = newnode(nametree->mctx, name); @@ -175,7 +169,7 @@ dns_nametree_add(dns_nametree_t *nametree, const dns_name_t *name, result = dns_qp_getname(qp, name, DNS_DBNAMESPACE_NORMAL, (void **)&old, NULL); if (result == ISC_R_SUCCESS && matchbit(old->bits, value)) { - goto out; + return (ISC_R_SUCCESS); } size = pos = value / 8 + 2; @@ -208,12 +202,41 @@ dns_nametree_add(dns_nametree_t *nametree, const dns_name_t *name, */ dns_ntnode_detach(&new); -out: + return (result); +} + +isc_result_t +dns_nametree_add(dns_nametree_t *nametree, const dns_name_t *name, + uint32_t value) { + isc_result_t result; + dns_qp_t *qp = NULL; + + REQUIRE(VALID_NAMETREE(nametree)); + REQUIRE(name != NULL); + + dns_qpmulti_write(nametree->table, &qp); + result = nametree_add(nametree, qp, name, value); dns_qp_compact(qp, DNS_QPGC_MAYBE); dns_qpmulti_commit(nametree->table, &qp); return result; } +void +dns_nametree_add_batch(dns_nametree_t *nametree, const dns_name_t **names, + unsigned int count, uint32_t value) { + dns_qp_t *qp = NULL; + + REQUIRE(VALID_NAMETREE(nametree)); + REQUIRE(names != NULL); + + dns_qpmulti_write(nametree->table, &qp); + for (unsigned int i = 0; i < count; i++) { + (void)nametree_add(nametree, qp, names[i], value); + } + dns_qp_compact(qp, DNS_QPGC_ALL); + dns_qpmulti_commit(nametree->table, &qp); +} + isc_result_t dns_nametree_delete(dns_nametree_t *nametree, const dns_name_t *name) { isc_result_t result; diff --git a/lib/dns/view.c b/lib/dns/view.c index 8f25efb4309..575fda9941e 100644 --- a/lib/dns/view.c +++ b/lib/dns/view.c @@ -717,9 +717,13 @@ dns_view_addzone_batch(dns_view_t *view, dns_zone_t **zones, } rcu_read_unlock(); + const dns_name_t **names = + isc_mem_cget(view->mctx, count, sizeof(*names)); for (unsigned int i = 0; i < count; i++) { - dns_view_sfd_add(view, dns_zone_getorigin(zones[i])); + names[i] = dns_zone_getorigin(zones[i]); } + dns_view_sfd_add_batch(view, names, count); + isc_mem_cput(view->mctx, names, count, sizeof(*names)); } isc_result_t @@ -1979,6 +1983,14 @@ dns_view_sfd_add(dns_view_t *view, const dns_name_t *name) { RUNTIME_CHECK(result == ISC_R_SUCCESS); } +void +dns_view_sfd_add_batch(dns_view_t *view, const dns_name_t **names, + unsigned int count) { + REQUIRE(DNS_VIEW_VALID(view)); + + dns_nametree_add_batch(view->sfd, names, count, 0); +} + void dns_view_sfd_del(dns_view_t *view, const dns_name_t *name) { REQUIRE(DNS_VIEW_VALID(view));