-also run if system does not support IPv4 or IPv6 at all - #2123
authorChristian Grothoff <christian@grothoff.org>
Mon, 30 Jan 2012 21:21:49 +0000 (21:21 +0000)
committerChristian Grothoff <christian@grothoff.org>
Mon, 30 Jan 2012 21:21:49 +0000 (21:21 +0000)
src/exit/gnunet-daemon-exit.c
src/exit/gnunet-helper-exit.c
src/vpn/gnunet-helper-vpn.c
src/vpn/gnunet-service-vpn.c

index 99dec5ea07da09336267b3de173522cac790047c..a956bfa1a71ddbe8f3740c0ac8a7e9d6baa354e2 100644 (file)
@@ -2948,6 +2948,31 @@ read_service_conf (void *cls GNUNET_UNUSED, const char *section)
 }
 
 
+/**
+ * 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;
+    GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR,
+                        "socket");
+    return GNUNET_SYSERR;
+  }
+  close (s);
+  return GNUNET_OK;
+}
+
+
 /**
  * @brief Main function that will be run by the scheduler.
  *
@@ -3000,6 +3025,23 @@ run (void *cls, char *const *args GNUNET_UNUSED,
   ipv6_exit = GNUNET_CONFIGURATION_get_value_yesno (cfg, "exit", "EXIT_IPV6"); 
   ipv4_enabled = GNUNET_CONFIGURATION_get_value_yesno (cfg, "exit", "ENABLE_IPV4");
   ipv6_enabled = GNUNET_CONFIGURATION_get_value_yesno (cfg, "exit", "ENABLE_IPV6"); 
+
+  if ( (ipv4_exit || ipv4_enabled) &&
+       GNUNET_OK != test_af (AF_INET))
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+               _("This system does not support IPv4, will disable IPv4 functions despite them being enabled in the configuration\n"));
+    ipv4_exit = GNUNET_NO;
+    ipv4_enabled = GNUNET_NO;
+  }
+  if ( (ipv6_exit || ipv6_enabled) &&
+       GNUNET_OK != test_af (AF_INET6))
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+               _("This system does not support IPv6, will disable IPv6 functions despite them being enabled in the configuration\n"));
+    ipv6_exit = GNUNET_NO;
+    ipv6_enabled = GNUNET_NO;
+  }
   if (ipv4_exit && (! ipv4_enabled))
   {
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -3063,6 +3105,8 @@ run (void *cls, char *const *args GNUNET_UNUSED,
   {
     exit_argv[2] = GNUNET_strdup ("%");
   }
+  
+
   if (GNUNET_YES == ipv6_enabled)
   {
     if ( (GNUNET_SYSERR ==
index 518bebfc4ffec3abc14e5ae7b3e6a35207c66443..573bb7a502ebb5a8c49b41fbf87ebc887defd2d4 100644 (file)
@@ -226,7 +226,7 @@ set_address6 (const char *dev, const char *address, unsigned long prefix_len)
 
   if (-1 == (fd = socket (PF_INET6, SOCK_DGRAM, 0)))
   {
-    fprintf (stderr, "Error creating socket: %s\n", strerror (errno));
+    fprintf (stderr, "Error creating socket: %s\n", strerror (errno));    
     exit (1);
   }
 
index 5a1b708e249b9010697bf455aede9c7654fce417..5903255f88883d5fb641dce4f0af3dfb906c4dbb 100644 (file)
@@ -530,10 +530,10 @@ PROCESS_BUFFER:
  * @param argc must be 6
  * @param argv 0: binary name (gnunet-helper-vpn)
  *             1: tunnel interface name (gnunet-vpn)
- *             2: IPv6 address (::1)
- *             3: IPv6 netmask length in bits (64)
- *             4: IPv4 address (1.2.3.4)
- *             5: IPv4 netmask (255.255.0.0)
+ *             2: IPv6 address (::1), "-" to disable
+ *             3: IPv6 netmask length in bits (64), ignored if #2 is "-"
+ *             4: IPv4 address (1.2.3.4), "-" to disable
+ *             5: IPv4 netmask (255.255.0.0), ignored if #4 is "-"
  */
 int
 main (int argc, char **argv)
@@ -562,6 +562,7 @@ main (int argc, char **argv)
     return 1;
   }
 
+  if (0 != strcmp (argv[2], "-"))
   {
     const char *address = argv[2];
     long prefix_len = atol (argv[3]);
@@ -575,6 +576,7 @@ main (int argc, char **argv)
     set_address6 (dev, address, prefix_len);
   }
 
+  if (0 != strcmp (argv[4], "-"))
   {
     const char *address = argv[4];
     const char *mask = argv[5];
index 8e6ae655d2a9dfb084762963ea1047a02f5fffab..c8ffa8586bae6804cf0796d91a3d606114f1d323 100644 (file)
@@ -2989,6 +2989,31 @@ client_disconnect (void *cls, struct GNUNET_SERVER_Client *client)
 }
 
 
