X-Git-Url: https://www.tinc-vpn.org/git/browse?a=blobdiff_plain;f=src%2Fnet.c;h=28fa9955b9e87c79ce871335c8030efa1110f9e3;hb=0b8b23e0dd7219344543f135ca0aeba8a4a42d48;hp=ddca1c9b9a8b8a29a9ea2a7225904cafebb08fab;hpb=ff306f0cdaedb50de1472e7c1fb55de922a6ca60;p=tinc diff --git a/src/net.c b/src/net.c index ddca1c9b..28fa9955 100644 --- a/src/net.c +++ b/src/net.c @@ -44,33 +44,21 @@ time_t last_config_check = 0; /* Purge edges and subnets of unreachable nodes. Use carefully. */ void purge(void) { - splay_node_t *nnode, *nnext, *enode, *enext, *snode, *snext; - node_t *n; - edge_t *e; - subnet_t *s; - logger(DEBUG_PROTOCOL, LOG_DEBUG, "Purging unreachable nodes"); /* Remove all edges and subnets owned by unreachable nodes. */ - for(nnode = node_tree->head; nnode; nnode = nnext) { - nnext = nnode->next; - n = nnode->data; - + for splay_each(node_t, n, node_tree) { if(!n->status.reachable) { logger(DEBUG_SCARY_THINGS, LOG_DEBUG, "Purging node %s (%s)", n->name, n->hostname); - for(snode = n->subnet_tree->head; snode; snode = snext) { - snext = snode->next; - s = snode->data; + for splay_each(subnet_t, s, n->subnet_tree) { send_del_subnet(everyone, s); if(!strictsubnets) subnet_del(n, s); } - for(enode = n->edge_tree->head; enode; enode = enext) { - enext = enode->next; - e = enode->data; + for splay_each(edge_t, e, n->edge_tree) { if(!tunnelserver) send_del_edge(everyone, e); edge_del(e); @@ -80,20 +68,13 @@ void purge(void) { /* Check if anyone else claims to have an edge to an unreachable node. If not, delete node. */ - for(nnode = node_tree->head; nnode; nnode = nnext) { - nnext = nnode->next; - n = nnode->data; - + for splay_each(node_t, n, node_tree) { if(!n->status.reachable) { - for(enode = edge_weight_tree->head; enode; enode = enext) { - enext = enode->next; - e = enode->data; - + for splay_each(edge_t, e, edge_weight_tree) if(e->to == n) - break; - } + return; - if(!enode && (!strictsubnets || !n->subnet_tree->head)) + if(!strictsubnets || !n->subnet_tree->head) /* in strictsubnets mode do not delete nodes with subnets */ node_del(n); } @@ -159,10 +140,7 @@ void terminate_connection(connection_t *c, bool report) { static void timeout_handler(int fd, short events, void *event) { time_t now = time(NULL); - for(list_node_t *node = connection_list->head, *next; node; node = next) { - next = node->next; - connection_t *c = node->data; - + for list_each(connection_t, c, connection_list) { if(c->status.control) continue; @@ -272,16 +250,12 @@ int reload_configuration(void) { /* If StrictSubnet is set, expire deleted Subnets and read new ones in */ if(strictsubnets) { - for(splay_node_t *node = subnet_tree->head; node; node = node->next) { - subnet_t *subnet = node->data; + for splay_each(subnet_t, subnet, subnet_tree) subnet->expires = 1; - } load_all_subnets(); - for(splay_node_t *node = subnet_tree->head, *next; node; node = next) { - next = node->next; - subnet_t *subnet = node->data; + for splay_each(subnet_t, subnet, subnet_tree) { if(subnet->expires == 1) { send_del_subnet(everyone, subnet); if(subnet->owner->status.reachable) @@ -296,11 +270,9 @@ int reload_configuration(void) { } } } else { /* Only read our own subnets back in */ - for(splay_node_t *node = myself->subnet_tree->head; node; node = node->next) { - subnet_t *subnet = node->data; + for splay_each(subnet_t, subnet, myself->subnet_tree) if(!subnet->expires) subnet->expires = 1; - } config_t *cfg = lookup_config(config_tree, "Subnet"); @@ -324,9 +296,7 @@ int reload_configuration(void) { cfg = lookup_config_next(config_tree, cfg); } - for(splay_node_t *node = myself->subnet_tree->head, *next; node; node = next) { - next = node->next; - subnet_t *subnet = node->data; + for splay_each(subnet_t, subnet, myself->subnet_tree) { if(subnet->expires == 1) { send_del_subnet(everyone, subnet); subnet_update(myself, subnet, false); @@ -341,10 +311,7 @@ int reload_configuration(void) { /* Close connections to hosts that have a changed or deleted host config file */ - for(list_node_t *node = connection_list->head, *next; node; node = next) { - connection_t *c = node->data; - next = node->next; - + for list_each(connection_t, c, connection_list) { if(c->status.control) continue; @@ -363,10 +330,7 @@ int reload_configuration(void) { } void retry(void) { - for(list_node_t *node = connection_list->head, *next; node; node = next) { - next = node->next; - connection_t *c = node->data; - + for list_each(connection_t, c, connection_list) { if(c->outgoing && !c->node) { if(timeout_initialized(&c->outgoing->ev)) event_del(&c->outgoing->ev);