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"
50 proxytype_t proxytype;
52 bool disablebuggypeers;
54 char *scriptinterpreter;
55 char *scriptextension;
57 bool node_read_ecdsa_public_key(node_t *n) {
58 if(ecdsa_active(n->ecdsa))
61 splay_tree_t *config_tree;
66 init_configuration(&config_tree);
67 if(!read_host_config(config_tree, n->name))
70 /* First, check for simple ECDSAPublicKey statement */
72 if(get_config_string(lookup_config(config_tree, "ECDSAPublicKey"), &p)) {
73 n->ecdsa = ecdsa_set_base64_public_key(p);
78 /* Else, check for ECDSAPublicKeyFile statement and read it */
80 if(!get_config_string(lookup_config(config_tree, "ECDSAPublicKeyFile"), &pubname))
81 xasprintf(&pubname, "%s" SLASH "hosts" SLASH "%s", confbase, n->name);
83 fp = fopen(pubname, "r");
88 n->ecdsa = ecdsa_read_pem_public_key(fp);
92 exit_configuration(&config_tree);
97 bool read_ecdsa_public_key(connection_t *c) {
98 if(ecdsa_active(c->ecdsa))
105 if(!c->config_tree) {
106 init_configuration(&c->config_tree);
107 if(!read_host_config(c->config_tree, c->name))
111 /* First, check for simple ECDSAPublicKey statement */
113 if(get_config_string(lookup_config(c->config_tree, "ECDSAPublicKey"), &p)) {
114 c->ecdsa = ecdsa_set_base64_public_key(p);
119 /* Else, check for ECDSAPublicKeyFile statement and read it */
121 if(!get_config_string(lookup_config(c->config_tree, "ECDSAPublicKeyFile"), &fname))
122 xasprintf(&fname, "%s" SLASH "hosts" SLASH "%s", confbase, c->name);
124 fp = fopen(fname, "r");
127 logger(DEBUG_ALWAYS, LOG_ERR, "Error reading ECDSA public key file `%s': %s",
128 fname, strerror(errno));
133 c->ecdsa = ecdsa_read_pem_public_key(fp);
137 logger(DEBUG_ALWAYS, LOG_ERR, "Parsing ECDSA public key file `%s' failed.", fname);
142 bool read_rsa_public_key(connection_t *c) {
143 if(ecdsa_active(c->ecdsa))
150 /* First, check for simple PublicKey statement */
152 if(get_config_string(lookup_config(c->config_tree, "PublicKey"), &n)) {
153 c->rsa = rsa_set_hex_public_key(n, "FFFF");
158 /* Else, check for PublicKeyFile statement and read it */
160 if(!get_config_string(lookup_config(c->config_tree, "PublicKeyFile"), &fname))
161 xasprintf(&fname, "%s" SLASH "hosts" SLASH "%s", confbase, c->name);
163 fp = fopen(fname, "r");
166 logger(DEBUG_ALWAYS, LOG_ERR, "Error reading RSA public key file `%s': %s", fname, strerror(errno));
171 c->rsa = rsa_read_pem_public_key(fp);
175 logger(DEBUG_ALWAYS, LOG_ERR, "Reading RSA public key file `%s' failed: %s", fname, strerror(errno));
180 static bool read_ecdsa_private_key(void) {
184 /* Check for PrivateKeyFile statement and read it */
186 if(!get_config_string(lookup_config(config_tree, "ECDSAPrivateKeyFile"), &fname))
187 xasprintf(&fname, "%s" SLASH "ecdsa_key.priv", confbase);
189 fp = fopen(fname, "r");
192 logger(DEBUG_ALWAYS, LOG_ERR, "Error reading ECDSA private key file `%s': %s", fname, strerror(errno));
194 logger(DEBUG_ALWAYS, LOG_INFO, "Create an ECDSA keypair with `tinc -n %s generate-ecdsa-keys'.", netname ?: ".");
199 #if !defined(HAVE_MINGW) && !defined(HAVE_CYGWIN)
202 if(fstat(fileno(fp), &s)) {
203 logger(DEBUG_ALWAYS, LOG_ERR, "Could not stat ECDSA private key file `%s': %s'", fname, strerror(errno));
208 if(s.st_mode & ~0100700)
209 logger(DEBUG_ALWAYS, LOG_WARNING, "Warning: insecure file permissions for ECDSA private key file `%s'!", fname);
212 myself->connection->ecdsa = ecdsa_read_pem_private_key(fp);
215 if(!myself->connection->ecdsa)
216 logger(DEBUG_ALWAYS, LOG_ERR, "Reading ECDSA private key file `%s' failed: %s", fname, strerror(errno));
218 return myself->connection->ecdsa;
221 static bool read_invitation_key(void) {
226 ecdsa_free(invitation_key);
227 invitation_key = NULL;
230 xasprintf(&fname, "%s" SLASH "invitations" SLASH "ecdsa_key.priv", confbase);
232 fp = fopen(fname, "r");
235 invitation_key = ecdsa_read_pem_private_key(fp);
238 logger(DEBUG_ALWAYS, LOG_ERR, "Reading ECDSA private key file `%s' failed: %s", fname, strerror(errno));
242 return invitation_key;
245 static bool read_rsa_private_key(void) {
250 /* First, check for simple PrivateKey statement */
252 if(get_config_string(lookup_config(config_tree, "PrivateKey"), &d)) {
253 if(!get_config_string(lookup_config(config_tree, "PublicKey"), &n)) {
254 logger(DEBUG_ALWAYS, LOG_ERR, "PrivateKey used but no PublicKey found!");
258 myself->connection->rsa = rsa_set_hex_private_key(n, "FFFF", d);
261 return myself->connection->rsa;
264 /* Else, check for PrivateKeyFile statement and read it */
266 if(!get_config_string(lookup_config(config_tree, "PrivateKeyFile"), &fname))
267 xasprintf(&fname, "%s" SLASH "rsa_key.priv", confbase);
269 fp = fopen(fname, "r");
272 logger(DEBUG_ALWAYS, LOG_ERR, "Error reading RSA private key file `%s': %s",
273 fname, strerror(errno));
278 #if !defined(HAVE_MINGW) && !defined(HAVE_CYGWIN)
281 if(fstat(fileno(fp), &s)) {
282 logger(DEBUG_ALWAYS, LOG_ERR, "Could not stat RSA private key file `%s': %s'", fname, strerror(errno));
287 if(s.st_mode & ~0100700)
288 logger(DEBUG_ALWAYS, LOG_WARNING, "Warning: insecure file permissions for RSA private key file `%s'!", fname);
291 myself->connection->rsa = rsa_read_pem_private_key(fp);
294 if(!myself->connection->rsa)
295 logger(DEBUG_ALWAYS, LOG_ERR, "Reading RSA private key file `%s' failed: %s", fname, strerror(errno));
297 return myself->connection->rsa;
300 static timeout_t keyexpire_timeout;
302 static void keyexpire_handler(void *data) {
304 timeout_set(data, &(struct timeval){keylifetime, rand() % 100000});
307 void regenerate_key(void) {
308 logger(DEBUG_STATUS, LOG_INFO, "Expiring symmetric keys");
312 void load_all_nodes(void) {
317 xasprintf(&dname, "%s" SLASH "hosts", confbase);
318 dir = opendir(dname);
320 logger(DEBUG_ALWAYS, LOG_ERR, "Could not open %s: %s", dname, strerror(errno));
325 while((ent = readdir(dir))) {
326 if(!check_id(ent->d_name))
329 node_t *n = lookup_node(ent->d_name);
334 n->name = xstrdup(ent->d_name);
342 char *get_name(void) {
345 get_config_string(lookup_config(config_tree, "Name"), &name);
351 char *envname = getenv(name + 1);
352 char hostname[32] = "";
354 if(strcmp(name + 1, "HOST")) {
355 logger(DEBUG_ALWAYS, LOG_ERR, "Invalid Name: environment variable %s does not exist\n", name + 1);
358 if(gethostname(hostname, sizeof hostname) || !*hostname) {
359 logger(DEBUG_ALWAYS, LOG_ERR, "Could not get hostname: %s\n", strerror(errno));
366 name = xstrdup(envname);
367 for(char *c = name; *c; c++)
372 if(!check_id(name)) {
373 logger(DEBUG_ALWAYS, LOG_ERR, "Invalid name for myself!");
381 bool setup_myself_reloadable(void) {
387 char *address = NULL;
391 free(scriptinterpreter);
392 scriptinterpreter = NULL;
393 get_config_string(lookup_config(config_tree, "ScriptsInterpreter"), &scriptinterpreter);
396 free(scriptextension);
397 if(!get_config_string(lookup_config(config_tree, "ScriptsExtension"), &scriptextension))
398 scriptextension = xstrdup("");
400 get_config_string(lookup_config(config_tree, "Proxy"), &proxy);
402 if((space = strchr(proxy, ' ')))
405 if(!strcasecmp(proxy, "none")) {
406 proxytype = PROXY_NONE;
407 } else if(!strcasecmp(proxy, "socks4")) {
408 proxytype = PROXY_SOCKS4;
409 } else if(!strcasecmp(proxy, "socks4a")) {
410 proxytype = PROXY_SOCKS4A;
411 } else if(!strcasecmp(proxy, "socks5")) {
412 proxytype = PROXY_SOCKS5;
413 } else if(!strcasecmp(proxy, "http")) {
414 proxytype = PROXY_HTTP;
415 } else if(!strcasecmp(proxy, "exec")) {
416 proxytype = PROXY_EXEC;
418 logger(DEBUG_ALWAYS, LOG_ERR, "Unknown proxy type %s!", proxy);
428 if(!space || !*space) {
429 logger(DEBUG_ALWAYS, LOG_ERR, "Argument expected for proxy type exec!");
432 proxyhost = xstrdup(space);
440 if(space && (space = strchr(space, ' ')))
441 *space++ = 0, proxyport = space;
442 if(space && (space = strchr(space, ' ')))
443 *space++ = 0, proxyuser = space;
444 if(space && (space = strchr(space, ' ')))
445 *space++ = 0, proxypass = space;
446 if(!proxyhost || !*proxyhost || !proxyport || !*proxyport) {
447 logger(DEBUG_ALWAYS, LOG_ERR, "Host and port argument expected for proxy!");
450 proxyhost = xstrdup(proxyhost);
451 proxyport = xstrdup(proxyport);
452 if(proxyuser && *proxyuser)
453 proxyuser = xstrdup(proxyuser);
454 if(proxypass && *proxypass)
455 proxypass = xstrdup(proxypass);
462 if(get_config_bool(lookup_config(config_tree, "IndirectData"), &choice) && choice)
463 myself->options |= OPTION_INDIRECT;
465 if(get_config_bool(lookup_config(config_tree, "TCPOnly"), &choice) && choice)
466 myself->options |= OPTION_TCPONLY;
468 if(myself->options & OPTION_TCPONLY)
469 myself->options |= OPTION_INDIRECT;
471 get_config_bool(lookup_config(config_tree, "DirectOnly"), &directonly);
472 get_config_bool(lookup_config(config_tree, "LocalDiscovery"), &localdiscovery);
474 memset(&localdiscovery_address, 0, sizeof localdiscovery_address);
475 if(get_config_string(lookup_config(config_tree, "LocalDiscoveryAddress"), &address)) {
476 struct addrinfo *ai = str2addrinfo(address, myport, SOCK_DGRAM);
480 memcpy(&localdiscovery_address, ai->ai_addr, ai->ai_addrlen);
484 if(get_config_string(lookup_config(config_tree, "Mode"), &rmode)) {
485 if(!strcasecmp(rmode, "router"))
486 routing_mode = RMODE_ROUTER;
487 else if(!strcasecmp(rmode, "switch"))
488 routing_mode = RMODE_SWITCH;
489 else if(!strcasecmp(rmode, "hub"))
490 routing_mode = RMODE_HUB;
492 logger(DEBUG_ALWAYS, LOG_ERR, "Invalid routing mode!");
498 if(get_config_string(lookup_config(config_tree, "Forwarding"), &fmode)) {
499 if(!strcasecmp(fmode, "off"))
500 forwarding_mode = FMODE_OFF;
501 else if(!strcasecmp(fmode, "internal"))
502 forwarding_mode = FMODE_INTERNAL;
503 else if(!strcasecmp(fmode, "kernel"))
504 forwarding_mode = FMODE_KERNEL;
506 logger(DEBUG_ALWAYS, LOG_ERR, "Invalid forwarding mode!");
513 get_config_bool(lookup_config(config_tree, "PMTUDiscovery"), &choice);
515 myself->options |= OPTION_PMTU_DISCOVERY;
518 get_config_bool(lookup_config(config_tree, "ClampMSS"), &choice);
520 myself->options |= OPTION_CLAMP_MSS;
522 get_config_bool(lookup_config(config_tree, "PriorityInheritance"), &priorityinheritance);
523 get_config_bool(lookup_config(config_tree, "DecrementTTL"), &decrement_ttl);
524 if(get_config_string(lookup_config(config_tree, "Broadcast"), &bmode)) {
525 if(!strcasecmp(bmode, "no"))
526 broadcast_mode = BMODE_NONE;
527 else if(!strcasecmp(bmode, "yes") || !strcasecmp(bmode, "mst"))
528 broadcast_mode = BMODE_MST;
529 else if(!strcasecmp(bmode, "direct"))
530 broadcast_mode = BMODE_DIRECT;
532 logger(DEBUG_ALWAYS, LOG_ERR, "Invalid broadcast mode!");
538 #if !defined(SOL_IP) || !defined(IP_TOS)
539 if(priorityinheritance)
540 logger(DEBUG_ALWAYS, LOG_WARNING, "%s not supported on this platform", "PriorityInheritance");
543 if(!get_config_int(lookup_config(config_tree, "MACExpire"), &macexpire))
546 if(get_config_int(lookup_config(config_tree, "MaxTimeout"), &maxtimeout)) {
547 if(maxtimeout <= 0) {
548 logger(DEBUG_ALWAYS, LOG_ERR, "Bogus maximum timeout!");
554 if(get_config_string(lookup_config(config_tree, "AddressFamily"), &afname)) {
555 if(!strcasecmp(afname, "IPv4"))
556 addressfamily = AF_INET;
557 else if(!strcasecmp(afname, "IPv6"))
558 addressfamily = AF_INET6;
559 else if(!strcasecmp(afname, "any"))
560 addressfamily = AF_UNSPEC;
562 logger(DEBUG_ALWAYS, LOG_ERR, "Invalid address family!");
568 get_config_bool(lookup_config(config_tree, "Hostnames"), &hostnames);
570 if(!get_config_int(lookup_config(config_tree, "KeyExpire"), &keylifetime))
573 get_config_int(lookup_config(config_tree, "AutoConnect"), &autoconnect);
577 get_config_bool(lookup_config(config_tree, "DisableBuggyPeers"), &disablebuggypeers);
579 read_invitation_key();
585 Add listening sockets.
587 static bool add_listen_address(char *address, bool bindto) {
591 char *space = strchr(address, ' ');
597 if(!strcmp(address, "*"))
601 struct addrinfo *ai, hint = {0};
602 hint.ai_family = addressfamily;
603 hint.ai_socktype = SOCK_STREAM;
604 hint.ai_protocol = IPPROTO_TCP;
605 hint.ai_flags = AI_PASSIVE;
607 int err = getaddrinfo(address && *address ? address : NULL, port, &hint, &ai);
611 logger(DEBUG_ALWAYS, LOG_ERR, "System call `%s' failed: %s", "getaddrinfo", err == EAI_SYSTEM ? strerror(err) : gai_strerror(err));
615 for(struct addrinfo *aip = ai; aip; aip = aip->ai_next) {
616 // Ignore duplicate addresses
619 for(int i = 0; i < listen_sockets; i++)
620 if(!memcmp(&listen_socket[i].sa, aip->ai_addr, aip->ai_addrlen)) {
628 if(listen_sockets >= MAXSOCKETS) {
629 logger(DEBUG_ALWAYS, LOG_ERR, "Too many listening sockets");
633 int tcp_fd = setup_listen_socket((sockaddr_t *) aip->ai_addr);
638 int udp_fd = setup_vpn_in_socket((sockaddr_t *) aip->ai_addr);
645 io_add(&listen_socket[listen_sockets].tcp, handle_new_meta_connection, &listen_socket[listen_sockets], tcp_fd, IO_READ);
646 io_add(&listen_socket[listen_sockets].udp, handle_incoming_vpn_data, &listen_socket[listen_sockets], udp_fd, IO_READ);
648 if(debug_level >= DEBUG_CONNECTIONS) {
649 char *hostname = sockaddr2hostname((sockaddr_t *) aip->ai_addr);
650 logger(DEBUG_CONNECTIONS, LOG_NOTICE, "Listening on %s", hostname);
654 listen_socket[listen_sockets].bindto = bindto;
655 memcpy(&listen_socket[listen_sockets].sa, aip->ai_addr, aip->ai_addrlen);
664 Configure node_t myself and set up the local sockets (listen only)
666 bool setup_myself(void) {
667 char *name, *hostname, *cipher, *digest, *type;
668 char *address = NULL;
669 bool port_specified = false;
671 if(!(name = get_name())) {
672 logger(DEBUG_ALWAYS, LOG_ERR, "Name for tinc daemon required!");
677 myself->connection = new_connection();
679 myself->connection->name = xstrdup(name);
680 read_host_config(config_tree, name);
682 if(!get_config_string(lookup_config(config_tree, "Port"), &myport))
683 myport = xstrdup("655");
685 port_specified = true;
687 myself->connection->options = 0;
688 myself->connection->protocol_major = PROT_MAJOR;
689 myself->connection->protocol_minor = PROT_MINOR;
691 myself->options |= PROT_MINOR << 24;
693 if(!get_config_bool(lookup_config(config_tree, "ExperimentalProtocol"), &experimental)) {
694 experimental = read_ecdsa_private_key();
696 logger(DEBUG_ALWAYS, LOG_WARNING, "Support for SPTPS disabled.");
698 if(experimental && !read_ecdsa_private_key())
702 if(!read_rsa_private_key())
705 /* Ensure myport is numeric */
708 struct addrinfo *ai = str2addrinfo("localhost", myport, SOCK_DGRAM);
710 if(!ai || !ai->ai_addr)
713 memcpy(&sa, ai->ai_addr, ai->ai_addrlen);
714 sockaddr2str(&sa, NULL, &myport);
717 /* Check some options */
719 if(!setup_myself_reloadable())
722 get_config_bool(lookup_config(config_tree, "TunnelServer"), &tunnelserver);
724 if(get_config_int(lookup_config(config_tree, "MaxConnectionBurst"), &max_connection_burst)) {
725 if(max_connection_burst <= 0) {
726 logger(DEBUG_ALWAYS, LOG_ERR, "MaxConnectionBurst cannot be negative!");
731 if(get_config_int(lookup_config(config_tree, "UDPRcvBuf"), &udp_rcvbuf)) {
732 if(udp_rcvbuf <= 0) {
733 logger(DEBUG_ALWAYS, LOG_ERR, "UDPRcvBuf cannot be negative!");
738 if(get_config_int(lookup_config(config_tree, "UDPSndBuf"), &udp_sndbuf)) {
739 if(udp_sndbuf <= 0) {
740 logger(DEBUG_ALWAYS, LOG_ERR, "UDPSndBuf cannot be negative!");
746 if(get_config_int(lookup_config(config_tree, "ReplayWindow"), &replaywin_int)) {
747 if(replaywin_int < 0) {
748 logger(DEBUG_ALWAYS, LOG_ERR, "ReplayWindow cannot be negative!");
751 replaywin = (unsigned)replaywin_int;
752 sptps_replaywin = replaywin;
755 /* Generate packet encryption key */
757 if(!get_config_string(lookup_config(config_tree, "Cipher"), &cipher))
758 cipher = xstrdup("blowfish");
760 if(!strcasecmp(cipher, "none")) {
761 myself->incipher = NULL;
762 } else if(!(myself->incipher = cipher_open_by_name(cipher))) {
763 logger(DEBUG_ALWAYS, LOG_ERR, "Unrecognized cipher type!");
769 timeout_add(&keyexpire_timeout, keyexpire_handler, &keyexpire_timeout, &(struct timeval){keylifetime, rand() % 100000});
771 /* Check if we want to use message authentication codes... */
774 get_config_int(lookup_config(config_tree, "MACLength"), &maclength);
777 logger(DEBUG_ALWAYS, LOG_ERR, "Bogus MAC length!");
781 if(!get_config_string(lookup_config(config_tree, "Digest"), &digest))
782 digest = xstrdup("sha1");
784 if(!strcasecmp(digest, "none")) {
785 myself->indigest = NULL;
786 } else if(!(myself->indigest = digest_open_by_name(digest, maclength))) {
787 logger(DEBUG_ALWAYS, LOG_ERR, "Unrecognized digest type!");
795 if(get_config_int(lookup_config(config_tree, "Compression"), &myself->incompression)) {
796 if(myself->incompression < 0 || myself->incompression > 11) {
797 logger(DEBUG_ALWAYS, LOG_ERR, "Bogus compression level!");
801 myself->incompression = 0;
803 myself->connection->outcompression = 0;
807 myself->nexthop = myself;
808 myself->via = myself;
809 myself->status.reachable = true;
810 myself->last_state_change = now.tv_sec;
811 myself->status.sptps = experimental;
821 if(!do_detach && getenv("LISTEN_FDS")) {
825 listen_sockets = atoi(getenv("LISTEN_FDS"));
827 unsetenv("LISTEN_FDS");
830 if(listen_sockets > MAXSOCKETS) {
831 logger(DEBUG_ALWAYS, LOG_ERR, "Too many listening sockets");
835 for(int i = 0; i < listen_sockets; i++) {
837 if(getsockname(i + 3, &sa.sa, &salen) < 0) {
838 logger(DEBUG_ALWAYS, LOG_ERR, "Could not get address of listen fd %d: %s", i + 3, sockstrerror(errno));
843 fcntl(i + 3, F_SETFD, FD_CLOEXEC);
846 int udp_fd = setup_vpn_in_socket(&sa);
850 io_add(&listen_socket[i].tcp, (io_cb_t)handle_new_meta_connection, &listen_socket[i], i + 3, IO_READ);
851 io_add(&listen_socket[i].udp, (io_cb_t)handle_incoming_vpn_data, &listen_socket[i], udp_fd, IO_READ);
853 if(debug_level >= DEBUG_CONNECTIONS) {
854 hostname = sockaddr2hostname(&sa);
855 logger(DEBUG_CONNECTIONS, LOG_NOTICE, "Listening on %s", hostname);
859 memcpy(&listen_socket[i].sa, &sa, salen);
865 for(config_t *cfg = lookup_config(config_tree, "BindToAddress"); cfg; cfg = lookup_config_next(config_tree, cfg)) {
867 get_config_string(cfg, &address);
868 if(!add_listen_address(address, true))
872 for(config_t *cfg = lookup_config(config_tree, "ListenAddress"); cfg; cfg = lookup_config_next(config_tree, cfg)) {
874 get_config_string(cfg, &address);
875 if(!add_listen_address(address, false))
880 if(!add_listen_address(address, NULL))
884 if(!listen_sockets) {
885 logger(DEBUG_ALWAYS, LOG_ERR, "Unable to create any listening socket!");
889 /* If no Port option was specified, set myport to the port used by the first listening socket. */
891 if(!port_specified) {
893 socklen_t salen = sizeof sa;
894 if(!getsockname(listen_socket[0].udp.fd, &sa.sa, &salen)) {
896 sockaddr2str(&sa, NULL, &myport);
898 myport = xstrdup("655");
902 xasprintf(&myself->hostname, "MYSELF port %s", myport);
903 myself->connection->hostname = xstrdup(myself->hostname);
907 last_config_check = now.tv_sec;
915 bool setup_network(void) {
921 if(get_config_int(lookup_config(config_tree, "PingInterval"), &pinginterval)) {
922 if(pinginterval < 1) {
923 pinginterval = 86400;
928 if(!get_config_int(lookup_config(config_tree, "PingTimeout"), &pingtimeout))
930 if(pingtimeout < 1 || pingtimeout > pinginterval)
931 pingtimeout = pinginterval;
933 if(!get_config_int(lookup_config(config_tree, "MaxOutputBufferSize"), &maxoutbufsize))
934 maxoutbufsize = 10 * MTU;
942 /* Run tinc-up script to further initialize the tap interface */
944 char *envp[5] = {NULL};
945 xasprintf(&envp[0], "NETNAME=%s", netname ? : "");
946 xasprintf(&envp[3], "NAME=%s", myself->name);
948 execute_script("tinc-up", envp);
950 for(int i = 0; i < 4; i++)
957 close all open network connections
959 void close_network_connections(void) {
960 for(list_node_t *node = connection_list->head, *next; node; node = next) {
962 connection_t *c = node->data;
963 /* Keep control connections open until the end, so they know when we really terminated */
964 if(c->status.control)
967 terminate_connection(c, false);
971 list_delete_list(outgoing_list);
973 if(myself && myself->connection) {
974 terminate_connection(myself->connection, false);
975 free_connection(myself->connection);
978 for(int i = 0; i < listen_sockets; i++) {
979 io_del(&listen_socket[i].tcp);
980 io_del(&listen_socket[i].udp);
981 close(listen_socket[i].tcp.fd);
982 close(listen_socket[i].udp.fd);
985 char *envp[5] = {NULL};
986 xasprintf(&envp[0], "NETNAME=%s", netname ? : "");
987 xasprintf(&envp[3], "NAME=%s", myself->name);
994 execute_script("tinc-down", envp);
996 if(myport) free(myport);
998 for(int i = 0; i < 4; i++)