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
->tcpsend
.used
);
87 assert(!ads
->tcprecv
.used
);
88 assert(!ads
->tcprecv_skip
);
91 assert(ads
->tcpsocket
>= 0);
92 assert(ads
->tcprecv_skip
<= ads
->tcprecv
.used
);
95 assert(!"ads->tcpstate value");
98 assert(ads
->searchlist
|| !ads
->nsearchlist
);
101 static void checkc_queue_timew(adns_state ads
) {
104 DLIST_CHECK(ads
->timew
, qu
, , {
108 assert(!qu
->tcpfailed
);
111 assert(ads
->tcpstate
!= server_ok
);
116 assert(!"timew state");
118 assert(!qu
->children
.head
&& !qu
->children
.tail
);
119 checkc_query(ads
,qu
);
120 checkc_query_alloc(ads
,qu
);
124 static void checkc_queue_childw(adns_state ads
) {
125 adns_query parent
, child
;
127 DLIST_CHECK(ads
->childw
, parent
, , {
128 assert(parent
->state
== query_child
);
129 assert(parent
->children
.head
);
130 DLIST_CHECK(parent
->children
, child
, siblings
., {
131 assert(child
->parent
== parent
);
132 assert(child
->state
!= query_done
);
134 checkc_query(ads
,parent
);
135 checkc_query_alloc(ads
,parent
);
139 static void checkc_queue_output(adns_state ads
) {
142 DLIST_CHECK(ads
->output
, qu
, , {
143 assert(qu
->state
== query_done
);
144 assert(!qu
->children
.head
&& !qu
->children
.tail
);
146 assert(!qu
->allocations
.head
&& !qu
->allocations
.tail
);
147 checkc_query(ads
,qu
);
151 void adns__consistency(adns_state ads
, adns_query qu
, consistency_checks cc
) {
158 if (!(ads
->iflags
& adns_if_checkc_entex
)) return;
161 if ((ads
->iflags
& adns_if_checkc_freq
) != adns_if_checkc_freq
) return;
168 checkc_queue_timew(ads
);
169 checkc_queue_childw(ads
);
170 checkc_queue_output(ads
);
177 DLIST_ASSERTON(qu
, search
, ads
->timew
, );
180 DLIST_ASSERTON(qu
, search
, ads
->childw
, );
183 DLIST_ASSERTON(qu
, search
, ads
->output
, );
186 assert(!"specific query state");