start the code to send queries to the resolver
authorPhilipp Tölke <toelke@in.tum.de>
Mon, 6 Sep 2010 09:25:51 +0000 (09:25 +0000)
committerPhilipp Tölke <toelke@in.tum.de>
Mon, 6 Sep 2010 09:25:51 +0000 (09:25 +0000)
src/include/gnunet_protocols.h
src/vpn/gnunet-daemon-vpn.c
src/vpn/gnunet-service-dns-p.h [new file with mode: 0644]
src/vpn/gnunet-service-dns.c

index b5d74311451653709174efa757cfbb5ce711c86c..3f43769d3469260278612bdba362d03db94a32ed 100644 (file)
@@ -668,6 +668,14 @@ extern "C"
  * Type of messages for wlan
  */
 
+/**
+ * Type of messages to query the local service-dns
+ */
+#define GNUNET_MESSAGE_TYPE_LOCAL_QUERY_DNS 205
+/**
+ * Type of messages the local service-dns responds with
+ */
+#define GNUNET_MESSAGE_TYPE_LOCAL_RESPONSE_DNS 206
 
 
 /**
index 46a830f8d728aae88d808b927f98a6a6643fec36..9587bc8243abae3b04400b1f1d5ac5074e6e62fe 100644 (file)
@@ -33,6 +33,8 @@
 #include "gnunet_common.h"
 #include "gnunet_protocols.h"
 #include "gnunet_server_lib.h"
+#include "gnunet-service-dns-p.h"
+#include "gnunet_client_lib.h"
 
 /**
  * Final status code.
@@ -48,6 +50,8 @@ struct vpn_cls {
 
        struct GNUNET_SCHEDULER_Handle *sched;
 
+       struct GNUNET_CLIENT_Connection *dns_connection;
+
        pid_t helper_pid;
 };
 
@@ -136,9 +140,16 @@ static void message_token(void *cls, void *client, const struct GNUNET_MessageHe
        } else if (ntohs(pkt_tun->tun.type) == 0x0800) {
                struct ip_pkt *pkt = (struct ip_pkt*) message;
                struct ip_udp *udp = (struct ip_udp*) message;
-               fprintf(stderr, "IPv4\n");
+               GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "IPv4\n");
                if (pkt->ip_hdr.proto == 0x11 && ntohl(udp->ip_hdr.dadr) == 0x0a0a0a02 && ntohs(udp->udp_hdr.dpt) == 53 ) {
                        pkt_printf_ipdns((struct ip_udp_dns*)udp);
+                       struct query_packet* query = alloca((sizeof query) + ntohs(udp->udp_hdr.len) - 7); /* 7 = 8 for the udp-header - 1 for the unsigned char data[1]; */
+                       query->hdr.type = htons(GNUNET_MESSAGE_TYPE_LOCAL_QUERY_DNS);
+                       query->hdr.size = htons((sizeof query) + ntohs(udp->udp_hdr.len) - 7);
+                       query->orig_to = pkt->ip_hdr.dadr;
+                       query->orig_from = pkt->ip_hdr.sadr;
+                       query->src_port = udp->udp_hdr.spt;
+                       memcpy(query->data, udp->data, ntohs(udp->udp_hdr.len) - 8);
                }
        }
 
@@ -162,6 +173,10 @@ run (void *cls,
 {
   mycls.sched = sched;
   mycls.mst = GNUNET_SERVER_mst_create(&message_token, NULL);
+
+  mycls.dns_connection = GNUNET_CLIENT_connect (sched, "gnunet-service-dns", cfg);
+  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Connection: %x\n", mycls.dns_connection);
+
   GNUNET_SCHEDULER_add_delayed(sched, GNUNET_TIME_UNIT_FOREVER_REL, &cleanup, cls); 
   start_helper_and_schedule(mycls);
 }
diff --git a/src/vpn/gnunet-service-dns-p.h b/src/vpn/gnunet-service-dns-p.h
new file mode 100644 (file)
index 0000000..dea087e
--- /dev/null
@@ -0,0 +1,17 @@
+#ifndef GN_DNS_SERVICE_P_H
+#define GN_DNS_SERVICE_P_H
+
+#include "gnunet_common.h"
+
+struct query_packet {
+       struct GNUNET_MessageHeader hdr;
+       
+       unsigned orig_to:32 GNUNET_PACKED; /* The IP-Address, this query was originally sent to */
+       unsigned orig_from:32 GNUNET_PACKED;
+       unsigned src_port:16 GNUNET_PACKED;
+
+       unsigned char data[1]; /* The DNS-Packet */
+       
+};
+
+#endif
index 874b7ef0ff8e8aff2671d11d64030b2438f19f96..8abf19900b750a20c44398e39f0242f3c2492a58 100644 (file)
@@ -27,6 +27,8 @@
 #include "gnunet_service_lib.h"
 #include "gnunet_network_lib.h"
 #include "gnunet_os_lib.h"
+#include "gnunet-service-dns-p.h"
+#include "gnunet_protocols.h"
 
 struct dns_cls {
        struct GNUNET_SCHEDULER_Handle *sched;
@@ -52,6 +54,11 @@ void unhijack(unsigned short port) {
        GNUNET_OS_start_process(NULL, NULL, "gnunet-helper-hijack-dns", "gnunet-hijack-dns", "-d", port_s, NULL);
 }
 
+void receive_query(void *cls, struct GNUNET_SERVER_Client *client, const struct GNUNET_MessageHeader *message)
+{
+       GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Received query!\n");
+}
+
 /**
  * Task run during shutdown.
  *
@@ -78,6 +85,8 @@ run (void *cls,
      const struct GNUNET_CONFIGURATION_Handle *cfg)
 {
   static const struct GNUNET_SERVER_MessageHandler handlers[] = {
+         /* callback, cls, type, size */
+    {&receive_query, NULL, GNUNET_MESSAGE_TYPE_LOCAL_QUERY_DNS, 0},
     {NULL, NULL, 0, 0}
   };