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->tcpfailed & (~0UL << ads->nservers)));
67 assert(qu->udpretries <= UDPMAXRETRIES);
68 assert(qu->search_pos <= ads->nsearchlist);
69 if (qu->parent) DLIST_ASSERTON(qu, child, qu->parent->children, siblings.);
72 static void checkc_global(adns_state ads) {
75 assert(ads->udpsocket >= 0);
77 for (i=0; i<ads->nsortlist; i++)
78 assert(!(ads->sortlist[i].base.s_addr & ~ads->sortlist[i].mask.s_addr));
80 assert(ads->tcpserver >= 0 && ads->tcpserver < ads->nservers);
82 switch (ads->tcpstate) {
83 case server_connecting:
84 assert(ads->tcpsocket >= 0);
85 case server_disconnected: /* fall through */
86 assert(!ads->tcprecv.used);
87 assert(!ads->tcpsend.used);
90 assert(ads->tcpsocket >= 0);
93 assert(!"ads->tcpstate value");
96 assert(ads->searchlist || !ads->nsearchlist);
99 static void checkc_queue_timew(adns_state ads) {
102 DLIST_CHECK(ads->timew, qu, , {
106 assert(!qu->tcpfailed);
109 assert(ads->tcpstate != server_ok);
114 assert(!"timew state");
116 assert(!qu->children.head && !qu->children.tail);
117 checkc_query(ads,qu);
118 checkc_query_alloc(ads,qu);
122 static void checkc_queue_childw(adns_state ads) {
123 adns_query parent, child;
125 DLIST_CHECK(ads->childw, parent, , {
126 assert(parent->state == query_child);
127 assert(parent->children.head);
128 DLIST_CHECK(parent->children, child, siblings., {
129 assert(child->parent == parent);
130 assert(child->state != query_done);
132 checkc_query(ads,parent);
133 checkc_query_alloc(ads,parent);
137 static void checkc_queue_output(adns_state ads) {
140 DLIST_CHECK(ads->output, qu, , {
141 assert(qu->state == query_done);
142 assert(!qu->children.head && !qu->children.tail);
144 assert(!qu->allocations.head && !qu->allocations.tail);
145 checkc_query(ads,qu);
149 void adns__consistency(adns_state ads, adns_query qu, consistency_checks cc) {
156 if (!(ads->iflags & adns_if_checkc_entex)) return;
159 if ((ads->iflags & adns_if_checkc_freq) != adns_if_checkc_freq) return;
166 checkc_queue_timew(ads);
167 checkc_queue_childw(ads);
168 checkc_queue_output(ads);
175 DLIST_ASSERTON(qu, search, ads->timew, );
178 DLIST_ASSERTON(qu, search, ads->childw, );
181 DLIST_ASSERTON(qu, search, ads->output, );
184 assert(!"specific query state");