diff options
author | grothoff <grothoff@140774ce-b5e7-0310-ab8b-a85725594a96> | 2012-01-02 04:37:59 +0000 |
---|---|---|
committer | grothoff <grothoff@140774ce-b5e7-0310-ab8b-a85725594a96> | 2012-01-02 04:37:59 +0000 |
commit | 26f89386d0385186761ce879902f55fa5b29280a (patch) | |
tree | e19123a84f515ad810ed892811a5c6492b6b971f /src/dns | |
parent | 668ae8914843103371fbe50445aaa6c46633f982 (diff) |
-small steps towards saner DNS API
git-svn-id: https://gnunet.org/svn/gnunet@18915 140774ce-b5e7-0310-ab8b-a85725594a96
Diffstat (limited to 'src/dns')
-rw-r--r-- | src/dns/Makefile.am | 5 | ||||
-rw-r--r-- | src/dns/dns.conf | 11 | ||||
-rw-r--r-- | src/dns/dns.h | 54 | ||||
-rw-r--r-- | src/dns/dns_api.c | 89 | ||||
-rw-r--r-- | src/dns/gnunet-service-dns.c | 2 |
5 files changed, 156 insertions, 5 deletions
diff --git a/src/dns/Makefile.am b/src/dns/Makefile.am index 4e26372048..a7aafa4fc8 100644 --- a/src/dns/Makefile.am +++ b/src/dns/Makefile.am @@ -12,6 +12,9 @@ pkgcfgdir= $(pkgdatadir)/config.d/ plugindir = $(libdir)/gnunet +dist_pkgcfg_DATA = \ + dns.conf + if LINUX HIJACKBIN = gnunet-helper-hijack-dns install-exec-hook: @@ -52,7 +55,7 @@ libgnunetdnsparser_la_LDFLAGS = \ libgnunetdns_la_SOURCES = \ - dns_api.c + dns_api.c dns.h libgnunetdns_la_LIBADD = \ $(top_builddir)/src/util/libgnunetutil.la $(XLIB) libgnunetdns_la_LDFLAGS = \ diff --git a/src/dns/dns.conf b/src/dns/dns.conf new file mode 100644 index 0000000000..59d8276929 --- /dev/null +++ b/src/dns/dns.conf @@ -0,0 +1,11 @@ +[dns] +AUTOSTART = YES +PORT = 0 +HOSTNAME = localhost +HOME = $SERVICEHOME +CONFIG = $DEFAULTCONFIG +BINARY = gnunet-service-dns +ACCEPT_FROM = 127.0.0.1; +ACCEPT_FROM6 = ::1; +UNIXPATH = /tmp/gnunet-service-dns.sock +PROVIDE_EXIT = NO diff --git a/src/dns/dns.h b/src/dns/dns.h new file mode 100644 index 0000000000..dd0f55e166 --- /dev/null +++ b/src/dns/dns.h @@ -0,0 +1,54 @@ +/* + This file is part of GNUnet + (C) 2010, 2011, 2012 Christian Grothoff (and other contributing authors) + + GNUnet is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published + by the Free Software Foundation; either version 2, or (at your + option) any later version. + + GNUnet is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with GNUnet; see the file COPYING. If not, write to the + Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. + */ + +/** + * @file dns/dns.h + * @brief IPC messages between DNS API and DNS service + * @author Philipp Toelke + * @author Christian Grothoff + */ +#ifndef DNS_H +#define DNS_H + +GNUNET_NETWORK_STRUCT_BEGIN + +struct query_packet +{ + struct GNUNET_MessageHeader hdr; + + /** + * The IP-Address this query was originally sent to + */ + char orig_to[16]; + /** + * The IP-Address this query was originally sent from + */ + char orig_from[16]; + char addrlen; + /** + * The UDP-Port this query was originally sent from + */ + uint16_t src_port GNUNET_PACKED; + + unsigned char data[1]; /* The DNS-Packet */ +}; +GNUNET_NETWORK_STRUCT_END + +#endif diff --git a/src/dns/dns_api.c b/src/dns/dns_api.c index 90b4a8f42f..68b703ebab 100644 --- a/src/dns/dns_api.c +++ b/src/dns/dns_api.c @@ -34,6 +34,15 @@ #include <block_dns.h> #include "gnunet_dns_service.h" +#include "dns.h" + +struct query_packet_list +{ + struct query_packet_list *next GNUNET_PACKED; + struct query_packet_list *prev GNUNET_PACKED; + struct query_packet pkt; +}; + struct GNUNET_DNS_Handle @@ -237,9 +246,9 @@ GNUNET_DNS_restart_hijack (struct GNUNET_DNS_Handle *h) * FIXME: we should not expost our internal structures like this. * Just a quick initial hack. */ -void -GNUNET_DNS_queue_request (struct GNUNET_DNS_Handle *h, - struct query_packet_list *q) +static void +queue_request (struct GNUNET_DNS_Handle *h, + struct query_packet_list *q) { GNUNET_CONTAINER_DLL_insert_tail (h->head, h->tail, q); if (h->dns_connection != NULL && h->dns_transmit_handle == NULL) @@ -251,6 +260,78 @@ GNUNET_DNS_queue_request (struct GNUNET_DNS_Handle *h, } + +/** + * Process a DNS request sent to an IPv4 resolver. Pass it + * to the DNS service for resolution. + * + * @param h DNS handle + * @param dst_ip destination IPv4 address + * @param src_ip source IPv4 address (usually local machine) + * @param src_port source port (to be used for reply) + * @param udp_packet_len length of the UDP payload in bytes + * @param udp_packet UDP payload + */ +void +GNUNET_DNS_queue_request_v4 (struct GNUNET_DNS_Handle *h, + const struct in_addr *dst_ip, + const struct in_addr *src_ip, + uint16_t src_port, + size_t udp_packet_len, + const char *udp_packet) +{ + size_t len = sizeof (struct query_packet) + udp_packet_len - 1; + struct query_packet_list *query = + GNUNET_malloc (len + sizeof (struct answer_packet_list) - + sizeof (struct answer_packet)); + query->pkt.hdr.type = htons (GNUNET_MESSAGE_TYPE_VPN_DNS_LOCAL_QUERY_DNS); + query->pkt.hdr.size = htons (len); + memcpy (query->pkt.orig_to, dst_ip, 4); + memcpy (query->pkt.orig_from, src_ip, 4); + query->pkt.addrlen = 4; + query->pkt.src_port = htons (src_port); + memcpy (query->pkt.data, udp_packet, udp_packet_len); + queue_request (h, query); +} + + +/** + * Process a DNS request sent to an IPv6 resolver. Pass it + * to the DNS service for resolution. + * + * @param h DNS handle + * @param dst_ip destination IPv6 address + * @param src_ip source IPv6 address (usually local machine) + * @param src_port source port (to be used for reply) + * @param udp_packet_len length of the UDP payload in bytes + * @param udp_packet UDP payload + */ +void +GNUNET_DNS_queue_request_v6 (struct GNUNET_DNS_Handle *h, + const struct in6_addr *dst_ip, + const struct in6_addr *src_ip, + uint16_t src_port, + size_t udp_packet_len, + const char *udp_packet) +{ + size_t len = + sizeof (struct query_packet) + udp_packet_len - 1; + struct query_packet_list *query = + GNUNET_malloc (len + sizeof (struct answer_packet_list) - + sizeof (struct answer_packet)); + query->pkt.hdr.type = + htons (GNUNET_MESSAGE_TYPE_VPN_DNS_LOCAL_QUERY_DNS); + query->pkt.hdr.size = htons (len); + memcpy (query->pkt.orig_to, dst_ip, 16); + memcpy (query->pkt.orig_from, src_ip, 16); + query->pkt.addrlen = 16; + query->pkt.src_port = htons (src_port); + memcpy (query->pkt.data, udp_packet, + udp_packet_len); + queue_request (h, query); +} + + void GNUNET_DNS_disconnect (struct GNUNET_DNS_Handle *h) { @@ -261,3 +342,5 @@ GNUNET_DNS_disconnect (struct GNUNET_DNS_Handle *h) } GNUNET_free (h); } + +/* end of dns_api.c */ diff --git a/src/dns/gnunet-service-dns.c b/src/dns/gnunet-service-dns.c index 065c085c7f..a8c3254efd 100644 --- a/src/dns/gnunet-service-dns.c +++ b/src/dns/gnunet-service-dns.c @@ -41,7 +41,7 @@ #include "gnunet_mesh_service.h" #include "gnunet_signatures.h" - +#include "dns.h" |