2 This file is part of GNUnet.
3 (C) 2009 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 3, 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 vpn/gnunet-service-dns.c
23 * @author Philipp Toelke
26 #include "gnunet_getopt_lib.h"
27 #include "gnunet_service_lib.h"
28 #include <gnunet_constants.h>
29 #include "gnunet_network_lib.h"
30 #include "gnunet_os_lib.h"
31 #include "gnunet-service-dns-p.h"
32 #include "gnunet_protocols.h"
33 #include "gnunet_applications.h"
34 #include "gnunet-vpn-packet.h"
35 #include "gnunet_container_lib.h"
36 #include "gnunet-dns-parser.h"
37 #include "gnunet_dht_service.h"
38 #include "gnunet_block_lib.h"
39 #include "block_dns.h"
40 #include "gnunet_crypto_lib.h"
41 #include "gnunet_mesh_service.h"
42 #include "gnunet_signatures.h"
44 struct GNUNET_MESH_Handle *mesh_handle;
47 * The tunnel to send queries
49 static struct GNUNET_MESH_Tunnel* dns_tunnel;
51 char dns_tunnel_connected;
54 * The UDP-Socket through which DNS-Resolves will be sent if they are not to be
55 * sent through gnunet. The port of this socket will not be hijacked.
57 static struct GNUNET_NETWORK_Handle *dnsout;
60 * The port bound to the socket dnsout
62 static unsigned short dnsoutport;
65 * A handle to the DHT-Service
67 static struct GNUNET_DHT_Handle *dht;
70 * The configuration to use
72 static const struct GNUNET_CONFIGURATION_Handle *cfg;
75 * A list of DNS-Responses that have to be sent to the requesting client
77 static struct answer_packet_list *head;
80 * The tail of the list of DNS-responses
82 static struct answer_packet_list *tail;
85 * A structure containing a mapping from network-byte-ordered DNS-id (16 bit) to
86 * some information needed to handle this query
88 * It currently allocates at least
89 * (1 + machine-width + machine-width + 32 + 32 + 16 + machine-width + 8) * 65536 bit
95 struct GNUNET_SERVER_Client* client;
96 struct GNUNET_MESH_Tunnel *tunnel;
102 } query_states[UINT16_MAX];
105 * A struct used to give more than one value as
106 * closure to receive_dht
108 struct receive_dht_cls {
110 struct GNUNET_DHT_GetHandle* handle;
113 struct tunnel_notify_queue
115 struct tunnel_notify_queue* next;
116 struct tunnel_notify_queue* prev;
119 GNUNET_CONNECTION_TransmitReadyNotify cb;
123 * Hijack all outgoing DNS-Traffic but for traffic leaving "our" port.
126 hijack (void *cls __attribute__((unused)), const struct GNUNET_SCHEDULER_TaskContext *tc)
128 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
133 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Delaying the hijacking, port is still %d!\n", dnsoutport);
134 GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_SECONDS, hijack, NULL);
140 struct GNUNET_OS_Process *proc;
143 GNUNET_CONFIGURATION_get_value_string (cfg, "vpn", "VIRTDNS",
146 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
147 "No entry 'VIRTDNS' in configuration!\n");
151 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Hijacking, port is %d\n", dnsoutport);
152 snprintf (port_s, 6, "%d", dnsoutport);
153 if (NULL != (proc = GNUNET_OS_start_process (NULL,
155 "gnunet-helper-hijack-dns",
157 port_s, virt_dns, NULL)))
158 GNUNET_OS_process_close (proc);
159 GNUNET_free (virt_dns);
163 * Delete the hijacking-routes
166 unhijack (unsigned short port)
170 struct GNUNET_OS_Process *proc;
173 GNUNET_CONFIGURATION_get_value_string (cfg, "vpn", "VIRTDNS",
176 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
177 "No entry 'VIRTDNS' in configuration!\n");
181 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "unHijacking, port is %d\n", port);
182 snprintf (port_s, 6, "%d", port);
183 if (NULL != (proc = GNUNET_OS_start_process (NULL,
185 "gnunet-helper-hijack-dns",
187 "-d", port_s, virt_dns, NULL)))
188 GNUNET_OS_process_close (proc);
189 GNUNET_free (virt_dns);
193 * Send the DNS-Response to the client. Gets called via the notify_transmit_ready-
197 send_answer(void* cls, size_t size, void* buf) {
198 struct answer_packet_list* query = head;
199 size_t len = ntohs(query->pkt.hdr.size);
201 GNUNET_assert(len <= size);
203 memcpy(buf, &query->pkt.hdr, len);
205 GNUNET_CONTAINER_DLL_remove (head, tail, query);
209 /* When more data is to be sent, reschedule */
211 GNUNET_SERVER_notify_transmit_ready(cls,
212 ntohs(head->pkt.hdr.size),
213 GNUNET_TIME_UNIT_FOREVER_REL,
221 struct GNUNET_MESH_Tunnel *tunnel GNUNET_PACKED;
222 struct GNUNET_MessageHeader hdr;
226 struct tunnel_cls *remote_pending[UINT16_MAX];
229 mesh_send_response (void *cls, size_t size, void *buf)
231 GNUNET_assert (size >= sizeof (struct GNUNET_MessageHeader));
232 struct GNUNET_MessageHeader *hdr = buf;
234 struct GNUNET_MESH_Tunnel **tunnel = (struct GNUNET_MESH_Tunnel**)(sz+1);
235 GNUNET_MESH_tunnel_set_data(*tunnel, NULL);
236 struct dns_pkt *dns = (struct dns_pkt *) (tunnel + 1);
237 hdr->type = htons (GNUNET_MESSAGE_TYPE_REMOTE_ANSWER_DNS);
238 hdr->size = htons (*sz + sizeof (struct GNUNET_MessageHeader));
240 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
241 "Sending response, size=%d, sz=%d, sz+hdr=%d\n", size, *sz,
242 *sz + sizeof (struct GNUNET_MessageHeader));
244 GNUNET_assert (size >= (*sz + sizeof (struct GNUNET_MessageHeader)));
246 memcpy (hdr + 1, dns, *sz);
248 if (NULL != GNUNET_MESH_tunnel_get_head(*tunnel))
250 struct tunnel_notify_queue* element = GNUNET_MESH_tunnel_get_head(*tunnel);
251 struct tunnel_notify_queue* head = GNUNET_MESH_tunnel_get_head(*tunnel);
252 struct tunnel_notify_queue* tail = GNUNET_MESH_tunnel_get_tail(*tunnel);
254 GNUNET_CONTAINER_DLL_remove(head, tail, element);
256 GNUNET_MESH_tunnel_set_head(*tunnel, head);
257 GNUNET_MESH_tunnel_set_tail(*tunnel, tail);
258 struct GNUNET_MESH_TransmitHandle* th = GNUNET_MESH_notify_transmit_ready (*tunnel,
261 GNUNET_TIME_relative_divide
262 (GNUNET_CONSTANTS_MAX_CORK_DELAY, 2),
263 (const struct GNUNET_PeerIdentity *)
265 element->cb, element->cls);
266 /* save the handle */
267 GNUNET_MESH_tunnel_set_data(*tunnel, th);
272 return ntohs (hdr->size);
276 mesh_send (void *cls, size_t size, void *buf)
278 struct tunnel_cls *cls_ = (struct tunnel_cls *) cls;
279 GNUNET_MESH_tunnel_set_data(cls_->tunnel, NULL);
281 GNUNET_assert(cls_->hdr.size <= size);
283 size = cls_->hdr.size;
284 cls_->hdr.size = htons(cls_->hdr.size);
286 memcpy(buf, &cls_->hdr, size);
288 if (NULL != GNUNET_MESH_tunnel_get_head(cls_->tunnel))
290 struct tunnel_notify_queue* element = GNUNET_MESH_tunnel_get_head(cls_->tunnel);
291 struct tunnel_notify_queue* head = GNUNET_MESH_tunnel_get_head(cls_->tunnel);
292 struct tunnel_notify_queue* tail = GNUNET_MESH_tunnel_get_tail(cls_->tunnel);
294 GNUNET_CONTAINER_DLL_remove(head, tail, element);
296 GNUNET_MESH_tunnel_set_head(cls_->tunnel, head);
297 GNUNET_MESH_tunnel_set_tail(cls_->tunnel, tail);
298 struct GNUNET_MESH_TransmitHandle* th = GNUNET_MESH_notify_transmit_ready (cls_->tunnel,
301 GNUNET_TIME_relative_divide
302 (GNUNET_CONSTANTS_MAX_CORK_DELAY, 2),
303 (const struct GNUNET_PeerIdentity *)
305 element->cb, element->cls);
306 /* save the handle */
307 GNUNET_MESH_tunnel_set_data(cls_->tunnel, th);
308 GNUNET_free(element);
316 mesh_connect (void *cls, const struct GNUNET_PeerIdentity *peer,
317 const struct GNUNET_TRANSPORT_ATS_Information *atsi
318 __attribute__ ((unused)))
320 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "mesh_connect called with %x, %x\n", cls, peer);
324 struct tunnel_cls *cls_ = (struct tunnel_cls *) cls;
325 if ((struct GNUNET_PeerIdentity*)1 != peer)
326 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
327 "Connected to peer %s, sending query with id %d\n",
328 GNUNET_i2s (peer), ntohs (cls_->dns.s.id));
330 dns_tunnel_connected = 1;
332 if (NULL == GNUNET_MESH_tunnel_get_data (cls_->tunnel))
334 struct GNUNET_MESH_TransmitHandle *th =
335 GNUNET_MESH_notify_transmit_ready (cls_->tunnel,
338 GNUNET_TIME_UNIT_MINUTES,
344 GNUNET_MESH_tunnel_set_data (cls_->tunnel, th);
348 struct tunnel_notify_queue* head = GNUNET_MESH_tunnel_get_head(cls_->tunnel);
349 struct tunnel_notify_queue* tail = GNUNET_MESH_tunnel_get_tail(cls_->tunnel);
351 struct tunnel_notify_queue* element = GNUNET_malloc(sizeof(struct tunnel_notify_queue));
353 element->len = cls_->hdr.size;
354 element->cb = mesh_send;
356 GNUNET_CONTAINER_DLL_insert_tail(head, tail, element);
357 GNUNET_MESH_tunnel_set_head(cls_->tunnel, head);
358 GNUNET_MESH_tunnel_set_tail(cls_->tunnel, tail);
363 call_mesh_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
365 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
368 mesh_connect (cls, (struct GNUNET_PeerIdentity *) 1, NULL);
373 send_mesh_query (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
375 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
378 struct tunnel_cls *cls_ = (struct tunnel_cls*)cls;
380 if (NULL == dns_tunnel || dns_tunnel_connected == 0)
382 dns_tunnel = GNUNET_MESH_peer_request_connect_by_type(mesh_handle,
383 GNUNET_TIME_UNIT_HOURS,
384 GNUNET_APPLICATION_TYPE_INTERNET_RESOLVER,
390 GNUNET_SCHEDULER_add_now(call_mesh_connect, cls_);
392 cls_->tunnel = dns_tunnel;
393 remote_pending[cls_->dns.s.id] = cls_;
397 receive_mesh_query (void *cls __attribute__((unused)),
398 struct GNUNET_MESH_Tunnel *tunnel,
399 void **ctx __attribute__((unused)),
400 const struct GNUNET_PeerIdentity *sender __attribute__((unused)),
401 const struct GNUNET_MessageHeader *message,
402 const struct GNUNET_TRANSPORT_ATS_Information *atsi __attribute__((unused)))
404 struct dns_pkt *dns = (struct dns_pkt*)(message + 1);
406 struct sockaddr_in dest;
407 memset(&dest, 0, sizeof dest);
408 dest.sin_port = htons(53);
409 /* TODO: read from config */
410 inet_pton(AF_INET, "8.8.8.8", &dest.sin_addr);
412 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Querying for remote, id=%d\n", ntohs(dns->s.id));
413 query_states[dns->s.id].tunnel = tunnel;
414 query_states[dns->s.id].valid = GNUNET_YES;
416 GNUNET_NETWORK_socket_sendto(dnsout,
418 ntohs(message->size) - sizeof(struct GNUNET_MessageHeader),
419 (struct sockaddr*) &dest,
422 return GNUNET_SYSERR;
426 receive_mesh_answer (void *cls __attribute__((unused)),
427 struct GNUNET_MESH_Tunnel *tunnel,
428 void **ctx __attribute__((unused)),
429 const struct GNUNET_PeerIdentity *sender,
430 const struct GNUNET_MessageHeader *message,
431 const struct GNUNET_TRANSPORT_ATS_Information *atsi __attribute__((unused)))
433 /* TODo: size check */
434 struct dns_pkt *dns = (struct dns_pkt *) (message + 1);
436 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "received dns-answer via %x, id=%d/%\nd\n", tunnel, dns->s.id, ntohs(dns->s.id));
438 /* They sent us a packet we were not waiting for */
439 if (remote_pending[dns->s.id] == NULL
440 || remote_pending[dns->s.id]->tunnel != tunnel)
443 GNUNET_free(remote_pending[dns->s.id]);
444 remote_pending[dns->s.id] = NULL;
446 if (query_states[dns->s.id].valid != GNUNET_YES)
447 return GNUNET_SYSERR;
448 query_states[dns->s.id].valid = GNUNET_NO;
450 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Received answer from peer %s, dns-id %d\n", GNUNET_i2s(sender), ntohs(dns->s.id));
452 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 */
453 + sizeof (struct dns_record_line) - 1 + 16; /* To hold the IPv6-Address */
455 struct answer_packet_list *answer =
456 GNUNET_malloc (len + 2 * sizeof (struct answer_packet_list *));
457 memset (answer, 0, len + 2 * sizeof (struct answer_packet_list *));
459 answer->pkt.hdr.type = htons (GNUNET_MESSAGE_TYPE_LOCAL_RESPONSE_DNS);
460 answer->pkt.hdr.size = htons (len);
462 struct dns_pkt_parsed* pdns = parse_dns_packet(dns);
464 if (ntohs(pdns->s.ancount) < 1)
466 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Answer only contains %d answers.\n", ntohs(pdns->s.ancount));
467 free_parsed_dns_packet(pdns);
471 answer->pkt.addrsize = ntohs(pdns->answers[0]->data_len);
472 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "The first answer has the addrlen %d\n", answer->pkt.addrsize);
473 memcpy(answer->pkt.addr, pdns->answers[0]->data, ntohs(pdns->answers[0]->data_len));
475 answer->pkt.from = query_states[dns->s.id].remote_ip;
477 answer->pkt.to = query_states[dns->s.id].local_ip;
478 answer->pkt.dst_port = query_states[dns->s.id].local_port;
480 struct dns_pkt *dpkt = (struct dns_pkt *) answer->pkt.data;
482 dpkt->s.id = dns->s.id;
486 dpkt->s.qdcount = htons (1);
487 dpkt->s.ancount = htons (1);
489 memcpy (dpkt->data, query_states[dns->s.id].name,
490 query_states[dns->s.id].namelen);
491 GNUNET_free (query_states[dns->s.id].name);
493 struct dns_query_line *dque =
494 (struct dns_query_line *) (dpkt->data +
495 (query_states[dns->s.id].namelen));
497 struct dns_record_line *drec_data =
498 (struct dns_record_line *) (dpkt->data +
499 (query_states[dns->s.id].namelen) +
500 sizeof (struct dns_query_line) + 2);
501 if (16 == answer->pkt.addrsize)
503 answer->pkt.subtype = GNUNET_DNS_ANSWER_TYPE_REMOTE_AAAA;
504 dque->type = htons (28); /* AAAA */
505 drec_data->type = htons (28); /* AAAA */
506 drec_data->data_len = htons (16);
510 answer->pkt.subtype = GNUNET_DNS_ANSWER_TYPE_REMOTE_A;
511 dque->type = htons (1); /* A */
512 drec_data->type = htons (1); /* A*/
513 drec_data->data_len = htons (4);
515 dque->class = htons (1); /* IN */
518 (char *) (dpkt->data + (query_states[dns->s.id].namelen) +
519 sizeof (struct dns_query_line));
520 memcpy (anname, "\xc0\x0c", 2);
521 drec_data->class = htons (1); /* IN */
523 drec_data->ttl = pdns->answers[0]->ttl;
525 /* Calculate at which offset in the packet the IPv6-Address belongs, it is
526 * filled in by the daemon-vpn */
527 answer->pkt.addroffset =
528 htons ((unsigned short) ((unsigned long) (&drec_data->data) -
529 (unsigned long) (&answer->pkt)));
531 GNUNET_CONTAINER_DLL_insert_after (head, tail, tail, answer);
533 GNUNET_SERVER_notify_transmit_ready (query_states[dns->s.id].client,
535 GNUNET_TIME_UNIT_FOREVER_REL,
537 query_states[dns->s.id].client);
539 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Sent answer of length %d on to client, addroffset = %d\n", len, answer->pkt.addroffset);
541 free_parsed_dns_packet(pdns);
547 send_rev_query(void * cls, const struct GNUNET_SCHEDULER_TaskContext *tc) {
548 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
551 struct dns_pkt_parsed* pdns = (struct dns_pkt_parsed*) cls;
553 unsigned short id = pdns->s.id;
555 free_parsed_dns_packet(pdns);
557 if (query_states[id].valid != GNUNET_YES) return;
558 query_states[id].valid = GNUNET_NO;
560 GNUNET_assert(query_states[id].namelen == 74);
562 size_t len = sizeof(struct answer_packet) - 1 \
563 + sizeof(struct dns_static) \
564 + 74 /* this is the length of a reverse ipv6-lookup */ \
565 + sizeof(struct dns_query_line) \
566 + 2 /* To hold the pointer (as defined in RFC1035) to the name */ \
567 + sizeof(struct dns_record_line) - 1 \
568 - 2 /* We do not know the lenght of the answer yet*/;
570 struct answer_packet_list* answer = GNUNET_malloc(len + 2*sizeof(struct answer_packet_list*));
571 memset(answer, 0, len + 2*sizeof(struct answer_packet_list*));
573 answer->pkt.hdr.type = htons(GNUNET_MESSAGE_TYPE_LOCAL_RESPONSE_DNS);
574 answer->pkt.hdr.size = htons(len);
575 answer->pkt.subtype = GNUNET_DNS_ANSWER_TYPE_REV;
577 answer->pkt.from = query_states[id].remote_ip;
579 answer->pkt.to = query_states[id].local_ip;
580 answer->pkt.dst_port = query_states[id].local_port;
582 struct dns_pkt *dpkt = (struct dns_pkt*)answer->pkt.data;
588 dpkt->s.qdcount = htons(1);
589 dpkt->s.ancount = htons(1);
591 memcpy(dpkt->data, query_states[id].name, query_states[id].namelen);
592 GNUNET_free(query_states[id].name);
594 struct dns_query_line* dque = (struct dns_query_line*)(dpkt->data+(query_states[id].namelen));
595 dque->type = htons(12); /* PTR */
596 dque->class = htons(1); /* IN */
598 char* anname = (char*)(dpkt->data+(query_states[id].namelen)+sizeof(struct dns_query_line));
599 memcpy(anname, "\xc0\x0c", 2);
601 struct dns_record_line *drec_data = (struct dns_record_line*)(dpkt->data+(query_states[id].namelen)+sizeof(struct dns_query_line)+2);
602 drec_data->type = htons(12); /* AAAA */
603 drec_data->class = htons(1); /* IN */
604 /* FIXME: read the TTL from block:
605 * GNUNET_TIME_absolute_get_remaining(rec->expiration_time)
607 * But how to get the seconds out of this?
609 drec_data->ttl = htonl(3600);
611 /* Calculate at which offset in the packet the length of the name and the
612 * name, it is filled in by the daemon-vpn */
613 answer->pkt.addroffset = htons((unsigned short)((unsigned long)(&drec_data->data_len)-(unsigned long)(&answer->pkt)));
615 GNUNET_CONTAINER_DLL_insert_after(head, tail, tail, answer);
617 GNUNET_SERVER_notify_transmit_ready(query_states[id].client,
619 GNUNET_TIME_UNIT_FOREVER_REL,
621 query_states[id].client);
625 * Receive a block from the dht.
628 receive_dht(void *cls,
629 struct GNUNET_TIME_Absolute exp __attribute__((unused)),
630 const GNUNET_HashCode *key __attribute__((unused)),
631 const struct GNUNET_PeerIdentity *const *get_path __attribute__((unused)),
632 const struct GNUNET_PeerIdentity *const *put_path __attribute__((unused)),
633 enum GNUNET_BLOCK_Type type,
637 unsigned short id = ((struct receive_dht_cls*)cls)->id;
638 struct GNUNET_DHT_GetHandle* handle = ((struct receive_dht_cls*)cls)->handle;
641 GNUNET_assert(type == GNUNET_BLOCK_TYPE_DNS);
643 /* If no query with this id is pending, ignore the block */
644 if (query_states[id].valid != GNUNET_YES) return;
645 query_states[id].valid = GNUNET_NO;
647 const struct GNUNET_DNS_Record* rec = data;
648 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
649 "Got block of size %d, peer: %08x, desc: %08x\n",
651 *((unsigned int*)&rec->peer),
652 *((unsigned int*)&rec->service_descriptor));
654 size_t len = sizeof(struct answer_packet) - 1 \
655 + sizeof(struct dns_static) \
656 + query_states[id].namelen \
657 + sizeof(struct dns_query_line) \
658 + 2 /* To hold the pointer (as defined in RFC1035) to the name */ \
659 + sizeof(struct dns_record_line) - 1 \
660 + 16; /* To hold the IPv6-Address */
662 struct answer_packet_list* answer = GNUNET_malloc(len + 2*sizeof(struct answer_packet_list*));
663 memset(answer, 0, len + 2*sizeof(struct answer_packet_list*));
665 answer->pkt.hdr.type = htons(GNUNET_MESSAGE_TYPE_LOCAL_RESPONSE_DNS);
666 answer->pkt.hdr.size = htons(len);
667 answer->pkt.subtype = GNUNET_DNS_ANSWER_TYPE_SERVICE;
669 GNUNET_CRYPTO_hash(&rec->peer,
670 sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
671 &answer->pkt.service_descr.peer);
673 memcpy(&answer->pkt.service_descr.service_descriptor,
674 &rec->service_descriptor,
675 sizeof(GNUNET_HashCode));
676 memcpy(&answer->pkt.service_descr.service_type,
678 sizeof(answer->pkt.service_descr.service_type));
679 memcpy(&answer->pkt.service_descr.ports, &rec->ports, sizeof(answer->pkt.service_descr.ports));
681 answer->pkt.from = query_states[id].remote_ip;
683 answer->pkt.to = query_states[id].local_ip;
684 answer->pkt.dst_port = query_states[id].local_port;
686 struct dns_pkt *dpkt = (struct dns_pkt*)answer->pkt.data;
692 dpkt->s.qdcount = htons(1);
693 dpkt->s.ancount = htons(1);
695 memcpy(dpkt->data, query_states[id].name, query_states[id].namelen);
696 GNUNET_free(query_states[id].name);
698 struct dns_query_line* dque = (struct dns_query_line*)(dpkt->data+(query_states[id].namelen));
699 dque->type = htons(28); /* AAAA */
700 dque->class = htons(1); /* IN */
702 char* anname = (char*)(dpkt->data+(query_states[id].namelen)+sizeof(struct dns_query_line));
703 memcpy(anname, "\xc0\x0c", 2);
705 struct dns_record_line *drec_data = (struct dns_record_line*)(dpkt->data+(query_states[id].namelen)+sizeof(struct dns_query_line)+2);
706 drec_data->type = htons(28); /* AAAA */
707 drec_data->class = htons(1); /* IN */
709 /* FIXME: read the TTL from block:
710 * GNUNET_TIME_absolute_get_remaining(rec->expiration_time)
712 * But how to get the seconds out of this?
714 drec_data->ttl = htonl(3600);
715 drec_data->data_len = htons(16);
717 /* Calculate at which offset in the packet the IPv6-Address belongs, it is
718 * filled in by the daemon-vpn */
719 answer->pkt.addroffset = htons((unsigned short)((unsigned long)(&drec_data->data)-(unsigned long)(&answer->pkt)));
721 GNUNET_CONTAINER_DLL_insert_after(head, tail, tail, answer);
723 GNUNET_SERVER_notify_transmit_ready(query_states[id].client,
725 GNUNET_TIME_UNIT_FOREVER_REL,
727 query_states[id].client);
729 GNUNET_DHT_get_stop(handle);
733 * This receives a GNUNET_MESSAGE_TYPE_REHIJACK and rehijacks the DNS
736 rehijack(void *cls __attribute__((unused)),
737 struct GNUNET_SERVER_Client *client,
738 const struct GNUNET_MessageHeader *message __attribute__((unused))) {
739 unhijack(dnsoutport);
740 GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_SECONDS, hijack, NULL);
742 GNUNET_SERVER_receive_done(client, GNUNET_OK);
746 * This receives the dns-payload from the daemon-vpn and sends it on over the udp-socket
749 receive_query(void *cls __attribute__((unused)),
750 struct GNUNET_SERVER_Client *client,
751 const struct GNUNET_MessageHeader *message) {
752 struct query_packet* pkt = (struct query_packet*)message;
753 struct dns_pkt* dns = (struct dns_pkt*)pkt->data;
754 struct dns_pkt_parsed* pdns = parse_dns_packet(dns);
756 query_states[dns->s.id].valid = GNUNET_YES;
757 query_states[dns->s.id].client = client;
758 query_states[dns->s.id].local_ip = pkt->orig_from;
759 query_states[dns->s.id].local_port = pkt->src_port;
760 query_states[dns->s.id].remote_ip = pkt->orig_to;
761 query_states[dns->s.id].namelen = strlen((char*)dns->data) + 1;
762 if (query_states[dns->s.id].name != NULL)
763 GNUNET_free(query_states[dns->s.id].name);
764 query_states[dns->s.id].name = GNUNET_malloc(query_states[dns->s.id].namelen);
765 memcpy(query_states[dns->s.id].name, dns->data, query_states[dns->s.id].namelen);
767 /* The query is for a .gnunet-address */
768 if (pdns->queries[0]->namelen > 9 &&
769 0 == strncmp(pdns->queries[0]->name+(pdns->queries[0]->namelen - 9), ".gnunet.", 9))
771 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Query for .gnunet!\n");
773 GNUNET_CRYPTO_hash(pdns->queries[0]->name, pdns->queries[0]->namelen, &key);
775 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
776 "Getting with key %08x, len is %d\n",
777 *((unsigned int*)&key),
778 pdns->queries[0]->namelen);
780 struct receive_dht_cls* cls = GNUNET_malloc(sizeof(struct receive_dht_cls));
783 cls->handle = GNUNET_DHT_get_start(dht,
784 GNUNET_TIME_UNIT_MINUTES,
785 GNUNET_BLOCK_TYPE_DNS,
787 DEFAULT_GET_REPLICATION,
799 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Query for '%s'; namelen=%d\n", pdns->queries[0]->name, pdns->queries[0]->namelen);
801 /* This is a PTR-Query. Check if it is for "our" network */
802 if (htons(pdns->queries[0]->qtype) == 12 &&
803 74 == pdns->queries[0]->namelen)
807 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.";
809 unsigned long long ipv6prefix;
810 unsigned int comparelen;
812 GNUNET_assert(GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(cfg, "vpn", "IPV6ADDR", &ipv6addr));
813 inet_pton (AF_INET6, ipv6addr, ipv6);
814 GNUNET_free(ipv6addr);
816 GNUNET_assert(GNUNET_OK == GNUNET_CONFIGURATION_get_value_number(cfg, "vpn", "IPV6PREFIX", &ipv6prefix));
817 GNUNET_assert(ipv6prefix < 127);
818 ipv6prefix = (ipv6prefix + 7)/8;
820 for (i = ipv6prefix; i < 16; i++)
823 for (i = 0; i < 16; i++)
825 unsigned char c1 = ipv6[i] >> 4;
826 unsigned char c2 = ipv6[i] & 0xf;
829 ipv6rev[62-(4*i)] = c1 + '0';
831 ipv6rev[62-(4*i)] = c1 + 87; /* 87 is the difference between 'a' and 10 */
834 ipv6rev[62-((4*i)+2)] = c2 + '0';
836 ipv6rev[62-((4*i)+2)] = c2 + 87;
838 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "My network is %s'.\n", ipv6rev);
839 comparelen = 10 + 4*ipv6prefix;
840 if(0 == strncmp(pdns->queries[0]->name+(pdns->queries[0]->namelen - comparelen),
841 ipv6rev + (74 - comparelen),
844 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Reverse-Query for .gnunet!\n");
846 GNUNET_SCHEDULER_add_now(send_rev_query, pdns);
853 unsigned int virt_dns_bytes;
855 GNUNET_CONFIGURATION_get_value_string (cfg, "vpn", "VIRTDNS",
858 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
859 "No entry 'VIRTDNS' in configuration!\n");
863 if (1 != inet_pton (AF_INET, virt_dns, &virt_dns_bytes))
865 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
866 "Error parsing 'VIRTDNS': %s; %m!\n", virt_dns);
870 GNUNET_free(virt_dns);
872 if (virt_dns_bytes == pkt->orig_to)
874 /* This is a packet that was sent directly to the virtual dns-server
876 * This means we have to send this query over gnunet
879 size_t size = sizeof(struct GNUNET_MESH_Tunnel*) + sizeof(struct GNUNET_MessageHeader) + (ntohs(message->size) - sizeof(struct query_packet) + 1);
880 struct tunnel_cls *cls_ = GNUNET_malloc(size);
881 cls_->hdr.size = size - sizeof(struct GNUNET_MESH_Tunnel*);
883 cls_->hdr.type = ntohs(GNUNET_MESSAGE_TYPE_REMOTE_QUERY_DNS);
884 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "size: %d\n", size);
886 memcpy(&cls_->dns, dns, cls_->hdr.size - sizeof(struct GNUNET_MessageHeader));
887 GNUNET_SCHEDULER_add_now(send_mesh_query, cls_);
893 /* The query should be sent to the network */
895 struct sockaddr_in dest;
896 memset(&dest, 0, sizeof dest);
897 dest.sin_port = htons(53);
898 dest.sin_addr.s_addr = pkt->orig_to;
900 GNUNET_NETWORK_socket_sendto(dnsout,
902 ntohs(pkt->hdr.size) - sizeof(struct query_packet) + 1,
903 (struct sockaddr*) &dest,
907 free_parsed_dns_packet(pdns);
910 GNUNET_SERVER_receive_done(client, GNUNET_OK);
913 static void read_response (void *cls,
914 const struct GNUNET_SCHEDULER_TaskContext *tc);
919 struct sockaddr_in addr;
921 dnsout = GNUNET_NETWORK_socket_create (AF_INET, SOCK_DGRAM, 0);
923 return GNUNET_SYSERR;
924 memset (&addr, 0, sizeof (struct sockaddr_in));
926 addr.sin_family = AF_INET;
927 int err = GNUNET_NETWORK_socket_bind (dnsout,
928 (struct sockaddr *) &addr,
929 sizeof (struct sockaddr_in));
931 if (err != GNUNET_OK)
933 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
934 "Could not bind a port: %m\n");
935 return GNUNET_SYSERR;
938 /* Read the port we bound to */
939 socklen_t addrlen = sizeof (struct sockaddr_in);
940 err = getsockname (GNUNET_NETWORK_get_fd (dnsout),
941 (struct sockaddr *) &addr, &addrlen);
943 dnsoutport = htons (addr.sin_port);
945 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Bound to port %d.\n", dnsoutport);
947 GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, dnsout,
948 &read_response, NULL);
954 * Read a response-packet of the UDP-Socket
957 read_response (void *cls
958 __attribute__ ((unused)),
959 const struct GNUNET_SCHEDULER_TaskContext *tc)
961 struct sockaddr_in addr;
962 socklen_t addrlen = sizeof (addr);
966 if (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)
969 memset (&addr, 0, sizeof addr);
972 if (0 != ioctl (GNUNET_NETWORK_get_fd (dnsout), FIONREAD, &len))
974 unhijack (dnsoutport);
975 if (GNUNET_YES == open_port ())
976 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, hijack, NULL);
980 /* port the code above? */
984 unsigned char buf[len];
985 struct dns_pkt *dns = (struct dns_pkt *) buf;
987 r = GNUNET_NETWORK_socket_recvfrom (dnsout,
990 (struct sockaddr *) &addr, &addrlen);
994 unhijack (dnsoutport);
995 if (GNUNET_YES == open_port ())
996 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, hijack, NULL);
1000 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Answer to query %d\n", ntohs(dns->s.id));
1002 if (query_states[dns->s.id].valid == GNUNET_YES)
1004 if (query_states[dns->s.id].tunnel != NULL)
1006 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Answer to query %d for a remote peer!\n", ntohs(dns->s.id));
1007 /* This response should go through a tunnel */
1008 uint32_t *c = GNUNET_malloc (4 + sizeof(struct GNUNET_MESH_Tunnel*) + r);
1010 struct GNUNET_MESH_Tunnel** t = (struct GNUNET_MESH_Tunnel**)(c + 1);
1011 *t = query_states[dns->s.id].tunnel;
1012 memcpy (t + 1, dns, r);
1014 GNUNET_MESH_tunnel_get_data (query_states[dns->s.id].tunnel))
1016 struct GNUNET_MESH_TransmitHandle *th =
1017 GNUNET_MESH_notify_transmit_ready (query_states[dns->s.id].tunnel,
1020 GNUNET_TIME_UNIT_MINUTES,
1024 GNUNET_MessageHeader),
1025 mesh_send_response, c);
1026 GNUNET_MESH_tunnel_set_data (query_states[dns->s.id].tunnel,
1031 struct tunnel_notify_queue* head = GNUNET_MESH_tunnel_get_head(query_states[dns->s.id].tunnel);
1032 struct tunnel_notify_queue* tail = GNUNET_MESH_tunnel_get_tail(query_states[dns->s.id].tunnel);
1034 struct tunnel_notify_queue* element = GNUNET_malloc(sizeof(struct tunnel_notify_queue));
1036 element->len = r+sizeof(struct GNUNET_MessageHeader);
1037 element->cb = mesh_send_response;
1039 GNUNET_CONTAINER_DLL_insert_tail(head, tail, element);
1040 GNUNET_MESH_tunnel_set_head(query_states[dns->s.id].tunnel, head);
1041 GNUNET_MESH_tunnel_set_tail(query_states[dns->s.id].tunnel, tail);
1046 query_states[dns->s.id].valid = GNUNET_NO;
1048 size_t len = sizeof (struct answer_packet) + r - 1; /* 1 for the unsigned char data[1]; */
1049 struct answer_packet_list *answer =
1050 GNUNET_malloc (len + 2 * sizeof (struct answer_packet_list *));
1051 answer->pkt.hdr.type =
1052 htons (GNUNET_MESSAGE_TYPE_LOCAL_RESPONSE_DNS);
1053 answer->pkt.hdr.size = htons (len);
1054 answer->pkt.subtype = GNUNET_DNS_ANSWER_TYPE_IP;
1055 answer->pkt.from = addr.sin_addr.s_addr;
1056 answer->pkt.to = query_states[dns->s.id].local_ip;
1057 answer->pkt.dst_port = query_states[dns->s.id].local_port;
1058 memcpy (answer->pkt.data, buf, r);
1060 GNUNET_CONTAINER_DLL_insert_after (head, tail, tail, answer);
1062 GNUNET_SERVER_notify_transmit_ready (query_states
1063 [dns->s.id].client, len,
1064 GNUNET_TIME_UNIT_FOREVER_REL,
1066 query_states[dns->s.
1071 GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
1072 dnsout, &read_response, NULL);
1077 * Task run during shutdown.
1083 cleanup_task (void *cls __attribute__((unused)),
1084 const struct GNUNET_SCHEDULER_TaskContext *tc)
1086 GNUNET_assert(0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN));
1088 unhijack(dnsoutport);
1089 GNUNET_DHT_disconnect(dht);
1090 GNUNET_MESH_disconnect(mesh_handle);
1094 * @brief Create a port-map from udp and tcp redirects
1096 * @param udp_redirects
1097 * @param tcp_redirects
1102 get_port_from_redirects (const char *udp_redirects, const char *tcp_redirects)
1105 char* cpy, *hostname, *redirect;
1106 int local_port, count = 0;
1108 if (NULL != udp_redirects)
1110 cpy = GNUNET_strdup (udp_redirects);
1111 for (redirect = strtok (cpy, " "); redirect != NULL; redirect = strtok (NULL, " "))
1113 if (NULL == (hostname = strstr (redirect, ":")))
1115 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Warning: option %s is not formatted correctly!\n", redirect);
1119 local_port = atoi (redirect);
1120 if (!((local_port > 0) && (local_port < 65536)))
1121 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Warning: %s is not a correct port.", redirect);
1123 ret |= (0xFFFF & htons(local_port));
1137 if (NULL != tcp_redirects)
1139 cpy = GNUNET_strdup (tcp_redirects);
1140 for (redirect = strtok (cpy, " "); redirect != NULL; redirect = strtok (NULL, " "))
1142 if (NULL == (hostname = strstr (redirect, ":")))
1144 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Warning: option %s is not formatted correctly!\n", redirect);
1148 local_port = atoi (redirect);
1149 if (!((local_port > 0) && (local_port < 65536)))
1150 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Warning: %s is not a correct port.", redirect);
1152 ret |= (0xFFFF & htons(local_port));
1173 publish_name (const char *name, uint64_t ports, uint32_t service_type,
1174 struct GNUNET_CRYPTO_RsaPrivateKey *my_private_key)
1176 size_t size = sizeof (struct GNUNET_DNS_Record);
1177 struct GNUNET_DNS_Record data;
1178 memset (&data, 0, size);
1181 htonl (size - sizeof (struct GNUNET_CRYPTO_RsaSignature));
1182 data.purpose.purpose = GNUNET_SIGNATURE_PURPOSE_DNS_RECORD;
1184 GNUNET_CRYPTO_hash (name, strlen (name) + 1, &data.service_descriptor);
1185 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Store with key1 %x\n",
1186 *((unsigned long long *) &data.service_descriptor));
1188 data.service_type = service_type;
1191 GNUNET_CRYPTO_rsa_key_get_public (my_private_key, &data.peer);
1193 data.expiration_time =
1194 GNUNET_TIME_relative_to_absolute (GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_HOURS, 2));
1196 /* Sign the block */
1197 if (GNUNET_OK != GNUNET_CRYPTO_rsa_sign (my_private_key,
1198 &data.purpose, &data.signature))
1200 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "could not sign DNS_Record\n");
1204 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1205 "Putting with key %08x, size = %d\n",
1206 *((unsigned int *) &data.service_descriptor), size);
1208 GNUNET_DHT_put (dht,
1209 &data.service_descriptor,
1210 DEFAULT_PUT_REPLICATION,
1212 GNUNET_BLOCK_TYPE_DNS,
1215 GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_HOURS),
1216 GNUNET_TIME_UNIT_MINUTES, NULL, NULL);
1220 * @brief Publishes the record defined by the section section
1222 * @param cls closure
1223 * @param section the current section
1226 publish_iterate (void *cls __attribute__((unused)), const char *section)
1228 if ((strlen(section) < 8) || (0 != strcmp (".gnunet.", section + (strlen(section) - 8))))
1231 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Parsing dns-name %s\n", section);
1233 char *udp_redirects, *tcp_redirects, *alternative_names, *alternative_name,
1236 GNUNET_CONFIGURATION_get_value_string (cfg, section,
1237 "UDP_REDIRECTS", &udp_redirects);
1238 GNUNET_CONFIGURATION_get_value_string (cfg, section, "TCP_REDIRECTS",
1241 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg, "GNUNETD",
1245 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "could not read keyfile-value\n");
1246 if (keyfile != NULL)
1247 GNUNET_free (keyfile);
1251 struct GNUNET_CRYPTO_RsaPrivateKey *my_private_key =
1252 GNUNET_CRYPTO_rsa_key_create_from_file (keyfile);
1253 GNUNET_free (keyfile);
1254 GNUNET_assert (my_private_key != NULL);
1256 uint64_t ports = get_port_from_redirects (udp_redirects, tcp_redirects);
1257 uint32_t service_type = 0;
1259 if (NULL != udp_redirects)
1260 service_type = GNUNET_DNS_SERVICE_TYPE_UDP;
1262 if (NULL != tcp_redirects)
1263 service_type |= GNUNET_DNS_SERVICE_TYPE_TCP;
1265 service_type = htonl (service_type);
1268 publish_name (section, ports, service_type, my_private_key);
1270 GNUNET_CONFIGURATION_get_value_string (cfg, section,
1271 "ALTERNATIVE_NAMES",
1272 &alternative_names);
1273 for (alternative_name = strtok (alternative_names, " ");
1274 alternative_name != NULL; alternative_name = strtok (NULL, " "))
1277 alloca (strlen (alternative_name) + strlen (section) + 1 + 1);
1278 strcpy (altname, alternative_name);
1279 strcpy (altname + strlen (alternative_name) + 1, section);
1280 altname[strlen (alternative_name)] = '.';
1282 publish_name (altname, ports, service_type, my_private_key);
1285 GNUNET_free_non_null(alternative_names);
1286 GNUNET_CRYPTO_rsa_key_free (my_private_key);
1287 GNUNET_free_non_null (udp_redirects);
1288 GNUNET_free_non_null (tcp_redirects);
1292 * Publish a DNS-record in the DHT.
1295 publish_names (void *cls __attribute__((unused)),
1296 const struct GNUNET_SCHEDULER_TaskContext *tc) {
1297 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
1300 GNUNET_CONFIGURATION_iterate_sections(cfg, publish_iterate, NULL);
1302 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_HOURS,
1308 * @param cls closure
1309 * @param server the initialized server
1310 * @param cfg_ configuration to use
1314 struct GNUNET_SERVER_Handle *server,
1315 const struct GNUNET_CONFIGURATION_Handle *cfg_)
1317 static const struct GNUNET_SERVER_MessageHandler handlers[] = {
1318 /* callback, cls, type, size */
1319 {&receive_query, NULL, GNUNET_MESSAGE_TYPE_LOCAL_QUERY_DNS, 0},
1320 {&rehijack, NULL, GNUNET_MESSAGE_TYPE_REHIJACK,
1321 sizeof (struct GNUNET_MessageHeader)},
1325 static const struct GNUNET_MESH_MessageHandler mesh_handlers[] = {
1326 {receive_mesh_query, GNUNET_MESSAGE_TYPE_REMOTE_QUERY_DNS, 0},
1327 {receive_mesh_answer, GNUNET_MESSAGE_TYPE_REMOTE_ANSWER_DNS, 0},
1331 static GNUNET_MESH_ApplicationType *apptypes;
1333 if (GNUNET_YES != open_port ())
1335 GNUNET_SCHEDULER_shutdown();
1340 GNUNET_CONFIGURATION_get_value_yesno (cfg_, "dns", "PROVIDE_EXIT"))
1341 apptypes = (GNUNET_MESH_ApplicationType[])
1343 GNUNET_APPLICATION_TYPE_INTERNET_RESOLVER,
1344 GNUNET_APPLICATION_TYPE_END};
1346 apptypes = (GNUNET_MESH_ApplicationType[])
1348 GNUNET_APPLICATION_TYPE_END};
1351 GNUNET_MESH_connect (cfg_, NULL, NULL, mesh_handlers, apptypes);
1356 for (i = 0; i < 65536; i++)
1358 query_states[i].valid = GNUNET_NO;
1361 dht = GNUNET_DHT_connect (cfg, 1024);
1363 GNUNET_SCHEDULER_add_now (publish_names, NULL);
1365 GNUNET_SERVER_add_handlers (server, handlers);
1366 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
1367 &cleanup_task, cls);
1371 * The main function for the dns service.
1373 * @param argc number of arguments from the command line
1374 * @param argv command line arguments
1375 * @return 0 ok, 1 on error
1378 main (int argc, char *const *argv)
1380 return (GNUNET_OK ==
1381 GNUNET_SERVICE_run (argc,
1384 GNUNET_SERVICE_OPTION_NONE,
1385 &run, NULL)) ? 0 : 1;