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.179 2002/09/09 19:39:58 guus Exp $
*/
#include "config.h"
#include "process.h"
#include "protocol.h"
#include "subnet.h"
+#include "graph.h"
#include "process.h"
#include "route.h"
#include "device.h"
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
+ cp();
if(debug_lvl >= DEBUG_PROTOCOL)
syslog(LOG_DEBUG, _("Purging unreachable nodes"));
{
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);
}
}
-cp
+ cp();
}
/*
avl_node_t *node, *next;
connection_t *c;
int i;
-cp
+ cp();
FD_ZERO(fs);
for(node = connection_tree->head; node; node = next)
}
FD_SET(device_fd, fs);
-cp
+ 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
+ cp();
if(c->status.remove)
return;
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)
retry_outgoing(c->outgoing);
c->outgoing = NULL;
}
-cp
+ 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)
+ cp();
+ 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)
{
}
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);
}
}
}
-cp
+ cp();
}
/*
int result, i;
int len = sizeof(result);
vpn_packet_t packet;
-cp
+ cp();
if(FD_ISSET(device_fd, f))
{
if(!read_packet(&packet))
if(FD_ISSET(listen_socket[i].tcp, f))
handle_new_meta_connection(listen_socket[i].tcp);
}
-cp
+ cp();
}
/*
int r;
time_t last_ping_check;
event_t *event;
-cp
+ cp();
last_ping_check = now;
srand(now);
build_fdset(&fset);
- if((r = select(FD_SETSIZE, &fset, NULL, NULL, &tv)) < 0)
+ r = select(FD_SETSIZE, &fset, NULL, NULL, &tv);
+
+ if(r < 0)
{
if(errno != EINTR && errno != EAGAIN)
{
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;
}
}
continue;
}
}
-cp
+ cp();
}