When connecting to mesh, give your app-types!
[oweals/gnunet.git] / src / vpn / gnunet-service-dns.c
1 /*
2      This file is part of GNUnet.
3      (C) 2009 Christian Grothoff (and other contributing authors)
4
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 3, or (at your
8      option) any later version.
9
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.
14
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.
19 */
20
21 /**
22  * @file vpn/gnunet-service-dns.c
23  * @author Philipp Toelke
24  */
25 #include "platform.h"
26 #include "gnunet_getopt_lib.h"
27 #include "gnunet_service_lib.h"
28 #include "gnunet_network_lib.h"
29 #include "gnunet_os_lib.h"
30 #include "gnunet-service-dns-p.h"
31 #include "gnunet_protocols.h"
32 #include "gnunet_applications.h"
33 #include "gnunet-vpn-packet.h"
34 #include "gnunet_container_lib.h"
35 #include "gnunet-dns-parser.h"
36 #include "gnunet_dht_service.h"
37 #include "gnunet_block_lib.h"
38 #include "block_dns.h"
39 #include "gnunet_crypto_lib.h"
40 #include "gnunet_mesh_service.h"
41 #include "gnunet_signatures.h"
42
43 struct GNUNET_MESH_Handle *mesh_handle;
44
45 /**
46  * The UDP-Socket through which DNS-Resolves will be sent if they are not to be
47  * sent through gnunet. The port of this socket will not be hijacked.
48  */
49 static struct GNUNET_NETWORK_Handle *dnsout;
50
51 /**
52  * The port bound to the socket dnsout
53  */
54 static unsigned short dnsoutport;
55
56 /**
57  * A handle to the DHT-Service
58  */
59 static struct GNUNET_DHT_Handle *dht;
60
61 /**
62  * The configuration to use
63  */
64 static const struct GNUNET_CONFIGURATION_Handle *cfg;
65
66 /**
67  * The handle to the service-configuration
68  */
69 static struct GNUNET_CONFIGURATION_Handle *servicecfg;
70
71 /**
72  * A list of DNS-Responses that have to be sent to the requesting client
73  */
74 static struct answer_packet_list *head;
75
76 /**
77  * The tail of the list of DNS-responses
78  */
79 static struct answer_packet_list *tail;
80
81 /**
82  * A structure containing a mapping from network-byte-ordered DNS-id (16 bit) to
83  * some information needed to handle this query
84  *
85  * It currently allocates at least
86  * (1 + machine-width + machine-width + 32 + 32 + 16 + machine-width + 8) * 65536 bit
87  * = 17 MiB on 64 bit.
88  * = 11 MiB on 32 bit.
89  */
90 static struct {
91     unsigned valid:1;
92     struct GNUNET_SERVER_Client* client;
93     struct GNUNET_MESH_Tunnel *tunnel;
94     uint32_t local_ip;
95     uint32_t remote_ip;
96     uint16_t local_port;
97     char* name;
98     uint8_t namelen;
99 } query_states[UINT16_MAX];
100
101 /**
102  * A struct used to give more than one value as
103  * closure to receive_dht
104  */
105 struct receive_dht_cls {
106     uint16_t id;
107     struct GNUNET_DHT_GetHandle* handle;
108 };
109
110 /**
111  * Hijack all outgoing DNS-Traffic but for traffic leaving "our" port.
112  */
113 static void
114 hijack (void *cls __attribute__((unused)), const struct GNUNET_SCHEDULER_TaskContext *tc)
115 {
116   if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
117     return;
118
119   char port_s[6];
120   char *virt_dns;
121   struct GNUNET_OS_Process *proc;
122
123   if (GNUNET_SYSERR ==
124       GNUNET_CONFIGURATION_get_value_string (cfg, "vpn", "VIRTDNS",
125                                              &virt_dns))
126     {
127       GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
128                   "No entry 'VIRTDNS' in configuration!\n");
129       exit (1);
130     }
131
132   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Hijacking, port is %d\n", dnsoutport);
133   snprintf (port_s, 6, "%d", dnsoutport);
134   if (NULL != (proc = GNUNET_OS_start_process (NULL,
135                                                NULL,
136                                                "gnunet-helper-hijack-dns",
137                                                "gnunet-hijack-dns",
138                                                port_s, virt_dns, NULL)))
139     GNUNET_OS_process_close (proc);
140   GNUNET_free (virt_dns);
141 }
142
143 /**
144  * Delete the hijacking-routes
145  */
146 static void
147 unhijack (unsigned short port)
148 {
149   char port_s[6];
150   char *virt_dns;
151   struct GNUNET_OS_Process *proc;
152
153   if (GNUNET_SYSERR ==
154       GNUNET_CONFIGURATION_get_value_string (cfg, "vpn", "VIRTDNS",
155                                              &virt_dns))
156     {
157       GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
158                   "No entry 'VIRTDNS' in configuration!\n");
159       exit (1);
160     }
161
162   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "unHijacking, port is %d\n", port);
163   snprintf (port_s, 6, "%d", port);
164   if (NULL != (proc = GNUNET_OS_start_process (NULL,
165                                                NULL,
166                                                "gnunet-helper-hijack-dns",
167                                                "gnunet-hijack-dns",
168                                                "-d", port_s, virt_dns, NULL)))
169     GNUNET_OS_process_close (proc);
170   GNUNET_free (virt_dns);
171 }
172
173 /**
174  * Send the DNS-Response to the client. Gets called via the notify_transmit_ready-
175  * system.
176  */
177 static size_t
178 send_answer(void* cls, size_t size, void* buf) {
179     struct answer_packet_list* query = head;
180     size_t len = ntohs(query->pkt.hdr.size);
181
182     GNUNET_assert(len <= size);
183
184     memcpy(buf, &query->pkt.hdr, len);
185
186     GNUNET_CONTAINER_DLL_remove (head, tail, query);
187
188     GNUNET_free(query);
189
190     /* When more data is to be sent, reschedule */
191     if (head != NULL)
192       GNUNET_SERVER_notify_transmit_ready(cls,
193                                           ntohs(head->pkt.hdr.size),
194                                           GNUNET_TIME_UNIT_FOREVER_REL,
195                                           &send_answer,
196                                           cls);
197
198     return len;
199 }
200
201 struct tunnel_cls {
202     struct GNUNET_MESH_Tunnel *tunnel GNUNET_PACKED;
203     struct GNUNET_MessageHeader hdr;
204     struct dns_pkt dns;
205 };
206
207 struct tunnel_cls *remote_pending[UINT16_MAX];
208
209 static size_t
210 mesh_send_response (void *cls, size_t size, void *buf)
211 {
212   GNUNET_assert (size >= sizeof (struct GNUNET_MessageHeader));
213   struct GNUNET_MessageHeader *hdr = buf;
214   uint32_t *sz = cls;
215   struct dns_pkt *dns = (struct dns_pkt *) (sz + 1);
216   hdr->type = htons (GNUNET_MESSAGE_TYPE_REMOTE_ANSWER_DNS);
217   hdr->size = htons (*sz + sizeof (struct GNUNET_MessageHeader));
218
219   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
220               "Sending response, size=%d, sz=%d, sz+hdr=%d\n", size, *sz,
221               *sz + sizeof (struct GNUNET_MessageHeader));
222
223   GNUNET_assert (size >= (*sz + sizeof (struct GNUNET_MessageHeader)));
224
225   memcpy (hdr + 1, dns, *sz);
226   GNUNET_free (cls);
227   return ntohs (hdr->size);
228 }
229
230 static size_t
231 mesh_send (void *cls, size_t size, void *buf)
232 {
233   struct tunnel_cls *cls_ = (struct tunnel_cls *) cls;
234
235   GNUNET_assert(cls_->hdr.size <= size);
236
237   size = cls_->hdr.size;
238   cls_->hdr.size = htons(cls_->hdr.size);
239
240   memcpy(buf, &cls_->hdr, size);
241   return size;
242 }
243
244
245 void mesh_connect (void* cls, const struct GNUNET_PeerIdentity* peer, const struct GNUNET_TRANSPORT_ATS_Information *atsi __attribute__((unused))) {
246   GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Connected to peer %x\n", *((unsigned long*)peer));
247   struct tunnel_cls *cls_ = (struct tunnel_cls*)cls;
248
249   GNUNET_MESH_notify_transmit_ready(cls_->tunnel,
250                                     GNUNET_YES,
251                                     42,
252                                     GNUNET_TIME_UNIT_MINUTES,
253                                     NULL,
254                                     cls_->hdr.size,
255                                     mesh_send,
256                                     cls);
257 }
258
259
260 static void
261 send_mesh_query (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
262 {
263   if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
264     return;
265
266   struct tunnel_cls *cls_ = (struct tunnel_cls*)cls;
267
268   cls_->tunnel = GNUNET_MESH_peer_request_connect_by_type(mesh_handle,
269                                            GNUNET_TIME_UNIT_HOURS,
270                                            GNUNET_APPLICATION_TYPE_INTERNET_RESOLVER,
271                                            mesh_connect,
272                                            NULL,
273                                            cls_);
274
275   remote_pending[cls_->dns.s.id] = cls_;
276 }
277
278 static int
279 receive_mesh_query (void *cls __attribute__((unused)),
280                     struct GNUNET_MESH_Tunnel *tunnel,
281                     void **ctx __attribute__((unused)),
282                     const struct GNUNET_PeerIdentity *sender __attribute__((unused)),
283                     const struct GNUNET_MessageHeader *message,
284                     const struct GNUNET_TRANSPORT_ATS_Information *atsi __attribute__((unused)))
285 {
286   struct dns_pkt *dns = (struct dns_pkt*)(message + 1);
287
288   struct sockaddr_in dest;
289   memset(&dest, 0, sizeof dest);
290   dest.sin_port = htons(53);
291   /* TODO: read from config */
292   inet_pton(AF_INET, "8.8.8.8", &dest.sin_addr);
293
294   query_states[dns->s.id].tunnel = tunnel;
295   query_states[dns->s.id].valid = GNUNET_YES;
296
297   GNUNET_NETWORK_socket_sendto(dnsout,
298                                dns,
299                                ntohs(message->size) - sizeof(struct GNUNET_MessageHeader),
300                                (struct sockaddr*) &dest,
301                                sizeof dest);
302
303   return GNUNET_SYSERR;
304 }
305
306 static int
307 receive_mesh_answer (void *cls __attribute__((unused)),
308                      struct GNUNET_MESH_Tunnel *tunnel,
309                      void **ctx __attribute__((unused)),
310                      const struct GNUNET_PeerIdentity *sender __attribute__((unused)),
311                      const struct GNUNET_MessageHeader *message,
312                      const struct GNUNET_TRANSPORT_ATS_Information *atsi __attribute__((unused)))
313 {
314   /* TODo: size check */
315   struct dns_pkt *dns = (struct dns_pkt *) (message + 1);
316
317   /* They sent us a packet we were not waiting for */
318   if (remote_pending[dns->s.id] == NULL
319       || remote_pending[dns->s.id]->tunnel != tunnel)
320     return GNUNET_SYSERR;
321   if (query_states[dns->s.id].valid != GNUNET_YES)
322     return GNUNET_SYSERR;
323   query_states[dns->s.id].valid = GNUNET_NO;
324
325   size_t len = sizeof (struct answer_packet) - 1 + sizeof (struct dns_static) + query_states[dns->s.id].namelen + sizeof (struct dns_query_line) + 2    /* To hold the pointer (as defined in RFC1035) to the name */
326     + sizeof (struct dns_record_line) - 1 + 16; /* To hold the IPv6-Address */
327
328   struct answer_packet_list *answer =
329     GNUNET_malloc (len + 2 * sizeof (struct answer_packet_list *));
330   memset (answer, 0, len + 2 * sizeof (struct answer_packet_list *));
331
332   answer->pkt.hdr.type = htons (GNUNET_MESSAGE_TYPE_LOCAL_RESPONSE_DNS);
333   answer->pkt.hdr.size = htons (len);
334   answer->pkt.subtype = GNUNET_DNS_ANSWER_TYPE_REMOTE;
335
336   struct dns_pkt_parsed* pdns = parse_dns_packet(dns);
337
338   if (ntohs(pdns->s.ancount) < 1)
339     {
340       free_parsed_dns_packet(pdns);
341       return GNUNET_OK;
342     }
343
344   answer->pkt.addrsize = pdns->answers[0]->data_len;
345   memcpy(answer->pkt.addr, pdns->answers[0]->data, ntohs(pdns->answers[0]->data_len));
346
347   answer->pkt.from = query_states[dns->s.id].remote_ip;
348
349   answer->pkt.to = query_states[dns->s.id].local_ip;
350   answer->pkt.dst_port = query_states[dns->s.id].local_port;
351
352   struct dns_pkt *dpkt = (struct dns_pkt *) answer->pkt.data;
353
354   dpkt->s.id = dns->s.id;
355   dpkt->s.aa = 1;
356   dpkt->s.qr = 1;
357   dpkt->s.ra = 1;
358   dpkt->s.qdcount = htons (1);
359   dpkt->s.ancount = htons (1);
360
361   memcpy (dpkt->data, query_states[dns->s.id].name,
362           query_states[dns->s.id].namelen);
363   GNUNET_free (query_states[dns->s.id].name);
364
365   struct dns_query_line *dque =
366     (struct dns_query_line *) (dpkt->data +
367                                (query_states[dns->s.id].namelen));
368   dque->type = htons (28);      /* AAAA */
369   dque->class = htons (1);      /* IN */
370
371   char *anname =
372     (char *) (dpkt->data + (query_states[dns->s.id].namelen) +
373               sizeof (struct dns_query_line));
374   memcpy (anname, "\xc0\x0c", 2);
375
376   struct dns_record_line *drec_data =
377     (struct dns_record_line *) (dpkt->data +
378                                 (query_states[dns->s.id].namelen) +
379                                 sizeof (struct dns_query_line) + 2);
380   drec_data->type = htons (28); /* AAAA */
381   drec_data->class = htons (1); /* IN */
382
383   drec_data->ttl = pdns->answers[0]->ttl;
384   drec_data->data_len = htons (16);
385
386   /* Calculate at which offset in the packet the IPv6-Address belongs, it is
387    * filled in by the daemon-vpn */
388   answer->pkt.addroffset =
389     htons ((unsigned short) ((unsigned long) (&drec_data->data) -
390                              (unsigned long) (&answer->pkt)));
391
392   GNUNET_CONTAINER_DLL_insert_after (head, tail, tail, answer);
393
394   GNUNET_SERVER_notify_transmit_ready (query_states[dns->s.id].client,
395                                        len,
396                                        GNUNET_TIME_UNIT_FOREVER_REL,
397                                        &send_answer,
398                                        query_states[dns->s.id].client);
399
400   free_parsed_dns_packet(pdns);
401   return GNUNET_OK;
402 }
403
404
405 static void
406 send_rev_query(void * cls, const struct GNUNET_SCHEDULER_TaskContext *tc) {
407     if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
408       return;
409
410     struct dns_pkt_parsed* pdns = (struct dns_pkt_parsed*) cls;
411
412     unsigned short id = pdns->s.id;
413
414     free_parsed_dns_packet(pdns);
415
416     if (query_states[id].valid != GNUNET_YES) return;
417     query_states[id].valid = GNUNET_NO;
418
419     GNUNET_assert(query_states[id].namelen == 74);
420
421     size_t len = sizeof(struct answer_packet) - 1 \
422                  + sizeof(struct dns_static) \
423                  + 74 /* this is the length of a reverse ipv6-lookup */ \
424                  + sizeof(struct dns_query_line) \
425                  + 2 /* To hold the pointer (as defined in RFC1035) to the name */ \
426                  + sizeof(struct dns_record_line) - 1 \
427                  - 2 /* We do not know the lenght of the answer yet*/;
428
429     struct answer_packet_list* answer = GNUNET_malloc(len + 2*sizeof(struct answer_packet_list*));
430     memset(answer, 0, len + 2*sizeof(struct answer_packet_list*));
431
432     answer->pkt.hdr.type = htons(GNUNET_MESSAGE_TYPE_LOCAL_RESPONSE_DNS);
433     answer->pkt.hdr.size = htons(len);
434     answer->pkt.subtype = GNUNET_DNS_ANSWER_TYPE_REV;
435
436     answer->pkt.from = query_states[id].remote_ip;
437
438     answer->pkt.to = query_states[id].local_ip;
439     answer->pkt.dst_port = query_states[id].local_port;
440
441     struct dns_pkt *dpkt = (struct dns_pkt*)answer->pkt.data;
442
443     dpkt->s.id = id;
444     dpkt->s.aa = 1;
445     dpkt->s.qr = 1;
446     dpkt->s.ra = 1;
447     dpkt->s.qdcount = htons(1);
448     dpkt->s.ancount = htons(1);
449
450     memcpy(dpkt->data, query_states[id].name, query_states[id].namelen);
451     GNUNET_free(query_states[id].name);
452
453     struct dns_query_line* dque = (struct dns_query_line*)(dpkt->data+(query_states[id].namelen));
454     dque->type = htons(12); /* PTR */
455     dque->class = htons(1); /* IN */
456
457     char* anname = (char*)(dpkt->data+(query_states[id].namelen)+sizeof(struct dns_query_line));
458     memcpy(anname, "\xc0\x0c", 2);
459
460     struct dns_record_line *drec_data = (struct dns_record_line*)(dpkt->data+(query_states[id].namelen)+sizeof(struct dns_query_line)+2);
461     drec_data->type = htons(12); /* AAAA */
462     drec_data->class = htons(1); /* IN */
463     /* FIXME: read the TTL from block:
464      * GNUNET_TIME_absolute_get_remaining(rec->expiration_time)
465      *
466      * But how to get the seconds out of this?
467      */
468     drec_data->ttl = htonl(3600);
469
470     /* Calculate at which offset in the packet the length of the name and the
471      * name, it is filled in by the daemon-vpn */
472     answer->pkt.addroffset = htons((unsigned short)((unsigned long)(&drec_data->data_len)-(unsigned long)(&answer->pkt)));
473
474     GNUNET_CONTAINER_DLL_insert_after(head, tail, tail, answer);
475
476     GNUNET_SERVER_notify_transmit_ready(query_states[id].client,
477                                         len,
478                                         GNUNET_TIME_UNIT_FOREVER_REL,
479                                         &send_answer,
480                                         query_states[id].client);
481 }
482
483 /**
484  * Receive a block from the dht.
485  */
486 static void
487 receive_dht(void *cls,
488             struct GNUNET_TIME_Absolute exp __attribute__((unused)),
489             const GNUNET_HashCode *key __attribute__((unused)),
490             const struct GNUNET_PeerIdentity *const *get_path __attribute__((unused)),
491             const struct GNUNET_PeerIdentity *const *put_path __attribute__((unused)),
492             enum GNUNET_BLOCK_Type type,
493             size_t size,
494             const void *data) {
495
496     unsigned short id = ((struct receive_dht_cls*)cls)->id;
497     struct GNUNET_DHT_GetHandle* handle = ((struct receive_dht_cls*)cls)->handle;
498     GNUNET_free(cls);
499
500     GNUNET_assert(type == GNUNET_BLOCK_TYPE_DNS);
501
502     /* If no query with this id is pending, ignore the block */
503     if (query_states[id].valid != GNUNET_YES) return;
504     query_states[id].valid = GNUNET_NO;
505
506     const struct GNUNET_DNS_Record* rec = data;
507     GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
508                "Got block of size %d, peer: %08x, desc: %08x\n",
509                size,
510                *((unsigned int*)&rec->peer),
511                *((unsigned int*)&rec->service_descriptor));
512
513     size_t len = sizeof(struct answer_packet) - 1 \
514                  + sizeof(struct dns_static) \
515                  + query_states[id].namelen \
516                  + sizeof(struct dns_query_line) \
517                  + 2 /* To hold the pointer (as defined in RFC1035) to the name */ \
518                  + sizeof(struct dns_record_line) - 1 \
519                  + 16; /* To hold the IPv6-Address */
520
521     struct answer_packet_list* answer = GNUNET_malloc(len + 2*sizeof(struct answer_packet_list*));
522     memset(answer, 0, len + 2*sizeof(struct answer_packet_list*));
523
524     answer->pkt.hdr.type = htons(GNUNET_MESSAGE_TYPE_LOCAL_RESPONSE_DNS);
525     answer->pkt.hdr.size = htons(len);
526     answer->pkt.subtype = GNUNET_DNS_ANSWER_TYPE_SERVICE;
527
528     GNUNET_CRYPTO_hash(&rec->peer,
529                        sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
530                        &answer->pkt.service_descr.peer);
531
532     memcpy(&answer->pkt.service_descr.service_descriptor,
533            &rec->service_descriptor,
534            sizeof(GNUNET_HashCode));
535     memcpy(&answer->pkt.service_descr.service_type,
536            &rec->service_type,
537            sizeof(answer->pkt.service_descr.service_type));
538     memcpy(&answer->pkt.service_descr.ports, &rec->ports, sizeof(answer->pkt.service_descr.ports));
539
540     answer->pkt.from = query_states[id].remote_ip;
541
542     answer->pkt.to = query_states[id].local_ip;
543     answer->pkt.dst_port = query_states[id].local_port;
544
545     struct dns_pkt *dpkt = (struct dns_pkt*)answer->pkt.data;
546
547     dpkt->s.id = id;
548     dpkt->s.aa = 1;
549     dpkt->s.qr = 1;
550     dpkt->s.ra = 1;
551     dpkt->s.qdcount = htons(1);
552     dpkt->s.ancount = htons(1);
553
554     memcpy(dpkt->data, query_states[id].name, query_states[id].namelen);
555     GNUNET_free(query_states[id].name);
556
557     struct dns_query_line* dque = (struct dns_query_line*)(dpkt->data+(query_states[id].namelen));
558     dque->type = htons(28); /* AAAA */
559     dque->class = htons(1); /* IN */
560
561     char* anname = (char*)(dpkt->data+(query_states[id].namelen)+sizeof(struct dns_query_line));
562     memcpy(anname, "\xc0\x0c", 2);
563
564     struct dns_record_line *drec_data = (struct dns_record_line*)(dpkt->data+(query_states[id].namelen)+sizeof(struct dns_query_line)+2);
565     drec_data->type = htons(28); /* AAAA */
566     drec_data->class = htons(1); /* IN */
567
568     /* FIXME: read the TTL from block:
569      * GNUNET_TIME_absolute_get_remaining(rec->expiration_time)
570      *
571      * But how to get the seconds out of this?
572      */
573     drec_data->ttl = htonl(3600);
574     drec_data->data_len = htons(16);
575
576     /* Calculate at which offset in the packet the IPv6-Address belongs, it is
577      * filled in by the daemon-vpn */
578     answer->pkt.addroffset = htons((unsigned short)((unsigned long)(&drec_data->data)-(unsigned long)(&answer->pkt)));
579
580     GNUNET_CONTAINER_DLL_insert_after(head, tail, tail, answer);
581
582     GNUNET_SERVER_notify_transmit_ready(query_states[id].client,
583                                         len,
584                                         GNUNET_TIME_UNIT_FOREVER_REL,
585                                         &send_answer,
586                                         query_states[id].client);
587
588     GNUNET_DHT_get_stop(handle);
589 }
590
591 /**
592  * This receives a GNUNET_MESSAGE_TYPE_REHIJACK and rehijacks the DNS
593  */
594 static void
595 rehijack(void *cls __attribute__((unused)),
596          struct GNUNET_SERVER_Client *client,
597          const struct GNUNET_MessageHeader *message __attribute__((unused))) {
598     unhijack(dnsoutport);
599     GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_SECONDS, hijack, NULL);
600
601     GNUNET_SERVER_receive_done(client, GNUNET_OK);
602 }
603
604 /**
605  * This receives the dns-payload from the daemon-vpn and sends it on over the udp-socket
606  */
607 static void
608 receive_query(void *cls __attribute__((unused)),
609               struct GNUNET_SERVER_Client *client,
610               const struct GNUNET_MessageHeader *message) {
611     struct query_packet* pkt = (struct query_packet*)message;
612     struct dns_pkt* dns = (struct dns_pkt*)pkt->data;
613     struct dns_pkt_parsed* pdns = parse_dns_packet(dns);
614
615     query_states[dns->s.id].valid = GNUNET_YES;
616     query_states[dns->s.id].client = client;
617     query_states[dns->s.id].local_ip = pkt->orig_from;
618     query_states[dns->s.id].local_port = pkt->src_port;
619     query_states[dns->s.id].remote_ip = pkt->orig_to;
620     query_states[dns->s.id].namelen = strlen((char*)dns->data) + 1;
621     query_states[dns->s.id].name = GNUNET_malloc(query_states[dns->s.id].namelen);
622     memcpy(query_states[dns->s.id].name, dns->data, query_states[dns->s.id].namelen);
623
624     /* The query is for a .gnunet-address */
625     if (pdns->queries[0]->namelen > 9 &&
626         0 == strncmp(pdns->queries[0]->name+(pdns->queries[0]->namelen - 9), ".gnunet.", 9))
627       {
628         GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Query for .gnunet!\n");
629         GNUNET_HashCode key;
630         GNUNET_CRYPTO_hash(pdns->queries[0]->name, pdns->queries[0]->namelen, &key);
631
632         GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
633                    "Getting with key %08x, len is %d\n",
634                    *((unsigned int*)&key),
635                    pdns->queries[0]->namelen);
636
637         struct receive_dht_cls* cls = GNUNET_malloc(sizeof(struct receive_dht_cls));
638         cls->id = dns->s.id;
639
640         cls->handle = GNUNET_DHT_get_start(dht,
641                                            GNUNET_TIME_UNIT_MINUTES,
642                                            GNUNET_BLOCK_TYPE_DNS,
643                                            &key,
644                                            DEFAULT_GET_REPLICATION,
645                                            GNUNET_DHT_RO_NONE,
646                                            NULL,
647                                            0,
648                                            NULL,
649                                            0,
650                                            receive_dht,
651                                            cls);
652
653         goto outfree;
654       }
655
656     GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Query for '%s'; namelen=%d\n", pdns->queries[0]->name, pdns->queries[0]->namelen);
657
658     /* This is a PTR-Query. Check if it is for "our" network */
659     if (htons(pdns->queries[0]->qtype) == 12 &&
660         74 == pdns->queries[0]->namelen)
661       {
662         char* ipv6addr;
663         char ipv6[16];
664         char ipv6rev[74] = "X.X.X.X.X.X.X.X.X.X.X.X.X.X.X.X.X.X.X.X.X.X.X.X.X.X.X.X.X.X.X.X.ip6.arpa.";
665         unsigned int i;
666         unsigned long long ipv6prefix;
667         unsigned int comparelen;
668
669         GNUNET_assert(GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(cfg, "vpn", "IPV6ADDR", &ipv6addr));
670         inet_pton (AF_INET6, ipv6addr, ipv6);
671         GNUNET_free(ipv6addr);
672
673         GNUNET_assert(GNUNET_OK == GNUNET_CONFIGURATION_get_value_number(cfg, "vpn", "IPV6PREFIX", &ipv6prefix));
674         GNUNET_assert(ipv6prefix < 127);
675         ipv6prefix = (ipv6prefix + 7)/8;
676
677         for (i = ipv6prefix; i < 16; i++)
678           ipv6[i] = 0;
679
680         for (i = 0; i < 16; i++)
681           {
682             unsigned char c1 = ipv6[i] >> 4;
683             unsigned char c2 = ipv6[i] & 0xf;
684
685             if (c1 <= 9)
686               ipv6rev[62-(4*i)] = c1 + '0';
687             else
688               ipv6rev[62-(4*i)] = c1 + 87; /* 87 is the difference between 'a' and 10 */
689
690             if (c2 <= 9)
691               ipv6rev[62-((4*i)+2)] = c2 + '0';
692             else
693               ipv6rev[62-((4*i)+2)] = c2 + 87;
694           }
695         GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "My network is %s'.\n", ipv6rev);
696         comparelen = 10 + 4*ipv6prefix;
697         if(0 == strncmp(pdns->queries[0]->name+(pdns->queries[0]->namelen - comparelen),
698                         ipv6rev + (74 - comparelen),
699                         comparelen))
700           {
701             GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Reverse-Query for .gnunet!\n");
702
703             GNUNET_SCHEDULER_add_now(send_rev_query, pdns);
704
705             goto out;
706           }
707       }
708
709     char* virt_dns;
710     unsigned int virt_dns_bytes;
711     if (GNUNET_SYSERR ==
712         GNUNET_CONFIGURATION_get_value_string (cfg, "vpn", "VIRTDNS",
713                                                &virt_dns))
714       {
715         GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
716                     "No entry 'VIRTDNS' in configuration!\n");
717         exit (1);
718       }
719
720     if (1 != inet_pton (AF_INET, virt_dns, &virt_dns_bytes))
721       {
722         GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
723                     "Error parsing 'VIRTDNS': %s; %m!\n", virt_dns);
724         exit(1);
725       }
726
727     GNUNET_free(virt_dns);
728
729     if (virt_dns_bytes == pkt->orig_to)
730       {
731         /* This is a packet that was sent directly to the virtual dns-server
732          *
733          * This means we have to send this query over gnunet
734          */
735
736         size_t size = sizeof(struct GNUNET_MESH_Tunnel*) + sizeof(struct GNUNET_MessageHeader) + (ntohs(message->size) - sizeof(struct query_packet) + 1);
737         struct tunnel_cls *cls_ =  GNUNET_malloc(size);
738         cls_->hdr.size = size - sizeof(struct GNUNET_MESH_Tunnel*);
739
740         cls_->hdr.type = ntohs(GNUNET_MESSAGE_TYPE_REMOTE_QUERY_DNS);
741         GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "size: %d\n", size);
742
743         memcpy(&cls_->dns, dns, cls_->hdr.size);
744         GNUNET_SCHEDULER_add_now(send_mesh_query, cls_);
745
746         goto out;
747       }
748
749
750     /* The query should be sent to the network */
751
752     struct sockaddr_in dest;
753     memset(&dest, 0, sizeof dest);
754     dest.sin_port = htons(53);
755     dest.sin_addr.s_addr = pkt->orig_to;
756
757     GNUNET_NETWORK_socket_sendto(dnsout,
758                                  dns,
759                                  ntohs(pkt->hdr.size) - sizeof(struct query_packet) + 1,
760                                  (struct sockaddr*) &dest,
761                                  sizeof dest);
762
763 outfree:
764     free_parsed_dns_packet(pdns);
765     pdns = NULL;
766 out:
767     GNUNET_SERVER_receive_done(client, GNUNET_OK);
768 }
769
770 static void read_response (void *cls,
771                            const struct GNUNET_SCHEDULER_TaskContext *tc);
772
773 static void
774 open_port ()
775 {
776   struct sockaddr_in addr;
777
778   dnsout = GNUNET_NETWORK_socket_create (AF_INET, SOCK_DGRAM, 0);
779   if (dnsout == NULL)
780     return;
781   memset (&addr, 0, sizeof (struct sockaddr_in));
782
783   int err = GNUNET_NETWORK_socket_bind (dnsout,
784                                         (struct sockaddr *) &addr,
785                                         sizeof (struct sockaddr_in));
786
787   if (err != GNUNET_YES)
788     {
789       GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
790                   "Could not bind a port, exiting\n");
791       return;
792     }
793
794   /* Read the port we bound to */
795   socklen_t addrlen = sizeof (struct sockaddr_in);
796   err = getsockname (GNUNET_NETWORK_get_fd (dnsout),
797                      (struct sockaddr *) &addr, &addrlen);
798
799   dnsoutport = htons (addr.sin_port);
800
801   GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, dnsout,
802                                  &read_response, NULL);
803 }
804
805 /**
806  * Read a response-packet of the UDP-Socket
807  */
808 static void
809 read_response (void *cls __attribute__((unused)), const struct GNUNET_SCHEDULER_TaskContext *tc)
810 {
811   struct sockaddr_in addr;
812   socklen_t addrlen = sizeof (addr);
813   int r;
814   int len;
815
816   if (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)
817     return;
818
819   memset (&addr, 0, sizeof addr);
820
821 #ifndef MINGW
822   if (0 != ioctl (GNUNET_NETWORK_get_fd (dnsout), FIONREAD, &len))
823     {
824       unhijack (dnsoutport);
825       open_port ();
826       GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, hijack, NULL);
827       return;
828     }
829 #else
830   /* port the code above? */
831   len = 65536;
832 #endif
833   {
834     unsigned char buf[len];
835     struct dns_pkt *dns = (struct dns_pkt *) buf;
836
837     r = GNUNET_NETWORK_socket_recvfrom (dnsout,
838                                         buf,
839                                         sizeof (buf),
840                                         (struct sockaddr *) &addr, &addrlen);
841
842     if (r < 0)
843       {
844         unhijack (dnsoutport);
845         open_port ();
846         GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, hijack, NULL);
847         return;
848       }
849
850     if (query_states[dns->s.id].valid == GNUNET_YES)
851       {
852         if (query_states[dns->s.id].tunnel != NULL)
853           {
854             uint32_t *c = GNUNET_malloc(4 + r);
855             *c = r;
856             memcpy(c+1, dns, r);
857             GNUNET_MESH_notify_transmit_ready (query_states[dns->s.id].tunnel,
858                                                GNUNET_YES,
859                                                32,
860                                                GNUNET_TIME_UNIT_MINUTES,
861                                                NULL, r + sizeof(struct GNUNET_MessageHeader), mesh_send_response, c);
862           }
863         else
864           {
865             query_states[dns->s.id].valid = GNUNET_NO;
866
867             size_t len = sizeof (struct answer_packet) + r - 1; /* 1 for the unsigned char data[1]; */
868             struct answer_packet_list *answer =
869               GNUNET_malloc (len + 2 * sizeof (struct answer_packet_list *));
870             answer->pkt.hdr.type =
871               htons (GNUNET_MESSAGE_TYPE_LOCAL_RESPONSE_DNS);
872             answer->pkt.hdr.size = htons (len);
873             answer->pkt.subtype = GNUNET_DNS_ANSWER_TYPE_IP;
874             answer->pkt.from = addr.sin_addr.s_addr;
875             answer->pkt.to = query_states[dns->s.id].local_ip;
876             answer->pkt.dst_port = query_states[dns->s.id].local_port;
877             memcpy (answer->pkt.data, buf, r);
878
879             GNUNET_CONTAINER_DLL_insert_after (head, tail, tail, answer);
880
881             GNUNET_SERVER_notify_transmit_ready (query_states[dns->s.id].
882                                                  client, len,
883                                                  GNUNET_TIME_UNIT_FOREVER_REL,
884                                                  &send_answer,
885                                                  query_states[dns->s.id].
886                                                  client);
887           }
888       }
889   }
890   GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
891                                  dnsout, &read_response, NULL);
892 }
893
894
895 /**
896  * Task run during shutdown.
897  *
898  * @param cls unused
899  * @param tc unused
900  */
901 static void
902 cleanup_task (void *cls __attribute__((unused)),
903               const struct GNUNET_SCHEDULER_TaskContext *tc)
904 {
905   GNUNET_assert(0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN));
906
907   unhijack(dnsoutport);
908   GNUNET_DHT_disconnect(dht);
909 }
910
911 /**
912  * @brief Create a port-map from udp and tcp redirects
913  *
914  * @param udp_redirects
915  * @param tcp_redirects
916  *
917  * @return 
918  */
919 uint64_t
920 get_port_from_redirects (const char *udp_redirects, const char *tcp_redirects)
921 {
922   uint64_t ret = 0;
923   char* cpy, *hostname, *redirect;
924   int local_port, count = 0;
925
926   if (NULL != udp_redirects)
927     {
928       cpy = GNUNET_strdup (udp_redirects);
929       for (redirect = strtok (cpy, " "); redirect != NULL; redirect = strtok (NULL, " "))
930         {
931           if (NULL == (hostname = strstr (redirect, ":")))
932             {
933               GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Warning: option %s is not formatted correctly!\n", redirect);
934               continue;
935             }
936           hostname[0] = '\0';
937           local_port = atoi (redirect);
938           if (!((local_port > 0) && (local_port < 65536)))
939             GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Warning: %s is not a correct port.", redirect);
940
941           ret |= (0xFFFF & htons(local_port));
942           ret <<= 16;
943           count ++;
944
945           if(count > 4)
946             {
947               ret = 0;
948               goto out;
949             }
950         }
951       GNUNET_free(cpy);
952       cpy = NULL;
953     }
954
955   if (NULL != tcp_redirects)
956     {
957       cpy = GNUNET_strdup (tcp_redirects);
958       for (redirect = strtok (cpy, " "); redirect != NULL; redirect = strtok (NULL, " "))
959         {
960           if (NULL == (hostname = strstr (redirect, ":")))
961             {
962               GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Warning: option %s is not formatted correctly!\n", redirect);
963               continue;
964             }
965           hostname[0] = '\0';
966           local_port = atoi (redirect);
967           if (!((local_port > 0) && (local_port < 65536)))
968             GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Warning: %s is not a correct port.", redirect);
969
970           ret |= (0xFFFF & htons(local_port));
971           ret <<= 16;
972           count ++;
973
974           if(count > 4)
975             {
976               ret = 0;
977               goto out;
978             }
979         }
980       GNUNET_free(cpy);
981       cpy = NULL;
982     }
983
984 out:
985   if (NULL != cpy)
986     GNUNET_free(cpy);
987   return ret;
988 }
989
990 void
991 publish_name (const char *name, uint64_t ports, uint32_t service_type,
992               struct GNUNET_CRYPTO_RsaPrivateKey *my_private_key)
993 {
994   size_t size = sizeof (struct GNUNET_DNS_Record);
995   struct GNUNET_DNS_Record data;
996   memset (&data, 0, size);
997
998   data.purpose.size =
999     htonl (size - sizeof (struct GNUNET_CRYPTO_RsaSignature));
1000   data.purpose.purpose = GNUNET_SIGNATURE_PURPOSE_DNS_RECORD;
1001
1002   GNUNET_CRYPTO_hash (name, strlen (name) + 1, &data.service_descriptor);
1003   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Store with key1 %x\n",
1004               *((unsigned long long *) &data.service_descriptor));
1005
1006   data.service_type = service_type;
1007   data.ports = ports;
1008
1009   GNUNET_CRYPTO_rsa_key_get_public (my_private_key, &data.peer);
1010
1011   data.expiration_time =
1012     GNUNET_TIME_relative_to_absolute (GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_HOURS, 2));
1013
1014   /* Sign the block */
1015   if (GNUNET_OK != GNUNET_CRYPTO_rsa_sign (my_private_key,
1016                                            &data.purpose, &data.signature))
1017     {
1018       GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "could not sign DNS_Record\n");
1019       return;
1020     }
1021
1022   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1023               "Putting with key %08x, size = %d\n",
1024               *((unsigned int *) &data.service_descriptor), size);
1025
1026   GNUNET_DHT_put (dht,
1027                   &data.service_descriptor,
1028                   DEFAULT_PUT_REPLICATION,
1029                   GNUNET_DHT_RO_NONE,
1030                   GNUNET_BLOCK_TYPE_DNS,
1031                   size,
1032                   (char *) &data,
1033                   GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_HOURS),
1034                   GNUNET_TIME_UNIT_MINUTES, NULL, NULL);
1035 }
1036
1037 /**
1038  * @brief Publishes the record defined by the section section
1039  *
1040  * @param cls closure
1041  * @param section the current section
1042  */
1043 void
1044 publish_iterate (void *cls __attribute__((unused)), const char *section)
1045 {
1046   char *udp_redirects, *tcp_redirects, *alternative_names, *alternative_name,
1047     *keyfile;
1048
1049   GNUNET_CONFIGURATION_get_value_string (servicecfg, section,
1050                                          "UDP_REDIRECTS", &udp_redirects);
1051   GNUNET_CONFIGURATION_get_value_string (servicecfg, section, "TCP_REDIRECTS",
1052                                          &tcp_redirects);
1053
1054   if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg, "GNUNETD",
1055                                                             "HOSTKEY",
1056                                                             &keyfile))
1057     {
1058       GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "could not read keyfile-value\n");
1059       if (keyfile != NULL)
1060         GNUNET_free (keyfile);
1061       return;
1062     }
1063
1064   struct GNUNET_CRYPTO_RsaPrivateKey *my_private_key =
1065     GNUNET_CRYPTO_rsa_key_create_from_file (keyfile);
1066   GNUNET_free (keyfile);
1067   GNUNET_assert (my_private_key != NULL);
1068
1069   uint64_t ports = get_port_from_redirects (udp_redirects, tcp_redirects);
1070   uint32_t service_type = 0;
1071
1072   if (NULL != udp_redirects)
1073     service_type = GNUNET_DNS_SERVICE_TYPE_UDP;
1074
1075   if (NULL != tcp_redirects)
1076     service_type |= GNUNET_DNS_SERVICE_TYPE_TCP;
1077
1078   service_type = htonl (service_type);
1079
1080
1081   publish_name (section, ports, service_type, my_private_key);
1082
1083   GNUNET_CONFIGURATION_get_value_string (servicecfg, section,
1084                                          "ALTERNATIVE_NAMES",
1085                                          &alternative_names);
1086   for (alternative_name = strtok (alternative_names, " ");
1087        alternative_name != NULL; alternative_name = strtok (NULL, " "))
1088     {
1089       char *altname =
1090         alloca (strlen (alternative_name) + strlen (section) + 1 + 1);
1091       strcpy (altname, alternative_name);
1092       strcpy (altname + strlen (alternative_name) + 1, section);
1093       altname[strlen (alternative_name)] = '.';
1094
1095       publish_name (altname, ports, service_type, my_private_key);
1096     }
1097
1098   GNUNET_free_non_null(alternative_names);
1099   GNUNET_CRYPTO_rsa_key_free (my_private_key);
1100   GNUNET_free_non_null (udp_redirects);
1101   GNUNET_free_non_null (tcp_redirects);
1102 }
1103
1104 /**
1105  * Publish a DNS-record in the DHT. This is up to now just for testing.
1106  */
1107 static void
1108 publish_names (void *cls __attribute__((unused)),
1109                const struct GNUNET_SCHEDULER_TaskContext *tc) {
1110     char *services;
1111     if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
1112       return;
1113
1114     if (NULL != servicecfg)
1115       GNUNET_CONFIGURATION_destroy(servicecfg);
1116
1117     GNUNET_CONFIGURATION_get_value_filename(cfg, "dns", "SERVICES", &services);
1118
1119     servicecfg = GNUNET_CONFIGURATION_create();
1120     if (GNUNET_OK == GNUNET_CONFIGURATION_parse(servicecfg, services))
1121       {
1122         GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Parsing services %s\n", services);
1123         GNUNET_CONFIGURATION_iterate_sections(servicecfg, publish_iterate, NULL);
1124       }
1125     if (NULL != services)
1126       GNUNET_free(services);
1127
1128     GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_HOURS,
1129                                   publish_names,
1130                                   NULL);
1131 }
1132
1133 /**
1134  * @param cls closure
1135  * @param server the initialized server
1136  * @param cfg_ configuration to use
1137  */
1138 static void
1139 run (void *cls,
1140      struct GNUNET_SERVER_Handle *server,
1141      const struct GNUNET_CONFIGURATION_Handle *cfg_)
1142 {
1143   static const struct GNUNET_SERVER_MessageHandler handlers[] = {
1144     /* callback, cls, type, size */
1145     {&receive_query, NULL, GNUNET_MESSAGE_TYPE_LOCAL_QUERY_DNS, 0},
1146     {&rehijack, NULL, GNUNET_MESSAGE_TYPE_REHIJACK,
1147      sizeof (struct GNUNET_MessageHeader)},
1148     {NULL, NULL, 0, 0}
1149   };
1150
1151   static struct GNUNET_MESH_MessageHandler *mesh_handlers;
1152
1153   if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_yesno(cfg_, "dns", "PROVIDE_EXIT"))
1154     mesh_handlers = (struct GNUNET_MESH_MessageHandler[]) {
1155           {receive_mesh_query, GNUNET_MESSAGE_TYPE_REMOTE_QUERY_DNS, 0},
1156           {NULL, 0, 0}
1157     };
1158   else
1159     mesh_handlers = (struct GNUNET_MESH_MessageHandler[]) {
1160           {receive_mesh_answer, GNUNET_MESSAGE_TYPE_REMOTE_ANSWER_DNS, 0},
1161           {NULL, 0, 0}
1162     };
1163
1164   static const GNUNET_MESH_ApplicationType apptypes[] =
1165     { GNUNET_APPLICATION_TYPE_INTERNET_RESOLVER,
1166     GNUNET_APPLICATION_TYPE_END
1167   };
1168
1169   mesh_handle = GNUNET_MESH_connect (cfg_, NULL, NULL, mesh_handlers, apptypes);
1170
1171   cfg = cfg_;
1172
1173   unsigned int i;
1174   for (i = 0; i < 65536; i++)
1175     {
1176       query_states[i].valid = GNUNET_NO;
1177     }
1178
1179   dht = GNUNET_DHT_connect (cfg, 1024);
1180
1181   open_port ();
1182
1183   GNUNET_SCHEDULER_add_now (publish_names, NULL);
1184
1185   GNUNET_SERVER_add_handlers (server, handlers);
1186   GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
1187                                 &cleanup_task, cls);
1188 }
1189
1190 /**
1191  * The main function for the dns service.
1192  *
1193  * @param argc number of arguments from the command line
1194  * @param argv command line arguments
1195  * @return 0 ok, 1 on error
1196  */
1197 int
1198 main (int argc, char *const *argv)
1199 {
1200   return (GNUNET_OK ==
1201           GNUNET_SERVICE_run (argc,
1202                               argv,
1203                               "dns",
1204                               GNUNET_SERVICE_OPTION_NONE,
1205                               &run, NULL)) ? 0 : 1;
1206 }