+/* Purge edges and subnets of unreachable nodes. Use carefully. */
+
+void purge(void)
+{
+ avl_node_t *nnode, *nnext, *enode, *enext, *snode, *snext, *cnode;
+ node_t *n;
+ edge_t *e;
+ subnet_t *s;
+ connection_t *c;
+cp
+ if(debug_lvl >= DEBUG_PROTOCOL)
+ syslog(LOG_DEBUG, _("Purging unreachable nodes"));
+
+ for(nnode = node_tree->head; nnode; nnode = nnext)
+ {
+ nnext = nnode->next;
+ n = (node_t *)nnode->data;
+
+ if(!n->status.reachable)
+ {
+ if(debug_lvl >= DEBUG_SCARY_THINGS)
+ syslog(LOG_DEBUG, _("Purging node %s (%s)"), n->name, n->hostname);
+
+ for(snode = n->subnet_tree->head; snode; snode = snext)
+ {
+ 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);
+ }
+
+ subnet_del(n, s);
+ }
+
+ for(enode = n->edge_tree->head; enode; enode = enext)
+ {
+ enext = enode->next;
+ e = (edge_t *)enode->data;
+
+ for(cnode = connection_tree->head; cnode; cnode = cnode->next)
+ {
+ c = (connection_t *)cnode->data;
+ if(c->status.active)
+ send_del_edge(c, e);
+ }
+
+ edge_del(e);
+ }
+
+ node_del(n);
+ }
+ }
+cp
+}
+