X-Git-Url: https://tinc-vpn.org/git/browse?a=blobdiff_plain;f=src%2Fnet.c;h=7efe7fa3f86cfe39739be804bd0e347f53917542;hb=8c10a4131f19dc27b0bc56ef48ae481d1fa03cb0;hp=dffe0b472c36694053d0bc611efc6969ba368258;hpb=0871c3095151bce6a4031a2662aa51b7193b855c;p=tinc diff --git a/src/net.c b/src/net.c index dffe0b47..7efe7fa3 100644 --- a/src/net.c +++ b/src/net.c @@ -26,6 +26,7 @@ #include "conf_net.h" #include "conf.h" #include "connection.h" +#include "crypto.h" #include "graph.h" #include "logger.h" #include "meta.h" @@ -50,11 +51,11 @@ void purge(void) { /* Remove all edges and subnets owned by unreachable nodes. */ - for splay_each(node_t, n, node_tree) { + 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 splay_each(subnet_t, s, n->subnet_tree) { + for splay_each(subnet_t, s, &n->subnet_tree) { send_del_subnet(everyone, s); if(!strictsubnets) { @@ -62,7 +63,7 @@ void purge(void) { } } - for splay_each(edge_t, e, n->edge_tree) { + for splay_each(edge_t, e, &n->edge_tree) { if(!tunnelserver) { send_del_edge(everyone, e); } @@ -74,14 +75,14 @@ void purge(void) { /* Check if anyone else claims to have an edge to an unreachable node. If not, delete node. */ - for splay_each(node_t, n, node_tree) { + for splay_each(node_t, n, &node_tree) { if(!n->status.reachable) { - for splay_each(edge_t, e, edge_weight_tree) + for splay_each(edge_t, e, &edge_weight_tree) if(e->to == n) { return; } - if(!autoconnect && (!strictsubnets || !n->subnet_tree->head)) + if(!autoconnect && (!strictsubnets || !n->subnet_tree.head)) /* in strictsubnets mode do not delete nodes with subnets */ { node_del(n); @@ -256,7 +257,7 @@ static void timeout_handler(void *data) { } timeout_set(data, &(struct timeval) { - 1, rand() % 100000 + 1, jitter() }); } @@ -289,12 +290,12 @@ static void periodic_handler(void *data) { /* If AutoConnect is set, check if we need to make or break connections. */ - if(autoconnect && node_tree->count > 1) { + if(autoconnect && node_tree.count > 1) { do_autoconnect(); } timeout_set(data, &(struct timeval) { - 5, rand() % 100000 + 5, jitter() }); } @@ -335,18 +336,17 @@ int reload_configuration(void) { /* Reread our own configuration file */ - exit_configuration(&config_tree); - init_configuration(&config_tree); + splay_empty_tree(&config_tree); - if(!read_server_config(config_tree)) { + if(!read_server_config(&config_tree)) { logger(DEBUG_ALWAYS, LOG_ERR, "Unable to reread configuration file."); return EINVAL; } - read_config_options(config_tree, NULL); + read_config_options(&config_tree, NULL); snprintf(fname, sizeof(fname), "%s" SLASH "hosts" SLASH "%s", confbase, myself->name); - read_config_file(config_tree, fname, true); + read_config_file(&config_tree, fname, true); /* Parse some options that are allowed to be changed while tinc is running */ @@ -355,20 +355,20 @@ int reload_configuration(void) { /* If StrictSubnet is set, expire deleted Subnets and read new ones in */ if(strictsubnets) { - for splay_each(subnet_t, subnet, subnet_tree) + for splay_each(subnet_t, subnet, &subnet_tree) if(subnet->owner) { subnet->expires = 1; } } - for splay_each(node_t, n, node_tree) { + for splay_each(node_t, n, &node_tree) { n->status.has_address = false; } load_all_nodes(); if(strictsubnets) { - for splay_each(subnet_t, subnet, subnet_tree) { + for splay_each(subnet_t, subnet, &subnet_tree) { if(!subnet->owner) { continue; } @@ -392,12 +392,12 @@ int reload_configuration(void) { } } } else { /* Only read our own subnets back in */ - for splay_each(subnet_t, subnet, myself->subnet_tree) + for splay_each(subnet_t, subnet, &myself->subnet_tree) if(!subnet->expires) { subnet->expires = 1; } - config_t *cfg = lookup_config(config_tree, "Subnet"); + config_t *cfg = lookup_config(&config_tree, "Subnet"); while(cfg) { subnet_t *subnet, *s2; @@ -416,10 +416,10 @@ int reload_configuration(void) { } } - cfg = lookup_config_next(config_tree, cfg); + cfg = lookup_config_next(&config_tree, cfg); } - for splay_each(subnet_t, subnet, myself->subnet_tree) { + for splay_each(subnet_t, subnet, &myself->subnet_tree) { if(subnet->expires == 1) { send_del_subnet(everyone, subnet); subnet_update(myself, subnet, false); @@ -483,7 +483,7 @@ void retry(void) { int main_loop(void) { last_periodic_run_time = now; timeout_add(&pingtimer, timeout_handler, &pingtimer, &(struct timeval) { - pingtimeout, rand() % 100000 + pingtimeout, jitter() }); timeout_add(&periodictimer, periodic_handler, &periodictimer, &(struct timeval) { 0, 0