head 1.5; access; symbols adns_1_0:1.1.1.3 adns_0_9:1.1.1.2 adns_0_8:1.1.1.2 adns_0_7:1.1.1.1 adns_0_6:1.1.1.1 vendor:1.1.1; locks; strict; comment @ * @; 1.5 date 2000.09.19.15.55.21; author rse; state Exp; branches; next 1.4; 1.4 date 2000.08.12.12.01.15; author rse; state Exp; branches; next 1.3; 1.3 date 2000.05.08.14.10.24; author rse; state Exp; branches; next 1.2; 1.2 date 99.11.30.15.51.12; author rse; state Exp; branches; next 1.1; 1.1 date 99.11.30.15.42.25; author rse; state Exp; branches 1.1.1.1; next ; 1.1.1.1 date 99.11.30.15.42.25; author rse; state Exp; branches; next 1.1.1.2; 1.1.1.2 date 2000.05.08.14.05.32; author rse; state Exp; branches; next 1.1.1.3; 1.1.1.3 date 2000.09.19.15.46.45; author rse; state Exp; branches; next ; desc @@ 1.5 log @Merge in conflicts @ text @/* * check.c * - consistency checks */ /* * This file is * Copyright (C) 1997-1999 Ian Jackson * * It is part of adns, which is * Copyright (C) 1997-2000 Ian Jackson * Copyright (C) 1999-2000 Tony Finch * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software Foundation, * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "adns_internal.h" void adns_checkconsistency(adns_state ads, adns_query qu) { adns__consistency(ads,qu,cc_user); } #define ADNS_DLIST_CHECK(list, nodevar, part, body) \ if ((list).head) { \ assert(! (list).head->part back); \ for ((nodevar)= (list).head; (nodevar); (nodevar)= (nodevar)->part next) { \ assert((nodevar)->part next \ ? (nodevar) == (nodevar)->part next->part back \ : (nodevar) == (list).tail); \ body \ } \ } #define ADNS_DLIST_ASSERTON(node, nodevar, list, part) \ do { \ for ((nodevar)= (list).head; \ (nodevar) != (node); \ (nodevar)= (nodevar)->part next) { \ assert((nodevar)); \ } \ } while(0) static void checkc_query_alloc(adns_state ads, adns_query qu) { allocnode *an; ADNS_DLIST_CHECK(qu->allocations, an, , { }); } static void checkc_query(adns_state ads, adns_query qu) { adns_query child; assert(qu->udpnextserver < ads->nservers); assert(!(qu->udpsent & (~0UL << ads->nservers))); assert(qu->search_pos <= ads->nsearchlist); if (qu->parent) ADNS_DLIST_ASSERTON(qu, child, qu->parent->children, siblings.); } static void checkc_notcpbuf(adns_state ads) { assert(!ads->tcpsend.used); assert(!ads->tcprecv.used); assert(!ads->tcprecv_skip); } static void checkc_global(adns_state ads) { int i; assert(ads->udpsocket >= 0); for (i=0; insortlist; i++) assert(!(ads->sortlist[i].base.s_addr & ~ads->sortlist[i].mask.s_addr)); assert(ads->tcpserver >= 0 && ads->tcpserver < ads->nservers); switch (ads->tcpstate) { case server_connecting: assert(ads->tcpsocket >= 0); checkc_notcpbuf(ads); break; case server_disconnected: case server_broken: assert(ads->tcpsocket == -1); checkc_notcpbuf(ads); break; case server_ok: assert(ads->tcpsocket >= 0); assert(ads->tcprecv_skip <= ads->tcprecv.used); break; default: assert(!"ads->tcpstate value"); } assert(ads->searchlist || !ads->nsearchlist); } static void checkc_queue_udpw(adns_state ads) { adns_query qu; ADNS_DLIST_CHECK(ads->udpw, qu, , { assert(qu->state==query_tosend); assert(qu->retries <= UDPMAXRETRIES); assert(qu->udpsent); assert(!qu->children.head && !qu->children.tail); checkc_query(ads,qu); checkc_query_alloc(ads,qu); }); } static void checkc_queue_tcpw(adns_state ads) { adns_query qu; ADNS_DLIST_CHECK(ads->tcpw, qu, , { assert(qu->state==query_tcpw); assert(!qu->children.head && !qu->children.tail); assert(qu->retries <= ads->nservers+1); checkc_query(ads,qu); checkc_query_alloc(ads,qu); }); } static void checkc_queue_childw(adns_state ads) { adns_query parent, child; ADNS_DLIST_CHECK(ads->childw, parent, , { assert(parent->state == query_childw); assert(parent->children.head); ADNS_DLIST_CHECK(parent->children, child, siblings., { assert(child->parent == parent); assert(child->state != query_done); }); checkc_query(ads,parent); checkc_query_alloc(ads,parent); }); } static void checkc_queue_output(adns_state ads) { adns_query qu; ADNS_DLIST_CHECK(ads->output, qu, , { assert(qu->state == query_done); assert(!qu->children.head && !qu->children.tail); assert(!qu->parent); assert(!qu->allocations.head && !qu->allocations.tail); checkc_query(ads,qu); }); } void adns__consistency(adns_state ads, adns_query qu, consistency_checks cc) { adns_query search; switch (cc) { case cc_user: break; case cc_entex: if (!(ads->iflags & adns_if_checkc_entex)) return; break; case cc_freq: if ((ads->iflags & adns_if_checkc_freq) != adns_if_checkc_freq) return; break; default: abort(); } checkc_global(ads); checkc_queue_udpw(ads); checkc_queue_tcpw(ads); checkc_queue_childw(ads); checkc_queue_output(ads); if (qu) { switch (qu->state) { case query_tosend: ADNS_DLIST_ASSERTON(qu, search, ads->udpw, ); break; case query_tcpw: ADNS_DLIST_ASSERTON(qu, search, ads->tcpw, ); break; case query_childw: ADNS_DLIST_ASSERTON(qu, search, ads->childw, ); break; case query_done: ADNS_DLIST_ASSERTON(qu, search, ads->output, ); break; default: assert(!"specific query state"); } } } @ 1.4 log @- merge in conflicts of upgrade to ADNS 0.9 - upgrade to GNU shtool 1.5.1 - upgrade to GNU libtool 1.3.5 - replace LIST_ stuff with ADNS_LIST_ to avoid conflicts with FreeBSD @ text @d11 1 a11 1 * Copyright (C) 1999 Tony Finch @ 1.3 log @Resolve conflicts with ADNS 0.8 @ text @d34 1 a34 1 #define DLIST_CHECK(list, nodevar, part, body) \ d45 1 a45 1 #define DLIST_ASSERTON(node, nodevar, list, part) \ d57 1 a57 1 DLIST_CHECK(qu->allocations, an, , { d67 1 a67 1 if (qu->parent) DLIST_ASSERTON(qu, child, qu->parent->children, siblings.); d110 1 a110 1 DLIST_CHECK(ads->udpw, qu, , { d123 1 a123 1 DLIST_CHECK(ads->tcpw, qu, , { d135 1 a135 1 DLIST_CHECK(ads->childw, parent, , { d138 1 a138 1 DLIST_CHECK(parent->children, child, siblings., { d150 1 a150 1 DLIST_CHECK(ads->output, qu, , { d184 1 a184 1 DLIST_ASSERTON(qu, search, ads->udpw, ); d187 1 a187 1 DLIST_ASSERTON(qu, search, ads->tcpw, ); d190 1 a190 1 DLIST_ASSERTON(qu, search, ads->childw, ); d193 1 a193 1 DLIST_ASSERTON(qu, search, ads->output, ); @ 1.2 log @Adjust sources for OSSP source tree layout @ text @d10 1 a10 1 * Copyright (C) 1997-1999 Ian Jackson @ 1.1 log @Initial revision @ text @d28 1 a28 1 #include "internal.h" @ 1.1.1.1 log @Import of adns 0.6; adjusted for OSSP @ text @@ 1.1.1.2 log @Import of ADNS 0.8 @ text @d10 1 a10 1 * Copyright (C) 1997-2000 Ian Jackson @ 1.1.1.3 log @Import of ADNS 1.0 @ text @d11 1 a11 1 * Copyright (C) 1999-2000 Tony Finch @