-/*
- read, encrypt and send data that is
- available through the ethertap device
-*/
-void handle_tap_input(void)
-{
- vpn_packet_t vp;
- int lenin;
-cp
- if(taptype == TAP_TYPE_TUNTAP)
- {
- if((lenin = read(tap_fd, vp.data, MTU)) <= 0)
- {
- syslog(LOG_ERR, _("Error while reading from tun/tap device: %m"));
- return;
- }
- vp.len = lenin;
- }
- else /* ethertap */
- {
- if((lenin = read(tap_fd, vp.data - 2, MTU)) <= 0)
- {
- syslog(LOG_ERR, _("Error while reading from ethertap device: %m"));
- return;
- }
- vp.len = lenin - 2;
- }
-
- total_tap_in += lenin;
-
- if(lenin < 32)
- {
- if(debug_lvl >= DEBUG_TRAFFIC)
- syslog(LOG_WARNING, _("Received short packet from tap device"));
- return;
- }
-
- if(debug_lvl >= DEBUG_TRAFFIC)
- {
- syslog(LOG_DEBUG, _("Read packet of length %d from tap device"), vp.len);
- }
-
- send_packet(ntohl(*((unsigned long*)(&vp.data[30]))), &vp);
-cp
+static void sigint_handler(int signal, short events, void *data) {
+ static int saved_debug_level = -1;
+
+ logger(LOG_NOTICE, _("Got %s signal"), strsignal(signal));
+
+ if(saved_debug_level != -1) {
+ logger(LOG_NOTICE, _("Reverting to old debug level (%d)"),
+ saved_debug_level);
+ debug_level = saved_debug_level;
+ saved_debug_level = -1;
+ } else {
+ logger(LOG_NOTICE,
+ _("Temporarily setting debug level to 5. Kill me with SIGINT again to go back to level %d."),
+ debug_level);
+ saved_debug_level = debug_level;
+ debug_level = 5;
+ }
+}
+
+static void sigusr1_handler(int signal, short events, void *data) {
+ logger(LOG_NOTICE, _("Got %s signal"), strsignal(signal));
+ dump_connections();
+}
+
+static void sigusr2_handler(int signal, short events, void *data) {
+ logger(LOG_NOTICE, _("Got %s signal"), strsignal(signal));
+ dump_device_stats();
+ dump_nodes();
+ dump_edges();
+ dump_subnets();
+}
+
+static void sigwinch_handler(int signal, short events, void *data) {
+ logger(LOG_NOTICE, _("Got %s signal"), strsignal(signal));
+ purge();
+}
+
+static void sighup_handler(int signal, short events, void *data) {
+ connection_t *c;
+ avl_node_t *node;
+ char *fname;
+ struct stat s;
+ static time_t last_config_check = 0;
+
+ logger(LOG_NOTICE, _("Got %s signal"), strsignal(signal));
+
+ /* Reread our own configuration file */
+
+ exit_configuration(&config_tree);
+ init_configuration(&config_tree);
+
+ if(!read_server_config()) {
+ logger(LOG_ERR, _("Unable to reread configuration file, exitting."));
+ event_loopexit(NULL);
+ return;
+ }
+
+ /* Close connections to hosts that have a changed or deleted host config file */
+
+ for(node = connection_tree->head; node; node = node->next) {
+ c = node->data;
+
+ if(c->outgoing) {
+ free(c->outgoing->name);
+ if(c->outgoing->ai)
+ freeaddrinfo(c->outgoing->ai);
+ free(c->outgoing);
+ c->outgoing = NULL;
+ }
+
+ asprintf(&fname, "%s/hosts/%s", confbase, c->name);
+ if(stat(fname, &s) || s.st_mtime > last_config_check)
+ terminate_connection(c, c->status.active);
+ free(fname);
+ }
+
+ last_config_check = time(NULL);
+
+ /* Try to make outgoing connections */
+
+ try_outgoing_connections();
+}
+
+static void sigalrm_handler(int signal, short events, void *data) {
+ logger(LOG_NOTICE, _("Got %s signal"), strsignal(signal));
+
+ connection_t *c;
+ avl_node_t *node;
+
+ for(node = connection_tree->head; node; node = node->next) {
+ c = node->data;
+
+ if(c->outgoing && !c->node) {
+ if(timeout_initialized(&c->outgoing->ev))
+ event_del(&c->outgoing->ev);
+ if(c->status.connecting)
+ close(c->socket);
+ c->outgoing->timeout = 0;
+ do_outgoing_connection(c);
+ }
+ }