Configure minimum reconnect timeouts.
[tinc] / src / net_setup.c
index 60335fd..a00a321 100644 (file)
@@ -1,7 +1,7 @@
 /*
     net_setup.c -- Setup.
     Copyright (C) 1998-2005 Ivo Timmermans,
-                  2000-2013 Guus Sliepen <guus@tinc-vpn.org>
+                  2000-2014 Guus Sliepen <guus@tinc-vpn.org>
                   2006      Scott Lamb <slamb@slamb.org>
                   2010      Brandon Black <blblack@gmail.com>
 
@@ -404,6 +404,7 @@ static bool setup_myself(void) {
                        proxytype = PROXY_EXEC;
                } else {
                        logger(LOG_ERR, "Unknown proxy type %s!", proxy);
+                       free(proxy);
                        return false;
                }
 
@@ -415,6 +416,7 @@ static bool setup_myself(void) {
                        case PROXY_EXEC:
                                if(!space || !*space) {
                                        logger(LOG_ERR, "Argument expected for proxy type exec!");
+                                       free(proxy);
                                        return false;
                                }
                                proxyhost =  xstrdup(space);
@@ -433,6 +435,7 @@ static bool setup_myself(void) {
                                        *space++ = 0, proxypass = space;
                                if(!proxyhost || !*proxyhost || !proxyport || !*proxyport) {
                                        logger(LOG_ERR, "Host and port argument expected for proxy!");
+                                       free(proxy);
                                        return false;
                                }
                                proxyhost = xstrdup(proxyhost);
@@ -486,6 +489,7 @@ static bool setup_myself(void) {
                        routing_mode = RMODE_HUB;
                else {
                        logger(LOG_ERR, "Invalid routing mode!");
+                       free(mode);
                        return false;
                }
                free(mode);
@@ -500,6 +504,7 @@ static bool setup_myself(void) {
                        forwarding_mode = FMODE_KERNEL;
                else {
                        logger(LOG_ERR, "Invalid forwarding mode!");
+                       free(mode);
                        return false;
                }
                free(mode);
@@ -526,6 +531,7 @@ static bool setup_myself(void) {
                        broadcast_mode = BMODE_DIRECT;
                else {
                        logger(LOG_ERR, "Invalid broadcast mode!");
+                       free(mode);
                        return false;
                }
                free(mode);
@@ -547,6 +553,18 @@ static bool setup_myself(void) {
        } else
                maxtimeout = 900;
 
+       if(get_config_int(lookup_config(config_tree, "MinTimeout"), &mintimeout)) {
+                       if(mintimeout < 0) {
+                               logger(LOG_ERR, "Bogus minimum timeout!");
+                               return false;
+                       }
+                       if(mintimeout > maxtimeout) {
+                               logger(LOG_WARNING, "Minimum timeout (%d s) cannot be larger than maximum timeout (%d s). Correcting !", mintimeout, maxtimeout );
+                               mintimeout=maxtimeout;
+                       }
+               } else
+                       mintimeout = 0;
+
        if(get_config_int(lookup_config(config_tree, "UDPRcvBuf"), &udp_rcvbuf)) {
                if(udp_rcvbuf <= 0) {
                        logger(LOG_ERR, "UDPRcvBuf cannot be negative!");
@@ -707,6 +725,12 @@ static bool setup_myself(void) {
        xasprintf(&envp[2], "INTERFACE=%s", iface ? : "");
        xasprintf(&envp[3], "NAME=%s", myself->name);
 
+#ifdef HAVE_MINGW
+       Sleep(1000);
+#endif
+#ifdef HAVE_CYGWIN
+       sleep(1);
+#endif
        execute_script("tinc-up", envp);
 
        for(i = 0; i < 4; i++)