diff options
-rw-r--r-- | doc/man/gnunet-dns2gns.1 | 20 | ||||
-rw-r--r-- | src/gns/gnunet-dns2gns.c | 382 |
2 files changed, 118 insertions, 284 deletions
diff --git a/doc/man/gnunet-dns2gns.1 b/doc/man/gnunet-dns2gns.1 index 03f471ed8..04fcb7f53 100644 --- a/doc/man/gnunet-dns2gns.1 +++ b/doc/man/gnunet-dns2gns.1 | |||
@@ -1,4 +1,4 @@ | |||
1 | .TH GNUNET\-DNS2GNS 1 "Oct 25, 2012" "GNUnet" | 1 | .TH GNUNET\-DNS2GNS 1 "March 5, 2018" "GNUnet" |
2 | 2 | ||
3 | .SH NAME | 3 | .SH NAME |
4 | gnunet\-dns2gns \- run a DNS-to-GNS proxy | 4 | gnunet\-dns2gns \- run a DNS-to-GNS proxy |
@@ -9,13 +9,9 @@ gnunet\-dns2gns \- run a DNS-to-GNS proxy | |||
9 | .br | 9 | .br |
10 | 10 | ||
11 | .SH DESCRIPTION | 11 | .SH DESCRIPTION |
12 | Most users will not want to run an DNS to GADS proxy/gateway and thus will not need this program. | 12 | Most users will not want to run an DNS to GNS proxy/gateway and thus will not need this program. |
13 | 13 | ||
14 | \fBgnunet\-dns2gns\fP runs a DNS resolver which delegates requests to the ".gads" and ".zkey" zones to GADS. All other requests are forwarded to DNS. This DNS proxy is useful for enabling non-personalized GADS\-resolution to an entire network or to offer GADS\-resolution to DNS users. | 14 | \fBgnunet\-dns2gns\fP runs a DNS resolver which delegates requests GNS if the TLD matches one configured for GNS. All other requests are forwarded to DNS. This DNS proxy is useful for enabling non-personalized GNS\-resolution to an entire network or to offer GNS\-resolution to DNS users. |
15 | |||
16 | A DNS\-to\-GNS proxy using gnunet\-dns2gns is available at ".zkey.eu" | ||
17 | |||
18 | If you do not want to specify a public key and are the owner of the zone that gnunet\-dns2gns will use for GNS lookups, you need to first create a pseudonym (using "gnunet\-identity \-C NAME"), and then assign it to be used for the "dns2gns" service using "gnunet\-identity \-e NAME \-s dns2gns". After that, you can start the dns2gns service (possibly using gnunet\-arm) without specifying a public key using "\-z". | ||
19 | 15 | ||
20 | .SH OPTIONS | 16 | .SH OPTIONS |
21 | .B | 17 | .B |
@@ -25,24 +21,14 @@ Use the configuration file FILENAME. | |||
25 | .IP "\-d IP, \-\-dns=IP" | 21 | .IP "\-d IP, \-\-dns=IP" |
26 | IP address of a recursive DNS resolver that should be used for non-GADS hostnames. | 22 | IP address of a recursive DNS resolver that should be used for non-GADS hostnames. |
27 | .B | 23 | .B |
28 | .IP "\-f NAME, \-\-fcfs=NAME" | ||
29 | Authoritative FCFS suffix to use. This is the name under which the local zone's names will be made available. Default is "fcfs.zkey.eu". | ||
30 | .B | ||
31 | .IP "\-h, \-\-help" | 24 | .IP "\-h, \-\-help" |
32 | Print short help on options. | 25 | Print short help on options. |
33 | .B | 26 | .B |
34 | .IP "\-L LOGLEVEL, \-\-loglevel=LOGLEVEL" | 27 | .IP "\-L LOGLEVEL, \-\-loglevel=LOGLEVEL" |
35 | Use LOGLEVEL for logging. Valid values are DEBUG, INFO, WARNING and ERROR. | 28 | Use LOGLEVEL for logging. Valid values are DEBUG, INFO, WARNING and ERROR. |
36 | .B | 29 | .B |
37 | .IP "\-s SUFFIX, \-\-suffix=SUFFIX" | ||
38 | Authoritative DNS suffix to use. This is the name under which the GADS ".zkey" zone is mapped into the DNS namespace. Default is "zkey.eu". | ||
39 | .B | ||
40 | .IP "\-v, \-\-version" | 30 | .IP "\-v, \-\-version" |
41 | Print GNUnet version number. | 31 | Print GNUnet version number. |
42 | .B | ||
43 | .IP "\-z PUBLICKEY, \-\-zone=PUBLICKEY" | ||
44 | Use PUBLICKEY for the zone to resolve GNS names in. The PUBLICKEY must be encoded in the text format which can be obtained using gnunet\-ecc, seen in PKEY records and output by gnunet\-identity. If this option is not specified, the default ego associated by gnunet\-identity for the "dns2gns" subsystem will be used. | ||
45 | |||
46 | 32 | ||
47 | .SH BUGS | 33 | .SH BUGS |
48 | Report bugs by using Mantis <https://gnunet.org/bugs/> or by sending electronic mail to <bug\-gnunet@gnu.org> | 34 | Report bugs by using Mantis <https://gnunet.org/bugs/> or by sending electronic mail to <bug\-gnunet@gnu.org> |
diff --git a/src/gns/gnunet-dns2gns.c b/src/gns/gnunet-dns2gns.c index 2f0de030d..3d16cd773 100644 --- a/src/gns/gnunet-dns2gns.c +++ b/src/gns/gnunet-dns2gns.c | |||
@@ -26,7 +26,6 @@ | |||
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_identity_service.h> | ||
30 | #include <gnunet_dnsstub_lib.h> | 29 | #include <gnunet_dnsstub_lib.h> |
31 | #include "gns.h" | 30 | #include "gns.h" |
32 | 31 | ||
@@ -36,16 +35,6 @@ | |||
36 | #define TIMEOUT GNUNET_TIME_UNIT_MINUTES | 35 | #define TIMEOUT GNUNET_TIME_UNIT_MINUTES |
37 | 36 | ||
38 | /** | 37 | /** |
39 | * Default suffix | ||
40 | */ | ||
41 | #define DNS_SUFFIX ".zkey.eu" | ||
42 | |||
43 | /** | ||
44 | * FCFS suffix | ||
45 | */ | ||
46 | #define FCFS_SUFFIX "fcfs.zkey.eu" | ||
47 | |||
48 | /** | ||
49 | * Data kept per request. | 38 | * Data kept per request. |
50 | */ | 39 | */ |
51 | struct Request | 40 | struct Request |
@@ -69,7 +58,7 @@ struct Request | |||
69 | /** | 58 | /** |
70 | * Our GNS request handle. | 59 | * Our GNS request handle. |
71 | */ | 60 | */ |
72 | struct GNUNET_GNS_LookupRequest *lookup; | 61 | struct GNUNET_GNS_LookupWithTldRequest *lookup; |
73 | 62 | ||
74 | /** | 63 | /** |
75 | * Our DNS request handle | 64 | * Our DNS request handle |
@@ -80,13 +69,22 @@ struct Request | |||
80 | * Task run on timeout or shutdown to clean up without | 69 | * Task run on timeout or shutdown to clean up without |
81 | * response. | 70 | * response. |
82 | */ | 71 | */ |
83 | struct GNUNET_SCHEDULER_Task * timeout_task; | 72 | struct GNUNET_SCHEDULER_Task *timeout_task; |
84 | 73 | ||
85 | /** | 74 | /** |
86 | * Number of bytes in 'addr'. | 75 | * Original UDP request message. |
76 | */ | ||
77 | char *udp_msg; | ||
78 | |||
79 | /** | ||
80 | * Number of bytes in @e addr. | ||
87 | */ | 81 | */ |
88 | size_t addr_len; | 82 | size_t addr_len; |
89 | 83 | ||
84 | /** | ||
85 | * Number of bytes in @e udp_msg. | ||
86 | */ | ||
87 | size_t udp_msg_size; | ||
90 | }; | 88 | }; |
91 | 89 | ||
92 | 90 | ||
@@ -113,22 +111,12 @@ static struct GNUNET_NETWORK_Handle *listen_socket6; | |||
113 | /** | 111 | /** |
114 | * Task for IPv4 socket. | 112 | * Task for IPv4 socket. |
115 | */ | 113 | */ |
116 | static struct GNUNET_SCHEDULER_Task * t4; | 114 | static struct GNUNET_SCHEDULER_Task *t4; |
117 | 115 | ||
118 | /** | 116 | /** |
119 | * Task for IPv6 socket. | 117 | * Task for IPv6 socket. |
120 | */ | 118 | */ |
121 | static struct GNUNET_SCHEDULER_Task * t6; | 119 | static struct GNUNET_SCHEDULER_Task *t6; |
122 | |||
123 | /** | ||
124 | * DNS suffix, suffix of this gateway in DNS; defaults to '.zkey.eu' | ||
125 | */ | ||
126 | static char *dns_suffix; | ||
127 | |||
128 | /** | ||
129 | * FCFS suffix, suffix of FCFS-authority in DNS; defaults to 'fcfs.zkey.eu'. | ||
130 | */ | ||
131 | static char *fcfs_suffix; | ||
132 | 120 | ||
133 | /** | 121 | /** |
134 | * IP of DNS server | 122 | * IP of DNS server |
@@ -141,30 +129,10 @@ static char *dns_ip; | |||
141 | static unsigned int listen_port = 53; | 129 | static unsigned int listen_port = 53; |
142 | 130 | ||
143 | /** | 131 | /** |
144 | * Which GNS zone do we translate incoming DNS requests to? | ||
145 | */ | ||
146 | static struct GNUNET_CRYPTO_EcdsaPublicKey my_zone; | ||
147 | |||
148 | /** | ||
149 | * '-z' option with the main zone to use. | ||
150 | */ | ||
151 | static char *gns_zone_str; | ||
152 | |||
153 | /** | ||
154 | * Configuration to use. | 132 | * Configuration to use. |
155 | */ | 133 | */ |
156 | static const struct GNUNET_CONFIGURATION_Handle *cfg; | 134 | static const struct GNUNET_CONFIGURATION_Handle *cfg; |
157 | 135 | ||
158 | /** | ||
159 | * Connection to identity service. | ||
160 | */ | ||
161 | static struct GNUNET_IDENTITY_Handle *identity; | ||
162 | |||
163 | /** | ||
164 | * Request for our ego. | ||
165 | */ | ||
166 | static struct GNUNET_IDENTITY_Operation *id_op; | ||
167 | |||
168 | 136 | ||
169 | /** | 137 | /** |
170 | * Task run on shutdown. Cleans up everything. | 138 | * Task run on shutdown. Cleans up everything. |
@@ -174,6 +142,7 @@ static struct GNUNET_IDENTITY_Operation *id_op; | |||
174 | static void | 142 | static void |
175 | do_shutdown (void *cls) | 143 | do_shutdown (void *cls) |
176 | { | 144 | { |
145 | (void) cls; | ||
177 | if (NULL != t4) | 146 | if (NULL != t4) |
178 | { | 147 | { |
179 | GNUNET_SCHEDULER_cancel (t4); | 148 | GNUNET_SCHEDULER_cancel (t4); |
@@ -194,16 +163,6 @@ do_shutdown (void *cls) | |||
194 | GNUNET_NETWORK_socket_close (listen_socket6); | 163 | GNUNET_NETWORK_socket_close (listen_socket6); |
195 | listen_socket6 = NULL; | 164 | listen_socket6 = NULL; |
196 | } | 165 | } |
197 | if (NULL != id_op) | ||
198 | { | ||
199 | GNUNET_IDENTITY_cancel (id_op); | ||
200 | id_op = NULL; | ||
201 | } | ||
202 | if (NULL != identity) | ||
203 | { | ||
204 | GNUNET_IDENTITY_disconnect (identity); | ||
205 | identity = NULL; | ||
206 | } | ||
207 | if (NULL != gns) | 166 | if (NULL != gns) |
208 | { | 167 | { |
209 | GNUNET_GNS_disconnect (gns); | 168 | GNUNET_GNS_disconnect (gns); |
@@ -227,6 +186,7 @@ send_response (struct Request *request) | |||
227 | { | 186 | { |
228 | char *buf; | 187 | char *buf; |
229 | size_t size; | 188 | size_t size; |
189 | ssize_t sret; | ||
230 | 190 | ||
231 | if (GNUNET_SYSERR == | 191 | if (GNUNET_SYSERR == |
232 | GNUNET_DNSPARSER_pack (request->packet, | 192 | GNUNET_DNSPARSER_pack (request->packet, |
@@ -239,16 +199,20 @@ send_response (struct Request *request) | |||
239 | } | 199 | } |
240 | else | 200 | else |
241 | { | 201 | { |
242 | if (size != | 202 | sret = GNUNET_NETWORK_socket_sendto (request->lsock, |
243 | GNUNET_NETWORK_socket_sendto (request->lsock, | 203 | buf, |
244 | buf, size, | 204 | size, |
245 | request->addr, | 205 | request->addr, |
246 | request->addr_len)) | 206 | request->addr_len); |
247 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "sendto"); | 207 | if ( (sret < 0) || |
208 | (size != (size_t) sret) ) | ||
209 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, | ||
210 | "sendto"); | ||
248 | GNUNET_free (buf); | 211 | GNUNET_free (buf); |
249 | } | 212 | } |
250 | GNUNET_SCHEDULER_cancel (request->timeout_task); | 213 | GNUNET_SCHEDULER_cancel (request->timeout_task); |
251 | GNUNET_DNSPARSER_free_packet (request->packet); | 214 | GNUNET_DNSPARSER_free_packet (request->packet); |
215 | GNUNET_free (request->udp_msg); | ||
252 | GNUNET_free (request); | 216 | GNUNET_free (request); |
253 | } | 217 | } |
254 | 218 | ||
@@ -266,9 +230,10 @@ do_timeout (void *cls) | |||
266 | if (NULL != request->packet) | 230 | if (NULL != request->packet) |
267 | GNUNET_DNSPARSER_free_packet (request->packet); | 231 | GNUNET_DNSPARSER_free_packet (request->packet); |
268 | if (NULL != request->lookup) | 232 | if (NULL != request->lookup) |
269 | GNUNET_GNS_lookup_cancel (request->lookup); | 233 | GNUNET_GNS_lookup_with_tld_cancel (request->lookup); |
270 | if (NULL != request->dns_lookup) | 234 | if (NULL != request->dns_lookup) |
271 | GNUNET_DNSSTUB_resolve_cancel (request->dns_lookup); | 235 | GNUNET_DNSSTUB_resolve_cancel (request->dns_lookup); |
236 | GNUNET_free (request->udp_msg); | ||
272 | GNUNET_free (request); | 237 | GNUNET_free (request); |
273 | } | 238 | } |
274 | 239 | ||
@@ -289,7 +254,9 @@ dns_result_processor (void *cls, | |||
289 | { | 254 | { |
290 | struct Request *request = cls; | 255 | struct Request *request = cls; |
291 | 256 | ||
292 | request->packet = GNUNET_DNSPARSER_parse ((char*)dns, r); | 257 | (void) rs; |
258 | request->packet = GNUNET_DNSPARSER_parse ((char*)dns, | ||
259 | r); | ||
293 | send_response (request); | 260 | send_response (request); |
294 | } | 261 | } |
295 | 262 | ||
@@ -298,11 +265,13 @@ dns_result_processor (void *cls, | |||
298 | * Iterator called on obtained result for a GNS lookup. | 265 | * Iterator called on obtained result for a GNS lookup. |
299 | * | 266 | * |
300 | * @param cls closure | 267 | * @param cls closure |
268 | * @param was_gns #GNUNET_NO if the TLD is not configured for GNS | ||
301 | * @param rd_count number of records in @a rd | 269 | * @param rd_count number of records in @a rd |
302 | * @param rd the records in reply | 270 | * @param rd the records in reply |
303 | */ | 271 | */ |
304 | static void | 272 | static void |
305 | result_processor (void *cls, | 273 | result_processor (void *cls, |
274 | int was_gns, | ||
306 | uint32_t rd_count, | 275 | uint32_t rd_count, |
307 | const struct GNUNET_GNSRECORD_Data *rd) | 276 | const struct GNUNET_GNSRECORD_Data *rd) |
308 | { | 277 | { |
@@ -312,6 +281,22 @@ result_processor (void *cls, | |||
312 | struct GNUNET_DNSPARSER_Record rec; | 281 | struct GNUNET_DNSPARSER_Record rec; |
313 | 282 | ||
314 | request->lookup = NULL; | 283 | request->lookup = NULL; |
284 | if (GNUNET_NO == was_gns) | ||
285 | { | ||
286 | /* TLD not configured for GNS, fall back to DNS */ | ||
287 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
288 | "Using DNS resolver IP `%s' to resolve `%s'\n", | ||
289 | dns_ip, | ||
290 | request->packet->queries[0].name); | ||
291 | GNUNET_DNSPARSER_free_packet (request->packet); | ||
292 | request->packet = NULL; | ||
293 | request->dns_lookup = GNUNET_DNSSTUB_resolve2 (dns_stub, | ||
294 | request->udp_msg, | ||
295 | request->udp_msg_size, | ||
296 | &dns_result_processor, | ||
297 | request); | ||
298 | return; | ||
299 | } | ||
315 | packet = request->packet; | 300 | packet = request->packet; |
316 | packet->flags.query_or_response = 1; | 301 | packet->flags.query_or_response = 1; |
317 | packet->flags.return_code = GNUNET_TUN_DNS_RETURN_CODE_NO_ERROR; | 302 | packet->flags.return_code = GNUNET_TUN_DNS_RETURN_CODE_NO_ERROR; |
@@ -396,19 +381,16 @@ handle_request (struct GNUNET_NETWORK_Handle *lsock, | |||
396 | { | 381 | { |
397 | struct Request *request; | 382 | struct Request *request; |
398 | struct GNUNET_DNSPARSER_Packet *packet; | 383 | struct GNUNET_DNSPARSER_Packet *packet; |
399 | char *name; | ||
400 | size_t name_len; | ||
401 | int type; | ||
402 | int use_gns; | ||
403 | 384 | ||
404 | packet = GNUNET_DNSPARSER_parse (udp_msg, udp_msg_size); | 385 | packet = GNUNET_DNSPARSER_parse (udp_msg, |
386 | udp_msg_size); | ||
405 | if (NULL == packet) | 387 | if (NULL == packet) |
406 | { | 388 | { |
407 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 389 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
408 | _("Cannot parse DNS request from %s\n"), | 390 | _("Cannot parse DNS request from %s\n"), |
409 | GNUNET_a2s (addr, addr_len)); | 391 | GNUNET_a2s (addr, addr_len)); |
410 | return; | 392 | return; |
411 | } | 393 | } |
412 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 394 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
413 | "Received request for `%s' with flags %u, #answers %d, #auth %d, #additional %d\n", | 395 | "Received request for `%s' with flags %u, #answers %d, #auth %d, #additional %d\n", |
414 | packet->queries[0].name, | 396 | packet->queries[0].name, |
@@ -419,88 +401,45 @@ handle_request (struct GNUNET_NETWORK_Handle *lsock, | |||
419 | if ( (0 != packet->flags.query_or_response) || | 401 | if ( (0 != packet->flags.query_or_response) || |
420 | (0 != packet->num_answers) || | 402 | (0 != packet->num_answers) || |
421 | (0 != packet->num_authority_records)) | 403 | (0 != packet->num_authority_records)) |
422 | { | 404 | { |
423 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 405 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
424 | _("Received malformed DNS request from %s\n"), | 406 | _("Received malformed DNS request from %s\n"), |
425 | GNUNET_a2s (addr, addr_len)); | 407 | GNUNET_a2s (addr, addr_len)); |
426 | GNUNET_DNSPARSER_free_packet (packet); | 408 | GNUNET_DNSPARSER_free_packet (packet); |
427 | return; | 409 | return; |
428 | } | 410 | } |
429 | if ( (1 != packet->num_queries) ) | 411 | if ( (1 != packet->num_queries) ) |
430 | { | 412 | { |
431 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 413 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
432 | _("Received unsupported DNS request from %s\n"), | 414 | _("Received unsupported DNS request from %s\n"), |
433 | GNUNET_a2s (addr, addr_len)); | 415 | GNUNET_a2s (addr, |
434 | GNUNET_DNSPARSER_free_packet (packet); | 416 | addr_len)); |
435 | return; | 417 | GNUNET_DNSPARSER_free_packet (packet); |
436 | } | 418 | return; |
419 | } | ||
437 | request = GNUNET_malloc (sizeof (struct Request) + addr_len); | 420 | request = GNUNET_malloc (sizeof (struct Request) + addr_len); |
438 | request->lsock = lsock; | 421 | request->lsock = lsock; |
439 | request->packet = packet; | 422 | request->packet = packet; |
440 | request->addr = &request[1]; | 423 | request->addr = &request[1]; |
441 | request->addr_len = addr_len; | 424 | request->addr_len = addr_len; |
442 | GNUNET_memcpy (&request[1], addr, addr_len); | 425 | GNUNET_memcpy (&request[1], |
426 | addr, | ||
427 | addr_len); | ||
428 | request->udp_msg_size = udp_msg_size; | ||
429 | request->udp_msg = GNUNET_memdup (udp_msg, | ||
430 | udp_msg_size); | ||
443 | request->timeout_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, | 431 | request->timeout_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, |
444 | &do_timeout, | 432 | &do_timeout, |
445 | request); | 433 | request); |
446 | name = GNUNET_strdup (packet->queries[0].name); | 434 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
447 | name_len = strlen (name); | 435 | "Calling GNS on `%s'\n", |
448 | use_gns = GNUNET_NO; | 436 | packet->queries[0].name); |
449 | 437 | request->lookup = GNUNET_GNS_lookup_with_tld (gns, | |
450 | 438 | packet->queries[0].name, | |
451 | if ( (name_len > strlen (fcfs_suffix)) && | 439 | packet->queries[0].type, |
452 | (0 == strcasecmp (fcfs_suffix, | 440 | GNUNET_NO, |
453 | &name[name_len - strlen (fcfs_suffix)])) ) | 441 | &result_processor, |
454 | { | 442 | request); |
455 | /* replace ".fcfs.zkey.eu" with ".gnu" */ | ||
456 | strcpy (&name[name_len - strlen (fcfs_suffix)], | ||
457 | ".gnu"); | ||
458 | use_gns = GNUNET_YES; | ||
459 | } | ||
460 | else if ( (name_len > strlen (dns_suffix)) && | ||
461 | (0 == strcasecmp (dns_suffix, | ||
462 | &name[name_len - strlen (dns_suffix)])) ) | ||
463 | { | ||
464 | /* replace ".zkey.eu" with ".zkey" */ | ||
465 | strcpy (&name[name_len - strlen (dns_suffix)], | ||
466 | ".zkey"); | ||
467 | use_gns = GNUNET_YES; | ||
468 | } else if ( (name_len > strlen (".gnu")) && | ||
469 | (0 == strcasecmp (".gnu", | ||
470 | &name[name_len - strlen (".gnu")])) ) | ||
471 | { | ||
472 | /* name is in GNS */ | ||
473 | use_gns = GNUNET_YES; | ||
474 | } | ||
475 | if (GNUNET_YES == use_gns) | ||
476 | { | ||
477 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
478 | "Calling GNS on `%s'\n", | ||
479 | name); | ||
480 | type = packet->queries[0].type; | ||
481 | request->lookup = GNUNET_GNS_lookup (gns, | ||
482 | name, | ||
483 | &my_zone, | ||
484 | type, | ||
485 | GNUNET_NO, | ||
486 | &result_processor, | ||
487 | request); | ||
488 | } | ||
489 | else | ||
490 | { | ||
491 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
492 | "Using DNS resolver IP `%s' to resolve `%s'\n", | ||
493 | dns_ip, | ||
494 | name); | ||
495 | GNUNET_DNSPARSER_free_packet (request->packet); | ||
496 | request->packet = NULL; | ||
497 | request->dns_lookup = GNUNET_DNSSTUB_resolve2 (dns_stub, | ||
498 | udp_msg, | ||
499 | udp_msg_size, | ||
500 | &dns_result_processor, | ||
501 | request); | ||
502 | } | ||
503 | GNUNET_free (name); | ||
504 | } | 443 | } |
505 | 444 | ||
506 | 445 | ||
@@ -547,7 +486,7 @@ read_dns4 (void *cls) | |||
547 | "recvfrom"); | 486 | "recvfrom"); |
548 | return; | 487 | return; |
549 | } | 488 | } |
550 | GNUNET_break (size == (size_t) sret); | 489 | GNUNET_break (size == sret); |
551 | handle_request (listen_socket4, | 490 | handle_request (listen_socket4, |
552 | &v4, | 491 | &v4, |
553 | addrlen, | 492 | addrlen, |
@@ -600,7 +539,7 @@ read_dns6 (void *cls) | |||
600 | "recvfrom"); | 539 | "recvfrom"); |
601 | return; | 540 | return; |
602 | } | 541 | } |
603 | GNUNET_break (size == (size_t) sret); | 542 | GNUNET_break (size == sret); |
604 | handle_request (listen_socket6, | 543 | handle_request (listen_socket6, |
605 | &v6, | 544 | &v6, |
606 | addrlen, | 545 | addrlen, |
@@ -611,15 +550,31 @@ read_dns6 (void *cls) | |||
611 | 550 | ||
612 | 551 | ||
613 | /** | 552 | /** |
614 | * Start DNS daemon. | 553 | * Main function that will be run. |
554 | * | ||
555 | * @param cls closure | ||
556 | * @param args remaining command-line arguments | ||
557 | * @param cfgfile name of the configuration file used (for saving, can be NULL!) | ||
558 | * @param c configuration | ||
615 | */ | 559 | */ |
616 | static void | 560 | static void |
617 | run_dnsd () | 561 | run (void *cls, |
562 | char *const *args, | ||
563 | const char *cfgfile, | ||
564 | const struct GNUNET_CONFIGURATION_Handle *c) | ||
618 | { | 565 | { |
619 | if (NULL == dns_suffix) | 566 | (void) cls; |
620 | dns_suffix = DNS_SUFFIX; | 567 | (void) args; |
621 | if (NULL == fcfs_suffix) | 568 | (void) cfgfile; |
622 | fcfs_suffix = FCFS_SUFFIX; | 569 | cfg = c; |
570 | if (NULL == dns_ip) | ||
571 | { | ||
572 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
573 | _("No DNS server specified!\n")); | ||
574 | return; | ||
575 | } | ||
576 | GNUNET_SCHEDULER_add_shutdown (&do_shutdown, | ||
577 | NULL); | ||
623 | if (NULL == (gns = GNUNET_GNS_connect (cfg))) | 578 | if (NULL == (gns = GNUNET_GNS_connect (cfg))) |
624 | return; | 579 | return; |
625 | if (NULL == (dns_stub = GNUNET_DNSSTUB_start (dns_ip))) | 580 | if (NULL == (dns_stub = GNUNET_DNSSTUB_start (dns_ip))) |
@@ -697,92 +652,6 @@ run_dnsd () | |||
697 | 652 | ||
698 | 653 | ||
699 | /** | 654 | /** |
700 | * Method called to inform about the egos of this peer. | ||
701 | * | ||
702 | * When used with #GNUNET_IDENTITY_create or #GNUNET_IDENTITY_get, | ||
703 | * this function is only called ONCE, and 'NULL' being passed in | ||
704 | * @a ego does indicate an error (i.e. name is taken or no default | ||
705 | * value is known). If @a ego is non-NULL and if '*ctx' | ||
706 | * is set in those callbacks, the value WILL be passed to a subsequent | ||
707 | * call to the identity callback of #GNUNET_IDENTITY_connect (if | ||
708 | * that one was not NULL). | ||
709 | * | ||
710 | * @param cls closure, NULL | ||
711 | * @param ego ego handle | ||
712 | * @param ctx context for application to store data for this ego | ||
713 | * (during the lifetime of this process, initially NULL) | ||
714 | * @param name name assigned by the user for this ego, | ||
715 | * NULL if the user just deleted the ego and it | ||
716 | * must thus no longer be used | ||
717 | */ | ||
718 | static void | ||
719 | identity_cb (void *cls, | ||
720 | struct GNUNET_IDENTITY_Ego *ego, | ||
721 | void **ctx, | ||
722 | const char *name) | ||
723 | { | ||
724 | id_op = NULL; | ||
725 | if (NULL == ego) | ||
726 | { | ||
727 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
728 | _("No ego configured for `dns2gns` subsystem\n")); | ||
729 | return; | ||
730 | } | ||
731 | GNUNET_IDENTITY_ego_get_public_key (ego, | ||
732 | &my_zone); | ||
733 | run_dnsd (); | ||
734 | } | ||
735 | |||
736 | |||
737 | /** | ||
738 | * Main function that will be run. | ||
739 | * | ||
740 | * @param cls closure | ||
741 | * @param args remaining command-line arguments | ||
742 | * @param cfgfile name of the configuration file used (for saving, can be NULL!) | ||
743 | * @param c configuration | ||
744 | */ | ||
745 | static void | ||
746 | run (void *cls, | ||
747 | char *const *args, | ||
748 | const char *cfgfile, | ||
749 | const struct GNUNET_CONFIGURATION_Handle *c) | ||
750 | { | ||
751 | cfg = c; | ||
752 | |||
753 | if (NULL == dns_ip) | ||
754 | { | ||
755 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
756 | _("No DNS server specified!\n")); | ||
757 | return; | ||
758 | } | ||
759 | GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL); | ||
760 | if (NULL == gns_zone_str) | ||
761 | { | ||
762 | identity = GNUNET_IDENTITY_connect (cfg, | ||
763 | NULL, NULL); | ||
764 | id_op = GNUNET_IDENTITY_get (identity, | ||
765 | "dns2gns", | ||
766 | &identity_cb, | ||
767 | NULL); | ||
768 | return; | ||
769 | } | ||
770 | if ( (NULL == gns_zone_str) || | ||
771 | (GNUNET_OK != | ||
772 | GNUNET_CRYPTO_ecdsa_public_key_from_string (gns_zone_str, | ||
773 | strlen (gns_zone_str), | ||
774 | &my_zone)) ) | ||
775 | { | ||
776 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
777 | _("No valid GNS zone specified!\n")); | ||
778 | GNUNET_SCHEDULER_shutdown (); | ||
779 | return; | ||
780 | } | ||
781 | run_dnsd (); | ||
782 | } | ||
783 | |||
784 | |||
785 | /** | ||
786 | * The main function for the dns2gns daemon. | 655 | * The main function for the dns2gns daemon. |
787 | * | 656 | * |
788 | * @param argc number of arguments from the command line | 657 | * @param argc number of arguments from the command line |
@@ -794,37 +663,16 @@ main (int argc, | |||
794 | char *const *argv) | 663 | char *const *argv) |
795 | { | 664 | { |
796 | struct GNUNET_GETOPT_CommandLineOption options[] = { | 665 | struct GNUNET_GETOPT_CommandLineOption options[] = { |
797 | |||
798 | GNUNET_GETOPT_option_string ('d', | 666 | GNUNET_GETOPT_option_string ('d', |
799 | "dns", | 667 | "dns", |
800 | "IP", | 668 | "IP", |
801 | gettext_noop ("IP of recursive DNS resolver to use (required)"), | 669 | gettext_noop ("IP of recursive DNS resolver to use (required)"), |
802 | &dns_ip), | 670 | &dns_ip), |
803 | |||
804 | GNUNET_GETOPT_option_string ('f', | ||
805 | "fcfs", | ||
806 | "NAME", | ||
807 | gettext_noop ("Authoritative FCFS suffix to use (optional); default: fcfs.zkey.eu"), | ||
808 | &fcfs_suffix), | ||
809 | |||
810 | GNUNET_GETOPT_option_string ('s', | ||
811 | "suffix", | ||
812 | "SUFFIX", | ||
813 | gettext_noop ("Authoritative DNS suffix to use (optional); default: zkey.eu"), | ||
814 | &dns_suffix), | ||
815 | |||
816 | GNUNET_GETOPT_option_uint ('p', | 671 | GNUNET_GETOPT_option_uint ('p', |
817 | "port", | 672 | "port", |
818 | "UDPPORT", | 673 | "UDPPORT", |
819 | gettext_noop ("UDP port to listen on for inbound DNS requests; default: 2853"), | 674 | gettext_noop ("UDP port to listen on for inbound DNS requests; default: 2853"), |
820 | &listen_port), | 675 | &listen_port), |
821 | |||
822 | GNUNET_GETOPT_option_string ('z', | ||
823 | "zone", | ||
824 | "PUBLICKEY", | ||
825 | gettext_noop ("Public key of the GNS zone to use (overrides default)"), | ||
826 | &gns_zone_str), | ||
827 | |||
828 | GNUNET_GETOPT_OPTION_END | 676 | GNUNET_GETOPT_OPTION_END |
829 | }; | 677 | }; |
830 | int ret; | 678 | int ret; |