CHECK(dns_client_setservers(client, dns_rdataclass_in, name, &servers));
cleanup:
- while (!ISC_LIST_EMPTY(servers)) {
- sa = ISC_LIST_HEAD(servers);
- ISC_LIST_UNLINK(servers, sa, link);
- isc_mem_put(mctx, sa, sizeof(*sa));
+ ISC_LIST_FOREACH_SAFE (servers, s, link) {
+ ISC_LIST_UNLINK(servers, s, link);
+ isc_mem_put(mctx, s, sizeof(*s));
}
if (result != ISC_R_SUCCESS) {
void
flush_server_list(void) {
- dig_server_t *s, *ps;
-
debug("flush_server_list()");
- s = ISC_LIST_HEAD(server_list);
- while (s != NULL) {
- ps = s;
- s = ISC_LIST_NEXT(s, link);
- ISC_LIST_DEQUEUE(server_list, ps, link);
- isc_mem_free(mctx, ps);
+ ISC_LIST_FOREACH_SAFE (server_list, s, link) {
+ ISC_LIST_DEQUEUE(server_list, s, link);
+ isc_mem_free(mctx, s);
}
}
*/
void
clone_server_list(dig_serverlist_t src, dig_serverlist_t *dest) {
- dig_server_t *srv, *newsrv;
-
debug("clone_server_list()");
- srv = ISC_LIST_HEAD(src);
- while (srv != NULL) {
- newsrv = make_server(srv->servername, srv->userarg);
+ ISC_LIST_FOREACH_SAFE (src, srv, link) {
+ dig_server_t *newsrv = make_server(srv->servername,
+ srv->userarg);
ISC_LINK_INIT(newsrv, link);
ISC_LIST_ENQUEUE(*dest, newsrv, link);
- srv = ISC_LIST_NEXT(srv, link);
}
}
static void
clear_searchlist(void) {
- dig_searchlist_t *search;
- while ((search = ISC_LIST_HEAD(search_list)) != NULL) {
+ ISC_LIST_FOREACH_SAFE (search_list, search, link) {
ISC_LIST_UNLINK(search_list, search, link);
isc_mem_free(mctx, search);
}
*/
static void
check_if_done(void) {
- dig_lookup_t *lookup = NULL;
-
debug("check_if_done()");
debug("list %s", ISC_LIST_EMPTY(lookup_list) ? "empty" : "full");
- lookup = ISC_LIST_HEAD(lookup_list);
- while (lookup != NULL) {
- dig_lookup_t *next = NULL;
+ ISC_LIST_FOREACH (lookup_list, lookup, link) {
debug("pending lookup %p", lookup);
- next = ISC_LIST_NEXT(lookup, link);
- lookup = next;
}
if (ISC_LIST_EMPTY(lookup_list) && current_lookup == NULL &&
*/
static bool
check_if_queries_done(dig_lookup_t *l, dig_query_t *except_q) {
- dig_query_t *q = ISC_LIST_HEAD(l->q);
-
debug("check_if_queries_done(%p)", l);
- while (q != NULL) {
+ ISC_LIST_FOREACH (l->q, q, link) {
if (!q->started || isc_refcount_current(&q->references) > 1) {
if (!q->canceled && q != except_q) {
debug("there is a pending query %p", q);
return false;
}
}
- q = ISC_LIST_NEXT(q, link);
}
return true;
static void
_destroy_lookup(dig_lookup_t *lookup) {
- dig_server_t *s;
- void *ptr;
-
REQUIRE(lookup != NULL);
REQUIRE(ISC_LIST_EMPTY(lookup->q));
isc_refcount_destroy(&lookup->references);
- s = ISC_LIST_HEAD(lookup->my_server_list);
- while (s != NULL) {
+ ISC_LIST_FOREACH_SAFE (lookup->my_server_list, s, link) {
debug("freeing server %p belonging to %p", s, lookup);
- ptr = s;
- s = ISC_LIST_NEXT(s, link);
- ISC_LIST_DEQUEUE(lookup->my_server_list, (dig_server_t *)ptr,
- link);
- isc_mem_free(mctx, ptr);
+ ISC_LIST_DEQUEUE(lookup->my_server_list, s, link);
+ isc_mem_free(mctx, s);
}
if (lookup->sendmsg != NULL) {
dns_message_detach(&lookup->sendmsg);
static void
_cancel_lookup(dig_lookup_t *lookup, const char *file, unsigned int line) {
- dig_query_t *query, *next;
-
debug("%s:%u:%s()", file, line, __func__);
- query = ISC_LIST_HEAD(lookup->q);
- while (query != NULL) {
+ ISC_LIST_FOREACH_SAFE (lookup->q, query, link) {
REQUIRE(DIG_VALID_QUERY(query));
- next = ISC_LIST_NEXT(query, link);
ISC_LIST_DEQUEUE(lookup->q, query, link);
debug("canceling pending query %p, belonging to %p", query,
query->lookup);
isc_nm_cancelread(query->readhandle);
}
query_detach(&query);
- query = next;
}
lookup->pending = false;
lookup->retries = 0;
*/
void
cancel_all(void) {
- dig_lookup_t *l, *n;
-
debug("cancel_all()");
if (free_now) {
lookup_detach(¤t_lookup);
}
}
- l = ISC_LIST_HEAD(lookup_list);
- while (l != NULL) {
- n = ISC_LIST_NEXT(l, link);
+ ISC_LIST_FOREACH_SAFE (lookup_list, l, link) {
ISC_LIST_DEQUEUE(lookup_list, l, link);
lookup_detach(&l);
- l = n;
}
}
static void
show_settings(bool full, bool serv_only) {
- dig_server_t *srv;
isc_sockaddr_t sockaddr;
isc_result_t result;
- srv = ISC_LIST_HEAD(server_list);
-
- while (srv != NULL) {
+ ISC_LIST_FOREACH (server_list, srv, link) {
char sockstr[ISC_SOCKADDR_FORMATSIZE];
result = get_address(srv->servername, port, &sockaddr);
if (!full) {
return;
}
- srv = ISC_LIST_NEXT(srv, link);
}
if (serv_only) {
return;
keys_sorted[i++] = dk;
}
qsort(keys_sorted, n, sizeof(dns_dnsseckey_t *), keyalgtag_cmp);
- while (!ISC_LIST_EMPTY(keys_read)) {
- dns_dnsseckey_t *key = ISC_LIST_HEAD(keys_read);
+ ISC_LIST_FOREACH_SAFE (keys_read, key, link) {
ISC_LIST_UNLINK(keys_read, key, link);
}
/* Save sorted list in 'keys' */
static void
cleanup(dns_dnsseckeylist_t *keys, dns_kasp_t *kasp) {
- while (!ISC_LIST_EMPTY(*keys)) {
- dns_dnsseckey_t *key = ISC_LIST_HEAD(*keys);
+ ISC_LIST_FOREACH_SAFE (*keys, key, link) {
ISC_LIST_UNLINK(*keys, key, link);
dst_key_free(&key->key);
dns_dnsseckey_destroy(mctx, &key);
}
dns_kasp_detach(&kasp);
- isc_buffer_t *cbuf = ISC_LIST_HEAD(cleanup_list);
- while (cbuf != NULL) {
- isc_buffer_t *nbuf = ISC_LIST_NEXT(cbuf, link);
+ ISC_LIST_FOREACH_SAFE (cleanup_list, cbuf, link) {
ISC_LIST_UNLINK(cleanup_list, cbuf, link);
isc_buffer_free(&cbuf);
- cbuf = nbuf;
}
}
static void
clear_keylist(dns_dnsseckeylist_t *list) {
- dns_dnsseckey_t *key;
- while (!ISC_LIST_EMPTY(*list)) {
- key = ISC_LIST_HEAD(*list);
+ ISC_LIST_FOREACH_SAFE (*list, key, link) {
ISC_LIST_UNLINK(*list, key, link);
dns_dnsseckey_destroy(mctx, &key);
}
static void
destroynode(bdbnode_t *node) {
- dns_rdatalist_t *list = NULL;
- dns_rdata_t *rdata = NULL;
- isc_buffer_t *b = NULL;
bdb_t *bdb = NULL;
isc_mem_t *mctx = NULL;
bdb = node->bdb;
mctx = bdb->common.mctx;
- while (!ISC_LIST_EMPTY(node->lists)) {
- list = ISC_LIST_HEAD(node->lists);
- while (!ISC_LIST_EMPTY(list->rdata)) {
- rdata = ISC_LIST_HEAD(list->rdata);
+ ISC_LIST_FOREACH_SAFE (node->lists, list, link) {
+ ISC_LIST_FOREACH_SAFE (list->rdata, rdata, link) {
ISC_LIST_UNLINK(list->rdata, rdata, link);
isc_mem_put(mctx, rdata, sizeof(dns_rdata_t));
}
isc_mem_put(mctx, list, sizeof(dns_rdatalist_t));
}
- while (!ISC_LIST_EMPTY(node->buffers)) {
- b = ISC_LIST_HEAD(node->buffers);
+ ISC_LIST_FOREACH_SAFE (node->buffers, b, link) {
ISC_LIST_UNLINK(node->buffers, b, link);
isc_buffer_free(&b);
}
dns_rdataset_t *rdataset,
dns_rdataset_t *sigrdataset DNS__DB_FLARG) {
bdbnode_t *bdbnode = (bdbnode_t *)node;
- dns_rdatalist_t *list = NULL;
REQUIRE(VALID_BDBNODE(bdbnode));
return ISC_R_NOTIMPLEMENTED;
}
- list = ISC_LIST_HEAD(bdbnode->lists);
- while (list != NULL) {
+ ISC_LIST_FOREACH (bdbnode->lists, list, link) {
if (list->type == type) {
- break;
+ new_rdataset(list, db, node, rdataset);
+ return ISC_R_SUCCESS;
}
- list = ISC_LIST_NEXT(list, link);
}
- if (list == NULL) {
- return ISC_R_NOTFOUND;
- }
-
- new_rdataset(list, db, node, rdataset);
- return ISC_R_SUCCESS;
+ return ISC_R_NOTFOUND;
}
static isc_result_t
static void
free_controlkeylist(controlkeylist_t *keylist, isc_mem_t *mctx) {
- while (!ISC_LIST_EMPTY(*keylist)) {
- controlkey_t *key = ISC_LIST_HEAD(*keylist);
+ ISC_LIST_FOREACH_SAFE (*keylist, key, link) {
ISC_LIST_UNLINK(*keylist, key, link);
free_controlkey(key, mctx);
}
const cfg_listelt_t *element = NULL;
dns_fwdpolicy_t fwdpolicy = dns_fwdpolicy_none;
dns_forwarderlist_t fwdlist;
- dns_forwarder_t *fwd = NULL;
isc_result_t result;
in_port_t port;
in_port_t tls_port;
const cfg_obj_t *forwarder = cfg_listelt_value(element);
const char *cur_tls = NULL;
- fwd = isc_mem_get(view->mctx, sizeof(dns_forwarder_t));
+ dns_forwarder_t *fwd = isc_mem_get(view->mctx,
+ sizeof(dns_forwarder_t));
fwd->tlsname = NULL;
cur_tls = cfg_obj_getsockaddrtls(forwarder);
if (cur_tls == NULL) {
cleanup:
- while (!ISC_LIST_EMPTY(fwdlist)) {
- fwd = ISC_LIST_HEAD(fwdlist);
+ ISC_LIST_FOREACH_SAFE (fwdlist, fwd, link) {
ISC_LIST_UNLINK(fwdlist, fwd, link);
if (fwd->tlsname != NULL) {
dns_name_free(fwd->tlsname, view->mctx);
bool first_time) {
cfg_obj_t *config = NULL, *bindkeys = NULL;
cfg_parser_t *conf_parser = NULL, *bindkeys_parser = NULL;
- const cfg_listelt_t *element;
- const cfg_obj_t *builtin_views;
+ const cfg_listelt_t *element = NULL;
+ const cfg_obj_t *builtin_views = NULL;
const cfg_obj_t *maps[3];
- const cfg_obj_t *obj;
- const cfg_obj_t *options;
- const cfg_obj_t *kasps;
- const cfg_obj_t *keystores;
+ const cfg_obj_t *obj = NULL;
+ const cfg_obj_t *options = NULL;
+ const cfg_obj_t *kasps = NULL;
+ const cfg_obj_t *keystores = NULL;
dns_kasp_t *default_kasp = NULL;
dns_kasplist_t tmpkasplist, kasplist;
dns_keystorelist_t tmpkeystorelist, keystorelist;
uint32_t send_tcp_buffer_size;
uint32_t recv_udp_buffer_size;
uint32_t send_udp_buffer_size;
- named_cache_t *nsc = NULL;
named_cachelist_t cachelist, tmpcachelist;
- ns_altsecret_t *altsecret;
+ ns_altsecret_t *altsecret = NULL;
ns_altsecretlist_t altsecrets, tmpaltsecrets;
uint32_t softquota = 0;
uint32_t max;
* were swapped above or not.
*/
cleanup_altsecrets:
- while ((altsecret = ISC_LIST_HEAD(altsecrets)) != NULL) {
- ISC_LIST_UNLINK(altsecrets, altsecret, link);
- isc_mem_put(server->sctx->mctx, altsecret, sizeof(*altsecret));
+ ISC_LIST_FOREACH_SAFE (altsecrets, as, link) {
+ ISC_LIST_UNLINK(altsecrets, as, link);
+ isc_mem_put(server->sctx->mctx, as, sizeof(*as));
}
cleanup_logc:
}
cleanup_cachelist:
- while ((nsc = ISC_LIST_HEAD(cachelist)) != NULL) {
+ ISC_LIST_FOREACH_SAFE (cachelist, nsc, link) {
ISC_LIST_UNLINK(cachelist, nsc, link);
dns_cache_detach(&nsc->cache);
isc_mem_put(server->mctx, nsc, sizeof(*nsc));
shutdown_server(void *arg) {
named_server_t *server = (named_server_t *)arg;
bool flush = server->flushonshutdown;
- named_cache_t *nsc = NULL;
named_os_notify_systemd("STOPPING=1\n");
named_os_notify_close();
*/
dns_dyndb_cleanup();
- while ((nsc = ISC_LIST_HEAD(server->cachelist)) != NULL) {
+ ISC_LIST_FOREACH_SAFE (server->cachelist, nsc, link) {
ISC_LIST_UNLINK(server->cachelist, nsc, link);
dns_cache_detach(&nsc->cache);
isc_mem_put(server->mctx, nsc, sizeof(*nsc));
static void
dumpcontext_destroy(struct dumpcontext *dctx) {
- struct viewlistentry *vle;
- struct zonelistentry *zle;
-
- vle = ISC_LIST_HEAD(dctx->viewlist);
- while (vle != NULL) {
+ ISC_LIST_FOREACH_SAFE (dctx->viewlist, vle, link) {
ISC_LIST_UNLINK(dctx->viewlist, vle, link);
- zle = ISC_LIST_HEAD(vle->zonelist);
- while (zle != NULL) {
+ ISC_LIST_FOREACH_SAFE (vle->zonelist, zle, link) {
ISC_LIST_UNLINK(vle->zonelist, zle, link);
dns_zone_detach(&zle->zone);
isc_mem_put(dctx->mctx, zle, sizeof *zle);
- zle = ISC_LIST_HEAD(vle->zonelist);
}
dns_view_detach(&vle->view);
isc_mem_put(dctx->mctx, vle, sizeof *vle);
- vle = ISC_LIST_HEAD(dctx->viewlist);
}
if (dctx->version != NULL) {
dns_db_closeversion(dctx->db, &dctx->version, false);
dns_zone_t *zone = NULL;
dns_kasp_t *kasp = NULL;
dns_dnsseckeylist_t keys;
- dns_dnsseckey_t *key;
char *ptr, *zonetext = NULL;
const char *msg = NULL;
/* variables for -checkds */
dns_db_detach(&db);
}
- while (!ISC_LIST_EMPTY(keys)) {
- key = ISC_LIST_HEAD(keys);
+ ISC_LIST_FOREACH_SAFE (keys, key, link) {
ISC_LIST_UNLINK(keys, key, link);
dns_dnsseckey_destroy(dns_zone_getmctx(zone), &key);
}
static isc_result_t
generatejson(named_server_t *server, size_t *msglen, const char **msg,
json_object **rootp, uint32_t flags) {
- dns_view_t *view;
isc_result_t result = ISC_R_SUCCESS;
json_object *bindstats, *viewlist, *counters, *obj;
json_object *traffic = NULL;
json_object_object_add(bindstats, "views", viewlist);
- view = ISC_LIST_HEAD(server->viewlist);
- while (view != NULL) {
+ ISC_LIST_FOREACH (server->viewlist, view, link) {
json_object *za, *xa, *v = json_object_new_object();
dns_adb_t *adb = NULL;
counters);
}
}
-
- view = ISC_LIST_NEXT(view, link);
}
}
dns_rdatalist_t rdatalist_ns, rdatalist_a, rdatalist_aaaa;
dns_rdatalist_t *rdatalists[] = { &rdatalist_ns, &rdatalist_a,
&rdatalist_aaaa, NULL };
- dns_rdata_t *rdata;
isc_region_t region;
/* Create the DB beforehand */
dns_db_detach(&db);
}
for (i = 0; rdatalists[i] != NULL; i++) {
- while ((rdata = ISC_LIST_HEAD(rdatalists[i]->rdata)) != NULL) {
+ ISC_LIST_FOREACH_SAFE (rdatalists[i]->rdata, rdata, link) {
ISC_LIST_UNLINK(rdatalists[i]->rdata, rdata, link);
dns_rdata_toregion(rdata, ®ion);
isc_mem_put(mctx, rdata,
/*% Main processing routine for mdig */
int
main(int argc, char *argv[]) {
- struct query *query = NULL;
isc_result_t result;
unsigned int i;
int ns;
fatal("can't choose between IPv4 and IPv6");
}
- query = ISC_LIST_HEAD(queries);
isc_loopmgr_setup(loopmgr, setup, NULL);
- isc_loopmgr_setup(loopmgr, sendqueries, query);
+ isc_loopmgr_setup(loopmgr, sendqueries, ISC_LIST_HEAD(queries));
isc_loopmgr_teardown(loopmgr, teardown, NULL);
/*
isc_loopmgr_run(loopmgr);
- query = ISC_LIST_HEAD(queries);
- while (query != NULL) {
- struct query *next = ISC_LIST_NEXT(query, link);
-
+ ISC_LIST_FOREACH_SAFE (queries, query, link) {
if (query->ednsopts != NULL) {
for (i = 0; i < EDNSOPTS; i++) {
if (query->ednsopts[i].value != NULL) {
query->ecs_addr = NULL;
}
isc_mem_free(mctx, query);
- query = next;
}
if (default_query.ecs_addr != NULL) {
*/
static void
clean_namehooks(dns_adb_t *adb, dns_adbnamehooklist_t *namehooks) {
- dns_adbnamehook_t *namehook = NULL;
-
- namehook = ISC_LIST_HEAD(*namehooks);
- while (namehook != NULL) {
+ ISC_LIST_FOREACH_SAFE (*namehooks, namehook, name_link) {
INSIST(DNS_ADBNAMEHOOK_VALID(namehook));
INSIST(DNS_ADBENTRY_VALID(namehook->entry));
dns_adbentry_detach(&adbentry);
free_adbnamehook(adb, &namehook);
-
- namehook = ISC_LIST_HEAD(*namehooks);
}
}
static void
copy_namehook_lists(dns_adb_t *adb, dns_adbfind_t *find, dns_adbname_t *name) {
- dns_adbnamehook_t *namehook = NULL;
dns_adbentry_t *entry = NULL;
if ((find->options & DNS_ADBFIND_INET) != 0) {
- namehook = ISC_LIST_HEAD(name->v4);
- while (namehook != NULL) {
+ ISC_LIST_FOREACH (name->v4, namehook, name_link) {
dns_adbaddrinfo_t *addrinfo = NULL;
entry = namehook->entry;
adbentry_overquota(entry))
{
find->options |= DNS_ADBFIND_OVERQUOTA;
- goto nextv4;
+ continue;
}
addrinfo = new_adbaddrinfo(adb, entry, find->port);
* Found a valid entry. Add it to the find's list.
*/
ISC_LIST_APPEND(find->list, addrinfo, publink);
- nextv4:
- namehook = ISC_LIST_NEXT(namehook, name_link);
}
}
if ((find->options & DNS_ADBFIND_INET6) != 0) {
- namehook = ISC_LIST_HEAD(name->v6);
- while (namehook != NULL) {
+ ISC_LIST_FOREACH (name->v6, namehook, name_link) {
dns_adbaddrinfo_t *addrinfo = NULL;
entry = namehook->entry;
adbentry_overquota(entry))
{
find->options |= DNS_ADBFIND_OVERQUOTA;
- goto nextv6;
+ continue;
}
addrinfo = new_adbaddrinfo(adb, entry, find->port);
* Found a valid entry. Add it to the find's list.
*/
ISC_LIST_APPEND(find->list, addrinfo, publink);
- nextv6:
- namehook = ISC_LIST_NEXT(namehook, name_link);
}
}
}
void
dns_adb_destroyfind(dns_adbfind_t **findp) {
dns_adbfind_t *find = NULL;
- dns_adbaddrinfo_t *ai = NULL;
dns_adb_t *adb = NULL;
REQUIRE(findp != NULL && DNS_ADBFIND_VALID(*findp));
* we also need to decrement the reference counter in the
* associated adbentry every time we remove one from the list.
*/
- ai = ISC_LIST_HEAD(find->list);
- while (ai != NULL) {
+ ISC_LIST_FOREACH_SAFE (find->list, ai, publink) {
ISC_LIST_UNLINK(find->list, ai, publink);
free_adbaddrinfo(adb, &ai);
- ai = ISC_LIST_HEAD(find->list);
}
UNLOCK(&find->lock);
dumpfind(dns_adbfind_t *find, FILE *f) {
char tmp[512];
const char *tmpp = NULL;
- dns_adbaddrinfo_t *ai = NULL;
isc_sockaddr_t *sa = NULL;
/*
find->flags);
fprintf(f, ";\tname %p\n", find->adbname);
- ai = ISC_LIST_HEAD(find->list);
- if (ai != NULL) {
+ if (!ISC_LIST_EMPTY(find->list)) {
fprintf(f, "\tAddresses:\n");
}
- while (ai != NULL) {
+ ISC_LIST_FOREACH (find->list, ai, publink) {
sa = &ai->sockaddr;
switch (sa->type.sa.sa_family) {
case AF_INET:
"\t\tentry %p, flags %08x"
" srtt %u addr %s\n",
ai->entry, ai->flags, ai->srtt, tmpp);
-
- ai = ISC_LIST_NEXT(ai, publink);
}
UNLOCK(&find->lock);
static void
print_find_list(FILE *f, dns_adbname_t *name) {
- dns_adbfind_t *find = NULL;
-
- find = ISC_LIST_HEAD(name->finds);
- while (find != NULL) {
+ ISC_LIST_FOREACH (name->finds, find, plink) {
dumpfind(find, f);
- find = ISC_LIST_NEXT(find, plink);
}
}
* Free temporary resources
*/
if (ansname != NULL) {
- dns_rdataset_t *rdataset;
-
- while ((rdataset = ISC_LIST_HEAD(ansname->list)) !=
- NULL)
- {
+ ISC_LIST_FOREACH_SAFE (ansname->list, rdataset, link) {
ISC_LIST_UNLINK(ansname->list, rdataset, link);
putrdataset(mctx, &rdataset);
}
void
dns_diff_clear(dns_diff_t *diff) {
- dns_difftuple_t *t;
REQUIRE(DNS_DIFF_VALID(diff));
- while ((t = ISC_LIST_HEAD(diff->tuples)) != NULL) {
+ ISC_LIST_FOREACH_SAFE (diff->tuples, t, link) {
ISC_LIST_UNLINK(diff->tuples, t, link);
dns_difftuple_free(&t);
}
dns_dnsseckey_t *key = NULL;
/* Skip duplicates */
- for (key = ISC_LIST_HEAD(*keylist); key != NULL;
- key = ISC_LIST_NEXT(key, link))
- {
- if (dst_key_id(key->key) == dst_key_id(*newkey) &&
- dst_key_alg(key->key) == dst_key_alg(*newkey) &&
- dns_name_equal(dst_key_name(key->key),
- dst_key_name(*newkey)))
+ ISC_LIST_FOREACH (*keylist, k, link) {
+ if (dst_key_id(k->key) == dst_key_id(*newkey) &&
+ dst_key_alg(k->key) == dst_key_alg(*newkey) &&
+ dns_name_equal(dst_key_name(k->key), dst_key_name(*newkey)))
{
+ key = k;
break;
}
}
char keystr2[DST_KEY_FORMATSIZE];
dns_dnsseckey_t *key2 = NULL;
- for (key2 = ISC_LIST_HEAD(*keys); key2 != NULL;
- key2 = ISC_LIST_NEXT(key2, link))
- {
+ ISC_LIST_FOREACH (*keys, k2, link) {
int f1 = dst_key_flags(key1->key);
- int f2 = dst_key_flags(key2->key);
+ int f2 = dst_key_flags(k2->key);
int nr1 = f1 & ~DNS_KEYFLAG_REVOKE;
int nr2 = f2 & ~DNS_KEYFLAG_REVOKE;
if (nr1 == nr2 &&
- dst_key_alg(key1->key) == dst_key_alg(key2->key) &&
- dst_key_pubcompare(key1->key, key2->key, true))
+ dst_key_alg(key1->key) == dst_key_alg(k2->key) &&
+ dst_key_pubcompare(key1->key, k2->key, true))
{
- int r1, r2;
- r1 = dst_key_flags(key1->key) &
- DNS_KEYFLAG_REVOKE;
- r2 = dst_key_flags(key2->key) &
- DNS_KEYFLAG_REVOKE;
+ int r1 = dst_key_flags(key1->key) &
+ DNS_KEYFLAG_REVOKE;
+ int r2 = dst_key_flags(k2->key) &
+ DNS_KEYFLAG_REVOKE;
key_revoked = (r1 != r2);
+ key2 = k2;
break;
}
}
static void
destroy_forwarders(dns_forwarders_t *forwarders) {
- dns_forwarder_t *fwd = NULL;
-
- while (!ISC_LIST_EMPTY(forwarders->fwdrs)) {
- fwd = ISC_LIST_HEAD(forwarders->fwdrs);
+ ISC_LIST_FOREACH_SAFE (forwarders->fwdrs, fwd, link) {
ISC_LIST_UNLINK(forwarders->fwdrs, fwd, link);
if (fwd->tlsname != NULL) {
dns_name_free(fwd->tlsname, forwarders->mctx);
dns_kasp_t *kasp, isc_stdtime_t now, isc_stdtime_t *nexttime) {
isc_result_t result = ISC_R_SUCCESS;
dns_dnsseckeylist_t newkeys;
- dns_dnsseckey_t *newkey = NULL;
bool secure_to_insecure = false;
int numkeys = 0;
int options = (DST_TYPE_PRIVATE | DST_TYPE_PUBLIC | DST_TYPE_STATE);
failure:
if (result != ISC_R_SUCCESS) {
- while ((newkey = ISC_LIST_HEAD(newkeys)) != NULL) {
+ ISC_LIST_FOREACH_SAFE (newkeys, newkey, link) {
ISC_LIST_UNLINK(newkeys, newkey, link);
INSIST(newkey->key != NULL);
dst_key_free(&newkey->key);
isc_result_t result = ISC_R_UNEXPECTED;
rdatalist_head_t glue_list;
rdatalist_head_t current_list;
- dns_rdatalist_t *this = NULL;
dns_rdatalist_t *rdatalist = NULL;
dns_rdatalist_t *new_rdatalist = NULL;
int rdlcount = 0;
}
source = isc_lex_getsourcename(lctx->lex);
while (true) {
+ dns_rdatalist_t *this = NULL;
+
if (atomic_load_acquire(&lctx->canceled)) {
result = ISC_R_CANCELED;
goto log_and_cleanup;
callbacks->commit(callbacks->add_private);
}
- while ((this = ISC_LIST_HEAD(current_list)) != NULL) {
+ ISC_LIST_FOREACH_SAFE (current_list, this, link) {
ISC_LIST_UNLINK(current_list, this, link);
}
- while ((this = ISC_LIST_HEAD(glue_list)) != NULL) {
+ ISC_LIST_FOREACH_SAFE (glue_list, this, link) {
ISC_LIST_UNLINK(glue_list, this, link);
}
if (rdatalist != NULL) {
dns_rdatalist_t *newlist;
int rdlcount = 0;
ISC_LIST(dns_rdatalist_t) save;
- dns_rdatalist_t *this;
newlist = isc_mem_cget(mctx, new_len, sizeof(newlist[0]));
ISC_LIST_INIT(save);
- while ((this = ISC_LIST_HEAD(*current)) != NULL) {
+ ISC_LIST_FOREACH_SAFE (*current, this, link) {
ISC_LIST_UNLINK(*current, this, link);
ISC_LIST_APPEND(save, this, link);
}
- while ((this = ISC_LIST_HEAD(save)) != NULL) {
+ ISC_LIST_FOREACH_SAFE (save, this, link) {
ISC_LIST_UNLINK(save, this, link);
INSIST(rdlcount < new_len);
newlist[rdlcount] = *this;
}
ISC_LIST_INIT(save);
- while ((this = ISC_LIST_HEAD(*glue)) != NULL) {
+ ISC_LIST_FOREACH_SAFE (*glue, this, link) {
ISC_LIST_UNLINK(*glue, this, link);
ISC_LIST_APPEND(save, this, link);
}
- while ((this = ISC_LIST_HEAD(save)) != NULL) {
+ ISC_LIST_FOREACH_SAFE (save, this, link) {
ISC_LIST_UNLINK(save, this, link);
INSIST(rdlcount < new_len);
newlist[rdlcount] = *this;
dns_rdata_t *newlist;
int rdcount = 0;
ISC_LIST(dns_rdata_t) save;
- dns_rdatalist_t *this;
- dns_rdata_t *rdata;
newlist = isc_mem_cget(mctx, new_len, sizeof(*newlist));
/*
* Copy current relinking.
*/
- this = ISC_LIST_HEAD(*current);
- while (this != NULL) {
+ ISC_LIST_FOREACH (*current, this, link) {
ISC_LIST_INIT(save);
- while ((rdata = ISC_LIST_HEAD(this->rdata)) != NULL) {
+ ISC_LIST_FOREACH_SAFE (this->rdata, rdata, link) {
ISC_LIST_UNLINK(this->rdata, rdata, link);
ISC_LIST_APPEND(save, rdata, link);
}
- while ((rdata = ISC_LIST_HEAD(save)) != NULL) {
+ ISC_LIST_FOREACH_SAFE (save, rdata, link) {
ISC_LIST_UNLINK(save, rdata, link);
INSIST(rdcount < new_len);
newlist[rdcount] = *rdata;
ISC_LIST_APPEND(this->rdata, &newlist[rdcount], link);
rdcount++;
}
- this = ISC_LIST_NEXT(this, link);
}
/*
* Copy glue relinking.
*/
- this = ISC_LIST_HEAD(*glue);
- while (this != NULL) {
+ ISC_LIST_FOREACH (*glue, this, link) {
ISC_LIST_INIT(save);
- while ((rdata = ISC_LIST_HEAD(this->rdata)) != NULL) {
+ ISC_LIST_FOREACH (this->rdata, rdata, link) {
ISC_LIST_UNLINK(this->rdata, rdata, link);
ISC_LIST_APPEND(save, rdata, link);
}
- while ((rdata = ISC_LIST_HEAD(save)) != NULL) {
+ ISC_LIST_FOREACH (save, rdata, link) {
ISC_LIST_UNLINK(save, rdata, link);
INSIST(rdcount < new_len);
newlist[rdcount] = *rdata;
ISC_LIST_APPEND(this->rdata, &newlist[rdcount], link);
rdcount++;
}
- this = ISC_LIST_NEXT(this, link);
}
INSIST(rdcount == old_len || rdcount == 0);
if (oldlist != NULL) {
commit(dns_rdatacallbacks_t *callbacks, dns_loadctx_t *lctx,
rdatalist_head_t *head, dns_name_t *owner, const char *source,
unsigned int line) {
- dns_rdatalist_t *this;
dns_rdataset_t dataset;
isc_result_t result = ISC_R_SUCCESS;
char namebuf[DNS_NAME_FORMATSIZE];
void (*error)(struct dns_rdatacallbacks *, const char *, ...);
- this = ISC_LIST_HEAD(*head);
error = callbacks->error;
- while (this != NULL) {
+ ISC_LIST_FOREACH_SAFE (*head, this, link) {
dns_rdataset_init(&dataset);
dns_rdatalist_tordataset(this, &dataset);
dataset.trust = dns_trust_ultimate;
break;
}
ISC_LIST_UNLINK(*head, this, link);
- this = ISC_LIST_HEAD(*head);
}
return result;
static bool
is_glue(rdatalist_head_t *head, dns_name_t *owner) {
- dns_rdatalist_t *this;
- dns_rdata_t *rdata;
+ dns_rdatalist_t *nslist = NULL;
isc_region_t region;
dns_name_t name;
/*
* Find NS rrset.
*/
- this = ISC_LIST_HEAD(*head);
- while (this != NULL) {
+ ISC_LIST_FOREACH (*head, this, link) {
if (this->type == dns_rdatatype_ns) {
+ nslist = this;
break;
}
- this = ISC_LIST_NEXT(this, link);
}
- if (this == NULL) {
+ if (nslist == NULL) {
return false;
}
- rdata = ISC_LIST_HEAD(this->rdata);
- while (rdata != NULL) {
+ ISC_LIST_FOREACH (nslist->rdata, rdata, link) {
dns_name_init(&name);
dns_rdata_toregion(rdata, ®ion);
dns_name_fromregion(&name, ®ion);
if (dns_name_equal(&name, owner)) {
return true;
}
- rdata = ISC_LIST_NEXT(rdata, link);
}
return false;
}
msgreset(dns_message_t *msg, bool everything) {
dns_msgblock_t *msgblock = NULL, *next_msgblock = NULL;
isc_buffer_t *dynbuf = NULL, *next_dynbuf = NULL;
- dns_rdata_t *rdata = NULL;
- dns_rdatalist_t *rdatalist = NULL;
msgresetnames(msg, 0);
msgresetopt(msg);
* The memory isn't lost since these are part of message blocks we
* have allocated.
*/
- rdata = ISC_LIST_HEAD(msg->freerdata);
- while (rdata != NULL) {
+ ISC_LIST_FOREACH_SAFE (msg->freerdata, rdata, link) {
ISC_LIST_UNLINK(msg->freerdata, rdata, link);
- rdata = ISC_LIST_HEAD(msg->freerdata);
}
- rdatalist = ISC_LIST_HEAD(msg->freerdatalist);
- while (rdatalist != NULL) {
+ ISC_LIST_FOREACH_SAFE (msg->freerdatalist, rdatalist, link) {
ISC_LIST_UNLINK(msg->freerdatalist, rdatalist, link);
- rdatalist = ISC_LIST_HEAD(msg->freerdatalist);
}
dynbuf = ISC_LIST_HEAD(msg->scratchpad);
{
bool deleted = false;
if (diff != NULL) {
- for (dns_difftuple_t *tuple =
- ISC_LIST_HEAD(diff->tuples);
- tuple != NULL;
- tuple = ISC_LIST_NEXT(tuple, link))
- {
+ ISC_LIST_FOREACH (diff->tuples, tuple, link) {
if (tuple->rdata.type !=
dns_rdatatype_dnskey ||
tuple->op != DNS_DIFFOP_DEL)
void
dns_order_detach(dns_order_t **orderp) {
REQUIRE(orderp != NULL && DNS_ORDER_VALID(*orderp));
- dns_order_t *order;
- order = *orderp;
+ dns_order_t *order = *orderp;
*orderp = NULL;
if (isc_refcount_decrement(&order->references) == 1) {
isc_refcount_destroy(&order->references);
order->magic = 0;
- dns_order_ent_t *ent;
- while ((ent = ISC_LIST_HEAD(order->ents)) != NULL) {
+ ISC_LIST_FOREACH_SAFE (order->ents, ent, link) {
ISC_LIST_UNLINK(order->ents, ent, link);
isc_mem_put(order->mctx, ent, sizeof(*ent));
}
static void
peerlist_delete(dns_peerlist_t **list) {
- dns_peerlist_t *l;
- dns_peer_t *server, *stmp;
+ dns_peerlist_t *l = NULL;
REQUIRE(list != NULL);
REQUIRE(DNS_PEERLIST_VALID(*list));
isc_refcount_destroy(&l->refs);
- server = ISC_LIST_HEAD(l->elements);
- while (server != NULL) {
- stmp = ISC_LIST_NEXT(server, next);
+ ISC_LIST_FOREACH_SAFE (l->elements, server, next) {
ISC_LIST_UNLINK(l->elements, server, next);
dns_peer_detach(&server);
- server = stmp;
}
l->magic = 0;
isc_result_t
dns_peerlist_peerbyaddr(dns_peerlist_t *servers, const isc_netaddr_t *addr,
dns_peer_t **retval) {
- dns_peer_t *server;
- isc_result_t res;
-
REQUIRE(retval != NULL);
REQUIRE(DNS_PEERLIST_VALID(servers));
- server = ISC_LIST_HEAD(servers->elements);
- while (server != NULL) {
+ ISC_LIST_FOREACH (servers->elements, server, next) {
if (isc_netaddr_eqprefix(addr, &server->address,
server->prefixlen))
{
- break;
+ *retval = server;
+ return ISC_R_SUCCESS;
}
-
- server = ISC_LIST_NEXT(server, next);
- }
-
- if (server != NULL) {
- *retval = server;
- res = ISC_R_SUCCESS;
- } else {
- res = ISC_R_NOTFOUND;
}
- return res;
+ return ISC_R_NOTFOUND;
}
isc_result_t
static void
free_search(irs_resconf_t *conf) {
- irs_resconf_search_t *searchentry;
-
- while ((searchentry = ISC_LIST_HEAD(conf->searchlist)) != NULL) {
+ ISC_LIST_FOREACH_SAFE (conf->searchlist, searchentry, link) {
ISC_LIST_UNLINK(conf->searchlist, searchentry, link);
isc_mem_free(conf->mctx, searchentry->domain);
isc_mem_put(conf->mctx, searchentry, sizeof(*searchentry));
void
irs_resconf_destroy(irs_resconf_t **confp) {
- irs_resconf_t *conf;
- isc_sockaddr_t *address;
+ irs_resconf_t *conf = NULL;
REQUIRE(confp != NULL);
conf = *confp;
free_search(conf);
- while ((address = ISC_LIST_HEAD(conf->nameservers)) != NULL) {
+ ISC_LIST_FOREACH_SAFE (conf->nameservers, address, link) {
ISC_LIST_UNLINK(conf->nameservers, address, link);
isc_mem_put(conf->mctx, address, sizeof(*address));
}
bool create, char *log_buf, unsigned int log_buf_len) {
dns_rrl_key_t key;
uint32_t hval;
- dns_rrl_entry_t *e;
- dns_rrl_hash_t *hash;
- dns_rrl_bin_t *new_bin, *old_bin;
+ dns_rrl_hash_t *hash = NULL;
+ dns_rrl_bin_t *new_bin = NULL, *old_bin = NULL;
int probes, age;
make_key(rrl, &key, client_addr, zone, qtype, qname, qclass, rtype);
*/
new_bin = get_bin(rrl->hash, hval);
probes = 1;
- e = ISC_LIST_HEAD(*new_bin);
- while (e != NULL) {
+ ISC_LIST_FOREACH (*new_bin, e, hlink) {
if (key_cmp(&e->key, &key)) {
ref_entry(rrl, e, probes, now);
return e;
}
++probes;
- e = ISC_LIST_NEXT(e, hlink);
}
/*
*/
if (rrl->old_hash != NULL) {
old_bin = get_bin(rrl->old_hash, hval);
- e = ISC_LIST_HEAD(*old_bin);
- while (e != NULL) {
+ ISC_LIST_FOREACH (*old_bin, e, hlink) {
if (key_cmp(&e->key, &key)) {
ISC_LIST_UNLINK(*old_bin, e, hlink);
ISC_LIST_PREPEND(*new_bin, e, hlink);
ref_entry(rrl, e, probes, now);
return e;
}
- e = ISC_LIST_NEXT(e, hlink);
}
/*
* Try to make more entries if none are idle.
* Steal the oldest entry if we cannot create more.
*/
- for (e = ISC_LIST_TAIL(rrl->lru); e != NULL; e = ISC_LIST_PREV(e, lru))
- {
+ dns_rrl_entry_t *entry = NULL;
+ ISC_LIST_FOREACH_REV (rrl->lru, e, lru) {
+ entry = e;
if (!ISC_LINK_LINKED(e, hlink)) {
break;
}
age = get_age(rrl, e, now);
if (age <= 1) {
- e = NULL;
+ entry = NULL;
break;
}
if (!e->logged && response_balance(rrl, e, age) > 0) {
break;
}
}
- if (e == NULL) {
+
+ if (entry == NULL) {
expand_entries(rrl, ISC_MIN((rrl->num_entries + 1) / 2, 1000));
- e = ISC_LIST_TAIL(rrl->lru);
+ entry = ISC_LIST_TAIL(rrl->lru);
}
- if (e->logged) {
- log_end(rrl, e, true, log_buf, log_buf_len);
+ if (entry->logged) {
+ log_end(rrl, entry, true, log_buf, log_buf_len);
}
- if (ISC_LINK_LINKED(e, hlink)) {
- if (e->hash_gen == rrl->hash_gen) {
+ if (ISC_LINK_LINKED(entry, hlink)) {
+ if (entry->hash_gen == rrl->hash_gen) {
hash = rrl->hash;
} else {
hash = rrl->old_hash;
}
- old_bin = get_bin(hash, hash_key(&e->key));
- ISC_LIST_UNLINK(*old_bin, e, hlink);
- }
- ISC_LIST_PREPEND(*new_bin, e, hlink);
- e->hash_gen = rrl->hash_gen;
- e->key = key;
- e->ts_valid = false;
- ref_entry(rrl, e, probes, now);
- return e;
+ old_bin = get_bin(hash, hash_key(&entry->key));
+ ISC_LIST_UNLINK(*old_bin, entry, hlink);
+ }
+ ISC_LIST_PREPEND(*new_bin, entry, hlink);
+ entry->hash_gen = rrl->hash_gen;
+ entry->key = key;
+ entry->ts_valid = false;
+ ref_entry(rrl, entry, probes, now);
+ return entry;
}
static void
void
dns_rrl_view_destroy(dns_view_t *view) {
- dns_rrl_t *rrl;
- dns_rrl_block_t *b;
- dns_rrl_hash_t *h;
+ dns_rrl_t *rrl = NULL;
+ dns_rrl_hash_t *h = NULL;
char log_buf[DNS_RRL_LOG_BUF_LEN];
int i;
isc_mutex_destroy(&rrl->lock);
- while (!ISC_LIST_EMPTY(rrl->blocks)) {
- b = ISC_LIST_HEAD(rrl->blocks);
+ ISC_LIST_FOREACH_SAFE (rrl->blocks, b, link) {
ISC_LIST_UNLINK(rrl->blocks, b, link);
isc_mem_put(rrl->mctx, b, b->size);
}
REQUIRE(VALID_SSUTABLE(table));
mctx = table->mctx;
- while (!ISC_LIST_EMPTY(table->rules)) {
- dns_ssurule_t *rule = ISC_LIST_HEAD(table->rules);
+ ISC_LIST_FOREACH_SAFE (table->rules, rule, link) {
if (rule->identity != NULL) {
dns_name_free(rule->identity, mctx);
isc_mem_put(mctx, rule->identity,
static isc_result_t
uniqify_name_list(dns_diff_t *list) {
isc_result_t result;
- dns_difftuple_t *p, *q;
CHECK(dns_diff_sort(list, name_order));
- p = ISC_LIST_HEAD(list->tuples);
- while (p != NULL) {
- do {
- q = ISC_LIST_NEXT(p, link);
- if (q == NULL || !dns_name_equal(&p->name, &q->name)) {
- break;
- }
- ISC_LIST_UNLINK(list->tuples, q, link);
- dns_difftuple_free(&q);
- } while (1);
- p = ISC_LIST_NEXT(p, link);
+ dns_name_t *curr_name = NULL;
+ ISC_LIST_FOREACH_SAFE (list->tuples, p, link) {
+ if (curr_name == NULL || !dns_name_equal(curr_name, &p->name)) {
+ curr_name = &(p->name);
+ } else {
+ ISC_LIST_UNLINK(list->tuples, p, link);
+ dns_difftuple_free(&p);
+ }
}
failure:
return result;
find_zone_keys(dns_zone_t *zone, isc_mem_t *mctx, unsigned int maxkeys,
dst_key_t **keys, unsigned int *nkeys) {
dns_dnsseckeylist_t keylist;
- dns_dnsseckey_t *k = NULL;
unsigned int count = 0;
isc_result_t result;
isc_stdtime_t now = isc_stdtime_now();
}
/* Add new 'dnskeys' to 'keys' */
- while ((k = ISC_LIST_HEAD(keylist)) != NULL) {
+ ISC_LIST_FOREACH_SAFE (keylist, k, link) {
if (count >= maxkeys) {
+ ISC_LIST_UNLINK(keylist, k, link);
+ dns_dnsseckey_destroy(mctx, &k);
result = ISC_R_NOSPACE;
- goto next;
+ break;
}
/* Detect inactive keys */
k->key = NULL;
count++;
- next:
ISC_LIST_UNLINK(keylist, k, link);
dns_dnsseckey_destroy(mctx, &k);
}
static void
clear_keylist(dns_dnsseckeylist_t *list, isc_mem_t *mctx) {
- dns_dnsseckey_t *key;
- while (!ISC_LIST_EMPTY(*list)) {
- key = ISC_LIST_HEAD(*list);
+ ISC_LIST_FOREACH_SAFE (*list, key, link) {
ISC_LIST_UNLINK(*list, key, link);
dns_dnsseckey_destroy(mctx, &key);
}
static void
process_zone_setnsec3param(dns_zone_t *zone) {
- struct np3 *npe = NULL;
- while ((npe = ISC_LIST_HEAD(zone->setnsec3param_queue)) != NULL) {
+ ISC_LIST_FOREACH_SAFE (zone->setnsec3param_queue, npe, link) {
ISC_LIST_UNLINK(zone->setnsec3param_queue, npe, link);
zone_iattach(zone, &npe->zone);
isc_async_run(zone->loop, setnsec3param, npe);
if (node != NULL) {
dns_db_detachnode(db, &node);
}
- while (!ISC_LIST_EMPTY(dnskeys)) {
- dns_dnsseckey_t *key = ISC_LIST_HEAD(dnskeys);
+ ISC_LIST_FOREACH_SAFE (dnskeys, key, link) {
ISC_LIST_UNLINK(dnskeys, key, link);
dns_dnsseckey_destroy(dns_zone_getmctx(zone), &key);
}
isc_result_t
dns_zone_dnskey_inuse(dns_zone_t *zone, dns_rdata_t *rdata, bool *inuse) {
dns_dnsseckeylist_t keylist;
- dns_dnsseckey_t *key = NULL;
isc_result_t result = ISC_R_SUCCESS;
isc_stdtime_t now = isc_stdtime_now();
isc_mem_t *mctx;
break;
}
- while (!ISC_LIST_EMPTY(keylist)) {
- key = ISC_LIST_HEAD(keylist);
+ ISC_LIST_FOREACH_SAFE (keylist, key, link) {
ISC_LIST_UNLINK(keylist, key, link);
dns_dnsseckey_destroy(mctx, &key);
}
remove_rdataset(zone, diff, cdnskeyset);
/* Add the records from the bundle. */
- dns_difftuple_t *tuple = ISC_LIST_HEAD(bundle->diff.tuples);
- while (tuple != NULL) {
+ ISC_LIST_FOREACH (bundle->diff.tuples, tuple, link) {
switch (tuple->rdata.type) {
case dns_rdatatype_dnskey:
add_tuple(diff, tuple);
default:
INSIST(0);
}
-
- tuple = ISC_LIST_NEXT(tuple, link);
}
}
void
isc_logconfig_destroy(isc_logconfig_t **lcfgp) {
- isc_logconfig_t *lcfg;
- isc_mem_t *mctx;
- isc_logchannel_t *channel;
- char *filename;
+ isc_logconfig_t *lcfg = NULL;
+ isc_mem_t *mctx = NULL;
+ char *filename = NULL;
REQUIRE(lcfgp != NULL && VALID_CONFIG(*lcfgp));
mctx = lcfg->lctx->mctx;
- while ((channel = ISC_LIST_HEAD(lcfg->channels)) != NULL) {
- ISC_LIST_UNLINK(lcfg->channels, channel, link);
-
+ ISC_LIST_FOREACH_SAFE (lcfg->channels, channel, link) {
if (channel->type == ISC_LOG_TOFILE) {
/*
* The filename for the channel may have ultimately
isc_logconfig_t *lcfg = rcu_dereference(isc__lctx->logconfig);
if (lcfg != NULL) {
LOCK(&isc__lctx->lock);
- for (isc_logchannel_t *channel =
- ISC_LIST_HEAD(lcfg->channels);
- channel != NULL;
- channel = ISC_LIST_NEXT(channel, link))
- {
+ ISC_LIST_FOREACH (lcfg->channels, channel, link) {
if (channel->type == ISC_LOG_TOFILE &&
(channel->flags & ISC_LOG_DEBUGONLY) != 0 &&
FILE_STREAM(channel) != NULL)
static void
delete_trace_entry(isc_mem_t *mctx, const void *ptr, size_t size FLARG) {
- debuglink_t *dl = NULL;
uint32_t hash;
uint32_t idx;
#endif
idx = hash % DEBUG_TABLE_COUNT;
- dl = ISC_LIST_HEAD(mctx->debuglist[idx]);
- while (dl != NULL) {
+ ISC_LIST_FOREACH (mctx->debuglist[idx], dl, link) {
if (dl->ptr == ptr) {
ISC_LIST_UNLINK(mctx->debuglist[idx], dl, link);
sdallocx(dl, dl->dlsize, mctx->jemalloc_flags);
goto unlock;
}
- dl = ISC_LIST_NEXT(dl, link);
}
/*
static void
print_active(isc_mem_t *mctx, FILE *out) {
if (mctx->debuglist != NULL) {
- debuglink_t *dl;
unsigned int i;
bool found;
"allocations:\n");
found = false;
for (i = 0; i < DEBUG_TABLE_COUNT; i++) {
- dl = ISC_LIST_HEAD(mctx->debuglist[i]);
-
- if (dl != NULL) {
+ ISC_LIST_FOREACH (mctx->debuglist[i], dl, link) {
found = true;
- }
-
- while (dl != NULL) {
if (dl->ptr != NULL) {
fprintf(out,
"\tptr %p size %zu "
dl->ptr, dl->size, dl->file,
dl->line);
}
- dl = ISC_LIST_NEXT(dl, link);
}
}
*/
void
isc_mem_stats(isc_mem_t *ctx, FILE *out) {
- isc_mempool_t *pool = NULL;
-
REQUIRE(VALID_CONTEXT(ctx));
MCTXLOCK(ctx);
* isc_mem_t's lock, however, so walking this list and
* extracting integers from stats fields is always safe.
*/
- pool = ISC_LIST_HEAD(ctx->pools);
- if (pool != NULL) {
+ if (!ISC_LIST_EMPTY(ctx->pools)) {
fprintf(out, "[Pool statistics]\n");
fprintf(out, "%15s %10s %10s %10s %10s %10s %10s %1s\n", "name",
"size", "allocated", "freecount", "freemax",
"fillcount", "gets", "L");
}
- while (pool != NULL) {
+ ISC_LIST_FOREACH (ctx->pools, pool, link) {
fprintf(out,
"%15s %10zu %10zu %10zu %10zu %10zu %10zu %10zu %s\n",
pool->name, pool->size, (size_t)0, pool->allocated,
pool->freecount, pool->freemax, pool->fillcount,
pool->gets, "N");
- pool = ISC_LIST_NEXT(pool, link);
}
#if ISC_MEM_TRACKLINES
static void
call_pending_callbacks(isc__nm_http_pending_callbacks_t pending_callbacks,
isc_result_t result) {
- isc__nm_uvreq_t *cbreq = ISC_LIST_HEAD(pending_callbacks);
- while (cbreq != NULL) {
- isc__nm_uvreq_t *next = ISC_LIST_NEXT(cbreq, link);
+ ISC_LIST_FOREACH_SAFE (pending_callbacks, cbreq, link) {
ISC_LIST_UNLINK(pending_callbacks, cbreq, link);
isc__nm_sendcb(cbreq->handle->sock, cbreq, result, true);
- cbreq = next;
}
}
isc_nm_http_endpoints_detach(isc_nm_http_endpoints_t **restrict epsp) {
isc_nm_http_endpoints_t *restrict eps;
isc_mem_t *mctx;
- isc_nm_httphandler_t *handler = NULL;
REQUIRE(epsp != NULL);
eps = *epsp;
mctx = eps->mctx;
/* Delete all handlers */
- handler = ISC_LIST_HEAD(eps->handlers);
- while (handler != NULL) {
- isc_nm_httphandler_t *next = NULL;
-
- next = ISC_LIST_NEXT(handler, link);
+ ISC_LIST_FOREACH_SAFE (eps->handlers, handler, link) {
ISC_LIST_DEQUEUE(eps->handlers, handler, link);
isc_mem_free(mctx, handler->path);
handler->magic = 0;
isc_mem_put(mctx, handler, sizeof(*handler));
- handler = next;
}
eps->magic = 0;
static void
client_call_failed_read_cb(isc_result_t result,
isc_nm_http_session_t *session) {
- http_cstream_t *cstream = NULL;
-
REQUIRE(VALID_HTTP2_SESSION(session));
REQUIRE(result != ISC_R_SUCCESS);
- cstream = ISC_LIST_HEAD(session->cstreams);
- while (cstream != NULL) {
- http_cstream_t *next = ISC_LIST_NEXT(cstream, link);
-
+ ISC_LIST_FOREACH_SAFE (session->cstreams, cstream, link) {
/*
* read_cb could be NULL if cstream was allocated and added
* to the tracking list, but was not properly initialized due
ISC_LIST_DEQUEUE(session->cstreams, cstream, link);
put_http_cstream(session->mctx, cstream);
}
-
- cstream = next;
}
}
REQUIRE(VALID_NMSOCK(sock));
REQUIRE(!isc__nmsocket_active(sock));
- isc_nmhandle_t *handle = NULL;
isc__networker_t *worker = sock->worker;
isc_refcount_destroy(&sock->references);
isc__nmsocket_detach(&sock->outer);
}
- while ((handle = ISC_LIST_HEAD(sock->inactive_handles)) != NULL) {
+ ISC_LIST_FOREACH_SAFE (sock->inactive_handles, handle, inactive_link) {
ISC_LIST_DEQUEUE(sock->inactive_handles, handle, inactive_link);
nmhandle_free(sock, handle);
}
static void
isc__ratelimiter_tick(void *arg) {
isc_ratelimiter_t *rl = (isc_ratelimiter_t *)arg;
- isc_rlevent_t *rle = NULL;
uint32_t pertic;
ISC_LIST(isc_rlevent_t) pending;
pertic = rl->pertic;
while (pertic != 0) {
- rle = ISC_LIST_HEAD(rl->pending);
+ isc_rlevent_t *rle = ISC_LIST_HEAD(rl->pending);
if (rle != NULL) {
/* There is work to do. Let's do it after unlocking. */
ISC_LIST_UNLINK(rl->pending, rle, link);
unlock:
UNLOCK(&rl->lock);
- while ((rle = ISC_LIST_HEAD(pending)) != NULL) {
+ ISC_LIST_FOREACH_SAFE (pending, rle, link) {
ISC_LIST_UNLINK(pending, rle, link);
isc_async_run(rle->loop, rle->cb, rle->arg);
}
void
isc_ratelimiter_shutdown(isc_ratelimiter_t *restrict rl) {
- isc_rlevent_t *rle = NULL;
ISC_LIST(isc_rlevent_t) pending;
REQUIRE(VALID_RATELIMITER(rl));
}
UNLOCK(&rl->lock);
- while ((rle = ISC_LIST_HEAD(pending)) != NULL) {
+ ISC_LIST_FOREACH_SAFE (pending, rle, link) {
ISC_LIST_UNLINK(pending, rle, link);
rle->canceled = true;
isc_async_run(rl->loop, rle->cb, rle->arg);
isc_tlsctx_client_session_cache_detach(
isc_tlsctx_client_session_cache_t **cachep) {
isc_tlsctx_client_session_cache_t *cache = NULL;
- client_session_cache_entry_t *entry = NULL, *next = NULL;
REQUIRE(cachep != NULL);
isc_refcount_destroy(&cache->references);
- entry = ISC_LIST_HEAD(cache->lru_entries);
- while (entry != NULL) {
- next = ISC_LIST_NEXT(entry, cache_link);
+ ISC_LIST_FOREACH_SAFE (cache->lru_entries, entry, cache_link) {
client_cache_entry_delete(cache, entry);
- entry = next;
}
RUNTIME_CHECK(isc_ht_count(cache->buckets) == 0);
void
ns_client_dumprecursing(FILE *f, ns_clientmgr_t *manager) {
- ns_client_t *client;
char namebuf[DNS_NAME_FORMATSIZE];
char original[DNS_NAME_FORMATSIZE];
char peerbuf[ISC_SOCKADDR_FORMATSIZE];
REQUIRE(VALID_MANAGER(manager));
LOCK(&manager->reclock);
- client = ISC_LIST_HEAD(manager->recursing);
- while (client != NULL) {
+ ISC_LIST_FOREACH (manager->recursing, client, rlink) {
INSIST(client->state == NS_CLIENTSTATE_RECURSING);
ns_client_name(client, peerbuf, sizeof(peerbuf));
sep, name, client->message->id, namebuf, typebuf,
classbuf, origfor, original,
isc_time_seconds(&client->requesttime));
- client = ISC_LIST_NEXT(client, rlink);
}
UNLOCK(&manager->reclock);
}
static void
clearlistenon(ns_interfacemgr_t *mgr) {
- ISC_LIST(isc_sockaddr_t) listenon;
- isc_sockaddr_t *old;
-
- ISC_LIST_INIT(listenon);
+ ISC_LIST(isc_sockaddr_t) listenon = ISC_LIST_INITIALIZER;
LOCK(&mgr->lock);
ISC_LIST_MOVE(listenon, mgr->listenon);
UNLOCK(&mgr->lock);
- old = ISC_LIST_HEAD(listenon);
- while (old != NULL) {
+ ISC_LIST_FOREACH_SAFE (listenon, old, link) {
ISC_LIST_UNLINK(listenon, old, link);
isc_mem_put(mgr->mctx, old, sizeof(*old));
- old = ISC_LIST_HEAD(listenon);
}
}
static void
message_clearrdataset(dns_message_t *msg, unsigned int attr) {
unsigned int i;
- 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++) {
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);
+ ISC_LIST_FOREACH_SAFE (name->list, rds, link) {
if ((rds->attributes & attr) != attr) {
- rds = next_rds;
continue;
}
ISC_LIST_UNLINK(name->list, rds, link);
INSIST(dns_rdataset_isassociated(rds));
dns_rdataset_disassociate(rds);
isc_mempool_put(msg->rdspool, rds);
- rds = next_rds;
}
if (ISC_LIST_EMPTY(name->list)) {
*sctxp = NULL;
if (isc_refcount_decrement(&sctx->references) == 1) {
- ns_altsecret_t *altsecret;
- isc_quota_t *http_quota;
-
- while ((altsecret = ISC_LIST_HEAD(sctx->altsecrets)) != NULL) {
+ ISC_LIST_FOREACH_SAFE (sctx->altsecrets, altsecret, link) {
ISC_LIST_UNLINK(sctx->altsecrets, altsecret, link);
isc_mem_put(sctx->mctx, altsecret, sizeof(*altsecret));
}
isc_quota_destroy(&sctx->tcpquota);
isc_quota_destroy(&sctx->xfroutquota);
- http_quota = ISC_LIST_HEAD(sctx->http_quotas);
- while (http_quota != NULL) {
- isc_quota_t *next = NULL;
-
- next = ISC_LIST_NEXT(http_quota, link);
+ ISC_LIST_FOREACH_SAFE (sctx->http_quotas, http_quota, link) {
ISC_LIST_DEQUEUE(sctx->http_quotas, http_quota, link);
isc_quota_destroy(http_quota);
isc_mem_put(sctx->mctx, http_quota,
sizeof(*http_quota));
- http_quota = next;
}
isc_mutex_destroy(&sctx->http_quotas_lock);
do_diff(dns_diff_t *updates, dns_db_t *db, dns_dbversion_t *ver,
dns_diff_t *diff) {
isc_result_t result;
- while (!ISC_LIST_EMPTY(updates->tuples)) {
- dns_difftuple_t *t = ISC_LIST_HEAD(updates->tuples);
+ ISC_LIST_FOREACH_SAFE (updates->tuples, t, link) {
ISC_LIST_UNLINK(updates->tuples, t, link);
CHECK(do_one_tuple(&t, db, ver, diff));
}