From 62947a2d1690f607276aa84c36f269fe188fcb20 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Wed, 25 Jan 2012 21:26:27 +0000 Subject: [PATCH] -expanding tests to cover 4-to-6, 6-to-4 and 6-over-4 as well --- src/vpn/Makefile.am | 31 +++++++++++++++-- src/vpn/test_gnunet_vpn.c | 73 +++++++++++++++++++++++++++++++++++---- 2 files changed, 95 insertions(+), 9 deletions(-) diff --git a/src/vpn/Makefile.am b/src/vpn/Makefile.am index fea89724d..2cd798591 100644 --- a/src/vpn/Makefile.am +++ b/src/vpn/Makefile.am @@ -34,7 +34,11 @@ bin_PROGRAMS = \ if HAVE_MHD - VPN_TEST = test_gnunet_vpn + VPN_TEST = \ + test_gnunet_vpn-4_to_6 \ + test_gnunet_vpn-6_to_4 \ + test_gnunet_vpn-6_over \ + test_gnunet_vpn-4_over endif check_PROGRAMS = $(VPN_TEST) @@ -75,9 +79,30 @@ libgnunetvpn_la_LDFLAGS = \ $(GN_LIB_LDFLAGS) -test_gnunet_vpn_SOURCES = \ +test_gnunet_vpn_4_over_SOURCES = \ test_gnunet_vpn.c -test_gnunet_vpn_LDADD = -lmicrohttpd @LIBCURL@ \ +test_gnunet_vpn_4_over_LDADD = -lmicrohttpd @LIBCURL@ \ + $(top_builddir)/src/vpn/libgnunetvpn.la \ + $(top_builddir)/src/arm/libgnunetarm.la \ + $(top_builddir)/src/util/libgnunetutil.la + +test_gnunet_vpn_6_over_SOURCES = \ + test_gnunet_vpn.c +test_gnunet_vpn_6_over_LDADD = -lmicrohttpd @LIBCURL@ \ + $(top_builddir)/src/vpn/libgnunetvpn.la \ + $(top_builddir)/src/arm/libgnunetarm.la \ + $(top_builddir)/src/util/libgnunetutil.la + +test_gnunet_vpn_4_to_6_SOURCES = \ + test_gnunet_vpn.c +test_gnunet_vpn_4_to_6_LDADD = -lmicrohttpd @LIBCURL@ \ + $(top_builddir)/src/vpn/libgnunetvpn.la \ + $(top_builddir)/src/arm/libgnunetarm.la \ + $(top_builddir)/src/util/libgnunetutil.la + +test_gnunet_vpn_6_to_4_SOURCES = \ + test_gnunet_vpn.c +test_gnunet_vpn_6_to_4_LDADD = -lmicrohttpd @LIBCURL@ \ $(top_builddir)/src/vpn/libgnunetvpn.la \ $(top_builddir)/src/arm/libgnunetarm.la \ $(top_builddir)/src/util/libgnunetutil.la diff --git a/src/vpn/test_gnunet_vpn.c b/src/vpn/test_gnunet_vpn.c index 1e4e2044d..781eae5ec 100644 --- a/src/vpn/test_gnunet_vpn.c +++ b/src/vpn/test_gnunet_vpn.c @@ -71,6 +71,22 @@ static CURLM *multi; static char *url; +/** + * IP address of the ultimate destination. + */ +static const char *dest_ip; + +/** + * Address family of the dest_ip. + */ +static int dest_af; + +/** + * Address family to use by the curl client. + */ +static int src_af; + + struct CBC { char buf[1024]; @@ -267,10 +283,10 @@ allocation_cb (void *cls, int af, const void *address) { - char ips[INET_ADDRSTRLEN]; + char ips[INET6_ADDRSTRLEN]; rr = NULL; - if (AF_INET != af) + if (src_af != af) { fprintf (stderr, "VPN failed to allocate appropriate address\n"); @@ -371,20 +387,24 @@ run (void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) { struct in_addr v4; + enum MHD_FLAG flags; vpn = GNUNET_VPN_connect (cfg); GNUNET_assert (NULL != vpn); - mhd = MHD_start_daemon (MHD_USE_DEBUG, + flags = MHD_USE_DEBUG; + if (AF_INET6 == dest_af) + flags |= MHD_USE_IPv6; + mhd = MHD_start_daemon (flags, PORT, NULL, NULL, &mhd_ahc, NULL, MHD_OPTION_END); GNUNET_assert (NULL != mhd); mhd_main (); - GNUNET_assert (1 == inet_pton (AF_INET, "169.254.86.1", &v4)); + GNUNET_assert (1 == inet_pton (dest_af, dest_ip, &v4)); rr = GNUNET_VPN_redirect_to_ip (vpn, - AF_INET, - AF_INET, + src_af, + dest_af, &v4, GNUNET_YES, GNUNET_TIME_UNIT_FOREVER_ABS, @@ -436,6 +456,8 @@ stop_peer (struct PeerContext *p) int main (int argc, char *const *argv) { + const char *type; + const char *bin; char *const argvx[] = { "test_gnunet_vpn", "-c", @@ -448,6 +470,45 @@ main (int argc, char *const *argv) struct GNUNET_GETOPT_CommandLineOption options[] = { GNUNET_GETOPT_OPTION_END }; + bin = argv[0]; + if (NULL != strstr (bin, "lt-")) + bin = strstr (bin, "lt-") + 4; + type = strstr (bin, "-"); + if (NULL == type) + { + fprintf (stderr, "invalid binary name\n"); + return 1; + } + type++; + if (0 == strcmp (type, "4_to_6")) + { + dest_ip = "FC5A:04E1:C2BA::1"; + dest_af = AF_INET6; + src_af = AF_INET; + } + else if (0 == strcmp (type, "6_to_4")) + { + dest_ip = "169.254.86.1"; + dest_af = AF_INET; + src_af = AF_INET6; + } + else if (0 == strcmp (type, "4_over")) + { + dest_ip = "169.254.86.1"; + dest_af = AF_INET; + src_af = AF_INET; + } + else if (0 == strcmp (type, "6_over")) + { + dest_ip = "FC5A:04E1:C2BA::1"; + dest_af = AF_INET6; + src_af = AF_INET6; + } + else + { + fprintf (stderr, "invalid binary suffix `%s'\n", type); + return 1; + } if (0 != curl_global_init (CURL_GLOBAL_WIN32)) return 2; -- 2.25.1