aboutsummaryrefslogtreecommitdiff
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)
downloadgnunet-f9d3867c01ad8769c3c8a3c8b317cc0b5b47ffbd.tar.gz
gnunet-f9d3867c01ad8769c3c8a3c8b317cc0b5b47ffbd.zip
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"
699 */ 699 */
700#define GNUNET_MESSAGE_TYPE_SERVICE_TCP_BACK 189 700#define GNUNET_MESSAGE_TYPE_SERVICE_TCP_BACK 189
701 701
702/**
703 * Type of messages containing an UDP packet for a remote host
704 */
705#define GNUNET_MESSAGE_TYPE_REMOTE_UDP 190
706
707/**
708 * Type of messages containing an UDP packet from a remote host
709 */
710#define GNUNET_MESSAGE_TYPE_REMOTE_UDP_BACK 191
711
712/**
713 * Type of messages containing an TCP packet for a remote host
714 */
715#define GNUNET_MESSAGE_TYPE_REMOTE_TCP 192
716
717/**
718 * Type of messages containing an TCP packet from a remote host
719 */
720#define GNUNET_MESSAGE_TYPE_REMOTE_TCP_BACK 193
721
702 722
703/** 723/**
704 * Type of messages between the gnunet-wlan-helper and the daemon 724 * 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 @@
33#include <gnunet_container_lib.h> 33#include <gnunet_container_lib.h>
34#include <block_dns.h> 34#include <block_dns.h>
35#include <gnunet_configuration_lib.h> 35#include <gnunet_configuration_lib.h>
36#include <gnunet_applications.h>
36 37
37#include "gnunet-daemon-vpn-dns.h" 38#include "gnunet-daemon-vpn-dns.h"
38#include "gnunet-daemon-vpn.h" 39#include "gnunet-daemon-vpn.h"
@@ -44,6 +45,13 @@
44 45
45struct GNUNET_VPN_HELPER_Handle *helper_handle; 46struct GNUNET_VPN_HELPER_Handle *helper_handle;
46 47
48struct remote_addr
49{
50 char addrlen;
51 unsigned char addr[16];
52 char proto;
53};
54
47/** 55/**
48 * Start the helper-process 56 * Start the helper-process
49 * 57 *
@@ -250,63 +258,102 @@ message_token (void *cls,
250 sizeof (GNUNET_HashCode) + 258 sizeof (GNUNET_HashCode) +
251 ntohs (pkt6->ip6_hdr.paylgth)); 259 ntohs (pkt6->ip6_hdr.paylgth));
252 260
253 memcpy (hc, &me->desc.service_descriptor, 261 GNUNET_MESH_ApplicationType app_type;
254 sizeof (GNUNET_HashCode)); 262 if (me->addrlen == 0)
255
256 if (0x11 == pkt6->ip6_hdr.nxthdr
257 && (me->desc.
258 service_type & htonl (GNUNET_DNS_SERVICE_TYPE_UDP))
259 && (port_in_ports (me->desc.ports, pkt6_udp->udp_hdr.dpt)
260 || testBit (me->additional_ports,
261 ntohs (pkt6_udp->udp_hdr.dpt))))
262 { 263 {
263 hdr->type = ntohs (GNUNET_MESSAGE_TYPE_SERVICE_UDP); 264 /* This is a mapping to a gnunet-service */
264 265 memcpy (hc, &me->desc.service_descriptor,
265 memcpy (hc + 1, &pkt6_udp->udp_hdr, 266 sizeof (GNUNET_HashCode));
266 ntohs (pkt6_udp->udp_hdr.len)); 267
267 268 if (0x11 == pkt6->ip6_hdr.nxthdr
268 } 269 && (me->desc.
269 else if (0x06 == pkt6->ip6_hdr.nxthdr 270 service_type & htonl (GNUNET_DNS_SERVICE_TYPE_UDP))
270 && (me->desc. 271 && (port_in_ports (me->desc.ports, pkt6_udp->udp_hdr.dpt)
271 service_type & htonl (GNUNET_DNS_SERVICE_TYPE_TCP)) 272 || testBit (me->additional_ports,
272 && 273 ntohs (pkt6_udp->udp_hdr.dpt))))
273 (port_in_ports (me->desc.ports, pkt6_tcp->tcp_hdr.dpt))) 274 {
274 { 275 hdr->type = ntohs (GNUNET_MESSAGE_TYPE_SERVICE_UDP);
275 hdr->type = ntohs (GNUNET_MESSAGE_TYPE_SERVICE_TCP); 276
276 277 memcpy (hc + 1, &pkt6_udp->udp_hdr,
277 memcpy (hc + 1, &pkt6_tcp->tcp_hdr, 278 ntohs (pkt6_udp->udp_hdr.len));
278 ntohs (pkt6->ip6_hdr.paylgth)); 279
279 280 }
281 else if (0x06 == pkt6->ip6_hdr.nxthdr
282 && (me->desc.
283 service_type & htonl (GNUNET_DNS_SERVICE_TYPE_TCP))
284 &&
285 (port_in_ports (me->desc.ports, pkt6_tcp->tcp_hdr.dpt)))
286 {
287 hdr->type = ntohs (GNUNET_MESSAGE_TYPE_SERVICE_TCP);
288
289 memcpy (hc + 1, &pkt6_tcp->tcp_hdr,
290 ntohs (pkt6->ip6_hdr.paylgth));
291
292 }
293 if (me->tunnel == NULL && NULL != cls)
294 {
295 *cls =
296 GNUNET_MESH_peer_request_connect_all (mesh_handle,
297 GNUNET_TIME_UNIT_FOREVER_REL,
298 1,
299 (struct
300 GNUNET_PeerIdentity
301 *) &me->desc.peer,
302 send_pkt_to_peer,
303 NULL, cls);
304 me->tunnel = *cls;
305 }
306 else if (NULL != cls)
307 {
308 *cls = me->tunnel;
309 send_pkt_to_peer (cls, (struct GNUNET_PeerIdentity *) 1,
310 NULL);
311 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
312 "Queued to send to peer %x, type %d\n",
313 *((unsigned int *) &me->desc.peer), ntohs(hdr->type));
314 }
280 } 315 }
281 else 316 else
282 { 317 {
283 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Dropping packet. nxthdr=%d, type=%d, dpt=%x, flg=%d, ports=%x\n", 318 /* This is a mapping to a "real" address */
284 pkt6->ip6_hdr.nxthdr, ntohl(me->desc.service_type), 319 struct remote_addr *s = (struct remote_addr*) hc;
285 ntohs(pkt6_tcp->tcp_hdr.dpt), pkt6_tcp->tcp_hdr.flg, me->desc.ports); 320 s->addrlen = me->addrlen;
286 GNUNET_free (cls); 321 memcpy(s->addr, me->addr, me->addrlen);
287 cls = NULL; 322 s->proto= pkt6->ip6_hdr.nxthdr;
323 if (s->proto == 0x11)
324 {
325 hdr->type = GNUNET_MESSAGE_TYPE_REMOTE_UDP;
326 memcpy (hc + 1, &pkt6_udp->udp_hdr,
327 ntohs (pkt6_udp->udp_hdr.len));
328 app_type = GNUNET_APPLICATION_TYPE_INTERNET_UDP_GATEWAY;
329 }
330 else if (s->proto == 0x06)
331 {
332 hdr->type = GNUNET_MESSAGE_TYPE_REMOTE_TCP;
333 memcpy (hc + 1, &pkt6_tcp->tcp_hdr,
334 ntohs (pkt6->ip6_hdr.paylgth));
335 if (ntohs(pkt6_tcp->tcp_hdr.dpt) == 443)
336 app_type = GNUNET_APPLICATION_TYPE_INTERNET_HTTPS_GATEWAY;
337 else if (ntohs(pkt6_tcp->tcp_hdr.dpt) == 80)
338 app_type = GNUNET_APPLICATION_TYPE_INTERNET_HTTP_GATEWAY;
339 else
340 app_type = GNUNET_APPLICATION_TYPE_INTERNET_TCP_GATEWAY;
341 }
288 } 342 }
289 if (me->tunnel == NULL && NULL != cls) 343 if (me->tunnel == NULL && NULL != cls)
290 { 344 {
291 *cls = 345 *cls = GNUNET_MESH_peer_request_connect_by_type(mesh_handle,
292 GNUNET_MESH_peer_request_connect_all (mesh_handle, 346 GNUNET_TIME_UNIT_FOREVER_REL,
293 GNUNET_TIME_UNIT_FOREVER_REL, 347 app_type,
294 1, 348 send_pkt_to_peer,
295 (struct 349 NULL,
296 GNUNET_PeerIdentity 350 cls);
297 *) &me->desc.peer,
298 send_pkt_to_peer,
299 NULL, cls);
300 me->tunnel = *cls; 351 me->tunnel = *cls;
301 } 352 }
302 else if (NULL != cls) 353 else if (NULL != cls)
303 { 354 {
304 *cls = me->tunnel; 355 *cls = me->tunnel;
305 send_pkt_to_peer (cls, (struct GNUNET_PeerIdentity *) 1, 356 send_pkt_to_peer(cls, (struct GNUNET_PeerIdentity*) 1, NULL);
306 NULL);
307 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
308 "Queued to send to peer %x, type %d\n",
309 *((unsigned int *) &me->desc.peer), ntohs(hdr->type));
310 } 357 }
311 } 358 }
312 break; 359 break;