diff --git a/.clang-format b/.clang-format index 57e98f2453..ee6e784bbc 100644 --- a/.clang-format +++ b/.clang-format @@ -78,6 +78,6 @@ PenaltyBreakString: 80 PenaltyExcessCharacter: 100 Standard: Cpp11 ContinuationIndentWidth: 8 -ForEachMacros: [ 'cds_lfs_for_each', 'cds_lfs_for_each_safe', 'cds_list_for_each_entry_safe', 'ISC_LIST_FOREACH', 'ISC_LIST_FOREACH_SAFE', 'ISC_LIST_FOREACH_REV', 'ISC_LIST_FOREACH_REV_SAFE', 'MSG_SECTION_FOREACH', 'DNS_RDATASET_FOREACH', 'CFG_LIST_FOREACH' ] +ForEachMacros: [ 'cds_lfs_for_each', 'cds_lfs_for_each_safe', 'cds_list_for_each_entry_safe', 'ISC_LIST_FOREACH', 'ISC_LIST_FOREACH_SAFE', 'ISC_LIST_FOREACH_REV', 'ISC_LIST_FOREACH_REV_SAFE', 'MSG_SECTION_FOREACH', 'DNS_DBITERATOR_FOREACH', 'DNS_RDATASET_FOREACH', 'DNS_RDATASETITER_FOREACH', 'CFG_LIST_FOREACH' ] RemoveParentheses: ReturnStatement RemoveSemicolon: true diff --git a/bin/dnssec/dnssec-signzone.c b/bin/dnssec/dnssec-signzone.c index c9ea79dfea..c4b95dace9 100644 --- a/bin/dnssec/dnssec-signzone.c +++ b/bin/dnssec/dnssec-signzone.c @@ -199,7 +199,6 @@ savezonecut(dns_fixedname_t *fzonecut, dns_name_t *name) { static void dumpnode(dns_name_t *name, dns_dbnode_t *node) { - dns_rdataset_t rds; dns_rdatasetiter_t *iter = NULL; isc_buffer_t *buffer = NULL; isc_region_t r; @@ -213,13 +212,10 @@ dumpnode(dns_name_t *name, dns_dbnode_t *node) { result = dns_db_allrdatasets(gdb, node, gversion, 0, 0, &iter); check_result(result, "dns_db_allrdatasets"); - dns_rdataset_init(&rds); - isc_buffer_allocate(mctx, &buffer, bufsize); - for (result = dns_rdatasetiter_first(iter); result == ISC_R_SUCCESS; - result = dns_rdatasetiter_next(iter)) - { + DNS_RDATASETITER_FOREACH (iter) { + dns_rdataset_t rds = DNS_RDATASET_INIT; dns_rdatasetiter_current(iter, &rds); if (rds.type != dns_rdatatype_rrsig && @@ -1191,8 +1187,7 @@ signname(dns_dbnode_t *node, bool apex, dns_name_t *name) { rdsiter = NULL; result = dns_db_allrdatasets(gdb, node, gversion, 0, 0, &rdsiter); check_result(result, "dns_db_allrdatasets()"); - result = dns_rdatasetiter_first(rdsiter); - while (result == ISC_R_SUCCESS) { + DNS_RDATASETITER_FOREACH (rdsiter) { dns_rdatasetiter_current(rdsiter, &rdataset); /* If this is a RRSIG set, skip it. */ @@ -1226,11 +1221,6 @@ signname(dns_dbnode_t *node, bool apex, dns_name_t *name) { skip: dns_rdataset_disassociate(&rdataset); - result = dns_rdatasetiter_next(rdsiter); - } - if (result != ISC_R_NOMORE) { - fatal("rdataset iteration for name '%s' failed: %s", namestr, - isc_result_totext(result)); } dns_rdatasetiter_destroy(&rdsiter); @@ -1261,43 +1251,31 @@ active_node(dns_dbnode_t *node) { dns_rdatasetiter_t *rdsiter2 = NULL; bool active = false; isc_result_t result; - dns_rdataset_t rdataset; + dns_rdataset_t rdataset = DNS_RDATASET_INIT; dns_rdatatype_t type; dns_rdatatype_t covers; bool found; - dns_rdataset_init(&rdataset); result = dns_db_allrdatasets(gdb, node, gversion, 0, 0, &rdsiter); check_result(result, "dns_db_allrdatasets()"); - result = dns_rdatasetiter_first(rdsiter); - while (result == ISC_R_SUCCESS) { + DNS_RDATASETITER_FOREACH (rdsiter) { dns_rdatasetiter_current(rdsiter, &rdataset); - if (rdataset.type != dns_rdatatype_nsec && - rdataset.type != dns_rdatatype_nsec3 && - rdataset.type != dns_rdatatype_rrsig) + dns_rdatatype_t t = rdataset.type; + dns_rdataset_disassociate(&rdataset); + + if (t != dns_rdatatype_nsec && t != dns_rdatatype_nsec3 && + t != dns_rdatatype_rrsig) { active = true; + break; } - dns_rdataset_disassociate(&rdataset); - if (!active) { - result = dns_rdatasetiter_next(rdsiter); - } else { - result = ISC_R_NOMORE; - } - } - if (result != ISC_R_NOMORE) { - fatal("rdataset iteration failed: %s", - isc_result_totext(result)); } if (!active && nsec_datatype == dns_rdatatype_nsec) { /*% * The node is empty of everything but NSEC / RRSIG records. */ - for (result = dns_rdatasetiter_first(rdsiter); - result == ISC_R_SUCCESS; - result = dns_rdatasetiter_next(rdsiter)) - { + DNS_RDATASETITER_FOREACH (rdsiter) { dns_rdatasetiter_current(rdsiter, &rdataset); result = dns_db_deleterdataset(gdb, node, gversion, rdataset.type, @@ -1305,10 +1283,6 @@ active_node(dns_dbnode_t *node) { check_result(result, "dns_db_deleterdataset()"); dns_rdataset_disassociate(&rdataset); } - if (result != ISC_R_NOMORE) { - fatal("rdataset iteration failed: %s", - isc_result_totext(result)); - } } else { /* * Delete RRSIGs for types that no longer exist. @@ -1316,10 +1290,7 @@ active_node(dns_dbnode_t *node) { result = dns_db_allrdatasets(gdb, node, gversion, 0, 0, &rdsiter2); check_result(result, "dns_db_allrdatasets()"); - for (result = dns_rdatasetiter_first(rdsiter); - result == ISC_R_SUCCESS; - result = dns_rdatasetiter_next(rdsiter)) - { + DNS_RDATASETITER_FOREACH (rdsiter) { dns_rdatasetiter_current(rdsiter, &rdataset); type = rdataset.type; covers = rdataset.covers; @@ -1342,10 +1313,7 @@ active_node(dns_dbnode_t *node) { continue; } found = false; - for (result = dns_rdatasetiter_first(rdsiter2); - !found && result == ISC_R_SUCCESS; - result = dns_rdatasetiter_next(rdsiter2)) - { + DNS_RDATASETITER_FOREACH (rdsiter2) { dns_rdatasetiter_current(rdsiter2, &rdataset); if (rdataset.type == covers) { found = true; @@ -1353,25 +1321,15 @@ active_node(dns_dbnode_t *node) { dns_rdataset_disassociate(&rdataset); } if (!found) { - if (result != ISC_R_NOMORE) { - fatal("rdataset iteration failed: %s", - isc_result_totext(result)); - } result = dns_db_deleterdataset( gdb, node, gversion, type, covers); check_result(result, "dns_db_deleterdataset(" "rrsig)"); - } else if (result != ISC_R_NOMORE && - result != ISC_R_SUCCESS) - { + } else if (result != ISC_R_SUCCESS) { fatal("rdataset iteration failed: %s", isc_result_totext(result)); } } - if (result != ISC_R_NOMORE) { - fatal("rdataset iteration failed: %s", - isc_result_totext(result)); - } dns_rdatasetiter_destroy(&rdsiter2); } dns_rdatasetiter_destroy(&rdsiter); @@ -1725,18 +1683,14 @@ remove_records(dns_dbnode_t *node, dns_rdatatype_t which, bool checknsec) { isc_result_t result; dns_rdatatype_t type, covers; dns_rdatasetiter_t *rdsiter = NULL; - dns_rdataset_t rdataset; - - dns_rdataset_init(&rdataset); /* * Delete any records of the given type at the apex. */ result = dns_db_allrdatasets(gdb, node, gversion, 0, 0, &rdsiter); check_result(result, "dns_db_allrdatasets()"); - for (result = dns_rdatasetiter_first(rdsiter); result == ISC_R_SUCCESS; - result = dns_rdatasetiter_next(rdsiter)) - { + DNS_RDATASETITER_FOREACH (rdsiter) { + dns_rdataset_t rdataset = DNS_RDATASET_INIT; dns_rdatasetiter_current(rdsiter, &rdataset); type = rdataset.type; covers = rdataset.covers; @@ -1772,14 +1726,11 @@ remove_sigs(dns_dbnode_t *node, bool delegation, dns_rdatatype_t which) { isc_result_t result; dns_rdatatype_t type, covers; dns_rdatasetiter_t *rdsiter = NULL; - dns_rdataset_t rdataset; - dns_rdataset_init(&rdataset); result = dns_db_allrdatasets(gdb, node, gversion, 0, 0, &rdsiter); check_result(result, "dns_db_allrdatasets()"); - for (result = dns_rdatasetiter_first(rdsiter); result == ISC_R_SUCCESS; - result = dns_rdatasetiter_next(rdsiter)) - { + DNS_RDATASETITER_FOREACH (rdsiter) { + dns_rdataset_t rdataset = DNS_RDATASET_INIT; dns_rdatasetiter_current(rdsiter, &rdataset); type = rdataset.type; covers = rdataset.covers; @@ -1816,36 +1767,28 @@ nsecify(void) { dns_dbiterator_t *dbiter = NULL; dns_dbnode_t *node = NULL, *nextnode = NULL; dns_fixedname_t fname, fnextname, fzonecut; - dns_name_t *name, *nextname, *zonecut; - dns_rdataset_t rdataset; + dns_name_t *name = dns_fixedname_initname(&fname); + dns_name_t *nextname = dns_fixedname_initname(&fnextname); + dns_name_t *zonecut = NULL; dns_rdatasetiter_t *rdsiter = NULL; dns_rdatatype_t type, covers; bool done = false; isc_result_t result; uint32_t nsttl = 0; - dns_rdataset_init(&rdataset); - name = dns_fixedname_initname(&fname); - nextname = dns_fixedname_initname(&fnextname); - zonecut = NULL; - /* * Remove any NSEC3 chains. */ result = dns_db_createiterator(gdb, DNS_DB_NSEC3ONLY, &dbiter); check_result(result, "dns_db_createiterator()"); - for (result = dns_dbiterator_first(dbiter); result == ISC_R_SUCCESS; - result = dns_dbiterator_next(dbiter)) - { + DNS_DBITERATOR_FOREACH (dbiter) { + dns_rdataset_t rdataset = DNS_RDATASET_INIT; result = dns_dbiterator_current(dbiter, &node, name); check_dns_dbiterator_current(result); result = dns_db_allrdatasets(gdb, node, gversion, 0, 0, &rdsiter); check_result(result, "dns_db_allrdatasets()"); - for (result = dns_rdatasetiter_first(rdsiter); - result == ISC_R_SUCCESS; - result = dns_rdatasetiter_next(rdsiter)) - { + DNS_RDATASETITER_FOREACH (rdsiter) { dns_rdatasetiter_current(rdsiter, &rdataset); type = rdataset.type; covers = rdataset.covers; @@ -2221,43 +2164,30 @@ cleanup_zone(void) { dns_rdatasetiter_t *rdsiter = NULL; dns_diff_t add, del; dns_dbnode_t *node = NULL; - dns_rdataset_t rdataset; dns_fixedname_t fname; - dns_name_t *name; + dns_name_t *name = dns_fixedname_initname(&fname); dns_diff_init(mctx, &add); dns_diff_init(mctx, &del); - name = dns_fixedname_initname(&fname); - dns_rdataset_init(&rdataset); result = dns_db_createiterator(gdb, 0, &dbiter); check_result(result, "dns_db_createiterator()"); - for (result = dns_dbiterator_first(dbiter); result == ISC_R_SUCCESS; - result = dns_dbiterator_next(dbiter)) - { + DNS_DBITERATOR_FOREACH (dbiter) { + dns_rdataset_t rdataset = DNS_RDATASET_INIT; result = dns_dbiterator_current(dbiter, &node, name); check_dns_dbiterator_current(result); result = dns_db_allrdatasets(gdb, node, gversion, 0, 0, &rdsiter); check_result(result, "dns_db_allrdatasets()"); - for (result = dns_rdatasetiter_first(rdsiter); - result == ISC_R_SUCCESS; - result = dns_rdatasetiter_next(rdsiter)) - { + DNS_RDATASETITER_FOREACH (rdsiter) { dns_rdatasetiter_current(rdsiter, &rdataset); rrset_cleanup(name, &rdataset, &add, &del); dns_rdataset_disassociate(&rdataset); } - if (result != ISC_R_NOMORE) { - fatal("rdatasets iteration failed."); - } dns_rdatasetiter_destroy(&rdsiter); dns_db_detachnode(gdb, &node); } - if (result != ISC_R_NOMORE) { - fatal("zone iteration failed."); - } result = dns_diff_applysilently(&del, gdb, gversion); check_result(result, "dns_diff_applysilently"); @@ -2432,9 +2362,7 @@ nsec3ify(unsigned int hashalg, dns_iterations_t iterations, result = dns_db_createiterator(gdb, DNS_DB_NSEC3ONLY, &dbiter); check_result(result, "dns_db_createiterator()"); - for (result = dns_dbiterator_first(dbiter); result == ISC_R_SUCCESS; - result = dns_dbiterator_next(dbiter)) - { + DNS_DBITERATOR_FOREACH (dbiter) { result = dns_dbiterator_current(dbiter, &node, name); check_dns_dbiterator_current(result); nsec3clean(name, node, hashalg, iterations, salt, salt_len, diff --git a/lib/dns/cache.c b/lib/dns/cache.c index f0f204e650..d43865e98f 100644 --- a/lib/dns/cache.c +++ b/lib/dns/cache.c @@ -377,11 +377,8 @@ clearnode(dns_db_t *db, dns_dbnode_t *node) { return result; } - for (result = dns_rdatasetiter_first(iter); result == ISC_R_SUCCESS; - result = dns_rdatasetiter_next(iter)) - { - dns_rdataset_t rdataset; - dns_rdataset_init(&rdataset); + DNS_RDATASETITER_FOREACH (iter) { + dns_rdataset_t rdataset = DNS_RDATASET_INIT; dns_rdatasetiter_current(iter, &rdataset); result = dns_db_deleterdataset(db, node, NULL, rdataset.type, @@ -392,10 +389,6 @@ clearnode(dns_db_t *db, dns_dbnode_t *node) { } } - if (result == ISC_R_NOMORE) { - result = ISC_R_SUCCESS; - } - dns_rdatasetiter_destroy(&iter); return result; } diff --git a/lib/dns/catz.c b/lib/dns/catz.c index f6c6bc51ce..6a83146f26 100644 --- a/lib/dns/catz.c +++ b/lib/dns/catz.c @@ -2384,8 +2384,7 @@ dns__catz_update_cb(void *data) { } dns_rdataset_init(&rdataset); - result = dns_rdatasetiter_first(rdsiter); - while (result == ISC_R_SUCCESS) { + DNS_RDATASETITER_FOREACH (rdsiter) { dns_rdatasetiter_current(rdsiter, &rdataset); /* @@ -2395,7 +2394,8 @@ dns__catz_update_cb(void *data) { * and produce an unnecessary warning message. */ if (!catz_rdatatype_is_processable(rdataset.type)) { - goto next; + dns_rdataset_disassociate(&rdataset); + continue; } /* @@ -2427,9 +2427,8 @@ dns__catz_update_cb(void *data) { cname, classbuf, typebuf, isc_result_totext(result)); } - next: + dns_rdataset_disassociate(&rdataset); - result = dns_rdatasetiter_next(rdsiter); } dns_rdatasetiter_destroy(&rdsiter); diff --git a/lib/dns/dbiterator.c b/lib/dns/dbiterator.c index 8f202871a6..626e4c4543 100644 --- a/lib/dns/dbiterator.c +++ b/lib/dns/dbiterator.c @@ -22,10 +22,6 @@ void dns__dbiterator_destroy(dns_dbiterator_t **iteratorp DNS__DB_FLARG) { - /* - * Destroy '*iteratorp'. - */ - REQUIRE(iteratorp != NULL); REQUIRE(DNS_DBITERATOR_VALID(*iteratorp)); @@ -36,33 +32,27 @@ dns__dbiterator_destroy(dns_dbiterator_t **iteratorp DNS__DB_FLARG) { isc_result_t dns__dbiterator_first(dns_dbiterator_t *iterator DNS__DB_FLARG) { - /* - * Move the node cursor to the first node in the database (if any). - */ - REQUIRE(DNS_DBITERATOR_VALID(iterator)); - return iterator->methods->first(iterator DNS__DB_FLARG_PASS); + isc_result_t result = + iterator->methods->first(iterator DNS__DB_FLARG_PASS); + ENSURE(result == ISC_R_SUCCESS || result == ISC_R_NOMORE); + return result; } isc_result_t dns__dbiterator_last(dns_dbiterator_t *iterator DNS__DB_FLARG) { - /* - * Move the node cursor to the first node in the database (if any). - */ - REQUIRE(DNS_DBITERATOR_VALID(iterator)); - return iterator->methods->last(iterator DNS__DB_FLARG_PASS); + isc_result_t result = + iterator->methods->last(iterator DNS__DB_FLARG_PASS); + ENSURE(result == ISC_R_SUCCESS || result == ISC_R_NOMORE); + return result; } isc_result_t dns__dbiterator_seek(dns_dbiterator_t *iterator, const dns_name_t *name DNS__DB_FLARG) { - /* - * Move the node cursor to the node with name 'name'. - */ - REQUIRE(DNS_DBITERATOR_VALID(iterator)); return iterator->methods->seek(iterator, name DNS__DB_FLARG_PASS); @@ -70,33 +60,27 @@ dns__dbiterator_seek(dns_dbiterator_t *iterator, isc_result_t dns__dbiterator_prev(dns_dbiterator_t *iterator DNS__DB_FLARG) { - /* - * Move the node cursor to the previous node in the database (if any). - */ - REQUIRE(DNS_DBITERATOR_VALID(iterator)); - return iterator->methods->prev(iterator DNS__DB_FLARG_PASS); + isc_result_t result = + iterator->methods->prev(iterator DNS__DB_FLARG_PASS); + ENSURE(result == ISC_R_SUCCESS || result == ISC_R_NOMORE); + return result; } isc_result_t dns__dbiterator_next(dns_dbiterator_t *iterator DNS__DB_FLARG) { - /* - * Move the node cursor to the next node in the database (if any). - */ - REQUIRE(DNS_DBITERATOR_VALID(iterator)); - return iterator->methods->next(iterator DNS__DB_FLARG_PASS); + isc_result_t result = + iterator->methods->next(iterator DNS__DB_FLARG_PASS); + ENSURE(result == ISC_R_SUCCESS || result == ISC_R_NOMORE); + return result; } isc_result_t dns__dbiterator_current(dns_dbiterator_t *iterator, dns_dbnode_t **nodep, dns_name_t *name DNS__DB_FLARG) { - /* - * Return the current node. - */ - REQUIRE(DNS_DBITERATOR_VALID(iterator)); REQUIRE(nodep != NULL && *nodep == NULL); REQUIRE(name == NULL || dns_name_hasbuffer(name)); @@ -107,10 +91,6 @@ dns__dbiterator_current(dns_dbiterator_t *iterator, dns_dbnode_t **nodep, isc_result_t dns_dbiterator_pause(dns_dbiterator_t *iterator) { - /* - * Pause iteration. - */ - REQUIRE(DNS_DBITERATOR_VALID(iterator)); return iterator->methods->pause(iterator); @@ -118,10 +98,6 @@ dns_dbiterator_pause(dns_dbiterator_t *iterator) { isc_result_t dns_dbiterator_origin(dns_dbiterator_t *iterator, dns_name_t *name) { - /* - * Return the origin to which returned node names are relative. - */ - REQUIRE(DNS_DBITERATOR_VALID(iterator)); REQUIRE(iterator->relative_names); REQUIRE(dns_name_hasbuffer(name)); diff --git a/lib/dns/include/dns/dbiterator.h b/lib/dns/include/dns/dbiterator.h index e97e9add0b..0371401cb2 100644 --- a/lib/dns/include/dns/dbiterator.h +++ b/lib/dns/include/dns/dbiterator.h @@ -99,6 +99,22 @@ struct dns_dbiterator { bool relative_names; }; +/* clang-format off */ +/* + * This is a hack to build a unique variable name to + * replace 'res' below. (Two layers of macro indirection are + * needed to make the line number be part of the variable + * name; otherwise it would just be "x__LINE__".) + */ +#define DNS__DBITERATOR_CONNECT(x,y) x##y +#define DNS__DBITERATOR_CONCAT(x,y) DNS__DBITERATOR_CONNECT(x,y) +#define DNS_DBITERATOR_FOREACH_RES(rds, res) \ + for (isc_result_t res = dns_dbiterator_first((rds)); \ + res == ISC_R_SUCCESS; res = dns_dbiterator_next((rds))) +#define DNS_DBITERATOR_FOREACH(rds) \ + DNS_DBITERATOR_FOREACH_RES(rds, DNS__DBITERATOR_CONCAT(x, __LINE__)) +/* clang-format on */ + #define dns_dbiterator_destroy(iteratorp) \ dns__dbiterator_destroy(iteratorp DNS__DB_FILELINE) void diff --git a/lib/dns/include/dns/rdatasetiter.h b/lib/dns/include/dns/rdatasetiter.h index a91c1ec416..e53f44dbf6 100644 --- a/lib/dns/include/dns/rdatasetiter.h +++ b/lib/dns/include/dns/rdatasetiter.h @@ -94,6 +94,22 @@ struct dns_rdatasetiter { unsigned int options; }; +/* clang-format off */ +/* + * This is a hack to build a unique variable name to + * replace 'res' below. (Two layers of macro indirection are + * needed to make the line number be part of the variable + * name; otherwise it would just be "x__LINE__".) + */ +#define DNS__RDATASETITER_CONNECT(x,y) x##y +#define DNS__RDATASETITER_CONCAT(x,y) DNS__RDATASETITER_CONNECT(x,y) +#define DNS_RDATASETITER_FOREACH_RES(rds, res) \ + for (isc_result_t res = dns_rdatasetiter_first((rds)); \ + res == ISC_R_SUCCESS; res = dns_rdatasetiter_next((rds))) +#define DNS_RDATASETITER_FOREACH(rds) \ + DNS_RDATASETITER_FOREACH_RES(rds, DNS__RDATASETITER_CONCAT(x, __LINE__)) +/* clang-format on */ + #define dns_rdatasetiter_destroy(iteratorp) \ dns__rdatasetiter_destroy(iteratorp DNS__DB_FILELINE) void diff --git a/lib/dns/journal.c b/lib/dns/journal.c index e7724ad74c..e68fc1f4dd 100644 --- a/lib/dns/journal.c +++ b/lib/dns/journal.c @@ -2140,11 +2140,8 @@ get_name_diff(dns_db_t *db, dns_dbversion_t *ver, isc_stdtime_t now, goto cleanup_node; } - for (result = dns_rdatasetiter_first(rdsiter); result == ISC_R_SUCCESS; - result = dns_rdatasetiter_next(rdsiter)) - { + DNS_RDATASETITER_FOREACH (rdsiter) { dns_rdataset_t rdataset = DNS_RDATASET_INIT; - dns_rdatasetiter_current(rdsiter, &rdataset); DNS_RDATASET_FOREACH (&rdataset) { @@ -2156,15 +2153,10 @@ get_name_diff(dns_db_t *db, dns_dbversion_t *ver, isc_stdtime_t now, } dns_rdataset_disassociate(&rdataset); } - if (result != ISC_R_NOMORE) { - goto cleanup_iterator; - } + dns_rdatasetiter_destroy(&rdsiter); result = ISC_R_SUCCESS; -cleanup_iterator: - dns_rdatasetiter_destroy(&rdsiter); - cleanup_node: dns_db_detachnode(db, &node); diff --git a/lib/dns/masterdump.c b/lib/dns/masterdump.c index 2787114f9f..0f0d680976 100644 --- a/lib/dns/masterdump.c +++ b/lib/dns/masterdump.c @@ -1312,17 +1312,13 @@ static isc_result_t dump_rdatasets_raw(isc_mem_t *mctx, const dns_name_t *owner_name, dns_rdatasetiter_t *rdsiter, dns_totext_ctx_t *ctx, isc_buffer_t *buffer, FILE *f) { - isc_result_t result; - dns_rdataset_t rdataset; + isc_result_t result = ISC_R_SUCCESS; dns_fixedname_t fixed; - dns_name_t *name; + dns_name_t *name = dns_fixedname_initname(&fixed); - name = dns_fixedname_initname(&fixed); dns_name_copy(owner_name, name); - for (result = dns_rdatasetiter_first(rdsiter); result == ISC_R_SUCCESS; - result = dns_rdatasetiter_next(rdsiter)) - { - dns_rdataset_init(&rdataset); + DNS_RDATASETITER_FOREACH (rdsiter) { + dns_rdataset_t rdataset = DNS_RDATASET_INIT; dns_rdatasetiter_current(rdsiter, &rdataset); dns_rdataset_getownercase(&rdataset, name); @@ -1341,10 +1337,6 @@ dump_rdatasets_raw(isc_mem_t *mctx, const dns_name_t *owner_name, } } - if (result == ISC_R_NOMORE) { - result = ISC_R_SUCCESS; - } - return result; } @@ -1716,12 +1708,7 @@ dumptostream(dns_dumpctx_t *dctx) { CHECK(writeheader(dctx)); - result = dns_dbiterator_first(dctx->dbiter); - if (result != ISC_R_SUCCESS && result != ISC_R_NOMORE) { - goto cleanup; - } - - while (result == ISC_R_SUCCESS) { + DNS_DBITERATOR_FOREACH (dctx->dbiter) { dns_rdatasetiter_t *rdsiter = NULL; dns_dbnode_t *node = NULL; @@ -1759,7 +1746,6 @@ dumptostream(dns_dumpctx_t *dctx) { goto cleanup; } dns_db_detachnode(dctx->db, &node); - result = dns_dbiterator_next(dctx->dbiter); } if (result == ISC_R_NOMORE) { diff --git a/lib/dns/nsec.c b/lib/dns/nsec.c index 12d85c42dd..8aeb1ed90e 100644 --- a/lib/dns/nsec.c +++ b/lib/dns/nsec.c @@ -96,10 +96,8 @@ dns_nsec_buildrdata(dns_db_t *db, dns_dbversion_t *version, dns_dbnode_t *node, const dns_name_t *target, unsigned char *buffer, dns_rdata_t *rdata) { isc_result_t result; - dns_rdataset_t rdataset; isc_region_t r; unsigned int i; - unsigned char *nsec_bits, *bm; unsigned int max_type; dns_rdatasetiter_t *rdsiter; @@ -119,15 +117,13 @@ dns_nsec_buildrdata(dns_db_t *db, dns_dbversion_t *version, dns_dbnode_t *node, dns_nsec_setbit(bm, dns_rdatatype_rrsig, 1); dns_nsec_setbit(bm, dns_rdatatype_nsec, 1); max_type = dns_rdatatype_nsec; - dns_rdataset_init(&rdataset); rdsiter = NULL; result = dns_db_allrdatasets(db, node, version, 0, 0, &rdsiter); if (result != ISC_R_SUCCESS) { return result; } - for (result = dns_rdatasetiter_first(rdsiter); result == ISC_R_SUCCESS; - result = dns_rdatasetiter_next(rdsiter)) - { + DNS_RDATASETITER_FOREACH (rdsiter) { + dns_rdataset_t rdataset = DNS_RDATASET_INIT; dns_rdatasetiter_current(rdsiter, &rdataset); if (rdataset.type != dns_rdatatype_nsec && rdataset.type != dns_rdatatype_nsec3 && @@ -140,6 +136,7 @@ dns_nsec_buildrdata(dns_db_t *db, dns_dbversion_t *version, dns_dbnode_t *node, } dns_rdataset_disassociate(&rdataset); } + dns_rdatasetiter_destroy(&rdsiter); /* * At zone cuts, deny the existence of glue in the parent zone. @@ -156,11 +153,6 @@ dns_nsec_buildrdata(dns_db_t *db, dns_dbversion_t *version, dns_dbnode_t *node, } } - dns_rdatasetiter_destroy(&rdsiter); - if (result != ISC_R_NOMORE) { - return result; - } - nsec_bits += dns_nsec_compressbitmap(nsec_bits, bm, max_type); r.length = (unsigned int)(nsec_bits - r.base); diff --git a/lib/dns/nsec3.c b/lib/dns/nsec3.c index 662c689ef2..e0fa980410 100644 --- a/lib/dns/nsec3.c +++ b/lib/dns/nsec3.c @@ -61,13 +61,11 @@ dns_nsec3_buildrdata(dns_db_t *db, dns_dbversion_t *version, dns_dbnode_t *node, size_t hash_length, unsigned char *buffer, dns_rdata_t *rdata) { isc_result_t result; - dns_rdataset_t rdataset; isc_region_t r; unsigned int i; bool found; bool found_ns; bool need_rrsig; - unsigned char *nsec_bits, *bm; unsigned int max_type; dns_rdatasetiter_t *rdsiter; @@ -116,16 +114,14 @@ dns_nsec3_buildrdata(dns_db_t *db, dns_dbversion_t *version, dns_dbnode_t *node, if (node == NULL) { goto collapse_bitmap; } - dns_rdataset_init(&rdataset); rdsiter = NULL; result = dns_db_allrdatasets(db, node, version, 0, 0, &rdsiter); if (result != ISC_R_SUCCESS) { return result; } found = found_ns = need_rrsig = false; - for (result = dns_rdatasetiter_first(rdsiter); result == ISC_R_SUCCESS; - result = dns_rdatasetiter_next(rdsiter)) - { + DNS_RDATASETITER_FOREACH (rdsiter) { + dns_rdataset_t rdataset = DNS_RDATASET_INIT; dns_rdatasetiter_current(rdsiter, &rdataset); if (rdataset.type != dns_rdatatype_nsec && rdataset.type != dns_rdatatype_nsec3 && @@ -156,6 +152,8 @@ dns_nsec3_buildrdata(dns_db_t *db, dns_dbversion_t *version, dns_dbnode_t *node, } dns_rdataset_disassociate(&rdataset); } + dns_rdatasetiter_destroy(&rdsiter); + if ((found && !found_ns) || need_rrsig) { if (dns_rdatatype_rrsig > max_type) { max_type = dns_rdatatype_rrsig; @@ -178,11 +176,6 @@ dns_nsec3_buildrdata(dns_db_t *db, dns_dbversion_t *version, dns_dbnode_t *node, } } - dns_rdatasetiter_destroy(&rdsiter); - if (result != ISC_R_NOMORE) { - return result; - } - collapse_bitmap: nsec_bits += dns_nsec_compressbitmap(nsec_bits, bm, max_type); r.length = (unsigned int)(nsec_bits - r.base); diff --git a/lib/dns/rdatasetiter.c b/lib/dns/rdatasetiter.c index 197de0ca26..fdf039d147 100644 --- a/lib/dns/rdatasetiter.c +++ b/lib/dns/rdatasetiter.c @@ -22,10 +22,6 @@ void dns__rdatasetiter_destroy(dns_rdatasetiter_t **iteratorp DNS__DB_FLARG) { - /* - * Destroy '*iteratorp'. - */ - REQUIRE(iteratorp != NULL); REQUIRE(DNS_RDATASETITER_VALID(*iteratorp)); @@ -36,33 +32,27 @@ dns__rdatasetiter_destroy(dns_rdatasetiter_t **iteratorp DNS__DB_FLARG) { isc_result_t dns__rdatasetiter_first(dns_rdatasetiter_t *iterator DNS__DB_FLARG) { - /* - * Move the rdataset cursor to the first rdataset at the node (if any). - */ - REQUIRE(DNS_RDATASETITER_VALID(iterator)); - return iterator->methods->first(iterator DNS__DB_FLARG_PASS); + isc_result_t result = + iterator->methods->first(iterator DNS__DB_FLARG_PASS); + ENSURE(result == ISC_R_SUCCESS || result == ISC_R_NOMORE); + return result; } isc_result_t dns__rdatasetiter_next(dns_rdatasetiter_t *iterator DNS__DB_FLARG) { - /* - * Move the rdataset cursor to the next rdataset at the node (if any). - */ - REQUIRE(DNS_RDATASETITER_VALID(iterator)); - return iterator->methods->next(iterator DNS__DB_FLARG_PASS); + isc_result_t result = + iterator->methods->next(iterator DNS__DB_FLARG_PASS); + ENSURE(result == ISC_R_SUCCESS || result == ISC_R_NOMORE); + return result; } void dns__rdatasetiter_current(dns_rdatasetiter_t *iterator, dns_rdataset_t *rdataset DNS__DB_FLARG) { - /* - * Return the current rdataset. - */ - REQUIRE(DNS_RDATASETITER_VALID(iterator)); REQUIRE(DNS_RDATASET_VALID(rdataset)); REQUIRE(!dns_rdataset_isassociated(rdataset)); diff --git a/lib/dns/rootns.c b/lib/dns/rootns.c index d78a000588..295f30cd80 100644 --- a/lib/dns/rootns.c +++ b/lib/dns/rootns.c @@ -125,41 +125,27 @@ in_rootns(dns_rdataset_t *rootns, dns_name_t *name) { static isc_result_t check_node(dns_rdataset_t *rootns, dns_name_t *name, dns_rdatasetiter_t *rdsiter) { - isc_result_t result; - dns_rdataset_t rdataset; - - dns_rdataset_init(&rdataset); - result = dns_rdatasetiter_first(rdsiter); - while (result == ISC_R_SUCCESS) { + DNS_RDATASETITER_FOREACH (rdsiter) { + dns_rdataset_t rdataset = DNS_RDATASET_INIT; dns_rdatasetiter_current(rdsiter, &rdataset); - switch (rdataset.type) { + dns_rdatatype_t type = rdataset.type; + dns_rdataset_disassociate(&rdataset); + + switch (type) { case dns_rdatatype_a: case dns_rdatatype_aaaa: - result = in_rootns(rootns, name); - if (result != ISC_R_SUCCESS) { - goto cleanup; - } - break; + return in_rootns(rootns, name); case dns_rdatatype_ns: if (dns_name_compare(name, dns_rootname) == 0) { - break; + return ISC_R_SUCCESS; } FALLTHROUGH; default: - result = ISC_R_FAILURE; - goto cleanup; + return ISC_R_FAILURE; } - dns_rdataset_disassociate(&rdataset); - result = dns_rdatasetiter_next(rdsiter); } - if (result == ISC_R_NOMORE) { - result = ISC_R_SUCCESS; - } -cleanup: - if (dns_rdataset_isassociated(&rdataset)) { - dns_rdataset_disassociate(&rdataset); - } - return result; + + return ISC_R_SUCCESS; } static isc_result_t @@ -182,8 +168,7 @@ check_hints(dns_db_t *db) { if (result != ISC_R_SUCCESS) { goto cleanup; } - result = dns_dbiterator_first(dbiter); - while (result == ISC_R_SUCCESS) { + DNS_DBITERATOR_FOREACH (dbiter) { result = dns_dbiterator_current(dbiter, &node, name); if (result != ISC_R_SUCCESS) { goto cleanup; @@ -198,10 +183,6 @@ check_hints(dns_db_t *db) { } dns_rdatasetiter_destroy(&rdsiter); dns_db_detachnode(db, &node); - result = dns_dbiterator_next(dbiter); - } - if (result == ISC_R_NOMORE) { - result = ISC_R_SUCCESS; } cleanup: diff --git a/lib/dns/update.c b/lib/dns/update.c index fa27e222f9..0cd35bd6dd 100644 --- a/lib/dns/update.c +++ b/lib/dns/update.c @@ -341,10 +341,9 @@ static isc_result_t foreach_rrset(dns_db_t *db, dns_dbversion_t *ver, dns_name_t *name, rrset_func *action, void *action_data) { isc_result_t result; - dns_dbnode_t *node; - dns_rdatasetiter_t *iter; + dns_dbnode_t *node = NULL; + dns_rdatasetiter_t *iter = NULL; - node = NULL; result = dns_db_findnode(db, name, false, &node); if (result == ISC_R_NOTFOUND) { return ISC_R_SUCCESS; @@ -353,32 +352,23 @@ foreach_rrset(dns_db_t *db, dns_dbversion_t *ver, dns_name_t *name, return result; } - iter = NULL; result = dns_db_allrdatasets(db, node, ver, 0, (isc_stdtime_t)0, &iter); if (result != ISC_R_SUCCESS) { goto cleanup_node; } - for (result = dns_rdatasetiter_first(iter); result == ISC_R_SUCCESS; - result = dns_rdatasetiter_next(iter)) - { - dns_rdataset_t rdataset; + DNS_RDATASETITER_FOREACH (iter) { + dns_rdataset_t rdataset = DNS_RDATASET_INIT; - dns_rdataset_init(&rdataset); dns_rdatasetiter_current(iter, &rdataset); result = (*action)(action_data, &rdataset); dns_rdataset_disassociate(&rdataset); if (result != ISC_R_SUCCESS) { - goto cleanup_iterator; + break; } } - if (result == ISC_R_NOMORE) { - result = ISC_R_SUCCESS; - } - -cleanup_iterator: dns_rdatasetiter_destroy(&iter); cleanup_node: @@ -1379,14 +1369,11 @@ add_exposed_sigs(dns_update_log_t *log, dns_zone_t *zone, dns_db_t *db, goto cleanup_node; } - for (result = dns_rdatasetiter_first(iter); result == ISC_R_SUCCESS; - result = dns_rdatasetiter_next(iter)) - { - dns_rdataset_t rdataset; + DNS_RDATASETITER_FOREACH (iter) { + dns_rdataset_t rdataset = DNS_RDATASET_INIT; dns_rdatatype_t type; bool flag; - dns_rdataset_init(&rdataset); dns_rdatasetiter_current(iter, &rdataset); type = rdataset.type; dns_rdataset_disassociate(&rdataset); @@ -1403,7 +1390,7 @@ add_exposed_sigs(dns_update_log_t *log, dns_zone_t *zone, dns_db_t *db, result = rrset_exists(db, ver, name, dns_rdatatype_rrsig, type, &flag); if (result != ISC_R_SUCCESS) { - goto cleanup_iterator; + break; } if (flag) { continue; @@ -1411,15 +1398,10 @@ add_exposed_sigs(dns_update_log_t *log, dns_zone_t *zone, dns_db_t *db, result = add_sigs(log, zone, db, ver, name, type, diff, keys, nkeys, now, inception, expire); if (result != ISC_R_SUCCESS) { - goto cleanup_iterator; + break; } (*sigs)++; } - if (result == ISC_R_NOMORE) { - result = ISC_R_SUCCESS; - } - -cleanup_iterator: dns_rdatasetiter_destroy(&iter); cleanup_node: diff --git a/lib/dns/zone.c b/lib/dns/zone.c index f8f533843e..79738fe595 100644 --- a/lib/dns/zone.c +++ b/lib/dns/zone.c @@ -3143,23 +3143,17 @@ zone_check_dup(dns_zone_t *zone, dns_db_t *db) { dns_dbiterator_t *dbiterator = NULL; dns_dbnode_t *node = NULL; dns_fixedname_t fixed; - dns_name_t *name; - dns_rdataset_t rdataset; + dns_name_t *name = dns_fixedname_initname(&fixed); dns_rdatasetiter_t *rdsit = NULL; bool ok = true; isc_result_t result; - name = dns_fixedname_initname(&fixed); - dns_rdataset_init(&rdataset); - result = dns_db_createiterator(db, 0, &dbiterator); if (result != ISC_R_SUCCESS) { return true; } - for (result = dns_dbiterator_first(dbiterator); result == ISC_R_SUCCESS; - result = dns_dbiterator_next(dbiterator)) - { + DNS_DBITERATOR_FOREACH (dbiterator) { result = dns_dbiterator_current(dbiterator, &node, name); if (result != ISC_R_SUCCESS) { continue; @@ -3170,10 +3164,8 @@ zone_check_dup(dns_zone_t *zone, dns_db_t *db) { continue; } - for (result = dns_rdatasetiter_first(rdsit); - result == ISC_R_SUCCESS; - result = dns_rdatasetiter_next(rdsit)) - { + DNS_RDATASETITER_FOREACH (rdsit) { + dns_rdataset_t rdataset = DNS_RDATASET_INIT; dns_rdatasetiter_current(rdsit, &rdataset); if (!zone_rrset_check_dup(zone, name, &rdataset)) { ok = false; @@ -3291,8 +3283,7 @@ integrity_checks(dns_zone_t *zone, dns_db_t *db) { return true; } - result = dns_dbiterator_first(dbiterator); - while (result == ISC_R_SUCCESS) { + DNS_DBITERATOR_FOREACH (dbiterator) { result = dns_dbiterator_current(dbiterator, &node, name); if (result != ISC_R_SUCCESS) { goto cleanup; @@ -3478,7 +3469,6 @@ integrity_checks(dns_zone_t *zone, dns_db_t *db) { next: dns_db_detachnode(db, &node); - result = dns_dbiterator_next(dbiterator); } if (has_a) { @@ -7579,7 +7569,6 @@ check_if_bottom_of_zone(dns_db_t *db, dns_dbnode_t *node, dns_dbversion_t *version, bool *is_bottom_of_zone) { isc_result_t result; dns_rdatasetiter_t *iterator = NULL; - dns_rdataset_t rdataset; bool seen_soa = false, seen_ns = false, seen_dname = false; REQUIRE(is_bottom_of_zone != NULL); @@ -7592,10 +7581,8 @@ check_if_bottom_of_zone(dns_db_t *db, dns_dbnode_t *node, return result; } - dns_rdataset_init(&rdataset); - for (result = dns_rdatasetiter_first(iterator); result == ISC_R_SUCCESS; - result = dns_rdatasetiter_next(iterator)) - { + DNS_RDATASETITER_FOREACH (iterator) { + dns_rdataset_t rdataset = DNS_RDATASET_INIT; dns_rdatasetiter_current(iterator, &rdataset); switch (rdataset.type) { case dns_rdatatype_soa: @@ -7610,18 +7597,13 @@ check_if_bottom_of_zone(dns_db_t *db, dns_dbnode_t *node, } dns_rdataset_disassociate(&rdataset); } - if (result != ISC_R_NOMORE) { - goto failure; - } + if ((seen_ns && !seen_soa) || seen_dname) { *is_bottom_of_zone = true; } - result = ISC_R_SUCCESS; -failure: dns_rdatasetiter_destroy(&iterator); - - return result; + return ISC_R_SUCCESS; } static isc_result_t @@ -7633,7 +7615,7 @@ sign_a_node(dns_db_t *db, dns_zone_t *zone, dns_name_t *name, dns_diff_t *diff, int32_t *signatures, isc_mem_t *mctx) { isc_result_t result; dns_rdatasetiter_t *iterator = NULL; - dns_rdataset_t rdataset; + dns_rdataset_t rdataset = DNS_RDATASET_INIT; dns_rdata_t rdata = DNS_RDATA_INIT; dns_stats_t *dnssecsignstats; bool offlineksk = false; @@ -7653,12 +7635,9 @@ sign_a_node(dns_db_t *db, dns_zone_t *zone, dns_name_t *name, return result; } - dns_rdataset_init(&rdataset); isc_buffer_init(&buffer, data, sizeof(data)); seen_rr = seen_soa = seen_ns = seen_nsec = seen_nsec3 = seen_ds = false; - for (result = dns_rdatasetiter_first(iterator); result == ISC_R_SUCCESS; - result = dns_rdatasetiter_next(iterator)) - { + DNS_RDATASETITER_FOREACH (iterator) { dns_rdatasetiter_current(iterator, &rdataset); if (rdataset.type == dns_rdatatype_soa) { seen_soa = true; @@ -7676,9 +7655,7 @@ sign_a_node(dns_db_t *db, dns_zone_t *zone, dns_name_t *name, } dns_rdataset_disassociate(&rdataset); } - if (result != ISC_R_NOMORE) { - goto failure; - } + /* * Going from insecure to NSEC3. * Don't generate NSEC3 records for NSEC3 records. @@ -7704,15 +7681,19 @@ sign_a_node(dns_db_t *db, dns_zone_t *zone, dns_name_t *name, (*signatures)--; } } - result = dns_rdatasetiter_first(iterator); - while (result == ISC_R_SUCCESS) { + + DNS_RDATASETITER_FOREACH (iterator) { isc_stdtime_t when; + if (dns_rdataset_isassociated(&rdataset)) { + dns_rdataset_disassociate(&rdataset); + } + dns_rdatasetiter_current(iterator, &rdataset); if (rdataset.type == dns_rdatatype_soa || rdataset.type == dns_rdatatype_rrsig) { - goto next_rdataset; + continue; } if (dns_rdatatype_iskeymaterial(rdataset.type)) { /* @@ -7722,28 +7703,28 @@ sign_a_node(dns_db_t *db, dns_zone_t *zone, dns_name_t *name, * which would only include KSK's.) */ if (!is_ksk && both) { - goto next_rdataset; + continue; } } else if (!is_zsk && both) { - goto next_rdataset; + continue; } else if (is_zsk && !dst_key_is_signing(key, DST_BOOL_ZSK, now, &when)) { /* Only applies to dnssec-policy. */ if (zone->kasp != NULL) { - goto next_rdataset; + continue; } } if (seen_ns && !seen_soa && rdataset.type != dns_rdatatype_ds && rdataset.type != dns_rdatatype_nsec) { - goto next_rdataset; + continue; } if (signed_with_good_key(zone, db, node, version, rdataset.type, key)) { - goto next_rdataset; + continue; } /* Calculate the signature, creating a RRSIG RDATA. */ @@ -7781,13 +7762,8 @@ sign_a_node(dns_db_t *db, dns_zone_t *zone, dns_name_t *name, } (*signatures)--; - next_rdataset: - dns_rdataset_disassociate(&rdataset); - result = dns_rdatasetiter_next(iterator); - } - if (result == ISC_R_NOMORE) { - result = ISC_R_SUCCESS; } + failure: if (dns_rdataset_isassociated(&rdataset)) { dns_rdataset_disassociate(&rdataset); @@ -8401,7 +8377,6 @@ zone_nsec3chain(dns_zone_t *zone) { dns_fixedname_t fixed; dns_fixedname_t nextfixed; dns_name_t *name = NULL, *nextname = NULL; - dns_rdataset_t rdataset; dns_nsec3chain_t *nsec3chain = NULL; dns_nsec3chainlist_t cleanup; dst_key_t *zone_keys[DNS_MAXZONEKEYS]; @@ -8423,7 +8398,6 @@ zone_nsec3chain(dns_zone_t *zone) { ENTER; - dns_rdataset_init(&rdataset); name = dns_fixedname_initname(&fixed); nextname = dns_fixedname_initname(&nextfixed); dns_diff_init(zone->mctx, ¶m_diff); @@ -8596,10 +8570,8 @@ zone_nsec3chain(dns_zone_t *zone) { } seen_soa = seen_ns = seen_dname = seen_ds = seen_nsec = false; - for (result = dns_rdatasetiter_first(iterator); - result == ISC_R_SUCCESS; - result = dns_rdatasetiter_next(iterator)) - { + DNS_RDATASETITER_FOREACH (iterator) { + dns_rdataset_t rdataset = DNS_RDATASET_INIT; dns_rdatasetiter_current(iterator, &rdataset); INSIST(rdataset.type != dns_rdatatype_nsec3); if (rdataset.type == dns_rdatatype_soa) { @@ -8862,10 +8834,8 @@ zone_nsec3chain(dns_zone_t *zone) { seen_soa = seen_ns = seen_dname = seen_nsec3 = seen_nsec = seen_rr = false; - for (result = dns_rdatasetiter_first(iterator); - result == ISC_R_SUCCESS; - result = dns_rdatasetiter_next(iterator)) - { + DNS_RDATASETITER_FOREACH (iterator) { + dns_rdataset_t rdataset = DNS_RDATASET_INIT; dns_rdatasetiter_current(iterator, &rdataset); if (rdataset.type == dns_rdatatype_soa) { seen_soa = true; @@ -8980,10 +8950,8 @@ skip_removals: isc_result_totext(result)); goto failure; } - for (result = dns_rdatasetiter_first(iterator); - result == ISC_R_SUCCESS; - result = dns_rdatasetiter_next(iterator)) - { + DNS_RDATASETITER_FOREACH (iterator) { + dns_rdataset_t rdataset = DNS_RDATASET_INIT; dns_rdatasetiter_current(iterator, &rdataset); if (rdataset.type == dns_rdatatype_nsec) { rebuild_nsec = true; @@ -9275,9 +9243,7 @@ del_sig(dns_db_t *db, dns_dbversion_t *version, dns_name_t *name, } dns_rdataset_init(&rdataset); - for (result = dns_rdatasetiter_first(iterator); result == ISC_R_SUCCESS; - result = dns_rdatasetiter_next(iterator)) - { + DNS_RDATASETITER_FOREACH (iterator) { bool has_alg = false; dns_rdatasetiter_current(iterator, &rdataset); if (nkeys == 0 && rdataset.type == dns_rdatatype_nsec) { @@ -9323,9 +9289,6 @@ del_sig(dns_db_t *db, dns_dbversion_t *version, dns_name_t *name, alg_missed = true; } } - if (result == ISC_R_NOMORE) { - result = ISC_R_SUCCESS; - } /* * Set `has_algp` if the algorithm was found in every RRset: @@ -17324,7 +17287,6 @@ copy_non_dnssec_records(dns_db_t *db, dns_dbversion_t *version, dns_db_t *rawdb, dns_dbnode_t *rawnode = NULL, *node = NULL; dns_fixedname_t fixed; dns_name_t *name = dns_fixedname_initname(&fixed); - dns_rdataset_t rdataset; dns_rdatasetiter_t *rdsit = NULL; isc_result_t result; @@ -17345,11 +17307,8 @@ copy_non_dnssec_records(dns_db_t *db, dns_dbversion_t *version, dns_db_t *rawdb, goto cleanup; } - dns_rdataset_init(&rdataset); - - for (result = dns_rdatasetiter_first(rdsit); result == ISC_R_SUCCESS; - result = dns_rdatasetiter_next(rdsit)) - { + DNS_RDATASETITER_FOREACH (rdsit) { + dns_rdataset_t rdataset = DNS_RDATASET_INIT; dns_rdatasetiter_current(rdsit, &rdataset); if (rdataset.type == dns_rdatatype_nsec || rdataset.type == dns_rdatatype_rrsig || @@ -17374,12 +17333,9 @@ copy_non_dnssec_records(dns_db_t *db, dns_dbversion_t *version, dns_db_t *rawdb, } dns_rdataset_disassociate(&rdataset); if (result != ISC_R_SUCCESS) { - goto cleanup; + break; } } - if (result == ISC_R_NOMORE) { - result = ISC_R_SUCCESS; - } cleanup: if (rdsit != NULL) { @@ -17456,9 +17412,7 @@ receive_secure_db(void *arg) { goto failure; } - for (result = dns_dbiterator_first(dbiterator); result == ISC_R_SUCCESS; - result = dns_dbiterator_next(dbiterator)) - { + DNS_DBITERATOR_FOREACH (dbiterator) { result = copy_non_dnssec_records(db, version, rawdb, dbiterator, oldserialp); if (result != ISC_R_SUCCESS) { @@ -17466,9 +17420,6 @@ receive_secure_db(void *arg) { } } dns_dbiterator_destroy(&dbiterator); - if (result != ISC_R_NOMORE) { - goto failure; - } /* * Call restore_nsec3param() to create private-type records from diff --git a/lib/dns/zoneverify.c b/lib/dns/zoneverify.c index 5a6b891ae7..aeb010746a 100644 --- a/lib/dns/zoneverify.c +++ b/lib/dns/zoneverify.c @@ -301,7 +301,7 @@ check_no_rrsig(const vctx_t *vctx, const dns_rdataset_t *rdataset, const dns_name_t *name, dns_dbnode_t *node) { char namebuf[DNS_NAME_FORMATSIZE]; char typebuf[DNS_RDATATYPE_FORMATSIZE]; - dns_rdataset_t sigrdataset; + dns_rdataset_t sigrdataset = DNS_RDATASET_INIT; dns_rdatasetiter_t *rdsiter = NULL; isc_result_t result; @@ -312,9 +312,7 @@ check_no_rrsig(const vctx_t *vctx, const dns_rdataset_t *rdataset, isc_result_totext(result)); return result; } - for (result = dns_rdatasetiter_first(rdsiter); result == ISC_R_SUCCESS; - result = dns_rdatasetiter_next(rdsiter)) - { + DNS_RDATASETITER_FOREACH (rdsiter) { dns_rdatasetiter_current(rdsiter, &sigrdataset); if (sigrdataset.type == dns_rdatatype_rrsig && sigrdataset.covers == rdataset->type) @@ -798,29 +796,29 @@ verifyset(vctx_t *vctx, dns_rdataset_t *rdataset, const dns_name_t *name, char namebuf[DNS_NAME_FORMATSIZE]; char algbuf[DNS_SECALG_FORMATSIZE]; char typebuf[DNS_RDATATYPE_FORMATSIZE]; - dns_rdataset_t sigrdataset; + dns_rdataset_t sigrdataset = DNS_RDATASET_INIT; dns_rdatasetiter_t *rdsiter = NULL; + bool match = false; isc_result_t result; - dns_rdataset_init(&sigrdataset); result = dns_db_allrdatasets(vctx->db, node, vctx->ver, 0, 0, &rdsiter); if (result != ISC_R_SUCCESS) { zoneverify_log_error(vctx, "dns_db_allrdatasets(): %s", isc_result_totext(result)); return result; } - for (result = dns_rdatasetiter_first(rdsiter); result == ISC_R_SUCCESS; - result = dns_rdatasetiter_next(rdsiter)) - { + DNS_RDATASETITER_FOREACH (rdsiter) { dns_rdatasetiter_current(rdsiter, &sigrdataset); if (sigrdataset.type == dns_rdatatype_rrsig && sigrdataset.covers == rdataset->type) { + match = true; break; } dns_rdataset_disassociate(&sigrdataset); } - if (result != ISC_R_SUCCESS) { + + if (!match) { dns_name_format(name, namebuf, sizeof(namebuf)); dns_rdatatype_format(rdataset->type, typebuf, sizeof(typebuf)); zoneverify_log_error(vctx, "No signatures for %s/%s", namebuf, @@ -899,7 +897,6 @@ verifynode(vctx_t *vctx, const dns_name_t *name, dns_dbnode_t *node, const dns_name_t *nextname, isc_result_t *vresult) { unsigned char types[8192] = { 0 }; unsigned int maxtype = 0; - dns_rdataset_t rdataset; dns_rdatasetiter_t *rdsiter = NULL; isc_result_t result, tvresult = ISC_R_UNSET; @@ -912,10 +909,10 @@ verifynode(vctx_t *vctx, const dns_name_t *name, dns_dbnode_t *node, return result; } - result = dns_rdatasetiter_first(rdsiter); - dns_rdataset_init(&rdataset); - while (result == ISC_R_SUCCESS) { + DNS_RDATASETITER_FOREACH (rdsiter) { + dns_rdataset_t rdataset = DNS_RDATASET_INIT; dns_rdatasetiter_current(rdsiter, &rdataset); + /* * If we are not at a delegation then everything should be * signed. If we are at a delegation then only the DS set @@ -958,14 +955,8 @@ verifynode(vctx_t *vctx, const dns_name_t *name, dns_dbnode_t *node, } } dns_rdataset_disassociate(&rdataset); - result = dns_rdatasetiter_next(rdsiter); } dns_rdatasetiter_destroy(&rdsiter); - if (result != ISC_R_NOMORE) { - zoneverify_log_error(vctx, "rdataset iteration failed: %s", - isc_result_totext(result)); - return result; - } if (vresult == NULL) { return ISC_R_SUCCESS; @@ -1848,9 +1839,7 @@ verify_nodes(vctx_t *vctx, isc_result_t *vresult) { return result; } - for (result = dns_dbiterator_first(dbiter); result == ISC_R_SUCCESS; - result = dns_dbiterator_next(dbiter)) - { + DNS_DBITERATOR_FOREACH (dbiter) { result = dns_dbiterator_current(dbiter, &node, name); if (result != ISC_R_SUCCESS && result != DNS_R_NEWORIGIN) { zoneverify_log_error(vctx, diff --git a/lib/ns/query.c b/lib/ns/query.c index 805f4a00d7..b6f181a7fd 100644 --- a/lib/ns/query.c +++ b/lib/ns/query.c @@ -3251,9 +3251,9 @@ rpz_find_p(ns_client_t *client, dns_name_t *self_name, dns_rdatatype_t qtype, * Choose the best rdataset if we found something. */ if (result == ISC_R_SUCCESS) { - dns_rdatasetiter_t *rdsiter; + dns_rdatasetiter_t *rdsiter = NULL; + bool match = false; - rdsiter = NULL; result = dns_db_allrdatasets(*dbp, *nodep, *versionp, 0, 0, &rdsiter); if (result != ISC_R_SUCCESS) { @@ -3266,10 +3266,7 @@ rpz_find_p(ns_client_t *client, dns_name_t *self_name, dns_rdatatype_t qtype, if (qtype == dns_rdatatype_aaaa && !ISC_LIST_EMPTY(client->view->dns64)) { - for (result = dns_rdatasetiter_first(rdsiter); - result == ISC_R_SUCCESS; - result = dns_rdatasetiter_next(rdsiter)) - { + DNS_RDATASETITER_FOREACH (rdsiter) { dns_rdatasetiter_current(rdsiter, *rdatasetp); if ((*rdatasetp)->type == dns_rdatatype_a) { found_a = true; @@ -3277,28 +3274,18 @@ rpz_find_p(ns_client_t *client, dns_name_t *self_name, dns_rdatatype_t qtype, dns_rdataset_disassociate(*rdatasetp); } } - for (result = dns_rdatasetiter_first(rdsiter); - result == ISC_R_SUCCESS; - result = dns_rdatasetiter_next(rdsiter)) - { + DNS_RDATASETITER_FOREACH (rdsiter) { dns_rdatasetiter_current(rdsiter, *rdatasetp); if ((*rdatasetp)->type == dns_rdatatype_cname || (*rdatasetp)->type == qtype) { + match = true; break; } dns_rdataset_disassociate(*rdatasetp); } dns_rdatasetiter_destroy(&rdsiter); - if (result != ISC_R_SUCCESS) { - if (result != ISC_R_NOMORE) { - rpz_log_fail(client, DNS_RPZ_ERROR_LEVEL, - p_name, rpz_type, "rdatasetiter", - result); - CTRACE(ISC_LOG_ERROR, "rpz_find_p: " - "rdatasetiter failed"); - return DNS_R_SERVFAIL; - } + if (!match) { /* * Ask again to get the right DNS_R_DNAME/NXRRSET/... * result if there is neither a CNAME nor target type. @@ -7660,8 +7647,7 @@ query_respond_any(query_ctx_t *qctx) { ns_client_keepname(qctx->client, qctx->fname, qctx->dbuf); qctx->tname = qctx->fname; - result = dns_rdatasetiter_first(rdsiter); - while (result == ISC_R_SUCCESS) { + DNS_RDATASETITER_FOREACH (rdsiter) { dns_rdatasetiter_current(rdsiter, qctx->rdataset); /* @@ -7770,19 +7756,10 @@ query_respond_any(query_ctx_t *qctx) { */ dns_rdataset_disassociate(qctx->rdataset); } - - result = dns_rdatasetiter_next(rdsiter); } dns_rdatasetiter_destroy(&rdsiter); - if (result != ISC_R_NOMORE) { - CCTRACE(ISC_LOG_ERROR, "query_respond_any: rdataset iterator " - "failed"); - QUERY_ERROR(qctx, DNS_R_SERVFAIL); - return ns_query_done(qctx); - } - if (found) { /* * Call hook if any answers were found. diff --git a/lib/ns/update.c b/lib/ns/update.c index 6d04f62c87..f215805e41 100644 --- a/lib/ns/update.c +++ b/lib/ns/update.c @@ -607,26 +607,17 @@ foreach_rrset(dns_db_t *db, dns_dbversion_t *ver, dns_name_t *name, goto cleanup_node; } - for (result = dns_rdatasetiter_first(iter); result == ISC_R_SUCCESS; - result = dns_rdatasetiter_next(iter)) - { - dns_rdataset_t rdataset; - - dns_rdataset_init(&rdataset); + DNS_RDATASETITER_FOREACH (iter) { + dns_rdataset_t rdataset = DNS_RDATASET_INIT; dns_rdatasetiter_current(iter, &rdataset); result = (*action)(action_data, &rdataset); dns_rdataset_disassociate(&rdataset); if (result != ISC_R_SUCCESS) { - goto cleanup_iterator; + break; } } - if (result == ISC_R_NOMORE) { - result = ISC_R_SUCCESS; - } - -cleanup_iterator: dns_rdatasetiter_destroy(&iter); cleanup_node: diff --git a/tests/dns/dbiterator_test.c b/tests/dns/dbiterator_test.c index a84e4d806c..d5eabfb280 100644 --- a/tests/dns/dbiterator_test.c +++ b/tests/dns/dbiterator_test.c @@ -93,9 +93,7 @@ test_walk(const char *filename, int flags, int nodes) { result = dns_db_createiterator(db, flags, &iter); assert_int_equal(result, ISC_R_SUCCESS); - for (result = dns_dbiterator_first(iter); result == ISC_R_SUCCESS; - result = dns_dbiterator_next(iter)) - { + DNS_DBITERATOR_FOREACH (iter) { result = dns_dbiterator_current(iter, &node, name); assert_int_equal(result, ISC_R_SUCCESS); dns_db_detachnode(db, &node);