aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/dns/dnsparser.c16
-rw-r--r--src/dns/gnunet-service-dns.c78
-rw-r--r--src/exit/exit.h6
-rw-r--r--src/exit/gnunet-daemon-exit.c116
-rw-r--r--src/include/gnunet_tun_lib.h38
-rw-r--r--src/tun/Makefile.am2
-rw-r--r--src/vpn/gnunet-service-vpn.c134
7 files changed, 195 insertions, 195 deletions
diff --git a/src/dns/dnsparser.c b/src/dns/dnsparser.c
index 12253a2e7..63207d5ce 100644
--- a/src/dns/dnsparser.c
+++ b/src/dns/dnsparser.c
@@ -32,7 +32,7 @@
32// DNS-Stuff 32// DNS-Stuff
33GNUNET_NETWORK_STRUCT_BEGIN 33GNUNET_NETWORK_STRUCT_BEGIN
34/* FIXME: replace this one with the one from tcpip_tun.h! */ 34/* FIXME: replace this one with the one from tcpip_tun.h! */
35struct dns_header 35struct GNUNET_TUN_DnsHeader
36{ 36{
37 uint16_t id GNUNET_PACKED; 37 uint16_t id GNUNET_PACKED;
38 struct GNUNET_DNSPARSER_Flags flags; 38 struct GNUNET_DNSPARSER_Flags flags;
@@ -306,15 +306,15 @@ GNUNET_DNSPARSER_parse (const char *udp_payload,
306 size_t udp_payload_length) 306 size_t udp_payload_length)
307{ 307{
308 struct GNUNET_DNSPARSER_Packet *p; 308 struct GNUNET_DNSPARSER_Packet *p;
309 const struct dns_header *dns; 309 const struct GNUNET_TUN_DnsHeader *dns;
310 size_t off; 310 size_t off;
311 unsigned int n; 311 unsigned int n;
312 unsigned int i; 312 unsigned int i;
313 313
314 if (udp_payload_length < sizeof (struct dns_header)) 314 if (udp_payload_length < sizeof (struct GNUNET_TUN_DnsHeader))
315 return NULL; 315 return NULL;
316 dns = (const struct dns_header *) udp_payload; 316 dns = (const struct GNUNET_TUN_DnsHeader *) udp_payload;
317 off = sizeof (struct dns_header); 317 off = sizeof (struct GNUNET_TUN_DnsHeader);
318 p = GNUNET_malloc (sizeof (struct GNUNET_DNSPARSER_Packet)); 318 p = GNUNET_malloc (sizeof (struct GNUNET_DNSPARSER_Packet));
319 p->flags = dns->flags; 319 p->flags = dns->flags;
320 p->id = dns->id; 320 p->id = dns->id;
@@ -711,7 +711,7 @@ GNUNET_DNSPARSER_pack (const struct GNUNET_DNSPARSER_Packet *p,
711 char **buf, 711 char **buf,
712 size_t *buf_length) 712 size_t *buf_length)
713{ 713{
714 struct dns_header dns; 714 struct GNUNET_TUN_DnsHeader dns;
715 size_t off; 715 size_t off;
716 char tmp[max]; 716 char tmp[max];
717 unsigned int i; 717 unsigned int i;
@@ -730,7 +730,7 @@ GNUNET_DNSPARSER_pack (const struct GNUNET_DNSPARSER_Packet *p,
730 dns.authority_rcount = htons (p->num_authority_records); 730 dns.authority_rcount = htons (p->num_authority_records);
731 dns.additional_rcount = htons (p->num_additional_records); 731 dns.additional_rcount = htons (p->num_additional_records);
732 732
733 off = sizeof (struct dns_header); 733 off = sizeof (struct GNUNET_TUN_DnsHeader);
734 trc = GNUNET_NO; 734 trc = GNUNET_NO;
735 for (i=0;i<p->num_queries;i++) 735 for (i=0;i<p->num_queries;i++)
736 { 736 {
@@ -783,7 +783,7 @@ GNUNET_DNSPARSER_pack (const struct GNUNET_DNSPARSER_Packet *p,
783 783
784 if (GNUNET_YES == trc) 784 if (GNUNET_YES == trc)
785 dns.flags.message_truncated = 1; 785 dns.flags.message_truncated = 1;
786 memcpy (tmp, &dns, sizeof (struct dns_header)); 786 memcpy (tmp, &dns, sizeof (struct GNUNET_TUN_DnsHeader));
787 787
788 *buf = GNUNET_malloc (off); 788 *buf = GNUNET_malloc (off);
789 *buf_length = off; 789 *buf_length = off;
diff --git a/src/dns/gnunet-service-dns.c b/src/dns/gnunet-service-dns.c
index 76beaaf5c..175215634 100644
--- a/src/dns/gnunet-service-dns.c
+++ b/src/dns/gnunet-service-dns.c
@@ -328,21 +328,21 @@ request_done (struct RequestRecord *rr)
328 328
329 /* send response via hijacker */ 329 /* send response via hijacker */
330 reply_len = sizeof (struct GNUNET_MessageHeader); 330 reply_len = sizeof (struct GNUNET_MessageHeader);
331 reply_len += sizeof (struct tun_header); 331 reply_len += sizeof (struct GNUNET_TUN_Layer2PacketHeader);
332 switch (rr->src_addr.ss_family) 332 switch (rr->src_addr.ss_family)
333 { 333 {
334 case AF_INET: 334 case AF_INET:
335 reply_len += sizeof (struct ip4_header); 335 reply_len += sizeof (struct GNUNET_TUN_IPv4Header);
336 break; 336 break;
337 case AF_INET6: 337 case AF_INET6:
338 reply_len += sizeof (struct ip6_header); 338 reply_len += sizeof (struct GNUNET_TUN_IPv6Header);
339 break; 339 break;
340 default: 340 default:
341 GNUNET_break (0); 341 GNUNET_break (0);
342 cleanup_rr (rr); 342 cleanup_rr (rr);
343 return; 343 return;
344 } 344 }
345 reply_len += sizeof (struct udp_packet); 345 reply_len += sizeof (struct GNUNET_TUN_UdpHeader);
346 reply_len += rr->payload_length; 346 reply_len += rr->payload_length;
347 if (reply_len >= GNUNET_SERVER_MAX_MESSAGE_SIZE) 347 if (reply_len >= GNUNET_SERVER_MAX_MESSAGE_SIZE)
348 { 348 {
@@ -364,15 +364,15 @@ request_done (struct RequestRecord *rr)
364 364
365 /* first, TUN header */ 365 /* first, TUN header */
366 { 366 {
367 struct tun_header tun; 367 struct GNUNET_TUN_Layer2PacketHeader tun;
368 368
369 tun.flags = htons (0); 369 tun.flags = htons (0);
370 if (rr->src_addr.ss_family == AF_INET) 370 if (rr->src_addr.ss_family == AF_INET)
371 tun.proto = htons (ETH_P_IPV4); 371 tun.proto = htons (ETH_P_IPV4);
372 else 372 else
373 tun.proto = htons (ETH_P_IPV6); 373 tun.proto = htons (ETH_P_IPV6);
374 memcpy (&buf[off], &tun, sizeof (struct tun_header)); 374 memcpy (&buf[off], &tun, sizeof (struct GNUNET_TUN_Layer2PacketHeader));
375 off += sizeof (struct tun_header); 375 off += sizeof (struct GNUNET_TUN_Layer2PacketHeader);
376 } 376 }
377 377
378 /* now IP header */ 378 /* now IP header */
@@ -383,11 +383,11 @@ request_done (struct RequestRecord *rr)
383 { 383 {
384 struct sockaddr_in *src = (struct sockaddr_in *) &rr->src_addr; 384 struct sockaddr_in *src = (struct sockaddr_in *) &rr->src_addr;
385 struct sockaddr_in *dst = (struct sockaddr_in *) &rr->dst_addr; 385 struct sockaddr_in *dst = (struct sockaddr_in *) &rr->dst_addr;
386 struct ip4_header ip; 386 struct GNUNET_TUN_IPv4Header ip;
387 387
388 spt = dst->sin_port; 388 spt = dst->sin_port;
389 dpt = src->sin_port; 389 dpt = src->sin_port;
390 ip.header_length = sizeof (struct ip4_header) / 4; 390 ip.header_length = sizeof (struct GNUNET_TUN_IPv4Header) / 4;
391 ip.version = IPVERSION; /* aka 4 */ 391 ip.version = IPVERSION; /* aka 4 */
392 ip.diff_serv = 0; 392 ip.diff_serv = 0;
393 ip.total_length = htons ((uint16_t) reply_len - off); 393 ip.total_length = htons ((uint16_t) reply_len - off);
@@ -412,7 +412,7 @@ request_done (struct RequestRecord *rr)
412 udp_crc_sum = GNUNET_CRYPTO_crc16_step (udp_crc_sum, 412 udp_crc_sum = GNUNET_CRYPTO_crc16_step (udp_crc_sum,
413 &tmp, 413 &tmp,
414 sizeof (uint16_t)); 414 sizeof (uint16_t));
415 tmp = htons (rr->payload_length + sizeof (struct udp_packet)); 415 tmp = htons (rr->payload_length + sizeof (struct GNUNET_TUN_UdpHeader));
416 udp_crc_sum = GNUNET_CRYPTO_crc16_step (udp_crc_sum, 416 udp_crc_sum = GNUNET_CRYPTO_crc16_step (udp_crc_sum,
417 &tmp, 417 &tmp,
418 sizeof (uint16_t)); 418 sizeof (uint16_t));
@@ -425,7 +425,7 @@ request_done (struct RequestRecord *rr)
425 { 425 {
426 struct sockaddr_in6 *src = (struct sockaddr_in6 *) &rr->src_addr; 426 struct sockaddr_in6 *src = (struct sockaddr_in6 *) &rr->src_addr;
427 struct sockaddr_in6 *dst = (struct sockaddr_in6 *) &rr->dst_addr; 427 struct sockaddr_in6 *dst = (struct sockaddr_in6 *) &rr->dst_addr;
428 struct ip6_header ip; 428 struct GNUNET_TUN_IPv6Header ip;
429 429
430 spt = dst->sin6_port; 430 spt = dst->sin6_port;
431 dpt = src->sin6_port; 431 dpt = src->sin6_port;
@@ -444,7 +444,7 @@ request_done (struct RequestRecord *rr)
444 { 444 {
445 uint32_t tmp; 445 uint32_t tmp;
446 446
447 tmp = htons (rr->payload_length + sizeof (struct udp_packet)); 447 tmp = htons (rr->payload_length + sizeof (struct GNUNET_TUN_UdpHeader));
448 udp_crc_sum = GNUNET_CRYPTO_crc16_step (udp_crc_sum, 448 udp_crc_sum = GNUNET_CRYPTO_crc16_step (udp_crc_sum,
449 &tmp, 449 &tmp,
450 sizeof (uint32_t)); 450 sizeof (uint32_t));
@@ -463,7 +463,7 @@ request_done (struct RequestRecord *rr)
463 463
464 /* now UDP header */ 464 /* now UDP header */
465 { 465 {
466 struct udp_packet udp; 466 struct GNUNET_TUN_UdpHeader udp;
467 467
468 udp.spt = spt; 468 udp.spt = spt;
469 udp.dpt = dpt; 469 udp.dpt = dpt;
@@ -597,11 +597,11 @@ next_phase (struct RequestRecord *rr)
597 { 597 {
598 case AF_INET: 598 case AF_INET:
599 dnsout = dnsout4; 599 dnsout = dnsout4;
600 salen = sizeof (struct ip4_header); 600 salen = sizeof (struct GNUNET_TUN_IPv4Header);
601 break; 601 break;
602 case AF_INET6: 602 case AF_INET6:
603 dnsout = dnsout6; 603 dnsout = dnsout6;
604 salen = sizeof (struct ip6_header); 604 salen = sizeof (struct GNUNET_TUN_IPv6Header);
605 break; 605 break;
606 default: 606 default:
607 GNUNET_break (0); 607 GNUNET_break (0);
@@ -715,7 +715,7 @@ read_response (void *cls,
715 struct sockaddr_in addr4; 715 struct sockaddr_in addr4;
716 struct sockaddr_in6 addr6; 716 struct sockaddr_in6 addr6;
717 struct sockaddr *addr; 717 struct sockaddr *addr;
718 struct dns_header *dns; 718 struct GNUNET_TUN_DnsHeader *dns;
719 socklen_t addrlen; 719 socklen_t addrlen;
720 struct RequestRecord *rr; 720 struct RequestRecord *rr;
721 ssize_t r; 721 ssize_t r;
@@ -765,14 +765,14 @@ read_response (void *cls,
765 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "recvfrom"); 765 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "recvfrom");
766 return; 766 return;
767 } 767 }
768 if (sizeof (struct dns_header) > r) 768 if (sizeof (struct GNUNET_TUN_DnsHeader) > r)
769 { 769 {
770 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 770 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
771 _("Received DNS response that is too small (%u bytes)"), 771 _("Received DNS response that is too small (%u bytes)"),
772 r); 772 r);
773 return; 773 return;
774 } 774 }
775 dns = (struct dns_header *) buf; 775 dns = (struct GNUNET_TUN_DnsHeader *) buf;
776 rr = &requests[dns->id]; 776 rr = &requests[dns->id];
777 if (rr->phase != RP_INTERNET_DNS) 777 if (rr->phase != RP_INTERNET_DNS)
778 { 778 {
@@ -986,7 +986,7 @@ handle_client_response (void *cls GNUNET_UNUSED,
986 break; 986 break;
987 case 2: /* update */ 987 case 2: /* update */
988 msize -= sizeof (struct GNUNET_DNS_Response); 988 msize -= sizeof (struct GNUNET_DNS_Response);
989 if ( (sizeof (struct dns_header) > msize) || 989 if ( (sizeof (struct GNUNET_TUN_DnsHeader) > msize) ||
990 (RP_REQUEST_MONITOR == rr->phase) || 990 (RP_REQUEST_MONITOR == rr->phase) ||
991 (RP_RESPONSE_MONITOR == rr->phase) ) 991 (RP_RESPONSE_MONITOR == rr->phase) )
992 { 992 {
@@ -1036,11 +1036,11 @@ process_helper_messages (void *cls GNUNET_UNUSED, void *client,
1036 const struct GNUNET_MessageHeader *message) 1036 const struct GNUNET_MessageHeader *message)
1037{ 1037{
1038 uint16_t msize; 1038 uint16_t msize;
1039 const struct tun_header *tun; 1039 const struct GNUNET_TUN_Layer2PacketHeader *tun;
1040 const struct ip4_header *ip4; 1040 const struct GNUNET_TUN_IPv4Header *ip4;
1041 const struct ip6_header *ip6; 1041 const struct GNUNET_TUN_IPv6Header *ip6;
1042 const struct udp_packet *udp; 1042 const struct GNUNET_TUN_UdpHeader *udp;
1043 const struct dns_header *dns; 1043 const struct GNUNET_TUN_DnsHeader *dns;
1044 struct RequestRecord *rr; 1044 struct RequestRecord *rr;
1045 struct sockaddr_in *srca4; 1045 struct sockaddr_in *srca4;
1046 struct sockaddr_in6 *srca6; 1046 struct sockaddr_in6 *srca6;
@@ -1048,22 +1048,22 @@ process_helper_messages (void *cls GNUNET_UNUSED, void *client,
1048 struct sockaddr_in6 *dsta6; 1048 struct sockaddr_in6 *dsta6;
1049 1049
1050 msize = ntohs (message->size); 1050 msize = ntohs (message->size);
1051 if (msize < sizeof (struct GNUNET_MessageHeader) + sizeof (struct tun_header) + sizeof (struct ip4_header)) 1051 if (msize < sizeof (struct GNUNET_MessageHeader) + sizeof (struct GNUNET_TUN_Layer2PacketHeader) + sizeof (struct GNUNET_TUN_IPv4Header))
1052 { 1052 {
1053 /* non-IP packet received on TUN!? */ 1053 /* non-IP packet received on TUN!? */
1054 GNUNET_break (0); 1054 GNUNET_break (0);
1055 return; 1055 return;
1056 } 1056 }
1057 msize -= sizeof (struct GNUNET_MessageHeader); 1057 msize -= sizeof (struct GNUNET_MessageHeader);
1058 tun = (const struct tun_header *) &message[1]; 1058 tun = (const struct GNUNET_TUN_Layer2PacketHeader *) &message[1];
1059 msize -= sizeof (struct tun_header); 1059 msize -= sizeof (struct GNUNET_TUN_Layer2PacketHeader);
1060 switch (ntohs (tun->proto)) 1060 switch (ntohs (tun->proto))
1061 { 1061 {
1062 case ETH_P_IPV4: 1062 case ETH_P_IPV4:
1063 ip4 = (const struct ip4_header *) &tun[1]; 1063 ip4 = (const struct GNUNET_TUN_IPv4Header *) &tun[1];
1064 if ( (msize < sizeof (struct ip4_header)) || 1064 if ( (msize < sizeof (struct GNUNET_TUN_IPv4Header)) ||
1065 (ip4->version != IPVERSION) || 1065 (ip4->version != IPVERSION) ||
1066 (ip4->header_length != sizeof (struct ip4_header) / 4) || 1066 (ip4->header_length != sizeof (struct GNUNET_TUN_IPv4Header) / 4) ||
1067 (ntohs(ip4->total_length) != msize) || 1067 (ntohs(ip4->total_length) != msize) ||
1068 (ip4->protocol != IPPROTO_UDP) ) 1068 (ip4->protocol != IPPROTO_UDP) )
1069 { 1069 {
@@ -1072,12 +1072,12 @@ process_helper_messages (void *cls GNUNET_UNUSED, void *client,
1072 _("Received malformed IPv4-UDP packet on TUN interface.\n")); 1072 _("Received malformed IPv4-UDP packet on TUN interface.\n"));
1073 return; 1073 return;
1074 } 1074 }
1075 udp = (const struct udp_packet*) &ip4[1]; 1075 udp = (const struct GNUNET_TUN_UdpHeader*) &ip4[1];
1076 msize -= sizeof (struct ip4_header); 1076 msize -= sizeof (struct GNUNET_TUN_IPv4Header);
1077 break; 1077 break;
1078 case ETH_P_IPV6: 1078 case ETH_P_IPV6:
1079 ip6 = (const struct ip6_header *) &tun[1]; 1079 ip6 = (const struct GNUNET_TUN_IPv6Header *) &tun[1];
1080 if ( (msize < sizeof (struct ip6_header)) || 1080 if ( (msize < sizeof (struct GNUNET_TUN_IPv6Header)) ||
1081 (ip6->version != 6) || 1081 (ip6->version != 6) ||
1082 (ntohs (ip6->payload_length) != msize) || 1082 (ntohs (ip6->payload_length) != msize) ||
1083 (ip6->next_header != IPPROTO_UDP) ) 1083 (ip6->next_header != IPPROTO_UDP) )
@@ -1087,8 +1087,8 @@ process_helper_messages (void *cls GNUNET_UNUSED, void *client,
1087 _("Received malformed IPv6-UDP packet on TUN interface.\n")); 1087 _("Received malformed IPv6-UDP packet on TUN interface.\n"));
1088 return; 1088 return;
1089 } 1089 }
1090 udp = (const struct udp_packet*) &ip6[1]; 1090 udp = (const struct GNUNET_TUN_UdpHeader*) &ip6[1];
1091 msize -= sizeof (struct ip6_header); 1091 msize -= sizeof (struct GNUNET_TUN_IPv6Header);
1092 break; 1092 break;
1093 default: 1093 default:
1094 /* non-IP packet received on TUN!? */ 1094 /* non-IP packet received on TUN!? */
@@ -1098,7 +1098,7 @@ process_helper_messages (void *cls GNUNET_UNUSED, void *client,
1098 ntohs (tun->proto)); 1098 ntohs (tun->proto));
1099 return; 1099 return;
1100 } 1100 }
1101 if (msize <= sizeof (struct udp_packet) + sizeof (struct dns_header)) 1101 if (msize <= sizeof (struct GNUNET_TUN_UdpHeader) + sizeof (struct GNUNET_TUN_DnsHeader))
1102 { 1102 {
1103 /* non-DNS packet received on TUN, ignore */ 1103 /* non-DNS packet received on TUN, ignore */
1104 GNUNET_STATISTICS_update (stats, 1104 GNUNET_STATISTICS_update (stats,
@@ -1106,8 +1106,8 @@ process_helper_messages (void *cls GNUNET_UNUSED, void *client,
1106 1, GNUNET_NO); 1106 1, GNUNET_NO);
1107 return; 1107 return;
1108 } 1108 }
1109 msize -= sizeof (struct udp_packet); 1109 msize -= sizeof (struct GNUNET_TUN_UdpHeader);
1110 dns = (const struct dns_header*) &udp[1]; 1110 dns = (const struct GNUNET_TUN_DnsHeader*) &udp[1];
1111 rr = &requests[dns->id]; 1111 rr = &requests[dns->id];
1112 1112
1113 /* clean up from previous request */ 1113 /* clean up from previous request */
diff --git a/src/exit/exit.h b/src/exit/exit.h
index 2047ca113..3cd4292bd 100644
--- a/src/exit/exit.h
+++ b/src/exit/exit.h
@@ -53,7 +53,7 @@ struct GNUNET_EXIT_TcpServiceStartMessage
53 * Skeleton of the TCP header to send. Port numbers are to 53 * Skeleton of the TCP header to send. Port numbers are to
54 * be replaced and the checksum may be updated as necessary. 54 * be replaced and the checksum may be updated as necessary.
55 */ 55 */
56 struct tcp_packet tcp_header; 56 struct GNUNET_TUN_TcpHeader tcp_header;
57 57
58 /* followed by TCP payload */ 58 /* followed by TCP payload */
59}; 59};
@@ -79,7 +79,7 @@ struct GNUNET_EXIT_TcpInternetStartMessage
79 * Skeleton of the TCP header to send. Port numbers are to 79 * Skeleton of the TCP header to send. Port numbers are to
80 * be replaced and the checksum may be updated as necessary. 80 * be replaced and the checksum may be updated as necessary.
81 */ 81 */
82 struct tcp_packet tcp_header; 82 struct GNUNET_TUN_TcpHeader tcp_header;
83 83
84 /* followed by IP address of the destination; either 84 /* followed by IP address of the destination; either
85 'struct in_addr' or 'struct in6_addr', depending on af */ 85 'struct in_addr' or 'struct in6_addr', depending on af */
@@ -110,7 +110,7 @@ struct GNUNET_EXIT_TcpDataMessage
110 * Skeleton of the TCP header to send. Port numbers are to 110 * Skeleton of the TCP header to send. Port numbers are to
111 * be replaced and the checksum may be updated as necessary. (The destination port number should not be changed, as it contains the desired destination port.) 111 * be replaced and the checksum may be updated as necessary. (The destination port number should not be changed, as it contains the desired destination port.)
112 */ 112 */
113 struct tcp_packet tcp_header; 113 struct GNUNET_TUN_TcpHeader tcp_header;
114 114
115 /* followed by TCP payload */ 115 /* followed by TCP payload */
116}; 116};
diff --git a/src/exit/gnunet-daemon-exit.c b/src/exit/gnunet-daemon-exit.c
index 3dce69a3e..7df72fb02 100644
--- a/src/exit/gnunet-daemon-exit.c
+++ b/src/exit/gnunet-daemon-exit.c
@@ -595,7 +595,7 @@ send_packet_to_mesh_tunnel (struct GNUNET_MESH_Tunnel *mesh_tunnel,
595 * be the original destination address) 595 * be the original destination address)
596 */ 596 */
597static void 597static void
598udp_from_helper (const struct udp_packet *udp, 598udp_from_helper (const struct GNUNET_TUN_UdpHeader *udp,
599 size_t pktlen, 599 size_t pktlen,
600 int af, 600 int af,
601 const void *destination_ip, 601 const void *destination_ip,
@@ -617,7 +617,7 @@ udp_from_helper (const struct udp_packet *udp,
617 dbuf, sizeof (dbuf)), 617 dbuf, sizeof (dbuf)),
618 (unsigned int) ntohs (udp->dpt)); 618 (unsigned int) ntohs (udp->dpt));
619 } 619 }
620 if (pktlen < sizeof (struct udp_packet)) 620 if (pktlen < sizeof (struct GNUNET_TUN_UdpHeader))
621 { 621 {
622 /* blame kernel */ 622 /* blame kernel */
623 GNUNET_break (0); 623 GNUNET_break (0);
@@ -642,7 +642,7 @@ udp_from_helper (const struct udp_packet *udp,
642 return; 642 return;
643 } 643 }
644 send_packet_to_mesh_tunnel (state->tunnel, 644 send_packet_to_mesh_tunnel (state->tunnel,
645 &udp[1], pktlen - sizeof (struct udp_packet), 645 &udp[1], pktlen - sizeof (struct GNUNET_TUN_UdpHeader),
646 NULL, 646 NULL,
647 state->serv != NULL 647 state->serv != NULL
648 ? GNUNET_MESSAGE_TYPE_VPN_SERVICE_UDP_BACK 648 ? GNUNET_MESSAGE_TYPE_VPN_SERVICE_UDP_BACK
@@ -662,7 +662,7 @@ udp_from_helper (const struct udp_packet *udp,
662 * be the original destination address) 662 * be the original destination address)
663 */ 663 */
664static void 664static void
665tcp_from_helper (const struct tcp_packet *tcp, 665tcp_from_helper (const struct GNUNET_TUN_TcpHeader *tcp,
666 size_t pktlen, 666 size_t pktlen,
667 int af, 667 int af,
668 const void *destination_ip, 668 const void *destination_ip,
@@ -670,7 +670,7 @@ tcp_from_helper (const struct tcp_packet *tcp,
670{ 670{
671 struct TunnelState *state; 671 struct TunnelState *state;
672 char buf[pktlen]; 672 char buf[pktlen];
673 struct tcp_packet *mtcp; 673 struct GNUNET_TUN_TcpHeader *mtcp;
674 674
675 { 675 {
676 char sbuf[INET6_ADDRSTRLEN]; 676 char sbuf[INET6_ADDRSTRLEN];
@@ -686,7 +686,7 @@ tcp_from_helper (const struct tcp_packet *tcp,
686 dbuf, sizeof (dbuf)), 686 dbuf, sizeof (dbuf)),
687 (unsigned int) ntohs (tcp->dpt)); 687 (unsigned int) ntohs (tcp->dpt));
688 } 688 }
689 if (pktlen < sizeof (struct tcp_packet)) 689 if (pktlen < sizeof (struct GNUNET_TUN_TcpHeader))
690 { 690 {
691 /* blame kernel */ 691 /* blame kernel */
692 GNUNET_break (0); 692 GNUNET_break (0);
@@ -708,7 +708,7 @@ tcp_from_helper (const struct tcp_packet *tcp,
708 /* mug port numbers and crc to avoid information leakage; 708 /* mug port numbers and crc to avoid information leakage;
709 sender will need to lookup the correct values anyway */ 709 sender will need to lookup the correct values anyway */
710 memcpy (buf, tcp, pktlen); 710 memcpy (buf, tcp, pktlen);
711 mtcp = (struct tcp_packet *) buf; 711 mtcp = (struct GNUNET_TUN_TcpHeader *) buf;
712 mtcp->spt = 0; 712 mtcp->spt = 0;
713 mtcp->dpt = 0; 713 mtcp->dpt = 0;
714 mtcp->crc = 0; 714 mtcp->crc = 0;
@@ -732,7 +732,7 @@ static void
732message_token (void *cls GNUNET_UNUSED, void *client GNUNET_UNUSED, 732message_token (void *cls GNUNET_UNUSED, void *client GNUNET_UNUSED,
733 const struct GNUNET_MessageHeader *message) 733 const struct GNUNET_MessageHeader *message)
734{ 734{
735 const struct tun_header *pkt_tun; 735 const struct GNUNET_TUN_Layer2PacketHeader *pkt_tun;
736 size_t size; 736 size_t size;
737 737
738 GNUNET_STATISTICS_update (stats, 738 GNUNET_STATISTICS_update (stats,
@@ -744,7 +744,7 @@ message_token (void *cls GNUNET_UNUSED, void *client GNUNET_UNUSED,
744 return; 744 return;
745 } 745 }
746 size = ntohs (message->size); 746 size = ntohs (message->size);
747 if (size < sizeof (struct tun_header) + sizeof (struct GNUNET_MessageHeader)) 747 if (size < sizeof (struct GNUNET_TUN_Layer2PacketHeader) + sizeof (struct GNUNET_MessageHeader))
748 { 748 {
749 GNUNET_break (0); 749 GNUNET_break (0);
750 return; 750 return;
@@ -752,38 +752,38 @@ message_token (void *cls GNUNET_UNUSED, void *client GNUNET_UNUSED,
752 GNUNET_STATISTICS_update (stats, 752 GNUNET_STATISTICS_update (stats,
753 gettext_noop ("# Bytes received from TUN"), 753 gettext_noop ("# Bytes received from TUN"),
754 size, GNUNET_NO); 754 size, GNUNET_NO);
755 pkt_tun = (const struct tun_header *) &message[1]; 755 pkt_tun = (const struct GNUNET_TUN_Layer2PacketHeader *) &message[1];
756 size -= sizeof (struct tun_header) + sizeof (struct GNUNET_MessageHeader); 756 size -= sizeof (struct GNUNET_TUN_Layer2PacketHeader) + sizeof (struct GNUNET_MessageHeader);
757 switch (ntohs (pkt_tun->proto)) 757 switch (ntohs (pkt_tun->proto))
758 { 758 {
759 case ETH_P_IPV6: 759 case ETH_P_IPV6:
760 { 760 {
761 const struct ip6_header *pkt6; 761 const struct GNUNET_TUN_IPv6Header *pkt6;
762 762
763 if (size < sizeof (struct ip6_header)) 763 if (size < sizeof (struct GNUNET_TUN_IPv6Header))
764 { 764 {
765 /* Kernel to blame? */ 765 /* Kernel to blame? */
766 GNUNET_break (0); 766 GNUNET_break (0);
767 return; 767 return;
768 } 768 }
769 pkt6 = (struct ip6_header *) &pkt_tun[1]; 769 pkt6 = (struct GNUNET_TUN_IPv6Header *) &pkt_tun[1];
770 if (size != ntohs (pkt6->payload_length)) 770 if (size != ntohs (pkt6->payload_length))
771 { 771 {
772 /* Kernel to blame? */ 772 /* Kernel to blame? */
773 GNUNET_break (0); 773 GNUNET_break (0);
774 return; 774 return;
775 } 775 }
776 size -= sizeof (struct ip6_header); 776 size -= sizeof (struct GNUNET_TUN_IPv6Header);
777 switch (pkt6->next_header) 777 switch (pkt6->next_header)
778 { 778 {
779 case IPPROTO_UDP: 779 case IPPROTO_UDP:
780 udp_from_helper ((const struct udp_packet *) &pkt6[1], size, 780 udp_from_helper ((const struct GNUNET_TUN_UdpHeader *) &pkt6[1], size,
781 AF_INET6, 781 AF_INET6,
782 &pkt6->destination_address, 782 &pkt6->destination_address,
783 &pkt6->source_address); 783 &pkt6->source_address);
784 break; 784 break;
785 case IPPROTO_TCP: 785 case IPPROTO_TCP:
786 tcp_from_helper ((const struct tcp_packet *) &pkt6[1], size, 786 tcp_from_helper ((const struct GNUNET_TUN_TcpHeader *) &pkt6[1], size,
787 AF_INET6, 787 AF_INET6,
788 &pkt6->destination_address, 788 &pkt6->destination_address,
789 &pkt6->source_address); 789 &pkt6->source_address);
@@ -797,37 +797,37 @@ message_token (void *cls GNUNET_UNUSED, void *client GNUNET_UNUSED,
797 break; 797 break;
798 case ETH_P_IPV4: 798 case ETH_P_IPV4:
799 { 799 {
800 const struct ip4_header *pkt4; 800 const struct GNUNET_TUN_IPv4Header *pkt4;
801 801
802 if (size < sizeof (struct ip4_header)) 802 if (size < sizeof (struct GNUNET_TUN_IPv4Header))
803 { 803 {
804 /* Kernel to blame? */ 804 /* Kernel to blame? */
805 GNUNET_break (0); 805 GNUNET_break (0);
806 return; 806 return;
807 } 807 }
808 pkt4 = (const struct ip4_header *) &pkt_tun[1]; 808 pkt4 = (const struct GNUNET_TUN_IPv4Header *) &pkt_tun[1];
809 if (size != ntohs (pkt4->total_length)) 809 if (size != ntohs (pkt4->total_length))
810 { 810 {
811 /* Kernel to blame? */ 811 /* Kernel to blame? */
812 GNUNET_break (0); 812 GNUNET_break (0);
813 return; 813 return;
814 } 814 }
815 if (pkt4->header_length * 4 != sizeof (struct ip4_header)) 815 if (pkt4->header_length * 4 != sizeof (struct GNUNET_TUN_IPv4Header))
816 { 816 {
817 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 817 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
818 _("IPv4 packet options received. Ignored.\n")); 818 _("IPv4 packet options received. Ignored.\n"));
819 return; 819 return;
820 } 820 }
821 size -= sizeof (struct ip4_header); 821 size -= sizeof (struct GNUNET_TUN_IPv4Header);
822 switch (pkt4->protocol) 822 switch (pkt4->protocol)
823 { 823 {
824 case IPPROTO_UDP: 824 case IPPROTO_UDP:
825 udp_from_helper ((const struct udp_packet *) &pkt4[1], size, 825 udp_from_helper ((const struct GNUNET_TUN_UdpHeader *) &pkt4[1], size,
826 AF_INET, 826 AF_INET,
827 &pkt4->destination_address, 827 &pkt4->destination_address,
828 &pkt4->source_address); 828 &pkt4->source_address);
829 case IPPROTO_TCP: 829 case IPPROTO_TCP:
830 tcp_from_helper ((const struct tcp_packet *) &pkt4[1], size, 830 tcp_from_helper ((const struct GNUNET_TUN_TcpHeader *) &pkt4[1], size,
831 AF_INET, 831 AF_INET,
832 &pkt4->destination_address, 832 &pkt4->destination_address,
833 &pkt4->source_address); 833 &pkt4->source_address);
@@ -1038,10 +1038,10 @@ setup_state_record (struct TunnelState *state)
1038static void 1038static void
1039prepare_ipv4_packet (const void *payload, size_t payload_length, 1039prepare_ipv4_packet (const void *payload, size_t payload_length,
1040 int protocol, 1040 int protocol,
1041 const struct tcp_packet *tcp_header, 1041 const struct GNUNET_TUN_TcpHeader *tcp_header,
1042 const struct SocketAddress *src_address, 1042 const struct SocketAddress *src_address,
1043 const struct SocketAddress *dst_address, 1043 const struct SocketAddress *dst_address,
1044 struct ip4_header *pkt4) 1044 struct GNUNET_TUN_IPv4Header *pkt4)
1045{ 1045{
1046 size_t len; 1046 size_t len;
1047 1047
@@ -1049,26 +1049,26 @@ prepare_ipv4_packet (const void *payload, size_t payload_length,
1049 switch (protocol) 1049 switch (protocol)
1050 { 1050 {
1051 case IPPROTO_UDP: 1051 case IPPROTO_UDP:
1052 len += sizeof (struct udp_packet); 1052 len += sizeof (struct GNUNET_TUN_UdpHeader);
1053 break; 1053 break;
1054 case IPPROTO_TCP: 1054 case IPPROTO_TCP:
1055 len += sizeof (struct tcp_packet); 1055 len += sizeof (struct GNUNET_TUN_TcpHeader);
1056 GNUNET_assert (NULL != tcp_header); 1056 GNUNET_assert (NULL != tcp_header);
1057 break; 1057 break;
1058 default: 1058 default:
1059 GNUNET_break (0); 1059 GNUNET_break (0);
1060 return; 1060 return;
1061 } 1061 }
1062 if (len + sizeof (struct ip4_header) > UINT16_MAX) 1062 if (len + sizeof (struct GNUNET_TUN_IPv4Header) > UINT16_MAX)
1063 { 1063 {
1064 GNUNET_break (0); 1064 GNUNET_break (0);
1065 return; 1065 return;
1066 } 1066 }
1067 1067
1068 pkt4->version = 4; 1068 pkt4->version = 4;
1069 pkt4->header_length = sizeof (struct ip4_header) / 4; 1069 pkt4->header_length = sizeof (struct GNUNET_TUN_IPv4Header) / 4;
1070 pkt4->diff_serv = 0; 1070 pkt4->diff_serv = 0;
1071 pkt4->total_length = htons ((uint16_t) (sizeof (struct ip4_header) + len)); 1071 pkt4->total_length = htons ((uint16_t) (sizeof (struct GNUNET_TUN_IPv4Header) + len));
1072 pkt4->identification = (uint16_t) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 1072 pkt4->identification = (uint16_t) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
1073 UINT16_MAX + 1); 1073 UINT16_MAX + 1);
1074 pkt4->flags = 0; 1074 pkt4->flags = 0;
@@ -1078,13 +1078,13 @@ prepare_ipv4_packet (const void *payload, size_t payload_length,
1078 pkt4->checksum = 0; 1078 pkt4->checksum = 0;
1079 pkt4->destination_address = dst_address->address.ipv4; 1079 pkt4->destination_address = dst_address->address.ipv4;
1080 pkt4->source_address = src_address->address.ipv4; 1080 pkt4->source_address = src_address->address.ipv4;
1081 pkt4->checksum = GNUNET_CRYPTO_crc16_n (pkt4, sizeof (struct ip4_header)); 1081 pkt4->checksum = GNUNET_CRYPTO_crc16_n (pkt4, sizeof (struct GNUNET_TUN_IPv4Header));
1082 1082
1083 switch (protocol) 1083 switch (protocol)
1084 { 1084 {
1085 case IPPROTO_UDP: 1085 case IPPROTO_UDP:
1086 { 1086 {
1087 struct udp_packet *pkt4_udp = (struct udp_packet *) &pkt4[1]; 1087 struct GNUNET_TUN_UdpHeader *pkt4_udp = (struct GNUNET_TUN_UdpHeader *) &pkt4[1];
1088 1088
1089 pkt4_udp->spt = htons (src_address->port); 1089 pkt4_udp->spt = htons (src_address->port);
1090 pkt4_udp->dpt = htons (dst_address->port); 1090 pkt4_udp->dpt = htons (dst_address->port);
@@ -1095,9 +1095,9 @@ prepare_ipv4_packet (const void *payload, size_t payload_length,
1095 break; 1095 break;
1096 case IPPROTO_TCP: 1096 case IPPROTO_TCP:
1097 { 1097 {
1098 struct tcp_packet *pkt4_tcp = (struct tcp_packet *) &pkt4[1]; 1098 struct GNUNET_TUN_TcpHeader *pkt4_tcp = (struct GNUNET_TUN_TcpHeader *) &pkt4[1];
1099 1099
1100 memcpy (pkt4_tcp, tcp_header, sizeof (struct tcp_packet)); 1100 memcpy (pkt4_tcp, tcp_header, sizeof (struct GNUNET_TUN_TcpHeader));
1101 memcpy (&pkt4_tcp[1], payload, payload_length); 1101 memcpy (&pkt4_tcp[1], payload, payload_length);
1102 pkt4_tcp->spt = htons (src_address->port); 1102 pkt4_tcp->spt = htons (src_address->port);
1103 pkt4_tcp->dpt = htons (dst_address->port); 1103 pkt4_tcp->dpt = htons (dst_address->port);
@@ -1138,10 +1138,10 @@ prepare_ipv4_packet (const void *payload, size_t payload_length,
1138static void 1138static void
1139prepare_ipv6_packet (const void *payload, size_t payload_length, 1139prepare_ipv6_packet (const void *payload, size_t payload_length,
1140 int protocol, 1140 int protocol,
1141 const struct tcp_packet *tcp_header, 1141 const struct GNUNET_TUN_TcpHeader *tcp_header,
1142 const struct SocketAddress *src_address, 1142 const struct SocketAddress *src_address,
1143 const struct SocketAddress *dst_address, 1143 const struct SocketAddress *dst_address,
1144 struct ip6_header *pkt6) 1144 struct GNUNET_TUN_IPv6Header *pkt6)
1145{ 1145{
1146 size_t len; 1146 size_t len;
1147 1147
@@ -1149,11 +1149,11 @@ prepare_ipv6_packet (const void *payload, size_t payload_length,
1149 switch (protocol) 1149 switch (protocol)
1150 { 1150 {
1151 case IPPROTO_UDP: 1151 case IPPROTO_UDP:
1152 len += sizeof (struct udp_packet); 1152 len += sizeof (struct GNUNET_TUN_UdpHeader);
1153 break; 1153 break;
1154 case IPPROTO_TCP: 1154 case IPPROTO_TCP:
1155 /* tcp_header (with port/crc not set) must be part of payload! */ 1155 /* tcp_header (with port/crc not set) must be part of payload! */
1156 if (len < sizeof (struct tcp_packet)) 1156 if (len < sizeof (struct GNUNET_TUN_TcpHeader))
1157 { 1157 {
1158 GNUNET_break (0); 1158 GNUNET_break (0);
1159 return; 1159 return;
@@ -1171,7 +1171,7 @@ prepare_ipv6_packet (const void *payload, size_t payload_length,
1171 1171
1172 pkt6->version = 6; 1172 pkt6->version = 6;
1173 pkt6->next_header = protocol; 1173 pkt6->next_header = protocol;
1174 pkt6->payload_length = htons ((uint16_t) (len + sizeof (struct ip6_header))); 1174 pkt6->payload_length = htons ((uint16_t) (len + sizeof (struct GNUNET_TUN_IPv6Header)));
1175 pkt6->hop_limit = 255; 1175 pkt6->hop_limit = 255;
1176 pkt6->destination_address = dst_address->address.ipv6; 1176 pkt6->destination_address = dst_address->address.ipv6;
1177 pkt6->source_address = src_address->address.ipv6; 1177 pkt6->source_address = src_address->address.ipv6;
@@ -1180,7 +1180,7 @@ prepare_ipv6_packet (const void *payload, size_t payload_length,
1180 { 1180 {
1181 case IPPROTO_UDP: 1181 case IPPROTO_UDP:
1182 { 1182 {
1183 struct udp_packet *pkt6_udp = (struct udp_packet *) &pkt6[1]; 1183 struct GNUNET_TUN_UdpHeader *pkt6_udp = (struct GNUNET_TUN_UdpHeader *) &pkt6[1];
1184 1184
1185 memcpy (&pkt6[1], payload, payload_length); 1185 memcpy (&pkt6[1], payload, payload_length);
1186 pkt6_udp->crc = 0; 1186 pkt6_udp->crc = 0;
@@ -1202,7 +1202,7 @@ prepare_ipv6_packet (const void *payload, size_t payload_length,
1202 break; 1202 break;
1203 case IPPROTO_TCP: 1203 case IPPROTO_TCP:
1204 { 1204 {
1205 struct tcp_packet *pkt6_tcp = (struct tcp_packet *) pkt6; 1205 struct GNUNET_TUN_TcpHeader *pkt6_tcp = (struct GNUNET_TUN_TcpHeader *) pkt6;
1206 1206
1207 memcpy (pkt6_tcp, payload, payload_length); 1207 memcpy (pkt6_tcp, payload, payload_length);
1208 pkt6_tcp->crc = 0; 1208 pkt6_tcp->crc = 0;
@@ -1239,7 +1239,7 @@ prepare_ipv6_packet (const void *payload, size_t payload_length,
1239static void 1239static void
1240send_tcp_packet_via_tun (const struct SocketAddress *destination_address, 1240send_tcp_packet_via_tun (const struct SocketAddress *destination_address,
1241 const struct SocketAddress *source_address, 1241 const struct SocketAddress *source_address,
1242 const struct tcp_packet *tcp_header, 1242 const struct GNUNET_TUN_TcpHeader *tcp_header,
1243 const void *payload, size_t payload_length) 1243 const void *payload, size_t payload_length)
1244{ 1244{
1245 size_t len; 1245 size_t len;
@@ -1250,14 +1250,14 @@ send_tcp_packet_via_tun (const struct SocketAddress *destination_address,
1250 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1250 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1251 "Sending packet with %u bytes TCP payload via TUN\n", 1251 "Sending packet with %u bytes TCP payload via TUN\n",
1252 (unsigned int) payload_length); 1252 (unsigned int) payload_length);
1253 len = sizeof (struct GNUNET_MessageHeader) + sizeof (struct tun_header); 1253 len = sizeof (struct GNUNET_MessageHeader) + sizeof (struct GNUNET_TUN_Layer2PacketHeader);
1254 switch (source_address->af) 1254 switch (source_address->af)
1255 { 1255 {
1256 case AF_INET: 1256 case AF_INET:
1257 len += sizeof (struct ip4_header); 1257 len += sizeof (struct GNUNET_TUN_IPv4Header);
1258 break; 1258 break;
1259 case AF_INET6: 1259 case AF_INET6:
1260 len += sizeof (struct ip6_header); 1260 len += sizeof (struct GNUNET_TUN_IPv6Header);
1261 break; 1261 break;
1262 default: 1262 default:
1263 GNUNET_break (0); 1263 GNUNET_break (0);
@@ -1272,18 +1272,18 @@ send_tcp_packet_via_tun (const struct SocketAddress *destination_address,
1272 { 1272 {
1273 char buf[len]; 1273 char buf[len];
1274 struct GNUNET_MessageHeader *hdr; 1274 struct GNUNET_MessageHeader *hdr;
1275 struct tun_header *tun; 1275 struct GNUNET_TUN_Layer2PacketHeader *tun;
1276 1276
1277 hdr= (struct GNUNET_MessageHeader *) buf; 1277 hdr= (struct GNUNET_MessageHeader *) buf;
1278 hdr->type = htons (GNUNET_MESSAGE_TYPE_VPN_HELPER); 1278 hdr->type = htons (GNUNET_MESSAGE_TYPE_VPN_HELPER);
1279 hdr->size = htons (len); 1279 hdr->size = htons (len);
1280 tun = (struct tun_header*) &hdr[1]; 1280 tun = (struct GNUNET_TUN_Layer2PacketHeader*) &hdr[1];
1281 tun->flags = htons (0); 1281 tun->flags = htons (0);
1282 switch (source_address->af) 1282 switch (source_address->af)
1283 { 1283 {
1284 case AF_INET: 1284 case AF_INET:
1285 { 1285 {
1286 struct ip4_header * ipv4 = (struct ip4_header*) &tun[1]; 1286 struct GNUNET_TUN_IPv4Header * ipv4 = (struct GNUNET_TUN_IPv4Header*) &tun[1];
1287 1287
1288 tun->proto = htons (ETH_P_IPV4); 1288 tun->proto = htons (ETH_P_IPV4);
1289 prepare_ipv4_packet (payload, payload_length, 1289 prepare_ipv4_packet (payload, payload_length,
@@ -1296,7 +1296,7 @@ send_tcp_packet_via_tun (const struct SocketAddress *destination_address,
1296 break; 1296 break;
1297 case AF_INET6: 1297 case AF_INET6:
1298 { 1298 {
1299 struct ip6_header * ipv6 = (struct ip6_header*) &tun[1]; 1299 struct GNUNET_TUN_IPv6Header * ipv6 = (struct GNUNET_TUN_IPv6Header*) &tun[1];
1300 1300
1301 tun->proto = htons (ETH_P_IPV6); 1301 tun->proto = htons (ETH_P_IPV6);
1302 prepare_ipv6_packet (payload, payload_length, 1302 prepare_ipv6_packet (payload, payload_length,
@@ -1589,20 +1589,20 @@ send_udp_packet_via_tun (const struct SocketAddress *destination_address,
1589 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1589 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1590 "Sending packet with %u bytes UDP payload via TUN\n", 1590 "Sending packet with %u bytes UDP payload via TUN\n",
1591 (unsigned int) payload_length); 1591 (unsigned int) payload_length);
1592 len = sizeof (struct GNUNET_MessageHeader) + sizeof (struct tun_header); 1592 len = sizeof (struct GNUNET_MessageHeader) + sizeof (struct GNUNET_TUN_Layer2PacketHeader);
1593 switch (source_address->af) 1593 switch (source_address->af)
1594 { 1594 {
1595 case AF_INET: 1595 case AF_INET:
1596 len += sizeof (struct ip4_header); 1596 len += sizeof (struct GNUNET_TUN_IPv4Header);
1597 break; 1597 break;
1598 case AF_INET6: 1598 case AF_INET6:
1599 len += sizeof (struct ip6_header); 1599 len += sizeof (struct GNUNET_TUN_IPv6Header);
1600 break; 1600 break;
1601 default: 1601 default:
1602 GNUNET_break (0); 1602 GNUNET_break (0);
1603 return; 1603 return;
1604 } 1604 }
1605 len += sizeof (struct udp_packet); 1605 len += sizeof (struct GNUNET_TUN_UdpHeader);
1606 len += payload_length; 1606 len += payload_length;
1607 if (len >= GNUNET_SERVER_MAX_MESSAGE_SIZE) 1607 if (len >= GNUNET_SERVER_MAX_MESSAGE_SIZE)
1608 { 1608 {
@@ -1612,18 +1612,18 @@ send_udp_packet_via_tun (const struct SocketAddress *destination_address,
1612 { 1612 {
1613 char buf[len]; 1613 char buf[len];
1614 struct GNUNET_MessageHeader *hdr; 1614 struct GNUNET_MessageHeader *hdr;
1615 struct tun_header *tun; 1615 struct GNUNET_TUN_Layer2PacketHeader *tun;
1616 1616
1617 hdr= (struct GNUNET_MessageHeader *) buf; 1617 hdr= (struct GNUNET_MessageHeader *) buf;
1618 hdr->type = htons (GNUNET_MESSAGE_TYPE_VPN_HELPER); 1618 hdr->type = htons (GNUNET_MESSAGE_TYPE_VPN_HELPER);
1619 hdr->size = htons (len); 1619 hdr->size = htons (len);
1620 tun = (struct tun_header*) &hdr[1]; 1620 tun = (struct GNUNET_TUN_Layer2PacketHeader*) &hdr[1];
1621 tun->flags = htons (0); 1621 tun->flags = htons (0);
1622 switch (source_address->af) 1622 switch (source_address->af)
1623 { 1623 {
1624 case AF_INET: 1624 case AF_INET:
1625 { 1625 {
1626 struct ip4_header * ipv4 = (struct ip4_header*) &tun[1]; 1626 struct GNUNET_TUN_IPv4Header * ipv4 = (struct GNUNET_TUN_IPv4Header*) &tun[1];
1627 1627
1628 tun->proto = htons (ETH_P_IPV4); 1628 tun->proto = htons (ETH_P_IPV4);
1629 prepare_ipv4_packet (payload, payload_length, 1629 prepare_ipv4_packet (payload, payload_length,
@@ -1636,7 +1636,7 @@ send_udp_packet_via_tun (const struct SocketAddress *destination_address,
1636 break; 1636 break;
1637 case AF_INET6: 1637 case AF_INET6:
1638 { 1638 {
1639 struct ip6_header * ipv6 = (struct ip6_header*) &tun[1]; 1639 struct GNUNET_TUN_IPv6Header * ipv6 = (struct GNUNET_TUN_IPv6Header*) &tun[1];
1640 1640
1641 tun->proto = htons (ETH_P_IPV6); 1641 tun->proto = htons (ETH_P_IPV6);
1642 prepare_ipv6_packet (payload, payload_length, 1642 prepare_ipv6_packet (payload, payload_length,
diff --git a/src/include/gnunet_tun_lib.h b/src/include/gnunet_tun_lib.h
index ca521db3b..dc6f01e1e 100644
--- a/src/include/gnunet_tun_lib.h
+++ b/src/include/gnunet_tun_lib.h
@@ -23,32 +23,35 @@
23 * @brief standard TCP/IP network structs and IP checksum calculations for TUN interaction 23 * @brief standard TCP/IP network structs and IP checksum calculations for TUN interaction
24 * @author Philipp Toelke 24 * @author Philipp Toelke
25 * @author Christian Grothoff 25 * @author Christian Grothoff
26 *
27 * TODO:
28 * - currently does not follow our naming conventions
29 */ 26 */
30#ifndef TCPIP_TUN_H 27#ifndef GNUNET_TUN_LIB_H
31#define TCPIP_TUN_H 28#define GNUNET_TUN_LIB_H
32 29
33#include "platform.h"
34#include "gnunet_util_lib.h" 30#include "gnunet_util_lib.h"
35 31
36 32
37/* see http://www.iana.org/assignments/ethernet-numbers */ 33/* see http://www.iana.org/assignments/ethernet-numbers */
38#ifndef ETH_P_IPV4 34#ifndef ETH_P_IPV4
35/**
36 * Number for IPv4
37 */
39#define ETH_P_IPV4 0x0800 38#define ETH_P_IPV4 0x0800
40#endif 39#endif
41 40
42#ifndef ETH_P_IPV6 41#ifndef ETH_P_IPV6
42/**
43 * Number for IPv6
44 */
43#define ETH_P_IPV6 0x86DD 45#define ETH_P_IPV6 0x86DD
44#endif 46#endif
45 47
46 48
47GNUNET_NETWORK_STRUCT_BEGIN 49GNUNET_NETWORK_STRUCT_BEGIN
50
48/** 51/**
49 * Header from Linux TUN interface. 52 * Header from Linux TUN interface.
50 */ 53 */
51struct tun_header 54struct GNUNET_TUN_Layer2PacketHeader
52{ 55{
53 /** 56 /**
54 * Some flags (unused). 57 * Some flags (unused).
@@ -65,7 +68,7 @@ struct tun_header
65/** 68/**
66 * Standard IPv4 header. 69 * Standard IPv4 header.
67 */ 70 */
68struct ip4_header 71struct GNUNET_TUN_IPv4Header
69{ 72{
70 unsigned header_length:4 GNUNET_PACKED; 73 unsigned header_length:4 GNUNET_PACKED;
71 unsigned version:4 GNUNET_PACKED; 74 unsigned version:4 GNUNET_PACKED;
@@ -81,10 +84,11 @@ struct ip4_header
81 struct in_addr destination_address GNUNET_PACKED; 84 struct in_addr destination_address GNUNET_PACKED;
82}; 85};
83 86
87
84/** 88/**
85 * Standard IPv6 header. 89 * Standard IPv6 header.
86 */ 90 */
87struct ip6_header 91struct GNUNET_TUN_IPv6Header
88{ 92{
89 unsigned traffic_class_h:4 GNUNET_PACKED; 93 unsigned traffic_class_h:4 GNUNET_PACKED;
90 unsigned version:4 GNUNET_PACKED; 94 unsigned version:4 GNUNET_PACKED;
@@ -97,12 +101,11 @@ struct ip6_header
97 struct in6_addr destination_address GNUNET_PACKED; 101 struct in6_addr destination_address GNUNET_PACKED;
98}; 102};
99 103
100#define TCP_FLAG_SYN 2
101 104
102/** 105/**
103 * TCP packet header (FIXME: rename!) 106 * TCP packet header (FIXME: rename!)
104 */ 107 */
105struct tcp_packet 108struct GNUNET_TUN_TcpHeader
106{ 109{
107 unsigned spt:16 GNUNET_PACKED; 110 unsigned spt:16 GNUNET_PACKED;
108 unsigned dpt:16 GNUNET_PACKED; 111 unsigned dpt:16 GNUNET_PACKED;
@@ -116,10 +119,11 @@ struct tcp_packet
116 unsigned urg:16 GNUNET_PACKED; 119 unsigned urg:16 GNUNET_PACKED;
117}; 120};
118 121
122
119/** 123/**
120 * UDP packet header (FIXME: rename!) 124 * UDP packet header (FIXME: rename!)
121 */ 125 */
122struct udp_packet 126struct GNUNET_TUN_UdpHeader
123{ 127{
124 uint16_t spt GNUNET_PACKED; 128 uint16_t spt GNUNET_PACKED;
125 uint16_t dpt GNUNET_PACKED; 129 uint16_t dpt GNUNET_PACKED;
@@ -127,10 +131,11 @@ struct udp_packet
127 uint16_t crc GNUNET_PACKED; 131 uint16_t crc GNUNET_PACKED;
128}; 132};
129 133
134
130/** 135/**
131 * DNS header. 136 * DNS header.
132 */ 137 */
133struct dns_header 138struct GNUNET_TUN_DnsHeader
134{ 139{
135 uint16_t id GNUNET_PACKED; 140 uint16_t id GNUNET_PACKED;
136 uint16_t flags GNUNET_PACKED; 141 uint16_t flags GNUNET_PACKED;
@@ -139,13 +144,8 @@ struct dns_header
139 uint16_t nscount GNUNET_PACKED; 144 uint16_t nscount GNUNET_PACKED;
140 uint16_t arcount GNUNET_PACKED; 145 uint16_t arcount GNUNET_PACKED;
141}; 146};
142GNUNET_NETWORK_STRUCT_END
143
144
145
146
147
148 147
148GNUNET_NETWORK_STRUCT_END
149 149
150 150
151#endif 151#endif
diff --git a/src/tun/Makefile.am b/src/tun/Makefile.am
index 15b0d6205..bfc1135d8 100644
--- a/src/tun/Makefile.am
+++ b/src/tun/Makefile.am
@@ -15,6 +15,6 @@ libgnunettun_la_SOURCES = \
15 tun.c 15 tun.c
16libgnunettun_la_LIBADD = \ 16libgnunettun_la_LIBADD = \
17 $(top_builddir)/src/util/libgnunetutil.la $(XLIB) 17 $(top_builddir)/src/util/libgnunetutil.la $(XLIB)
18libgnunethello_la_LDFLAGS = \ 18libgnunettun_la_LDFLAGS = \
19 $(GN_LIB_LDFLAGS) 19 $(GN_LIB_LDFLAGS)
20 20
diff --git a/src/vpn/gnunet-service-vpn.c b/src/vpn/gnunet-service-vpn.c
index 9c0fb1667..7aeabf457 100644
--- a/src/vpn/gnunet-service-vpn.c
+++ b/src/vpn/gnunet-service-vpn.c
@@ -880,8 +880,8 @@ route_packet (struct DestinationEntry *destination,
880 size_t alen; 880 size_t alen;
881 size_t mlen; 881 size_t mlen;
882 int is_new; 882 int is_new;
883 const struct udp_packet *udp; 883 const struct GNUNET_TUN_UdpHeader *udp;
884 const struct tcp_packet *tcp; 884 const struct GNUNET_TUN_TcpHeader *tcp;
885 uint16_t spt; 885 uint16_t spt;
886 uint16_t dpt; 886 uint16_t dpt;
887 887
@@ -889,7 +889,7 @@ route_packet (struct DestinationEntry *destination,
889 { 889 {
890 case IPPROTO_UDP: 890 case IPPROTO_UDP:
891 { 891 {
892 if (payload_length < sizeof (struct udp_packet)) 892 if (payload_length < sizeof (struct GNUNET_TUN_UdpHeader))
893 { 893 {
894 /* blame kernel? */ 894 /* blame kernel? */
895 GNUNET_break (0); 895 GNUNET_break (0);
@@ -909,7 +909,7 @@ route_packet (struct DestinationEntry *destination,
909 break; 909 break;
910 case IPPROTO_TCP: 910 case IPPROTO_TCP:
911 { 911 {
912 if (payload_length < sizeof (struct tcp_packet)) 912 if (payload_length < sizeof (struct GNUNET_TUN_TcpHeader))
913 { 913 {
914 /* blame kernel? */ 914 /* blame kernel? */
915 GNUNET_break (0); 915 GNUNET_break (0);
@@ -1050,7 +1050,7 @@ route_packet (struct DestinationEntry *destination,
1050 struct GNUNET_EXIT_UdpServiceMessage *usm; 1050 struct GNUNET_EXIT_UdpServiceMessage *usm;
1051 1051
1052 mlen = sizeof (struct GNUNET_EXIT_UdpServiceMessage) + 1052 mlen = sizeof (struct GNUNET_EXIT_UdpServiceMessage) +
1053 payload_length - sizeof (struct udp_packet); 1053 payload_length - sizeof (struct GNUNET_TUN_UdpHeader);
1054 if (mlen >= GNUNET_SERVER_MAX_MESSAGE_SIZE) 1054 if (mlen >= GNUNET_SERVER_MAX_MESSAGE_SIZE)
1055 { 1055 {
1056 GNUNET_break (0); 1056 GNUNET_break (0);
@@ -1069,7 +1069,7 @@ route_packet (struct DestinationEntry *destination,
1069 usm->service_descriptor = destination->details.service_destination.service_descriptor; 1069 usm->service_descriptor = destination->details.service_destination.service_descriptor;
1070 memcpy (&usm[1], 1070 memcpy (&usm[1],
1071 &udp[1], 1071 &udp[1],
1072 payload_length - sizeof (struct udp_packet)); 1072 payload_length - sizeof (struct GNUNET_TUN_UdpHeader));
1073 } 1073 }
1074 else 1074 else
1075 { 1075 {
@@ -1079,7 +1079,7 @@ route_packet (struct DestinationEntry *destination,
1079 void *payload; 1079 void *payload;
1080 1080
1081 mlen = sizeof (struct GNUNET_EXIT_UdpInternetMessage) + 1081 mlen = sizeof (struct GNUNET_EXIT_UdpInternetMessage) +
1082 alen + payload_length - sizeof (struct udp_packet); 1082 alen + payload_length - sizeof (struct GNUNET_TUN_UdpHeader);
1083 if (mlen >= GNUNET_SERVER_MAX_MESSAGE_SIZE) 1083 if (mlen >= GNUNET_SERVER_MAX_MESSAGE_SIZE)
1084 { 1084 {
1085 GNUNET_break (0); 1085 GNUNET_break (0);
@@ -1112,7 +1112,7 @@ route_packet (struct DestinationEntry *destination,
1112 } 1112 }
1113 memcpy (payload, 1113 memcpy (payload,
1114 &udp[1], 1114 &udp[1],
1115 payload_length - sizeof (struct udp_packet)); 1115 payload_length - sizeof (struct GNUNET_TUN_UdpHeader));
1116 } 1116 }
1117 break; 1117 break;
1118 case IPPROTO_TCP: 1118 case IPPROTO_TCP:
@@ -1123,7 +1123,7 @@ route_packet (struct DestinationEntry *destination,
1123 struct GNUNET_EXIT_TcpServiceStartMessage *tsm; 1123 struct GNUNET_EXIT_TcpServiceStartMessage *tsm;
1124 1124
1125 mlen = sizeof (struct GNUNET_EXIT_TcpServiceStartMessage) + 1125 mlen = sizeof (struct GNUNET_EXIT_TcpServiceStartMessage) +
1126 payload_length - sizeof (struct tcp_packet); 1126 payload_length - sizeof (struct GNUNET_TUN_TcpHeader);
1127 if (mlen >= GNUNET_SERVER_MAX_MESSAGE_SIZE) 1127 if (mlen >= GNUNET_SERVER_MAX_MESSAGE_SIZE)
1128 { 1128 {
1129 GNUNET_break (0); 1129 GNUNET_break (0);
@@ -1140,7 +1140,7 @@ route_packet (struct DestinationEntry *destination,
1140 tsm->tcp_header = *tcp; 1140 tsm->tcp_header = *tcp;
1141 memcpy (&tsm[1], 1141 memcpy (&tsm[1],
1142 &tcp[1], 1142 &tcp[1],
1143 payload_length - sizeof (struct tcp_packet)); 1143 payload_length - sizeof (struct GNUNET_TUN_TcpHeader));
1144 } 1144 }
1145 else 1145 else
1146 { 1146 {
@@ -1150,7 +1150,7 @@ route_packet (struct DestinationEntry *destination,
1150 void *payload; 1150 void *payload;
1151 1151
1152 mlen = sizeof (struct GNUNET_EXIT_TcpInternetStartMessage) + 1152 mlen = sizeof (struct GNUNET_EXIT_TcpInternetStartMessage) +
1153 alen + payload_length - sizeof (struct tcp_packet); 1153 alen + payload_length - sizeof (struct GNUNET_TUN_TcpHeader);
1154 if (mlen >= GNUNET_SERVER_MAX_MESSAGE_SIZE) 1154 if (mlen >= GNUNET_SERVER_MAX_MESSAGE_SIZE)
1155 { 1155 {
1156 GNUNET_break (0); 1156 GNUNET_break (0);
@@ -1181,7 +1181,7 @@ route_packet (struct DestinationEntry *destination,
1181 } 1181 }
1182 memcpy (payload, 1182 memcpy (payload,
1183 &tcp[1], 1183 &tcp[1],
1184 payload_length - sizeof (struct tcp_packet)); 1184 payload_length - sizeof (struct GNUNET_TUN_TcpHeader));
1185 } 1185 }
1186 } 1186 }
1187 else 1187 else
@@ -1189,7 +1189,7 @@ route_packet (struct DestinationEntry *destination,
1189 struct GNUNET_EXIT_TcpDataMessage *tdm; 1189 struct GNUNET_EXIT_TcpDataMessage *tdm;
1190 1190
1191 mlen = sizeof (struct GNUNET_EXIT_TcpDataMessage) + 1191 mlen = sizeof (struct GNUNET_EXIT_TcpDataMessage) +
1192 alen + payload_length - sizeof (struct tcp_packet); 1192 alen + payload_length - sizeof (struct GNUNET_TUN_TcpHeader);
1193 if (mlen >= GNUNET_SERVER_MAX_MESSAGE_SIZE) 1193 if (mlen >= GNUNET_SERVER_MAX_MESSAGE_SIZE)
1194 { 1194 {
1195 GNUNET_break (0); 1195 GNUNET_break (0);
@@ -1205,7 +1205,7 @@ route_packet (struct DestinationEntry *destination,
1205 tdm->tcp_header = *tcp; 1205 tdm->tcp_header = *tcp;
1206 memcpy (&tdm[1], 1206 memcpy (&tdm[1],
1207 &tcp[1], 1207 &tcp[1],
1208 payload_length - sizeof (struct tcp_packet)); 1208 payload_length - sizeof (struct GNUNET_TUN_TcpHeader));
1209 } 1209 }
1210 break; 1210 break;
1211 default: 1211 default:
@@ -1231,7 +1231,7 @@ static void
1231message_token (void *cls GNUNET_UNUSED, void *client GNUNET_UNUSED, 1231message_token (void *cls GNUNET_UNUSED, void *client GNUNET_UNUSED,
1232 const struct GNUNET_MessageHeader *message) 1232 const struct GNUNET_MessageHeader *message)
1233{ 1233{
1234 const struct tun_header *tun; 1234 const struct GNUNET_TUN_Layer2PacketHeader *tun;
1235 size_t mlen; 1235 size_t mlen;
1236 GNUNET_HashCode key; 1236 GNUNET_HashCode key;
1237 struct DestinationEntry *de; 1237 struct DestinationEntry *de;
@@ -1241,26 +1241,26 @@ message_token (void *cls GNUNET_UNUSED, void *client GNUNET_UNUSED,
1241 1, GNUNET_NO); 1241 1, GNUNET_NO);
1242 mlen = ntohs (message->size); 1242 mlen = ntohs (message->size);
1243 if ( (ntohs (message->type) != GNUNET_MESSAGE_TYPE_VPN_HELPER) || 1243 if ( (ntohs (message->type) != GNUNET_MESSAGE_TYPE_VPN_HELPER) ||
1244 (mlen < sizeof (struct GNUNET_MessageHeader) + sizeof (struct tun_header)) ) 1244 (mlen < sizeof (struct GNUNET_MessageHeader) + sizeof (struct GNUNET_TUN_Layer2PacketHeader)) )
1245 { 1245 {
1246 GNUNET_break (0); 1246 GNUNET_break (0);
1247 return; 1247 return;
1248 } 1248 }
1249 tun = (const struct tun_header *) &message[1]; 1249 tun = (const struct GNUNET_TUN_Layer2PacketHeader *) &message[1];
1250 mlen -= (sizeof (struct GNUNET_MessageHeader) + sizeof (struct tun_header)); 1250 mlen -= (sizeof (struct GNUNET_MessageHeader) + sizeof (struct GNUNET_TUN_Layer2PacketHeader));
1251 switch (ntohs (tun->proto)) 1251 switch (ntohs (tun->proto))
1252 { 1252 {
1253 case ETH_P_IPV6: 1253 case ETH_P_IPV6:
1254 { 1254 {
1255 const struct ip6_header *pkt6; 1255 const struct GNUNET_TUN_IPv6Header *pkt6;
1256 1256
1257 if (mlen < sizeof (struct ip6_header)) 1257 if (mlen < sizeof (struct GNUNET_TUN_IPv6Header))
1258 { 1258 {
1259 /* blame kernel */ 1259 /* blame kernel */
1260 GNUNET_break (0); 1260 GNUNET_break (0);
1261 return; 1261 return;
1262 } 1262 }
1263 pkt6 = (const struct ip6_header *) &tun[1]; 1263 pkt6 = (const struct GNUNET_TUN_IPv6Header *) &tun[1];
1264 get_destination_key_from_ip (AF_INET6, 1264 get_destination_key_from_ip (AF_INET6,
1265 &pkt6->destination_address, 1265 &pkt6->destination_address,
1266 &key); 1266 &key);
@@ -1288,20 +1288,20 @@ message_token (void *cls GNUNET_UNUSED, void *client GNUNET_UNUSED,
1288 &pkt6->source_address, 1288 &pkt6->source_address,
1289 &pkt6->destination_address, 1289 &pkt6->destination_address,
1290 &pkt6[1], 1290 &pkt6[1],
1291 mlen - sizeof (struct ip6_header)); 1291 mlen - sizeof (struct GNUNET_TUN_IPv6Header));
1292 } 1292 }
1293 break; 1293 break;
1294 case ETH_P_IPV4: 1294 case ETH_P_IPV4:
1295 { 1295 {
1296 struct ip4_header *pkt4; 1296 struct GNUNET_TUN_IPv4Header *pkt4;
1297 1297
1298 if (mlen < sizeof (struct ip4_header)) 1298 if (mlen < sizeof (struct GNUNET_TUN_IPv4Header))
1299 { 1299 {
1300 /* blame kernel */ 1300 /* blame kernel */
1301 GNUNET_break (0); 1301 GNUNET_break (0);
1302 return; 1302 return;
1303 } 1303 }
1304 pkt4 = (struct ip4_header *) &tun[1]; 1304 pkt4 = (struct GNUNET_TUN_IPv4Header *) &tun[1];
1305 get_destination_key_from_ip (AF_INET, 1305 get_destination_key_from_ip (AF_INET,
1306 &pkt4->destination_address, 1306 &pkt4->destination_address,
1307 &key); 1307 &key);
@@ -1323,7 +1323,7 @@ message_token (void *cls GNUNET_UNUSED, void *client GNUNET_UNUSED,
1323 sizeof (buf))); 1323 sizeof (buf)));
1324 return; 1324 return;
1325 } 1325 }
1326 if (pkt4->header_length * 4 != sizeof (struct ip4_header)) 1326 if (pkt4->header_length * 4 != sizeof (struct GNUNET_TUN_IPv4Header))
1327 { 1327 {
1328 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 1328 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1329 _("Received IPv4 packet with options (dropping it)\n")); 1329 _("Received IPv4 packet with options (dropping it)\n"));
@@ -1335,7 +1335,7 @@ message_token (void *cls GNUNET_UNUSED, void *client GNUNET_UNUSED,
1335 &pkt4->source_address, 1335 &pkt4->source_address,
1336 &pkt4->destination_address, 1336 &pkt4->destination_address,
1337 &pkt4[1], 1337 &pkt4[1],
1338 mlen - sizeof (struct ip4_header)); 1338 mlen - sizeof (struct GNUNET_TUN_IPv4Header));
1339 } 1339 }
1340 break; 1340 break;
1341 default: 1341 default:
@@ -1407,26 +1407,26 @@ receive_udp_back (void *cls GNUNET_UNUSED, struct GNUNET_MESH_Tunnel *tunnel,
1407 { 1407 {
1408 case AF_INET: 1408 case AF_INET:
1409 { 1409 {
1410 size_t size = sizeof (struct ip4_header) 1410 size_t size = sizeof (struct GNUNET_TUN_IPv4Header)
1411 + sizeof (struct udp_packet) 1411 + sizeof (struct GNUNET_TUN_UdpHeader)
1412 + sizeof (struct GNUNET_MessageHeader) + 1412 + sizeof (struct GNUNET_MessageHeader) +
1413 sizeof (struct tun_header) + 1413 sizeof (struct GNUNET_TUN_Layer2PacketHeader) +
1414 mlen; 1414 mlen;
1415 { 1415 {
1416 char buf[size]; 1416 char buf[size];
1417 struct GNUNET_MessageHeader *msg = (struct GNUNET_MessageHeader *) buf; 1417 struct GNUNET_MessageHeader *msg = (struct GNUNET_MessageHeader *) buf;
1418 struct tun_header *tun = (struct tun_header*) &msg[1]; 1418 struct GNUNET_TUN_Layer2PacketHeader *tun = (struct GNUNET_TUN_Layer2PacketHeader*) &msg[1];
1419 struct ip4_header *ipv4 = (struct ip4_header *) &tun[1]; 1419 struct GNUNET_TUN_IPv4Header *ipv4 = (struct GNUNET_TUN_IPv4Header *) &tun[1];
1420 struct udp_packet *udp = (struct udp_packet *) &ipv4[1]; 1420 struct GNUNET_TUN_UdpHeader *udp = (struct GNUNET_TUN_UdpHeader *) &ipv4[1];
1421 msg->type = htons (GNUNET_MESSAGE_TYPE_VPN_HELPER); 1421 msg->type = htons (GNUNET_MESSAGE_TYPE_VPN_HELPER);
1422 msg->size = htons (size); 1422 msg->size = htons (size);
1423 tun->flags = htons (0); 1423 tun->flags = htons (0);
1424 tun->proto = htons (ETH_P_IPV4); 1424 tun->proto = htons (ETH_P_IPV4);
1425 ipv4->version = 4; 1425 ipv4->version = 4;
1426 ipv4->header_length = sizeof (struct ip4_header) / 4; 1426 ipv4->header_length = sizeof (struct GNUNET_TUN_IPv4Header) / 4;
1427 ipv4->diff_serv = 0; 1427 ipv4->diff_serv = 0;
1428 ipv4->total_length = htons (sizeof (struct ip4_header) + 1428 ipv4->total_length = htons (sizeof (struct GNUNET_TUN_IPv4Header) +
1429 sizeof (struct udp_packet) + 1429 sizeof (struct GNUNET_TUN_UdpHeader) +
1430 mlen); 1430 mlen);
1431 ipv4->identification = (uint16_t) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 1431 ipv4->identification = (uint16_t) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
1432 UINT16_MAX + 1); 1432 UINT16_MAX + 1);
@@ -1438,7 +1438,7 @@ receive_udp_back (void *cls GNUNET_UNUSED, struct GNUNET_MESH_Tunnel *tunnel,
1438 ipv4->source_address = ts->destination_ip.v4; 1438 ipv4->source_address = ts->destination_ip.v4;
1439 ipv4->destination_address = ts->source_ip.v4; 1439 ipv4->destination_address = ts->source_ip.v4;
1440 ipv4->checksum = 1440 ipv4->checksum =
1441 GNUNET_CRYPTO_crc16_n (ipv4, sizeof (struct ip4_header)); 1441 GNUNET_CRYPTO_crc16_n (ipv4, sizeof (struct GNUNET_TUN_IPv4Header));
1442 if (0 == ntohs (reply->source_port)) 1442 if (0 == ntohs (reply->source_port))
1443 udp->spt = htons (ts->destination_port); 1443 udp->spt = htons (ts->destination_port);
1444 else 1444 else
@@ -1447,7 +1447,7 @@ receive_udp_back (void *cls GNUNET_UNUSED, struct GNUNET_MESH_Tunnel *tunnel,
1447 udp->dpt = htons (ts->source_port); 1447 udp->dpt = htons (ts->source_port);
1448 else 1448 else
1449 udp->dpt = reply->destination_port; 1449 udp->dpt = reply->destination_port;
1450 udp->len = htons (mlen + sizeof (struct udp_packet)); 1450 udp->len = htons (mlen + sizeof (struct GNUNET_TUN_UdpHeader));
1451 udp->crc = 0; // FIXME: optional, but we might want to calculate this one anyway 1451 udp->crc = 0; // FIXME: optional, but we might want to calculate this one anyway
1452 memcpy (&udp[1], 1452 memcpy (&udp[1],
1453 &reply[1], 1453 &reply[1],
@@ -1461,17 +1461,17 @@ receive_udp_back (void *cls GNUNET_UNUSED, struct GNUNET_MESH_Tunnel *tunnel,
1461 break; 1461 break;
1462 case AF_INET6: 1462 case AF_INET6:
1463 { 1463 {
1464 size_t size = sizeof (struct ip6_header) 1464 size_t size = sizeof (struct GNUNET_TUN_IPv6Header)
1465 + sizeof (struct udp_packet) 1465 + sizeof (struct GNUNET_TUN_UdpHeader)
1466 + sizeof (struct GNUNET_MessageHeader) + 1466 + sizeof (struct GNUNET_MessageHeader) +
1467 sizeof (struct tun_header) + 1467 sizeof (struct GNUNET_TUN_Layer2PacketHeader) +
1468 mlen; 1468 mlen;
1469 { 1469 {
1470 char buf[size]; 1470 char buf[size];
1471 struct GNUNET_MessageHeader *msg = (struct GNUNET_MessageHeader *) buf; 1471 struct GNUNET_MessageHeader *msg = (struct GNUNET_MessageHeader *) buf;
1472 struct tun_header *tun = (struct tun_header*) &msg[1]; 1472 struct GNUNET_TUN_Layer2PacketHeader *tun = (struct GNUNET_TUN_Layer2PacketHeader*) &msg[1];
1473 struct ip6_header *ipv6 = (struct ip6_header *) &tun[1]; 1473 struct GNUNET_TUN_IPv6Header *ipv6 = (struct GNUNET_TUN_IPv6Header *) &tun[1];
1474 struct udp_packet *udp = (struct udp_packet *) &ipv6[1]; 1474 struct GNUNET_TUN_UdpHeader *udp = (struct GNUNET_TUN_UdpHeader *) &ipv6[1];
1475 msg->type = htons (GNUNET_MESSAGE_TYPE_VPN_HELPER); 1475 msg->type = htons (GNUNET_MESSAGE_TYPE_VPN_HELPER);
1476 msg->size = htons (size); 1476 msg->size = htons (size);
1477 tun->flags = htons (0); 1477 tun->flags = htons (0);
@@ -1480,7 +1480,7 @@ receive_udp_back (void *cls GNUNET_UNUSED, struct GNUNET_MESH_Tunnel *tunnel,
1480 ipv6->version = 6; 1480 ipv6->version = 6;
1481 ipv6->traffic_class_l = 0; 1481 ipv6->traffic_class_l = 0;
1482 ipv6->flow_label = 0; 1482 ipv6->flow_label = 0;
1483 ipv6->payload_length = htons (sizeof (struct udp_packet) + sizeof (struct ip6_header) + mlen); 1483 ipv6->payload_length = htons (sizeof (struct GNUNET_TUN_UdpHeader) + sizeof (struct GNUNET_TUN_IPv6Header) + mlen);
1484 ipv6->next_header = IPPROTO_UDP; 1484 ipv6->next_header = IPPROTO_UDP;
1485 ipv6->hop_limit = 255; 1485 ipv6->hop_limit = 255;
1486 ipv6->source_address = ts->destination_ip.v6; 1486 ipv6->source_address = ts->destination_ip.v6;
@@ -1493,7 +1493,7 @@ receive_udp_back (void *cls GNUNET_UNUSED, struct GNUNET_MESH_Tunnel *tunnel,
1493 udp->dpt = htons (ts->source_port); 1493 udp->dpt = htons (ts->source_port);
1494 else 1494 else
1495 udp->dpt = reply->destination_port; 1495 udp->dpt = reply->destination_port;
1496 udp->len = htons (mlen + sizeof (struct udp_packet)); 1496 udp->len = htons (mlen + sizeof (struct GNUNET_TUN_UdpHeader));
1497 udp->crc = 0; 1497 udp->crc = 0;
1498 memcpy (&udp[1], 1498 memcpy (&udp[1],
1499 &reply[1], 1499 &reply[1],
@@ -1585,26 +1585,26 @@ receive_tcp_back (void *cls GNUNET_UNUSED, struct GNUNET_MESH_Tunnel *tunnel,
1585 { 1585 {
1586 case AF_INET: 1586 case AF_INET:
1587 { 1587 {
1588 size_t size = sizeof (struct ip4_header) 1588 size_t size = sizeof (struct GNUNET_TUN_IPv4Header)
1589 + sizeof (struct tcp_packet) 1589 + sizeof (struct GNUNET_TUN_TcpHeader)
1590 + sizeof (struct GNUNET_MessageHeader) + 1590 + sizeof (struct GNUNET_MessageHeader) +
1591 sizeof (struct tun_header) + 1591 sizeof (struct GNUNET_TUN_Layer2PacketHeader) +
1592 mlen; 1592 mlen;
1593 { 1593 {
1594 char buf[size]; 1594 char buf[size];
1595 struct GNUNET_MessageHeader *msg = (struct GNUNET_MessageHeader *) buf; 1595 struct GNUNET_MessageHeader *msg = (struct GNUNET_MessageHeader *) buf;
1596 struct tun_header *tun = (struct tun_header*) &msg[1]; 1596 struct GNUNET_TUN_Layer2PacketHeader *tun = (struct GNUNET_TUN_Layer2PacketHeader*) &msg[1];
1597 struct ip4_header *ipv4 = (struct ip4_header *) &tun[1]; 1597 struct GNUNET_TUN_IPv4Header *ipv4 = (struct GNUNET_TUN_IPv4Header *) &tun[1];
1598 struct tcp_packet *tcp = (struct tcp_packet *) &ipv4[1]; 1598 struct GNUNET_TUN_TcpHeader *tcp = (struct GNUNET_TUN_TcpHeader *) &ipv4[1];
1599 msg->type = htons (GNUNET_MESSAGE_TYPE_VPN_HELPER); 1599 msg->type = htons (GNUNET_MESSAGE_TYPE_VPN_HELPER);
1600 msg->size = htons (size); 1600 msg->size = htons (size);
1601 tun->flags = htons (0); 1601 tun->flags = htons (0);
1602 tun->proto = htons (ETH_P_IPV4); 1602 tun->proto = htons (ETH_P_IPV4);
1603 ipv4->version = 4; 1603 ipv4->version = 4;
1604 ipv4->header_length = sizeof (struct ip4_header) / 4; 1604 ipv4->header_length = sizeof (struct GNUNET_TUN_IPv4Header) / 4;
1605 ipv4->diff_serv = 0; 1605 ipv4->diff_serv = 0;
1606 ipv4->total_length = htons (sizeof (struct ip4_header) + 1606 ipv4->total_length = htons (sizeof (struct GNUNET_TUN_IPv4Header) +
1607 sizeof (struct tcp_packet) + 1607 sizeof (struct GNUNET_TUN_TcpHeader) +
1608 mlen); 1608 mlen);
1609 ipv4->identification = (uint16_t) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 1609 ipv4->identification = (uint16_t) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
1610 UINT16_MAX + 1); 1610 UINT16_MAX + 1);
@@ -1616,7 +1616,7 @@ receive_tcp_back (void *cls GNUNET_UNUSED, struct GNUNET_MESH_Tunnel *tunnel,
1616 ipv4->source_address = ts->destination_ip.v4; 1616 ipv4->source_address = ts->destination_ip.v4;
1617 ipv4->destination_address = ts->source_ip.v4; 1617 ipv4->destination_address = ts->source_ip.v4;
1618 ipv4->checksum = 1618 ipv4->checksum =
1619 GNUNET_CRYPTO_crc16_n (ipv4, sizeof (struct ip4_header)); 1619 GNUNET_CRYPTO_crc16_n (ipv4, sizeof (struct GNUNET_TUN_IPv4Header));
1620 *tcp = data->tcp_header; 1620 *tcp = data->tcp_header;
1621 tcp->spt = htons (ts->destination_port); 1621 tcp->spt = htons (ts->destination_port);
1622 tcp->dpt = htons (ts->source_port); 1622 tcp->dpt = htons (ts->source_port);
@@ -1631,9 +1631,9 @@ receive_tcp_back (void *cls GNUNET_UNUSED, struct GNUNET_MESH_Tunnel *tunnel,
1631 sum = GNUNET_CRYPTO_crc16_step (sum, 1631 sum = GNUNET_CRYPTO_crc16_step (sum,
1632 &ipv4->source_address, 1632 &ipv4->source_address,
1633 2 * sizeof (struct in_addr)); 1633 2 * sizeof (struct in_addr));
1634 tmp = htonl ((IPPROTO_TCP << 16) | (mlen + sizeof (struct tcp_packet))); 1634 tmp = htonl ((IPPROTO_TCP << 16) | (mlen + sizeof (struct GNUNET_TUN_TcpHeader)));
1635 sum = GNUNET_CRYPTO_crc16_step (sum, &tmp, sizeof (uint32_t)); 1635 sum = GNUNET_CRYPTO_crc16_step (sum, &tmp, sizeof (uint32_t));
1636 sum = GNUNET_CRYPTO_crc16_step (sum, tcp, mlen + sizeof (struct tcp_packet)); 1636 sum = GNUNET_CRYPTO_crc16_step (sum, tcp, mlen + sizeof (struct GNUNET_TUN_TcpHeader));
1637 tcp->crc = GNUNET_CRYPTO_crc16_finish (sum); 1637 tcp->crc = GNUNET_CRYPTO_crc16_finish (sum);
1638 } 1638 }
1639 (void) GNUNET_HELPER_send (helper_handle, 1639 (void) GNUNET_HELPER_send (helper_handle,
@@ -1645,17 +1645,17 @@ receive_tcp_back (void *cls GNUNET_UNUSED, struct GNUNET_MESH_Tunnel *tunnel,
1645 break; 1645 break;
1646 case AF_INET6: 1646 case AF_INET6:
1647 { 1647 {
1648 size_t size = sizeof (struct ip6_header) 1648 size_t size = sizeof (struct GNUNET_TUN_IPv6Header)
1649 + sizeof (struct tcp_packet) 1649 + sizeof (struct GNUNET_TUN_TcpHeader)
1650 + sizeof (struct GNUNET_MessageHeader) + 1650 + sizeof (struct GNUNET_MessageHeader) +
1651 sizeof (struct tun_header) + 1651 sizeof (struct GNUNET_TUN_Layer2PacketHeader) +
1652 mlen; 1652 mlen;
1653 { 1653 {
1654 char buf[size]; 1654 char buf[size];
1655 struct GNUNET_MessageHeader *msg = (struct GNUNET_MessageHeader *) buf; 1655 struct GNUNET_MessageHeader *msg = (struct GNUNET_MessageHeader *) buf;
1656 struct tun_header *tun = (struct tun_header*) &msg[1]; 1656 struct GNUNET_TUN_Layer2PacketHeader *tun = (struct GNUNET_TUN_Layer2PacketHeader*) &msg[1];
1657 struct ip6_header *ipv6 = (struct ip6_header *) &tun[1]; 1657 struct GNUNET_TUN_IPv6Header *ipv6 = (struct GNUNET_TUN_IPv6Header *) &tun[1];
1658 struct tcp_packet *tcp = (struct tcp_packet *) &ipv6[1]; 1658 struct GNUNET_TUN_TcpHeader *tcp = (struct GNUNET_TUN_TcpHeader *) &ipv6[1];
1659 msg->type = htons (GNUNET_MESSAGE_TYPE_VPN_HELPER); 1659 msg->type = htons (GNUNET_MESSAGE_TYPE_VPN_HELPER);
1660 msg->size = htons (size); 1660 msg->size = htons (size);
1661 tun->flags = htons (0); 1661 tun->flags = htons (0);
@@ -1664,7 +1664,7 @@ receive_tcp_back (void *cls GNUNET_UNUSED, struct GNUNET_MESH_Tunnel *tunnel,
1664 ipv6->version = 6; 1664 ipv6->version = 6;
1665 ipv6->traffic_class_l = 0; 1665 ipv6->traffic_class_l = 0;
1666 ipv6->flow_label = 0; 1666 ipv6->flow_label = 0;
1667 ipv6->payload_length = htons (sizeof (struct tcp_packet) + sizeof (struct ip6_header) + mlen); 1667 ipv6->payload_length = htons (sizeof (struct GNUNET_TUN_TcpHeader) + sizeof (struct GNUNET_TUN_IPv6Header) + mlen);
1668 ipv6->next_header = IPPROTO_TCP; 1668 ipv6->next_header = IPPROTO_TCP;
1669 ipv6->hop_limit = 255; 1669 ipv6->hop_limit = 255;
1670 ipv6->source_address = ts->destination_ip.v6; 1670 ipv6->source_address = ts->destination_ip.v6;
@@ -1677,12 +1677,12 @@ receive_tcp_back (void *cls GNUNET_UNUSED, struct GNUNET_MESH_Tunnel *tunnel,
1677 uint32_t tmp; 1677 uint32_t tmp;
1678 1678
1679 sum = GNUNET_CRYPTO_crc16_step (sum, &ipv6->source_address, 2 * sizeof (struct in6_addr)); 1679 sum = GNUNET_CRYPTO_crc16_step (sum, &ipv6->source_address, 2 * sizeof (struct in6_addr));
1680 tmp = htonl (sizeof (struct tcp_packet) + mlen); 1680 tmp = htonl (sizeof (struct GNUNET_TUN_TcpHeader) + mlen);
1681 sum = GNUNET_CRYPTO_crc16_step (sum, &tmp, sizeof (uint32_t)); 1681 sum = GNUNET_CRYPTO_crc16_step (sum, &tmp, sizeof (uint32_t));
1682 tmp = htonl (IPPROTO_TCP); 1682 tmp = htonl (IPPROTO_TCP);
1683 sum = GNUNET_CRYPTO_crc16_step (sum, &tmp, sizeof (uint32_t)); 1683 sum = GNUNET_CRYPTO_crc16_step (sum, &tmp, sizeof (uint32_t));
1684 sum = GNUNET_CRYPTO_crc16_step (sum, tcp, 1684 sum = GNUNET_CRYPTO_crc16_step (sum, tcp,
1685 sizeof (struct tcp_packet) + mlen); 1685 sizeof (struct GNUNET_TUN_TcpHeader) + mlen);
1686 tcp->crc = GNUNET_CRYPTO_crc16_finish (sum); 1686 tcp->crc = GNUNET_CRYPTO_crc16_finish (sum);
1687 } 1687 }
1688 (void) GNUNET_HELPER_send (helper_handle, 1688 (void) GNUNET_HELPER_send (helper_handle,