outbound_list.c revision 1.2
1/*	$OpenBSD: outbound_list.c,v 1.2 2015/01/20 04:41:01 krw Exp $	*/
2/*
3 * services/outbound_list.c - keep list of outbound serviced queries.
4 *
5 * Copyright (c) 2007, NLnet Labs. All rights reserved.
6 *
7 * This software is open source.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 *
13 * Redistributions of source code must retain the above copyright notice,
14 * this list of conditions and the following disclaimer.
15 *
16 * Redistributions in binary form must reproduce the above copyright notice,
17 * this list of conditions and the following disclaimer in the documentation
18 * and/or other materials provided with the distribution.
19 *
20 * Neither the name of the NLNET LABS nor the names of its contributors may
21 * be used to endorse or promote products derived from this software without
22 * specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
27 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
28 * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
29 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
30 * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
31 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
32 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
33 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
34 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 */
36
37/**
38 * \file
39 *
40 * This file contains functions to help a module keep track of the
41 * queries it has outstanding to authoritative servers.
42 */
43#include "config.h"
44#include <sys/time.h>
45#include "services/outbound_list.h"
46#include "services/outside_network.h"
47
48void
49outbound_list_init(struct outbound_list* list)
50{
51	list->first = NULL;
52}
53
54void
55outbound_list_clear(struct outbound_list* list)
56{
57	struct outbound_entry *p, *np;
58	p = list->first;
59	while(p) {
60		np = p->next;
61		outnet_serviced_query_stop(p->qsent, p);
62		/* in region, no free needed */
63		p = np;
64	}
65	outbound_list_init(list);
66}
67
68void
69outbound_list_insert(struct outbound_list* list, struct outbound_entry* e)
70{
71	if(list->first)
72		list->first->prev = e;
73	e->next = list->first;
74	e->prev = NULL;
75	list->first = e;
76}
77
78void
79outbound_list_remove(struct outbound_list* list, struct outbound_entry* e)
80{
81	if(!e)
82		return;
83	outnet_serviced_query_stop(e->qsent, e);
84	if(e->next)
85		e->next->prev = e->prev;
86	if(e->prev)
87		e->prev->next = e->next;
88	else	list->first = e->next;
89	/* in region, no free needed */
90}
91