-expanding draft code
authorChristian Grothoff <christian@grothoff.org>
Mon, 16 Jan 2012 19:21:48 +0000 (19:21 +0000)
committerChristian Grothoff <christian@grothoff.org>
Mon, 16 Jan 2012 19:21:48 +0000 (19:21 +0000)
src/pt/Makefile.am
src/pt/gnunet-daemon-pt
src/pt/gnunet-daemon-pt.c

index c437871337ee20879ec7c5590e767b03f5cd0ea0..8e33b45c2b9a5d76af0ae110e1569a99619c8883 100644 (file)
@@ -23,6 +23,7 @@ gnunet_daemon_pt_SOURCES = \
 gnunet_daemon_pt_LDADD = \
   $(top_builddir)/src/vpn/libgnunetvpn.la \
   $(top_builddir)/src/dns/libgnunetdns.la \
+  $(top_builddir)/src/dns/libgnunetdnsparser.la \
   $(top_builddir)/src/statistics/libgnunetstatistics.la \
   $(top_builddir)/src/util/libgnunetutil.la \
   $(top_builddir)/src/mesh/libgnunetmesh.la \
index d729865e356dd303915929cd73f3c629cea9562a..84ebead21dd9cd2497dfc5199e3b24dcda2fb188 100755 (executable)
@@ -32,13 +32,13 @@ DUALCASE=1; export DUALCASE # for MKS sh
 # if CDPATH is set.
 (unset CDPATH) >/dev/null 2>&1 && unset CDPATH
 
-relink_command="(cd /home/grothoff/svn/gnunet/src/pt; { test -z \"\${LIBRARY_PATH+set}\" || unset LIBRARY_PATH || { LIBRARY_PATH=; export LIBRARY_PATH; }; }; { test -z \"\${COMPILER_PATH+set}\" || unset COMPILER_PATH || { COMPILER_PATH=; export COMPILER_PATH; }; }; { test -z \"\${GCC_EXEC_PREFIX+set}\" || unset GCC_EXEC_PREFIX || { GCC_EXEC_PREFIX=; export GCC_EXEC_PREFIX; }; }; { test -z \"\${LD_RUN_PATH+set}\" || unset LD_RUN_PATH || { LD_RUN_PATH=; export LD_RUN_PATH; }; }; LD_LIBRARY_PATH=/usr/lib/debug:/home/grothoff/lib; export LD_LIBRARY_PATH; PATH=/opt/jdk1.6.0_22/bin:/usr/lib/jvm/java-6-sun//bin:.:/home/grothoff/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games; export PATH; gcc -fno-strict-aliasing -Wall -g -Wall -Werror -O0 -I/home/grothoff//include -o \$progdir/\$file gnunet-daemon-pt.o  -L/home/grothoff//lib ../../src/vpn/.libs/libgnunetvpn.so ../../src/dns/.libs/libgnunetdns.so ../../src/statistics/.libs/libgnunetstatistics.so ../../src/util/.libs/libgnunetutil.so ../../src/mesh/.libs/libgnunetmesh.so -ldl -Wl,-rpath -Wl,/home/grothoff/svn/gnunet/src/vpn/.libs -Wl,-rpath -Wl,/home/grothoff/svn/gnunet/src/dns/.libs -Wl,-rpath -Wl,/home/grothoff/svn/gnunet/src/statistics/.libs -Wl,-rpath -Wl,/home/grothoff/svn/gnunet/src/util/.libs -Wl,-rpath -Wl,/home/grothoff/svn/gnunet/src/mesh/.libs -Wl,-rpath -Wl,/home/grothoff/lib)"
+relink_command="(cd /home/grothoff/svn/gnunet/src/pt; { test -z \"\${LIBRARY_PATH+set}\" || unset LIBRARY_PATH || { LIBRARY_PATH=; export LIBRARY_PATH; }; }; { test -z \"\${COMPILER_PATH+set}\" || unset COMPILER_PATH || { COMPILER_PATH=; export COMPILER_PATH; }; }; { test -z \"\${GCC_EXEC_PREFIX+set}\" || unset GCC_EXEC_PREFIX || { GCC_EXEC_PREFIX=; export GCC_EXEC_PREFIX; }; }; { test -z \"\${LD_RUN_PATH+set}\" || unset LD_RUN_PATH || { LD_RUN_PATH=; export LD_RUN_PATH; }; }; LD_LIBRARY_PATH=/usr/lib/debug:/home/grothoff/lib; export LD_LIBRARY_PATH; PATH=/opt/jdk1.6.0_22/bin:/usr/lib/jvm/java-6-sun//bin:.:/home/grothoff/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games; export PATH; gcc -fno-strict-aliasing -Wall -g -Wall -Werror -O0 -I/home/grothoff//include -o \$progdir/\$file gnunet-daemon-pt.o  -L/home/grothoff//lib ../../src/vpn/.libs/libgnunetvpn.so ../../src/dns/.libs/libgnunetdns.so ../../src/dns/.libs/libgnunetdnsparser.so ../../src/statistics/.libs/libgnunetstatistics.so ../../src/util/.libs/libgnunetutil.so ../../src/mesh/.libs/libgnunetmesh.so -ldl -Wl,-rpath -Wl,/home/grothoff/svn/gnunet/src/vpn/.libs -Wl,-rpath -Wl,/home/grothoff/svn/gnunet/src/dns/.libs -Wl,-rpath -Wl,/home/grothoff/svn/gnunet/src/statistics/.libs -Wl,-rpath -Wl,/home/grothoff/svn/gnunet/src/util/.libs -Wl,-rpath -Wl,/home/grothoff/svn/gnunet/src/mesh/.libs -Wl,-rpath -Wl,/home/grothoff/lib)"
 
 # This environment variable determines our operation mode.
 if test "$libtool_install_magic" = "%%%MAGIC variable%%%"; then
   # install mode needs the following variables:
   generated_by_libtool_version='2.2.6b'
