pass section name instead of specific option via IPC
authorChristian Grothoff <christian@grothoff.org>
Thu, 5 Jan 2017 20:23:02 +0000 (21:23 +0100)
committerChristian Grothoff <christian@grothoff.org>
Thu, 5 Jan 2017 20:23:02 +0000 (21:23 +0100)
doc/man/gnunet-nat.1
src/include/gnunet_nat_service.h
src/nat/gnunet-nat.c
src/nat/gnunet-service-nat.c
src/nat/nat.h
src/nat/nat_api.c
src/transport/transport.conf.in

index a834a1d9652f70dd0c14c29404fa1d98d5a8fd9e..01e0267a4e74966e4a98a9f1374fad1f6fd7ad1f 100644 (file)
@@ -39,8 +39,8 @@ Assuming we are listening at ADDRESS for connection reversal requests.
 Ask the peer at ADDRESS for connection reversal, using the local address for the target address of the reversal.
 
 .B
-.IP "\-p ADDRESS,  \-\-punch=ADDRESS"
-A hole was punched manually through the NAT. We should use ADDRESS as our external hostname and port for advertising for incoming requests. The special hostname 'AUTO' can be used to indicate that GNUnet should determine the external IP address by other means (such as upnpc), and just take the port number from ADDRESS.
+.IP "\-S NAME,  \-\-section=NAME"
+Name of section in configuration file to use for additional options.
 
 .B
 .IP "\-s,  \-\-stun"
index 0dbc23e7425119b3b0b5239e49be125268b2c550..6b9650306f284ec5863a810ad3346fdddf650bbe 100644 (file)
@@ -185,8 +185,8 @@ struct GNUNET_NAT_Handle;
  * address_callback for any 'plausible' external address.
  *
  * @param cfg configuration to use
+ * @param config_section name of the configuration section for optionsx
  * @param proto protocol this is about, IPPROTO_TCP or IPPROTO_UDP
- * @param hole_external hostname and port of manually punched hole in NAT, otherwise NULL (or empty string)
  * @param num_addrs number of addresses in @a addrs
  * @param addrs list of local addresses packets should be redirected to
  * @param addrlens actual lengths of the addresses in @a addrs
