Testing and core related changes.
[oweals/gnunet.git] / src / vpn / gnunet-daemon-exit.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-exit.c
23  * @brief
24  * @author Philipp Toelke
25  */
26 #include <platform.h>
27 #include <gnunet_common.h>
28 #include <gnunet_program_lib.h>
29 #include <gnunet_protocols.h>
30 #include <gnunet_mesh_service.h>
31 #include <gnunet_constants.h>
32 #include <string.h>
33
34 #include "gnunet-vpn-packet.h"
35 #include "gnunet-helper-vpn-api.h"
36 #include "gnunet-vpn-checksum.h"
37
38 /**
39  * The handle to the configuration used throughout the process
40  */
41 static const struct GNUNET_CONFIGURATION_Handle *cfg;
42
43 /**
44  * The handle to the service-configuration
45  */
46 static struct GNUNET_CONFIGURATION_Handle *servicecfg;
47
48 /**
49  * The handle to the helper
50  */
51 struct GNUNET_VPN_HELPER_Handle *helper_handle;
52
53 /**
54  * Final status code.
55  */
56 static int ret;
57
58 /**
59  * The handle to mesh
60  */
61 static struct GNUNET_MESH_Handle *mesh_handle;
62
63 /**
64  * This hashmap contains the mapping from peer, service-descriptor,
65  * source-port and destination-port to a socket
66  */
67 static struct GNUNET_CONTAINER_MultiHashMap *udp_connections;
68
69 /**
70  * This struct is saved into the services-hashmap
71  */
72 struct udp_service
73 {
74   /**
75    * One of 4 or 6
76    */
77   unsigned int version;
78   uint16_t my_port;
79   uint16_t remote_port;
80
81   union
82   {
83     struct
84     {
85       char ip4address[4];
86     } v4;
87     struct
88     {
89       char ip6address[16];
90     } v6;
91   };
92 };
93
94 struct udp_info
95 {
96     /**
97      * The source-address of this connection. When a packet to this address is
98      * received, this tunnel is used to forward it.  ipv4-addresses will be put
99      * here left-aligned */
100   char addr[16];
101     /**
102      * The source-port of this connection
103      */
104   uint16_t pt;
105 };
106
107 /**
108  * This struct is saved into udp_connections;
109  */
110 struct udp_state
111 {
112   struct GNUNET_MESH_Tunnel *tunnel;
113   GNUNET_HashCode desc;
114   struct udp_service *serv;
115
116   /**
117    * The source-address and -port of this connection
118    */
119   struct udp_info udp_info;
120 };
121
122 /**
123  * This hashmap saves interesting things about the configured services
124  */
125 static struct GNUNET_CONTAINER_MultiHashMap *udp_services;
126
127 /**
128  * Function that frees everything from a hashmap
129  */
130 static int
131 free_iterate(void* cls, const GNUNET_HashCode* hash, void* value)
132 {
133   GNUNET_free(value);
134   return GNUNET_YES;
135 }
136
137 /**
138  * Function scheduled as very last function, cleans up after us
139  */
140 static void
141 cleanup(void* cls, const struct GNUNET_SCHEDULER_TaskContext* tskctx) {
142     GNUNET_assert (0 != (tskctx->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN));
143
144     GNUNET_CONTAINER_multihashmap_iterate(udp_connections,
145                                           free_iterate,
146                                           NULL);
147
148     if (mesh_handle != NULL)
149       {
150         GNUNET_MESH_disconnect(mesh_handle);
151         mesh_handle = NULL;
152       }
153 }
154
155 /**
156  * cls is the pointer to a GNUNET_MessageHeader that is
157  * followed by the service-descriptor and the udp-packet that should be sent;
158  */
159 static size_t
160 send_udp_to_peer_notify_callback (void *cls, size_t size, void *buf)
161 {
162   struct GNUNET_MessageHeader *hdr = cls;
163   GNUNET_assert (size >= ntohs (hdr->size));
164   memcpy (buf, hdr, ntohs (hdr->size));
165   size = ntohs(hdr->size);
166   GNUNET_free (cls);
167   return size;
168 }
169
170 /**
171  * Receive packets from the helper-process
172  */
173 static void
174 message_token (void *cls,
175                void *client, const struct GNUNET_MessageHeader *message)
176 {
177   GNUNET_assert (ntohs (message->type) == GNUNET_MESSAGE_TYPE_VPN_HELPER);
178
179   struct tun_pkt *pkt_tun = (struct tun_pkt *) message;
180
181   struct GNUNET_MessageHeader *msg;
182   struct GNUNET_MESH_Tunnel *tunnel;
183   uint32_t len;
184
185   struct udp_pkt *udp;
186   struct udp_info u_i;
187   memset(&u_i, 0, sizeof(struct udp_info));
188
189   unsigned int version;
190
191   /* ethertype is ipv6 */
192   if (ntohs (pkt_tun->tun.type) == 0x86dd)
193     {
194       struct ip6_udp *pkt6 = (struct ip6_udp*)pkt_tun;
195       if (pkt6->ip6_hdr.nxthdr != 0x11) return;
196       /* lookup in udp_connections for dpt/dadr*/
197       memcpy(&u_i.addr, pkt6->ip6_hdr.dadr, 16);
198       udp = &pkt6->udp_hdr;
199       version = 6;
200     }
201   else if (ntohs(pkt_tun->tun.type) == 0x0800)
202     {
203       struct ip_udp *pkt4 = (struct ip_udp*)pkt_tun;
204       if (pkt4->ip_hdr.proto != 0x11) return;
205       uint32_t tmp = pkt4->ip_hdr.dadr;
206       memcpy(&u_i.addr, &tmp, 4);
207       udp = &pkt4->udp_hdr;
208       version = 4;
209     }
210   else
211     {
212       return;
213     }
214
215   u_i.pt = udp->dpt;
216
217   /* get tunnel and service-descriptor from this*/
218   GNUNET_HashCode hash;
219   GNUNET_CRYPTO_hash(&u_i, sizeof(struct udp_info), &hash);
220   struct udp_state *state = GNUNET_CONTAINER_multihashmap_get(udp_connections, &hash);
221
222   tunnel = state->tunnel;
223
224   /* check if spt == serv.remote if yes: set spt = serv.myport*/
225   if (ntohs(udp->spt) == state->serv->remote_port)
226     {
227       udp->spt = htons(state->serv->my_port);
228     }
229   else
230     {
231       struct udp_service *serv = GNUNET_malloc(sizeof(struct udp_service));
232       memcpy(serv, state->serv, sizeof(struct udp_service));
233       serv->my_port = ntohs(udp->spt);
234       serv->remote_port = ntohs(udp->spt);
235       uint16_t *desc = alloca (sizeof (GNUNET_HashCode) + 2);
236       memcpy((GNUNET_HashCode *) (desc + 1), &state->desc, sizeof(GNUNET_HashCode));
237       *desc = ntohs(udp->spt);
238       GNUNET_HashCode hash;
239       GNUNET_CRYPTO_hash (desc, sizeof (GNUNET_HashCode) + 2, &hash);
240       GNUNET_assert (GNUNET_OK ==
241                      GNUNET_CONTAINER_multihashmap_put (udp_services,
242                                                         &hash, serv,
243                                                         GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
244       state->serv = serv;
245     }
246   /* send udp-packet back */ 
247   len = sizeof(struct GNUNET_MessageHeader) + sizeof(GNUNET_HashCode) + ntohs(udp->len);
248   msg = GNUNET_malloc(len);
249   msg->size = htons(len);
250   msg->type = htons(GNUNET_MESSAGE_TYPE_SERVICE_UDP_BACK);
251   GNUNET_HashCode *desc = (GNUNET_HashCode*)(msg+1);
252   memcpy(desc, &state->desc, sizeof(GNUNET_HashCode));
253   void* _udp = desc+1;
254   memcpy(_udp, udp, ntohs(udp->len));
255
256   GNUNET_MESH_notify_transmit_ready (tunnel,
257                                      GNUNET_NO,
258                                      42,
259                                      GNUNET_TIME_relative_divide(GNUNET_CONSTANTS_MAX_CORK_DELAY, 2),
260                                      len,
261                                      send_udp_to_peer_notify_callback,
262                                      msg);
263 }
264
265 /**
266  * Reads the configuration servicecfg and populates udp_services
267  */
268 static void
269 read_service_conf (void *cls, const char *section, const char *option,
270                    const char *value)
271 {
272   GNUNET_HashCode hash;
273   uint16_t *desc = alloca (sizeof (GNUNET_HashCode) + 2);
274   GNUNET_CRYPTO_hash (section, strlen (section) + 1,
275                       (GNUNET_HashCode *) (desc + 1));
276
277   if (0 == strcmp ("UDP_REDIRECTS", option))
278     {
279       char *saveptr;
280       char *value_ = alloca (strlen (value) + 1);
281       memcpy (value_, value, strlen (value) + 1);
282       char *token = strtok_r (value_, " ", &saveptr);
283       while (NULL != token)
284         {
285           char *isaveptr;
286
287           char *itoken = strtok_r (token, ":", &isaveptr);
288           GNUNET_assert (NULL != itoken);
289           int local_port = atoi (itoken);
290           GNUNET_assert ((local_port > 0) && (local_port < 65536));
291           *desc = local_port;
292
293           GNUNET_CRYPTO_hash (desc, sizeof (GNUNET_HashCode) + 2, &hash);
294
295           struct udp_service *serv =
296             GNUNET_malloc (sizeof (struct udp_service));
297           memset (serv, 0, sizeof (struct udp_service));
298           serv->my_port = local_port;
299
300           itoken = strtok_r (NULL, ":", &isaveptr);
301           GNUNET_assert (NULL != itoken);
302           if (0 == strcmp ("localhost4", itoken))
303             {
304               serv->version = 4;
305
306               char *ip4addr;
307               GNUNET_assert (GNUNET_OK ==
308                              GNUNET_CONFIGURATION_get_value_string (cfg,
309                                                                     "exit",
310                                                                     "IPV4ADDR",
311                                                                     &ip4addr));
312               GNUNET_assert (1 ==
313                              inet_pton (AF_INET, ip4addr,
314                                         serv->v4.ip4address));
315               GNUNET_free (ip4addr);
316             }
317           else if (0 == strcmp ("localhost6", itoken))
318             {
319               serv->version = 6;
320
321               char *ip6addr;
322               GNUNET_assert (GNUNET_OK ==
323                              GNUNET_CONFIGURATION_get_value_string (cfg,
324                                                                     "exit",
325                                                                     "IPV6ADDR",
326                                                                     &ip6addr));
327               GNUNET_assert (1 ==
328                              inet_pton (AF_INET6, ip6addr,
329                                         serv->v6.ip6address));
330               GNUNET_free (ip6addr);
331             }
332           else
333             {
334               // Lookup, yadayadayada
335               GNUNET_assert (0);
336             }
337
338           itoken = strtok_r (NULL, ":", &isaveptr);
339           GNUNET_assert (NULL != itoken);
340           serv->remote_port = atoi (itoken);
341
342           GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Store with key1 %x\n",
343                       *((unsigned long long *) (desc + 1)));
344           GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Store with key2 %x\n",
345                       *((unsigned long long *) &hash));
346           GNUNET_assert (GNUNET_OK ==
347                          GNUNET_CONTAINER_multihashmap_put (udp_services,
348                                                             &hash, serv,
349                                                             GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
350
351           token = strtok_r (NULL, " ", &saveptr);
352         }
353     }
354 }
355
356 /**
357  * Start the helper-process
358  *
359  * If cls != NULL it is assumed that this function is called as a result of a dying
360  * helper. cls is then taken as handle to the old helper and is cleaned up.
361  */
362 static void
363 start_helper_and_schedule(void *cls,
364                           const struct GNUNET_SCHEDULER_TaskContext *tc) {
365     if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
366       return;
367
368     if (cls != NULL)
369       cleanup_helper(cls);
370     cls = NULL;
371
372     char* ifname;
373     char* ipv6addr;
374     char* ipv6prefix;
375     char* ipv4addr;
376     char* ipv4mask;
377
378     if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg, "exit", "IFNAME", &ifname))
379       {
380         GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "No entry 'IFNAME' in configuration!\n");
381         exit(1);
382       }
383
384     if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg, "exit", "IPV6ADDR", &ipv6addr))
385       {
386         GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "No entry 'IPV6ADDR' in configuration!\n");
387         exit(1);
388       }
389
390     if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg, "exit", "IPV6PREFIX", &ipv6prefix))
391       {
392         GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "No entry 'IPV6PREFIX' in configuration!\n");
393         exit(1);
394       }
395
396     if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg, "exit", "IPV4ADDR", &ipv4addr))
397       {
398         GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "No entry 'IPV4ADDR' in configuration!\n");
399         exit(1);
400       }
401
402     if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg, "exit", "IPV4MASK", &ipv4mask))
403       {
404         GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "No entry 'IPV4MASK' in configuration!\n");
405         exit(1);
406       }
407
408     /* Start the helper
409      * Messages get passed to the function message_token
410      * When the helper dies, this function will be called again with the
411      * helper_handle as cls.
412      */
413     helper_handle = start_helper(ifname,
414                                  ipv6addr,
415                                  ipv6prefix,
416                                  ipv4addr,
417                                  ipv4mask,
418                                  "exit-gnunet",
419                                  start_helper_and_schedule,
420                                  message_token,
421                                  NULL,
422                                  NULL);
423
424     GNUNET_free(ipv6addr);
425     GNUNET_free(ipv6prefix);
426     GNUNET_free(ipv4addr);
427     GNUNET_free(ipv4mask);
428     GNUNET_free(ifname);
429 }
430
431 /**
432  * The messages are one GNUNET_HashCode for the service, followed by a struct udp_pkt
433  */
434 static int
435 receive_udp_service (void *cls,
436                      struct GNUNET_MESH_Tunnel *tunnel,
437                      void **tunnel_ctx,
438                      const struct GNUNET_MessageHeader *message,
439                      const struct GNUNET_TRANSPORT_ATS_Information *atsi)
440 {
441   GNUNET_HashCode hash;
442   GNUNET_HashCode *desc = (GNUNET_HashCode *) (message + 1);
443   struct udp_pkt *pkt = (struct udp_pkt *) (desc + 1);
444   struct ip6_udp *pkt6;
445   struct ip_udp *pkt4;
446
447   GNUNET_assert (ntohs (pkt->len) ==
448                  ntohs (message->size) -
449                  sizeof (struct GNUNET_MessageHeader) -
450                  sizeof (GNUNET_HashCode));
451
452   /* Get the configuration from the hashmap */
453   uint16_t *udp_desc = alloca(sizeof(GNUNET_HashCode)+2);
454   memcpy(udp_desc + 1, desc, sizeof(GNUNET_HashCode));
455   *udp_desc = ntohs(pkt->dpt);
456   GNUNET_CRYPTO_hash(udp_desc, sizeof(GNUNET_HashCode)+2, &hash);
457   struct udp_service *serv = GNUNET_CONTAINER_multihashmap_get(udp_services, &hash);
458   if (NULL == serv)
459     {
460       GNUNET_log(GNUNET_ERROR_TYPE_INFO, "No service found for dpt %d!\n", *udp_desc);
461       return GNUNET_YES;
462     }
463
464   pkt->dpt = htons(serv->remote_port);
465   /* FIXME -> check acl etc */
466
467   char* buf;
468   size_t len;
469   uint32_t tmp, tmp2;
470
471   /* Prepare the state.
472    * This will be saved in the hashmap, so that the receiving procedure knows
473    * through which tunnel this connection has to be routed.
474    */
475   struct udp_state *state = GNUNET_malloc (sizeof (struct udp_state));
476   memset(state, 0, sizeof(struct udp_state));
477   state->tunnel = tunnel;
478   state->serv = serv;
479   memcpy(&state->desc, desc, sizeof(GNUNET_HashCode));
480
481   switch (serv->version)
482     {
483     case 4:
484       len = sizeof (struct GNUNET_MessageHeader) + sizeof (struct pkt_tun) +
485                 sizeof (struct ip_hdr) + ntohs (pkt->len);
486       pkt4 = alloca(len);
487       memset (pkt4, 0, len);
488       buf = (char*)pkt4;
489
490       pkt4->shdr.type = htons(GNUNET_MESSAGE_TYPE_VPN_HELPER);
491       pkt4->shdr.size = htons(len);
492       pkt4->tun.flags = 0;
493       pkt4->tun.type = htons(0x0800);
494
495       memcpy(&pkt4->udp_hdr, pkt, ntohs(pkt->len));
496
497       pkt4->ip_hdr.version = 4;
498       pkt4->ip_hdr.hdr_lngth = 5;
499       pkt4->ip_hdr.diff_serv = 0;
500       pkt4->ip_hdr.tot_lngth = htons(20 + ntohs(pkt->len));
501       pkt4->ip_hdr.ident = 0;
502       pkt4->ip_hdr.flags = 0;
503       pkt4->ip_hdr.frag_off = 0;
504       pkt4->ip_hdr.ttl = 255;
505       pkt4->ip_hdr.proto = 0x11; /* UDP */
506       pkt4->ip_hdr.chks = 0; /* Will be calculated later*/
507
508       memcpy(&tmp, &serv->v4.ip4address, 4);
509       pkt4->ip_hdr.dadr = tmp;
510
511       /* Generate a new src-address */
512       char* ipv4addr;
513       char* ipv4mask;
514       GNUNET_assert(GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(cfg, "exit", "IPV4ADDR", &ipv4addr));
515       GNUNET_assert(GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(cfg, "exit", "IPV4MASK", &ipv4mask));
516       inet_pton(AF_INET, ipv4addr, &tmp);
517       inet_pton(AF_INET, ipv4mask, &tmp2);
518       GNUNET_free(ipv4addr);
519       GNUNET_free(ipv4mask);
520
521       /* This should be a noop */
522       tmp = tmp & tmp2;
523
524       tmp |= ntohl(*((uint32_t*)tunnel)) & (~tmp2);
525
526       pkt4->ip_hdr.sadr = tmp;
527
528       memcpy(&state->udp_info.addr, &tmp, 4);
529       state->udp_info.pt = pkt4->udp_hdr.spt;
530
531       pkt4->udp_hdr.crc = 0; /* Optional for IPv4 */
532
533       pkt4->ip_hdr.chks = calculate_ip_checksum((uint16_t*)&pkt4->ip_hdr, 5*4);
534
535       break;
536     case 6:
537       len = sizeof (struct GNUNET_MessageHeader) + sizeof (struct pkt_tun) +
538                 sizeof (struct ip6_hdr) + ntohs (pkt->len);
539       pkt6 =
540         alloca (len);
541       memset (pkt6, 0, len);
542       buf =(char*) pkt6;
543
544       pkt6->shdr.type = htons(GNUNET_MESSAGE_TYPE_VPN_HELPER);
545       pkt6->shdr.size = htons(len);
546       pkt6->tun.flags = 0;
547       pkt6->tun.type = htons(0x86dd);
548
549       memcpy (&pkt6->udp_hdr, pkt, ntohs (pkt->len));
550
551       pkt6->ip6_hdr.version = 6;
552       pkt6->ip6_hdr.nxthdr = 0x11;  //UDP
553       pkt6->ip6_hdr.paylgth = pkt->len;
554       pkt6->ip6_hdr.hoplmt = 64;
555
556       memcpy(pkt6->ip6_hdr.dadr, &serv->v6.ip6address, 16);
557
558       /* Generate a new src-address
559        * This takes as much from the address of the tunnel as fits into
560        * the host-mask*/
561       char* ipv6addr;
562       unsigned long long ipv6prefix;
563       GNUNET_assert(GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(cfg, "exit", "IPV6ADDR", &ipv6addr));
564       GNUNET_assert(GNUNET_OK == GNUNET_CONFIGURATION_get_value_number(cfg, "exit", "IPV6PREFIX", &ipv6prefix));
565       GNUNET_assert(ipv6prefix < 127);
566       ipv6prefix = (ipv6prefix + 7)/8;
567
568       inet_pton (AF_INET6, ipv6addr, &pkt6->ip6_hdr.sadr);
569       GNUNET_free(ipv6addr);
570
571       if (ipv6prefix < (16 - sizeof(void*)))
572         ipv6prefix = 16 - sizeof(void*);
573
574       unsigned int offset = ipv6prefix - (16-sizeof(void*));
575       memcpy((((char*)&pkt6->ip6_hdr.sadr))+ipv6prefix, ((char*)&tunnel)+offset, 16 - ipv6prefix);
576
577       /* copy the needed information into the state */
578       memcpy(&state->udp_info.addr, &pkt6->ip6_hdr.sadr, 16);
579       state->udp_info.pt = pkt6->udp_hdr.spt;
580
581       pkt6->udp_hdr.crc = 0;
582       uint32_t sum = 0;
583       sum = calculate_checksum_update(sum, (uint16_t*)&pkt6->ip6_hdr.sadr, 16);
584       sum = calculate_checksum_update(sum, (uint16_t*)&pkt6->ip6_hdr.dadr, 16);
585       tmp = (pkt6->udp_hdr.len & 0xffff);
586       sum = calculate_checksum_update(sum, (uint16_t*)&tmp, 4);
587       tmp = htons(((pkt6->ip6_hdr.nxthdr & 0x00ff)));
588       sum = calculate_checksum_update(sum, (uint16_t*)&tmp, 4);
589
590       sum = calculate_checksum_update(sum, (uint16_t*)&pkt6->udp_hdr, ntohs(pkt6->udp_hdr.len));
591       pkt6->udp_hdr.crc = calculate_checksum_end(sum);
592
593       break;
594     default:
595       GNUNET_assert(0);
596       break;
597     }
598
599   GNUNET_CRYPTO_hash (&state->udp_info, sizeof(struct udp_info), &hash);
600
601   if (GNUNET_NO ==
602       GNUNET_CONTAINER_multihashmap_contains (udp_connections, &hash))
603     GNUNET_CONTAINER_multihashmap_put (udp_connections, &hash, state,
604                                        GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
605   else
606     GNUNET_free(state);
607
608   (void)GNUNET_DISK_file_write(helper_handle->fh_to_helper, buf, len);
609   return GNUNET_YES;
610 }
611
612 /**
613  * @brief Main function that will be run by the scheduler.
614  *
615  * @param cls closure
616  * @param args remaining command-line arguments
617  * @param cfgfile name of the configuration file used (for saving, can be NULL!)
618  * @param cfg_ configuration
619  */
620 static void
621 run (void *cls,
622      char *const *args,
623      const char *cfgfile,
624      const struct GNUNET_CONFIGURATION_Handle *cfg_)
625 {
626   const static struct GNUNET_MESH_MessageHandler handlers[] = {
627         {receive_udp_service, GNUNET_MESSAGE_TYPE_SERVICE_UDP, 0},
628         {NULL, 0, 0}
629   };
630   mesh_handle = GNUNET_MESH_connect(cfg_,
631                                     NULL,
632                                     NULL, /* FIXME */
633                                     handlers);
634
635   cfg = cfg_;
636   udp_connections = GNUNET_CONTAINER_multihashmap_create(65536);
637   udp_services = GNUNET_CONTAINER_multihashmap_create(65536);
638
639   char *services;
640   GNUNET_CONFIGURATION_get_value_filename(cfg, "dns", "SERVICES", &services);
641   servicecfg = GNUNET_CONFIGURATION_create();
642   if (GNUNET_OK == GNUNET_CONFIGURATION_parse(servicecfg, services))
643     {
644       GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Parsing services %s\n", services);
645       GNUNET_CONFIGURATION_iterate(servicecfg, read_service_conf, NULL);
646     }
647   if (NULL != services)
648     GNUNET_free(services);
649
650   GNUNET_SCHEDULER_add_now (start_helper_and_schedule, NULL);
651   GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_FOREVER_REL, &cleanup, cls);
652 }
653
654 /**
655  * The main function to obtain template from gnunetd.
656  *
657  * @param argc number of arguments from the command line
658  * @param argv command line arguments
659  * @return 0 ok, 1 on error
660  */
661 int
662 main (int argc, char *const *argv) {
663     static const struct GNUNET_GETOPT_CommandLineOption options[] = {
664         GNUNET_GETOPT_OPTION_END
665     };
666
667     return (GNUNET_OK ==
668             GNUNET_PROGRAM_run (argc,
669                                 argv,
670                                 "exit",
671                                 gettext_noop ("help text"),
672                                 options, &run, NULL)) ? ret : 1;
673 }
674
675 /* end of gnunet-daemon-exit.c */
676