aboutsummaryrefslogtreecommitdiff
path: root/src/tun
diff options
context:
space:
mode:
authorgrothoff <grothoff@140774ce-b5e7-0310-ab8b-a85725594a96>2012-01-17 19:39:52 +0000
committergrothoff <grothoff@140774ce-b5e7-0310-ab8b-a85725594a96>2012-01-17 19:39:52 +0000
commitbf8b298c753f2dcd202939380b58aedf2b0fc05b (patch)
tree7de9ae93ccde2ec4ccaf11b590d9ec5c339e26a6 /src/tun
parent54b312343894bbd7ad76e9b0498f0782d72287b4 (diff)
-move IPv6-TCP checksum calculation to tun library
git-svn-id: https://gnunet.org/svn/gnunet@19216 140774ce-b5e7-0310-ab8b-a85725594a96
Diffstat (limited to 'src/tun')
-rw-r--r--src/tun/tun.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/src/tun/tun.c b/src/tun/tun.c
index 005c7013dd..c30861cce8 100644
--- a/src/tun/tun.c
+++ b/src/tun/tun.c
@@ -95,5 +95,37 @@ GNUNET_TUN_initialize_ipv6_header (struct GNUNET_TUN_IPv6Header *ip,
}
+/**
+ * Calculate IPv6 TCP checksum.
+ *
+ * @param ipv6 header fully initialized
+ * @param tcp header (initialized except for CRC)
+ * @param payload the TCP payload
+ * @param payload_length number of bytes of TCP payload
+ */
+void
+GNUNET_TUN_calculate_tcp6_checksum (const struct GNUNET_TUN_IPv6Header *ip,
+ struct GNUNET_TUN_TcpHeader *tcp,
+ const void *payload,
+ uint16_t payload_length)
+{
+ uint32_t sum;
+ uint32_t tmp;
+
+ GNUNET_assert (payload_length + sizeof (struct GNUNET_TUN_IPv6Header) + sizeof (struct GNUNET_TUN_TcpHeader) ==
+ ntohs (ip->payload_length));
+ tcp->crc = 0;
+ sum = GNUNET_CRYPTO_crc16_step (0, &ip->source_address, 2 * sizeof (struct in6_addr));
+ tmp = htonl (sizeof (struct GNUNET_TUN_TcpHeader) + payload_length);
+ sum = GNUNET_CRYPTO_crc16_step (sum, &tmp, sizeof (uint32_t));
+ tmp = htonl (IPPROTO_TCP);
+ sum = GNUNET_CRYPTO_crc16_step (sum, &tmp, sizeof (uint32_t));
+ sum = GNUNET_CRYPTO_crc16_step (sum, tcp,
+ sizeof (struct GNUNET_TUN_TcpHeader));
+ sum = GNUNET_CRYPTO_crc16_step (sum, payload, payload_length);
+ tcp->crc = GNUNET_CRYPTO_crc16_finish (sum);
+}
+
+
/* end of tun.c */