]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
use a count nametree for synthfromdnssec
authorEvan Hunt <each@isc.org>
Thu, 17 Aug 2023 07:45:38 +0000 (00:45 -0700)
committerOndřej Surý <ondrej@isc.org>
Mon, 4 Sep 2023 08:19:48 +0000 (10:19 +0200)
use the count semantics for dns_nametree to support view->sfd.

lib/dns/include/dns/view.h
lib/dns/view.c

index 9bb9f3bf13ea161322da6e3f1f4309161041c9e2..f8b1d943c75a536cba8b3e7be2f0a8cca8a97865 100644 (file)
@@ -143,9 +143,8 @@ struct dns_view {
        dns_nametree_t       *answeracl_exclude;
        dns_nametree_t       *denyanswernames;
        dns_nametree_t       *answernames_exclude;
+       dns_nametree_t       *sfd;
        dns_rrl_t            *rrl;
-       dns_rbt_t            *sfd;
-       isc_rwlock_t          sfd_lock;
        bool                  provideixfr;
        bool                  requestnsid;
        bool                  sendcookie;
index be043cee2ff76e41ee8f1f8cf592ef149208d8ec..7c486acebbe3085d5cbc6fa9c0dd8af7bddacc57 100644 (file)
@@ -137,8 +137,6 @@ dns_view_create(isc_mem_t *mctx, dns_dispatchmgr_t *dispatchmgr,
 
        isc_mutex_init(&view->lock);
 
-       isc_rwlock_init(&view->sfd_lock);
-
        dns_zt_create(mctx, view, &view->zonetable);
 
        dns_fwdtable_create(mctx, view, &view->fwdtable);
@@ -196,7 +194,6 @@ cleanup_new_zone_lock:
        dns_fwdtable_destroy(&view->fwdtable);
        dns_zt_detach(&view->zonetable);
 
-       isc_rwlock_destroy(&view->sfd_lock);
        isc_mutex_destroy(&view->lock);
 
        if (view->nta_file != NULL) {
@@ -358,7 +355,7 @@ destroy(dns_view_t *view) {
                dns_nametree_detach(&view->answernames_exclude);
        }
        if (view->sfd != NULL) {
-               dns_rbt_destroy(&view->sfd);
+               dns_nametree_detach(&view->sfd);
        }
        if (view->secroots_priv != NULL) {
                dns_keytable_detach(&view->secroots_priv);
@@ -408,7 +405,6 @@ destroy(dns_view_t *view) {
                dns_badcache_destroy(&view->failcache);
        }
        isc_mutex_destroy(&view->new_zone_lock);
-       isc_rwlock_destroy(&view->sfd_lock);
        isc_mutex_destroy(&view->lock);
        isc_refcount_destroy(&view->references);
        isc_refcount_destroy(&view->weakrefs);
@@ -2318,58 +2314,26 @@ dns_view_flushonshutdown(dns_view_t *view, bool flush) {
        view->flush = flush;
 }
 
-static void
-free_sfd(void *data, void *arg) {
-       isc_mem_put(arg, data, sizeof(unsigned int));
-}
-
 void
 dns_view_sfd_add(dns_view_t *view, const dns_name_t *name) {
        isc_result_t result;
-       dns_rbtnode_t *node = NULL;
 
        REQUIRE(DNS_VIEW_VALID(view));
 
-       RWLOCK(&view->sfd_lock, isc_rwlocktype_write);
        if (view->sfd == NULL) {
-               result = dns_rbt_create(view->mctx, free_sfd, view->mctx,
-                                       &view->sfd);
-               RUNTIME_CHECK(result == ISC_R_SUCCESS);
+               dns_nametree_create(view->mctx, DNS_NAMETREE_COUNT, "sfd",
+                                   &view->sfd);
        }
 
-       result = dns_rbt_addnode(view->sfd, name, &node);
-       RUNTIME_CHECK(result == ISC_R_SUCCESS || result == ISC_R_EXISTS);
-       if (node->data != NULL) {
-               unsigned int *count = node->data;
-               (*count)++;
-       } else {
-               unsigned int *count = isc_mem_get(view->mctx,
-                                                 sizeof(unsigned int));
-               *count = 1;
-               node->data = count;
-       }
-       RWUNLOCK(&view->sfd_lock, isc_rwlocktype_write);
+       result = dns_nametree_add(view->sfd, name, 0);
+       RUNTIME_CHECK(result == ISC_R_SUCCESS);
 }
 
 void
 dns_view_sfd_del(dns_view_t *view, const dns_name_t *name) {
-       isc_result_t result;
-       void *data = NULL;
-
        REQUIRE(DNS_VIEW_VALID(view));
 
-       RWLOCK(&view->sfd_lock, isc_rwlocktype_write);
-       INSIST(view->sfd != NULL);
-       result = dns_rbt_findname(view->sfd, name, 0, NULL, &data);
-       if (result == ISC_R_SUCCESS) {
-               unsigned int *count = data;
-               INSIST(count != NULL);
-               if (--(*count) == 0U) {
-                       result = dns_rbt_deletename(view->sfd, name, false);
-                       RUNTIME_CHECK(result == ISC_R_SUCCESS);
-               }
-       }
-       RWUNLOCK(&view->sfd_lock, isc_rwlocktype_write);
+       dns_nametree_delete(view->sfd, name);
 }
 
 void
@@ -2378,17 +2342,9 @@ dns_view_sfd_find(dns_view_t *view, const dns_name_t *name,
        REQUIRE(DNS_VIEW_VALID(view));
 
        if (view->sfd != NULL) {
-               isc_result_t result;
-               void *data = NULL;
-
-               RWLOCK(&view->sfd_lock, isc_rwlocktype_read);
-               result = dns_rbt_findname(view->sfd, name, 0, foundname, &data);
-               RWUNLOCK(&view->sfd_lock, isc_rwlocktype_read);
-               if (result != ISC_R_SUCCESS && result != DNS_R_PARTIALMATCH) {
+               if (!dns_nametree_covered(view->sfd, name, foundname, 0)) {
                        dns_name_copy(dns_rootname, foundname);
                }
-       } else {
-               dns_name_copy(dns_rootname, foundname);
        }
 }