2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-29 13:38:26 +00:00

Cleanup the dns_catz unit API

1. Change the _new, _add and _copy functions to return the new object
   instead of returning 'void' (or always ISC_R_SUCCESS)

2. Cleanup the isc_ht_find() + isc_ht_add() usage - the code is always
   locked with catzs->lock (mutex), so when isc_ht_find() returns
   ISC_R_NOTFOUND, the isc_ht_add() must always succeed.

3. Instead of returning direct iterator for the catalog zone entries,
   add dns_catz_zone_for_each_entry2() function that calls callback
   for each catalog zone entry and passes two extra arguments to the
   callback.  This will allow changing the internal storage for the
   catalog zone entries.

4. Cleanup the naming - dns_catz_<fn>_<obj> -> dns_catz_<obj>_<fn>, as an
   example dns_catz_new_zone() gets renamed to dns_catz_zone_new().
This commit is contained in:
Ondřej Surý 2023-07-12 09:22:11 +02:00
parent aad9fda87d
commit 48714a9c1d
No known key found for this signature in database
GPG Key ID: 2820F37E873DEA41
6 changed files with 189 additions and 251 deletions

View File

@ -2872,7 +2872,7 @@ cleanup:
cfg_obj_destroy(cfg->add_parser, &zoneconf); cfg_obj_destroy(cfg->add_parser, &zoneconf);
} }
dns_catz_entry_detach(cz->origin, &cz->entry); dns_catz_entry_detach(cz->origin, &cz->entry);
dns_catz_detach_catz(&cz->origin); dns_catz_zone_detach(&cz->origin);
dns_view_detach(&cz->view); dns_view_detach(&cz->view);
isc_mem_putanddetach(&cz->mctx, cz, sizeof(*cz)); isc_mem_putanddetach(&cz->mctx, cz, sizeof(*cz));
} }
@ -2946,7 +2946,7 @@ cleanup:
dns_zone_detach(&zone); dns_zone_detach(&zone);
} }
dns_catz_entry_detach(cz->origin, &cz->entry); dns_catz_entry_detach(cz->origin, &cz->entry);
dns_catz_detach_catz(&cz->origin); dns_catz_zone_detach(&cz->origin);
dns_view_detach(&cz->view); dns_view_detach(&cz->view);
isc_mem_putanddetach(&cz->mctx, cz, sizeof(*cz)); isc_mem_putanddetach(&cz->mctx, cz, sizeof(*cz));
} }
@ -2978,7 +2978,7 @@ catz_run(dns_catz_entry_t *entry, dns_catz_zone_t *origin, dns_view_t *view,
isc_mem_attach(view->mctx, &cz->mctx); isc_mem_attach(view->mctx, &cz->mctx);
dns_catz_entry_attach(entry, &cz->entry); dns_catz_entry_attach(entry, &cz->entry);
dns_catz_attach_catz(origin, &cz->origin); dns_catz_zone_attach(origin, &cz->origin);
dns_view_attach(view, &cz->view); dns_view_attach(view, &cz->view);
isc_async_run(named_g_mainloop, action, cz); isc_async_run(named_g_mainloop, action, cz);
@ -3004,6 +3004,25 @@ catz_modzone(dns_catz_entry_t *entry, dns_catz_zone_t *origin, dns_view_t *view,
return (catz_run(entry, origin, view, udata, CATZ_MODZONE)); return (catz_run(entry, origin, view, udata, CATZ_MODZONE));
} }
static void
catz_changeview(dns_catz_entry_t *entry, void *arg1, void *arg2) {
dns_view_t *pview = arg1;
dns_view_t *view = arg2;
dns_zone_t *zone = NULL;
isc_result_t result = dns_view_findzone(
pview, dns_catz_entry_getname(entry), DNS_ZTFIND_EXACT, &zone);
if (result != ISC_R_SUCCESS) {
return;
}
dns_zone_setview(zone, view);
dns_view_addzone(view, zone);
dns_zone_detach(&zone);
}
static isc_result_t static isc_result_t
configure_catz_zone(dns_view_t *view, dns_view_t *pview, configure_catz_zone(dns_view_t *view, dns_view_t *pview,
const cfg_obj_t *config, const cfg_listelt_t *element) { const cfg_obj_t *config, const cfg_listelt_t *element) {
@ -3031,65 +3050,14 @@ configure_catz_zone(dns_view_t *view, dns_view_t *pview,
goto cleanup; goto cleanup;
} }
result = dns_catz_add_zone(view->catzs, &origin, &zone); result = dns_catz_zone_add(view->catzs, &origin, &zone);
if (result != ISC_R_SUCCESS && result != ISC_R_EXISTS) {
cfg_obj_log(catz_obj, named_g_lctx, DNS_CATZ_ERROR_LEVEL,
"catz: unable to create catalog zone '%s', "
"error %s",
str, isc_result_totext(result));
goto cleanup;
}
if (result == ISC_R_EXISTS) { if (result == ISC_R_EXISTS) {
isc_ht_iter_t *it = NULL;
RUNTIME_CHECK(pview != NULL);
/* /*
* xxxwpk todo: reconfigure the zone!!!! * We have to walk through all the member zones and re-attach
*/
cfg_obj_log(catz_obj, named_g_lctx, DNS_CATZ_ERROR_LEVEL,
"catz: catalog zone '%s' will not be reconfigured",
str);
/*
* We have to walk through all the member zones and attach
* them to current view * them to current view
*/ */
dns_catz_get_iterator(zone, &it); dns_catz_zone_for_each_entry2(zone, catz_changeview, pview,
view);
for (result = isc_ht_iter_first(it); result == ISC_R_SUCCESS;
result = isc_ht_iter_next(it))
{
dns_name_t *name = NULL;
dns_zone_t *dnszone = NULL;
dns_catz_entry_t *entry = NULL;
isc_result_t tresult;
isc_ht_iter_current(it, (void **)&entry);
name = dns_catz_entry_getname(entry);
tresult = dns_view_findzone(pview, name,
DNS_ZTFIND_EXACT, &dnszone);
if (tresult != ISC_R_SUCCESS) {
continue;
}
dns_zone_setview(dnszone, view);
dns_view_addzone(view, dnszone);
/*
* The dns_view_findzone() call above increments the
* zone's reference count, which we need to decrement
* back. However, as dns_zone_detach() sets the
* supplied pointer to NULL, calling it is deferred
* until the dnszone variable is no longer used.
*/
dns_zone_detach(&dnszone);
}
isc_ht_iter_destroy(&it);
result = ISC_R_SUCCESS;
} }
dns_catz_zone_resetdefoptions(zone); dns_catz_zone_resetdefoptions(zone);
@ -3167,12 +3135,12 @@ configure_catz(dns_view_t *view, dns_view_t *pview, const cfg_obj_t *config,
} }
if (old != NULL) { if (old != NULL) {
dns_catz_attach_catzs(pview->catzs, &view->catzs); dns_catz_zones_attach(pview->catzs, &view->catzs);
dns_catz_detach_catzs(&pview->catzs); dns_catz_zones_detach(&pview->catzs);
dns_catz_prereconfig(view->catzs); dns_catz_prereconfig(view->catzs);
} else { } else {
dns_catz_new_zones(view->mctx, named_g_loopmgr, &view->catzs, view->catzs = dns_catz_zones_new(view->mctx, named_g_loopmgr,
&ns_catz_zonemodmethods); &ns_catz_zonemodmethods);
} }
while (zone_element != NULL) { while (zone_element != NULL) {
@ -6725,7 +6693,7 @@ configure_zone(const cfg_obj_t *config, const cfg_obj_t *zconfig,
} }
if (view->catzs != NULL && if (view->catzs != NULL &&
dns_catz_get_zone(view->catzs, origin) != NULL) dns_catz_zone_get(view->catzs, origin) != NULL)
{ {
zone_is_catz = true; zone_is_catz = true;
} }

View File

@ -85,8 +85,7 @@ n=0
n=$((n+1)) n=$((n+1))
echo_i "checking that catalog-bad1.example (with no version) has failed to load ($n)" echo_i "checking that catalog-bad1.example (with no version) has failed to load ($n)"
ret=0 ret=0
wait_for_message ns2/named.run "catz: zone 'catalog-bad1.example' has no 'version' record" && wait_for_message ns2/named.run "catz: zone 'catalog-bad1.example' has no 'version' record and will not be processed" &&
wait_for_message ns2/named.run "catz: new catalog zone 'catalog-bad1.example' is broken and will not be processed" || ret=1
if [ $ret -ne 0 ]; then echo_i "failed"; fi if [ $ret -ne 0 ]; then echo_i "failed"; fi
status=$((status+ret)) status=$((status+ret))
@ -122,7 +121,7 @@ echo_i "checking that catalog-bad5.example (non-IN class) has failed to load ($n
ret=0 ret=0
wait_for_message ns2/named.run "'catalog-zones' option is only supported for views with class IN" && wait_for_message ns2/named.run "'catalog-zones' option is only supported for views with class IN" &&
wait_for_message ns2/named.run "all zones loaded" || ret=1 wait_for_message ns2/named.run "all zones loaded" || ret=1
grep -F "catz: dns_catz_add_zone catalog-bad5.example" ns2/named.run && ret=1 grep -F "catz: dns_catz_zone_add catalog-bad5.example" ns2/named.run && ret=1
if [ $ret -ne 0 ]; then echo_i "failed"; fi if [ $ret -ne 0 ]; then echo_i "failed"; fi
status=$((status+ret)) status=$((status+ret))

View File

@ -241,21 +241,20 @@ dns_catz_options_setdefault(isc_mem_t *mctx, const dns_catz_options_t *defaults,
opts->in_memory = defaults->in_memory; opts->in_memory = defaults->in_memory;
} }
static void static dns_catz_coo_t *
catz_coo_new(isc_mem_t *mctx, const dns_name_t *domain, catz_coo_new(isc_mem_t *mctx, const dns_name_t *domain) {
dns_catz_coo_t **ncoop) {
dns_catz_coo_t *ncoo;
REQUIRE(mctx != NULL); REQUIRE(mctx != NULL);
REQUIRE(domain != NULL); REQUIRE(domain != NULL);
REQUIRE(ncoop != NULL && *ncoop == NULL);
ncoo = isc_mem_get(mctx, sizeof(*ncoo)); dns_catz_coo_t *ncoo = isc_mem_get(mctx, sizeof(*ncoo));
*ncoo = (dns_catz_coo_t){
.magic = DNS_CATZ_COO_MAGIC,
};
dns_name_init(&ncoo->name, NULL); dns_name_init(&ncoo->name, NULL);
dns_name_dup(domain, mctx, &ncoo->name); dns_name_dup(domain, mctx, &ncoo->name);
isc_refcount_init(&ncoo->references, 1); isc_refcount_init(&ncoo->references, 1);
ncoo->magic = DNS_CATZ_COO_MAGIC;
*ncoop = ncoo; return (ncoo);
} }
static void static void
@ -278,15 +277,33 @@ catz_coo_detach(dns_catz_zone_t *catz, dns_catz_coo_t **coop) {
} }
} }
void static void
dns_catz_entry_new(isc_mem_t *mctx, const dns_name_t *domain, catz_coo_add(dns_catz_zone_t *catz, dns_catz_entry_t *entry,
dns_catz_entry_t **nentryp) { const dns_name_t *domain) {
dns_catz_entry_t *nentry; REQUIRE(DNS_CATZ_ZONE_VALID(catz));
REQUIRE(DNS_CATZ_ENTRY_VALID(entry));
REQUIRE(domain != NULL);
/* We are write locked, so the add must succeed if not found */
dns_catz_coo_t *coo = NULL;
isc_result_t result = isc_ht_find(catz->coos, entry->name.ndata,
entry->name.length, (void **)&coo);
if (result != ISC_R_SUCCESS) {
coo = catz_coo_new(catz->catzs->mctx, domain);
result = isc_ht_add(catz->coos, entry->name.ndata,
entry->name.length, coo);
}
INSIST(result == ISC_R_SUCCESS);
}
dns_catz_entry_t *
dns_catz_entry_new(isc_mem_t *mctx, const dns_name_t *domain) {
REQUIRE(mctx != NULL); REQUIRE(mctx != NULL);
REQUIRE(nentryp != NULL && *nentryp == NULL);
nentry = isc_mem_get(mctx, sizeof(*nentry)); dns_catz_entry_t *nentry = isc_mem_get(mctx, sizeof(*nentry));
*nentry = (dns_catz_entry_t){
.magic = DNS_CATZ_ENTRY_MAGIC,
};
dns_name_init(&nentry->name, NULL); dns_name_init(&nentry->name, NULL);
if (domain != NULL) { if (domain != NULL) {
@ -295,8 +312,8 @@ dns_catz_entry_new(isc_mem_t *mctx, const dns_name_t *domain,
dns_catz_options_init(&nentry->opts); dns_catz_options_init(&nentry->opts);
isc_refcount_init(&nentry->references, 1); isc_refcount_init(&nentry->references, 1);
nentry->magic = DNS_CATZ_ENTRY_MAGIC;
*nentryp = nentry; return (nentry);
} }
dns_name_t * dns_name_t *
@ -305,19 +322,17 @@ dns_catz_entry_getname(dns_catz_entry_t *entry) {
return (&entry->name); return (&entry->name);
} }
void dns_catz_entry_t *
dns_catz_entry_copy(dns_catz_zone_t *catz, const dns_catz_entry_t *entry, dns_catz_entry_copy(dns_catz_zone_t *catz, const dns_catz_entry_t *entry) {
dns_catz_entry_t **nentryp) {
dns_catz_entry_t *nentry = NULL;
REQUIRE(DNS_CATZ_ZONE_VALID(catz)); REQUIRE(DNS_CATZ_ZONE_VALID(catz));
REQUIRE(DNS_CATZ_ENTRY_VALID(entry)); REQUIRE(DNS_CATZ_ENTRY_VALID(entry));
REQUIRE(nentryp != NULL && *nentryp == NULL);
dns_catz_entry_new(catz->catzs->mctx, &entry->name, &nentry); dns_catz_entry_t *nentry = dns_catz_entry_new(catz->catzs->mctx,
&entry->name);
dns_catz_options_copy(catz->catzs->mctx, &entry->opts, &nentry->opts); dns_catz_options_copy(catz->catzs->mctx, &entry->opts, &nentry->opts);
*nentryp = nentry;
return (nentry);
} }
void void
@ -767,17 +782,14 @@ dns__catz_zones_merge(dns_catz_zone_t *catz, dns_catz_zone_t *newcatz) {
return (result); return (result);
} }
void dns_catz_zones_t *
dns_catz_new_zones(isc_mem_t *mctx, isc_loopmgr_t *loopmgr, dns_catz_zones_new(isc_mem_t *mctx, isc_loopmgr_t *loopmgr,
dns_catz_zones_t **catzsp, dns_catz_zonemodmethods_t *zmm) { dns_catz_zonemodmethods_t *zmm) {
dns_catz_zones_t *catzs = NULL;
REQUIRE(mctx != NULL); REQUIRE(mctx != NULL);
REQUIRE(loopmgr != NULL); REQUIRE(loopmgr != NULL);
REQUIRE(catzsp != NULL && *catzsp == NULL);
REQUIRE(zmm != NULL); REQUIRE(zmm != NULL);
catzs = isc_mem_get(mctx, sizeof(*catzs)); dns_catz_zones_t *catzs = isc_mem_get(mctx, sizeof(*catzs));
*catzs = (dns_catz_zones_t){ .loopmgr = loopmgr, *catzs = (dns_catz_zones_t){ .loopmgr = loopmgr,
.zmm = zmm, .zmm = zmm,
.magic = DNS_CATZ_ZONES_MAGIC }; .magic = DNS_CATZ_ZONES_MAGIC };
@ -787,7 +799,7 @@ dns_catz_new_zones(isc_mem_t *mctx, isc_loopmgr_t *loopmgr,
isc_ht_init(&catzs->zones, mctx, 4, ISC_HT_CASE_SENSITIVE); isc_ht_init(&catzs->zones, mctx, 4, ISC_HT_CASE_SENSITIVE);
isc_mem_attach(mctx, &catzs->mctx); isc_mem_attach(mctx, &catzs->mctx);
*catzsp = catzs; return (catzs);
} }
void void
@ -800,16 +812,12 @@ dns_catz_catzs_set_view(dns_catz_zones_t *catzs, dns_view_t *view) {
catzs->view = view; catzs->view = view;
} }
isc_result_t dns_catz_zone_t *
dns_catz_new_zone(dns_catz_zones_t *catzs, dns_catz_zone_t **catzp, dns_catz_zone_new(dns_catz_zones_t *catzs, const dns_name_t *name) {
const dns_name_t *name) {
dns_catz_zone_t *catz;
REQUIRE(DNS_CATZ_ZONES_VALID(catzs)); REQUIRE(DNS_CATZ_ZONES_VALID(catzs));
REQUIRE(catzp != NULL && *catzp == NULL);
REQUIRE(ISC_MAGIC_VALID(name, DNS_NAME_MAGIC)); REQUIRE(ISC_MAGIC_VALID(name, DNS_NAME_MAGIC));
catz = isc_mem_get(catzs->mctx, sizeof(*catz)); dns_catz_zone_t *catz = isc_mem_get(catzs->mctx, sizeof(*catz));
*catz = (dns_catz_zone_t){ .active = true, *catz = (dns_catz_zone_t){ .active = true,
.version = DNS_CATZ_VERSION_UNDEFINED, .version = DNS_CATZ_VERSION_UNDEFINED,
.magic = DNS_CATZ_ZONE_MAGIC }; .magic = DNS_CATZ_ZONE_MAGIC };
@ -825,9 +833,7 @@ dns_catz_new_zone(dns_catz_zones_t *catzs, dns_catz_zone_t **catzp,
dns_name_init(&catz->name, NULL); dns_name_init(&catz->name, NULL);
dns_name_dup(name, catzs->mctx, &catz->name); dns_name_dup(name, catzs->mctx, &catz->name);
*catzp = catz; return (catz);
return (ISC_R_SUCCESS);
} }
static void static void
@ -872,57 +878,54 @@ dns__catz_timer_stop(void *arg) {
isc_timer_destroy(&catz->updatetimer); isc_timer_destroy(&catz->updatetimer);
catz->loop = NULL; catz->loop = NULL;
dns_catz_detach_catz(&catz); dns_catz_zone_detach(&catz);
} }
isc_result_t isc_result_t
dns_catz_add_zone(dns_catz_zones_t *catzs, const dns_name_t *name, dns_catz_zone_add(dns_catz_zones_t *catzs, const dns_name_t *name,
dns_catz_zone_t **catzp) { dns_catz_zone_t **catzp) {
dns_catz_zone_t *catz = NULL;
isc_result_t result, tresult;
char zname[DNS_NAME_FORMATSIZE];
REQUIRE(DNS_CATZ_ZONES_VALID(catzs)); REQUIRE(DNS_CATZ_ZONES_VALID(catzs));
REQUIRE(ISC_MAGIC_VALID(name, DNS_NAME_MAGIC)); REQUIRE(ISC_MAGIC_VALID(name, DNS_NAME_MAGIC));
REQUIRE(catzp != NULL && *catzp == NULL); REQUIRE(catzp != NULL && *catzp == NULL);
dns_catz_zone_t *catz = NULL;
isc_result_t result;
char zname[DNS_NAME_FORMATSIZE];
dns_name_format(name, zname, DNS_NAME_FORMATSIZE); dns_name_format(name, zname, DNS_NAME_FORMATSIZE);
isc_log_write(dns_lctx, DNS_LOGCATEGORY_GENERAL, DNS_LOGMODULE_MASTER, isc_log_write(dns_lctx, DNS_LOGCATEGORY_GENERAL, DNS_LOGMODULE_MASTER,
ISC_LOG_DEBUG(3), "catz: dns_catz_add_zone %s", zname); ISC_LOG_DEBUG(3), "catz: dns_catz_zone_add %s", zname);
LOCK(&catzs->lock); LOCK(&catzs->lock);
result = dns_catz_new_zone(catzs, &catz, name); result = isc_ht_find(catzs->zones, name->ndata, name->length,
if (result != ISC_R_SUCCESS) { (void **)&catz);
goto cleanup; switch (result) {
} case ISC_R_SUCCESS:
INSIST(!catz->active);
result = isc_ht_add(catzs->zones, catz->name.ndata, catz->name.length,
catz);
if (result != ISC_R_SUCCESS) {
dns_catz_detach_catz(&catz);
if (result != ISC_R_EXISTS) {
goto cleanup;
}
}
if (result == ISC_R_EXISTS) {
tresult = isc_ht_find(catzs->zones, name->ndata, name->length,
(void **)&catz);
INSIST(tresult == ISC_R_SUCCESS && !catz->active);
catz->active = true; catz->active = true;
result = ISC_R_EXISTS;
break;
case ISC_R_NOTFOUND:
catz = dns_catz_zone_new(catzs, name);
result = isc_ht_add(catzs->zones, catz->name.ndata,
catz->name.length, catz);
INSIST(result == ISC_R_SUCCESS);
break;
default:
UNREACHABLE();
} }
UNLOCK(&catzs->lock);
*catzp = catz; *catzp = catz;
cleanup:
UNLOCK(&catzs->lock);
return (result); return (result);
} }
dns_catz_zone_t * dns_catz_zone_t *
dns_catz_get_zone(dns_catz_zones_t *catzs, const dns_name_t *name) { dns_catz_zone_get(dns_catz_zones_t *catzs, const dns_name_t *name) {
isc_result_t result; isc_result_t result;
dns_catz_zone_t *found = NULL; dns_catz_zone_t *found = NULL;
@ -941,7 +944,7 @@ dns_catz_get_zone(dns_catz_zones_t *catzs, const dns_name_t *name) {
} }
static void static void
dns__catz_shutdown(dns_catz_zone_t *catz) { dns__catz_zone_shutdown(dns_catz_zone_t *catz) {
/* lock must be locked */ /* lock must be locked */
if (catz->updatetimer != NULL) { if (catz->updatetimer != NULL) {
/* Don't wait for timer to trigger for shutdown */ /* Don't wait for timer to trigger for shutdown */
@ -949,7 +952,7 @@ dns__catz_shutdown(dns_catz_zone_t *catz) {
isc_async_run(catz->loop, dns__catz_timer_stop, catz); isc_async_run(catz->loop, dns__catz_timer_stop, catz);
} else { } else {
dns_catz_detach_catz(&catz); dns_catz_zone_detach(&catz);
} }
} }
@ -1038,7 +1041,7 @@ dns__catz_zones_destroy(dns_catz_zones_t *catzs) {
} }
void void
dns_catz_shutdown_catzs(dns_catz_zones_t *catzs) { dns_catz_zones_shutdown(dns_catz_zones_t *catzs) {
REQUIRE(DNS_CATZ_ZONES_VALID(catzs)); REQUIRE(DNS_CATZ_ZONES_VALID(catzs));
if (!atomic_compare_exchange_strong(&catzs->shuttingdown, if (!atomic_compare_exchange_strong(&catzs->shuttingdown,
@ -1057,7 +1060,7 @@ dns_catz_shutdown_catzs(dns_catz_zones_t *catzs) {
dns_catz_zone_t *catz = NULL; dns_catz_zone_t *catz = NULL;
isc_ht_iter_current(iter, (void **)&catz); isc_ht_iter_current(iter, (void **)&catz);
result = isc_ht_iter_delcurrent_next(iter); result = isc_ht_iter_delcurrent_next(iter);
dns__catz_shutdown(catz); dns__catz_zone_shutdown(catz);
} }
INSIST(result == ISC_R_NOMORE); INSIST(result == ISC_R_NOMORE);
isc_ht_iter_destroy(&iter); isc_ht_iter_destroy(&iter);
@ -1156,8 +1159,6 @@ catz_process_coo(dns_catz_zone_t *catz, dns_label_t *mhash,
dns_rdata_t rdata; dns_rdata_t rdata;
dns_rdata_ptr_t ptr; dns_rdata_ptr_t ptr;
dns_catz_entry_t *entry = NULL; dns_catz_entry_t *entry = NULL;
dns_catz_coo_t *ncoo = NULL;
dns_catz_coo_t *ocoo = NULL;
REQUIRE(DNS_CATZ_ZONE_VALID(catz)); REQUIRE(DNS_CATZ_ZONE_VALID(catz));
REQUIRE(mhash != NULL); REQUIRE(mhash != NULL);
@ -1211,19 +1212,7 @@ catz_process_coo(dns_catz_zone_t *catz, dns_label_t *mhash,
goto cleanup; goto cleanup;
} }
result = isc_ht_find(catz->coos, entry->name.ndata, entry->name.length, catz_coo_add(catz, entry, &ptr.ptr);
(void **)&ocoo);
if (result == ISC_R_SUCCESS) {
/* The change of ownership permission was already registered. */
goto cleanup;
}
catz_coo_new(catz->catzs->mctx, &ptr.ptr, &ncoo);
result = isc_ht_add(catz->coos, entry->name.ndata, entry->name.length,
ncoo);
if (result != ISC_R_SUCCESS) {
catz_coo_detach(catz, &ncoo);
}
cleanup: cleanup:
dns_rdata_freestruct(&ptr); dns_rdata_freestruct(&ptr);
@ -1276,16 +1265,12 @@ catz_process_zones_entry(dns_catz_zone_t *catz, dns_rdataset_t *value,
dns_name_dup(&ptr.ptr, catz->catzs->mctx, &entry->name); dns_name_dup(&ptr.ptr, catz->catzs->mctx, &entry->name);
} }
} else { } else {
dns_catz_entry_new(catz->catzs->mctx, &ptr.ptr, &entry); entry = dns_catz_entry_new(catz->catzs->mctx, &ptr.ptr);
result = isc_ht_add(catz->entries, mhash->base, mhash->length, result = isc_ht_add(catz->entries, mhash->base, mhash->length,
entry); entry);
if (result != ISC_R_SUCCESS) {
dns_rdata_freestruct(&ptr);
dns_catz_entry_detach(catz, &entry);
return (result);
}
} }
INSIST(result == ISC_R_SUCCESS);
dns_rdata_freestruct(&ptr); dns_rdata_freestruct(&ptr);
@ -1673,14 +1658,11 @@ catz_process_zones_suboption(dns_catz_zone_t *catz, dns_rdataset_t *value,
result = isc_ht_find(catz->entries, mhash->base, mhash->length, result = isc_ht_find(catz->entries, mhash->base, mhash->length,
(void **)&entry); (void **)&entry);
if (result != ISC_R_SUCCESS) { if (result != ISC_R_SUCCESS) {
dns_catz_entry_new(catz->catzs->mctx, NULL, &entry); entry = dns_catz_entry_new(catz->catzs->mctx, NULL);
result = isc_ht_add(catz->entries, mhash->base, mhash->length, result = isc_ht_add(catz->entries, mhash->base, mhash->length,
entry); entry);
if (result != ISC_R_SUCCESS) {
dns_catz_entry_detach(catz, &entry);
return (result);
}
} }
INSIST(result == ISC_R_SUCCESS);
dns_name_init(&prefix, NULL); dns_name_init(&prefix, NULL);
dns_name_split(name, suffix_labels, &prefix, NULL); dns_name_split(name, suffix_labels, &prefix, NULL);
@ -2113,7 +2095,7 @@ dns__catz_timer_cb(void *arg) {
isc_log_write(dns_lctx, DNS_LOGCATEGORY_GENERAL, DNS_LOGMODULE_MASTER, isc_log_write(dns_lctx, DNS_LOGCATEGORY_GENERAL, DNS_LOGMODULE_MASTER,
ISC_LOG_INFO, "catz: %s: reload start", domain); ISC_LOG_INFO, "catz: %s: reload start", domain);
dns_catz_ref_catz(catz); dns_catz_zone_ref(catz);
isc_work_enqueue(catz->loop, dns__catz_update_cb, dns__catz_done_cb, isc_work_enqueue(catz->loop, dns__catz_update_cb, dns__catz_done_cb,
catz); catz);
@ -2306,18 +2288,8 @@ dns__catz_update_cb(void *data) {
"catz: updating catalog zone '%s' with serial %" PRIu32, "catz: updating catalog zone '%s' with serial %" PRIu32,
bname, vers); bname, vers);
result = dns_catz_new_zone(catzs, &newcatz, &updb->origin);
if (result != ISC_R_SUCCESS) {
isc_log_write(dns_lctx, DNS_LOGCATEGORY_GENERAL,
DNS_LOGMODULE_MASTER, ISC_LOG_ERROR,
"catz: failed to create new zone - %s",
isc_result_totext(result));
goto exit;
}
result = dns_db_createiterator(updb, DNS_DB_NONSEC3, &updbit); result = dns_db_createiterator(updb, DNS_DB_NONSEC3, &updbit);
if (result != ISC_R_SUCCESS) { if (result != ISC_R_SUCCESS) {
dns_catz_detach_catz(&newcatz);
isc_log_write(dns_lctx, DNS_LOGCATEGORY_GENERAL, isc_log_write(dns_lctx, DNS_LOGCATEGORY_GENERAL,
DNS_LOGMODULE_MASTER, ISC_LOG_ERROR, DNS_LOGMODULE_MASTER, ISC_LOG_ERROR,
"catz: failed to create DB iterator - %s", "catz: failed to create DB iterator - %s",
@ -2335,24 +2307,25 @@ dns__catz_update_cb(void *data) {
result = dns_name_fromstring2(name, "version", &updb->origin, 0, NULL); result = dns_name_fromstring2(name, "version", &updb->origin, 0, NULL);
if (result != ISC_R_SUCCESS) { if (result != ISC_R_SUCCESS) {
dns_dbiterator_destroy(&updbit); dns_dbiterator_destroy(&updbit);
dns_catz_detach_catz(&newcatz);
isc_log_write(dns_lctx, DNS_LOGCATEGORY_GENERAL, isc_log_write(dns_lctx, DNS_LOGCATEGORY_GENERAL,
DNS_LOGMODULE_MASTER, ISC_LOG_ERROR, DNS_LOGMODULE_MASTER, ISC_LOG_ERROR,
"catz: failed to create name from string - %s", "catz: failed to create name from string - %s",
isc_result_totext(result)); isc_result_totext(result));
goto exit; goto exit;
} }
result = dns_dbiterator_seek(updbit, name); result = dns_dbiterator_seek(updbit, name);
if (result != ISC_R_SUCCESS) { if (result != ISC_R_SUCCESS) {
dns_dbiterator_destroy(&updbit); dns_dbiterator_destroy(&updbit);
isc_log_write(dns_lctx, DNS_LOGCATEGORY_GENERAL, isc_log_write(dns_lctx, DNS_LOGCATEGORY_GENERAL,
DNS_LOGMODULE_MASTER, ISC_LOG_ERROR, DNS_LOGMODULE_MASTER, ISC_LOG_ERROR,
"catz: zone '%s' has no 'version' record (%s)", "catz: zone '%s' has no 'version' record (%s) "
"and will not be processed",
bname, isc_result_totext(result)); bname, isc_result_totext(result));
newcatz->broken = true; goto exit;
goto final;
} }
newcatz = dns_catz_zone_new(catzs, &updb->origin);
name = dns_fixedname_initname(&fixname); name = dns_fixedname_initname(&fixname);
/* /*
@ -2486,7 +2459,6 @@ dns__catz_update_cb(void *data) {
oldcatz->version = catz_vers; oldcatz->version = catz_vers;
} }
final:
if (newcatz->broken) { if (newcatz->broken) {
dns_name_format(name, cname, DNS_NAME_FORMATSIZE); dns_name_format(name, cname, DNS_NAME_FORMATSIZE);
isc_log_write(dns_lctx, DNS_LOGCATEGORY_GENERAL, isc_log_write(dns_lctx, DNS_LOGCATEGORY_GENERAL,
@ -2494,7 +2466,7 @@ final:
"catz: new catalog zone '%s' is broken and " "catz: new catalog zone '%s' is broken and "
"will not be processed", "will not be processed",
bname); bname);
dns_catz_detach_catz(&newcatz); dns_catz_zone_detach(&newcatz);
result = ISC_R_FAILURE; result = ISC_R_FAILURE;
goto exit; goto exit;
} }
@ -2503,7 +2475,7 @@ final:
* Finally merge new zone into old zone. * Finally merge new zone into old zone.
*/ */
result = dns__catz_zones_merge(oldcatz, newcatz); result = dns__catz_zones_merge(oldcatz, newcatz);
dns_catz_detach_catz(&newcatz); dns_catz_zone_detach(&newcatz);
if (result != ISC_R_SUCCESS) { if (result != ISC_R_SUCCESS) {
isc_log_write(dns_lctx, DNS_LOGCATEGORY_GENERAL, isc_log_write(dns_lctx, DNS_LOGCATEGORY_GENERAL,
DNS_LOGMODULE_MASTER, ISC_LOG_ERROR, DNS_LOGMODULE_MASTER, ISC_LOG_ERROR,
@ -2563,7 +2535,7 @@ dns__catz_done_cb(void *data) {
ISC_LOG_INFO, "catz: %s: reload done: %s", dname, ISC_LOG_INFO, "catz: %s: reload done: %s", dname,
isc_result_totext(catz->updateresult)); isc_result_totext(catz->updateresult));
dns_catz_unref_catz(catz); dns_catz_zone_unref(catz);
} }
void void
@ -2613,16 +2585,14 @@ dns_catz_postreconfig(dns_catz_zones_t *catzs) {
* Merge the old zone with an empty one to remove * Merge the old zone with an empty one to remove
* all members. * all members.
*/ */
result = dns_catz_new_zone(catzs, &newcatz, newcatz = dns_catz_zone_new(catzs, &catz->name);
&catz->name);
INSIST(result == ISC_R_SUCCESS);
dns__catz_zones_merge(catz, newcatz); dns__catz_zones_merge(catz, newcatz);
dns_catz_detach_catz(&newcatz); dns_catz_zone_detach(&newcatz);
/* Make sure that we have an empty catalog zone. */ /* Make sure that we have an empty catalog zone. */
INSIST(isc_ht_count(catz->entries) == 0); INSIST(isc_ht_count(catz->entries) == 0);
result = isc_ht_iter_delcurrent_next(iter); result = isc_ht_iter_delcurrent_next(iter);
dns_catz_detach_catz(&catz); dns_catz_zone_detach(&catz);
} else { } else {
result = isc_ht_iter_next(iter); result = isc_ht_iter_next(iter);
} }
@ -2633,8 +2603,23 @@ dns_catz_postreconfig(dns_catz_zones_t *catzs) {
} }
void void
dns_catz_get_iterator(dns_catz_zone_t *catz, isc_ht_iter_t **itp) { dns_catz_zone_for_each_entry2(dns_catz_zone_t *catz, dns_catz_entry_cb2 cb,
void *arg1, void *arg2) {
REQUIRE(DNS_CATZ_ZONE_VALID(catz)); REQUIRE(DNS_CATZ_ZONE_VALID(catz));
isc_ht_iter_create(catz->entries, itp); isc_ht_iter_t *iter = NULL;
isc_result_t result;
LOCK(&catz->catzs->lock);
isc_ht_iter_create(catz->entries, &iter);
for (result = isc_ht_iter_first(iter); result == ISC_R_SUCCESS;
result = isc_ht_iter_next(iter))
{
dns_catz_entry_t *entry = NULL;
isc_ht_iter_current(iter, (void **)&entry);
cb(entry, arg1, arg2);
}
isc_ht_iter_destroy(&iter);
UNLOCK(&catz->catzs->lock);
} }

View File

@ -132,32 +132,28 @@ dns_catz_entry_getname(dns_catz_entry_t *entry);
* \li domain name for entry. * \li domain name for entry.
*/ */
void dns_catz_entry_t *
dns_catz_entry_new(isc_mem_t *mctx, const dns_name_t *domain, dns_catz_entry_new(isc_mem_t *mctx, const dns_name_t *domain);
dns_catz_entry_t **nentryp);
/*%< /*%<
* Allocate a new catz_entry on 'mctx', with the name 'domain' * Allocate a new catz_entry on 'mctx', with the name 'domain'
* *
* Requires: * Requires:
* \li 'mctx' to be a valid memory context. * \li 'mctx' to be a valid memory context.
* \li 'domain' to be valid dns_name or NULL. * \li 'domain' to be valid dns_name or NULL.
* \li 'nentryp' to be non NULL, *nentryp to be NULL.
* *
* Returns: * Returns:
* \li ISC_R_SUCCESS on success * \li ISC_R_SUCCESS on success
* \li ISC_R_NOMEMORY on allocation failure * \li ISC_R_NOMEMORY on allocation failure
*/ */
void dns_catz_entry_t *
dns_catz_entry_copy(dns_catz_zone_t *catz, const dns_catz_entry_t *entry, dns_catz_entry_copy(dns_catz_zone_t *catz, const dns_catz_entry_t *entry);
dns_catz_entry_t **nentryp);
/*%< /*%<
* Allocate a new catz_entry and deep copy 'entry' into 'nentryp'. * Allocate a new catz_entry and deep copy 'entry' into 'nentryp'.
* *
* Requires: * Requires:
* \li 'mctx' to be a valid memory context. * \li 'mctx' to be a valid memory context.
* \li 'entry' to be non NULL. * \li 'entry' to be non NULL.
* \li 'nentryp' to be non NULL, *nentryp to be NULL.
* *
* Returns: * Returns:
* \li ISC_R_SUCCESS on success * \li ISC_R_SUCCESS on success
@ -208,9 +204,8 @@ dns_catz_entry_cmp(const dns_catz_entry_t *ea, const dns_catz_entry_t *eb);
* \li 'false' if the entries differ. * \li 'false' if the entries differ.
*/ */
isc_result_t dns_catz_zone_t *
dns_catz_new_zone(dns_catz_zones_t *catzs, dns_catz_zone_t **catzp, dns_catz_zone_new(dns_catz_zones_t *catzs, const dns_name_t *name);
const dns_name_t *name);
/*%< /*%<
* Allocate a new catz zone on catzs mctx * Allocate a new catz zone on catzs mctx
* *
@ -291,9 +286,9 @@ struct dns_catz_zonemodmethods {
void *udata; void *udata;
}; };
void dns_catz_zones_t *
dns_catz_new_zones(isc_mem_t *mctx, isc_loopmgr_t *loopmgr, dns_catz_zones_new(isc_mem_t *mctx, isc_loopmgr_t *loopmgr,
dns_catz_zones_t **catzsp, dns_catz_zonemodmethods_t *zmm); dns_catz_zonemodmethods_t *zmm);
/*%< /*%<
* Allocate a new catz_zones object, a collection storing all catalog zones * Allocate a new catz_zones object, a collection storing all catalog zones
* for a view. * for a view.
@ -307,7 +302,7 @@ dns_catz_new_zones(isc_mem_t *mctx, isc_loopmgr_t *loopmgr,
*/ */
isc_result_t isc_result_t
dns_catz_add_zone(dns_catz_zones_t *catzs, const dns_name_t *name, dns_catz_zone_add(dns_catz_zones_t *catzs, const dns_name_t *name,
dns_catz_zone_t **catzp); dns_catz_zone_t **catzp);
/*%< /*%<
* Allocate a new catz named 'name' and put it in 'catzs' collection. * Allocate a new catz named 'name' and put it in 'catzs' collection.
@ -320,7 +315,7 @@ dns_catz_add_zone(dns_catz_zones_t *catzs, const dns_name_t *name,
*/ */
dns_catz_zone_t * dns_catz_zone_t *
dns_catz_get_zone(dns_catz_zones_t *catzs, const dns_name_t *name); dns_catz_zone_get(dns_catz_zones_t *catzs, const dns_name_t *name);
/*%< /*%<
* Returns a zone named 'name' from collection 'catzs' * Returns a zone named 'name' from collection 'catzs'
* *
@ -355,7 +350,7 @@ dns_catz_dbupdate_callback(dns_db_t *db, void *fn_arg);
*/ */
void void
dns_catz_dbupdate_unregister(dns_db_t *db, dns_catz_zones_t *catzs); dns_catz_dbupdate_register(dns_db_t *db, dns_catz_zones_t *catzs);
/*%< /*%<
* Register the catalog zone database update notify callback. * Register the catalog zone database update notify callback.
* *
@ -365,7 +360,7 @@ dns_catz_dbupdate_unregister(dns_db_t *db, dns_catz_zones_t *catzs);
*/ */
void void
dns_catz_dbupdate_register(dns_db_t *db, dns_catz_zones_t *catzs); dns_catz_dbupdate_unregister(dns_db_t *db, dns_catz_zones_t *catzs);
/*%< /*%<
* Unregister the catalog zone database update notify callback. * Unregister the catalog zone database update notify callback.
* *
@ -395,18 +390,7 @@ dns_catz_postreconfig(dns_catz_zones_t *catzs);
*/ */
void void
dns_catz_get_iterator(dns_catz_zone_t *catz, isc_ht_iter_t **itp); dns_catz_zones_shutdown(dns_catz_zones_t *catzs);
/*%<
* Get the hashtable iterator on catalog zone members, point '*itp' to it.
*
* Requires:
* \li 'catzs' is a valid dns_catz_zones_t.
* \li 'itp' is not NULL and '*itp' is NULL.
*
*/
void
dns_catz_shutdown_catzs(dns_catz_zones_t *catzs);
/*%< /*%<
* Shut down the catalog zones. * Shut down the catalog zones.
* *
@ -415,41 +399,43 @@ dns_catz_shutdown_catzs(dns_catz_zones_t *catzs);
* *
*/ */
typedef void (*dns_catz_entry_cb2)(dns_catz_entry_t *entry, void *arg1,
void *arg2);
void
dns_catz_zone_for_each_entry2(dns_catz_zone_t *catz, dns_catz_entry_cb2 cb,
void *arg1, void *arg2);
/*%<
* Iterate on the catalog zone members, call 'cb' on each 'entry'.
*
* Requires:
* \li 'catz' is a valid dns_catz_zones_t.
*
*/
#ifdef DNS_CATZ_TRACE #ifdef DNS_CATZ_TRACE
/* Compatibility macros */ /* Compatibility macros */
#define dns_catz_attach_catz(catz, catzp) \ #define dns_catz_zone_attach(catz, catzp) \
dns_catz_zone__attach(catz, catzp, __func__, __FILE__, __LINE__) dns_catz_zone__attach(catz, catzp, __func__, __FILE__, __LINE__)
#define dns_catz_detach_catz(catzp) \ #define dns_catz_zone_detach(catzp) \
dns_catz_zone__detach(catzp, __func__, __FILE__, __LINE__) dns_catz_zone__detach(catzp, __func__, __FILE__, __LINE__)
#define dns_catz_ref_catz(ptr) \ #define dns_catz_zone_ref(ptr) \
dns_catz_zone__ref(ptr, __func__, __FILE__, __LINE__) dns_catz_zone__ref(ptr, __func__, __FILE__, __LINE__)
#define dns_catz_unref_catz(ptr) \ #define dns_catz_zone_unref(ptr) \
dns_catz_zone__unref(ptr, __func__, __FILE__, __LINE__) dns_catz_zone__unref(ptr, __func__, __FILE__, __LINE__)
#define dns_catz_attach_catzs(catzs, catzsp) \ #define dns_catz_zones_attach(catzs, catzsp) \
dns_catz_zones__attach(catzs, catzsp, __func__, __FILE__, __LINE__) dns_catz_zones__attach(catzs, catzsp, __func__, __FILE__, __LINE__)
#define dns_catz_detach_catzs(catzsp) \ #define dns_catz_zones_detach(catzsp) \
dns_catz_zones__detach(catzsp, __func__, __FILE__, __LINE__) dns_catz_zones__detach(catzsp, __func__, __FILE__, __LINE__)
#define dns_catz_ref_catzs(ptr) \ #define dns_catz_zones_ref(ptr) \
dns_catz_zones__ref(ptr, __func__, __FILE__, __LINE__) dns_catz_zones__ref(ptr, __func__, __FILE__, __LINE__)
#define dns_catz_unref_catzs(ptr) \ #define dns_catz_zones_unref(ptr) \
dns_catz_zones__unref(ptr, __func__, __FILE__, __LINE__) dns_catz_zones__unref(ptr, __func__, __FILE__, __LINE__)
ISC_REFCOUNT_TRACE_DECL(dns_catz_zone); ISC_REFCOUNT_TRACE_DECL(dns_catz_zone);
ISC_REFCOUNT_TRACE_DECL(dns_catz_zones); ISC_REFCOUNT_TRACE_DECL(dns_catz_zones);
#else #else
/* Compatibility macros */
#define dns_catz_attach_catz(catz, catzp) dns_catz_zone_attach(catz, catzp)
#define dns_catz_detach_catz(catzp) dns_catz_zone_detach(catzp)
#define dns_catz_ref_catz(ptr) dns_catz_zone_ref(ptr)
#define dns_catz_unref_catz(ptr) dns_catz_zone_unref(ptr)
#define dns_catz_attach_catzs(catzs, catzsp) \
dns_catz_zones_attach(catzs, catzsp)
#define dns_catz_detach_catzs(catzsp) dns_catz_zones_detach(catzsp)
#define dns_catz_ref_catzs(ptr) dns_catz_zones_ref(ptr)
#define dns_catz_unref_catzs(ptr) dns_catz_zones_unref(ptr)
ISC_REFCOUNT_DECL(dns_catz_zone); ISC_REFCOUNT_DECL(dns_catz_zone);
ISC_REFCOUNT_DECL(dns_catz_zones); ISC_REFCOUNT_DECL(dns_catz_zones);
#endif /* DNS_CATZ_TRACE */ #endif /* DNS_CATZ_TRACE */

View File

@ -286,8 +286,8 @@ destroy(dns_view_t *view) {
dns_rpz_detach_rpzs(&view->rpzs); dns_rpz_detach_rpzs(&view->rpzs);
} }
if (view->catzs != NULL) { if (view->catzs != NULL) {
dns_catz_shutdown_catzs(view->catzs); dns_catz_zones_shutdown(view->catzs);
dns_catz_detach_catzs(&view->catzs); dns_catz_zones_detach(&view->catzs);
} }
for (dlzdb = ISC_LIST_HEAD(view->dlz_searched); dlzdb != NULL; for (dlzdb = ISC_LIST_HEAD(view->dlz_searched); dlzdb != NULL;
dlzdb = ISC_LIST_HEAD(view->dlz_searched)) dlzdb = ISC_LIST_HEAD(view->dlz_searched))
@ -514,8 +514,8 @@ dns_view_detach(dns_view_t **viewp) {
} }
} }
if (view->catzs != NULL) { if (view->catzs != NULL) {
dns_catz_shutdown_catzs(view->catzs); dns_catz_zones_shutdown(view->catzs);
dns_catz_detach_catzs(&view->catzs); dns_catz_zones_detach(&view->catzs);
} }
if (view->ntatable_priv != NULL) { if (view->ntatable_priv != NULL) {
dns_ntatable_shutdown(view->ntatable_priv); dns_ntatable_shutdown(view->ntatable_priv);

View File

@ -1301,7 +1301,7 @@ zone_free(dns_zone_t *zone) {
zone->rpz_num = DNS_RPZ_INVALID_NUM; zone->rpz_num = DNS_RPZ_INVALID_NUM;
} }
if (zone->catzs != NULL) { if (zone->catzs != NULL) {
dns_catz_detach_catzs(&zone->catzs); dns_catz_zones_detach(&zone->catzs);
} }
zone_freedbargs(zone); zone_freedbargs(zone);
@ -1961,7 +1961,7 @@ zone_catz_enable(dns_zone_t *zone, dns_catz_zones_t *catzs) {
INSIST(zone->catzs == NULL || zone->catzs == catzs); INSIST(zone->catzs == NULL || zone->catzs == catzs);
dns_catz_catzs_set_view(catzs, zone->view); dns_catz_catzs_set_view(catzs, zone->view);
if (zone->catzs == NULL) { if (zone->catzs == NULL) {
dns_catz_attach_catzs(catzs, &zone->catzs); dns_catz_zones_attach(catzs, &zone->catzs);
} }
} }
@ -1982,7 +1982,7 @@ zone_catz_disable(dns_zone_t *zone) {
if (zone->db != NULL) { if (zone->db != NULL) {
dns_zone_catz_disable_db(zone, zone->db); dns_zone_catz_disable_db(zone, zone->db);
} }
dns_catz_detach_catzs(&zone->catzs); dns_catz_zones_detach(&zone->catzs);
} }
} }