]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Refactor to use list-like macro for message sections
authoralessio <alessio@isc.org>
Wed, 19 Mar 2025 19:29:17 +0000 (20:29 +0100)
committerxoranth <xoranth@xoranths-MacBook-Air.local>
Thu, 27 Mar 2025 02:09:46 +0000 (03:09 +0100)
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.

22 files changed:
.clang-format
bin/delv/delv.c
bin/dig/dig.c
bin/dig/dighost.c
bin/dig/host.c
bin/dig/nslookup.c
bin/nsupdate/nsupdate.c
bin/plugins/filter-a.c
bin/plugins/filter-aaaa.c
bin/tools/mdig.c
lib/dns/client.c
lib/dns/include/dns/message.h
lib/dns/message.c
lib/dns/ncache.c
lib/dns/resolver.c
lib/dns/tkey.c
lib/dns/xfrin.c
lib/dns/zone.c
lib/ns/notify.c
lib/ns/query.c
lib/ns/update.c
lib/ns/xfrout.c

index 7bd90052abb56d790ae79d47c45721a657a68222..2e7ab89d69b6a2fc85b4dd328287d9fd4c57ff56 100644 (file)
@@ -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
index c489df8671822a27984eb1da7f46c34f5a5b0f97..f5c4ad997154608067bb63c4f6a4cd6052527219 100644 (file)
@@ -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;
 
index 04aafc44528c754667eaa52d170b262b2b08e7eb..2862eb6b374b036bdcae22ef7c24836a096a031e 100644 (file)
@@ -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;
                }
index 440c3a5c2b76af100710140fce31411a35aa22ed..d92c30a3f93cb87e07021a613d405b18b502cee6 100644 (file)
@@ -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;
+                       }
                }
        }
 
index 4e6dc8d9cdea1b7d4ad5b6bc980bc720d1a2ec29..69d898937c92bc71d7801131d429e069216afd0d 100644 (file)
@@ -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;
index 68116749dd0e591a117fd5f5a8db8379d3319e1b..5001c0dfeb5112a2ad43a00629288b2be589c768 100644 (file)
@@ -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;
 }
index 638024d793d35d4aa51e233e6616b459bc438a11..be1d720c4a0b51f26c4f11af507ab6bf7bb85cb2 100644 (file)
@@ -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
index bccbb76ada6c503bf972b5814ff530ed3fafba9e..c990206fc4976adfe9aaa594eb62f8b6785d200c 100644 (file)
@@ -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.
index a1c64d9fa5e3ec9fd6754215cab7aa0d3a7204ae..dcd5554d1625df6e21ac467e88102fb66ad067bb 100644 (file)
@@ -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.
index cafaf482c97ded4e3fce71c69116230811551bf5..a4fa4e1274bfdb3f459e746b1ba6ca100b6236a5 100644 (file)
@@ -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);
                }
        }
 
index 0fb9d9012e96bb9ac376d73b08fbc29ab137cc51..1949bd34abc44d7dc69f71e609595b641ac4fcc4 100644 (file)
@@ -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);
                }
index 178a809ef28c6bc1dd158b5734e387d93c6fd584..69e2b7b6f353e7a1824bd101cb8583b692d0c902 100644 (file)
@@ -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 {
index b5268f1ce0c20afb8b04c413d894c118a5f73e97..e9432a9a468bffca1f0ff3831c44789eea232c0b 100644 (file)
@@ -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)
index bd9c43288b52219f0a1d2b010d47886c788769fc..6c7ee711720ced7616c853a285ef4916ff06d003 100644 (file)
@@ -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) {
index 646e702974a7bf45b23157636911baeba244a3ce..11e7b500788110eb6eba075c5fa22eac8a48f01e 100644 (file)
@@ -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(
index ecfb21731d2a57aa8cd4a492dea07db8ae01baf0..b6a241a6bdeb7b13a2bdb2d40af0f6a8ef98c234 100644 (file)
@@ -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
index 294bdb0f47fe51ee6bf820214de65816ad98bcdf..570abef2110754e12ba80f50bdbc72b1d0edfb20 100644 (file)
@@ -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) {
index 00f7a9e6352ae0fcd2cfdb5e3d2241f60e1d0b1f..3ae40953ceef59fdd5892a9519be5dac33cc4985 100644 (file)
@@ -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) {
index b973f288c67f6643b703089ecabd8cc26244e214..4dc5b2b604423f188d98a5ace02455fed6b7ea56 100644 (file)
@@ -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;
index d892f96b491a29499d1b74f97834c51b0d224dc0..dba623c7949d5da8ad64f72566ef511aea1357fe 100644 (file)
@@ -22,6 +22,7 @@
 #include <isc/async.h>
 #include <isc/counter.h>
 #include <isc/hex.h>
+#include <isc/list.h>
 #include <isc/log.h>
 #include <isc/mem.h>
 #include <isc/once.h>
@@ -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;
        }
 
index 573c9f7b3fadf0da3311dc0eb5fdfc7f4120c658..dfb846f229839184736f0319c55bcf343fe804ff 100644 (file)
@@ -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;
        }
 
        /*
index 6df1b20559a4dc8d80b6f0123b9e0510f5627255..12350a317b3ce06e4c74c1bf3ef2c35d900bb11d 100644 (file)
@@ -15,6 +15,7 @@
 #include <stdbool.h>
 
 #include <isc/formatcheck.h>
+#include <isc/list.h>
 #include <isc/log.h>
 #include <isc/mem.h>
 #include <isc/netmgr.h>
@@ -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.
                         */