+ setBit (me->additional_ports, port);
+}
+
+static int
+receive_udp_back (void *cls
+ __attribute__ ((unused)), struct GNUNET_MESH_Tunnel *tunnel,
+ void **tunnel_ctx, const struct GNUNET_PeerIdentity *sender,
+ const struct GNUNET_MessageHeader *message,
+ const struct GNUNET_ATS_Information *atsi
+ __attribute__ ((unused)))
+{
+ GNUNET_HashCode *desc = (GNUNET_HashCode *) (message + 1);
+ struct remote_addr *s = (struct remote_addr *) desc;
+ struct udp_pkt *pkt = (struct udp_pkt *) (desc + 1);
+ const struct GNUNET_PeerIdentity *other = sender;
+ struct tunnel_state *ts = *tunnel_ctx;
+
+ if (16 == ts->addrlen)
+ {
+ size_t size =
+ sizeof (struct ip6_udp) + ntohs (pkt->len) - 1 -
+ sizeof (struct udp_pkt);
+
+ struct ip6_udp *pkt6 = alloca (size);
+
+ GNUNET_assert (pkt6 != NULL);
+
+ if (ntohs (message->type) == GNUNET_MESSAGE_TYPE_VPN_SERVICE_UDP_BACK)
+ new_ip6addr (pkt6->ip6_hdr.sadr, &other->hashPubKey, desc);
+ else
+ new_ip6addr_remote (pkt6->ip6_hdr.sadr, s->addr, s->addrlen);
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Relaying calc:%d gnu:%d udp:%d bytes!\n", size,
+ ntohs (message->size), ntohs (pkt->len));
+
+ pkt6->shdr.type = htons (GNUNET_MESSAGE_TYPE_VPN_HELPER);
+ pkt6->shdr.size = htons (size);
+
+ pkt6->tun.flags = 0;
+ pkt6->tun.type = htons (0x86dd);
+
+ pkt6->ip6_hdr.version = 6;
+ pkt6->ip6_hdr.tclass_h = 0;
+ pkt6->ip6_hdr.tclass_l = 0;
+ pkt6->ip6_hdr.flowlbl = 0;
+ pkt6->ip6_hdr.paylgth = pkt->len;
+ pkt6->ip6_hdr.nxthdr = IPPROTO_UDP;
+ pkt6->ip6_hdr.hoplmt = 0xff;
+
+ {
+ char *ipv6addr;
+
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_CONFIGURATION_get_value_string (cfg, "vpn",
+ "IPV6ADDR",
+ &ipv6addr));
+ inet_pton (AF_INET6, ipv6addr, pkt6->ip6_hdr.dadr);
+ GNUNET_free (ipv6addr);
+ }
+ memcpy (&pkt6->udp_hdr, pkt, ntohs (pkt->len));
+
+ GNUNET_HashCode *key = address6_mapping_exists (pkt6->ip6_hdr.sadr);
+
+ GNUNET_assert (key != NULL);
+
+ struct map_entry *me = GNUNET_CONTAINER_multihashmap_get (hashmap, key);
+
+ GNUNET_CONTAINER_heap_update_cost (heap, me->heap_node,
+ GNUNET_TIME_absolute_get ().abs_value);
+
+ GNUNET_free (key);
+
+ GNUNET_assert (me != NULL);
+ if (ntohs (message->type) == GNUNET_MESSAGE_TYPE_VPN_SERVICE_UDP_BACK)
+ {
+ GNUNET_assert (me->desc.
+ service_type & htonl (GNUNET_DNS_SERVICE_TYPE_UDP));
+ if (!port_in_ports (me->desc.ports, pkt6->udp_hdr.spt) &&
+ !testBit (me->additional_ports, ntohs (pkt6->udp_hdr.spt)))
+ {
+ add_additional_port (me, ntohs (pkt6->udp_hdr.spt));
+ }
+ }
+
+ pkt6->udp_hdr.crc = 0;
+ uint32_t sum = 0;
+
+ sum =
+ calculate_checksum_update (sum, (uint16_t *) & pkt6->ip6_hdr.sadr, 16);
+ sum =
+ calculate_checksum_update (sum, (uint16_t *) & pkt6->ip6_hdr.dadr, 16);
+ uint32_t tmp = (pkt6->udp_hdr.len & 0xffff);
+
+ sum = calculate_checksum_update (sum, (uint16_t *) & tmp, 4);
+ tmp = htons (((pkt6->ip6_hdr.nxthdr & 0x00ff)));
+ sum = calculate_checksum_update (sum, (uint16_t *) & tmp, 4);
+
+ sum =
+ calculate_checksum_update (sum, (uint16_t *) & pkt6->udp_hdr,
+ ntohs (pkt->len));
+ pkt6->udp_hdr.crc = calculate_checksum_end (sum);
+
+ write_to_helper (pkt6, size);
+ }
+ else
+ {
+ size_t size =
+ sizeof (struct ip_udp) + ntohs (pkt->len) - 1 - sizeof (struct udp_pkt);
+
+ struct ip_udp *pkt4 = alloca (size);
+
+ GNUNET_assert (pkt4 != NULL);
+
+ GNUNET_assert (ntohs (message->type) ==
+ GNUNET_MESSAGE_TYPE_VPN_REMOTE_UDP_BACK);
+ uint32_t sadr;
+
+ new_ip4addr_remote ((unsigned char *) &sadr, s->addr, s->addrlen);
+ pkt4->ip_hdr.sadr = sadr;
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Relaying calc:%d gnu:%d udp:%d bytes!\n", size,
+ ntohs (message->size), ntohs (pkt->len));
+
+ pkt4->shdr.type = htons (GNUNET_MESSAGE_TYPE_VPN_HELPER);
+ pkt4->shdr.size = htons (size);
+
+ pkt4->tun.flags = 0;
+ pkt4->tun.type = htons (0x0800);
+
+ pkt4->ip_hdr.version = 4;
+ pkt4->ip_hdr.hdr_lngth = 5;
+ pkt4->ip_hdr.diff_serv = 0;
+ pkt4->ip_hdr.tot_lngth = htons (20 + ntohs (pkt->len));
+ pkt4->ip_hdr.ident = 0;
+ pkt4->ip_hdr.flags = 0;
+ pkt4->ip_hdr.frag_off = 0;
+ pkt4->ip_hdr.ttl = 255;
+ pkt4->ip_hdr.proto = IPPROTO_UDP;
+ pkt4->ip_hdr.chks = 0; /* Will be calculated later */
+