fix misc compilation issues in nat-auto
authorChristian Grothoff <christian@grothoff.org>
Tue, 10 Jan 2017 17:50:16 +0000 (18:50 +0100)
committerChristian Grothoff <christian@grothoff.org>
Tue, 10 Jan 2017 17:50:16 +0000 (18:50 +0100)
doc/man/gnunet-nat-auto.1
src/include/gnunet_nat_auto_service.h
src/nat-auto/gnunet-nat-auto.c
src/nat-auto/nat_auto_api_test.c
src/transport/plugin_transport_udp_broadcasting.c

index 310f14d4364972b6f5ec95549611f194263ce6e0..249d54da469b7691d7817d5ae3386f1503e644b3 100644 (file)
@@ -18,17 +18,13 @@ as attempting auto\-configuration.
 .IP "\-a,  \-\-auto"
 Attempt auto\-configuration for NAT traversal.
 
-.B
-.IP "\-b ADDRESS,  \-\-bind=ADDRESS"
-Assume that the service is (locally) bound to ADDRESS.
-
 .B
 .IP "\-c FILENAME,  \-\-config=FILENAME"
 Use the configuration file FILENAME.
 
 .B
-.IP "\-e ADDRESS,  \-\-external=ADDRESS"
-Assume that ADDRESS is the globally visible address of the peer.
+.IP "\-S NAME,  \-\-section=NAME"
+Name of the configuration section with details about the configuration to test. For example "transport-tcp".
 
 .IP "\-t,  \-\-tcp"
 Use TCP.
@@ -49,11 +45,25 @@ Write configuration to configuration file, useful in combination with autoconfig
 Probe and write result to configuration:
 
   # gnunet\-nat\-auto \-aw
-  
+
+
+\fBTest configuration:\fR
+
+Test TCP configuration:
+
+  # gnunet\-nat\-auto -t \-S transport-tcp
+
+Test HTTP configuration:
+
+  # gnunet\-nat\-auto -t \-S transport-http
+
+Test UDP configuration:
+
+  # gnunet\-nat\-auto -u \-S transport-udp
+
 
 .SH BUGS
 Report bugs by using Mantis <https://gnunet.org/bugs/> or by sending electronic mail to <gnunet\-developers@gnu.org>
 
 .SH SEE ALSO
 gnunet\-transport(1) gnunet\-nat(1)
-
index c458dc81a51f9f51390fc3a3731315b2a143af24..a369c49e05d3988ecd7ea26aba79d4d8596e750a 100644 (file)
@@ -45,16 +45,12 @@ struct GNUNET_NAT_AUTO_Test;
 
 
 /**
- * Start testing if NAT traversal works using the given configuration
- * (IPv4-only).  The transport adapters should be down while using
- * this function.
+ * Start testing if NAT traversal works using the given configuration.
+ *  The transport adapters should be down while using this function.
  *
  * @param cfg configuration for the NAT traversal
  * @param proto protocol to test, i.e. IPPROTO_TCP or IPPROTO_UDP
- * @param bind_ip IPv4 address to bind to
- * @param bnd_port port to bind to, 0 to test connection reversal
- * @param extern_ip IPv4 address to externally advertise
- * @param extern_port externally advertised port to use
+ * @param section_name configuration section to use for configuration
  * @param report function to call with the result of the test
  * @param report_cls closure for @a report
  * @return handle to cancel NAT test
@@ -62,10 +58,7 @@ struct GNUNET_NAT_AUTO_Test;
 struct GNUNET_NAT_AUTO_Test *
 GNUNET_NAT_AUTO_test_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
                            uint8_t proto,
-                           struct in_addr bind_ip,
-                           uint16_t bnd_port,
-                           struct in_addr extern_ip,
-                           uint16_t extern_port,
+                           const char *section_name,
                            GNUNET_NAT_TestCallback report,
                            void *report_cls);
 
index d411c6d75915d08337680e278daf1aa2394cf6b6..9ba81eb5f17f379bd1eddb5be49cf02a09122289 100644 (file)
@@ -47,7 +47,7 @@ static int write_cfg;
 
 /**
  * Configuration filename.
- */ 
+ */
 static const char *cfg_file;
 
 /**
@@ -56,16 +56,9 @@ static const char *cfg_file;
 static const struct GNUNET_CONFIGURATION_Handle *cfg;
 
 /**
- * Address we are bound to (in test), or should bind to
- * (if #do_stun is set).
- */
-static char *bind_addr;
-
-/**
- * External IP address and port to use for the test.
- * If not set, use #bind_addr.
+ * Adapter we are supposed to test.
  */
