From 2a2509d66f5a7d670fbecb2b62498f1cab180161 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Philipp=20T=C3=B6lke?= Date: Tue, 7 Sep 2010 13:37:28 +0000 Subject: [PATCH] send dns-queries to the service-dns and pretty-print them --- src/vpn/Makefile.am | 6 ++++-- src/vpn/gnunet-daemon-vpn.c | 9 ++++++--- src/vpn/gnunet-service-dns.c | 5 +++++ src/vpn/gnunet-vpn-pretty-print.h | 2 ++ 4 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/vpn/Makefile.am b/src/vpn/Makefile.am index 370528772..ca8f6c1af 100644 --- a/src/vpn/Makefile.am +++ b/src/vpn/Makefile.am @@ -34,7 +34,8 @@ gnunet_helper_hijack_dns_SOURCES = \ gnunet-helper-hijack-dns.c gnunet_daemon_vpn_SOURCES = \ - gnunet-daemon-vpn.c gnunet-vpn-pretty-print.c + gnunet-daemon-vpn.c \ + gnunet-vpn-pretty-print.c gnunet_daemon_vpn_LDADD = \ $(top_builddir)/src/core/libgnunetcore.la \ $(top_builddir)/src/statistics/libgnunetstatistics.la \ @@ -42,7 +43,8 @@ gnunet_daemon_vpn_LDADD = \ $(GN_LIBINTL) gnunet_service_dns_SOURCES = \ - gnunet-service-dns.c + gnunet-service-dns.c \ + gnunet-vpn-pretty-print.c gnunet_service_dns_LDADD = \ $(top_builddir)/src/core/libgnunetcore.la \ $(top_builddir)/src/statistics/libgnunetstatistics.la \ diff --git a/src/vpn/gnunet-daemon-vpn.c b/src/vpn/gnunet-daemon-vpn.c index 6eb3ea9a0..147983f5c 100644 --- a/src/vpn/gnunet-daemon-vpn.c +++ b/src/vpn/gnunet-daemon-vpn.c @@ -149,7 +149,7 @@ static void message_token(void *cls, void *client, const struct GNUNET_MessageHe struct ip_pkt *pkt = (struct ip_pkt*) message; struct ip_udp *udp = (struct ip_udp*) message; if (pkt->ip_hdr.proto == 0x11 && udp->ip_hdr.dadr == 0x020a0a0a && ntohs(udp->udp_hdr.dpt) == 53 ) { - size_t len = sizeof(struct query_packet*) + ntohs(udp->udp_hdr.len) - 7; /* 7 = 8 for the udp-header - 1 for the unsigned char data[1]; */ + size_t len = sizeof(struct query_packet) + ntohs(udp->udp_hdr.len) - 9; /* 7 = 8 for the udp-header + 1 for the unsigned char data[1]; */ struct query_packet* query = GNUNET_malloc(len); query->hdr.type = htons(GNUNET_MESSAGE_TYPE_LOCAL_QUERY_DNS); query->hdr.size = htons(len); @@ -157,8 +157,11 @@ static void message_token(void *cls, void *client, const struct GNUNET_MessageHe 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); - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Queued sending\n"); - GNUNET_CLIENT_notify_transmit_ready(mycls.dns_connection, len, GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_YES, &send_query, query); + struct GNUNET_CLIENT_TransmitHandle* th = GNUNET_CLIENT_notify_transmit_ready(mycls.dns_connection, len, GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_YES, &send_query, query); + if (th != NULL) + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Queued sending of %d bytes.\n", len); + else + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Already queued!\n"); } } diff --git a/src/vpn/gnunet-service-dns.c b/src/vpn/gnunet-service-dns.c index 90e789010..c85ba0027 100644 --- a/src/vpn/gnunet-service-dns.c +++ b/src/vpn/gnunet-service-dns.c @@ -29,6 +29,8 @@ #include "gnunet_os_lib.h" #include "gnunet-service-dns-p.h" #include "gnunet_protocols.h" +#include "gnunet-vpn-packet.h" +#include "gnunet-vpn-pretty-print.h" struct dns_cls { struct GNUNET_SCHEDULER_Handle *sched; @@ -58,6 +60,9 @@ void receive_query(void *cls, struct GNUNET_SERVER_Client *client, const struct { GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Received query!\n"); struct query_packet* pkt = (struct query_packet*)message; + struct dns_pkt* dns = (struct dns_pkt*)pkt->data; + + pkt_printf_dns(dns); GNUNET_SERVER_receive_done(client, GNUNET_OK); } diff --git a/src/vpn/gnunet-vpn-pretty-print.h b/src/vpn/gnunet-vpn-pretty-print.h index 8e5ff66c2..26f651fac 100644 --- a/src/vpn/gnunet-vpn-pretty-print.h +++ b/src/vpn/gnunet-vpn-pretty-print.h @@ -7,6 +7,8 @@ extern void pp_write_header(char* dest, struct ip6_pkt* pkt); extern void pkt_printf(struct ip6_pkt* pkt); +void pkt_printf_dns(struct dns_pkt* pkt); + void pkt_printf_ip6tcp(struct ip6_tcp* pkt); void pkt_printf_ip6udp(struct ip6_udp* pkt); void pkt_printf_ip6dns(struct ip6_udp_dns* pkt); -- 2.25.1