Make broadcast addresses configurable.
[tinc] / src / subnet.c
index bf4300e..23160e5 100644 (file)
@@ -29,7 +29,7 @@
 #include "net.h"
 #include "netutl.h"
 #include "node.h"
-#include "process.h"
+#include "script.h"
 #include "subnet.h"
 #include "utils.h"
 #include "xalloc.h"
@@ -92,13 +92,15 @@ void subnet_add(node_t *n, subnet_t *subnet) {
        subnet->owner = n;
 
        splay_insert(subnet_tree, subnet);
-       splay_insert(n->subnet_tree, subnet);
+       if (n)
+               splay_insert(n->subnet_tree, subnet);
 
        subnet_cache_flush();
 }
 
 void subnet_del(node_t *n, subnet_t *subnet) {
-       splay_delete(n->subnet_tree, subnet);
+       if (n)
+               splay_delete(n->subnet_tree, subnet);
        splay_delete(subnet_tree, subnet);
 
        subnet_cache_flush();
@@ -126,7 +128,7 @@ subnet_t *lookup_subnet_mac(const node_t *owner, const mac_t *address) {
 
                if(!memcmp(address, &p->net.mac.address, sizeof *address)) {
                        r = p;
-                       if(p->owner->status.reachable)
+                       if(!p->owner || p->owner->status.reachable)
                                break;
                }
        }
@@ -155,7 +157,7 @@ subnet_t *lookup_subnet_ipv4(const ipv4_t *address) {
 
                if(!maskcmp(address, &p->net.ipv4.address, p->net.ipv4.prefixlength)) {
                        r = p;
-                       if(p->owner->status.reachable)
+                       if(!p->owner || p->owner->status.reachable)
                                break;
                }
        }
@@ -184,7 +186,7 @@ subnet_t *lookup_subnet_ipv6(const ipv6_t *address) {
 
                if(!maskcmp(address, &p->net.ipv6.address, p->net.ipv6.prefixlength)) {
                        r = p;
-                       if(p->owner->status.reachable)
+                       if(!p->owner || p->owner->status.reachable)
                                break;
                }
        }
@@ -204,7 +206,7 @@ void subnet_update(node_t *owner, subnet_t *subnet, bool up) {
 
        // Prepare environment variables to be passed to the script
 
-       char *envp[9] = {NULL};
+       char *envp[10] = {NULL};
        xasprintf(&envp[0], "NETNAME=%s", netname ? : "");
        xasprintf(&envp[1], "DEVICE=%s", device ? : "");
        xasprintf(&envp[2], "INTERFACE=%s", iface ? : "");
@@ -219,6 +221,8 @@ void subnet_update(node_t *owner, subnet_t *subnet, bool up) {
                free(address);
        }
 
+       xasprintf(&envp[8], "NAME=%s", myself->name);
+
        name = up ? "subnet-up" : "subnet-down";
 
        if(!subnet) {
@@ -260,7 +264,7 @@ void subnet_update(node_t *owner, subnet_t *subnet, bool up) {
                }
        }
 
-       for(int i = 0; envp[i] && i < 8; i++)
+       for(int i = 0; envp[i] && i < 9; i++)
                free(envp[i]);
 }