7 * Copyright (C) 1997-1999 Ian Jackson <ian@davenant.greenend.org.uk>
9 * It is part of adns, which is
10 * Copyright (C) 1997-2000 Ian Jackson <ian@davenant.greenend.org.uk>
11 * Copyright (C) 1999-2000 Tony Finch <dot@dotat.at>
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2, or (at your option)
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software Foundation,
25 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
30 void adns_checkconsistency(adns_state ads, adns_query qu) {
31 adns__consistency(ads,qu,cc_user);
34 #define DLIST_CHECK(list, nodevar, part, body) \
36 assert(! (list).head->part back); \
37 for ((nodevar)= (list).head; \
39 (nodevar)= (nodevar)->part next) { \
40 assert((nodevar)->part next \
41 ? (nodevar) == (nodevar)->part next->part back \
42 : (nodevar) == (list).tail); \
47 #define DLIST_ASSERTON(node, nodevar, list, part) \
49 for ((nodevar)= (list).head; \
50 (nodevar) != (node); \
51 (nodevar)= (nodevar)->part next) { \
56 static void checkc_query_alloc(adns_state ads, adns_query qu) {
59 DLIST_CHECK(qu->allocations, an, , {
63 static void checkc_query(adns_state ads, adns_query qu) {
66 assert(qu->udpnextserver < ads->nservers);
67 assert(!(qu->udpsent & (~0UL << ads->nservers)));
68 assert(qu->search_pos <= ads->nsearchlist);
69 if (qu->parent) DLIST_ASSERTON(qu, child, qu->parent->children, siblings.);
72 static void checkc_notcpbuf(adns_state ads) {
73 assert(!ads->tcpsend.used);
74 assert(!ads->tcprecv.used);
75 assert(!ads->tcprecv_skip);
78 static void checkc_global(adns_state ads) {
81 assert(ads->udpsocket >= 0);
83 for (i=0; i<ads->nsortlist; i++)
84 assert(!(ads->sortlist[i].base.s_addr & ~ads->sortlist[i].mask.s_addr));
86 assert(ads->tcpserver >= 0 && ads->tcpserver < ads->nservers);
88 switch (ads->tcpstate) {
89 case server_connecting:
90 assert(ads->tcpsocket >= 0);
93 case server_disconnected:
95 assert(ads->tcpsocket == -1);
99 assert(ads->tcpsocket >= 0);
100 assert(ads->tcprecv_skip <= ads->tcprecv.used);
103 assert(!"ads->tcpstate value");
106 assert(ads->searchlist || !ads->nsearchlist);
109 static void checkc_queue_udpw(adns_state ads) {
112 DLIST_CHECK(ads->udpw, qu, , {
113 assert(qu->state==query_tosend);
114 assert(qu->retries <= UDPMAXRETRIES);
116 assert(!qu->children.head && !qu->children.tail);
117 checkc_query(ads,qu);
118 checkc_query_alloc(ads,qu);
122 static void checkc_queue_tcpw(adns_state ads) {
125 DLIST_CHECK(ads->tcpw, qu, , {
126 assert(qu->state==query_tcpw);
127 assert(!qu->children.head && !qu->children.tail);
128 assert(qu->retries <= ads->nservers+1);
129 checkc_query(ads,qu);
130 checkc_query_alloc(ads,qu);
134 static void checkc_queue_childw(adns_state ads) {
135 adns_query parent, child;
137 DLIST_CHECK(ads->childw, parent, , {
138 assert(parent->state == query_childw);
139 assert(parent->children.head);
140 DLIST_CHECK(parent->children, child, siblings., {
141 assert(child->parent == parent);
142 assert(child->state != query_done);
144 checkc_query(ads,parent);
145 checkc_query_alloc(ads,parent);
149 static void checkc_queue_output(adns_state ads) {
152 DLIST_CHECK(ads->output, qu, , {
153 assert(qu->state == query_done);
154 assert(!qu->children.head && !qu->children.tail);
156 assert(!qu->allocations.head && !qu->allocations.tail);
157 checkc_query(ads,qu);
161 void adns__consistency(adns_state ads, adns_query qu, consistency_checks cc) {
168 if (!(ads->iflags & adns_if_checkc_entex)) return;
171 if ((ads->iflags & adns_if_checkc_freq) != adns_if_checkc_freq) return;
178 checkc_queue_udpw(ads);
179 checkc_queue_tcpw(ads);
180 checkc_queue_childw(ads);
181 checkc_queue_output(ads);
186 DLIST_ASSERTON(qu, search, ads->udpw, );
189 DLIST_ASSERTON(qu, search, ads->tcpw, );
192 DLIST_ASSERTON(qu, search, ads->childw, );
195 DLIST_ASSERTON(qu, search, ads->output, );
198 assert(!"specific query state");