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 6ffd998..528e046 100644 (file)
--- a/src/net.c
+++ b/src/net.c
@@ -489,6 +489,31 @@ int main_loop(void) {
 
                        last_config_check = now;
 
 
                        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();
                        /* Try to make outgoing connections */
                        
                        try_outgoing_connections();
index fe4b54b..a97759f 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 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)
 
 #ifndef HAVE_MINGW
 #define closesocket(s) close(s)
index 813c58b..118d719 100644 (file)
@@ -204,14 +204,14 @@ bool read_rsa_private_key(void) {
 /*
   Read Subnets from all host config files
 */
 /*
   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;
        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;
 
        node_t *n;
        bool result;
 
@@ -251,7 +251,11 @@ static void load_all_subnets(void) {
                        if(!get_config_subnet(cfg, &s))
                                continue;
 
                        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);
                }
 
                exit_configuration(&config_tree);
index b2124a0..e129a95 100644 (file)
@@ -64,6 +64,8 @@ typedef struct subnet_t {
 
 #define MAXNETSTR 64
 
 
 #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 *);
 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 *);