-static char *extern_addr;
+static char *section_name;
 
 /**
  * Should we run autoconfiguration?
@@ -122,7 +115,7 @@ auto_conf_iter (void *cls,
                 const char *value)
 {
   struct GNUNET_CONFIGURATION_Handle *new_cfg = cls;
-  
+
   PRINTF ("%s: %s\n",
          option,
          value);
@@ -192,7 +185,7 @@ auto_config_cb (void *cls,
   /* Apply diff to original configuration and show changes
      to the user */
   new_cfg = write_cfg ? GNUNET_CONFIGURATION_dup (cfg) : NULL;
-  
+
   if (NULL != diff)
   {
     GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
@@ -296,12 +289,9 @@ run (void *cls,
      const char *cfgfile,
      const struct GNUNET_CONFIGURATION_Handle *c)
 {
-  struct sockaddr_in bind_sa;
-  struct sockaddr_in extern_sa;
-
   cfg_file = cfgfile;
   cfg = c;
-  
+
   GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
                                 NULL);
 
@@ -327,45 +317,11 @@ run (void *cls,
   if (use_udp)
     proto = IPPROTO_UDP;
 
-  if (NULL != bind_addr)
-  {
-    if (GNUNET_OK !=
-       GNUNET_STRINGS_to_address_ipv4 (bind_addr,
-                                       strlen (bind_addr),
-                                       &bind_sa))
-    {
-      GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
-                 "Invalid socket address `%s'\n",
-                 bind_addr);
-      global_ret = 1;
-      return;
-    }
-  }
-  if (NULL != extern_addr)
-  {
-    if (GNUNET_OK !=
-       GNUNET_STRINGS_to_address_ipv4 (extern_addr,
-                                       strlen (extern_addr),
-                                       &extern_sa))
-    {
-      GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
-                 "Invalid socket address `%s'\n",
-                 extern_addr);
-      global_ret = 1;
-      return;
-    }
-  }
-
-  if (NULL != bind_addr)
+  if (NULL != section_name)
   {
-    if (NULL == extern_addr)
-      extern_sa = bind_sa;
     nt = GNUNET_NAT_AUTO_test_start (c,
                                     proto,
-                                    bind_sa.sin_addr,
-                                    ntohs (bind_sa.sin_port),
-                                    extern_sa.sin_addr,
-                                    ntohs (extern_sa.sin_port),
+                                    section_name,
                                     &test_report_cb,
                                     NULL);
   }
