Accept Subnets passed with the -o option when StrictSubnets = yes.
[oweals/tinc.git] / src / net_setup.c
index 279feaefd24a7b1c1f21e48cd69dfc0e70597e35..2684514392dac017d4b3faeba8f8b4aa510bce69 100644 (file)
@@ -1,7 +1,7 @@
 /*
     net_setup.c -- Setup.
     Copyright (C) 1998-2005 Ivo Timmermans,
-                  2000-2011 Guus Sliepen <guus@tinc-vpn.org>
+                  2000-2012 Guus Sliepen <guus@tinc-vpn.org>
                   2006      Scott Lamb <slamb@slamb.org>
                   2010      Brandon Black <blblack@gmail.com>
 
@@ -221,7 +221,6 @@ void load_all_subnets(void) {
        config_t *cfg;
        subnet_t *s, *s2;
        node_t *n;
-       bool result;
 
        xasprintf(&dname, "%s/hosts", confbase);
        dir = opendir(dname);
@@ -243,10 +242,9 @@ void load_all_subnets(void) {
 
                xasprintf(&fname, "%s/hosts/%s", confbase, ent->d_name);
                init_configuration(&config_tree);
-               result = read_config_file(config_tree, fname);
+               read_config_options(config_tree, ent->d_name);
+               read_config_file(config_tree, fname);
                free(fname);
-               if(!result)
-                       continue;
 
                if(!n) {
                        n = new_node();
@@ -356,6 +354,7 @@ static bool setup_myself(void) {
        get_config_bool(lookup_config(config_tree, "DirectOnly"), &directonly);
        get_config_bool(lookup_config(config_tree, "StrictSubnets"), &strictsubnets);
        get_config_bool(lookup_config(config_tree, "TunnelServer"), &tunnelserver);
+       get_config_bool(lookup_config(config_tree, "LocalDiscovery"), &localdiscovery);
        strictsubnets |= tunnelserver;
 
        if(get_config_string(lookup_config(config_tree, "Mode"), &mode)) {
@@ -397,6 +396,8 @@ static bool setup_myself(void) {
                myself->options |= OPTION_CLAMP_MSS;
 
        get_config_bool(lookup_config(config_tree, "PriorityInheritance"), &priorityinheritance);
+       get_config_bool(lookup_config(config_tree, "DecrementTTL"), &decrement_ttl);
+       get_config_bool(lookup_config(config_tree, "Broadcast"), &broadcast);
 
 #if !defined(SOL_IP) || !defined(IP_TOS)
        if(priorityinheritance)
@@ -540,6 +541,8 @@ static bool setup_myself(void) {
 
        /* Open device */
 
+       devops = os_devops;
+
        if(get_config_string(lookup_config(config_tree, "DeviceType"), &type)) {
                if(!strcasecmp(type, "dummy"))
                        devops = dummy_devops;
@@ -553,12 +556,6 @@ static bool setup_myself(void) {
                else if(!strcasecmp(type, "vde"))
                        devops = vde_devops;
 #endif
-               else {
-                       logger(LOG_ERR, "Unknown device type %s!", type);
-                       return false;
-               }
-       } else {
-               devops = os_devops;
        }
 
        if(!devops.setup())
@@ -582,6 +579,7 @@ static bool setup_myself(void) {
 
        /* Open sockets */
 
+       listen_sockets = 0;
        cfg = lookup_config(config_tree, "BindToAddress");
 
        do {
@@ -603,9 +601,12 @@ static bool setup_myself(void) {
                        return false;
                }
 
-               listen_sockets = 0;
-
                for(aip = ai; aip; aip = aip->ai_next) {
+                       if(listen_sockets >= MAXSOCKETS) {
+                               logger(LOG_ERR, "Too many listening sockets");
+                               return false;
+                       }
+
                        listen_socket[listen_sockets].tcp =
                                setup_listen_socket((sockaddr_t *) aip->ai_addr);