From: Evan Hunt Date: Thu, 20 Mar 2025 22:46:35 +0000 (-0700) Subject: implicitly declare list elements in ISC_LIST_FOREACH macros X-Git-Tag: v9.21.7~9^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5cff8f9017dc025bb5a1922e9b4a1af1b3a5c8d2;p=thirdparty%2Fbind9.git implicitly declare list elements in ISC_LIST_FOREACH macros ISC_LIST_FOREACH and related macros now use 'typeof(list.head)' to declare the list elements automatically; the caller no longer needs to do so. ISC_LIST_FOREACH_SAFE also now implicitly declares its own 'next' pointer, so it only needs three parameters instead of four. --- diff --git a/bin/delv/delv.c b/bin/delv/delv.c index f5c4ad99715..bb57747a654 100644 --- a/bin/delv/delv.c +++ b/bin/delv/delv.c @@ -1840,7 +1840,6 @@ static void resolve_cb(dns_client_t *client, const dns_name_t *query_name, dns_namelist_t *namelist, isc_result_t result) { char namestr[DNS_NAME_FORMATSIZE]; - dns_rdataset_t *rdataset; if (result != ISC_R_SUCCESS && !yaml) { delv_log(ISC_LOG_ERROR, "resolution failed: %s", @@ -1855,9 +1854,9 @@ resolve_cb(dns_client_t *client, const dns_name_t *query_name, printf("records:\n"); } - dns_name_t *response_name; ISC_LIST_FOREACH (*namelist, response_name, link) { - for (rdataset = ISC_LIST_HEAD(response_name->list); + for (dns_rdataset_t *rdataset = + ISC_LIST_HEAD(response_name->list); rdataset != NULL; rdataset = ISC_LIST_NEXT(rdataset, link)) { printdata(rdataset, response_name); @@ -1985,7 +1984,6 @@ recvresponse(void *arg) { } MSG_SECTION_FOREACH (response, DNS_SECTION_ANSWER, name) { - dns_rdataset_t *rdataset = NULL; dns_rdatatype_t prevtype = 0; ISC_LIST_FOREACH (name->list, rdataset, link) { diff --git a/bin/dig/dig.c b/bin/dig/dig.c index 2862eb6b374..b8b6468c696 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_rdataset_t *rdataset; isc_result_t result, loopresult; dns_name_t empty_name; dns_rdata_t rdata = DNS_RDATA_INIT; diff --git a/bin/dig/dighost.c b/bin/dig/dighost.c index 334ad2be8d7..5b4a6edda93 100644 --- a/bin/dig/dighost.c +++ b/bin/dig/dighost.c @@ -3696,7 +3696,6 @@ tcp_connected(isc_nmhandle_t *handle, isc_result_t eresult, void *arg) { static bool check_for_more_data(dig_lookup_t *lookup, dig_query_t *query, dns_message_t *msg, isc_sockaddr_t *peer, int len) { - dns_rdataset_t *rdataset = NULL; dns_rdata_t rdata = DNS_RDATA_INIT; dns_rdata_soa_t soa; uint32_t ixfr_serial = lookup->ixfr_serial, serial; @@ -4255,7 +4254,6 @@ recv_done(isc_nmhandle_t *handle, isc_result_t eresult, isc_region_t *region, } else { match = true; MSG_SECTION_FOREACH (msg, DNS_SECTION_QUESTION, name) { - dns_rdataset_t *rdataset; ISC_LIST_FOREACH (name->list, rdataset, link) { if (l->rdtype != rdataset->type || l->rdclass != rdataset->rdclass || diff --git a/bin/dig/nslookup.c b/bin/dig/nslookup.c index a6b30183f45..f34145f0fa9 100644 --- a/bin/dig/nslookup.c +++ b/bin/dig/nslookup.c @@ -198,7 +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) { - dns_rdataset_t *rdataset = NULL; dns_rdata_t rdata = DNS_RDATA_INIT; char namebuf[DNS_NAME_FORMATSIZE]; @@ -248,7 +247,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) { - dns_rdataset_t *rdataset = NULL; dns_rdata_t rdata = DNS_RDATA_INIT; char namebuf[DNS_NAME_FORMATSIZE]; diff --git a/bin/nsupdate/nsupdate.c b/bin/nsupdate/nsupdate.c index 30bf9a15c36..43f1ed1bfb9 100644 --- a/bin/nsupdate/nsupdate.c +++ b/bin/nsupdate/nsupdate.c @@ -2181,17 +2181,16 @@ evaluate_checksvcb(char *cmdline) { static void setzone(dns_name_t *zonename) { + dns_namelist_t *secs = updatemsg->sections; dns_name_t *name = NULL; - dns_rdataset_t *rdataset = NULL, *next_rds = NULL; - 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_FOREACH_SAFE (name->list, rdataset, link) { ISC_LIST_UNLINK(name->list, rdataset, link); dns_rdataset_disassociate(rdataset); dns_message_puttemprdataset(updatemsg, &rdataset); @@ -2200,6 +2199,8 @@ setzone(dns_name_t *zonename) { } if (zonename != NULL) { + dns_rdataset_t *rdataset = NULL; + dns_message_gettempname(updatemsg, &name); dns_name_clone(zonename, name); dns_message_gettemprdataset(updatemsg, &rdataset); @@ -2824,20 +2825,21 @@ lookforsoa: goto lookforsoa; } - ISC_LIST_FOREACH (rcvmsg->sections[section], name, link) { + ISC_LIST_FOREACH (rcvmsg->sections[section], n, link) { soaset = NULL; - result = dns_message_findtype(name, dns_rdatatype_soa, 0, - &soaset); + result = dns_message_findtype(n, dns_rdatatype_soa, 0, &soaset); if (result == ISC_R_SUCCESS) { + name = n; break; } if (section == DNS_SECTION_ANSWER) { dns_rdataset_t *tset = NULL; - if (dns_message_findtype(name, dns_rdatatype_cname, 0, + if (dns_message_findtype(n, dns_rdatatype_cname, 0, &tset) == ISC_R_SUCCESS || - dns_message_findtype(name, dns_rdatatype_dname, 0, + dns_message_findtype(n, dns_rdatatype_dname, 0, &tset) == ISC_R_SUCCESS) { + name = n; seencname = true; break; } diff --git a/bin/plugins/filter-a.c b/bin/plugins/filter-a.c index c990206fc49..30d01255305 100644 --- a/bin/plugins/filter-a.c +++ b/bin/plugins/filter-a.c @@ -540,14 +540,14 @@ process_name(query_ctx_t *qctx, filter_a_t mode, const dns_name_t *name, dns_rdataset_t *rdataset = NULL, *sigrdataset = NULL; isc_result_t result; bool modified = false; + dns_name_t *n = UNCONST(name); if (only_if_aaaa_exists) { - CHECK(dns_message_findtype(name, dns_rdatatype_aaaa, 0, NULL)); + CHECK(dns_message_findtype(n, dns_rdatatype_aaaa, 0, NULL)); } - (void)dns_message_findtype(name, type, 0, &rdataset); - (void)dns_message_findtype(name, dns_rdatatype_rrsig, type, - &sigrdataset); + (void)dns_message_findtype(n, type, 0, &rdataset); + (void)dns_message_findtype(n, dns_rdatatype_rrsig, type, &sigrdataset); if (rdataset != NULL && (sigrdataset == NULL || !WANTDNSSEC(qctx->client) || diff --git a/bin/plugins/filter-aaaa.c b/bin/plugins/filter-aaaa.c index dcd5554d162..8202a8b0cd3 100644 --- a/bin/plugins/filter-aaaa.c +++ b/bin/plugins/filter-aaaa.c @@ -544,14 +544,14 @@ process_name(query_ctx_t *qctx, filter_aaaa_t mode, const dns_name_t *name, dns_rdataset_t *rdataset = NULL, *sigrdataset = NULL; isc_result_t result; bool modified = false; + dns_name_t *n = UNCONST(name); if (only_if_a_exists) { - CHECK(dns_message_findtype(name, dns_rdatatype_a, 0, NULL)); + CHECK(dns_message_findtype(n, dns_rdatatype_a, 0, NULL)); } - (void)dns_message_findtype(name, type, 0, &rdataset); - (void)dns_message_findtype(name, dns_rdatatype_rrsig, type, - &sigrdataset); + (void)dns_message_findtype(n, type, 0, &rdataset); + (void)dns_message_findtype(n, dns_rdatatype_rrsig, type, &sigrdataset); if (rdataset != NULL && (sigrdataset == NULL || !WANTDNSSEC(qctx->client) || diff --git a/bin/tools/mdig.c b/bin/tools/mdig.c index a4fa4e1274b..f4024c75a9b 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_rdataset_t *rdataset; isc_result_t loopresult; dns_name_t empty_name; dns_rdata_t rdata = DNS_RDATA_INIT; diff --git a/lib/dns/acl.c b/lib/dns/acl.c index d4e7ee81903..07c4881ef53 100644 --- a/lib/dns/acl.c +++ b/lib/dns/acl.c @@ -462,11 +462,7 @@ dns_aclelement_match(const isc_netaddr_t *reqaddr, const dns_name_t *reqsigner, static void dns__acl_destroy_port_transports(dns_acl_t *acl) { - dns_acl_port_transports_t *port_proto = NULL; - dns_acl_port_transports_t *next = NULL; - ISC_LIST_FOREACH_SAFE (acl->ports_and_transports, port_proto, link, - next) - { + ISC_LIST_FOREACH_SAFE (acl->ports_and_transports, port_proto, link) { ISC_LIST_DEQUEUE(acl->ports_and_transports, port_proto, link); isc_mem_put(acl->mctx, port_proto, sizeof(*port_proto)); } diff --git a/lib/dns/client.c b/lib/dns/client.c index 1949bd34abc..113c3b2641d 100644 --- a/lib/dns/client.c +++ b/lib/dns/client.c @@ -824,10 +824,9 @@ client_resfind(resctx_t *rctx, dns_fetchresponse_t *resp) { } while (want_restart); if (send_event) { - 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); + ISC_LIST_FOREACH_SAFE (rctx->namelist, n, link) { + ISC_LIST_UNLINK(rctx->namelist, n, link); + ISC_LIST_APPEND(rctx->rev->answerlist, n, link); } rctx->rev->result = result; @@ -840,14 +839,12 @@ static void resolve_done(void *arg) { dns_clientresume_t *rev = (dns_clientresume_t *)arg; resarg_t *resarg = rev->arg; - dns_name_t *name = NULL; isc_result_t result; resarg->result = rev->result; resarg->vresult = rev->vresult; - dns_name_t *new_name; - ISC_LIST_FOREACH_SAFE (rev->answerlist, name, link, new_name) { + ISC_LIST_FOREACH_SAFE (rev->answerlist, name, link) { ISC_LIST_UNLINK(rev->answerlist, name, link); ISC_LIST_APPEND(*resarg->namelist, name, link); } @@ -1003,20 +1000,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, *new_name; - dns_rdataset_t *rdataset, *new_rdataset; - REQUIRE(DNS_CLIENT_VALID(client)); REQUIRE(namelist != NULL); - ISC_LIST_FOREACH_SAFE (*namelist, name, link, new_name) { + ISC_LIST_FOREACH_SAFE (*namelist, name, link) { ISC_LIST_UNLINK(*namelist, name, link); - ISC_LIST_FOREACH_SAFE (name->list, rdataset, link, new_rdataset) - { + ISC_LIST_FOREACH_SAFE (name->list, rdataset, link) { ISC_LIST_UNLINK(name->list, rdataset, link); putrdataset(client->mctx, &rdataset); } + dns_name_free(name, client->mctx); isc_mem_put(client->mctx, name, sizeof(*name)); } diff --git a/lib/dns/include/dns/message.h b/lib/dns/include/dns/message.h index 69e2b7b6f35..81458aa68c4 100644 --- a/lib/dns/include/dns/message.h +++ b/lib/dns/include/dns/message.h @@ -804,7 +804,7 @@ dns_message_findname(dns_message_t *msg, dns_section_t section, */ isc_result_t -dns_message_findtype(const dns_name_t *name, dns_rdatatype_t type, +dns_message_findtype(dns_name_t *name, dns_rdatatype_t type, dns_rdatatype_t covers, dns_rdataset_t **rdataset); /*%< * Search the name for the specified type. If it is found, *rdataset is diff --git a/lib/dns/message.c b/lib/dns/message.c index 989b0a3832e..099ceb119ea 100644 --- a/lib/dns/message.c +++ b/lib/dns/message.c @@ -442,11 +442,8 @@ msginit(dns_message_t *m) { static void msgresetname(dns_message_t *msg, dns_name_t *name) { - dns_rdataset_t *rds = NULL, *next_rds = NULL; - - ISC_LIST_FOREACH_SAFE (name->list, rds, link, next_rds) { + ISC_LIST_FOREACH_SAFE (name->list, rds, link) { ISC_LIST_UNLINK(name->list, rds, link); - dns__message_putassociatedrdataset(msg, &rds); } } @@ -455,14 +452,9 @@ static void msgresetnames(dns_message_t *msg, unsigned int first_section) { /* Clean up name lists. */ for (size_t i = first_section; i < DNS_SECTION_MAX; i++) { - dns_name_t *name = NULL, *next_name = NULL; - - ISC_LIST_FOREACH_SAFE (msg->sections[i], name, link, next_name) - { + ISC_LIST_FOREACH_SAFE (msg->sections[i], name, link) { ISC_LIST_UNLINK(msg->sections[i], name, link); - msgresetname(msg, name); - dns_message_puttempname(msg, &name); } } @@ -765,8 +757,6 @@ name_match(void *node, const void *key) { static isc_result_t findname(dns_name_t **foundname, const dns_name_t *target, dns_namelist_t *section) { - dns_name_t *name = NULL; - ISC_LIST_FOREACH_REV (*section, name, link) { if (dns_name_equal(name, target)) { if (foundname != NULL) { @@ -801,17 +791,14 @@ rds_match(void *node, const void *key0) { } isc_result_t -dns_message_findtype(const dns_name_t *name, dns_rdatatype_t type, +dns_message_findtype(dns_name_t *name, dns_rdatatype_t type, dns_rdatatype_t covers, dns_rdataset_t **rdatasetp) { - dns_rdataset_t *rds = NULL; - REQUIRE(name != NULL); REQUIRE(rdatasetp == NULL || *rdatasetp == NULL); ISC_LIST_FOREACH_REV (name->list, rds, link) { if (rds->type == type && rds->covers == covers) { SET_IF_NOT_NULL(rdatasetp, rds); - return ISC_R_SUCCESS; } } @@ -923,7 +910,6 @@ getrdata(isc_buffer_t *source, dns_message_t *msg, dns_decompress_t dctx, static void cleanup_name_hashmaps(dns_namelist_t *section) { - dns_name_t *name = NULL; ISC_LIST_FOREACH (*section, name, link) { if (name->hashmap != NULL) { isc_hashmap_destroy(&name->hashmap); @@ -1883,9 +1869,9 @@ update_min_section_ttl(dns_message_t *restrict msg, isc_result_t dns_message_rendersection(dns_message_t *msg, dns_section_t sectionid, unsigned int options) { - dns_namelist_t *section; - dns_name_t *name, *next_name; - dns_rdataset_t *rdataset, *next_rdataset; + dns_namelist_t *section = NULL; + dns_name_t *name = NULL; + dns_rdataset_t *rdataset = NULL; unsigned int count, total; isc_result_t result; isc_buffer_t st; /* for rollbacks */ @@ -1989,24 +1975,20 @@ dns_message_rendersection(dns_message_t *msg, dns_section_t sectionid, return ISC_R_SUCCESS; } - 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); - - if ((rdataset->attributes & + ISC_LIST_FOREACH_SAFE (*section, n, link) { + ISC_LIST_FOREACH_SAFE (n->list, rds, link) { + if ((rds->attributes & DNS_RDATASETATTR_RENDERED) != 0) { - goto next; + continue; } if (((options & DNS_MESSAGERENDER_ORDERED) == 0) && (sectionid == DNS_SECTION_ADDITIONAL) && - wrong_priority(rdataset, pass, - preferred_glue)) + wrong_priority(rds, pass, preferred_glue)) { - goto next; + continue; } st = *(msg->buffer); @@ -2014,14 +1996,12 @@ dns_message_rendersection(dns_message_t *msg, dns_section_t sectionid, count = 0; if (partial) { result = dns_rdataset_towirepartial( - rdataset, name, msg->cctx, - msg->buffer, rd_options, &count, - NULL); + rds, n, msg->cctx, msg->buffer, + rd_options, &count, NULL); } else { result = dns_rdataset_towire( - rdataset, name, msg->cctx, - msg->buffer, rd_options, - &count); + rds, n, msg->cctx, msg->buffer, + rd_options, &count); } total += count; @@ -2059,24 +2039,19 @@ dns_message_rendersection(dns_message_t *msg, dns_section_t sectionid, * If we have rendered non-validated data, * ensure that the AD bit is not set. */ - if (rdataset->trust != dns_trust_secure && + if (rds->trust != dns_trust_secure && (sectionid == DNS_SECTION_ANSWER || sectionid == DNS_SECTION_AUTHORITY)) { msg->flags &= ~DNS_MESSAGEFLAG_AD; } - if (OPTOUT(rdataset)) { + if (OPTOUT(rds)) { msg->flags &= ~DNS_MESSAGEFLAG_AD; } - update_min_section_ttl(msg, sectionid, - rdataset); - - rdataset->attributes |= - DNS_RDATASETATTR_RENDERED; + update_min_section_ttl(msg, sectionid, rds); - next: - rdataset = next_rdataset; + rds->attributes |= DNS_RDATASETATTR_RENDERED; } } } while (--pass != 0); @@ -2305,7 +2280,6 @@ dns_message_renderreset(dns_message_t *msg) { msg->cursors[i] = NULL; msg->counts[i] = 0; MSG_SECTION_FOREACH (msg, i, name) { - dns_rdataset_t *rds = NULL; ISC_LIST_FOREACH (name->list, rds, link) { rds->attributes &= ~DNS_RDATASETATTR_RENDERED; } @@ -3306,7 +3280,6 @@ dns_message_sectiontotext(dns_message_t *msg, dns_section_t section, 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 && rds->type == dns_rdatatype_soa) @@ -4997,7 +4970,6 @@ message_authority_soa_min(dns_message_t *msg, dns_ttl_t *ttlp) { } 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 6c7ee711720..9b319d7d059 100644 --- a/lib/dns/ncache.c +++ b/lib/dns/ncache.c @@ -128,7 +128,6 @@ addoptout(dns_message_t *message, dns_db_t *cache, dns_dbnode_t *node, dns_rdataset_t *addedrdataset) { isc_buffer_t buffer; isc_region_t r; - dns_rdataset_t *rdataset; dns_rdatatype_t type; dns_ttl_t ttl; dns_trust_t trust; diff --git a/lib/dns/request.c b/lib/dns/request.c index 3b30599a491..3d8521c0fc7 100644 --- a/lib/dns/request.c +++ b/lib/dns/request.c @@ -172,10 +172,9 @@ dns_requestmgr_create(isc_mem_t *mctx, isc_loopmgr_t *loopmgr, static void requests_shutdown(void *arg) { dns_requestmgr_t *requestmgr = arg; - dns_request_t *request = NULL, *next = NULL; uint32_t tid = isc_tid(); - ISC_LIST_FOREACH_SAFE (requestmgr->requests[tid], request, link, next) { + ISC_LIST_FOREACH_SAFE (requestmgr->requests[tid], request, link) { req_log(ISC_LOG_DEBUG(3), "%s(%" PRIu32 ": request %p", __func__, tid, request); if (DNS_REQUEST_COMPLETE(request)) { diff --git a/lib/dns/resolver.c b/lib/dns/resolver.c index 11e7b500788..eb8c7e6c8a3 100644 --- a/lib/dns/resolver.c +++ b/lib/dns/resolver.c @@ -4984,8 +4984,6 @@ cleanup_nameservers: */ static bool is_lame(fetchctx_t *fctx, dns_message_t *message) { - dns_rdataset_t *rdataset; - if (message->rcode != dns_rcode_noerror && message->rcode != dns_rcode_yxdomain && message->rcode != dns_rcode_nxdomain) @@ -5314,8 +5312,6 @@ validated(void *arg) { dns_fetchresponse_t *hresp = NULL; dns_rdataset_t *ardataset = NULL; dns_rdataset_t *asigrdataset = NULL; - dns_rdataset_t *rdataset = NULL; - dns_rdataset_t *sigrdataset = NULL; dns_resolver_t *res = NULL; dns_valarg_t *valarg = NULL; fetchctx_t *fctx = NULL; @@ -5649,6 +5645,8 @@ answer_response: */ MSG_SECTION_FOREACH (message, DNS_SECTION_AUTHORITY, name) { ISC_LIST_FOREACH (name->list, rdataset, link) { + dns_rdataset_t *sigrdataset = NULL; + if ((rdataset->type != dns_rdatatype_ns && rdataset->type != dns_rdatatype_soa && rdataset->type != dns_rdatatype_nsec) || @@ -5657,13 +5655,13 @@ answer_response: continue; } - ISC_LIST_FOREACH (name->list, sigrdataset, link) { - if (sigrdataset->type != dns_rdatatype_rrsig || - sigrdataset->covers != rdataset->type) + ISC_LIST_FOREACH (name->list, s, link) { + if (s->type == dns_rdatatype_rrsig && + s->covers == rdataset->type) { - continue; + sigrdataset = s; + break; } - break; } if (sigrdataset == NULL || sigrdataset->trust != dns_trust_secure) @@ -5838,7 +5836,7 @@ 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, *sigrdataset; + dns_rdataset_t *sigrdataset = NULL; dns_rdata_rrsig_t rrsig; isc_result_t result; unsigned int labels; @@ -5858,12 +5856,9 @@ findnoqname(fetchctx_t *fctx, dns_message_t *message, dns_name_t *name, /* * Find the SIG for this rdataset, if we have it. */ - for (sigrdataset = ISC_LIST_HEAD(name->list); sigrdataset != NULL; - sigrdataset = ISC_LIST_NEXT(sigrdataset, link)) - { - if (sigrdataset->type == dns_rdatatype_rrsig && - sigrdataset->covers == type) - { + ISC_LIST_FOREACH (name->list, sig, link) { + if (sig->type == dns_rdatatype_rrsig && sig->covers == type) { + sigrdataset = sig; break; } } @@ -6614,7 +6609,6 @@ ncache_message(fetchctx_t *fctx, dns_message_t *message, * Mark all rdatasets as pending. */ MSG_SECTION_FOREACH (message, DNS_SECTION_AUTHORITY, tname) { - dns_rdataset_t *trdataset = NULL; ISC_LIST_FOREACH (tname->list, trdataset, link) { trdataset->trust = dns_trust_pending_answer; } @@ -7296,16 +7290,13 @@ cleanup: static void checknamessection(dns_message_t *message, dns_section_t section) { - isc_result_t result; - dns_rdata_t rdata = DNS_RDATA_INIT; - dns_rdataset_t *rdataset; - MSG_SECTION_FOREACH (message, section, name) { ISC_LIST_FOREACH (name->list, rdataset, link) { - for (result = dns_rdataset_first(rdataset); + for (isc_result_t result = dns_rdataset_first(rdataset); result == ISC_R_SUCCESS; result = dns_rdataset_next(rdataset)) { + dns_rdata_t rdata = DNS_RDATA_INIT; dns_rdataset_current(rdataset, &rdata); if (!dns_rdata_checkowner(name, rdata.rdclass, rdata.type, false) || @@ -7314,7 +7305,6 @@ checknamessection(dns_message_t *message, dns_section_t section) { rdataset->attributes |= DNS_RDATASETATTR_CHECKNAMES; } - dns_rdata_reset(&rdata); } } } @@ -7486,9 +7476,8 @@ log_zoneversion(unsigned char *version, size_t version_len, unsigned char *nsid, static bool betterreferral(respctx_t *rctx) { - dns_rdataset_t *rdataset; - dns_message_t *msg = rctx->query->rmessage; + MSG_SECTION_FOREACH (msg, DNS_SECTION_AUTHORITY, name) { if (!isstrictsubdomain(name, rctx->fctx->domain)) { continue; @@ -8572,9 +8561,8 @@ rctx_answer_positive(respctx_t *rctx) { static void rctx_answer_scan(respctx_t *rctx) { fetchctx_t *fctx = rctx->fctx; - dns_rdataset_t *rdataset = NULL; - dns_message_t *msg = rctx->query->rmessage; + MSG_SECTION_FOREACH (msg, DNS_SECTION_ANSWER, name) { int order; unsigned int nlabels; @@ -8913,8 +8901,6 @@ rctx_authority_positive(respctx_t *rctx) { 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; - /* * We expect to find NS or SIG NS rdatasets, and * nothing else. @@ -9106,7 +9092,6 @@ static isc_result_t rctx_authority_negative(respctx_t *rctx) { fetchctx_t *fctx = rctx->fctx; dns_section_t section; - dns_rdataset_t *rdataset = NULL; section = DNS_SECTION_AUTHORITY; @@ -9250,7 +9235,6 @@ static isc_result_t rctx_authority_dnssec(respctx_t *rctx) { isc_result_t result; fetchctx_t *fctx = rctx->fctx; - dns_rdataset_t *rdataset = NULL; dns_message_t *msg = rctx->query->rmessage; MSG_SECTION_FOREACH (msg, DNS_SECTION_AUTHORITY, name) { @@ -9509,7 +9493,6 @@ again: dns_message_t *msg = rctx->query->rmessage; MSG_SECTION_FOREACH (msg, section, name) { - dns_rdataset_t *rdataset; if (!name->attributes.chase) { continue; } diff --git a/lib/dns/tkey.c b/lib/dns/tkey.c index b6a241a6bde..bf137aa69c2 100644 --- a/lib/dns/tkey.c +++ b/lib/dns/tkey.c @@ -154,13 +154,9 @@ 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, *new_name = NULL; - - ISC_LIST_FOREACH_SAFE (*namelist, name, link, new_name) { - dns_rdataset_t *set = NULL, *new_set = NULL; + ISC_LIST_FOREACH_SAFE (*namelist, name, link) { ISC_LIST_UNLINK(*namelist, name, link); - - ISC_LIST_FOREACH_SAFE (name->list, set, link, new_set) { + ISC_LIST_FOREACH_SAFE (name->list, set, link) { ISC_LIST_UNLINK(name->list, set, link); if (dns_rdataset_isassociated(set)) { dns_rdataset_disassociate(set); @@ -354,7 +350,7 @@ dns_tkey_processquery(dns_message_t *msg, dns_tkeyctx_t *tctx, dns_tsigkeyring_t *ring) { isc_result_t result = ISC_R_SUCCESS; dns_rdata_tkey_t tkeyin, tkeyout; - dns_name_t *qname = NULL, *name = NULL; + dns_name_t *qname = NULL; dns_name_t *keyname = NULL, *signer = NULL; dns_name_t tsigner = DNS_NAME_INITEMPTY; dns_fixedname_t fkeyname; @@ -378,11 +374,10 @@ dns_tkey_processquery(dns_message_t *msg, dns_tkeyctx_t *tctx, qname = ISC_LIST_HEAD(msg->sections[DNS_SECTION_QUESTION]); - /* - * Look for a TKEY record that matches the question. + /* * Look for a TKEY record that matches the question. */ result = dns_message_findname(msg, DNS_SECTION_ADDITIONAL, qname, - dns_rdatatype_tkey, 0, &name, &tkeyset); + dns_rdatatype_tkey, 0, NULL, &tkeyset); if (result != ISC_R_SUCCESS) { result = DNS_R_FORMERR; tkey_log("dns_tkey_processquery: couldn't find a TKEY " @@ -509,8 +504,7 @@ 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); - dns_name_t *new_name; - ISC_LIST_FOREACH_SAFE (namelist, name, link, new_name) { + ISC_LIST_FOREACH_SAFE (namelist, name, link) { ISC_LIST_UNLINK(namelist, name, link); dns_message_addname(msg, name, DNS_SECTION_ANSWER); } diff --git a/lib/dns/xfrin.c b/lib/dns/xfrin.c index 570abef2110..6751c9c99f5 100644 --- a/lib/dns/xfrin.c +++ b/lib/dns/xfrin.c @@ -1973,8 +1973,6 @@ xfrin_recv_done(isc_result_t result, isc_region_t *region, void *arg) { } MSG_SECTION_FOREACH (msg, DNS_SECTION_ANSWER, name) { - dns_rdataset_t *rds = NULL; - LIBDNS_XFRIN_RECV_ANSWER(xfr, xfr->info, msg); ISC_LIST_FOREACH (name->list, rds, link) { diff --git a/lib/dns/zone.c b/lib/dns/zone.c index 3ae40953cee..639e595cc77 100644 --- a/lib/dns/zone.c +++ b/lib/dns/zone.c @@ -13597,7 +13597,7 @@ save_nsrrset(dns_message_t *message, dns_name_t *name, isc_result_t result; dns_rdata_t rdata = DNS_RDATA_INIT; bool has_glue = false; - dns_name_t *ns_name; + /* * List of NS entries in answer, keep names that will be used * to resolve missing A/AAAA glue for each entry. @@ -13725,9 +13725,8 @@ save_nsrrset(dns_message_t *message, dns_name_t *name, result = ISC_R_SUCCESS; - dns_name_t *new_ns_name; done: - ISC_LIST_FOREACH_SAFE (ns_list, ns_name, link, new_ns_name) { + ISC_LIST_FOREACH_SAFE (ns_list, ns_name, link) { 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)); @@ -16189,7 +16188,6 @@ 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) { - dns_rdataset_t *curr; int count = 0; MSG_SECTION_FOREACH (msg, section, name) { @@ -21134,7 +21132,6 @@ checkds_done(void *arg) { /* Lookup DS RRset. */ MSG_SECTION_FOREACH (message, DNS_SECTION_ANSWER, name) { - dns_rdataset_t *rdataset; if (dns_name_compare(&zone->origin, name) != 0) { continue; } diff --git a/lib/isc/httpd.c b/lib/isc/httpd.c index 320d72e6503..c2b74a0ead3 100644 --- a/lib/isc/httpd.c +++ b/lib/isc/httpd.c @@ -290,8 +290,7 @@ destroy_httpdmgr(isc_httpdmgr_t *httpdmgr) { * Clear out the list of all actions we know about. Just free the * memory. */ - isc_httpdurl_t *url, *next; - ISC_LIST_FOREACH_SAFE (httpdmgr->urls, url, link, next) { + ISC_LIST_FOREACH_SAFE (httpdmgr->urls, url, link) { isc_mem_free(httpdmgr->mctx, url->url); ISC_LIST_UNLINK(httpdmgr->urls, url, link); isc_mem_put(httpdmgr->mctx, url, sizeof(isc_httpdurl_t)); @@ -780,8 +779,9 @@ prepare_response(void *arg) { } LOCK(&mgr->lock); - ISC_LIST_FOREACH (mgr->urls, url, link) { - if (strncmp(path, url->url, path_len) == 0) { + ISC_LIST_FOREACH (mgr->urls, u, link) { + if (strncmp(path, u->url, path_len) == 0) { + url = u; break; } } @@ -978,8 +978,7 @@ isc_httpdmgr_shutdown(isc_httpdmgr_t **httpdmgrp) { LOCK(&httpdmgr->lock); - isc_httpd_t *httpd = NULL, *next = NULL; - ISC_LIST_FOREACH_SAFE (httpdmgr->running, httpd, link, next) { + ISC_LIST_FOREACH_SAFE (httpdmgr->running, httpd, link) { if (httpd->handle != NULL) { httpd_request(httpd->handle, ISC_R_SUCCESS, NULL, httpd); diff --git a/lib/isc/include/isc/list.h b/lib/isc/include/isc/list.h index 9668e89f989..fd18a01d648 100644 --- a/lib/isc/include/isc/list.h +++ b/lib/isc/include/isc/list.h @@ -230,29 +230,33 @@ } /* clang-format off */ -#define ISC_LIST_FOREACH(list, elt, link) \ - for (elt = ISC_LIST_HEAD(list); \ - elt != NULL; \ +#define ISC_LIST_FOREACH(list, elt, link) \ + for (typeof((list).head) elt = ISC_LIST_HEAD(list); \ + elt != NULL; \ elt = ISC_LIST_NEXT(elt, link)) /* clang-format on */ /* clang-format off */ -#define ISC_LIST_FOREACH_SAFE(list, elt, link, next) \ - for (elt = ISC_LIST_HEAD(list), next = (elt != NULL) ? ISC_LIST_NEXT(elt, link) : NULL; \ - elt != NULL; \ - elt = next, next = (elt != NULL) ? ISC_LIST_NEXT(elt, link) : NULL) +#define ISC_LIST_FOREACH_SAFE(list, elt, link) \ + for (typeof((list).head) elt = ISC_LIST_HEAD(list), \ + elt##_next = (elt != NULL) ? ISC_LIST_NEXT(elt, link) : NULL; \ + elt != NULL; \ + elt = elt##_next, \ + elt##_next = (elt != NULL) ? ISC_LIST_NEXT(elt, link) : NULL) /* clang-format on */ /* clang-format off */ -#define ISC_LIST_FOREACH_REV(list, elt, link) \ - for (elt = ISC_LIST_TAIL(list); \ - elt != NULL; \ +#define ISC_LIST_FOREACH_REV(list, elt, link) \ + for (typeof((list).tail) elt = ISC_LIST_TAIL(list); \ + elt != NULL; \ elt = ISC_LIST_PREV(elt, link)) /* clang-format on */ /* clang-format off */ -#define ISC_LIST_FOREACH_REV_SAFE(list, elt, link, prev) \ - for (elt = ISC_LIST_TAIL(list), prev = (elt != NULL) ? ISC_LIST_PREV(elt, link) : NULL; \ - elt != NULL; \ - elt = prev, prev = (elt != NULL) ? ISC_LIST_PREV(elt, link) : NULL) +#define ISC_LIST_FOREACH_REV_SAFE(list, elt, link) \ + for (typeof((list).tail) elt = ISC_LIST_TAIL(list), \ + elt##_prev = (elt != NULL) ? ISC_LIST_PREV(elt, link) : NULL; \ + elt != NULL; \ + elt = elt##_prev, \ + elt##_prev = (elt != NULL) ? ISC_LIST_PREV(elt, link) : NULL) /* clang-format on */ diff --git a/lib/isc/log.c b/lib/isc/log.c index 576e6b4150f..8222a85552b 100644 --- a/lib/isc/log.c +++ b/lib/isc/log.c @@ -437,9 +437,7 @@ isc_logconfig_destroy(isc_logconfig_t **lcfgp) { } for (size_t i = 0; i < ARRAY_SIZE(lcfg->channellists); i++) { - isc_logchannellist_t *item = NULL, *next = NULL; - ISC_LIST_FOREACH_SAFE (lcfg->channellists[i], item, link, next) - { + ISC_LIST_FOREACH_SAFE (lcfg->channellists[i], item, link) { ISC_LIST_UNLINK(lcfg->channellists[i], item, link); isc_mem_put(mctx, item, sizeof(*item)); } diff --git a/lib/ns/query.c b/lib/ns/query.c index dba623c7949..75228db6c15 100644 --- a/lib/ns/query.c +++ b/lib/ns/query.c @@ -6032,9 +6032,7 @@ message_clearrdataset(dns_message_t *msg, unsigned int attr) { * Clean up name lists by calling the rdataset disassociate function. */ for (i = DNS_SECTION_ANSWER; i < DNS_SECTION_MAX; i++) { - dns_name_t *name, *next_name; - ISC_LIST_FOREACH_SAFE (msg->sections[i], name, link, next_name) - { + ISC_LIST_FOREACH_SAFE (msg->sections[i], name, link) { rds = ISC_LIST_HEAD(name->list); while (rds != NULL) { next_rds = ISC_LIST_NEXT(rds, link); @@ -11240,7 +11238,6 @@ query_glueanswer(query_ctx_t *qctx) { const dns_namelist_t *secs = qctx->client->message->sections; const dns_section_t section = DNS_SECTION_ADDITIONAL; dns_message_t *msg; - dns_rdataset_t *rdataset = NULL; if (!ISC_LIST_EMPTY(secs[DNS_SECTION_ANSWER]) || qctx->client->message->rcode != dns_rcode_noerror || diff --git a/lib/ns/xfrout.c b/lib/ns/xfrout.c index 12350a317b3..e5b1895b74b 100644 --- a/lib/ns/xfrout.c +++ b/lib/ns/xfrout.c @@ -732,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_rdataset_t *soa_rdataset; dns_rdata_t soa_rdata = DNS_RDATA_INIT; bool have_soa = false; const char *mnemonic = NULL;