@@ -374,7 +330,7 @@ run (void *cls,
 
 
 /**
- * Main function of gnunet-nat
+ * Main function of gnunet-nat-auto
  *
  * @param argc number of command-line arguments
  * @param argv command line
@@ -388,12 +344,9 @@ main (int argc,
     {'a', "auto", NULL,
      gettext_noop ("run autoconfiguration"),
      GNUNET_NO, &GNUNET_GETOPT_set_one, &do_auto },
-    {'b', "bind", "ADDRESS",
-     gettext_noop ("which IP and port are we bound to"),
-     GNUNET_YES, &GNUNET_GETOPT_set_string, &bind_addr },
-    {'e', "external", "ADDRESS",
-     gettext_noop ("which external IP and port should be used to test"),
-     GNUNET_YES, &GNUNET_GETOPT_set_string, &extern_addr },
+    {'S', "section", "NAME",
+     gettext_noop ("section name providing the configuration for the adapter"),
+     GNUNET_YES, &GNUNET_GETOPT_set_string, &section_name },
     {'t', "tcp", NULL,
      gettext_noop ("use TCP"),
      GNUNET_NO, &GNUNET_GETOPT_set_one, &use_tcp },
index 8359e3cb5cdb8991ec4430fa7ea7ff1db55599d3..fb2bcd6798f318a7ae387da6afd0b7359522d375 100644 (file)
@@ -24,7 +24,8 @@
  */
 #include "platform.h"
 #include "gnunet_util_lib.h"
-#include "gnunet_nat_lib.h"
+#include "gnunet_nat_service.h"
+#include "gnunet_nat_auto_service.h"
 #include "nat-auto.h"
 
 #define LOG(kind,...) GNUNET_log_from (kind, "nat", __VA_ARGS__)
@@ -153,19 +154,19 @@ struct GNUNET_NAT_AUTO_Test
   struct GNUNET_SCHEDULER_Task *ttask;
 
   /**
-   * #GNUNET_YES if we're testing TCP
+   * Section name of plugin to test.
    */
-  int is_tcp;
+  char *section_name;
 
   /**
-   * Data that should be transmitted or source-port.
+   * IPPROTO_TCP or IPPROTO_UDP.
    */
-  uint16_t data;
+  int proto;
 
   /**
-   * Advertised port to the other peer.
+   * Data that should be transmitted or source-port.
    */
-  uint16_t adv_port;
+  uint16_t data;
 
   /**
    * Status code to be reported to the timeout/status call
@@ -358,12 +359,14 @@ mq_error_handler (void *cls,
  * @param cls closure
  * @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
  * @param addr either the previous or the new public IP address
  * @param addrlen actual length of the @a addr
  */
 static void
 addr_cb (void *cls,
          int add_remove,
+         enum GNUNET_NAT_AddressClass ac,
          const struct sockaddr *addr,
          socklen_t addrlen)
 {
@@ -411,58 +414,50 @@ addr_cb (void *cls,
   msg->dst_ipv4 = sa->sin_addr.s_addr;
   msg->dport = sa->sin_port;
   msg->data = h->data;
-  msg->is_tcp = htonl ((uint32_t) h->is_tcp);
+  msg->is_tcp = htonl ((uint32_t) (h->proto == IPPROTO_TCP));
   GNUNET_MQ_send (ca->mq,
                   env);
 }
 
 
 /**
- * Timeout task for a nat test.
- * Calls the report-callback with a timeout return value
+ * Calls the report-callback reporting failure.
  *
  * Destroys the nat handle after the callback has been processed.
  *
  * @param cls handle to the timed out NAT test
  */
 static void
-do_timeout (void *cls)
+do_fail (void *cls)
 {
   struct GNUNET_NAT_AUTO_Test *nh = cls;
 
   nh->ttask = NULL;
   nh->report (nh->report_cls,
-              (GNUNET_NAT_ERROR_SUCCESS == nh->status)
-              ? GNUNET_NAT_ERROR_TIMEOUT
-              : nh->status);
+              nh->status);
 }
 
 
 /**
- * Start testing if NAT traversal works using the
- * given configuration (IPv4-only).
- *
- * ALL failures are reported directly to the report callback
+ * Start testing if NAT traversal works using the given configuration.
+ *  The transport adapters should be down while using this function.
  *
  * @param cfg configuration for the NAT traversal
- * @param is_tcp #GNUNET_YES to test TCP, #GNUNET_NO to test UDP
- * @param bnd_port port to bind to, 0 for connection reversal
- * @param adv_port externally advertised port to use
- * @param timeout delay after which the test should be aborted
+ * @param proto protocol to test, i.e. IPPROTO_TCP or IPPROTO_UDP
+ * @param section_name configuration section to use for configuration
  * @param report function to call with the result of the test
  * @param report_cls closure for @a report
- * @return handle to cancel NAT test or NULL. The error is always indicated via the report callback
+ * @return handle to cancel NAT test
  */
 struct GNUNET_NAT_AUTO_Test *
 GNUNET_NAT_AUTO_test_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
-                       int is_tcp,
-                       uint16_t bnd_port,
-                       uint16_t adv_port,
-                       struct GNUNET_TIME_Relative timeout,
-                       GNUNET_NAT_TestCallback report,
-                       void *report_cls)
+                           uint8_t proto,
+                           const char *section_name,
+                           GNUNET_NAT_TestCallback report,
+                           void *report_cls)
 {
   struct GNUNET_NAT_AUTO_Test *nh;
+  unsigned long long bnd_port;
   struct sockaddr_in sa;
   const struct sockaddr *addrs[] = {
     (const struct sockaddr *) &sa
@@ -471,18 +466,30 @@ GNUNET_NAT_AUTO_test_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
     sizeof (sa)
   };
 
+  if ( (GNUNET_OK !=
+        GNUNET_CONFIGURATION_get_value_number (cfg,
+                                               section_name,
+                                               "PORT",
+                                               &bnd_port)) ||
+       (bnd_port > 65535) )
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                _("Failed to find valid PORT in section `%s'\n"),
+                section_name);
+    return NULL;
+  }
+
   memset (&sa, 0, sizeof (sa));
   sa.sin_family = AF_INET;
-  sa.sin_port = htons (bnd_port);
+  sa.sin_port = htons ((uint16_t) bnd_port);
 #if HAVE_SOCKADDR_IN_SIN_LEN
   sa.sin_len = sizeof (sa);
 #endif
 
   nh = GNUNET_new (struct GNUNET_NAT_AUTO_Test);
   nh->cfg = cfg;
