REST/NAMESTORE: rework API
[oweals/gnunet.git] / src / transport / plugin_transport_tcp.c
index b1f7900f253a1c517a2903d07c6b1e8b947505ee..a0dd8061701545cfebcf854af1dc8b5e02dee01d 100644 (file)
@@ -3,7 +3,7 @@
   Copyright (C) 2002--2015 GNUnet e.V.
 
   GNUnet is free software: you can redistribute it and/or modify it
-  under the terms of the GNU General Public License as published
+  under the terms of the GNU Affero General Public License as published
   by the Free Software Foundation, either version 3 of the License,
   or (at your option) any later version.
 
   WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Affero General Public License for more details.
+
+  You should have received a copy of the GNU Affero General Public License
+  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+     SPDX-License-Identifier: AGPL3.0-or-later
  */
 /**
  * @file transport/plugin_transport_tcp.c
@@ -856,7 +861,7 @@ struct GNUNET_ATS_Session
   /**
    * Network type of the address.
    */
-  enum GNUNET_ATS_Network_Type scope;
+  enum GNUNET_NetworkType scope;
 
   /**
    * Are we still expecting the welcome message? (#GNUNET_YES/#GNUNET_NO)
@@ -1425,6 +1430,8 @@ notify_session_monitor (struct Plugin *plugin,
  * Our external IP address/port mapping has changed.
  *
  * @param cls closure, the `struct Plugin`
+ * @param app_ctx[in,out] location where the app can store stuff
+ *                  on add and retrieve it on remove
  * @param add_remove #GNUNET_YES to mean the new public IP address, #GNUNET_NO to mean
  *     the previous (now invalid) one
  * @param ac address class the address belongs to
@@ -1433,6 +1440,7 @@ notify_session_monitor (struct Plugin *plugin,
  */
 static void
 tcp_nat_port_map_callback (void *cls,
+                          void **app_ctx,
                            int add_remove,
                           enum GNUNET_NAT_AddressClass ac,
                           const struct sockaddr *addr,
@@ -1445,6 +1453,7 @@ tcp_nat_port_map_callback (void *cls,
   void *arg;
   size_t args;
 
+  (void) app_ctx;
   LOG (GNUNET_ERROR_TYPE_INFO,
        "NAT notification to %s address `%s'\n",
        (GNUNET_YES == add_remove) ? "add" : "remove",
@@ -1462,6 +1471,12 @@ tcp_nat_port_map_callback (void *cls,
     args = sizeof (t4);
     break;
   case AF_INET6:
+    if (IN6_IS_ADDR_LINKLOCAL (&((struct sockaddr_in6 *) addr)->sin6_addr))
+    {
+      /* skip link local, we don't allow them in
+         #tcp_plugin_check_address() */
+      return;
+    }
     GNUNET_assert(addrlen == sizeof(struct sockaddr_in6));
     memset (&t6, 0, sizeof(t6));
     GNUNET_memcpy (&t6.ipv6_addr,
@@ -1887,7 +1902,7 @@ reschedule_session_timeout (struct GNUNET_ATS_Session *s)
 static struct GNUNET_ATS_Session *
 create_session (struct Plugin *plugin,
                 const struct GNUNET_HELLO_Address *address,
-                enum GNUNET_ATS_Network_Type scope,
+                enum GNUNET_NetworkType scope,
                 struct GNUNET_SERVER_Client *client,
                 int is_nat)
 {
@@ -2433,7 +2448,7 @@ tcp_plugin_get_session (void *cls,
   const struct IPv4TcpAddress *t4;
   const struct IPv6TcpAddress *t6;
   unsigned int options;
-  enum GNUNET_ATS_Network_Type net_type;
+  enum GNUNET_NetworkType net_type;
   unsigned int is_natd = GNUNET_NO;
   size_t addrlen;
 #ifdef TCP_STEALTH
@@ -2536,7 +2551,7 @@ tcp_plugin_get_session (void *cls,
   net_type = plugin->env->get_address_type (plugin->env->cls,
                                             sb,
                                             sbs);
-  GNUNET_break (net_type != GNUNET_ATS_NET_UNSPECIFIED);
+  GNUNET_break (net_type != GNUNET_NT_UNSPECIFIED);
 
   if ( (is_natd == GNUNET_YES) &&
        (addrlen == sizeof(struct IPv6TcpAddress)) )
@@ -3260,7 +3275,7 @@ handle_tcp_welcome (void *cls,
                                                                alen),
                                 client,
                                 GNUNET_NO);
-      GNUNET_break (GNUNET_ATS_NET_UNSPECIFIED != session->scope);
+      GNUNET_break (GNUNET_NT_UNSPECIFIED != session->scope);
       GNUNET_HELLO_address_free (address);
       LOG (GNUNET_ERROR_TYPE_DEBUG,
            "Creating new%s session %p for peer `%s' client %p\n",
@@ -3620,7 +3635,7 @@ try_connection_reversal (void *cls,
  * @param session the session
  * @return the network type in HBO or #GNUNET_SYSERR
  */
-static enum GNUNET_ATS_Network_Type
+static enum GNUNET_NetworkType
 tcp_plugin_get_network (void *cls,
                         struct GNUNET_ATS_Session *session)
 {
@@ -3635,7 +3650,7 @@ tcp_plugin_get_network (void *cls,
  * @param address the address
  * @return the network type
  */
-static enum GNUNET_ATS_Network_Type
+static enum GNUNET_NetworkType
 tcp_plugin_get_network_for_address (void *cls,
                                     const struct GNUNET_HELLO_Address *address)
 {
@@ -3680,7 +3695,7 @@ tcp_plugin_get_network_for_address (void *cls,
   else
   {
     GNUNET_break (0);
-    return GNUNET_ATS_NET_UNSPECIFIED;
+    return GNUNET_NT_UNSPECIFIED;
   }
   return plugin->env->get_address_type (plugin->env->cls,
                                         sb,