diff options
author | Christian Grothoff <christian@grothoff.org> | 2012-01-11 17:00:52 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2012-01-11 17:00:52 +0000 |
commit | f1b851a7ece3a993bb07269a730dd82f7e60a6ac (patch) | |
tree | 0d3e98f283ce693c82d2552d9c9462e03c0c10af /src/vpn/gnunet-service-vpn.c | |
parent | 1854e857263b6eb449eaa286570f391e1d8bf173 (diff) | |
download | gnunet-f1b851a7ece3a993bb07269a730dd82f7e60a6ac.tar.gz gnunet-f1b851a7ece3a993bb07269a730dd82f7e60a6ac.zip |
-generate messages in new mesh format
Diffstat (limited to 'src/vpn/gnunet-service-vpn.c')
-rw-r--r-- | src/vpn/gnunet-service-vpn.c | 75 |
1 files changed, 69 insertions, 6 deletions
diff --git a/src/vpn/gnunet-service-vpn.c b/src/vpn/gnunet-service-vpn.c index db0a4f2be..3b9fe02e4 100644 --- a/src/vpn/gnunet-service-vpn.c +++ b/src/vpn/gnunet-service-vpn.c | |||
@@ -704,12 +704,22 @@ route_packet (struct DestinationEntry *destination, | |||
704 | tnq = GNUNET_malloc (sizeof (struct TunnelMessageQueueEntry) + mlen); | 704 | tnq = GNUNET_malloc (sizeof (struct TunnelMessageQueueEntry) + mlen); |
705 | usm = (struct GNUNET_EXIT_UdpServiceMessage *) &tnq[1]; | 705 | usm = (struct GNUNET_EXIT_UdpServiceMessage *) &tnq[1]; |
706 | usm->header.size = htons ((uint16_t) mlen); | 706 | usm->header.size = htons ((uint16_t) mlen); |
707 | usm->header.type = htons (GNUNET_MESSAGE_TYPE_VPN_UDP_TO_SERVICE); | ||
708 | /* if the source port is below 32000, we assume it has a special | ||
709 | meaning; if not, we pick a random port (this is a heuristic) */ | ||
710 | usm->source_port = (ntohs (udp->spt) < 32000) ? udp->spt : 0; | ||
711 | usm->destination_port = udp->dpt; | ||
707 | usm->service_descriptor = destination->details.service_destination.service_descriptor; | 712 | usm->service_descriptor = destination->details.service_destination.service_descriptor; |
708 | // FIXME: build message! | 713 | memcpy (&usm[1], |
714 | &udp[1], | ||
715 | payload_length - sizeof (struct udp_packet)); | ||
709 | } | 716 | } |
710 | else | 717 | else |
711 | { | 718 | { |
712 | struct GNUNET_EXIT_UdpInternetMessage *uim; | 719 | struct GNUNET_EXIT_UdpInternetMessage *uim; |
720 | struct in_addr *ip4dst; | ||
721 | struct in6_addr *ip6dst; | ||
722 | void *payload; | ||
713 | 723 | ||
714 | mlen = sizeof (struct GNUNET_EXIT_UdpInternetMessage) + | 724 | mlen = sizeof (struct GNUNET_EXIT_UdpInternetMessage) + |
715 | alen + payload_length - sizeof (struct udp_packet); | 725 | alen + payload_length - sizeof (struct udp_packet); |
@@ -722,9 +732,28 @@ route_packet (struct DestinationEntry *destination, | |||
722 | mlen); | 732 | mlen); |
723 | uim = (struct GNUNET_EXIT_UdpInternetMessage *) &tnq[1]; | 733 | uim = (struct GNUNET_EXIT_UdpInternetMessage *) &tnq[1]; |
724 | uim->header.size = htons ((uint16_t) mlen); | 734 | uim->header.size = htons ((uint16_t) mlen); |
735 | uim->header.type = htons (GNUNET_MESSAGE_TYPE_VPN_UDP_TO_INTERNET); | ||
725 | uim->af = htonl (destination->details.exit_destination.af); | 736 | uim->af = htonl (destination->details.exit_destination.af); |
726 | 737 | uim->source_port = (ntohs (udp->spt) < 32000) ? udp->spt : 0; | |
727 | // FIXME: build message! | 738 | uim->destination_port = udp->dpt; |
739 | switch (destination->details.exit_destination.af) | ||
740 | { | ||
741 | case AF_INET: | ||
742 | ip4dst = (struct in_addr *) &uim[1]; | ||
743 | *ip4dst = destination->details.exit_destination.ip.v4; | ||
744 | payload = &ip4dst[1]; | ||
745 | break; | ||
746 | case AF_INET6: | ||
747 | ip6dst = (struct in6_addr *) &uim[1]; | ||
748 | *ip6dst = destination->details.exit_destination.ip.v6; | ||
749 | payload = &ip6dst[1]; | ||
750 | break; | ||
751 | default: | ||
752 | GNUNET_assert (0); | ||
753 | } | ||
754 | memcpy (payload, | ||
755 | &udp[1], | ||
756 | payload_length - sizeof (struct udp_packet)); | ||
728 | } | 757 | } |
729 | break; | 758 | break; |
730 | case IPPROTO_TCP: | 759 | case IPPROTO_TCP: |
@@ -744,11 +773,20 @@ route_packet (struct DestinationEntry *destination, | |||
744 | tnq = GNUNET_malloc (sizeof (struct TunnelMessageQueueEntry) + mlen); | 773 | tnq = GNUNET_malloc (sizeof (struct TunnelMessageQueueEntry) + mlen); |
745 | tsm = (struct GNUNET_EXIT_TcpServiceStartMessage *) &tnq[1]; | 774 | tsm = (struct GNUNET_EXIT_TcpServiceStartMessage *) &tnq[1]; |
746 | tsm->header.size = htons ((uint16_t) mlen); | 775 | tsm->header.size = htons ((uint16_t) mlen); |
747 | // FIXME: build message! | 776 | tsm->header.type = htons (GNUNET_MESSAGE_TYPE_VPN_TCP_TO_SERVICE_START); |
777 | tsm->reserved = htonl (0); | ||
778 | tsm->service_descriptor = destination->details.service_destination.service_descriptor; | ||
779 | tsm->tcp_header = *tcp; | ||
780 | memcpy (&tsm[1], | ||
781 | &tcp[1], | ||
782 | payload_length - sizeof (struct tcp_packet)); | ||
748 | } | 783 | } |
749 | else | 784 | else |
750 | { | 785 | { |
751 | struct GNUNET_EXIT_TcpInternetStartMessage *tim; | 786 | struct GNUNET_EXIT_TcpInternetStartMessage *tim; |
787 | struct in_addr *ip4dst; | ||
788 | struct in6_addr *ip6dst; | ||
789 | void *payload; | ||
752 | 790 | ||
753 | mlen = sizeof (struct GNUNET_EXIT_TcpInternetStartMessage) + | 791 | mlen = sizeof (struct GNUNET_EXIT_TcpInternetStartMessage) + |
754 | alen + payload_length - sizeof (struct tcp_packet); | 792 | alen + payload_length - sizeof (struct tcp_packet); |
@@ -760,7 +798,27 @@ route_packet (struct DestinationEntry *destination, | |||
760 | tnq = GNUNET_malloc (sizeof (struct TunnelMessageQueueEntry) + mlen); | 798 | tnq = GNUNET_malloc (sizeof (struct TunnelMessageQueueEntry) + mlen); |
761 | tim = (struct GNUNET_EXIT_TcpInternetStartMessage *) &tnq[1]; | 799 | tim = (struct GNUNET_EXIT_TcpInternetStartMessage *) &tnq[1]; |
762 | tim->header.size = htons ((uint16_t) mlen); | 800 | tim->header.size = htons ((uint16_t) mlen); |
763 | // FIXME: build message! | 801 | tim->header.type = htons (GNUNET_MESSAGE_TYPE_VPN_TCP_TO_INTERNET_START); |
802 | tim->af = htonl (destination->details.exit_destination.af); | ||
803 | tim->tcp_header = *tcp; | ||
804 | switch (destination->details.exit_destination.af) | ||
805 | { | ||
806 | case AF_INET: | ||
807 | ip4dst = (struct in_addr *) &tim[1]; | ||
808 | *ip4dst = destination->details.exit_destination.ip.v4; | ||
809 | payload = &ip4dst[1]; | ||
810 | break; | ||
811 | case AF_INET6: | ||
812 | ip6dst = (struct in6_addr *) &tim[1]; | ||
813 | *ip6dst = destination->details.exit_destination.ip.v6; | ||
814 | payload = &ip6dst[1]; | ||
815 | break; | ||
816 | default: | ||
817 | GNUNET_assert (0); | ||
818 | } | ||
819 | memcpy (payload, | ||
820 | &tcp[1], | ||
821 | payload_length - sizeof (struct tcp_packet)); | ||
764 | } | 822 | } |
765 | } | 823 | } |
766 | else | 824 | else |
@@ -777,7 +835,12 @@ route_packet (struct DestinationEntry *destination, | |||
777 | tnq = GNUNET_malloc (sizeof (struct TunnelMessageQueueEntry) + mlen); | 835 | tnq = GNUNET_malloc (sizeof (struct TunnelMessageQueueEntry) + mlen); |
778 | tdm = (struct GNUNET_EXIT_TcpDataMessage *) &tnq[1]; | 836 | tdm = (struct GNUNET_EXIT_TcpDataMessage *) &tnq[1]; |
779 | tdm->header.size = htons ((uint16_t) mlen); | 837 | tdm->header.size = htons ((uint16_t) mlen); |
780 | // FIXME: build message! | 838 | tdm->header.type = htons (GNUNET_MESSAGE_TYPE_VPN_TCP_DATA); |
839 | tdm->reserved = htonl (0); | ||
840 | tdm->tcp_header = *tcp; | ||
841 | memcpy (&tdm[1], | ||
842 | &tcp[1], | ||
843 | payload_length - sizeof (struct tcp_packet)); | ||
781 | } | 844 | } |
782 | break; | 845 | break; |
783 | default: | 846 | default: |