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.4 2000/10/15 00:59:34 guus Exp $
25 #include "net.h" /* Don't ask. */
32 /* Root of the connection list */
34 conn_list_t *conn_list = NULL;
35 conn_list_t *myself = NULL;
37 /* Creation and deletion of conn_list elements */
39 conn_list_t *new_conn_list(void)
41 conn_list_t *p = (conn_list_t *)xmalloc(sizeof(*p));
43 /* initialise all those stupid pointers at once */
44 memset(p, '\0', sizeof(*p));
49 void free_conn_list(conn_list_t *p)
56 if(p->name && p->name!=unknown)
61 RSA_free(p->public_key);
63 free(p->cipher_pktkey);
71 remove all marked connections
73 void prune_conn_list(void)
75 conn_list_t *p, *prev = NULL, *next = NULL;
77 for(p = conn_list; p != NULL; )
99 free all elements of conn_list
101 void destroy_conn_list(void)
103 conn_list_t *p, *next;
105 for(p = conn_list; p != NULL; )
116 /* Linked list management */
118 void conn_list_add(conn_list_t *cl)
121 cl->next = conn_list;
128 void conn_list_del(conn_list_t *cl)
132 cl->prev->next = cl->next;
134 conn_list = cl->next;
136 cl->next->prev = cl->prev;
141 /* Lookup functions */
143 conn_list_t *lookup_id(char *name)
147 for(p = conn_list; p != NULL; p = p->next)
148 if(strcmp(name, p->name) == 0)
154 conn_list_t *lookup_conn_list_mac(mac_t address)
158 for(p = conn_list; p != NULL; p = p->next)
159 if(lookup_subnet_mac(p->subnets, address))
165 conn_list_t *lookup_conn_list_ipv4(ipv4_t address)
169 for(p = conn_list; p != NULL; p = p->next)
170 if(lookup_subnet_ipv4(p->subnets, address))
176 conn_list_t *lookup_conn_list_ipv6(ipv6_t address)
180 for(p = conn_list; p != NULL; p = p->next)
181 if(lookup_subnet_ipv6(p->subnets, address))
189 void dump_conn_list(void)
195 syslog(LOG_DEBUG, _("Connection list:"));
197 for(p = conn_list; p != NULL; p = p->next)
199 syslog(LOG_DEBUG, _("%s at %s port %hd flags %d sockets %d, %d status %04x"),
200 p->name, p->hostname, p->port, p->flags,
201 p->socket, p->meta_socket, p->status);
202 for(s = p->subnets; s != NULL; s = s->next)
205 syslog(LOG_DEBUG, ": %s", netstr);
210 syslog(LOG_DEBUG, _("End of connection list."));
214 int read_host_config(conn_list_t *cl)
219 asprintf(&fname, "%s/hosts/%s", confbase, cl->name);
220 x = read_config_file(&cl->config, fname);