diff options
-rw-r--r-- | src/Makefile.am | 1 | ||||
-rw-r--r-- | src/dns/Makefile.am | 1 | ||||
-rw-r--r-- | src/dns/gnunet-service-dns.c | 28 | ||||
-rw-r--r-- | src/exit/Makefile.am | 1 | ||||
-rw-r--r-- | src/exit/gnunet-daemon-exit.c | 20 | ||||
-rw-r--r-- | src/include/gnunet_tun_lib.h | 17 | ||||
-rw-r--r-- | src/vpn/Makefile.am | 1 | ||||
-rw-r--r-- | src/vpn/gnunet-service-vpn.c | 44 |
8 files changed, 45 insertions, 68 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index 12862af38..36e87f82b 100644 --- a/src/Makefile.am +++ b/src/Makefile.am | |||
@@ -10,6 +10,7 @@ SUBDIRS = \ | |||
10 | include $(INTLEMU_SUBDIRS) \ | 10 | include $(INTLEMU_SUBDIRS) \ |
11 | util \ | 11 | util \ |
12 | hello \ | 12 | hello \ |
13 | tun \ | ||
13 | block \ | 14 | block \ |
14 | statistics \ | 15 | statistics \ |
15 | arm \ | 16 | arm \ |
diff --git a/src/dns/Makefile.am b/src/dns/Makefile.am index f8bdae94e..5f9f39116 100644 --- a/src/dns/Makefile.am +++ b/src/dns/Makefile.am | |||
@@ -70,6 +70,7 @@ gnunet_dns_redirector_DEPENDENCIES = \ | |||
70 | gnunet_service_dns_SOURCES = \ | 70 | gnunet_service_dns_SOURCES = \ |
71 | gnunet-service-dns.c | 71 | gnunet-service-dns.c |
72 | gnunet_service_dns_LDADD = \ | 72 | gnunet_service_dns_LDADD = \ |
73 | $(top_builddir)/src/tun/libgnunettun.la \ | ||
73 | $(top_builddir)/src/statistics/libgnunetstatistics.la \ | 74 | $(top_builddir)/src/statistics/libgnunetstatistics.la \ |
74 | $(top_builddir)/src/util/libgnunetutil.la \ | 75 | $(top_builddir)/src/util/libgnunetutil.la \ |
75 | $(GN_LIBINTL) | 76 | $(GN_LIBINTL) |
diff --git a/src/dns/gnunet-service-dns.c b/src/dns/gnunet-service-dns.c index 175215634..5dc6641e7 100644 --- a/src/dns/gnunet-service-dns.c +++ b/src/dns/gnunet-service-dns.c | |||
@@ -32,9 +32,6 @@ | |||
32 | #include "gnunet_statistics_service.h" | 32 | #include "gnunet_statistics_service.h" |
33 | #include "gnunet_tun_lib.h" | 33 | #include "gnunet_tun_lib.h" |
34 | 34 | ||
35 | #ifndef IPVERSION | ||
36 | #define IPVERSION 4 | ||
37 | #endif | ||
38 | 35 | ||
39 | /** | 36 | /** |
40 | * Phases each request goes through. | 37 | * Phases each request goes through. |
@@ -387,20 +384,13 @@ request_done (struct RequestRecord *rr) | |||
387 | 384 | ||
388 | spt = dst->sin_port; | 385 | spt = dst->sin_port; |
389 | dpt = src->sin_port; | 386 | dpt = src->sin_port; |
390 | ip.header_length = sizeof (struct GNUNET_TUN_IPv4Header) / 4; | 387 | GNUNET_TUN_initialize_ipv4_header (&ip, |
391 | ip.version = IPVERSION; /* aka 4 */ | 388 | IPPROTO_UDP, |
392 | ip.diff_serv = 0; | 389 | reply_len - off - sizeof (struct GNUNET_TUN_IPv4Header), |
393 | ip.total_length = htons ((uint16_t) reply_len - off); | 390 | &dst->sin_addr, |
394 | ip.identification = (uint16_t) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, | 391 | &src->sin_addr); |
395 | 65536); | 392 | |
396 | ip.flags = 0; | 393 | |
397 | ip.fragmentation_offset = 0; | ||
398 | ip.ttl = 255; /* or lower? */ | ||
399 | ip.protocol = IPPROTO_UDP; | ||
400 | ip.checksum = 0; /* checksum is optional */ | ||
401 | ip.source_address = dst->sin_addr; | ||
402 | ip.destination_address = src->sin_addr; | ||
403 | ip.checksum = GNUNET_CRYPTO_crc16_n (&ip, sizeof (ip)); | ||
404 | 394 | ||
405 | udp_crc_sum = GNUNET_CRYPTO_crc16_step (udp_crc_sum, | 395 | udp_crc_sum = GNUNET_CRYPTO_crc16_step (udp_crc_sum, |
406 | &ip.source_address, | 396 | &ip.source_address, |
@@ -1062,7 +1052,7 @@ process_helper_messages (void *cls GNUNET_UNUSED, void *client, | |||
1062 | case ETH_P_IPV4: | 1052 | case ETH_P_IPV4: |
1063 | ip4 = (const struct GNUNET_TUN_IPv4Header *) &tun[1]; | 1053 | ip4 = (const struct GNUNET_TUN_IPv4Header *) &tun[1]; |
1064 | if ( (msize < sizeof (struct GNUNET_TUN_IPv4Header)) || | 1054 | if ( (msize < sizeof (struct GNUNET_TUN_IPv4Header)) || |
1065 | (ip4->version != IPVERSION) || | 1055 | (ip4->version != 4) || |
1066 | (ip4->header_length != sizeof (struct GNUNET_TUN_IPv4Header) / 4) || | 1056 | (ip4->header_length != sizeof (struct GNUNET_TUN_IPv4Header) / 4) || |
1067 | (ntohs(ip4->total_length) != msize) || | 1057 | (ntohs(ip4->total_length) != msize) || |
1068 | (ip4->protocol != IPPROTO_UDP) ) | 1058 | (ip4->protocol != IPPROTO_UDP) ) |
@@ -1119,7 +1109,7 @@ process_helper_messages (void *cls GNUNET_UNUSED, void *client, | |||
1119 | 1109 | ||
1120 | /* setup new request */ | 1110 | /* setup new request */ |
1121 | rr->phase = RP_INIT; | 1111 | rr->phase = RP_INIT; |
1122 | if (ip4->version == IPVERSION) | 1112 | if (ip4->version == 4) |
1123 | { | 1113 | { |
1124 | srca4 = (struct sockaddr_in*) &rr->src_addr; | 1114 | srca4 = (struct sockaddr_in*) &rr->src_addr; |
1125 | dsta4 = (struct sockaddr_in*) &rr->dst_addr; | 1115 | dsta4 = (struct sockaddr_in*) &rr->dst_addr; |
diff --git a/src/exit/Makefile.am b/src/exit/Makefile.am index 736bb5fd3..5a047a13a 100644 --- a/src/exit/Makefile.am +++ b/src/exit/Makefile.am | |||
@@ -37,6 +37,7 @@ gnunet_daemon_exit_SOURCES = \ | |||
37 | gnunet_daemon_exit_LDADD = \ | 37 | gnunet_daemon_exit_LDADD = \ |
38 | $(top_builddir)/src/core/libgnunetcore.la \ | 38 | $(top_builddir)/src/core/libgnunetcore.la \ |
39 | $(top_builddir)/src/statistics/libgnunetstatistics.la \ | 39 | $(top_builddir)/src/statistics/libgnunetstatistics.la \ |
40 | $(top_builddir)/src/tun/libgnunettun.la \ | ||
40 | $(top_builddir)/src/util/libgnunetutil.la \ | 41 | $(top_builddir)/src/util/libgnunetutil.la \ |
41 | $(top_builddir)/src/mesh/libgnunetmesh.la \ | 42 | $(top_builddir)/src/mesh/libgnunetmesh.la \ |
42 | $(GN_LIBINTL) | 43 | $(GN_LIBINTL) |
diff --git a/src/exit/gnunet-daemon-exit.c b/src/exit/gnunet-daemon-exit.c index 7df72fb02..a4a0f967d 100644 --- a/src/exit/gnunet-daemon-exit.c +++ b/src/exit/gnunet-daemon-exit.c | |||
@@ -1065,21 +1065,11 @@ prepare_ipv4_packet (const void *payload, size_t payload_length, | |||
1065 | return; | 1065 | return; |
1066 | } | 1066 | } |
1067 | 1067 | ||
1068 | pkt4->version = 4; | 1068 | GNUNET_TUN_initialize_ipv4_header (pkt4, |
1069 | pkt4->header_length = sizeof (struct GNUNET_TUN_IPv4Header) / 4; | 1069 | protocol, |
1070 | pkt4->diff_serv = 0; | 1070 | len, |
1071 | pkt4->total_length = htons ((uint16_t) (sizeof (struct GNUNET_TUN_IPv4Header) + len)); | 1071 | &src_address->address.ipv4, |
1072 | pkt4->identification = (uint16_t) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, | 1072 | &dst_address->address.ipv4); |
1073 | UINT16_MAX + 1); | ||
1074 | pkt4->flags = 0; | ||
1075 | pkt4->fragmentation_offset = 0; | ||
1076 | pkt4->ttl = 255; | ||
1077 | pkt4->protocol = protocol; | ||
1078 | pkt4->checksum = 0; | ||
1079 | pkt4->destination_address = dst_address->address.ipv4; | ||
1080 | pkt4->source_address = src_address->address.ipv4; | ||
1081 | pkt4->checksum = GNUNET_CRYPTO_crc16_n (pkt4, sizeof (struct GNUNET_TUN_IPv4Header)); | ||
1082 | |||
1083 | switch (protocol) | 1073 | switch (protocol) |
1084 | { | 1074 | { |
1085 | case IPPROTO_UDP: | 1075 | case IPPROTO_UDP: |
diff --git a/src/include/gnunet_tun_lib.h b/src/include/gnunet_tun_lib.h index dc6f01e1e..ae16bc65f 100644 --- a/src/include/gnunet_tun_lib.h +++ b/src/include/gnunet_tun_lib.h | |||
@@ -148,4 +148,21 @@ struct GNUNET_TUN_DnsHeader | |||
148 | GNUNET_NETWORK_STRUCT_END | 148 | GNUNET_NETWORK_STRUCT_END |
149 | 149 | ||
150 | 150 | ||
151 | /** | ||
152 | * Initialize an IPv4 header. | ||
153 | * | ||
154 | * @param ip header to initialize | ||
155 | * @param protocol protocol to use (i.e. IPPROTO_UDP) | ||
156 | * @param payload_length number of bytes of payload that follow (excluding IPv4 header) | ||
157 | * @param src source IP address to use | ||
158 | * @param dst destination IP address to use | ||
159 | */ | ||
160 | void | ||
161 | GNUNET_TUN_initialize_ipv4_header (struct GNUNET_TUN_IPv4Header *ip, | ||
162 | uint8_t protocol, | ||
163 | uint16_t payload_length, | ||
164 | const struct in_addr *src, | ||
165 | const struct in_addr *dst); | ||
166 | |||
167 | |||
151 | #endif | 168 | #endif |
diff --git a/src/vpn/Makefile.am b/src/vpn/Makefile.am index bb0993c66..786f94d6a 100644 --- a/src/vpn/Makefile.am +++ b/src/vpn/Makefile.am | |||
@@ -40,6 +40,7 @@ gnunet_service_vpn_SOURCES = \ | |||
40 | gnunet-service-vpn.c | 40 | gnunet-service-vpn.c |
41 | gnunet_service_vpn_LDADD = \ | 41 | gnunet_service_vpn_LDADD = \ |
42 | $(top_builddir)/src/statistics/libgnunetstatistics.la \ | 42 | $(top_builddir)/src/statistics/libgnunetstatistics.la \ |
43 | $(top_builddir)/src/tun/libgnunettun.la \ | ||
43 | $(top_builddir)/src/util/libgnunetutil.la \ | 44 | $(top_builddir)/src/util/libgnunetutil.la \ |
44 | $(top_builddir)/src/mesh/libgnunetmesh.la \ | 45 | $(top_builddir)/src/mesh/libgnunetmesh.la \ |
45 | $(GN_LIBINTL) | 46 | $(GN_LIBINTL) |
diff --git a/src/vpn/gnunet-service-vpn.c b/src/vpn/gnunet-service-vpn.c index 7aeabf457..f0cdf6a3c 100644 --- a/src/vpn/gnunet-service-vpn.c +++ b/src/vpn/gnunet-service-vpn.c | |||
@@ -1422,23 +1422,11 @@ receive_udp_back (void *cls GNUNET_UNUSED, struct GNUNET_MESH_Tunnel *tunnel, | |||
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 | GNUNET_TUN_initialize_ipv4_header (ipv4, |
1426 | ipv4->header_length = sizeof (struct GNUNET_TUN_IPv4Header) / 4; | 1426 | IPPROTO_UDP, |
1427 | ipv4->diff_serv = 0; | 1427 | sizeof (struct GNUNET_TUN_UdpHeader) + mlen, |
1428 | ipv4->total_length = htons (sizeof (struct GNUNET_TUN_IPv4Header) + | 1428 | &ts->destination_ip.v4, |
1429 | sizeof (struct GNUNET_TUN_UdpHeader) + | 1429 | &ts->source_ip.v4); |
1430 | mlen); | ||
1431 | ipv4->identification = (uint16_t) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, | ||
1432 | UINT16_MAX + 1); | ||
1433 | ipv4->flags = 0; | ||
1434 | ipv4->fragmentation_offset = 0; | ||
1435 | ipv4->ttl = 255; | ||
1436 | ipv4->protocol = IPPROTO_UDP; | ||
1437 | ipv4->checksum = 0; | ||
1438 | ipv4->source_address = ts->destination_ip.v4; | ||
1439 | ipv4->destination_address = ts->source_ip.v4; | ||
1440 | ipv4->checksum = | ||
1441 | GNUNET_CRYPTO_crc16_n (ipv4, sizeof (struct GNUNET_TUN_IPv4Header)); | ||
1442 | if (0 == ntohs (reply->source_port)) | 1430 | if (0 == ntohs (reply->source_port)) |
1443 | udp->spt = htons (ts->destination_port); | 1431 | udp->spt = htons (ts->destination_port); |
1444 | else | 1432 | else |
@@ -1600,23 +1588,11 @@ receive_tcp_back (void *cls GNUNET_UNUSED, struct GNUNET_MESH_Tunnel *tunnel, | |||
1600 | msg->size = htons (size); | 1588 | msg->size = htons (size); |
1601 | tun->flags = htons (0); | 1589 | tun->flags = htons (0); |
1602 | tun->proto = htons (ETH_P_IPV4); | 1590 | tun->proto = htons (ETH_P_IPV4); |
1603 | ipv4->version = 4; | 1591 | GNUNET_TUN_initialize_ipv4_header (ipv4, |
1604 | ipv4->header_length = sizeof (struct GNUNET_TUN_IPv4Header) / 4; | 1592 | IPPROTO_TCP, |
1605 | ipv4->diff_serv = 0; | 1593 | sizeof (struct GNUNET_TUN_TcpHeader) + mlen, |
1606 | ipv4->total_length = htons (sizeof (struct GNUNET_TUN_IPv4Header) + | 1594 | &ts->destination_ip.v4, |
1607 | sizeof (struct GNUNET_TUN_TcpHeader) + | 1595 | &ts->source_ip.v4); |
1608 | mlen); | ||
1609 | ipv4->identification = (uint16_t) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, | ||
1610 | UINT16_MAX + 1); | ||
1611 | ipv4->flags = 0; | ||
1612 | ipv4->fragmentation_offset = 0; | ||
1613 | ipv4->ttl = 255; | ||
1614 | ipv4->protocol = IPPROTO_TCP; | ||
1615 | ipv4->checksum = 0; | ||
1616 | ipv4->source_address = ts->destination_ip.v4; | ||
1617 | ipv4->destination_address = ts->source_ip.v4; | ||
1618 | ipv4->checksum = | ||
1619 | GNUNET_CRYPTO_crc16_n (ipv4, sizeof (struct GNUNET_TUN_IPv4Header)); | ||
1620 | *tcp = data->tcp_header; | 1596 | *tcp = data->tcp_header; |
1621 | tcp->spt = htons (ts->destination_port); | 1597 | tcp->spt = htons (ts->destination_port); |
1622 | tcp->dpt = htons (ts->source_port); | 1598 | tcp->dpt = htons (ts->source_port); |