6 * This file is part of adns, which is
7 * Copyright (C) 1997-2000,2003,2006 Ian Jackson
8 * Copyright (C) 1999-2000,2003,2006 Tony Finch
9 * Copyright (C) 1991 Massachusetts Institute of Technology
10 * (See the file INSTALL for full details.)
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2, or (at your option)
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software Foundation,
24 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
31 void adns_checkconsistency(adns_state ads, adns_query qu) {
32 adns__consistency(ads,qu,cc_user);
35 #define DLIST_CHECK(list, nodevar, part, body) \
37 assert(! (list).head->part back); \
38 for ((nodevar)= (list).head; \
40 (nodevar)= (nodevar)->part next) { \
41 assert((nodevar)->part next \
42 ? (nodevar) == (nodevar)->part next->part back \
43 : (nodevar) == (list).tail); \
48 #define DLIST_ASSERTON(node, nodevar, list, part) \
50 for ((nodevar)= (list).head; \
51 (nodevar) != (node); \
52 (nodevar)= (nodevar)->part next) { \
57 static void checkc_query_alloc(adns_state ads, adns_query qu) {
60 DLIST_CHECK(qu->allocations, an, , {
64 static void checkc_query(adns_state ads, adns_query qu) {
67 assert(qu->udpnextserver < ads->nservers);
68 assert(!(qu->udpsent & (~0UL << ads->nservers)));
69 assert(qu->search_pos <= ads->nsearchlist);
70 if (qu->parent) DLIST_ASSERTON(qu, child, qu->parent->children, siblings.);
73 static void checkc_notcpbuf(adns_state ads) {
74 assert(!ads->tcpsend.used);
75 assert(!ads->tcprecv.used);
76 assert(!ads->tcprecv_skip);
79 static void checkc_global(adns_state ads) {
82 assert(ads->udpsocket >= 0);
84 for (i=0; i<ads->nsortlist; i++)
85 assert(!(ads->sortlist[i].base.s_addr & ~ads->sortlist[i].mask.s_addr));
87 assert(ads->tcpserver >= 0 && ads->tcpserver < ads->nservers);
89 switch (ads->tcpstate) {
90 case server_connecting:
91 assert(ads->tcpsocket >= 0);
94 case server_disconnected:
96 assert(ads->tcpsocket == -1);
100 assert(ads->tcpsocket >= 0);
101 assert(ads->tcprecv_skip <= ads->tcprecv.used);
104 assert(!"ads->tcpstate value");
107 assert(ads->searchlist || !ads->nsearchlist);
110 static void checkc_queue_udpw(adns_state ads) {
113 DLIST_CHECK(ads->udpw, qu, , {
114 assert(qu->state==query_tosend);
115 assert(qu->retries <= UDPMAXRETRIES);
117 assert(!qu->children.head && !qu->children.tail);
118 checkc_query(ads,qu);
119 checkc_query_alloc(ads,qu);
123 static void checkc_queue_tcpw(adns_state ads) {
126 DLIST_CHECK(ads->tcpw, qu, , {
127 assert(qu->state==query_tcpw);
128 assert(!qu->children.head && !qu->children.tail);
129 assert(qu->retries <= ads->nservers+1);
130 checkc_query(ads,qu);
131 checkc_query_alloc(ads,qu);
135 static void checkc_queue_childw(adns_state ads) {
136 adns_query parent, child;
138 DLIST_CHECK(ads->childw, parent, , {
139 assert(parent->state == query_childw);
140 assert(parent->children.head);
141 DLIST_CHECK(parent->children, child, siblings., {
142 assert(child->parent == parent);
143 assert(child->state != query_done);
145 checkc_query(ads,parent);
146 checkc_query_alloc(ads,parent);
150 static void checkc_queue_output(adns_state ads) {
153 DLIST_CHECK(ads->output, qu, , {
154 assert(qu->state == query_done);
155 assert(!qu->children.head && !qu->children.tail);
157 assert(!qu->allocations.head && !qu->allocations.tail);
158 checkc_query(ads,qu);
162 void adns__consistency(adns_state ads, adns_query qu, consistency_checks cc) {
169 if (!(ads->iflags & adns_if_checkc_entex)) return;
172 if ((ads->iflags & adns_if_checkc_freq) != adns_if_checkc_freq) return;
179 checkc_queue_udpw(ads);
180 checkc_queue_tcpw(ads);
181 checkc_queue_childw(ads);
182 checkc_queue_output(ads);
187 DLIST_ASSERTON(qu, search, ads->udpw, );
190 DLIST_ASSERTON(qu, search, ads->tcpw, );
193 DLIST_ASSERTON(qu, search, ads->childw, );
196 DLIST_ASSERTON(qu, search, ads->output, );
199 assert(!"specific query state");