2 connection.c -- connection list management
3 Copyright (C) 2000-2012 Guus Sliepen <guus@tinc-vpn.org>,
4 2000-2005 Ivo Timmermans
5 2008 Max Rijevski <maksuf@gmail.com>
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License along
18 with this program; if not, write to the Free Software Foundation, Inc.,
19 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
31 avl_tree_t *connection_tree; /* Meta connections */
32 connection_t *everyone;
34 static int connection_compare(const connection_t *a, const connection_t *b) {
35 return a < b ? -1 : a == b ? 0 : 1;
38 void init_connections(void) {
39 connection_tree = avl_alloc_tree((avl_compare_t) connection_compare, (avl_action_t) free_connection);
40 everyone = new_connection();
41 everyone->name = xstrdup("everyone");
42 everyone->hostname = xstrdup("BROADCAST");
45 void exit_connections(void) {
46 avl_delete_tree(connection_tree);
47 free_connection(everyone);
50 connection_t *new_connection(void) {
53 c = xmalloc_and_zero(sizeof(connection_t));
58 gettimeofday(&c->start, NULL);
63 void free_connection_partially(connection_t *c) {
67 free(c->hischallenge);
72 c->mychallenge = NULL;
73 c->hischallenge = NULL;
85 EVP_CIPHER_CTX_cleanup(c->inctx);
91 EVP_CIPHER_CTX_cleanup(c->outctx);
102 void free_connection(connection_t *c) {
103 free_connection_partially(c);
109 exit_configuration(&c->config_tree);
114 void connection_add(connection_t *c) {
115 avl_insert(connection_tree, c);
118 void connection_del(connection_t *c) {
119 avl_delete(connection_tree, c);
122 void dump_connections(void) {
126 logger(LOG_DEBUG, "Connections:");
128 for(node = connection_tree->head; node; node = node->next) {
130 logger(LOG_DEBUG, " %s at %s options %x socket %d status %04x outbuf %d/%d/%d",
131 c->name, c->hostname, c->options, c->socket, bitfield_to_int(&c->status, sizeof c->status),
132 c->outbufsize, c->outbufstart, c->outbuflen);
135 logger(LOG_DEBUG, "End of connections.");