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.12 2000/11/03 22:35:10 zarq Exp $
28 #include "net.h" /* Don't ask. */
36 /* Root of the connection list */
38 conn_list_t *conn_list = NULL;
39 conn_list_t *myself = NULL;
41 /* Creation and deletion of conn_list elements */
43 conn_list_t *new_conn_list(void)
45 conn_list_t *p = (conn_list_t *)xmalloc(sizeof(*p));
47 /* initialise all those stupid pointers at once */
48 memset(p, '\0', sizeof(*p));
53 void free_conn_list(conn_list_t *p)
60 if(p->name && p->name!=unknown)
67 free(p->cipher_pktkey);
71 clear_config(&p->config);
77 remove all marked connections
79 void prune_conn_list(void)
81 conn_list_t *p, *prev = NULL, *next = NULL;
83 for(p = conn_list; p != NULL; )
98 free all elements of conn_list
100 void destroy_conn_list(void)
102 conn_list_t *p, *next;
104 for(p = conn_list; p != NULL; )
115 /* Linked list management */
117 void conn_list_add(conn_list_t *cl)
120 cl->next = conn_list;
130 void conn_list_del(conn_list_t *cl)
134 cl->prev->next = cl->next;
136 conn_list = cl->next;
139 cl->next->prev = cl->prev;
145 /* Lookup functions */
147 conn_list_t *lookup_id(char *name)
151 for(p = conn_list; p != NULL; p = p->next)
153 if(strcmp(name, p->name) == 0)
161 void dump_conn_list(void)
167 syslog(LOG_DEBUG, _("Connection list:"));
169 syslog(LOG_DEBUG, _("%s at %s port %hd flags %d sockets %d, %d status %04x"),
170 myself->name, myself->hostname, myself->port, myself->flags,
171 myself->socket, myself->meta_socket, myself->status);
173 for(s = myself->subnets; s != NULL; s = s->next)
176 syslog(LOG_DEBUG, " %s", netstr);
180 for(p = conn_list; p != NULL; p = p->next)
182 syslog(LOG_DEBUG, _(" %s at %s port %hd flags %d sockets %d, %d status %04x"),
183 p->name, p->hostname, p->port, p->flags,
184 p->socket, p->meta_socket, p->status);
186 for(s = p->subnets; s != NULL; s = s->next)
189 syslog(LOG_DEBUG, " %s", netstr);
194 syslog(LOG_DEBUG, _("End of connection list."));
198 int read_host_config(conn_list_t *cl)
203 asprintf(&fname, "%s/hosts/%s", confbase, cl->name);
204 x = read_config_file(&cl->config, fname);