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_query qu
) {
26 adns__consistency(ads
,qu
,cc_user
);
29 #define DLIST_CHECK(list, nodevar, part, body) \
31 assert(! (list).head->part back); \
32 for ((nodevar)= (list).head; (nodevar); (nodevar)= (nodevar)->part next) { \
33 assert((nodevar)->part next \
34 ? (nodevar) == (nodevar)->part next->part back \
35 : (nodevar) == (list).tail); \
40 #define DLIST_ASSERTON(node, nodevar, list, part) \
42 for ((nodevar)= (list).head; \
43 (nodevar) != (node); \
44 (nodevar)= (nodevar)->part next) { \
49 static void checkc_query_alloc(adns_state ads
, adns_query qu
) {
52 DLIST_CHECK(qu
->allocations
, an
, , {
56 static void checkc_query(adns_state ads
, adns_query qu
) {
59 assert(qu
->udpnextserver
< ads
->nservers
);
60 assert(!(qu
->udpsent
& (~0UL << ads
->nservers
)));
61 assert(!(qu
->tcpfailed
& (~0UL << ads
->nservers
)));
62 assert(qu
->udpretries
<= UDPMAXRETRIES
);
63 assert(qu
->search_pos
<= ads
->nsearchlist
);
64 if (qu
->parent
) DLIST_ASSERTON(qu
, child
, qu
->parent
->children
, siblings
.);
67 static void checkc_global(adns_state ads
) {
70 assert(ads
->udpsocket
>= 0);
72 for (i
=0; i
<ads
->nsortlist
; i
++)
73 assert(!(ads
->sortlist
[i
].base
.s_addr
& ~ads
->sortlist
[i
].mask
.s_addr
));
75 assert(ads
->tcpserver
>= 0 && ads
->tcpserver
< ads
->nservers
);
77 switch (ads
->tcpstate
) {
78 case server_connecting
:
79 assert(ads
->tcpsocket
>= 0);
80 case server_disconnected
: /* fall through */
81 assert(!ads
->tcprecv
.used
);
82 assert(!ads
->tcpsend
.used
);
85 assert(ads
->tcpsocket
>= 0);
88 assert(!"ads->tcpstate value");
91 assert(ads
->searchlist
|| !ads
->nsearchlist
);
94 static void checkc_queue_timew(adns_state ads
) {
97 DLIST_CHECK(ads
->timew
, qu
, , {
101 assert(!qu
->tcpfailed
);
104 assert(ads
->tcpstate
!= server_ok
);
109 assert(!"timew state");
111 assert(!qu
->children
.head
&& !qu
->children
.tail
);
112 checkc_query(ads
,qu
);
113 checkc_query_alloc(ads
,qu
);
117 static void checkc_queue_childw(adns_state ads
) {
118 adns_query parent
, child
;
120 DLIST_CHECK(ads
->childw
, parent
, , {
121 assert(parent
->state
== query_child
);
122 assert(parent
->children
.head
);
123 DLIST_CHECK(parent
->children
, child
, siblings
., {
124 assert(child
->parent
== parent
);
125 assert(child
->state
!= query_done
);
127 checkc_query(ads
,parent
);
128 checkc_query_alloc(ads
,parent
);
132 static void checkc_queue_output(adns_state ads
) {
135 DLIST_CHECK(ads
->output
, qu
, , {
136 assert(qu
->state
== query_done
);
137 assert(!qu
->children
.head
&& !qu
->children
.tail
);
139 checkc_query(ads
,qu
);
143 void adns__consistency(adns_state ads
, adns_query qu
, consistency_checks cc
) {
150 if (!(ads
->iflags
& adns_if_checkc_entex
)) return;
153 if ((ads
->iflags
& adns_if_checkc_freq
) != adns_if_checkc_freq
) return;
160 checkc_queue_timew(ads
);
161 checkc_queue_childw(ads
);
162 checkc_queue_output(ads
);
169 DLIST_ASSERTON(qu
, search
, ads
->timew
, );
172 DLIST_ASSERTON(qu
, search
, ads
->childw
, );
175 DLIST_ASSERTON(qu
, search
, ads
->output
, );
178 assert(!"specific query state");