2 connlist.c -- connection list management
3 Copyright (C) 2000 Guus Sliepen <guus@sliepen.warande.net>,
4 2000 Ivo Timmermans <itimmermans@bigfoot.com>
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 $Id: connlist.c,v 1.1.2.1 2000/10/11 10:35:15 guus Exp $
28 /* Root of the connection list */
30 conn_list_t *conn_list = NULL;
31 conn_list_t *myself = NULL;
33 /* Creation and deletion of conn_list elements */
35 conn_list_t *new_conn_list(void)
37 conn_list_t *p = xmalloc(sizeof(*p));
39 /* initialise all those stupid pointers at once */
40 memset(p, '\0', sizeof(*p));
45 void free_conn_list(conn_list_t *p)
56 free_key(p->public_key);
63 remove all marked connections
65 void prune_conn_list(void)
67 conn_list_t *p, *prev = NULL, *next = NULL;
69 for(p = conn_list; p != NULL; )
91 free all elements of conn_list
93 void destroy_conn_list(void)
95 conn_list_t *p, *next;
97 for(p = conn_list; p != NULL; )
100 free_conn_element(p);
108 /* Linked list management */
110 void conn_list_add(conn_list_t *cl)
120 void conn_list_del(conn_list_t *cl)
124 cl->prev->next = cl->next;
128 cl->next->prev = cl->prev;
133 /* Lookup functions */
135 conn_list_t *lookup_conn_list_mac(mac_t address)
139 for(p = conn_list; p != NULL; p = p->next)
140 if(lookup_subnet_mac(p, address))
146 conn_list_t *lookup_conn_list_ipv4(ipv4_t address)
150 for(p = conn_list; p != NULL; p = p->next)
151 if(lookup_subnet_ipv4(p, address))
157 conn_list_t *lookup_conn_list_ipv6(ipv6_t address)
161 for(p = conn_list; p != NULL; p = p->next)
162 if(lookup_subnet_ipv6(p, address))
170 void dump_conn_list(void)
174 syslog(LOG_DEBUG, _("Connection list:"));
176 for(p = conn_list; p != NULL; p = p->next)
178 syslog(LOG_DEBUG, _("%s netmask %d.%d.%d.%d at %s port %hd flags %d sockets %d, %d status %04x"),
179 p->name, IP_ADDR_V(p->vpn_mask), p->hostname, p->port, p->flags,
180 p->socket, p->meta_socket, p->status);