From 2f27d664502a2e70bda9ddd9923444dfc7ff7d94 Mon Sep 17 00:00:00 2001 From: alessio Date: Wed, 19 Mar 2025 20:29:17 +0100 Subject: [PATCH] Refactor to use list-like macro for message sections In the code base it is very common to iterate over all names in a message section and all rdatasets for each name, but various idioms are used for iteration. This commit standardizes them as much as possible to a single idiom, using the macro MSG_SECTION_FOREACH, similar to the existing ISC_LIST_FOREACH. --- .clang-format | 2 +- bin/delv/delv.c | 18 +-- bin/dig/dig.c | 31 +---- bin/dig/dighost.c | 70 ++++------ bin/dig/host.c | 21 +-- bin/dig/nslookup.c | 48 +------ bin/nsupdate/nsupdate.c | 58 ++++----- bin/plugins/filter-a.c | 8 +- bin/plugins/filter-aaaa.c | 8 +- bin/tools/mdig.c | 22 +--- lib/dns/client.c | 17 ++- lib/dns/include/dns/message.h | 7 + lib/dns/message.c | 36 ++---- lib/dns/ncache.c | 23 +--- lib/dns/resolver.c | 234 +++++++--------------------------- lib/dns/tkey.c | 33 ++--- lib/dns/xfrin.c | 31 +---- lib/dns/zone.c | 36 ++---- lib/ns/notify.c | 9 +- lib/ns/query.c | 98 +++++--------- lib/ns/update.c | 66 ++++------ lib/ns/xfrout.c | 26 +--- 22 files changed, 246 insertions(+), 656 deletions(-) diff --git a/.clang-format b/.clang-format index 7bd90052ab..2e7ab89d69 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' ] +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' ] RemoveParentheses: ReturnStatement RemoveSemicolon: true diff --git a/bin/delv/delv.c b/bin/delv/delv.c index c489df8671..f5c4ad9971 100644 --- a/bin/delv/delv.c +++ b/bin/delv/delv.c @@ -1855,10 +1855,8 @@ resolve_cb(dns_client_t *client, const dns_name_t *query_name, printf("records:\n"); } - for (dns_name_t *response_name = ISC_LIST_HEAD(*namelist); - response_name != NULL; - response_name = ISC_LIST_NEXT(response_name, link)) - { + dns_name_t *response_name; + ISC_LIST_FOREACH (*namelist, response_name, link) { for (rdataset = ISC_LIST_HEAD(response_name->list); rdataset != NULL; rdataset = ISC_LIST_NEXT(rdataset, link)) { @@ -1986,19 +1984,11 @@ recvresponse(void *arg) { goto cleanup; } - for (result = dns_message_firstname(response, DNS_SECTION_ANSWER); - result == ISC_R_SUCCESS; - result = dns_message_nextname(response, DNS_SECTION_ANSWER)) - { - dns_name_t *name = NULL; + MSG_SECTION_FOREACH (response, DNS_SECTION_ANSWER, name) { dns_rdataset_t *rdataset = NULL; dns_rdatatype_t prevtype = 0; - dns_message_currentname(response, DNS_SECTION_ANSWER, &name); - - for (rdataset = ISC_LIST_HEAD(name->list); rdataset != NULL; - rdataset = ISC_LIST_NEXT(rdataset, link)) - { + ISC_LIST_FOREACH (name->list, rdataset, link) { dns_rdataset_t rds, sigs; int options = 0; diff --git a/bin/dig/dig.c b/bin/dig/dig.c index 04aafc4452..2862eb6b37 100644 --- a/bin/dig/dig.c +++ b/bin/dig/dig.c @@ -579,7 +579,6 @@ dns64prefix_answer(dns_message_t *msg, isc_buffer_t *buf) { static isc_result_t short_answer(dns_message_t *msg, dns_messagetextflag_t flags, isc_buffer_t *buf, dig_query_t *query) { - dns_name_t *name; dns_rdataset_t *rdataset; isc_result_t result, loopresult; dns_name_t empty_name; @@ -588,20 +587,8 @@ short_answer(dns_message_t *msg, dns_messagetextflag_t flags, isc_buffer_t *buf, UNUSED(flags); dns_name_init(&empty_name); - result = dns_message_firstname(msg, DNS_SECTION_ANSWER); - if (result == ISC_R_NOMORE) { - return ISC_R_SUCCESS; - } else if (result != ISC_R_SUCCESS) { - return result; - } - - for (;;) { - name = NULL; - dns_message_currentname(msg, DNS_SECTION_ANSWER, &name); - - for (rdataset = ISC_LIST_HEAD(name->list); rdataset != NULL; - rdataset = ISC_LIST_NEXT(rdataset, link)) - { + MSG_SECTION_FOREACH (msg, DNS_SECTION_ANSWER, name) { + ISC_LIST_FOREACH (name->list, rdataset, link) { loopresult = dns_rdataset_first(rdataset); while (loopresult == ISC_R_SUCCESS) { dns_rdataset_current(rdataset, &rdata); @@ -614,12 +601,6 @@ short_answer(dns_message_t *msg, dns_messagetextflag_t flags, isc_buffer_t *buf, dns_rdata_reset(&rdata); } } - result = dns_message_nextname(msg, DNS_SECTION_ANSWER); - if (result == ISC_R_NOMORE) { - break; - } else if (result != ISC_R_SUCCESS) { - return result; - } } return ISC_R_SUCCESS; @@ -627,16 +608,10 @@ short_answer(dns_message_t *msg, dns_messagetextflag_t flags, isc_buffer_t *buf, static bool isdotlocal(dns_message_t *msg) { - isc_result_t result; static unsigned char local_ndata[] = { "\005local" }; static dns_name_t local = DNS_NAME_INITABSOLUTE(local_ndata); - for (result = dns_message_firstname(msg, DNS_SECTION_QUESTION); - result == ISC_R_SUCCESS; - result = dns_message_nextname(msg, DNS_SECTION_QUESTION)) - { - dns_name_t *name = NULL; - dns_message_currentname(msg, DNS_SECTION_QUESTION, &name); + MSG_SECTION_FOREACH (msg, DNS_SECTION_QUESTION, name) { if (dns_name_issubdomain(name, &local)) { return true; } diff --git a/bin/dig/dighost.c b/bin/dig/dighost.c index 440c3a5c2b..d92c30a3f9 100644 --- a/bin/dig/dighost.c +++ b/bin/dig/dighost.c @@ -1835,8 +1835,7 @@ followup_lookup(dns_message_t *msg, dig_query_t *query, dns_section_t section) { dig_server_t *srv = NULL; dns_rdataset_t *rdataset = NULL; dns_rdata_t rdata = DNS_RDATA_INIT; - dns_name_t *name = NULL; - isc_result_t result; + isc_result_t result = ISC_R_NOMORE; bool success = false; int numLookups = 0; int num; @@ -1851,13 +1850,8 @@ followup_lookup(dns_message_t *msg, dig_query_t *query, dns_section_t section) { addresses_result = ISC_R_SUCCESS; bad_namestr[0] = '\0'; - for (result = dns_message_firstname(msg, section); - result == ISC_R_SUCCESS; - result = dns_message_nextname(msg, section)) - { - name = NULL; - dns_message_currentname(msg, section, &name); + MSG_SECTION_FOREACH (msg, section, name) { if (section == DNS_SECTION_AUTHORITY) { rdataset = NULL; result = dns_message_findtype(name, dns_rdatatype_soa, @@ -3716,18 +3710,13 @@ check_for_more_data(dig_lookup_t *lookup, dig_query_t *query, query->msg_count++; query->byte_count += len; - result = dns_message_firstname(msg, DNS_SECTION_ANSWER); - if (result != ISC_R_SUCCESS) { + + if (ISC_LIST_EMPTY(msg->sections[DNS_SECTION_ANSWER])) { puts("; Transfer failed."); return true; } - do { - dns_name_t *name; - name = NULL; - dns_message_currentname(msg, DNS_SECTION_ANSWER, &name); - for (rdataset = ISC_LIST_HEAD(name->list); rdataset != NULL; - rdataset = ISC_LIST_NEXT(rdataset, link)) - { + MSG_SECTION_FOREACH (msg, DNS_SECTION_ANSWER, name) { + ISC_LIST_FOREACH (name->list, rdataset, link) { result = dns_rdataset_first(rdataset); if (result != ISC_R_SUCCESS) { continue; @@ -3820,8 +3809,8 @@ check_for_more_data(dig_lookup_t *lookup, dig_query_t *query, result = dns_rdataset_next(rdataset); } while (result == ISC_R_SUCCESS); } - result = dns_message_nextname(msg, DNS_SECTION_ANSWER); - } while (result == ISC_R_SUCCESS); + } + isc_nmhandle_detach(&query->readhandle); launch_next_query(query); query_detach(&query); @@ -4254,19 +4243,9 @@ recv_done(isc_nmhandle_t *handle, isc_result_t eresult, isc_region_t *region, } } else { match = true; - for (result = dns_message_firstname(msg, DNS_SECTION_QUESTION); - result == ISC_R_SUCCESS && match; - result = dns_message_nextname(msg, DNS_SECTION_QUESTION)) - { - dns_name_t *name = NULL; + MSG_SECTION_FOREACH (msg, DNS_SECTION_QUESTION, name) { dns_rdataset_t *rdataset; - - dns_message_currentname(msg, DNS_SECTION_QUESTION, - &name); - for (rdataset = ISC_LIST_HEAD(name->list); - rdataset != NULL; - rdataset = ISC_LIST_NEXT(rdataset, link)) - { + ISC_LIST_FOREACH (name->list, rdataset, link) { if (l->rdtype != rdataset->type || l->rdclass != rdataset->rdclass || !dns_name_equal(l->name, name)) @@ -4290,22 +4269,23 @@ recv_done(isc_nmhandle_t *handle, isc_result_t eresult, isc_region_t *region, match = false; } } - } - if (!match) { - if (l->tcp_mode) { - goto cancel_lookup; + /* Break out of the loop on mismatch */ + if (!match) { + if (l->tcp_mode) { + goto cancel_lookup; + } + + /* + * We are still attached to query and the + * query->readhandle is also attached + */ + isc_refcount_increment0(&recvcount); + debug("recvcount=%" PRIuFAST32, + isc_refcount_current(&recvcount)); + isc_nm_read(handle, recv_done, query); + goto keep_query; } - - /* - * We are still attached to query and the - * query->readhandle is also attached - */ - isc_refcount_increment0(&recvcount); - debug("recvcount=%" PRIuFAST32, - isc_refcount_current(&recvcount)); - isc_nm_read(handle, recv_done, query); - goto keep_query; } } diff --git a/bin/dig/host.c b/bin/dig/host.c index 4e6dc8d9cd..69d898937c 100644 --- a/bin/dig/host.c +++ b/bin/dig/host.c @@ -206,7 +206,7 @@ retry: static isc_result_t printsection(dns_message_t *msg, dns_section_t sectionid, const char *section_name, bool headers, dig_query_t *query) { - dns_name_t *name, *print_name; + dns_name_t *print_name; dns_rdataset_t *rdataset; dns_rdata_t rdata = DNS_RDATA_INIT; isc_buffer_t target; @@ -223,17 +223,7 @@ printsection(dns_message_t *msg, dns_section_t sectionid, dns_name_init(&empty_name); - result = dns_message_firstname(msg, sectionid); - if (result == ISC_R_NOMORE) { - return ISC_R_SUCCESS; - } else if (result != ISC_R_SUCCESS) { - return result; - } - - for (;;) { - name = NULL; - dns_message_currentname(msg, sectionid, &name); - + MSG_SECTION_FOREACH (msg, sectionid, name) { isc_buffer_init(&target, tbuf, sizeof(tbuf)); first = true; print_name = name; @@ -314,13 +304,6 @@ printsection(dns_message_t *msg, dns_section_t sectionid, printf("%.*s", (int)r.length, (char *)r.base); } } - - result = dns_message_nextname(msg, sectionid); - if (result == ISC_R_NOMORE) { - break; - } else if (result != ISC_R_SUCCESS) { - return result; - } } return ISC_R_SUCCESS; diff --git a/bin/dig/nslookup.c b/bin/dig/nslookup.c index 68116749dd..5001c0dfeb 100644 --- a/bin/dig/nslookup.c +++ b/bin/dig/nslookup.c @@ -198,8 +198,6 @@ printrdata(dns_rdata_t *rdata) { static isc_result_t printsection(dig_query_t *query, dns_message_t *msg, bool headers, dns_section_t section) { - isc_result_t result, loopresult; - dns_name_t *name; dns_rdataset_t *rdataset = NULL; dns_rdata_t rdata = DNS_RDATA_INIT; char namebuf[DNS_NAME_FORMATSIZE]; @@ -209,19 +207,9 @@ printsection(dig_query_t *query, dns_message_t *msg, bool headers, debug("printsection()"); - result = dns_message_firstname(msg, section); - if (result == ISC_R_NOMORE) { - return ISC_R_SUCCESS; - } else if (result != ISC_R_SUCCESS) { - return result; - } - for (;;) { - name = NULL; - dns_message_currentname(msg, section, &name); - for (rdataset = ISC_LIST_HEAD(name->list); rdataset != NULL; - rdataset = ISC_LIST_NEXT(rdataset, link)) - { - loopresult = dns_rdataset_first(rdataset); + MSG_SECTION_FOREACH (msg, section, name) { + ISC_LIST_FOREACH (name->list, rdataset, link) { + isc_result_t loopresult = dns_rdataset_first(rdataset); while (loopresult == ISC_R_SUCCESS) { dns_rdataset_current(rdataset, &rdata); switch (rdata.type) { @@ -253,12 +241,6 @@ printsection(dig_query_t *query, dns_message_t *msg, bool headers, loopresult = dns_rdataset_next(rdataset); } } - result = dns_message_nextname(msg, section); - if (result == ISC_R_NOMORE) { - break; - } else if (result != ISC_R_SUCCESS) { - return result; - } } return ISC_R_SUCCESS; } @@ -266,8 +248,6 @@ printsection(dig_query_t *query, dns_message_t *msg, bool headers, static isc_result_t detailsection(dig_query_t *query, dns_message_t *msg, bool headers, dns_section_t section) { - isc_result_t result, loopresult; - dns_name_t *name; dns_rdataset_t *rdataset = NULL; dns_rdata_t rdata = DNS_RDATA_INIT; char namebuf[DNS_NAME_FORMATSIZE]; @@ -293,18 +273,8 @@ detailsection(dig_query_t *query, dns_message_t *msg, bool headers, } } - result = dns_message_firstname(msg, section); - if (result == ISC_R_NOMORE) { - return ISC_R_SUCCESS; - } else if (result != ISC_R_SUCCESS) { - return result; - } - for (;;) { - name = NULL; - dns_message_currentname(msg, section, &name); - for (rdataset = ISC_LIST_HEAD(name->list); rdataset != NULL; - rdataset = ISC_LIST_NEXT(rdataset, link)) - { + MSG_SECTION_FOREACH (msg, section, name) { + ISC_LIST_FOREACH (name->list, rdataset, link) { if (section == DNS_SECTION_QUESTION) { dns_name_format(name, namebuf, sizeof(namebuf)); printf("\t%s, ", namebuf); @@ -315,7 +285,7 @@ detailsection(dig_query_t *query, dns_message_t *msg, bool headers, namebuf, sizeof(namebuf)); printf("class = %s\n", namebuf); } - loopresult = dns_rdataset_first(rdataset); + isc_result_t loopresult = dns_rdataset_first(rdataset); while (loopresult == ISC_R_SUCCESS) { dns_rdataset_current(rdataset, &rdata); @@ -335,12 +305,6 @@ detailsection(dig_query_t *query, dns_message_t *msg, bool headers, loopresult = dns_rdataset_next(rdataset); } } - result = dns_message_nextname(msg, section); - if (result == ISC_R_NOMORE) { - break; - } else if (result != ISC_R_SUCCESS) { - return result; - } } return ISC_R_SUCCESS; } diff --git a/bin/nsupdate/nsupdate.c b/bin/nsupdate/nsupdate.c index 638024d793..be1d720c4a 100644 --- a/bin/nsupdate/nsupdate.c +++ b/bin/nsupdate/nsupdate.c @@ -2182,17 +2182,17 @@ evaluate_checksvcb(char *cmdline) { static void setzone(dns_name_t *zonename) { - isc_result_t result; dns_name_t *name = NULL; - dns_rdataset_t *rdataset = NULL; + dns_rdataset_t *rdataset = NULL, *next_rds = NULL; - result = dns_message_firstname(updatemsg, DNS_SECTION_ZONE); - if (result == ISC_R_SUCCESS) { - dns_message_currentname(updatemsg, DNS_SECTION_ZONE, &name); - dns_message_removename(updatemsg, name, DNS_SECTION_ZONE); - for (rdataset = ISC_LIST_HEAD(name->list); rdataset != NULL; - rdataset = ISC_LIST_HEAD(name->list)) - { + dns_namelist_t *secs = updatemsg->sections; + if (!ISC_LIST_EMPTY(secs[DNS_SECTION_ZONE])) { + INSIST(updatemsg->from_to_wire == DNS_MESSAGE_INTENTRENDER); + + name = ISC_LIST_HEAD(secs[DNS_SECTION_ZONE]); + ISC_LIST_UNLINK(secs[DNS_SECTION_ZONE], name, link); + + ISC_LIST_FOREACH_SAFE (name->list, rdataset, link, next_rds) { ISC_LIST_UNLINK(name->list, rdataset, link); dns_rdataset_disassociate(rdataset); dns_message_puttemprdataset(updatemsg, &rdataset); @@ -2820,14 +2820,12 @@ lookforsoa: goto droplabel; } - result = dns_message_firstname(rcvmsg, section); - if (result != ISC_R_SUCCESS) { + if (ISC_LIST_EMPTY(rcvmsg->sections[section])) { pass++; goto lookforsoa; } - while (result == ISC_R_SUCCESS) { - name = NULL; - dns_message_currentname(rcvmsg, section, &name); + + ISC_LIST_FOREACH (rcvmsg->sections[section], name, link) { soaset = NULL; result = dns_message_findtype(name, dns_rdatatype_soa, 0, &soaset); @@ -2845,8 +2843,6 @@ lookforsoa: break; } } - - result = dns_message_nextname(rcvmsg, section); } if (soaset == NULL && !seencname) { @@ -2951,10 +2947,8 @@ out: return; droplabel: - result = dns_message_firstname(soaquery, DNS_SECTION_QUESTION); - INSIST(result == ISC_R_SUCCESS); - name = NULL; - dns_message_currentname(soaquery, DNS_SECTION_QUESTION, &name); + INSIST(!ISC_LIST_EMPTY(soaquery->sections[DNS_SECTION_QUESTION])); + name = ISC_LIST_HEAD(soaquery->sections[DNS_SECTION_QUESTION]); nlabels = dns_name_countlabels(name); if (nlabels == 1) { fatal("could not find enclosing zone"); @@ -3340,13 +3334,10 @@ recvgss(void *arg) { static void start_update(void) { - isc_result_t result; dns_rdataset_t *rdataset = NULL; dns_name_t *name = NULL; dns_request_t *request = NULL; dns_message_t *soaquery = NULL; - dns_name_t *firstname; - dns_section_t section = DNS_SECTION_UPDATE; ddebug("start_update()"); @@ -3385,12 +3376,17 @@ start_update(void) { dns_name_clone(userzone, name); } else { dns_rdataset_t *tmprdataset; - result = dns_message_firstname(updatemsg, section); - if (result == ISC_R_NOMORE) { + + dns_namelist_t *msg_sections = updatemsg->sections; + dns_section_t section; + + if (!ISC_LIST_EMPTY(msg_sections[DNS_SECTION_UPDATE])) { + section = DNS_SECTION_UPDATE; + } else if (!ISC_LIST_EMPTY( + msg_sections[DNS_SECTION_PREREQUISITE])) + { section = DNS_SECTION_PREREQUISITE; - result = dns_message_firstname(updatemsg, section); - } - if (result != ISC_R_SUCCESS) { + } else { dns_message_puttempname(soaquery, &name); dns_rdataset_disassociate(rdataset); dns_message_puttemprdataset(soaquery, &rdataset); @@ -3398,9 +3394,11 @@ start_update(void) { done_update(); return; } - firstname = NULL; - dns_message_currentname(updatemsg, section, &firstname); + + dns_name_t *firstname = + ISC_LIST_HEAD(updatemsg->sections[section]); dns_name_clone(firstname, name); + /* * Looks to see if the first name references a DS record * and if that name is not the root remove a label as DS diff --git a/bin/plugins/filter-a.c b/bin/plugins/filter-a.c index bccbb76ada..c990206fc4 100644 --- a/bin/plugins/filter-a.c +++ b/bin/plugins/filter-a.c @@ -591,14 +591,8 @@ process_section(const section_filter_t *filter) { bool only_if_aaaa_exists = filter->only_if_aaaa_exists; dns_message_t *message = qctx->client->message; - isc_result_t result; - for (result = dns_message_firstname(message, section); - result == ISC_R_SUCCESS; - result = dns_message_nextname(message, section)) - { - dns_name_t *cur = NULL; - dns_message_currentname(message, section, &cur); + MSG_SECTION_FOREACH (message, section, cur) { if (name != NULL && !dns_name_equal(name, cur)) { /* * We only want to process 'name' and this is not it. diff --git a/bin/plugins/filter-aaaa.c b/bin/plugins/filter-aaaa.c index a1c64d9fa5..dcd5554d16 100644 --- a/bin/plugins/filter-aaaa.c +++ b/bin/plugins/filter-aaaa.c @@ -595,14 +595,8 @@ process_section(const section_filter_t *filter) { bool only_if_a_exists = filter->only_if_a_exists; dns_message_t *message = qctx->client->message; - isc_result_t result; - for (result = dns_message_firstname(message, section); - result == ISC_R_SUCCESS; - result = dns_message_nextname(message, section)) - { - dns_name_t *cur = NULL; - dns_message_currentname(message, section, &cur); + MSG_SECTION_FOREACH (message, section, cur) { if (name != NULL && !dns_name_equal(name, cur)) { /* * We only want to process 'name' and this is not it. diff --git a/bin/tools/mdig.c b/bin/tools/mdig.c index cafaf482c9..a4fa4e1274 100644 --- a/bin/tools/mdig.c +++ b/bin/tools/mdig.c @@ -427,7 +427,6 @@ repopulate_buffer: } CHECK("dns_message_sectiontotext", result); } else if (display_answer) { - dns_name_t *name; dns_rdataset_t *rdataset; isc_result_t loopresult; dns_name_t empty_name; @@ -442,24 +441,9 @@ repopulate_buffer: } dns_name_init(&empty_name); - result = dns_message_firstname(response, DNS_SECTION_ANSWER); - if (result != ISC_R_NOMORE) { - CHECK("dns_message_firstname", result); - } - for (;;) { - if (result == ISC_R_NOMORE) { - break; - } - CHECK("dns_message_nextname", result); - name = NULL; - dns_message_currentname(response, DNS_SECTION_ANSWER, - &name); - - for (rdataset = ISC_LIST_HEAD(name->list); - rdataset != NULL; - rdataset = ISC_LIST_NEXT(rdataset, link)) - { + MSG_SECTION_FOREACH (response, DNS_SECTION_ANSWER, name) { + ISC_LIST_FOREACH (name->list, rdataset, link) { loopresult = dns_rdataset_first(rdataset); while (loopresult == ISC_R_SUCCESS) { dns_rdataset_current(rdataset, &rdata); @@ -481,8 +465,6 @@ repopulate_buffer: isc_buffer_putstr(buf, "\n"); } } - result = dns_message_nextname(response, - DNS_SECTION_ANSWER); } } diff --git a/lib/dns/client.c b/lib/dns/client.c index 0fb9d9012e..1949bd34ab 100644 --- a/lib/dns/client.c +++ b/lib/dns/client.c @@ -824,7 +824,8 @@ client_resfind(resctx_t *rctx, dns_fetchresponse_t *resp) { } while (want_restart); if (send_event) { - while ((name = ISC_LIST_HEAD(rctx->namelist)) != NULL) { + dns_name_t *next_name; + ISC_LIST_FOREACH_SAFE (rctx->namelist, name, link, next_name) { ISC_LIST_UNLINK(rctx->namelist, name, link); ISC_LIST_APPEND(rctx->rev->answerlist, name, link); } @@ -844,7 +845,9 @@ resolve_done(void *arg) { resarg->result = rev->result; resarg->vresult = rev->vresult; - while ((name = ISC_LIST_HEAD(rev->answerlist)) != NULL) { + + dns_name_t *new_name; + ISC_LIST_FOREACH_SAFE (rev->answerlist, name, link, new_name) { ISC_LIST_UNLINK(rev->answerlist, name, link); ISC_LIST_APPEND(*resarg->namelist, name, link); } @@ -1000,15 +1003,17 @@ dns_client_resolve(dns_client_t *client, const dns_name_t *name, void dns_client_freeresanswer(dns_client_t *client, dns_namelist_t *namelist) { - dns_name_t *name; - dns_rdataset_t *rdataset; + dns_name_t *name, *new_name; + dns_rdataset_t *rdataset, *new_rdataset; REQUIRE(DNS_CLIENT_VALID(client)); REQUIRE(namelist != NULL); - while ((name = ISC_LIST_HEAD(*namelist)) != NULL) { + ISC_LIST_FOREACH_SAFE (*namelist, name, link, new_name) { ISC_LIST_UNLINK(*namelist, name, link); - while ((rdataset = ISC_LIST_HEAD(name->list)) != NULL) { + + ISC_LIST_FOREACH_SAFE (name->list, rdataset, link, new_rdataset) + { ISC_LIST_UNLINK(name->list, rdataset, link); putrdataset(client->mctx, &rdataset); } diff --git a/lib/dns/include/dns/message.h b/lib/dns/include/dns/message.h index 178a809ef2..69e2b7b6f3 100644 --- a/lib/dns/include/dns/message.h +++ b/lib/dns/include/dns/message.h @@ -208,6 +208,13 @@ typedef enum dns_message_intent { * additional section. */ /* Obsolete: DNS_MESSAGERENDER_FILTER_AAAA 0x0020 */ +/* clang-format off */ +#define MSG_SECTION_FOREACH(msg, section, elt) \ + for (dns_name_t *elt = ISC_LIST_HEAD((msg)->sections[(section)]); \ + elt != NULL; \ + elt = ISC_LIST_NEXT(elt, link)) +/* clang-format on */ + typedef struct dns_msgblock dns_msgblock_t; typedef struct dns_minttl { diff --git a/lib/dns/message.c b/lib/dns/message.c index b5268f1ce0..e9432a9a46 100644 --- a/lib/dns/message.c +++ b/lib/dns/message.c @@ -1989,9 +1989,7 @@ dns_message_rendersection(dns_message_t *msg, dns_section_t sectionid, return ISC_R_SUCCESS; } - while (name != NULL) { - next_name = ISC_LIST_NEXT(name, link); - + ISC_LIST_FOREACH_SAFE (*section, name, link, next_name) { rdataset = ISC_LIST_HEAD(name->list); while (rdataset != NULL) { next_rdataset = ISC_LIST_NEXT(rdataset, link); @@ -2080,8 +2078,6 @@ dns_message_rendersection(dns_message_t *msg, dns_section_t sectionid, next: rdataset = next_rdataset; } - - name = next_name; } } while (--pass != 0); @@ -2306,11 +2302,9 @@ dns_message_renderreset(dns_message_t *msg) { msg->buffer = NULL; for (size_t i = 0; i < DNS_SECTION_MAX; i++) { - dns_name_t *name = NULL; - msg->cursors[i] = NULL; msg->counts[i] = 0; - ISC_LIST_FOREACH (msg->sections[i], name, link) { + MSG_SECTION_FOREACH (msg, i, name) { dns_rdataset_t *rds = NULL; ISC_LIST_FOREACH (name->list, rds, link) { rds->attributes &= ~DNS_RDATASETATTR_RENDERED; @@ -3305,17 +3299,13 @@ dns_message_sectiontotext(dns_message_t *msg, dns_section_t section, } dns_name_init(&empty_name); - result = dns_message_firstname(msg, section); - if (result != ISC_R_SUCCESS) { + if (ISC_LIST_EMPTY(msg->sections[section])) { goto cleanup; } - if ((sflags & DNS_STYLEFLAG_YAML) != 0) { - msg->indent.count++; - } - do { - dns_name_t *name = NULL; - dns_message_currentname(msg, section, &name); + bool has_yaml = (sflags & DNS_STYLEFLAG_YAML) != 0; + msg->indent.count += has_yaml; + MSG_SECTION_FOREACH (msg, section, name) { dns_rdataset_t *rds = NULL; ISC_LIST_FOREACH (name->list, rds, link) { if (section == DNS_SECTION_ANSWER && @@ -3347,11 +3337,9 @@ dns_message_sectiontotext(dns_message_t *msg, dns_section_t section, goto cleanup; } } - result = dns_message_nextname(msg, section); - } while (result == ISC_R_SUCCESS); - if ((sflags & DNS_STYLEFLAG_YAML) != 0) { - msg->indent.count--; } + msg->indent.count -= has_yaml; + if ((flags & DNS_MESSAGETEXTFLAG_NOHEADERS) == 0 && (flags & DNS_MESSAGETEXTFLAG_NOCOMMENTS) == 0 && (sflags & DNS_STYLEFLAG_YAML) == 0) @@ -5011,13 +4999,7 @@ message_authority_soa_min(dns_message_t *msg, dns_ttl_t *ttlp) { return ISC_R_NOTFOUND; } - for (result = dns_message_firstname(msg, DNS_SECTION_AUTHORITY); - result == ISC_R_SUCCESS; - result = dns_message_nextname(msg, DNS_SECTION_AUTHORITY)) - { - dns_name_t *name = NULL; - dns_message_currentname(msg, DNS_SECTION_AUTHORITY, &name); - + MSG_SECTION_FOREACH (msg, DNS_SECTION_AUTHORITY, name) { dns_rdataset_t *rds = NULL; ISC_LIST_FOREACH (name->list, rds, link) { if ((rds->attributes & DNS_RDATASETATTR_RENDERED) == 0) diff --git a/lib/dns/ncache.c b/lib/dns/ncache.c index bd9c43288b..6c7ee71172 100644 --- a/lib/dns/ncache.c +++ b/lib/dns/ncache.c @@ -126,12 +126,10 @@ addoptout(dns_message_t *message, dns_db_t *cache, dns_dbnode_t *node, dns_rdatatype_t covers, isc_stdtime_t now, dns_ttl_t minttl, dns_ttl_t maxttl, bool optout, bool secure, dns_rdataset_t *addedrdataset) { - isc_result_t result; isc_buffer_t buffer; isc_region_t r; dns_rdataset_t *rdataset; dns_rdatatype_t type; - dns_name_t *name; dns_ttl_t ttl; dns_trust_t trust; dns_rdata_t rdata[DNS_NCACHE_RDATA]; @@ -166,19 +164,12 @@ addoptout(dns_message_t *message, dns_db_t *cache, dns_dbnode_t *node, ttl = maxttl; trust = 0xffff; isc_buffer_init(&buffer, data, sizeof(data)); - if (message->counts[DNS_SECTION_AUTHORITY]) { - result = dns_message_firstname(message, DNS_SECTION_AUTHORITY); - } else { - result = ISC_R_NOMORE; - } - while (result == ISC_R_SUCCESS) { - name = NULL; - dns_message_currentname(message, DNS_SECTION_AUTHORITY, &name); + + MSG_SECTION_FOREACH (message, DNS_SECTION_AUTHORITY, name) { + isc_result_t result = ISC_R_SUCCESS; + if (name->attributes.ncache) { - for (rdataset = ISC_LIST_HEAD(name->list); - rdataset != NULL; - rdataset = ISC_LIST_NEXT(rdataset, link)) - { + ISC_LIST_FOREACH (name->list, rdataset, link) { if ((rdataset->attributes & DNS_RDATASETATTR_NCACHE) == 0) { @@ -249,10 +240,6 @@ addoptout(dns_message_t *message, dns_db_t *cache, dns_dbnode_t *node, } } } - result = dns_message_nextname(message, DNS_SECTION_AUTHORITY); - } - if (result != ISC_R_NOMORE) { - return result; } if (trust == 0xffff) { diff --git a/lib/dns/resolver.c b/lib/dns/resolver.c index 646e702974..11e7b50078 100644 --- a/lib/dns/resolver.c +++ b/lib/dns/resolver.c @@ -4984,9 +4984,7 @@ cleanup_nameservers: */ static bool is_lame(fetchctx_t *fctx, dns_message_t *message) { - dns_name_t *name; dns_rdataset_t *rdataset; - isc_result_t result; if (message->rcode != dns_rcode_noerror && message->rcode != dns_rcode_yxdomain && @@ -5003,13 +5001,8 @@ is_lame(fetchctx_t *fctx, dns_message_t *message) { return false; } - result = dns_message_firstname(message, DNS_SECTION_AUTHORITY); - while (result == ISC_R_SUCCESS) { - name = NULL; - dns_message_currentname(message, DNS_SECTION_AUTHORITY, &name); - for (rdataset = ISC_LIST_HEAD(name->list); rdataset != NULL; - rdataset = ISC_LIST_NEXT(rdataset, link)) - { + MSG_SECTION_FOREACH (message, DNS_SECTION_AUTHORITY, name) { + ISC_LIST_FOREACH (name->list, rdataset, link) { dns_namereln_t namereln; int order; unsigned int labels; @@ -5028,7 +5021,6 @@ is_lame(fetchctx_t *fctx, dns_message_t *message) { } return true; } - result = dns_message_nextname(message, DNS_SECTION_AUTHORITY); } return false; @@ -5068,7 +5060,6 @@ log_formerr(fetchctx_t *fctx, const char *format, ...) { static isc_result_t same_question(fetchctx_t *fctx, dns_message_t *message) { - isc_result_t result; dns_name_t *name = NULL; dns_rdataset_t *rdataset = NULL; @@ -5108,12 +5099,10 @@ same_question(fetchctx_t *fctx, dns_message_t *message) { return DNS_R_FORMERR; } - result = dns_message_firstname(message, DNS_SECTION_QUESTION); - if (result != ISC_R_SUCCESS) { - return result; + if (ISC_LIST_EMPTY(message->sections[DNS_SECTION_QUESTION])) { + return ISC_R_NOMORE; } - - dns_message_currentname(message, DNS_SECTION_QUESTION, &name); + name = ISC_LIST_HEAD(message->sections[DNS_SECTION_QUESTION]); rdataset = ISC_LIST_HEAD(name->list); INSIST(rdataset != NULL); INSIST(ISC_LIST_NEXT(rdataset, link) == NULL); @@ -5323,7 +5312,6 @@ validated(void *arg) { dns_dbnode_t *node = NULL; dns_dbnode_t *nsnode = NULL; dns_fetchresponse_t *hresp = NULL; - dns_name_t *name = NULL; dns_rdataset_t *ardataset = NULL; dns_rdataset_t *asigrdataset = NULL; dns_rdataset_t *rdataset = NULL; @@ -5659,13 +5647,8 @@ answer_response: /* * Cache any SOA/NS/NSEC records that happened to be validated. */ - result = dns_message_firstname(message, DNS_SECTION_AUTHORITY); - while (result == ISC_R_SUCCESS) { - name = NULL; - dns_message_currentname(message, DNS_SECTION_AUTHORITY, &name); - for (rdataset = ISC_LIST_HEAD(name->list); rdataset != NULL; - rdataset = ISC_LIST_NEXT(rdataset, link)) - { + MSG_SECTION_FOREACH (message, DNS_SECTION_AUTHORITY, name) { + ISC_LIST_FOREACH (name->list, rdataset, link) { if ((rdataset->type != dns_rdatatype_ns && rdataset->type != dns_rdatatype_soa && rdataset->type != dns_rdatatype_nsec) || @@ -5673,10 +5656,8 @@ answer_response: { continue; } - for (sigrdataset = ISC_LIST_HEAD(name->list); - sigrdataset != NULL; - sigrdataset = ISC_LIST_NEXT(sigrdataset, link)) - { + + ISC_LIST_FOREACH (name->list, sigrdataset, link) { if (sigrdataset->type != dns_rdatatype_rrsig || sigrdataset->covers != rdataset->type) { @@ -5746,7 +5727,6 @@ answer_response: continue; } } - result = dns_message_nextname(message, DNS_SECTION_AUTHORITY); } /* @@ -5858,11 +5838,10 @@ fctx_log(void *arg, int level, const char *fmt, ...) { static isc_result_t findnoqname(fetchctx_t *fctx, dns_message_t *message, dns_name_t *name, dns_rdatatype_t type, dns_name_t **noqnamep) { - dns_rdataset_t *nrdataset, *next, *sigrdataset; + dns_rdataset_t *nrdataset, *sigrdataset; dns_rdata_rrsig_t rrsig; isc_result_t result; unsigned int labels; - dns_section_t section; dns_name_t *zonename; dns_fixedname_t fzonename; dns_name_t *closest; @@ -5922,22 +5901,13 @@ findnoqname(fetchctx_t *fctx, dns_message_t *message, dns_name_t *name, #define NXND(x) ((x) == ISC_R_SUCCESS) - section = DNS_SECTION_AUTHORITY; - for (result = dns_message_firstname(message, section); - result == ISC_R_SUCCESS; - result = dns_message_nextname(message, section)) - { - dns_name_t *nsec = NULL; - dns_message_currentname(message, section, &nsec); - for (nrdataset = ISC_LIST_HEAD(nsec->list); nrdataset != NULL; - nrdataset = next) - { + MSG_SECTION_FOREACH (message, DNS_SECTION_AUTHORITY, nsec) { + ISC_LIST_FOREACH (nsec->list, nrdataset, link) { bool data = false, exists = false; bool optout = false, unknown = false; bool setclosest = false; bool setnearest = false; - next = ISC_LIST_NEXT(nrdataset, link); if (nrdataset->type != dns_rdatatype_nsec && nrdataset->type != dns_rdatatype_nsec3) { @@ -5969,9 +5939,7 @@ findnoqname(fetchctx_t *fctx, dns_message_t *message, dns_name_t *name, } } } - if (result == ISC_R_NOMORE) { - result = ISC_R_SUCCESS; - } + if (noqname != NULL) { for (sigrdataset = ISC_LIST_HEAD(noqname->list); sigrdataset != NULL; @@ -6495,42 +6463,29 @@ cache_name(fetchctx_t *fctx, dns_name_t *name, dns_message_t *message, static isc_result_t cache_message(fetchctx_t *fctx, dns_message_t *message, dns_adbaddrinfo_t *addrinfo, isc_stdtime_t now) { - isc_result_t result; - dns_section_t section; - dns_name_t *name; - FCTXTRACE("cache_message"); FCTX_ATTR_CLR(fctx, FCTX_ATTR_WANTCACHE); LOCK(&fctx->lock); - for (section = DNS_SECTION_ANSWER; section <= DNS_SECTION_ADDITIONAL; - section++) + isc_result_t result = ISC_R_SUCCESS; + for (dns_section_t section = DNS_SECTION_ANSWER; + section <= DNS_SECTION_ADDITIONAL; section++) { - result = dns_message_firstname(message, section); - while (result == ISC_R_SUCCESS) { - name = NULL; - dns_message_currentname(message, section, &name); + MSG_SECTION_FOREACH (message, section, name) { if (name->attributes.cache) { result = cache_name(fctx, name, message, addrinfo, now); if (result != ISC_R_SUCCESS) { - break; + goto cleanup; } } - result = dns_message_nextname(message, section); } - if (result != ISC_R_NOMORE) { - break; - } - } - if (result == ISC_R_NOMORE) { - result = ISC_R_SUCCESS; } +cleanup: UNLOCK(&fctx->lock); - return result; } @@ -6658,24 +6613,11 @@ ncache_message(fetchctx_t *fctx, dns_message_t *message, /* * Mark all rdatasets as pending. */ - result = dns_message_firstname(message, DNS_SECTION_AUTHORITY); - while (result == ISC_R_SUCCESS) { + MSG_SECTION_FOREACH (message, DNS_SECTION_AUTHORITY, tname) { dns_rdataset_t *trdataset = NULL; - dns_name_t *tname = NULL; - - dns_message_currentname(message, DNS_SECTION_AUTHORITY, - &tname); - for (trdataset = ISC_LIST_HEAD(tname->list); - trdataset != NULL; - trdataset = ISC_LIST_NEXT(trdataset, link)) - { + ISC_LIST_FOREACH (tname->list, trdataset, link) { trdataset->trust = dns_trust_pending_answer; } - result = dns_message_nextname(message, - DNS_SECTION_AUTHORITY); - } - if (result != ISC_R_NOMORE) { - return result; } } @@ -7355,19 +7297,11 @@ cleanup: static void checknamessection(dns_message_t *message, dns_section_t section) { isc_result_t result; - dns_name_t *name; dns_rdata_t rdata = DNS_RDATA_INIT; dns_rdataset_t *rdataset; - for (result = dns_message_firstname(message, section); - result == ISC_R_SUCCESS; - result = dns_message_nextname(message, section)) - { - name = NULL; - dns_message_currentname(message, section, &name); - for (rdataset = ISC_LIST_HEAD(name->list); rdataset != NULL; - rdataset = ISC_LIST_NEXT(rdataset, link)) - { + MSG_SECTION_FOREACH (message, section, name) { + ISC_LIST_FOREACH (name->list, rdataset, link) { for (result = dns_rdataset_first(rdataset); result == ISC_R_SUCCESS; result = dns_rdataset_next(rdataset)) @@ -7552,25 +7486,15 @@ log_zoneversion(unsigned char *version, size_t version_len, unsigned char *nsid, static bool betterreferral(respctx_t *rctx) { - isc_result_t result; - dns_name_t *name; dns_rdataset_t *rdataset; - for (result = dns_message_firstname(rctx->query->rmessage, - DNS_SECTION_AUTHORITY); - result == ISC_R_SUCCESS; - result = dns_message_nextname(rctx->query->rmessage, - DNS_SECTION_AUTHORITY)) - { - name = NULL; - dns_message_currentname(rctx->query->rmessage, - DNS_SECTION_AUTHORITY, &name); + dns_message_t *msg = rctx->query->rmessage; + MSG_SECTION_FOREACH (msg, DNS_SECTION_AUTHORITY, name) { if (!isstrictsubdomain(name, rctx->fctx->domain)) { continue; } - for (rdataset = ISC_LIST_HEAD(name->list); rdataset != NULL; - rdataset = ISC_LIST_NEXT(rdataset, link)) - { + + ISC_LIST_FOREACH (name->list, rdataset, link) { if (rdataset->type == dns_rdatatype_ns) { return true; } @@ -8647,31 +8571,20 @@ rctx_answer_positive(respctx_t *rctx) { */ static void rctx_answer_scan(respctx_t *rctx) { - isc_result_t result; fetchctx_t *fctx = rctx->fctx; dns_rdataset_t *rdataset = NULL; - for (result = dns_message_firstname(rctx->query->rmessage, - DNS_SECTION_ANSWER); - result == ISC_R_SUCCESS; - result = dns_message_nextname(rctx->query->rmessage, - DNS_SECTION_ANSWER)) - { + dns_message_t *msg = rctx->query->rmessage; + MSG_SECTION_FOREACH (msg, DNS_SECTION_ANSWER, name) { int order; unsigned int nlabels; dns_namereln_t namereln; - dns_name_t *name = NULL; - dns_message_currentname(rctx->query->rmessage, - DNS_SECTION_ANSWER, &name); namereln = dns_name_fullcompare(fctx->name, name, &order, &nlabels); switch (namereln) { case dns_namereln_equal: - for (rdataset = ISC_LIST_HEAD(name->list); - rdataset != NULL; - rdataset = ISC_LIST_NEXT(rdataset, link)) - { + ISC_LIST_FOREACH (name->list, rdataset, link) { if (rdataset->type == rctx->type || rctx->type == dns_rdatatype_any) { @@ -8714,10 +8627,7 @@ rctx_answer_scan(respctx_t *rctx) { * there are multiple ones (which there * shouldn't be). */ - for (rdataset = ISC_LIST_HEAD(name->list); - rdataset != NULL; - rdataset = ISC_LIST_NEXT(rdataset, link)) - { + ISC_LIST_FOREACH (name->list, rdataset, link) { if (rdataset->type != dns_rdatatype_dname) { continue; } @@ -8999,17 +8909,9 @@ rctx_answer_dname(respctx_t *rctx) { static void rctx_authority_positive(respctx_t *rctx) { fetchctx_t *fctx = rctx->fctx; - bool done = false; - isc_result_t result; - - result = dns_message_firstname(rctx->query->rmessage, - DNS_SECTION_AUTHORITY); - while (!done && result == ISC_R_SUCCESS) { - dns_name_t *name = NULL; - - dns_message_currentname(rctx->query->rmessage, - DNS_SECTION_AUTHORITY, &name); + dns_message_t *msg = rctx->query->rmessage; + MSG_SECTION_FOREACH (msg, DNS_SECTION_AUTHORITY, name) { if (!name_external(name, dns_rdatatype_ns, fctx)) { dns_rdataset_t *rdataset = NULL; @@ -9017,10 +8919,7 @@ rctx_authority_positive(respctx_t *rctx) { * We expect to find NS or SIG NS rdatasets, and * nothing else. */ - for (rdataset = ISC_LIST_HEAD(name->list); - rdataset != NULL; - rdataset = ISC_LIST_NEXT(rdataset, link)) - { + ISC_LIST_FOREACH (name->list, rdataset, link) { if (rdataset->type == dns_rdatatype_ns || (rdataset->type == dns_rdatatype_rrsig && rdataset->covers == dns_rdatatype_ns)) @@ -9050,13 +8949,10 @@ rctx_authority_positive(respctx_t *rctx) { rdataset, name, check_related, rctx, DNS_RDATASET_MAXADDITIONAL); - done = true; + return; } } } - - result = dns_message_nextname(rctx->query->rmessage, - DNS_SECTION_AUTHORITY); } } @@ -9208,35 +9104,19 @@ rctx_answer_none(respctx_t *rctx) { */ static isc_result_t rctx_authority_negative(respctx_t *rctx) { - isc_result_t result; fetchctx_t *fctx = rctx->fctx; dns_section_t section; dns_rdataset_t *rdataset = NULL; - bool finished = false; section = DNS_SECTION_AUTHORITY; - result = dns_message_firstname(rctx->query->rmessage, section); - if (result != ISC_R_SUCCESS) { - return ISC_R_SUCCESS; - } - - while (!finished) { - dns_name_t *name = NULL; - - dns_message_currentname(rctx->query->rmessage, section, &name); - result = dns_message_nextname(rctx->query->rmessage, section); - if (result != ISC_R_SUCCESS) { - finished = true; - } - + dns_message_t *msg = rctx->query->rmessage; + MSG_SECTION_FOREACH (msg, section, name) { if (!dns_name_issubdomain(name, fctx->domain)) { continue; } - for (rdataset = ISC_LIST_HEAD(name->list); rdataset != NULL; - rdataset = ISC_LIST_NEXT(rdataset, link)) - { + ISC_LIST_FOREACH (name->list, rdataset, link) { dns_rdatatype_t type = rdataset->type; if (dns_rdatatype_issig(rdataset->type)) { type = rdataset->covers; @@ -9371,25 +9251,9 @@ rctx_authority_dnssec(respctx_t *rctx) { isc_result_t result; fetchctx_t *fctx = rctx->fctx; dns_rdataset_t *rdataset = NULL; - bool finished = false; - - result = dns_message_firstname(rctx->query->rmessage, - DNS_SECTION_AUTHORITY); - if (result != ISC_R_SUCCESS) { - return ISC_R_SUCCESS; - } - - while (!finished) { - dns_name_t *name = NULL; - - dns_message_currentname(rctx->query->rmessage, - DNS_SECTION_AUTHORITY, &name); - result = dns_message_nextname(rctx->query->rmessage, - DNS_SECTION_AUTHORITY); - if (result != ISC_R_SUCCESS) { - finished = true; - } + dns_message_t *msg = rctx->query->rmessage; + MSG_SECTION_FOREACH (msg, DNS_SECTION_AUTHORITY, name) { if (!dns_name_issubdomain(name, fctx->domain)) { /* * Invalid name found; preserve it for logging @@ -9400,9 +9264,7 @@ rctx_authority_dnssec(respctx_t *rctx) { continue; } - for (rdataset = ISC_LIST_HEAD(name->list); rdataset != NULL; - rdataset = ISC_LIST_NEXT(rdataset, link)) - { + ISC_LIST_FOREACH (name->list, rdataset, link) { bool checknta = true; bool secure_domain = false; dns_rdatatype_t type = rdataset->type; @@ -9641,26 +9503,18 @@ static void rctx_additional(respctx_t *rctx) { bool rescan; dns_section_t section = DNS_SECTION_ADDITIONAL; - isc_result_t result; again: rescan = false; - for (result = dns_message_firstname(rctx->query->rmessage, section); - result == ISC_R_SUCCESS; - result = dns_message_nextname(rctx->query->rmessage, section)) - { - dns_name_t *name = NULL; + dns_message_t *msg = rctx->query->rmessage; + MSG_SECTION_FOREACH (msg, section, name) { dns_rdataset_t *rdataset; - dns_message_currentname(rctx->query->rmessage, - DNS_SECTION_ADDITIONAL, &name); if (!name->attributes.chase) { continue; } name->attributes.chase = false; - for (rdataset = ISC_LIST_HEAD(name->list); rdataset != NULL; - rdataset = ISC_LIST_NEXT(rdataset, link)) - { + ISC_LIST_FOREACH (name->list, rdataset, link) { if (CHASE(rdataset)) { rdataset->attributes &= ~DNS_RDATASETATTR_CHASE; (void)dns_rdataset_additionaldata( diff --git a/lib/dns/tkey.c b/lib/dns/tkey.c index ecfb21731d..b6a241a6bd 100644 --- a/lib/dns/tkey.c +++ b/lib/dns/tkey.c @@ -154,12 +154,13 @@ add_rdata_to_list(dns_message_t *msg, dns_name_t *name, dns_rdata_t *rdata, static void free_namelist(dns_message_t *msg, dns_namelist_t *namelist) { - dns_name_t *name = NULL; + dns_name_t *name = NULL, *new_name = NULL; - while ((name = ISC_LIST_HEAD(*namelist)) != NULL) { - dns_rdataset_t *set = NULL; + ISC_LIST_FOREACH_SAFE (*namelist, name, link, new_name) { + dns_rdataset_t *set = NULL, *new_set = NULL; ISC_LIST_UNLINK(*namelist, name, link); - while ((set = ISC_LIST_HEAD(name->list)) != NULL) { + + ISC_LIST_FOREACH_SAFE (name->list, set, link, new_set) { ISC_LIST_UNLINK(name->list, set, link); if (dns_rdataset_isassociated(set)) { dns_rdataset_disassociate(set); @@ -371,12 +372,11 @@ dns_tkey_processquery(dns_message_t *msg, dns_tkeyctx_t *tctx, /* * Interpret the question section. */ - result = dns_message_firstname(msg, DNS_SECTION_QUESTION); - if (result != ISC_R_SUCCESS) { + if (ISC_LIST_EMPTY(msg->sections[DNS_SECTION_QUESTION])) { return DNS_R_FORMERR; } - dns_message_currentname(msg, DNS_SECTION_QUESTION, &qname); + qname = ISC_LIST_HEAD(msg->sections[DNS_SECTION_QUESTION]); /* * Look for a TKEY record that matches the question. @@ -508,7 +508,9 @@ dns_tkey_processquery(dns_message_t *msg, dns_tkeyctx_t *tctx, RETERR(dns_message_reply(msg, true)); add_rdata_to_list(msg, keyname, &rdata, 0, &namelist); - while ((name = ISC_LIST_HEAD(namelist)) != NULL) { + + dns_name_t *new_name; + ISC_LIST_FOREACH_SAFE (namelist, name, link, new_name) { ISC_LIST_UNLINK(namelist, name, link); dns_message_addname(msg, name, DNS_SECTION_ANSWER); } @@ -617,30 +619,23 @@ find_tkey(dns_message_t *msg, dns_name_t **name, dns_rdata_t *rdata, int section) { isc_result_t result; - result = dns_message_firstname(msg, section); - while (result == ISC_R_SUCCESS) { + MSG_SECTION_FOREACH (msg, section, cur) { dns_rdataset_t *tkeyset = NULL; - dns_name_t *cur = NULL; - - dns_message_currentname(msg, section, &cur); result = dns_message_findtype(cur, dns_rdatatype_tkey, 0, &tkeyset); if (result == ISC_R_SUCCESS) { result = dns_rdataset_first(tkeyset); if (result != ISC_R_SUCCESS) { - break; + return result; } dns_rdataset_current(tkeyset, rdata); *name = cur; return ISC_R_SUCCESS; } - result = dns_message_nextname(msg, section); } - if (result == ISC_R_NOMORE) { - return ISC_R_NOTFOUND; - } - return result; + + return ISC_R_NOTFOUND; } isc_result_t diff --git a/lib/dns/xfrin.c b/lib/dns/xfrin.c index 294bdb0f47..570abef211 100644 --- a/lib/dns/xfrin.c +++ b/lib/dns/xfrin.c @@ -1794,7 +1794,6 @@ static void xfrin_recv_done(isc_result_t result, isc_region_t *region, void *arg) { dns_xfrin_t *xfr = (dns_xfrin_t *)arg; dns_message_t *msg = NULL; - dns_name_t *name = NULL; const dns_name_t *tsigowner = NULL; isc_buffer_t buffer; @@ -1917,16 +1916,11 @@ xfrin_recv_done(isc_result_t result, isc_region_t *region, void *arg) { goto failure; } - for (result = dns_message_firstname(msg, DNS_SECTION_QUESTION); - result == ISC_R_SUCCESS; - result = dns_message_nextname(msg, DNS_SECTION_QUESTION)) - { + MSG_SECTION_FOREACH (msg, DNS_SECTION_QUESTION, name) { dns_rdataset_t *rds = NULL; LIBDNS_XFRIN_RECV_QUESTION(xfr, xfr->info, msg); - name = NULL; - dns_message_currentname(msg, DNS_SECTION_QUESTION, &name); if (!dns_name_equal(name, &xfr->name)) { xfrin_log(xfr, ISC_LOG_NOTICE, "question name mismatch"); @@ -1948,9 +1942,6 @@ xfrin_recv_done(isc_result_t result, isc_region_t *region, void *arg) { goto failure; } } - if (result != ISC_R_NOMORE) { - goto failure; - } /* * Does the server know about IXFR? If it doesn't we will get @@ -1981,22 +1972,15 @@ xfrin_recv_done(isc_result_t result, isc_region_t *region, void *arg) { goto failure; } - for (result = dns_message_firstname(msg, DNS_SECTION_ANSWER); - result == ISC_R_SUCCESS; - result = dns_message_nextname(msg, DNS_SECTION_ANSWER)) - { + MSG_SECTION_FOREACH (msg, DNS_SECTION_ANSWER, name) { dns_rdataset_t *rds = NULL; LIBDNS_XFRIN_RECV_ANSWER(xfr, xfr->info, msg); - name = NULL; - dns_message_currentname(msg, DNS_SECTION_ANSWER, &name); - for (rds = ISC_LIST_HEAD(name->list); rds != NULL; - rds = ISC_LIST_NEXT(rds, link)) - { - for (result = dns_rdataset_first(rds); - result == ISC_R_SUCCESS; - result = dns_rdataset_next(rds)) + ISC_LIST_FOREACH (name->list, rds, link) { + for (isc_result_t iter = dns_rdataset_first(rds); + iter == ISC_R_SUCCESS; + iter = dns_rdataset_next(rds)) { dns_rdata_t rdata = DNS_RDATA_INIT; dns_rdataset_current(rds, &rdata); @@ -2017,9 +2001,6 @@ xfrin_recv_done(isc_result_t result, isc_region_t *region, void *arg) { } } } - if (result == ISC_R_NOMORE) { - result = ISC_R_SUCCESS; - } CHECK(result); if (dns_message_gettsig(msg, &tsigowner) != NULL) { diff --git a/lib/dns/zone.c b/lib/dns/zone.c index 00f7a9e635..3ae40953ce 100644 --- a/lib/dns/zone.c +++ b/lib/dns/zone.c @@ -13703,9 +13703,7 @@ save_nsrrset(dns_message_t *message, dns_name_t *name, * for each NS entry found in the answer. */ if (!has_glue) { - for (ns_name = ISC_LIST_HEAD(ns_list); ns_name != NULL; - ns_name = ISC_LIST_NEXT(ns_name, link)) - { + ISC_LIST_FOREACH (ns_list, ns_name, link) { /* * Resolve NS IPv4 address/A. */ @@ -13727,8 +13725,9 @@ save_nsrrset(dns_message_t *message, dns_name_t *name, result = ISC_R_SUCCESS; + dns_name_t *new_ns_name; done: - while ((ns_name = ISC_LIST_HEAD(ns_list)) != NULL) { + ISC_LIST_FOREACH_SAFE (ns_list, ns_name, link, new_ns_name) { ISC_LIST_UNLINK(ns_list, ns_name, link); dns_name_free(ns_name, cb_args->stub->mctx); isc_mem_put(cb_args->stub->mctx, ns_name, sizeof(*ns_name)); @@ -16190,24 +16189,15 @@ dnssec_log(dns_zone_t *zone, int level, const char *fmt, ...) { static int message_count(dns_message_t *msg, dns_section_t section, dns_rdatatype_t type) { - isc_result_t result; - dns_name_t *name; dns_rdataset_t *curr; int count = 0; - result = dns_message_firstname(msg, section); - while (result == ISC_R_SUCCESS) { - name = NULL; - dns_message_currentname(msg, section, &name); - - for (curr = ISC_LIST_TAIL(name->list); curr != NULL; - curr = ISC_LIST_PREV(curr, link)) - { + MSG_SECTION_FOREACH (msg, section, name) { + ISC_LIST_FOREACH_REV (name->list, curr, link) { if (curr->type == type) { count++; } } - result = dns_message_nextname(msg, section); } return count; @@ -21142,19 +21132,14 @@ checkds_done(void *arg) { } /* Lookup DS RRset. */ - result = dns_message_firstname(message, DNS_SECTION_ANSWER); - while (result == ISC_R_SUCCESS) { - dns_name_t *name = NULL; - dns_rdataset_t *rdataset; - dns_message_currentname(message, DNS_SECTION_ANSWER, &name); + MSG_SECTION_FOREACH (message, DNS_SECTION_ANSWER, name) { + dns_rdataset_t *rdataset; if (dns_name_compare(&zone->origin, name) != 0) { - goto next; + continue; } - for (rdataset = ISC_LIST_HEAD(name->list); rdataset != NULL; - rdataset = ISC_LIST_NEXT(rdataset, link)) - { + ISC_LIST_FOREACH (name->list, rdataset, link) { if (rdataset->type != dns_rdatatype_ds) { goto next; } @@ -21167,8 +21152,7 @@ checkds_done(void *arg) { break; } - next: - result = dns_message_nextname(message, DNS_SECTION_ANSWER); + next:; } if (ds_rrset == NULL) { diff --git a/lib/ns/notify.c b/lib/ns/notify.c index b973f288c6..4dc5b2b604 100644 --- a/lib/ns/notify.c +++ b/lib/ns/notify.c @@ -88,8 +88,7 @@ ns_notify_start(ns_client_t *client, isc_nmhandle_t *handle) { /* * Interpret the question section. */ - result = dns_message_firstname(request, DNS_SECTION_QUESTION); - if (result != ISC_R_SUCCESS) { + if (ISC_LIST_EMPTY(request->sections[DNS_SECTION_QUESTION])) { notify_log(client, ISC_LOG_NOTICE, "notify question section empty"); result = DNS_R_FORMERR; @@ -99,8 +98,7 @@ ns_notify_start(ns_client_t *client, isc_nmhandle_t *handle) { /* * The question section must contain exactly one question. */ - zonename = NULL; - dns_message_currentname(request, DNS_SECTION_QUESTION, &zonename); + zonename = ISC_LIST_HEAD(request->sections[DNS_SECTION_QUESTION]); zone_rdataset = ISC_LIST_HEAD(zonename->list); if (ISC_LIST_NEXT(zone_rdataset, link) != NULL) { notify_log(client, ISC_LOG_NOTICE, @@ -110,8 +108,7 @@ ns_notify_start(ns_client_t *client, isc_nmhandle_t *handle) { } /* The zone section must have exactly one name. */ - result = dns_message_nextname(request, DNS_SECTION_ZONE); - if (result != ISC_R_NOMORE) { + if (ISC_LIST_NEXT(zonename, link) != NULL) { notify_log(client, ISC_LOG_NOTICE, "notify question section contains multiple RRs"); result = DNS_R_FORMERR; diff --git a/lib/ns/query.c b/lib/ns/query.c index d892f96b49..dba623c794 100644 --- a/lib/ns/query.c +++ b/lib/ns/query.c @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -6025,17 +6026,15 @@ cleanup: static void message_clearrdataset(dns_message_t *msg, unsigned int attr) { unsigned int i; - dns_name_t *name, *next_name; dns_rdataset_t *rds, *next_rds; /* * Clean up name lists by calling the rdataset disassociate function. */ for (i = DNS_SECTION_ANSWER; i < DNS_SECTION_MAX; i++) { - name = ISC_LIST_HEAD(msg->sections[i]); - while (name != NULL) { - next_name = ISC_LIST_NEXT(name, link); - + dns_name_t *name, *next_name; + ISC_LIST_FOREACH_SAFE (msg->sections[i], name, link, next_name) + { rds = ISC_LIST_HEAD(name->list); while (rds != NULL) { next_rds = ISC_LIST_NEXT(rds, link); @@ -6057,8 +6056,6 @@ message_clearrdataset(dns_message_t *msg, unsigned int attr) { } isc_mempool_put(msg->namepool, name); } - - name = next_name; } } } @@ -8795,7 +8792,6 @@ query_addds(query_ctx_t *qctx) { ns_client_t *client = qctx->client; dns_fixedname_t fixed; dns_name_t *fname = NULL; - dns_name_t *rname = NULL; dns_name_t *name; dns_rdataset_t *rdataset = NULL, *sigrdataset = NULL; isc_buffer_t *dbuf, b; @@ -8840,41 +8836,24 @@ query_addds(query_ctx_t *qctx) { goto addnsec3; } - /* - * We've already added the NS record, so if the name's not there, - * we have other problems. - */ - result = dns_message_firstname(client->message, DNS_SECTION_AUTHORITY); - if (result != ISC_R_SUCCESS) { - goto cleanup; - } - /* * Find the delegation in the response message - it is not necessarily * the first name in the AUTHORITY section when wildcard processing is * involved. */ - while (result == ISC_R_SUCCESS) { - rname = NULL; - dns_message_currentname(client->message, DNS_SECTION_AUTHORITY, - &rname); + MSG_SECTION_FOREACH (client->message, DNS_SECTION_AUTHORITY, rname) { result = dns_message_findtype(rname, dns_rdatatype_ns, 0, NULL); if (result == ISC_R_SUCCESS) { + /* + * Add the relevant RRset (DS or NSEC) to the + * delegation. + */ + query_addrrset(qctx, &rname, &rdataset, &sigrdataset, + NULL, DNS_SECTION_AUTHORITY); break; } - result = dns_message_nextname(client->message, - DNS_SECTION_AUTHORITY); } - if (result != ISC_R_SUCCESS) { - goto cleanup; - } - - /* - * Add the relevant RRset (DS or NSEC) to the delegation. - */ - query_addrrset(qctx, &rname, &rdataset, &sigrdataset, NULL, - DNS_SECTION_AUTHORITY); goto cleanup; addnsec3: @@ -11260,7 +11239,6 @@ static void query_glueanswer(query_ctx_t *qctx) { const dns_namelist_t *secs = qctx->client->message->sections; const dns_section_t section = DNS_SECTION_ADDITIONAL; - dns_name_t *name; dns_message_t *msg; dns_rdataset_t *rdataset = NULL; @@ -11272,28 +11250,26 @@ query_glueanswer(query_ctx_t *qctx) { } msg = qctx->client->message; - for (name = ISC_LIST_HEAD(msg->sections[section]); name != NULL; - name = ISC_LIST_NEXT(name, link)) - { + MSG_SECTION_FOREACH (msg, section, name) { if (dns_name_equal(name, qctx->client->query.qname)) { - for (rdataset = ISC_LIST_HEAD(name->list); - rdataset != NULL; - rdataset = ISC_LIST_NEXT(rdataset, link)) - { + ISC_LIST_FOREACH (name->list, rdataset, link) { if (rdataset->type == qctx->qtype) { + ISC_LIST_UNLINK(msg->sections[section], + name, link); + ISC_LIST_PREPEND(msg->sections[section], + name, link); + ISC_LIST_UNLINK(name->list, rdataset, + link); + ISC_LIST_PREPEND(name->list, rdataset, + link); + rdataset->attributes |= + DNS_RDATASETATTR_REQUIRED; break; } } break; } } - if (rdataset != NULL) { - ISC_LIST_UNLINK(msg->sections[section], name, link); - ISC_LIST_PREPEND(msg->sections[section], name, link); - ISC_LIST_UNLINK(name->list, rdataset, link); - ISC_LIST_PREPEND(name->list, rdataset, link); - rdataset->attributes |= DNS_RDATASETATTR_REQUIRED; - } } isc_result_t @@ -11691,25 +11667,21 @@ ns_query_start(ns_client_t *client, isc_nmhandle_t *handle) { /* * Get the question name. */ - result = dns_message_firstname(message, DNS_SECTION_QUESTION); - if (result != ISC_R_SUCCESS) { - query_error(client, result, __LINE__); + if (ISC_LIST_EMPTY(message->sections[DNS_SECTION_QUESTION])) { + query_error(client, ISC_R_NOMORE, __LINE__); return; } - dns_message_currentname(message, DNS_SECTION_QUESTION, - &client->query.qname); + + client->query.qname = + ISC_LIST_HEAD(message->sections[DNS_SECTION_QUESTION]); client->query.origqname = client->query.qname; - result = dns_message_nextname(message, DNS_SECTION_QUESTION); - if (result != ISC_R_NOMORE) { - if (result == ISC_R_SUCCESS) { - /* - * There's more than one QNAME in the question - * section. - */ - query_error(client, DNS_R_FORMERR, __LINE__); - } else { - query_error(client, result, __LINE__); - } + + if (ISC_LIST_NEXT(client->query.qname, link) != NULL) { + /* + * There's more than one QNAME in the question + * section. + */ + query_error(client, DNS_R_FORMERR, __LINE__); return; } diff --git a/lib/ns/update.c b/lib/ns/update.c index 573c9f7b3f..dfb846f229 100644 --- a/lib/ns/update.c +++ b/lib/ns/update.c @@ -1517,14 +1517,12 @@ add_rr_prepare_action(void *data, rr_t *rr) { * 'rdata', and 'ttl', respectively. */ static void -get_current_rr(dns_message_t *msg, dns_section_t section, - dns_rdataclass_t zoneclass, dns_name_t **name, - dns_rdata_t *rdata, dns_rdatatype_t *covers, dns_ttl_t *ttl, +get_current_rr(dns_rdataclass_t zoneclass, dns_name_t *name, dns_rdata_t *rdata, + dns_rdatatype_t *covers, dns_ttl_t *ttl, dns_rdataclass_t *update_class) { dns_rdataset_t *rdataset; isc_result_t result; - dns_message_currentname(msg, section, name); - rdataset = ISC_LIST_HEAD((*name)->list); + rdataset = ISC_LIST_HEAD(name->list); INSIST(rdataset != NULL); INSIST(ISC_LIST_NEXT(rdataset, link) == NULL); *covers = rdataset->covers; @@ -1688,20 +1686,15 @@ send_update(ns_client_t *client, dns_zone_t *zone) { sizeof(*maxbytype)); } - for (update = 0, - result = dns_message_firstname(request, DNS_SECTION_UPDATE); - result == ISC_R_SUCCESS; update++, - result = dns_message_nextname(request, DNS_SECTION_UPDATE)) - { - dns_name_t *name = NULL; + update = 0; + MSG_SECTION_FOREACH (request, DNS_SECTION_UPDATE, name) { dns_rdata_t rdata = DNS_RDATA_INIT; dns_ttl_t ttl; dns_rdataclass_t update_class; INSIST(ssutable == NULL || update < maxbytypelen); - - get_current_rr(request, DNS_SECTION_UPDATE, zoneclass, &name, - &rdata, &covers, &ttl, &update_class); + get_current_rr(zoneclass, name, &rdata, &covers, &ttl, + &update_class); if (!dns_name_issubdomain(name, zonename)) { FAILC(DNS_R_NOTZONE, "update RR is outside zone"); @@ -1859,9 +1852,7 @@ send_update(ns_client_t *client, dns_zone_t *zone) { } } } - } - if (result != ISC_R_NOMORE) { - FAIL(result); + update++; } update_log(client, zone, LOGLEVEL_DEBUG, "update section prescan OK"); @@ -1944,8 +1935,8 @@ ns_update_start(ns_client_t *client, isc_nmhandle_t *handle, /* * Interpret the zone section. */ - result = dns_message_firstname(request, DNS_SECTION_ZONE); - if (result != ISC_R_SUCCESS) { + + if (ISC_LIST_EMPTY(request->sections[DNS_SECTION_ZONE])) { FAILC(DNS_R_FORMERR, "update zone section empty"); } @@ -1953,8 +1944,7 @@ ns_update_start(ns_client_t *client, isc_nmhandle_t *handle, * The zone section must contain exactly one "question", and * it must be of type SOA. */ - zonename = NULL; - dns_message_currentname(request, DNS_SECTION_ZONE, &zonename); + zonename = ISC_LIST_HEAD(request->sections[DNS_SECTION_ZONE]); zone_rdataset = ISC_LIST_HEAD(zonename->list); if (zone_rdataset->type != dns_rdatatype_soa) { FAILC(DNS_R_FORMERR, "update zone section contains non-SOA"); @@ -1965,8 +1955,7 @@ ns_update_start(ns_client_t *client, isc_nmhandle_t *handle, } /* The zone section must have exactly one name. */ - result = dns_message_nextname(request, DNS_SECTION_ZONE); - if (result != ISC_R_NOMORE) { + if (ISC_LIST_NEXT(zonename, link) != NULL) { FAILC(DNS_R_FORMERR, "update zone section contains multiple RRs"); } @@ -2775,18 +2764,14 @@ update_action(void *arg) { * Check prerequisites. */ - for (result = dns_message_firstname(request, DNS_SECTION_PREREQUISITE); - result == ISC_R_SUCCESS; - result = dns_message_nextname(request, DNS_SECTION_PREREQUISITE)) - { - dns_name_t *name = NULL; + MSG_SECTION_FOREACH (request, DNS_SECTION_PREREQUISITE, name) { dns_rdata_t rdata = DNS_RDATA_INIT; dns_ttl_t ttl; dns_rdataclass_t update_class; bool flag; - get_current_rr(request, DNS_SECTION_PREREQUISITE, zoneclass, - &name, &rdata, &covers, &ttl, &update_class); + get_current_rr(zoneclass, name, &rdata, &covers, &ttl, + &update_class); if (ttl != 0) { PREREQFAILC(DNS_R_FORMERR, @@ -2856,9 +2841,6 @@ update_action(void *arg) { PREREQFAILC(DNS_R_FORMERR, "malformed prerequisite"); } } - if (result != ISC_R_NOMORE) { - FAIL(result); - } /* * Perform the final check of the "rrset exists (value dependent)" @@ -2892,12 +2874,9 @@ update_action(void *arg) { * Process the Update Section. */ INSIST(ssutable == NULL || maxbytype != NULL); - for (update = 0, - result = dns_message_firstname(request, DNS_SECTION_UPDATE); - result == ISC_R_SUCCESS; update++, - result = dns_message_nextname(request, DNS_SECTION_UPDATE)) - { - dns_name_t *name = NULL; + + update = 0; + MSG_SECTION_FOREACH (request, DNS_SECTION_UPDATE, name) { dns_rdata_t rdata = DNS_RDATA_INIT; dns_ttl_t ttl; dns_rdataclass_t update_class; @@ -2905,8 +2884,8 @@ update_action(void *arg) { INSIST(ssutable == NULL || update < maxbytypelen); - get_current_rr(request, DNS_SECTION_UPDATE, zoneclass, &name, - &rdata, &covers, &ttl, &update_class); + get_current_rr(zoneclass, name, &rdata, &covers, &ttl, + &update_class); if (update_class == zoneclass) { /* @@ -3254,9 +3233,8 @@ update_action(void *arg) { CHECK(delete_if(rr_equal_p, db, ver, name, rdata.type, covers, &rdata, &diff)); } - } - if (result != ISC_R_NOMORE) { - FAIL(result); + + ++update; } /* diff --git a/lib/ns/xfrout.c b/lib/ns/xfrout.c index 6df1b20559..12350a317b 100644 --- a/lib/ns/xfrout.c +++ b/lib/ns/xfrout.c @@ -15,6 +15,7 @@ #include #include +#include #include #include #include @@ -731,7 +732,6 @@ ns_xfr_start(ns_client_t *client, dns_rdatatype_t reqtype) { rrstream_t *data_stream = NULL; rrstream_t *stream = NULL; dns_difftuple_t *current_soa_tuple = NULL; - dns_name_t *soa_name; dns_rdataset_t *soa_rdataset; dns_rdata_t soa_rdata = DNS_RDATA_INIT; bool have_soa = false; @@ -779,23 +779,21 @@ ns_xfr_start(ns_client_t *client, dns_rdatatype_t reqtype) { /* * Interpret the question section. */ - result = dns_message_firstname(request, DNS_SECTION_QUESTION); - INSIST(result == ISC_R_SUCCESS); + INSIST(!ISC_LIST_EMPTY(request->sections[DNS_SECTION_QUESTION])); /* * The question section must contain exactly one question, and * it must be for AXFR/IXFR as appropriate. */ - question_name = NULL; - dns_message_currentname(request, DNS_SECTION_QUESTION, &question_name); + question_name = ISC_LIST_HEAD(request->sections[DNS_SECTION_QUESTION]); question_rdataset = ISC_LIST_HEAD(question_name->list); question_class = question_rdataset->rdclass; INSIST(question_rdataset->type == reqtype); if (ISC_LIST_NEXT(question_rdataset, link) != NULL) { FAILC(DNS_R_FORMERR, "multiple questions"); } - result = dns_message_nextname(request, DNS_SECTION_QUESTION); - if (result != ISC_R_NOMORE) { + + if (ISC_LIST_NEXT(question_name, link) != NULL) { FAILC(DNS_R_FORMERR, "multiple questions"); } @@ -870,14 +868,7 @@ ns_xfr_start(ns_client_t *client, dns_rdatatype_t reqtype) { * Check the authority section. Look for a SOA record with * the same name and class as the question. */ - for (result = dns_message_firstname(request, DNS_SECTION_AUTHORITY); - result == ISC_R_SUCCESS; - result = dns_message_nextname(request, DNS_SECTION_AUTHORITY)) - { - soa_name = NULL; - dns_message_currentname(request, DNS_SECTION_AUTHORITY, - &soa_name); - + MSG_SECTION_FOREACH (request, DNS_SECTION_AUTHORITY, soa_name) { /* * Ignore data whose owner name is not the zone apex. */ @@ -885,10 +876,7 @@ ns_xfr_start(ns_client_t *client, dns_rdatatype_t reqtype) { continue; } - for (soa_rdataset = ISC_LIST_HEAD(soa_name->list); - soa_rdataset != NULL; - soa_rdataset = ISC_LIST_NEXT(soa_rdataset, link)) - { + ISC_LIST_FOREACH (soa_name->list, soa_rdataset, link) { /* * Ignore non-SOA data. */