3 Copyright (C) 1998-2005 Ivo Timmermans,
4 2000-2012 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"
45 static io_t device_io;
52 proxytype_t proxytype;
55 char *scriptinterpreter;
56 char *scriptextension;
58 bool node_read_ecdsa_public_key(node_t *n) {
59 if(ecdsa_active(&n->ecdsa))
62 splay_tree_t *config_tree;
64 char *pubname = NULL, *hcfname = NULL;
68 xasprintf(&hcfname, "%s" SLASH "hosts" SLASH "%s", confbase, n->name);
70 init_configuration(&config_tree);
71 if(!read_config_file(config_tree, hcfname))
74 /* First, check for simple ECDSAPublicKey statement */
76 if(get_config_string(lookup_config(config_tree, "ECDSAPublicKey"), &p)) {
77 result = ecdsa_set_base64_public_key(&n->ecdsa, p);
82 /* Else, check for ECDSAPublicKeyFile statement and read it */
84 if(!get_config_string(lookup_config(config_tree, "ECDSAPublicKeyFile"), &pubname))
85 xasprintf(&pubname, "%s" SLASH "hosts" SLASH "%s", confbase, n->name);
87 fp = fopen(pubname, "r");
90 logger(DEBUG_ALWAYS, LOG_ERR, "Error reading ECDSA public key file `%s': %s", pubname, strerror(errno));
94 result = ecdsa_read_pem_public_key(&n->ecdsa, fp);
98 exit_configuration(&config_tree);
104 bool read_ecdsa_public_key(connection_t *c) {
110 /* First, check for simple ECDSAPublicKey statement */
112 if(get_config_string(lookup_config(c->config_tree, "ECDSAPublicKey"), &p)) {
113 result = ecdsa_set_base64_public_key(&c->ecdsa, p);
118 /* Else, check for ECDSAPublicKeyFile statement and read it */
120 if(!get_config_string(lookup_config(c->config_tree, "ECDSAPublicKeyFile"), &fname))
121 xasprintf(&fname, "%s" SLASH "hosts" SLASH "%s", confbase, c->name);
123 fp = fopen(fname, "r");
126 logger(DEBUG_ALWAYS, LOG_ERR, "Error reading ECDSA public key file `%s': %s",
127 fname, strerror(errno));
132 result = ecdsa_read_pem_public_key(&c->ecdsa, fp);
136 logger(DEBUG_ALWAYS, LOG_ERR, "Parsing ECDSA public key file `%s' failed.", fname);
141 bool read_rsa_public_key(connection_t *c) {
147 /* First, check for simple PublicKey statement */
149 if(get_config_string(lookup_config(c->config_tree, "PublicKey"), &n)) {
150 result = rsa_set_hex_public_key(&c->rsa, n, "FFFF");
155 /* Else, check for PublicKeyFile statement and read it */
157 if(!get_config_string(lookup_config(c->config_tree, "PublicKeyFile"), &fname))
158 xasprintf(&fname, "%s" SLASH "hosts" SLASH "%s", confbase, c->name);
160 fp = fopen(fname, "r");
163 logger(DEBUG_ALWAYS, LOG_ERR, "Error reading RSA public key file `%s': %s", fname, strerror(errno));
168 result = rsa_read_pem_public_key(&c->rsa, fp);
172 logger(DEBUG_ALWAYS, LOG_ERR, "Reading RSA public key file `%s' failed: %s", fname, strerror(errno));
177 static bool read_ecdsa_private_key(void) {
182 /* Check for PrivateKeyFile statement and read it */
184 if(!get_config_string(lookup_config(config_tree, "ECDSAPrivateKeyFile"), &fname))
185 xasprintf(&fname, "%s" SLASH "ecdsa_key.priv", confbase);
187 fp = fopen(fname, "r");
190 logger(DEBUG_ALWAYS, LOG_ERR, "Error reading ECDSA private key file `%s': %s", fname, strerror(errno));
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 result = ecdsa_read_pem_private_key(&myself->connection->ecdsa, fp);
212 logger(DEBUG_ALWAYS, LOG_ERR, "Reading ECDSA private key file `%s' failed: %s", fname, strerror(errno));
217 static bool read_rsa_private_key(void) {
223 /* First, check for simple PrivateKey statement */
225 if(get_config_string(lookup_config(config_tree, "PrivateKey"), &d)) {
226 if(!get_config_string(lookup_config(config_tree, "PublicKey"), &n)) {
227 logger(DEBUG_ALWAYS, LOG_ERR, "PrivateKey used but no PublicKey found!");
231 result = rsa_set_hex_private_key(&myself->connection->rsa, n, "FFFF", d);
237 /* Else, check for PrivateKeyFile statement and read it */
239 if(!get_config_string(lookup_config(config_tree, "PrivateKeyFile"), &fname))
240 xasprintf(&fname, "%s" SLASH "rsa_key.priv", confbase);
242 fp = fopen(fname, "r");
245 logger(DEBUG_ALWAYS, LOG_ERR, "Error reading RSA private key file `%s': %s",
246 fname, strerror(errno));
251 #if !defined(HAVE_MINGW) && !defined(HAVE_CYGWIN)
254 if(fstat(fileno(fp), &s)) {
255 logger(DEBUG_ALWAYS, LOG_ERR, "Could not stat RSA private key file `%s': %s'", fname, strerror(errno));
260 if(s.st_mode & ~0100700)
261 logger(DEBUG_ALWAYS, LOG_WARNING, "Warning: insecure file permissions for RSA private key file `%s'!", fname);
264 result = rsa_read_pem_private_key(&myself->connection->rsa, fp);
268 logger(DEBUG_ALWAYS, LOG_ERR, "Reading RSA private key file `%s' failed: %s", fname, strerror(errno));
273 static timeout_t keyexpire_timeout;
275 static void keyexpire_handler(void *data) {
277 timeout_set(data, &(struct timeval){keylifetime, rand() % 100000});
280 void regenerate_key(void) {
281 logger(DEBUG_STATUS, LOG_INFO, "Expiring symmetric keys");
286 Read Subnets from all host config files
288 void load_all_subnets(void) {
293 xasprintf(&dname, "%s" SLASH "hosts", confbase);
294 dir = opendir(dname);
296 logger(DEBUG_ALWAYS, LOG_ERR, "Could not open %s: %s", dname, strerror(errno));
301 while((ent = readdir(dir))) {
302 if(!check_id(ent->d_name))
305 node_t *n = lookup_node(ent->d_name);
306 #ifdef _DIRENT_HAVE_D_TYPE
307 //if(ent->d_type != DT_REG)
312 xasprintf(&fname, "%s" SLASH "hosts" SLASH "%s", confbase, ent->d_name);
314 splay_tree_t *config_tree;
315 init_configuration(&config_tree);
316 read_config_options(config_tree, ent->d_name);
317 read_config_file(config_tree, fname);
322 n->name = xstrdup(ent->d_name);
326 for(config_t *cfg = lookup_config(config_tree, "Subnet"); cfg; cfg = lookup_config_next(config_tree, cfg)) {
329 if(!get_config_subnet(cfg, &s))
332 if((s2 = lookup_subnet(n, s))) {
339 exit_configuration(&config_tree);
345 void load_all_nodes(void) {
350 xasprintf(&dname, "%s" SLASH "hosts", confbase);
351 dir = opendir(dname);
353 logger(DEBUG_ALWAYS, LOG_ERR, "Could not open %s: %s", dname, strerror(errno));
358 while((ent = readdir(dir))) {
359 if(!check_id(ent->d_name))
362 node_t *n = lookup_node(ent->d_name);
367 n->name = xstrdup(ent->d_name);
375 char *get_name(void) {
378 get_config_string(lookup_config(config_tree, "Name"), &name);
384 char *envname = getenv(name + 1);
386 if(strcmp(name + 1, "HOST")) {
387 logger(DEBUG_ALWAYS, LOG_ERR, "Invalid Name: environment variable %s does not exist\n", name + 1);
391 if(gethostname(envname, 32)) {
392 logger(DEBUG_ALWAYS, LOG_ERR, "Could not get hostname: %s\n", strerror(errno));
398 name = xstrdup(envname);
399 for(char *c = name; *c; c++)
404 if(!check_id(name)) {
405 logger(DEBUG_ALWAYS, LOG_ERR, "Invalid name for myself!");
413 bool setup_myself_reloadable(void) {
422 free(scriptinterpreter);
423 scriptinterpreter = NULL;
424 get_config_string(lookup_config(config_tree, "ScriptsInterpreter"), &scriptinterpreter);
427 free(scriptextension);
428 if(!get_config_string(lookup_config(config_tree, "ScriptsExtension"), &scriptextension))
430 scriptextension = xstrdup(".bat");
432 scriptextension = xstrdup("");
435 get_config_string(lookup_config(config_tree, "Proxy"), &proxy);
437 if((space = strchr(proxy, ' ')))
440 if(!strcasecmp(proxy, "none")) {
441 proxytype = PROXY_NONE;
442 } else if(!strcasecmp(proxy, "socks4")) {
443 proxytype = PROXY_SOCKS4;
444 } else if(!strcasecmp(proxy, "socks4a")) {
445 proxytype = PROXY_SOCKS4A;
446 } else if(!strcasecmp(proxy, "socks5")) {
447 proxytype = PROXY_SOCKS5;
448 } else if(!strcasecmp(proxy, "http")) {
449 proxytype = PROXY_HTTP;
450 } else if(!strcasecmp(proxy, "exec")) {
451 proxytype = PROXY_EXEC;
453 logger(DEBUG_ALWAYS, LOG_ERR, "Unknown proxy type %s!", proxy);
463 if(!space || !*space) {
464 logger(DEBUG_ALWAYS, LOG_ERR, "Argument expected for proxy type exec!");
467 proxyhost = xstrdup(space);
475 if(space && (space = strchr(space, ' ')))
476 *space++ = 0, proxyport = space;
477 if(space && (space = strchr(space, ' ')))
478 *space++ = 0, proxyuser = space;
479 if(space && (space = strchr(space, ' ')))
480 *space++ = 0, proxypass = space;
481 if(!proxyhost || !*proxyhost || !proxyport || !*proxyport) {
482 logger(DEBUG_ALWAYS, LOG_ERR, "Host and port argument expected for proxy!");
485 proxyhost = xstrdup(proxyhost);
486 proxyport = xstrdup(proxyport);
487 if(proxyuser && *proxyuser)
488 proxyuser = xstrdup(proxyuser);
489 if(proxypass && *proxypass)
490 proxypass = xstrdup(proxypass);
497 if(get_config_bool(lookup_config(config_tree, "IndirectData"), &choice) && choice)
498 myself->options |= OPTION_INDIRECT;
500 if(get_config_bool(lookup_config(config_tree, "TCPOnly"), &choice) && choice)
501 myself->options |= OPTION_TCPONLY;
503 if(myself->options & OPTION_TCPONLY)
504 myself->options |= OPTION_INDIRECT;
506 get_config_bool(lookup_config(config_tree, "DirectOnly"), &directonly);
507 get_config_bool(lookup_config(config_tree, "LocalDiscovery"), &localdiscovery);
509 if(get_config_string(lookup_config(config_tree, "Mode"), &rmode)) {
510 if(!strcasecmp(rmode, "router"))
511 routing_mode = RMODE_ROUTER;
512 else if(!strcasecmp(rmode, "switch"))
513 routing_mode = RMODE_SWITCH;
514 else if(!strcasecmp(rmode, "hub"))
515 routing_mode = RMODE_HUB;
517 logger(DEBUG_ALWAYS, LOG_ERR, "Invalid routing mode!");
523 if(get_config_string(lookup_config(config_tree, "Forwarding"), &fmode)) {
524 if(!strcasecmp(fmode, "off"))
525 forwarding_mode = FMODE_OFF;
526 else if(!strcasecmp(fmode, "internal"))
527 forwarding_mode = FMODE_INTERNAL;
528 else if(!strcasecmp(fmode, "kernel"))
529 forwarding_mode = FMODE_KERNEL;
531 logger(DEBUG_ALWAYS, LOG_ERR, "Invalid forwarding mode!");
538 get_config_bool(lookup_config(config_tree, "PMTUDiscovery"), &choice);
540 myself->options |= OPTION_PMTU_DISCOVERY;
543 get_config_bool(lookup_config(config_tree, "ClampMSS"), &choice);
545 myself->options |= OPTION_CLAMP_MSS;
547 get_config_bool(lookup_config(config_tree, "PriorityInheritance"), &priorityinheritance);
548 get_config_bool(lookup_config(config_tree, "DecrementTTL"), &decrement_ttl);
549 if(get_config_string(lookup_config(config_tree, "Broadcast"), &bmode)) {
550 if(!strcasecmp(bmode, "no"))
551 broadcast_mode = BMODE_NONE;
552 else if(!strcasecmp(bmode, "yes") || !strcasecmp(bmode, "mst"))
553 broadcast_mode = BMODE_MST;
554 else if(!strcasecmp(bmode, "direct"))
555 broadcast_mode = BMODE_DIRECT;
557 logger(DEBUG_ALWAYS, LOG_ERR, "Invalid broadcast mode!");
563 #if !defined(SOL_IP) || !defined(IP_TOS)
564 if(priorityinheritance)
565 logger(DEBUG_ALWAYS, LOG_WARNING, "%s not supported on this platform", "PriorityInheritance");
568 if(!get_config_int(lookup_config(config_tree, "MACExpire"), &macexpire))
571 if(get_config_int(lookup_config(config_tree, "MaxTimeout"), &maxtimeout)) {
572 if(maxtimeout <= 0) {
573 logger(DEBUG_ALWAYS, LOG_ERR, "Bogus maximum timeout!");
579 if(get_config_string(lookup_config(config_tree, "AddressFamily"), &afname)) {
580 if(!strcasecmp(afname, "IPv4"))
581 addressfamily = AF_INET;
582 else if(!strcasecmp(afname, "IPv6"))
583 addressfamily = AF_INET6;
584 else if(!strcasecmp(afname, "any"))
585 addressfamily = AF_UNSPEC;
587 logger(DEBUG_ALWAYS, LOG_ERR, "Invalid address family!");
593 get_config_bool(lookup_config(config_tree, "Hostnames"), &hostnames);
595 if(!get_config_int(lookup_config(config_tree, "KeyExpire"), &keylifetime))
598 get_config_int(lookup_config(config_tree, "AutoConnect"), &autoconnect);
604 Configure node_t myself and set up the local sockets (listen only)
606 static bool setup_myself(void) {
607 char *name, *hostname, *cipher, *digest, *type;
609 char *address = NULL;
611 if(!(name = get_name())) {
612 logger(DEBUG_ALWAYS, LOG_ERR, "Name for tinc daemon required!");
617 myself->connection = new_connection();
619 myself->connection->name = xstrdup(name);
620 xasprintf(&fname, "%s" SLASH "hosts" SLASH "%s", confbase, name);
621 read_config_options(config_tree, name);
622 read_config_file(config_tree, fname);
625 if(!get_config_string(lookup_config(config_tree, "Port"), &myport))
626 myport = xstrdup("655");
628 xasprintf(&myself->hostname, "MYSELF port %s", myport);
629 myself->connection->hostname = xstrdup(myself->hostname);
631 myself->connection->options = 0;
632 myself->connection->protocol_major = PROT_MAJOR;
633 myself->connection->protocol_minor = PROT_MINOR;
635 myself->options |= PROT_MINOR << 24;
637 get_config_bool(lookup_config(config_tree, "ExperimentalProtocol"), &experimental);
639 if(experimental && !read_ecdsa_private_key())
642 if(!read_rsa_private_key())
646 struct addrinfo *ai = str2addrinfo("localhost", myport, SOCK_DGRAM);
648 if(!ai || !ai->ai_addr)
651 memcpy(&sa, ai->ai_addr, ai->ai_addrlen);
652 sockaddr2str(&sa, NULL, &myport);
655 /* Read in all the subnets specified in the host configuration file */
657 for(config_t *cfg = lookup_config(config_tree, "Subnet"); cfg; cfg = lookup_config_next(config_tree, cfg)) {
660 if(!get_config_subnet(cfg, &subnet))
663 subnet_add(myself, subnet);
666 /* Check some options */
668 if(!setup_myself_reloadable())
671 get_config_bool(lookup_config(config_tree, "StrictSubnets"), &strictsubnets);
672 get_config_bool(lookup_config(config_tree, "TunnelServer"), &tunnelserver);
673 strictsubnets |= tunnelserver;
677 if(get_config_int(lookup_config(config_tree, "UDPRcvBuf"), &udp_rcvbuf)) {
678 if(udp_rcvbuf <= 0) {
679 logger(DEBUG_ALWAYS, LOG_ERR, "UDPRcvBuf cannot be negative!");
684 if(get_config_int(lookup_config(config_tree, "UDPSndBuf"), &udp_sndbuf)) {
685 if(udp_sndbuf <= 0) {
686 logger(DEBUG_ALWAYS, LOG_ERR, "UDPSndBuf cannot be negative!");
692 if(get_config_int(lookup_config(config_tree, "ReplayWindow"), &replaywin_int)) {
693 if(replaywin_int < 0) {
694 logger(DEBUG_ALWAYS, LOG_ERR, "ReplayWindow cannot be negative!");
697 replaywin = (unsigned)replaywin_int;
698 sptps_replaywin = replaywin;
701 /* Generate packet encryption key */
703 if(!get_config_string(lookup_config(config_tree, "Cipher"), &cipher))
704 cipher = xstrdup("blowfish");
706 if(!cipher_open_by_name(&myself->incipher, cipher)) {
707 logger(DEBUG_ALWAYS, LOG_ERR, "Unrecognized cipher type!");
714 timeout_add(&keyexpire_timeout, keyexpire_handler, &keyexpire_timeout, &(struct timeval){keylifetime, rand() % 100000});
716 /* Check if we want to use message authentication codes... */
719 get_config_int(lookup_config(config_tree, "MACLength"), &maclength);
722 logger(DEBUG_ALWAYS, LOG_ERR, "Bogus MAC length!");
726 if(!get_config_string(lookup_config(config_tree, "Digest"), &digest))
727 digest = xstrdup("sha1");
729 if(!digest_open_by_name(&myself->indigest, digest, maclength)) {
730 logger(DEBUG_ALWAYS, LOG_ERR, "Unrecognized digest type!");
738 if(get_config_int(lookup_config(config_tree, "Compression"), &myself->incompression)) {
739 if(myself->incompression < 0 || myself->incompression > 11) {
740 logger(DEBUG_ALWAYS, LOG_ERR, "Bogus compression level!");
744 myself->incompression = 0;
746 myself->connection->outcompression = 0;
750 myself->nexthop = myself;
751 myself->via = myself;
752 myself->status.reachable = true;
753 myself->last_state_change = time(NULL);
754 myself->status.sptps = experimental;
768 if(get_config_string(lookup_config(config_tree, "DeviceType"), &type)) {
769 if(!strcasecmp(type, "dummy"))
770 devops = dummy_devops;
771 else if(!strcasecmp(type, "raw_socket"))
772 devops = raw_socket_devops;
773 else if(!strcasecmp(type, "multicast"))
774 devops = multicast_devops;
776 else if(!strcasecmp(type, "uml"))
780 else if(!strcasecmp(type, "vde"))
789 io_add(&device_io, handle_device_data, NULL, device_fd, IO_READ);
791 /* Run tinc-up script to further initialize the tap interface */
793 xasprintf(&envp[0], "NETNAME=%s", netname ? : "");
794 xasprintf(&envp[1], "DEVICE=%s", device ? : "");
795 xasprintf(&envp[2], "INTERFACE=%s", iface ? : "");
796 xasprintf(&envp[3], "NAME=%s", myself->name);
799 execute_script("tinc-up", envp);
801 for(int i = 0; i < 4; i++)
804 /* Run subnet-up scripts for our own subnets */
806 subnet_update(myself, NULL, true);
810 if(!do_detach && getenv("LISTEN_FDS")) {
814 listen_sockets = atoi(getenv("LISTEN_FDS"));
816 unsetenv("LISTEN_FDS");
819 if(listen_sockets > MAXSOCKETS) {
820 logger(DEBUG_ALWAYS, LOG_ERR, "Too many listening sockets");
824 for(int i = 0; i < listen_sockets; i++) {
826 if(getsockname(i + 3, &sa.sa, &salen) < 0) {
827 logger(DEBUG_ALWAYS, LOG_ERR, "Could not get address of listen fd %d: %s", i + 3, sockstrerror(errno));
832 fcntl(i + 3, F_SETFD, FD_CLOEXEC);
835 int udp_fd = setup_vpn_in_socket(&sa);
839 io_add(&listen_socket[i].tcp, (io_cb_t)handle_new_meta_connection, &listen_socket[i], i + 3, IO_READ);
840 io_add(&listen_socket[i].udp, (io_cb_t)handle_incoming_vpn_data, &listen_socket[i], udp_fd, IO_READ);
842 if(debug_level >= DEBUG_CONNECTIONS) {
843 hostname = sockaddr2hostname(&sa);
844 logger(DEBUG_CONNECTIONS, LOG_NOTICE, "Listening on %s", hostname);
848 memcpy(&listen_socket[i].sa, &sa, salen);
852 config_t *cfg = lookup_config(config_tree, "BindToAddress");
855 get_config_string(cfg, &address);
857 cfg = lookup_config_next(config_tree, cfg);
862 char *space = strchr(address, ' ');
868 if(!strcmp(address, "*"))
872 struct addrinfo *ai, hint = {0};
873 hint.ai_family = addressfamily;
874 hint.ai_socktype = SOCK_STREAM;
875 hint.ai_protocol = IPPROTO_TCP;
876 hint.ai_flags = AI_PASSIVE;
878 int err = getaddrinfo(address && *address ? address : NULL, port, &hint, &ai);
882 logger(DEBUG_ALWAYS, LOG_ERR, "System call `%s' failed: %s", "getaddrinfo",
887 for(struct addrinfo *aip = ai; aip; aip = aip->ai_next) {
888 if(listen_sockets >= MAXSOCKETS) {
889 logger(DEBUG_ALWAYS, LOG_ERR, "Too many listening sockets");
893 int tcp_fd = setup_listen_socket((sockaddr_t *) aip->ai_addr);
898 int udp_fd = setup_vpn_in_socket((sockaddr_t *) aip->ai_addr);
905 io_add(&listen_socket[listen_sockets].tcp, handle_new_meta_connection, &listen_socket[listen_sockets], tcp_fd, IO_READ);
906 io_add(&listen_socket[listen_sockets].udp, handle_incoming_vpn_data, &listen_socket[listen_sockets], udp_fd, IO_READ);
908 if(debug_level >= DEBUG_CONNECTIONS) {
909 hostname = sockaddr2hostname((sockaddr_t *) aip->ai_addr);
910 logger(DEBUG_CONNECTIONS, LOG_NOTICE, "Listening on %s", hostname);
914 memcpy(&listen_socket[listen_sockets].sa, aip->ai_addr, aip->ai_addrlen);
923 logger(DEBUG_ALWAYS, LOG_NOTICE, "Ready");
925 logger(DEBUG_ALWAYS, LOG_ERR, "Unable to create any listening socket!");
929 last_config_check = time(NULL);
937 bool setup_network(void) {
944 if(get_config_int(lookup_config(config_tree, "PingInterval"), &pinginterval)) {
945 if(pinginterval < 1) {
946 pinginterval = 86400;
951 if(!get_config_int(lookup_config(config_tree, "PingTimeout"), &pingtimeout))
953 if(pingtimeout < 1 || pingtimeout > pinginterval)
954 pingtimeout = pinginterval;
956 if(!get_config_int(lookup_config(config_tree, "MaxOutputBufferSize"), &maxoutbufsize))
957 maxoutbufsize = 10 * MTU;
966 close all open network connections
968 void close_network_connections(void) {
969 for(list_node_t *node = connection_list->head, *next; node; node = next) {
971 connection_t *c = node->data;
972 /* Keep control connections open until the end, so they know when we really terminated */
973 if(c->status.control)
976 terminate_connection(c, false);
979 list_delete_list(outgoing_list);
981 if(myself && myself->connection) {
982 subnet_update(myself, NULL, false);
983 terminate_connection(myself->connection, false);
984 free_connection(myself->connection);
987 for(int i = 0; i < listen_sockets; i++) {
988 io_del(&listen_socket[i].tcp);
989 io_del(&listen_socket[i].udp);
990 close(listen_socket[i].tcp.fd);
991 close(listen_socket[i].udp.fd);
995 xasprintf(&envp[0], "NETNAME=%s", netname ? : "");
996 xasprintf(&envp[1], "DEVICE=%s", device ? : "");
997 xasprintf(&envp[2], "INTERFACE=%s", iface ? : "");
998 xasprintf(&envp[3], "NAME=%s", myself->name);
1007 execute_script("tinc-down", envp);
1009 if(myport) free(myport);
1011 for(int i = 0; i < 4; i++)