-  notinst_deplibs=' ../../src/vpn/libgnunetvpn.la ../../src/dns/libgnunetdns.la ../../src/statistics/libgnunetstatistics.la ../../src/util/libgnunetutil.la ../../src/mesh/libgnunetmesh.la'
+  notinst_deplibs=' ../../src/vpn/libgnunetvpn.la ../../src/dns/libgnunetdns.la ../../src/dns/libgnunetdnsparser.la ../../src/statistics/libgnunetstatistics.la ../../src/util/libgnunetutil.la ../../src/mesh/libgnunetmesh.la'
 else
   # When we are sourced in execute mode, $file and $ECHO are already set.
   if test "$libtool_execute_magic" != "%%%MAGIC variable%%%"; then
index f8d83237a9706c727af7b36e1c6db07d3e1ade2b..762df276e2aa319101b2f98ca6feecfcf4215414 100644 (file)
@@ -27,6 +27,7 @@
 #include "platform.h"
 #include "gnunet_util_lib.h"
 #include "gnunet_dns_service.h"
+#include "gnunet_dnsparser_lib.h"
 #include "gnunet_vpn_service.h"
 #include "gnunet_statistics_service.h"
 
@@ -62,6 +63,36 @@ static int ipv4_pt;
 static int ipv6_pt;
 
 
+/**
+ * Test if any of the given records need protocol-translation work.
+ *
+ * @param ra array of records
+ * @param ra_len number of entries in ra
+ * @return GNUNET_YES if any of the given records require protocol-translation
+ */
+static int
+work_test (const struct GNUNET_DNSPARSER_Record *ra,
+          unsigned int ra_len)
+{
+  unsigned int i;
+
+  for (i=0;i<ra_len;i++)
+  {
+    switch (ra[i].type)
+    {
+    case GNUNET_DNSPARSER_TYPE_A:
+      if (ipv4_pt)
+       return GNUNET_YES;
+      break;
+    case GNUNET_DNSPARSER_TYPE_AAAA:
+      if (ipv6_pt)
+       return GNUNET_YES;
+      break;
+    }
+  }
+  return GNUNET_NO;
+}
+
 
 /**
  * Signature of a function that is called whenever the DNS service
@@ -92,6 +123,27 @@ dns_request_handler (void *cls,
                     size_t request_length,
                     const char *request)
 {
+  struct GNUNET_DNSPARSER_Packet *dns;
+  int work;
+
+  dns = GNUNET_DNSPARSER_parse (request, request_length);
+  if (NULL == dns)
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+               _("Failed to parse DNS request.  Dropping.\n"));
+    GNUNET_DNS_request_drop (rh);
+    return;
+  }
+  work = GNUNET_NO;
+  work |= work_test (dns->answers, dns->num_answers);
+  work |= work_test (dns->authority_records, dns->num_authority_records);
+  work |= work_test (dns->additional_records, dns->num_additional_records);
+  if (! work)
+  {
+    GNUNET_DNS_request_forward (rh);
+    return;
+  }
+  /* FIXME: translate A/AAAA records using VPN! */
 }