From: Guus Sliepen Date: Sat, 10 Apr 2010 22:50:42 +0000 (+0200) Subject: Reload Subnets when getting a HUP signal and StrictSubnets is used. X-Git-Tag: release-1.0.13~6 X-Git-Url: https://www.tinc-vpn.org/git/browse?p=tinc;a=commitdiff_plain;h=9f53ab209d8a6a7622a49ed03cef735b6e3f3eeb Reload Subnets when getting a HUP signal and StrictSubnets is used. --- diff --git a/src/net.c b/src/net.c index 6ffd9989..528e046b 100644 --- a/src/net.c +++ b/src/net.c @@ -489,6 +489,31 @@ int main_loop(void) { last_config_check = now; + /* 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; + } + + load_all_subnets(); + + for(node = subnet_tree->head; node; node = next) { + next = node->next; + subnet = node->data; + if(subnet->expires == 1) { + send_del_subnet(broadcast, subnet); + subnet_del(subnet->owner, subnet); + } else if(subnet->expires == -1) { + send_add_subnet(broadcast, subnet); + subnet->expires = 0; + } + } + } + /* Try to make outgoing connections */ try_outgoing_connections(); diff --git a/src/net.h b/src/net.h index fe4b54b7..a97759fc 100644 --- a/src/net.h +++ b/src/net.h @@ -139,6 +139,7 @@ extern void terminate_connection(struct connection_t *, bool); extern void flush_queue(struct node_t *); extern bool read_rsa_public_key(struct connection_t *); extern void send_mtu_probe(struct node_t *); +extern void load_all_subnets(); #ifndef HAVE_MINGW #define closesocket(s) close(s) diff --git a/src/net_setup.c b/src/net_setup.c index 813c58ba..118d719c 100644 --- a/src/net_setup.c +++ b/src/net_setup.c @@ -204,14 +204,14 @@ bool read_rsa_private_key(void) { /* Read Subnets from all host config files */ -static void load_all_subnets(void) { +void load_all_subnets(void) { DIR *dir; struct dirent *ent; char *dname; char *fname; avl_tree_t *config_tree; config_t *cfg; - subnet_t *s; + subnet_t *s, *s2; node_t *n; bool result; @@ -251,7 +251,11 @@ static void load_all_subnets(void) { if(!get_config_subnet(cfg, &s)) continue; - subnet_add(n, s); + if((s2 = lookup_subnet(n, s))) { + s2->expires = -1; + } else { + subnet_add(n, s); + } } exit_configuration(&config_tree); diff --git a/src/subnet.h b/src/subnet.h index b2124a0e..e129a959 100644 --- a/src/subnet.h +++ b/src/subnet.h @@ -64,6 +64,8 @@ typedef struct subnet_t { #define MAXNETSTR 64 +extern avl_tree_t *subnet_tree; + extern int subnet_compare(const struct subnet_t *, const struct subnet_t *); extern subnet_t *new_subnet(void) __attribute__ ((__malloc__)); extern void free_subnet(subnet_t *);