2 connection.c -- connection list management
3 Copyright (C) 2000-2013 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.
27 #include "control_common.h"
35 list_t *connection_list;
36 connection_t *everyone;
38 void init_connections(void) {
39 connection_list = list_alloc((list_action_t) free_connection);
40 everyone = new_connection();
41 everyone->name = xstrdup("everyone");
42 everyone->hostname = xstrdup("BROADCAST");
45 void exit_connections(void) {
46 list_delete_list(connection_list);
47 free_connection(everyone);
50 connection_t *new_connection(void) {
51 return xzalloc(sizeof(connection_t));
54 void free_connection(connection_t *c) {
59 #ifndef DISABLE_LEGACY
60 cipher_close(c->incipher);
61 digest_close(c->indigest);
62 cipher_close(c->outcipher);
63 digest_close(c->outdigest);
67 sptps_stop(&c->sptps);
70 free(c->hischallenge);
72 buffer_clear(&c->inbuf);
73 buffer_clear(&c->outbuf);
78 closesocket(c->socket);
85 exit_configuration(&c->config_tree);
91 void connection_add(connection_t *c) {
92 list_insert_tail(connection_list, c);
95 void connection_del(connection_t *c) {
96 list_delete(connection_list, c);
99 bool dump_connections(connection_t *cdump) {
100 for list_each(connection_t, c, connection_list) {
101 send_request(cdump, "%d %d %s %s %x %d %x",
102 CONTROL, REQ_DUMP_CONNECTIONS,
103 c->name, c->hostname, c->options, c->socket,
104 bitfield_to_int(&c->status, sizeof(c->status)));
107 return send_request(cdump, "%d %d", CONTROL, REQ_DUMP_CONNECTIONS);