aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/dns/gnunet-service-dns.c17
-rw-r--r--src/exit/gnunet-daemon-exit.c11
-rw-r--r--src/include/gnunet_tun_lib.h17
-rw-r--r--src/tun/tun.c30
-rw-r--r--src/vpn/gnunet-service-vpn.c14
5 files changed, 62 insertions, 27 deletions
diff --git a/src/dns/gnunet-service-dns.c b/src/dns/gnunet-service-dns.c
index 5dc6641e7..288304600 100644
--- a/src/dns/gnunet-service-dns.c
+++ b/src/dns/gnunet-service-dns.c
@@ -419,18 +419,11 @@ request_done (struct RequestRecord *rr)
419 419
420 spt = dst->sin6_port; 420 spt = dst->sin6_port;
421 dpt = src->sin6_port; 421 dpt = src->sin6_port;
422 ip.traffic_class_h = 0; 422 GNUNET_TUN_initialize_ipv6_header (&ip,
423 ip.version = 6; /* is there a named constant? I couldn't find one */ 423 IPPROTO_UDP,
424 ip.traffic_class_l = 0; 424 reply_len - sizeof (struct GNUNET_TUN_IPv6Header),
425 ip.flow_label = 0; 425 &dst->sin6_addr,
426 ip.payload_length = htons ((uint16_t) reply_len); 426 &src->sin6_addr);
427 ip.next_header = IPPROTO_UDP;
428 ip.hop_limit = 255; /* or lower? */
429 ip.source_address = dst->sin6_addr;
430 ip.destination_address = src->sin6_addr;
431 udp_crc_sum = GNUNET_CRYPTO_crc16_step (udp_crc_sum,
432 &ip.source_address,
433 sizeof (struct in6_addr) * 2);
434 { 427 {
435 uint32_t tmp; 428 uint32_t tmp;
436 429
diff --git a/src/exit/gnunet-daemon-exit.c b/src/exit/gnunet-daemon-exit.c
index a4a0f967d..664a86f23 100644
--- a/src/exit/gnunet-daemon-exit.c
+++ b/src/exit/gnunet-daemon-exit.c
@@ -1159,12 +1159,11 @@ prepare_ipv6_packet (const void *payload, size_t payload_length,
1159 return; 1159 return;
1160 } 1160 }
1161 1161
1162 pkt6->version = 6; 1162 GNUNET_TUN_initialize_ipv6_header (pkt6,
1163 pkt6->next_header = protocol; 1163 protocol,
1164 pkt6->payload_length = htons ((uint16_t) (len + sizeof (struct GNUNET_TUN_IPv6Header))); 1164 len,
1165 pkt6->hop_limit = 255; 1165 &dst_address->address.ipv6,
1166 pkt6->destination_address = dst_address->address.ipv6; 1166 &src_address->address.ipv6);
1167 pkt6->source_address = src_address->address.ipv6;
1168 1167
1169 switch (protocol) 1168 switch (protocol)
1170 { 1169 {
diff --git a/src/include/gnunet_tun_lib.h b/src/include/gnunet_tun_lib.h
index ae16bc65f..89cfdd2b3 100644
--- a/src/include/gnunet_tun_lib.h
+++ b/src/include/gnunet_tun_lib.h
@@ -165,4 +165,21 @@ GNUNET_TUN_initialize_ipv4_header (struct GNUNET_TUN_IPv4Header *ip,
165 const struct in_addr *dst); 165 const struct in_addr *dst);
166 166
167 167
168/**
169 * Initialize an IPv6 header.
170 *
171 * @param ip header to initialize
172 * @param protocol protocol to use (i.e. IPPROTO_UDP)
173 * @param payload_length number of bytes of payload that follow (excluding IPv4 header)
174 * @param src source IP address to use
175 * @param dst destination IP address to use
176 */
177void
178GNUNET_TUN_initialize_ipv6_header (struct GNUNET_TUN_IPv6Header *ip,
179 uint8_t protocol,
180 uint16_t payload_length,
181 const struct in6_addr *src,
182 const struct in6_addr *dst);
183
184
168#endif 185#endif
diff --git a/src/tun/tun.c b/src/tun/tun.c
index 97b7a730e..005c7013d 100644
--- a/src/tun/tun.c
+++ b/src/tun/tun.c
@@ -48,6 +48,7 @@ GNUNET_TUN_initialize_ipv4_header (struct GNUNET_TUN_IPv4Header *ip,
48 const struct in_addr *src, 48 const struct in_addr *src,
49 const struct in_addr *dst) 49 const struct in_addr *dst)
50{ 50{
51 GNUNET_assert (payload_length <= UINT16_MAX - sizeof (struct GNUNET_TUN_IPv4Header));
51 ip->header_length = sizeof (struct GNUNET_TUN_IPv4Header) / 4; 52 ip->header_length = sizeof (struct GNUNET_TUN_IPv4Header) / 4;
52 ip->version = 4; 53 ip->version = 4;
53 ip->diff_serv = 0; 54 ip->diff_serv = 0;
@@ -65,5 +66,34 @@ GNUNET_TUN_initialize_ipv4_header (struct GNUNET_TUN_IPv4Header *ip,
65} 66}
66 67
67 68
69/**
70 * Initialize an IPv6 header.
71 *
72 * @param ip header to initialize
73 * @param protocol protocol to use (i.e. IPPROTO_UDP), technically "next_header" for IPv6
74 * @param payload_length number of bytes of payload that follow (excluding IPv4 header)
75 * @param src source IP address to use
76 * @param dst destination IP address to use
77 */
78void
79GNUNET_TUN_initialize_ipv6_header (struct GNUNET_TUN_IPv6Header *ip,
80 uint8_t protocol,
81 uint16_t payload_length,
82 const struct in6_addr *src,
83 const struct in6_addr *dst)
84{
85 GNUNET_assert (payload_length <= UINT16_MAX - sizeof (struct GNUNET_TUN_IPv6Header));
86 ip->traffic_class_h = 0;
87 ip->version = 6;
88 ip->traffic_class_l = 0;
89 ip->flow_label = 0;
90 ip->next_header = protocol;
91 ip->payload_length = htons ((uint16_t) (payload_length + sizeof (struct GNUNET_TUN_IPv6Header)));
92 ip->hop_limit = FRESH_TTL;
93 ip->destination_address = *dst;
94 ip->source_address = *src;
95}
96
97
68 98
69/* end of tun.c */ 99/* end of tun.c */
diff --git a/src/vpn/gnunet-service-vpn.c b/src/vpn/gnunet-service-vpn.c
index f0cdf6a3c..b352e216b 100644
--- a/src/vpn/gnunet-service-vpn.c
+++ b/src/vpn/gnunet-service-vpn.c
@@ -1636,15 +1636,11 @@ receive_tcp_back (void *cls GNUNET_UNUSED, struct GNUNET_MESH_Tunnel *tunnel,
1636 msg->size = htons (size); 1636 msg->size = htons (size);
1637 tun->flags = htons (0); 1637 tun->flags = htons (0);
1638 tun->proto = htons (ETH_P_IPV6); 1638 tun->proto = htons (ETH_P_IPV6);
1639 ipv6->traffic_class_h = 0; 1639 GNUNET_TUN_initialize_ipv6_header (ipv6,
1640 ipv6->version = 6; 1640 IPPROTO_TCP,
1641 ipv6->traffic_class_l = 0; 1641 sizeof (struct GNUNET_TUN_TcpHeader) + mlen,
1642 ipv6->flow_label = 0; 1642 &ts->destination_ip.v6,
1643 ipv6->payload_length = htons (sizeof (struct GNUNET_TUN_TcpHeader) + sizeof (struct GNUNET_TUN_IPv6Header) + mlen); 1643 &ts->source_ip.v6);
1644 ipv6->next_header = IPPROTO_TCP;
1645 ipv6->hop_limit = 255;
1646 ipv6->source_address = ts->destination_ip.v6;
1647 ipv6->destination_address = ts->source_ip.v6;
1648 tcp->spt = htons (ts->destination_port); 1644 tcp->spt = htons (ts->destination_port);
1649 tcp->dpt = htons (ts->source_port); 1645 tcp->dpt = htons (ts->source_port);
1650 tcp->crc = 0; 1646 tcp->crc = 0;