]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Add dns_view_apply
authorMark Andrews <marka@isc.org>
Wed, 31 May 2023 05:52:36 +0000 (15:52 +1000)
committerOndřej Surý <ondrej@isc.org>
Thu, 1 Jun 2023 14:51:38 +0000 (16:51 +0200)
Add dns_view_apply to allow dns_zt_apply to be called on
view->zonetable with rcu locking applied.

bin/named/server.c
bin/named/statschannel.c
lib/dns/include/dns/view.h
lib/dns/view.c
tests/dns/zt_test.c

index 425fdcc871683a316eb99244f9810ed09b95f6d7..c51f388fbfb6b0c203984360e4253d92d7bd3e3c 100644 (file)
@@ -9740,8 +9740,7 @@ cleanup_viewlist:
                if (result == ISC_R_SUCCESS && strcmp(view->name, "_bind") != 0)
                {
                        dns_view_setviewrevert(view);
-                       (void)dns_zt_apply(view->zonetable, false, NULL,
-                                          removed, view);
+                       (void)dns_view_apply(view, false, NULL, removed, view);
                }
                dns_view_detach(&view);
        }
@@ -11311,8 +11310,8 @@ add_view_tolist(struct dumpcontext *dctx, dns_view_t *view) {
        ISC_LIST_INIT(vle->zonelist);
        ISC_LIST_APPEND(dctx->viewlist, vle, link);
        if (dctx->dumpzones) {
-               result = dns_zt_apply(view->zonetable, true, NULL,
-                                     add_zone_tolist, dctx);
+               result = dns_view_apply(view, true, NULL, add_zone_tolist,
+                                       dctx);
        }
        return (result);
 }
@@ -12409,8 +12408,8 @@ named_server_sync(named_server_t *server, isc_lex_t *lex, isc_buffer_t **text) {
                for (view = ISC_LIST_HEAD(server->viewlist); view != NULL;
                     view = ISC_LIST_NEXT(view, link))
                {
-                       result = dns_zt_apply(view->zonetable, false, NULL,
-                                             synczone, &cleanup);
+                       result = dns_view_apply(view, false, NULL, synczone,
+                                               &cleanup);
                        if (result != ISC_R_SUCCESS && tresult == ISC_R_SUCCESS)
                        {
                                tresult = result;
index bbb402262e0946a5970d58e3e6b93a4d0326a206..0b97cdaa7b355470b21ba40ff322821e6b2f2e1d 100644 (file)
@@ -1780,8 +1780,8 @@ generatexml(named_server_t *server, uint32_t flags, int *buflen,
                if ((flags & STATS_XML_ZONES) != 0) {
                        TRY0(xmlTextWriterStartElement(writer,
                                                       ISC_XMLCHAR "zones"));
-                       CHECK(dns_zt_apply(view->zonetable, true, NULL,
-                                          zone_xmlrender, writer));
+                       CHECK(dns_view_apply(view, true, NULL, zone_xmlrender,
+                                            writer));
                        TRY0(xmlTextWriterEndElement(writer)); /* /zones */
                }
 
@@ -2494,8 +2494,8 @@ generatejson(named_server_t *server, size_t *msglen, const char **msg,
                        CHECKMEM(za);
 
                        if ((flags & STATS_JSON_ZONES) != 0) {
-                               CHECK(dns_zt_apply(view->zonetable, true, NULL,
-                                                  zone_jsonrender, za));
+                               CHECK(dns_view_apply(view, true, NULL,
+                                                    zone_jsonrender, za));
                        }
 
                        if (json_object_array_length(za) != 0) {
index aa0a650f0b4f9ac04928b9857f8629f4d58fd447..51f5fceb8979eb04cacbbded1d92c9b6be5008c1 100644 (file)
@@ -1291,4 +1291,20 @@ dns_view_addtrustedkey(dns_view_t *view, dns_rdatatype_t rdtype,
  *
  *\li  Anything else                           Failure.
  */
+
+isc_result_t
+dns_view_apply(dns_view_t *view, bool stop, isc_result_t *sub,
+              isc_result_t (*action)(dns_zone_t *, void *), void *uap);
+/*%<
+ * Call dns_zt_apply on the view's zonetable.
+ *
+ * Returns:
+ * \li  ISC_R_SUCCESS if action was applied to all nodes.  If 'stop' is
+ *     false and 'sub' is non NULL then the first error (if any)
+ *     reported by 'action' is returned in '*sub'. If 'stop' is true,
+ *     the first error code from 'action' is returned.
+ *
+ * \li ISC_R_SHUTTINGDOWN if the view is in the process of shutting down.
+ */
+
 ISC_LANG_ENDDECLS
index 809223f67dfc60b31b868281eaef58562ec40775..55347368e74a6df5a0164a4cce7482865f1a1b05 100644 (file)
@@ -2474,3 +2474,22 @@ dns_view_addtrustedkey(dns_view_t *view, dns_rdatatype_t rdtype,
 cleanup:
        return (result);
 }
+
+isc_result_t
+dns_view_apply(dns_view_t *view, bool stop, isc_result_t *sub,
+              isc_result_t (*action)(dns_zone_t *, void *), void *uap) {
+       isc_result_t result;
+       dns_zt_t *zonetable = NULL;
+
+       REQUIRE(DNS_VIEW_VALID(view));
+
+       rcu_read_lock();
+       zonetable = rcu_dereference(view->zonetable);
+       if (zonetable != NULL) {
+               result = dns_zt_apply(zonetable, stop, sub, action, uap);
+       } else {
+               result = ISC_R_SHUTTINGDOWN;
+       }
+       rcu_read_unlock();
+       return (result);
+}
index 33232f1edbc5edad5a665b8a026567a6c8e15d46..2ca5f14a2dd7c817d6b61ae540bec3ef2b169785 100644 (file)
@@ -71,8 +71,7 @@ ISC_LOOP_TEST_IMPL(apply) {
        assert_non_null(zt);
 
        assert_int_equal(nzones, 0);
-       result = dns_zt_apply(view->zonetable, false, NULL, count_zone,
-                             &nzones);
+       result = dns_view_apply(view, false, NULL, count_zone, &nzones);
        assert_int_equal(result, ISC_R_SUCCESS);
        assert_int_equal(nzones, 1);