6 * This file is part of adns, which is Copyright (C) 1997-1999 Ian Jackson
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2, or (at your option)
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software Foundation,
20 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25 void adns_checkconsistency(adns_state ads) { adns__consistency(ads,cc_user); }
27 #define DLIST_CHECK(list, nodevar, part, body) \
29 assert(! (list).head->part back); \
30 for ((nodevar)= (list).head; (nodevar); (nodevar)= (nodevar)->part next) { \
31 assert((nodevar)->part next \
32 ? (nodevar) == (nodevar)->part next->part back \
33 : (nodevar) == (list).tail); \
38 static void checkc_query_alloc(adns_state ads, adns_query qu) {
41 DLIST_CHECK(qu->allocations, an, , {
45 static void checkc_query(adns_state ads, adns_query qu) {
46 assert(qu->udpnextserver < ads->nservers);
47 assert(!(qu->udpsent & (~0UL << ads->nservers)));
48 assert(!(qu->tcpfailed & (~0UL << ads->nservers)));
49 assert(qu->udpretries <= UDPMAXRETRIES);
50 assert(qu->search_pos <= ads->nsearchlist);
53 static void checkc_global(adns_state ads) {
56 assert(ads->udpsocket >= 0);
58 for (i=0; i<ads->nsortlist; i++)
59 assert(!(ads->sortlist[i].base.s_addr & ~ads->sortlist[i].mask.s_addr));
61 assert(ads->tcpserver >= 0 && ads->tcpserver < ads->nservers);
63 switch (ads->tcpstate) {
64 case server_connecting:
65 assert(ads->tcpsocket >= 0);
66 case server_disconnected: /* fall through */
67 assert(!ads->tcprecv.used);
68 assert(!ads->tcpsend.used);
71 assert(ads->tcpsocket >= 0);
74 assert(!"ads->tcpstate value");
77 assert(ads->searchlist || !ads->nsearchlist);
80 static void checkc_queue_timew(adns_state ads) {
83 DLIST_CHECK(ads->timew, qu, , {
87 assert(!qu->tcpfailed);
90 assert(ads->tcpstate != server_ok);
95 assert(!"timew state");
97 assert(!qu->children.head && !qu->children.tail);
99 checkc_query_alloc(ads,qu);
103 static void checkc_queue_childw(adns_state ads) {
104 adns_query parent, child;
106 DLIST_CHECK(ads->childw, parent, , {
107 assert(parent->state == query_child);
108 assert(parent->children.head);
109 DLIST_CHECK(parent->children, child, siblings., {
110 assert(child->parent == parent);
111 assert(child->state != query_done);
113 checkc_query(ads,parent);
114 checkc_query_alloc(ads,parent);
118 static void checkc_queue_output(adns_state ads) {
121 DLIST_CHECK(ads->output, qu, , {
122 assert(qu->state == query_done);
123 assert(!qu->children.head && !qu->children.tail);
125 checkc_query(ads,qu);
129 void adns__consistency(adns_state ads, consistency_checks cc) {
134 if (!(ads->iflags & adns_if_checkc_entex)) return;
137 if ((ads->iflags & adns_if_checkc_freq) != adns_if_checkc_freq) return;
144 checkc_queue_timew(ads);
145 checkc_queue_childw(ads);
146 checkc_queue_output(ads);