diff options
author | Christian Grothoff <christian@grothoff.org> | 2012-01-02 04:37:59 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2012-01-02 04:37:59 +0000 |
commit | 86a020dbabef7e047706f462840bfe66b036093c (patch) | |
tree | e19123a84f515ad810ed892811a5c6492b6b971f /src/dns/dns_api.c | |
parent | 1fd2ff9b321277b55444c2a074e6476cc10099c2 (diff) | |
download | gnunet-86a020dbabef7e047706f462840bfe66b036093c.tar.gz gnunet-86a020dbabef7e047706f462840bfe66b036093c.zip |
-small steps towards saner DNS API
Diffstat (limited to 'src/dns/dns_api.c')
-rw-r--r-- | src/dns/dns_api.c | 89 |
1 files changed, 86 insertions, 3 deletions
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 | |||
39 | struct 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 | ||
39 | struct GNUNET_DNS_Handle | 48 | struct 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 | */ |
240 | void | 249 | static void |
241 | GNUNET_DNS_queue_request (struct GNUNET_DNS_Handle *h, | 250 | queue_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 | */ | ||
275 | void | ||
276 | GNUNET_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 | */ | ||
309 | void | ||
310 | GNUNET_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 | |||
254 | void | 335 | void |
255 | GNUNET_DNS_disconnect (struct GNUNET_DNS_Handle *h) | 336 | GNUNET_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 */ | ||