@@ -198,8 +198,8 @@ struct GNUNET_NAT_Handle;
  */
 struct GNUNET_NAT_Handle *
 GNUNET_NAT_register (const struct GNUNET_CONFIGURATION_Handle *cfg,
+                     const char *config_section,
                      uint8_t proto,
-                     const char *hole_external,
                      unsigned int num_addrs,
                      const struct sockaddr **addrs,
                      const socklen_t *addrlens,
index 81e4549b5d2763c07e6c566a6ff8d200543a5895..4171babf941347db90378806e72d674143f70f41 100644 (file)
@@ -39,10 +39,10 @@ static int global_ret;
 static struct GNUNET_NAT_AutoHandle *ah;
 
 /**
- * External hostname and port, if user manually punched
- * the NAT.  
+ * Name of section in configuration file to use for 
+ * additional options.
  */ 
-static char *hole_external;
+static char *section_name;
 
 /**
  * Flag set to 1 if we use IPPROTO_UDP.
@@ -568,8 +568,8 @@ run (void *cls,
   if (NULL != local_addr)
   {
     nh = GNUNET_NAT_register (c,
+                             section_name,
                              proto,
-                             hole_external,
                              1,
                              (const struct sockaddr **) &local_sa,
                              &local_len,
@@ -698,9 +698,9 @@ main (int argc,
     {'r', "remote", "ADDRESS",
      gettext_noop ("which remote IP and port should be asked for connection reversal"),
      GNUNET_YES, &GNUNET_GETOPT_set_string, &remote_addr },
-    {'p', "punched", NULL,
-     gettext_noop ("external hostname and port of NAT, if punched manually; use AUTO for hostname for automatic determination of the external IP"),
-     GNUNET_YES, &GNUNET_GETOPT_set_string, &hole_external },
+    {'S', "section", NULL,
+     gettext_noop ("name of configuration section to find additional options, such as manual host punching data"),
+     GNUNET_YES, &GNUNET_GETOPT_set_string, &section_name },
     {'s', "stun", NULL,
      gettext_noop ("enable STUN processing"),
      GNUNET_NO, &GNUNET_GETOPT_set_one, &do_stun },
index 8af27af9ee3e5db0596a883c4f6f618659369a15..79f806f271417bb2a22b58d82ccd07530deaaa00 100644 (file)
@@ -30,8 +30,6 @@
  * TODO:
  * - test and document (!) ICMP based NAT traversal
  * - test manual hole punching support
- * - consider passing transport plugin name instead of
- *   external IP address string (more flexible!)
  * - adapt existing transports to use new NAT logic
  * - abandon legacy NAT code
  *
@@ -185,6 +183,11 @@ struct ClientHandle
    */
   char *hole_external;
 
+  /**
+   * Name of the configuration section this client cares about.
+   */
+  char *section_name;
+
   /**
    * Task for periodically re-running the @e ext_dns DNS lookup.
    */ 
@@ -505,7 +508,7 @@ check_register (void *cls,
     off += alen;
     left -= alen;
   }
-  if (left != ntohs (message->hole_external_len))
+  if (left != ntohs (message->str_len))
   {
     GNUNET_break (0);
     return GNUNET_SYSERR;      
@@ -1575,10 +1578,14 @@ handle_register (void *cls,
     off += alen;
   }
 
-  ch->hole_external
+  ch->section_name
     = GNUNET_strndup (off,
-                     ntohs (message->hole_external_len));
-  if (0 != ntohs (message->hole_external_len))
+                     ntohs (message->str_len));
+  if (GNUNET_OK ==
+      GNUNET_CONFIGURATION_get_value_string (cfg,
+                                            ch->section_name,
+                                            "HOLE_EXTERNAL",
+                                            &ch->hole_external))
     lookup_hole_external (ch);
   
   /* Actually send IP address list to client */
@@ -2352,6 +2359,7 @@ client_disconnect_cb (void *cls,
     ch->ext_dns = NULL;
   }
   GNUNET_free (ch->hole_external);
+  GNUNET_free (ch->section_name);
   GNUNET_free (ch);
 }
 
index af418c7c248bc15b7fcd1de81b36f53b1f461fad..02bae71e90fc4512e2d763641db2e0ce5550111e 100644 (file)
@@ -29,6 +29,7 @@
 #include "gnunet_util_lib.h"
 
 
+
 GNUNET_NETWORK_STRUCT_BEGIN
 
 /**
@@ -111,10 +112,9 @@ struct GNUNET_NAT_RegisterMessage
 
   /**
    * Number of bytes in the string that follow which
-   * specify the hostname and port of a manually punched
-   * hole for this client.
+   * specifies a section name in the configuration.
    */
-  uint16_t hole_external_len GNUNET_PACKED;
+  uint16_t str_len GNUNET_PACKED;
 
   /**
    * Number of addresses that this service is bound to that follow.
@@ -126,8 +126,7 @@ struct GNUNET_NAT_RegisterMessage
   /* Followed by @e num_addrs addresses of type 'struct
      sockaddr' */
 
-  /* Followed by @e hole_external_len bytes giving a hostname
-     and port */
+  /* Followed by @e str_len section name to use for options */
   
 };
 
index 008ad19e4a5be51ea4add786b2ad97784db25b90..06b4b99fa4e213486ee7078524b4745ff9955796 100644 (file)
@@ -368,8 +368,8 @@ do_connect (void *cls)
  * address_callback for any 'plausible' external address.
  *
  * @param cfg configuration to use
+ * @param config_section name of the configuration section for optionsx
  * @param proto protocol this is about, IPPROTO_TCP or IPPROTO_UDP
- * @param hole_external hostname and port of manually punched hole in NAT, otherwise NULL (or empty string)
  * @param num_addrs number of addresses in @a addrs
  * @param addrs list of local addresses packets should be redirected to
  * @param addrlens actual lengths of the addresses in @a addrs
