diff options
author | Martin Schanzenbach <mschanzenbach@posteo.de> | 2012-08-21 13:04:41 +0000 |
---|---|---|
committer | Martin Schanzenbach <mschanzenbach@posteo.de> | 2012-08-21 13:04:41 +0000 |
commit | 89080e0fd7f5641fec564a3c1ccc4c4296598122 (patch) | |
tree | 9e35ef1b390e2b6429d4501414f71992e7032371 /src/gns/gnunet-dns2gns.c | |
parent | 45b2bdc144f331fd57b474c34fd83d768ba6ba98 (diff) | |
download | gnunet-89080e0fd7f5641fec564a3c1ccc4c4296598122.tar.gz gnunet-89080e0fd7f5641fec564a3c1ccc4c4296598122.zip |
-bugfix dnsstub, add dns support to gns gateway
Diffstat (limited to 'src/gns/gnunet-dns2gns.c')
-rw-r--r-- | src/gns/gnunet-dns2gns.c | 128 |
1 files changed, 113 insertions, 15 deletions
diff --git a/src/gns/gnunet-dns2gns.c b/src/gns/gnunet-dns2gns.c index 893d592eb..5676471b8 100644 --- a/src/gns/gnunet-dns2gns.c +++ b/src/gns/gnunet-dns2gns.c | |||
@@ -26,6 +26,8 @@ | |||
26 | #include <gnunet_util_lib.h> | 26 | #include <gnunet_util_lib.h> |
27 | #include <gnunet_dnsparser_lib.h> | 27 | #include <gnunet_dnsparser_lib.h> |
28 | #include <gnunet_gns_service.h> | 28 | #include <gnunet_gns_service.h> |
29 | #include <gnunet_dnsstub_lib.h> | ||
30 | #include "gns.h" | ||
29 | 31 | ||
30 | /** | 32 | /** |
31 | * Timeout for DNS requests. | 33 | * Timeout for DNS requests. |
@@ -33,6 +35,16 @@ | |||
33 | #define TIMEOUT GNUNET_TIME_UNIT_MINUTES | 35 | #define TIMEOUT GNUNET_TIME_UNIT_MINUTES |
34 | 36 | ||
35 | /** | 37 | /** |
38 | * Default suffix | ||
39 | */ | ||
40 | #define DNS_SUFFIX ".zkey.eu" | ||
41 | |||
42 | /** | ||
43 | * FCFS suffix | ||
44 | */ | ||
45 | #define FCFS_SUFFIX "fcfs.zkey.eu" | ||
46 | |||
47 | /** | ||
36 | * Data kept per request. | 48 | * Data kept per request. |
37 | */ | 49 | */ |
38 | struct Request | 50 | struct Request |
@@ -59,6 +71,11 @@ struct Request | |||
59 | struct GNUNET_GNS_LookupRequest *lookup; | 71 | struct GNUNET_GNS_LookupRequest *lookup; |
60 | 72 | ||
61 | /** | 73 | /** |
74 | * Our DNS request handle | ||
75 | */ | ||
76 | struct GNUNET_DNSSTUB_RequestSocket *dns_lookup; | ||
77 | |||
78 | /** | ||
62 | * Task run on timeout or shutdown to clean up without | 79 | * Task run on timeout or shutdown to clean up without |
63 | * response. | 80 | * response. |
64 | */ | 81 | */ |
@@ -78,6 +95,11 @@ struct Request | |||
78 | struct GNUNET_GNS_Handle *gns; | 95 | struct GNUNET_GNS_Handle *gns; |
79 | 96 | ||
80 | /** | 97 | /** |
98 | * Stub resolver | ||
99 | */ | ||
100 | struct GNUNET_DNSSTUB_Context *dns_stub; | ||
101 | |||
102 | /** | ||
81 | * Listen socket for IPv4. | 103 | * Listen socket for IPv4. |
82 | */ | 104 | */ |
83 | static struct GNUNET_NETWORK_Handle *listen_socket4; | 105 | static struct GNUNET_NETWORK_Handle *listen_socket4; |
@@ -97,6 +119,20 @@ static GNUNET_SCHEDULER_TaskIdentifier t4; | |||
97 | */ | 119 | */ |
98 | static GNUNET_SCHEDULER_TaskIdentifier t6; | 120 | static GNUNET_SCHEDULER_TaskIdentifier t6; |
99 | 121 | ||
122 | /** | ||
123 | * DNS suffix | ||
124 | */ | ||
125 | static char *dns_suffix; | ||
126 | |||
127 | /** | ||
128 | * FCFS suffix | ||
129 | */ | ||
130 | static char *fcfs_suffix; | ||
131 | |||
132 | /** | ||
133 | * IP of DNS server | ||
134 | */ | ||
135 | static char *dns_ip; | ||
100 | 136 | ||
101 | /** | 137 | /** |
102 | * Task run on shutdown. Cleans up everything. | 138 | * Task run on shutdown. Cleans up everything. |
@@ -123,6 +159,7 @@ do_shutdown (void *cls, | |||
123 | listen_socket6 = NULL; | 159 | listen_socket6 = NULL; |
124 | } | 160 | } |
125 | GNUNET_GNS_disconnect (gns); | 161 | GNUNET_GNS_disconnect (gns); |
162 | GNUNET_DNSSTUB_stop (dns_stub); | ||
126 | gns = NULL; | 163 | gns = NULL; |
127 | } | 164 | } |
128 | 165 | ||
@@ -182,6 +219,24 @@ do_timeout (void *cls, | |||
182 | GNUNET_free (request); | 219 | GNUNET_free (request); |
183 | } | 220 | } |
184 | 221 | ||
222 | /** | ||
223 | * Iterator called on obtained result for a DNS | ||
224 | * lookup | ||
225 | * | ||
226 | * @param cls closure | ||
227 | * @param rd_count number of records | ||
228 | * @param rd the records in reply | ||
229 | */ | ||
230 | static void | ||
231 | dns_result_processor (void *cls, | ||
232 | struct GNUNET_DNSSTUB_RequestSocket *rs, | ||
233 | const struct GNUNET_TUN_DnsHeader *dns, | ||
234 | size_t r) | ||
235 | { | ||
236 | struct Request *request = cls; | ||
237 | request->packet = GNUNET_DNSPARSER_parse ((char*)dns, r); | ||
238 | send_response (request); | ||
239 | } | ||
185 | 240 | ||
186 | /** | 241 | /** |
187 | * Iterator called on obtained result for a GNS | 242 | * Iterator called on obtained result for a GNS |
@@ -332,32 +387,37 @@ handle_request (struct GNUNET_NETWORK_Handle *lsock, | |||
332 | name = GNUNET_strdup (packet->queries[0].name); | 387 | name = GNUNET_strdup (packet->queries[0].name); |
333 | name_len = strlen (name); | 388 | name_len = strlen (name); |
334 | use_gns = GNUNET_NO; | 389 | use_gns = GNUNET_NO; |
335 | if ( (name_len > strlen (".zkey.eu")) && | 390 | if ( (name_len > strlen (dns_suffix)) && |
336 | (0 == strcasecmp (".zkey.eu", | 391 | (0 == strcasecmp (dns_suffix, |
337 | &name[name_len - strlen (".zkey.eu")])) ) | 392 | &name[name_len - strlen (dns_suffix)])) ) |
338 | { | 393 | { |
339 | if (0 == strcasecmp ("fcfs.zkey.eu", | 394 | if (0 == strcasecmp (fcfs_suffix, |
340 | &name[name_len - strlen ("fcfs.zkey.eu")])) | 395 | &name[name_len - strlen (fcfs_suffix)])) |
341 | { | 396 | { |
342 | name[name_len - strlen ("zkey.eu")] = '\0'; | 397 | name[name_len - strlen (dns_suffix) + 1] = '\0'; |
343 | strcat (name, ".gnunet"); | 398 | strcat (name, GNUNET_GNS_TLD); |
344 | } | 399 | } |
345 | else | 400 | else |
346 | name[name_len - strlen (".eu")] = '\0'; | 401 | { |
402 | name[name_len - strlen (dns_suffix) + 1] = '\0'; | ||
403 | strcat (name, GNUNET_GNS_TLD_ZKEY); | ||
404 | } | ||
347 | name_len = strlen (name); | 405 | name_len = strlen (name); |
348 | } | 406 | } |
349 | if ( (name_len > strlen (".gnunet")) && | 407 | if ( (name_len > strlen ((GNUNET_GNS_TLD) + 1)) && |
350 | (0 == strcasecmp (".gnunet", | 408 | (0 == strcasecmp (GNUNET_GNS_TLD, |
351 | &name[name_len - strlen (".gnunet")])) ) | 409 | &name[name_len - strlen (GNUNET_GNS_TLD)])) ) |
352 | use_gns = GNUNET_YES; | 410 | use_gns = GNUNET_YES; |
353 | 411 | ||
354 | if ( (name_len > strlen (".zkey")) && | 412 | if ( (name_len > strlen (GNUNET_GNS_TLD_ZKEY)) && |
355 | (0 == strcasecmp (".zkey", | 413 | (0 == strcasecmp (GNUNET_GNS_TLD_ZKEY, |
356 | &name[name_len - strlen (".zkey")])) ) | 414 | &name[name_len - strlen (GNUNET_GNS_TLD_ZKEY)])) ) |
357 | use_gns = GNUNET_YES; | 415 | use_gns = GNUNET_YES; |
358 | 416 | ||
359 | if (GNUNET_YES == use_gns) | 417 | if (GNUNET_YES == use_gns) |
360 | { | 418 | { |
419 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
420 | "Calling GNS\n"); | ||
361 | type = packet->queries[0].type; | 421 | type = packet->queries[0].type; |
362 | request->lookup = GNUNET_GNS_lookup (gns, | 422 | request->lookup = GNUNET_GNS_lookup (gns, |
363 | name, | 423 | name, |
@@ -372,7 +432,17 @@ handle_request (struct GNUNET_NETWORK_Handle *lsock, | |||
372 | /* FIXME: do traditional *DNS* lookup; note that | 432 | /* FIXME: do traditional *DNS* lookup; note that |
373 | gnunet-service-dns already has code to do this; | 433 | gnunet-service-dns already has code to do this; |
374 | factor into library to share! Why not use GNUNET_RESOLVER here?*/ | 434 | factor into library to share! Why not use GNUNET_RESOLVER here?*/ |
375 | GNUNET_break (0); | 435 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
436 | "Calling DNS at %s\n", dns_ip); | ||
437 | GNUNET_DNSPARSER_free_packet (request->packet); | ||
438 | request->dns_lookup = GNUNET_DNSSTUB_resolve2 (dns_stub, | ||
439 | udp_msg, | ||
440 | udp_msg_size, | ||
441 | &dns_result_processor, | ||
442 | request); | ||
443 | |||
444 | |||
445 | |||
376 | } | 446 | } |
377 | GNUNET_free (name); | 447 | GNUNET_free (name); |
378 | } | 448 | } |
@@ -476,7 +546,26 @@ static void | |||
476 | run (void *cls, char *const *args, const char *cfgfile, | 546 | run (void *cls, char *const *args, const char *cfgfile, |
477 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 547 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
478 | { | 548 | { |
549 | if (NULL == dns_ip) | ||
550 | { | ||
551 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
552 | "No DNS server specified!\n"); | ||
553 | return; | ||
554 | } | ||
555 | |||
556 | if (NULL == dns_suffix) | ||
557 | dns_suffix = DNS_SUFFIX; | ||
558 | |||
559 | if (NULL == fcfs_suffix) | ||
560 | fcfs_suffix = FCFS_SUFFIX; | ||
561 | |||
479 | gns = GNUNET_GNS_connect (cfg); | 562 | gns = GNUNET_GNS_connect (cfg); |
563 | |||
564 | dns_stub = GNUNET_DNSSTUB_start (dns_ip); | ||
565 | |||
566 | if (NULL == dns_stub) | ||
567 | return; | ||
568 | |||
480 | if (NULL == gns) | 569 | if (NULL == gns) |
481 | return; | 570 | return; |
482 | listen_socket4 = GNUNET_NETWORK_socket_create (PF_INET, | 571 | listen_socket4 = GNUNET_NETWORK_socket_create (PF_INET, |
@@ -556,6 +645,15 @@ main (int argc, | |||
556 | char *const *argv) | 645 | char *const *argv) |
557 | { | 646 | { |
558 | static const struct GNUNET_GETOPT_CommandLineOption options[] = { | 647 | static const struct GNUNET_GETOPT_CommandLineOption options[] = { |
648 | {'d', "dns", NULL, | ||
649 | gettext_noop ("IP of recursive dns resolver to use (required)"), 1, | ||
650 | &GNUNET_GETOPT_set_string, &dns_ip}, | ||
651 | {'s', "suffix", NULL, | ||
652 | gettext_noop ("Authoritative DNS suffix to use (optional); default: zkey.eu"), 1, | ||
653 | &GNUNET_GETOPT_set_string, &dns_suffix}, | ||
654 | {'f', "fcfs", NULL, | ||
655 | gettext_noop ("Authoritative FCFS suffix to use (optional); default: fcfs.zkey.eu"), 1, | ||
656 | &GNUNET_GETOPT_set_string, &fcfs_suffix}, | ||
559 | GNUNET_GETOPT_OPTION_END | 657 | GNUNET_GETOPT_OPTION_END |
560 | }; | 658 | }; |
561 | int ret; | 659 | int ret; |