X-Git-Url: https://www.tinc-vpn.org/git/browse?a=blobdiff_plain;f=src%2Fnet.c;h=8cf4a765673b755a5d87dfd0a79ab272e63a4718;hb=c5325ffdd1c6749beaf842c272eb28ecd5a070b6;hp=2565be113506502626af2c65ff49c7cb8cf7b61c;hpb=a96c4f016c9fff2392d85f762e16f5430c0b6463;p=tinc diff --git a/src/net.c b/src/net.c index 2565be11..8cf4a765 100644 --- a/src/net.c +++ b/src/net.c @@ -40,6 +40,7 @@ int contradicting_add_edge = 0; int contradicting_del_edge = 0; static int sleeptime = 10; +time_t last_config_check = 0; /* Purge edges and subnets of unreachable nodes. Use carefully. */ @@ -113,7 +114,7 @@ void terminate_connection(connection_t *c, bool report) { c->status.active = false; - if(c->node) + if(c->node && c->node->connection == c) c->node->connection = NULL; if(c->edge) { @@ -145,8 +146,10 @@ void terminate_connection(connection_t *c, bool report) { /* Check if this was our outgoing connection */ if(c->outgoing) { - do_outgoing_connection(c); - } + do_outgoing_connection(c); + } else { + connection_del(c); + } } /* @@ -261,7 +264,6 @@ int reload_configuration(void) { splay_node_t *node, *next; char *fname; struct stat s; - static time_t last_config_check = 0; /* Reread our own configuration file */ @@ -274,37 +276,21 @@ int reload_configuration(void) { return EINVAL; } - /* Close connections to hosts that have a changed or deleted host config file */ - - for(node = connection_tree->head; node; node = next) { - c = node->data; - next = node->next; + read_config_options(config_tree, NULL); - if(c->status.control) - continue; - - if(c->outgoing) { - free(c->outgoing->name); - if(c->outgoing->ai) - freeaddrinfo(c->outgoing->ai); - free(c->outgoing); - c->outgoing = NULL; - } - - xasprintf(&fname, "%s/hosts/%s", confbase, c->name); - if(stat(fname, &s) || s.st_mtime > last_config_check) - terminate_connection(c, c->status.active); - free(fname); - } + xasprintf(&fname, "%s" SLASH "hosts" SLASH "%s", confbase, myself->name); + read_config_file(config_tree, fname); + free(fname); - last_config_check = time(NULL); + /* Parse some options that are allowed to be changed while tinc is running */ + + setup_myself_reloadable(); /* If StrictSubnet is set, expire deleted Subnets and read new ones in */ if(strictsubnets) { subnet_t *subnet; - for(node = subnet_tree->head; node; node = node->next) { subnet = node->data; subnet->expires = 1; @@ -328,20 +314,82 @@ int reload_configuration(void) { subnet_update(subnet->owner, subnet, true); } } + } else { /* Only read our own subnets back in */ + subnet_t *subnet, *s2; + + for(node = myself->subnet_tree->head; node; node = node->next) { + subnet_t *subnet = node->data; + logger(DEBUG_ALWAYS, LOG_DEBUG, "subnet %p expires %d", subnet, (int)subnet->expires); + if(!subnet->expires) + subnet->expires = 1; + } + + config_t *cfg = lookup_config(config_tree, "Subnet"); + + while(cfg) { + if(!get_config_subnet(cfg, &subnet)) + continue; + + if((s2 = lookup_subnet(myself, subnet))) { + logger(DEBUG_ALWAYS, LOG_DEBUG, "read subnet that already exists: %p expires %d", s2, (int)s2->expires); + if(s2->expires == 1) + s2->expires = 0; + + free_subnet(subnet); + } else { + logger(DEBUG_ALWAYS, LOG_DEBUG, "read new subnet %p", subnet); + subnet_add(myself, subnet); + send_add_subnet(everyone, subnet); + subnet_update(myself, subnet, true); + } + + cfg = lookup_config_next(config_tree, cfg); + } + + for(node = myself->subnet_tree->head; node; node = next) { + next = node->next; + subnet_t *subnet = node->data; + if(subnet->expires == 1) { + logger(DEBUG_ALWAYS, LOG_DEBUG, "removed subnet %p", subnet); + send_del_subnet(everyone, subnet); + subnet_update(myself, subnet, false); + subnet_del(myself, subnet); + } + } } /* Try to make outgoing connections */ try_outgoing_connections(); + /* Close connections to hosts that have a changed or deleted host config file */ + + for(node = connection_tree->head; node; node = next) { + c = node->data; + next = node->next; + + if(c->status.control) + continue; + + xasprintf(&fname, "%s" SLASH "hosts" SLASH "%s", confbase, c->name); + if(stat(fname, &s) || s.st_mtime > last_config_check) { + fprintf(stderr, "ZOMG %ld > %ld\n", s.st_mtime, last_config_check); + terminate_connection(c, c->status.active); + } + free(fname); + } + + last_config_check = time(NULL); + return 0; } void retry(void) { connection_t *c; - splay_node_t *node; + splay_node_t *node, *next; - for(node = connection_tree->head; node; node = node->next) { + for(node = connection_tree->head; node; node = next) { + next = node->next; c = node->data; if(c->outgoing && !c->node) {