X-Git-Url: https://tinc-vpn.org/git/browse?p=tinc;a=blobdiff_plain;f=src%2Fnet.c;h=69a0133e652bcd399a63bf3d8e594d417559772e;hp=ca70886ff7d41a97ef3f47e79d5f0e255e6aff1d;hb=5638b9830f9cfe43f545c37cfd7ccf1d4b4bfcc6;hpb=d134c4542d4e890e1c1007f32b866742319853c5 diff --git a/src/net.c b/src/net.c index ca70886f..69a0133e 100644 --- a/src/net.c +++ b/src/net.c @@ -17,7 +17,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - $Id: net.c,v 1.35.4.175 2002/09/03 20:43:25 guus Exp $ + $Id: net.c,v 1.35.4.178 2002/09/06 21:22:35 guus Exp $ */ #include "config.h" @@ -65,6 +65,7 @@ #include "process.h" #include "protocol.h" #include "subnet.h" +#include "graph.h" #include "process.h" #include "route.h" #include "device.h" @@ -82,14 +83,14 @@ int sigalrm = 0; time_t now = 0; -/* Purge subnets of unreachable nodes. Use carefully. */ +/* Purge edges and subnets of unreachable nodes. Use carefully. */ void purge(void) { - avl_node_t *nnode, *nnext, *snode, *snext, *cnode; + avl_node_t *nnode, *nnext, *enode, *enext, *snode, *snext; node_t *n; + edge_t *e; subnet_t *s; - connection_t *c; cp if(debug_lvl >= DEBUG_PROTOCOL) syslog(LOG_DEBUG, _("Purging unreachable nodes")); @@ -108,17 +109,18 @@ cp { snext = snode->next; s = (subnet_t *)snode->data; - - for(cnode = connection_tree->head; cnode; cnode = cnode->next) - { - c = (connection_t *)cnode->data; - if(c->status.active) - send_del_subnet(c, s); - } - + send_del_subnet(broadcast, s); subnet_del(n, s); } + for(enode = n->edge_tree->head; enode; enode = enext) + { + enext = enode->next; + e = (edge_t *)enode->data; + send_del_edge(broadcast, e); + edge_del(e); + } + node_del(n); } } @@ -165,15 +167,12 @@ cp /* Terminate a connection: - Close the socket - - Tell other connections about it if report = 1 + - Remove associated edge and tell other connections about it if report = 1 - Check if we need to retry making an outgoing connection - Deactivate the host */ void terminate_connection(connection_t *c, int report) { - avl_node_t *node, *node2; - connection_t *other; - node_t *n; cp if(c->status.remove) return; @@ -186,31 +185,23 @@ cp c->status.active = 0; if(c->node) - { - if(report && c->node->connection) - { - for(node = connection_tree->head; node; node = node->next) - { - other = (connection_t *)node->data; - if(other == c) - continue; - for(node2 = node_tree->head; node2; node2 = node2->next) - { - n = (node_t *)node2->data; - if(n->nexthop == c->node) - { - send_del_node(other, n); - n->status.reachable = 0; - } - } - } - } - c->node->connection = NULL; - } + c->node->connection = NULL; if(c->socket) close(c->socket); + if(c->edge) + { + if(report) + send_del_edge(broadcast, c->edge); + + edge_del(c->edge); + + /* Run MST and SSSP algorithms */ + + graph(); + } + /* Check if this was our outgoing connection */ if(c->outgoing) @@ -231,13 +222,14 @@ cp */ void check_dead_connections(void) { - avl_node_t *node; + avl_node_t *node, *next; connection_t *c; cp - for(node = connection_tree->head; node; node = node->next) + for(node = connection_tree->head; node; node = next) { + next = node->next; c = (connection_t *)node->data; - if(c->last_ping_time + pingtimeout < now && !c->status.remove) + if(c->last_ping_time + pingtimeout < now) { if(c->status.active) { @@ -256,6 +248,12 @@ cp } else { + if(c->status.remove) + { + syslog(LOG_WARNING, _("Old connection_t for %s (%s) status %04x still lingering, deleting..."), c->name, c->hostname, c->status); + connection_del(c); + continue; + } if(debug_lvl >= DEBUG_CONNECTIONS) syslog(LOG_WARNING, _("Timeout from %s (%s) during authentication"), c->name, c->hostname); @@ -391,7 +389,7 @@ cp syslog(LOG_INFO, _("Regenerating symmetric key")); RAND_pseudo_bytes(myself->key, myself->keylength); - send_key_changed(myself->connection, myself); + send_key_changed(broadcast, myself); keyexpires = now + keylifetime; } }