From 8d86fa7135136f50e17ef0318aa127b6e7dad232 Mon Sep 17 00:00:00 2001 From: Mark Andrews Date: Wed, 31 May 2023 16:03:56 +1000 Subject: [PATCH] Extend dns_view_findzone to take an options argument This is in preparation to allow the few remaining direct dns_zt_find(view->zonetable, ...) to use it for rcu mediated access to view->zonetable. --- bin/named/server.c | 46 +++++++++++++++++----------- bin/tests/system/dyndb/driver/zone.c | 2 +- lib/dns/catz.c | 2 +- lib/dns/dlz.c | 2 +- lib/dns/include/dns/view.h | 6 ++-- lib/dns/view.c | 4 +-- lib/ns/notify.c | 3 +- lib/ns/update.c | 3 +- lib/ns/xfrout.c | 3 +- 9 files changed, 42 insertions(+), 29 deletions(-) diff --git a/bin/named/server.c b/bin/named/server.c index c51f388fbf..4456cfb12c 100644 --- a/bin/named/server.c +++ b/bin/named/server.c @@ -2708,7 +2708,7 @@ catz_addmodzone_cb(void *arg) { goto cleanup; } - result = dns_view_findzone(cz->view, name, &zone); + result = dns_view_findzone(cz->view, name, DNS_ZTFIND_EXACT, &zone); if (cz->mod) { dns_catz_zone_t *parentcatz; @@ -2834,7 +2834,7 @@ catz_addmodzone_cb(void *arg) { } /* Is it there yet? */ - CHECK(dns_view_findzone(cz->view, name, &zone)); + CHECK(dns_view_findzone(cz->view, name, DNS_ZTFIND_EXACT, &zone)); /* * Load the zone from the master file. If this fails, we'll @@ -2891,7 +2891,7 @@ catz_delzone_cb(void *arg) { dns_name_format(dns_catz_entry_getname(cz->entry), cname, DNS_NAME_FORMATSIZE); result = dns_view_findzone(cz->view, dns_catz_entry_getname(cz->entry), - &zone); + DNS_ZTFIND_EXACT, &zone); if (result != ISC_R_SUCCESS) { isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL, NAMED_LOGMODULE_SERVER, ISC_LOG_WARNING, @@ -3068,7 +3068,8 @@ configure_catz_zone(dns_view_t *view, dns_view_t *pview, isc_ht_iter_current(it, (void **)&entry); name = dns_catz_entry_getname(entry); - tresult = dns_view_findzone(pview, name, &dnszone); + tresult = dns_view_findzone(pview, name, + DNS_ZTFIND_EXACT, &dnszone); if (tresult != ISC_R_SUCCESS) { continue; } @@ -5036,7 +5037,8 @@ configure_view(dns_view_t *view, dns_viewlist_t *viewlist, cfg_obj_t *config, */ if (view->hints == NULL) { dns_zone_t *rootzone = NULL; - (void)dns_view_findzone(view, dns_rootname, &rootzone); + (void)dns_view_findzone(view, dns_rootname, DNS_ZTFIND_EXACT, + &rootzone); if (rootzone != NULL) { dns_zone_detach(&rootzone); need_hints = false; @@ -5768,7 +5770,8 @@ configure_view(dns_view_t *view, dns_viewlist_t *viewlist, cfg_obj_t *config, /* * This zone already exists. */ - (void)dns_view_findzone(view, name, &zone); + (void)dns_view_findzone(view, name, DNS_ZTFIND_EXACT, + &zone); if (zone != NULL) { dns_zone_detach(&zone); continue; @@ -5799,7 +5802,8 @@ configure_view(dns_view_t *view, dns_viewlist_t *viewlist, cfg_obj_t *config, } if (pview != NULL) { - (void)dns_view_findzone(pview, name, &zone); + (void)dns_view_findzone( + pview, name, DNS_ZTFIND_EXACT, &zone); dns_view_detach(&pview); } @@ -5858,7 +5862,8 @@ configure_view(dns_view_t *view, dns_viewlist_t *viewlist, cfg_obj_t *config, CHECK(dns_name_fromstring( name, zones[ipv4only_zone].name, 0, NULL)); - (void)dns_view_findzone(view, name, &zone); + (void)dns_view_findzone(view, name, DNS_ZTFIND_EXACT, + &zone); if (zone != NULL) { dns_zone_detach(&zone); continue; @@ -5888,7 +5893,8 @@ configure_view(dns_view_t *view, dns_viewlist_t *viewlist, cfg_obj_t *config, } if (pview != NULL) { - (void)dns_view_findzone(pview, name, &zone); + (void)dns_view_findzone( + pview, name, DNS_ZTFIND_EXACT, &zone); dns_view_detach(&pview); } @@ -6574,7 +6580,8 @@ configure_zone(const cfg_obj_t *config, const cfg_obj_t *zconfig, goto cleanup; } - result = dns_view_findzone(otherview, origin, &zone); + result = dns_view_findzone(otherview, origin, DNS_ZTFIND_EXACT, + &zone); dns_view_detach(&otherview); if (result != ISC_R_SUCCESS) { cfg_obj_log(zconfig, named_g_lctx, ISC_LOG_ERROR, @@ -6693,7 +6700,8 @@ configure_zone(const cfg_obj_t *config, const cfg_obj_t *zconfig, /* * Check for duplicates in the new zone table. */ - result = dns_view_findzone(view, origin, &dupzone); + result = dns_view_findzone(view, origin, DNS_ZTFIND_EXACT, + &dupzone); if (result == ISC_R_SUCCESS) { /* * We already have this zone! @@ -6749,7 +6757,8 @@ configure_zone(const cfg_obj_t *config, const cfg_obj_t *zconfig, goto cleanup; } if (pview != NULL) { - result = dns_view_findzone(pview, origin, &zone); + result = dns_view_findzone(pview, origin, DNS_ZTFIND_EXACT, + &zone); } if (result != ISC_R_NOTFOUND && result != ISC_R_SUCCESS) { goto cleanup; @@ -7815,7 +7824,7 @@ configure_zone_setviewcommit(isc_result_t result, const cfg_obj_t *zconfig, return; } - result2 = dns_view_findzone(pview, origin, &zone); + result2 = dns_view_findzone(pview, origin, DNS_ZTFIND_EXACT, &zone); if (result2 != ISC_R_SUCCESS) { dns_view_detach(&pview); return; @@ -10571,7 +10580,8 @@ zone_from_args(named_server_t *server, isc_lex_t *lex, const char *zonetxt, result = ISC_R_NOTFOUND; } } else { - result = dns_view_findzone(view, name, zonep); + result = dns_view_findzone(view, name, DNS_ZTFIND_EXACT, + zonep); } if (result != ISC_R_SUCCESS) { snprintf(problem, sizeof(problem), @@ -13438,7 +13448,7 @@ do_addzone(named_server_t *server, ns_cfgctx_t *cfg, dns_view_t *view, result = (view->redirect == NULL) ? ISC_R_NOTFOUND : ISC_R_EXISTS; } else { - result = dns_view_findzone(view, name, &zone); + result = dns_view_findzone(view, name, DNS_ZTFIND_EXACT, &zone); if (result == ISC_R_SUCCESS) { result = ISC_R_EXISTS; } @@ -13502,7 +13512,7 @@ do_addzone(named_server_t *server, ns_cfgctx_t *cfg, dns_view_t *view, } dns_zone_attach(view->redirect, &zone); } else { - result = dns_view_findzone(view, name, &zone); + result = dns_view_findzone(view, name, DNS_ZTFIND_EXACT, &zone); if (result != ISC_R_SUCCESS) { isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL, NAMED_LOGMODULE_SERVER, ISC_LOG_ERROR, @@ -13618,7 +13628,7 @@ do_modzone(named_server_t *server, ns_cfgctx_t *cfg, dns_view_t *view, result = ISC_R_NOTFOUND; } } else { - result = dns_view_findzone(view, name, &zone); + result = dns_view_findzone(view, name, DNS_ZTFIND_EXACT, &zone); } if (result != ISC_R_SUCCESS) { goto cleanup; @@ -13687,7 +13697,7 @@ do_modzone(named_server_t *server, ns_cfgctx_t *cfg, dns_view_t *view, } dns_zone_attach(view->redirect, &zone); } else { - CHECK(dns_view_findzone(view, name, &zone)); + CHECK(dns_view_findzone(view, name, DNS_ZTFIND_EXACT, &zone)); } #ifndef HAVE_LMDB diff --git a/bin/tests/system/dyndb/driver/zone.c b/bin/tests/system/dyndb/driver/zone.c index a8d36058d7..595b01da6a 100644 --- a/bin/tests/system/dyndb/driver/zone.c +++ b/bin/tests/system/dyndb/driver/zone.c @@ -139,7 +139,7 @@ publish_zone(sample_instance_t *inst, dns_zone_t *zone) { /* Return success if the zone is already in the view as expected. */ result = dns_view_findzone(inst->view, dns_zone_getorigin(zone), - &zone_in_view); + DNS_ZTFIND_EXACT, &zone_in_view); if (result != ISC_R_SUCCESS && result != ISC_R_NOTFOUND) { goto cleanup; } diff --git a/lib/dns/catz.c b/lib/dns/catz.c index f4b9c962fa..bcf887e3bb 100644 --- a/lib/dns/catz.c +++ b/lib/dns/catz.c @@ -561,7 +561,7 @@ dns__catz_zones_merge(dns_catz_zone_t *catz, dns_catz_zone_t *newcatz) { /* Try to find the zone in the view */ find_result = dns_view_findzone(catz->catzs->view, dns_catz_entry_getname(nentry), - &zone); + DNS_ZTFIND_EXACT, &zone); if (find_result == ISC_R_SUCCESS) { dns_catz_coo_t *coo = NULL; char pczname[DNS_NAME_FORMATSIZE]; diff --git a/lib/dns/dlz.c b/lib/dns/dlz.c index 3cd390600c..de22dd3a83 100644 --- a/lib/dns/dlz.c +++ b/lib/dns/dlz.c @@ -441,7 +441,7 @@ dns_dlz_writeablezone(dns_view_t *view, dns_dlzdb_t *dlzdb, } /* See if the zone already exists */ - result = dns_view_findzone(view, origin, &dupzone); + result = dns_view_findzone(view, origin, DNS_ZTFIND_EXACT, &dupzone); if (result == ISC_R_SUCCESS) { dns_zone_detach(&dupzone); result = ISC_R_EXISTS; diff --git a/lib/dns/include/dns/view.h b/lib/dns/include/dns/view.h index 51f5fceb89..adb8dc7612 100644 --- a/lib/dns/include/dns/view.h +++ b/lib/dns/include/dns/view.h @@ -761,11 +761,11 @@ dns_viewlist_findzone(dns_viewlist_t *list, const dns_name_t *name, */ isc_result_t -dns_view_findzone(dns_view_t *view, const dns_name_t *name, dns_zone_t **zonep); +dns_view_findzone(dns_view_t *view, const dns_name_t *name, + unsigned int options, dns_zone_t **zonep); /*%< * Search for the zone 'name' in the zone table of 'view'. - * If found, 'zonep' is (strongly) attached to it. There - * are no partial matches. + * If found, 'zonep' is (strongly) attached to it. * * Requires: * diff --git a/lib/dns/view.c b/lib/dns/view.c index 55347368e7..49fc8a8d80 100644 --- a/lib/dns/view.c +++ b/lib/dns/view.c @@ -808,7 +808,7 @@ dns_view_delzone(dns_view_t *view, dns_zone_t *zone) { isc_result_t dns_view_findzone(dns_view_t *view, const dns_name_t *name, - dns_zone_t **zonep) { + unsigned int options, dns_zone_t **zonep) { isc_result_t result; dns_zt_t *zonetable = NULL; @@ -817,7 +817,7 @@ dns_view_findzone(dns_view_t *view, const dns_name_t *name, rcu_read_lock(); zonetable = rcu_dereference(view->zonetable); if (zonetable != NULL) { - result = dns_zt_find(zonetable, name, DNS_ZTFIND_EXACT, zonep); + result = dns_zt_find(zonetable, name, options, zonep); } else { result = ISC_R_NOTFOUND; } diff --git a/lib/ns/notify.c b/lib/ns/notify.c index dd3a2882f5..633ed96b8b 100644 --- a/lib/ns/notify.c +++ b/lib/ns/notify.c @@ -146,7 +146,8 @@ ns_notify_start(ns_client_t *client, isc_nmhandle_t *handle) { } dns_name_format(zonename, namebuf, sizeof(namebuf)); - result = dns_view_findzone(client->view, zonename, &zone); + result = dns_view_findzone(client->view, zonename, DNS_ZTFIND_EXACT, + &zone); if (result == ISC_R_SUCCESS) { dns_zonetype_t zonetype = dns_zone_gettype(zone); diff --git a/lib/ns/update.c b/lib/ns/update.c index 3103263366..7d2f570953 100644 --- a/lib/ns/update.c +++ b/lib/ns/update.c @@ -1987,7 +1987,8 @@ ns_update_start(ns_client_t *client, isc_nmhandle_t *handle, "RRs"); } - result = dns_view_findzone(client->view, zonename, &zone); + result = dns_view_findzone(client->view, zonename, DNS_ZTFIND_EXACT, + &zone); if (result != ISC_R_SUCCESS) { FAILN(DNS_R_NOTAUTH, zonename, "not authoritative for update zone"); diff --git a/lib/ns/xfrout.c b/lib/ns/xfrout.c index b782a29654..cad24d2170 100644 --- a/lib/ns/xfrout.c +++ b/lib/ns/xfrout.c @@ -795,7 +795,8 @@ ns_xfr_start(ns_client_t *client, dns_rdatatype_t reqtype) { FAILC(DNS_R_FORMERR, "multiple questions"); } - result = dns_view_findzone(client->view, question_name, &zone); + result = dns_view_findzone(client->view, question_name, + DNS_ZTFIND_EXACT, &zone); if (result != ISC_R_SUCCESS || dns_zone_gettype(zone) == dns_zone_dlz) { /* * The normal zone table does not have a match, or this is