X-Git-Url: https://www.tinc-vpn.org/git/browse?a=blobdiff_plain;f=src%2Fnet.c;h=dbff75b9b1cfc95ced7c6522902ba5c9f17a5049;hb=1b30cee086148975886f961aadc26e23b1bfd6f2;hp=1c267f64801a5dc161021b674cfb93d3833834ed;hpb=7ea85043ac1fb2096baea44f6b0af27ac0d0b2cf;p=tinc diff --git a/src/net.c b/src/net.c index 1c267f64..dbff75b9 100644 --- a/src/net.c +++ b/src/net.c @@ -1,7 +1,7 @@ /* net.c -- most of the network code Copyright (C) 1998-2005 Ivo Timmermans, - 2000-2009 Guus Sliepen + 2000-2010 Guus Sliepen 2006 Scott Lamb This program is free software; you can redistribute it and/or modify @@ -21,8 +21,6 @@ #include "system.h" -#include - #include "utils.h" #include "splay_tree.h" #include "conf.h" @@ -38,6 +36,9 @@ #include "subnet.h" #include "xalloc.h" +int contradicting_add_edge = 0; +int contradicting_del_edge = 0; + /* Purge edges and subnets of unreachable nodes. Use carefully. */ void purge(void) { @@ -61,9 +62,9 @@ void purge(void) { for(snode = n->subnet_tree->head; snode; snode = snext) { snext = snode->next; s = snode->data; - if(!tunnelserver) - send_del_subnet(broadcast, s); - subnet_del(n, s); + send_del_subnet(broadcast, s); + if(!strictsubnets) + subnet_del(n, s); } for(enode = n->edge_tree->head; enode; enode = enext) { @@ -91,7 +92,8 @@ void purge(void) { break; } - if(!enode) + if(!enode && (!strictsubnets || !n->subnet_tree->head)) + /* in strictsubnets mode do not delete nodes with subnets */ node_del(n); } } @@ -190,10 +192,23 @@ static void timeout_handler(int fd, short events, void *event) { } } + if(contradicting_del_edge && contradicting_add_edge) { + logger(LOG_WARNING, "Possible node with same Name as us!"); + + if(rand() % 3 == 0) { + logger(LOG_ERR, "Shutting down, check configuration of all nodes for duplicate Names!"); + event_loopexit(NULL); + return; + } + + contradicting_add_edge = 0; + contradicting_del_edge = 0; + } + event_add(event, &(struct timeval){pingtimeout, 0}); } -void handle_meta_connection_data(int fd, short events, void *data) { +void handle_meta_connection_data(void *data) { connection_t *c = data; int result; socklen_t len = sizeof result; @@ -208,16 +223,18 @@ void handle_meta_connection_data(int fd, short events, void *data) { else { ifdebug(CONNECTIONS) logger(LOG_DEBUG, "Error while connecting to %s (%s): %s", - c->name, c->hostname, strerror(result)); + c->name, c->hostname, sockstrerror(result)); closesocket(c->socket); do_outgoing_connection(c); return; } } - if (!receive_meta(c)) { - terminate_connection(c, c->status.active); - return; + while(true) { + if (!receive_meta(c)) { + terminate_connection(c, c->status.active); + return; + } } } @@ -271,6 +288,37 @@ int reload_configuration(void) { last_config_check = time(NULL); + /* If StrictSubnet is set, expire deleted Subnets and read new ones in */ + + if(strictsubnets) { + subnet_t *subnet; + + + for(node = subnet_tree->head; node; node = node->next) { + subnet = node->data; + subnet->expires = 1; + } + + load_all_subnets(); + + for(node = subnet_tree->head; node; node = next) { + next = node->next; + subnet = node->data; + if(subnet->expires == 1) { + send_del_subnet(broadcast, subnet); + if(subnet->owner->status.reachable) + subnet_update(subnet->owner, subnet, false); + subnet_del(subnet->owner, subnet); + } else if(subnet->expires == -1) { + subnet->expires = 0; + } else { + send_add_subnet(broadcast, subnet); + if(subnet->owner->status.reachable) + subnet_update(subnet->owner, subnet, true); + } + } + } + /* Try to make outgoing connections */ try_outgoing_connections(); @@ -307,12 +355,19 @@ int main_loop(void) { timeout_set(&timeout_event, timeout_handler, &timeout_event); event_add(&timeout_event, &(struct timeval){pingtimeout, 0}); + +#ifdef SIGHUP signal_set(&sighup_event, SIGHUP, sighup_handler, NULL); signal_add(&sighup_event, NULL); +#endif +#ifdef SIGTERM signal_set(&sigterm_event, SIGTERM, sigterm_handler, NULL); signal_add(&sigterm_event, NULL); +#endif +#ifdef SIGQUIT signal_set(&sigquit_event, SIGQUIT, sigterm_handler, NULL); signal_add(&sigquit_event, NULL); +#endif if(event_loop(0) < 0) { logger(LOG_ERR, "Error while waiting for input: %s", strerror(errno));