aboutsummaryrefslogtreecommitdiff
path: root/src/vpn
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2019-07-17 10:50:45 +0200
committerChristian Grothoff <christian@grothoff.org>2019-07-17 10:50:45 +0200
commita7ccf828ae4f7e306ffe3e7efebc0e678615f6c5 (patch)
tree71489a2649bb3c9100fccc19d135d832d3cbea05 /src/vpn
parent963c4fe2e94208a251b269e3a6918a71e8de1939 (diff)
downloadgnunet-a7ccf828ae4f7e306ffe3e7efebc0e678615f6c5.tar.gz
gnunet-a7ccf828ae4f7e306ffe3e7efebc0e678615f6c5.zip
remove duplication MQ options, make conversation build
Diffstat (limited to 'src/vpn')
-rw-r--r--src/vpn/gnunet-service-vpn.c2466
1 files changed, 1212 insertions, 1254 deletions
diff --git a/src/vpn/gnunet-service-vpn.c b/src/vpn/gnunet-service-vpn.c
index 7bd26798e..e2d8a8e50 100644
--- a/src/vpn/gnunet-service-vpn.c
+++ b/src/vpn/gnunet-service-vpn.c
@@ -11,7 +11,7 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
@@ -87,7 +87,6 @@ struct DestinationChannel
87 * Destination port this channel state is used for. 87 * Destination port this channel state is used for.
88 */ 88 */
89 uint16_t destination_port; 89 uint16_t destination_port;
90
91}; 90};
92 91
93 92
@@ -158,21 +157,20 @@ struct DestinationEntry
158 */ 157 */
159 union 158 union
160 { 159 {
161 /** 160 /**
162 * Address if af is AF_INET. 161 * Address if af is AF_INET.
163 */ 162 */
164 struct in_addr v4; 163 struct in_addr v4;
165 164
166 /** 165 /**
167 * Address if af is AF_INET6. 166 * Address if af is AF_INET6.
168 */ 167 */
169 struct in6_addr v6; 168 struct in6_addr v6;
170 } ip; 169 } ip;
171 170
172 } exit_destination; 171 } exit_destination;
173 172
174 } details; 173 } details;
175
176}; 174};
177 175
178 176
@@ -309,7 +307,6 @@ struct ChannelState
309 * Destination port used by the sender on our end; 0 for uninitialized. 307 * Destination port used by the sender on our end; 0 for uninitialized.
310 */ 308 */
311 uint16_t destination_port; 309 uint16_t destination_port;
312
313}; 310};
314 311
315 312
@@ -394,20 +391,16 @@ static unsigned long long max_channel_mappings;
394 */ 391 */
395static void 392static void
396get_destination_key_from_ip (int af, 393get_destination_key_from_ip (int af,
397 const void *address, 394 const void *address,
398 struct GNUNET_HashCode *key) 395 struct GNUNET_HashCode *key)
399{ 396{
400 switch (af) 397 switch (af)
401 { 398 {
402 case AF_INET: 399 case AF_INET:
403 GNUNET_CRYPTO_hash (address, 400 GNUNET_CRYPTO_hash (address, sizeof (struct in_addr), key);
404 sizeof (struct in_addr),
405 key);
406 break; 401 break;
407 case AF_INET6: 402 case AF_INET6:
408 GNUNET_CRYPTO_hash (address, 403 GNUNET_CRYPTO_hash (address, sizeof (struct in6_addr), key);
409 sizeof (struct in6_addr),
410 key);
411 break; 404 break;
412 default: 405 default:
413 GNUNET_assert (0); 406 GNUNET_assert (0);
@@ -442,7 +435,7 @@ get_channel_key_from_ips (int af,
442 memset (key, 0, sizeof (struct GNUNET_HashCode)); 435 memset (key, 0, sizeof (struct GNUNET_HashCode));
443 /* the GNUnet hashmap only uses the first sizeof(unsigned int) of the hash, 436 /* the GNUnet hashmap only uses the first sizeof(unsigned int) of the hash,
444 so we put the ports in there (and hope for few collisions) */ 437 so we put the ports in there (and hope for few collisions) */
445 off = (char*) key; 438 off = (char *) key;
446 GNUNET_memcpy (off, &source_port, sizeof (uint16_t)); 439 GNUNET_memcpy (off, &source_port, sizeof (uint16_t));
447 off += sizeof (uint16_t); 440 off += sizeof (uint16_t);
448 GNUNET_memcpy (off, &destination_port, sizeof (uint16_t)); 441 GNUNET_memcpy (off, &destination_port, sizeof (uint16_t));
@@ -480,9 +473,9 @@ get_channel_key_from_ips (int af,
480 */ 473 */
481static void 474static void
482send_client_reply (struct GNUNET_SERVICE_Client *client, 475send_client_reply (struct GNUNET_SERVICE_Client *client,
483 uint64_t request_id, 476 uint64_t request_id,
484 int result_af, 477 int result_af,
485 const void *addr) 478 const void *addr)
486{ 479{
487 struct GNUNET_MQ_Envelope *env; 480 struct GNUNET_MQ_Envelope *env;
488 struct RedirectToIpResponseMessage *res; 481 struct RedirectToIpResponseMessage *res;
@@ -503,16 +496,11 @@ send_client_reply (struct GNUNET_SERVICE_Client *client,
503 GNUNET_assert (0); 496 GNUNET_assert (0);
504 return; 497 return;
505 } 498 }
506 env = GNUNET_MQ_msg_extra (res, 499 env = GNUNET_MQ_msg_extra (res, rlen, GNUNET_MESSAGE_TYPE_VPN_CLIENT_USE_IP);
507 rlen,
508 GNUNET_MESSAGE_TYPE_VPN_CLIENT_USE_IP);
509 res->result_af = htonl (result_af); 500 res->result_af = htonl (result_af);
510 res->request_id = request_id; 501 res->request_id = request_id;
511 GNUNET_memcpy (&res[1], 502 GNUNET_memcpy (&res[1], addr, rlen);
512 addr, 503 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), env);
513 rlen);
514 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client),
515 env);
516} 504}
517 505
518 506
@@ -528,8 +516,7 @@ free_channel_state (struct ChannelState *ts)
528 struct ChannelMessageQueueEntry *tnq; 516 struct ChannelMessageQueueEntry *tnq;
529 struct GNUNET_CADET_Channel *channel; 517 struct GNUNET_CADET_Channel *channel;
530 518
531 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 519 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Cleaning up channel state\n");
532 "Cleaning up channel state\n");
533 if (NULL != (channel = ts->channel)) 520 if (NULL != (channel = ts->channel))
534 { 521 {
535 ts->channel = NULL; 522 ts->channel = NULL;
@@ -537,13 +524,12 @@ free_channel_state (struct ChannelState *ts)
537 return; 524 return;
538 } 525 }
539 GNUNET_STATISTICS_update (stats, 526 GNUNET_STATISTICS_update (stats,
540 gettext_noop ("# Active channels"), 527 gettext_noop ("# Active channels"),
541 -1, GNUNET_NO); 528 -1,
529 GNUNET_NO);
542 while (NULL != (tnq = ts->tmq_head)) 530 while (NULL != (tnq = ts->tmq_head))
543 { 531 {
544 GNUNET_CONTAINER_DLL_remove (ts->tmq_head, 532 GNUNET_CONTAINER_DLL_remove (ts->tmq_head, ts->tmq_tail, tnq);
545 ts->tmq_tail,
546 tnq);
547 ts->tmq_length--; 533 ts->tmq_length--;
548 GNUNET_free (tnq); 534 GNUNET_free (tnq);
549 } 535 }
@@ -559,16 +545,15 @@ free_channel_state (struct ChannelState *ts)
559 GNUNET_CONTAINER_heap_remove_node (ts->heap_node); 545 GNUNET_CONTAINER_heap_remove_node (ts->heap_node);
560 ts->heap_node = NULL; 546 ts->heap_node = NULL;
561 get_channel_key_from_ips (ts->af, 547 get_channel_key_from_ips (ts->af,
562 ts->protocol, 548 ts->protocol,
563 &ts->source_ip, 549 &ts->source_ip,
564 ts->source_port, 550 ts->source_port,
565 &ts->destination_ip, 551 &ts->destination_ip,
566 ts->destination_port, 552 ts->destination_port,
567 &key); 553 &key);
568 GNUNET_assert (GNUNET_YES == 554 GNUNET_assert (
569 GNUNET_CONTAINER_multihashmap_remove (channel_map, 555 GNUNET_YES ==
570 &key, 556 GNUNET_CONTAINER_multihashmap_remove (channel_map, &key, ts));
571 ts));
572 } 557 }
573 GNUNET_free (ts); 558 GNUNET_free (ts);
574} 559}
@@ -582,25 +567,25 @@ free_channel_state (struct ChannelState *ts)
582 * @param env message to queue 567 * @param env message to queue
583 */ 568 */
584static void 569static void
585send_to_channel (struct ChannelState *ts, 570send_to_channel (struct ChannelState *ts, struct GNUNET_MQ_Envelope *env)
586 struct GNUNET_MQ_Envelope *env)
587{ 571{
588 struct GNUNET_MQ_Handle *mq; 572 struct GNUNET_MQ_Handle *mq;
589 573
590 GNUNET_assert (NULL != ts->channel); 574 GNUNET_assert (NULL != ts->channel);
591 mq = GNUNET_CADET_get_mq (ts->channel); 575 mq = GNUNET_CADET_get_mq (ts->channel);
592 GNUNET_MQ_env_set_options(env, 576 GNUNET_MQ_env_set_options (env,
593 GNUNET_MQ_PREF_DEFAULT); 577 GNUNET_MQ_PRIO_BEST_EFFORT |
594 GNUNET_MQ_send (mq, 578 GNUNET_MQ_PREF_OUT_OF_ORDER);
595 env); 579 GNUNET_MQ_send (mq, env);
596 if (GNUNET_MQ_get_length (mq) > MAX_MESSAGE_QUEUE_SIZE) 580 if (GNUNET_MQ_get_length (mq) > MAX_MESSAGE_QUEUE_SIZE)
597 { 581 {
598 env = GNUNET_MQ_unsent_head (mq); 582 env = GNUNET_MQ_unsent_head (mq);
599 GNUNET_assert (NULL != env); 583 GNUNET_assert (NULL != env);
600 GNUNET_STATISTICS_update (stats, 584 GNUNET_STATISTICS_update (stats,
601 gettext_noop ("# Messages dropped in cadet queue (overflow)"), 585 gettext_noop (
602 1, 586 "# Messages dropped in cadet queue (overflow)"),
603 GNUNET_NO); 587 1,
588 GNUNET_NO);
604 GNUNET_MQ_discard (env); 589 GNUNET_MQ_discard (env);
605 } 590 }
606} 591}
@@ -623,7 +608,8 @@ print_channel_destination (const struct DestinationEntry *de)
623 sizeof (dest), 608 sizeof (dest),
624 "HS: %s-%s", 609 "HS: %s-%s",
625 GNUNET_i2s (&de->details.service_destination.target), 610 GNUNET_i2s (&de->details.service_destination.target),
626 GNUNET_h2s (&de->details.service_destination.service_descriptor)); 611 GNUNET_h2s (
612 &de->details.service_destination.service_descriptor));
627 } 613 }
628 else 614 else
629 { 615 {
@@ -644,14 +630,14 @@ print_channel_destination (const struct DestinationEntry *de)
644 * @param channel connection to the other end (henceforth invalid) 630 * @param channel connection to the other end (henceforth invalid)
645 */ 631 */
646static void 632static void
647channel_cleaner (void *cls, 633channel_cleaner (void *cls, const struct GNUNET_CADET_Channel *channel)
648 const struct GNUNET_CADET_Channel *channel)
649{ 634{
650 struct ChannelState *ts = cls; 635 struct ChannelState *ts = cls;
651 636
652 ts->channel = NULL; /* we must not call GNUNET_CADET_channel_destroy() anymore */ 637 ts->channel =
638 NULL; /* we must not call GNUNET_CADET_channel_destroy() anymore */
653 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 639 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
654 "CADET notified us about death of channel to `%s'\n", 640 "CADET notified us about death of channel to `%s'\n",
655 print_channel_destination (&ts->destination)); 641 print_channel_destination (&ts->destination));
656 free_channel_state (ts); 642 free_channel_state (ts);
657} 643}
@@ -668,14 +654,14 @@ channel_cleaner (void *cls,
668 */ 654 */
669static void 655static void
670make_up_icmpv4_payload (struct ChannelState *ts, 656make_up_icmpv4_payload (struct ChannelState *ts,
671 struct GNUNET_TUN_IPv4Header *ipp, 657 struct GNUNET_TUN_IPv4Header *ipp,
672 struct GNUNET_TUN_UdpHeader *udp) 658 struct GNUNET_TUN_UdpHeader *udp)
673{ 659{
674 GNUNET_TUN_initialize_ipv4_header (ipp, 660 GNUNET_TUN_initialize_ipv4_header (ipp,
675 ts->protocol, 661 ts->protocol,
676 sizeof (struct GNUNET_TUN_TcpHeader), 662 sizeof (struct GNUNET_TUN_TcpHeader),
677 &ts->source_ip.v4, 663 &ts->source_ip.v4,
678 &ts->destination_ip.v4); 664 &ts->destination_ip.v4);
679 udp->source_port = htons (ts->source_port); 665 udp->source_port = htons (ts->source_port);
680 udp->destination_port = htons (ts->destination_port); 666 udp->destination_port = htons (ts->destination_port);
681 udp->len = htons (0); 667 udp->len = htons (0);
@@ -694,14 +680,14 @@ make_up_icmpv4_payload (struct ChannelState *ts,
694 */ 680 */
695static void 681static void
696make_up_icmpv6_payload (struct ChannelState *ts, 682make_up_icmpv6_payload (struct ChannelState *ts,
697 struct GNUNET_TUN_IPv6Header *ipp, 683 struct GNUNET_TUN_IPv6Header *ipp,
698 struct GNUNET_TUN_UdpHeader *udp) 684 struct GNUNET_TUN_UdpHeader *udp)
699{ 685{
700 GNUNET_TUN_initialize_ipv6_header (ipp, 686 GNUNET_TUN_initialize_ipv6_header (ipp,
701 ts->protocol, 687 ts->protocol,
702 sizeof (struct GNUNET_TUN_TcpHeader), 688 sizeof (struct GNUNET_TUN_TcpHeader),
703 &ts->source_ip.v6, 689 &ts->source_ip.v6,
704 &ts->destination_ip.v6); 690 &ts->destination_ip.v6);
705 udp->source_port = htons (ts->source_port); 691 udp->source_port = htons (ts->source_port);
706 udp->destination_port = htons (ts->destination_port); 692 udp->destination_port = htons (ts->destination_port);
707 udp->len = htons (0); 693 udp->len = htons (0);
@@ -718,8 +704,7 @@ make_up_icmpv6_payload (struct ChannelState *ts,
718 * #GNUNET_SYSERR to close it (signal serious error) 704 * #GNUNET_SYSERR to close it (signal serious error)
719 */ 705 */
720static int 706static int
721check_icmp_back (void *cls, 707check_icmp_back (void *cls, const struct GNUNET_EXIT_IcmpToVPNMessage *i2v)
722 const struct GNUNET_EXIT_IcmpToVPNMessage *i2v)
723{ 708{
724 struct ChannelState *ts = cls; 709 struct ChannelState *ts = cls;
725 710
@@ -745,309 +730,323 @@ check_icmp_back (void *cls,
745 * @param message the actual message 730 * @param message the actual message
746 */ 731 */
747static void 732static void
748handle_icmp_back (void *cls, 733handle_icmp_back (void *cls, const struct GNUNET_EXIT_IcmpToVPNMessage *i2v)
749 const struct GNUNET_EXIT_IcmpToVPNMessage *i2v)
750{ 734{
751 struct ChannelState *ts = cls; 735 struct ChannelState *ts = cls;
752 size_t mlen; 736 size_t mlen;
753 737
754 GNUNET_STATISTICS_update (stats, 738 GNUNET_STATISTICS_update (stats,
755 gettext_noop ("# ICMP packets received from cadet"), 739 gettext_noop ("# ICMP packets received from cadet"),
756 1, 740 1,
757 GNUNET_NO); 741 GNUNET_NO);
758 mlen = ntohs (i2v->header.size) - sizeof (struct GNUNET_EXIT_IcmpToVPNMessage); 742 mlen =
743 ntohs (i2v->header.size) - sizeof (struct GNUNET_EXIT_IcmpToVPNMessage);
759 { 744 {
760 char sbuf[INET6_ADDRSTRLEN]; 745 char sbuf[INET6_ADDRSTRLEN];
761 char dbuf[INET6_ADDRSTRLEN]; 746 char dbuf[INET6_ADDRSTRLEN];
762 747
763 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 748 GNUNET_log (
764 "Received ICMP packet from cadet, sending %u bytes from %s -> %s via TUN\n", 749 GNUNET_ERROR_TYPE_DEBUG,
765 (unsigned int) mlen, 750 "Received ICMP packet from cadet, sending %u bytes from %s -> %s via TUN\n",
766 inet_ntop (ts->af, &ts->destination_ip, sbuf, sizeof (sbuf)), 751 (unsigned int) mlen,
767 inet_ntop (ts->af, &ts->source_ip, dbuf, sizeof (dbuf))); 752 inet_ntop (ts->af, &ts->destination_ip, sbuf, sizeof (sbuf)),
753 inet_ntop (ts->af, &ts->source_ip, dbuf, sizeof (dbuf)));
768 } 754 }
769 switch (ts->af) 755 switch (ts->af)
770 { 756 {
771 case AF_INET: 757 case AF_INET: {
758 size_t size = sizeof (struct GNUNET_TUN_IPv4Header) +
759 sizeof (struct GNUNET_TUN_IcmpHeader) +
760 sizeof (struct GNUNET_MessageHeader) +
761 sizeof (struct GNUNET_TUN_Layer2PacketHeader) + mlen;
772 { 762 {
773 size_t size = sizeof (struct GNUNET_TUN_IPv4Header) 763 /* reserve some extra space in case we have an ICMP type here where
774 + sizeof (struct GNUNET_TUN_IcmpHeader)
775 + sizeof (struct GNUNET_MessageHeader) +
776 sizeof (struct GNUNET_TUN_Layer2PacketHeader) +
777 mlen;
778 {
779 /* reserve some extra space in case we have an ICMP type here where
780 we will need to make up the payload ourselves */ 764 we will need to make up the payload ourselves */
781 char buf[size + sizeof (struct GNUNET_TUN_IPv4Header) + 8] GNUNET_ALIGN; 765 char buf[size + sizeof (struct GNUNET_TUN_IPv4Header) + 8] GNUNET_ALIGN;
782 struct GNUNET_MessageHeader *msg = (struct GNUNET_MessageHeader *) buf; 766 struct GNUNET_MessageHeader *msg = (struct GNUNET_MessageHeader *) buf;
783 struct GNUNET_TUN_Layer2PacketHeader *tun = (struct GNUNET_TUN_Layer2PacketHeader*) &msg[1]; 767 struct GNUNET_TUN_Layer2PacketHeader *tun =
784 struct GNUNET_TUN_IPv4Header *ipv4 = (struct GNUNET_TUN_IPv4Header *) &tun[1]; 768 (struct GNUNET_TUN_Layer2PacketHeader *) &msg[1];
785 struct GNUNET_TUN_IcmpHeader *icmp = (struct GNUNET_TUN_IcmpHeader *) &ipv4[1]; 769 struct GNUNET_TUN_IPv4Header *ipv4 =
786 msg->type = htons (GNUNET_MESSAGE_TYPE_VPN_HELPER); 770 (struct GNUNET_TUN_IPv4Header *) &tun[1];
787 tun->flags = htons (0); 771 struct GNUNET_TUN_IcmpHeader *icmp =
788 tun->proto = htons (ETH_P_IPV4); 772 (struct GNUNET_TUN_IcmpHeader *) &ipv4[1];
789 GNUNET_TUN_initialize_ipv4_header (ipv4, 773 msg->type = htons (GNUNET_MESSAGE_TYPE_VPN_HELPER);
790 IPPROTO_ICMP, 774 tun->flags = htons (0);
791 sizeof (struct GNUNET_TUN_IcmpHeader) + mlen, 775 tun->proto = htons (ETH_P_IPV4);
792 &ts->destination_ip.v4, 776 GNUNET_TUN_initialize_ipv4_header (ipv4,
793 &ts->source_ip.v4); 777 IPPROTO_ICMP,
794 *icmp = i2v->icmp_header; 778 sizeof (struct GNUNET_TUN_IcmpHeader) +
795 GNUNET_memcpy (&icmp[1], 779 mlen,
796 &i2v[1], 780 &ts->destination_ip.v4,
797 mlen); 781 &ts->source_ip.v4);
798 /* For some ICMP types, we need to adjust (make up) the payload here. 782 *icmp = i2v->icmp_header;
783 GNUNET_memcpy (&icmp[1], &i2v[1], mlen);
784 /* For some ICMP types, we need to adjust (make up) the payload here.
799 Also, depending on the AF used on the other side, we have to 785 Also, depending on the AF used on the other side, we have to
800 do ICMP PT (translate ICMP types) */ 786 do ICMP PT (translate ICMP types) */
801 switch (ntohl (i2v->af)) 787 switch (ntohl (i2v->af))
802 { 788 {
803 case AF_INET: 789 case AF_INET:
804 switch (icmp->type) 790 switch (icmp->type)
805 { 791 {
806 case GNUNET_TUN_ICMPTYPE_ECHO_REPLY: 792 case GNUNET_TUN_ICMPTYPE_ECHO_REPLY:
807 case GNUNET_TUN_ICMPTYPE_ECHO_REQUEST: 793 case GNUNET_TUN_ICMPTYPE_ECHO_REQUEST:
808 break; 794 break;
809 case GNUNET_TUN_ICMPTYPE_DESTINATION_UNREACHABLE: 795 case GNUNET_TUN_ICMPTYPE_DESTINATION_UNREACHABLE:
810 case GNUNET_TUN_ICMPTYPE_SOURCE_QUENCH: 796 case GNUNET_TUN_ICMPTYPE_SOURCE_QUENCH:
811 case GNUNET_TUN_ICMPTYPE_TIME_EXCEEDED: 797 case GNUNET_TUN_ICMPTYPE_TIME_EXCEEDED: {
812 { 798 struct GNUNET_TUN_IPv4Header *ipp =
813 struct GNUNET_TUN_IPv4Header *ipp = (struct GNUNET_TUN_IPv4Header *) &icmp[1]; 799 (struct GNUNET_TUN_IPv4Header *) &icmp[1];
814 struct GNUNET_TUN_UdpHeader *udp = (struct GNUNET_TUN_UdpHeader *) &ipp[1]; 800 struct GNUNET_TUN_UdpHeader *udp =
815 801 (struct GNUNET_TUN_UdpHeader *) &ipp[1];
816 if (mlen != 0) 802
817 { 803 if (mlen != 0)
818 /* sender did not strip ICMP payload? */ 804 {
819 GNUNET_break_op (0); 805 /* sender did not strip ICMP payload? */
820 return; 806 GNUNET_break_op (0);
821 } 807 return;
822 size += sizeof (struct GNUNET_TUN_IPv4Header) + 8; 808 }
823 GNUNET_assert (8 == sizeof (struct GNUNET_TUN_UdpHeader)); 809 size += sizeof (struct GNUNET_TUN_IPv4Header) + 8;
824 make_up_icmpv4_payload (ts, ipp, udp); 810 GNUNET_assert (8 == sizeof (struct GNUNET_TUN_UdpHeader));
825 } 811 make_up_icmpv4_payload (ts, ipp, udp);
826 break; 812 }
827 default: 813 break;
828 GNUNET_break_op (0); 814 default:
829 GNUNET_STATISTICS_update (stats, 815 GNUNET_break_op (0);
830 gettext_noop ("# ICMPv4 packets dropped (type not allowed)"), 816 GNUNET_STATISTICS_update (
831 1, GNUNET_NO); 817 stats,
832 return; 818 gettext_noop ("# ICMPv4 packets dropped (type not allowed)"),
833 } 819 1,
834 /* end AF_INET */ 820 GNUNET_NO);
835 break; 821 return;
836 case AF_INET6: 822 }
837 /* ICMP PT 6-to-4 and possibly making up payloads */ 823 /* end AF_INET */
838 switch (icmp->type) 824 break;
839 { 825 case AF_INET6:
840 case GNUNET_TUN_ICMPTYPE6_DESTINATION_UNREACHABLE: 826 /* ICMP PT 6-to-4 and possibly making up payloads */
841 icmp->type = GNUNET_TUN_ICMPTYPE_DESTINATION_UNREACHABLE; 827 switch (icmp->type)
842 { 828 {
843 struct GNUNET_TUN_IPv4Header *ipp = (struct GNUNET_TUN_IPv4Header *) &icmp[1]; 829 case GNUNET_TUN_ICMPTYPE6_DESTINATION_UNREACHABLE:
844 struct GNUNET_TUN_UdpHeader *udp = (struct GNUNET_TUN_UdpHeader *) &ipp[1]; 830 icmp->type = GNUNET_TUN_ICMPTYPE_DESTINATION_UNREACHABLE;
845 831 {
846 if (mlen != 0) 832 struct GNUNET_TUN_IPv4Header *ipp =
847 { 833 (struct GNUNET_TUN_IPv4Header *) &icmp[1];
848 /* sender did not strip ICMP payload? */ 834 struct GNUNET_TUN_UdpHeader *udp =
849 GNUNET_break_op (0); 835 (struct GNUNET_TUN_UdpHeader *) &ipp[1];
850 return; 836
851 } 837 if (mlen != 0)
852 size += sizeof (struct GNUNET_TUN_IPv4Header) + 8; 838 {
853 GNUNET_assert (8 == sizeof (struct GNUNET_TUN_UdpHeader)); 839 /* sender did not strip ICMP payload? */
854 make_up_icmpv4_payload (ts, ipp, udp); 840 GNUNET_break_op (0);
855 } 841 return;
856 break; 842 }
857 case GNUNET_TUN_ICMPTYPE6_TIME_EXCEEDED: 843 size += sizeof (struct GNUNET_TUN_IPv4Header) + 8;
858 icmp->type = GNUNET_TUN_ICMPTYPE_TIME_EXCEEDED; 844 GNUNET_assert (8 == sizeof (struct GNUNET_TUN_UdpHeader));
859 { 845 make_up_icmpv4_payload (ts, ipp, udp);
860 struct GNUNET_TUN_IPv4Header *ipp = (struct GNUNET_TUN_IPv4Header *) &icmp[1]; 846 }
861 struct GNUNET_TUN_UdpHeader *udp = (struct GNUNET_TUN_UdpHeader *) &ipp[1]; 847 break;
862 848 case GNUNET_TUN_ICMPTYPE6_TIME_EXCEEDED:
863 if (mlen != 0) 849 icmp->type = GNUNET_TUN_ICMPTYPE_TIME_EXCEEDED;
864 { 850 {
865 /* sender did not strip ICMP payload? */ 851 struct GNUNET_TUN_IPv4Header *ipp =
866 GNUNET_break_op (0); 852 (struct GNUNET_TUN_IPv4Header *) &icmp[1];
867 return; 853 struct GNUNET_TUN_UdpHeader *udp =
868 } 854 (struct GNUNET_TUN_UdpHeader *) &ipp[1];
869 size += sizeof (struct GNUNET_TUN_IPv4Header) + 8; 855
870 GNUNET_assert (8 == sizeof (struct GNUNET_TUN_UdpHeader)); 856 if (mlen != 0)
871 make_up_icmpv4_payload (ts, ipp, udp); 857 {
872 } 858 /* sender did not strip ICMP payload? */
873 break; 859 GNUNET_break_op (0);
874 case GNUNET_TUN_ICMPTYPE6_PACKET_TOO_BIG: 860 return;
875 case GNUNET_TUN_ICMPTYPE6_PARAMETER_PROBLEM: 861 }
876 GNUNET_STATISTICS_update (stats, 862 size += sizeof (struct GNUNET_TUN_IPv4Header) + 8;
877 gettext_noop ("# ICMPv6 packets dropped (impossible PT to v4)"), 863 GNUNET_assert (8 == sizeof (struct GNUNET_TUN_UdpHeader));
878 1, GNUNET_NO); 864 make_up_icmpv4_payload (ts, ipp, udp);
879 return; 865 }
880 case GNUNET_TUN_ICMPTYPE6_ECHO_REQUEST: 866 break;
881 icmp->type = GNUNET_TUN_ICMPTYPE_ECHO_REQUEST; 867 case GNUNET_TUN_ICMPTYPE6_PACKET_TOO_BIG:
882 break; 868 case GNUNET_TUN_ICMPTYPE6_PARAMETER_PROBLEM:
883 case GNUNET_TUN_ICMPTYPE6_ECHO_REPLY: 869 GNUNET_STATISTICS_update (
884 icmp->type = GNUNET_TUN_ICMPTYPE_ECHO_REPLY; 870 stats,
885 break; 871 gettext_noop ("# ICMPv6 packets dropped (impossible PT to v4)"),
886 default: 872 1,
887 GNUNET_break_op (0); 873 GNUNET_NO);
888 GNUNET_STATISTICS_update (stats, 874 return;
889 gettext_noop ("# ICMPv6 packets dropped (type not allowed)"), 875 case GNUNET_TUN_ICMPTYPE6_ECHO_REQUEST:
890 1, GNUNET_NO); 876 icmp->type = GNUNET_TUN_ICMPTYPE_ECHO_REQUEST;
891 return; 877 break;
892 } 878 case GNUNET_TUN_ICMPTYPE6_ECHO_REPLY:
893 /* end AF_INET6 */ 879 icmp->type = GNUNET_TUN_ICMPTYPE_ECHO_REPLY;
894 break; 880 break;
895 default: 881 default:
896 GNUNET_break_op (0); 882 GNUNET_break_op (0);
897 return; 883 GNUNET_STATISTICS_update (
898 } 884 stats,
899 msg->size = htons (size); 885 gettext_noop ("# ICMPv6 packets dropped (type not allowed)"),
900 GNUNET_TUN_calculate_icmp_checksum (icmp, 886 1,
901 &i2v[1], 887 GNUNET_NO);
902 mlen); 888 return;
903 (void) GNUNET_HELPER_send (helper_handle, 889 }
904 msg, 890 /* end AF_INET6 */
905 GNUNET_YES, 891 break;
906 NULL, NULL); 892 default:
893 GNUNET_break_op (0);
894 return;
907 } 895 }
896 msg->size = htons (size);
897 GNUNET_TUN_calculate_icmp_checksum (icmp, &i2v[1], mlen);
898 (void) GNUNET_HELPER_send (helper_handle, msg, GNUNET_YES, NULL, NULL);
908 } 899 }
909 break; 900 }
910 case AF_INET6: 901 break;
902 case AF_INET6: {
903 size_t size = sizeof (struct GNUNET_TUN_IPv6Header) +
904 sizeof (struct GNUNET_TUN_IcmpHeader) +
905 sizeof (struct GNUNET_MessageHeader) +
906 sizeof (struct GNUNET_TUN_Layer2PacketHeader) + mlen;
911 { 907 {
912 size_t size = sizeof (struct GNUNET_TUN_IPv6Header) 908 char buf[size + sizeof (struct GNUNET_TUN_IPv6Header) + 8] GNUNET_ALIGN;
913 + sizeof (struct GNUNET_TUN_IcmpHeader) 909 struct GNUNET_MessageHeader *msg = (struct GNUNET_MessageHeader *) buf;
914 + sizeof (struct GNUNET_MessageHeader) + 910 struct GNUNET_TUN_Layer2PacketHeader *tun =
915 sizeof (struct GNUNET_TUN_Layer2PacketHeader) + 911 (struct GNUNET_TUN_Layer2PacketHeader *) &msg[1];
916 mlen; 912 struct GNUNET_TUN_IPv6Header *ipv6 =
917 { 913 (struct GNUNET_TUN_IPv6Header *) &tun[1];
918 char buf[size + sizeof (struct GNUNET_TUN_IPv6Header) + 8] GNUNET_ALIGN; 914 struct GNUNET_TUN_IcmpHeader *icmp =
919 struct GNUNET_MessageHeader *msg = (struct GNUNET_MessageHeader *) buf; 915 (struct GNUNET_TUN_IcmpHeader *) &ipv6[1];
920 struct GNUNET_TUN_Layer2PacketHeader *tun = (struct GNUNET_TUN_Layer2PacketHeader*) &msg[1]; 916 msg->type = htons (GNUNET_MESSAGE_TYPE_VPN_HELPER);
921 struct GNUNET_TUN_IPv6Header *ipv6 = (struct GNUNET_TUN_IPv6Header *) &tun[1]; 917 tun->flags = htons (0);
922 struct GNUNET_TUN_IcmpHeader *icmp = (struct GNUNET_TUN_IcmpHeader *) &ipv6[1]; 918 tun->proto = htons (ETH_P_IPV6);
923 msg->type = htons (GNUNET_MESSAGE_TYPE_VPN_HELPER); 919 GNUNET_TUN_initialize_ipv6_header (ipv6,
924 tun->flags = htons (0); 920 IPPROTO_ICMPV6,
925 tun->proto = htons (ETH_P_IPV6); 921 sizeof (struct GNUNET_TUN_IcmpHeader) +
926 GNUNET_TUN_initialize_ipv6_header (ipv6, 922 mlen,
927 IPPROTO_ICMPV6, 923 &ts->destination_ip.v6,
928 sizeof (struct GNUNET_TUN_IcmpHeader) + mlen, 924 &ts->source_ip.v6);
929 &ts->destination_ip.v6, 925 *icmp = i2v->icmp_header;
930 &ts->source_ip.v6); 926 GNUNET_memcpy (&icmp[1], &i2v[1], mlen);
931 *icmp = i2v->icmp_header; 927
932 GNUNET_memcpy (&icmp[1], 928 /* For some ICMP types, we need to adjust (make up) the payload here.
933 &i2v[1],
934 mlen);
935
936 /* For some ICMP types, we need to adjust (make up) the payload here.
937 Also, depending on the AF used on the other side, we have to 929 Also, depending on the AF used on the other side, we have to
938 do ICMP PT (translate ICMP types) */ 930 do ICMP PT (translate ICMP types) */
939 switch (ntohl (i2v->af)) 931 switch (ntohl (i2v->af))
940 { 932 {
941 case AF_INET: 933 case AF_INET:
942 /* ICMP PT 4-to-6 and possibly making up payloads */ 934 /* ICMP PT 4-to-6 and possibly making up payloads */
943 switch (icmp->type) 935 switch (icmp->type)
944 { 936 {
945 case GNUNET_TUN_ICMPTYPE_ECHO_REPLY: 937 case GNUNET_TUN_ICMPTYPE_ECHO_REPLY:
946 icmp->type = GNUNET_TUN_ICMPTYPE6_ECHO_REPLY; 938 icmp->type = GNUNET_TUN_ICMPTYPE6_ECHO_REPLY;
947 break; 939 break;
948 case GNUNET_TUN_ICMPTYPE_ECHO_REQUEST: 940 case GNUNET_TUN_ICMPTYPE_ECHO_REQUEST:
949 icmp->type = GNUNET_TUN_ICMPTYPE6_ECHO_REQUEST; 941 icmp->type = GNUNET_TUN_ICMPTYPE6_ECHO_REQUEST;
950 break; 942 break;
951 case GNUNET_TUN_ICMPTYPE_DESTINATION_UNREACHABLE: 943 case GNUNET_TUN_ICMPTYPE_DESTINATION_UNREACHABLE:
952 icmp->type = GNUNET_TUN_ICMPTYPE6_DESTINATION_UNREACHABLE; 944 icmp->type = GNUNET_TUN_ICMPTYPE6_DESTINATION_UNREACHABLE;
953 { 945 {
954 struct GNUNET_TUN_IPv6Header *ipp = (struct GNUNET_TUN_IPv6Header *) &icmp[1]; 946 struct GNUNET_TUN_IPv6Header *ipp =
955 struct GNUNET_TUN_UdpHeader *udp = (struct GNUNET_TUN_UdpHeader *) &ipp[1]; 947 (struct GNUNET_TUN_IPv6Header *) &icmp[1];
956 948 struct GNUNET_TUN_UdpHeader *udp =
957 if (mlen != 0) 949 (struct GNUNET_TUN_UdpHeader *) &ipp[1];
958 { 950
959 /* sender did not strip ICMP payload? */ 951 if (mlen != 0)
960 GNUNET_break_op (0); 952 {
961 return; 953 /* sender did not strip ICMP payload? */
962 } 954 GNUNET_break_op (0);
963 size += sizeof (struct GNUNET_TUN_IPv6Header) + 8; 955 return;
964 GNUNET_assert (8 == sizeof (struct GNUNET_TUN_UdpHeader)); 956 }
965 make_up_icmpv6_payload (ts, ipp, udp); 957 size += sizeof (struct GNUNET_TUN_IPv6Header) + 8;
966 } 958 GNUNET_assert (8 == sizeof (struct GNUNET_TUN_UdpHeader));
967 break; 959 make_up_icmpv6_payload (ts, ipp, udp);
968 case GNUNET_TUN_ICMPTYPE_TIME_EXCEEDED: 960 }
969 icmp->type = GNUNET_TUN_ICMPTYPE6_TIME_EXCEEDED; 961 break;
970 { 962 case GNUNET_TUN_ICMPTYPE_TIME_EXCEEDED:
971 struct GNUNET_TUN_IPv6Header *ipp = (struct GNUNET_TUN_IPv6Header *) &icmp[1]; 963 icmp->type = GNUNET_TUN_ICMPTYPE6_TIME_EXCEEDED;
972 struct GNUNET_TUN_UdpHeader *udp = (struct GNUNET_TUN_UdpHeader *) &ipp[1]; 964 {
973 965 struct GNUNET_TUN_IPv6Header *ipp =
974 if (mlen != 0) 966 (struct GNUNET_TUN_IPv6Header *) &icmp[1];
975 { 967 struct GNUNET_TUN_UdpHeader *udp =
976 /* sender did not strip ICMP payload? */ 968 (struct GNUNET_TUN_UdpHeader *) &ipp[1];
977 GNUNET_break_op (0); 969
978 return; 970 if (mlen != 0)
979 } 971 {
980 size += sizeof (struct GNUNET_TUN_IPv6Header) + 8; 972 /* sender did not strip ICMP payload? */
981 GNUNET_assert (8 == sizeof (struct GNUNET_TUN_UdpHeader)); 973 GNUNET_break_op (0);
982 make_up_icmpv6_payload (ts, ipp, udp); 974 return;
983 } 975 }
984 break; 976 size += sizeof (struct GNUNET_TUN_IPv6Header) + 8;
985 case GNUNET_TUN_ICMPTYPE_SOURCE_QUENCH: 977 GNUNET_assert (8 == sizeof (struct GNUNET_TUN_UdpHeader));
986 GNUNET_STATISTICS_update (stats, 978 make_up_icmpv6_payload (ts, ipp, udp);
987 gettext_noop ("# ICMPv4 packets dropped (impossible PT to v6)"), 979 }
988 1, GNUNET_NO); 980 break;
989 return; 981 case GNUNET_TUN_ICMPTYPE_SOURCE_QUENCH:
990 default: 982 GNUNET_STATISTICS_update (
991 GNUNET_break_op (0); 983 stats,
992 GNUNET_STATISTICS_update (stats, 984 gettext_noop ("# ICMPv4 packets dropped (impossible PT to v6)"),
993 gettext_noop ("# ICMPv4 packets dropped (type not allowed)"), 985 1,
994 1, GNUNET_NO); 986 GNUNET_NO);
995 return; 987 return;
996 } 988 default:
997 /* end AF_INET */ 989 GNUNET_break_op (0);
998 break; 990 GNUNET_STATISTICS_update (
999 case AF_INET6: 991 stats,
1000 switch (icmp->type) 992 gettext_noop ("# ICMPv4 packets dropped (type not allowed)"),
1001 { 993 1,
1002 case GNUNET_TUN_ICMPTYPE6_DESTINATION_UNREACHABLE: 994 GNUNET_NO);
1003 case GNUNET_TUN_ICMPTYPE6_TIME_EXCEEDED: 995 return;
1004 case GNUNET_TUN_ICMPTYPE6_PACKET_TOO_BIG: 996 }
1005 case GNUNET_TUN_ICMPTYPE6_PARAMETER_PROBLEM: 997 /* end AF_INET */
1006 { 998 break;
1007 struct GNUNET_TUN_IPv6Header *ipp = (struct GNUNET_TUN_IPv6Header *) &icmp[1]; 999 case AF_INET6:
1008 struct GNUNET_TUN_UdpHeader *udp = (struct GNUNET_TUN_UdpHeader *) &ipp[1]; 1000 switch (icmp->type)
1009 1001 {
1010 if (mlen != 0) 1002 case GNUNET_TUN_ICMPTYPE6_DESTINATION_UNREACHABLE:
1011 { 1003 case GNUNET_TUN_ICMPTYPE6_TIME_EXCEEDED:
1012 /* sender did not strip ICMP payload? */ 1004 case GNUNET_TUN_ICMPTYPE6_PACKET_TOO_BIG:
1013 GNUNET_break_op (0); 1005 case GNUNET_TUN_ICMPTYPE6_PARAMETER_PROBLEM: {
1014 return; 1006 struct GNUNET_TUN_IPv6Header *ipp =
1015 } 1007 (struct GNUNET_TUN_IPv6Header *) &icmp[1];
1016 size += sizeof (struct GNUNET_TUN_IPv6Header) + 8; 1008 struct GNUNET_TUN_UdpHeader *udp =
1017 GNUNET_assert (8 == sizeof (struct GNUNET_TUN_UdpHeader)); 1009 (struct GNUNET_TUN_UdpHeader *) &ipp[1];
1018 make_up_icmpv6_payload (ts, ipp, udp); 1010
1019 } 1011 if (mlen != 0)
1020 break; 1012 {
1021 case GNUNET_TUN_ICMPTYPE6_ECHO_REQUEST: 1013 /* sender did not strip ICMP payload? */
1022 break; 1014 GNUNET_break_op (0);
1023 default: 1015 return;
1024 GNUNET_break_op (0); 1016 }
1025 GNUNET_STATISTICS_update (stats, 1017 size += sizeof (struct GNUNET_TUN_IPv6Header) + 8;
1026 gettext_noop ("# ICMPv6 packets dropped (type not allowed)"), 1018 GNUNET_assert (8 == sizeof (struct GNUNET_TUN_UdpHeader));
1027 1, GNUNET_NO); 1019 make_up_icmpv6_payload (ts, ipp, udp);
1028 return; 1020 }
1029 } 1021 break;
1030 /* end AF_INET6 */ 1022 case GNUNET_TUN_ICMPTYPE6_ECHO_REQUEST:
1031 break; 1023 break;
1032 default: 1024 default:
1033 GNUNET_break_op (0); 1025 GNUNET_break_op (0);
1034 return; 1026 GNUNET_STATISTICS_update (
1035 } 1027 stats,
1036 msg->size = htons (size); 1028 gettext_noop ("# ICMPv6 packets dropped (type not allowed)"),
1037 GNUNET_TUN_calculate_icmp_checksum (icmp, 1029 1,
1038 &i2v[1], mlen); 1030 GNUNET_NO);
1039 (void) GNUNET_HELPER_send (helper_handle, 1031 return;
1040 msg, 1032 }
1041 GNUNET_YES, 1033 /* end AF_INET6 */
1042 NULL, NULL); 1034 break;
1035 default:
1036 GNUNET_break_op (0);
1037 return;
1043 } 1038 }
1039 msg->size = htons (size);
1040 GNUNET_TUN_calculate_icmp_checksum (icmp, &i2v[1], mlen);
1041 (void) GNUNET_HELPER_send (helper_handle, msg, GNUNET_YES, NULL, NULL);
1044 } 1042 }
1045 break; 1043 }
1044 break;
1046 default: 1045 default:
1047 GNUNET_assert (0); 1046 GNUNET_assert (0);
1048 } 1047 }
1049 GNUNET_CONTAINER_heap_update_cost (ts->heap_node, 1048 GNUNET_CONTAINER_heap_update_cost (ts->heap_node,
1050 GNUNET_TIME_absolute_get ().abs_value_us); 1049 GNUNET_TIME_absolute_get ().abs_value_us);
1051 GNUNET_CADET_receive_done (ts->channel); 1050 GNUNET_CADET_receive_done (ts->channel);
1052} 1051}
1053 1052
@@ -1061,8 +1060,7 @@ handle_icmp_back (void *cls,
1061 * #GNUNET_SYSERR to close it (signal serious error) 1060 * #GNUNET_SYSERR to close it (signal serious error)
1062 */ 1061 */
1063static int 1062static int
1064check_udp_back (void *cls, 1063check_udp_back (void *cls, const struct GNUNET_EXIT_UdpReplyMessage *reply)
1065 const struct GNUNET_EXIT_UdpReplyMessage *reply)
1066{ 1064{
1067 struct ChannelState *ts = cls; 1065 struct ChannelState *ts = cls;
1068 1066
@@ -1088,125 +1086,115 @@ check_udp_back (void *cls,
1088 * @param reply the actual message 1086 * @param reply the actual message
1089 */ 1087 */
1090static void 1088static void
1091handle_udp_back (void *cls, 1089handle_udp_back (void *cls, const struct GNUNET_EXIT_UdpReplyMessage *reply)
1092 const struct GNUNET_EXIT_UdpReplyMessage *reply)
1093{ 1090{
1094 struct ChannelState *ts = cls; 1091 struct ChannelState *ts = cls;
1095 size_t mlen; 1092 size_t mlen;
1096 1093
1097 GNUNET_STATISTICS_update (stats, 1094 GNUNET_STATISTICS_update (stats,
1098 gettext_noop ("# UDP packets received from cadet"), 1095 gettext_noop ("# UDP packets received from cadet"),
1099 1, 1096 1,
1100 GNUNET_NO); 1097 GNUNET_NO);
1101 mlen = ntohs (reply->header.size) - sizeof (struct GNUNET_EXIT_UdpReplyMessage); 1098 mlen =
1099 ntohs (reply->header.size) - sizeof (struct GNUNET_EXIT_UdpReplyMessage);
1102 { 1100 {
1103 char sbuf[INET6_ADDRSTRLEN]; 1101 char sbuf[INET6_ADDRSTRLEN];
1104 char dbuf[INET6_ADDRSTRLEN]; 1102 char dbuf[INET6_ADDRSTRLEN];
1105 1103
1106 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1104 GNUNET_log (
1107 "Received UDP reply from cadet, sending %u bytes from [%s]:%u -> [%s]:%u via TUN\n", 1105 GNUNET_ERROR_TYPE_DEBUG,
1108 (unsigned int) mlen, 1106 "Received UDP reply from cadet, sending %u bytes from [%s]:%u -> [%s]:%u via TUN\n",
1109 inet_ntop (ts->af, &ts->destination_ip, sbuf, sizeof (sbuf)), 1107 (unsigned int) mlen,
1110 ts->destination_port, 1108 inet_ntop (ts->af, &ts->destination_ip, sbuf, sizeof (sbuf)),
1111 inet_ntop (ts->af, &ts->source_ip, dbuf, sizeof (dbuf)), 1109 ts->destination_port,
1112 ts->source_port); 1110 inet_ntop (ts->af, &ts->source_ip, dbuf, sizeof (dbuf)),
1111 ts->source_port);
1113 } 1112 }
1114 switch (ts->af) 1113 switch (ts->af)
1115 { 1114 {
1116 case AF_INET: 1115 case AF_INET: {
1116 size_t size = sizeof (struct GNUNET_TUN_IPv4Header) +
1117 sizeof (struct GNUNET_TUN_UdpHeader) +
1118 sizeof (struct GNUNET_MessageHeader) +
1119 sizeof (struct GNUNET_TUN_Layer2PacketHeader) + mlen;
1117 { 1120 {
1118 size_t size = sizeof (struct GNUNET_TUN_IPv4Header) 1121 char buf[size] GNUNET_ALIGN;
1119 + sizeof (struct GNUNET_TUN_UdpHeader) 1122 struct GNUNET_MessageHeader *msg = (struct GNUNET_MessageHeader *) buf;
1120 + sizeof (struct GNUNET_MessageHeader) + 1123 struct GNUNET_TUN_Layer2PacketHeader *tun =
1121 sizeof (struct GNUNET_TUN_Layer2PacketHeader) + 1124 (struct GNUNET_TUN_Layer2PacketHeader *) &msg[1];
1122 mlen; 1125 struct GNUNET_TUN_IPv4Header *ipv4 =
1123 { 1126 (struct GNUNET_TUN_IPv4Header *) &tun[1];
1124 char buf[size] GNUNET_ALIGN; 1127 struct GNUNET_TUN_UdpHeader *udp =
1125 struct GNUNET_MessageHeader *msg = (struct GNUNET_MessageHeader *) buf; 1128 (struct GNUNET_TUN_UdpHeader *) &ipv4[1];
1126 struct GNUNET_TUN_Layer2PacketHeader *tun = (struct GNUNET_TUN_Layer2PacketHeader*) &msg[1]; 1129 msg->type = htons (GNUNET_MESSAGE_TYPE_VPN_HELPER);
1127 struct GNUNET_TUN_IPv4Header *ipv4 = (struct GNUNET_TUN_IPv4Header *) &tun[1]; 1130 msg->size = htons (size);
1128 struct GNUNET_TUN_UdpHeader *udp = (struct GNUNET_TUN_UdpHeader *) &ipv4[1]; 1131 tun->flags = htons (0);
1129 msg->type = htons (GNUNET_MESSAGE_TYPE_VPN_HELPER); 1132 tun->proto = htons (ETH_P_IPV4);
1130 msg->size = htons (size); 1133 GNUNET_TUN_initialize_ipv4_header (ipv4,
1131 tun->flags = htons (0); 1134 IPPROTO_UDP,
1132 tun->proto = htons (ETH_P_IPV4); 1135 sizeof (struct GNUNET_TUN_UdpHeader) +
1133 GNUNET_TUN_initialize_ipv4_header (ipv4, 1136 mlen,
1134 IPPROTO_UDP, 1137 &ts->destination_ip.v4,
1135 sizeof (struct GNUNET_TUN_UdpHeader) + mlen, 1138 &ts->source_ip.v4);
1136 &ts->destination_ip.v4, 1139 if (0 == ntohs (reply->source_port))
1137 &ts->source_ip.v4); 1140 udp->source_port = htons (ts->destination_port);
1138 if (0 == ntohs (reply->source_port)) 1141 else
1139 udp->source_port = htons (ts->destination_port); 1142 udp->source_port = reply->source_port;
1140 else 1143 if (0 == ntohs (reply->destination_port))
1141 udp->source_port = reply->source_port; 1144 udp->destination_port = htons (ts->source_port);
1142 if (0 == ntohs (reply->destination_port)) 1145 else
1143 udp->destination_port = htons (ts->source_port); 1146 udp->destination_port = reply->destination_port;
1144 else 1147 udp->len = htons (mlen + sizeof (struct GNUNET_TUN_UdpHeader));
1145 udp->destination_port = reply->destination_port; 1148 GNUNET_TUN_calculate_udp4_checksum (ipv4, udp, &reply[1], mlen);
1146 udp->len = htons (mlen + sizeof (struct GNUNET_TUN_UdpHeader)); 1149 GNUNET_memcpy (&udp[1], &reply[1], mlen);
1147 GNUNET_TUN_calculate_udp4_checksum (ipv4, 1150 (void) GNUNET_HELPER_send (helper_handle, msg, GNUNET_YES, NULL, NULL);
1148 udp,
1149 &reply[1],
1150 mlen);
1151 GNUNET_memcpy (&udp[1],
1152 &reply[1],
1153 mlen);
1154 (void) GNUNET_HELPER_send (helper_handle,
1155 msg,
1156 GNUNET_YES,
1157 NULL, NULL);
1158 }
1159 } 1151 }
1160 break; 1152 }
1161 case AF_INET6: 1153 break;
1154 case AF_INET6: {
1155 size_t size = sizeof (struct GNUNET_TUN_IPv6Header) +
1156 sizeof (struct GNUNET_TUN_UdpHeader) +
1157 sizeof (struct GNUNET_MessageHeader) +
1158 sizeof (struct GNUNET_TUN_Layer2PacketHeader) + mlen;
1162 { 1159 {
1163 size_t size = sizeof (struct GNUNET_TUN_IPv6Header) 1160 char buf[size] GNUNET_ALIGN;
1164 + sizeof (struct GNUNET_TUN_UdpHeader) 1161 struct GNUNET_MessageHeader *msg = (struct GNUNET_MessageHeader *) buf;
1165 + sizeof (struct GNUNET_MessageHeader) + 1162 struct GNUNET_TUN_Layer2PacketHeader *tun =
1166 sizeof (struct GNUNET_TUN_Layer2PacketHeader) + 1163 (struct GNUNET_TUN_Layer2PacketHeader *) &msg[1];
1167 mlen; 1164 struct GNUNET_TUN_IPv6Header *ipv6 =
1168 { 1165 (struct GNUNET_TUN_IPv6Header *) &tun[1];
1169 char buf[size] GNUNET_ALIGN; 1166 struct GNUNET_TUN_UdpHeader *udp =
1170 struct GNUNET_MessageHeader *msg = (struct GNUNET_MessageHeader *) buf; 1167 (struct GNUNET_TUN_UdpHeader *) &ipv6[1];
1171 struct GNUNET_TUN_Layer2PacketHeader *tun = (struct GNUNET_TUN_Layer2PacketHeader*) &msg[1]; 1168 msg->type = htons (GNUNET_MESSAGE_TYPE_VPN_HELPER);
1172 struct GNUNET_TUN_IPv6Header *ipv6 = (struct GNUNET_TUN_IPv6Header *) &tun[1]; 1169 msg->size = htons (size);
1173 struct GNUNET_TUN_UdpHeader *udp = (struct GNUNET_TUN_UdpHeader *) &ipv6[1]; 1170 tun->flags = htons (0);
1174 msg->type = htons (GNUNET_MESSAGE_TYPE_VPN_HELPER); 1171 tun->proto = htons (ETH_P_IPV6);
1175 msg->size = htons (size); 1172 GNUNET_TUN_initialize_ipv6_header (ipv6,
1176 tun->flags = htons (0); 1173 IPPROTO_UDP,
1177 tun->proto = htons (ETH_P_IPV6); 1174 sizeof (struct GNUNET_TUN_UdpHeader) +
1178 GNUNET_TUN_initialize_ipv6_header (ipv6, 1175 mlen,
1179 IPPROTO_UDP, 1176 &ts->destination_ip.v6,
1180 sizeof (struct GNUNET_TUN_UdpHeader) + mlen, 1177 &ts->source_ip.v6);
1181 &ts->destination_ip.v6, 1178 if (0 == ntohs (reply->source_port))
1182 &ts->source_ip.v6); 1179 udp->source_port = htons (ts->destination_port);
1183 if (0 == ntohs (reply->source_port)) 1180 else
1184 udp->source_port = htons (ts->destination_port); 1181 udp->source_port = reply->source_port;
1185 else 1182 if (0 == ntohs (reply->destination_port))
1186 udp->source_port = reply->source_port; 1183 udp->destination_port = htons (ts->source_port);
1187 if (0 == ntohs (reply->destination_port)) 1184 else
1188 udp->destination_port = htons (ts->source_port); 1185 udp->destination_port = reply->destination_port;
1189 else 1186 udp->len = htons (mlen + sizeof (struct GNUNET_TUN_UdpHeader));
1190 udp->destination_port = reply->destination_port; 1187 GNUNET_TUN_calculate_udp6_checksum (ipv6, udp, &reply[1], mlen);
1191 udp->len = htons (mlen + sizeof (struct GNUNET_TUN_UdpHeader)); 1188 GNUNET_memcpy (&udp[1], &reply[1], mlen);
1192 GNUNET_TUN_calculate_udp6_checksum (ipv6, 1189 (void) GNUNET_HELPER_send (helper_handle, msg, GNUNET_YES, NULL, NULL);
1193 udp,
1194 &reply[1], mlen);
1195 GNUNET_memcpy (&udp[1],
1196 &reply[1],
1197 mlen);
1198 (void) GNUNET_HELPER_send (helper_handle,
1199 msg,
1200 GNUNET_YES,
1201 NULL, NULL);
1202 }
1203 } 1190 }
1204 break; 1191 }
1192 break;
1205 default: 1193 default:
1206 GNUNET_assert (0); 1194 GNUNET_assert (0);
1207 } 1195 }
1208 GNUNET_CONTAINER_heap_update_cost (ts->heap_node, 1196 GNUNET_CONTAINER_heap_update_cost (ts->heap_node,
1209 GNUNET_TIME_absolute_get ().abs_value_us); 1197 GNUNET_TIME_absolute_get ().abs_value_us);
1210 GNUNET_CADET_receive_done (ts->channel); 1198 GNUNET_CADET_receive_done (ts->channel);
1211} 1199}
1212 1200
@@ -1220,8 +1208,7 @@ handle_udp_back (void *cls,
1220 * #GNUNET_SYSERR to close it (signal serious error) 1208 * #GNUNET_SYSERR to close it (signal serious error)
1221 */ 1209 */
1222static int 1210static int
1223check_tcp_back (void *cls, 1211check_tcp_back (void *cls, const struct GNUNET_EXIT_TcpDataMessage *data)
1224 const struct GNUNET_EXIT_TcpDataMessage *data)
1225{ 1212{
1226 struct ChannelState *ts = cls; 1213 struct ChannelState *ts = cls;
1227 1214
@@ -1247,112 +1234,100 @@ check_tcp_back (void *cls,
1247 * @param data the actual message 1234 * @param data the actual message
1248 */ 1235 */
1249static void 1236static void
1250handle_tcp_back (void *cls, 1237handle_tcp_back (void *cls, const struct GNUNET_EXIT_TcpDataMessage *data)
1251 const struct GNUNET_EXIT_TcpDataMessage *data)
1252{ 1238{
1253 struct ChannelState *ts = cls; 1239 struct ChannelState *ts = cls;
1254 size_t mlen; 1240 size_t mlen;
1255 1241
1256 GNUNET_STATISTICS_update (stats, 1242 GNUNET_STATISTICS_update (stats,
1257 gettext_noop ("# TCP packets received from cadet"), 1243 gettext_noop ("# TCP packets received from cadet"),
1258 1, 1244 1,
1259 GNUNET_NO); 1245 GNUNET_NO);
1260 mlen = ntohs (data->header.size) - sizeof (struct GNUNET_EXIT_TcpDataMessage); 1246 mlen = ntohs (data->header.size) - sizeof (struct GNUNET_EXIT_TcpDataMessage);
1261 { 1247 {
1262 char sbuf[INET6_ADDRSTRLEN]; 1248 char sbuf[INET6_ADDRSTRLEN];
1263 char dbuf[INET6_ADDRSTRLEN]; 1249 char dbuf[INET6_ADDRSTRLEN];
1264 1250
1265 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1251 GNUNET_log (
1266 "Received TCP reply from cadet, sending %u bytes from [%s]:%u -> [%s]:%u via TUN\n", 1252 GNUNET_ERROR_TYPE_DEBUG,
1267 (unsigned int) mlen, 1253 "Received TCP reply from cadet, sending %u bytes from [%s]:%u -> [%s]:%u via TUN\n",
1268 inet_ntop (ts->af, &ts->destination_ip, sbuf, sizeof (sbuf)), 1254 (unsigned int) mlen,
1269 ts->destination_port, 1255 inet_ntop (ts->af, &ts->destination_ip, sbuf, sizeof (sbuf)),
1270 inet_ntop (ts->af, &ts->source_ip, dbuf, sizeof (dbuf)), 1256 ts->destination_port,
1271 ts->source_port); 1257 inet_ntop (ts->af, &ts->source_ip, dbuf, sizeof (dbuf)),
1258 ts->source_port);
1272 } 1259 }
1273 switch (ts->af) 1260 switch (ts->af)
1274 { 1261 {
1275 case AF_INET: 1262 case AF_INET: {
1263 size_t size = sizeof (struct GNUNET_TUN_IPv4Header) +
1264 sizeof (struct GNUNET_TUN_TcpHeader) +
1265 sizeof (struct GNUNET_MessageHeader) +
1266 sizeof (struct GNUNET_TUN_Layer2PacketHeader) + mlen;
1276 { 1267 {
1277 size_t size = sizeof (struct GNUNET_TUN_IPv4Header) 1268 char buf[size] GNUNET_ALIGN;
1278 + sizeof (struct GNUNET_TUN_TcpHeader) 1269 struct GNUNET_MessageHeader *msg = (struct GNUNET_MessageHeader *) buf;
1279 + sizeof (struct GNUNET_MessageHeader) + 1270 struct GNUNET_TUN_Layer2PacketHeader *tun =
1280 sizeof (struct GNUNET_TUN_Layer2PacketHeader) + 1271 (struct GNUNET_TUN_Layer2PacketHeader *) &msg[1];
1281 mlen; 1272 struct GNUNET_TUN_IPv4Header *ipv4 =
1282 { 1273 (struct GNUNET_TUN_IPv4Header *) &tun[1];
1283 char buf[size] GNUNET_ALIGN; 1274 struct GNUNET_TUN_TcpHeader *tcp =
1284 struct GNUNET_MessageHeader *msg = (struct GNUNET_MessageHeader *) buf; 1275 (struct GNUNET_TUN_TcpHeader *) &ipv4[1];
1285 struct GNUNET_TUN_Layer2PacketHeader *tun = (struct GNUNET_TUN_Layer2PacketHeader*) &msg[1]; 1276 msg->type = htons (GNUNET_MESSAGE_TYPE_VPN_HELPER);
1286 struct GNUNET_TUN_IPv4Header *ipv4 = (struct GNUNET_TUN_IPv4Header *) &tun[1]; 1277 msg->size = htons (size);
1287 struct GNUNET_TUN_TcpHeader *tcp = (struct GNUNET_TUN_TcpHeader *) &ipv4[1]; 1278 tun->flags = htons (0);
1288 msg->type = htons (GNUNET_MESSAGE_TYPE_VPN_HELPER); 1279 tun->proto = htons (ETH_P_IPV4);
1289 msg->size = htons (size); 1280 GNUNET_TUN_initialize_ipv4_header (ipv4,
1290 tun->flags = htons (0); 1281 IPPROTO_TCP,
1291 tun->proto = htons (ETH_P_IPV4); 1282 sizeof (struct GNUNET_TUN_TcpHeader) +
1292 GNUNET_TUN_initialize_ipv4_header (ipv4, 1283 mlen,
1293 IPPROTO_TCP, 1284 &ts->destination_ip.v4,
1294 sizeof (struct GNUNET_TUN_TcpHeader) + mlen, 1285 &ts->source_ip.v4);
1295 &ts->destination_ip.v4, 1286 *tcp = data->tcp_header;
1296 &ts->source_ip.v4); 1287 tcp->source_port = htons (ts->destination_port);
1297 *tcp = data->tcp_header; 1288 tcp->destination_port = htons (ts->source_port);
1298 tcp->source_port = htons (ts->destination_port); 1289 GNUNET_TUN_calculate_tcp4_checksum (ipv4, tcp, &data[1], mlen);
1299 tcp->destination_port = htons (ts->source_port); 1290 GNUNET_memcpy (&tcp[1], &data[1], mlen);
1300 GNUNET_TUN_calculate_tcp4_checksum (ipv4, 1291 (void) GNUNET_HELPER_send (helper_handle, msg, GNUNET_YES, NULL, NULL);
1301 tcp,
1302 &data[1],
1303 mlen);
1304 GNUNET_memcpy (&tcp[1],
1305 &data[1],
1306 mlen);
1307 (void) GNUNET_HELPER_send (helper_handle,
1308 msg,
1309 GNUNET_YES,
1310 NULL, NULL);
1311 }
1312 } 1292 }
1313 break; 1293 }
1314 case AF_INET6: 1294 break;
1295 case AF_INET6: {
1296 size_t size = sizeof (struct GNUNET_TUN_IPv6Header) +
1297 sizeof (struct GNUNET_TUN_TcpHeader) +
1298 sizeof (struct GNUNET_MessageHeader) +
1299 sizeof (struct GNUNET_TUN_Layer2PacketHeader) + mlen;
1315 { 1300 {
1316 size_t size = sizeof (struct GNUNET_TUN_IPv6Header) 1301 char buf[size] GNUNET_ALIGN;
1317 + sizeof (struct GNUNET_TUN_TcpHeader) 1302 struct GNUNET_MessageHeader *msg = (struct GNUNET_MessageHeader *) buf;
1318 + sizeof (struct GNUNET_MessageHeader) + 1303 struct GNUNET_TUN_Layer2PacketHeader *tun =
1319 sizeof (struct GNUNET_TUN_Layer2PacketHeader) + 1304 (struct GNUNET_TUN_Layer2PacketHeader *) &msg[1];
1320 mlen; 1305 struct GNUNET_TUN_IPv6Header *ipv6 =
1321 { 1306 (struct GNUNET_TUN_IPv6Header *) &tun[1];
1322 char buf[size] GNUNET_ALIGN; 1307 struct GNUNET_TUN_TcpHeader *tcp =
1323 struct GNUNET_MessageHeader *msg = (struct GNUNET_MessageHeader *) buf; 1308 (struct GNUNET_TUN_TcpHeader *) &ipv6[1];
1324 struct GNUNET_TUN_Layer2PacketHeader *tun = (struct GNUNET_TUN_Layer2PacketHeader*) &msg[1]; 1309 msg->type = htons (GNUNET_MESSAGE_TYPE_VPN_HELPER);
1325 struct GNUNET_TUN_IPv6Header *ipv6 = (struct GNUNET_TUN_IPv6Header *) &tun[1]; 1310 msg->size = htons (size);
1326 struct GNUNET_TUN_TcpHeader *tcp = (struct GNUNET_TUN_TcpHeader *) &ipv6[1]; 1311 tun->flags = htons (0);
1327 msg->type = htons (GNUNET_MESSAGE_TYPE_VPN_HELPER); 1312 tun->proto = htons (ETH_P_IPV6);
1328 msg->size = htons (size); 1313 GNUNET_TUN_initialize_ipv6_header (ipv6,
1329 tun->flags = htons (0); 1314 IPPROTO_TCP,
1330 tun->proto = htons (ETH_P_IPV6); 1315 sizeof (struct GNUNET_TUN_TcpHeader) +
1331 GNUNET_TUN_initialize_ipv6_header (ipv6, 1316 mlen,
1332 IPPROTO_TCP, 1317 &ts->destination_ip.v6,
1333 sizeof (struct GNUNET_TUN_TcpHeader) + mlen, 1318 &ts->source_ip.v6);
1334 &ts->destination_ip.v6, 1319 *tcp = data->tcp_header;
1335 &ts->source_ip.v6); 1320 tcp->source_port = htons (ts->destination_port);
1336 *tcp = data->tcp_header; 1321 tcp->destination_port = htons (ts->source_port);
1337 tcp->source_port = htons (ts->destination_port); 1322 GNUNET_TUN_calculate_tcp6_checksum (ipv6, tcp, &data[1], mlen);
1338 tcp->destination_port = htons (ts->source_port); 1323 GNUNET_memcpy (&tcp[1], &data[1], mlen);
1339 GNUNET_TUN_calculate_tcp6_checksum (ipv6, 1324 (void) GNUNET_HELPER_send (helper_handle, msg, GNUNET_YES, NULL, NULL);
1340 tcp,
1341 &data[1],
1342 mlen);
1343 GNUNET_memcpy (&tcp[1],
1344 &data[1],
1345 mlen);
1346 (void) GNUNET_HELPER_send (helper_handle,
1347 msg,
1348 GNUNET_YES,
1349 NULL, NULL);
1350 }
1351 } 1325 }
1352 break; 1326 }
1327 break;
1353 } 1328 }
1354 GNUNET_CONTAINER_heap_update_cost (ts->heap_node, 1329 GNUNET_CONTAINER_heap_update_cost (ts->heap_node,
1355 GNUNET_TIME_absolute_get ().abs_value_us); 1330 GNUNET_TIME_absolute_get ().abs_value_us);
1356 GNUNET_CADET_receive_done (ts->channel); 1331 GNUNET_CADET_receive_done (ts->channel);
1357} 1332}
1358 1333
@@ -1370,21 +1345,20 @@ create_channel (struct ChannelState *ts,
1370 const struct GNUNET_PeerIdentity *target, 1345 const struct GNUNET_PeerIdentity *target,
1371 const struct GNUNET_HashCode *port) 1346 const struct GNUNET_HashCode *port)
1372{ 1347{
1373 struct GNUNET_MQ_MessageHandler cadet_handlers[] = { 1348 struct GNUNET_MQ_MessageHandler cadet_handlers[] =
1374 GNUNET_MQ_hd_var_size (udp_back, 1349 {GNUNET_MQ_hd_var_size (udp_back,
1375 GNUNET_MESSAGE_TYPE_VPN_UDP_REPLY, 1350 GNUNET_MESSAGE_TYPE_VPN_UDP_REPLY,
1376 struct GNUNET_EXIT_UdpReplyMessage, 1351 struct GNUNET_EXIT_UdpReplyMessage,
1377 ts), 1352 ts),
1378 GNUNET_MQ_hd_var_size (tcp_back, 1353 GNUNET_MQ_hd_var_size (tcp_back,
1379 GNUNET_MESSAGE_TYPE_VPN_TCP_DATA_TO_VPN, 1354 GNUNET_MESSAGE_TYPE_VPN_TCP_DATA_TO_VPN,
1380 struct GNUNET_EXIT_TcpDataMessage, 1355 struct GNUNET_EXIT_TcpDataMessage,
1381 ts), 1356 ts),
1382 GNUNET_MQ_hd_var_size (icmp_back, 1357 GNUNET_MQ_hd_var_size (icmp_back,
1383 GNUNET_MESSAGE_TYPE_VPN_ICMP_TO_VPN, 1358 GNUNET_MESSAGE_TYPE_VPN_ICMP_TO_VPN,
1384 struct GNUNET_EXIT_IcmpToVPNMessage, 1359 struct GNUNET_EXIT_IcmpToVPNMessage,
1385 ts), 1360 ts),
1386 GNUNET_MQ_handler_end() 1361 GNUNET_MQ_handler_end ()};
1387 };
1388 1362
1389 return GNUNET_CADET_channel_create (cadet_handle, 1363 return GNUNET_CADET_channel_create (cadet_handle,
1390 ts, 1364 ts,
@@ -1408,11 +1382,11 @@ create_channel (struct ChannelState *ts,
1408 */ 1382 */
1409static void 1383static void
1410handle_regex_result (void *cls, 1384handle_regex_result (void *cls,
1411 const struct GNUNET_PeerIdentity *id, 1385 const struct GNUNET_PeerIdentity *id,
1412 const struct GNUNET_PeerIdentity *get_path, 1386 const struct GNUNET_PeerIdentity *get_path,
1413 unsigned int get_path_length, 1387 unsigned int get_path_length,
1414 const struct GNUNET_PeerIdentity *put_path, 1388 const struct GNUNET_PeerIdentity *put_path,
1415 unsigned int put_path_length) 1389 unsigned int put_path_length)
1416{ 1390{
1417 struct ChannelState *ts = cls; 1391 struct ChannelState *ts = cls;
1418 struct GNUNET_HashCode port; 1392 struct GNUNET_HashCode port;
@@ -1445,9 +1419,7 @@ handle_regex_result (void *cls,
1445 "Creating tunnel to %s for destination %s!\n", 1419 "Creating tunnel to %s for destination %s!\n",
1446 GNUNET_i2s (id), 1420 GNUNET_i2s (id),
1447 print_channel_destination (&ts->destination)); 1421 print_channel_destination (&ts->destination));
1448 ts->channel = create_channel (ts, 1422 ts->channel = create_channel (ts, id, &port);
1449 id,
1450 &port);
1451} 1423}
1452 1424
1453 1425
@@ -1459,14 +1431,13 @@ handle_regex_result (void *cls,
1459 * @return channel state of the channel that was created 1431 * @return channel state of the channel that was created
1460 */ 1432 */
1461static struct ChannelState * 1433static struct ChannelState *
1462create_channel_to_destination (struct DestinationChannel *dt, 1434create_channel_to_destination (struct DestinationChannel *dt, int client_af)
1463 int client_af)
1464{ 1435{
1465 struct ChannelState *ts; 1436 struct ChannelState *ts;
1466 1437
1467 GNUNET_STATISTICS_update (stats, 1438 GNUNET_STATISTICS_update (stats,
1468 gettext_noop ("# Cadet channels created"), 1439 gettext_noop ("# Cadet channels created"),
1469 1, 1440 1,
1470 GNUNET_NO); 1441 GNUNET_NO);
1471 ts = GNUNET_new (struct ChannelState); 1442 ts = GNUNET_new (struct ChannelState);
1472 ts->af = client_af; 1443 ts->af = client_af;
@@ -1477,12 +1448,15 @@ create_channel_to_destination (struct DestinationChannel *dt,
1477 { 1448 {
1478 struct GNUNET_HashCode cadet_port; 1449 struct GNUNET_HashCode cadet_port;
1479 1450
1480 GNUNET_TUN_compute_service_cadet_port (&ts->destination.details.service_destination.service_descriptor, 1451 GNUNET_TUN_compute_service_cadet_port (&ts->destination.details
1452 .service_destination
1453 .service_descriptor,
1481 ts->destination_port, 1454 ts->destination_port,
1482 &cadet_port); 1455 &cadet_port);
1483 ts->channel = create_channel (ts, 1456 ts->channel =
1484 &dt->destination->details.service_destination.target, 1457 create_channel (ts,
1485 &cadet_port); 1458 &dt->destination->details.service_destination.target,
1459 &cadet_port);
1486 1460
1487 if (NULL == ts->channel) 1461 if (NULL == ts->channel)
1488 { 1462 {
@@ -1491,9 +1465,11 @@ create_channel_to_destination (struct DestinationChannel *dt,
1491 return NULL; 1465 return NULL;
1492 } 1466 }
1493 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1467 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1494 "Creating channel to peer %s offering service %s on port %u\n", 1468 "Creating channel to peer %s offering service %s on port %u\n",
1495 GNUNET_i2s (&dt->destination->details.service_destination.target), 1469 GNUNET_i2s (
1496 GNUNET_h2s (&ts->destination.details.service_destination.service_descriptor), 1470 &dt->destination->details.service_destination.target),
1471 GNUNET_h2s (&ts->destination.details.service_destination
1472 .service_descriptor),
1497 (unsigned int) ts->destination_port); 1473 (unsigned int) ts->destination_port);
1498 } 1474 }
1499 else 1475 else
@@ -1502,25 +1478,25 @@ create_channel_to_destination (struct DestinationChannel *dt,
1502 1478
1503 switch (dt->destination->details.exit_destination.af) 1479 switch (dt->destination->details.exit_destination.af)
1504 { 1480 {
1505 case AF_INET: 1481 case AF_INET: {
1506 {
1507 char address[GNUNET_TUN_IPV4_REGEXLEN]; 1482 char address[GNUNET_TUN_IPV4_REGEXLEN];
1508 1483
1509 GNUNET_TUN_ipv4toregexsearch (&dt->destination->details.exit_destination.ip.v4, 1484 GNUNET_TUN_ipv4toregexsearch (&dt->destination->details.exit_destination
1510 dt->destination_port, 1485 .ip.v4,
1511 address); 1486 dt->destination_port,
1487 address);
1512 GNUNET_asprintf (&policy, 1488 GNUNET_asprintf (&policy,
1513 "%s%s", 1489 "%s%s",
1514 GNUNET_APPLICATION_TYPE_EXIT_REGEX_PREFIX, 1490 GNUNET_APPLICATION_TYPE_EXIT_REGEX_PREFIX,
1515 address); 1491 address);
1516 break; 1492 break;
1517 } 1493 }
1518 case AF_INET6: 1494 case AF_INET6: {
1519 {
1520 char address[GNUNET_TUN_IPV6_REGEXLEN]; 1495 char address[GNUNET_TUN_IPV6_REGEXLEN];
1521 1496
1522 GNUNET_TUN_ipv6toregexsearch (&dt->destination->details.exit_destination.ip.v6, 1497 GNUNET_TUN_ipv6toregexsearch (&dt->destination->details.exit_destination
1523 dt->destination_port, 1498 .ip.v6,
1499 dt->destination_port,
1524 address); 1500 address);
1525 GNUNET_asprintf (&policy, 1501 GNUNET_asprintf (&policy,
1526 "%s%s", 1502 "%s%s",
@@ -1534,12 +1510,9 @@ create_channel_to_destination (struct DestinationChannel *dt,
1534 } 1510 }
1535 1511
1536 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1512 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1537 "Requesting connect by string: %s\n", 1513 "Requesting connect by string: %s\n",
1538 policy); 1514 policy);
1539 ts->search = GNUNET_REGEX_search (cfg, 1515 ts->search = GNUNET_REGEX_search (cfg, policy, &handle_regex_result, ts);
1540 policy,
1541 &handle_regex_result,
1542 ts);
1543 GNUNET_free (policy); 1516 GNUNET_free (policy);
1544 } 1517 }
1545 return ts; 1518 return ts;
@@ -1580,12 +1553,12 @@ expire_channel (struct ChannelState *except)
1580 */ 1553 */
1581static void 1554static void
1582route_packet (struct DestinationEntry *destination, 1555route_packet (struct DestinationEntry *destination,
1583 int af, 1556 int af,
1584 uint8_t protocol, 1557 uint8_t protocol,
1585 const void *source_ip, 1558 const void *source_ip,
1586 const void *destination_ip, 1559 const void *destination_ip,
1587 const void *payload, 1560 const void *payload,
1588 size_t payload_length) 1561 size_t payload_length)
1589{ 1562{
1590 struct GNUNET_HashCode key; 1563 struct GNUNET_HashCode key;
1591 struct ChannelState *ts; 1564 struct ChannelState *ts;
@@ -1601,92 +1574,89 @@ route_packet (struct DestinationEntry *destination,
1601 1574
1602 switch (protocol) 1575 switch (protocol)
1603 { 1576 {
1604 case IPPROTO_UDP: 1577 case IPPROTO_UDP: {
1578 if (payload_length < sizeof (struct GNUNET_TUN_UdpHeader))
1605 { 1579 {
1606 if (payload_length < sizeof (struct GNUNET_TUN_UdpHeader)) 1580 /* blame kernel? */
1607 { 1581 GNUNET_break (0);
1608 /* blame kernel? */ 1582 return;
1609 GNUNET_break (0);
1610 return;
1611 }
1612 tcp = NULL; /* make compiler happy */
1613 icmp = NULL; /* make compiler happy */
1614 udp = payload;
1615 if (udp->len < sizeof (struct GNUNET_TUN_UdpHeader))
1616 {
1617 GNUNET_break_op (0);
1618 return;
1619 }
1620 source_port = ntohs (udp->source_port);
1621 destination_port = ntohs (udp->destination_port);
1622 get_channel_key_from_ips (af,
1623 IPPROTO_UDP,
1624 source_ip,
1625 source_port,
1626 destination_ip,
1627 destination_port,
1628 &key);
1629 } 1583 }
1630 break; 1584 tcp = NULL; /* make compiler happy */
1631 case IPPROTO_TCP: 1585 icmp = NULL; /* make compiler happy */
1586 udp = payload;
1587 if (udp->len < sizeof (struct GNUNET_TUN_UdpHeader))
1632 { 1588 {
1633 if (payload_length < sizeof (struct GNUNET_TUN_TcpHeader)) 1589 GNUNET_break_op (0);
1634 { 1590 return;
1635 /* blame kernel? */
1636 GNUNET_break (0);
1637 return;
1638 }
1639 udp = NULL; /* make compiler happy */
1640 icmp = NULL; /* make compiler happy */
1641 tcp = payload;
1642 if (tcp->off * 4 < sizeof (struct GNUNET_TUN_TcpHeader))
1643 {
1644 GNUNET_break_op (0);
1645 return;
1646 }
1647 source_port = ntohs (tcp->source_port);
1648 destination_port = ntohs (tcp->destination_port);
1649 get_channel_key_from_ips (af,
1650 IPPROTO_TCP,
1651 source_ip,
1652 source_port,
1653 destination_ip,
1654 destination_port,
1655 &key);
1656 } 1591 }
1657 break; 1592 source_port = ntohs (udp->source_port);
1593 destination_port = ntohs (udp->destination_port);
1594 get_channel_key_from_ips (af,
1595 IPPROTO_UDP,
1596 source_ip,
1597 source_port,
1598 destination_ip,
1599 destination_port,
1600 &key);
1601 }
1602 break;
1603 case IPPROTO_TCP: {
1604 if (payload_length < sizeof (struct GNUNET_TUN_TcpHeader))
1605 {
1606 /* blame kernel? */
1607 GNUNET_break (0);
1608 return;
1609 }
1610 udp = NULL; /* make compiler happy */
1611 icmp = NULL; /* make compiler happy */
1612 tcp = payload;
1613 if (tcp->off * 4 < sizeof (struct GNUNET_TUN_TcpHeader))
1614 {
1615 GNUNET_break_op (0);
1616 return;
1617 }
1618 source_port = ntohs (tcp->source_port);
1619 destination_port = ntohs (tcp->destination_port);
1620 get_channel_key_from_ips (af,
1621 IPPROTO_TCP,
1622 source_ip,
1623 source_port,
1624 destination_ip,
1625 destination_port,
1626 &key);
1627 }
1628 break;
1658 case IPPROTO_ICMP: 1629 case IPPROTO_ICMP:
1659 case IPPROTO_ICMPV6: 1630 case IPPROTO_ICMPV6: {
1631 if ((AF_INET == af) ^ (protocol == IPPROTO_ICMP))
1660 { 1632 {
1661 if ( (AF_INET == af) ^ (protocol == IPPROTO_ICMP) ) 1633 GNUNET_break (0);
1662 { 1634 return;
1663 GNUNET_break (0);
1664 return;
1665 }
1666 if (payload_length < sizeof (struct GNUNET_TUN_IcmpHeader))
1667 {
1668 /* blame kernel? */
1669 GNUNET_break (0);
1670 return;
1671 }
1672 tcp = NULL; /* make compiler happy */
1673 udp = NULL; /* make compiler happy */
1674 icmp = payload;
1675 source_port = 0;
1676 destination_port = 0;
1677 get_channel_key_from_ips (af,
1678 protocol,
1679 source_ip,
1680 0,
1681 destination_ip,
1682 0,
1683 &key);
1684 } 1635 }
1685 break; 1636 if (payload_length < sizeof (struct GNUNET_TUN_IcmpHeader))
1637 {
1638 /* blame kernel? */
1639 GNUNET_break (0);
1640 return;
1641 }
1642 tcp = NULL; /* make compiler happy */
1643 udp = NULL; /* make compiler happy */
1644 icmp = payload;
1645 source_port = 0;
1646 destination_port = 0;
1647 get_channel_key_from_ips (af,
1648 protocol,
1649 source_ip,
1650 0,
1651 destination_ip,
1652 0,
1653 &key);
1654 }
1655 break;
1686 default: 1656 default:
1687 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 1657 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1688 _("Protocol %u not supported, dropping\n"), 1658 _ ("Protocol %u not supported, dropping\n"),
1689 (unsigned int) protocol); 1659 (unsigned int) protocol);
1690 return; 1660 return;
1691 } 1661 }
1692 alen = 0; 1662 alen = 0;
@@ -1696,7 +1666,7 @@ route_packet (struct DestinationEntry *destination,
1696 { 1666 {
1697 case AF_INET: 1667 case AF_INET:
1698 alen = sizeof (struct in_addr); 1668 alen = sizeof (struct in_addr);
1699 break; 1669 break;
1700 case AF_INET6: 1670 case AF_INET6:
1701 alen = sizeof (struct in6_addr); 1671 alen = sizeof (struct in6_addr);
1702 break; 1672 break;
@@ -1709,27 +1679,23 @@ route_packet (struct DestinationEntry *destination,
1709 char dbuf[INET6_ADDRSTRLEN]; 1679 char dbuf[INET6_ADDRSTRLEN];
1710 char xbuf[INET6_ADDRSTRLEN]; 1680 char xbuf[INET6_ADDRSTRLEN];
1711 1681
1712 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1682 GNUNET_log (
1713 "Routing %s packet from [%s]:%u -> [%s]:%u to destination [%s]:%u\n", 1683 GNUNET_ERROR_TYPE_DEBUG,
1714 (protocol == IPPROTO_TCP) ? "TCP" : "UDP", 1684 "Routing %s packet from [%s]:%u -> [%s]:%u to destination [%s]:%u\n",
1715 inet_ntop (af, 1685 (protocol == IPPROTO_TCP) ? "TCP" : "UDP",
1716 source_ip, 1686 inet_ntop (af, source_ip, sbuf, sizeof (sbuf)),
1717 sbuf, 1687 source_port,
1718 sizeof (sbuf)), 1688 inet_ntop (af, destination_ip, dbuf, sizeof (dbuf)),
1719 source_port, 1689 destination_port,
1720 inet_ntop (af, 1690 inet_ntop (destination->details.exit_destination.af,
1721 destination_ip, 1691 &destination->details.exit_destination.ip,
1722 dbuf, 1692 xbuf,
1723 sizeof (dbuf)), 1693 sizeof (xbuf)),
1724 destination_port, 1694 destination_port);
1725 inet_ntop (destination->details.exit_destination.af,
1726 &destination->details.exit_destination.ip,
1727 xbuf, sizeof (xbuf)),
1728 destination_port);
1729 } 1695 }
1730 for (dt = destination->dt_head; NULL != dt; dt = dt->next) 1696 for (dt = destination->dt_head; NULL != dt; dt = dt->next)
1731 if (dt->destination_port == destination_port) 1697 if (dt->destination_port == destination_port)
1732 break; 1698 break;
1733 } 1699 }
1734 else 1700 else
1735 { 1701 {
@@ -1737,39 +1703,34 @@ route_packet (struct DestinationEntry *destination,
1737 char sbuf[INET6_ADDRSTRLEN]; 1703 char sbuf[INET6_ADDRSTRLEN];
1738 char dbuf[INET6_ADDRSTRLEN]; 1704 char dbuf[INET6_ADDRSTRLEN];
1739 1705
1740 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1706 GNUNET_log (
1741 "Routing %s packet from [%s]:%u -> [%s]:%u to service %s at peer %s\n", 1707 GNUNET_ERROR_TYPE_DEBUG,
1742 (protocol == IPPROTO_TCP) ? "TCP" : "UDP", 1708 "Routing %s packet from [%s]:%u -> [%s]:%u to service %s at peer %s\n",
1743 inet_ntop (af, 1709 (protocol == IPPROTO_TCP) ? "TCP" : "UDP",
1744 source_ip, 1710 inet_ntop (af, source_ip, sbuf, sizeof (sbuf)),
1745 sbuf, 1711 source_port,
1746 sizeof (sbuf)), 1712 inet_ntop (af, destination_ip, dbuf, sizeof (dbuf)),
1747 source_port, 1713 destination_port,
1748 inet_ntop (af, 1714 GNUNET_h2s (
1749 destination_ip, 1715 &destination->details.service_destination.service_descriptor),
1750 dbuf, 1716 GNUNET_i2s (&destination->details.service_destination.target));
1751 sizeof (dbuf)),
1752 destination_port,
1753 GNUNET_h2s (&destination->details.service_destination.service_descriptor),
1754 GNUNET_i2s (&destination->details.service_destination.target));
1755 } 1717 }
1756 for (dt = destination->dt_head; NULL != dt; dt = dt->next) 1718 for (dt = destination->dt_head; NULL != dt; dt = dt->next)
1757 if (dt->destination_port == destination_port) 1719 if (dt->destination_port == destination_port)
1758 break; 1720 break;
1759 } 1721 }
1760 if (NULL == dt) 1722 if (NULL == dt)
1761 { 1723 {
1762 dt = GNUNET_new (struct DestinationChannel); 1724 dt = GNUNET_new (struct DestinationChannel);
1763 dt->destination = destination; 1725 dt->destination = destination;
1764 GNUNET_CONTAINER_DLL_insert (destination->dt_head, 1726 GNUNET_CONTAINER_DLL_insert (destination->dt_head,
1765 destination->dt_tail, 1727 destination->dt_tail,
1766 dt); 1728 dt);
1767 dt->destination_port = destination_port; 1729 dt->destination_port = destination_port;
1768 } 1730 }
1769 1731
1770 /* see if we have an existing channel for this destination */ 1732 /* see if we have an existing channel for this destination */
1771 ts = GNUNET_CONTAINER_multihashmap_get (channel_map, 1733 ts = GNUNET_CONTAINER_multihashmap_get (channel_map, &key);
1772 &key);
1773 if (NULL == ts) 1734 if (NULL == ts)
1774 { 1735 {
1775 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1736 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -1777,8 +1738,7 @@ route_packet (struct DestinationEntry *destination,
1777 GNUNET_h2s (&key)); 1738 GNUNET_h2s (&key));
1778 /* need to either use the existing channel from the destination (if still 1739 /* need to either use the existing channel from the destination (if still
1779 available) or create a fresh one */ 1740 available) or create a fresh one */
1780 ts = create_channel_to_destination (dt, 1741 ts = create_channel_to_destination (dt, af);
1781 af);
1782 if (NULL == ts) 1742 if (NULL == ts)
1783 return; 1743 return;
1784 /* now bind existing "unbound" channel to our IP/port tuple */ 1744 /* now bind existing "unbound" channel to our IP/port tuple */
@@ -1786,46 +1746,51 @@ route_packet (struct DestinationEntry *destination,
1786 ts->af = af; 1746 ts->af = af;
1787 if (AF_INET == af) 1747 if (AF_INET == af)
1788 { 1748 {
1789 ts->source_ip.v4 = * (const struct in_addr *) source_ip; 1749 ts->source_ip.v4 = *(const struct in_addr *) source_ip;
1790 ts->destination_ip.v4 = * (const struct in_addr *) destination_ip; 1750 ts->destination_ip.v4 = *(const struct in_addr *) destination_ip;
1791 } 1751 }
1792 else 1752 else
1793 { 1753 {
1794 ts->source_ip.v6 = * (const struct in6_addr *) source_ip; 1754 ts->source_ip.v6 = *(const struct in6_addr *) source_ip;
1795 ts->destination_ip.v6 = * (const struct in6_addr *) destination_ip; 1755 ts->destination_ip.v6 = *(const struct in6_addr *) destination_ip;
1796 } 1756 }
1797 ts->source_port = source_port; 1757 ts->source_port = source_port;
1798 ts->destination_port = destination_port; 1758 ts->destination_port = destination_port;
1799 ts->heap_node = GNUNET_CONTAINER_heap_insert (channel_heap, 1759 ts->heap_node =
1800 ts, 1760 GNUNET_CONTAINER_heap_insert (channel_heap,
1801 GNUNET_TIME_absolute_get ().abs_value_us); 1761 ts,
1762 GNUNET_TIME_absolute_get ().abs_value_us);
1802 GNUNET_assert (GNUNET_YES == 1763 GNUNET_assert (GNUNET_YES ==
1803 GNUNET_CONTAINER_multihashmap_put (channel_map, 1764 GNUNET_CONTAINER_multihashmap_put (
1804 &key, 1765 channel_map,
1805 ts, 1766 &key,
1806 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 1767 ts,
1768 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
1807 GNUNET_STATISTICS_update (stats, 1769 GNUNET_STATISTICS_update (stats,
1808 gettext_noop ("# Active channels"), 1770 gettext_noop ("# Active channels"),
1809 1, GNUNET_NO); 1771 1,
1810 while (GNUNET_CONTAINER_multihashmap_size (channel_map) > max_channel_mappings) 1772 GNUNET_NO);
1773 while (GNUNET_CONTAINER_multihashmap_size (channel_map) >
1774 max_channel_mappings)
1811 expire_channel (ts); 1775 expire_channel (ts);
1812 } 1776 }
1813 else 1777 else
1814 { 1778 {
1815 GNUNET_CONTAINER_heap_update_cost (ts->heap_node, 1779 GNUNET_CONTAINER_heap_update_cost (ts->heap_node,
1816 GNUNET_TIME_absolute_get ().abs_value_us); 1780 GNUNET_TIME_absolute_get ()
1781 .abs_value_us);
1817 } 1782 }
1818 if (NULL == ts->channel) 1783 if (NULL == ts->channel)
1819 { 1784 {
1820 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1785 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1821 "Packet dropped, channel to %s not yet ready (%s)\n", 1786 "Packet dropped, channel to %s not yet ready (%s)\n",
1822 print_channel_destination (&ts->destination), 1787 print_channel_destination (&ts->destination),
1823 (NULL == ts->search) 1788 (NULL == ts->search) ? "EXIT search failed"
1824 ? "EXIT search failed" 1789 : "EXIT search active");
1825 : "EXIT search active");
1826 GNUNET_STATISTICS_update (stats, 1790 GNUNET_STATISTICS_update (stats,
1827 gettext_noop ("# Packets dropped (channel not yet online)"), 1791 gettext_noop (
1828 1, 1792 "# Packets dropped (channel not yet online)"),
1793 1,
1829 GNUNET_NO); 1794 GNUNET_NO);
1830 return; 1795 return;
1831 } 1796 }
@@ -1838,19 +1803,21 @@ route_packet (struct DestinationEntry *destination,
1838 { 1803 {
1839 struct GNUNET_EXIT_UdpServiceMessage *usm; 1804 struct GNUNET_EXIT_UdpServiceMessage *usm;
1840 1805
1841 mlen = sizeof (struct GNUNET_EXIT_UdpServiceMessage) + 1806 mlen = sizeof (struct GNUNET_EXIT_UdpServiceMessage) + payload_length -
1842 payload_length - sizeof (struct GNUNET_TUN_UdpHeader); 1807 sizeof (struct GNUNET_TUN_UdpHeader);
1843 if (mlen >= GNUNET_MAX_MESSAGE_SIZE) 1808 if (mlen >= GNUNET_MAX_MESSAGE_SIZE)
1844 { 1809 {
1845 GNUNET_break (0); 1810 GNUNET_break (0);
1846 return; 1811 return;
1847 } 1812 }
1848 env = GNUNET_MQ_msg_extra (usm, 1813 env = GNUNET_MQ_msg_extra (usm,
1849 payload_length - sizeof (struct GNUNET_TUN_UdpHeader), 1814 payload_length -
1815 sizeof (struct GNUNET_TUN_UdpHeader),
1850 GNUNET_MESSAGE_TYPE_VPN_UDP_TO_SERVICE); 1816 GNUNET_MESSAGE_TYPE_VPN_UDP_TO_SERVICE);
1851 /* if the source port is below 32000, we assume it has a special 1817 /* if the source port is below 32000, we assume it has a special
1852 meaning; if not, we pick a random port (this is a heuristic) */ 1818 meaning; if not, we pick a random port (this is a heuristic) */
1853 usm->source_port = (ntohs (udp->source_port) < 32000) ? udp->source_port : 0; 1819 usm->source_port =
1820 (ntohs (udp->source_port) < 32000) ? udp->source_port : 0;
1854 usm->destination_port = udp->destination_port; 1821 usm->destination_port = udp->destination_port;
1855 GNUNET_memcpy (&usm[1], 1822 GNUNET_memcpy (&usm[1],
1856 &udp[1], 1823 &udp[1],
@@ -1863,33 +1830,35 @@ route_packet (struct DestinationEntry *destination,
1863 struct in6_addr *ip6dst; 1830 struct in6_addr *ip6dst;
1864 void *payload; 1831 void *payload;
1865 1832
1866 mlen = sizeof (struct GNUNET_EXIT_UdpInternetMessage) + 1833 mlen = sizeof (struct GNUNET_EXIT_UdpInternetMessage) + alen +
1867 alen + payload_length - sizeof (struct GNUNET_TUN_UdpHeader); 1834 payload_length - sizeof (struct GNUNET_TUN_UdpHeader);
1868 if (mlen >= GNUNET_MAX_MESSAGE_SIZE) 1835 if (mlen >= GNUNET_MAX_MESSAGE_SIZE)
1869 { 1836 {
1870 GNUNET_break (0); 1837 GNUNET_break (0);
1871 return; 1838 return;
1872 } 1839 }
1873 env = GNUNET_MQ_msg_extra (uim, 1840 env = GNUNET_MQ_msg_extra (uim,
1874 payload_length + alen - sizeof (struct GNUNET_TUN_UdpHeader), 1841 payload_length + alen -
1842 sizeof (struct GNUNET_TUN_UdpHeader),
1875 GNUNET_MESSAGE_TYPE_VPN_UDP_TO_INTERNET); 1843 GNUNET_MESSAGE_TYPE_VPN_UDP_TO_INTERNET);
1876 uim->af = htonl (destination->details.exit_destination.af); 1844 uim->af = htonl (destination->details.exit_destination.af);
1877 uim->source_port = (ntohs (udp->source_port) < 32000) ? udp->source_port : 0; 1845 uim->source_port =
1846 (ntohs (udp->source_port) < 32000) ? udp->source_port : 0;
1878 uim->destination_port = udp->destination_port; 1847 uim->destination_port = udp->destination_port;
1879 switch (destination->details.exit_destination.af) 1848 switch (destination->details.exit_destination.af)
1880 { 1849 {
1881 case AF_INET: 1850 case AF_INET:
1882 ip4dst = (struct in_addr *) &uim[1]; 1851 ip4dst = (struct in_addr *) &uim[1];
1883 *ip4dst = destination->details.exit_destination.ip.v4; 1852 *ip4dst = destination->details.exit_destination.ip.v4;
1884 payload = &ip4dst[1]; 1853 payload = &ip4dst[1];
1885 break; 1854 break;
1886 case AF_INET6: 1855 case AF_INET6:
1887 ip6dst = (struct in6_addr *) &uim[1]; 1856 ip6dst = (struct in6_addr *) &uim[1];
1888 *ip6dst = destination->details.exit_destination.ip.v6; 1857 *ip6dst = destination->details.exit_destination.ip.v6;
1889 payload = &ip6dst[1]; 1858 payload = &ip6dst[1];
1890 break; 1859 break;
1891 default: 1860 default:
1892 GNUNET_assert (0); 1861 GNUNET_assert (0);
1893 } 1862 }
1894 GNUNET_memcpy (payload, 1863 GNUNET_memcpy (payload,
1895 &udp[1], 1864 &udp[1],
@@ -1901,59 +1870,63 @@ route_packet (struct DestinationEntry *destination,
1901 { 1870 {
1902 if (destination->is_service) 1871 if (destination->is_service)
1903 { 1872 {
1904 struct GNUNET_EXIT_TcpServiceStartMessage *tsm; 1873 struct GNUNET_EXIT_TcpServiceStartMessage *tsm;
1905 1874
1906 mlen = sizeof (struct GNUNET_EXIT_TcpServiceStartMessage) + 1875 mlen = sizeof (struct GNUNET_EXIT_TcpServiceStartMessage) +
1907 payload_length - sizeof (struct GNUNET_TUN_TcpHeader); 1876 payload_length - sizeof (struct GNUNET_TUN_TcpHeader);
1908 if (mlen >= GNUNET_MAX_MESSAGE_SIZE) 1877 if (mlen >= GNUNET_MAX_MESSAGE_SIZE)
1909 { 1878 {
1910 GNUNET_break (0); 1879 GNUNET_break (0);
1911 return; 1880 return;
1912 } 1881 }
1913 env = GNUNET_MQ_msg_extra (tsm, 1882 env =
1914 payload_length - sizeof (struct GNUNET_TUN_TcpHeader), 1883 GNUNET_MQ_msg_extra (tsm,
1915 GNUNET_MESSAGE_TYPE_VPN_TCP_TO_SERVICE_START); 1884 payload_length -
1916 tsm->reserved = htonl (0); 1885 sizeof (struct GNUNET_TUN_TcpHeader),
1917 tsm->tcp_header = *tcp; 1886 GNUNET_MESSAGE_TYPE_VPN_TCP_TO_SERVICE_START);
1918 GNUNET_memcpy (&tsm[1], 1887 tsm->reserved = htonl (0);
1888 tsm->tcp_header = *tcp;
1889 GNUNET_memcpy (&tsm[1],
1919 &tcp[1], 1890 &tcp[1],
1920 payload_length - sizeof (struct GNUNET_TUN_TcpHeader)); 1891 payload_length - sizeof (struct GNUNET_TUN_TcpHeader));
1921 } 1892 }
1922 else 1893 else
1923 { 1894 {
1924 struct GNUNET_EXIT_TcpInternetStartMessage *tim; 1895 struct GNUNET_EXIT_TcpInternetStartMessage *tim;
1925 struct in_addr *ip4dst; 1896 struct in_addr *ip4dst;
1926 struct in6_addr *ip6dst; 1897 struct in6_addr *ip6dst;
1927 void *payload; 1898 void *payload;
1928 1899
1929 mlen = sizeof (struct GNUNET_EXIT_TcpInternetStartMessage) + 1900 mlen = sizeof (struct GNUNET_EXIT_TcpInternetStartMessage) + alen +
1930 alen + payload_length - sizeof (struct GNUNET_TUN_TcpHeader); 1901 payload_length - sizeof (struct GNUNET_TUN_TcpHeader);
1931 if (mlen >= GNUNET_MAX_MESSAGE_SIZE) 1902 if (mlen >= GNUNET_MAX_MESSAGE_SIZE)
1932 { 1903 {
1933 GNUNET_break (0); 1904 GNUNET_break (0);
1934 return; 1905 return;
1935 } 1906 }
1936 env = GNUNET_MQ_msg_extra (tim, 1907 env =
1937 payload_length + alen - sizeof (struct GNUNET_TUN_TcpHeader), 1908 GNUNET_MQ_msg_extra (tim,
1938 GNUNET_MESSAGE_TYPE_VPN_TCP_TO_INTERNET_START); 1909 payload_length + alen -
1939 tim->af = htonl (destination->details.exit_destination.af); 1910 sizeof (struct GNUNET_TUN_TcpHeader),
1940 tim->tcp_header = *tcp; 1911 GNUNET_MESSAGE_TYPE_VPN_TCP_TO_INTERNET_START);
1941 switch (destination->details.exit_destination.af) 1912 tim->af = htonl (destination->details.exit_destination.af);
1942 { 1913 tim->tcp_header = *tcp;
1943 case AF_INET: 1914 switch (destination->details.exit_destination.af)
1944 ip4dst = (struct in_addr *) &tim[1]; 1915 {
1945 *ip4dst = destination->details.exit_destination.ip.v4; 1916 case AF_INET:
1946 payload = &ip4dst[1]; 1917 ip4dst = (struct in_addr *) &tim[1];
1947 break; 1918 *ip4dst = destination->details.exit_destination.ip.v4;
1948 case AF_INET6: 1919 payload = &ip4dst[1];
1949 ip6dst = (struct in6_addr *) &tim[1]; 1920 break;
1950 *ip6dst = destination->details.exit_destination.ip.v6; 1921 case AF_INET6:
1951 payload = &ip6dst[1]; 1922 ip6dst = (struct in6_addr *) &tim[1];
1952 break; 1923 *ip6dst = destination->details.exit_destination.ip.v6;
1953 default: 1924 payload = &ip6dst[1];
1954 GNUNET_assert (0); 1925 break;
1955 } 1926 default:
1956 GNUNET_memcpy (payload, 1927 GNUNET_assert (0);
1928 }
1929 GNUNET_memcpy (payload,
1957 &tcp[1], 1930 &tcp[1],
1958 payload_length - sizeof (struct GNUNET_TUN_TcpHeader)); 1931 payload_length - sizeof (struct GNUNET_TUN_TcpHeader));
1959 } 1932 }
@@ -1962,22 +1935,23 @@ route_packet (struct DestinationEntry *destination,
1962 { 1935 {
1963 struct GNUNET_EXIT_TcpDataMessage *tdm; 1936 struct GNUNET_EXIT_TcpDataMessage *tdm;
1964 1937
1965 mlen = sizeof (struct GNUNET_EXIT_TcpDataMessage) + 1938 mlen = sizeof (struct GNUNET_EXIT_TcpDataMessage) + payload_length -
1966 payload_length - sizeof (struct GNUNET_TUN_TcpHeader); 1939 sizeof (struct GNUNET_TUN_TcpHeader);
1967 if (mlen >= GNUNET_MAX_MESSAGE_SIZE) 1940 if (mlen >= GNUNET_MAX_MESSAGE_SIZE)
1968 { 1941 {
1969 GNUNET_break (0); 1942 GNUNET_break (0);
1970 return; 1943 return;
1971 } 1944 }
1972 env = GNUNET_MQ_msg_extra (tdm, 1945 env = GNUNET_MQ_msg_extra (tdm,
1973 payload_length - sizeof (struct GNUNET_TUN_TcpHeader), 1946 payload_length -
1947 sizeof (struct GNUNET_TUN_TcpHeader),
1974 GNUNET_MESSAGE_TYPE_VPN_TCP_DATA_TO_EXIT); 1948 GNUNET_MESSAGE_TYPE_VPN_TCP_DATA_TO_EXIT);
1975 tdm->reserved = htonl (0); 1949 tdm->reserved = htonl (0);
1976 tdm->tcp_header = *tcp; 1950 tdm->tcp_header = *tcp;
1977 GNUNET_memcpy (&tdm[1], 1951 GNUNET_memcpy (&tdm[1],
1978 &tcp[1], 1952 &tcp[1],
1979 payload_length - sizeof (struct GNUNET_TUN_TcpHeader)); 1953 payload_length - sizeof (struct GNUNET_TUN_TcpHeader));
1980 } 1954 }
1981 break; 1955 break;
1982 case IPPROTO_ICMP: 1956 case IPPROTO_ICMP:
1983 case IPPROTO_ICMPV6: 1957 case IPPROTO_ICMPV6:
@@ -1991,62 +1965,67 @@ route_packet (struct DestinationEntry *destination,
1991 switch (af) 1965 switch (af)
1992 { 1966 {
1993 case AF_INET: 1967 case AF_INET:
1994 switch (icmp->type) 1968 switch (icmp->type)
1995 { 1969 {
1996 case GNUNET_TUN_ICMPTYPE_ECHO_REPLY: 1970 case GNUNET_TUN_ICMPTYPE_ECHO_REPLY:
1997 case GNUNET_TUN_ICMPTYPE_ECHO_REQUEST: 1971 case GNUNET_TUN_ICMPTYPE_ECHO_REQUEST:
1998 break; 1972 break;
1999 case GNUNET_TUN_ICMPTYPE_DESTINATION_UNREACHABLE: 1973 case GNUNET_TUN_ICMPTYPE_DESTINATION_UNREACHABLE:
2000 case GNUNET_TUN_ICMPTYPE_SOURCE_QUENCH: 1974 case GNUNET_TUN_ICMPTYPE_SOURCE_QUENCH:
2001 case GNUNET_TUN_ICMPTYPE_TIME_EXCEEDED: 1975 case GNUNET_TUN_ICMPTYPE_TIME_EXCEEDED:
2002 /* throw away ICMP payload, won't be useful for the other side anyway */ 1976 /* throw away ICMP payload, won't be useful for the other side anyway */
2003 payload_length = sizeof (struct GNUNET_TUN_IcmpHeader); 1977 payload_length = sizeof (struct GNUNET_TUN_IcmpHeader);
2004 break; 1978 break;
2005 default: 1979 default:
2006 GNUNET_STATISTICS_update (stats, 1980 GNUNET_STATISTICS_update (stats,
2007 gettext_noop ("# ICMPv4 packets dropped (not allowed)"), 1981 gettext_noop (
2008 1, GNUNET_NO); 1982 "# ICMPv4 packets dropped (not allowed)"),
2009 return; 1983 1,
2010 } 1984 GNUNET_NO);
2011 /* end of AF_INET */ 1985 return;
2012 break; 1986 }
1987 /* end of AF_INET */
1988 break;
2013 case AF_INET6: 1989 case AF_INET6:
2014 switch (icmp->type) 1990 switch (icmp->type)
2015 { 1991 {
2016 case GNUNET_TUN_ICMPTYPE6_DESTINATION_UNREACHABLE: 1992 case GNUNET_TUN_ICMPTYPE6_DESTINATION_UNREACHABLE:
2017 case GNUNET_TUN_ICMPTYPE6_PACKET_TOO_BIG: 1993 case GNUNET_TUN_ICMPTYPE6_PACKET_TOO_BIG:
2018 case GNUNET_TUN_ICMPTYPE6_TIME_EXCEEDED: 1994 case GNUNET_TUN_ICMPTYPE6_TIME_EXCEEDED:
2019 case GNUNET_TUN_ICMPTYPE6_PARAMETER_PROBLEM: 1995 case GNUNET_TUN_ICMPTYPE6_PARAMETER_PROBLEM:
2020 /* throw away ICMP payload, won't be useful for the other side anyway */ 1996 /* throw away ICMP payload, won't be useful for the other side anyway */
2021 payload_length = sizeof (struct GNUNET_TUN_IcmpHeader); 1997 payload_length = sizeof (struct GNUNET_TUN_IcmpHeader);
2022 break; 1998 break;
2023 case GNUNET_TUN_ICMPTYPE6_ECHO_REQUEST: 1999 case GNUNET_TUN_ICMPTYPE6_ECHO_REQUEST:
2024 case GNUNET_TUN_ICMPTYPE6_ECHO_REPLY: 2000 case GNUNET_TUN_ICMPTYPE6_ECHO_REPLY:
2025 break; 2001 break;
2026 default: 2002 default:
2027 GNUNET_STATISTICS_update (stats, 2003 GNUNET_STATISTICS_update (stats,
2028 gettext_noop ("# ICMPv6 packets dropped (not allowed)"), 2004 gettext_noop (
2029 1, GNUNET_NO); 2005 "# ICMPv6 packets dropped (not allowed)"),
2030 return; 2006 1,
2031 } 2007 GNUNET_NO);
2032 /* end of AF_INET6 */ 2008 return;
2033 break; 2009 }
2010 /* end of AF_INET6 */
2011 break;
2034 default: 2012 default:
2035 GNUNET_assert (0); 2013 GNUNET_assert (0);
2036 break; 2014 break;
2037 } 2015 }
2038 2016
2039 /* update length calculations, as payload_length may have changed */ 2017 /* update length calculations, as payload_length may have changed */
2040 mlen = sizeof (struct GNUNET_EXIT_IcmpServiceMessage) + 2018 mlen = sizeof (struct GNUNET_EXIT_IcmpServiceMessage) + alen +
2041 alen + payload_length - sizeof (struct GNUNET_TUN_IcmpHeader); 2019 payload_length - sizeof (struct GNUNET_TUN_IcmpHeader);
2042 if (mlen >= GNUNET_MAX_MESSAGE_SIZE) 2020 if (mlen >= GNUNET_MAX_MESSAGE_SIZE)
2043 { 2021 {
2044 GNUNET_break (0); 2022 GNUNET_break (0);
2045 return; 2023 return;
2046 } 2024 }
2047 2025
2048 env = GNUNET_MQ_msg_extra (ism, 2026 env = GNUNET_MQ_msg_extra (ism,
2049 payload_length - sizeof (struct GNUNET_TUN_IcmpHeader), 2027 payload_length -
2028 sizeof (struct GNUNET_TUN_IcmpHeader),
2050 GNUNET_MESSAGE_TYPE_VPN_ICMP_TO_SERVICE); 2029 GNUNET_MESSAGE_TYPE_VPN_ICMP_TO_SERVICE);
2051 ism->af = htonl (af); /* need to tell destination ICMP protocol family! */ 2030 ism->af = htonl (af); /* need to tell destination ICMP protocol family! */
2052 ism->icmp_header = *icmp; 2031 ism->icmp_header = *icmp;
@@ -2068,114 +2047,125 @@ route_packet (struct DestinationEntry *destination,
2068 switch (af) 2047 switch (af)
2069 { 2048 {
2070 case AF_INET: 2049 case AF_INET:
2071 switch (icmp->type) 2050 switch (icmp->type)
2072 { 2051 {
2073 case GNUNET_TUN_ICMPTYPE_ECHO_REPLY: 2052 case GNUNET_TUN_ICMPTYPE_ECHO_REPLY:
2074 if (destination->details.exit_destination.af == AF_INET6) 2053 if (destination->details.exit_destination.af == AF_INET6)
2075 new_type = GNUNET_TUN_ICMPTYPE6_ECHO_REPLY; 2054 new_type = GNUNET_TUN_ICMPTYPE6_ECHO_REPLY;
2076 break; 2055 break;
2077 case GNUNET_TUN_ICMPTYPE_ECHO_REQUEST: 2056 case GNUNET_TUN_ICMPTYPE_ECHO_REQUEST:
2078 if (destination->details.exit_destination.af == AF_INET6) 2057 if (destination->details.exit_destination.af == AF_INET6)
2079 new_type = GNUNET_TUN_ICMPTYPE6_ECHO_REQUEST; 2058 new_type = GNUNET_TUN_ICMPTYPE6_ECHO_REQUEST;
2080 break; 2059 break;
2081 case GNUNET_TUN_ICMPTYPE_DESTINATION_UNREACHABLE: 2060 case GNUNET_TUN_ICMPTYPE_DESTINATION_UNREACHABLE:
2082 if (destination->details.exit_destination.af == AF_INET6) 2061 if (destination->details.exit_destination.af == AF_INET6)
2083 new_type = GNUNET_TUN_ICMPTYPE6_DESTINATION_UNREACHABLE; 2062 new_type = GNUNET_TUN_ICMPTYPE6_DESTINATION_UNREACHABLE;
2084 /* throw away IP-payload, exit will have to make it up anyway */ 2063 /* throw away IP-payload, exit will have to make it up anyway */
2085 payload_length = sizeof (struct GNUNET_TUN_IcmpHeader); 2064 payload_length = sizeof (struct GNUNET_TUN_IcmpHeader);
2086 break; 2065 break;
2087 case GNUNET_TUN_ICMPTYPE_TIME_EXCEEDED: 2066 case GNUNET_TUN_ICMPTYPE_TIME_EXCEEDED:
2088 if (destination->details.exit_destination.af == AF_INET6) 2067 if (destination->details.exit_destination.af == AF_INET6)
2089 new_type = GNUNET_TUN_ICMPTYPE6_TIME_EXCEEDED; 2068 new_type = GNUNET_TUN_ICMPTYPE6_TIME_EXCEEDED;
2090 /* throw away IP-payload, exit will have to make it up anyway */ 2069 /* throw away IP-payload, exit will have to make it up anyway */
2091 payload_length = sizeof (struct GNUNET_TUN_IcmpHeader); 2070 payload_length = sizeof (struct GNUNET_TUN_IcmpHeader);
2092 break; 2071 break;
2093 case GNUNET_TUN_ICMPTYPE_SOURCE_QUENCH: 2072 case GNUNET_TUN_ICMPTYPE_SOURCE_QUENCH:
2094 if (destination->details.exit_destination.af == AF_INET6) 2073 if (destination->details.exit_destination.af == AF_INET6)
2095 { 2074 {
2096 GNUNET_STATISTICS_update (stats, 2075 GNUNET_STATISTICS_update (
2097 gettext_noop ("# ICMPv4 packets dropped (impossible PT to v6)"), 2076 stats,
2098 1, GNUNET_NO); 2077 gettext_noop ("# ICMPv4 packets dropped (impossible PT to v6)"),
2099 return; 2078 1,
2100 } 2079 GNUNET_NO);
2101 /* throw away IP-payload, exit will have to make it up anyway */ 2080 return;
2102 payload_length = sizeof (struct GNUNET_TUN_IcmpHeader); 2081 }
2103 break; 2082 /* throw away IP-payload, exit will have to make it up anyway */
2104 default: 2083 payload_length = sizeof (struct GNUNET_TUN_IcmpHeader);
2105 GNUNET_STATISTICS_update (stats, 2084 break;
2106 gettext_noop ("# ICMPv4 packets dropped (type not allowed)"), 2085 default:
2107 1, GNUNET_NO); 2086 GNUNET_STATISTICS_update (
2108 return; 2087 stats,
2109 } 2088 gettext_noop ("# ICMPv4 packets dropped (type not allowed)"),
2110 /* end of AF_INET */ 2089 1,
2111 break; 2090 GNUNET_NO);
2091 return;
2092 }
2093 /* end of AF_INET */
2094 break;
2112 case AF_INET6: 2095 case AF_INET6:
2113 switch (icmp->type) 2096 switch (icmp->type)
2114 { 2097 {
2115 case GNUNET_TUN_ICMPTYPE6_DESTINATION_UNREACHABLE: 2098 case GNUNET_TUN_ICMPTYPE6_DESTINATION_UNREACHABLE:
2116 if (destination->details.exit_destination.af == AF_INET) 2099 if (destination->details.exit_destination.af == AF_INET)
2117 new_type = GNUNET_TUN_ICMPTYPE_DESTINATION_UNREACHABLE; 2100 new_type = GNUNET_TUN_ICMPTYPE_DESTINATION_UNREACHABLE;
2118 /* throw away IP-payload, exit will have to make it up anyway */ 2101 /* throw away IP-payload, exit will have to make it up anyway */
2119 payload_length = sizeof (struct GNUNET_TUN_IcmpHeader); 2102 payload_length = sizeof (struct GNUNET_TUN_IcmpHeader);
2120 break; 2103 break;
2121 case GNUNET_TUN_ICMPTYPE6_TIME_EXCEEDED: 2104 case GNUNET_TUN_ICMPTYPE6_TIME_EXCEEDED:
2122 if (destination->details.exit_destination.af == AF_INET) 2105 if (destination->details.exit_destination.af == AF_INET)
2123 new_type = GNUNET_TUN_ICMPTYPE_TIME_EXCEEDED; 2106 new_type = GNUNET_TUN_ICMPTYPE_TIME_EXCEEDED;
2124 /* throw away IP-payload, exit will have to make it up anyway */ 2107 /* throw away IP-payload, exit will have to make it up anyway */
2125 payload_length = sizeof (struct GNUNET_TUN_IcmpHeader); 2108 payload_length = sizeof (struct GNUNET_TUN_IcmpHeader);
2126 break; 2109 break;
2127 case GNUNET_TUN_ICMPTYPE6_PACKET_TOO_BIG: 2110 case GNUNET_TUN_ICMPTYPE6_PACKET_TOO_BIG:
2128 if (destination->details.exit_destination.af == AF_INET) 2111 if (destination->details.exit_destination.af == AF_INET)
2129 { 2112 {
2130 GNUNET_STATISTICS_update (stats, 2113 GNUNET_STATISTICS_update (
2131 gettext_noop ("# ICMPv6 packets dropped (impossible PT to v4)"), 2114 stats,
2132 1, GNUNET_NO); 2115 gettext_noop ("# ICMPv6 packets dropped (impossible PT to v4)"),
2133 return; 2116 1,
2134 } 2117 GNUNET_NO);
2135 /* throw away IP-payload, exit will have to make it up anyway */ 2118 return;
2136 payload_length = sizeof (struct GNUNET_TUN_IcmpHeader); 2119 }
2137 break; 2120 /* throw away IP-payload, exit will have to make it up anyway */
2138 case GNUNET_TUN_ICMPTYPE6_PARAMETER_PROBLEM: 2121 payload_length = sizeof (struct GNUNET_TUN_IcmpHeader);
2139 if (destination->details.exit_destination.af == AF_INET) 2122 break;
2140 { 2123 case GNUNET_TUN_ICMPTYPE6_PARAMETER_PROBLEM:
2141 GNUNET_STATISTICS_update (stats, 2124 if (destination->details.exit_destination.af == AF_INET)
2142 gettext_noop ("# ICMPv6 packets dropped (impossible PT to v4)"), 2125 {
2143 1, GNUNET_NO); 2126 GNUNET_STATISTICS_update (
2144 return; 2127 stats,
2145 } 2128 gettext_noop ("# ICMPv6 packets dropped (impossible PT to v4)"),
2146 /* throw away IP-payload, exit will have to make it up anyway */ 2129 1,
2147 payload_length = sizeof (struct GNUNET_TUN_IcmpHeader); 2130 GNUNET_NO);
2148 break; 2131 return;
2149 case GNUNET_TUN_ICMPTYPE6_ECHO_REQUEST: 2132 }
2150 if (destination->details.exit_destination.af == AF_INET) 2133 /* throw away IP-payload, exit will have to make it up anyway */
2151 new_type = GNUNET_TUN_ICMPTYPE_ECHO_REQUEST; 2134 payload_length = sizeof (struct GNUNET_TUN_IcmpHeader);
2152 break; 2135 break;
2153 case GNUNET_TUN_ICMPTYPE6_ECHO_REPLY: 2136 case GNUNET_TUN_ICMPTYPE6_ECHO_REQUEST:
2154 if (destination->details.exit_destination.af == AF_INET) 2137 if (destination->details.exit_destination.af == AF_INET)
2155 new_type = GNUNET_TUN_ICMPTYPE_ECHO_REPLY; 2138 new_type = GNUNET_TUN_ICMPTYPE_ECHO_REQUEST;
2156 break; 2139 break;
2157 default: 2140 case GNUNET_TUN_ICMPTYPE6_ECHO_REPLY:
2158 GNUNET_STATISTICS_update (stats, 2141 if (destination->details.exit_destination.af == AF_INET)
2159 gettext_noop ("# ICMPv6 packets dropped (type not allowed)"), 2142 new_type = GNUNET_TUN_ICMPTYPE_ECHO_REPLY;
2160 1, GNUNET_NO); 2143 break;
2161 return; 2144 default:
2162 } 2145 GNUNET_STATISTICS_update (
2163 /* end of AF_INET6 */ 2146 stats,
2164 break; 2147 gettext_noop ("# ICMPv6 packets dropped (type not allowed)"),
2148 1,
2149 GNUNET_NO);
2150 return;
2151 }
2152 /* end of AF_INET6 */
2153 break;
2165 default: 2154 default:
2166 GNUNET_assert (0); 2155 GNUNET_assert (0);
2167 } 2156 }
2168 2157
2169 /* update length calculations, as payload_length may have changed */ 2158 /* update length calculations, as payload_length may have changed */
2170 mlen = sizeof (struct GNUNET_EXIT_IcmpInternetMessage) + 2159 mlen = sizeof (struct GNUNET_EXIT_IcmpInternetMessage) + alen +
2171 alen + payload_length - sizeof (struct GNUNET_TUN_IcmpHeader); 2160 payload_length - sizeof (struct GNUNET_TUN_IcmpHeader);
2172 if (mlen >= GNUNET_MAX_MESSAGE_SIZE) 2161 if (mlen >= GNUNET_MAX_MESSAGE_SIZE)
2173 { 2162 {
2174 GNUNET_break (0); 2163 GNUNET_break (0);
2175 return; 2164 return;
2176 } 2165 }
2177 env = GNUNET_MQ_msg_extra (iim, 2166 env = GNUNET_MQ_msg_extra (iim,
2178 alen + payload_length - sizeof (struct GNUNET_TUN_IcmpHeader), 2167 alen + payload_length -
2168 sizeof (struct GNUNET_TUN_IcmpHeader),
2179 GNUNET_MESSAGE_TYPE_VPN_ICMP_TO_INTERNET); 2169 GNUNET_MESSAGE_TYPE_VPN_ICMP_TO_INTERNET);
2180 iim->icmp_header = *icmp; 2170 iim->icmp_header = *icmp;
2181 iim->icmp_header.type = new_type; 2171 iim->icmp_header.type = new_type;
@@ -2183,17 +2173,17 @@ route_packet (struct DestinationEntry *destination,
2183 switch (destination->details.exit_destination.af) 2173 switch (destination->details.exit_destination.af)
2184 { 2174 {
2185 case AF_INET: 2175 case AF_INET:
2186 ip4dst = (struct in_addr *) &iim[1]; 2176 ip4dst = (struct in_addr *) &iim[1];
2187 *ip4dst = destination->details.exit_destination.ip.v4; 2177 *ip4dst = destination->details.exit_destination.ip.v4;
2188 payload = &ip4dst[1]; 2178 payload = &ip4dst[1];
2189 break; 2179 break;
2190 case AF_INET6: 2180 case AF_INET6:
2191 ip6dst = (struct in6_addr *) &iim[1]; 2181 ip6dst = (struct in6_addr *) &iim[1];
2192 *ip6dst = destination->details.exit_destination.ip.v6; 2182 *ip6dst = destination->details.exit_destination.ip.v6;
2193 payload = &ip6dst[1]; 2183 payload = &ip6dst[1];
2194 break; 2184 break;
2195 default: 2185 default:
2196 GNUNET_assert (0); 2186 GNUNET_assert (0);
2197 } 2187 }
2198 GNUNET_memcpy (payload, 2188 GNUNET_memcpy (payload,
2199 &icmp[1], 2189 &icmp[1],
@@ -2206,8 +2196,7 @@ route_packet (struct DestinationEntry *destination,
2206 break; 2196 break;
2207 } 2197 }
2208 ts->is_established = GNUNET_YES; 2198 ts->is_established = GNUNET_YES;
2209 send_to_channel (ts, 2199 send_to_channel (ts, env);
2210 env);
2211} 2200}
2212 2201
2213 2202
@@ -2224,8 +2213,7 @@ route_packet (struct DestinationEntry *destination,
2224 * #GNUNET_SYSERR to stop further processing with error 2213 * #GNUNET_SYSERR to stop further processing with error
2225 */ 2214 */
2226static int 2215static int
2227message_token (void *cls, 2216message_token (void *cls, const struct GNUNET_MessageHeader *message)
2228 const struct GNUNET_MessageHeader *message)
2229{ 2217{
2230 const struct GNUNET_TUN_Layer2PacketHeader *tun; 2218 const struct GNUNET_TUN_Layer2PacketHeader *tun;
2231 size_t mlen; 2219 size_t mlen;
@@ -2233,101 +2221,96 @@ message_token (void *cls,
2233 struct DestinationEntry *de; 2221 struct DestinationEntry *de;
2234 2222
2235 GNUNET_STATISTICS_update (stats, 2223 GNUNET_STATISTICS_update (stats,
2236 gettext_noop ("# Packets received from TUN interface"), 2224 gettext_noop (
2237 1, GNUNET_NO); 2225 "# Packets received from TUN interface"),
2226 1,
2227 GNUNET_NO);
2238 mlen = ntohs (message->size); 2228 mlen = ntohs (message->size);
2239 if ( (ntohs (message->type) != GNUNET_MESSAGE_TYPE_VPN_HELPER) || 2229 if ((ntohs (message->type) != GNUNET_MESSAGE_TYPE_VPN_HELPER) ||
2240 (mlen < sizeof (struct GNUNET_MessageHeader) + sizeof (struct GNUNET_TUN_Layer2PacketHeader)) ) 2230 (mlen < sizeof (struct GNUNET_MessageHeader) +
2231 sizeof (struct GNUNET_TUN_Layer2PacketHeader)))
2241 { 2232 {
2242 GNUNET_break (0); 2233 GNUNET_break (0);
2243 return GNUNET_OK; 2234 return GNUNET_OK;
2244 } 2235 }
2245 tun = (const struct GNUNET_TUN_Layer2PacketHeader *) &message[1]; 2236 tun = (const struct GNUNET_TUN_Layer2PacketHeader *) &message[1];
2246 mlen -= (sizeof (struct GNUNET_MessageHeader) + sizeof (struct GNUNET_TUN_Layer2PacketHeader)); 2237 mlen -= (sizeof (struct GNUNET_MessageHeader) +
2238 sizeof (struct GNUNET_TUN_Layer2PacketHeader));
2247 switch (ntohs (tun->proto)) 2239 switch (ntohs (tun->proto))
2248 { 2240 {
2249 case ETH_P_IPV6: 2241 case ETH_P_IPV6: {
2242 const struct GNUNET_TUN_IPv6Header *pkt6;
2243
2244 if (mlen < sizeof (struct GNUNET_TUN_IPv6Header))
2245 {
2246 /* blame kernel */
2247 GNUNET_break (0);
2248 return GNUNET_OK;
2249 }
2250 pkt6 = (const struct GNUNET_TUN_IPv6Header *) &tun[1];
2251 get_destination_key_from_ip (AF_INET6, &pkt6->destination_address, &key);
2252 de = GNUNET_CONTAINER_multihashmap_get (destination_map, &key);
2253 if (NULL == de)
2250 { 2254 {
2251 const struct GNUNET_TUN_IPv6Header *pkt6; 2255 char buf[INET6_ADDRSTRLEN];
2252 2256
2253 if (mlen < sizeof (struct GNUNET_TUN_IPv6Header)) 2257 GNUNET_log (
2254 { 2258 GNUNET_ERROR_TYPE_INFO,
2255 /* blame kernel */ 2259 _ ("Packet received for unmapped destination `%s' (dropping it)\n"),
2256 GNUNET_break (0); 2260 inet_ntop (AF_INET6, &pkt6->destination_address, buf, sizeof (buf)));
2257 return GNUNET_OK; 2261 return GNUNET_OK;
2258 }
2259 pkt6 = (const struct GNUNET_TUN_IPv6Header *) &tun[1];
2260 get_destination_key_from_ip (AF_INET6,
2261 &pkt6->destination_address,
2262 &key);
2263 de = GNUNET_CONTAINER_multihashmap_get (destination_map, &key);
2264 if (NULL == de)
2265 {
2266 char buf[INET6_ADDRSTRLEN];
2267
2268 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
2269 _("Packet received for unmapped destination `%s' (dropping it)\n"),
2270 inet_ntop (AF_INET6,
2271 &pkt6->destination_address,
2272 buf,
2273 sizeof (buf)));
2274 return GNUNET_OK;
2275 }
2276 route_packet (de,
2277 AF_INET6,
2278 pkt6->next_header,
2279 &pkt6->source_address,
2280 &pkt6->destination_address,
2281 &pkt6[1],
2282 mlen - sizeof (struct GNUNET_TUN_IPv6Header));
2283 } 2262 }
2284 break; 2263 route_packet (de,
2285 case ETH_P_IPV4: 2264 AF_INET6,
2265 pkt6->next_header,
2266 &pkt6->source_address,
2267 &pkt6->destination_address,
2268 &pkt6[1],
2269 mlen - sizeof (struct GNUNET_TUN_IPv6Header));
2270 }
2271 break;
2272 case ETH_P_IPV4: {
2273 struct GNUNET_TUN_IPv4Header *pkt4;
2274
2275 if (mlen < sizeof (struct GNUNET_TUN_IPv4Header))
2286 { 2276 {
2287 struct GNUNET_TUN_IPv4Header *pkt4; 2277 /* blame kernel */
2278 GNUNET_break (0);
2279 return GNUNET_OK;
2280 }
2281 pkt4 = (struct GNUNET_TUN_IPv4Header *) &tun[1];
2282 get_destination_key_from_ip (AF_INET, &pkt4->destination_address, &key);
2283 de = GNUNET_CONTAINER_multihashmap_get (destination_map, &key);
2284 if (NULL == de)
2285 {
2286 char buf[INET_ADDRSTRLEN];
2288 2287
2289 if (mlen < sizeof (struct GNUNET_TUN_IPv4Header)) 2288 GNUNET_log (
2290 { 2289 GNUNET_ERROR_TYPE_INFO,
2291 /* blame kernel */ 2290 _ ("Packet received for unmapped destination `%s' (dropping it)\n"),
2292 GNUNET_break (0); 2291 inet_ntop (AF_INET, &pkt4->destination_address, buf, sizeof (buf)));
2293 return GNUNET_OK; 2292 return GNUNET_OK;
2294 }
2295 pkt4 = (struct GNUNET_TUN_IPv4Header *) &tun[1];
2296 get_destination_key_from_ip (AF_INET,
2297 &pkt4->destination_address,
2298 &key);
2299 de = GNUNET_CONTAINER_multihashmap_get (destination_map, &key);
2300 if (NULL == de)
2301 {
2302 char buf[INET_ADDRSTRLEN];
2303
2304 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
2305 _("Packet received for unmapped destination `%s' (dropping it)\n"),
2306 inet_ntop (AF_INET,
2307 &pkt4->destination_address,
2308 buf,
2309 sizeof (buf)));
2310 return GNUNET_OK;
2311 }
2312 if (pkt4->header_length * 4 != sizeof (struct GNUNET_TUN_IPv4Header))
2313 {
2314 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
2315 _("Received IPv4 packet with options (dropping it)\n"));
2316 return GNUNET_OK;
2317 }
2318 route_packet (de,
2319 AF_INET,
2320 pkt4->protocol,
2321 &pkt4->source_address,
2322 &pkt4->destination_address,
2323 &pkt4[1],
2324 mlen - sizeof (struct GNUNET_TUN_IPv4Header));
2325 } 2293 }
2326 break; 2294 if (pkt4->header_length * 4 != sizeof (struct GNUNET_TUN_IPv4Header))
2295 {
2296 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
2297 _ ("Received IPv4 packet with options (dropping it)\n"));
2298 return GNUNET_OK;
2299 }
2300 route_packet (de,
2301 AF_INET,
2302 pkt4->protocol,
2303 &pkt4->source_address,
2304 &pkt4->destination_address,
2305 &pkt4[1],
2306 mlen - sizeof (struct GNUNET_TUN_IPv4Header));
2307 }
2308 break;
2327 default: 2309 default:
2328 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 2310 GNUNET_log (
2329 _("Received packet of unknown protocol %d from TUN (dropping it)\n"), 2311 GNUNET_ERROR_TYPE_INFO,
2330 (unsigned int) ntohs (tun->proto)); 2312 _ ("Received packet of unknown protocol %d from TUN (dropping it)\n"),
2313 (unsigned int) ntohs (tun->proto));
2331 break; 2314 break;
2332 } 2315 }
2333 return GNUNET_OK; 2316 return GNUNET_OK;
@@ -2360,27 +2343,23 @@ allocate_v4_address (struct in_addr *v4)
2360 mask.s_addr = addr.s_addr | ~mask.s_addr; 2343 mask.s_addr = addr.s_addr | ~mask.s_addr;
2361 tries = 0; 2344 tries = 0;
2362 do 2345 do
2346 {
2347 tries++;
2348 if (tries > 16)
2363 { 2349 {
2364 tries++; 2350 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2365 if (tries > 16) 2351 _ (
2366 { 2352 "Failed to find unallocated IPv4 address in VPN's range\n"));
2367 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 2353 return GNUNET_SYSERR;
2368 _("Failed to find unallocated IPv4 address in VPN's range\n"));
2369 return GNUNET_SYSERR;
2370 }
2371 /* Pick random IPv4 address within the subnet, except 'addr' or 'mask' itself */
2372 rnd.s_addr = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
2373 UINT32_MAX);
2374 v4->s_addr = (addr.s_addr | rnd.s_addr) & mask.s_addr;
2375 get_destination_key_from_ip (AF_INET,
2376 v4,
2377 &key);
2378 } 2354 }
2379 while ( (GNUNET_YES == 2355 /* Pick random IPv4 address within the subnet, except 'addr' or 'mask' itself */
2380 GNUNET_CONTAINER_multihashmap_contains (destination_map, 2356 rnd.s_addr =
2381 &key)) || 2357 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, UINT32_MAX);
2382 (v4->s_addr == addr.s_addr) || 2358 v4->s_addr = (addr.s_addr | rnd.s_addr) & mask.s_addr;
2383 (v4->s_addr == mask.s_addr) ); 2359 get_destination_key_from_ip (AF_INET, v4, &key);
2360 } while ((GNUNET_YES ==
2361 GNUNET_CONTAINER_multihashmap_contains (destination_map, &key)) ||
2362 (v4->s_addr == addr.s_addr) || (v4->s_addr == mask.s_addr));
2384 return GNUNET_OK; 2363 return GNUNET_OK;
2385} 2364}
2386 2365
@@ -2409,39 +2388,33 @@ allocate_v6_address (struct in6_addr *v6)
2409 /* Given ABCD::/96, we want a mask of 'ABCD::FFFF:FFFF, 2388 /* Given ABCD::/96, we want a mask of 'ABCD::FFFF:FFFF,
2410 thus: */ 2389 thus: */
2411 mask = addr; 2390 mask = addr;
2412 for (i=127;i>=ipv6prefix;i--) 2391 for (i = 127; i >= ipv6prefix; i--)
2413 mask.s6_addr[i / 8] |= (1 << (i % 8)); 2392 mask.s6_addr[i / 8] |= (1 << (i % 8));
2414 2393
2415 /* Pick random IPv6 address within the subnet, except 'addr' or 'mask' itself */ 2394 /* Pick random IPv6 address within the subnet, except 'addr' or 'mask' itself */
2416 tries = 0; 2395 tries = 0;
2417 do 2396 do
2397 {
2398 tries++;
2399 if (tries > 16)
2418 { 2400 {
2419 tries++; 2401 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2420 if (tries > 16) 2402 _ (
2421 { 2403 "Failed to find unallocated IPv6 address in VPN's range\n"));
2422 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 2404 return GNUNET_SYSERR;
2423 _("Failed to find unallocated IPv6 address in VPN's range\n"));
2424 return GNUNET_SYSERR;
2425
2426 }
2427 for (i=0;i<16;i++)
2428 {
2429 rnd.s6_addr[i] = (unsigned char) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
2430 256);
2431 v6->s6_addr[i]
2432 = (addr.s6_addr[i] | rnd.s6_addr[i]) & mask.s6_addr[i];
2433 }
2434 get_destination_key_from_ip (AF_INET6,
2435 v6,
2436 &key);
2437 } 2405 }
2438 while ( (GNUNET_YES == 2406 for (i = 0; i < 16; i++)
2439 GNUNET_CONTAINER_multihashmap_contains (destination_map, 2407 {
2440 &key)) || 2408 rnd.s6_addr[i] =
2441 (0 == GNUNET_memcmp (v6, 2409 (unsigned char) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
2442 &addr)) || 2410 256);
2443 (0 == GNUNET_memcmp (v6, 2411 v6->s6_addr[i] = (addr.s6_addr[i] | rnd.s6_addr[i]) & mask.s6_addr[i];
2444 &mask)) ); 2412 }
2413 get_destination_key_from_ip (AF_INET6, v6, &key);
2414 } while ((GNUNET_YES ==
2415 GNUNET_CONTAINER_multihashmap_contains (destination_map, &key)) ||
2416 (0 == GNUNET_memcmp (v6, &addr)) ||
2417 (0 == GNUNET_memcmp (v6, &mask)));
2445 return GNUNET_OK; 2418 return GNUNET_OK;
2446} 2419}
2447 2420
@@ -2457,26 +2430,24 @@ free_destination_entry (struct DestinationEntry *de)
2457 struct DestinationChannel *dt; 2430 struct DestinationChannel *dt;
2458 2431
2459 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2432 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2460 "Cleaning up destination entry `%s'\n", 2433 "Cleaning up destination entry `%s'\n",
2461 print_channel_destination (de)); 2434 print_channel_destination (de));
2462 GNUNET_STATISTICS_update (stats, 2435 GNUNET_STATISTICS_update (stats,
2463 gettext_noop ("# Active destinations"), 2436 gettext_noop ("# Active destinations"),
2464 -1, GNUNET_NO); 2437 -1,
2438 GNUNET_NO);
2465 while (NULL != (dt = de->dt_head)) 2439 while (NULL != (dt = de->dt_head))
2466 { 2440 {
2467 GNUNET_CONTAINER_DLL_remove (de->dt_head, 2441 GNUNET_CONTAINER_DLL_remove (de->dt_head, de->dt_tail, dt);
2468 de->dt_tail,
2469 dt);
2470 GNUNET_free (dt); 2442 GNUNET_free (dt);
2471 } 2443 }
2472 if (NULL != de->heap_node) 2444 if (NULL != de->heap_node)
2473 { 2445 {
2474 GNUNET_CONTAINER_heap_remove_node (de->heap_node); 2446 GNUNET_CONTAINER_heap_remove_node (de->heap_node);
2475 de->heap_node = NULL; 2447 de->heap_node = NULL;
2476 GNUNET_assert (GNUNET_YES == 2448 GNUNET_assert (
2477 GNUNET_CONTAINER_multihashmap_remove (destination_map, 2449 GNUNET_YES ==
2478 &de->key, 2450 GNUNET_CONTAINER_multihashmap_remove (destination_map, &de->key, de));
2479 de));
2480 } 2451 }
2481 GNUNET_free (de); 2452 GNUNET_free (de);
2482} 2453}
@@ -2516,36 +2487,32 @@ expire_destination (struct DestinationEntry *except)
2516 */ 2487 */
2517static int 2488static int
2518allocate_response_ip (int *result_af, 2489allocate_response_ip (int *result_af,
2519 void **addr, 2490 void **addr,
2520 struct in_addr *v4, 2491 struct in_addr *v4,
2521 struct in6_addr *v6) 2492 struct in6_addr *v6)
2522{ 2493{
2523 *addr = NULL; 2494 *addr = NULL;
2524 switch (*result_af) 2495 switch (*result_af)
2525 { 2496 {
2526 case AF_INET: 2497 case AF_INET:
2527 if (GNUNET_OK != 2498 if (GNUNET_OK != allocate_v4_address (v4))
2528 allocate_v4_address (v4))
2529 *result_af = AF_UNSPEC; 2499 *result_af = AF_UNSPEC;
2530 else 2500 else
2531 *addr = v4; 2501 *addr = v4;
2532 break; 2502 break;
2533 case AF_INET6: 2503 case AF_INET6:
2534 if (GNUNET_OK != 2504 if (GNUNET_OK != allocate_v6_address (v6))
2535 allocate_v6_address (v6))
2536 *result_af = AF_UNSPEC; 2505 *result_af = AF_UNSPEC;
2537 else 2506 else
2538 *addr = v6; 2507 *addr = v6;
2539 break; 2508 break;
2540 case AF_UNSPEC: 2509 case AF_UNSPEC:
2541 if (GNUNET_OK == 2510 if (GNUNET_OK == allocate_v4_address (v4))
2542 allocate_v4_address (v4))
2543 { 2511 {
2544 *addr = v4; 2512 *addr = v4;
2545 *result_af = AF_INET; 2513 *result_af = AF_INET;
2546 } 2514 }
2547 else if (GNUNET_OK == 2515 else if (GNUNET_OK == allocate_v6_address (v6))
2548 allocate_v6_address (v6))
2549 { 2516 {
2550 *addr = v6; 2517 *addr = v6;
2551 *result_af = AF_INET6; 2518 *result_af = AF_INET6;
@@ -2627,18 +2594,13 @@ handle_client_redirect_to_ip (void *cls,
2627 addr_af = (int) htonl (msg->addr_af); 2594 addr_af = (int) htonl (msg->addr_af);
2628 /* allocate response IP */ 2595 /* allocate response IP */
2629 result_af = (int) htonl (msg->result_af); 2596 result_af = (int) htonl (msg->result_af);
2630 if (GNUNET_OK != allocate_response_ip (&result_af, 2597 if (GNUNET_OK != allocate_response_ip (&result_af, &addr, &v4, &v6))
2631 &addr,
2632 &v4, &v6))
2633 { 2598 {
2634 GNUNET_SERVICE_client_drop (client); 2599 GNUNET_SERVICE_client_drop (client);
2635 return; 2600 return;
2636 } 2601 }
2637 /* send reply with our IP address */ 2602 /* send reply with our IP address */
2638 send_client_reply (client, 2603 send_client_reply (client, msg->request_id, result_af, addr);
2639 msg->request_id,
2640 result_af,
2641 addr);
2642 if (result_af == AF_UNSPEC) 2604 if (result_af == AF_UNSPEC)
2643 { 2605 {
2644 /* failure, we're done */ 2606 /* failure, we're done */
@@ -2651,40 +2613,34 @@ handle_client_redirect_to_ip (void *cls,
2651 char dbuf[INET6_ADDRSTRLEN]; 2613 char dbuf[INET6_ADDRSTRLEN];
2652 2614
2653 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2615 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2654 "Allocated address %s for redirection via exit to %s\n", 2616 "Allocated address %s for redirection via exit to %s\n",
2655 inet_ntop (result_af, 2617 inet_ntop (result_af, addr, sbuf, sizeof (sbuf)),
2656 addr, 2618 inet_ntop (addr_af, &msg[1], dbuf, sizeof (dbuf)));
2657 sbuf,
2658 sizeof (sbuf)),
2659 inet_ntop (addr_af,
2660 &msg[1],
2661 dbuf,
2662 sizeof (dbuf)));
2663 } 2619 }
2664 2620
2665 /* setup destination record */ 2621 /* setup destination record */
2666 de = GNUNET_new (struct DestinationEntry); 2622 de = GNUNET_new (struct DestinationEntry);
2667 de->is_service = GNUNET_NO; 2623 de->is_service = GNUNET_NO;
2668 de->details.exit_destination.af = addr_af; 2624 de->details.exit_destination.af = addr_af;
2669 GNUNET_memcpy (&de->details.exit_destination.ip, 2625 GNUNET_memcpy (&de->details.exit_destination.ip, &msg[1], alen);
2670 &msg[1], 2626 get_destination_key_from_ip (result_af, addr, &key);
2671 alen);
2672 get_destination_key_from_ip (result_af,
2673 addr,
2674 &key);
2675 de->key = key; 2627 de->key = key;
2676 GNUNET_assert (GNUNET_OK == 2628 GNUNET_assert (GNUNET_OK == GNUNET_CONTAINER_multihashmap_put (
2677 GNUNET_CONTAINER_multihashmap_put (destination_map, 2629 destination_map,
2678 &key, 2630 &key,
2679 de, 2631 de,
2680 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); 2632 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE));
2681 de->heap_node = GNUNET_CONTAINER_heap_insert (destination_heap, 2633 de->heap_node = GNUNET_CONTAINER_heap_insert (destination_heap,
2682 de, 2634 de,
2683 GNUNET_TIME_absolute_ntoh (msg->expiration_time).abs_value_us); 2635 GNUNET_TIME_absolute_ntoh (
2636 msg->expiration_time)
2637 .abs_value_us);
2684 GNUNET_STATISTICS_update (stats, 2638 GNUNET_STATISTICS_update (stats,
2685 gettext_noop ("# Active destinations"), 2639 gettext_noop ("# Active destinations"),
2686 1, GNUNET_NO); 2640 1,
2687 while (GNUNET_CONTAINER_multihashmap_size (destination_map) > max_destination_mappings) 2641 GNUNET_NO);
2642 while (GNUNET_CONTAINER_multihashmap_size (destination_map) >
2643 max_destination_mappings)
2688 expire_destination (de); 2644 expire_destination (de);
2689 GNUNET_SERVICE_client_continue (client); 2645 GNUNET_SERVICE_client_continue (client);
2690} 2646}
@@ -2699,8 +2655,9 @@ handle_client_redirect_to_ip (void *cls,
2699 * @param msg redirection request 2655 * @param msg redirection request
2700 */ 2656 */
2701static void 2657static void
2702handle_client_redirect_to_service (void *cls, 2658handle_client_redirect_to_service (
2703 const struct RedirectToServiceRequestMessage *msg) 2659 void *cls,
2660 const struct RedirectToServiceRequestMessage *msg)
2704{ 2661{
2705 struct GNUNET_SERVICE_Client *client = cls; 2662 struct GNUNET_SERVICE_Client *client = cls;
2706 int result_af; 2663 int result_af;
@@ -2713,25 +2670,18 @@ handle_client_redirect_to_service (void *cls,
2713 2670
2714 /* allocate response IP */ 2671 /* allocate response IP */
2715 result_af = (int) htonl (msg->result_af); 2672 result_af = (int) htonl (msg->result_af);
2716 if (GNUNET_OK != 2673 if (GNUNET_OK != allocate_response_ip (&result_af, &addr, &v4, &v6))
2717 allocate_response_ip (&result_af,
2718 &addr,
2719 &v4,
2720 &v6))
2721 { 2674 {
2722 GNUNET_break (0); 2675 GNUNET_break (0);
2723 GNUNET_SERVICE_client_drop (client); 2676 GNUNET_SERVICE_client_drop (client);
2724 return; 2677 return;
2725 } 2678 }
2726 send_client_reply (client, 2679 send_client_reply (client, msg->request_id, result_af, addr);
2727 msg->request_id,
2728 result_af,
2729 addr);
2730 if (result_af == AF_UNSPEC) 2680 if (result_af == AF_UNSPEC)
2731 { 2681 {
2732 /* failure, we're done */ 2682 /* failure, we're done */
2733 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 2683 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2734 _("Failed to allocate IP address for new destination\n")); 2684 _ ("Failed to allocate IP address for new destination\n"));
2735 GNUNET_SERVICE_client_continue (client); 2685 GNUNET_SERVICE_client_continue (client);
2736 return; 2686 return;
2737 } 2687 }
@@ -2740,13 +2690,10 @@ handle_client_redirect_to_service (void *cls,
2740 char sbuf[INET6_ADDRSTRLEN]; 2690 char sbuf[INET6_ADDRSTRLEN];
2741 2691
2742 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2692 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2743 "Allocated address %s for redirection to service %s on peer %s\n", 2693 "Allocated address %s for redirection to service %s on peer %s\n",
2744 inet_ntop (result_af, 2694 inet_ntop (result_af, addr, sbuf, sizeof (sbuf)),
2745 addr, 2695 GNUNET_h2s (&msg->service_descriptor),
2746 sbuf, 2696 GNUNET_i2s (&msg->target));
2747 sizeof (sbuf)),
2748 GNUNET_h2s (&msg->service_descriptor),
2749 GNUNET_i2s (&msg->target));
2750 } 2697 }
2751 2698
2752 /* setup destination record */ 2699 /* setup destination record */
@@ -2754,33 +2701,30 @@ handle_client_redirect_to_service (void *cls,
2754 de->is_service = GNUNET_YES; 2701 de->is_service = GNUNET_YES;
2755 de->details.service_destination.target = msg->target; 2702 de->details.service_destination.target = msg->target;
2756 de->details.service_destination.service_descriptor = msg->service_descriptor; 2703 de->details.service_destination.service_descriptor = msg->service_descriptor;
2757 get_destination_key_from_ip (result_af, 2704 get_destination_key_from_ip (result_af, addr, &key);
2758 addr,
2759 &key);
2760 de->key = key; 2705 de->key = key;
2761 GNUNET_assert (GNUNET_OK == 2706 GNUNET_assert (GNUNET_OK == GNUNET_CONTAINER_multihashmap_put (
2762 GNUNET_CONTAINER_multihashmap_put (destination_map, 2707 destination_map,
2763 &key, 2708 &key,
2764 de, 2709 de,
2765 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); 2710 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE));
2766 de->heap_node 2711 de->heap_node = GNUNET_CONTAINER_heap_insert (destination_heap,
2767 = GNUNET_CONTAINER_heap_insert (destination_heap, 2712 de,
2768 de, 2713 GNUNET_TIME_absolute_ntoh (
2769 GNUNET_TIME_absolute_ntoh (msg->expiration_time).abs_value_us); 2714 msg->expiration_time)
2770 while (GNUNET_CONTAINER_multihashmap_size (destination_map) > max_destination_mappings) 2715 .abs_value_us);
2716 while (GNUNET_CONTAINER_multihashmap_size (destination_map) >
2717 max_destination_mappings)
2771 expire_destination (de); 2718 expire_destination (de);
2772 2719
2773 dt = GNUNET_new (struct DestinationChannel); 2720 dt = GNUNET_new (struct DestinationChannel);
2774 dt->destination = de; 2721 dt->destination = de;
2775 GNUNET_CONTAINER_DLL_insert (de->dt_head, 2722 GNUNET_CONTAINER_DLL_insert (de->dt_head, de->dt_tail, dt);
2776 de->dt_tail,
2777 dt);
2778 /* we're done */ 2723 /* we're done */
2779 GNUNET_SERVICE_client_continue (client); 2724 GNUNET_SERVICE_client_continue (client);
2780} 2725}
2781 2726
2782 2727
2783
2784/** 2728/**
2785 * Free memory occupied by an entry in the destination map. 2729 * Free memory occupied by an entry in the destination map.
2786 * 2730 *
@@ -2790,9 +2734,7 @@ handle_client_redirect_to_service (void *cls,
2790 * @return #GNUNET_OK (continue to iterate) 2734 * @return #GNUNET_OK (continue to iterate)
2791 */ 2735 */
2792static int 2736static int
2793cleanup_destination (void *cls, 2737cleanup_destination (void *cls, const struct GNUNET_HashCode *key, void *value)
2794 const struct GNUNET_HashCode *key,
2795 void *value)
2796{ 2738{
2797 struct DestinationEntry *de = value; 2739 struct DestinationEntry *de = value;
2798 2740
@@ -2810,14 +2752,12 @@ cleanup_destination (void *cls,
2810 * @return #GNUNET_OK (continue to iterate) 2752 * @return #GNUNET_OK (continue to iterate)
2811 */ 2753 */
2812static int 2754static int
2813cleanup_channel (void *cls, 2755cleanup_channel (void *cls, const struct GNUNET_HashCode *key, void *value)
2814 const struct GNUNET_HashCode *key,
2815 void *value)
2816{ 2756{
2817 struct ChannelState *ts = value; 2757 struct ChannelState *ts = value;
2818 2758
2819 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2759 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2820 "Tearing down channel to `%s' during cleanup\n", 2760 "Tearing down channel to `%s' during cleanup\n",
2821 print_channel_destination (&ts->destination)); 2761 print_channel_destination (&ts->destination));
2822 free_channel_state (ts); 2762 free_channel_state (ts);
2823 return GNUNET_OK; 2763 return GNUNET_OK;
@@ -2834,13 +2774,12 @@ cleanup (void *cls)
2834{ 2774{
2835 unsigned int i; 2775 unsigned int i;
2836 2776
2837 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2777 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "VPN is shutting down\n");
2838 "VPN is shutting down\n");
2839 if (NULL != destination_map) 2778 if (NULL != destination_map)
2840 { 2779 {
2841 GNUNET_CONTAINER_multihashmap_iterate (destination_map, 2780 GNUNET_CONTAINER_multihashmap_iterate (destination_map,
2842 &cleanup_destination, 2781 &cleanup_destination,
2843 NULL); 2782 NULL);
2844 GNUNET_CONTAINER_multihashmap_destroy (destination_map); 2783 GNUNET_CONTAINER_multihashmap_destroy (destination_map);
2845 destination_map = NULL; 2784 destination_map = NULL;
2846 } 2785 }
@@ -2851,9 +2790,7 @@ cleanup (void *cls)
2851 } 2790 }
2852 if (NULL != channel_map) 2791 if (NULL != channel_map)
2853 { 2792 {
2854 GNUNET_CONTAINER_multihashmap_iterate (channel_map, 2793 GNUNET_CONTAINER_multihashmap_iterate (channel_map, &cleanup_channel, NULL);
2855 &cleanup_channel,
2856 NULL);
2857 GNUNET_CONTAINER_multihashmap_destroy (channel_map); 2794 GNUNET_CONTAINER_multihashmap_destroy (channel_map);
2858 channel_map = NULL; 2795 channel_map = NULL;
2859 } 2796 }
@@ -2878,7 +2815,7 @@ cleanup (void *cls)
2878 GNUNET_STATISTICS_destroy (stats, GNUNET_NO); 2815 GNUNET_STATISTICS_destroy (stats, GNUNET_NO);
2879 stats = NULL; 2816 stats = NULL;
2880 } 2817 }
2881 for (i=0;i<5;i++) 2818 for (i = 0; i < 5; i++)
2882 GNUNET_free_non_null (vpn_argv[i]); 2819 GNUNET_free_non_null (vpn_argv[i]);
2883} 2820}
2884 2821
@@ -2893,8 +2830,8 @@ cleanup (void *cls)
2893 */ 2830 */
2894static void * 2831static void *
2895client_connect_cb (void *cls, 2832client_connect_cb (void *cls,
2896 struct GNUNET_SERVICE_Client *c, 2833 struct GNUNET_SERVICE_Client *c,
2897 struct GNUNET_MQ_Handle *mq) 2834 struct GNUNET_MQ_Handle *mq)
2898{ 2835{
2899 return c; 2836 return c;
2900} 2837}
@@ -2909,8 +2846,8 @@ client_connect_cb (void *cls,
2909 */ 2846 */
2910static void 2847static void
2911client_disconnect_cb (void *cls, 2848client_disconnect_cb (void *cls,
2912 struct GNUNET_SERVICE_Client *c, 2849 struct GNUNET_SERVICE_Client *c,
2913 void *internal_cls) 2850 void *internal_cls)
2914{ 2851{
2915 GNUNET_assert (c == internal_cls); 2852 GNUNET_assert (c == internal_cls);
2916} 2853}
@@ -2940,9 +2877,10 @@ run (void *cls,
2940 binary = GNUNET_OS_get_libexec_binary_path ("gnunet-helper-vpn"); 2877 binary = GNUNET_OS_get_libexec_binary_path ("gnunet-helper-vpn");
2941 2878
2942 if (GNUNET_YES != 2879 if (GNUNET_YES !=
2943 GNUNET_OS_check_helper_binary (binary, 2880 GNUNET_OS_check_helper_binary (
2944 GNUNET_YES, 2881 binary,
2945 "-d gnunet-vpn - - 169.1.3.3.7 255.255.255.0")) //ipv4 only please! 2882 GNUNET_YES,
2883 "-d gnunet-vpn - - 169.1.3.3.7 255.255.255.0")) //ipv4 only please!
2946 { 2884 {
2947 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 2885 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2948 "`%s' is not SUID, refusing to run.\n", 2886 "`%s' is not SUID, refusing to run.\n",
@@ -2961,18 +2899,22 @@ run (void *cls,
2961 GNUNET_CONFIGURATION_get_value_number (cfg, 2899 GNUNET_CONFIGURATION_get_value_number (cfg,
2962 "VPN", 2900 "VPN",
2963 "MAX_MAPPING", 2901 "MAX_MAPPING",
2964 &max_destination_mappings)) 2902 &max_destination_mappings))
2965 max_destination_mappings = 200; 2903 max_destination_mappings = 200;
2966 if (GNUNET_OK != 2904 if (GNUNET_OK !=
2967 GNUNET_CONFIGURATION_get_value_number (cfg, 2905 GNUNET_CONFIGURATION_get_value_number (cfg,
2968 "VPN", 2906 "VPN",
2969 "MAX_TUNNELS", 2907 "MAX_TUNNELS",
2970 &max_channel_mappings)) 2908 &max_channel_mappings))
2971 max_channel_mappings = 200; 2909 max_channel_mappings = 200;
2972 2910
2973 destination_map = GNUNET_CONTAINER_multihashmap_create (max_destination_mappings * 2, GNUNET_NO); 2911 destination_map =
2974 destination_heap = GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN); 2912 GNUNET_CONTAINER_multihashmap_create (max_destination_mappings * 2,
2975 channel_map = GNUNET_CONTAINER_multihashmap_create (max_channel_mappings * 2, GNUNET_NO); 2913 GNUNET_NO);
2914 destination_heap =
2915 GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN);
2916 channel_map =
2917 GNUNET_CONTAINER_multihashmap_create (max_channel_mappings * 2, GNUNET_NO);
2976 channel_heap = GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN); 2918 channel_heap = GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN);
2977 2919
2978 2920
@@ -2988,22 +2930,26 @@ run (void *cls,
2988 ipv6addr = NULL; 2930 ipv6addr = NULL;
2989 if (GNUNET_OK == GNUNET_NETWORK_test_pf (PF_INET6)) 2931 if (GNUNET_OK == GNUNET_NETWORK_test_pf (PF_INET6))
2990 { 2932 {
2991 if ( (GNUNET_SYSERR == 2933 if ((GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg,
2992 GNUNET_CONFIGURATION_get_value_string (cfg, "VPN", "IPV6ADDR", 2934 "VPN",
2993 &ipv6addr) || 2935 "IPV6ADDR",
2994 (1 != inet_pton (AF_INET6, ipv6addr, &v6))) ) 2936 &ipv6addr) ||
2937 (1 != inet_pton (AF_INET6, ipv6addr, &v6))))
2995 { 2938 {
2996 GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR, "VPN", "IPV6ADDR", 2939 GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR,
2997 _("Must specify valid IPv6 address")); 2940 "VPN",
2941 "IPV6ADDR",
2942 _ ("Must specify valid IPv6 address"));
2998 GNUNET_SCHEDULER_shutdown (); 2943 GNUNET_SCHEDULER_shutdown ();
2999 GNUNET_free_non_null (ipv6addr); 2944 GNUNET_free_non_null (ipv6addr);
3000 return; 2945 return;
3001 } 2946 }
3002 vpn_argv[2] = ipv6addr; 2947 vpn_argv[2] = ipv6addr;
3003 ipv6prefix_s = NULL; 2948 ipv6prefix_s = NULL;
3004 if (GNUNET_SYSERR == 2949 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg,
3005 GNUNET_CONFIGURATION_get_value_string (cfg, "VPN", "IPV6PREFIX", 2950 "VPN",
3006 &ipv6prefix_s)) 2951 "IPV6PREFIX",
2952 &ipv6prefix_s))
3007 { 2953 {
3008 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, "VPN", "IPV6PREFIX"); 2954 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, "VPN", "IPV6PREFIX");
3009 GNUNET_SCHEDULER_shutdown (); 2955 GNUNET_SCHEDULER_shutdown ();
@@ -3011,14 +2957,16 @@ run (void *cls,
3011 return; 2957 return;
3012 } 2958 }
3013 vpn_argv[3] = ipv6prefix_s; 2959 vpn_argv[3] = ipv6prefix_s;
3014 if ( (GNUNET_OK != 2960 if ((GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (cfg,
3015 GNUNET_CONFIGURATION_get_value_number (cfg, "VPN", 2961 "VPN",
3016 "IPV6PREFIX", 2962 "IPV6PREFIX",
3017 &ipv6prefix)) || 2963 &ipv6prefix)) ||
3018 (ipv6prefix >= 127) ) 2964 (ipv6prefix >= 127))
3019 { 2965 {
3020 GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR, "VPN", "IPV4MASK", 2966 GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR,
3021 _("Must specify valid IPv6 mask")); 2967 "VPN",
2968 "IPV4MASK",
2969 _ ("Must specify valid IPv6 mask"));
3022 GNUNET_SCHEDULER_shutdown (); 2970 GNUNET_SCHEDULER_shutdown ();
3023 return; 2971 return;
3024 } 2972 }
@@ -3026,33 +2974,40 @@ run (void *cls,
3026 else 2974 else
3027 { 2975 {
3028 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 2976 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
3029 _("IPv6 support disabled as this system does not support IPv6\n")); 2977 _ (
2978 "IPv6 support disabled as this system does not support IPv6\n"));
3030 vpn_argv[2] = GNUNET_strdup ("-"); 2979 vpn_argv[2] = GNUNET_strdup ("-");
3031 vpn_argv[3] = GNUNET_strdup ("-"); 2980 vpn_argv[3] = GNUNET_strdup ("-");
3032 } 2981 }
3033 if (GNUNET_OK == GNUNET_NETWORK_test_pf (PF_INET)) 2982 if (GNUNET_OK == GNUNET_NETWORK_test_pf (PF_INET))
3034 { 2983 {
3035 ipv4addr = NULL; 2984 ipv4addr = NULL;
3036 if ( (GNUNET_SYSERR == 2985 if ((GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg,
3037 GNUNET_CONFIGURATION_get_value_string (cfg, "vpn", "IPV4ADDR", 2986 "vpn",
3038 &ipv4addr) || 2987 "IPV4ADDR",
3039 (1 != inet_pton (AF_INET, ipv4addr, &v4))) ) 2988 &ipv4addr) ||
2989 (1 != inet_pton (AF_INET, ipv4addr, &v4))))
3040 { 2990 {
3041 GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR, "VPN", "IPV4ADDR", 2991 GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR,
3042 _("Must specify valid IPv4 address")); 2992 "VPN",
2993 "IPV4ADDR",
2994 _ ("Must specify valid IPv4 address"));
3043 GNUNET_SCHEDULER_shutdown (); 2995 GNUNET_SCHEDULER_shutdown ();
3044 GNUNET_free_non_null (ipv4addr); 2996 GNUNET_free_non_null (ipv4addr);
3045 return; 2997 return;
3046 } 2998 }
3047 vpn_argv[4] = ipv4addr; 2999 vpn_argv[4] = ipv4addr;
3048 ipv4mask = NULL; 3000 ipv4mask = NULL;
3049 if ( (GNUNET_SYSERR == 3001 if ((GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg,
3050 GNUNET_CONFIGURATION_get_value_string (cfg, "vpn", "IPV4MASK", 3002 "vpn",
3051 &ipv4mask) || 3003 "IPV4MASK",
3052 (1 != inet_pton (AF_INET, ipv4mask, &v4))) ) 3004 &ipv4mask) ||
3005 (1 != inet_pton (AF_INET, ipv4mask, &v4))))
3053 { 3006 {
3054 GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR, "VPN", "IPV4MASK", 3007 GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR,
3055 _("Must specify valid IPv4 mask")); 3008 "VPN",
3009 "IPV4MASK",
3010 _ ("Must specify valid IPv4 mask"));
3056 GNUNET_SCHEDULER_shutdown (); 3011 GNUNET_SCHEDULER_shutdown ();
3057 GNUNET_free_non_null (ipv4mask); 3012 GNUNET_free_non_null (ipv4mask);
3058 return; 3013 return;
@@ -3062,41 +3017,44 @@ run (void *cls,
3062 else 3017 else
3063 { 3018 {
3064 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 3019 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
3065 _("IPv4 support disabled as this system does not support IPv4\n")); 3020 _ (
3021 "IPv4 support disabled as this system does not support IPv4\n"));
3066 vpn_argv[4] = GNUNET_strdup ("-"); 3022 vpn_argv[4] = GNUNET_strdup ("-");
3067 vpn_argv[5] = GNUNET_strdup ("-"); 3023 vpn_argv[5] = GNUNET_strdup ("-");
3068 } 3024 }
3069 vpn_argv[6] = NULL; 3025 vpn_argv[6] = NULL;
3070 3026
3071 cadet_handle = GNUNET_CADET_connect (cfg_); 3027 cadet_handle = GNUNET_CADET_connect (cfg_);
3072 // FIXME never opens ports??? 3028 // FIXME never opens ports???
3073 helper_handle = GNUNET_HELPER_start (GNUNET_NO, 3029 helper_handle = GNUNET_HELPER_start (GNUNET_NO,
3074 "gnunet-helper-vpn", vpn_argv, 3030 "gnunet-helper-vpn",
3075 &message_token, NULL, NULL); 3031 vpn_argv,
3076 GNUNET_SCHEDULER_add_shutdown (&cleanup, 3032 &message_token,
3077 NULL); 3033 NULL,
3034 NULL);
3035 GNUNET_SCHEDULER_add_shutdown (&cleanup, NULL);
3078} 3036}
3079 3037
3080 3038
3081/** 3039/**
3082 * Define "main" method using service macro. 3040 * Define "main" method using service macro.
3083 */ 3041 */
3084GNUNET_SERVICE_MAIN 3042GNUNET_SERVICE_MAIN (
3085("vpn", 3043 "vpn",
3086 GNUNET_SERVICE_OPTION_NONE, 3044 GNUNET_SERVICE_OPTION_NONE,
3087 &run, 3045 &run,
3088 &client_connect_cb, 3046 &client_connect_cb,
3089 &client_disconnect_cb, 3047 &client_disconnect_cb,
3090 NULL, 3048 NULL,
3091 GNUNET_MQ_hd_var_size (client_redirect_to_ip, 3049 GNUNET_MQ_hd_var_size (client_redirect_to_ip,
3092 GNUNET_MESSAGE_TYPE_VPN_CLIENT_REDIRECT_TO_IP, 3050 GNUNET_MESSAGE_TYPE_VPN_CLIENT_REDIRECT_TO_IP,
3093 struct RedirectToIpRequestMessage, 3051 struct RedirectToIpRequestMessage,
3094 NULL), 3052 NULL),
3095 GNUNET_MQ_hd_fixed_size (client_redirect_to_service, 3053 GNUNET_MQ_hd_fixed_size (client_redirect_to_service,
3096 GNUNET_MESSAGE_TYPE_VPN_CLIENT_REDIRECT_TO_SERVICE, 3054 GNUNET_MESSAGE_TYPE_VPN_CLIENT_REDIRECT_TO_SERVICE,
3097 struct RedirectToServiceRequestMessage, 3055 struct RedirectToServiceRequestMessage,
3098 NULL), 3056 NULL),
3099 GNUNET_MQ_handler_end ()); 3057 GNUNET_MQ_handler_end ());
3100 3058
3101 3059
3102/* end of gnunet-service-vpn.c */ 3060/* end of gnunet-service-vpn.c */