summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPhilipp Tölke <toelke@in.tum.de>2011-05-07 12:50:52 +0000
committerPhilipp Tölke <toelke@in.tum.de>2011-05-07 12:50:52 +0000
commitf9d3867c01ad8769c3c8a3c8b317cc0b5b47ffbd (patch)
treee502021e190df1ec2e98604693d20b4def62c634 /src
parent8b16edf8dd01fc6833ec70be4f3aad9e18a6aafd (diff)
send packets to remote hosts
Diffstat (limited to 'src')
-rw-r--r--src/include/gnunet_protocols.h20
-rw-r--r--src/vpn/gnunet-daemon-vpn-helper.c137
2 files changed, 112 insertions, 45 deletions
diff --git a/src/include/gnunet_protocols.h b/src/include/gnunet_protocols.h
index 38d9713a5..e6099dfd8 100644
--- a/src/include/gnunet_protocols.h
+++ b/src/include/gnunet_protocols.h
@@ -699,6 +699,26 @@ extern "C"
*/
#define GNUNET_MESSAGE_TYPE_SERVICE_TCP_BACK 189
+/**
+ * Type of messages containing an UDP packet for a remote host
+ */
+#define GNUNET_MESSAGE_TYPE_REMOTE_UDP 190
+
+/**
+ * Type of messages containing an UDP packet from a remote host
+ */
+#define GNUNET_MESSAGE_TYPE_REMOTE_UDP_BACK 191
+
+/**
+ * Type of messages containing an TCP packet for a remote host
+ */
+#define GNUNET_MESSAGE_TYPE_REMOTE_TCP 192
+
+/**
+ * Type of messages containing an TCP packet from a remote host
+ */
+#define GNUNET_MESSAGE_TYPE_REMOTE_TCP_BACK 193
+
/**
* Type of messages between the gnunet-wlan-helper and the daemon
diff --git a/src/vpn/gnunet-daemon-vpn-helper.c b/src/vpn/gnunet-daemon-vpn-helper.c
index fdb5dddaa..3ac11a2b2 100644
--- a/src/vpn/gnunet-daemon-vpn-helper.c
+++ b/src/vpn/gnunet-daemon-vpn-helper.c
@@ -33,6 +33,7 @@
#include <gnunet_container_lib.h>
#include <block_dns.h>
#include <gnunet_configuration_lib.h>
+#include <gnunet_applications.h>
#include "gnunet-daemon-vpn-dns.h"
#include "gnunet-daemon-vpn.h"
@@ -44,6 +45,13 @@
struct GNUNET_VPN_HELPER_Handle *helper_handle;
+struct remote_addr
+{
+ char addrlen;
+ unsigned char addr[16];
+ char proto;
+};
+
/**
* Start the helper-process
*
@@ -250,63 +258,102 @@ message_token (void *cls,
sizeof (GNUNET_HashCode) +
ntohs (pkt6->ip6_hdr.paylgth));
- memcpy (hc, &me->desc.service_descriptor,
- sizeof (GNUNET_HashCode));
-
- if (0x11 == 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))))
+ GNUNET_MESH_ApplicationType app_type;
+ if (me->addrlen == 0)
{
- hdr->type = ntohs (GNUNET_MESSAGE_TYPE_SERVICE_UDP);
-
- memcpy (hc + 1, &pkt6_udp->udp_hdr,
- ntohs (pkt6_udp->udp_hdr.len));
-
- }
- else if (0x06 == 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 = ntohs (GNUNET_MESSAGE_TYPE_SERVICE_TCP);
-
- memcpy (hc + 1, &pkt6_tcp->tcp_hdr,
- ntohs (pkt6->ip6_hdr.paylgth));
-
+ /* This is a mapping to a gnunet-service */
+ memcpy (hc, &me->desc.service_descriptor,
+ sizeof (GNUNET_HashCode));
+
+ if (0x11 == 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 = ntohs (GNUNET_MESSAGE_TYPE_SERVICE_UDP);
+
+ memcpy (hc + 1, &pkt6_udp->udp_hdr,
+ ntohs (pkt6_udp->udp_hdr.len));
+
+ }
+ else if (0x06 == 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 = ntohs (GNUNET_MESSAGE_TYPE_SERVICE_TCP);
+
+ memcpy (hc + 1, &pkt6_tcp->tcp_hdr,
+ ntohs (pkt6->ip6_hdr.paylgth));
+
+ }
+ if (me->tunnel == NULL && NULL != cls)
+ {
+ *cls =
+ GNUNET_MESH_peer_request_connect_all (mesh_handle,
+ GNUNET_TIME_UNIT_FOREVER_REL,
+ 1,
+ (struct
+ GNUNET_PeerIdentity
+ *) &me->desc.peer,
+ send_pkt_to_peer,
+ NULL, cls);
+ 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 to peer %x, type %d\n",
+ *((unsigned int *) &me->desc.peer), ntohs(hdr->type));
+ }
}
else
{
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Dropping packet. nxthdr=%d, type=%d, dpt=%x, flg=%d, ports=%x\n",
- pkt6->ip6_hdr.nxthdr, ntohl(me->desc.service_type),
- ntohs(pkt6_tcp->tcp_hdr.dpt), pkt6_tcp->tcp_hdr.flg, me->desc.ports);
- GNUNET_free (cls);
- cls = NULL;
+ /* 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 == 0x11)
+ {
+ hdr->type = GNUNET_MESSAGE_TYPE_REMOTE_UDP;
+ memcpy (hc + 1, &pkt6_udp->udp_hdr,
+ ntohs (pkt6_udp->udp_hdr.len));
+ app_type = GNUNET_APPLICATION_TYPE_INTERNET_UDP_GATEWAY;
+ }
+ else if (s->proto == 0x06)
+ {
+ hdr->type = GNUNET_MESSAGE_TYPE_REMOTE_TCP;
+ memcpy (hc + 1, &pkt6_tcp->tcp_hdr,
+ ntohs (pkt6->ip6_hdr.paylgth));
+ if (ntohs(pkt6_tcp->tcp_hdr.dpt) == 443)
+ app_type = GNUNET_APPLICATION_TYPE_INTERNET_HTTPS_GATEWAY;
+ else if (ntohs(pkt6_tcp->tcp_hdr.dpt) == 80)
+ app_type = GNUNET_APPLICATION_TYPE_INTERNET_HTTP_GATEWAY;
+ else
+ app_type = GNUNET_APPLICATION_TYPE_INTERNET_TCP_GATEWAY;
+ }
}
if (me->tunnel == NULL && NULL != cls)
{
- *cls =
- GNUNET_MESH_peer_request_connect_all (mesh_handle,
- GNUNET_TIME_UNIT_FOREVER_REL,
- 1,
- (struct
- GNUNET_PeerIdentity
- *) &me->desc.peer,
- send_pkt_to_peer,
- NULL, cls);
+ *cls = GNUNET_MESH_peer_request_connect_by_type(mesh_handle,
+ GNUNET_TIME_UNIT_FOREVER_REL,
+ app_type,
+ send_pkt_to_peer,
+ NULL,
+ cls);
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 to peer %x, type %d\n",
- *((unsigned int *) &me->desc.peer), ntohs(hdr->type));
+ send_pkt_to_peer(cls, (struct GNUNET_PeerIdentity*) 1, NULL);
}
}
break;