Reload Subnets when getting a HUP signal and StrictSubnets is used.
authorGuus Sliepen <guus@tinc-vpn.org>
Sat, 10 Apr 2010 22:50:42 +0000 (00:50 +0200)
committerGuus Sliepen <guus@tinc-vpn.org>
Sat, 10 Apr 2010 22:50:42 +0000 (00:50 +0200)
src/net.c
src/net.h
src/net_setup.c
src/subnet.h

index 6ffd9989d5d4356e6e83c1e3cc08edfa20e16b08..528e046b9464a9903a79bad73aceaccc8d123cbf 100644 (file)
--- 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();
index fe4b54b776e58dd16d180ea1765b54e161ef0580..a97759fc80dfcf755e4b74bf24c327a63cec5c90 100644 (file)
--- 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)
index 813c58baca29fbf782a88d2133d9f01e00d72e4d..118d719c439d4420e023915c0406686973c9c45f 100644 (file)
@@ -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);
index b2124a0ef87037a00d00b9daed4cbf411c3b1270..e129a9592d3f98975db56aa0e7bf41dfff63bbd6 100644 (file)
@@ -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 *);