2 net.c -- most of the network code
3 Copyright (C) 1998-2001 Ivo Timmermans <itimmermans@bigfoot.com>,
4 2000,2001 Guus Sliepen <guus@sliepen.warande.net>
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 $Id: net.c,v 1.35.4.137 2001/10/27 12:13:17 guus Exp $
28 #include <netinet/in.h>
30 #include <netinet/ip.h>
31 #include <netinet/tcp.h>
36 #include <sys/signal.h>
38 #include <sys/types.h>
41 #include <sys/ioctl.h>
42 /* SunOS really wants sys/socket.h BEFORE net/if.h,
43 and FreeBSD wants these lines below the rest. */
44 #include <arpa/inet.h>
45 #include <sys/socket.h>
48 #include <openssl/rand.h>
49 #include <openssl/evp.h>
50 #include <openssl/pem.h>
52 #ifndef HAVE_RAND_PSEUDO_BYTES
53 #define RAND_pseudo_bytes RAND_bytes
62 #include "connection.h"
75 int seconds_till_retry = 5;
84 void receive_udppacket(node_t *n, vpn_packet_t *inpkt)
90 /* Decrypt the packet */
92 EVP_DecryptInit(&ctx, myself->cipher, myself->key, myself->key + myself->cipher->key_len);
93 EVP_DecryptUpdate(&ctx, outpkt.salt, &outlen, inpkt->salt, inpkt->len);
94 EVP_DecryptFinal(&ctx, outpkt.salt + outlen, &outpad);
96 outpkt.len = outlen - sizeof(outpkt.salt);
98 receive_packet(n, &outpkt);
102 void receive_tcppacket(connection_t *c, char *buffer, int len)
107 memcpy(outpkt.data, buffer, len);
109 receive_packet(c->node, &outpkt);
113 void receive_packet(node_t *n, vpn_packet_t *packet)
116 if(debug_lvl >= DEBUG_TRAFFIC)
117 syslog(LOG_DEBUG, _("Received packet of %d bytes from %s (%s)"), packet->len, n->name, n->hostname);
119 route_incoming(n, packet);
123 void send_udppacket(node_t *n, vpn_packet_t *inpkt)
128 struct sockaddr_in to;
129 socklen_t tolen = sizeof(to);
132 if(!n->status.validkey)
134 if(debug_lvl >= DEBUG_TRAFFIC)
135 syslog(LOG_INFO, _("No valid key known yet for %s (%s), queueing packet"),
136 n->name, n->hostname);
138 /* Since packet is on the stack of handle_tap_input(),
139 we have to make a copy of it first. */
141 copy = xmalloc(sizeof(vpn_packet_t));
142 memcpy(copy, inpkt, sizeof(vpn_packet_t));
144 list_insert_tail(n->queue, copy);
146 if(!n->status.waitingforkey)
147 send_req_key(n->nexthop->connection, myself, n);
151 /* Encrypt the packet. */
153 RAND_pseudo_bytes(inpkt->salt, sizeof(inpkt->salt));
155 EVP_EncryptInit(&ctx, n->cipher, n->key, n->key + n->cipher->key_len);
156 EVP_EncryptUpdate(&ctx, outpkt.salt, &outlen, inpkt->salt, inpkt->len + sizeof(inpkt->salt));
157 EVP_EncryptFinal(&ctx, outpkt.salt + outlen, &outpad);
160 to.sin_family = AF_INET;
161 to.sin_addr.s_addr = htonl(n->address);
162 to.sin_port = htons(n->port);
164 if((sendto(socket, (char *) outpkt.salt, outlen, 0, (const struct sockaddr *)&to, tolen)) < 0)
166 syslog(LOG_ERR, _("Error sending packet to %s (%s): %m"),
167 n->name, n->hostname);
174 send a packet to the given vpn ip.
176 void send_packet(node_t *n, vpn_packet_t *packet)
179 if(debug_lvl >= DEBUG_TRAFFIC)
180 syslog(LOG_ERR, _("Sending packet of %d bytes to %s (%s)"),
181 packet->len, n->name, n->hostname);
185 if(debug_lvl >= DEBUG_TRAFFIC)
187 syslog(LOG_NOTICE, _("Packet is looping back to us!"));
193 if(!n->status.active)
195 if(debug_lvl >= DEBUG_TRAFFIC)
196 syslog(LOG_INFO, _("%s (%s) is not active, dropping packet"),
197 n->name, n->hostname);
207 if(via != n && debug_lvl >= DEBUG_TRAFFIC)
208 syslog(LOG_ERR, _("Sending packet to %s via %s (%s)"),
209 n->name, via->name, via->hostname);
211 if((myself->options | via->options) & OPTION_TCPONLY)
213 if(send_tcppacket(via->connection, packet))
214 terminate_connection(via->connection, 1);
217 send_udppacket(via, packet);
221 /* Broadcast a packet to all active direct connections */
223 void broadcast_packet(node_t *from, vpn_packet_t *packet)
228 if(debug_lvl >= DEBUG_TRAFFIC)
229 syslog(LOG_INFO, _("Broadcasting packet of %d bytes from %s (%s)"),
230 packet->len, from->name, from->hostname);
232 for(node = connection_tree->head; node; node = node->next)
234 c = (connection_t *)node->data;
235 if(c->status.active && c != from->nexthop->connection)
236 send_packet(c->node, packet);
241 void flush_queue(node_t *n)
243 list_node_t *node, *next;
245 if(debug_lvl >= DEBUG_TRAFFIC)
246 syslog(LOG_INFO, _("Flushing queue for %s (%s)"), n->name, n->hostname);
248 for(node = n->queue->head; node; node = next)
251 send_udppacket(n, (vpn_packet_t *)node->data);
252 list_delete_node(n->queue, node);
259 int setup_listen_socket(int port)
262 struct sockaddr_in a;
268 if((nfd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0)
270 syslog(LOG_ERR, _("Creating metasocket failed: %m"));
274 flags = fcntl(nfd, F_GETFL);
275 if(fcntl(nfd, F_SETFL, flags | O_NONBLOCK) < 0)
278 syslog(LOG_ERR, _("System call `%s' failed: %m"),
283 /* Optimize TCP settings */
286 setsockopt(nfd, SOL_SOCKET, SO_REUSEADDR, &option, sizeof(option));
287 setsockopt(nfd, SOL_SOCKET, SO_KEEPALIVE, &option, sizeof(option));
289 setsockopt(nfd, SOL_TCP, TCP_NODELAY, &option, sizeof(option));
291 option = IPTOS_LOWDELAY;
292 setsockopt(nfd, SOL_IP, IP_TOS, &option, sizeof(option));
294 if(get_config_string(lookup_config(config_tree, "BindToInterface"), &interface))
295 if(setsockopt(nfd, SOL_SOCKET, SO_BINDTODEVICE, interface, strlen(interface)))
298 syslog(LOG_ERR, _("Can't bind to interface %s: %m"), interface);
303 memset(&a, 0, sizeof(a));
304 a.sin_family = AF_INET;
305 a.sin_addr.s_addr = htonl(INADDR_ANY);
306 a.sin_port = htons(port);
308 if(get_config_string(lookup_config(config_tree, "BindToAddress"), &address))
310 ipmask = strtoip(address);
313 a.sin_addr.s_addr = htonl(ipmask->address);
318 if(bind(nfd, (struct sockaddr *)&a, sizeof(struct sockaddr)))
321 syslog(LOG_ERR, _("Can't bind to port %hd/tcp: %m"), port);
328 syslog(LOG_ERR, _("System call `%s' failed: %m"),
336 int setup_vpn_in_socket(int port)
339 struct sockaddr_in a;
342 if((nfd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0)
345 syslog(LOG_ERR, _("Creating socket failed: %m"));
349 setsockopt(nfd, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one));
351 flags = fcntl(nfd, F_GETFL);
352 if(fcntl(nfd, F_SETFL, flags | O_NONBLOCK) < 0)
355 syslog(LOG_ERR, _("System call `%s' failed: %m"),
360 memset(&a, 0, sizeof(a));
361 a.sin_family = AF_INET;
362 a.sin_port = htons(port);
363 a.sin_addr.s_addr = htonl(INADDR_ANY);
365 if(bind(nfd, (struct sockaddr *)&a, sizeof(struct sockaddr)))
368 syslog(LOG_ERR, _("Can't bind to port %hd/udp: %m"), port);
375 int setup_outgoing_socket(connection_t *c)
378 struct sockaddr_in a;
381 if(debug_lvl >= DEBUG_CONNECTIONS)
382 syslog(LOG_INFO, _("Trying to connect to %s (%s)"), c->name, c->hostname);
384 c->socket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
388 syslog(LOG_ERR, _("Creating socket for %s port %d failed: %m"),
389 c->hostname, c->port);
393 /* Bind first to get a fix on our source port???
395 a.sin_family = AF_INET;
396 a.sin_port = htons(0);
397 a.sin_addr.s_addr = htonl(INADDR_ANY);
399 if(bind(c->socket, (struct sockaddr *)&a, sizeof(struct sockaddr)))
402 syslog(LOG_ERR, _("System call `%s' failed: %m"), "bind");
408 /* Optimize TCP settings?
411 setsockopt(c->socket, SOL_SOCKET, SO_KEEPALIVE, &option, sizeof(option));
413 setsockopt(c->socket, SOL_TCP, TCP_NODELAY, &option, sizeof(option));
415 option = IPTOS_LOWDELAY;
416 setsockopt(c->socket, SOL_IP, IP_TOS, &option, sizeof(option));
423 a.sin_family = AF_INET;
424 a.sin_port = htons(c->port);
425 a.sin_addr.s_addr = htonl(c->address);
427 if(connect(c->socket, (struct sockaddr *)&a, sizeof(a)) == -1)
430 syslog(LOG_ERR, _("%s port %hd: %m"), c->hostname, c->port);
434 flags = fcntl(c->socket, F_GETFL);
436 if(fcntl(c->socket, F_SETFL, flags | O_NONBLOCK) < 0)
439 syslog(LOG_ERR, _("fcntl for %s port %d: %m"),
440 c->hostname, c->port);
444 if(debug_lvl >= DEBUG_CONNECTIONS)
445 syslog(LOG_INFO, _("Connected to %s port %hd"),
446 c->hostname, c->port);
451 int setup_outgoing_connection(char *name)
456 c = new_connection();
457 c->name = xstrdup(name);
459 read_connection_config(c);
461 if(!get_config_string(lookup_config(c->config_tree, "Address"), &c->hostname))
463 syslog(LOG_ERR, _("No address specified for %s"), c->name);
468 if(!get_config_port(lookup_config(c->config_tree, "Port"), &c->port))
470 syslog(LOG_ERR, _("No port specified for %s"), c->name);
475 if(!(h = gethostbyname(c->hostname)))
477 syslog(LOG_ERR, _("Error looking up `%s': %m"), c->hostname);
482 c->address = ntohl(*((ipv4_t*)(h->h_addr_list[0])));
483 c->hostname = hostlookup(htonl(c->address));
485 if(setup_outgoing_socket(c) < 0)
487 syslog(LOG_ERR, _("Could not set up a meta connection to %s (%s)"),
488 c->name, c->hostname);
493 c->status.outgoing = 1;
494 c->last_ping_time = time(NULL);
503 int read_rsa_public_key(connection_t *c)
511 c->rsa_key = RSA_new();
513 /* First, check for simple PublicKey statement */
515 if(get_config_string(lookup_config(c->config_tree, "PublicKey"), &key))
517 BN_hex2bn(&c->rsa_key->n, key);
518 BN_hex2bn(&c->rsa_key->e, "FFFF");
522 /* Else, check for PublicKeyFile statement and read it */
524 if(get_config_string(lookup_config(c->config_tree, "PublicKeyFile"), &fname))
526 if(is_safe_path(fname))
528 if((fp = fopen(fname, "r")) == NULL)
530 syslog(LOG_ERR, _("Error reading RSA public key file `%s': %m"),
534 result = PEM_read_RSAPublicKey(fp, &c->rsa_key, NULL, NULL);
538 syslog(LOG_ERR, _("Reading RSA public key file `%s' failed: %m"),
548 /* Else, check if a harnessed public key is in the config file */
552 asprintf(&fname, "%s/hosts/%s", confbase, c->name);
553 if((fp = fopen(fname, "r")))
555 result = PEM_read_RSAPublicKey(fp, &c->rsa_key, NULL, NULL);
566 syslog(LOG_ERR, _("No public key for %s specified!"), c->name);
571 int read_rsa_private_key(void)
577 if(!myself->connection->rsa_key)
578 myself->connection->rsa_key = RSA_new();
580 if(get_config_string(lookup_config(config_tree, "PrivateKey"), &key))
582 BN_hex2bn(&myself->connection->rsa_key->d, key);
583 BN_hex2bn(&myself->connection->rsa_key->e, "FFFF");
585 else if(get_config_string(lookup_config(config_tree, "PrivateKeyFile"), &fname))
587 if((fp = fopen(fname, "r")) == NULL)
589 syslog(LOG_ERR, _("Error reading RSA private key file `%s': %m"),
593 result = PEM_read_RSAPrivateKey(fp, &myself->connection->rsa_key, NULL, NULL);
597 syslog(LOG_ERR, _("Reading RSA private key file `%s' failed: %m"),
604 syslog(LOG_ERR, _("No private key for tinc daemon specified!"));
612 Configure node_t myself and set up the local sockets (listen only)
614 int setup_myself(void)
622 myself->connection = new_connection();
624 asprintf(&myself->hostname, _("MYSELF"));
625 asprintf(&myself->connection->hostname, _("MYSELF"));
627 myself->connection->options = 0;
628 myself->connection->protocol_version = PROT_CURRENT;
630 if(!get_config_string(lookup_config(config_tree, "Name"), &name)) /* Not acceptable */
632 syslog(LOG_ERR, _("Name for tinc daemon required!"));
638 syslog(LOG_ERR, _("Invalid name for myself!"));
644 myself->connection->name = xstrdup(name);
647 if(read_rsa_private_key())
650 if(read_connection_config(myself->connection))
652 syslog(LOG_ERR, _("Cannot open host configuration file for myself!"));
656 if(read_rsa_public_key(myself->connection))
661 if(RSA_check_key(rsa_key) != 1)
663 syslog(LOG_ERR, _("Invalid public/private keypair!"));
667 if(!get_config_port(lookup_config(myself->connection->config_tree, "Port"), &myself->connection->port))
670 /* Read in all the subnets specified in the host configuration file */
672 cfg = lookup_config(myself->connection->config_tree, "Subnet");
676 if(!get_config_subnet(cfg, &subnet))
679 subnet_add(myself, subnet);
681 cfg = lookup_config_next(myself->connection->config_tree, cfg);
685 /* Check some options */
687 if(get_config_bool(lookup_config(config_tree, "IndirectData"), &choice))
689 myself->options |= OPTION_INDIRECT;
691 if(get_config_bool(lookup_config(config_tree, "TCPOnly"), &choice))
693 myself->options |= OPTION_TCPONLY;
695 if(get_config_bool(lookup_config(myself->connection->config_tree, "IndirectData"), &choice))
697 myself->options |= OPTION_INDIRECT;
699 if(get_config_bool(lookup_config(myself->connection->config_tree, "TCPOnly"), &choice))
701 myself->options |= OPTION_TCPONLY;
703 if(myself->options & OPTION_TCPONLY)
704 myself->options |= OPTION_INDIRECT;
706 if(get_config_string(lookup_config(myself->connection->config_tree, "Mode"), &mode))
708 if(!strcasecmp(mode, "router"))
709 routing_mode = RMODE_ROUTER;
710 else if (!strcasecmp(mode, "switch"))
711 routing_mode = RMODE_SWITCH;
712 else if (!strcasecmp(mode, "hub"))
713 routing_mode = RMODE_HUB;
716 syslog(LOG_ERR, _("Invalid routing mode!"));
721 routing_mode = RMODE_ROUTER;
726 if((tcp_socket = setup_listen_socket(myself->port)) < 0)
728 syslog(LOG_ERR, _("Unable to set up a listening TCP socket!"));
732 if((udp_socket = setup_vpn_in_socket(myself->port)) < 0)
734 syslog(LOG_ERR, _("Unable to set up a listening UDP socket!"));
738 /* Generate packet encryption key */
740 myself->cipher = EVP_bf_cbc();
742 myself->keylength = myself->cipher->key_len + myself->cipher->iv_len;
744 myself->key = (char *)xmalloc(myself->keylength);
745 RAND_pseudo_bytes(myself->key, myself->keylength);
747 if(!get_config_int(lookup_config(myself->connection->config_tree, "KeyExpire"), &keylifetime))
750 keyexpires = time(NULL) + keylifetime;
754 myself->nexthop = myself;
755 myself->via = myself;
756 myself->status.active = 1;
759 syslog(LOG_NOTICE, _("Ready: listening on port %hd"), myself->port);
765 setup all initial network connections
767 int setup_network_connections(void)
773 if(get_config_int(lookup_config(myself->connection->config_tree, "PingTimeout"), &timeout))
783 if(setup_device() < 0)
786 /* Run tinc-up script to further initialize the tap interface */
787 execute_script("tinc-up");
789 if(setup_myself() < 0)
792 signal(SIGALRM, try_outgoing_connections);
799 close all open network connections
801 void close_network_connections(void)
803 avl_node_t *node, *next;
806 for(node = connection_tree->head; node; node = next)
809 c = (connection_t *)node->data;
810 c->status.outgoing = 0;
811 terminate_connection(c, 0);
814 // terminate_connection(myself, 0);
818 execute_script("tinc-down");
826 handle an incoming tcp connect call and open
829 connection_t *create_new_connection(int sfd)
832 struct sockaddr_in ci;
833 int len = sizeof(ci);
835 c = new_connection();
837 if(getpeername(sfd, (struct sockaddr *) &ci, (socklen_t *) &len) < 0)
839 syslog(LOG_ERR, _("System call `%s' failed: %m"),
845 c->address = ntohl(ci.sin_addr.s_addr);
846 c->hostname = hostlookup(ci.sin_addr.s_addr);
847 c->port = htons(ci.sin_port); /* This one will be overwritten later */
849 c->last_ping_time = time(NULL);
851 if(debug_lvl >= DEBUG_CONNECTIONS)
852 syslog(LOG_NOTICE, _("Connection from %s port %d"),
853 c->hostname, htons(ci.sin_port));
855 c->allow_request = ID;
861 put all file descriptors in an fd_set array
863 void build_fdset(fd_set *fs)
870 for(node = connection_tree->head; node; node = node->next)
872 c = (connection_t *)node->data;
873 FD_SET(c->socket, fs);
876 FD_SET(tcp_socket, fs);
877 FD_SET(udp_socket, fs);
878 FD_SET(device_fd, fs);
883 receive incoming data from the listening
884 udp socket and write it to the ethertap
885 device after being decrypted
887 void handle_incoming_vpn_data(void)
890 int x, l = sizeof(x);
891 struct sockaddr_in from;
892 socklen_t fromlen = sizeof(from);
895 if(getsockopt(udp_socket, SOL_SOCKET, SO_ERROR, &x, &l) < 0)
897 syslog(LOG_ERR, _("This is a bug: %s:%d: %d:%m"),
898 __FILE__, __LINE__, udp_socket);
903 syslog(LOG_ERR, _("Incoming data socket error: %s"), strerror(x));
907 if((pkt.len = recvfrom(udp_socket, (char *) pkt.salt, MTU, 0, (struct sockaddr *)&from, &fromlen)) <= 0)
909 syslog(LOG_ERR, _("Receiving packet failed: %m"));
913 n = lookup_node_udp(ntohl(from.sin_addr.s_addr), ntohs(from.sin_port));
917 syslog(LOG_WARNING, _("Received UDP packets on port %hd from unknown source %x:%hd"), myself->port, ntohl(from.sin_addr.s_addr), ntohs(from.sin_port));
922 n->connection->last_ping_time = time(NULL);
924 receive_udppacket(n, &pkt);
929 Terminate a connection:
931 - Remove associated hosts and subnets
932 - Deactivate the host
933 - Since it might still be referenced, put it on the prune list.
934 - If report == 1, then send DEL_HOST messages to the other tinc daemons.
936 void terminate_connection(connection_t *c, int report)
938 /* Needs a serious rewrite. */
942 Check if the other end is active.
943 If we have sent packets, but didn't receive any,
944 then possibly the other end is dead. We send a
945 PING request over the meta connection. If the other
946 end does not reply in time, we consider them dead
947 and close the connection.
949 void check_dead_connections(void)
952 avl_node_t *node, *next;
957 for(node = connection_tree->head; node; node = next)
960 c = (connection_t *)node->data;
961 if(c->last_ping_time + timeout < now)
967 if(debug_lvl >= DEBUG_PROTOCOL)
968 syslog(LOG_INFO, _("%s (%s) didn't respond to PING"),
969 c->name, c->hostname);
970 c->status.timeout = 1;
971 terminate_connection(c, 1);
980 if(debug_lvl >= DEBUG_CONNECTIONS)
981 syslog(LOG_WARNING, _("Timeout from %s (%s) during authentication"),
982 c->name, c->hostname);
983 terminate_connection(c, 0);
991 accept a new tcp connect and create a
994 int handle_new_meta_connection()
997 struct sockaddr client;
998 int fd, len = sizeof(client);
1000 if((fd = accept(tcp_socket, &client, &len)) < 0)
1002 syslog(LOG_ERR, _("Accepting a new connection failed: %m"));
1006 if(!(new = create_new_connection(fd)))
1010 syslog(LOG_NOTICE, _("Closed attempted connection"));
1014 connection_add(new);
1021 void randomized_alarm(int seconds)
1024 RAND_pseudo_bytes(&r, 1);
1025 alarm((seconds * (int)r) / 128 + 1);
1028 /* This function is severely fucked up.
1029 We want to redesign it so the following rules apply:
1031 - Try all ConnectTo's in a row:
1032 - if a connect() fails, try next one immediately,
1033 - if it works, wait 5 seconds or so.
1034 - If none of them were succesful, increase delay and retry.
1035 - If all were succesful, don't try anymore.
1039 try_outgoing_connections(int a)
1041 static config_t *cfg = NULL;
1042 static int retry = 0;
1044 int maxtimeout = 900;
1047 cfg = lookup_config(config_tree, "ConnectTo");
1054 get_config_string(cfg, &name);
1055 cfg = lookup_config_next(config_tree, cfg); /* Next time skip to next ConnectTo line */
1057 if(!setup_outgoing_connection(name)) /* function returns 0 when there are no problems */
1062 get_config_int(lookup_config(config_tree, "MaxTimeout"), &maxtimeout);
1066 seconds_till_retry += 5;
1067 if(seconds_till_retry > maxtimeout) /* Don't wait more than MAXTIMEOUT seconds. */
1068 seconds_till_retry = maxtimeout;
1070 syslog(LOG_ERR, _("Failed to setup all outgoing connections, will retry in %d seconds"),
1071 seconds_till_retry);
1073 /* Randomize timeout to avoid global synchronisation effects */
1074 randomized_alarm(seconds_till_retry);
1078 seconds_till_retry = 5;
1084 check all connections to see if anything
1085 happened on their sockets
1087 void check_network_activity(fd_set *f)
1092 if(FD_ISSET(udp_socket, f))
1093 handle_incoming_vpn_data();
1095 for(node = connection_tree->head; node; node = node->next)
1097 c = (connection_t *)node->data;
1099 if(c->status.remove)
1102 if(FD_ISSET(c->socket, f))
1103 if(receive_meta(c) < 0)
1105 terminate_connection(c, c->status.active);
1110 if(FD_ISSET(tcp_socket, f))
1111 handle_new_meta_connection();
1116 this is where it all happens...
1118 void main_loop(void)
1123 time_t last_ping_check;
1126 last_ping_check = time(NULL);
1130 tv.tv_sec = timeout;
1135 if((r = select(FD_SETSIZE, &fset, NULL, NULL, &tv)) < 0)
1137 if(errno != EINTR) /* because of alarm */
1139 syslog(LOG_ERR, _("Error while waiting for input: %m"));
1146 syslog(LOG_INFO, _("Rereading configuration file and restarting in 5 seconds"));
1148 close_network_connections();
1149 exit_configuration(&config_tree);
1151 if(read_server_config())
1153 syslog(LOG_ERR, _("Unable to reread configuration file, exiting"));
1159 if(setup_network_connections())
1167 /* Let's check if everybody is still alive */
1169 if(last_ping_check + timeout < t)
1171 check_dead_connections();
1172 last_ping_check = time(NULL);
1174 /* Should we regenerate our key? */
1178 if(debug_lvl >= DEBUG_STATUS)
1179 syslog(LOG_INFO, _("Regenerating symmetric key"));
1181 RAND_pseudo_bytes(myself->key, myself->keylength);
1182 send_key_changed(myself->connection, myself);
1183 keyexpires = time(NULL) + keylifetime;
1189 check_network_activity(&fset);
1191 /* local tap data */
1192 if(FD_ISSET(device_fd, &fset))