aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2012-01-11 22:11:12 +0000
committerChristian Grothoff <christian@grothoff.org>2012-01-11 22:11:12 +0000
commit2f31bf62ac7c57984f9e674fca3fc9eb68b1b656 (patch)
tree9d5e17d2e444e665285abf26838d87b512b5c932 /src
parent5826f9d6280175acde486a1b02c93197a49396bd (diff)
downloadgnunet-2f31bf62ac7c57984f9e674fca3fc9eb68b1b656.tar.gz
gnunet-2f31bf62ac7c57984f9e674fca3fc9eb68b1b656.zip
-building IPv6 UDP reply messages for TUN
Diffstat (limited to 'src')
-rw-r--r--src/vpn/gnunet-service-vpn.c129
1 files changed, 62 insertions, 67 deletions
diff --git a/src/vpn/gnunet-service-vpn.c b/src/vpn/gnunet-service-vpn.c
index 7eeb76908..9739e24d0 100644
--- a/src/vpn/gnunet-service-vpn.c
+++ b/src/vpn/gnunet-service-vpn.c
@@ -1064,80 +1064,75 @@ receive_udp_back (void *cls GNUNET_UNUSED, struct GNUNET_MESH_Tunnel *tunnel,
1064 } 1064 }
1065 break; 1065 break;
1066 case AF_INET6: 1066 case AF_INET6:
1067 // FIXME: parse message, build IP packet, give to TUN!
1068#if 0
1069 pkt6->shdr.type = htons (GNUNET_MESSAGE_TYPE_VPN_HELPER);
1070 pkt6->shdr.size = htons (size);
1071
1072 pkt6->tun.flags = 0;
1073 pkt6->tun.type = htons (0x86dd);
1074
1075 pkt6->ip6_hdr.version = 6;
1076 pkt6->ip6_hdr.tclass_h = 0;
1077 pkt6->ip6_hdr.tclass_l = 0;
1078 pkt6->ip6_hdr.flowlbl = 0;
1079 pkt6->ip6_hdr.paylgth = pkt->len;
1080 pkt6->ip6_hdr.nxthdr = IPPROTO_UDP;
1081 pkt6->ip6_hdr.hoplmt = 0xff;
1082
1083 { 1067 {
1084 char *ipv6addr; 1068 size_t size = sizeof (struct ip6_header)
1085 1069 + sizeof (struct udp_packet)
1086 GNUNET_assert (GNUNET_OK == 1070 + sizeof (struct GNUNET_MessageHeader) +
1087 GNUNET_CONFIGURATION_get_value_string (cfg, "vpn", 1071 sizeof (struct tun_header) +
1088 "IPV6ADDR", 1072 mlen;
1089 &ipv6addr)); 1073 {
1090 inet_pton (AF_INET6, ipv6addr, &pkt6->ip6_hdr.dadr); 1074 char buf[size];
1091 GNUNET_free (ipv6addr); 1075 struct GNUNET_MessageHeader *msg = (struct GNUNET_MessageHeader *) buf;
1076 struct tun_header *tun = (struct tun_header*) &msg[1];
1077 struct ip6_header *ipv6 = (struct ip6_header *) &tun[1];
1078 struct udp_packet *udp = (struct udp_packet *) &ipv6[1];
1079 msg->type = htons (GNUNET_MESSAGE_TYPE_VPN_HELPER);
1080 msg->size = htons (size);
1081 tun->flags = htons (0);
1082 tun->proto = htons (ETH_P_IPV6);
1083 ipv6->traffic_class_h = 0;
1084 ipv6->version = 6;
1085 ipv6->traffic_class_l = 0;
1086 ipv6->flow_label = 0;
1087 ipv6->payload_length = htons (sizeof (struct udp_packet) + sizeof (struct ip6_header) + mlen);
1088 ipv6->next_header = IPPROTO_UDP;
1089 ipv6->hop_limit = 255;
1090 ipv6->source_address = ts->destination_ip.v6;
1091 ipv6->destination_address = ts->source_ip.v6;
1092 if (0 == ntohs (reply->source_port))
1093 udp->spt = htons (ts->destination_port);
1094 else
1095 udp->spt = reply->source_port;
1096 if (0 == ntohs (reply->destination_port))
1097 udp->dpt = htons (ts->source_port);
1098 else
1099 udp->dpt = reply->destination_port;
1100 udp->len = htons (mlen + sizeof (struct udp_packet));
1101 udp->crc = 0;
1102 memcpy (&udp[1],
1103 &reply[1],
1104 mlen);
1105 {
1106 uint32_t sum = 0;
1107 sum =
1108 GNUNET_CRYPTO_crc16_step (sum, &ipv6->source_address,
1109 sizeof (struct in6_addr) * 2);
1110 uint32_t tmp = udp->len;
1111 sum = GNUNET_CRYPTO_crc16_step (sum, &tmp, sizeof (uint32_t));
1112 tmp = htons (IPPROTO_UDP);
1113 sum = GNUNET_CRYPTO_crc16_step (sum, &tmp, sizeof (uint32_t));
1114 sum = GNUNET_CRYPTO_crc16_step (sum,
1115 udp,
1116 ntohs (udp->len));
1117 udp->crc = GNUNET_CRYPTO_crc16_finish (sum);
1118 }
1119 (void) GNUNET_HELPER_send (helper_handle,
1120 msg,
1121 GNUNET_YES,
1122 NULL, NULL);
1123 }
1092 } 1124 }
1093 memcpy (&pkt6->udp_hdr, pkt, ntohs (pkt->len));
1094
1095 GNUNET_HashCode *key = address6_mapping_exists (&pkt6->ip6_hdr.sadr);
1096
1097 GNUNET_assert (key != NULL);
1098
1099 struct map_entry *me = GNUNET_CONTAINER_multihashmap_get (hashmap, key);
1100
1101 GNUNET_CONTAINER_heap_update_cost (heap, me->heap_node,
1102 GNUNET_TIME_absolute_get ().abs_value);
1103
1104 GNUNET_free (key);
1105
1106 GNUNET_assert (me != NULL);
1107
1108 pkt6->udp_hdr.crc = 0;
1109 uint32_t sum = 0;
1110
1111 sum =
1112 GNUNET_CRYPTO_crc16_step (sum, (uint16_t *) & pkt6->ip6_hdr.sadr, 16);
1113 sum =
1114 GNUNET_CRYPTO_crc16_step (sum, (uint16_t *) & pkt6->ip6_hdr.dadr, 16);
1115 uint32_t tmp = (pkt6->udp_hdr.len & 0xffff);
1116
1117 sum = GNUNET_CRYPTO_crc16_step (sum, (uint16_t *) & tmp, 4);
1118 tmp = htons (((pkt6->ip6_hdr.nxthdr & 0x00ff)));
1119 sum = GNUNET_CRYPTO_crc16_step (sum, (uint16_t *) & tmp, 4);
1120
1121 sum =
1122 GNUNET_CRYPTO_crc16_step (sum, (uint16_t *) & pkt6->udp_hdr,
1123 ntohs (pkt->len));
1124 pkt6->udp_hdr.crc = GNUNET_CRYPTO_crc16_finish (sum);
1125
1126 (void) GNUNET_HELPER_send (helper_handle,
1127 &pkt6->shdr,
1128 GNUNET_YES,
1129 NULL, NULL);
1130#endif
1131 break; 1125 break;
1132 default: 1126 default:
1133 GNUNET_assert (0); 1127 GNUNET_assert (0);
1134 } 1128 }
1135#if 0 1129#if 0
1136 struct map_entry *me = GNUNET_CONTAINER_multihashmap_get (hashmap, key); 1130 // FIXME: refresh entry to avoid expiration...
1137 1131 struct map_entry *me = GNUNET_CONTAINER_multihashmap_get (hashmap, key);
1138 GNUNET_CONTAINER_heap_update_cost (heap, me->heap_node, 1132
1139 GNUNET_TIME_absolute_get ().abs_value); 1133 GNUNET_CONTAINER_heap_update_cost (heap, me->heap_node,
1140 1134 GNUNET_TIME_absolute_get ().abs_value);
1135
1141#endif 1136#endif
1142 return GNUNET_OK; 1137 return GNUNET_OK;
1143} 1138}