aboutsummaryrefslogtreecommitdiff
path: root/src/vpn
diff options
context:
space:
mode:
authorPhilipp Tölke <toelke@in.tum.de>2011-03-14 15:16:31 +0000
committerPhilipp Tölke <toelke@in.tum.de>2011-03-14 15:16:31 +0000
commit153197a8d91efea03723827c36c383be39acbff5 (patch)
tree08f366b1b9a96f97cb33e4e7c37980af8c9a67c7 /src/vpn
parent85196cb7eec16cf4888fc26759c80e6f76eebd9f (diff)
downloadgnunet-153197a8d91efea03723827c36c383be39acbff5.tar.gz
gnunet-153197a8d91efea03723827c36c383be39acbff5.zip
tcp from vpn to exit. way back still missing
Diffstat (limited to 'src/vpn')
-rw-r--r--src/vpn/gnunet-daemon-exit.c318
-rw-r--r--src/vpn/gnunet-daemon-vpn-helper.c20
-rw-r--r--src/vpn/gnunet-service-dns.c2
-rw-r--r--src/vpn/gnunet-vpn-packet.h11
4 files changed, 269 insertions, 82 deletions
diff --git a/src/vpn/gnunet-daemon-exit.c b/src/vpn/gnunet-daemon-exit.c
index e76c8c32c..b6b86cfc8 100644
--- a/src/vpn/gnunet-daemon-exit.c
+++ b/src/vpn/gnunet-daemon-exit.c
@@ -65,11 +65,12 @@ static struct GNUNET_MESH_Handle *mesh_handle;
65 * source-port and destination-port to a socket 65 * source-port and destination-port to a socket
66 */ 66 */
67static struct GNUNET_CONTAINER_MultiHashMap *udp_connections; 67static struct GNUNET_CONTAINER_MultiHashMap *udp_connections;
68static struct GNUNET_CONTAINER_MultiHashMap *tcp_connections;
68 69
69/** 70/**
70 * This struct is saved into the services-hashmap 71 * This struct is saved into the services-hashmap
71 */ 72 */
72struct udp_service 73struct redirect_service
73{ 74{
74 /** 75 /**
75 * One of 4 or 6 76 * One of 4 or 6
@@ -91,7 +92,7 @@ struct udp_service
91 }; 92 };
92}; 93};
93 94
94struct udp_info 95struct redirect_info
95{ 96{
96 /** 97 /**
97 * The source-address of this connection. When a packet to this address is 98 * The source-address of this connection. When a packet to this address is
@@ -105,24 +106,25 @@ struct udp_info
105}; 106};
106 107
107/** 108/**
108 * This struct is saved into udp_connections; 109 * This struct is saved into {tcp,udp}_connections;
109 */ 110 */
110struct udp_state 111struct redirect_state
111{ 112{
112 struct GNUNET_MESH_Tunnel *tunnel; 113 struct GNUNET_MESH_Tunnel *tunnel;
113 GNUNET_HashCode desc; 114 GNUNET_HashCode desc;
114 struct udp_service *serv; 115 struct redirect_service *serv;
115 116
116 /** 117 /**
117 * The source-address and -port of this connection 118 * The source-address and -port of this connection
118 */ 119 */
119 struct udp_info udp_info; 120 struct redirect_info redirect_info;
120}; 121};
121 122
122/** 123/**
123 * This hashmap saves interesting things about the configured services 124 * This hashmaps saves interesting things about the configured services
124 */ 125 */
125static struct GNUNET_CONTAINER_MultiHashMap *udp_services; 126static struct GNUNET_CONTAINER_MultiHashMap *udp_services;
127static struct GNUNET_CONTAINER_MultiHashMap *tcp_services;
126 128
127/** 129/**
128 * Function that frees everything from a hashmap 130 * Function that frees everything from a hashmap
@@ -145,6 +147,10 @@ cleanup(void* cls, const struct GNUNET_SCHEDULER_TaskContext* tskctx) {
145 free_iterate, 147 free_iterate,
146 NULL); 148 NULL);
147 149
150 GNUNET_CONTAINER_multihashmap_iterate(tcp_connections,
151 free_iterate,
152 NULL);
153
148 if (mesh_handle != NULL) 154 if (mesh_handle != NULL)
149 { 155 {
150 GNUNET_MESH_disconnect(mesh_handle); 156 GNUNET_MESH_disconnect(mesh_handle);
@@ -183,8 +189,8 @@ message_token (void *cls,
183 uint32_t len; 189 uint32_t len;
184 190
185 struct udp_pkt *udp; 191 struct udp_pkt *udp;
186 struct udp_info u_i; 192 struct redirect_info u_i;
187 memset(&u_i, 0, sizeof(struct udp_info)); 193 memset(&u_i, 0, sizeof(struct redirect_info));
188 194
189 unsigned int version; 195 unsigned int version;
190 196
@@ -216,8 +222,8 @@ message_token (void *cls,
216 222
217 /* get tunnel and service-descriptor from this*/ 223 /* get tunnel and service-descriptor from this*/
218 GNUNET_HashCode hash; 224 GNUNET_HashCode hash;
219 GNUNET_CRYPTO_hash(&u_i, sizeof(struct udp_info), &hash); 225 GNUNET_CRYPTO_hash(&u_i, sizeof(struct redirect_info), &hash);
220 struct udp_state *state = GNUNET_CONTAINER_multihashmap_get(udp_connections, &hash); 226 struct redirect_state *state = GNUNET_CONTAINER_multihashmap_get(udp_connections, &hash);
221 227
222 tunnel = state->tunnel; 228 tunnel = state->tunnel;
223 229
@@ -228,8 +234,8 @@ message_token (void *cls,
228 } 234 }
229 else 235 else
230 { 236 {
231 struct udp_service *serv = GNUNET_malloc(sizeof(struct udp_service)); 237 struct redirect_service *serv = GNUNET_malloc(sizeof(struct redirect_service));
232 memcpy(serv, state->serv, sizeof(struct udp_service)); 238 memcpy(serv, state->serv, sizeof(struct redirect_service));
233 serv->my_port = ntohs(udp->spt); 239 serv->my_port = ntohs(udp->spt);
234 serv->remote_port = ntohs(udp->spt); 240 serv->remote_port = ntohs(udp->spt);
235 uint16_t *desc = alloca (sizeof (GNUNET_HashCode) + 2); 241 uint16_t *desc = alloca (sizeof (GNUNET_HashCode) + 2);
@@ -285,37 +291,52 @@ read_service_conf (void *cls, const char *section, const char *option,
285 GNUNET_CRYPTO_hash (section, strlen (section) + 1, 291 GNUNET_CRYPTO_hash (section, strlen (section) + 1,
286 (GNUNET_HashCode *) (desc + 1)); 292 (GNUNET_HashCode *) (desc + 1));
287 293
294#define TCP 2
295#define UDP 1
296
297 unsigned int proto;
288 if (0 == strcmp ("UDP_REDIRECTS", option)) 298 if (0 == strcmp ("UDP_REDIRECTS", option))
299 proto = UDP;
300 else if (0 == strcmp ("TCP_REDIRECTS", option))
301 proto = TCP;
302 else
303 proto = 0;
304
305 if (0 != proto)
289 { 306 {
290 cpy = GNUNET_strdup (value); 307 cpy = GNUNET_strdup (value);
291 for (redirect = strtok (cpy, " "); redirect != NULL; redirect = strtok (NULL, " ")) 308 for (redirect = strtok (cpy, " "); redirect != NULL; redirect = strtok
292 { 309 (NULL, " "))
293 if (NULL == (hostname = strstr (redirect, ":"))) 310 {
294 { 311 if (NULL == (hostname = strstr (redirect, ":")))
295 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Warning: option %s is not formatted correctly!\n", redirect); 312 {
296 continue; 313 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Warning: option %s is not formatted correctly!\n",
297 } 314 redirect);
298 hostname[0] = '\0'; 315 continue;
299 hostname++; 316 }
300 if (NULL == (hostport = strstr (hostname, ":"))) 317 hostname[0] = '\0';
301 { 318 hostname++;
302 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Warning: option %s is not formatted correctly!\n", redirect); 319 if (NULL == (hostport = strstr (hostname, ":")))
303 continue; 320 {
304 } 321 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Warning: option %s is not formatted correctly!\n",
305 hostport[0] = '\0'; 322 redirect);
306 hostport++; 323 continue;
307 324 }
325 hostport[0] = '\0';
326 hostport++;
327
308 int local_port = atoi (redirect); 328 int local_port = atoi (redirect);
309 if (!((local_port > 0) && (local_port < 65536))) 329 if (!((local_port > 0) && (local_port < 65536)))
310 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Warning: %s is not a correct port.", redirect); 330 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Warning: %s is not a correct port.",
331 redirect);
311 332
312 *desc = local_port; 333 *desc = local_port;
313 334
314 GNUNET_CRYPTO_hash (desc, sizeof (GNUNET_HashCode) + 2, &hash); 335 GNUNET_CRYPTO_hash (desc, sizeof (GNUNET_HashCode) + 2, &hash);
315 336
316 struct udp_service *serv = 337 struct redirect_service *serv =
317 GNUNET_malloc (sizeof (struct udp_service)); 338 GNUNET_malloc (sizeof (struct redirect_service));
318 memset (serv, 0, sizeof (struct udp_service)); 339 memset (serv, 0, sizeof (struct redirect_service));
319 serv->my_port = local_port; 340 serv->my_port = local_port;
320 341
321 if (0 == strcmp ("localhost4", hostname)) 342 if (0 == strcmp ("localhost4", hostname))
@@ -358,10 +379,17 @@ read_service_conf (void *cls, const char *section, const char *option,
358 *((unsigned long long *) (desc + 1))); 379 *((unsigned long long *) (desc + 1)));
359 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Store with key2 %x\n", 380 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Store with key2 %x\n",
360 *((unsigned long long *) &hash)); 381 *((unsigned long long *) &hash));
361 GNUNET_assert (GNUNET_OK == 382 if (UDP == proto)
362 GNUNET_CONTAINER_multihashmap_put (udp_services, 383 GNUNET_assert (GNUNET_OK ==
363 &hash, serv, 384 GNUNET_CONTAINER_multihashmap_put (udp_services,
364 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 385 &hash, serv,
386 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
387 else
388 GNUNET_assert (GNUNET_OK ==
389 GNUNET_CONTAINER_multihashmap_put (tcp_services,
390 &hash, serv,
391 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
392
365 } 393 }
366 GNUNET_free (cpy); 394 GNUNET_free (cpy);
367 } 395 }
@@ -445,7 +473,7 @@ start_helper_and_schedule(void *cls,
445static void 473static void
446prepare_ipv4_packet (ssize_t len, ssize_t pktlen, void *payload, 474prepare_ipv4_packet (ssize_t len, ssize_t pktlen, void *payload,
447 uint16_t protocol, void *ipaddress, void *tunnel, 475 uint16_t protocol, void *ipaddress, void *tunnel,
448 struct udp_state *state, struct ip_udp *pkt4) 476 struct redirect_state *state, struct ip_pkt *pkt4)
449{ 477{
450 uint32_t tmp, tmp2; 478 uint32_t tmp, tmp2;
451 479
@@ -454,7 +482,7 @@ prepare_ipv4_packet (ssize_t len, ssize_t pktlen, void *payload,
454 pkt4->tun.flags = 0; 482 pkt4->tun.flags = 0;
455 pkt4->tun.type = htons (0x0800); 483 pkt4->tun.type = htons (0x0800);
456 484
457 memcpy (&pkt4->udp_hdr, payload, pktlen); 485 memcpy (&pkt4->data, payload, pktlen);
458 486
459 pkt4->ip_hdr.version = 4; 487 pkt4->ip_hdr.version = 4;
460 pkt4->ip_hdr.hdr_lngth = 5; 488 pkt4->ip_hdr.hdr_lngth = 5;
@@ -493,10 +521,40 @@ prepare_ipv4_packet (ssize_t len, ssize_t pktlen, void *payload,
493 521
494 pkt4->ip_hdr.sadr = tmp; 522 pkt4->ip_hdr.sadr = tmp;
495 523
496 memcpy (&state->udp_info.addr, &tmp, 4); 524 memcpy (&state->redirect_info.addr, &tmp, 4);
497 state->udp_info.pt = pkt4->udp_hdr.spt; 525 if (0x11 == protocol)
526 {
527 struct ip_udp* pkt4_udp = (struct ip_udp*)pkt4;
528 state->redirect_info.pt = pkt4_udp->udp_hdr.spt;
529
530 pkt4_udp->udp_hdr.crc = 0; /* Optional for IPv4 */
531 }
532 else if (0x06 == protocol)
533 {
534 struct ip_tcp* pkt4_tcp = (struct ip_tcp*)pkt4;
535 state->redirect_info.pt = pkt4_tcp->tcp_hdr.spt;
536
537 pkt4_tcp->tcp_hdr.crc = 0;
538 uint32_t sum = 0;
539 tmp = pkt4->ip_hdr.sadr;
540 sum =
541 calculate_checksum_update (sum, (uint16_t *) & tmp, 4);
542 tmp = pkt4->ip_hdr.dadr;
543 sum =
544 calculate_checksum_update (sum, (uint16_t *) & tmp, 4);
498 545
499 pkt4->udp_hdr.crc = 0; /* Optional for IPv4 */ 546 tmp = (protocol << 16) | (0xffff & pktlen);
547
548 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "line: %08x, %x \n", tmp, (0xffff & pktlen));
549
550 tmp = htonl(tmp);
551
552 sum = calculate_checksum_update (sum, (uint16_t *) & tmp, 4);
553
554 sum =
555 calculate_checksum_update (sum, (uint16_t *) & pkt4_tcp->tcp_hdr, pktlen);
556 pkt4_tcp->tcp_hdr.crc = calculate_checksum_end (sum);
557 }
500 558
501 pkt4->ip_hdr.chks = 559 pkt4->ip_hdr.chks =
502 calculate_ip_checksum ((uint16_t *) & pkt4->ip_hdr, 5 * 4); 560 calculate_ip_checksum ((uint16_t *) & pkt4->ip_hdr, 5 * 4);
@@ -505,7 +563,7 @@ prepare_ipv4_packet (ssize_t len, ssize_t pktlen, void *payload,
505static void 563static void
506prepare_ipv6_packet (ssize_t len, ssize_t pktlen, void *payload, 564prepare_ipv6_packet (ssize_t len, ssize_t pktlen, void *payload,
507 uint16_t protocol, void *ipaddress, void *tunnel, 565 uint16_t protocol, void *ipaddress, void *tunnel,
508 struct udp_state *state, struct ip6_udp *pkt6) 566 struct redirect_state *state, struct ip6_pkt *pkt6)
509{ 567{
510 uint32_t tmp; 568 uint32_t tmp;
511 569
@@ -515,7 +573,7 @@ prepare_ipv6_packet (ssize_t len, ssize_t pktlen, void *payload,
515 573
516 pkt6->tun.type = htons (0x86dd); 574 pkt6->tun.type = htons (0x86dd);
517 575
518 memcpy (&pkt6->udp_hdr, payload, pktlen); 576 memcpy (&pkt6->data, payload, pktlen);
519 577
520 pkt6->ip6_hdr.version = 6; 578 pkt6->ip6_hdr.version = 6;
521 pkt6->ip6_hdr.nxthdr = protocol; 579 pkt6->ip6_hdr.nxthdr = protocol;
@@ -551,24 +609,141 @@ prepare_ipv6_packet (ssize_t len, ssize_t pktlen, void *payload,
551 ((char *) &tunnel) + offset, 16 - ipv6prefix); 609 ((char *) &tunnel) + offset, 16 - ipv6prefix);
552 610
553 /* copy the needed information into the state */ 611 /* copy the needed information into the state */
554 memcpy (&state->udp_info.addr, &pkt6->ip6_hdr.sadr, 16); 612 memcpy (&state->redirect_info.addr, &pkt6->ip6_hdr.sadr, 16);
555 state->udp_info.pt = pkt6->udp_hdr.spt; 613
556 614 if (0x11 == protocol)
557 pkt6->udp_hdr.crc = 0; 615 {
558 uint32_t sum = 0; 616 struct ip6_udp* pkt6_udp = (struct ip6_udp*)pkt6;
559 sum = 617 state->redirect_info.pt = pkt6_udp->udp_hdr.spt;
560 calculate_checksum_update (sum, (uint16_t *) & pkt6->ip6_hdr.sadr, 16); 618
561 sum = 619 pkt6_udp->udp_hdr.crc = 0;
562 calculate_checksum_update (sum, (uint16_t *) & pkt6->ip6_hdr.dadr, 16); 620 uint32_t sum = 0;
563 tmp = (htons (pktlen) & 0xffff); 621 sum =
564 sum = calculate_checksum_update (sum, (uint16_t *) & tmp, 4); 622 calculate_checksum_update (sum, (uint16_t *) & pkt6_udp->ip6_hdr.sadr, 16);
565 tmp = htons (((pkt6->ip6_hdr.nxthdr & 0x00ff))); 623 sum =
566 sum = calculate_checksum_update (sum, (uint16_t *) & tmp, 4); 624 calculate_checksum_update (sum, (uint16_t *) & pkt6_udp->ip6_hdr.dadr, 16);
567 625 tmp = (htons (pktlen) & 0xffff);
568 sum = 626 sum = calculate_checksum_update (sum, (uint16_t *) & tmp, 4);
569 calculate_checksum_update (sum, (uint16_t *) & pkt6->udp_hdr, 627 tmp = htons (((pkt6_udp->ip6_hdr.nxthdr & 0x00ff)));
570 ntohs (pkt6->udp_hdr.len)); 628 sum = calculate_checksum_update (sum, (uint16_t *) & tmp, 4);
571 pkt6->udp_hdr.crc = calculate_checksum_end (sum); 629
630 sum =
631 calculate_checksum_update (sum, (uint16_t *) & pkt6_udp->udp_hdr,
632 ntohs (pkt6_udp->udp_hdr.len));
633 pkt6_udp->udp_hdr.crc = calculate_checksum_end (sum);
634 }
635 else if (0x06 == protocol)
636 {
637 struct ip6_tcp* pkt6_tcp = (struct ip6_tcp*)pkt6;
638 state->redirect_info.pt = pkt6_tcp->tcp_hdr.spt;
639
640 pkt6_tcp->tcp_hdr.crc = 0;
641 uint32_t sum = 0;
642 sum =
643 calculate_checksum_update (sum, (uint16_t *) & pkt6->ip6_hdr.sadr, 16);
644 sum =
645 calculate_checksum_update (sum, (uint16_t *) & pkt6->ip6_hdr.dadr, 16);
646 tmp = htonl(pktlen);
647 sum = calculate_checksum_update (sum, (uint16_t *) & tmp, 4);
648 tmp = htonl (((pkt6->ip6_hdr.nxthdr & 0x000000ff)));
649 sum = calculate_checksum_update (sum, (uint16_t *) & tmp, 4);
650
651 sum =
652 calculate_checksum_update (sum, (uint16_t *) & pkt6_tcp->tcp_hdr,
653 ntohs (pkt6->ip6_hdr.paylgth));
654 pkt6_tcp->tcp_hdr.crc = calculate_checksum_end (sum);
655 }
656}
657
658/**
659 * The messages are one GNUNET_HashCode for the service followed by a struct tcp_pkt
660 */
661static int
662receive_tcp_service (void *cls,
663 struct GNUNET_MESH_Tunnel *tunnel,
664 void **tunnel_ctx,
665 const struct GNUNET_PeerIdentity *sender,
666 const struct GNUNET_MessageHeader *message,
667 const struct GNUNET_TRANSPORT_ATS_Information *atsi)
668{
669 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Received TCP-Packet\n");
670 GNUNET_HashCode hash;
671 GNUNET_HashCode *desc = (GNUNET_HashCode *) (message + 1);
672 struct tcp_pkt *pkt = (struct tcp_pkt *) (desc + 1);
673 unsigned int pkt_len = ntohs(message->size) - sizeof (struct
674 GNUNET_MessageHeader) -
675 sizeof(GNUNET_HashCode);
676
677 /** Get the configuration from the services-hashmap.
678 *
679 * Which service is needed only depends on the service-descriptor and the
680 * destination-port
681 */
682 uint16_t *tcp_desc = alloca (sizeof (GNUNET_HashCode) + 2);
683
684 memcpy (tcp_desc + 1, desc, sizeof (GNUNET_HashCode));
685 *tcp_desc = ntohs (pkt->dpt);
686 GNUNET_CRYPTO_hash (tcp_desc, sizeof (GNUNET_HashCode) + 2, &hash);
687 struct redirect_service *serv =
688 GNUNET_CONTAINER_multihashmap_get (tcp_services, &hash);
689 if (NULL == serv)
690 {
691 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "No service found for TCP dpt %d!\n",
692 *tcp_desc);
693 return GNUNET_YES;
694 }
695
696 pkt->dpt = htons (serv->remote_port);
697 /* FIXME -> check acl etc */
698
699 char *buf;
700 size_t len;
701
702 /* Prepare the state.
703 * This will be saved in the hashmap, so that the receiving procedure knows
704 * through which tunnel this connection has to be routed.
705 */
706 struct redirect_state *state = GNUNET_malloc (sizeof (struct redirect_state));
707 memset (state, 0, sizeof (struct redirect_state));
708 state->tunnel = tunnel;
709 state->serv = serv;
710 memcpy (&state->desc, desc, sizeof (GNUNET_HashCode));
711
712 len = sizeof (struct GNUNET_MessageHeader) + sizeof (struct pkt_tun) +
713 sizeof (struct ip6_hdr) + pkt_len;
714 buf = alloca (len);
715
716 memset (buf, 0, len);
717
718 switch (serv->version)
719 {
720 case 4:
721 prepare_ipv4_packet (len, pkt_len, pkt, 0x06, /* TCP */
722 &serv->v4.ip4address,
723 tunnel, state, (struct ip_pkt *) buf);
724 break;
725 case 6:
726 prepare_ipv6_packet (len, pkt_len, pkt, 0x06, /* TCP */
727 &serv->v6.ip6address,
728 tunnel, state, (struct ip6_pkt *) buf);
729
730 break;
731 default:
732 GNUNET_assert (0);
733 break;
734 }
735
736 GNUNET_CRYPTO_hash (&state->redirect_info, sizeof (struct redirect_info), &hash);
737
738 if (GNUNET_NO ==
739 GNUNET_CONTAINER_multihashmap_contains (tcp_connections, &hash))
740 GNUNET_CONTAINER_multihashmap_put (tcp_connections, &hash, state,
741 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
742 else
743 GNUNET_free (state);
744
745 (void) GNUNET_DISK_file_write (helper_handle->fh_to_helper, buf, len);
746 return GNUNET_YES;
572} 747}
573 748
574/** 749/**
@@ -596,11 +771,11 @@ receive_udp_service (void *cls,
596 memcpy (udp_desc + 1, desc, sizeof (GNUNET_HashCode)); 771 memcpy (udp_desc + 1, desc, sizeof (GNUNET_HashCode));
597 *udp_desc = ntohs (pkt->dpt); 772 *udp_desc = ntohs (pkt->dpt);
598 GNUNET_CRYPTO_hash (udp_desc, sizeof (GNUNET_HashCode) + 2, &hash); 773 GNUNET_CRYPTO_hash (udp_desc, sizeof (GNUNET_HashCode) + 2, &hash);
599 struct udp_service *serv = 774 struct redirect_service *serv =
600 GNUNET_CONTAINER_multihashmap_get (udp_services, &hash); 775 GNUNET_CONTAINER_multihashmap_get (udp_services, &hash);
601 if (NULL == serv) 776 if (NULL == serv)
602 { 777 {
603 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "No service found for dpt %d!\n", 778 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "No service found for UDP dpt %d!\n",
604 *udp_desc); 779 *udp_desc);
605 return GNUNET_YES; 780 return GNUNET_YES;
606 } 781 }
@@ -615,8 +790,8 @@ receive_udp_service (void *cls,
615 * This will be saved in the hashmap, so that the receiving procedure knows 790 * This will be saved in the hashmap, so that the receiving procedure knows
616 * through which tunnel this connection has to be routed. 791 * through which tunnel this connection has to be routed.
617 */ 792 */
618 struct udp_state *state = GNUNET_malloc (sizeof (struct udp_state)); 793 struct redirect_state *state = GNUNET_malloc (sizeof (struct redirect_state));
619 memset (state, 0, sizeof (struct udp_state)); 794 memset (state, 0, sizeof (struct redirect_state));
620 state->tunnel = tunnel; 795 state->tunnel = tunnel;
621 state->serv = serv; 796 state->serv = serv;
622 memcpy (&state->desc, desc, sizeof (GNUNET_HashCode)); 797 memcpy (&state->desc, desc, sizeof (GNUNET_HashCode));
@@ -632,12 +807,12 @@ receive_udp_service (void *cls,
632 case 4: 807 case 4:
633 prepare_ipv4_packet (len, ntohs (pkt->len), pkt, 0x11, /* UDP */ 808 prepare_ipv4_packet (len, ntohs (pkt->len), pkt, 0x11, /* UDP */
634 &serv->v4.ip4address, 809 &serv->v4.ip4address,
635 tunnel, state, (struct ip_udp *) buf); 810 tunnel, state, (struct ip_pkt *) buf);
636 break; 811 break;
637 case 6: 812 case 6:
638 prepare_ipv6_packet (len, ntohs (pkt->len), pkt, 0x11, /* UDP */ 813 prepare_ipv6_packet (len, ntohs (pkt->len), pkt, 0x11, /* UDP */
639 &serv->v6.ip6address, 814 &serv->v6.ip6address,
640 tunnel, state, (struct ip6_udp *) buf); 815 tunnel, state, (struct ip6_pkt *) buf);
641 816
642 break; 817 break;
643 default: 818 default:
@@ -645,7 +820,7 @@ receive_udp_service (void *cls,
645 break; 820 break;
646 } 821 }
647 822
648 GNUNET_CRYPTO_hash (&state->udp_info, sizeof (struct udp_info), &hash); 823 GNUNET_CRYPTO_hash (&state->redirect_info, sizeof (struct redirect_info), &hash);
649 824
650 if (GNUNET_NO == 825 if (GNUNET_NO ==
651 GNUNET_CONTAINER_multihashmap_contains (udp_connections, &hash)) 826 GNUNET_CONTAINER_multihashmap_contains (udp_connections, &hash))
@@ -674,6 +849,7 @@ run (void *cls,
674{ 849{
675 const static struct GNUNET_MESH_MessageHandler handlers[] = { 850 const static struct GNUNET_MESH_MessageHandler handlers[] = {
676 {receive_udp_service, GNUNET_MESSAGE_TYPE_SERVICE_UDP, 0}, 851 {receive_udp_service, GNUNET_MESSAGE_TYPE_SERVICE_UDP, 0},
852 {receive_tcp_service, GNUNET_MESSAGE_TYPE_SERVICE_TCP, 0},
677 {NULL, 0, 0} 853 {NULL, 0, 0}
678 }; 854 };
679 mesh_handle = GNUNET_MESH_connect(cfg_, 855 mesh_handle = GNUNET_MESH_connect(cfg_,
@@ -683,7 +859,9 @@ run (void *cls,
683 859
684 cfg = cfg_; 860 cfg = cfg_;
685 udp_connections = GNUNET_CONTAINER_multihashmap_create(65536); 861 udp_connections = GNUNET_CONTAINER_multihashmap_create(65536);
862 tcp_connections = GNUNET_CONTAINER_multihashmap_create(65536);
686 udp_services = GNUNET_CONTAINER_multihashmap_create(65536); 863 udp_services = GNUNET_CONTAINER_multihashmap_create(65536);
864 tcp_services = GNUNET_CONTAINER_multihashmap_create(65536);
687 865
688 char *services; 866 char *services;
689 GNUNET_CONFIGURATION_get_value_filename(cfg, "dns", "SERVICES", &services); 867 GNUNET_CONFIGURATION_get_value_filename(cfg, "dns", "SERVICES", &services);
diff --git a/src/vpn/gnunet-daemon-vpn-helper.c b/src/vpn/gnunet-daemon-vpn-helper.c
index 9f8bc49f2..40cf96826 100644
--- a/src/vpn/gnunet-daemon-vpn-helper.c
+++ b/src/vpn/gnunet-daemon-vpn-helper.c
@@ -248,8 +248,8 @@ message_token (void *cls,
248 sizeof (GNUNET_HashCode)); 248 sizeof (GNUNET_HashCode));
249 249
250 if (0x11 == pkt6->ip6_hdr.nxthdr 250 if (0x11 == pkt6->ip6_hdr.nxthdr
251 && me-> 251 && (me->desc.
252 desc.service_type & htonl (GNUNET_DNS_SERVICE_TYPE_UDP) 252 service_type & htonl (GNUNET_DNS_SERVICE_TYPE_UDP))
253 && (port_in_ports (me->desc.ports, pkt6_udp->udp_hdr.dpt) 253 && (port_in_ports (me->desc.ports, pkt6_udp->udp_hdr.dpt)
254 || testBit (me->additional_ports, 254 || testBit (me->additional_ports,
255 ntohs (pkt6_udp->udp_hdr.dpt)))) 255 ntohs (pkt6_udp->udp_hdr.dpt))))
@@ -260,13 +260,11 @@ message_token (void *cls,
260 ntohs (pkt6_udp->udp_hdr.len)); 260 ntohs (pkt6_udp->udp_hdr.len));
261 261
262 } 262 }
263 else if (0x11 == pkt6->ip6_hdr.nxthdr 263 else if (0x06 == pkt6->ip6_hdr.nxthdr
264 && me->desc. 264 && (me->desc.
265 service_type & htonl (GNUNET_DNS_SERVICE_TYPE_TCP) 265 service_type & htonl (GNUNET_DNS_SERVICE_TYPE_TCP))
266 && 266 &&
267 (port_in_ports (me->desc.ports, pkt6_tcp->tcp_hdr.dpt) 267 (port_in_ports (me->desc.ports, pkt6_tcp->tcp_hdr.dpt)))
268 && testBit (me->additional_ports,
269 ntohs (pkt6_tcp->tcp_hdr.spt))))
270 { 268 {
271 hdr->type = ntohs (GNUNET_MESSAGE_TYPE_SERVICE_TCP); 269 hdr->type = ntohs (GNUNET_MESSAGE_TYPE_SERVICE_TCP);
272 270
@@ -297,10 +295,10 @@ message_token (void *cls,
297 *cls = me->tunnel; 295 *cls = me->tunnel;
298 send_pkt_to_peer (cls, (struct GNUNET_PeerIdentity *) 1, 296 send_pkt_to_peer (cls, (struct GNUNET_PeerIdentity *) 1,
299 NULL); 297 NULL);
298 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
299 "Queued to send to peer %x, type %d\n",
300 *((unsigned int *) &me->desc.peer), ntohs(hdr->type));
300 } 301 }
301 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
302 "Queued to send to peer %x\n",
303 *((unsigned int *) &me->desc.peer));
304 } 302 }
305 break; 303 break;
306 case 0x3a: 304 case 0x3a:
diff --git a/src/vpn/gnunet-service-dns.c b/src/vpn/gnunet-service-dns.c
index 40c3d8052..3741a52c9 100644
--- a/src/vpn/gnunet-service-dns.c
+++ b/src/vpn/gnunet-service-dns.c
@@ -738,7 +738,7 @@ publish_iterate (void *cls, const char *section)
738 service_type = GNUNET_DNS_SERVICE_TYPE_UDP; 738 service_type = GNUNET_DNS_SERVICE_TYPE_UDP;
739 739
740 if (NULL != tcp_redirects) 740 if (NULL != tcp_redirects)
741 service_type = GNUNET_DNS_SERVICE_TYPE_TCP; 741 service_type |= GNUNET_DNS_SERVICE_TYPE_TCP;
742 742
743 service_type = htonl (service_type); 743 service_type = htonl (service_type);
744 744
diff --git a/src/vpn/gnunet-vpn-packet.h b/src/vpn/gnunet-vpn-packet.h
index c60d3dc92..51cf4c4e8 100644
--- a/src/vpn/gnunet-vpn-packet.h
+++ b/src/vpn/gnunet-vpn-packet.h
@@ -41,6 +41,8 @@ struct ip_hdr {
41 unsigned dadr:32 GNUNET_PACKED; 41 unsigned dadr:32 GNUNET_PACKED;
42}; 42};
43 43
44#define TCP_FLAG_SYN 2
45
44struct tcp_pkt { 46struct tcp_pkt {
45 unsigned spt:16 GNUNET_PACKED; 47 unsigned spt:16 GNUNET_PACKED;
46 unsigned dpt:16 GNUNET_PACKED; 48 unsigned dpt:16 GNUNET_PACKED;
@@ -197,6 +199,7 @@ struct ip_udp {
197 struct udp_pkt udp_hdr; 199 struct udp_pkt udp_hdr;
198 unsigned char data[1]; 200 unsigned char data[1];
199}; 201};
202
200struct ip_udp_dns { 203struct ip_udp_dns {
201 struct GNUNET_MessageHeader shdr; 204 struct GNUNET_MessageHeader shdr;
202 struct pkt_tun tun; 205 struct pkt_tun tun;
@@ -204,4 +207,12 @@ struct ip_udp_dns {
204 struct udp_dns udp_dns; 207 struct udp_dns udp_dns;
205}; 208};
206 209
210struct ip_tcp {
211 struct GNUNET_MessageHeader shdr;
212 struct pkt_tun tun;
213 struct ip_hdr ip_hdr;
214 struct tcp_pkt tcp_hdr;
215 unsigned char data[1];
216};
217
207#endif 218#endif