log gauger data, differentiate between hostkey generation and hostkey loading/copying
[oweals/gnunet.git] / src / vpn / gnunet-daemon-vpn.c
1 /*
2      This file is part of GNUnet.
3      (C) 2010 Christian Grothoff
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-daemon-vpn.c
23  * @brief
24  * @author Philipp Toelke
25  */
26 #include "platform.h"
27 #include "gnunet_getopt_lib.h"
28 #include "gnunet_program_lib.h"
29 #include "gnunet-vpn-packet.h"
30 #include "gnunet_common.h"
31 #include "gnunet_protocols.h"
32 #include <gnunet_mesh_service.h>
33 #include "gnunet_client_lib.h"
34 #include "gnunet_container_lib.h"
35 #include "gnunet_constants.h"
36 #include <block_dns.h>
37 #include "gnunet-daemon-vpn-helper.h"
38 #include "gnunet-daemon-vpn-dns.h"
39 #include "gnunet-daemon-vpn.h"
40 #include "gnunet-vpn-checksum.h"
41
42 const struct GNUNET_CONFIGURATION_Handle *cfg;
43 struct GNUNET_MESH_Handle *mesh_handle;
44 struct GNUNET_CONTAINER_MultiHashMap* hashmap;
45
46 /**
47  * Final status code.
48  */
49 static int ret;
50
51 /**
52  * This hashmap contains the mapping from peer, service-descriptor,
53  * source-port and destination-port to a socket
54  */
55 static struct GNUNET_CONTAINER_MultiHashMap *udp_connections;
56
57 /**
58  * Function scheduled as very last function, cleans up after us
59  *{{{
60  */
61 static void
62 cleanup(void* cls, const struct GNUNET_SCHEDULER_TaskContext* tskctx) {
63     GNUNET_assert (0 != (tskctx->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN));
64
65     /* stop the helper */
66     cleanup_helper(helper_handle);
67
68     /* close the connection to the service-dns */
69     if (dns_connection != NULL)
70       {
71         GNUNET_CLIENT_disconnect (dns_connection, GNUNET_NO);
72         dns_connection = NULL;
73       }
74
75     if (mesh_handle != NULL)
76       {
77         GNUNET_MESH_disconnect(mesh_handle);
78         mesh_handle = NULL;
79       }
80 }
81 /*}}}*/
82
83 /**
84  * @return the hash of the IP-Address if a mapping exists, NULL otherwise
85  */
86 GNUNET_HashCode*
87 address_mapping_exists(unsigned char addr[]) {
88     GNUNET_HashCode* key = GNUNET_malloc(sizeof(GNUNET_HashCode));
89     unsigned char* k = (unsigned char*)key;
90     memset(key, 0, sizeof(GNUNET_HashCode));
91     unsigned int i;
92     for (i = 0; i < 16; i++)
93         k[15-i] = addr[i];
94
95     if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains(hashmap, key))
96       return key;
97     else
98       {
99         GNUNET_free(key);
100         return NULL;
101       }
102 }
103
104 void
105 send_icmp_response(void* cls, const struct GNUNET_SCHEDULER_TaskContext *tc) {
106     struct ip6_icmp* request = cls;
107
108     struct ip6_icmp* response = alloca(ntohs(request->shdr.size));
109     GNUNET_assert(response != NULL);
110     memset(response, 0, ntohs(request->shdr.size));
111
112     response->shdr.size = request->shdr.size;
113     response->shdr.type = htons(GNUNET_MESSAGE_TYPE_VPN_HELPER);
114
115     response->tun.flags = 0;
116     response->tun.type = htons(0x86dd);
117
118     response->ip6_hdr.hoplmt = 255;
119     response->ip6_hdr.paylgth = request->ip6_hdr.paylgth;
120     response->ip6_hdr.nxthdr = 0x3a;
121     response->ip6_hdr.version = 6;
122     memcpy(&response->ip6_hdr.sadr, &request->ip6_hdr.dadr, 16);
123     memcpy(&response->ip6_hdr.dadr, &request->ip6_hdr.sadr, 16);
124
125     response->icmp_hdr.code = 0;
126     response->icmp_hdr.type = 0x81;
127
128     /* Magic, more Magic! */
129     response->icmp_hdr.chks = request->icmp_hdr.chks - 0x1;
130
131     /* Copy the rest of the packet */
132     memcpy(response+1, request+1, ntohs(request->shdr.size) - sizeof(struct ip6_icmp));
133
134     write_to_helper(response, ntohs(response->shdr.size));
135
136     GNUNET_free(request);
137 }
138
139 /**
140  * cls is the pointer to a GNUNET_MessageHeader that is
141  * followed by the service-descriptor and the packet that should be sent;
142  */
143 static size_t
144 send_pkt_to_peer_notify_callback (void *cls, size_t size, void *buf)
145 {
146   struct GNUNET_MESH_Tunnel **tunnel = cls;
147   struct GNUNET_MessageHeader *hdr =
148     (struct GNUNET_MessageHeader *) (tunnel + 1);
149   GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "send_pkt_to_peer_notify_callback: buf = %x; size = %u;\n", buf, size);
150   GNUNET_assert (size >= ntohs (hdr->size));
151   memcpy (buf, hdr, ntohs (hdr->size));
152   size = ntohs(hdr->size);
153   GNUNET_free (cls);
154   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sent!\n");
155   return size;
156 }
157
158 unsigned int
159 port_in_ports (uint64_t ports, uint16_t port)
160 {
161   uint16_t *ps = (uint16_t *) & ports;
162   return ps[0] == port || ps[1] == port || ps[2] == port || ps[3] == port;
163 }
164
165 void
166 send_pkt_to_peer (void *cls, 
167                   const struct GNUNET_PeerIdentity *peer,
168                   const struct GNUNET_TRANSPORT_ATS_Information *atsi)
169 {
170   if (peer == NULL) return;
171   struct GNUNET_MESH_Tunnel **tunnel = cls;
172   struct GNUNET_MessageHeader *hdr =
173     (struct GNUNET_MessageHeader *) (tunnel + 1);
174
175   GNUNET_assert(NULL != tunnel);
176   GNUNET_assert(NULL != *tunnel);
177
178   GNUNET_MESH_notify_transmit_ready (*tunnel,
179                                      GNUNET_NO,
180                                      42,
181                                      GNUNET_TIME_relative_divide(GNUNET_CONSTANTS_MAX_CORK_DELAY, 2),
182                                      (const struct GNUNET_PeerIdentity *)NULL,
183                                      ntohs(hdr->size),
184                                      send_pkt_to_peer_notify_callback,
185                                      cls);
186 }
187
188 /**
189  * Create a new Address from an answer-packet
190  */
191 void
192 new_ip6addr(unsigned char* buf, const GNUNET_HashCode *peer, const GNUNET_HashCode *service_desc) { /* {{{ */
193     char* ipv6addr;
194     unsigned long long ipv6prefix;
195     GNUNET_assert(GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(cfg, "vpn", "IPV6ADDR", &ipv6addr));
196     GNUNET_assert(GNUNET_OK == GNUNET_CONFIGURATION_get_value_number(cfg, "vpn", "IPV6PREFIX", &ipv6prefix));
197     GNUNET_assert(ipv6prefix < 127);
198     ipv6prefix = (ipv6prefix + 7)/8;
199
200     inet_pton (AF_INET6, ipv6addr, buf);
201     GNUNET_free(ipv6addr);
202
203     int peer_length = 16 - ipv6prefix - 6;
204     if (peer_length <= 0)
205       peer_length = 0;
206
207     int service_length = 16 - ipv6prefix - peer_length;
208     if (service_length <= 0)
209       service_length = 0;
210
211     memcpy(buf+ipv6prefix, service_desc, service_length);
212     memcpy(buf+ipv6prefix+service_length, peer, peer_length);
213 }
214 /*}}}*/
215
216 /**
217  * This gets scheduled with cls pointing to an answer_packet and does everything
218  * needed in order to send it to the helper.
219  *
220  * At the moment this means "inventing" and IPv6-Address for .gnunet-services and
221  * doing nothing for "real" services.
222  */
223 void
224 process_answer(void* cls, const struct GNUNET_SCHEDULER_TaskContext* tc) {
225     struct answer_packet* pkt = cls;
226     struct answer_packet_list* list;
227
228     /* This answer is about a .gnunet-service
229      *
230      * It contains an almost complete DNS-Response, we have to fill in the ip
231      * at the offset pkt->addroffset
232      */
233     if (pkt->subtype == GNUNET_DNS_ANSWER_TYPE_SERVICE)
234       {
235         pkt->subtype = GNUNET_DNS_ANSWER_TYPE_IP;
236
237         GNUNET_HashCode key;
238         memset(&key, 0, sizeof(GNUNET_HashCode));
239
240         unsigned char* c = ((unsigned char*)pkt)+ntohs(pkt->addroffset);
241         unsigned char* k = (unsigned char*)&key;
242         new_ip6addr(c, &pkt->service_descr.peer, &pkt->service_descr.service_descriptor);
243         /*
244          * Copy the newly generated ip-address to the key backwarts (as only the first part is hashed)
245          */
246         unsigned int i;
247         for (i = 0; i < 16; i++)
248             k[15-i] = c[i];
249
250         uint16_t namelen = strlen((char*)pkt->data+12)+1;
251
252         struct map_entry* value = GNUNET_malloc(sizeof(struct map_entry) + namelen);
253         char* name = (char*)(value +1);
254
255         value->namelen = namelen;
256         memcpy(name, pkt->data+12, namelen);
257
258         memcpy(&value->desc, &pkt->service_descr, sizeof(struct GNUNET_vpn_service_descriptor));
259
260         memset(value->additional_ports, 0, 8192);
261
262         /* FIXME save this to heap, too */
263         if (GNUNET_NO ==
264             GNUNET_CONTAINER_multihashmap_contains (hashmap, &key))
265           GNUNET_CONTAINER_multihashmap_put (hashmap, &key, value,
266                                        GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
267         else
268           GNUNET_free(value);
269
270
271         list = GNUNET_malloc(htons(pkt->hdr.size) + 2*sizeof(struct answer_packet_list*));
272
273         memcpy(&list->pkt, pkt, htons(pkt->hdr.size));
274
275       }
276     else if (pkt->subtype == GNUNET_DNS_ANSWER_TYPE_REV)
277       {
278         GNUNET_HashCode key;
279         memset(&key, 0, sizeof key);
280         unsigned char* k = (unsigned char*)&key;
281         unsigned char* s = pkt->data+12;
282         int i = 0;
283         /* Whoever designed the reverse IPv6-lookup is batshit insane */
284         for (i = 0; i < 16; i++)
285           {
286             unsigned char c1 = s[(4*i)+1];
287             unsigned char c2 = s[(4*i)+3];
288             if (c1 <= '9')
289               k[i] = c1 - '0';
290             else
291               k[i] = c1 - 87; /* 87 is the difference between 'a' and 10 */
292             if (c2 <= '9')
293               k[i] += 16*(c2 - '0');
294             else
295               k[i] += 16*(c2 - 87);
296           }
297
298         /* FIXME: update costs in heap */
299         struct map_entry* map_entry = GNUNET_CONTAINER_multihashmap_get(hashmap, &key);
300         uint16_t offset = ntohs(pkt->addroffset);
301
302         if (map_entry == NULL)
303           {
304             GNUNET_free(pkt);
305             return;
306           }
307
308         unsigned short namelen = htons(map_entry->namelen);
309         char* name = (char*)(map_entry + 1);
310
311         list = GNUNET_malloc(2*sizeof(struct answer_packet_list*) + offset + 2 + ntohs(namelen));
312
313         struct answer_packet* rpkt = &list->pkt;
314
315         /* The offset points to the first byte belonging to the address */
316         memcpy(rpkt, pkt, offset - 1);
317
318         rpkt->subtype = GNUNET_DNS_ANSWER_TYPE_IP;
319         rpkt->hdr.size = ntohs(offset + 2 + ntohs(namelen));
320
321         memcpy(((char*)rpkt)+offset, &namelen, 2);
322         memcpy(((char*)rpkt)+offset+2, name, ntohs(namelen));
323
324       }
325     else if (pkt->subtype == GNUNET_DNS_ANSWER_TYPE_IP)
326       {
327         list = GNUNET_malloc(htons(pkt->hdr.size) + 2*sizeof(struct answer_packet_list*));
328         memcpy(&list->pkt, pkt, htons(pkt->hdr.size));
329       }
330     else
331       {
332         GNUNET_break(0);
333         GNUNET_free(pkt);
334         return;
335       }
336
337     GNUNET_free(pkt);
338
339     GNUNET_CONTAINER_DLL_insert_after(answer_proc_head, answer_proc_tail, answer_proc_tail, list);
340
341     schedule_helper_write(GNUNET_TIME_UNIT_FOREVER_REL, NULL);
342
343     return;
344 }
345
346 /**
347  * Sets a bit active in a bitArray.
348  *
349  * @param bitArray memory area to set the bit in
350  * @param bitIdx which bit to set
351  */
352 void
353 setBit (char *bitArray, unsigned int bitIdx)
354 {
355   size_t arraySlot;
356   unsigned int targetBit;
357
358   arraySlot = bitIdx / 8;
359   targetBit = (1L << (bitIdx % 8));
360   bitArray[arraySlot] |= targetBit;
361 }
362
363 /**
364  * Clears a bit from bitArray.
365  *
366  * @param bitArray memory area to set the bit in
367  * @param bitIdx which bit to unset
368  */
369 void
370 clearBit (char *bitArray, unsigned int bitIdx)
371 {
372   size_t slot;
373   unsigned int targetBit;
374
375   slot = bitIdx / 8;
376   targetBit = (1L << (bitIdx % 8));
377   bitArray[slot] = bitArray[slot] & (~targetBit);
378 }
379
380 /**
381  * Checks if a bit is active in the bitArray
382  *
383  * @param bitArray memory area to set the bit in
384  * @param bitIdx which bit to test
385  * @return GNUNET_YES if the bit is set, GNUNET_NO if not.
386  */
387 int
388 testBit (char *bitArray, unsigned int bitIdx)
389 {
390   size_t slot;
391   unsigned int targetBit;
392
393   slot = bitIdx / 8;
394   targetBit = (1L << (bitIdx % 8));
395   if (bitArray[slot] & targetBit)
396     return GNUNET_YES;
397   else
398     return GNUNET_NO;
399 }
400
401 /**
402  * @brief Add the port to the list of additional ports in the map_entry
403  *
404  * @param me the map_entry
405  * @param port the port in host-byte-order
406  */
407 static void
408 add_additional_port (struct map_entry *me, uint16_t port)
409 {
410   setBit(me->additional_ports, port);
411 }
412
413 static int
414 receive_udp_back (void *cls, struct GNUNET_MESH_Tunnel* tunnel,
415                   void **tunnel_ctx,
416                   const struct GNUNET_PeerIdentity *sender,
417                   const struct GNUNET_MessageHeader *message,
418                   const struct GNUNET_TRANSPORT_ATS_Information *atsi)
419 {
420   GNUNET_HashCode *desc = (GNUNET_HashCode *) (message + 1);
421   struct udp_pkt *pkt = (struct udp_pkt *) (desc + 1);
422   const struct GNUNET_PeerIdentity* other = GNUNET_MESH_get_peer(tunnel);
423
424   size_t size = sizeof(struct ip6_udp) + ntohs(pkt->len) - 1 - sizeof(struct udp_pkt);
425
426   struct ip6_udp* pkt6 = alloca(size);
427
428   GNUNET_assert(pkt6 != NULL);
429
430   new_ip6addr(pkt6->ip6_hdr.sadr, &other->hashPubKey, desc);
431
432   GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Relaying calc:%d gnu:%d udp:%d bytes!\n", size, ntohs(message->size), ntohs(pkt->len));
433
434   pkt6->shdr.type = htons(GNUNET_MESSAGE_TYPE_VPN_HELPER);
435   pkt6->shdr.size = htons(size);
436
437   pkt6->tun.flags = 0;
438   pkt6->tun.type = htons(0x86dd);
439
440   pkt6->ip6_hdr.version = 6;
441   pkt6->ip6_hdr.tclass_h = 0;
442   pkt6->ip6_hdr.tclass_l = 0;
443   pkt6->ip6_hdr.flowlbl = 0;
444   pkt6->ip6_hdr.paylgth = pkt->len;
445   pkt6->ip6_hdr.nxthdr = 0x11;
446   pkt6->ip6_hdr.hoplmt = 0xff;
447
448   {
449     char* ipv6addr;
450     GNUNET_assert(GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(cfg, "vpn", "IPV6ADDR", &ipv6addr));
451     inet_pton (AF_INET6, ipv6addr, pkt6->ip6_hdr.dadr);
452     GNUNET_free(ipv6addr);
453   }
454   memcpy(&pkt6->udp_hdr, pkt, ntohs(pkt->len));
455
456   GNUNET_HashCode* key = address_mapping_exists(pkt6->ip6_hdr.sadr);
457   GNUNET_assert (key != NULL);
458
459   /* FIXME: update costs in heap */
460   struct map_entry *me = GNUNET_CONTAINER_multihashmap_get(hashmap, key);
461
462   GNUNET_free(key);
463
464   GNUNET_assert (me != NULL);
465   GNUNET_assert (me->desc.service_type & htonl(GNUNET_DNS_SERVICE_TYPE_UDP));
466   if (!port_in_ports(me->desc.ports, pkt6->udp_hdr.spt) &&
467       !testBit(me->additional_ports, ntohs(pkt6->udp_hdr.spt))) {
468       add_additional_port(me, ntohs(pkt6->udp_hdr.spt));
469   }
470
471   pkt6->udp_hdr.crc = 0;
472   uint32_t sum = 0;
473   sum = calculate_checksum_update(sum, (uint16_t*)&pkt6->ip6_hdr.sadr, 16);
474   sum = calculate_checksum_update(sum, (uint16_t*)&pkt6->ip6_hdr.dadr, 16);
475   uint32_t tmp = (pkt6->udp_hdr.len & 0xffff);
476   sum = calculate_checksum_update(sum, (uint16_t*)&tmp, 4);
477   tmp = htons(((pkt6->ip6_hdr.nxthdr & 0x00ff)));
478   sum = calculate_checksum_update(sum, (uint16_t*)&tmp, 4);
479
480   sum = calculate_checksum_update(sum, (uint16_t*)&pkt6->udp_hdr, ntohs(pkt->len));
481   pkt6->udp_hdr.crc = calculate_checksum_end(sum);
482
483   write_to_helper(pkt6, size);
484
485   return GNUNET_OK;
486 }
487
488 static int
489 receive_tcp_back (void *cls, struct GNUNET_MESH_Tunnel* tunnel,
490                   void **tunnel_ctx,
491                   const struct GNUNET_PeerIdentity *sender,
492                   const struct GNUNET_MessageHeader *message,
493                   const struct GNUNET_TRANSPORT_ATS_Information *atsi)
494 {
495   GNUNET_HashCode *desc = (GNUNET_HashCode *) (message + 1);
496   struct tcp_pkt *pkt = (struct tcp_pkt *) (desc + 1);
497   const struct GNUNET_PeerIdentity* other = GNUNET_MESH_get_peer(tunnel);
498
499   size_t pktlen = ntohs(message->size) - sizeof(struct GNUNET_MessageHeader) - sizeof(GNUNET_HashCode);
500   size_t size = pktlen + sizeof(struct ip6_tcp) - 1;
501
502   struct ip6_tcp* pkt6 = alloca(size);
503
504   GNUNET_assert(pkt6 != NULL);
505
506   new_ip6addr(pkt6->ip6_hdr.sadr, &other->hashPubKey, desc);
507
508   pkt6->shdr.type = htons(GNUNET_MESSAGE_TYPE_VPN_HELPER);
509   pkt6->shdr.size = htons(size);
510
511   pkt6->tun.flags = 0;
512   pkt6->tun.type = htons(0x86dd);
513
514   pkt6->ip6_hdr.version = 6;
515   pkt6->ip6_hdr.tclass_h = 0;
516   pkt6->ip6_hdr.tclass_l = 0;
517   pkt6->ip6_hdr.flowlbl = 0;
518   pkt6->ip6_hdr.paylgth = htons(pktlen);
519   pkt6->ip6_hdr.nxthdr = 0x06;
520   pkt6->ip6_hdr.hoplmt = 0xff;
521
522   {
523     char* ipv6addr;
524     GNUNET_assert(GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(cfg, "vpn", "IPV6ADDR", &ipv6addr));
525     inet_pton (AF_INET6, ipv6addr, pkt6->ip6_hdr.dadr);
526     GNUNET_free(ipv6addr);
527   }
528   memcpy(&pkt6->tcp_hdr, pkt, pktlen);
529
530   GNUNET_HashCode* key = address_mapping_exists(pkt6->ip6_hdr.sadr);
531   GNUNET_assert (key != NULL);
532
533   /* FIXME: update costs in heap */
534   struct map_entry *me = GNUNET_CONTAINER_multihashmap_get(hashmap, key);
535
536   GNUNET_free(key);
537
538   GNUNET_assert (me != NULL);
539   GNUNET_assert (me->desc.service_type & htonl(GNUNET_DNS_SERVICE_TYPE_TCP));
540
541   pkt6->tcp_hdr.crc = 0;
542   uint32_t sum = 0;
543   uint32_t tmp;
544   sum =
545     calculate_checksum_update (sum, (uint16_t *) & pkt6->ip6_hdr.sadr, 16);
546   sum =
547     calculate_checksum_update (sum, (uint16_t *) & pkt6->ip6_hdr.dadr, 16);
548   tmp = htonl(pktlen);
549   sum = calculate_checksum_update (sum, (uint16_t *) & tmp, 4);
550   tmp = htonl (((pkt6->ip6_hdr.nxthdr & 0x000000ff)));
551   sum = calculate_checksum_update (sum, (uint16_t *) & tmp, 4);
552
553   sum =
554     calculate_checksum_update (sum, (uint16_t *) & pkt6->tcp_hdr,
555                                ntohs (pkt6->ip6_hdr.paylgth));
556   pkt6->tcp_hdr.crc = calculate_checksum_end (sum);
557
558   write_to_helper(pkt6, size);
559
560   return GNUNET_OK;
561 }
562
563 void init_mesh (void* cls, struct GNUNET_MESH_Handle* server, const struct GNUNET_PeerIdentity* my_identity, const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *pubkey) {
564   GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Connected to MESH, I am %x\n", *((unsigned long*)my_identity));
565 }
566
567 void connect_mesh (void* cls, const struct GNUNET_PeerIdentity* peer, const struct GNUNET_TRANSPORT_ATS_Information *atsi) {
568   GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Connected to peer %x\n", *((unsigned long*)peer));
569 }
570
571 /**
572  * Main function that will be run by the scheduler.
573  *
574  * @param cls closure
575  * @param args remaining command-line arguments
576  * @param cfgfile name of the configuration file used (for saving, can be NULL!)
577  * @param cfg_ configuration
578  */
579 static void
580 run (void *cls,
581      char *const *args,
582      const char *cfgfile,
583      const struct GNUNET_CONFIGURATION_Handle *cfg_)
584 {
585     const static struct GNUNET_MESH_MessageHandler handlers[] = {
586           {receive_udp_back, GNUNET_MESSAGE_TYPE_SERVICE_UDP_BACK, 0},
587           {receive_tcp_back, GNUNET_MESSAGE_TYPE_SERVICE_TCP_BACK, 0},
588           {NULL, 0, 0}
589     };
590     mesh_handle = GNUNET_MESH_connect(cfg_,
591                                       NULL,
592                                       NULL,
593                                       handlers,
594                                       NULL);
595     cfg = cfg_;
596     restart_hijack = 0;
597     hashmap = GNUNET_CONTAINER_multihashmap_create(65536);
598     udp_connections = GNUNET_CONTAINER_multihashmap_create(65536);
599     GNUNET_SCHEDULER_TaskIdentifier conn_task = GNUNET_SCHEDULER_add_now (connect_to_service_dns, NULL);
600     GNUNET_SCHEDULER_add_after (conn_task, start_helper_and_schedule, NULL);
601     GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_FOREVER_REL, &cleanup, cls);
602 }
603
604 /**
605  * The main function to obtain template from gnunetd.
606  *
607  * @param argc number of arguments from the command line
608  * @param argv command line arguments
609  * @return 0 ok, 1 on error
610  */
611 int
612 main (int argc, char *const *argv) {
613     static const struct GNUNET_GETOPT_CommandLineOption options[] = {
614         GNUNET_GETOPT_OPTION_END
615     };
616
617     return (GNUNET_OK ==
618             GNUNET_PROGRAM_run (argc,
619                                 argv,
620                                 "gnunet-daemon-vpn",
621                                 gettext_noop ("help text"),
622                                 options, &run, NULL)) ? ret : 1;
623 }
624
625 /* end of gnunet-daemon-vpn.c */
626