[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r19215 - in gnunet/src: dns exit include tun vpn
From: |
gnunet |
Subject: |
[GNUnet-SVN] r19215 - in gnunet/src: dns exit include tun vpn |
Date: |
Tue, 17 Jan 2012 20:30:12 +0100 |
Author: grothoff
Date: 2012-01-17 20:30:12 +0100 (Tue, 17 Jan 2012)
New Revision: 19215
Modified:
gnunet/src/dns/gnunet-service-dns.c
gnunet/src/exit/gnunet-daemon-exit.c
gnunet/src/include/gnunet_tun_lib.h
gnunet/src/tun/tun.c
gnunet/src/vpn/gnunet-service-vpn.c
Log:
-move IPv6 header initialization to tun library
Modified: gnunet/src/dns/gnunet-service-dns.c
===================================================================
--- gnunet/src/dns/gnunet-service-dns.c 2012-01-17 19:23:18 UTC (rev 19214)
+++ gnunet/src/dns/gnunet-service-dns.c 2012-01-17 19:30:12 UTC (rev 19215)
@@ -419,18 +419,11 @@
spt = dst->sin6_port;
dpt = src->sin6_port;
- ip.traffic_class_h = 0;
- ip.version = 6; /* is there a named constant? I couldn't find one */
- ip.traffic_class_l = 0;
- ip.flow_label = 0;
- ip.payload_length = htons ((uint16_t) reply_len);
- ip.next_header = IPPROTO_UDP;
- ip.hop_limit = 255; /* or lower? */
- ip.source_address = dst->sin6_addr;
- ip.destination_address = src->sin6_addr;
- udp_crc_sum = GNUNET_CRYPTO_crc16_step (udp_crc_sum,
- &ip.source_address,
- sizeof (struct in6_addr) * 2);
+ GNUNET_TUN_initialize_ipv6_header (&ip,
+ IPPROTO_UDP,
+ reply_len - sizeof (struct
GNUNET_TUN_IPv6Header),
+ &dst->sin6_addr,
+ &src->sin6_addr);
{
uint32_t tmp;
Modified: gnunet/src/exit/gnunet-daemon-exit.c
===================================================================
--- gnunet/src/exit/gnunet-daemon-exit.c 2012-01-17 19:23:18 UTC (rev
19214)
+++ gnunet/src/exit/gnunet-daemon-exit.c 2012-01-17 19:30:12 UTC (rev
19215)
@@ -1159,12 +1159,11 @@
return;
}
- pkt6->version = 6;
- pkt6->next_header = protocol;
- pkt6->payload_length = htons ((uint16_t) (len + sizeof (struct
GNUNET_TUN_IPv6Header)));
- pkt6->hop_limit = 255;
- pkt6->destination_address = dst_address->address.ipv6;
- pkt6->source_address = src_address->address.ipv6;
+ GNUNET_TUN_initialize_ipv6_header (pkt6,
+ protocol,
+ len,
+ &dst_address->address.ipv6,
+ &src_address->address.ipv6);
switch (protocol)
{
Modified: gnunet/src/include/gnunet_tun_lib.h
===================================================================
--- gnunet/src/include/gnunet_tun_lib.h 2012-01-17 19:23:18 UTC (rev 19214)
+++ gnunet/src/include/gnunet_tun_lib.h 2012-01-17 19:30:12 UTC (rev 19215)
@@ -165,4 +165,21 @@
const struct in_addr *dst);
+/**
+ * Initialize an IPv6 header.
+ *
+ * @param ip header to initialize
+ * @param protocol protocol to use (i.e. IPPROTO_UDP)
+ * @param payload_length number of bytes of payload that follow (excluding
IPv4 header)
+ * @param src source IP address to use
+ * @param dst destination IP address to use
+ */
+void
+GNUNET_TUN_initialize_ipv6_header (struct GNUNET_TUN_IPv6Header *ip,
+ uint8_t protocol,
+ uint16_t payload_length,
+ const struct in6_addr *src,
+ const struct in6_addr *dst);
+
+
#endif
Modified: gnunet/src/tun/tun.c
===================================================================
--- gnunet/src/tun/tun.c 2012-01-17 19:23:18 UTC (rev 19214)
+++ gnunet/src/tun/tun.c 2012-01-17 19:30:12 UTC (rev 19215)
@@ -48,6 +48,7 @@
const struct in_addr *src,
const struct in_addr *dst)
{
+ GNUNET_assert (payload_length <= UINT16_MAX - sizeof (struct
GNUNET_TUN_IPv4Header));
ip->header_length = sizeof (struct GNUNET_TUN_IPv4Header) / 4;
ip->version = 4;
ip->diff_serv = 0;
@@ -65,5 +66,34 @@
}
+/**
+ * Initialize an IPv6 header.
+ *
+ * @param ip header to initialize
+ * @param protocol protocol to use (i.e. IPPROTO_UDP), technically
"next_header" for IPv6
+ * @param payload_length number of bytes of payload that follow (excluding
IPv4 header)
+ * @param src source IP address to use
+ * @param dst destination IP address to use
+ */
+void
+GNUNET_TUN_initialize_ipv6_header (struct GNUNET_TUN_IPv6Header *ip,
+ uint8_t protocol,
+ uint16_t payload_length,
+ const struct in6_addr *src,
+ const struct in6_addr *dst)
+{
+ GNUNET_assert (payload_length <= UINT16_MAX - sizeof (struct
GNUNET_TUN_IPv6Header));
+ ip->traffic_class_h = 0;
+ ip->version = 6;
+ ip->traffic_class_l = 0;
+ ip->flow_label = 0;
+ ip->next_header = protocol;
+ ip->payload_length = htons ((uint16_t) (payload_length + sizeof (struct
GNUNET_TUN_IPv6Header)));
+ ip->hop_limit = FRESH_TTL;
+ ip->destination_address = *dst;
+ ip->source_address = *src;
+}
+
+
/* end of tun.c */
Modified: gnunet/src/vpn/gnunet-service-vpn.c
===================================================================
--- gnunet/src/vpn/gnunet-service-vpn.c 2012-01-17 19:23:18 UTC (rev 19214)
+++ gnunet/src/vpn/gnunet-service-vpn.c 2012-01-17 19:30:12 UTC (rev 19215)
@@ -1636,15 +1636,11 @@
msg->size = htons (size);
tun->flags = htons (0);
tun->proto = htons (ETH_P_IPV6);
- ipv6->traffic_class_h = 0;
- ipv6->version = 6;
- ipv6->traffic_class_l = 0;
- ipv6->flow_label = 0;
- ipv6->payload_length = htons (sizeof (struct GNUNET_TUN_TcpHeader) +
sizeof (struct GNUNET_TUN_IPv6Header) + mlen);
- ipv6->next_header = IPPROTO_TCP;
- ipv6->hop_limit = 255;
- ipv6->source_address = ts->destination_ip.v6;
- ipv6->destination_address = ts->source_ip.v6;
+ GNUNET_TUN_initialize_ipv6_header (ipv6,
+ IPPROTO_TCP,
+ sizeof (struct GNUNET_TUN_TcpHeader)
+ mlen,
+ &ts->destination_ip.v6,
+ &ts->source_ip.v6);
tcp->spt = htons (ts->destination_port);
tcp->dpt = htons (ts->source_port);
tcp->crc = 0;
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r19215 - in gnunet/src: dns exit include tun vpn,
gnunet <=