From: Philipp Tölke Date: Mon, 6 Sep 2010 09:25:51 +0000 (+0000) Subject: start the code to send queries to the resolver X-Git-Tag: initial-import-from-subversion-38251~20442 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=83bfe795348dfcdb83cb565dd81d0a32fcb43dba;p=oweals%2Fgnunet.git start the code to send queries to the resolver --- diff --git a/src/include/gnunet_protocols.h b/src/include/gnunet_protocols.h index b5d743114..3f43769d3 100644 --- a/src/include/gnunet_protocols.h +++ b/src/include/gnunet_protocols.h @@ -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 /** diff --git a/src/vpn/gnunet-daemon-vpn.c b/src/vpn/gnunet-daemon-vpn.c index 46a830f8d..9587bc824 100644 --- a/src/vpn/gnunet-daemon-vpn.c +++ b/src/vpn/gnunet-daemon-vpn.c @@ -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 index 000000000..dea087e89 --- /dev/null +++ b/src/vpn/gnunet-service-dns-p.h @@ -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 diff --git a/src/vpn/gnunet-service-dns.c b/src/vpn/gnunet-service-dns.c index 874b7ef0f..8abf19900 100644 --- a/src/vpn/gnunet-service-dns.c +++ b/src/vpn/gnunet-service-dns.c @@ -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} };