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