-  nh->is_tcp = is_tcp;
-  nh->data = bnd_port;
-  nh->adv_port = adv_port;
+  nh->proto = proto;
+  nh->section_name = GNUNET_strdup (section_name);
   nh->report = report;
   nh->report_cls = report_cls;
   nh->status = GNUNET_NAT_ERROR_SUCCESS;
@@ -490,28 +497,24 @@ GNUNET_NAT_AUTO_test_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
   {
     nh->nat
       = GNUNET_NAT_register (cfg,
-                             is_tcp,
-                             0,
-                             0,
-                            NULL,
-                             NULL,
+                             section_name,
+                             proto,
+                             0, NULL, NULL,
                             &addr_cb,
                              &reversal_cb,
-                             nh,
-                             NULL);
+                             nh);
   }
   else
   {
-    nh->lsock =
-        GNUNET_NETWORK_socket_create (AF_INET,
-                                      (is_tcp ==
-                                       GNUNET_YES) ? SOCK_STREAM : SOCK_DGRAM,
+    nh->lsock
+      = GNUNET_NETWORK_socket_create (AF_INET,
+                                      proto,
                                       0);
-    if ((nh->lsock == NULL) ||
-        (GNUNET_OK !=
-         GNUNET_NETWORK_socket_bind (nh->lsock,
-                                     (const struct sockaddr *) &sa,
-                                     sizeof (sa))))
+    if ( (NULL == nh->lsock) ||
+         (GNUNET_OK !=
+          GNUNET_NETWORK_socket_bind (nh->lsock,
+                                      (const struct sockaddr *) &sa,
+                                      sizeof (sa))))
     {
       GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                   _("Failed to create listen socket bound to `%s' for NAT test: %s\n"),
@@ -524,11 +527,11 @@ GNUNET_NAT_AUTO_test_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
         nh->lsock = NULL;
       }
       nh->status = GNUNET_NAT_ERROR_INTERNAL_NETWORK_ERROR;
-      nh->ttask = GNUNET_SCHEDULER_add_now (&do_timeout,
+      nh->ttask = GNUNET_SCHEDULER_add_now (&do_fail,
                                             nh);
       return nh;
     }
-    if (GNUNET_YES == is_tcp)
+    if (IPPROTO_TCP == proto)
     {
       GNUNET_break (GNUNET_OK ==
                     GNUNET_NETWORK_socket_listen (nh->lsock,
@@ -550,17 +553,16 @@ GNUNET_NAT_AUTO_test_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
     LOG (GNUNET_ERROR_TYPE_INFO,
         "NAT test listens on port %u (%s)\n",
         bnd_port,
-        (GNUNET_YES == is_tcp) ? "tcp" : "udp");
+        (IPPROTO_TCP == proto) ? "tcp" : "udp");
     nh->nat = GNUNET_NAT_register (cfg,
-                                   is_tcp,
-                                   adv_port,
+                                   section_name,
+                                   proto,
                                    1,
                                    addrs,
                                    addrlens,
                                    &addr_cb,
                                    NULL,
-                                   nh,
-                                   NULL);
+                                   nh);
     if (NULL == nh->nat)
     {
       LOG (GNUNET_ERROR_TYPE_INFO,
@@ -576,14 +578,11 @@ GNUNET_NAT_AUTO_test_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
         nh->lsock = NULL;
       }
       nh->status = GNUNET_NAT_ERROR_NAT_REGISTER_FAILED;
-      nh->ttask = GNUNET_SCHEDULER_add_now (&do_timeout,
+      nh->ttask = GNUNET_SCHEDULER_add_now (&do_fail,
                                             nh);
       return nh;
     }
   }
-  nh->ttask = GNUNET_SCHEDULER_add_delayed (timeout,
-                                           &do_timeout,
-                                           nh);
   return nh;
 }
 
@@ -638,6 +637,7 @@ GNUNET_NAT_AUTO_test_stop (struct GNUNET_NAT_AUTO_Test *tst)
     GNUNET_NAT_unregister (tst->nat);
     tst->nat = NULL;
   }
+  GNUNET_free (tst->section_name);
   GNUNET_free (tst);
 }
 
index 8ef001ddba1058be275f6320bc3fc42f3fb88439..a440830fd9450252a2749bad235779b701bc1981 100644 (file)
@@ -29,7 +29,6 @@
 #include "gnunet_hello_lib.h"
 #include "gnunet_util_lib.h"
 #include "gnunet_fragmentation_lib.h"
-#include "gnunet_nat_lib.h"
 #include "gnunet_protocols.h"
 #include "gnunet_resolver_service.h"
 #include "gnunet_signatures.h"