- doxygen
[oweals/gnunet.git] / src / pt / test_gnunet_vpn.c
index f40a363b7d1f924d6d32110bc20f3b06f61b13af..7e83fdcd11b1a409eb6dedd104b0294c1cb4093d 100644 (file)
@@ -4,7 +4,7 @@
 
      GNUnet is free software; you can redistribute it and/or modify
      it under the terms of the GNU General Public License as published
-     by the Free Software Foundation; either version 2, or (at your
+     by the Free Software Foundation; either version 3, or (at your
      option) any later version.
 
      GNUnet is distributed in the hope that it will be useful, but
@@ -27,7 +27,7 @@
 #include <curl/curl.h>
 #include <microhttpd.h>
 #include "gnunet_vpn_service.h"
-#include "gnunet_testing_lib-new.h"
+#include "gnunet_testing_lib.h"
 
 #define PORT 48080
 
@@ -366,6 +366,8 @@ run (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg,
   mhd =
       MHD_start_daemon (flags, PORT, NULL, NULL, &mhd_ahc, NULL,
                         MHD_OPTION_END);
+
+
   GNUNET_assert (NULL != mhd);
   mhd_main ();
   addr = NULL;
@@ -382,7 +384,7 @@ run (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg,
   default:
     GNUNET_assert (0);
   }
-  rr = GNUNET_VPN_redirect_to_ip (vpn, src_af, dest_af, addr, GNUNET_YES,
+  rr = GNUNET_VPN_redirect_to_ip (vpn, src_af, dest_af, addr,
                                   GNUNET_TIME_UNIT_FOREVER_ABS, &allocation_cb,
                                   NULL);
   ctrl_c_task_id =
@@ -390,36 +392,16 @@ run (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg,
 }
 
 
-/**
- * Test if the given AF is supported by this system.
- *
- * @param af to test
- * @return GNUNET_OK if the AF is supported
- */
-static int
-test_af (int af)
-{
-  int s;
-
-  s = socket (af, SOCK_STREAM, 0);
-  if (-1 == s)
-  {
-    if (EAFNOSUPPORT == errno)
-      return GNUNET_NO;
-    fprintf (stderr, "Failed to create test socket: %s\n", STRERROR (errno));
-    return GNUNET_SYSERR;
-  }
-  close (s);
-  return GNUNET_OK;
-}
-
-
 int
 main (int argc, char *const *argv)
 {
   const char *type;
   const char *bin;
+  char *vpn_binary;
+  char *exit_binary;
+  int ret=0;
 
+#ifndef MINGW
   if (0 != ACCESS ("/dev/net/tun", R_OK))
   {
     GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "access",
@@ -427,16 +409,23 @@ main (int argc, char *const *argv)
     fprintf (stderr, "WARNING: System unable to run test, skipping.\n");
     return 0;
   }
-  if ((GNUNET_YES != GNUNET_OS_check_helper_binary ("gnunet-helper-vpn")) ||
-      (GNUNET_YES != GNUNET_OS_check_helper_binary ("gnunet-helper-exit")))
+#endif
+  vpn_binary = GNUNET_OS_get_libexec_binary_path ("gnunet-helper-vpn");
+  exit_binary = GNUNET_OS_get_libexec_binary_path ("gnunet-helper-exit");
+  fprintf (stderr,"%s\n", vpn_binary);
+  fprintf (stderr,"%s\n", exit_binary);
+  if ((GNUNET_YES != (ret = GNUNET_OS_check_helper_binary (vpn_binary, GNUNET_YES, "-d gnunet-vpn - - 169.1.3.3.7 255.255.255.0"))) || //ipv4 only please!
+      (GNUNET_YES != (ret = GNUNET_OS_check_helper_binary (exit_binary, GNUNET_YES, "-d gnunet-vpn - - - 169.1.3.3.7 255.255.255.0")))) //no nat, ipv4 only
   {
+    GNUNET_free (vpn_binary);
+    GNUNET_free (exit_binary);
     fprintf (stderr,
-             "WARNING: gnunet-helper-{exit,vpn} binaries in $PATH are not SUID, refusing to run test (as it would have to fail).\n");
-    fprintf (stderr,
-             "Change $PATH ('.' in $PATH before $GNUNET_PREFIX/bin is problematic) or permissions (run 'make install' as root) to fix this!\n");
+             "WARNING: gnunet-helper-{exit,vpn} binaries are not SUID, refusing to run test (as it would have to fail). %d\n", ret);
     return 0;
   }
-  GNUNET_CRYPTO_setup_hostkey ("test_gnunet_vpn.conf");
+
+  GNUNET_free (vpn_binary);
+  GNUNET_free (exit_binary);
   bin = argv[0];
   if (NULL != strstr (bin, "lt-"))
     bin = strstr (bin, "lt-") + 4;
@@ -447,25 +436,28 @@ main (int argc, char *const *argv)
     return 1;
   }
   type++;
-  if (0 == strcmp (type, "4_to_6"))
+  /* on Windows, .exe is suffixed to these binaries,
+   * thus cease comparison after the 6th char.
+   */
+  if (0 == strncmp (type, "4_to_6",6))
   {
     dest_ip = "FC5A:04E1:C2BA::1";
     dest_af = AF_INET6;
     src_af = AF_INET;
   }
-  else if (0 == strcmp (type, "6_to_4"))
+  else if (0 == strncmp (type, "6_to_4",6))
   {
     dest_ip = "169.254.86.1";
     dest_af = AF_INET;
     src_af = AF_INET6;
   }
-  else if (0 == strcmp (type, "4_over"))
+  else if (0 == strncmp (type, "4_over",6))
   {
     dest_ip = "169.254.86.1";
     dest_af = AF_INET;
     src_af = AF_INET;
   }
-  else if (0 == strcmp (type, "6_over"))
+  else if (0 == strncmp (type, "6_over",6))
   {
     dest_ip = "FC5A:04E1:C2BA::1";
     dest_af = AF_INET6;
@@ -476,7 +468,8 @@ main (int argc, char *const *argv)
     fprintf (stderr, "invalid binary suffix `%s'\n", type);
     return 1;
   }
-  if ((GNUNET_OK != test_af (src_af)) || (GNUNET_OK != test_af (dest_af)))
+  if ((GNUNET_OK != GNUNET_NETWORK_test_pf (src_af)) ||
+      (GNUNET_OK != GNUNET_NETWORK_test_pf (dest_af)))
   {
     fprintf (stderr,
              "Required address families not supported by this system, skipping test.\n");