From: Mark Andrews Date: Wed, 31 May 2023 05:52:36 +0000 (+1000) Subject: Add dns_view_apply X-Git-Tag: v9.19.14~12^2~3 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=ceb3264082a7726c8deda2619873c67203a637da;p=thirdparty%2Fbind9.git Add dns_view_apply Add dns_view_apply to allow dns_zt_apply to be called on view->zonetable with rcu locking applied. --- diff --git a/bin/named/server.c b/bin/named/server.c index 425fdcc8716..c51f388fbfb 100644 --- a/bin/named/server.c +++ b/bin/named/server.c @@ -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; diff --git a/bin/named/statschannel.c b/bin/named/statschannel.c index bbb402262e0..0b97cdaa7b3 100644 --- a/bin/named/statschannel.c +++ b/bin/named/statschannel.c @@ -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) { diff --git a/lib/dns/include/dns/view.h b/lib/dns/include/dns/view.h index aa0a650f0b4..51f5fceb897 100644 --- a/lib/dns/include/dns/view.h +++ b/lib/dns/include/dns/view.h @@ -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 diff --git a/lib/dns/view.c b/lib/dns/view.c index 809223f67df..55347368e74 100644 --- a/lib/dns/view.c +++ b/lib/dns/view.c @@ -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); +} diff --git a/tests/dns/zt_test.c b/tests/dns/zt_test.c index 33232f1edbc..2ca5f14a2dd 100644 --- a/tests/dns/zt_test.c +++ b/tests/dns/zt_test.c @@ -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);