2 net.c -- most of the network code
3 Copyright (C) 1998,1999,2000 Ivo Timmermans <itimmermans@bigfoot.com>,
4 2000 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.37 2000/10/15 19:53:15 zarq Exp $
25 #include <arpa/inet.h>
29 #include <netinet/in.h>
33 #include <sys/signal.h>
34 #include <sys/socket.h>
36 #include <sys/types.h>
40 /* Next two includes are for tun/tap support */
43 #ifdef HAVE_LINUX_IF_TUN_H
44 #include <linux/if_tun.h>
62 int total_tap_out = 0;
63 int total_socket_in = 0;
64 int total_socket_out = 0;
66 int upstreamindex = 0;
67 static int seconds_till_retry;
72 strip off the MAC adresses of an ethernet frame
74 void strip_mac_addresses(vpn_packet_t *p)
77 memmove(p->data, p->data + 12, p->len -= 12);
82 reassemble MAC addresses
84 void add_mac_addresses(vpn_packet_t *p)
87 memcpy(p->data + 12, p->data, p->len);
89 p->data[0] = p->data[6] = 0xfe;
90 p->data[1] = p->data[7] = 0xfd;
91 /* Really evil pointer stuff just below! */
92 *((ip_t*)(&p->data[2])) = (ip_t)(htonl(myself->address));
93 *((ip_t*)(&p->data[8])) = *((ip_t*)(&p->data[26]));
97 int xsend(conn_list_t *cl, vpn_packet_t *inpkt)
102 outpkt.len = inpkt->len;
103 EVP_EncryptInit(cl->cipher_pktctx, cl->cipher_pkttype, cl->cipher_pktkey, NULL);
104 EVP_EncryptUpdate(cl->cipher_pktctx, outpkt.data, &outlen, inpkt->data, inpkt->len);
105 EVP_EncryptFinal(cl->cipher_pktctx, outpkt.data + outlen, &outpad);
109 syslog(LOG_ERR, _("Sending packet of %d bytes to %s (%s)"),
110 outlen, cl->name, cl->hostname);
112 total_socket_out += outlen;
116 if((send(cl->socket, (char *) &(outpkt.len), outlen + 2, 0)) < 0)
118 syslog(LOG_ERR, _("Error sending packet to %s (%s): %m"),
119 cl->name, cl->hostname);
126 int xrecv(vpn_packet_t *inpkt)
132 syslog(LOG_ERR, _("Receiving packet of %d bytes"),
135 outpkt.len = inpkt->len;
136 EVP_DecryptInit(myself->cipher_pktctx, myself->cipher_pkttype, myself->cipher_pktkey, NULL);
137 EVP_DecryptUpdate(myself->cipher_pktctx, outpkt.data, &outlen, inpkt->data, inpkt->len);
138 /* FIXME: grok DecryptFinal
139 EVP_DecryptFinal(myself->cipher_pktctx, outpkt.data + outlen, &outpad);
142 add_mac_addresses(&outpkt);
144 if(write(tap_fd, outpkt.data, outpkt.len) < 0)
145 syslog(LOG_ERR, _("Can't write to tap device: %m"));
147 total_tap_out += outpkt.len;
153 add the given packet of size s to the
154 queue q, be it the send or receive queue
156 void add_queue(packet_queue_t **q, void *packet, size_t s)
160 e = xmalloc(sizeof(*e));
161 e->packet = xmalloc(s);
162 memcpy(e->packet, packet, s);
166 *q = xmalloc(sizeof(**q));
167 (*q)->head = (*q)->tail = NULL;
170 e->next = NULL; /* We insert at the tail */
172 if((*q)->tail) /* Do we have a tail? */
174 (*q)->tail->next = e;
175 e->prev = (*q)->tail;
177 else /* No tail -> no head too */
187 /* Remove a queue element */
188 void del_queue(packet_queue_t **q, queue_element_t *e)
193 if(e->next) /* There is a successor, so we are not tail */
195 if(e->prev) /* There is a predecessor, so we are not head */
197 e->next->prev = e->prev;
198 e->prev->next = e->next;
200 else /* We are head */
202 e->next->prev = NULL;
203 (*q)->head = e->next;
206 else /* We are tail (or all alone!) */
208 if(e->prev) /* We are not alone :) */
210 e->prev->next = NULL;
211 (*q)->tail = e->prev;
225 flush a queue by calling function for
226 each packet, and removing it when that
227 returned a zero exit code
229 void flush_queue(conn_list_t *cl, packet_queue_t **pq,
230 int (*function)(conn_list_t*,void*))
232 queue_element_t *p, *next = NULL;
234 for(p = (*pq)->head; p != NULL; )
238 if(!function(cl, p->packet))
245 syslog(LOG_DEBUG, _("Queue flushed"));
250 flush the send&recv queues
251 void because nothing goes wrong here, packets
252 remain in the queue if something goes wrong
254 void flush_queues(conn_list_t *cl)
260 syslog(LOG_DEBUG, _("Flushing send queue for %s (%s)"),
261 cl->name, cl->hostname);
262 flush_queue(cl, &(cl->sq), xsend);
268 syslog(LOG_DEBUG, _("Flushing receive queue for %s (%s)"),
269 cl->name, cl->hostname);
270 flush_queue(cl, &(cl->rq), xrecv);
276 send a packet to the given vpn ip.
278 int send_packet(ip_t to, vpn_packet_t *packet)
282 if((cl = lookup_conn_list_ipv4(to)) == NULL)
286 syslog(LOG_NOTICE, _("Trying to look up %d.%d.%d.%d in connection list failed!"),
293 /* If we ourselves have indirectdata flag set, we should send only to our uplink! */
295 /* FIXME - check for indirection and reprogram it The Right Way(tm) this time. */
297 if(!cl->status.dataopen)
298 if(setup_vpn_connection(cl) < 0)
300 syslog(LOG_ERR, _("Could not open UDP connection to %s (%s)"),
301 cl->name, cl->hostname);
305 if(!cl->status.validkey)
308 syslog(LOG_INFO, _("No valid key known yet for %s (%s), queueing packet"),
309 cl->name, cl->hostname);
310 add_queue(&(cl->sq), packet, packet->len + 2);
311 if(!cl->status.waitingforkey)
312 send_req_key(myself, cl); /* Keys should be sent to the host running the tincd */
316 if(!cl->status.active)
319 syslog(LOG_INFO, _("%s (%s) is not ready, queueing packet"),
320 cl->name, cl->hostname);
321 add_queue(&(cl->sq), packet, packet->len + 2);
322 return 0; /* We don't want to mess up, do we? */
325 /* can we send it? can we? can we? huh? */
327 return xsend(cl, packet);
331 open the local ethertap device
333 int setup_tap_fd(void)
336 const char *tapfname;
343 if((cfg = get_config_val(config, tapdevice)))
344 tapfname = cfg->data.ptr;
347 tapfname = "/dev/misc/net/tun";
349 tapfname = "/dev/tap0";
352 if((nfd = open(tapfname, O_RDWR | O_NONBLOCK)) < 0)
354 syslog(LOG_ERR, _("Could not open %s: %m"), tapfname);
361 /* Ok now check if this is an old ethertap or a new tun/tap thingie */
362 memset(&ifr, 0, sizeof(ifr));
364 ifr.ifr_flags = IFF_TAP;
366 strncpy(ifr.ifr_name, netname, IFNAMSIZ);
368 if (!ioctl(tap_fd, TUNSETIFF, (void *) &ifr))
370 syslog(LOG_INFO, _("%s is a new style tun/tap device"), tapfname);
371 if((cfg = get_config_val(config, tapsubnet)) == NULL)
372 syslog(LOG_INFO, _("tun/tap device will be left unconfigured"));
374 /* Setup inetaddr/netmask etc */;
383 set up the socket that we listen on for incoming
386 int setup_listen_meta_socket(int port)
389 struct sockaddr_in a;
393 if((nfd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0)
395 syslog(LOG_ERR, _("Creating metasocket failed: %m"));
399 if(setsockopt(nfd, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one)))
401 syslog(LOG_ERR, _("setsockopt: %m"));
405 if(setsockopt(nfd, SOL_SOCKET, SO_KEEPALIVE, &one, sizeof(one)))
407 syslog(LOG_ERR, _("setsockopt: %m"));
411 flags = fcntl(nfd, F_GETFL);
412 if(fcntl(nfd, F_SETFL, flags | O_NONBLOCK) < 0)
414 syslog(LOG_ERR, _("fcntl: %m"));
418 if((cfg = get_config_val(config, interface)))
420 if(setsockopt(nfd, SOL_SOCKET, SO_KEEPALIVE, cfg->data.ptr, strlen(cfg->data.ptr)))
422 syslog(LOG_ERR, _("Unable to bind listen socket to interface %s: %m"), cfg->data.ptr);
427 memset(&a, 0, sizeof(a));
428 a.sin_family = AF_INET;
429 a.sin_port = htons(port);
431 if((cfg = get_config_val(config, interfaceip)))
432 a.sin_addr.s_addr = htonl(cfg->data.ip->ip);
434 a.sin_addr.s_addr = htonl(INADDR_ANY);
436 if(bind(nfd, (struct sockaddr *)&a, sizeof(struct sockaddr)))
438 syslog(LOG_ERR, _("Can't bind to port %hd/tcp: %m"), port);
444 syslog(LOG_ERR, _("listen: %m"));
452 setup the socket for incoming encrypted
455 int setup_vpn_in_socket(int port)
458 struct sockaddr_in a;
461 if((nfd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0)
463 syslog(LOG_ERR, _("Creating socket failed: %m"));
467 if(setsockopt(nfd, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one)))
469 syslog(LOG_ERR, _("setsockopt: %m"));
473 flags = fcntl(nfd, F_GETFL);
474 if(fcntl(nfd, F_SETFL, flags | O_NONBLOCK) < 0)
476 syslog(LOG_ERR, _("fcntl: %m"));
480 memset(&a, 0, sizeof(a));
481 a.sin_family = AF_INET;
482 a.sin_port = htons(port);
483 a.sin_addr.s_addr = htonl(INADDR_ANY);
485 if(bind(nfd, (struct sockaddr *)&a, sizeof(struct sockaddr)))
487 syslog(LOG_ERR, _("Can't bind to port %hd/udp: %m"), port);
495 setup an outgoing meta (tcp) socket
497 int setup_outgoing_meta_socket(conn_list_t *cl)
500 struct sockaddr_in a;
504 syslog(LOG_INFO, _("Trying to connect to %s"), cl->hostname);
506 if((cfg = get_config_val(cl->config, port)) == NULL)
509 cl->port = cfg->data.val;
511 cl->meta_socket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
512 if(cl->meta_socket == -1)
514 syslog(LOG_ERR, _("Creating socket for %s port %d failed: %m"),
515 cl->hostname, cl->port);
519 a.sin_family = AF_INET;
520 a.sin_port = htons(cl->port);
521 a.sin_addr.s_addr = htonl(cl->address);
523 if(connect(cl->meta_socket, (struct sockaddr *)&a, sizeof(a)) == -1)
525 syslog(LOG_ERR, _("%s port %hd: %m"), cl->hostname, cl->port);
529 flags = fcntl(cl->meta_socket, F_GETFL);
530 if(fcntl(cl->meta_socket, F_SETFL, flags | O_NONBLOCK) < 0)
532 syslog(LOG_ERR, _("fcntl for %s port %d: %m"),
533 cl->hostname, cl->port);
538 syslog(LOG_INFO, _("Connected to %s port %hd"),
539 cl->hostname, cl->port);
545 setup an outgoing connection. It's not
546 necessary to also open an udp socket as
547 well, because the other host will initiate
548 an authentication sequence during which
549 we will do just that.
551 int setup_outgoing_connection(char *hostname)
556 if(!(h = gethostbyname(hostname)))
558 syslog(LOG_ERR, _("Error looking up `%s': %m"), hostname);
562 ncn = new_conn_list();
563 ncn->address = ntohl(*((ip_t*)(h->h_addr_list[0])));
564 ncn->hostname = hostlookup(htonl(ncn->address));
566 if(setup_outgoing_meta_socket(ncn) < 0)
568 syslog(LOG_ERR, _("Could not set up a meta connection to %s"),
574 ncn->status.meta = 1;
575 ncn->status.outgoing = 1;
576 ncn->next = conn_list;
583 set up the local sockets (listen only)
585 int setup_myself(void)
589 myself = new_conn_list();
591 asprintf(&myself->hostname, "MYSELF"); /* FIXME? Do hostlookup on ourselves? */
593 myself->protocol_version = PROT_CURRENT;
595 if(!(cfg = get_config_val(config, tincname))) /* Not acceptable */
597 syslog(LOG_ERR, _("Name for tinc daemon required!"));
601 myself->name = (char*)cfg->data.val;
603 if(check_id(myself->name))
605 syslog(LOG_ERR, _("Invalid name for myself!"));
609 if(read_host_config(myself))
611 syslog(LOG_ERR, _("Cannot open host configuration file for myself!"));
615 if(!(cfg = get_config_val(myself->config, port)))
618 myself->port = cfg->data.val;
620 if((cfg = get_config_val(myself->config, indirectdata)))
621 if(cfg->data.val == stupid_true)
622 myself->flags |= EXPORTINDIRECTDATA;
624 if((cfg = get_config_val(myself->config, tcponly)))
625 if(cfg->data.val == stupid_true)
626 myself->flags |= TCPONLY;
628 if((myself->meta_socket = setup_listen_meta_socket(myself->port)) < 0)
630 syslog(LOG_ERR, _("Unable to set up a listening socket!"));
634 if((myself->socket = setup_vpn_in_socket(myself->port)) < 0)
636 syslog(LOG_ERR, _("Unable to set up an incoming vpn data socket!"));
637 close(myself->meta_socket);
641 myself->status.active = 1;
643 syslog(LOG_NOTICE, _("Ready: listening on port %hd"), myself->port);
649 sigalrm_handler(int a)
653 /* FIXME! Use name instead of upstreamip.
654 cfg = get_next_config_val(config, upstreamip, upstreamindex++);
658 if(!setup_outgoing_connection(cfg->data.ptr)) /* function returns 0 when there are no problems */
660 signal(SIGALRM, SIG_IGN);
663 // cfg = get_next_config_val(config, upstreamip, upstreamindex++); /* Or else we try the next ConnectTo line */
666 signal(SIGALRM, sigalrm_handler);
668 seconds_till_retry += 5;
669 if(seconds_till_retry > MAXTIMEOUT) /* Don't wait more than MAXTIMEOUT seconds. */
670 seconds_till_retry = MAXTIMEOUT;
671 syslog(LOG_ERR, _("Still failed to connect to other, will retry in %d seconds"),
673 alarm(seconds_till_retry);
678 setup all initial network connections
680 int setup_network_connections(void)
684 if((cfg = get_config_val(config, pingtimeout)) == NULL)
687 timeout = cfg->data.val;
689 if(setup_tap_fd() < 0)
692 if(setup_myself() < 0)
695 // if((cfg = get_next_config_val(config, upstreamip, upstreamindex++)) == NULL)
696 /* No upstream IP given, we're listen only. */
701 if(!setup_outgoing_connection(cfg->data.ptr)) /* function returns 0 when there are no problems */
703 // cfg = get_next_config_val(config, upstreamip, upstreamindex++); /* Or else we try the next ConnectTo line */
706 signal(SIGALRM, sigalrm_handler);
708 seconds_till_retry = MAXTIMEOUT;
709 syslog(LOG_NOTICE, _("Trying to re-establish outgoing connection in %d seconds"), seconds_till_retry);
710 alarm(seconds_till_retry);
716 close all open network connections
718 void close_network_connections(void)
722 for(p = conn_list; p != NULL; p = p->next)
724 if(p->status.dataopen)
726 shutdown(p->socket, 0); /* No more receptions */
732 shutdown(p->meta_socket, 0); /* No more receptions */
733 close(p->meta_socket);
738 if(myself->status.active)
740 close(myself->meta_socket);
741 close(myself->socket);
747 syslog(LOG_NOTICE, _("Terminating"));
753 create a data (udp) socket
755 int setup_vpn_connection(conn_list_t *cl)
758 struct sockaddr_in a;
761 syslog(LOG_DEBUG, _("Opening UDP socket to %s"), cl->hostname);
763 nfd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
766 syslog(LOG_ERR, _("Creating UDP socket failed: %m"));
770 a.sin_family = AF_INET;
771 a.sin_port = htons(cl->port);
772 a.sin_addr.s_addr = htonl(cl->address);
774 if(connect(nfd, (struct sockaddr *)&a, sizeof(a)) == -1)
776 syslog(LOG_ERR, _("Connecting to %s port %d failed: %m"),
777 cl->hostname, cl->port);
781 flags = fcntl(nfd, F_GETFL);
782 if(fcntl(nfd, F_SETFL, flags | O_NONBLOCK) < 0)
784 syslog(LOG_ERR, _("This is a bug: %s:%d: %d:%m %s (%s)"), __FILE__, __LINE__, nfd,
785 cl->name, cl->hostname);
790 cl->status.dataopen = 1;
796 handle an incoming tcp connect call and open
799 conn_list_t *create_new_connection(int sfd)
802 struct sockaddr_in ci;
803 int len = sizeof(ci);
807 if(getpeername(sfd, &ci, &len) < 0)
809 syslog(LOG_ERR, _("Error: getpeername: %m"));
814 p->address = ntohl(ci.sin_addr.s_addr);
815 p->hostname = hostlookup(ci.sin_addr.s_addr);
816 p->meta_socket = sfd;
818 p->buffer = xmalloc(MAXBUFSIZE);
820 p->last_ping_time = time(NULL);
824 syslog(LOG_NOTICE, _("Connection from %s port %d"),
825 p->hostname, htons(ci.sin_port));
837 put all file descriptors in an fd_set array
839 void build_fdset(fd_set *fs)
845 for(p = conn_list; p != NULL; p = p->next)
848 FD_SET(p->meta_socket, fs);
849 if(p->status.dataopen)
850 FD_SET(p->socket, fs);
853 FD_SET(myself->meta_socket, fs);
854 FD_SET(myself->socket, fs);
860 receive incoming data from the listening
861 udp socket and write it to the ethertap
862 device after being decrypted
864 int handle_incoming_vpn_data()
868 int x, l = sizeof(x);
870 if(getsockopt(myself->socket, SOL_SOCKET, SO_ERROR, &x, &l) < 0)
872 syslog(LOG_ERR, _("This is a bug: %s:%d: %d:%m"),
873 __FILE__, __LINE__, myself->socket);
878 syslog(LOG_ERR, _("Incoming data socket error: %s"), strerror(x));
882 if(recvfrom(myself->socket, (char *) &(pkt.len), MTU, 0, NULL, NULL) <= 0)
884 syslog(LOG_ERR, _("Receiving packet failed: %m"));
893 terminate a connection and notify the other
894 end before closing the sockets
896 void terminate_connection(conn_list_t *cl)
901 if(cl->status.remove)
905 syslog(LOG_NOTICE, _("Closing connection with %s (%s)"),
906 cl->name, cl->hostname);
911 close(cl->meta_socket);
913 cl->status.remove = 1;
915 /* If this cl isn't active, don't send any DEL_HOSTs. */
917 /* FIXME: reprogram this.
918 if(cl->status.active)
919 notify_others(cl,NULL,send_del_host);
923 /* Find all connections that were lost because they were behind cl
924 (the connection that was dropped). */
926 for(p = conn_list; p != NULL; p = p->next)
928 if((p->nexthop == cl) && (p != cl))
930 if(cl->status.active && p->status.active)
931 /* FIXME: reprogram this
932 notify_others(p,cl,send_del_host);
936 p->status.active = 0;
937 p->status.remove = 1;
941 cl->status.active = 0;
943 if(cl->status.outgoing)
945 signal(SIGALRM, sigalrm_handler);
946 seconds_till_retry = 5;
947 alarm(seconds_till_retry);
948 syslog(LOG_NOTICE, _("Trying to re-establish outgoing connection in 5 seconds"));
954 Check if the other end is active.
955 If we have sent packets, but didn't receive any,
956 then possibly the other end is dead. We send a
957 PING request over the meta connection. If the other
958 end does not reply in time, we consider them dead
959 and close the connection.
961 int check_dead_connections(void)
967 for(p = conn_list; p != NULL; p = p->next)
971 if(p->status.active && p->status.meta)
973 if(p->last_ping_time + timeout < now)
975 if(p->status.pinged && !p->status.got_pong)
978 syslog(LOG_INFO, _("%s (%s) didn't respond to PING"),
979 p->name, p->hostname);
980 p->status.timeout = 1;
981 terminate_connection(p);
983 else if(p->want_ping)
986 p->last_ping_time = now;
987 p->status.pinged = 1;
988 p->status.got_pong = 0;
998 accept a new tcp connect and create a
1001 int handle_new_meta_connection()
1004 struct sockaddr client;
1005 int nfd, len = sizeof(client);
1007 if((nfd = accept(myself->meta_socket, &client, &len)) < 0)
1009 syslog(LOG_ERR, _("Accepting a new connection failed: %m"));
1013 if(!(ncn = create_new_connection(nfd)))
1017 syslog(LOG_NOTICE, _("Closed attempted connection"));
1021 ncn->status.meta = 1;
1022 ncn->next = conn_list;
1029 check all connections to see if anything
1030 happened on their sockets
1032 void check_network_activity(fd_set *f)
1035 int x, l = sizeof(x);
1037 for(p = conn_list; p != NULL; p = p->next)
1039 if(p->status.remove)
1042 if(p->status.dataopen)
1043 if(FD_ISSET(p->socket, f))
1046 The only thing that can happen to get us here is apparently an
1047 error on this outgoing(!) UDP socket that isn't immediate (i.e.
1048 something that will not trigger an error directly on send()).
1049 I've once got here when it said `No route to host'.
1051 getsockopt(p->socket, SOL_SOCKET, SO_ERROR, &x, &l);
1052 syslog(LOG_ERR, _("Outgoing data socket error for %s (%s): %s"),
1053 p->name, p->hostname, strerror(x));
1054 terminate_connection(p);
1059 if(FD_ISSET(p->meta_socket, f))
1060 if(receive_meta(p) < 0)
1062 terminate_connection(p);
1067 if(FD_ISSET(myself->socket, f))
1068 handle_incoming_vpn_data();
1070 if(FD_ISSET(myself->meta_socket, f))
1071 handle_new_meta_connection();
1076 read, encrypt and send data that is
1077 available through the ethertap device
1079 void handle_tap_input(void)
1083 int ether_type, lenin;
1085 memset(&vp, 0, sizeof(vp));
1086 if((lenin = read(tap_fd, &vp, MTU)) <= 0)
1088 syslog(LOG_ERR, _("Error while reading from tapdevice: %m"));
1092 total_tap_in += lenin;
1094 ether_type = ntohs(*((unsigned short*)(&vp.data[12])));
1095 if(ether_type != 0x0800)
1098 syslog(LOG_INFO, _("Non-IP ethernet frame %04x from %02x:%02x:%02x:%02x:%02x:%02x"), ether_type, MAC_ADDR_V(vp.data[6]));
1105 syslog(LOG_INFO, _("Dropping short packet from %02x:%02x:%02x:%02x:%02x:%02x"), MAC_ADDR_V(vp.data[6]));
1109 from = ntohl(*((unsigned long*)(&vp.data[26])));
1110 to = ntohl(*((unsigned long*)(&vp.data[30])));
1112 vp.len = (length_t)lenin - 2;
1114 strip_mac_addresses(&vp);
1116 send_packet(to, &vp);
1121 this is where it all happens...
1123 void main_loop(void)
1128 time_t last_ping_check;
1130 last_ping_check = time(NULL);
1134 tv.tv_sec = timeout;
1140 if((r = select(FD_SETSIZE, &fset, NULL, NULL, &tv)) < 0)
1142 if(errno != EINTR) /* because of alarm */
1144 syslog(LOG_ERR, _("Error while waiting for input: %m"));
1152 /* FIXME: reprogram this.
1154 syslog(LOG_INFO, _("Rereading configuration file"));
1155 close_network_connections();
1157 if(read_config_file(&config, configfilename))
1159 syslog(LOG_ERR, _("Unable to reread configuration file, exiting"));
1163 setup_network_connections();
1168 if(last_ping_check + timeout < time(NULL))
1169 /* Let's check if everybody is still alive */
1171 check_dead_connections();
1172 last_ping_check = time(NULL);
1177 check_network_activity(&fset);
1179 /* local tap data */
1180 if(FD_ISSET(tap_fd, &fset))