aboutsummaryrefslogtreecommitdiff
path: root/src/dns
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2012-01-02 04:37:59 +0000
committerChristian Grothoff <christian@grothoff.org>2012-01-02 04:37:59 +0000
commit86a020dbabef7e047706f462840bfe66b036093c (patch)
treee19123a84f515ad810ed892811a5c6492b6b971f /src/dns
parent1fd2ff9b321277b55444c2a074e6476cc10099c2 (diff)
downloadgnunet-86a020dbabef7e047706f462840bfe66b036093c.tar.gz
gnunet-86a020dbabef7e047706f462840bfe66b036093c.zip
-small steps towards saner DNS API
Diffstat (limited to 'src/dns')
-rw-r--r--src/dns/Makefile.am5
-rw-r--r--src/dns/dns.conf11
-rw-r--r--src/dns/dns.h54
-rw-r--r--src/dns/dns_api.c89
-rw-r--r--src/dns/gnunet-service-dns.c2
5 files changed, 156 insertions, 5 deletions
diff --git a/src/dns/Makefile.am b/src/dns/Makefile.am
index 4e2637204..a7aafa4fc 100644
--- a/src/dns/Makefile.am
+++ b/src/dns/Makefile.am
@@ -12,6 +12,9 @@ pkgcfgdir= $(pkgdatadir)/config.d/
12 12
13plugindir = $(libdir)/gnunet 13plugindir = $(libdir)/gnunet
14 14
15dist_pkgcfg_DATA = \
16 dns.conf
17
15if LINUX 18if LINUX
16HIJACKBIN = gnunet-helper-hijack-dns 19HIJACKBIN = gnunet-helper-hijack-dns
17install-exec-hook: 20install-exec-hook:
@@ -52,7 +55,7 @@ libgnunetdnsparser_la_LDFLAGS = \
52 55
53 56
54libgnunetdns_la_SOURCES = \ 57libgnunetdns_la_SOURCES = \
55 dns_api.c 58 dns_api.c dns.h
56libgnunetdns_la_LIBADD = \ 59libgnunetdns_la_LIBADD = \
57 $(top_builddir)/src/util/libgnunetutil.la $(XLIB) 60 $(top_builddir)/src/util/libgnunetutil.la $(XLIB)
58libgnunetdns_la_LDFLAGS = \ 61libgnunetdns_la_LDFLAGS = \
diff --git a/src/dns/dns.conf b/src/dns/dns.conf
new file mode 100644
index 000000000..59d827692
--- /dev/null
+++ b/src/dns/dns.conf
@@ -0,0 +1,11 @@
1[dns]
2AUTOSTART = YES
3PORT = 0
4HOSTNAME = localhost
5HOME = $SERVICEHOME
6CONFIG = $DEFAULTCONFIG
7BINARY = gnunet-service-dns
8ACCEPT_FROM = 127.0.0.1;
9ACCEPT_FROM6 = ::1;
10UNIXPATH = /tmp/gnunet-service-dns.sock
11PROVIDE_EXIT = NO
diff --git a/src/dns/dns.h b/src/dns/dns.h
new file mode 100644
index 000000000..dd0f55e16
--- /dev/null
+++ b/src/dns/dns.h
@@ -0,0 +1,54 @@
1/*
2 This file is part of GNUnet
3 (C) 2010, 2011, 2012 Christian Grothoff (and other contributing authors)
4
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 2, or (at your
8 option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19 */
20
21/**
22 * @file dns/dns.h
23 * @brief IPC messages between DNS API and DNS service
24 * @author Philipp Toelke
25 * @author Christian Grothoff
26 */
27#ifndef DNS_H
28#define DNS_H
29
30GNUNET_NETWORK_STRUCT_BEGIN
31
32struct query_packet
33{
34 struct GNUNET_MessageHeader hdr;
35
36 /**
37 * The IP-Address this query was originally sent to
38 */
39 char orig_to[16];
40 /**
41 * The IP-Address this query was originally sent from
42 */
43 char orig_from[16];
44 char addrlen;
45 /**
46 * The UDP-Port this query was originally sent from
47 */
48 uint16_t src_port GNUNET_PACKED;
49
50 unsigned char data[1]; /* The DNS-Packet */
51};
52GNUNET_NETWORK_STRUCT_END
53
54#endif
diff --git a/src/dns/dns_api.c b/src/dns/dns_api.c
index 90b4a8f42..68b703eba 100644
--- a/src/dns/dns_api.c
+++ b/src/dns/dns_api.c
@@ -34,6 +34,15 @@
34#include <block_dns.h> 34#include <block_dns.h>
35 35
36#include "gnunet_dns_service.h" 36#include "gnunet_dns_service.h"
37#include "dns.h"
38
39struct query_packet_list
40{
41 struct query_packet_list *next GNUNET_PACKED;
42 struct query_packet_list *prev GNUNET_PACKED;
43 struct query_packet pkt;
44};
45
37 46
38 47
39struct GNUNET_DNS_Handle 48struct GNUNET_DNS_Handle
@@ -237,9 +246,9 @@ GNUNET_DNS_restart_hijack (struct GNUNET_DNS_Handle *h)
237 * FIXME: we should not expost our internal structures like this. 246 * FIXME: we should not expost our internal structures like this.
238 * Just a quick initial hack. 247 * Just a quick initial hack.
239 */ 248 */
240void 249static void
241GNUNET_DNS_queue_request (struct GNUNET_DNS_Handle *h, 250queue_request (struct GNUNET_DNS_Handle *h,
242 struct query_packet_list *q) 251 struct query_packet_list *q)
243{ 252{
244 GNUNET_CONTAINER_DLL_insert_tail (h->head, h->tail, q); 253 GNUNET_CONTAINER_DLL_insert_tail (h->head, h->tail, q);
245 if (h->dns_connection != NULL && h->dns_transmit_handle == NULL) 254 if (h->dns_connection != NULL && h->dns_transmit_handle == NULL)
@@ -251,6 +260,78 @@ GNUNET_DNS_queue_request (struct GNUNET_DNS_Handle *h,
251} 260}
252 261
253 262
263
264/**
265 * Process a DNS request sent to an IPv4 resolver. Pass it
266 * to the DNS service for resolution.
267 *
268 * @param h DNS handle
269 * @param dst_ip destination IPv4 address
270 * @param src_ip source IPv4 address (usually local machine)
271 * @param src_port source port (to be used for reply)
272 * @param udp_packet_len length of the UDP payload in bytes
273 * @param udp_packet UDP payload
274 */
275void
276GNUNET_DNS_queue_request_v4 (struct GNUNET_DNS_Handle *h,
277 const struct in_addr *dst_ip,
278 const struct in_addr *src_ip,
279 uint16_t src_port,
280 size_t udp_packet_len,
281 const char *udp_packet)
282{
283 size_t len = sizeof (struct query_packet) + udp_packet_len - 1;
284 struct query_packet_list *query =
285 GNUNET_malloc (len + sizeof (struct answer_packet_list) -
286 sizeof (struct answer_packet));
287 query->pkt.hdr.type = htons (GNUNET_MESSAGE_TYPE_VPN_DNS_LOCAL_QUERY_DNS);
288 query->pkt.hdr.size = htons (len);
289 memcpy (query->pkt.orig_to, dst_ip, 4);
290 memcpy (query->pkt.orig_from, src_ip, 4);
291 query->pkt.addrlen = 4;
292 query->pkt.src_port = htons (src_port);
293 memcpy (query->pkt.data, udp_packet, udp_packet_len);
294 queue_request (h, query);
295}
296
297
298/**
299 * Process a DNS request sent to an IPv6 resolver. Pass it
300 * to the DNS service for resolution.
301 *
302 * @param h DNS handle
303 * @param dst_ip destination IPv6 address
304 * @param src_ip source IPv6 address (usually local machine)
305 * @param src_port source port (to be used for reply)
306 * @param udp_packet_len length of the UDP payload in bytes
307 * @param udp_packet UDP payload
308 */
309void
310GNUNET_DNS_queue_request_v6 (struct GNUNET_DNS_Handle *h,
311 const struct in6_addr *dst_ip,
312 const struct in6_addr *src_ip,
313 uint16_t src_port,
314 size_t udp_packet_len,
315 const char *udp_packet)
316{
317 size_t len =
318 sizeof (struct query_packet) + udp_packet_len - 1;
319 struct query_packet_list *query =
320 GNUNET_malloc (len + sizeof (struct answer_packet_list) -
321 sizeof (struct answer_packet));
322 query->pkt.hdr.type =
323 htons (GNUNET_MESSAGE_TYPE_VPN_DNS_LOCAL_QUERY_DNS);
324 query->pkt.hdr.size = htons (len);
325 memcpy (query->pkt.orig_to, dst_ip, 16);
326 memcpy (query->pkt.orig_from, src_ip, 16);
327 query->pkt.addrlen = 16;
328 query->pkt.src_port = htons (src_port);
329 memcpy (query->pkt.data, udp_packet,
330 udp_packet_len);
331 queue_request (h, query);
332}
333
334
254void 335void
255GNUNET_DNS_disconnect (struct GNUNET_DNS_Handle *h) 336GNUNET_DNS_disconnect (struct GNUNET_DNS_Handle *h)
256{ 337{
@@ -261,3 +342,5 @@ GNUNET_DNS_disconnect (struct GNUNET_DNS_Handle *h)
261 } 342 }
262 GNUNET_free (h); 343 GNUNET_free (h);
263} 344}
345
346/* end of dns_api.c */
diff --git a/src/dns/gnunet-service-dns.c b/src/dns/gnunet-service-dns.c
index 065c085c7..a8c3254ef 100644
--- a/src/dns/gnunet-service-dns.c
+++ b/src/dns/gnunet-service-dns.c
@@ -41,7 +41,7 @@
41#include "gnunet_mesh_service.h" 41#include "gnunet_mesh_service.h"
42#include "gnunet_signatures.h" 42#include "gnunet_signatures.h"
43 43
44 44#include "dns.h"
45 45
46 46
47 47