Don't try to call res_init() if ./configure told us it doesn't exist.
[tinc] / src / net_setup.c
index 9f25fb9..863616b 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-2015 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);
@@ -533,7 +539,12 @@ static bool setup_myself(void) {
 
 #if !defined(SOL_IP) || !defined(IP_TOS)
        if(priorityinheritance)
-               logger(LOG_WARNING, "%s not supported on this platform", "PriorityInheritance");
+               logger(LOG_WARNING, "%s not supported on this platform for IPv4 connection", "PriorityInheritance");
+#endif
+
+#if !defined(IPPROTO_IPV6) || !defined(IPV6_TCLASS)
+       if(priorityinheritance)
+               logger(LOG_WARNING, "%s not supported on this platform for IPv6 connection", "PriorityInheritance");
 #endif
 
        if(!get_config_int(lookup_config(config_tree, "MACExpire"), &macexpire))
@@ -547,6 +558,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!");
@@ -578,6 +601,7 @@ static bool setup_myself(void) {
                        addressfamily = AF_UNSPEC;
                else {
                        logger(LOG_ERR, "Invalid address family!");
+                       free(afname);
                        return false;
                }
                free(afname);
@@ -595,6 +619,7 @@ static bool setup_myself(void) {
 
                        if(!myself->incipher) {
                                logger(LOG_ERR, "Unrecognized cipher type!");
+                               free(cipher);
                                return false;
                        }
                }
@@ -705,6 +730,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++)
@@ -782,6 +813,10 @@ static bool setup_myself(void) {
                        hint.ai_protocol = IPPROTO_TCP;
                        hint.ai_flags = AI_PASSIVE;
 
+#if HAVE_DECL_RES_INIT
+                       // ensure glibc reloads /etc/resolv.conf.
+                       res_init();
+#endif
                        err = getaddrinfo(address && *address ? address : NULL, port, &hint, &ai);
                        free(address);