#include "gnunet_container_lib.h"
#include "gnunet_constants.h"
#include <block_dns.h>
-#include "gnunet-daemon-vpn-helper.h"
#include "gnunet_dns_service.h"
-#include "gnunet-daemon-vpn.h"
-#include "gnunet-vpn-checksum.h"
-const struct GNUNET_CONFIGURATION_Handle *cfg;
-struct GNUNET_MESH_Handle *mesh_handle;
-struct GNUNET_CONTAINER_MultiHashMap *hashmap;
-static struct GNUNET_CONTAINER_Heap *heap;
-struct GNUNET_DNS_Handle *dns_handle;
+struct answer_packet_list
+{
+ struct answer_packet_list *next;
+ struct answer_packet_list *prev;
+ struct GNUNET_SERVER_Client *client;
+ struct answer_packet pkt;
+};
+
+
+struct map_entry
+{
+ /** The description of the service (used for service) */
+ struct GNUNET_vpn_service_descriptor desc;
+
+ /** The real address of the service (used for remote) */
+ char addrlen;
+ char addr[16];
+
+ struct GNUNET_MESH_Tunnel *tunnel;
+ uint16_t namelen;
+ char additional_ports[8192];
+
+ struct GNUNET_CONTAINER_HeapNode *heap_node;
+ GNUNET_HashCode hash;
+ /**
+ * After this struct the name is located in DNS-Format!
+ */
+};
-struct answer_packet_list *answer_proc_head;
-struct answer_packet_list *answer_proc_tail;
+struct remote_addr
+{
+ char addrlen;
+ unsigned char addr[16];
+ char proto;
+};
struct tunnel_notify_queue
void *cls;
};
+
+struct tunnel_state
+{
+ struct GNUNET_MESH_TransmitHandle *th;
+ struct tunnel_notify_queue *head, *tail;
+
+ int addrlen;
+};
+
+
+static const struct GNUNET_CONFIGURATION_Handle *cfg;
+
+static struct GNUNET_MESH_Handle *mesh_handle;
+
+static struct GNUNET_CONTAINER_MultiHashMap *hashmap;
+
+static struct GNUNET_CONTAINER_Heap *heap;
+
+/**
+ * The handle to the helper
+ */
+static struct GNUNET_HELPER_Handle *helper_handle;
+
+/**
+ * Arguments to the exit helper.
+ */
+static char *vpn_argv[7];
+
+static struct GNUNET_DNS_Handle *dns_handle;
+
+static struct answer_packet_list *answer_proc_head;
+
+static struct answer_packet_list *answer_proc_tail;
+
/**
* If there are at least this many address-mappings, old ones will be removed
*/
*/
static struct GNUNET_CONTAINER_MultiHashMap *udp_connections;
-GNUNET_SCHEDULER_TaskIdentifier conn_task;
+static GNUNET_SCHEDULER_TaskIdentifier conn_task;
-GNUNET_SCHEDULER_TaskIdentifier shs_task;
+static GNUNET_SCHEDULER_TaskIdentifier shs_task;
+
+/**
+ * The tunnels that will be used to send tcp- and udp-packets
+ */
+static struct GNUNET_MESH_Tunnel *tcp_tunnel;
+static struct GNUNET_MESH_Tunnel *udp_tunnel;
+
+
+static unsigned int
+port_in_ports (uint64_t ports, uint16_t port)
+{
+ uint16_t *ps = (uint16_t *) & ports;
+
+ return ports == 0 || ps[0] == port || ps[1] == port || ps[2] == port ||
+ ps[3] == port;
+}
/**
* @param bitIdx which bit to test
* @return GNUNET_YES if the bit is set, GNUNET_NO if not.
*/
-int
+static int
testBit (char *bitArray, unsigned int bitIdx)
{
size_t slot;
cleanup (void *cls GNUNET_UNUSED,
const struct GNUNET_SCHEDULER_TaskContext *tskctx)
{
- GNUNET_assert (0 != (tskctx->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN));
-
- /* stop the helper */
- cleanup_helper (helper_handle);
+ unsigned int i;
+ GNUNET_assert (0 != (tskctx->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN));
/* close the connection to the service-dns */
GNUNET_DNS_disconnect (dns_handle);
if (mesh_handle != NULL)
GNUNET_MESH_disconnect (mesh_handle);
mesh_handle = NULL;
}
+ if (helper_handle != NULL)
+ {
+ GNUNET_HELPER_stop (helper_handle);
+ helper_handle = NULL;
+ }
if (GNUNET_SCHEDULER_NO_TASK != shs_task)
{
GNUNET_SCHEDULER_cancel (shs_task);
GNUNET_SCHEDULER_cancel (conn_task);
conn_task = GNUNET_SCHEDULER_NO_TASK;
}
+ for (i=0;i<5;i++)
+ GNUNET_free_non_null (vpn_argv[i]);
}
/*}}}*/
/**
* @return the hash of the IP-Address if a mapping exists, NULL otherwise
*/
-GNUNET_HashCode *
+static GNUNET_HashCode *
address6_mapping_exists (struct in6_addr *v6addr)
{
unsigned char *addr = (unsigned char*) v6addr;
/**
* @return the hash of the IP-Address if a mapping exists, NULL otherwise
*/
-GNUNET_HashCode *
+static GNUNET_HashCode *
address4_mapping_exists (uint32_t addr)
{
GNUNET_HashCode *key = GNUNET_malloc (sizeof (GNUNET_HashCode));
}
}
-static void
-collect_mappings (void *cls GNUNET_UNUSED,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
-{
- if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
- return;
-
- struct map_entry *me = GNUNET_CONTAINER_heap_remove_root (heap);
-
- /* This is free()ed memory! */
- me->heap_node = NULL;
-
- /* FIXME! GNUNET_MESH_close_tunnel(me->tunnel); */
- GNUNET_assert (GNUNET_YES ==
- GNUNET_CONTAINER_multihashmap_remove (hashmap, &me->hash, me));
+static void *
+initialize_tunnel_state (int addrlen, struct GNUNET_MESH_TransmitHandle *th)
+{
+ struct tunnel_state *ts = GNUNET_malloc (sizeof *ts);
- GNUNET_free (me);
+ ts->addrlen = addrlen;
+ ts->th = th;
+ return ts;
}
-void
+
+static void
send_icmp4_response (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
response->ip_hdr.tot_lngth = request->ip_hdr.tot_lngth;
response->ip_hdr.chks =
- calculate_ip_checksum ((uint16_t *) & response->ip_hdr, 20);
+ GNUNET_CRYPTO_crc16_n ((uint16_t *) & response->ip_hdr, 20);
response->icmp_hdr.code = 0;
response->icmp_hdr.type = 0x0;
memcpy (response + 1, request + 1,
ntohs (request->shdr.size) - sizeof (struct ip_icmp));
- write_to_helper (response, ntohs (response->shdr.size));
-
+ (void) GNUNET_HELPER_send (helper_handle,
+ &response->shdr,
+ GNUNET_YES,
+ NULL, NULL);
GNUNET_free (request);
}
-void
+
+static void
send_icmp6_response (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
memcpy (response + 1, request + 1,
ntohs (request->shdr.size) - sizeof (struct ip6_icmp));
- write_to_helper (response, ntohs (response->shdr.size));
-
+ (void) GNUNET_HELPER_send (helper_handle,
+ &response->shdr,
+ GNUNET_YES,
+ NULL, NULL);
GNUNET_free (request);
}
+
/**
* cls is the pointer to a GNUNET_MessageHeader that is
* followed by the service-descriptor and the packet that should be sent;
return size;
}
-unsigned int
-port_in_ports (uint64_t ports, uint16_t port)
-{
- uint16_t *ps = (uint16_t *) & ports;
-
- return ports == 0 || ps[0] == port || ps[1] == port || ps[2] == port ||
- ps[3] == port;
-}
-void
+static void
send_pkt_to_peer (void *cls, const struct GNUNET_PeerIdentity *peer,
const struct GNUNET_ATS_Information *atsi GNUNET_UNUSED)
{
}
}
+
+
+
+/**
+ * Receive packets from the helper-process
+ */
+static void
+message_token (void *cls GNUNET_UNUSED, void *client GNUNET_UNUSED,
+ const struct GNUNET_MessageHeader *message)
+{
+ GNUNET_assert (ntohs (message->type) == GNUNET_MESSAGE_TYPE_VPN_HELPER);
+
+ struct tun_pkt *pkt_tun = (struct tun_pkt *) message;
+ GNUNET_HashCode *key;
+
+ /* ethertype is ipv6 */
+ if (ntohs (pkt_tun->tun.type) == 0x86dd)
+ {
+ struct ip6_pkt *pkt6 = (struct ip6_pkt *) message;
+
+ GNUNET_assert (pkt6->ip6_hdr.version == 6);
+ struct ip6_tcp *pkt6_tcp;
+ struct ip6_udp *pkt6_udp;
+ struct ip6_icmp *pkt6_icmp;
+
+ pkt6_udp = NULL; /* make compiler happy */
+ switch (pkt6->ip6_hdr.nxthdr)
+ {
+ case IPPROTO_UDP:
+ pkt6_udp = (struct ip6_udp *) pkt6;
+ /* Send dns-packets to the service-dns */
+ if (ntohs (pkt6_udp->udp_hdr.dpt) == 53)
+ {
+ /* 9 = 8 for the udp-header + 1 for the unsigned char data[1]; */
+ GNUNET_DNS_queue_request_v6 (dns_handle,
+ &pkt6->ip6_hdr.dadr,
+ &pkt6->ip6_hdr.sadr,
+ ntohs (pkt6_udp->udp_hdr.spt),
+ ntohs (pkt6_udp->udp_hdr.len) - 8,
+ (const void*) pkt6_udp->data);
+
+ break;
+ }
+ /* fall through */
+ case IPPROTO_TCP:
+ pkt6_tcp = (struct ip6_tcp *) pkt6;
+
+ if ((key = address6_mapping_exists (&pkt6->ip6_hdr.dadr)) != NULL)
+ {
+ struct map_entry *me = GNUNET_CONTAINER_multihashmap_get (hashmap, key);
+
+ GNUNET_assert (me != NULL);
+ GNUNET_free (key);
+
+ size_t size =
+ sizeof (struct GNUNET_MESH_Tunnel *) +
+ sizeof (struct GNUNET_MessageHeader) + sizeof (GNUNET_HashCode) +
+ ntohs (pkt6->ip6_hdr.paylgth);
+
+ struct GNUNET_MESH_Tunnel **cls = GNUNET_malloc (size);
+ struct GNUNET_MessageHeader *hdr =
+ (struct GNUNET_MessageHeader *) (cls + 1);
+ GNUNET_HashCode *hc = (GNUNET_HashCode *) (hdr + 1);
+
+ hdr->size =
+ htons (sizeof (struct GNUNET_MessageHeader) +
+ sizeof (GNUNET_HashCode) + ntohs (pkt6->ip6_hdr.paylgth));
+
+ GNUNET_MESH_ApplicationType app_type = 0; /* fix compiler uninitialized warning... */
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "me->addrlen is %d\n",
+ me->addrlen);
+ if (me->addrlen == 0)
+ {
+ /* This is a mapping to a gnunet-service */
+ memcpy (hc, &me->desc.service_descriptor, sizeof (GNUNET_HashCode));
+
+ if (IPPROTO_UDP == pkt6->ip6_hdr.nxthdr &&
+ (me->desc.service_type & htonl (GNUNET_DNS_SERVICE_TYPE_UDP)) &&
+ (port_in_ports (me->desc.ports, pkt6_udp->udp_hdr.dpt) ||
+ testBit (me->additional_ports, ntohs (pkt6_udp->udp_hdr.dpt))))
+ {
+ hdr->type = htons (GNUNET_MESSAGE_TYPE_VPN_SERVICE_UDP);
+
+ memcpy (hc + 1, &pkt6_udp->udp_hdr, ntohs (pkt6_udp->udp_hdr.len));
+
+ }
+ else if (IPPROTO_TCP == pkt6->ip6_hdr.nxthdr &&
+ (me->desc.service_type & htonl (GNUNET_DNS_SERVICE_TYPE_TCP))
+ && (port_in_ports (me->desc.ports, pkt6_tcp->tcp_hdr.dpt)))
+ {
+ hdr->type = htons (GNUNET_MESSAGE_TYPE_VPN_SERVICE_TCP);
+
+ memcpy (hc + 1, &pkt6_tcp->tcp_hdr, ntohs (pkt6->ip6_hdr.paylgth));
+
+ }
+ else
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "pip: %d\n",
+ port_in_ports (me->desc.ports, pkt6_tcp->tcp_hdr.dpt));
+ GNUNET_assert (0);
+ }
+ if (me->tunnel == NULL && NULL != cls)
+ {
+ *cls =
+ GNUNET_MESH_tunnel_create (mesh_handle,
+ initialize_tunnel_state (16, NULL),
+ &send_pkt_to_peer, NULL, cls);
+
+ GNUNET_MESH_peer_request_connect_add (*cls,
+ (struct GNUNET_PeerIdentity *)
+ &me->desc.peer);
+ me->tunnel = *cls;
+ }
+ else if (NULL != cls)
+ {
+ *cls = me->tunnel;
+ send_pkt_to_peer (cls, (struct GNUNET_PeerIdentity *) 1, NULL);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Queued to send IPv6 to peer %x, type %d\n",
+ *((unsigned int *) &me->desc.peer), ntohs (hdr->type));
+ }
+ }
+ else
+ {
+ /* This is a mapping to a "real" address */
+ struct remote_addr *s = (struct remote_addr *) hc;
+
+ s->addrlen = me->addrlen;
+ memcpy (s->addr, me->addr, me->addrlen);
+ s->proto = pkt6->ip6_hdr.nxthdr;
+ if (s->proto == IPPROTO_UDP)
+ {
+ hdr->type = htons (GNUNET_MESSAGE_TYPE_VPN_REMOTE_UDP);
+ memcpy (hc + 1, &pkt6_udp->udp_hdr, ntohs (pkt6_udp->udp_hdr.len));
+ app_type = GNUNET_APPLICATION_TYPE_INTERNET_UDP_GATEWAY;
+ if (NULL != udp_tunnel)
+ me->tunnel = udp_tunnel;
+ }
+ else if (s->proto == IPPROTO_TCP)
+ {
+ hdr->type = htons (GNUNET_MESSAGE_TYPE_VPN_REMOTE_TCP);
+ memcpy (hc + 1, &pkt6_tcp->tcp_hdr, ntohs (pkt6->ip6_hdr.paylgth));
+ app_type = GNUNET_APPLICATION_TYPE_INTERNET_TCP_GATEWAY;
+ if (NULL != tcp_tunnel)
+ me->tunnel = tcp_tunnel;
+ }
+ else
+ {
+ GNUNET_assert (0);
+ }
+ if (me->tunnel == NULL && NULL != cls)
+ {
+ *cls =
+ GNUNET_MESH_tunnel_create (mesh_handle,
+ initialize_tunnel_state (16, NULL),
+ &send_pkt_to_peer, NULL, cls);
+
+ GNUNET_MESH_peer_request_connect_by_type (*cls, app_type);
+ me->tunnel = *cls;
+ if (GNUNET_APPLICATION_TYPE_INTERNET_UDP_GATEWAY == app_type)
+ udp_tunnel = *cls;
+ else if (GNUNET_APPLICATION_TYPE_INTERNET_TCP_GATEWAY == app_type)
+ tcp_tunnel = *cls;
+ }
+ else if (NULL != cls)
+ {
+ *cls = me->tunnel;
+ send_pkt_to_peer (cls, (struct GNUNET_PeerIdentity *) 1, NULL);
+ }
+ }
+ }
+ else
+ {
+ char pbuf[INET6_ADDRSTRLEN];
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Packet to %s, which has no mapping\n",
+ inet_ntop (AF_INET6,
+ &pkt6->ip6_hdr.dadr,
+ pbuf,
+ sizeof (pbuf)));
+ }
+ break;
+ case 0x3a:
+ /* ICMPv6 */
+ pkt6_icmp = (struct ip6_icmp *) pkt6;
+ /* If this packet is an icmp-echo-request and a mapping exists, answer */
+ if (pkt6_icmp->icmp_hdr.type == 0x80 &&
+ (key = address6_mapping_exists (&pkt6->ip6_hdr.dadr)) != NULL)
+ {
+ GNUNET_free (key);
+ pkt6_icmp = GNUNET_malloc (ntohs (pkt6->shdr.size));
+ memcpy (pkt6_icmp, pkt6, ntohs (pkt6->shdr.size));
+ GNUNET_SCHEDULER_add_now (&send_icmp6_response, pkt6_icmp);
+ }
+ break;
+ }
+ }
+ /* ethertype is ipv4 */
+ else if (ntohs (pkt_tun->tun.type) == 0x0800)
+ {
+ struct ip_pkt *pkt = (struct ip_pkt *) message;
+ struct ip_udp *udp = (struct ip_udp *) message;
+ struct ip_tcp *pkt_tcp;
+ struct ip_udp *pkt_udp;
+ struct ip_icmp *pkt_icmp;
+
+ GNUNET_assert (pkt->ip_hdr.version == 4);
+
+ /* Send dns-packets to the service-dns */
+ if (pkt->ip_hdr.proto == IPPROTO_UDP && ntohs (udp->udp_hdr.dpt) == 53)
+ {
+ GNUNET_DNS_queue_request_v4 (dns_handle,
+ &pkt->ip_hdr.dadr,
+ &pkt->ip_hdr.sadr,
+ ntohs (udp->udp_hdr.spt),
+ ntohs (udp->udp_hdr.len) - 8,
+ (const void*) udp->data);
+ }
+ else
+ {
+ uint32_t dadr = pkt->ip_hdr.dadr.s_addr;
+ unsigned char *c = (unsigned char *) &dadr;
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Packet to %d.%d.%d.%d, proto %x\n",
+ c[0], c[1], c[2], c[3], pkt->ip_hdr.proto);
+ switch (pkt->ip_hdr.proto)
+ {
+ case IPPROTO_TCP:
+ case IPPROTO_UDP:
+ pkt_tcp = (struct ip_tcp *) pkt;
+ pkt_udp = (struct ip_udp *) pkt;
+
+ if ((key = address4_mapping_exists (dadr)) != NULL)
+ {
+ struct map_entry *me =
+ GNUNET_CONTAINER_multihashmap_get (hashmap, key);
+ GNUNET_assert (me != NULL);
+ GNUNET_free (key);
+
+ size_t size =
+ sizeof (struct GNUNET_MESH_Tunnel *) +
+ sizeof (struct GNUNET_MessageHeader) + sizeof (GNUNET_HashCode) +
+ ntohs (pkt->ip_hdr.tot_lngth) - 4 * pkt->ip_hdr.hdr_lngth;
+
+ struct GNUNET_MESH_Tunnel **cls = GNUNET_malloc (size);
+ struct GNUNET_MessageHeader *hdr =
+ (struct GNUNET_MessageHeader *) (cls + 1);
+ GNUNET_HashCode *hc = (GNUNET_HashCode *) (hdr + 1);
+
+ hdr->size =
+ htons (sizeof (struct GNUNET_MessageHeader) +
+ sizeof (GNUNET_HashCode) + ntohs (pkt->ip_hdr.tot_lngth) -
+ 4 * pkt->ip_hdr.hdr_lngth);
+
+ GNUNET_MESH_ApplicationType app_type = 0; /* make compiler happy */
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "me->addrlen is %d\n",
+ me->addrlen);
+ if (me->addrlen == 0)
+ {
+ /* This is a mapping to a gnunet-service */
+ memcpy (hc, &me->desc.service_descriptor, sizeof (GNUNET_HashCode));
+
+ if ((IPPROTO_UDP == pkt->ip_hdr.proto) &&
+ (me->desc.service_type & htonl (GNUNET_DNS_SERVICE_TYPE_UDP)) &&
+ (port_in_ports (me->desc.ports, pkt_udp->udp_hdr.dpt) ||
+ testBit (me->additional_ports, ntohs (pkt_udp->udp_hdr.dpt))))
+ {
+ hdr->type = htons (GNUNET_MESSAGE_TYPE_VPN_SERVICE_UDP);
+
+ memcpy (hc + 1, &pkt_udp->udp_hdr, ntohs (pkt_udp->udp_hdr.len));
+
+ }
+ else if ((IPPROTO_TCP == pkt->ip_hdr.proto) &&
+ (me->
+ desc.service_type & htonl (GNUNET_DNS_SERVICE_TYPE_TCP))
+ && (port_in_ports (me->desc.ports, pkt_tcp->tcp_hdr.dpt)))
+ {
+ hdr->type = htons (GNUNET_MESSAGE_TYPE_VPN_SERVICE_TCP);
+
+ memcpy (hc + 1, &pkt_tcp->tcp_hdr,
+ ntohs (pkt->ip_hdr.tot_lngth) -
+ 4 * pkt->ip_hdr.hdr_lngth);
+
+ }
+ if (me->tunnel == NULL && NULL != cls)
+ {
+ *cls =
+ GNUNET_MESH_tunnel_create (mesh_handle,
+ initialize_tunnel_state (4, NULL),
+ send_pkt_to_peer, NULL, cls);
+ GNUNET_MESH_peer_request_connect_add (*cls,
+ (struct GNUNET_PeerIdentity
+ *) &me->desc.peer);
+ me->tunnel = *cls;
+ }
+ else if (NULL != cls)
+ {
+ *cls = me->tunnel;
+ send_pkt_to_peer (cls, (struct GNUNET_PeerIdentity *) 1, NULL);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Queued to send IPv4 to peer %x, type %d\n",
+ *((unsigned int *) &me->desc.peer),
+ ntohs (hdr->type));
+ }
+ }
+ else
+ {
+ /* This is a mapping to a "real" address */
+ struct remote_addr *s = (struct remote_addr *) hc;
+
+ s->addrlen = me->addrlen;
+ memcpy (s->addr, me->addr, me->addrlen);
+ s->proto = pkt->ip_hdr.proto;
+ if (s->proto == IPPROTO_UDP)
+ {
+ hdr->type = htons (GNUNET_MESSAGE_TYPE_VPN_REMOTE_UDP);
+ memcpy (hc + 1, &pkt_udp->udp_hdr, ntohs (pkt_udp->udp_hdr.len));
+ app_type = GNUNET_APPLICATION_TYPE_INTERNET_UDP_GATEWAY;
+ }
+ else if (s->proto == IPPROTO_TCP)
+ {
+ hdr->type = htons (GNUNET_MESSAGE_TYPE_VPN_REMOTE_TCP);
+ memcpy (hc + 1, &pkt_tcp->tcp_hdr,
+ ntohs (pkt->ip_hdr.tot_lngth) -
+ 4 * pkt->ip_hdr.hdr_lngth);
+ app_type = GNUNET_APPLICATION_TYPE_INTERNET_TCP_GATEWAY;
+ }
+ else
+ GNUNET_assert (0);
+ if (me->tunnel == NULL && NULL != cls)
+ {
+ *cls =
+ GNUNET_MESH_tunnel_create (mesh_handle,
+ initialize_tunnel_state (4, NULL),
+ send_pkt_to_peer, NULL, cls);
+
+ GNUNET_MESH_peer_request_connect_by_type (*cls, app_type);
+ me->tunnel = *cls;
+ }
+ else if (NULL != cls)
+ {
+ *cls = me->tunnel;
+ send_pkt_to_peer (cls, (struct GNUNET_PeerIdentity *) 1, NULL);
+ }
+ }
+ }
+ else
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Packet to %x which has no mapping\n", dadr);
+ }
+ break;
+ case 0x01:
+ /* ICMP */
+ pkt_icmp = (struct ip_icmp *) pkt;
+ if (pkt_icmp->icmp_hdr.type == 0x8 &&
+ (key = address4_mapping_exists (dadr)) != NULL)
+ {
+ GNUNET_free (key);
+ pkt_icmp = GNUNET_malloc (ntohs (pkt->shdr.size));
+ memcpy (pkt_icmp, pkt, ntohs (pkt->shdr.size));
+ GNUNET_SCHEDULER_add_now (&send_icmp4_response, pkt_icmp);
+ }
+ break;
+ }
+ }
+ }
+}
+
+
+
+static void
+collect_mappings (void *cls GNUNET_UNUSED,
+ const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+ if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
+ return;
+
+ struct map_entry *me = GNUNET_CONTAINER_heap_remove_root (heap);
+
+ /* This is free()ed memory! */
+ me->heap_node = NULL;
+
+ /* FIXME! GNUNET_MESH_close_tunnel(me->tunnel); */
+
+ GNUNET_assert (GNUNET_YES ==
+ GNUNET_CONTAINER_multihashmap_remove (hashmap, &me->hash, me));
+
+ GNUNET_free (me);
+}
+
+
/**
* Create a new Address from an answer-packet
*/
-void
+static void
new_ip6addr (struct in6_addr *v6addr,
const GNUNET_HashCode * peer,
const GNUNET_HashCode * service_desc)
/**
* Create a new Address from an answer-packet
*/
-void
+static void
new_ip6addr_remote (struct in6_addr *v6addr,
unsigned char *addr, char addrlen)
{ /* {{{ */
/**
* Create a new Address from an answer-packet
*/
-void
+static void
new_ip4addr_remote (unsigned char *buf, unsigned char *addr, char addrlen)
{ /* {{{ */
char *ipv4addr;
* At the moment this means "inventing" and IPv6-Address for .gnunet-services and
* doing nothing for "real" services.
*/
-void
+static void
process_answer (void *cls,
const struct answer_packet *pkt)
{
GNUNET_CONTAINER_DLL_insert_after (answer_proc_head, answer_proc_tail,
answer_proc_tail, list);
- schedule_helper_write (GNUNET_TIME_UNIT_FOREVER_REL, NULL);
-
- return;
}
uint32_t sum = 0;
sum =
- calculate_checksum_update (sum, (uint16_t *) & pkt6->ip6_hdr.sadr, 16);
+ GNUNET_CRYPTO_crc16_step (sum, (uint16_t *) & pkt6->ip6_hdr.sadr, 16);
sum =
- calculate_checksum_update (sum, (uint16_t *) & pkt6->ip6_hdr.dadr, 16);
+ GNUNET_CRYPTO_crc16_step (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);
+ sum = GNUNET_CRYPTO_crc16_step (sum, (uint16_t *) & tmp, 4);
tmp = htons (((pkt6->ip6_hdr.nxthdr & 0x00ff)));
- sum = calculate_checksum_update (sum, (uint16_t *) & tmp, 4);
+ sum = GNUNET_CRYPTO_crc16_step (sum, (uint16_t *) & tmp, 4);
sum =
- calculate_checksum_update (sum, (uint16_t *) & pkt6->udp_hdr,
+ GNUNET_CRYPTO_crc16_step (sum, (uint16_t *) & pkt6->udp_hdr,
ntohs (pkt->len));
- pkt6->udp_hdr.crc = calculate_checksum_end (sum);
-
- write_to_helper (pkt6, size);
+ pkt6->udp_hdr.crc = GNUNET_CRYPTO_crc16_finish (sum);
+
+ (void) GNUNET_HELPER_send (helper_handle,
+ &pkt6->shdr,
+ GNUNET_YES,
+ NULL, NULL);
}
else
{
pkt4->udp_hdr.crc = 0; /* Optional for IPv4 */
pkt4->ip_hdr.chks =
- calculate_ip_checksum ((uint16_t *) & pkt4->ip_hdr, 5 * 4);
+ GNUNET_CRYPTO_crc16_n ((uint16_t *) & pkt4->ip_hdr, 5 * 4);
- write_to_helper (pkt4, size);
+ (void) GNUNET_HELPER_send (helper_handle,
+ &pkt4->shdr,
+ GNUNET_YES,
+ NULL, NULL);
}
return GNUNET_OK;
uint32_t tmp;
sum =
- calculate_checksum_update (sum, (uint16_t *) & pkt6->ip6_hdr.sadr, 16);
+ GNUNET_CRYPTO_crc16_step (sum, (uint16_t *) & pkt6->ip6_hdr.sadr, 16);
sum =
- calculate_checksum_update (sum, (uint16_t *) & pkt6->ip6_hdr.dadr, 16);
+ GNUNET_CRYPTO_crc16_step (sum, (uint16_t *) & pkt6->ip6_hdr.dadr, 16);
tmp = htonl (pktlen);
- sum = calculate_checksum_update (sum, (uint16_t *) & tmp, 4);
+ sum = GNUNET_CRYPTO_crc16_step (sum, (uint16_t *) & tmp, 4);
tmp = htonl (((pkt6->ip6_hdr.nxthdr & 0x000000ff)));
- sum = calculate_checksum_update (sum, (uint16_t *) & tmp, 4);
+ sum = GNUNET_CRYPTO_crc16_step (sum, (uint16_t *) & tmp, 4);
sum =
- calculate_checksum_update (sum, (uint16_t *) & pkt6->tcp_hdr,
+ GNUNET_CRYPTO_crc16_step (sum, (uint16_t *) & pkt6->tcp_hdr,
ntohs (pkt6->ip6_hdr.paylgth));
- pkt6->tcp_hdr.crc = calculate_checksum_end (sum);
+ pkt6->tcp_hdr.crc = GNUNET_CRYPTO_crc16_finish (sum);
- write_to_helper (pkt6, size);
+ (void) GNUNET_HELPER_send (helper_handle,
+ &pkt6->shdr,
+ GNUNET_YES,
+ NULL, NULL);
}
else
{
uint32_t sum = 0;
uint32_t tmp;
- sum = calculate_checksum_update (sum, (uint16_t *) &pkt4->ip_hdr.sadr, 4);
- sum = calculate_checksum_update (sum, (uint16_t *) &pkt4->ip_hdr.dadr, 4);
+ sum = GNUNET_CRYPTO_crc16_step (sum, (uint16_t *) &pkt4->ip_hdr.sadr, 4);
+ sum = GNUNET_CRYPTO_crc16_step (sum, (uint16_t *) &pkt4->ip_hdr.dadr, 4);
tmp = (0x06 << 16) | (0xffff & pktlen); // 0x06 for TCP?
tmp = htonl (tmp);
- sum = calculate_checksum_update (sum, (uint16_t *) & tmp, 4);
+ sum = GNUNET_CRYPTO_crc16_step (sum, (uint16_t *) & tmp, 4);
- sum = calculate_checksum_update (sum, (uint16_t *) & pkt4->tcp_hdr, pktlen);
- pkt4->tcp_hdr.crc = calculate_checksum_end (sum);
+ sum = GNUNET_CRYPTO_crc16_step (sum, (uint16_t *) & pkt4->tcp_hdr, pktlen);
+ pkt4->tcp_hdr.crc = GNUNET_CRYPTO_crc16_finish (sum);
pkt4->ip_hdr.chks =
- calculate_ip_checksum ((uint16_t *) & pkt4->ip_hdr, 5 * 4);
+ GNUNET_CRYPTO_crc16_n ((uint16_t *) & pkt4->ip_hdr, 5 * 4);
+
+ (void) GNUNET_HELPER_send (helper_handle,
+ &pkt4->shdr,
+ GNUNET_YES,
+ NULL, NULL);
- write_to_helper (pkt4, size);
}
return GNUNET_OK;
{receive_tcp_back, GNUNET_MESSAGE_TYPE_VPN_REMOTE_TCP_BACK, 0},
{NULL, 0, 0}
};
-
static const GNUNET_MESH_ApplicationType types[] = {
GNUNET_APPLICATION_TYPE_END
};
+ char *ifname;
+ char *ipv6addr;
+ char *ipv6prefix;
+ char *ipv4addr;
+ char *ipv4mask;
mesh_handle =
GNUNET_MESH_connect (cfg_, 42, NULL, new_tunnel, cleaner, handlers,
dns_handle = GNUNET_DNS_connect (cfg,
&process_answer,
NULL);
- shs_task =
- GNUNET_SCHEDULER_add_after (conn_task, start_helper_and_schedule, NULL);
+ if (GNUNET_SYSERR ==
+ GNUNET_CONFIGURATION_get_value_string (cfg, "vpn", "IFNAME", &ifname))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "No entry 'IFNAME' in configuration!\n");
+ exit (1);
+ }
+
+ if (GNUNET_SYSERR ==
+ GNUNET_CONFIGURATION_get_value_string (cfg, "vpn", "IPV6ADDR", &ipv6addr))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "No entry 'IPV6ADDR' in configuration!\n");
+ exit (1);
+ }
+
+ if (GNUNET_SYSERR ==
+ GNUNET_CONFIGURATION_get_value_string (cfg, "vpn", "IPV6PREFIX",
+ &ipv6prefix))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "No entry 'IPV6PREFIX' in configuration!\n");
+ exit (1);
+ }
+
+ if (GNUNET_SYSERR ==
+ GNUNET_CONFIGURATION_get_value_string (cfg, "vpn", "IPV4ADDR", &ipv4addr))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "No entry 'IPV4ADDR' in configuration!\n");
+ exit (1);
+ }
+
+ if (GNUNET_SYSERR ==
+ GNUNET_CONFIGURATION_get_value_string (cfg, "vpn", "IPV4MASK", &ipv4mask))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "No entry 'IPV4MASK' in configuration!\n");
+ exit (1);
+ }
+
+ vpn_argv[0] = GNUNET_strdup ("vpn-gnunet");
+ vpn_argv[1] = ifname;
+ vpn_argv[2] = ipv6addr;
+ vpn_argv[3] = ipv6prefix;
+ vpn_argv[4] = ipv4addr;
+ vpn_argv[5] = ipv4mask;
+ vpn_argv[6] = NULL;
+
+ helper_handle = GNUNET_HELPER_start ("gnunet-helper-vpn", vpn_argv,
+ &message_token, NULL);
+ GNUNET_DNS_restart_hijack (dns_handle);
GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &cleanup, cls);
}