3 Copyright (C) 1998-2005 Ivo Timmermans,
4 2000-2014 Guus Sliepen <guus@tinc-vpn.org>
5 2006 Scott Lamb <slamb@slamb.org>
6 2010 Brandon Black <blblack@gmail.com>
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License along
19 with this program; if not, write to the Free Software Foundation, Inc.,
20 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 #include "connection.h"
48 proxytype_t proxytype;
50 bool disablebuggypeers;
52 bool node_read_ecdsa_public_key(node_t *n) {
53 if(ecdsa_active(n->ecdsa))
56 splay_tree_t *config_tree;
61 init_configuration(&config_tree);
62 if(!read_host_config(config_tree, n->name))
65 /* First, check for simple ECDSAPublicKey statement */
67 if(get_config_string(lookup_config(config_tree, "ECDSAPublicKey"), &p)) {
68 n->ecdsa = ecdsa_set_base64_public_key(p);
73 /* Else, check for ECDSAPublicKeyFile statement and read it */
75 if(!get_config_string(lookup_config(config_tree, "ECDSAPublicKeyFile"), &pubname))
76 xasprintf(&pubname, "%s" SLASH "hosts" SLASH "%s", confbase, n->name);
78 fp = fopen(pubname, "r");
83 n->ecdsa = ecdsa_read_pem_public_key(fp);
87 exit_configuration(&config_tree);
92 bool read_ecdsa_public_key(connection_t *c) {
93 if(ecdsa_active(c->ecdsa))
100 if(!c->config_tree) {
101 init_configuration(&c->config_tree);
102 if(!read_host_config(c->config_tree, c->name))
106 /* First, check for simple ECDSAPublicKey statement */
108 if(get_config_string(lookup_config(c->config_tree, "ECDSAPublicKey"), &p)) {
109 c->ecdsa = ecdsa_set_base64_public_key(p);
114 /* Else, check for ECDSAPublicKeyFile statement and read it */
116 if(!get_config_string(lookup_config(c->config_tree, "ECDSAPublicKeyFile"), &fname))
117 xasprintf(&fname, "%s" SLASH "hosts" SLASH "%s", confbase, c->name);
119 fp = fopen(fname, "r");
122 logger(DEBUG_ALWAYS, LOG_ERR, "Error reading ECDSA public key file `%s': %s",
123 fname, strerror(errno));
128 c->ecdsa = ecdsa_read_pem_public_key(fp);
132 logger(DEBUG_ALWAYS, LOG_ERR, "Parsing ECDSA public key file `%s' failed.", fname);
137 bool read_rsa_public_key(connection_t *c) {
138 if(ecdsa_active(c->ecdsa))
145 /* First, check for simple PublicKey statement */
147 if(get_config_string(lookup_config(c->config_tree, "PublicKey"), &n)) {
148 c->rsa = rsa_set_hex_public_key(n, "FFFF");
153 /* Else, check for PublicKeyFile statement and read it */
155 if(!get_config_string(lookup_config(c->config_tree, "PublicKeyFile"), &fname))
156 xasprintf(&fname, "%s" SLASH "hosts" SLASH "%s", confbase, c->name);
158 fp = fopen(fname, "r");
161 logger(DEBUG_ALWAYS, LOG_ERR, "Error reading RSA public key file `%s': %s", fname, strerror(errno));
166 c->rsa = rsa_read_pem_public_key(fp);
170 logger(DEBUG_ALWAYS, LOG_ERR, "Reading RSA public key file `%s' failed: %s", fname, strerror(errno));
175 static bool read_ecdsa_private_key(void) {
179 /* Check for PrivateKeyFile statement and read it */
181 if(!get_config_string(lookup_config(config_tree, "ECDSAPrivateKeyFile"), &fname))
182 xasprintf(&fname, "%s" SLASH "ecdsa_key.priv", confbase);
184 fp = fopen(fname, "r");
187 logger(DEBUG_ALWAYS, LOG_ERR, "Error reading ECDSA private key file `%s': %s", fname, strerror(errno));
189 logger(DEBUG_ALWAYS, LOG_INFO, "Create an ECDSA keypair with `tinc -n %s generate-ecdsa-keys'.", netname ?: ".");
194 #if !defined(HAVE_MINGW) && !defined(HAVE_CYGWIN)
197 if(fstat(fileno(fp), &s)) {
198 logger(DEBUG_ALWAYS, LOG_ERR, "Could not stat ECDSA private key file `%s': %s'", fname, strerror(errno));
203 if(s.st_mode & ~0100700)
204 logger(DEBUG_ALWAYS, LOG_WARNING, "Warning: insecure file permissions for ECDSA private key file `%s'!", fname);
207 myself->connection->ecdsa = ecdsa_read_pem_private_key(fp);
210 if(!myself->connection->ecdsa)
211 logger(DEBUG_ALWAYS, LOG_ERR, "Reading ECDSA private key file `%s' failed: %s", fname, strerror(errno));
213 return myself->connection->ecdsa;
216 static bool read_invitation_key(void) {
221 ecdsa_free(invitation_key);
222 invitation_key = NULL;
225 xasprintf(&fname, "%s" SLASH "invitations" SLASH "ecdsa_key.priv", confbase);
227 fp = fopen(fname, "r");
230 invitation_key = ecdsa_read_pem_private_key(fp);
233 logger(DEBUG_ALWAYS, LOG_ERR, "Reading ECDSA private key file `%s' failed: %s", fname, strerror(errno));
237 return invitation_key;
240 static bool read_rsa_private_key(void) {
245 /* First, check for simple PrivateKey statement */
247 if(get_config_string(lookup_config(config_tree, "PrivateKey"), &d)) {
248 if(!get_config_string(lookup_config(config_tree, "PublicKey"), &n)) {
249 logger(DEBUG_ALWAYS, LOG_ERR, "PrivateKey used but no PublicKey found!");
253 myself->connection->rsa = rsa_set_hex_private_key(n, "FFFF", d);
256 return myself->connection->rsa;
259 /* Else, check for PrivateKeyFile statement and read it */
261 if(!get_config_string(lookup_config(config_tree, "PrivateKeyFile"), &fname))
262 xasprintf(&fname, "%s" SLASH "rsa_key.priv", confbase);
264 fp = fopen(fname, "r");
267 logger(DEBUG_ALWAYS, LOG_ERR, "Error reading RSA private key file `%s': %s",
268 fname, strerror(errno));
273 #if !defined(HAVE_MINGW) && !defined(HAVE_CYGWIN)
276 if(fstat(fileno(fp), &s)) {
277 logger(DEBUG_ALWAYS, LOG_ERR, "Could not stat RSA private key file `%s': %s'", fname, strerror(errno));
282 if(s.st_mode & ~0100700)
283 logger(DEBUG_ALWAYS, LOG_WARNING, "Warning: insecure file permissions for RSA private key file `%s'!", fname);
286 myself->connection->rsa = rsa_read_pem_private_key(fp);
289 if(!myself->connection->rsa)
290 logger(DEBUG_ALWAYS, LOG_ERR, "Reading RSA private key file `%s' failed: %s", fname, strerror(errno));
292 return myself->connection->rsa;
295 static timeout_t keyexpire_timeout;
297 static void keyexpire_handler(void *data) {
299 timeout_set(data, &(struct timeval){keylifetime, rand() % 100000});
302 void regenerate_key(void) {
303 logger(DEBUG_STATUS, LOG_INFO, "Expiring symmetric keys");
307 void load_all_nodes(void) {
312 xasprintf(&dname, "%s" SLASH "hosts", confbase);
313 dir = opendir(dname);
315 logger(DEBUG_ALWAYS, LOG_ERR, "Could not open %s: %s", dname, strerror(errno));
320 while((ent = readdir(dir))) {
321 if(!check_id(ent->d_name))
324 node_t *n = lookup_node(ent->d_name);
329 n->name = xstrdup(ent->d_name);
337 char *get_name(void) {
340 get_config_string(lookup_config(config_tree, "Name"), &name);
346 char *envname = getenv(name + 1);
347 char hostname[32] = "";
349 if(strcmp(name + 1, "HOST")) {
350 logger(DEBUG_ALWAYS, LOG_ERR, "Invalid Name: environment variable %s does not exist\n", name + 1);
353 if(gethostname(hostname, sizeof hostname) || !*hostname) {
354 logger(DEBUG_ALWAYS, LOG_ERR, "Could not get hostname: %s\n", strerror(errno));
361 name = xstrdup(envname);
362 for(char *c = name; *c; c++)
367 if(!check_id(name)) {
368 logger(DEBUG_ALWAYS, LOG_ERR, "Invalid name for myself!");
376 bool setup_myself_reloadable(void) {
382 char *address = NULL;
386 get_config_string(lookup_config(config_tree, "Proxy"), &proxy);
388 if((space = strchr(proxy, ' ')))
391 if(!strcasecmp(proxy, "none")) {
392 proxytype = PROXY_NONE;
393 } else if(!strcasecmp(proxy, "socks4")) {
394 proxytype = PROXY_SOCKS4;
395 } else if(!strcasecmp(proxy, "socks4a")) {
396 proxytype = PROXY_SOCKS4A;
397 } else if(!strcasecmp(proxy, "socks5")) {
398 proxytype = PROXY_SOCKS5;
399 } else if(!strcasecmp(proxy, "http")) {
400 proxytype = PROXY_HTTP;
401 } else if(!strcasecmp(proxy, "exec")) {
402 proxytype = PROXY_EXEC;
404 logger(DEBUG_ALWAYS, LOG_ERR, "Unknown proxy type %s!", proxy);
414 if(!space || !*space) {
415 logger(DEBUG_ALWAYS, LOG_ERR, "Argument expected for proxy type exec!");
418 proxyhost = xstrdup(space);
426 if(space && (space = strchr(space, ' ')))
427 *space++ = 0, proxyport = space;
428 if(space && (space = strchr(space, ' ')))
429 *space++ = 0, proxyuser = space;
430 if(space && (space = strchr(space, ' ')))
431 *space++ = 0, proxypass = space;
432 if(!proxyhost || !*proxyhost || !proxyport || !*proxyport) {
433 logger(DEBUG_ALWAYS, LOG_ERR, "Host and port argument expected for proxy!");
436 proxyhost = xstrdup(proxyhost);
437 proxyport = xstrdup(proxyport);
438 if(proxyuser && *proxyuser)
439 proxyuser = xstrdup(proxyuser);
440 if(proxypass && *proxypass)
441 proxypass = xstrdup(proxypass);
448 if(get_config_bool(lookup_config(config_tree, "IndirectData"), &choice) && choice)
449 myself->options |= OPTION_INDIRECT;
451 if(get_config_bool(lookup_config(config_tree, "TCPOnly"), &choice) && choice)
452 myself->options |= OPTION_TCPONLY;
454 if(myself->options & OPTION_TCPONLY)
455 myself->options |= OPTION_INDIRECT;
457 get_config_bool(lookup_config(config_tree, "DirectOnly"), &directonly);
458 get_config_bool(lookup_config(config_tree, "LocalDiscovery"), &localdiscovery);
460 memset(&localdiscovery_address, 0, sizeof localdiscovery_address);
461 if(get_config_string(lookup_config(config_tree, "LocalDiscoveryAddress"), &address)) {
462 struct addrinfo *ai = str2addrinfo(address, myport, SOCK_DGRAM);
466 memcpy(&localdiscovery_address, ai->ai_addr, ai->ai_addrlen);
470 if(get_config_string(lookup_config(config_tree, "Mode"), &rmode)) {
471 if(!strcasecmp(rmode, "router"))
472 routing_mode = RMODE_ROUTER;
473 else if(!strcasecmp(rmode, "switch"))
474 routing_mode = RMODE_SWITCH;
475 else if(!strcasecmp(rmode, "hub"))
476 routing_mode = RMODE_HUB;
478 logger(DEBUG_ALWAYS, LOG_ERR, "Invalid routing mode!");
484 if(get_config_string(lookup_config(config_tree, "Forwarding"), &fmode)) {
485 if(!strcasecmp(fmode, "off"))
486 forwarding_mode = FMODE_OFF;
487 else if(!strcasecmp(fmode, "internal"))
488 forwarding_mode = FMODE_INTERNAL;
489 else if(!strcasecmp(fmode, "kernel"))
490 forwarding_mode = FMODE_KERNEL;
492 logger(DEBUG_ALWAYS, LOG_ERR, "Invalid forwarding mode!");
499 get_config_bool(lookup_config(config_tree, "PMTUDiscovery"), &choice);
501 myself->options |= OPTION_PMTU_DISCOVERY;
504 get_config_bool(lookup_config(config_tree, "ClampMSS"), &choice);
506 myself->options |= OPTION_CLAMP_MSS;
508 get_config_bool(lookup_config(config_tree, "PriorityInheritance"), &priorityinheritance);
509 get_config_bool(lookup_config(config_tree, "DecrementTTL"), &decrement_ttl);
510 if(get_config_string(lookup_config(config_tree, "Broadcast"), &bmode)) {
511 if(!strcasecmp(bmode, "no"))
512 broadcast_mode = BMODE_NONE;
513 else if(!strcasecmp(bmode, "yes") || !strcasecmp(bmode, "mst"))
514 broadcast_mode = BMODE_MST;
515 else if(!strcasecmp(bmode, "direct"))
516 broadcast_mode = BMODE_DIRECT;
518 logger(DEBUG_ALWAYS, LOG_ERR, "Invalid broadcast mode!");
524 #if !defined(SOL_IP) || !defined(IP_TOS)
525 if(priorityinheritance)
526 logger(DEBUG_ALWAYS, LOG_WARNING, "%s not supported on this platform", "PriorityInheritance");
529 if(!get_config_int(lookup_config(config_tree, "MACExpire"), &macexpire))
532 if(get_config_int(lookup_config(config_tree, "MaxTimeout"), &maxtimeout)) {
533 if(maxtimeout <= 0) {
534 logger(DEBUG_ALWAYS, LOG_ERR, "Bogus maximum timeout!");
540 if(get_config_string(lookup_config(config_tree, "AddressFamily"), &afname)) {
541 if(!strcasecmp(afname, "IPv4"))
542 addressfamily = AF_INET;
543 else if(!strcasecmp(afname, "IPv6"))
544 addressfamily = AF_INET6;
545 else if(!strcasecmp(afname, "any"))
546 addressfamily = AF_UNSPEC;
548 logger(DEBUG_ALWAYS, LOG_ERR, "Invalid address family!");
554 get_config_bool(lookup_config(config_tree, "Hostnames"), &hostnames);
556 if(!get_config_int(lookup_config(config_tree, "KeyExpire"), &keylifetime))
559 get_config_int(lookup_config(config_tree, "AutoConnect"), &autoconnect);
563 get_config_bool(lookup_config(config_tree, "DisableBuggyPeers"), &disablebuggypeers);
565 read_invitation_key();
571 Add listening sockets.
573 static bool add_listen_address(char *address, bool bindto) {
577 char *space = strchr(address, ' ');
583 if(!strcmp(address, "*"))
587 struct addrinfo *ai, hint = {0};
588 hint.ai_family = addressfamily;
589 hint.ai_socktype = SOCK_STREAM;
590 hint.ai_protocol = IPPROTO_TCP;
591 hint.ai_flags = AI_PASSIVE;
593 int err = getaddrinfo(address && *address ? address : NULL, port, &hint, &ai);
597 logger(DEBUG_ALWAYS, LOG_ERR, "System call `%s' failed: %s", "getaddrinfo", err == EAI_SYSTEM ? strerror(err) : gai_strerror(err));
601 for(struct addrinfo *aip = ai; aip; aip = aip->ai_next) {
602 // Ignore duplicate addresses
605 for(int i = 0; i < listen_sockets; i++)
606 if(!memcmp(&listen_socket[i].sa, aip->ai_addr, aip->ai_addrlen)) {
614 if(listen_sockets >= MAXSOCKETS) {
615 logger(DEBUG_ALWAYS, LOG_ERR, "Too many listening sockets");
619 int tcp_fd = setup_listen_socket((sockaddr_t *) aip->ai_addr);
624 int udp_fd = setup_vpn_in_socket((sockaddr_t *) aip->ai_addr);
631 io_add(&listen_socket[listen_sockets].tcp, handle_new_meta_connection, &listen_socket[listen_sockets], tcp_fd, IO_READ);
632 io_add(&listen_socket[listen_sockets].udp, handle_incoming_vpn_data, &listen_socket[listen_sockets], udp_fd, IO_READ);
634 if(debug_level >= DEBUG_CONNECTIONS) {
635 char *hostname = sockaddr2hostname((sockaddr_t *) aip->ai_addr);
636 logger(DEBUG_CONNECTIONS, LOG_NOTICE, "Listening on %s", hostname);
640 listen_socket[listen_sockets].bindto = bindto;
641 memcpy(&listen_socket[listen_sockets].sa, aip->ai_addr, aip->ai_addrlen);
650 Configure node_t myself and set up the local sockets (listen only)
652 bool setup_myself(void) {
653 char *name, *hostname, *cipher, *digest, *type;
654 char *address = NULL;
655 bool port_specified = false;
657 if(!(name = get_name())) {
658 logger(DEBUG_ALWAYS, LOG_ERR, "Name for tinc daemon required!");
663 myself->connection = new_connection();
665 myself->connection->name = xstrdup(name);
666 read_host_config(config_tree, name);
668 if(!get_config_string(lookup_config(config_tree, "Port"), &myport))
669 myport = xstrdup("655");
671 port_specified = true;
673 myself->connection->options = 0;
674 myself->connection->protocol_major = PROT_MAJOR;
675 myself->connection->protocol_minor = PROT_MINOR;
677 myself->options |= PROT_MINOR << 24;
679 if(!get_config_bool(lookup_config(config_tree, "ExperimentalProtocol"), &experimental)) {
680 experimental = read_ecdsa_private_key();
682 logger(DEBUG_ALWAYS, LOG_WARNING, "Support for SPTPS disabled.");
684 if(experimental && !read_ecdsa_private_key())
688 if(!read_rsa_private_key())
691 /* Ensure myport is numeric */
694 struct addrinfo *ai = str2addrinfo("localhost", myport, SOCK_DGRAM);
696 if(!ai || !ai->ai_addr)
699 memcpy(&sa, ai->ai_addr, ai->ai_addrlen);
700 sockaddr2str(&sa, NULL, &myport);
703 /* Check some options */
705 if(!setup_myself_reloadable())
708 get_config_bool(lookup_config(config_tree, "TunnelServer"), &tunnelserver);
710 if(get_config_int(lookup_config(config_tree, "MaxConnectionBurst"), &max_connection_burst)) {
711 if(max_connection_burst <= 0) {
712 logger(DEBUG_ALWAYS, LOG_ERR, "MaxConnectionBurst cannot be negative!");
717 if(get_config_int(lookup_config(config_tree, "UDPRcvBuf"), &udp_rcvbuf)) {
718 if(udp_rcvbuf <= 0) {
719 logger(DEBUG_ALWAYS, LOG_ERR, "UDPRcvBuf cannot be negative!");
724 if(get_config_int(lookup_config(config_tree, "UDPSndBuf"), &udp_sndbuf)) {
725 if(udp_sndbuf <= 0) {
726 logger(DEBUG_ALWAYS, LOG_ERR, "UDPSndBuf cannot be negative!");
732 if(get_config_int(lookup_config(config_tree, "ReplayWindow"), &replaywin_int)) {
733 if(replaywin_int < 0) {
734 logger(DEBUG_ALWAYS, LOG_ERR, "ReplayWindow cannot be negative!");
737 replaywin = (unsigned)replaywin_int;
738 sptps_replaywin = replaywin;
741 /* Generate packet encryption key */
743 if(!get_config_string(lookup_config(config_tree, "Cipher"), &cipher))
744 cipher = xstrdup("blowfish");
746 if(!strcasecmp(cipher, "none")) {
747 myself->incipher = NULL;
748 } else if(!(myself->incipher = cipher_open_by_name(cipher))) {
749 logger(DEBUG_ALWAYS, LOG_ERR, "Unrecognized cipher type!");
755 timeout_add(&keyexpire_timeout, keyexpire_handler, &keyexpire_timeout, &(struct timeval){keylifetime, rand() % 100000});
757 /* Check if we want to use message authentication codes... */
760 get_config_int(lookup_config(config_tree, "MACLength"), &maclength);
763 logger(DEBUG_ALWAYS, LOG_ERR, "Bogus MAC length!");
767 if(!get_config_string(lookup_config(config_tree, "Digest"), &digest))
768 digest = xstrdup("sha1");
770 if(!strcasecmp(digest, "none")) {
771 myself->indigest = NULL;
772 } else if(!(myself->indigest = digest_open_by_name(digest, maclength))) {
773 logger(DEBUG_ALWAYS, LOG_ERR, "Unrecognized digest type!");
781 if(get_config_int(lookup_config(config_tree, "Compression"), &myself->incompression)) {
782 if(myself->incompression < 0 || myself->incompression > 11) {
783 logger(DEBUG_ALWAYS, LOG_ERR, "Bogus compression level!");
787 myself->incompression = 0;
789 myself->connection->outcompression = 0;
793 myself->nexthop = myself;
794 myself->via = myself;
795 myself->status.reachable = true;
796 myself->last_state_change = now.tv_sec;
797 myself->status.sptps = experimental;
807 if(!do_detach && getenv("LISTEN_FDS")) {
811 listen_sockets = atoi(getenv("LISTEN_FDS"));
813 unsetenv("LISTEN_FDS");
816 if(listen_sockets > MAXSOCKETS) {
817 logger(DEBUG_ALWAYS, LOG_ERR, "Too many listening sockets");
821 for(int i = 0; i < listen_sockets; i++) {
823 if(getsockname(i + 3, &sa.sa, &salen) < 0) {
824 logger(DEBUG_ALWAYS, LOG_ERR, "Could not get address of listen fd %d: %s", i + 3, sockstrerror(errno));
829 fcntl(i + 3, F_SETFD, FD_CLOEXEC);
832 int udp_fd = setup_vpn_in_socket(&sa);
836 io_add(&listen_socket[i].tcp, (io_cb_t)handle_new_meta_connection, &listen_socket[i], i + 3, IO_READ);
837 io_add(&listen_socket[i].udp, (io_cb_t)handle_incoming_vpn_data, &listen_socket[i], udp_fd, IO_READ);
839 if(debug_level >= DEBUG_CONNECTIONS) {
840 hostname = sockaddr2hostname(&sa);
841 logger(DEBUG_CONNECTIONS, LOG_NOTICE, "Listening on %s", hostname);
845 memcpy(&listen_socket[i].sa, &sa, salen);
851 for(config_t *cfg = lookup_config(config_tree, "BindToAddress"); cfg; cfg = lookup_config_next(config_tree, cfg)) {
853 get_config_string(cfg, &address);
854 if(!add_listen_address(address, true))
858 for(config_t *cfg = lookup_config(config_tree, "ListenAddress"); cfg; cfg = lookup_config_next(config_tree, cfg)) {
860 get_config_string(cfg, &address);
861 if(!add_listen_address(address, false))
866 if(!add_listen_address(address, NULL))
870 if(!listen_sockets) {
871 logger(DEBUG_ALWAYS, LOG_ERR, "Unable to create any listening socket!");
875 /* If no Port option was specified, set myport to the port used by the first listening socket. */
877 if(!port_specified) {
879 socklen_t salen = sizeof sa;
880 if(!getsockname(listen_socket[0].udp.fd, &sa.sa, &salen)) {
882 sockaddr2str(&sa, NULL, &myport);
884 myport = xstrdup("655");
888 xasprintf(&myself->hostname, "MYSELF port %s", myport);
889 myself->connection->hostname = xstrdup(myself->hostname);
893 last_config_check = now.tv_sec;
901 bool setup_network(void) {
907 if(get_config_int(lookup_config(config_tree, "PingInterval"), &pinginterval)) {
908 if(pinginterval < 1) {
909 pinginterval = 86400;
914 if(!get_config_int(lookup_config(config_tree, "PingTimeout"), &pingtimeout))
916 if(pingtimeout < 1 || pingtimeout > pinginterval)
917 pingtimeout = pinginterval;
919 if(!get_config_int(lookup_config(config_tree, "MaxOutputBufferSize"), &maxoutbufsize))
920 maxoutbufsize = 10 * MTU;
929 close all open network connections
931 void close_network_connections(void) {
932 for(list_node_t *node = connection_list->head, *next; node; node = next) {
934 connection_t *c = node->data;
936 terminate_connection(c, false);
940 list_delete_list(outgoing_list);
942 if(myself && myself->connection) {
943 terminate_connection(myself->connection, false);
944 free_connection(myself->connection);
947 for(int i = 0; i < listen_sockets; i++) {
948 io_del(&listen_socket[i].tcp);
949 io_del(&listen_socket[i].udp);
950 close(listen_socket[i].tcp.fd);
951 close(listen_socket[i].udp.fd);
959 if(myport) free(myport);