Don't call terminate_connection(myself->connection).
[tinc] / src / net_setup.c
index 23dd252..30e6f84 100644 (file)
@@ -1,7 +1,7 @@
 /*
     net_setup.c -- Setup.
     Copyright (C) 1998-2005 Ivo Timmermans,
-                  2000-2015 Guus Sliepen <guus@tinc-vpn.org>
+                  2000-2016 Guus Sliepen <guus@tinc-vpn.org>
                   2006      Scott Lamb <slamb@slamb.org>
                   2010      Brandon Black <blblack@gmail.com>
 
 #include "utils.h"
 #include "xalloc.h"
 
+#ifdef HAVE_MINIUPNPC
+#include "upnp.h"
+#endif
+
 char *myport;
 static char *myname;
 static io_t device_io;
@@ -587,9 +591,14 @@ bool setup_myself_reloadable(void) {
                subnet_add(NULL, s);
        }
 
-#if !defined(SOL_IP) || !defined(IP_TOS)
+#if !defined(IPPROTO_IP) || !defined(IP_TOS)
+       if(priorityinheritance)
+               logger(DEBUG_ALWAYS, LOG_WARNING, "%s not supported on this platform for IPv4 connections", "PriorityInheritance");
+#endif
+
+#if !defined(IPPROTO_IPV6) || !defined(IPV6_TCLASS)
        if(priorityinheritance)
-               logger(DEBUG_ALWAYS, LOG_WARNING, "%s not supported on this platform", "PriorityInheritance");
+               logger(DEBUG_ALWAYS, LOG_WARNING, "%s not supported on this platform for IPv6 connections", "PriorityInheritance");
 #endif
 
        if(!get_config_int(lookup_config(config_tree, "MACExpire"), &macexpire))
@@ -1059,6 +1068,25 @@ static bool setup_myself(void) {
        xasprintf(&myself->hostname, "MYSELF port %s", myport);
        myself->connection->hostname = xstrdup(myself->hostname);
 
+       char *upnp = NULL;
+       get_config_string(lookup_config(config_tree, "UPnP"), &upnp);
+       bool upnp_tcp = false;
+       bool upnp_udp = false;
+       if (upnp) {
+               if (!strcasecmp(upnp, "yes"))
+                       upnp_tcp = upnp_udp = true;
+               else if (!strcasecmp(upnp, "udponly"))
+                       upnp_udp = true;
+               free(upnp);
+       }
+       if (upnp_tcp || upnp_udp) {
+#ifdef HAVE_MINIUPNPC
+               upnp_init(upnp_tcp, upnp_udp);
+#else
+               logger(DEBUG_ALWAYS, LOG_WARNING, "UPnP was requested, but tinc isn't built with miniupnpc support!");
+#endif
+       }
+
        /* Done. */
 
        last_config_check = now.tv_sec;
@@ -1126,8 +1154,7 @@ void close_network_connections(void) {
 
        if(myself && myself->connection) {
                subnet_update(myself, NULL, false);
-               terminate_connection(myself->connection, false);
-               free_connection(myself->connection);
+               connection_del(myself->connection);
        }
 
        for(int i = 0; i < listen_sockets; i++) {