X-Git-Url: https://tinc-vpn.org/git/browse?a=blobdiff_plain;f=src%2Fnet.c;h=ba8bcca789121a338a943cfc3bddb31acd0ac686;hb=9e76c464b26b066e1eb3aa5232e573792e28020d;hp=863dd762c326c885312a88d703f157f2ae4fc0ed;hpb=268c8545aaf83b7433f43402f5c77e39e20006ef;p=tinc diff --git a/src/net.c b/src/net.c index 863dd762..ba8bcca7 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. */ @@ -263,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 */ @@ -276,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; @@ -330,12 +314,69 @@ 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; + 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))) { + if(s2->expires == 1) + s2->expires = 0; + + free_subnet(subnet); + } else { + 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) { + 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; }