2 net_socket.c -- Handle various kinds of sockets.
3 Copyright (C) 1998-2005 Ivo Timmermans,
4 2000-2017 Guus Sliepen <guus@tinc-vpn.org>
5 2006 Scott Lamb <slamb@slamb.org>
6 2009 Florian Forster <octo@verplant.org>
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.
26 #include "connection.h"
27 #include "control_common.h"
38 int addressfamily = AF_UNSPEC;
40 int seconds_till_retry = 5;
41 int udp_rcvbuf = 1024 * 1024;
42 int udp_sndbuf = 1024 * 1024;
43 int max_connection_burst = 100;
45 listen_socket_t listen_socket[MAXSOCKETS];
50 list_t *outgoing_list = NULL;
54 static void configure_tcp(connection_t *c) {
58 int flags = fcntl(c->socket, F_GETFL);
60 if(fcntl(c->socket, F_SETFL, flags | O_NONBLOCK) < 0) {
61 logger(DEBUG_ALWAYS, LOG_ERR, "fcntl for %s: %s", c->hostname, strerror(errno));
65 unsigned long arg = 1;
67 if(ioctlsocket(c->socket, FIONBIO, &arg) != 0) {
68 logger(DEBUG_ALWAYS, LOG_ERR, "ioctlsocket for %s: %s", c->hostname, sockstrerror(sockerrno));
73 #if defined(IPPROTO_TCP) && defined(TCP_NODELAY)
75 setsockopt(c->socket, IPPROTO_TCP, TCP_NODELAY, (void *)&option, sizeof(option));
78 #if defined(IPPROTO_IP) && defined(IP_TOS) && defined(IPTOS_LOWDELAY)
79 option = IPTOS_LOWDELAY;
80 setsockopt(c->socket, IPPROTO_IP, IP_TOS, (void *)&option, sizeof(option));
83 #if defined(IPPROTO_IPV6) && defined(IPV6_TCLASS) && defined(IPTOS_LOWDELAY)
84 option = IPTOS_LOWDELAY;
85 setsockopt(c->socket, IPPROTO_IPV6, IPV6_TCLASS, (void *)&option, sizeof(option));
89 static bool bind_to_interface(int sd) {
92 #if defined(SOL_SOCKET) && defined(SO_BINDTODEVICE)
95 #endif /* defined(SOL_SOCKET) && defined(SO_BINDTODEVICE) */
97 if(!get_config_string(lookup_config(config_tree, "BindToInterface"), &iface)) {
101 #if defined(SOL_SOCKET) && defined(SO_BINDTODEVICE)
102 memset(&ifr, 0, sizeof(ifr));
103 strncpy(ifr.ifr_ifrn.ifrn_name, iface, IFNAMSIZ);
104 ifr.ifr_ifrn.ifrn_name[IFNAMSIZ - 1] = 0;
106 status = setsockopt(sd, SOL_SOCKET, SO_BINDTODEVICE, (void *)&ifr, sizeof(ifr));
109 logger(DEBUG_ALWAYS, LOG_ERR, "Can't bind to interface %s: %s", iface,
110 sockstrerror(sockerrno));
114 #else /* if !defined(SOL_SOCKET) || !defined(SO_BINDTODEVICE) */
115 logger(DEBUG_ALWAYS, LOG_WARNING, "%s not supported on this platform", "BindToInterface");
121 static bool bind_to_address(connection_t *c) {
124 for(int i = 0; i < listen_sockets && listen_socket[i].bindto; i++) {
125 if(listen_socket[i].sa.sa.sa_family != c->address.sa.sa_family) {
140 sockaddr_t sa = listen_socket[s].sa;
142 if(sa.sa.sa_family == AF_INET) {
144 } else if(sa.sa.sa_family == AF_INET6) {
145 sa.in6.sin6_port = 0;
148 if(bind(c->socket, &sa.sa, SALEN(sa.sa))) {
149 logger(DEBUG_CONNECTIONS, LOG_WARNING, "Can't bind outgoing socket: %s", sockstrerror(sockerrno));
156 int setup_listen_socket(const sockaddr_t *sa) {
162 nfd = socket(sa->sa.sa_family, SOCK_STREAM, IPPROTO_TCP);
165 logger(DEBUG_STATUS, LOG_ERR, "Creating metasocket failed: %s", sockstrerror(sockerrno));
170 fcntl(nfd, F_SETFD, FD_CLOEXEC);
173 /* Optimize TCP settings */
176 setsockopt(nfd, SOL_SOCKET, SO_REUSEADDR, (void *)&option, sizeof(option));
178 #if defined(IPPROTO_IPV6) && defined(IPV6_V6ONLY)
180 if(sa->sa.sa_family == AF_INET6) {
181 setsockopt(nfd, IPPROTO_IPV6, IPV6_V6ONLY, (void *)&option, sizeof(option));
187 (lookup_config(config_tree, "BindToInterface"), &iface)) {
188 #if defined(SOL_SOCKET) && defined(SO_BINDTODEVICE)
191 memset(&ifr, 0, sizeof(ifr));
192 strncpy(ifr.ifr_ifrn.ifrn_name, iface, IFNAMSIZ);
194 if(setsockopt(nfd, SOL_SOCKET, SO_BINDTODEVICE, (void *)&ifr, sizeof(ifr))) {
196 logger(DEBUG_ALWAYS, LOG_ERR, "Can't bind to interface %s: %s", iface,
197 sockstrerror(sockerrno));
202 logger(DEBUG_ALWAYS, LOG_WARNING, "%s not supported on this platform", "BindToInterface");
206 if(bind(nfd, &sa->sa, SALEN(sa->sa))) {
208 addrstr = sockaddr2hostname(sa);
209 logger(DEBUG_ALWAYS, LOG_ERR, "Can't bind to %s/tcp: %s", addrstr, sockstrerror(sockerrno));
216 logger(DEBUG_ALWAYS, LOG_ERR, "System call `%s' failed: %s", "listen", sockstrerror(sockerrno));
223 int setup_vpn_in_socket(const sockaddr_t *sa) {
228 nfd = socket(sa->sa.sa_family, SOCK_DGRAM, IPPROTO_UDP);
231 logger(DEBUG_ALWAYS, LOG_ERR, "Creating UDP socket failed: %s", sockstrerror(sockerrno));
236 fcntl(nfd, F_SETFD, FD_CLOEXEC);
241 int flags = fcntl(nfd, F_GETFL);
243 if(fcntl(nfd, F_SETFL, flags | O_NONBLOCK) < 0) {
245 logger(DEBUG_ALWAYS, LOG_ERR, "System call `%s' failed: %s", "fcntl",
252 unsigned long arg = 1;
254 if(ioctlsocket(nfd, FIONBIO, &arg) != 0) {
256 logger(DEBUG_ALWAYS, LOG_ERR, "Call to `%s' failed: %s", "ioctlsocket", sockstrerror(sockerrno));
263 setsockopt(nfd, SOL_SOCKET, SO_REUSEADDR, (void *)&option, sizeof(option));
264 setsockopt(nfd, SOL_SOCKET, SO_BROADCAST, (void *)&option, sizeof(option));
266 if(udp_rcvbuf && setsockopt(nfd, SOL_SOCKET, SO_RCVBUF, (void *)&udp_rcvbuf, sizeof(udp_rcvbuf))) {
267 logger(DEBUG_ALWAYS, LOG_WARNING, "Can't set UDP SO_RCVBUF to %i: %s", udp_rcvbuf, sockstrerror(sockerrno));
270 if(udp_sndbuf && setsockopt(nfd, SOL_SOCKET, SO_SNDBUF, (void *)&udp_sndbuf, sizeof(udp_sndbuf))) {
271 logger(DEBUG_ALWAYS, LOG_WARNING, "Can't set UDP SO_SNDBUF to %i: %s", udp_sndbuf, sockstrerror(sockerrno));
274 #if defined(IPPROTO_IPV6) && defined(IPV6_V6ONLY)
276 if(sa->sa.sa_family == AF_INET6) {
277 setsockopt(nfd, IPPROTO_IPV6, IPV6_V6ONLY, (void *)&option, sizeof(option));
282 #if defined(IP_DONTFRAG) && !defined(IP_DONTFRAGMENT)
283 #define IP_DONTFRAGMENT IP_DONTFRAG
286 #if defined(IPPROTO_IP) && defined(IP_MTU_DISCOVER) && defined(IP_PMTUDISC_DO)
288 if(myself->options & OPTION_PMTU_DISCOVERY) {
289 option = IP_PMTUDISC_DO;
290 setsockopt(nfd, IPPROTO_IP, IP_MTU_DISCOVER, (void *)&option, sizeof(option));
293 #elif defined(IPPROTO_IP) && defined(IP_DONTFRAGMENT)
295 if(myself->options & OPTION_PMTU_DISCOVERY) {
297 setsockopt(nfd, IPPROTO_IP, IP_DONTFRAGMENT, (void *)&option, sizeof(option));
302 #if defined(IPPROTO_IPV6) && defined(IPV6_MTU_DISCOVER) && defined(IPV6_PMTUDISC_DO)
304 if(myself->options & OPTION_PMTU_DISCOVERY) {
305 option = IPV6_PMTUDISC_DO;
306 setsockopt(nfd, IPPROTO_IPV6, IPV6_MTU_DISCOVER, (void *)&option, sizeof(option));
309 #elif defined(IPPROTO_IPV6) && defined(IPV6_DONTFRAG)
311 if(myself->options & OPTION_PMTU_DISCOVERY) {
313 setsockopt(nfd, IPPROTO_IPV6, IPV6_DONTFRAG, (void *)&option, sizeof(option));
318 if(!bind_to_interface(nfd)) {
323 if(bind(nfd, &sa->sa, SALEN(sa->sa))) {
325 addrstr = sockaddr2hostname(sa);
326 logger(DEBUG_ALWAYS, LOG_ERR, "Can't bind to %s/udp: %s", addrstr, sockstrerror(sockerrno));
332 } /* int setup_vpn_in_socket */
334 static void retry_outgoing_handler(void *data) {
335 setup_outgoing_connection(data, true);
338 void retry_outgoing(outgoing_t *outgoing) {
339 outgoing->timeout += 5;
341 if(outgoing->timeout > maxtimeout) {
342 outgoing->timeout = maxtimeout;
345 timeout_add(&outgoing->ev, retry_outgoing_handler, outgoing, &(struct timeval) {
346 outgoing->timeout, rand() % 100000
349 logger(DEBUG_CONNECTIONS, LOG_NOTICE, "Trying to re-establish outgoing connection in %d seconds", outgoing->timeout);
352 void finish_connecting(connection_t *c) {
353 logger(DEBUG_CONNECTIONS, LOG_INFO, "Connected to %s (%s)", c->name, c->hostname);
355 c->last_ping_time = now.tv_sec;
356 c->status.connecting = false;
361 static void do_outgoing_pipe(connection_t *c, char *command) {
365 if(socketpair(AF_UNIX, SOCK_STREAM, 0, fd)) {
366 logger(DEBUG_ALWAYS, LOG_ERR, "Could not create socketpair: %s", sockstrerror(sockerrno));
373 logger(DEBUG_CONNECTIONS, LOG_DEBUG, "Using proxy %s", command);
384 // Other filedescriptors should be closed automatically by CLOEXEC
389 sockaddr2str(&c->address, &host, &port);
390 setenv("REMOTEADDRESS", host, true);
391 setenv("REMOTEPORT", port, true);
392 setenv("NODE", c->name, true);
393 setenv("NAME", myself->name, true);
396 setenv("NETNAME", netname, true);
399 int result = system(command);
402 logger(DEBUG_ALWAYS, LOG_ERR, "Could not execute %s: %s", command, strerror(errno));
404 logger(DEBUG_ALWAYS, LOG_ERR, "%s exited with non-zero status %d", command, result);
409 logger(DEBUG_ALWAYS, LOG_ERR, "Proxy type exec not supported on this platform!");
414 static void handle_meta_write(connection_t *c) {
415 if(c->outbuf.len <= c->outbuf.offset) {
419 ssize_t outlen = send(c->socket, c->outbuf.data + c->outbuf.offset, c->outbuf.len - c->outbuf.offset, 0);
422 if(!sockerrno || sockerrno == EPIPE) {
423 logger(DEBUG_CONNECTIONS, LOG_NOTICE, "Connection closed by %s (%s)", c->name, c->hostname);
424 } else if(sockwouldblock(sockerrno)) {
425 logger(DEBUG_META, LOG_DEBUG, "Sending %d bytes to %s (%s) would block", c->outbuf.len - c->outbuf.offset, c->name, c->hostname);
428 logger(DEBUG_CONNECTIONS, LOG_ERR, "Could not send %d bytes of data to %s (%s): %s", c->outbuf.len - c->outbuf.offset, c->name, c->hostname, sockstrerror(sockerrno));
431 terminate_connection(c, c->edge);
435 buffer_read(&c->outbuf, outlen);
438 io_set(&c->io, IO_READ);
442 static void handle_meta_io(void *data, int flags) {
443 connection_t *c = data;
445 if(c->status.connecting) {
447 The event loop does not protect against spurious events. Verify that we are actually connected
448 by issuing an empty send() call.
450 Note that the behavior of send() on potentially unconnected sockets differ between platforms:
451 +------------+-----------+-------------+-----------+
452 | Event | POSIX | Linux | Windows |
453 +------------+-----------+-------------+-----------+
454 | Spurious | ENOTCONN | EWOULDBLOCK | ENOTCONN |
455 | Failed | ENOTCONN | (cause) | ENOTCONN |
456 | Successful | (success) | (success) | (success) |
457 +------------+-----------+-------------+-----------+
459 if(send(c->socket, NULL, 0, 0) != 0) {
460 if(sockwouldblock(sockerrno)) {
466 if(!socknotconn(sockerrno)) {
467 socket_error = sockerrno;
469 socklen_t len = sizeof(socket_error);
470 getsockopt(c->socket, SOL_SOCKET, SO_ERROR, (void *)&socket_error, &len);
474 logger(DEBUG_CONNECTIONS, LOG_DEBUG, "Error while connecting to %s (%s): %s", c->name, c->hostname, sockstrerror(socket_error));
475 terminate_connection(c, false);
481 c->status.connecting = false;
482 finish_connecting(c);
485 if(flags & IO_WRITE) {
486 handle_meta_write(c);
488 handle_meta_connection_data(c);
492 static void free_known_addresses(struct addrinfo *ai) {
493 for(struct addrinfo *aip = ai, *next; aip; aip = next) {
499 bool do_outgoing_connection(outgoing_t *outgoing) {
500 char *address, *port, *space;
501 struct addrinfo *proxyai = NULL;
506 if(!outgoing->ai && !outgoing->kai) {
508 logger(DEBUG_CONNECTIONS, LOG_ERR, "Could not set up a meta connection to %s", outgoing->name);
509 retry_outgoing(outgoing);
513 get_config_string(outgoing->cfg, &address);
515 space = strchr(address, ' ');
518 port = xstrdup(space + 1);
521 if(!get_config_string(lookup_config(outgoing->config_tree, "Port"), &port)) {
522 port = xstrdup("655");
526 outgoing->ai = str2addrinfo(address, port, SOCK_STREAM);
530 outgoing->aip = outgoing->ai;
531 outgoing->cfg = lookup_config_next(outgoing->config_tree, outgoing->cfg);
536 freeaddrinfo(outgoing->ai);
542 free_known_addresses(outgoing->kai);
545 outgoing->kai = NULL;
550 connection_t *c = new_connection();
551 c->outgoing = outgoing;
553 memcpy(&c->address, outgoing->aip->ai_addr, outgoing->aip->ai_addrlen);
554 outgoing->aip = outgoing->aip->ai_next;
556 c->hostname = sockaddr2hostname(&c->address);
558 logger(DEBUG_CONNECTIONS, LOG_INFO, "Trying to connect to %s (%s)", outgoing->name, c->hostname);
561 c->socket = socket(c->address.sa.sa_family, SOCK_STREAM, IPPROTO_TCP);
563 } else if(proxytype == PROXY_EXEC) {
564 do_outgoing_pipe(c, proxyhost);
566 proxyai = str2addrinfo(proxyhost, proxyport, SOCK_STREAM);
573 logger(DEBUG_CONNECTIONS, LOG_INFO, "Using proxy at %s port %s", proxyhost, proxyport);
574 c->socket = socket(proxyai->ai_family, SOCK_STREAM, IPPROTO_TCP);
578 if(c->socket == -1) {
579 logger(DEBUG_CONNECTIONS, LOG_ERR, "Creating socket for %s failed: %s", c->hostname, sockstrerror(sockerrno));
585 fcntl(c->socket, F_SETFD, FD_CLOEXEC);
588 if(proxytype != PROXY_EXEC) {
589 #if defined(IPPROTO_IPV6) && defined(IPV6_V6ONLY)
592 if(c->address.sa.sa_family == AF_INET6) {
593 setsockopt(c->socket, IPPROTO_IPV6, IPV6_V6ONLY, (void *)&option, sizeof(option));
598 bind_to_interface(c->socket);
605 result = connect(c->socket, &c->address.sa, SALEN(c->address.sa));
606 } else if(proxytype == PROXY_EXEC) {
613 result = connect(c->socket, proxyai->ai_addr, proxyai->ai_addrlen);
614 freeaddrinfo(proxyai);
617 if(result == -1 && !sockinprogress(sockerrno)) {
618 logger(DEBUG_CONNECTIONS, LOG_ERR, "Could not connect to %s (%s): %s", outgoing->name, c->hostname, sockstrerror(sockerrno));
624 /* Now that there is a working socket, fill in the rest and register this connection. */
626 c->last_ping_time = time(NULL);
627 c->status.connecting = true;
628 c->name = xstrdup(outgoing->name);
629 #ifndef DISABLE_LEGACY
630 c->outcipher = myself->connection->outcipher;
631 c->outdigest = myself->connection->outdigest;
633 c->outmaclength = myself->connection->outmaclength;
634 c->outcompression = myself->connection->outcompression;
635 c->last_ping_time = now.tv_sec;
639 io_add(&c->io, handle_meta_io, c, c->socket, IO_READ | IO_WRITE);
644 // Find edges pointing to this node, and use them to build a list of unique, known addresses.
645 static struct addrinfo *get_known_addresses(node_t *n) {
646 struct addrinfo *ai = NULL;
647 struct addrinfo *oai = NULL;
649 for splay_each(edge_t, e, n->edge_tree) {
656 for(struct addrinfo *aip = ai; aip; aip = aip->ai_next) {
657 if(!sockaddrcmp(&e->reverse->address, (sockaddr_t *)aip->ai_addr)) {
668 ai = xzalloc(sizeof(*ai));
669 ai->ai_family = e->reverse->address.sa.sa_family;
670 ai->ai_socktype = SOCK_STREAM;
671 ai->ai_protocol = IPPROTO_TCP;
672 ai->ai_addrlen = SALEN(e->reverse->address.sa);
673 ai->ai_addr = xmalloc(ai->ai_addrlen);
674 memcpy(ai->ai_addr, &e->reverse->address, ai->ai_addrlen);
681 void setup_outgoing_connection(outgoing_t *outgoing, bool verbose) {
682 timeout_del(&outgoing->ev);
684 node_t *n = lookup_node(outgoing->name);
686 if(n && n->connection) {
687 logger(DEBUG_CONNECTIONS, LOG_INFO, "Already connected to %s", outgoing->name);
689 if(!n->connection->outgoing) {
690 n->connection->outgoing = outgoing;
697 init_configuration(&outgoing->config_tree);
698 read_host_config(outgoing->config_tree, outgoing->name, verbose);
699 outgoing->cfg = lookup_config(outgoing->config_tree, "Address");
703 outgoing->aip = outgoing->kai = get_known_addresses(n);
707 logger(verbose ? DEBUG_ALWAYS : DEBUG_CONNECTIONS, LOG_DEBUG, "No address known for %s", outgoing->name);
712 do_outgoing_connection(outgoing);
716 list_delete(outgoing_list, outgoing);
720 accept a new tcp connect and create a
723 void handle_new_meta_connection(void *data, int flags) {
724 listen_socket_t *l = data;
728 socklen_t len = sizeof(sa);
730 fd = accept(l->tcp.fd, &sa.sa, &len);
733 logger(DEBUG_ALWAYS, LOG_ERR, "Accepting a new connection failed: %s", sockstrerror(sockerrno));
739 // Check if we get many connections from the same host
741 static sockaddr_t prev_sa;
742 static int tarpit = -1;
749 if(!sockaddrcmp_noport(&sa, &prev_sa)) {
750 static int samehost_burst;
751 static int samehost_burst_time;
753 if(now.tv_sec - samehost_burst_time > samehost_burst) {
756 samehost_burst -= now.tv_sec - samehost_burst_time;
759 samehost_burst_time = now.tv_sec;
762 if(samehost_burst > max_connection_burst) {
768 memcpy(&prev_sa, &sa, sizeof(sa));
770 // Check if we get many connections from different hosts
772 static int connection_burst;
773 static int connection_burst_time;
775 if(now.tv_sec - connection_burst_time > connection_burst) {
776 connection_burst = 0;
778 connection_burst -= now.tv_sec - connection_burst_time;
781 connection_burst_time = now.tv_sec;
784 if(connection_burst >= max_connection_burst) {
785 connection_burst = max_connection_burst;
790 // Accept the new connection
792 c = new_connection();
793 c->name = xstrdup("<unknown>");
794 #ifndef DISABLE_LEGACY
795 c->outcipher = myself->connection->outcipher;
796 c->outdigest = myself->connection->outdigest;
798 c->outmaclength = myself->connection->outmaclength;
799 c->outcompression = myself->connection->outcompression;
802 c->hostname = sockaddr2hostname(&sa);
804 c->last_ping_time = now.tv_sec;
806 logger(DEBUG_CONNECTIONS, LOG_NOTICE, "Connection from %s", c->hostname);
808 io_add(&c->io, handle_meta_io, c, c->socket, IO_READ);
814 c->allow_request = ID;
820 accept a new UNIX socket connection
822 void handle_new_unix_connection(void *data, int flags) {
827 socklen_t len = sizeof(sa);
829 fd = accept(io->fd, &sa.sa, &len);
832 logger(DEBUG_ALWAYS, LOG_ERR, "Accepting a new connection failed: %s", sockstrerror(sockerrno));
838 c = new_connection();
839 c->name = xstrdup("<control>");
841 c->hostname = xstrdup("localhost port unix");
843 c->last_ping_time = now.tv_sec;
845 logger(DEBUG_CONNECTIONS, LOG_NOTICE, "Connection from %s", c->hostname);
847 io_add(&c->io, handle_meta_io, c, c->socket, IO_READ);
851 c->allow_request = ID;
857 static void free_outgoing(outgoing_t *outgoing) {
858 timeout_del(&outgoing->ev);
861 freeaddrinfo(outgoing->ai);
865 free_known_addresses(outgoing->kai);
868 if(outgoing->config_tree) {
869 exit_configuration(&outgoing->config_tree);
873 free(outgoing->name);
879 void try_outgoing_connections(void) {
880 /* If there is no outgoing list yet, create one. Otherwise, mark all outgoings as deleted. */
883 outgoing_list = list_alloc((list_action_t)free_outgoing);
885 for list_each(outgoing_t, outgoing, outgoing_list) {
886 outgoing->timeout = -1;
890 /* Make sure there is one outgoing_t in the list for each ConnectTo. */
892 for(config_t *cfg = lookup_config(config_tree, "ConnectTo"); cfg; cfg = lookup_config_next(config_tree, cfg)) {
894 get_config_string(cfg, &name);
896 if(!check_id(name)) {
897 logger(DEBUG_ALWAYS, LOG_ERR,
898 "Invalid name for outgoing connection in %s line %d",
899 cfg->file, cfg->line);
904 if(!strcmp(name, myself->name)) {
911 for list_each(outgoing_t, outgoing, outgoing_list) {
912 if(!strcmp(outgoing->name, name)) {
914 outgoing->timeout = 0;
920 outgoing_t *outgoing = xzalloc(sizeof(*outgoing));
921 outgoing->name = name;
922 list_insert_tail(outgoing_list, outgoing);
923 setup_outgoing_connection(outgoing, true);
927 /* Terminate any connections whose outgoing_t is to be deleted. */
929 for list_each(connection_t, c, connection_list) {
930 if(c->outgoing && c->outgoing->timeout == -1) {
932 logger(DEBUG_CONNECTIONS, LOG_INFO, "No more outgoing connection to %s", c->name);
933 terminate_connection(c, c->edge);
937 /* Delete outgoing_ts for which there is no ConnectTo. */
939 for list_each(outgoing_t, outgoing, outgoing_list)
940 if(outgoing->timeout == -1) {
941 list_delete_node(outgoing_list, node);