diff options
author | Philipp Tölke <toelke@in.tum.de> | 2011-07-27 07:28:25 +0000 |
---|---|---|
committer | Philipp Tölke <toelke@in.tum.de> | 2011-07-27 07:28:25 +0000 |
commit | 2181ba329473b72a12052fa09486062281604bcc (patch) | |
tree | 1852f80641dac98c7f8575fc0c376c45d009ae4b /src/vpn | |
parent | 66728692d4f79d4dd72e794900a1b4f6e0a39300 (diff) | |
download | gnunet-2181ba329473b72a12052fa09486062281604bcc.tar.gz gnunet-2181ba329473b72a12052fa09486062281604bcc.zip |
let -vpn send back v4 packets
Diffstat (limited to 'src/vpn')
-rw-r--r-- | src/vpn/gnunet-daemon-vpn.c | 413 |
1 files changed, 296 insertions, 117 deletions
diff --git a/src/vpn/gnunet-daemon-vpn.c b/src/vpn/gnunet-daemon-vpn.c index ef54cdf2d..45f0f3054 100644 --- a/src/vpn/gnunet-daemon-vpn.c +++ b/src/vpn/gnunet-daemon-vpn.c | |||
@@ -790,84 +790,170 @@ add_additional_port (struct map_entry *me, uint16_t port) | |||
790 | } | 790 | } |
791 | 791 | ||
792 | static int | 792 | static int |
793 | receive_udp_back (void *cls __attribute__((unused)), struct GNUNET_MESH_Tunnel* tunnel, | 793 | receive_udp_back (void *cls |
794 | void **tunnel_ctx __attribute__((unused)), | 794 | __attribute__ ((unused)), struct GNUNET_MESH_Tunnel *tunnel, |
795 | const struct GNUNET_PeerIdentity *sender __attribute__((unused)), | 795 | void **tunnel_ctx __attribute__ ((unused)), |
796 | const struct GNUNET_MessageHeader *message, | 796 | const struct GNUNET_PeerIdentity *sender __attribute__ ((unused)), |
797 | const struct GNUNET_TRANSPORT_ATS_Information *atsi __attribute__((unused))) | 797 | const struct GNUNET_MessageHeader *message, |
798 | const struct GNUNET_TRANSPORT_ATS_Information *atsi __attribute__ ((unused))) | ||
798 | { | 799 | { |
799 | GNUNET_HashCode *desc = (GNUNET_HashCode *) (message + 1); | 800 | GNUNET_HashCode *desc = (GNUNET_HashCode *) (message + 1); |
800 | struct remote_addr* s = (struct remote_addr*)desc; | 801 | struct remote_addr *s = (struct remote_addr *) desc; |
801 | struct udp_pkt *pkt = (struct udp_pkt *) (desc + 1); | 802 | struct udp_pkt *pkt = (struct udp_pkt *) (desc + 1); |
802 | const struct GNUNET_PeerIdentity* other = GNUNET_MESH_get_peer(tunnel); | 803 | const struct GNUNET_PeerIdentity *other = GNUNET_MESH_get_peer (tunnel); |
803 | 804 | ||
804 | size_t size = sizeof(struct ip6_udp) + ntohs(pkt->len) - 1 - sizeof(struct udp_pkt); | 805 | if (16 == s->addrlen) |
806 | { | ||
807 | size_t size = | ||
808 | sizeof (struct ip6_udp) + ntohs (pkt->len) - 1 - sizeof (struct udp_pkt); | ||
805 | 809 | ||
806 | struct ip6_udp* pkt6 = alloca(size); | 810 | struct ip6_udp *pkt6 = alloca (size); |
807 | 811 | ||
808 | GNUNET_assert(pkt6 != NULL); | 812 | GNUNET_assert (pkt6 != NULL); |
809 | 813 | ||
810 | if (ntohs(message->type) == GNUNET_MESSAGE_TYPE_SERVICE_UDP_BACK) | 814 | if (ntohs (message->type) == GNUNET_MESSAGE_TYPE_SERVICE_UDP_BACK) |
811 | new_ip6addr(pkt6->ip6_hdr.sadr, &other->hashPubKey, desc); | 815 | new_ip6addr (pkt6->ip6_hdr.sadr, &other->hashPubKey, desc); |
812 | else | 816 | else |
813 | new_ip6addr_remote(pkt6->ip6_hdr.sadr, s->addr, s->addrlen); | 817 | new_ip6addr_remote (pkt6->ip6_hdr.sadr, s->addr, s->addrlen); |
814 | 818 | ||
815 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Relaying calc:%d gnu:%d udp:%d bytes!\n", size, ntohs(message->size), ntohs(pkt->len)); | 819 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
820 | "Relaying calc:%d gnu:%d udp:%d bytes!\n", size, | ||
821 | ntohs (message->size), ntohs (pkt->len)); | ||
816 | 822 | ||
817 | pkt6->shdr.type = htons(GNUNET_MESSAGE_TYPE_VPN_HELPER); | 823 | pkt6->shdr.type = htons (GNUNET_MESSAGE_TYPE_VPN_HELPER); |
818 | pkt6->shdr.size = htons(size); | 824 | pkt6->shdr.size = htons (size); |
819 | 825 | ||
820 | pkt6->tun.flags = 0; | 826 | pkt6->tun.flags = 0; |
821 | pkt6->tun.type = htons(0x86dd); | 827 | pkt6->tun.type = htons (0x86dd); |
822 | 828 | ||
823 | pkt6->ip6_hdr.version = 6; | 829 | pkt6->ip6_hdr.version = 6; |
824 | pkt6->ip6_hdr.tclass_h = 0; | 830 | pkt6->ip6_hdr.tclass_h = 0; |
825 | pkt6->ip6_hdr.tclass_l = 0; | 831 | pkt6->ip6_hdr.tclass_l = 0; |
826 | pkt6->ip6_hdr.flowlbl = 0; | 832 | pkt6->ip6_hdr.flowlbl = 0; |
827 | pkt6->ip6_hdr.paylgth = pkt->len; | 833 | pkt6->ip6_hdr.paylgth = pkt->len; |
828 | pkt6->ip6_hdr.nxthdr = 0x11; | 834 | pkt6->ip6_hdr.nxthdr = 0x11; |
829 | pkt6->ip6_hdr.hoplmt = 0xff; | 835 | pkt6->ip6_hdr.hoplmt = 0xff; |
830 | 836 | ||
831 | { | 837 | { |
832 | char* ipv6addr; | 838 | char *ipv6addr; |
833 | GNUNET_assert(GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(cfg, "vpn", "IPV6ADDR", &ipv6addr)); | 839 | GNUNET_assert (GNUNET_OK == |
834 | inet_pton (AF_INET6, ipv6addr, pkt6->ip6_hdr.dadr); | 840 | GNUNET_CONFIGURATION_get_value_string (cfg, "vpn", |
835 | GNUNET_free(ipv6addr); | 841 | "IPV6ADDR", |
836 | } | 842 | &ipv6addr)); |
837 | memcpy(&pkt6->udp_hdr, pkt, ntohs(pkt->len)); | 843 | inet_pton (AF_INET6, ipv6addr, pkt6->ip6_hdr.dadr); |
844 | GNUNET_free (ipv6addr); | ||
845 | } | ||
846 | memcpy (&pkt6->udp_hdr, pkt, ntohs (pkt->len)); | ||
847 | |||
848 | GNUNET_HashCode *key = address6_mapping_exists (pkt6->ip6_hdr.sadr); | ||
849 | GNUNET_assert (key != NULL); | ||
838 | 850 | ||
839 | GNUNET_HashCode* key = address6_mapping_exists(pkt6->ip6_hdr.sadr); | 851 | struct map_entry *me = GNUNET_CONTAINER_multihashmap_get (hashmap, key); |
840 | GNUNET_assert (key != NULL); | 852 | GNUNET_CONTAINER_heap_update_cost (heap, me->heap_node, |
853 | GNUNET_TIME_absolute_get (). | ||
854 | abs_value); | ||
841 | 855 | ||
842 | struct map_entry *me = GNUNET_CONTAINER_multihashmap_get(hashmap, key); | 856 | GNUNET_free (key); |
843 | GNUNET_CONTAINER_heap_update_cost (heap, me->heap_node, | ||
844 | GNUNET_TIME_absolute_get ().abs_value); | ||
845 | 857 | ||
846 | GNUNET_free(key); | 858 | GNUNET_assert (me != NULL); |
859 | if (ntohs (message->type) == GNUNET_MESSAGE_TYPE_SERVICE_UDP_BACK) | ||
860 | { | ||
861 | GNUNET_assert (me->desc. | ||
862 | service_type & htonl (GNUNET_DNS_SERVICE_TYPE_UDP)); | ||
863 | if (!port_in_ports (me->desc.ports, pkt6->udp_hdr.spt) | ||
864 | && !testBit (me->additional_ports, ntohs (pkt6->udp_hdr.spt))) | ||
865 | { | ||
866 | add_additional_port (me, ntohs (pkt6->udp_hdr.spt)); | ||
867 | } | ||
868 | } | ||
847 | 869 | ||
848 | GNUNET_assert (me != NULL); | 870 | pkt6->udp_hdr.crc = 0; |
849 | if (ntohs(message->type) == GNUNET_MESSAGE_TYPE_SERVICE_UDP_BACK) | 871 | uint32_t sum = 0; |
872 | sum = | ||
873 | calculate_checksum_update (sum, (uint16_t *) & pkt6->ip6_hdr.sadr, | ||
874 | 16); | ||
875 | sum = | ||
876 | calculate_checksum_update (sum, (uint16_t *) & pkt6->ip6_hdr.dadr, | ||
877 | 16); | ||
878 | uint32_t tmp = (pkt6->udp_hdr.len & 0xffff); | ||
879 | sum = calculate_checksum_update (sum, (uint16_t *) & tmp, 4); | ||
880 | tmp = htons (((pkt6->ip6_hdr.nxthdr & 0x00ff))); | ||
881 | sum = calculate_checksum_update (sum, (uint16_t *) & tmp, 4); | ||
882 | |||
883 | sum = | ||
884 | calculate_checksum_update (sum, (uint16_t *) & pkt6->udp_hdr, | ||
885 | ntohs (pkt->len)); | ||
886 | pkt6->udp_hdr.crc = calculate_checksum_end (sum); | ||
887 | |||
888 | write_to_helper (pkt6, size); | ||
889 | } | ||
890 | else | ||
850 | { | 891 | { |
851 | GNUNET_assert (me->desc.service_type & htonl(GNUNET_DNS_SERVICE_TYPE_UDP)); | 892 | size_t size = |
852 | if (!port_in_ports(me->desc.ports, pkt6->udp_hdr.spt) && | 893 | sizeof (struct ip_udp) + ntohs (pkt->len) - 1 - sizeof (struct udp_pkt); |
853 | !testBit(me->additional_ports, ntohs(pkt6->udp_hdr.spt))) { | 894 | |
854 | add_additional_port(me, ntohs(pkt6->udp_hdr.spt)); | 895 | struct ip_udp *pkt4 = alloca (size); |
896 | |||
897 | GNUNET_assert (pkt4 != NULL); | ||
898 | |||
899 | GNUNET_assert (ntohs (message->type) == GNUNET_MESSAGE_TYPE_REMOTE_UDP_BACK); | ||
900 | uint32_t sadr; | ||
901 | new_ip4addr_remote ((unsigned char*)&sadr, s->addr, s->addrlen); | ||
902 | pkt4->ip_hdr.sadr = sadr; | ||
903 | |||
904 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
905 | "Relaying calc:%d gnu:%d udp:%d bytes!\n", size, | ||
906 | ntohs (message->size), ntohs (pkt->len)); | ||
907 | |||
908 | pkt4->shdr.type = htons (GNUNET_MESSAGE_TYPE_VPN_HELPER); | ||
909 | pkt4->shdr.size = htons (size); | ||
910 | |||
911 | pkt4->tun.flags = 0; | ||
912 | pkt4->tun.type = htons (0x0800); | ||
913 | |||
914 | pkt4->ip_hdr.version = 4; | ||
915 | pkt4->ip_hdr.hdr_lngth = 5; | ||
916 | pkt4->ip_hdr.diff_serv = 0; | ||
917 | pkt4->ip_hdr.tot_lngth = htons (20 + ntohs(pkt->len)); | ||
918 | pkt4->ip_hdr.ident = 0; | ||
919 | pkt4->ip_hdr.flags = 0; | ||
920 | pkt4->ip_hdr.frag_off = 0; | ||
921 | pkt4->ip_hdr.ttl = 255; | ||
922 | pkt4->ip_hdr.proto = 0x11; | ||
923 | pkt4->ip_hdr.chks = 0; /* Will be calculated later */ | ||
924 | |||
925 | { | ||
926 | char *ipv4addr; | ||
927 | uint32_t dadr; | ||
928 | GNUNET_assert (GNUNET_OK == | ||
929 | GNUNET_CONFIGURATION_get_value_string (cfg, "vpn", | ||
930 | "IPV4ADDR", | ||
931 | &ipv4addr)); | ||
932 | inet_pton (AF_INET, ipv4addr, &dadr); | ||
933 | GNUNET_free (ipv4addr); | ||
934 | pkt4->ip_hdr.dadr = dadr; | ||
855 | } | 935 | } |
856 | } | 936 | memcpy (&pkt4->udp_hdr, pkt, ntohs (pkt->len)); |
937 | |||
938 | GNUNET_HashCode *key = address4_mapping_exists (pkt4->ip_hdr.sadr); | ||
939 | GNUNET_assert (key != NULL); | ||
857 | 940 | ||
858 | pkt6->udp_hdr.crc = 0; | 941 | struct map_entry *me = GNUNET_CONTAINER_multihashmap_get (hashmap, key); |
859 | uint32_t sum = 0; | 942 | GNUNET_CONTAINER_heap_update_cost (heap, me->heap_node, |
860 | sum = calculate_checksum_update(sum, (uint16_t*)&pkt6->ip6_hdr.sadr, 16); | 943 | GNUNET_TIME_absolute_get (). |
861 | sum = calculate_checksum_update(sum, (uint16_t*)&pkt6->ip6_hdr.dadr, 16); | 944 | abs_value); |
862 | uint32_t tmp = (pkt6->udp_hdr.len & 0xffff); | ||
863 | sum = calculate_checksum_update(sum, (uint16_t*)&tmp, 4); | ||
864 | tmp = htons(((pkt6->ip6_hdr.nxthdr & 0x00ff))); | ||
865 | sum = calculate_checksum_update(sum, (uint16_t*)&tmp, 4); | ||
866 | 945 | ||
867 | sum = calculate_checksum_update(sum, (uint16_t*)&pkt6->udp_hdr, ntohs(pkt->len)); | 946 | GNUNET_free (key); |
868 | pkt6->udp_hdr.crc = calculate_checksum_end(sum); | 947 | |
948 | GNUNET_assert (me != NULL); | ||
869 | 949 | ||
870 | write_to_helper(pkt6, size); | 950 | pkt4->udp_hdr.crc = 0; /* Optional for IPv4 */ |
951 | |||
952 | pkt4->ip_hdr.chks = | ||
953 | calculate_ip_checksum ((uint16_t *) & pkt4->ip_hdr, 5 * 4); | ||
954 | |||
955 | write_to_helper (pkt4, size); | ||
956 | } | ||
871 | 957 | ||
872 | return GNUNET_OK; | 958 | return GNUNET_OK; |
873 | } | 959 | } |
@@ -880,76 +966,169 @@ receive_tcp_back (void *cls __attribute__((unused)), struct GNUNET_MESH_Tunnel* | |||
880 | const struct GNUNET_TRANSPORT_ATS_Information *atsi __attribute__((unused))) | 966 | const struct GNUNET_TRANSPORT_ATS_Information *atsi __attribute__((unused))) |
881 | { | 967 | { |
882 | GNUNET_HashCode *desc = (GNUNET_HashCode *) (message + 1); | 968 | GNUNET_HashCode *desc = (GNUNET_HashCode *) (message + 1); |
883 | struct remote_addr* s = (struct remote_addr*)desc; | 969 | struct remote_addr *s = (struct remote_addr *) desc; |
884 | struct tcp_pkt *pkt = (struct tcp_pkt *) (desc + 1); | 970 | struct tcp_pkt *pkt = (struct tcp_pkt *) (desc + 1); |
885 | const struct GNUNET_PeerIdentity* other = GNUNET_MESH_get_peer(tunnel); | 971 | const struct GNUNET_PeerIdentity *other = GNUNET_MESH_get_peer (tunnel); |
972 | |||
973 | size_t pktlen = | ||
974 | ntohs (message->size) - sizeof (struct GNUNET_MessageHeader) - | ||
975 | sizeof (GNUNET_HashCode); | ||
976 | |||
977 | if (s->addrlen == 16) | ||
978 | { | ||
979 | size_t size = pktlen + sizeof (struct ip6_tcp) - 1; | ||
980 | |||
981 | struct ip6_tcp *pkt6 = alloca (size); | ||
982 | memset (pkt6, 0, size); | ||
983 | |||
984 | GNUNET_assert (pkt6 != NULL); | ||
985 | |||
986 | if (ntohs (message->type) == GNUNET_MESSAGE_TYPE_SERVICE_TCP_BACK) | ||
987 | new_ip6addr (pkt6->ip6_hdr.sadr, &other->hashPubKey, desc); | ||
988 | else | ||
989 | new_ip6addr_remote (pkt6->ip6_hdr.sadr, s->addr, s->addrlen); | ||
990 | |||
991 | pkt6->shdr.type = htons (GNUNET_MESSAGE_TYPE_VPN_HELPER); | ||
992 | pkt6->shdr.size = htons (size); | ||
886 | 993 | ||
887 | size_t pktlen = ntohs(message->size) - sizeof(struct GNUNET_MessageHeader) - sizeof(GNUNET_HashCode); | 994 | pkt6->tun.flags = 0; |
888 | size_t size = pktlen + sizeof(struct ip6_tcp) - 1; | 995 | pkt6->tun.type = htons (0x86dd); |
889 | 996 | ||
890 | struct ip6_tcp* pkt6 = alloca(size); | 997 | pkt6->ip6_hdr.version = 6; |
891 | memset(pkt6, 0, size); | 998 | pkt6->ip6_hdr.tclass_h = 0; |
999 | pkt6->ip6_hdr.tclass_l = 0; | ||
1000 | pkt6->ip6_hdr.flowlbl = 0; | ||
1001 | pkt6->ip6_hdr.paylgth = htons (pktlen); | ||
1002 | pkt6->ip6_hdr.nxthdr = 0x06; | ||
1003 | pkt6->ip6_hdr.hoplmt = 0xff; | ||
892 | 1004 | ||
893 | GNUNET_assert(pkt6 != NULL); | 1005 | { |
1006 | char *ipv6addr; | ||
1007 | GNUNET_assert (GNUNET_OK == | ||
1008 | GNUNET_CONFIGURATION_get_value_string (cfg, "vpn", | ||
1009 | "IPV6ADDR", | ||
1010 | &ipv6addr)); | ||
1011 | inet_pton (AF_INET6, ipv6addr, pkt6->ip6_hdr.dadr); | ||
1012 | GNUNET_free (ipv6addr); | ||
1013 | } | ||
1014 | memcpy (&pkt6->tcp_hdr, pkt, pktlen); | ||
1015 | |||
1016 | GNUNET_HashCode *key = address6_mapping_exists (pkt6->ip6_hdr.sadr); | ||
1017 | GNUNET_assert (key != NULL); | ||
1018 | |||
1019 | struct map_entry *me = GNUNET_CONTAINER_multihashmap_get (hashmap, key); | ||
1020 | GNUNET_CONTAINER_heap_update_cost (heap, me->heap_node, | ||
1021 | GNUNET_TIME_absolute_get (). | ||
1022 | abs_value); | ||
894 | 1023 | ||
895 | if (ntohs(message->type) == GNUNET_MESSAGE_TYPE_SERVICE_TCP_BACK) | 1024 | GNUNET_free (key); |
896 | new_ip6addr(pkt6->ip6_hdr.sadr, &other->hashPubKey, desc); | 1025 | |
1026 | GNUNET_assert (me != NULL); | ||
1027 | if (ntohs (message->type) == GNUNET_MESSAGE_TYPE_SERVICE_UDP_BACK) | ||
1028 | GNUNET_assert (me->desc. | ||
1029 | service_type & htonl (GNUNET_DNS_SERVICE_TYPE_TCP)); | ||
1030 | |||
1031 | pkt6->tcp_hdr.crc = 0; | ||
1032 | uint32_t sum = 0; | ||
1033 | uint32_t tmp; | ||
1034 | sum = | ||
1035 | calculate_checksum_update (sum, (uint16_t *) & pkt6->ip6_hdr.sadr, | ||
1036 | 16); | ||
1037 | sum = | ||
1038 | calculate_checksum_update (sum, (uint16_t *) & pkt6->ip6_hdr.dadr, | ||
1039 | 16); | ||
1040 | tmp = htonl (pktlen); | ||
1041 | sum = calculate_checksum_update (sum, (uint16_t *) & tmp, 4); | ||
1042 | tmp = htonl (((pkt6->ip6_hdr.nxthdr & 0x000000ff))); | ||
1043 | sum = calculate_checksum_update (sum, (uint16_t *) & tmp, 4); | ||
1044 | |||
1045 | sum = | ||
1046 | calculate_checksum_update (sum, (uint16_t *) & pkt6->tcp_hdr, | ||
1047 | ntohs (pkt6->ip6_hdr.paylgth)); | ||
1048 | pkt6->tcp_hdr.crc = calculate_checksum_end (sum); | ||
1049 | |||
1050 | write_to_helper (pkt6, size); | ||
1051 | } | ||
897 | else | 1052 | else |
898 | new_ip6addr_remote(pkt6->ip6_hdr.sadr, s->addr, s->addrlen); | 1053 | { |
1054 | size_t size = pktlen + sizeof (struct ip_tcp) - 1; | ||
1055 | |||
1056 | struct ip_tcp *pkt4 = alloca (size); | ||
1057 | GNUNET_assert (pkt4 != NULL); | ||
1058 | memset (pkt4, 0, size); | ||
1059 | |||
1060 | GNUNET_assert (ntohs (message->type) == GNUNET_MESSAGE_TYPE_REMOTE_TCP_BACK); | ||
1061 | uint32_t sadr; | ||
1062 | new_ip4addr_remote ((unsigned char*)&sadr, s->addr, s->addrlen); | ||
1063 | pkt4->ip_hdr.sadr = sadr; | ||
1064 | |||
1065 | pkt4->shdr.type = htons (GNUNET_MESSAGE_TYPE_VPN_HELPER); | ||
1066 | pkt4->shdr.size = htons (size); | ||
1067 | |||
1068 | pkt4->tun.flags = 0; | ||
1069 | pkt4->tun.type = htons (0x0800); | ||
1070 | |||
1071 | pkt4->ip_hdr.version = 4; | ||
1072 | pkt4->ip_hdr.hdr_lngth = 5; | ||
1073 | pkt4->ip_hdr.diff_serv = 0; | ||
1074 | pkt4->ip_hdr.tot_lngth = htons (20 + pktlen); | ||
1075 | pkt4->ip_hdr.ident = 0; | ||
1076 | pkt4->ip_hdr.flags = 0; | ||
1077 | pkt4->ip_hdr.frag_off = 0; | ||
1078 | pkt4->ip_hdr.ttl = 255; | ||
1079 | pkt4->ip_hdr.proto = 0x06; | ||
1080 | pkt4->ip_hdr.chks = 0; /* Will be calculated later */ | ||
899 | 1081 | ||
900 | pkt6->shdr.type = htons(GNUNET_MESSAGE_TYPE_VPN_HELPER); | 1082 | { |
901 | pkt6->shdr.size = htons(size); | 1083 | char *ipv4addr; |
1084 | uint32_t dadr; | ||
1085 | GNUNET_assert (GNUNET_OK == | ||
1086 | GNUNET_CONFIGURATION_get_value_string (cfg, "vpn", | ||
1087 | "IPV4ADDR", | ||
1088 | &ipv4addr)); | ||
1089 | inet_pton (AF_INET, ipv4addr, &dadr); | ||
1090 | GNUNET_free (ipv4addr); | ||
1091 | pkt4->ip_hdr.dadr = dadr; | ||
1092 | } | ||
902 | 1093 | ||
903 | pkt6->tun.flags = 0; | 1094 | memcpy (&pkt4->tcp_hdr, pkt, pktlen); |
904 | pkt6->tun.type = htons(0x86dd); | ||
905 | 1095 | ||
906 | pkt6->ip6_hdr.version = 6; | 1096 | GNUNET_HashCode *key = address4_mapping_exists (pkt4->ip_hdr.sadr); |
907 | pkt6->ip6_hdr.tclass_h = 0; | 1097 | GNUNET_assert (key != NULL); |
908 | pkt6->ip6_hdr.tclass_l = 0; | ||
909 | pkt6->ip6_hdr.flowlbl = 0; | ||
910 | pkt6->ip6_hdr.paylgth = htons(pktlen); | ||
911 | pkt6->ip6_hdr.nxthdr = 0x06; | ||
912 | pkt6->ip6_hdr.hoplmt = 0xff; | ||
913 | 1098 | ||
914 | { | 1099 | struct map_entry *me = GNUNET_CONTAINER_multihashmap_get (hashmap, key); |
915 | char* ipv6addr; | 1100 | GNUNET_CONTAINER_heap_update_cost (heap, me->heap_node, |
916 | GNUNET_assert(GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(cfg, "vpn", "IPV6ADDR", &ipv6addr)); | 1101 | GNUNET_TIME_absolute_get (). |
917 | inet_pton (AF_INET6, ipv6addr, pkt6->ip6_hdr.dadr); | 1102 | abs_value); |
918 | GNUNET_free(ipv6addr); | 1103 | |
919 | } | 1104 | GNUNET_free (key); |
920 | memcpy(&pkt6->tcp_hdr, pkt, pktlen); | 1105 | |
921 | 1106 | GNUNET_assert (me != NULL); | |
922 | GNUNET_HashCode* key = address6_mapping_exists(pkt6->ip6_hdr.sadr); | 1107 | pkt4->tcp_hdr.crc = 0; |
923 | GNUNET_assert (key != NULL); | 1108 | uint32_t sum = 0; |
924 | 1109 | uint32_t tmp; | |
925 | struct map_entry *me = GNUNET_CONTAINER_multihashmap_get(hashmap, key); | 1110 | tmp = pkt4->ip_hdr.sadr; |
926 | GNUNET_CONTAINER_heap_update_cost (heap, me->heap_node, | 1111 | sum = |
927 | GNUNET_TIME_absolute_get ().abs_value); | 1112 | calculate_checksum_update (sum, (uint16_t *) & tmp, 4); |
928 | 1113 | tmp = pkt4->ip_hdr.dadr; | |
929 | GNUNET_free(key); | 1114 | sum = |
930 | 1115 | calculate_checksum_update (sum, (uint16_t *) & tmp, 4); | |
931 | GNUNET_assert (me != NULL); | 1116 | |
932 | if (ntohs(message->type) == GNUNET_MESSAGE_TYPE_SERVICE_UDP_BACK) | 1117 | tmp = (0x06 << 16) | (0xffff & pktlen); |
933 | GNUNET_assert (me->desc.service_type & htonl(GNUNET_DNS_SERVICE_TYPE_TCP)); | 1118 | |
934 | 1119 | tmp = htonl(tmp); | |
935 | pkt6->tcp_hdr.crc = 0; | 1120 | |
936 | uint32_t sum = 0; | 1121 | sum = calculate_checksum_update (sum, (uint16_t *) & tmp, 4); |
937 | uint32_t tmp; | 1122 | |
938 | sum = | 1123 | sum = |
939 | calculate_checksum_update (sum, (uint16_t *) & pkt6->ip6_hdr.sadr, 16); | 1124 | calculate_checksum_update (sum, (uint16_t *) & pkt4->tcp_hdr, pktlen); |
940 | sum = | 1125 | pkt4->tcp_hdr.crc = calculate_checksum_end (sum); |
941 | calculate_checksum_update (sum, (uint16_t *) & pkt6->ip6_hdr.dadr, 16); | 1126 | |
942 | tmp = htonl(pktlen); | 1127 | pkt4->ip_hdr.chks = |
943 | sum = calculate_checksum_update (sum, (uint16_t *) & tmp, 4); | 1128 | calculate_ip_checksum ((uint16_t *) & pkt4->ip_hdr, 5 * 4); |
944 | tmp = htonl (((pkt6->ip6_hdr.nxthdr & 0x000000ff))); | 1129 | |
945 | sum = calculate_checksum_update (sum, (uint16_t *) & tmp, 4); | 1130 | write_to_helper (pkt4, size); |
946 | 1131 | } | |
947 | sum = | ||
948 | calculate_checksum_update (sum, (uint16_t *) & pkt6->tcp_hdr, | ||
949 | ntohs (pkt6->ip6_hdr.paylgth)); | ||
950 | pkt6->tcp_hdr.crc = calculate_checksum_end (sum); | ||
951 | |||
952 | write_to_helper(pkt6, size); | ||
953 | 1132 | ||
954 | return GNUNET_OK; | 1133 | return GNUNET_OK; |
955 | } | 1134 | } |