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 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Setting addrlen to %d\n", pkt->addrsize);
427 value->addrlen = pkt->addrsize;
428 memcpy(&value->addr, &pkt->addr, pkt->addrsize);
429 memset(value->additional_ports, 0, 8192);
431 memcpy(&value->hash, &key, sizeof(GNUNET_HashCode));
434 GNUNET_CONTAINER_multihashmap_contains (hashmap, &key))
436 GNUNET_CONTAINER_multihashmap_put (hashmap, &key, value,
437 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
438 value->heap_node = GNUNET_CONTAINER_heap_insert (heap, value,
439 GNUNET_TIME_absolute_get ().abs_value);
440 if (GNUNET_CONTAINER_heap_get_size(heap) > max_mappings)
441 GNUNET_SCHEDULER_add_now(collect_mappings, NULL);
446 list = GNUNET_malloc(htons(pkt->hdr.size) + 2*sizeof(struct answer_packet_list*));
448 memcpy(&list->pkt, pkt, htons(pkt->hdr.size));
459 GNUNET_CONTAINER_DLL_insert_after(answer_proc_head, answer_proc_tail, answer_proc_tail, list);
461 schedule_helper_write(GNUNET_TIME_UNIT_FOREVER_REL, NULL);
467 * Sets a bit active in a bitArray.
469 * @param bitArray memory area to set the bit in
470 * @param bitIdx which bit to set
473 setBit (char *bitArray, unsigned int bitIdx)
476 unsigned int targetBit;
478 arraySlot = bitIdx / 8;
479 targetBit = (1L << (bitIdx % 8));
480 bitArray[arraySlot] |= targetBit;
484 * Clears a bit from bitArray.
486 * @param bitArray memory area to set the bit in
487 * @param bitIdx which bit to unset
490 clearBit (char *bitArray, unsigned int bitIdx)
493 unsigned int targetBit;
496 targetBit = (1L << (bitIdx % 8));
497 bitArray[slot] = bitArray[slot] & (~targetBit);
501 * Checks if a bit is active in the bitArray
503 * @param bitArray memory area to set the bit in
504 * @param bitIdx which bit to test
505 * @return GNUNET_YES if the bit is set, GNUNET_NO if not.
508 testBit (char *bitArray, unsigned int bitIdx)
511 unsigned int targetBit;
514 targetBit = (1L << (bitIdx % 8));
515 if (bitArray[slot] & targetBit)
522 * @brief Add the port to the list of additional ports in the map_entry
524 * @param me the map_entry
525 * @param port the port in host-byte-order
528 add_additional_port (struct map_entry *me, uint16_t port)
530 setBit(me->additional_ports, port);
534 receive_udp_back (void *cls __attribute__((unused)), struct GNUNET_MESH_Tunnel* tunnel,
535 void **tunnel_ctx __attribute__((unused)),
536 const struct GNUNET_PeerIdentity *sender __attribute__((unused)),
537 const struct GNUNET_MessageHeader *message,
538 const struct GNUNET_TRANSPORT_ATS_Information *atsi __attribute__((unused)))
540 GNUNET_HashCode *desc = (GNUNET_HashCode *) (message + 1);
541 struct remote_addr* s = (struct remote_addr*)desc;
542 struct udp_pkt *pkt = (struct udp_pkt *) (desc + 1);
543 const struct GNUNET_PeerIdentity* other = GNUNET_MESH_get_peer(tunnel);
545 size_t size = sizeof(struct ip6_udp) + ntohs(pkt->len) - 1 - sizeof(struct udp_pkt);
547 struct ip6_udp* pkt6 = alloca(size);
549 GNUNET_assert(pkt6 != NULL);
551 if (ntohs(message->type) == GNUNET_MESSAGE_TYPE_SERVICE_UDP_BACK)
552 new_ip6addr(pkt6->ip6_hdr.sadr, &other->hashPubKey, desc);
554 new_ip6addr_remote(pkt6->ip6_hdr.sadr, s->addr, s->addrlen);
556 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Relaying calc:%d gnu:%d udp:%d bytes!\n", size, ntohs(message->size), ntohs(pkt->len));
558 pkt6->shdr.type = htons(GNUNET_MESSAGE_TYPE_VPN_HELPER);
559 pkt6->shdr.size = htons(size);
562 pkt6->tun.type = htons(0x86dd);
564 pkt6->ip6_hdr.version = 6;
565 pkt6->ip6_hdr.tclass_h = 0;
566 pkt6->ip6_hdr.tclass_l = 0;
567 pkt6->ip6_hdr.flowlbl = 0;
568 pkt6->ip6_hdr.paylgth = pkt->len;
569 pkt6->ip6_hdr.nxthdr = 0x11;
570 pkt6->ip6_hdr.hoplmt = 0xff;
574 GNUNET_assert(GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(cfg, "vpn", "IPV6ADDR", &ipv6addr));
575 inet_pton (AF_INET6, ipv6addr, pkt6->ip6_hdr.dadr);
576 GNUNET_free(ipv6addr);
578 memcpy(&pkt6->udp_hdr, pkt, ntohs(pkt->len));
580 GNUNET_HashCode* key = address_mapping_exists(pkt6->ip6_hdr.sadr);
581 GNUNET_assert (key != NULL);
583 struct map_entry *me = GNUNET_CONTAINER_multihashmap_get(hashmap, key);
584 GNUNET_CONTAINER_heap_update_cost (heap, me->heap_node,
585 GNUNET_TIME_absolute_get ().abs_value);
589 GNUNET_assert (me != NULL);
590 if (ntohs(message->type) == GNUNET_MESSAGE_TYPE_SERVICE_UDP_BACK)
592 GNUNET_assert (me->desc.service_type & htonl(GNUNET_DNS_SERVICE_TYPE_UDP));
593 if (!port_in_ports(me->desc.ports, pkt6->udp_hdr.spt) &&
594 !testBit(me->additional_ports, ntohs(pkt6->udp_hdr.spt))) {
595 add_additional_port(me, ntohs(pkt6->udp_hdr.spt));
599 pkt6->udp_hdr.crc = 0;
601 sum = calculate_checksum_update(sum, (uint16_t*)&pkt6->ip6_hdr.sadr, 16);
602 sum = calculate_checksum_update(sum, (uint16_t*)&pkt6->ip6_hdr.dadr, 16);
603 uint32_t tmp = (pkt6->udp_hdr.len & 0xffff);
604 sum = calculate_checksum_update(sum, (uint16_t*)&tmp, 4);
605 tmp = htons(((pkt6->ip6_hdr.nxthdr & 0x00ff)));
606 sum = calculate_checksum_update(sum, (uint16_t*)&tmp, 4);
608 sum = calculate_checksum_update(sum, (uint16_t*)&pkt6->udp_hdr, ntohs(pkt->len));
609 pkt6->udp_hdr.crc = calculate_checksum_end(sum);
611 write_to_helper(pkt6, size);
617 receive_tcp_back (void *cls __attribute__((unused)), struct GNUNET_MESH_Tunnel* tunnel,
618 void **tunnel_ctx __attribute__((unused)),
619 const struct GNUNET_PeerIdentity *sender __attribute__((unused)),
620 const struct GNUNET_MessageHeader *message,
621 const struct GNUNET_TRANSPORT_ATS_Information *atsi __attribute__((unused)))
623 GNUNET_HashCode *desc = (GNUNET_HashCode *) (message + 1);
624 struct remote_addr* s = (struct remote_addr*)desc;
625 struct tcp_pkt *pkt = (struct tcp_pkt *) (desc + 1);
626 const struct GNUNET_PeerIdentity* other = GNUNET_MESH_get_peer(tunnel);
628 size_t pktlen = ntohs(message->size) - sizeof(struct GNUNET_MessageHeader) - sizeof(GNUNET_HashCode);
629 size_t size = pktlen + sizeof(struct ip6_tcp) - 1;
631 struct ip6_tcp* pkt6 = alloca(size);
632 memset(pkt6, 0, size);
634 GNUNET_assert(pkt6 != NULL);
636 if (ntohs(message->type) == GNUNET_MESSAGE_TYPE_SERVICE_TCP_BACK)
637 new_ip6addr(pkt6->ip6_hdr.sadr, &other->hashPubKey, desc);
639 new_ip6addr_remote(pkt6->ip6_hdr.sadr, s->addr, s->addrlen);
641 pkt6->shdr.type = htons(GNUNET_MESSAGE_TYPE_VPN_HELPER);
642 pkt6->shdr.size = htons(size);
645 pkt6->tun.type = htons(0x86dd);
647 pkt6->ip6_hdr.version = 6;
648 pkt6->ip6_hdr.tclass_h = 0;
649 pkt6->ip6_hdr.tclass_l = 0;
650 pkt6->ip6_hdr.flowlbl = 0;
651 pkt6->ip6_hdr.paylgth = htons(pktlen);
652 pkt6->ip6_hdr.nxthdr = 0x06;
653 pkt6->ip6_hdr.hoplmt = 0xff;
657 GNUNET_assert(GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(cfg, "vpn", "IPV6ADDR", &ipv6addr));
658 inet_pton (AF_INET6, ipv6addr, pkt6->ip6_hdr.dadr);
659 GNUNET_free(ipv6addr);
661 memcpy(&pkt6->tcp_hdr, pkt, pktlen);
663 GNUNET_HashCode* key = address_mapping_exists(pkt6->ip6_hdr.sadr);
664 GNUNET_assert (key != NULL);
666 struct map_entry *me = GNUNET_CONTAINER_multihashmap_get(hashmap, key);
667 GNUNET_CONTAINER_heap_update_cost (heap, me->heap_node,
668 GNUNET_TIME_absolute_get ().abs_value);
672 GNUNET_assert (me != NULL);
673 if (ntohs(message->type) == GNUNET_MESSAGE_TYPE_SERVICE_UDP_BACK)
674 GNUNET_assert (me->desc.service_type & htonl(GNUNET_DNS_SERVICE_TYPE_TCP));
676 pkt6->tcp_hdr.crc = 0;
680 calculate_checksum_update (sum, (uint16_t *) & pkt6->ip6_hdr.sadr, 16);
682 calculate_checksum_update (sum, (uint16_t *) & pkt6->ip6_hdr.dadr, 16);
684 sum = calculate_checksum_update (sum, (uint16_t *) & tmp, 4);
685 tmp = htonl (((pkt6->ip6_hdr.nxthdr & 0x000000ff)));
686 sum = calculate_checksum_update (sum, (uint16_t *) & tmp, 4);
689 calculate_checksum_update (sum, (uint16_t *) & pkt6->tcp_hdr,
690 ntohs (pkt6->ip6_hdr.paylgth));
691 pkt6->tcp_hdr.crc = calculate_checksum_end (sum);
693 write_to_helper(pkt6, size);
699 * Main function that will be run by the scheduler.
702 * @param args remaining command-line arguments
703 * @param cfgfile name of the configuration file used (for saving, can be NULL!)
704 * @param cfg_ configuration
708 char *const *args __attribute__((unused)),
709 const char *cfgfilep __attribute__((unused)),
710 const struct GNUNET_CONFIGURATION_Handle *cfg_)
712 static const struct GNUNET_MESH_MessageHandler handlers[] = {
713 {receive_udp_back, GNUNET_MESSAGE_TYPE_SERVICE_UDP_BACK, 0},
714 {receive_tcp_back, GNUNET_MESSAGE_TYPE_SERVICE_TCP_BACK, 0},
715 {receive_udp_back, GNUNET_MESSAGE_TYPE_REMOTE_UDP_BACK, 0},
716 {receive_tcp_back, GNUNET_MESSAGE_TYPE_REMOTE_TCP_BACK, 0},
720 static const GNUNET_MESH_ApplicationType types[] = {
721 GNUNET_APPLICATION_TYPE_END
724 mesh_handle = GNUNET_MESH_connect(cfg_,
731 hashmap = GNUNET_CONTAINER_multihashmap_create(65536);
732 heap = GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN);
733 GNUNET_CONFIGURATION_get_value_number (cfg, "vpn", "MAX_MAPPINGg",
735 udp_connections = GNUNET_CONTAINER_multihashmap_create(65536);
736 GNUNET_SCHEDULER_TaskIdentifier conn_task = GNUNET_SCHEDULER_add_now (connect_to_service_dns, NULL);
737 GNUNET_SCHEDULER_add_after (conn_task, start_helper_and_schedule, NULL);
738 GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_FOREVER_REL, &cleanup, cls);
742 * The main function to obtain template from gnunetd.
744 * @param argc number of arguments from the command line
745 * @param argv command line arguments
746 * @return 0 ok, 1 on error
749 main (int argc, char *const *argv) {
750 static const struct GNUNET_GETOPT_CommandLineOption options[] = {
751 GNUNET_GETOPT_OPTION_END
755 GNUNET_PROGRAM_run (argc,
758 gettext_noop ("help text"),
759 options, &run, NULL)) ? ret : 1;
762 /* end of gnunet-daemon-vpn.c */