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
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))
{
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;
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;
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);
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;
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;
}
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;
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,
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;
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);
}
} 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))
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;
+ }
}
}
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;
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;
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;
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];
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) {
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;
}
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];
}
}
- 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);
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);
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;
}
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);
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);
break;
}
}
-
- result = dns_message_nextname(rcvmsg, section);
}
if (soaset == NULL && !seencname) {
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");
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()");
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);
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
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.
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.
}
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;
}
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);
isc_buffer_putstr(buf, "\n");
}
}
- result = dns_message_nextname(response,
- DNS_SECTION_ANSWER);
}
}
} 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);
}
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);
}
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);
}
* 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 {
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);
next:
rdataset = next_rdataset;
}
-
- name = next_name;
}
} while (--pass != 0);
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;
}
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 &&
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)
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)
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];
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)
{
}
}
}
- result = dns_message_nextname(message, DNS_SECTION_AUTHORITY);
- }
- if (result != ISC_R_NOMORE) {
- return result;
}
if (trust == 0xffff) {
*/
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 &&
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;
}
return true;
}
- result = dns_message_nextname(message, DNS_SECTION_AUTHORITY);
}
return false;
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;
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);
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;
/*
* 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) ||
{
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)
{
continue;
}
}
- result = dns_message_nextname(message, DNS_SECTION_AUTHORITY);
}
/*
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;
#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)
{
}
}
}
- if (result == ISC_R_NOMORE) {
- result = ISC_R_SUCCESS;
- }
+
if (noqname != NULL) {
for (sigrdataset = ISC_LIST_HEAD(noqname->list);
sigrdataset != NULL;
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;
}
/*
* 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;
}
}
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))
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;
}
*/
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)
{
* 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;
}
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;
* 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))
rdataset, name, check_related,
rctx,
DNS_RDATASET_MAXADDITIONAL);
- done = true;
+ return;
}
}
}
-
- result = dns_message_nextname(rctx->query->rmessage,
- DNS_SECTION_AUTHORITY);
}
}
*/
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;
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
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;
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(
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);
/*
* 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.
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);
}
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
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;
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");
goto failure;
}
}
- if (result != ISC_R_NOMORE) {
- goto failure;
- }
/*
* Does the server know about IXFR? If it doesn't we will get
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);
}
}
}
- if (result == ISC_R_NOMORE) {
- result = ISC_R_SUCCESS;
- }
CHECK(result);
if (dns_message_gettsig(msg, &tsigowner) != NULL) {
* 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.
*/
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));
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;
}
/* 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;
}
break;
}
- next:
- result = dns_message_nextname(message, DNS_SECTION_ANSWER);
+ next:;
}
if (ds_rrset == NULL) {
/*
* 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;
/*
* 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,
}
/* 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;
#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>
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);
}
isc_mempool_put(msg->namepool, name);
}
-
- name = next_name;
}
}
}
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;
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:
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;
}
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
/*
* 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;
}
* '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;
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");
}
}
}
- }
- if (result != ISC_R_NOMORE) {
- FAIL(result);
+ update++;
}
update_log(client, zone, LOGLEVEL_DEBUG, "update section prescan OK");
/*
* 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");
}
* 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");
}
/* 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");
}
* 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,
PREREQFAILC(DNS_R_FORMERR, "malformed prerequisite");
}
}
- if (result != ISC_R_NOMORE) {
- FAIL(result);
- }
/*
* Perform the final check of the "rrset exists (value dependent)"
* 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;
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) {
/*
CHECK(delete_if(rr_equal_p, db, ver, name, rdata.type,
covers, &rdata, &diff));
}
- }
- if (result != ISC_R_NOMORE) {
- FAIL(result);
+
+ ++update;
}
/*
#include <stdbool.h>
#include <isc/formatcheck.h>
+#include <isc/list.h>
#include <isc/log.h>
#include <isc/mem.h>
#include <isc/netmgr.h>
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;
/*
* 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");
}
* 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.
*/
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.
*/