X-Git-Url: https://www.tinc-vpn.org/git/browse?p=tinc;a=blobdiff_plain;f=src%2Fnet.c;h=13933d9a4bc4c33c9e3c2d0dd7728d86c91a2d12;hp=ca70886ff7d41a97ef3f47e79d5f0e255e6aff1d;hb=8b2b67e26c5b971761f5015764d5e188f6343bc4;hpb=d134c4542d4e890e1c1007f32b866742319853c5 diff --git a/src/net.c b/src/net.c index ca70886f..13933d9a 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.177 2002/09/04 16:26:44 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) { @@ -391,7 +383,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; } }