aboutsummaryrefslogtreecommitdiff
path: root/src/vpn
diff options
context:
space:
mode:
authorPhilipp Tölke <toelke@in.tum.de>2011-07-27 07:28:23 +0000
committerPhilipp Tölke <toelke@in.tum.de>2011-07-27 07:28:23 +0000
commit3b2f2088bdf9b864faebb484bddd4fd7ca0a8455 (patch)
tree755aca87f66d4ad5463f3967333851076223b594 /src/vpn
parentca51d9b99345521ca990e092234e140316ff95bd (diff)
downloadgnunet-3b2f2088bdf9b864faebb484bddd4fd7ca0a8455.tar.gz
gnunet-3b2f2088bdf9b864faebb484bddd4fd7ca0a8455.zip
send ipv4 through gnunet
Diffstat (limited to 'src/vpn')
-rw-r--r--src/vpn/gnunet-daemon-exit.c3
-rw-r--r--src/vpn/gnunet-daemon-vpn-helper.c114
2 files changed, 116 insertions, 1 deletions
diff --git a/src/vpn/gnunet-daemon-exit.c b/src/vpn/gnunet-daemon-exit.c
index 631873ced..c061780a1 100644
--- a/src/vpn/gnunet-daemon-exit.c
+++ b/src/vpn/gnunet-daemon-exit.c
@@ -237,7 +237,6 @@ send_udp_to_peer_notify_callback (void *cls, size_t size, void *buf)
237 GNUNET_assert (size >= ntohs (hdr->size)); 237 GNUNET_assert (size >= ntohs (hdr->size));
238 memcpy (buf, hdr, ntohs (hdr->size)); 238 memcpy (buf, hdr, ntohs (hdr->size));
239 size = ntohs(hdr->size); 239 size = ntohs(hdr->size);
240 GNUNET_free (cls);
241 240
242 if (NULL != GNUNET_MESH_tunnel_get_head(*tunnel)) 241 if (NULL != GNUNET_MESH_tunnel_get_head(*tunnel))
243 { 242 {
@@ -262,6 +261,8 @@ send_udp_to_peer_notify_callback (void *cls, size_t size, void *buf)
262 GNUNET_MESH_tunnel_set_data(*tunnel, th); 261 GNUNET_MESH_tunnel_set_data(*tunnel, th);
263 } 262 }
264 263
264 GNUNET_free (cls);
265
265 return size; 266 return size;
266} 267}
267 268
diff --git a/src/vpn/gnunet-daemon-vpn-helper.c b/src/vpn/gnunet-daemon-vpn-helper.c
index 76d169143..f99e38ce0 100644
--- a/src/vpn/gnunet-daemon-vpn-helper.c
+++ b/src/vpn/gnunet-daemon-vpn-helper.c
@@ -455,6 +455,120 @@ message_token (void *cls __attribute__((unused)),
455 455
456 if ((key = address4_mapping_exists (dadr)) != NULL) 456 if ((key = address4_mapping_exists (dadr)) != NULL)
457 { 457 {
458 struct map_entry *me =
459 GNUNET_CONTAINER_multihashmap_get (hashmap, key);
460 GNUNET_assert (me != NULL);
461 GNUNET_free (key);
462
463 size_t size =
464 sizeof (struct GNUNET_MESH_Tunnel *) +
465 sizeof (struct GNUNET_MessageHeader) +
466 sizeof (GNUNET_HashCode) + ntohs (pkt->ip_hdr.tot_lngth) - 4*pkt->ip_hdr.hdr_lngth;
467
468 struct GNUNET_MESH_Tunnel **cls = GNUNET_malloc (size);
469 struct GNUNET_MessageHeader *hdr =
470 (struct GNUNET_MessageHeader *) (cls + 1);
471 GNUNET_HashCode *hc = (GNUNET_HashCode *) (hdr + 1);
472
473 hdr->size = htons (sizeof (struct GNUNET_MessageHeader) + sizeof (GNUNET_HashCode) + ntohs (pkt->ip_hdr.tot_lngth) - 4*pkt->ip_hdr.hdr_lngth);
474
475 GNUNET_MESH_ApplicationType app_type;
476 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "me->addrlen is %d\n", me->addrlen);
477 if (me->addrlen == 0)
478 {
479 /* This is a mapping to a gnunet-service */
480 memcpy (hc, &me->desc.service_descriptor,
481 sizeof (GNUNET_HashCode));
482
483 if (0x11 == pkt->ip_hdr.proto
484 && (me->desc.
485 service_type & htonl (GNUNET_DNS_SERVICE_TYPE_UDP))
486 && (port_in_ports (me->desc.ports, pkt_udp->udp_hdr.dpt)
487 || testBit (me->additional_ports,
488 ntohs (pkt_udp->udp_hdr.dpt))))
489 {
490 hdr->type = ntohs (GNUNET_MESSAGE_TYPE_SERVICE_UDP);
491
492 memcpy (hc + 1, &pkt_udp->udp_hdr,
493 ntohs (pkt_udp->udp_hdr.len));
494
495 }
496 else if (0x06 == pkt->ip_hdr.proto
497 && (me->desc.
498 service_type & htonl (GNUNET_DNS_SERVICE_TYPE_TCP))
499 &&
500 (port_in_ports (me->desc.ports, pkt_tcp->tcp_hdr.dpt)))
501 {
502 hdr->type = ntohs (GNUNET_MESSAGE_TYPE_SERVICE_TCP);
503
504 memcpy (hc + 1, &pkt_tcp->tcp_hdr,
505 ntohs (pkt->ip_hdr.tot_lngth) - 4*pkt->ip_hdr.hdr_lngth);
506
507 }
508 if (me->tunnel == NULL && NULL != cls)
509 {
510 *cls =
511 GNUNET_MESH_peer_request_connect_all (mesh_handle,
512 GNUNET_TIME_UNIT_FOREVER_REL,
513 1,
514 (struct
515 GNUNET_PeerIdentity
516 *) &me->desc.peer,
517 send_pkt_to_peer,
518 NULL, cls);
519 me->tunnel = *cls;
520 }
521 else if (NULL != cls)
522 {
523 *cls = me->tunnel;
524 send_pkt_to_peer (cls, (struct GNUNET_PeerIdentity *) 1,
525 NULL);
526 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
527 "Queued to send to peer %x, type %d\n",
528 *((unsigned int *) &me->desc.peer), ntohs(hdr->type));
529 }
530 }
531 else
532 {
533 /* This is a mapping to a "real" address */
534 struct remote_addr *s = (struct remote_addr*) hc;
535 s->addrlen = me->addrlen;
536 memcpy(s->addr, me->addr, me->addrlen);
537 s->proto= pkt->ip_hdr.proto;
538 if (s->proto == 0x11)
539 {
540 hdr->type = htons(GNUNET_MESSAGE_TYPE_REMOTE_UDP);
541 memcpy (hc + 1, &pkt_udp->udp_hdr,
542 ntohs (pkt_udp->udp_hdr.len));
543 app_type = GNUNET_APPLICATION_TYPE_INTERNET_UDP_GATEWAY;
544 }
545 else if (s->proto == 0x06)
546 {
547 hdr->type = htons(GNUNET_MESSAGE_TYPE_REMOTE_TCP);
548 memcpy (hc + 1, &pkt_tcp->tcp_hdr,
549 ntohs (pkt->ip_hdr.tot_lngth) - 4*pkt->ip_hdr.hdr_lngth);
550 app_type = GNUNET_APPLICATION_TYPE_INTERNET_TCP_GATEWAY;
551 }
552 if (me->tunnel == NULL && NULL != cls)
553 {
554 *cls = GNUNET_MESH_peer_request_connect_by_type(mesh_handle,
555 GNUNET_TIME_UNIT_FOREVER_REL,
556 app_type,
557 send_pkt_to_peer,
558 NULL,
559 cls);
560 me->tunnel = *cls;
561 }
562 else if (NULL != cls)
563 {
564 *cls = me->tunnel;
565 send_pkt_to_peer(cls, (struct GNUNET_PeerIdentity*) 1, NULL);
566 }
567 }
568 }
569 else
570 {
571 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Packet to %x which has no mapping\n", dadr);
458 } 572 }
459 break; 573 break;
460 case 0x01: 574 case 0x01: