2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-09-03 16:15:27 +00:00

add missing DBC checks for catz and add isc_magic checks; add DBC checks to ht.c

This commit is contained in:
Mark Andrews
2018-11-28 18:57:38 +11:00
parent b726ca4533
commit a487473fc5
7 changed files with 226 additions and 123 deletions

View File

@@ -1,3 +1,6 @@
5103. [bug] Add missing design by contract tests to dns_catz*.
[GL #748]
5102. [bug] dnssec-coverage failed to use the default TTL when 5102. [bug] dnssec-coverage failed to use the default TTL when
checking KSK deletion times leading to a exception. checking KSK deletion times leading to a exception.
[GL #585] [GL #585]

View File

@@ -32,11 +32,19 @@
#include <dns/view.h> #include <dns/view.h>
#include <dns/zone.h> #include <dns/zone.h>
#define DNS_CATZ_ZONE_MAGIC ISC_MAGIC('c', 'a', 't', 'z')
#define DNS_CATZ_ZONES_MAGIC ISC_MAGIC('c', 'a', 't', 's')
#define DNS_CATZ_ENTRY_MAGIC ISC_MAGIC('c', 'a', 't', 'e')
#define DNS_CATZ_ZONE_VALID(catz) ISC_MAGIC_VALID(catz, DNS_CATZ_ZONE_MAGIC)
#define DNS_CATZ_ZONES_VALID(catzs) ISC_MAGIC_VALID(catzs, DNS_CATZ_ZONES_MAGIC)
#define DNS_CATZ_ENTRY_VALID(entry) ISC_MAGIC_VALID(entry, DNS_CATZ_ENTRY_MAGIC)
/*% /*%
* Single member zone in a catalog * Single member zone in a catalog
*/ */
struct dns_catz_entry { struct dns_catz_entry {
unsigned int magic;
dns_name_t name; dns_name_t name;
dns_catz_options_t opts; dns_catz_options_t opts;
isc_refcount_t refs; isc_refcount_t refs;
@@ -46,6 +54,7 @@ struct dns_catz_entry {
* Catalog zone * Catalog zone
*/ */
struct dns_catz_zone { struct dns_catz_zone {
unsigned int magic;
dns_name_t name; dns_name_t name;
dns_catz_zones_t *catzs; dns_catz_zones_t *catzs;
dns_rdata_t soa; dns_rdata_t soa;
@@ -84,6 +93,7 @@ catz_process_zones_suboption(dns_catz_zone_t *zone, dns_rdataset_t *value,
* Collection of catalog zones for a view * Collection of catalog zones for a view
*/ */
struct dns_catz_zones { struct dns_catz_zones {
unsigned int magic;
isc_ht_t *zones; isc_ht_t *zones;
isc_mem_t *mctx; isc_mem_t *mctx;
isc_refcount_t refs; isc_refcount_t refs;
@@ -97,6 +107,9 @@ struct dns_catz_zones {
void void
dns_catz_options_init(dns_catz_options_t *options) { dns_catz_options_init(dns_catz_options_t *options) {
REQUIRE(options != NULL);
dns_ipkeylist_init(&options->masters); dns_ipkeylist_init(&options->masters);
options->allow_query = NULL; options->allow_query = NULL;
@@ -112,6 +125,10 @@ dns_catz_options_init(dns_catz_options_t *options) {
void void
dns_catz_options_free(dns_catz_options_t *options, isc_mem_t *mctx) { dns_catz_options_free(dns_catz_options_t *options, isc_mem_t *mctx) {
REQUIRE(options != NULL);
REQUIRE(mctx != NULL);
if (options->masters.count != 0) if (options->masters.count != 0)
dns_ipkeylist_clear(mctx, &options->masters); dns_ipkeylist_clear(mctx, &options->masters);
if (options->zonedir != NULL) { if (options->zonedir != NULL) {
@@ -128,6 +145,7 @@ isc_result_t
dns_catz_options_copy(isc_mem_t *mctx, const dns_catz_options_t *src, dns_catz_options_copy(isc_mem_t *mctx, const dns_catz_options_t *src,
dns_catz_options_t *dst) dns_catz_options_t *dst)
{ {
REQUIRE(mctx != NULL);
REQUIRE(src != NULL); REQUIRE(src != NULL);
REQUIRE(dst != NULL); REQUIRE(dst != NULL);
REQUIRE(dst->masters.count == 0); REQUIRE(dst->masters.count == 0);
@@ -158,6 +176,10 @@ isc_result_t
dns_catz_options_setdefault(isc_mem_t *mctx, const dns_catz_options_t *defaults, dns_catz_options_setdefault(isc_mem_t *mctx, const dns_catz_options_t *defaults,
dns_catz_options_t *opts) dns_catz_options_t *opts)
{ {
REQUIRE(mctx != NULL);
REQUIRE(defaults != NULL);
REQUIRE(opts != NULL);
if (opts->masters.count == 0 && defaults->masters.count != 0) if (opts->masters.count == 0 && defaults->masters.count != 0)
dns_ipkeylist_copy(mctx, &defaults->masters, &opts->masters); dns_ipkeylist_copy(mctx, &defaults->masters, &opts->masters);
@@ -182,6 +204,7 @@ dns_catz_entry_new(isc_mem_t *mctx, const dns_name_t *domain,
dns_catz_entry_t *nentry; dns_catz_entry_t *nentry;
isc_result_t result; isc_result_t result;
REQUIRE(mctx != NULL);
REQUIRE(nentryp != NULL && *nentryp == NULL); REQUIRE(nentryp != NULL && *nentryp == NULL);
nentry = isc_mem_get(mctx, sizeof(dns_catz_entry_t)); nentry = isc_mem_get(mctx, sizeof(dns_catz_entry_t));
@@ -197,6 +220,7 @@ 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->refs, 1); isc_refcount_init(&nentry->refs, 1);
nentry->magic = DNS_CATZ_ENTRY_MAGIC;
*nentryp = nentry; *nentryp = nentry;
return (ISC_R_SUCCESS); return (ISC_R_SUCCESS);
@@ -207,6 +231,7 @@ cleanup:
dns_name_t * dns_name_t *
dns_catz_entry_getname(dns_catz_entry_t *entry) { dns_catz_entry_getname(dns_catz_entry_t *entry) {
REQUIRE(DNS_CATZ_ENTRY_VALID(entry));
return (&entry->name); return (&entry->name);
} }
@@ -217,6 +242,10 @@ dns_catz_entry_copy(dns_catz_zone_t *zone, const dns_catz_entry_t *entry,
isc_result_t result; isc_result_t result;
dns_catz_entry_t *nentry = NULL; dns_catz_entry_t *nentry = NULL;
REQUIRE(DNS_CATZ_ZONE_VALID(zone));
REQUIRE(DNS_CATZ_ENTRY_VALID(entry));
REQUIRE(nentryp != NULL && *nentryp == NULL);
result = dns_catz_entry_new(zone->catzs->mctx, &entry->name, &nentry); result = dns_catz_entry_new(zone->catzs->mctx, &entry->name, &nentry);
if (result != ISC_R_SUCCESS) if (result != ISC_R_SUCCESS)
return (result); return (result);
@@ -232,20 +261,28 @@ dns_catz_entry_copy(dns_catz_zone_t *zone, const dns_catz_entry_t *entry,
void void
dns_catz_entry_attach(dns_catz_entry_t *entry, dns_catz_entry_t **entryp) { dns_catz_entry_attach(dns_catz_entry_t *entry, dns_catz_entry_t **entryp) {
REQUIRE(DNS_CATZ_ENTRY_VALID(entry));
REQUIRE(entryp != NULL && *entryp == NULL); REQUIRE(entryp != NULL && *entryp == NULL);
isc_refcount_increment(&entry->refs); isc_refcount_increment(&entry->refs);
*entryp = entry; *entryp = entry;
} }
void void
dns_catz_entry_detach(dns_catz_zone_t *zone, dns_catz_entry_t **entryp) { dns_catz_entry_detach(dns_catz_zone_t *zone, dns_catz_entry_t **entryp) {
REQUIRE(entryp != NULL && *entryp != NULL); dns_catz_entry_t *entry;
dns_catz_entry_t *entry = *entryp;
REQUIRE(DNS_CATZ_ZONE_VALID(zone));
REQUIRE(entryp != NULL);
entry = *entryp;
REQUIRE(DNS_CATZ_ENTRY_VALID(entry));
*entryp = NULL; *entryp = NULL;
if (isc_refcount_decrement(&entry->refs) == 1) { if (isc_refcount_decrement(&entry->refs) == 1) {
isc_refcount_destroy(&entry->refs);
isc_mem_t *mctx = zone->catzs->mctx; isc_mem_t *mctx = zone->catzs->mctx;
entry->magic = 0;
isc_refcount_destroy(&entry->refs);
dns_catz_options_free(&entry->opts, mctx); dns_catz_options_free(&entry->opts, mctx);
if (dns_name_dynamic(&entry->name)) if (dns_name_dynamic(&entry->name))
dns_name_free(&entry->name, mctx); dns_name_free(&entry->name, mctx);
@@ -255,6 +292,7 @@ dns_catz_entry_detach(dns_catz_zone_t *zone, dns_catz_entry_t **entryp) {
bool bool
dns_catz_entry_validate(const dns_catz_entry_t *entry) { dns_catz_entry_validate(const dns_catz_entry_t *entry) {
REQUIRE(DNS_CATZ_ENTRY_VALID(entry));
UNUSED(entry); UNUSED(entry);
return (true); return (true);
@@ -264,6 +302,9 @@ bool
dns_catz_entry_cmp(const dns_catz_entry_t *ea, const dns_catz_entry_t *eb) { dns_catz_entry_cmp(const dns_catz_entry_t *ea, const dns_catz_entry_t *eb) {
isc_region_t ra, rb; isc_region_t ra, rb;
REQUIRE(DNS_CATZ_ENTRY_VALID(ea));
REQUIRE(DNS_CATZ_ENTRY_VALID(eb));
if (ea == eb) if (ea == eb)
return (true); return (true);
@@ -304,21 +345,21 @@ dns_catz_entry_cmp(const dns_catz_entry_t *ea, const dns_catz_entry_t *eb) {
dns_name_t * dns_name_t *
dns_catz_zone_getname(dns_catz_zone_t *zone) { dns_catz_zone_getname(dns_catz_zone_t *zone) {
REQUIRE(zone != NULL); REQUIRE(DNS_CATZ_ZONE_VALID(zone));
return (&zone->name); return (&zone->name);
} }
dns_catz_options_t * dns_catz_options_t *
dns_catz_zone_getdefoptions(dns_catz_zone_t *zone) { dns_catz_zone_getdefoptions(dns_catz_zone_t *zone) {
REQUIRE(zone != NULL); REQUIRE(DNS_CATZ_ZONE_VALID(zone));
return (&zone->defoptions); return (&zone->defoptions);
} }
void void
dns_catz_zone_resetdefoptions(dns_catz_zone_t *zone) { dns_catz_zone_resetdefoptions(dns_catz_zone_t *zone) {
REQUIRE(zone != NULL); REQUIRE(DNS_CATZ_ZONE_VALID(zone));
dns_catz_options_free(&zone->defoptions, zone->catzs->mctx); dns_catz_options_free(&zone->defoptions, zone->catzs->mctx);
dns_catz_options_init(&zone->defoptions); dns_catz_options_init(&zone->defoptions);
@@ -335,8 +376,8 @@ dns_catz_zones_merge(dns_catz_zone_t *target, dns_catz_zone_t *newzone) {
char zname[DNS_NAME_FORMATSIZE]; char zname[DNS_NAME_FORMATSIZE];
dns_catz_zoneop_fn_t addzone, modzone, delzone; dns_catz_zoneop_fn_t addzone, modzone, delzone;
REQUIRE(target != NULL); REQUIRE(DNS_CATZ_ZONE_VALID(newzone));
REQUIRE(newzone != NULL); REQUIRE(DNS_CATZ_ZONE_VALID(target));
/* TODO verify the new zone first! */ /* TODO verify the new zone first! */
@@ -391,9 +432,9 @@ dns_catz_zones_merge(dns_catz_zone_t *target, dns_catz_zone_t *newzone) {
result = delcur ? isc_ht_iter_delcurrent_next(iter1) : result = delcur ? isc_ht_iter_delcurrent_next(iter1) :
isc_ht_iter_next(iter1)) isc_ht_iter_next(iter1))
{ {
dns_catz_entry_t *nentry; dns_catz_entry_t *nentry = NULL;
dns_catz_entry_t *oentry; dns_catz_entry_t *oentry = NULL;
unsigned char * key; unsigned char * key = NULL;
size_t keysize; size_t keysize;
delcur = false; delcur = false;
@@ -464,7 +505,7 @@ dns_catz_zones_merge(dns_catz_zone_t *target, dns_catz_zone_t *newzone) {
result == ISC_R_SUCCESS; result == ISC_R_SUCCESS;
result = isc_ht_iter_delcurrent_next(iter2)) result = isc_ht_iter_delcurrent_next(iter2))
{ {
dns_catz_entry_t *entry; dns_catz_entry_t *entry = NULL;
isc_ht_iter_current(iter2, (void **) &entry); isc_ht_iter_current(iter2, (void **) &entry);
dns_name_format(&entry->name, zname, DNS_NAME_FORMATSIZE); dns_name_format(&entry->name, zname, DNS_NAME_FORMATSIZE);
@@ -487,7 +528,7 @@ dns_catz_zones_merge(dns_catz_zone_t *target, dns_catz_zone_t *newzone) {
result == ISC_R_SUCCESS; result == ISC_R_SUCCESS;
result = isc_ht_iter_delcurrent_next(iteradd)) result = isc_ht_iter_delcurrent_next(iteradd))
{ {
dns_catz_entry_t *entry; dns_catz_entry_t *entry = NULL;
isc_ht_iter_current(iteradd, (void **) &entry); isc_ht_iter_current(iteradd, (void **) &entry);
dns_name_format(&entry->name, zname, DNS_NAME_FORMATSIZE); dns_name_format(&entry->name, zname, DNS_NAME_FORMATSIZE);
@@ -506,7 +547,7 @@ dns_catz_zones_merge(dns_catz_zone_t *target, dns_catz_zone_t *newzone) {
result == ISC_R_SUCCESS; result == ISC_R_SUCCESS;
result = isc_ht_iter_delcurrent_next(itermod)) result = isc_ht_iter_delcurrent_next(itermod))
{ {
dns_catz_entry_t *entry; dns_catz_entry_t *entry = NULL;
isc_ht_iter_current(itermod, (void **) &entry); isc_ht_iter_current(itermod, (void **) &entry);
dns_name_format(&entry->name, zname, DNS_NAME_FORMATSIZE); dns_name_format(&entry->name, zname, DNS_NAME_FORMATSIZE);
@@ -540,7 +581,6 @@ cleanup:
if (tomod != NULL) if (tomod != NULL)
isc_ht_destroy(&tomod); isc_ht_destroy(&tomod);
return (result); return (result);
} }
isc_result_t isc_result_t
@@ -575,6 +615,7 @@ dns_catz_new_zones(dns_catz_zones_t **catzsp, dns_catz_zonemodmethods_t *zmm,
result = isc_task_create(taskmgr, 0, &new_zones->updater); result = isc_task_create(taskmgr, 0, &new_zones->updater);
if (result != ISC_R_SUCCESS) if (result != ISC_R_SUCCESS)
goto cleanup_ht; goto cleanup_ht;
new_zones->magic = DNS_CATZ_ZONES_MAGIC;
*catzsp = new_zones; *catzsp = new_zones;
return (ISC_R_SUCCESS); return (ISC_R_SUCCESS);
@@ -591,7 +632,7 @@ dns_catz_new_zones(dns_catz_zones_t **catzsp, dns_catz_zonemodmethods_t *zmm,
void void
dns_catz_catzs_set_view(dns_catz_zones_t *catzs, dns_view_t *view) { dns_catz_catzs_set_view(dns_catz_zones_t *catzs, dns_view_t *view) {
REQUIRE(catzs != NULL); REQUIRE(DNS_CATZ_ZONES_VALID(catzs));
REQUIRE(view != NULL); REQUIRE(view != NULL);
/* Either it's a new one or it's being reconfigured. */ /* Either it's a new one or it's being reconfigured. */
REQUIRE(catzs->view == NULL || !strcmp(catzs->view->name, view->name)); REQUIRE(catzs->view == NULL || !strcmp(catzs->view->name, view->name));
@@ -606,7 +647,9 @@ dns_catz_new_zone(dns_catz_zones_t *catzs, dns_catz_zone_t **zonep,
isc_result_t result; isc_result_t result;
dns_catz_zone_t *new_zone; dns_catz_zone_t *new_zone;
REQUIRE(DNS_CATZ_ZONES_VALID(catzs));
REQUIRE(zonep != NULL && *zonep == NULL); REQUIRE(zonep != NULL && *zonep == NULL);
REQUIRE(ISC_MAGIC_VALID(name, DNS_NAME_MAGIC));
new_zone = isc_mem_get(catzs->mctx, sizeof(*new_zone)); new_zone = isc_mem_get(catzs->mctx, sizeof(*new_zone));
if (new_zone == NULL) if (new_zone == NULL)
@@ -643,6 +686,7 @@ dns_catz_new_zone(dns_catz_zones_t *catzs, dns_catz_zone_t **zonep,
new_zone->db_registered = false; new_zone->db_registered = false;
new_zone->version = (uint32_t)(-1); new_zone->version = (uint32_t)(-1);
isc_refcount_init(&new_zone->refs, 1); isc_refcount_init(&new_zone->refs, 1);
new_zone->magic = DNS_CATZ_ZONE_MAGIC;
*zonep = new_zone; *zonep = new_zone;
@@ -666,9 +710,10 @@ dns_catz_add_zone(dns_catz_zones_t *catzs, const dns_name_t *name,
isc_result_t result, tresult; isc_result_t result, tresult;
char zname[DNS_NAME_FORMATSIZE]; char zname[DNS_NAME_FORMATSIZE];
REQUIRE(catzs != NULL); REQUIRE(DNS_CATZ_ZONES_VALID(catzs));
REQUIRE(name != NULL); REQUIRE(ISC_MAGIC_VALID(name, DNS_NAME_MAGIC));
REQUIRE(zonep != NULL && *zonep == NULL); REQUIRE(zonep != NULL && *zonep == NULL);
dns_name_format(name, zname, DNS_NAME_FORMATSIZE); dns_name_format(name, zname, DNS_NAME_FORMATSIZE);
isc_log_write(dns_lctx, DNS_LOGCATEGORY_GENERAL, isc_log_write(dns_lctx, DNS_LOGCATEGORY_GENERAL,
DNS_LOGMODULE_MASTER, ISC_LOG_DEBUG(3), DNS_LOGMODULE_MASTER, ISC_LOG_DEBUG(3),
@@ -706,7 +751,10 @@ 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_get_zone(dns_catz_zones_t *catzs, const dns_name_t *name) {
isc_result_t result; isc_result_t result;
dns_catz_zone_t *found; dns_catz_zone_t *found = NULL;
REQUIRE(DNS_CATZ_ZONES_VALID(catzs));
REQUIRE(ISC_MAGIC_VALID(name, DNS_NAME_MAGIC));
result = isc_ht_find(catzs->zones, name->ndata, name->length, result = isc_ht_find(catzs->zones, name->ndata, name->length,
(void **) &found); (void **) &found);
@@ -718,6 +766,7 @@ dns_catz_get_zone(dns_catz_zones_t *catzs, const dns_name_t *name) {
void void
dns_catz_catzs_attach(dns_catz_zones_t *catzs, dns_catz_zones_t **catzsp) { dns_catz_catzs_attach(dns_catz_zones_t *catzs, dns_catz_zones_t **catzsp) {
REQUIRE(DNS_CATZ_ZONES_VALID(catzs));
REQUIRE(catzsp != NULL && *catzsp == NULL); REQUIRE(catzsp != NULL && *catzsp == NULL);
isc_refcount_increment(&catzs->refs); isc_refcount_increment(&catzs->refs);
@@ -739,6 +788,7 @@ dns_catz_zone_detach(dns_catz_zone_t **zonep) {
*zonep = NULL; *zonep = NULL;
if (isc_refcount_decrement(&zone->refs) == 1) { if (isc_refcount_decrement(&zone->refs) == 1) {
isc_mem_t *mctx = zone->catzs->mctx;
isc_refcount_destroy(&zone->refs); isc_refcount_destroy(&zone->refs);
if (zone->entries != NULL) { if (zone->entries != NULL) {
isc_ht_iter_t *iter = NULL; isc_ht_iter_t *iter = NULL;
@@ -749,7 +799,7 @@ dns_catz_zone_detach(dns_catz_zone_t **zonep) {
result == ISC_R_SUCCESS; result == ISC_R_SUCCESS;
result = isc_ht_iter_delcurrent_next(iter)) result = isc_ht_iter_delcurrent_next(iter))
{ {
dns_catz_entry_t *entry; dns_catz_entry_t *entry = NULL;
isc_ht_iter_current(iter, (void **) &entry); isc_ht_iter_current(iter, (void **) &entry);
dns_catz_entry_detach(zone, &entry); dns_catz_entry_detach(zone, &entry);
@@ -761,7 +811,7 @@ dns_catz_zone_detach(dns_catz_zone_t **zonep) {
INSIST(isc_ht_count(zone->entries) == 0); INSIST(isc_ht_count(zone->entries) == 0);
isc_ht_destroy(&zone->entries); isc_ht_destroy(&zone->entries);
} }
isc_mem_t *mctx = zone->catzs->mctx; zone->magic = 0;
isc_timer_detach(&zone->updatetimer); isc_timer_detach(&zone->updatetimer);
if (zone->db_registered == true) { if (zone->db_registered == true) {
INSIST(dns_db_updatenotify_unregister( INSIST(dns_db_updatenotify_unregister(
@@ -794,6 +844,7 @@ dns_catz_catzs_detach(dns_catz_zones_t **catzsp) {
*catzsp = NULL; *catzsp = NULL;
if (isc_refcount_decrement(&catzs->refs) == 1) { if (isc_refcount_decrement(&catzs->refs) == 1) {
catzs->magic = 0;
isc_task_destroy(&catzs->updater); isc_task_destroy(&catzs->updater);
isc_mutex_destroy(&catzs->lock); isc_mutex_destroy(&catzs->lock);
if (catzs->zones != NULL) { if (catzs->zones != NULL) {
@@ -804,7 +855,7 @@ dns_catz_catzs_detach(dns_catz_zones_t **catzsp) {
for (result = isc_ht_iter_first(iter); for (result = isc_ht_iter_first(iter);
result == ISC_R_SUCCESS;) result == ISC_R_SUCCESS;)
{ {
dns_catz_zone_t *zone; dns_catz_zone_t *zone = NULL;
isc_ht_iter_current(iter, (void **) &zone); isc_ht_iter_current(iter, (void **) &zone);
result = isc_ht_iter_delcurrent_next(iter); result = isc_ht_iter_delcurrent_next(iter);
dns_catz_zone_detach(&zone); dns_catz_zone_detach(&zone);
@@ -861,9 +912,9 @@ catz_process_zones(dns_catz_zone_t *zone, dns_rdataset_t *value,
dns_label_t mhash; dns_label_t mhash;
dns_name_t opt; dns_name_t opt;
REQUIRE(zone != NULL); REQUIRE(DNS_CATZ_ZONE_VALID(zone));
REQUIRE(DNS_RDATASET_VALID(value)); REQUIRE(DNS_RDATASET_VALID(value));
REQUIRE(name != NULL); REQUIRE(ISC_MAGIC_VALID(name, DNS_NAME_MAGIC));
if (value->rdclass != dns_rdataclass_in) if (value->rdclass != dns_rdataclass_in)
return (ISC_R_FAILURE); return (ISC_R_FAILURE);
@@ -954,7 +1005,7 @@ catz_process_version(dns_catz_zone_t *zone, dns_rdataset_t *value) {
uint32_t tversion; uint32_t tversion;
char t[16]; char t[16];
REQUIRE(zone != NULL); REQUIRE(DNS_CATZ_ZONE_VALID(zone));
REQUIRE(DNS_RDATASET_VALID(value)); REQUIRE(DNS_RDATASET_VALID(value));
if (value->rdclass != dns_rdataclass_in || if (value->rdclass != dns_rdataclass_in ||
@@ -1019,11 +1070,11 @@ catz_process_masters(dns_catz_zone_t *zone, dns_ipkeylist_t *ipkl,
unsigned int rcount; unsigned int rcount;
unsigned int i; unsigned int i;
REQUIRE(zone != NULL); REQUIRE(DNS_CATZ_ZONE_VALID(zone));
REQUIRE(ipkl != NULL); REQUIRE(ipkl != NULL);
REQUIRE(DNS_RDATASET_VALID(value)); REQUIRE(DNS_RDATASET_VALID(value));
REQUIRE(dns_rdataset_isassociated(value)); REQUIRE(dns_rdataset_isassociated(value));
REQUIRE(name != NULL); REQUIRE(ISC_MAGIC_VALID(name, DNS_NAME_MAGIC));
mctx = zone->catzs->mctx; mctx = zone->catzs->mctx;
memset(&rdata_a, 0, sizeof(rdata_a)); memset(&rdata_a, 0, sizeof(rdata_a));
@@ -1203,7 +1254,7 @@ catz_process_apl(dns_catz_zone_t *zone, isc_buffer_t **aclbp,
isc_buffer_t *aclb = NULL; isc_buffer_t *aclb = NULL;
unsigned char buf[256]; /* larger than INET6_ADDRSTRLEN */ unsigned char buf[256]; /* larger than INET6_ADDRSTRLEN */
REQUIRE(zone != NULL); REQUIRE(DNS_CATZ_ZONE_VALID(zone));
REQUIRE(aclbp != NULL); REQUIRE(aclbp != NULL);
REQUIRE(*aclbp == NULL); REQUIRE(*aclbp == NULL);
REQUIRE(DNS_RDATASET_VALID(value)); REQUIRE(DNS_RDATASET_VALID(value));
@@ -1280,9 +1331,10 @@ catz_process_zones_suboption(dns_catz_zone_t *zone, dns_rdataset_t *value,
dns_name_t prefix; dns_name_t prefix;
catz_opt_t opt; catz_opt_t opt;
REQUIRE(zone != NULL); REQUIRE(DNS_CATZ_ZONE_VALID(zone));
REQUIRE(mhash != NULL); REQUIRE(mhash != NULL);
REQUIRE(DNS_RDATASET_VALID(value)); REQUIRE(DNS_RDATASET_VALID(value));
REQUIRE(ISC_MAGIC_VALID(name, DNS_NAME_MAGIC));
if (name->labels == 0) if (name->labels == 0)
return (ISC_R_FAILURE); return (ISC_R_FAILURE);
@@ -1338,8 +1390,8 @@ catz_process_value(dns_catz_zone_t *zone, dns_name_t *name,
dns_name_t prefix; dns_name_t prefix;
catz_opt_t opt; catz_opt_t opt;
REQUIRE(zone != NULL); REQUIRE(DNS_CATZ_ZONE_VALID(zone));
REQUIRE(name != NULL); REQUIRE(ISC_MAGIC_VALID(name, DNS_NAME_MAGIC));
REQUIRE(DNS_RDATASET_VALID(rdataset)); REQUIRE(DNS_RDATASET_VALID(rdataset));
dns_name_getlabel(name, name->labels - 1, &option); dns_name_getlabel(name, name->labels - 1, &option);
@@ -1384,8 +1436,9 @@ dns_catz_update_process(dns_catz_zones_t *catzs, dns_catz_zone_t *zone,
dns_rdata_soa_t soa; dns_rdata_soa_t soa;
dns_name_t prefix; dns_name_t prefix;
REQUIRE(catzs != NULL); REQUIRE(DNS_CATZ_ZONES_VALID(catzs));
REQUIRE(zone != NULL); REQUIRE(DNS_CATZ_ZONE_VALID(zone));
REQUIRE(ISC_MAGIC_VALID(src_name, DNS_NAME_MAGIC));
nrres = dns_name_fullcompare(src_name, &zone->name, &order, &nlabels); nrres = dns_name_fullcompare(src_name, &zone->name, &order, &nlabels);
if (nrres == dns_namereln_equal) { if (nrres == dns_namereln_equal) {
@@ -1444,7 +1497,7 @@ dns_catz_generate_masterfilename(dns_catz_zone_t *zone, dns_catz_entry_t *entry,
isc_result_t result; isc_result_t result;
size_t rlen; size_t rlen;
REQUIRE(zone != NULL); REQUIRE(DNS_CATZ_ZONE_VALID(zone));
REQUIRE(entry != NULL); REQUIRE(entry != NULL);
REQUIRE(buffer != NULL && *buffer != NULL); REQUIRE(buffer != NULL && *buffer != NULL);
@@ -1530,7 +1583,7 @@ dns_catz_generate_zonecfg(dns_catz_zone_t *zone, dns_catz_entry_t *entry,
char pbuf[sizeof("65535")]; /* used both for port number and DSCP */ char pbuf[sizeof("65535")]; /* used both for port number and DSCP */
char zname[DNS_NAME_FORMATSIZE]; char zname[DNS_NAME_FORMATSIZE];
REQUIRE(zone != NULL); REQUIRE(DNS_CATZ_ZONE_VALID(zone));
REQUIRE(entry != NULL); REQUIRE(entry != NULL);
REQUIRE(buf != NULL && *buf == NULL); REQUIRE(buf != NULL && *buf == NULL);
@@ -1642,7 +1695,7 @@ dns_catz_update_taskaction(isc_task_t *task, isc_event_t *event) {
REQUIRE(event != NULL); REQUIRE(event != NULL);
zone = event->ev_arg; zone = event->ev_arg;
REQUIRE(zone != NULL); REQUIRE(DNS_CATZ_ZONE_VALID(zone));
LOCK(&zone->catzs->lock); LOCK(&zone->catzs->lock);
zone->updatepending = false; zone->updatepending = false;
@@ -1754,7 +1807,7 @@ dns_catz_update_from_db(dns_db_t *db, dns_catz_zones_t *catzs) {
uint32_t vers; uint32_t vers;
REQUIRE(DNS_DB_VALID(db)); REQUIRE(DNS_DB_VALID(db));
REQUIRE(catzs != NULL); REQUIRE(DNS_CATZ_ZONES_VALID(catzs));
/* /*
* Create a new catz in the same context as current catz. * Create a new catz in the same context as current catz.
@@ -1927,9 +1980,8 @@ void
dns_catz_prereconfig(dns_catz_zones_t *catzs) { dns_catz_prereconfig(dns_catz_zones_t *catzs) {
isc_result_t result; isc_result_t result;
isc_ht_iter_t *iter = NULL; isc_ht_iter_t *iter = NULL;
dns_catz_zone_t *zone;
REQUIRE(catzs != NULL); REQUIRE(DNS_CATZ_ZONES_VALID(catzs));
result = isc_ht_iter_create(catzs->zones, &iter); result = isc_ht_iter_create(catzs->zones, &iter);
INSIST(result == ISC_R_SUCCESS); INSIST(result == ISC_R_SUCCESS);
@@ -1937,6 +1989,7 @@ dns_catz_prereconfig(dns_catz_zones_t *catzs) {
result == ISC_R_SUCCESS; result == ISC_R_SUCCESS;
result = isc_ht_iter_next(iter)) result = isc_ht_iter_next(iter))
{ {
dns_catz_zone_t *zone = NULL;
isc_ht_iter_current(iter, (void **) &zone); isc_ht_iter_current(iter, (void **) &zone);
zone->active = false; zone->active = false;
} }
@@ -1949,7 +2002,8 @@ dns_catz_postreconfig(dns_catz_zones_t *catzs) {
isc_result_t result; isc_result_t result;
dns_catz_zone_t *newzone = NULL; dns_catz_zone_t *newzone = NULL;
isc_ht_iter_t *iter = NULL; isc_ht_iter_t *iter = NULL;
dns_catz_zone_t *zone;
REQUIRE(DNS_CATZ_ZONES_VALID(catzs));
LOCK(&catzs->lock); LOCK(&catzs->lock);
result = isc_ht_iter_create(catzs->zones, &iter); result = isc_ht_iter_create(catzs->zones, &iter);
@@ -1957,6 +2011,8 @@ dns_catz_postreconfig(dns_catz_zones_t *catzs) {
for (result = isc_ht_iter_first(iter); for (result = isc_ht_iter_first(iter);
result == ISC_R_SUCCESS;) result == ISC_R_SUCCESS;)
{ {
dns_catz_zone_t *zone = NULL;
isc_ht_iter_current(iter, (void **) &zone); isc_ht_iter_current(iter, (void **) &zone);
if (zone->active == false) { if (zone->active == false) {
char cname[DNS_NAME_FORMATSIZE]; char cname[DNS_NAME_FORMATSIZE];
@@ -1992,5 +2048,6 @@ dns_catz_postreconfig(dns_catz_zones_t *catzs) {
isc_result_t isc_result_t
dns_catz_get_iterator(dns_catz_zone_t *catz, isc_ht_iter_t **itp) { dns_catz_get_iterator(dns_catz_zone_t *catz, isc_ht_iter_t **itp) {
REQUIRE(DNS_CATZ_ZONE_VALID(catz));
return (isc_ht_iter_create(catz->entries, itp)); return (isc_ht_iter_create(catz->entries, itp));
} }

View File

@@ -78,7 +78,7 @@ dns_catz_options_init(dns_catz_options_t *options);
* Initialize 'options' to NULL values. * Initialize 'options' to NULL values.
* *
* Requires: * Requires:
* \li options to be non NULL * \li 'options' to be non NULL.
*/ */
void void
@@ -87,20 +87,20 @@ dns_catz_options_free(dns_catz_options_t *options, isc_mem_t *mctx);
* Free 'options' contents into 'mctx'. ('options' itself is not freed.) * Free 'options' contents into 'mctx'. ('options' itself is not freed.)
* *
* Requires: * Requires:
* \li options to be non NULL * \li 'options' to be non NULL.
* \li mctx to be a valid memory context * \li 'mctx' to be a valid memory context.
*/ */
isc_result_t isc_result_t
dns_catz_options_copy(isc_mem_t *mctx, const dns_catz_options_t *opts, dns_catz_options_copy(isc_mem_t *mctx, const dns_catz_options_t *opts,
dns_catz_options_t *nopts); dns_catz_options_t *nopts);
/*%< /*%<
* Duplicate 'opts' into 'nopts', allocating space from 'mctx' * Duplicate 'opts' into 'nopts', allocating space from 'mctx'.
* *
* Requires: * Requires:
* \li 'mctx' to be a valid memory context * \li 'mctx' to be a valid memory context.
* \li 'options' to be non NULL and valid options * \li 'options' to be non NULL and valid options.
* \li 'nopts' to be non NULL * \li 'nopts' to be non NULL.
*/ */
isc_result_t isc_result_t
@@ -110,9 +110,9 @@ dns_catz_options_setdefault(isc_mem_t *mctx, const dns_catz_options_t *defaults,
* Replace empty values in 'opts' with values from 'defaults' * Replace empty values in 'opts' with values from 'defaults'
* *
* Requires: * Requires:
* \li mctx to be a valid memory context * \li 'mctx' to be a valid memory context.
* \li defaults to be non NULL and valid options * \li 'defaults' to be non NULL and valid options.
* \li opts to be non NULL * \li 'opts' to be non NULL.
*/ */
dns_name_t * dns_name_t *
@@ -121,10 +121,10 @@ dns_catz_entry_getname(dns_catz_entry_t *entry);
* Get domain name for 'entry' * Get domain name for 'entry'
* *
* Requires: * Requires:
* \li entry to be non NULL * \li 'entry' to be non NULL.
* *
* Returns: * Returns:
* \li domain name for entry * \li domain name for entry.
*/ */
isc_result_t isc_result_t
@@ -134,9 +134,9 @@ dns_catz_entry_new(isc_mem_t *mctx, const dns_name_t *domain,
* 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 * \li 'nentryp' to be non NULL, *nentryp to be NULL.
* *
* Returns: * Returns:
* \li ISC_R_SUCCESS on success * \li ISC_R_SUCCESS on success
@@ -150,9 +150,9 @@ dns_catz_entry_copy(dns_catz_zone_t *zone, const dns_catz_entry_t *entry,
* 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 * \li 'nentryp' to be non NULL, *nentryp to be NULL.
* *
* Returns: * Returns:
* \li ISC_R_SUCCESS on success * \li ISC_R_SUCCESS on success
@@ -165,8 +165,8 @@ dns_catz_entry_attach(dns_catz_entry_t *entry, dns_catz_entry_t **entryp);
* Attach an entry * Attach an entry
* *
* Requires: * Requires:
* \li entry is not NULL * \li 'entry' is a valid dns_catz_entry_t.
* \li entryp is not NULL, *entryp is NULL * \li 'entryp' is not NULL and '*entryp' is NULL.
*/ */
void void
@@ -175,8 +175,8 @@ dns_catz_entry_detach(dns_catz_zone_t *zone, dns_catz_entry_t **entryp);
* Detach an entry, free if no further references * Detach an entry, free if no further references
* *
* Requires: * Requires:
* \li zone is not NULL * \li 'zone' is a valid dns_catz_zone_t.
* \li entryp is not NULL, *entryp is not NULL * \li 'entryp' is not NULL and '*entryp' is not NULL.
*/ */
bool bool
@@ -184,6 +184,9 @@ dns_catz_entry_validate(const dns_catz_entry_t *entry);
/*%< /*%<
* Validate whether entry is correct. * Validate whether entry is correct.
* (NOT YET IMPLEMENTED: always returns true) * (NOT YET IMPLEMENTED: always returns true)
*
* Requires:
*\li 'entry' is a valid dns_catz_entry_t.
*/ */
bool bool
@@ -192,12 +195,12 @@ dns_catz_entry_cmp(const dns_catz_entry_t *ea, const dns_catz_entry_t *eb);
* Deep compare two entries * Deep compare two entries
* *
* Requires: * Requires:
* \li ea is not NULL * \li 'ea' is a valid dns_catz_entry_t.
* \li eb is not NULL * \li 'eb' is a valid dns_catz_entry_t.
* *
* Returns: * Returns:
* \li true if entries are the same * \li 'true' if entries are the same.
* \li false if the entries differ * \li 'false' if the entries differ.
*/ */
void void
@@ -206,8 +209,8 @@ dns_catz_zone_attach(dns_catz_zone_t *zone, dns_catz_zone_t **zonep);
* Attach a catzone * Attach a catzone
* *
* Requires: * Requires:
* \li zone is not NULL * \li 'zone' is a valid dns_catz_zone_t.
* \li zonep is not NULL, *zonep is NULL * \li 'zonep' is not NULL and '*zonep' is NULL.
*/ */
void void
@@ -216,7 +219,7 @@ dns_catz_zone_detach(dns_catz_zone_t** zonep);
* Detach a zone, free if no further references * Detach a zone, free if no further references
* *
* Requires: * Requires:
* \li zonep is not NULL, *zonep is not NULL * \li 'zonep' is not NULL and '*zonep' is not NULL.
*/ */
isc_result_t isc_result_t
@@ -226,9 +229,9 @@ dns_catz_new_zone(dns_catz_zones_t *catzs, dns_catz_zone_t **zonep,
* Allocate a new catz zone on catzs mctx * Allocate a new catz zone on catzs mctx
* *
* Requires: * Requires:
* \li catzs is not NULL * \li 'catzs' is a valid dns_catz_zones_t.
* \li zonep is not NULL, *zonep is NULL * \li 'zonep' is not NULL and '*zonep' is NULL.
* \li name is not NULL * \li 'name' is a valid dns_name_t.
* *
*/ */
@@ -238,7 +241,7 @@ dns_catz_zone_getname(dns_catz_zone_t *zone);
* Get catalog zone name * Get catalog zone name
* *
* Requires: * Requires:
* \li zone is not NULL * \li 'zone' is a valid dns_catz_zone_t.
*/ */
dns_catz_options_t * dns_catz_options_t *
@@ -247,7 +250,7 @@ dns_catz_zone_getdefoptions(dns_catz_zone_t *zone);
* Get default member zone options for catalog zone 'zone' * Get default member zone options for catalog zone 'zone'
* *
* Requires: * Requires:
* \li zone is not NULL * \li 'zone' is a valid dns_catz_zone_t.
*/ */
void void
@@ -257,7 +260,7 @@ dns_catz_zone_resetdefoptions(dns_catz_zone_t *zone);
* the default values. * the default values.
* *
* Requires: * Requires:
* \li zone is not NULL * \li 'zone' is a valid dns_catz_zone_t.
*/ */
isc_result_t isc_result_t
@@ -267,8 +270,8 @@ dns_catz_zones_merge(dns_catz_zone_t *target, dns_catz_zone_t *newzone);
* (from zone->catzs->zmm) for appropriate member zones. * (from zone->catzs->zmm) for appropriate member zones.
* *
* Requires: * Requires:
* \li orig is not NULL * \li 'orig' is a valid dns_catz_zone_t.
* \li newzone is not NULL, *newzone is not NULL * \li 'newzone' is not NULL and '*newzone' is not NULL.
* *
*/ */
@@ -280,10 +283,10 @@ dns_catz_update_process(dns_catz_zones_t *catzs, dns_catz_zone_t *zone,
* record name. * record name.
* *
* Requires: * Requires:
* \li catzs is not NULL * \li 'catzs' is a valid dns_catz_zones_t.
* \li zone is not NULL * \li 'zone' is a valid dns_catz_zone_t.
* \li src_name is not NULL * \li 'src_name' is a valid dns_name_t.
* \li rdataset is valid * \li 'rdataset' is valid rdataset.
*/ */
isc_result_t isc_result_t
@@ -297,9 +300,9 @@ dns_catz_generate_masterfilename(dns_catz_zone_t *zone, dns_catz_entry_t *entry,
* __catz__unique_hash_generated_from_the_above.db * __catz__unique_hash_generated_from_the_above.db
* *
* Requires: * Requires:
* \li zone is not NULL * \li 'zone' is a valid dns_catz_zone_t.
* \li entry is not NULL * \li 'entry' is a valid dns_catz_entry_t.
* \li buffer is not NULL and *buffer is not NULL * \li 'buffer' is not NULL and '*buffer' is not NULL.
*/ */
isc_result_t isc_result_t
@@ -310,10 +313,9 @@ dns_catz_generate_zonecfg(dns_catz_zone_t *zone, dns_catz_entry_t *entry,
* it into *buf. buf might be reallocated. * it into *buf. buf might be reallocated.
* *
* Requires: * Requires:
* \li zone is not NULL * \li 'zone' is a valid dns_catz_zone_t.
* \li entry is not NULL * \li 'entry' is a valid dns_catz_entry_t.
* \li buf is not NULL * \li 'buf' is not NULL and '*buf' is NULL.
* \li *buf is NULL
* *
*/ */
@@ -340,8 +342,8 @@ dns_catz_new_zones(dns_catz_zones_t **catzsp, dns_catz_zonemodmethods_t *zmm,
* for a view. * for a view.
* *
* Requires: * Requires:
* \li catzsp is not NULL, *catzsp is NULL * \li 'catzsp' is not NULL and '*catzsp' is NULL.
* \li zmm is not NULL * \li 'zmm' is not NULL.
* *
*/ */
@@ -352,9 +354,9 @@ dns_catz_add_zone(dns_catz_zones_t *catzs, const dns_name_t *name,
* Allocate a new catz named 'name' and put it in 'catzs' collection. * Allocate a new catz named 'name' and put it in 'catzs' collection.
* *
* Requires: * Requires:
* \li catzs is not NULL * \li 'catzs' is a valid dns_catz_zones_t.
* \li name is not NULL * \li 'name' is a valid dns_name_t.
* \li zonep is not NULL, *zonep is NULL * \li 'zonep' is not NULL and *zonep is NULL.
* *
*/ */
@@ -364,37 +366,37 @@ dns_catz_get_zone(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'
* *
* Requires: * Requires:
* \li catzs is not NULL * \li 'catzs' is a valid dns_catz_zones_t.
* \li name is not NULL * \li 'name' is a valid dns_name_t.
*/ */
void void
dns_catz_catzs_attach(dns_catz_zones_t *catzs, dns_catz_zones_t **catzsp); dns_catz_catzs_attach(dns_catz_zones_t *catzs, dns_catz_zones_t **catzsp);
/*%< /*%<
* Attach 'catzs' to 'catzsp' * Attach 'catzs' to 'catzsp'.
* *
* Requires: * Requires:
* \li catzs is not NULL * \li 'catzs' is a valid dns_catz_zones_t.
* \li catzsp is not NULL, *catzsp is NULL * \li 'catzsp' is not NULL and *catzsp is NULL.
*/ */
void void
dns_catz_catzs_detach(dns_catz_zones_t **catzsp); dns_catz_catzs_detach(dns_catz_zones_t **catzsp);
/*%< /*%<
* Detach 'catzsp', free if no further references * Detach 'catzsp', free if no further references.
* *
* Requires: * Requires:
* \li catzsp is not NULL, *catzsp is not NULL * \li 'catzsp' is not NULL and *catzsp is not NULL.
*/ */
void void
dns_catz_catzs_set_view(dns_catz_zones_t *catzs, dns_view_t *view); dns_catz_catzs_set_view(dns_catz_zones_t *catzs, dns_view_t *view);
/*%< /*%<
* Set a view for catzs * Set a view for 'catzs'.
* *
* Requires: * Requires:
* \li catzs is not NULL * \li 'catzs' is a valid dns_catz_zones_t.
* \li catzs->view is NULL or catzs->view == view * \li 'catzs->view' is NULL or 'catzs->view' == 'view'.
*/ */
@@ -409,17 +411,17 @@ dns_catz_dbupdate_callback(dns_db_t *db, void *fn_arg);
* If there is an update scheduled it replaces old db version with a new one. * If there is an update scheduled it replaces old db version with a new one.
* *
* Requires: * Requires:
* \li db is a valid database * \li 'db' is a valid database.
* \li fn_arg is not NULL (casted to dns_catz_zones_t*) * \li 'fn_arg' is not NULL (casted to dns_catz_zones_t*).
*/ */
void void
dns_catz_update_taskaction(isc_task_t *task, isc_event_t *event); dns_catz_update_taskaction(isc_task_t *task, isc_event_t *event);
/*%< /*%<
* Task that launches dns_catz_update_from_db * Task that launches dns_catz_update_from_db.
* *
* Requires: * Requires:
* \li event is not NULL * \li 'event' is not NULL.
*/ */
void void
@@ -430,8 +432,8 @@ dns_catz_update_from_db(dns_db_t *db, dns_catz_zones_t *catzs);
* then merges new catz into old catz. * then merges new catz into old catz.
* *
* Requires: * Requires:
* \li db is a valid DB * \li 'db' is a valid DB.
* \li catzs is not NULL * \li 'catzs' is a valid dns_catz_zones_t.
* *
*/ */
@@ -441,7 +443,7 @@ dns_catz_prereconfig(dns_catz_zones_t *catzs);
* Called before reconfig, clears 'active' flag on all the zones in set * Called before reconfig, clears 'active' flag on all the zones in set
* *
* Requires: * Requires:
* \li catzs is not NULL * \li 'catzs' is a valid dns_catz_zones_t.
* *
*/ */
@@ -452,7 +454,7 @@ dns_catz_postreconfig(dns_catz_zones_t *catzs);
* inactive and force reload of those with changed configuration. * inactive and force reload of those with changed configuration.
* *
* Requires: * Requires:
* \li catzs is not NULL * \li 'catzs' is a valid dns_catz_zones_t.
*/ */
isc_result_t isc_result_t
@@ -460,6 +462,10 @@ dns_catz_get_iterator(dns_catz_zone_t *catz, isc_ht_iter_t **itp);
/*%< /*%<
* Get the hashtable iterator on catalog zone members, point '*itp' to it. * 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.
*
* Returns: * Returns:
* \li #ISC_R_SUCCESS -- success * \li #ISC_R_SUCCESS -- success
* \li Any other value -- failure * \li Any other value -- failure

View File

@@ -1779,7 +1779,7 @@ finish_update(dns_rpz_zone_t *rpz) {
result = isc_ht_iter_delcurrent_next(iter)) result = isc_ht_iter_delcurrent_next(iter))
{ {
isc_region_t region; isc_region_t region;
unsigned char *key; unsigned char *key = NULL;
size_t keysize; size_t keysize;
isc_ht_iter_currentkey(iter, &key, &keysize); isc_ht_iter_currentkey(iter, &key, &keysize);

View File

@@ -162,6 +162,7 @@ isc_ht_find(const isc_ht_t *ht, const unsigned char *key,
REQUIRE(ISC_HT_VALID(ht)); REQUIRE(ISC_HT_VALID(ht));
REQUIRE(key != NULL && keysize > 0); REQUIRE(key != NULL && keysize > 0);
REQUIRE(valuep == NULL || *valuep == NULL);
hash = isc_hash_function(key, keysize, true, NULL); hash = isc_hash_function(key, keysize, true, NULL);
node = ht->table[hash & ht->mask]; node = ht->table[hash & ht->mask];
@@ -327,6 +328,8 @@ void
isc_ht_iter_current(isc_ht_iter_t *it, void **valuep) { isc_ht_iter_current(isc_ht_iter_t *it, void **valuep) {
REQUIRE(it != NULL); REQUIRE(it != NULL);
REQUIRE(it->cur != NULL); REQUIRE(it->cur != NULL);
REQUIRE(valuep != NULL && *valuep == NULL);
*valuep = it->cur->value; *valuep = it->cur->value;
} }
@@ -335,6 +338,8 @@ isc_ht_iter_currentkey(isc_ht_iter_t *it, unsigned char **key, size_t *keysize)
{ {
REQUIRE(it != NULL); REQUIRE(it != NULL);
REQUIRE(it->cur != NULL); REQUIRE(it->cur != NULL);
REQUIRE(key != NULL && *key == NULL);
*key = it->cur->key; *key = it->cur->key;
*keysize = it->cur->keysize; *keysize = it->cur->keysize;
} }

View File

@@ -27,10 +27,9 @@ typedef struct isc_ht_iter isc_ht_iter_t;
* Initialize hashtable at *htp, using memory context and size of (1<<bits) * Initialize hashtable at *htp, using memory context and size of (1<<bits)
* *
* Requires: * Requires:
*\li htp is not NULL *\li 'htp' is not NULL and '*htp' is NULL.
*\li *htp is NULL *\li 'mctx' is a valid memory context.
*\li mctx is a valid memory context *\li 'bits' >=1 and 'bits' <=32
*\li bits >=1 && bits <=32
* *
* Returns: * Returns:
*\li #ISC_R_NOMEMORY -- not enough memory to create pool *\li #ISC_R_NOMEMORY -- not enough memory to create pool
@@ -43,7 +42,7 @@ isc_ht_init(isc_ht_t **htp, isc_mem_t *mctx, uint8_t bits);
* Destroy hashtable, freeing everything * Destroy hashtable, freeing everything
* *
* Requires: * Requires:
* \li *htp is valid hashtable * \li '*htp' is valid hashtable
*/ */
void void
isc_ht_destroy(isc_ht_t **htp); isc_ht_destroy(isc_ht_t **htp);
@@ -53,7 +52,7 @@ isc_ht_destroy(isc_ht_t **htp);
* set its value to 'value' * set its value to 'value'
* *
* Requires: * Requires:
*\li ht is a valid hashtable *\li 'ht' is a valid hashtable
* *
* Returns: * Returns:
*\li #ISC_R_NOMEMORY -- not enough memory to create pool *\li #ISC_R_NOMEMORY -- not enough memory to create pool
@@ -83,6 +82,7 @@ isc_ht_find(const isc_ht_t *ht, const unsigned char *key,
/*% /*%
* Delete node from hashtable * Delete node from hashtable
*
* Requires: * Requires:
*\li ht is a valid hashtable *\li ht is a valid hashtable
* *
@@ -95,12 +95,19 @@ isc_ht_delete(isc_ht_t *ht, const unsigned char *key, uint32_t keysize);
/*% /*%
* Create an iterator for the hashtable; point '*itp' to it. * Create an iterator for the hashtable; point '*itp' to it.
*
* Requires:
*\li 'ht' is a valid hashtable
*\li 'itp' is non NULL and '*itp' is NULL.
*/ */
isc_result_t isc_result_t
isc_ht_iter_create(isc_ht_t *ht, isc_ht_iter_t **itp); isc_ht_iter_create(isc_ht_t *ht, isc_ht_iter_t **itp);
/*% /*%
* Destroy the iterator '*itp', set it to NULL * Destroy the iterator '*itp', set it to NULL
*
* Requires:
*\li 'itp' is non NULL and '*itp' is non NULL.
*/ */
void void
isc_ht_iter_destroy(isc_ht_iter_t **itp); isc_ht_iter_destroy(isc_ht_iter_t **itp);
@@ -108,6 +115,9 @@ isc_ht_iter_destroy(isc_ht_iter_t **itp);
/*% /*%
* Set an iterator to the first entry. * Set an iterator to the first entry.
* *
* Requires:
*\li 'it' is non NULL.
*
* Returns: * Returns:
* \li #ISC_R_SUCCESS -- success * \li #ISC_R_SUCCESS -- success
* \li #ISC_R_NOMORE -- no data in the hashtable * \li #ISC_R_NOMORE -- no data in the hashtable
@@ -118,6 +128,9 @@ isc_ht_iter_first(isc_ht_iter_t *it);
/*% /*%
* Set an iterator to the next entry. * Set an iterator to the next entry.
* *
* Requires:
*\li 'it' is non NULL.
*
* Returns: * Returns:
* \li #ISC_R_SUCCESS -- success * \li #ISC_R_SUCCESS -- success
* \li #ISC_R_NOMORE -- end of hashtable reached * \li #ISC_R_NOMORE -- end of hashtable reached
@@ -128,6 +141,9 @@ isc_ht_iter_next(isc_ht_iter_t *it);
/*% /*%
* Delete current entry and set an iterator to the next entry. * Delete current entry and set an iterator to the next entry.
* *
* Requires:
*\li 'it' is non NULL.
*
* Returns: * Returns:
* \li #ISC_R_SUCCESS -- success * \li #ISC_R_SUCCESS -- success
* \li #ISC_R_NOMORE -- end of hashtable reached * \li #ISC_R_NOMORE -- end of hashtable reached
@@ -138,6 +154,10 @@ isc_ht_iter_delcurrent_next(isc_ht_iter_t *it);
/*% /*%
* Set 'value' to the current value under the iterator * Set 'value' to the current value under the iterator
*
* Requires:
*\li 'it' is non NULL.
*\li 'valuep' is non NULL and '*valuep' is NULL.
*/ */
void void
isc_ht_iter_current(isc_ht_iter_t *it, void **valuep); isc_ht_iter_current(isc_ht_iter_t *it, void **valuep);
@@ -145,6 +165,11 @@ isc_ht_iter_current(isc_ht_iter_t *it, void **valuep);
/*% /*%
* Set 'key' and 'keysize to the current key and keysize for the value * Set 'key' and 'keysize to the current key and keysize for the value
* under the iterator * under the iterator
*
* Requires:
*\li 'it' is non NULL.
*\li 'key' is non NULL and '*key' is NULL.
*\li 'keysize' is non NULL.
*/ */
void void
isc_ht_iter_currentkey(isc_ht_iter_t *it, unsigned char **key, size_t *keysize); isc_ht_iter_currentkey(isc_ht_iter_t *it, unsigned char **key, size_t *keysize);

View File

@@ -203,11 +203,9 @@ test_ht_iterator() {
isc_mem_t *mctx = NULL; isc_mem_t *mctx = NULL;
isc_ht_iter_t * iter = NULL; isc_ht_iter_t * iter = NULL;
uintptr_t i; uintptr_t i;
void *v;
uintptr_t count = 10000; uintptr_t count = 10000;
uint32_t walked; uint32_t walked;
unsigned char key[16]; unsigned char key[16];
unsigned char *tkey;
size_t tksize; size_t tksize;
result = isc_mem_createx(0, 0, default_memalloc, default_memfree, result = isc_mem_createx(0, 0, default_memalloc, default_memfree,
@@ -236,6 +234,9 @@ test_ht_iterator() {
result == ISC_R_SUCCESS; result == ISC_R_SUCCESS;
result = isc_ht_iter_next(iter)) result = isc_ht_iter_next(iter))
{ {
unsigned char *tkey = NULL;
void *v = NULL;
isc_ht_iter_current(iter, &v); isc_ht_iter_current(iter, &v);
isc_ht_iter_currentkey(iter, &tkey, &tksize); isc_ht_iter_currentkey(iter, &tkey, &tksize);
assert_int_equal(tksize, 16); assert_int_equal(tksize, 16);
@@ -252,6 +253,9 @@ test_ht_iterator() {
walked = 0; walked = 0;
result = isc_ht_iter_first(iter); result = isc_ht_iter_first(iter);
while (result == ISC_R_SUCCESS) { while (result == ISC_R_SUCCESS) {
unsigned char *tkey = NULL;
void *v = NULL;
isc_ht_iter_current(iter, &v); isc_ht_iter_current(iter, &v);
isc_ht_iter_currentkey(iter, &tkey, &tksize); isc_ht_iter_currentkey(iter, &tkey, &tksize);
assert_int_equal(tksize, 16); assert_int_equal(tksize, 16);
@@ -273,6 +277,9 @@ test_ht_iterator() {
walked = 0; walked = 0;
result = isc_ht_iter_first(iter); result = isc_ht_iter_first(iter);
while (result == ISC_R_SUCCESS) { while (result == ISC_R_SUCCESS) {
unsigned char *tkey = NULL;
void *v = NULL;
isc_ht_iter_current(iter, &v); isc_ht_iter_current(iter, &v);
isc_ht_iter_currentkey(iter, &tkey, &tksize); isc_ht_iter_currentkey(iter, &tkey, &tksize);
assert_int_equal(tksize, 16); assert_int_equal(tksize, 16);