@@ -381,8 +381,8 @@ do_connect (void *cls)
  */
 struct GNUNET_NAT_Handle *
 GNUNET_NAT_register (const struct GNUNET_CONFIGURATION_Handle *cfg,
+                     const char *config_section,
                      uint8_t proto,
-                     const char *hole_external,
                      unsigned int num_addrs,
                      const struct sockaddr **addrs,
                      const socklen_t *addrlens,
@@ -393,17 +393,14 @@ GNUNET_NAT_register (const struct GNUNET_CONFIGURATION_Handle *cfg,
   struct GNUNET_NAT_Handle *nh;
   struct GNUNET_NAT_RegisterMessage *rm;
   size_t len;
-  size_t hole_external_len;
+  size_t str_len;
   char *off;
   
   len = 0;
   for (unsigned int i=0;i<num_addrs;i++)
     len += addrlens[i];
-  hole_external_len
-    = (NULL == hole_external)
-    ? 0
-    : strlen (hole_external);
-  len += hole_external_len;
+  str_len = strlen (config_section) + 1;
+  len += str_len;
   if ( (len > GNUNET_SERVER_MAX_MESSAGE_SIZE - sizeof (*rm)) ||
        (num_addrs > UINT16_MAX) )
   {
@@ -419,7 +416,7 @@ GNUNET_NAT_register (const struct GNUNET_CONFIGURATION_Handle *cfg,
   if (NULL != reversal_callback)
     rm->flags |= GNUNET_NAT_RF_REVERSAL;
   rm->proto = proto;
-  rm->hole_external_len = htons (hole_external_len);
+  rm->str_len = htons (str_len);
   rm->num_addrs = htons ((uint16_t) num_addrs);
   off = (char *) &rm[1];
   for (unsigned int i=0;i<num_addrs;i++)
@@ -459,8 +456,8 @@ GNUNET_NAT_register (const struct GNUNET_CONFIGURATION_Handle *cfg,
     off += addrlens[i];
   }
   GNUNET_memcpy (off,
-                hole_external,
-                hole_external_len);
+                config_section,
+                str_len);
 
   nh = GNUNET_new (struct GNUNET_NAT_Handle);
   nh->reg = &rm->header;
index 95e3f99446bebf025a84f7eed8e4927926e1f2d1..4e9f17f771460cb7fb3d23726392b3a52aabb044 100644 (file)
@@ -55,6 +55,9 @@ MAX_CONNECTIONS = 128
 # Enable TCP stealth?
 TCP_STEALTH = NO
 
+# Configuration for manually punched holes in NAT.
+# HOLE_EXTERNAL = auto:2086
+
 [transport-udp]
 # Use PORT = 0 to autodetect a port available
 PORT = 2086
@@ -69,6 +72,9 @@ BROADCAST_INTERVAL = 30 s
 MAX_BPS = 1000000
 TESTING_IGNORE_KEYS = ACCEPT_FROM;
 
+# Configuration for manually punched holes in NAT.
+# HOLE_EXTERNAL = auto:2086
+
 [transport-http_client]
 MAX_CONNECTIONS = 128
 TESTING_IGNORE_KEYS = ACCEPT_FROM;
@@ -99,6 +105,9 @@ TESTING_IGNORE_KEYS = ACCEPT_FROM;
 # Enable TCP stealth?
 TCP_STEALTH = NO
 
+# Configuration for manually punched holes in NAT.
+# HOLE_EXTERNAL = auto:2086
+
 [transport-https_client]
 MAX_CONNECTIONS = 128
 TESTING_IGNORE_KEYS = ACCEPT_FROM;
@@ -140,6 +149,10 @@ TESTING_IGNORE_KEYS = ACCEPT_FROM;
 # Enable TCP stealth?
 TCP_STEALTH = NO
 
+# Configuration for manually punched holes in NAT.
+# HOLE_EXTERNAL = auto:2086
+
+
 [transport-wlan]
 # Name of the interface in monitor mode (typically monX)
 INTERFACE = mon0