Add LocalDiscovery option which tries to detect peers on the local network.
[tinc] / src / net_setup.c
index 3268f5d..bab50fe 100644 (file)
@@ -356,6 +356,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 +398,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)
@@ -578,47 +581,58 @@ static bool setup_myself(void) {
 
        /* Open sockets */
 
-       get_config_string(lookup_config(config_tree, "BindToAddress"), &address);
+       listen_sockets = 0;
+       cfg = lookup_config(config_tree, "BindToAddress");
 
-       hint.ai_family = addressfamily;
-       hint.ai_socktype = SOCK_STREAM;
-       hint.ai_protocol = IPPROTO_TCP;
-       hint.ai_flags = AI_PASSIVE;
+       do {
+               get_config_string(cfg, &address);
+               if(cfg)
+                       cfg = lookup_config_next(config_tree, cfg);
 
-       err = getaddrinfo(address, myport, &hint, &ai);
+               hint.ai_family = addressfamily;
+               hint.ai_socktype = SOCK_STREAM;
+               hint.ai_protocol = IPPROTO_TCP;
+               hint.ai_flags = AI_PASSIVE;
 
-       if(err || !ai) {
-               logger(LOG_ERR, "System call `%s' failed: %s", "getaddrinfo",
-                          gai_strerror(err));
-               return false;
-       }
+               err = getaddrinfo(address, myport, &hint, &ai);
+               free(address);
 
-       listen_sockets = 0;
+               if(err || !ai) {
+                       logger(LOG_ERR, "System call `%s' failed: %s", "getaddrinfo",
+                                  gai_strerror(err));
+                       return false;
+               }
 
-       for(aip = ai; aip; aip = aip->ai_next) {
-               listen_socket[listen_sockets].tcp =
-                       setup_listen_socket((sockaddr_t *) aip->ai_addr);
+               for(aip = ai; aip; aip = aip->ai_next) {
+                       if(listen_sockets >= MAXSOCKETS) {
+                               logger(LOG_ERR, "Too many listening sockets");
+                               return false;
+                       }
 
-               if(listen_socket[listen_sockets].tcp < 0)
-                       continue;
+                       listen_socket[listen_sockets].tcp =
+                               setup_listen_socket((sockaddr_t *) aip->ai_addr);
 
-               listen_socket[listen_sockets].udp =
-                       setup_vpn_in_socket((sockaddr_t *) aip->ai_addr);
+                       if(listen_socket[listen_sockets].tcp < 0)
+                               continue;
 
-               if(listen_socket[listen_sockets].udp < 0)
-                       continue;
+                       listen_socket[listen_sockets].udp =
+                               setup_vpn_in_socket((sockaddr_t *) aip->ai_addr);
 
-               ifdebug(CONNECTIONS) {
-                       hostname = sockaddr2hostname((sockaddr_t *) aip->ai_addr);
-                       logger(LOG_NOTICE, "Listening on %s", hostname);
-                       free(hostname);
-               }
+                       if(listen_socket[listen_sockets].udp < 0)
+                               continue;
 
-               memcpy(&listen_socket[listen_sockets].sa, aip->ai_addr, aip->ai_addrlen);
-               listen_sockets++;
-       }
+                       ifdebug(CONNECTIONS) {
+                               hostname = sockaddr2hostname((sockaddr_t *) aip->ai_addr);
+                               logger(LOG_NOTICE, "Listening on %s", hostname);
+                               free(hostname);
+                       }
+
+                       memcpy(&listen_socket[listen_sockets].sa, aip->ai_addr, aip->ai_addrlen);
+                       listen_sockets++;
+               }
 
-       freeaddrinfo(ai);
+               freeaddrinfo(ai);
+       } while(cfg);
 
        if(listen_sockets)
                logger(LOG_NOTICE, "Ready");