2 This file is part of GNUnet
3 (C) 2010, 2011, 2012 Christian Grothoff (and other contributing authors)
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.
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.
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.
22 * @file include/gnunet_dns_service.h
23 * @brief API to access the DNS service. Not finished at all,
24 * currently only contains the structs for the IPC, which
25 * don't even belong here (legacy code in transition)
26 * @author Philipp Toelke
29 * - replace (most?) structs with nice function (prototypes) that take
30 * the appropriate arguments to pass the data
31 * - clean up API implementation itself (nicer reconnect, etc.)
33 #ifndef GNUNET_DNS_SERVICE_H
34 #define GNUNET_DNS_SERVICE_H
36 #include "gnunet_common.h"
37 #include "gnunet_util_lib.h"
41 * Subtypes of DNS answers.
43 enum GNUNET_DNS_ANSWER_Subtype
46 * Answers of this type contain a dns-packet that just has to be transmitted
48 GNUNET_DNS_ANSWER_TYPE_IP,
51 * Answers of this type contain an incomplete dns-packet. The IP-Address
52 * is all 0s. The addroffset points to it.
54 GNUNET_DNS_ANSWER_TYPE_SERVICE,
57 * Answers of this type contain an incomplete dns-packet as answer to a
58 * PTR-Query. The resolved name is not allocated. The addroffset points to it.
60 GNUNET_DNS_ANSWER_TYPE_REV,
63 * Answers of this type contains an IP6-Address but traffic to this IP should
64 * be routed through the GNUNet.
66 GNUNET_DNS_ANSWER_TYPE_REMOTE_AAAA,
69 * Answers of this type contains an IP4-Address but traffic to this IP should
70 * be routed through the GNUNet.
72 GNUNET_DNS_ANSWER_TYPE_REMOTE_A
77 GNUNET_NETWORK_STRUCT_BEGIN
78 struct GNUNET_vpn_service_descriptor
80 GNUNET_HashCode peer GNUNET_PACKED;
81 GNUNET_HashCode service_descriptor GNUNET_PACKED;
82 uint64_t ports GNUNET_PACKED;
83 uint32_t service_type GNUNET_PACKED;
90 struct GNUNET_MessageHeader hdr;
91 enum GNUNET_DNS_ANSWER_Subtype subtype GNUNET_PACKED;
96 unsigned dst_port:16 GNUNET_PACKED;
99 /* Data for GNUNET_DNS_ANSWER_TYPE_SERVICE */
100 struct GNUNET_vpn_service_descriptor service_descr;
103 /* Data for GNUNET_DNS_ANSWER_TYPE_REV */
104 /* The offsett in octets from the beginning of the struct to the field
105 * in data where the IP-Address has to go. */
106 uint16_t addroffset GNUNET_PACKED;
109 /* Data for GNUNET_DNS_ANSWER_TYPE_REMOTE */
112 unsigned char addr[16];
115 unsigned char data[1];
117 GNUNET_NETWORK_STRUCT_END
122 * Type of a function to be called by the DNS API whenever
123 * a DNS reply is obtained.
126 * @param pkt reply that we got
128 typedef void (*GNUNET_DNS_ResponseCallback)(void *cls,
129 const struct answer_packet *pkt);
135 struct GNUNET_DNS_Handle;
139 * Connect to the service-dns
141 * @param cfg configuration to use
142 * @param cb function to call with DNS replies
143 * @param cb_cls closure to pass to cb
146 struct GNUNET_DNS_Handle *
147 GNUNET_DNS_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
148 GNUNET_DNS_ResponseCallback cb,
153 * Signal the DNS service that it needs to re-initialize the DNS
154 * hijacking (the network setup has changed significantly).
156 * @param h DNS handle
159 GNUNET_DNS_restart_hijack (struct GNUNET_DNS_Handle *h);
163 * Process a DNS request sent to an IPv4 resolver. Pass it
164 * to the DNS service for resolution.
166 * @param h DNS handle
167 * @param dst_ip destination IPv4 address
168 * @param src_ip source IPv4 address (usually local machine)
169 * @param src_port source port (to be used for reply)
170 * @param udp_packet_len length of the UDP payload in bytes
171 * @param udp_packet UDP payload
174 GNUNET_DNS_queue_request_v4 (struct GNUNET_DNS_Handle *h,
175 const struct in_addr *dst_ip,
176 const struct in_addr *src_ip,
178 size_t udp_packet_len,
179 const char *udp_packet);
182 * Process a DNS request sent to an IPv6 resolver. Pass it
183 * to the DNS service for resolution.
185 * @param h DNS handle
186 * @param dst_ip destination IPv6 address
187 * @param src_ip source IPv6 address (usually local machine)
188 * @param src_port source port (to be used for reply)
189 * @param udp_packet_len length of the UDP payload in bytes
190 * @param udp_packet UDP payload
193 GNUNET_DNS_queue_request_v6 (struct GNUNET_DNS_Handle *h,
194 const struct in6_addr *dst_ip,
195 const struct in6_addr *src_ip,
197 size_t udp_packet_len,
198 const char *udp_packet);
201 * Disconnect from the DNS service.
203 * @param h DNS handle
206 GNUNET_DNS_disconnect (struct GNUNET_DNS_Handle *h);