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.
25 #include "splay_tree.h"
28 #include "connection.h"
46 static struct event device_ev;
53 proxytype_t proxytype;
55 bool node_read_ecdsa_public_key(node_t *n) {
56 if(ecdsa_active(&n->ecdsa))
59 splay_tree_t *config_tree;
65 xasprintf(&fname, "%s" SLASH "hosts" SLASH "%s", confbase, n->name);
67 init_configuration(&config_tree);
68 if(!read_config_file(config_tree, fname))
71 /* First, check for simple ECDSAPublicKey statement */
73 if(get_config_string(lookup_config(config_tree, "ECDSAPublicKey"), &p)) {
74 result = ecdsa_set_base64_public_key(&n->ecdsa, p);
79 /* Else, check for ECDSAPublicKeyFile statement and read it */
83 if(!get_config_string(lookup_config(config_tree, "ECDSAPublicKeyFile"), &fname))
84 xasprintf(&fname, "%s" SLASH "hosts" SLASH "%s", confbase, n->name);
86 fp = fopen(fname, "r");
89 logger(DEBUG_ALWAYS, LOG_ERR, "Error reading ECDSA public key file `%s': %s", fname, strerror(errno));
93 result = ecdsa_read_pem_public_key(&n->ecdsa, fp);
97 exit_configuration(&config_tree);
102 bool read_ecdsa_public_key(connection_t *c) {
108 /* First, check for simple ECDSAPublicKey statement */
110 if(get_config_string(lookup_config(c->config_tree, "ECDSAPublicKey"), &p)) {
111 result = ecdsa_set_base64_public_key(&c->ecdsa, p);
116 /* Else, check for ECDSAPublicKeyFile statement and read it */
118 if(!get_config_string(lookup_config(c->config_tree, "ECDSAPublicKeyFile"), &fname))
119 xasprintf(&fname, "%s" SLASH "hosts" SLASH "%s", confbase, c->name);
121 fp = fopen(fname, "r");
124 logger(DEBUG_ALWAYS, LOG_ERR, "Error reading ECDSA public key file `%s': %s",
125 fname, strerror(errno));
130 result = ecdsa_read_pem_public_key(&c->ecdsa, fp);
134 logger(DEBUG_ALWAYS, LOG_ERR, "Parsing ECDSA public key file `%s' failed.", fname);
139 bool read_rsa_public_key(connection_t *c) {
145 /* First, check for simple PublicKey statement */
147 if(get_config_string(lookup_config(c->config_tree, "PublicKey"), &n)) {
148 result = rsa_set_hex_public_key(&c->rsa, 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 result = rsa_read_pem_public_key(&c->rsa, 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) {
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));
193 #if !defined(HAVE_MINGW) && !defined(HAVE_CYGWIN)
196 if(fstat(fileno(fp), &s)) {
197 logger(DEBUG_ALWAYS, LOG_ERR, "Could not stat ECDSA private key file `%s': %s'", fname, strerror(errno));
202 if(s.st_mode & ~0100700)
203 logger(DEBUG_ALWAYS, LOG_WARNING, "Warning: insecure file permissions for ECDSA private key file `%s'!", fname);
206 result = ecdsa_read_pem_private_key(&myself->connection->ecdsa, fp);
210 logger(DEBUG_ALWAYS, LOG_ERR, "Reading ECDSA private key file `%s' failed: %s", fname, strerror(errno));
215 static bool read_rsa_private_key(void) {
221 /* First, check for simple PrivateKey statement */
223 if(get_config_string(lookup_config(config_tree, "PrivateKey"), &d)) {
224 if(!get_config_string(lookup_config(config_tree, "PublicKey"), &n)) {
225 logger(DEBUG_ALWAYS, LOG_ERR, "PrivateKey used but no PublicKey found!");
229 result = rsa_set_hex_private_key(&myself->connection->rsa, n, "FFFF", d);
235 /* Else, check for PrivateKeyFile statement and read it */
237 if(!get_config_string(lookup_config(config_tree, "PrivateKeyFile"), &fname))
238 xasprintf(&fname, "%s" SLASH "rsa_key.priv", confbase);
240 fp = fopen(fname, "r");
243 logger(DEBUG_ALWAYS, LOG_ERR, "Error reading RSA private key file `%s': %s",
244 fname, strerror(errno));
249 #if !defined(HAVE_MINGW) && !defined(HAVE_CYGWIN)
252 if(fstat(fileno(fp), &s)) {
253 logger(DEBUG_ALWAYS, LOG_ERR, "Could not stat RSA private key file `%s': %s'", fname, strerror(errno));
258 if(s.st_mode & ~0100700)
259 logger(DEBUG_ALWAYS, LOG_WARNING, "Warning: insecure file permissions for RSA private key file `%s'!", fname);
262 result = rsa_read_pem_private_key(&myself->connection->rsa, fp);
266 logger(DEBUG_ALWAYS, LOG_ERR, "Reading RSA private key file `%s' failed: %s", fname, strerror(errno));
271 static struct event keyexpire_event;
273 static void keyexpire_handler(int fd, short events, void *data) {
277 void regenerate_key(void) {
278 if(timeout_initialized(&keyexpire_event)) {
279 logger(DEBUG_STATUS, LOG_INFO, "Expiring symmetric keys");
280 event_del(&keyexpire_event);
283 timeout_set(&keyexpire_event, keyexpire_handler, NULL);
286 event_add(&keyexpire_event, &(struct timeval){keylifetime, 0});
290 Read Subnets from all host config files
292 void load_all_subnets(void) {
297 splay_tree_t *config_tree;
302 xasprintf(&dname, "%s" SLASH "hosts", confbase);
303 dir = opendir(dname);
305 logger(DEBUG_ALWAYS, LOG_ERR, "Could not open %s: %s", dname, strerror(errno));
310 while((ent = readdir(dir))) {
311 if(!check_id(ent->d_name))
314 n = lookup_node(ent->d_name);
315 #ifdef _DIRENT_HAVE_D_TYPE
316 //if(ent->d_type != DT_REG)
320 xasprintf(&fname, "%s" SLASH "hosts" SLASH "%s", confbase, ent->d_name);
321 init_configuration(&config_tree);
322 read_config_options(config_tree, ent->d_name);
323 read_config_file(config_tree, fname);
328 n->name = xstrdup(ent->d_name);
332 for(cfg = lookup_config(config_tree, "Subnet"); cfg; cfg = lookup_config_next(config_tree, cfg)) {
333 if(!get_config_subnet(cfg, &s))
336 if((s2 = lookup_subnet(n, s))) {
343 exit_configuration(&config_tree);
349 char *get_name(void) {
352 get_config_string(lookup_config(config_tree, "Name"), &name);
358 char *envname = getenv(name + 1);
360 if(strcmp(name + 1, "HOST")) {
361 fprintf(stderr, "Invalid Name: environment variable %s does not exist\n", name + 1);
364 envname = alloca(32);
365 if(gethostname(envname, 32)) {
366 fprintf(stderr, "Could not get hostname: %s\n", strerror(errno));
372 name = xstrdup(envname);
373 for(char *c = name; *c; c++)
378 if(!check_id(name)) {
379 logger(DEBUG_ALWAYS, LOG_ERR, "Invalid name for myself!");
387 bool setup_myself_reloadable(void) {
394 get_config_string(lookup_config(config_tree, "Proxy"), &proxy);
396 if((space = strchr(proxy, ' ')))
399 if(!strcasecmp(proxy, "none")) {
400 proxytype = PROXY_NONE;
401 } else if(!strcasecmp(proxy, "socks4")) {
402 proxytype = PROXY_SOCKS4;
403 } else if(!strcasecmp(proxy, "socks4a")) {
404 proxytype = PROXY_SOCKS4A;
405 } else if(!strcasecmp(proxy, "socks5")) {
406 proxytype = PROXY_SOCKS5;
407 } else if(!strcasecmp(proxy, "http")) {
408 proxytype = PROXY_HTTP;
409 } else if(!strcasecmp(proxy, "exec")) {
410 proxytype = PROXY_EXEC;
412 logger(DEBUG_ALWAYS, LOG_ERR, "Unknown proxy type %s!", proxy);
422 if(!space || !*space) {
423 logger(DEBUG_ALWAYS, LOG_ERR, "Argument expected for proxy type exec!");
426 proxyhost = xstrdup(space);
434 if(space && (space = strchr(space, ' ')))
435 *space++ = 0, proxyport = space;
436 if(space && (space = strchr(space, ' ')))
437 *space++ = 0, proxyuser = space;
438 if(space && (space = strchr(space, ' ')))
439 *space++ = 0, proxypass = space;
440 if(!proxyhost || !*proxyhost || !proxyport || !*proxyport) {
441 logger(DEBUG_ALWAYS, LOG_ERR, "Host and port argument expected for proxy!");
444 proxyhost = xstrdup(proxyhost);
445 proxyport = xstrdup(proxyport);
446 if(proxyuser && *proxyuser)
447 proxyuser = xstrdup(proxyuser);
448 if(proxypass && *proxypass)
449 proxypass = xstrdup(proxypass);
456 if(get_config_bool(lookup_config(config_tree, "IndirectData"), &choice) && choice)
457 myself->options |= OPTION_INDIRECT;
459 if(get_config_bool(lookup_config(config_tree, "TCPOnly"), &choice) && choice)
460 myself->options |= OPTION_TCPONLY;
462 if(myself->options & OPTION_TCPONLY)
463 myself->options |= OPTION_INDIRECT;
465 get_config_bool(lookup_config(config_tree, "DirectOnly"), &directonly);
466 get_config_bool(lookup_config(config_tree, "LocalDiscovery"), &localdiscovery);
468 if(get_config_string(lookup_config(config_tree, "Mode"), &mode)) {
469 if(!strcasecmp(mode, "router"))
470 routing_mode = RMODE_ROUTER;
471 else if(!strcasecmp(mode, "switch"))
472 routing_mode = RMODE_SWITCH;
473 else if(!strcasecmp(mode, "hub"))
474 routing_mode = RMODE_HUB;
476 logger(DEBUG_ALWAYS, LOG_ERR, "Invalid routing mode!");
482 if(get_config_string(lookup_config(config_tree, "Forwarding"), &mode)) {
483 if(!strcasecmp(mode, "off"))
484 forwarding_mode = FMODE_OFF;
485 else if(!strcasecmp(mode, "internal"))
486 forwarding_mode = FMODE_INTERNAL;
487 else if(!strcasecmp(mode, "kernel"))
488 forwarding_mode = FMODE_KERNEL;
490 logger(DEBUG_ALWAYS, LOG_ERR, "Invalid forwarding mode!");
497 get_config_bool(lookup_config(config_tree, "PMTUDiscovery"), &choice);
499 myself->options |= OPTION_PMTU_DISCOVERY;
502 get_config_bool(lookup_config(config_tree, "ClampMSS"), &choice);
504 myself->options |= OPTION_CLAMP_MSS;
506 get_config_bool(lookup_config(config_tree, "PriorityInheritance"), &priorityinheritance);
507 get_config_bool(lookup_config(config_tree, "DecrementTTL"), &decrement_ttl);
508 if(get_config_string(lookup_config(config_tree, "Broadcast"), &mode)) {
509 if(!strcasecmp(mode, "no"))
510 broadcast_mode = BMODE_NONE;
511 else if(!strcasecmp(mode, "yes") || !strcasecmp(mode, "mst"))
512 broadcast_mode = BMODE_MST;
513 else if(!strcasecmp(mode, "direct"))
514 broadcast_mode = BMODE_DIRECT;
516 logger(DEBUG_ALWAYS, LOG_ERR, "Invalid broadcast mode!");
522 #if !defined(SOL_IP) || !defined(IP_TOS)
523 if(priorityinheritance)
524 logger(DEBUG_ALWAYS, LOG_WARNING, "%s not supported on this platform", "PriorityInheritance");
527 if(!get_config_int(lookup_config(config_tree, "MACExpire"), &macexpire))
530 if(get_config_int(lookup_config(config_tree, "MaxTimeout"), &maxtimeout)) {
531 if(maxtimeout <= 0) {
532 logger(DEBUG_ALWAYS, LOG_ERR, "Bogus maximum timeout!");
538 if(get_config_string(lookup_config(config_tree, "AddressFamily"), &afname)) {
539 if(!strcasecmp(afname, "IPv4"))
540 addressfamily = AF_INET;
541 else if(!strcasecmp(afname, "IPv6"))
542 addressfamily = AF_INET6;
543 else if(!strcasecmp(afname, "any"))
544 addressfamily = AF_UNSPEC;
546 logger(DEBUG_ALWAYS, LOG_ERR, "Invalid address family!");
552 get_config_bool(lookup_config(config_tree, "Hostnames"), &hostnames);
554 if(!get_config_int(lookup_config(config_tree, "KeyExpire"), &keylifetime))
561 Configure node_t myself and set up the local sockets (listen only)
563 static bool setup_myself(void) {
566 char *name, *hostname, *cipher, *digest, *type;
568 char *address = NULL;
570 struct addrinfo *ai, *aip, hint = {0};
575 myself->connection = new_connection();
577 if(!get_config_string(lookup_config(config_tree, "Port"), &myport))
578 myport = xstrdup("655");
580 xasprintf(&myself->hostname, "MYSELF port %s", myport);
581 myself->connection->hostname = xstrdup(myself->hostname);
583 myself->connection->options = 0;
584 myself->connection->protocol_major = PROT_MAJOR;
585 myself->connection->protocol_minor = PROT_MINOR;
587 myself->options |= PROT_MINOR << 24;
589 if(!(name = get_name())) {
590 logger(DEBUG_ALWAYS, LOG_ERR, "Name for tinc daemon required!");
595 myself->connection->name = xstrdup(name);
596 xasprintf(&fname, "%s" SLASH "hosts" SLASH "%s", confbase, name);
597 read_config_options(config_tree, name);
598 read_config_file(config_tree, fname);
601 get_config_bool(lookup_config(config_tree, "ExperimentalProtocol"), &experimental);
603 if(experimental && !read_ecdsa_private_key())
606 if(!read_rsa_private_key())
610 struct addrinfo *ai = str2addrinfo("localhost", myport, SOCK_DGRAM);
612 if(!ai || !ai->ai_addr)
615 memcpy(&sa, ai->ai_addr, ai->ai_addrlen);
616 sockaddr2str(&sa, NULL, &myport);
619 /* Read in all the subnets specified in the host configuration file */
621 cfg = lookup_config(config_tree, "Subnet");
624 if(!get_config_subnet(cfg, &subnet))
627 subnet_add(myself, subnet);
629 cfg = lookup_config_next(config_tree, cfg);
632 /* Check some options */
634 if(!setup_myself_reloadable())
637 get_config_bool(lookup_config(config_tree, "StrictSubnets"), &strictsubnets);
638 get_config_bool(lookup_config(config_tree, "TunnelServer"), &tunnelserver);
639 strictsubnets |= tunnelserver;
643 if(get_config_int(lookup_config(config_tree, "UDPRcvBuf"), &udp_rcvbuf)) {
644 if(udp_rcvbuf <= 0) {
645 logger(DEBUG_ALWAYS, LOG_ERR, "UDPRcvBuf cannot be negative!");
650 if(get_config_int(lookup_config(config_tree, "UDPSndBuf"), &udp_sndbuf)) {
651 if(udp_sndbuf <= 0) {
652 logger(DEBUG_ALWAYS, LOG_ERR, "UDPSndBuf cannot be negative!");
657 if(get_config_int(lookup_config(config_tree, "ReplayWindow"), &replaywin_int)) {
658 if(replaywin_int < 0) {
659 logger(DEBUG_ALWAYS, LOG_ERR, "ReplayWindow cannot be negative!");
662 replaywin = (unsigned)replaywin_int;
665 /* Generate packet encryption key */
667 if(!get_config_string(lookup_config(config_tree, "Cipher"), &cipher))
668 cipher = xstrdup("blowfish");
670 if(!cipher_open_by_name(&myself->incipher, cipher)) {
671 logger(DEBUG_ALWAYS, LOG_ERR, "Unrecognized cipher type!");
677 /* Check if we want to use message authentication codes... */
680 get_config_int(lookup_config(config_tree, "MACLength"), &maclength);
683 logger(DEBUG_ALWAYS, LOG_ERR, "Bogus MAC length!");
687 if(!get_config_string(lookup_config(config_tree, "Digest"), &digest))
688 digest = xstrdup("sha1");
690 if(!digest_open_by_name(&myself->indigest, digest, maclength)) {
691 logger(DEBUG_ALWAYS, LOG_ERR, "Unrecognized digest type!");
697 if(get_config_int(lookup_config(config_tree, "Compression"), &myself->incompression)) {
698 if(myself->incompression < 0 || myself->incompression > 11) {
699 logger(DEBUG_ALWAYS, LOG_ERR, "Bogus compression level!");
703 myself->incompression = 0;
705 myself->connection->outcompression = 0;
709 myself->nexthop = myself;
710 myself->via = myself;
711 myself->status.reachable = true;
712 myself->last_state_change = time(NULL);
713 myself->status.sptps = experimental;
725 if(get_config_string(lookup_config(config_tree, "DeviceType"), &type)) {
726 if(!strcasecmp(type, "dummy"))
727 devops = dummy_devops;
728 else if(!strcasecmp(type, "raw_socket"))
729 devops = raw_socket_devops;
730 else if(!strcasecmp(type, "multicast"))
731 devops = multicast_devops;
733 else if(!strcasecmp(type, "uml"))
737 else if(!strcasecmp(type, "vde"))
746 event_set(&device_ev, device_fd, EV_READ|EV_PERSIST, handle_device_data, NULL);
748 if (event_add(&device_ev, NULL) < 0) {
749 logger(DEBUG_ALWAYS, LOG_ERR, "event_add failed: %s", strerror(errno));
755 /* Run tinc-up script to further initialize the tap interface */
756 xasprintf(&envp[0], "NETNAME=%s", netname ? : "");
757 xasprintf(&envp[1], "DEVICE=%s", device ? : "");
758 xasprintf(&envp[2], "INTERFACE=%s", iface ? : "");
759 xasprintf(&envp[3], "NAME=%s", myself->name);
762 execute_script("tinc-up", envp);
764 for(i = 0; i < 4; i++)
767 /* Run subnet-up scripts for our own subnets */
769 subnet_update(myself, NULL, true);
773 if(!do_detach && getenv("LISTEN_FDS")) {
777 listen_sockets = atoi(getenv("LISTEN_FDS"));
779 unsetenv("LISTEN_FDS");
782 if(listen_sockets > MAXSOCKETS) {
783 logger(DEBUG_ALWAYS, LOG_ERR, "Too many listening sockets");
787 for(i = 0; i < listen_sockets; i++) {
789 if(getsockname(i + 3, &sa.sa, &salen) < 0) {
790 logger(DEBUG_ALWAYS, LOG_ERR, "Could not get address of listen fd %d: %s", i + 3, sockstrerror(errno));
794 listen_socket[i].tcp = i + 3;
797 fcntl(i + 3, F_SETFD, FD_CLOEXEC);
800 listen_socket[i].udp = setup_vpn_in_socket(&sa);
801 if(listen_socket[i].udp < 0)
804 event_set(&listen_socket[i].ev_tcp, listen_socket[i].tcp, EV_READ|EV_PERSIST, handle_new_meta_connection, NULL);
805 if(event_add(&listen_socket[i].ev_tcp, NULL) < 0) {
806 logger(DEBUG_ALWAYS, LOG_ERR, "event_add failed: %s", strerror(errno));
810 event_set(&listen_socket[i].ev_udp, listen_socket[i].udp, EV_READ|EV_PERSIST, handle_incoming_vpn_data, (void *)(intptr_t)listen_sockets);
811 if(event_add(&listen_socket[listen_sockets].ev_udp, NULL) < 0) {
812 logger(DEBUG_ALWAYS, LOG_ERR, "event_add failed: %s", strerror(errno));
816 if(debug_level >= DEBUG_CONNECTIONS) {
817 hostname = sockaddr2hostname(&sa);
818 logger(DEBUG_CONNECTIONS, LOG_NOTICE, "Listening on %s", hostname);
822 memcpy(&listen_socket[i].sa, &sa, salen);
826 cfg = lookup_config(config_tree, "BindToAddress");
829 get_config_string(cfg, &address);
831 cfg = lookup_config_next(config_tree, cfg);
836 char *space = strchr(address, ' ');
842 if(!strcmp(address, "*"))
846 hint.ai_family = addressfamily;
847 hint.ai_socktype = SOCK_STREAM;
848 hint.ai_protocol = IPPROTO_TCP;
849 hint.ai_flags = AI_PASSIVE;
851 err = getaddrinfo(address && *address ? address : NULL, port, &hint, &ai);
855 logger(DEBUG_ALWAYS, LOG_ERR, "System call `%s' failed: %s", "getaddrinfo",
860 for(aip = ai; aip; aip = aip->ai_next) {
861 if(listen_sockets >= MAXSOCKETS) {
862 logger(DEBUG_ALWAYS, LOG_ERR, "Too many listening sockets");
866 listen_socket[listen_sockets].tcp =
867 setup_listen_socket((sockaddr_t *) aip->ai_addr);
869 if(listen_socket[listen_sockets].tcp < 0)
872 listen_socket[listen_sockets].udp =
873 setup_vpn_in_socket((sockaddr_t *) aip->ai_addr);
875 if(listen_socket[listen_sockets].udp < 0) {
876 close(listen_socket[listen_sockets].tcp);
880 event_set(&listen_socket[listen_sockets].ev_tcp,
881 listen_socket[listen_sockets].tcp,
883 handle_new_meta_connection, NULL);
884 if(event_add(&listen_socket[listen_sockets].ev_tcp, NULL) < 0) {
885 logger(DEBUG_ALWAYS, LOG_ERR, "event_add failed: %s", strerror(errno));
889 event_set(&listen_socket[listen_sockets].ev_udp,
890 listen_socket[listen_sockets].udp,
892 handle_incoming_vpn_data, (void *)(intptr_t)listen_sockets);
893 if(event_add(&listen_socket[listen_sockets].ev_udp, NULL) < 0) {
894 logger(DEBUG_ALWAYS, LOG_ERR, "event_add failed: %s", strerror(errno));
898 if(debug_level >= DEBUG_CONNECTIONS) {
899 hostname = sockaddr2hostname((sockaddr_t *) aip->ai_addr);
900 logger(DEBUG_CONNECTIONS, LOG_NOTICE, "Listening on %s", hostname);
904 memcpy(&listen_socket[listen_sockets].sa, aip->ai_addr, aip->ai_addrlen);
913 logger(DEBUG_ALWAYS, LOG_NOTICE, "Ready");
915 logger(DEBUG_ALWAYS, LOG_ERR, "Unable to create any listening socket!");
919 last_config_check = time(NULL);
927 bool setup_network(void) {
934 if(get_config_int(lookup_config(config_tree, "PingInterval"), &pinginterval)) {
935 if(pinginterval < 1) {
936 pinginterval = 86400;
941 if(!get_config_int(lookup_config(config_tree, "PingTimeout"), &pingtimeout))
943 if(pingtimeout < 1 || pingtimeout > pinginterval)
944 pingtimeout = pinginterval;
946 if(!get_config_int(lookup_config(config_tree, "MaxOutputBufferSize"), &maxoutbufsize))
947 maxoutbufsize = 10 * MTU;
956 close all open network connections
958 void close_network_connections(void) {
959 splay_node_t *node, *next;
964 for(node = connection_tree->head; node; node = next) {
968 terminate_connection(c, false);
971 list_delete_list(outgoing_list);
973 if(myself && myself->connection) {
974 subnet_update(myself, NULL, false);
975 terminate_connection(myself->connection, false);
976 free_connection(myself->connection);
979 for(i = 0; i < listen_sockets; i++) {
980 event_del(&listen_socket[i].ev_tcp);
981 event_del(&listen_socket[i].ev_udp);
982 close(listen_socket[i].tcp);
983 close(listen_socket[i].udp);
986 xasprintf(&envp[0], "NETNAME=%s", netname ? : "");
987 xasprintf(&envp[1], "DEVICE=%s", device ? : "");
988 xasprintf(&envp[2], "INTERFACE=%s", iface ? : "");
989 xasprintf(&envp[3], "NAME=%s", myself->name);
998 execute_script("tinc-down", envp);
1000 if(myport) free(myport);
1002 for(i = 0; i < 4; i++)