7 * Copyright (C) 1997-1999 Ian Jackson <ian@davenant.greenend.org.uk>
9 * It is part of adns, which is
10 * Copyright (C) 1997-1999 Ian Jackson <ian@davenant.greenend.org.uk>
11 * Copyright (C) 1999 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; (nodevar); (nodevar)= (nodevar)->part next) { \
38 assert((nodevar)->part next \
39 ? (nodevar) == (nodevar)->part next->part back \
40 : (nodevar) == (list).tail); \
45 #define DLIST_ASSERTON(node, nodevar, list, part) \
47 for ((nodevar)= (list).head; \
48 (nodevar) != (node); \
49 (nodevar)= (nodevar)->part next) { \
54 static void checkc_query_alloc(adns_state ads, adns_query qu) {
57 DLIST_CHECK(qu->allocations, an, , {
61 static void checkc_query(adns_state ads, adns_query qu) {
64 assert(qu->udpnextserver < ads->nservers);
65 assert(!(qu->udpsent & (~0UL << ads->nservers)));
66 assert(qu->search_pos <= ads->nsearchlist);
67 if (qu->parent) DLIST_ASSERTON(qu, child, qu->parent->children, siblings.);
70 static void checkc_notcpbuf(adns_state ads) {
71 assert(!ads->tcpsend.used);
72 assert(!ads->tcprecv.used);
73 assert(!ads->tcprecv_skip);
76 static void checkc_global(adns_state ads) {
79 assert(ads->udpsocket >= 0);
81 for (i=0; i<ads->nsortlist; i++)
82 assert(!(ads->sortlist[i].base.s_addr & ~ads->sortlist[i].mask.s_addr));
84 assert(ads->tcpserver >= 0 && ads->tcpserver < ads->nservers);
86 switch (ads->tcpstate) {
87 case server_connecting:
88 assert(ads->tcpsocket >= 0);
91 case server_disconnected:
93 assert(ads->tcpsocket == -1);
97 assert(ads->tcpsocket >= 0);
98 assert(ads->tcprecv_skip <= ads->tcprecv.used);
101 assert(!"ads->tcpstate value");
104 assert(ads->searchlist || !ads->nsearchlist);
107 static void checkc_queue_udpw(adns_state ads) {
110 DLIST_CHECK(ads->udpw, qu, , {
111 assert(qu->state==query_tosend);
112 assert(qu->retries <= UDPMAXRETRIES);
114 assert(!qu->children.head && !qu->children.tail);
115 checkc_query(ads,qu);
116 checkc_query_alloc(ads,qu);
120 static void checkc_queue_tcpw(adns_state ads) {
123 DLIST_CHECK(ads->tcpw, qu, , {
124 assert(qu->state==query_tcpw);
125 assert(!qu->children.head && !qu->children.tail);
126 assert(qu->retries <= ads->nservers+1);
127 checkc_query(ads,qu);
128 checkc_query_alloc(ads,qu);
132 static void checkc_queue_childw(adns_state ads) {
133 adns_query parent, child;
135 DLIST_CHECK(ads->childw, parent, , {
136 assert(parent->state == query_childw);
137 assert(parent->children.head);
138 DLIST_CHECK(parent->children, child, siblings., {
139 assert(child->parent == parent);
140 assert(child->state != query_done);
142 checkc_query(ads,parent);
143 checkc_query_alloc(ads,parent);
147 static void checkc_queue_output(adns_state ads) {
150 DLIST_CHECK(ads->output, qu, , {
151 assert(qu->state == query_done);
152 assert(!qu->children.head && !qu->children.tail);
154 assert(!qu->allocations.head && !qu->allocations.tail);
155 checkc_query(ads,qu);
159 void adns__consistency(adns_state ads, adns_query qu, consistency_checks cc) {
166 if (!(ads->iflags & adns_if_checkc_entex)) return;
169 if ((ads->iflags & adns_if_checkc_freq) != adns_if_checkc_freq) return;
176 checkc_queue_udpw(ads);
177 checkc_queue_tcpw(ads);
178 checkc_queue_childw(ads);
179 checkc_queue_output(ads);
184 DLIST_ASSERTON(qu, search, ads->udpw, );
187 DLIST_ASSERTON(qu, search, ads->tcpw, );
190 DLIST_ASSERTON(qu, search, ads->childw, );
193 DLIST_ASSERTON(qu, search, ads->output, );
196 assert(!"specific query state");