+/**
+ * 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;
+    GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR,
+                        "socket");
+    return GNUNET_SYSERR;
+  }
+  close (s);
+  return GNUNET_OK;
+}
+
+
 /**
  * Main function that will be run by the scheduler.
  *
@@ -3062,59 +3087,78 @@ run (void *cls,
     return;
   }
   vpn_argv[1] = ifname;
-  if ( (GNUNET_SYSERR ==
-       GNUNET_CONFIGURATION_get_value_string (cfg, "vpn", "IPV6ADDR",
-                                              &ipv6addr) ||
-       (1 != inet_pton (AF_INET6, ipv6addr, &v6))) )
+  if (GNUNET_OK == test_af (AF_INET6))
   {
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                "No valid entry 'IPV6ADDR' in configuration!\n");
-    GNUNET_SCHEDULER_shutdown ();
-    return;
-  }
-  vpn_argv[2] = ipv6addr;
-  if (GNUNET_SYSERR ==
-      GNUNET_CONFIGURATION_get_value_string (cfg, "vpn", "IPV6PREFIX",
-                                             &ipv6prefix_s))
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                "No entry 'IPV6PREFIX' in configuration!\n");
-    GNUNET_SCHEDULER_shutdown ();
-    return;
+    if ( (GNUNET_SYSERR ==
+         GNUNET_CONFIGURATION_get_value_string (cfg, "vpn", "IPV6ADDR",
+                                                &ipv6addr) ||
+         (1 != inet_pton (AF_INET6, ipv6addr, &v6))) )
+    {
+      GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                 "No valid entry 'IPV6ADDR' in configuration!\n");
+      GNUNET_SCHEDULER_shutdown ();
+      return;
+    }
+    vpn_argv[2] = ipv6addr;
+    if (GNUNET_SYSERR ==
+       GNUNET_CONFIGURATION_get_value_string (cfg, "vpn", "IPV6PREFIX",
+                                              &ipv6prefix_s))
+    {
+      GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                 "No entry 'IPV6PREFIX' in configuration!\n");
+      GNUNET_SCHEDULER_shutdown ();
+      return;
+    }
+    vpn_argv[3] = ipv6prefix_s;
+    if ( (GNUNET_OK !=
+         GNUNET_CONFIGURATION_get_value_number (cfg, "vpn",
+                                                "IPV6PREFIX",
+                                                &ipv6prefix)) ||
+        (ipv6prefix >= 127) )
+    {
+      GNUNET_SCHEDULER_shutdown ();
+      return;
+    }
   }
-  vpn_argv[3] = ipv6prefix_s;
-  if ( (GNUNET_OK !=
-       GNUNET_CONFIGURATION_get_value_number (cfg, "vpn",
-                                              "IPV6PREFIX",
-                                              &ipv6prefix)) ||
-       (ipv6prefix >= 127) )
+  else
   {
-    GNUNET_SCHEDULER_shutdown ();
-    return;
+    GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+               _("IPv6 support disabled as this system does not support IPv6\n"));
+    vpn_argv[2] = GNUNET_strdup ("-");
+    vpn_argv[3] = GNUNET_strdup ("-");
   }
-
-  if ( (GNUNET_SYSERR ==
-       GNUNET_CONFIGURATION_get_value_string (cfg, "vpn", "IPV4ADDR",
-                                              &ipv4addr) ||
-       (1 != inet_pton (AF_INET, ipv4addr, &v4))) )
+  if (GNUNET_OK == test_af (AF_INET))
   {
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                "No valid entry for 'IPV4ADDR' in configuration!\n");
-    GNUNET_SCHEDULER_shutdown ();
-    return;
+    if ( (GNUNET_SYSERR ==
+         GNUNET_CONFIGURATION_get_value_string (cfg, "vpn", "IPV4ADDR",
+                                                &ipv4addr) ||
+         (1 != inet_pton (AF_INET, ipv4addr, &v4))) )
+    {
+      GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                 "No valid entry for 'IPV4ADDR' in configuration!\n");
+      GNUNET_SCHEDULER_shutdown ();
+      return;
+    }
+    vpn_argv[4] = ipv4addr;
+    if ( (GNUNET_SYSERR ==
+         GNUNET_CONFIGURATION_get_value_string (cfg, "vpn", "IPV4MASK",
+                                                &ipv4mask) ||
+         (1 != inet_pton (AF_INET, ipv4mask, &v4))) )
+    {
+      GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                 "No valid entry 'IPV4MASK' in configuration!\n");
+      GNUNET_SCHEDULER_shutdown ();
+      return;
+    }
+    vpn_argv[5] = ipv4mask;
   }
-  vpn_argv[4] = ipv4addr;
-  if ( (GNUNET_SYSERR ==
-       GNUNET_CONFIGURATION_get_value_string (cfg, "vpn", "IPV4MASK",
-                                              &ipv4mask) ||
-       (1 != inet_pton (AF_INET, ipv4mask, &v4))) )
+  else
   {
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                "No valid entry 'IPV4MASK' in configuration!\n");
-    GNUNET_SCHEDULER_shutdown ();
-    return;
+    GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+               _("IPv4 support disabled as this system does not support IPv4\n"));
+    vpn_argv[4] = GNUNET_strdup ("-");
+    vpn_argv[5] = GNUNET_strdup ("-");
   }
-  vpn_argv[5] = ipv4mask;
   vpn_argv[6] = NULL;
 
   mesh_handle =