2 This file is part of GNUnet.
3 (C) 2010 Christian Grothoff
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-daemon-vpn.c
24 * @author Philipp Toelke
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_applications.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"
43 const struct GNUNET_CONFIGURATION_Handle *cfg;
44 struct GNUNET_MESH_Handle *mesh_handle;
45 struct GNUNET_CONTAINER_MultiHashMap* hashmap;
46 static struct GNUNET_CONTAINER_Heap *heap;
49 * If there are at least this many address-mappings, old ones will be removed
51 static long long unsigned int max_mappings = 200;
59 * This hashmap contains the mapping from peer, service-descriptor,
60 * source-port and destination-port to a socket
62 static struct GNUNET_CONTAINER_MultiHashMap *udp_connections;
65 * Function scheduled as very last function, cleans up after us
69 cleanup(void* cls __attribute__((unused)), const struct GNUNET_SCHEDULER_TaskContext* tskctx) {
70 GNUNET_assert (0 != (tskctx->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN));
73 cleanup_helper(helper_handle);
75 /* close the connection to the service-dns */
76 if (dns_connection != NULL)
78 GNUNET_CLIENT_disconnect (dns_connection, GNUNET_NO);
79 dns_connection = NULL;
82 if (mesh_handle != NULL)
84 GNUNET_MESH_disconnect(mesh_handle);
91 * @return the hash of the IP-Address if a mapping exists, NULL otherwise
94 address_mapping_exists(unsigned char addr[]) {
95 GNUNET_HashCode* key = GNUNET_malloc(sizeof(GNUNET_HashCode));
96 unsigned char* k = (unsigned char*)key;
97 memset(key, 0, sizeof(GNUNET_HashCode));
99 for (i = 0; i < 16; i++)
102 if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains(hashmap, key))
112 collect_mappings(void* cls __attribute__((unused)), const struct GNUNET_SCHEDULER_TaskContext* tc) {
113 if ( (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
116 struct map_entry* me = GNUNET_CONTAINER_heap_remove_root(heap);
118 /* This is free()ed memory! */
119 me->heap_node = NULL;
121 /* FIXME! GNUNET_MESH_close_tunnel(me->tunnel); */
123 GNUNET_CONTAINER_multihashmap_remove(hashmap, &me->hash, me);
129 send_icmp_response(void* cls, const struct GNUNET_SCHEDULER_TaskContext *tc) {
130 if ( (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
133 struct ip6_icmp* request = cls;
135 struct ip6_icmp* response = alloca(ntohs(request->shdr.size));
136 GNUNET_assert(response != NULL);
137 memset(response, 0, ntohs(request->shdr.size));
139 response->shdr.size = request->shdr.size;
140 response->shdr.type = htons(GNUNET_MESSAGE_TYPE_VPN_HELPER);
142 response->tun.flags = 0;
143 response->tun.type = htons(0x86dd);
145 response->ip6_hdr.hoplmt = 255;
146 response->ip6_hdr.paylgth = request->ip6_hdr.paylgth;
147 response->ip6_hdr.nxthdr = 0x3a;
148 response->ip6_hdr.version = 6;
149 memcpy(&response->ip6_hdr.sadr, &request->ip6_hdr.dadr, 16);
150 memcpy(&response->ip6_hdr.dadr, &request->ip6_hdr.sadr, 16);
152 response->icmp_hdr.code = 0;
153 response->icmp_hdr.type = 0x81;
155 /* Magic, more Magic! */
156 response->icmp_hdr.chks = request->icmp_hdr.chks - 0x1;
158 /* Copy the rest of the packet */
159 memcpy(response+1, request+1, ntohs(request->shdr.size) - sizeof(struct ip6_icmp));
161 write_to_helper(response, ntohs(response->shdr.size));
163 GNUNET_free(request);
167 * cls is the pointer to a GNUNET_MessageHeader that is
168 * followed by the service-descriptor and the packet that should be sent;
171 send_pkt_to_peer_notify_callback (void *cls, size_t size, void *buf)
173 struct GNUNET_MESH_Tunnel **tunnel = cls;
174 struct GNUNET_MessageHeader *hdr =
175 (struct GNUNET_MessageHeader *) (tunnel + 1);
176 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "send_pkt_to_peer_notify_callback: buf = %x; size = %u;\n", buf, size);
177 GNUNET_assert (size >= ntohs (hdr->size));
178 memcpy (buf, hdr, ntohs (hdr->size));
179 size = ntohs(hdr->size);
181 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sent!\n");
186 port_in_ports (uint64_t ports, uint16_t port)
188 uint16_t *ps = (uint16_t *) & ports;
189 return ps[0] == port || ps[1] == port || ps[2] == port || ps[3] == port;
193 send_pkt_to_peer (void *cls,
194 const struct GNUNET_PeerIdentity *peer,
195 const struct GNUNET_TRANSPORT_ATS_Information *atsi __attribute__((unused)))
197 /* peer == NULL means that all peers in this request are connected */
198 if (peer == NULL) return;
199 struct GNUNET_MESH_Tunnel **tunnel = cls;
200 struct GNUNET_MessageHeader *hdr =
201 (struct GNUNET_MessageHeader *) (tunnel + 1);
203 GNUNET_assert(NULL != tunnel);
204 GNUNET_assert(NULL != *tunnel);
206 GNUNET_MESH_notify_transmit_ready (*tunnel,
209 GNUNET_TIME_relative_divide(GNUNET_CONSTANTS_MAX_CORK_DELAY, 2),
210 (const struct GNUNET_PeerIdentity *)NULL,
212 send_pkt_to_peer_notify_callback,
217 * Create a new Address from an answer-packet
220 new_ip6addr(unsigned char* buf, const GNUNET_HashCode *peer, const GNUNET_HashCode *service_desc) { /* {{{ */
222 unsigned long long ipv6prefix;
223 GNUNET_assert(GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(cfg, "vpn", "IPV6ADDR", &ipv6addr));
224 GNUNET_assert(GNUNET_OK == GNUNET_CONFIGURATION_get_value_number(cfg, "vpn", "IPV6PREFIX", &ipv6prefix));
225 GNUNET_assert(ipv6prefix < 127);
226 ipv6prefix = (ipv6prefix + 7)/8;
228 inet_pton (AF_INET6, ipv6addr, buf);
229 GNUNET_free(ipv6addr);
231 int peer_length = 16 - ipv6prefix - 6;
232 if (peer_length <= 0)
235 int service_length = 16 - ipv6prefix - peer_length;
236 if (service_length <= 0)
239 memcpy(buf+ipv6prefix, service_desc, service_length);
240 memcpy(buf+ipv6prefix+service_length, peer, peer_length);
246 * Create a new Address from an answer-packet
249 new_ip6addr_remote (unsigned char *buf, unsigned char *addr, char addrlen)
252 unsigned long long ipv6prefix;
253 GNUNET_assert (GNUNET_OK ==
254 GNUNET_CONFIGURATION_get_value_string (cfg, "vpn",
257 GNUNET_assert (GNUNET_OK ==
258 GNUNET_CONFIGURATION_get_value_number (cfg, "vpn",
261 GNUNET_assert (ipv6prefix < 127);
262 ipv6prefix = (ipv6prefix + 7) / 8;
264 inet_pton (AF_INET6, ipv6addr, buf);
265 GNUNET_free (ipv6addr);
267 int local_length = 16 - ipv6prefix;
269 memcpy (buf + ipv6prefix, addr, GNUNET_MAX (addrlen, local_length));
274 * This gets scheduled with cls pointing to an answer_packet and does everything
275 * needed in order to send it to the helper.
277 * At the moment this means "inventing" and IPv6-Address for .gnunet-services and
278 * doing nothing for "real" services.
281 process_answer(void* cls, const struct GNUNET_SCHEDULER_TaskContext* tc) {
282 if ( (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
285 struct answer_packet* pkt = cls;
286 struct answer_packet_list* list;
288 /* This answer is about a .gnunet-service
290 * It contains an almost complete DNS-Response, we have to fill in the ip
291 * at the offset pkt->addroffset
293 if (pkt->subtype == GNUNET_DNS_ANSWER_TYPE_SERVICE)
295 pkt->subtype = GNUNET_DNS_ANSWER_TYPE_IP;
298 memset(&key, 0, sizeof(GNUNET_HashCode));
300 unsigned char* c = ((unsigned char*)pkt)+ntohs(pkt->addroffset);
301 unsigned char* k = (unsigned char*)&key;
302 new_ip6addr(c, &pkt->service_descr.peer, &pkt->service_descr.service_descriptor);
304 * Copy the newly generated ip-address to the key backwarts (as only the first part is hashed)
307 for (i = 0; i < 16; i++)
310 uint16_t namelen = strlen((char*)pkt->data+12)+1;
312 struct map_entry* value = GNUNET_malloc(sizeof(struct map_entry) + namelen);
313 char* name = (char*)(value +1);
315 value->namelen = namelen;
316 memcpy(name, pkt->data+12, namelen);
318 memcpy(&value->desc, &pkt->service_descr, sizeof(struct GNUNET_vpn_service_descriptor));
320 memset(value->additional_ports, 0, 8192);
322 memcpy(&value->hash, &key, sizeof(GNUNET_HashCode));
325 GNUNET_CONTAINER_multihashmap_contains (hashmap, &key))
327 GNUNET_CONTAINER_multihashmap_put (hashmap, &key, value,
328 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
330 value->heap_node = GNUNET_CONTAINER_heap_insert (heap, value,
331 GNUNET_TIME_absolute_get ().abs_value);
332 if (GNUNET_CONTAINER_heap_get_size(heap) > max_mappings)
333 GNUNET_SCHEDULER_add_now(collect_mappings, NULL);
339 list = GNUNET_malloc(htons(pkt->hdr.size) + 2*sizeof(struct answer_packet_list*));
341 memcpy(&list->pkt, pkt, htons(pkt->hdr.size));
344 else if (pkt->subtype == GNUNET_DNS_ANSWER_TYPE_REV)
347 memset(&key, 0, sizeof key);
348 unsigned char* k = (unsigned char*)&key;
349 unsigned char* s = pkt->data+12;
351 /* Whoever designed the reverse IPv6-lookup is batshit insane */
352 for (i = 0; i < 16; i++)
354 unsigned char c1 = s[(4*i)+1];
355 unsigned char c2 = s[(4*i)+3];
359 k[i] = c1 - 87; /* 87 is the difference between 'a' and 10 */
361 k[i] += 16*(c2 - '0');
363 k[i] += 16*(c2 - 87);
366 struct map_entry* map_entry = GNUNET_CONTAINER_multihashmap_get(hashmap, &key);
367 uint16_t offset = ntohs(pkt->addroffset);
369 if (map_entry == NULL)
375 GNUNET_CONTAINER_heap_update_cost (heap, map_entry->heap_node,
376 GNUNET_TIME_absolute_get ().abs_value);
379 unsigned short namelen = htons(map_entry->namelen);
380 char* name = (char*)(map_entry + 1);
382 list = GNUNET_malloc(2*sizeof(struct answer_packet_list*) + offset + 2 + ntohs(namelen));
384 struct answer_packet* rpkt = &list->pkt;
386 /* The offset points to the first byte belonging to the address */
387 memcpy(rpkt, pkt, offset - 1);
389 rpkt->subtype = GNUNET_DNS_ANSWER_TYPE_IP;
390 rpkt->hdr.size = ntohs(offset + 2 + ntohs(namelen));
392 memcpy(((char*)rpkt)+offset, &namelen, 2);
393 memcpy(((char*)rpkt)+offset+2, name, ntohs(namelen));
396 else if (pkt->subtype == GNUNET_DNS_ANSWER_TYPE_IP)
398 list = GNUNET_malloc(htons(pkt->hdr.size) + 2*sizeof(struct answer_packet_list*));
399 memcpy(&list->pkt, pkt, htons(pkt->hdr.size));
401 else if (pkt->subtype == GNUNET_DNS_ANSWER_TYPE_REMOTE)
403 pkt->subtype = GNUNET_DNS_ANSWER_TYPE_IP;
406 memset(&key, 0, sizeof(GNUNET_HashCode));
408 unsigned char* c = ((unsigned char*)pkt)+ntohs(pkt->addroffset);
409 new_ip6addr_remote(c, pkt->addr, pkt->addrsize);
410 unsigned char* k = (unsigned char*)&key;
412 * Copy the newly generated ip-address to the key backwards (as only the first part is used in the hash-table)
415 for (i = 0; i < 16; i++)
418 uint16_t namelen = strlen((char*)pkt->data+12)+1;
420 struct map_entry* value = GNUNET_malloc(sizeof(struct map_entry) + namelen);
421 char* name = (char*)(value +1);
423 value->namelen = namelen;
424 memcpy(name, pkt->data+12, namelen);
426 value->addrlen = pkt->addrsize;
427 memcpy(&value->addr, &pkt->addr, pkt->addrsize);
428 memset(value->additional_ports, 0, 8192);
430 memcpy(&value->hash, &key, sizeof(GNUNET_HashCode));
433 GNUNET_CONTAINER_multihashmap_contains (hashmap, &key))
435 GNUNET_CONTAINER_multihashmap_put (hashmap, &key, value,
436 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
437 value->heap_node = GNUNET_CONTAINER_heap_insert (heap, value,
438 GNUNET_TIME_absolute_get ().abs_value);
439 if (GNUNET_CONTAINER_heap_get_size(heap) > max_mappings)
440 GNUNET_SCHEDULER_add_now(collect_mappings, NULL);
445 list = GNUNET_malloc(htons(pkt->hdr.size) + 2*sizeof(struct answer_packet_list*));
447 memcpy(&list->pkt, pkt, htons(pkt->hdr.size));
458 GNUNET_CONTAINER_DLL_insert_after(answer_proc_head, answer_proc_tail, answer_proc_tail, list);
460 schedule_helper_write(GNUNET_TIME_UNIT_FOREVER_REL, NULL);
466 * Sets a bit active in a bitArray.
468 * @param bitArray memory area to set the bit in
469 * @param bitIdx which bit to set
472 setBit (char *bitArray, unsigned int bitIdx)
475 unsigned int targetBit;
477 arraySlot = bitIdx / 8;
478 targetBit = (1L << (bitIdx % 8));
479 bitArray[arraySlot] |= targetBit;
483 * Clears a bit from bitArray.
485 * @param bitArray memory area to set the bit in
486 * @param bitIdx which bit to unset
489 clearBit (char *bitArray, unsigned int bitIdx)
492 unsigned int targetBit;
495 targetBit = (1L << (bitIdx % 8));
496 bitArray[slot] = bitArray[slot] & (~targetBit);
500 * Checks if a bit is active in the bitArray
502 * @param bitArray memory area to set the bit in
503 * @param bitIdx which bit to test
504 * @return GNUNET_YES if the bit is set, GNUNET_NO if not.
507 testBit (char *bitArray, unsigned int bitIdx)
510 unsigned int targetBit;
513 targetBit = (1L << (bitIdx % 8));
514 if (bitArray[slot] & targetBit)
521 * @brief Add the port to the list of additional ports in the map_entry
523 * @param me the map_entry
524 * @param port the port in host-byte-order
527 add_additional_port (struct map_entry *me, uint16_t port)
529 setBit(me->additional_ports, port);
533 receive_udp_back (void *cls __attribute__((unused)), struct GNUNET_MESH_Tunnel* tunnel,
534 void **tunnel_ctx __attribute__((unused)),
535 const struct GNUNET_PeerIdentity *sender __attribute__((unused)),
536 const struct GNUNET_MessageHeader *message,
537 const struct GNUNET_TRANSPORT_ATS_Information *atsi __attribute__((unused)))
539 GNUNET_HashCode *desc = (GNUNET_HashCode *) (message + 1);
540 struct remote_addr* s = (struct remote_addr*)desc;
541 struct udp_pkt *pkt = (struct udp_pkt *) (desc + 1);
542 const struct GNUNET_PeerIdentity* other = GNUNET_MESH_get_peer(tunnel);
544 size_t size = sizeof(struct ip6_udp) + ntohs(pkt->len) - 1 - sizeof(struct udp_pkt);
546 struct ip6_udp* pkt6 = alloca(size);
548 GNUNET_assert(pkt6 != NULL);
550 if (ntohs(message->type) == GNUNET_MESSAGE_TYPE_SERVICE_UDP_BACK)
551 new_ip6addr(pkt6->ip6_hdr.sadr, &other->hashPubKey, desc);
553 new_ip6addr_remote(pkt6->ip6_hdr.sadr, s->addr, s->addrlen);
555 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Relaying calc:%d gnu:%d udp:%d bytes!\n", size, ntohs(message->size), ntohs(pkt->len));
557 pkt6->shdr.type = htons(GNUNET_MESSAGE_TYPE_VPN_HELPER);
558 pkt6->shdr.size = htons(size);
561 pkt6->tun.type = htons(0x86dd);
563 pkt6->ip6_hdr.version = 6;
564 pkt6->ip6_hdr.tclass_h = 0;
565 pkt6->ip6_hdr.tclass_l = 0;
566 pkt6->ip6_hdr.flowlbl = 0;
567 pkt6->ip6_hdr.paylgth = pkt->len;
568 pkt6->ip6_hdr.nxthdr = 0x11;
569 pkt6->ip6_hdr.hoplmt = 0xff;
573 GNUNET_assert(GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(cfg, "vpn", "IPV6ADDR", &ipv6addr));
574 inet_pton (AF_INET6, ipv6addr, pkt6->ip6_hdr.dadr);
575 GNUNET_free(ipv6addr);
577 memcpy(&pkt6->udp_hdr, pkt, ntohs(pkt->len));
579 GNUNET_HashCode* key = address_mapping_exists(pkt6->ip6_hdr.sadr);
580 GNUNET_assert (key != NULL);
582 struct map_entry *me = GNUNET_CONTAINER_multihashmap_get(hashmap, key);
583 GNUNET_CONTAINER_heap_update_cost (heap, me->heap_node,
584 GNUNET_TIME_absolute_get ().abs_value);
588 GNUNET_assert (me != NULL);
589 if (ntohs(message->type) == GNUNET_MESSAGE_TYPE_SERVICE_UDP_BACK)
591 GNUNET_assert (me->desc.service_type & htonl(GNUNET_DNS_SERVICE_TYPE_UDP));
592 if (!port_in_ports(me->desc.ports, pkt6->udp_hdr.spt) &&
593 !testBit(me->additional_ports, ntohs(pkt6->udp_hdr.spt))) {
594 add_additional_port(me, ntohs(pkt6->udp_hdr.spt));
598 pkt6->udp_hdr.crc = 0;
600 sum = calculate_checksum_update(sum, (uint16_t*)&pkt6->ip6_hdr.sadr, 16);
601 sum = calculate_checksum_update(sum, (uint16_t*)&pkt6->ip6_hdr.dadr, 16);
602 uint32_t tmp = (pkt6->udp_hdr.len & 0xffff);
603 sum = calculate_checksum_update(sum, (uint16_t*)&tmp, 4);
604 tmp = htons(((pkt6->ip6_hdr.nxthdr & 0x00ff)));
605 sum = calculate_checksum_update(sum, (uint16_t*)&tmp, 4);
607 sum = calculate_checksum_update(sum, (uint16_t*)&pkt6->udp_hdr, ntohs(pkt->len));
608 pkt6->udp_hdr.crc = calculate_checksum_end(sum);
610 write_to_helper(pkt6, size);
616 receive_tcp_back (void *cls __attribute__((unused)), struct GNUNET_MESH_Tunnel* tunnel,
617 void **tunnel_ctx __attribute__((unused)),
618 const struct GNUNET_PeerIdentity *sender __attribute__((unused)),
619 const struct GNUNET_MessageHeader *message,
620 const struct GNUNET_TRANSPORT_ATS_Information *atsi __attribute__((unused)))
622 GNUNET_HashCode *desc = (GNUNET_HashCode *) (message + 1);
623 struct remote_addr* s = (struct remote_addr*)desc;
624 struct tcp_pkt *pkt = (struct tcp_pkt *) (desc + 1);
625 const struct GNUNET_PeerIdentity* other = GNUNET_MESH_get_peer(tunnel);
627 size_t pktlen = ntohs(message->size) - sizeof(struct GNUNET_MessageHeader) - sizeof(GNUNET_HashCode);
628 size_t size = pktlen + sizeof(struct ip6_tcp) - 1;
630 struct ip6_tcp* pkt6 = alloca(size);
631 memset(pkt6, 0, size);
633 GNUNET_assert(pkt6 != NULL);
635 if (ntohs(message->type) == GNUNET_MESSAGE_TYPE_SERVICE_TCP_BACK)
636 new_ip6addr(pkt6->ip6_hdr.sadr, &other->hashPubKey, desc);
638 new_ip6addr_remote(pkt6->ip6_hdr.sadr, s->addr, s->addrlen);
640 pkt6->shdr.type = htons(GNUNET_MESSAGE_TYPE_VPN_HELPER);
641 pkt6->shdr.size = htons(size);
644 pkt6->tun.type = htons(0x86dd);
646 pkt6->ip6_hdr.version = 6;
647 pkt6->ip6_hdr.tclass_h = 0;
648 pkt6->ip6_hdr.tclass_l = 0;
649 pkt6->ip6_hdr.flowlbl = 0;
650 pkt6->ip6_hdr.paylgth = htons(pktlen);
651 pkt6->ip6_hdr.nxthdr = 0x06;
652 pkt6->ip6_hdr.hoplmt = 0xff;
656 GNUNET_assert(GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(cfg, "vpn", "IPV6ADDR", &ipv6addr));
657 inet_pton (AF_INET6, ipv6addr, pkt6->ip6_hdr.dadr);
658 GNUNET_free(ipv6addr);
660 memcpy(&pkt6->tcp_hdr, pkt, pktlen);
662 GNUNET_HashCode* key = address_mapping_exists(pkt6->ip6_hdr.sadr);
663 GNUNET_assert (key != NULL);
665 struct map_entry *me = GNUNET_CONTAINER_multihashmap_get(hashmap, key);
666 GNUNET_CONTAINER_heap_update_cost (heap, me->heap_node,
667 GNUNET_TIME_absolute_get ().abs_value);
671 GNUNET_assert (me != NULL);
672 if (ntohs(message->type) == GNUNET_MESSAGE_TYPE_SERVICE_UDP_BACK)
673 GNUNET_assert (me->desc.service_type & htonl(GNUNET_DNS_SERVICE_TYPE_TCP));
675 pkt6->tcp_hdr.crc = 0;
679 calculate_checksum_update (sum, (uint16_t *) & pkt6->ip6_hdr.sadr, 16);
681 calculate_checksum_update (sum, (uint16_t *) & pkt6->ip6_hdr.dadr, 16);
683 sum = calculate_checksum_update (sum, (uint16_t *) & tmp, 4);
684 tmp = htonl (((pkt6->ip6_hdr.nxthdr & 0x000000ff)));
685 sum = calculate_checksum_update (sum, (uint16_t *) & tmp, 4);
688 calculate_checksum_update (sum, (uint16_t *) & pkt6->tcp_hdr,
689 ntohs (pkt6->ip6_hdr.paylgth));
690 pkt6->tcp_hdr.crc = calculate_checksum_end (sum);
692 write_to_helper(pkt6, size);
698 * Main function that will be run by the scheduler.
701 * @param args remaining command-line arguments
702 * @param cfgfile name of the configuration file used (for saving, can be NULL!)
703 * @param cfg_ configuration
707 char *const *args __attribute__((unused)),
708 const char *cfgfilep __attribute__((unused)),
709 const struct GNUNET_CONFIGURATION_Handle *cfg_)
711 static const struct GNUNET_MESH_MessageHandler handlers[] = {
712 {receive_udp_back, GNUNET_MESSAGE_TYPE_SERVICE_UDP_BACK, 0},
713 {receive_tcp_back, GNUNET_MESSAGE_TYPE_SERVICE_TCP_BACK, 0},
714 {receive_udp_back, GNUNET_MESSAGE_TYPE_REMOTE_UDP_BACK, 0},
715 {receive_tcp_back, GNUNET_MESSAGE_TYPE_REMOTE_TCP_BACK, 0},
719 static const GNUNET_MESH_ApplicationType types[] = {
720 GNUNET_APPLICATION_TYPE_END
723 mesh_handle = GNUNET_MESH_connect(cfg_,
730 hashmap = GNUNET_CONTAINER_multihashmap_create(65536);
731 heap = GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN);
732 GNUNET_CONFIGURATION_get_value_number (cfg, "vpn", "MAX_MAPPINGg",
734 udp_connections = GNUNET_CONTAINER_multihashmap_create(65536);
735 GNUNET_SCHEDULER_TaskIdentifier conn_task = GNUNET_SCHEDULER_add_now (connect_to_service_dns, NULL);
736 GNUNET_SCHEDULER_add_after (conn_task, start_helper_and_schedule, NULL);
737 GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_FOREVER_REL, &cleanup, cls);
741 * The main function to obtain template from gnunetd.
743 * @param argc number of arguments from the command line
744 * @param argv command line arguments
745 * @return 0 ok, 1 on error
748 main (int argc, char *const *argv) {
749 static const struct GNUNET_GETOPT_CommandLineOption options[] = {
750 GNUNET_GETOPT_OPTION_END
754 GNUNET_PROGRAM_run (argc,
757 gettext_noop ("help text"),
758 options, &run, NULL)) ? ret : 1;
761 /* end of gnunet-daemon-vpn.c */