removed unneeded FIXME
[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   GNUNET_MESH_notify_transmit_ready (*tunnel,
175                                      GNUNET_NO,
176                                      42,
177                                      GNUNET_TIME_relative_divide(GNUNET_CONSTANTS_MAX_CORK_DELAY, 2),
178                                      (const struct GNUNET_PeerIdentity *)NULL,
179                                      ntohs(hdr->size),
180                                      send_pkt_to_peer_notify_callback,
181                                      cls);
182 }
183
184 /**
185  * Create a new Address from an answer-packet
186  */
187 void
188 new_ip6addr(unsigned char* buf, const GNUNET_HashCode *peer, const GNUNET_HashCode *service_desc) { /* {{{ */
189     char* ipv6addr;
190     unsigned long long ipv6prefix;
191     GNUNET_assert(GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(cfg, "vpn", "IPV6ADDR", &ipv6addr));
192     GNUNET_assert(GNUNET_OK == GNUNET_CONFIGURATION_get_value_number(cfg, "vpn", "IPV6PREFIX", &ipv6prefix));
193     GNUNET_assert(ipv6prefix < 127);
194     ipv6prefix = (ipv6prefix + 7)/8;
195
196     inet_pton (AF_INET6, ipv6addr, buf);
197     GNUNET_free(ipv6addr);
198
199     int peer_length = 16 - ipv6prefix - 6;
200     if (peer_length <= 0)
201       peer_length = 0;
202
203     int service_length = 16 - ipv6prefix - peer_length;
204     if (service_length <= 0)
205       service_length = 0;
206
207     memcpy(buf+ipv6prefix, service_desc, service_length);
208     memcpy(buf+ipv6prefix+service_length, peer, peer_length);
209 }
210 /*}}}*/
211
212 /**
213  * This gets scheduled with cls pointing to an answer_packet and does everything
214  * needed in order to send it to the helper.
215  *
216  * At the moment this means "inventing" and IPv6-Address for .gnunet-services and
217  * doing nothing for "real" services.
218  */
219 void
220 process_answer(void* cls, const struct GNUNET_SCHEDULER_TaskContext* tc) {
221     struct answer_packet* pkt = cls;
222     struct answer_packet_list* list;
223
224     /* This answer is about a .gnunet-service
225      *
226      * It contains an almost complete DNS-Response, we have to fill in the ip
227      * at the offset pkt->addroffset
228      */
229     if (pkt->subtype == GNUNET_DNS_ANSWER_TYPE_SERVICE)
230       {
231         pkt->subtype = GNUNET_DNS_ANSWER_TYPE_IP;
232
233         GNUNET_HashCode key;
234         memset(&key, 0, sizeof(GNUNET_HashCode));
235
236         unsigned char* c = ((unsigned char*)pkt)+ntohs(pkt->addroffset);
237         unsigned char* k = (unsigned char*)&key;
238         new_ip6addr(c, &pkt->service_descr.peer, &pkt->service_descr.service_descriptor);
239         /*
240          * Copy the newly generated ip-address to the key backwarts (as only the first part is hashed)
241          */
242         unsigned int i;
243         for (i = 0; i < 16; i++)
244             k[15-i] = c[i];
245
246         uint16_t namelen = strlen((char*)pkt->data+12)+1;
247
248         struct map_entry* value = GNUNET_malloc(sizeof(struct map_entry) + namelen);
249         char* name = (char*)(value +1);
250
251         value->namelen = namelen;
252         memcpy(name, pkt->data+12, namelen);
253
254         memcpy(&value->desc, &pkt->service_descr, sizeof(struct GNUNET_vpn_service_descriptor));
255
256         memset(value->additional_ports, 0, 8192);
257
258         if (GNUNET_NO ==
259             GNUNET_CONTAINER_multihashmap_contains (hashmap, &key))
260           GNUNET_CONTAINER_multihashmap_put (hashmap, &key, value,
261                                        GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
262         else
263           GNUNET_free(value);
264
265
266         list = GNUNET_malloc(htons(pkt->hdr.size) + 2*sizeof(struct answer_packet_list*));
267
268         memcpy(&list->pkt, pkt, htons(pkt->hdr.size));
269
270       }
271     else if (pkt->subtype == GNUNET_DNS_ANSWER_TYPE_REV)
272       {
273         GNUNET_HashCode key;
274         memset(&key, 0, sizeof key);
275         unsigned char* k = (unsigned char*)&key;
276         unsigned char* s = pkt->data+12;
277         int i = 0;
278         /* Whoever designed the reverse IPv6-lookup is batshit insane */
279         for (i = 0; i < 16; i++)
280           {
281             unsigned char c1 = s[(4*i)+1];
282             unsigned char c2 = s[(4*i)+3];
283             if (c1 <= '9')
284               k[i] = c1 - '0';
285             else
286               k[i] = c1 - 87; /* 87 is the difference between 'a' and 10 */
287             if (c2 <= '9')
288               k[i] += 16*(c2 - '0');
289             else
290               k[i] += 16*(c2 - 87);
291           }
292
293         struct map_entry* map_entry = GNUNET_CONTAINER_multihashmap_get(hashmap, &key);
294         uint16_t offset = ntohs(pkt->addroffset);
295
296         if (map_entry == NULL)
297           {
298             GNUNET_free(pkt);
299             return;
300           }
301
302         unsigned short namelen = htons(map_entry->namelen);
303         char* name = (char*)(map_entry + 1);
304
305         list = GNUNET_malloc(2*sizeof(struct answer_packet_list*) + offset + 2 + ntohs(namelen));
306
307         struct answer_packet* rpkt = &list->pkt;
308
309         /* The offset points to the first byte belonging to the address */
310         memcpy(rpkt, pkt, offset - 1);
311
312         rpkt->subtype = GNUNET_DNS_ANSWER_TYPE_IP;
313         rpkt->hdr.size = ntohs(offset + 2 + ntohs(namelen));
314
315         memcpy(((char*)rpkt)+offset, &namelen, 2);
316         memcpy(((char*)rpkt)+offset+2, name, ntohs(namelen));
317
318       }
319     else if (pkt->subtype == GNUNET_DNS_ANSWER_TYPE_IP)
320       {
321         list = GNUNET_malloc(htons(pkt->hdr.size) + 2*sizeof(struct answer_packet_list*));
322         memcpy(&list->pkt, pkt, htons(pkt->hdr.size));
323       }
324     else
325       {
326         GNUNET_break(0);
327         GNUNET_free(pkt);
328         return;
329       }
330
331     GNUNET_free(pkt);
332
333     GNUNET_CONTAINER_DLL_insert_after(answer_proc_head, answer_proc_tail, answer_proc_tail, list);
334
335     schedule_helper_write(GNUNET_TIME_UNIT_FOREVER_REL, NULL);
336
337     return;
338 }
339
340 /**
341  * Sets a bit active in a bitArray.
342  *
343  * @param bitArray memory area to set the bit in
344  * @param bitIdx which bit to set
345  */
346 void
347 setBit (char *bitArray, unsigned int bitIdx)
348 {
349   size_t arraySlot;
350   unsigned int targetBit;
351
352   arraySlot = bitIdx / 8;
353   targetBit = (1L << (bitIdx % 8));
354   bitArray[arraySlot] |= targetBit;
355 }
356
357 /**
358  * Clears a bit from bitArray.
359  *
360  * @param bitArray memory area to set the bit in
361  * @param bitIdx which bit to unset
362  */
363 void
364 clearBit (char *bitArray, unsigned int bitIdx)
365 {
366   size_t slot;
367   unsigned int targetBit;
368
369   slot = bitIdx / 8;
370   targetBit = (1L << (bitIdx % 8));
371   bitArray[slot] = bitArray[slot] & (~targetBit);
372 }
373
374 /**
375  * Checks if a bit is active in the bitArray
376  *
377  * @param bitArray memory area to set the bit in
378  * @param bitIdx which bit to test
379  * @return GNUNET_YES if the bit is set, GNUNET_NO if not.
380  */
381 int
382 testBit (char *bitArray, unsigned int bitIdx)
383 {
384   size_t slot;
385   unsigned int targetBit;
386
387   slot = bitIdx / 8;
388   targetBit = (1L << (bitIdx % 8));
389   if (bitArray[slot] & targetBit)
390     return GNUNET_YES;
391   else
392     return GNUNET_NO;
393 }
394
395 /**
396  * @brief Add the port to the list of additional ports in the map_entry
397  *
398  * @param me the map_entry
399  * @param port the port in host-byte-order
400  */
401 static void
402 add_additional_port (struct map_entry *me, uint16_t port)
403 {
404   setBit(me->additional_ports, port);
405 }
406
407 static int
408 receive_udp_back (void *cls, struct GNUNET_MESH_Tunnel* tunnel,
409                   void **tunnel_ctx,
410                   const struct GNUNET_PeerIdentity *sender,
411                   const struct GNUNET_MessageHeader *message,
412                   const struct GNUNET_TRANSPORT_ATS_Information *atsi)
413 {
414   GNUNET_HashCode *desc = (GNUNET_HashCode *) (message + 1);
415   struct udp_pkt *pkt = (struct udp_pkt *) (desc + 1);
416   const struct GNUNET_PeerIdentity* other = GNUNET_MESH_get_peer(tunnel);
417
418   size_t size = sizeof(struct ip6_udp) + ntohs(pkt->len) - 1 - sizeof(struct udp_pkt);
419
420   struct ip6_udp* pkt6 = alloca(size);
421
422   GNUNET_assert(pkt6 != NULL);
423
424   new_ip6addr(pkt6->ip6_hdr.sadr, &other->hashPubKey, desc);
425
426   GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Relaying calc:%d gnu:%d udp:%d bytes!\n", size, ntohs(message->size), ntohs(pkt->len));
427
428   pkt6->shdr.type = htons(GNUNET_MESSAGE_TYPE_VPN_HELPER);
429   pkt6->shdr.size = htons(size);
430
431   pkt6->tun.flags = 0;
432   pkt6->tun.type = htons(0x86dd);
433
434   pkt6->ip6_hdr.version = 6;
435   pkt6->ip6_hdr.tclass_h = 0;
436   pkt6->ip6_hdr.tclass_l = 0;
437   pkt6->ip6_hdr.flowlbl = 0;
438   pkt6->ip6_hdr.paylgth = pkt->len;
439   pkt6->ip6_hdr.nxthdr = 0x11;
440   pkt6->ip6_hdr.hoplmt = 0xff;
441
442   {
443     char* ipv6addr;
444     GNUNET_assert(GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(cfg, "vpn", "IPV6ADDR", &ipv6addr));
445     inet_pton (AF_INET6, ipv6addr, pkt6->ip6_hdr.dadr);
446     GNUNET_free(ipv6addr);
447   }
448   memcpy(&pkt6->udp_hdr, pkt, ntohs(pkt->len));
449
450   GNUNET_HashCode* key = address_mapping_exists(pkt6->ip6_hdr.sadr);
451   GNUNET_assert (key != NULL);
452
453   struct map_entry *me = GNUNET_CONTAINER_multihashmap_get(hashmap, key);
454
455   GNUNET_free(key);
456
457   GNUNET_assert (me != NULL);
458   GNUNET_assert (me->desc.service_type & htonl(GNUNET_DNS_SERVICE_TYPE_UDP));
459   if (!port_in_ports(me->desc.ports, pkt6->udp_hdr.spt) &&
460       !testBit(me->additional_ports, ntohs(pkt6->udp_hdr.spt))) {
461       add_additional_port(me, ntohs(pkt6->udp_hdr.spt));
462   }
463
464   pkt6->udp_hdr.crc = 0;
465   uint32_t sum = 0;
466   sum = calculate_checksum_update(sum, (uint16_t*)&pkt6->ip6_hdr.sadr, 16);
467   sum = calculate_checksum_update(sum, (uint16_t*)&pkt6->ip6_hdr.dadr, 16);
468   uint32_t tmp = (pkt6->udp_hdr.len & 0xffff);
469   sum = calculate_checksum_update(sum, (uint16_t*)&tmp, 4);
470   tmp = htons(((pkt6->ip6_hdr.nxthdr & 0x00ff)));
471   sum = calculate_checksum_update(sum, (uint16_t*)&tmp, 4);
472
473   sum = calculate_checksum_update(sum, (uint16_t*)&pkt6->udp_hdr, ntohs(pkt->len));
474   pkt6->udp_hdr.crc = calculate_checksum_end(sum);
475
476   write_to_helper(pkt6, size);
477
478   return GNUNET_OK;
479 }
480
481 static int
482 receive_tcp_back (void *cls, struct GNUNET_MESH_Tunnel* tunnel,
483                   void **tunnel_ctx,
484                   const struct GNUNET_PeerIdentity *sender,
485                   const struct GNUNET_MessageHeader *message,
486                   const struct GNUNET_TRANSPORT_ATS_Information *atsi)
487 {
488   GNUNET_HashCode *desc = (GNUNET_HashCode *) (message + 1);
489   struct tcp_pkt *pkt = (struct tcp_pkt *) (desc + 1);
490   const struct GNUNET_PeerIdentity* other = GNUNET_MESH_get_peer(tunnel);
491
492   size_t pktlen = ntohs(message->size) - sizeof(struct GNUNET_MessageHeader) - sizeof(GNUNET_HashCode);
493   size_t size = pktlen + sizeof(struct ip6_tcp) - 1;
494
495   struct ip6_tcp* pkt6 = alloca(size);
496
497   GNUNET_assert(pkt6 != NULL);
498
499   new_ip6addr(pkt6->ip6_hdr.sadr, &other->hashPubKey, desc);
500
501   pkt6->shdr.type = htons(GNUNET_MESSAGE_TYPE_VPN_HELPER);
502   pkt6->shdr.size = htons(size);
503
504   pkt6->tun.flags = 0;
505   pkt6->tun.type = htons(0x86dd);
506
507   pkt6->ip6_hdr.version = 6;
508   pkt6->ip6_hdr.tclass_h = 0;
509   pkt6->ip6_hdr.tclass_l = 0;
510   pkt6->ip6_hdr.flowlbl = 0;
511   pkt6->ip6_hdr.paylgth = htons(pktlen);
512   pkt6->ip6_hdr.nxthdr = 0x06;
513   pkt6->ip6_hdr.hoplmt = 0xff;
514
515   {
516     char* ipv6addr;
517     GNUNET_assert(GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(cfg, "vpn", "IPV6ADDR", &ipv6addr));
518     inet_pton (AF_INET6, ipv6addr, pkt6->ip6_hdr.dadr);
519     GNUNET_free(ipv6addr);
520   }
521   memcpy(&pkt6->tcp_hdr, pkt, pktlen);
522
523   GNUNET_HashCode* key = address_mapping_exists(pkt6->ip6_hdr.sadr);
524   GNUNET_assert (key != NULL);
525
526   struct map_entry *me = GNUNET_CONTAINER_multihashmap_get(hashmap, key);
527
528   GNUNET_free(key);
529
530   GNUNET_assert (me != NULL);
531   GNUNET_assert (me->desc.service_type & htonl(GNUNET_DNS_SERVICE_TYPE_TCP));
532
533   pkt6->tcp_hdr.crc = 0;
534   uint32_t sum = 0;
535   uint32_t tmp;
536   sum =
537     calculate_checksum_update (sum, (uint16_t *) & pkt6->ip6_hdr.sadr, 16);
538   sum =
539     calculate_checksum_update (sum, (uint16_t *) & pkt6->ip6_hdr.dadr, 16);
540   tmp = htonl(pktlen);
541   sum = calculate_checksum_update (sum, (uint16_t *) & tmp, 4);
542   tmp = htonl (((pkt6->ip6_hdr.nxthdr & 0x000000ff)));
543   sum = calculate_checksum_update (sum, (uint16_t *) & tmp, 4);
544
545   sum =
546     calculate_checksum_update (sum, (uint16_t *) & pkt6->tcp_hdr,
547                                ntohs (pkt6->ip6_hdr.paylgth));
548   pkt6->tcp_hdr.crc = calculate_checksum_end (sum);
549
550   write_to_helper(pkt6, size);
551
552   return GNUNET_OK;
553 }
554
555 void init_mesh (void* cls, struct GNUNET_MESH_Handle* server, const struct GNUNET_PeerIdentity* my_identity, const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *pubkey) {
556   GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Connected to MESH, I am %x\n", *((unsigned long*)my_identity));
557 }
558
559 void connect_mesh (void* cls, const struct GNUNET_PeerIdentity* peer, const struct GNUNET_TRANSPORT_ATS_Information *atsi) {
560   GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Connected to peer %x\n", *((unsigned long*)peer));
561 }
562
563 /**
564  * Main function that will be run by the scheduler.
565  *
566  * @param cls closure
567  * @param args remaining command-line arguments
568  * @param cfgfile name of the configuration file used (for saving, can be NULL!)
569  * @param cfg_ configuration
570  */
571 static void
572 run (void *cls,
573      char *const *args,
574      const char *cfgfile,
575      const struct GNUNET_CONFIGURATION_Handle *cfg_)
576 {
577     const static struct GNUNET_MESH_MessageHandler handlers[] = {
578           {receive_udp_back, GNUNET_MESSAGE_TYPE_SERVICE_UDP_BACK, 0},
579           {receive_tcp_back, GNUNET_MESSAGE_TYPE_SERVICE_TCP_BACK, 0},
580           {NULL, 0, 0}
581     };
582     mesh_handle = GNUNET_MESH_connect(cfg_,
583                                       NULL,
584                                       NULL,
585                                       handlers,
586                                       NULL);
587     cfg = cfg_;
588     restart_hijack = 0;
589     hashmap = GNUNET_CONTAINER_multihashmap_create(65536);
590     udp_connections = GNUNET_CONTAINER_multihashmap_create(65536);
591     GNUNET_SCHEDULER_TaskIdentifier conn_task = GNUNET_SCHEDULER_add_now (connect_to_service_dns, NULL);
592     GNUNET_SCHEDULER_add_after (conn_task, start_helper_and_schedule, NULL);
593     GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_FOREVER_REL, &cleanup, cls);
594 }
595
596 /**
597  * The main function to obtain template from gnunetd.
598  *
599  * @param argc number of arguments from the command line
600  * @param argv command line arguments
601  * @return 0 ok, 1 on error
602  */
603 int
604 main (int argc, char *const *argv) {
605     static const struct GNUNET_GETOPT_CommandLineOption options[] = {
606         GNUNET_GETOPT_OPTION_END
607     };
608
609     return (GNUNET_OK ==
610             GNUNET_PROGRAM_run (argc,
611                                 argv,
612                                 "gnunet-daemon-vpn",
613                                 gettext_noop ("help text"),
614                                 options, &run, NULL)) ? ret : 1;
615 }
616
617 /* end of gnunet-daemon-vpn.c */
618