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"
49 proxytype_t proxytype;
51 bool disablebuggypeers;
53 bool node_read_ecdsa_public_key(node_t *n) {
54 if(ecdsa_active(n->ecdsa))
57 splay_tree_t *config_tree;
62 init_configuration(&config_tree);
63 if(!read_host_config(config_tree, n->name))
66 /* First, check for simple ECDSAPublicKey statement */
68 if(get_config_string(lookup_config(config_tree, "ECDSAPublicKey"), &p)) {
69 n->ecdsa = ecdsa_set_base64_public_key(p);
74 /* Else, check for ECDSAPublicKeyFile statement and read it */
76 if(!get_config_string(lookup_config(config_tree, "ECDSAPublicKeyFile"), &pubname))
77 xasprintf(&pubname, "%s" SLASH "hosts" SLASH "%s", confbase, n->name);
79 fp = fopen(pubname, "r");
84 n->ecdsa = ecdsa_read_pem_public_key(fp);
88 exit_configuration(&config_tree);
93 bool read_ecdsa_public_key(connection_t *c) {
94 if(ecdsa_active(c->ecdsa))
101 if(!c->config_tree) {
102 init_configuration(&c->config_tree);
103 if(!read_host_config(c->config_tree, c->name))
107 /* First, check for simple ECDSAPublicKey statement */
109 if(get_config_string(lookup_config(c->config_tree, "ECDSAPublicKey"), &p)) {
110 c->ecdsa = ecdsa_set_base64_public_key(p);
115 /* Else, check for ECDSAPublicKeyFile statement and read it */
117 if(!get_config_string(lookup_config(c->config_tree, "ECDSAPublicKeyFile"), &fname))
118 xasprintf(&fname, "%s" SLASH "hosts" SLASH "%s", confbase, c->name);
120 fp = fopen(fname, "r");
123 logger(DEBUG_ALWAYS, LOG_ERR, "Error reading ECDSA public key file `%s': %s",
124 fname, strerror(errno));
129 c->ecdsa = ecdsa_read_pem_public_key(fp);
133 logger(DEBUG_ALWAYS, LOG_ERR, "Parsing ECDSA public key file `%s' failed.", fname);
138 bool read_rsa_public_key(connection_t *c) {
139 if(ecdsa_active(c->ecdsa))
146 /* First, check for simple PublicKey statement */
148 if(get_config_string(lookup_config(c->config_tree, "PublicKey"), &n)) {
149 c->rsa = rsa_set_hex_public_key(n, "FFFF");
154 /* Else, check for PublicKeyFile statement and read it */
156 if(!get_config_string(lookup_config(c->config_tree, "PublicKeyFile"), &fname))
157 xasprintf(&fname, "%s" SLASH "hosts" SLASH "%s", confbase, c->name);
159 fp = fopen(fname, "r");
162 logger(DEBUG_ALWAYS, LOG_ERR, "Error reading RSA public key file `%s': %s", fname, strerror(errno));
167 c->rsa = rsa_read_pem_public_key(fp);
171 logger(DEBUG_ALWAYS, LOG_ERR, "Reading RSA public key file `%s' failed: %s", fname, strerror(errno));
176 static bool read_ecdsa_private_key(void) {
180 /* Check for PrivateKeyFile statement and read it */
182 if(!get_config_string(lookup_config(config_tree, "ECDSAPrivateKeyFile"), &fname))
183 xasprintf(&fname, "%s" SLASH "ecdsa_key.priv", confbase);
185 fp = fopen(fname, "r");
188 logger(DEBUG_ALWAYS, LOG_ERR, "Error reading ECDSA private key file `%s': %s", fname, strerror(errno));
190 logger(DEBUG_ALWAYS, LOG_INFO, "Create an ECDSA keypair with `tinc -n %s generate-ecdsa-keys'.", netname ?: ".");
195 #if !defined(HAVE_MINGW) && !defined(HAVE_CYGWIN)
198 if(fstat(fileno(fp), &s)) {
199 logger(DEBUG_ALWAYS, LOG_ERR, "Could not stat ECDSA private key file `%s': %s'", fname, strerror(errno));
204 if(s.st_mode & ~0100700)
205 logger(DEBUG_ALWAYS, LOG_WARNING, "Warning: insecure file permissions for ECDSA private key file `%s'!", fname);
208 myself->connection->ecdsa = ecdsa_read_pem_private_key(fp);
211 if(!myself->connection->ecdsa)
212 logger(DEBUG_ALWAYS, LOG_ERR, "Reading ECDSA private key file `%s' failed: %s", fname, strerror(errno));
214 return myself->connection->ecdsa;
217 static bool read_invitation_key(void) {
222 ecdsa_free(invitation_key);
223 invitation_key = NULL;
226 xasprintf(&fname, "%s" SLASH "invitations" SLASH "ecdsa_key.priv", confbase);
228 fp = fopen(fname, "r");
231 invitation_key = ecdsa_read_pem_private_key(fp);
234 logger(DEBUG_ALWAYS, LOG_ERR, "Reading ECDSA private key file `%s' failed: %s", fname, strerror(errno));
238 return invitation_key;
241 static bool read_rsa_private_key(void) {
246 /* First, check for simple PrivateKey statement */
248 if(get_config_string(lookup_config(config_tree, "PrivateKey"), &d)) {
249 if(!get_config_string(lookup_config(config_tree, "PublicKey"), &n)) {
250 logger(DEBUG_ALWAYS, LOG_ERR, "PrivateKey used but no PublicKey found!");
254 myself->connection->rsa = rsa_set_hex_private_key(n, "FFFF", d);
257 return myself->connection->rsa;
260 /* Else, check for PrivateKeyFile statement and read it */
262 if(!get_config_string(lookup_config(config_tree, "PrivateKeyFile"), &fname))
263 xasprintf(&fname, "%s" SLASH "rsa_key.priv", confbase);
265 fp = fopen(fname, "r");
268 logger(DEBUG_ALWAYS, LOG_ERR, "Error reading RSA private key file `%s': %s",
269 fname, strerror(errno));
274 #if !defined(HAVE_MINGW) && !defined(HAVE_CYGWIN)
277 if(fstat(fileno(fp), &s)) {
278 logger(DEBUG_ALWAYS, LOG_ERR, "Could not stat RSA private key file `%s': %s'", fname, strerror(errno));
283 if(s.st_mode & ~0100700)
284 logger(DEBUG_ALWAYS, LOG_WARNING, "Warning: insecure file permissions for RSA private key file `%s'!", fname);
287 myself->connection->rsa = rsa_read_pem_private_key(fp);
290 if(!myself->connection->rsa)
291 logger(DEBUG_ALWAYS, LOG_ERR, "Reading RSA private key file `%s' failed: %s", fname, strerror(errno));
293 return myself->connection->rsa;
296 static timeout_t keyexpire_timeout;
298 static void keyexpire_handler(void *data) {
300 timeout_set(data, &(struct timeval){keylifetime, rand() % 100000});
303 void regenerate_key(void) {
304 logger(DEBUG_STATUS, LOG_INFO, "Expiring symmetric keys");
308 void load_all_nodes(void) {
313 xasprintf(&dname, "%s" SLASH "hosts", confbase);
314 dir = opendir(dname);
316 logger(DEBUG_ALWAYS, LOG_ERR, "Could not open %s: %s", dname, strerror(errno));
321 while((ent = readdir(dir))) {
322 if(!check_id(ent->d_name))
325 node_t *n = lookup_node(ent->d_name);
330 n->name = xstrdup(ent->d_name);
338 char *get_name(void) {
341 get_config_string(lookup_config(config_tree, "Name"), &name);
347 char *envname = getenv(name + 1);
348 char hostname[32] = "";
350 if(strcmp(name + 1, "HOST")) {
351 logger(DEBUG_ALWAYS, LOG_ERR, "Invalid Name: environment variable %s does not exist\n", name + 1);
354 if(gethostname(hostname, sizeof hostname) || !*hostname) {
355 logger(DEBUG_ALWAYS, LOG_ERR, "Could not get hostname: %s\n", strerror(errno));
362 name = xstrdup(envname);
363 for(char *c = name; *c; c++)
368 if(!check_id(name)) {
369 logger(DEBUG_ALWAYS, LOG_ERR, "Invalid name for myself!");
377 bool setup_myself_reloadable(void) {
383 char *address = NULL;
387 get_config_string(lookup_config(config_tree, "Proxy"), &proxy);
389 if((space = strchr(proxy, ' ')))
392 if(!strcasecmp(proxy, "none")) {
393 proxytype = PROXY_NONE;
394 } else if(!strcasecmp(proxy, "socks4")) {
395 proxytype = PROXY_SOCKS4;
396 } else if(!strcasecmp(proxy, "socks4a")) {
397 proxytype = PROXY_SOCKS4A;
398 } else if(!strcasecmp(proxy, "socks5")) {
399 proxytype = PROXY_SOCKS5;
400 } else if(!strcasecmp(proxy, "http")) {
401 proxytype = PROXY_HTTP;
402 } else if(!strcasecmp(proxy, "exec")) {
403 proxytype = PROXY_EXEC;
405 logger(DEBUG_ALWAYS, LOG_ERR, "Unknown proxy type %s!", proxy);
415 if(!space || !*space) {
416 logger(DEBUG_ALWAYS, LOG_ERR, "Argument expected for proxy type exec!");
419 proxyhost = xstrdup(space);
427 if(space && (space = strchr(space, ' ')))
428 *space++ = 0, proxyport = space;
429 if(space && (space = strchr(space, ' ')))
430 *space++ = 0, proxyuser = space;
431 if(space && (space = strchr(space, ' ')))
432 *space++ = 0, proxypass = space;
433 if(!proxyhost || !*proxyhost || !proxyport || !*proxyport) {
434 logger(DEBUG_ALWAYS, LOG_ERR, "Host and port argument expected for proxy!");
437 proxyhost = xstrdup(proxyhost);
438 proxyport = xstrdup(proxyport);
439 if(proxyuser && *proxyuser)
440 proxyuser = xstrdup(proxyuser);
441 if(proxypass && *proxypass)
442 proxypass = xstrdup(proxypass);
449 if(get_config_bool(lookup_config(config_tree, "IndirectData"), &choice) && choice)
450 myself->options |= OPTION_INDIRECT;
452 if(get_config_bool(lookup_config(config_tree, "TCPOnly"), &choice) && choice)
453 myself->options |= OPTION_TCPONLY;
455 if(myself->options & OPTION_TCPONLY)
456 myself->options |= OPTION_INDIRECT;
458 get_config_bool(lookup_config(config_tree, "DirectOnly"), &directonly);
459 get_config_bool(lookup_config(config_tree, "LocalDiscovery"), &localdiscovery);
461 memset(&localdiscovery_address, 0, sizeof localdiscovery_address);
462 if(get_config_string(lookup_config(config_tree, "LocalDiscoveryAddress"), &address)) {
463 struct addrinfo *ai = str2addrinfo(address, myport, SOCK_DGRAM);
467 memcpy(&localdiscovery_address, ai->ai_addr, ai->ai_addrlen);
471 if(get_config_string(lookup_config(config_tree, "Mode"), &rmode)) {
472 if(!strcasecmp(rmode, "router"))
473 routing_mode = RMODE_ROUTER;
474 else if(!strcasecmp(rmode, "switch"))
475 routing_mode = RMODE_SWITCH;
476 else if(!strcasecmp(rmode, "hub"))
477 routing_mode = RMODE_HUB;
479 logger(DEBUG_ALWAYS, LOG_ERR, "Invalid routing mode!");
485 if(get_config_string(lookup_config(config_tree, "Forwarding"), &fmode)) {
486 if(!strcasecmp(fmode, "off"))
487 forwarding_mode = FMODE_OFF;
488 else if(!strcasecmp(fmode, "internal"))
489 forwarding_mode = FMODE_INTERNAL;
490 else if(!strcasecmp(fmode, "kernel"))
491 forwarding_mode = FMODE_KERNEL;
493 logger(DEBUG_ALWAYS, LOG_ERR, "Invalid forwarding mode!");
500 get_config_bool(lookup_config(config_tree, "PMTUDiscovery"), &choice);
502 myself->options |= OPTION_PMTU_DISCOVERY;
505 get_config_bool(lookup_config(config_tree, "ClampMSS"), &choice);
507 myself->options |= OPTION_CLAMP_MSS;
509 get_config_bool(lookup_config(config_tree, "PriorityInheritance"), &priorityinheritance);
510 get_config_bool(lookup_config(config_tree, "DecrementTTL"), &decrement_ttl);
511 if(get_config_string(lookup_config(config_tree, "Broadcast"), &bmode)) {
512 if(!strcasecmp(bmode, "no"))
513 broadcast_mode = BMODE_NONE;
514 else if(!strcasecmp(bmode, "yes") || !strcasecmp(bmode, "mst"))
515 broadcast_mode = BMODE_MST;
516 else if(!strcasecmp(bmode, "direct"))
517 broadcast_mode = BMODE_DIRECT;
519 logger(DEBUG_ALWAYS, LOG_ERR, "Invalid broadcast mode!");
525 #if !defined(SOL_IP) || !defined(IP_TOS)
526 if(priorityinheritance)
527 logger(DEBUG_ALWAYS, LOG_WARNING, "%s not supported on this platform", "PriorityInheritance");
530 if(!get_config_int(lookup_config(config_tree, "MACExpire"), &macexpire))
533 if(get_config_int(lookup_config(config_tree, "MaxTimeout"), &maxtimeout)) {
534 if(maxtimeout <= 0) {
535 logger(DEBUG_ALWAYS, LOG_ERR, "Bogus maximum timeout!");
541 if(get_config_string(lookup_config(config_tree, "AddressFamily"), &afname)) {
542 if(!strcasecmp(afname, "IPv4"))
543 addressfamily = AF_INET;
544 else if(!strcasecmp(afname, "IPv6"))
545 addressfamily = AF_INET6;
546 else if(!strcasecmp(afname, "any"))
547 addressfamily = AF_UNSPEC;
549 logger(DEBUG_ALWAYS, LOG_ERR, "Invalid address family!");
555 get_config_bool(lookup_config(config_tree, "Hostnames"), &hostnames);
557 if(!get_config_int(lookup_config(config_tree, "KeyExpire"), &keylifetime))
560 get_config_int(lookup_config(config_tree, "AutoConnect"), &autoconnect);
564 get_config_bool(lookup_config(config_tree, "DisableBuggyPeers"), &disablebuggypeers);
566 read_invitation_key();
572 Add listening sockets.
574 static bool add_listen_address(char *address, bool bindto) {
578 char *space = strchr(address, ' ');
584 if(!strcmp(address, "*"))
588 struct addrinfo *ai, hint = {0};
589 hint.ai_family = addressfamily;
590 hint.ai_socktype = SOCK_STREAM;
591 hint.ai_protocol = IPPROTO_TCP;
592 hint.ai_flags = AI_PASSIVE;
594 int err = getaddrinfo(address && *address ? address : NULL, port, &hint, &ai);
598 logger(DEBUG_ALWAYS, LOG_ERR, "System call `%s' failed: %s", "getaddrinfo", err == EAI_SYSTEM ? strerror(err) : gai_strerror(err));
602 for(struct addrinfo *aip = ai; aip; aip = aip->ai_next) {
603 // Ignore duplicate addresses
606 for(int i = 0; i < listen_sockets; i++)
607 if(!memcmp(&listen_socket[i].sa, aip->ai_addr, aip->ai_addrlen)) {
615 if(listen_sockets >= MAXSOCKETS) {
616 logger(DEBUG_ALWAYS, LOG_ERR, "Too many listening sockets");
620 int tcp_fd = setup_listen_socket((sockaddr_t *) aip->ai_addr);
625 int udp_fd = setup_vpn_in_socket((sockaddr_t *) aip->ai_addr);
632 io_add(&listen_socket[listen_sockets].tcp, handle_new_meta_connection, &listen_socket[listen_sockets], tcp_fd, IO_READ);
633 io_add(&listen_socket[listen_sockets].udp, handle_incoming_vpn_data, &listen_socket[listen_sockets], udp_fd, IO_READ);
635 if(debug_level >= DEBUG_CONNECTIONS) {
636 char *hostname = sockaddr2hostname((sockaddr_t *) aip->ai_addr);
637 logger(DEBUG_CONNECTIONS, LOG_NOTICE, "Listening on %s", hostname);
641 listen_socket[listen_sockets].bindto = bindto;
642 memcpy(&listen_socket[listen_sockets].sa, aip->ai_addr, aip->ai_addrlen);
651 Configure node_t myself and set up the local sockets (listen only)
653 bool setup_myself(void) {
654 char *name, *hostname, *cipher, *digest, *type;
655 char *address = NULL;
656 bool port_specified = false;
658 if(!(name = get_name())) {
659 logger(DEBUG_ALWAYS, LOG_ERR, "Name for tinc daemon required!");
664 myself->connection = new_connection();
666 myself->connection->name = xstrdup(name);
667 read_host_config(config_tree, name);
669 if(!get_config_string(lookup_config(config_tree, "Port"), &myport))
670 myport = xstrdup("655");
672 port_specified = true;
674 myself->connection->options = 0;
675 myself->connection->protocol_major = PROT_MAJOR;
676 myself->connection->protocol_minor = PROT_MINOR;
678 myself->options |= PROT_MINOR << 24;
680 if(!get_config_bool(lookup_config(config_tree, "ExperimentalProtocol"), &experimental)) {
681 experimental = read_ecdsa_private_key();
683 logger(DEBUG_ALWAYS, LOG_WARNING, "Support for SPTPS disabled.");
685 if(experimental && !read_ecdsa_private_key())
689 if(!read_rsa_private_key())
692 /* Ensure myport is numeric */
695 struct addrinfo *ai = str2addrinfo("localhost", myport, SOCK_DGRAM);
697 if(!ai || !ai->ai_addr)
700 memcpy(&sa, ai->ai_addr, ai->ai_addrlen);
701 sockaddr2str(&sa, NULL, &myport);
704 /* Check some options */
706 if(!setup_myself_reloadable())
709 get_config_bool(lookup_config(config_tree, "TunnelServer"), &tunnelserver);
711 if(get_config_int(lookup_config(config_tree, "MaxConnectionBurst"), &max_connection_burst)) {
712 if(max_connection_burst <= 0) {
713 logger(DEBUG_ALWAYS, LOG_ERR, "MaxConnectionBurst cannot be negative!");
718 if(get_config_int(lookup_config(config_tree, "UDPRcvBuf"), &udp_rcvbuf)) {
719 if(udp_rcvbuf <= 0) {
720 logger(DEBUG_ALWAYS, LOG_ERR, "UDPRcvBuf cannot be negative!");
725 if(get_config_int(lookup_config(config_tree, "UDPSndBuf"), &udp_sndbuf)) {
726 if(udp_sndbuf <= 0) {
727 logger(DEBUG_ALWAYS, LOG_ERR, "UDPSndBuf cannot be negative!");
733 if(get_config_int(lookup_config(config_tree, "ReplayWindow"), &replaywin_int)) {
734 if(replaywin_int < 0) {
735 logger(DEBUG_ALWAYS, LOG_ERR, "ReplayWindow cannot be negative!");
738 replaywin = (unsigned)replaywin_int;
739 sptps_replaywin = replaywin;
742 /* Generate packet encryption key */
744 if(!get_config_string(lookup_config(config_tree, "Cipher"), &cipher))
745 cipher = xstrdup("blowfish");
747 if(!strcasecmp(cipher, "none")) {
748 myself->incipher = NULL;
749 } else if(!(myself->incipher = cipher_open_by_name(cipher))) {
750 logger(DEBUG_ALWAYS, LOG_ERR, "Unrecognized cipher type!");
756 timeout_add(&keyexpire_timeout, keyexpire_handler, &keyexpire_timeout, &(struct timeval){keylifetime, rand() % 100000});
758 /* Check if we want to use message authentication codes... */
761 get_config_int(lookup_config(config_tree, "MACLength"), &maclength);
764 logger(DEBUG_ALWAYS, LOG_ERR, "Bogus MAC length!");
768 if(!get_config_string(lookup_config(config_tree, "Digest"), &digest))
769 digest = xstrdup("sha1");
771 if(!strcasecmp(digest, "none")) {
772 myself->indigest = NULL;
773 } else if(!(myself->indigest = digest_open_by_name(digest, maclength))) {
774 logger(DEBUG_ALWAYS, LOG_ERR, "Unrecognized digest type!");
782 if(get_config_int(lookup_config(config_tree, "Compression"), &myself->incompression)) {
783 if(myself->incompression < 0 || myself->incompression > 11) {
784 logger(DEBUG_ALWAYS, LOG_ERR, "Bogus compression level!");
788 myself->incompression = 0;
790 myself->connection->outcompression = 0;
794 myself->nexthop = myself;
795 myself->via = myself;
796 myself->status.reachable = true;
797 myself->last_state_change = now.tv_sec;
798 myself->status.sptps = experimental;
808 if(!do_detach && getenv("LISTEN_FDS")) {
812 listen_sockets = atoi(getenv("LISTEN_FDS"));
814 unsetenv("LISTEN_FDS");
817 if(listen_sockets > MAXSOCKETS) {
818 logger(DEBUG_ALWAYS, LOG_ERR, "Too many listening sockets");
822 for(int i = 0; i < listen_sockets; i++) {
824 if(getsockname(i + 3, &sa.sa, &salen) < 0) {
825 logger(DEBUG_ALWAYS, LOG_ERR, "Could not get address of listen fd %d: %s", i + 3, sockstrerror(errno));
830 fcntl(i + 3, F_SETFD, FD_CLOEXEC);
833 int udp_fd = setup_vpn_in_socket(&sa);
837 io_add(&listen_socket[i].tcp, (io_cb_t)handle_new_meta_connection, &listen_socket[i], i + 3, IO_READ);
838 io_add(&listen_socket[i].udp, (io_cb_t)handle_incoming_vpn_data, &listen_socket[i], udp_fd, IO_READ);
840 if(debug_level >= DEBUG_CONNECTIONS) {
841 hostname = sockaddr2hostname(&sa);
842 logger(DEBUG_CONNECTIONS, LOG_NOTICE, "Listening on %s", hostname);
846 memcpy(&listen_socket[i].sa, &sa, salen);
852 for(config_t *cfg = lookup_config(config_tree, "BindToAddress"); cfg; cfg = lookup_config_next(config_tree, cfg)) {
854 get_config_string(cfg, &address);
855 if(!add_listen_address(address, true))
859 for(config_t *cfg = lookup_config(config_tree, "ListenAddress"); cfg; cfg = lookup_config_next(config_tree, cfg)) {
861 get_config_string(cfg, &address);
862 if(!add_listen_address(address, false))
867 if(!add_listen_address(address, NULL))
871 if(!listen_sockets) {
872 logger(DEBUG_ALWAYS, LOG_ERR, "Unable to create any listening socket!");
876 /* If no Port option was specified, set myport to the port used by the first listening socket. */
878 if(!port_specified) {
880 socklen_t salen = sizeof sa;
881 if(!getsockname(listen_socket[0].udp.fd, &sa.sa, &salen)) {
883 sockaddr2str(&sa, NULL, &myport);
885 myport = xstrdup("655");
889 xasprintf(&myself->hostname, "MYSELF port %s", myport);
890 myself->connection->hostname = xstrdup(myself->hostname);
894 last_config_check = now.tv_sec;
902 bool setup_network(void) {
908 if(get_config_int(lookup_config(config_tree, "PingInterval"), &pinginterval)) {
909 if(pinginterval < 1) {
910 pinginterval = 86400;
915 if(!get_config_int(lookup_config(config_tree, "PingTimeout"), &pingtimeout))
917 if(pingtimeout < 1 || pingtimeout > pinginterval)
918 pingtimeout = pinginterval;
920 if(!get_config_int(lookup_config(config_tree, "MaxOutputBufferSize"), &maxoutbufsize))
921 maxoutbufsize = 10 * MTU;
933 close all open network connections
935 void close_network_connections(void) {
936 for(list_node_t *node = connection_list->head, *next; node; node = next) {
938 connection_t *c = node->data;
939 /* Keep control connections open until the end, so they know when we really terminated */
940 if(c->status.control)
943 terminate_connection(c, false);
947 list_delete_list(outgoing_list);
949 if(myself && myself->connection) {
950 terminate_connection(myself->connection, false);
951 free_connection(myself->connection);
954 for(int i = 0; i < listen_sockets; i++) {
955 io_del(&listen_socket[i].tcp);
956 io_del(&listen_socket[i].udp);
957 close(listen_socket[i].tcp.fd);
958 close(listen_socket[i].udp.fd);
966 if(myport) free(myport);