aboutsummaryrefslogtreecommitdiff
path: root/src/tun
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2012-01-17 19:39:52 +0000
committerChristian Grothoff <christian@grothoff.org>2012-01-17 19:39:52 +0000
commita1d0953d72d75d3fa53a308dd19e1e1bec371b53 (patch)
tree7de9ae93ccde2ec4ccaf11b590d9ec5c339e26a6 /src/tun
parente0d8c3f1c05ab0cb218d7182c723298f7e981b58 (diff)
downloadgnunet-a1d0953d72d75d3fa53a308dd19e1e1bec371b53.tar.gz
gnunet-a1d0953d72d75d3fa53a308dd19e1e1bec371b53.zip
-move IPv6-TCP checksum calculation to tun library
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 005c7013d..c30861cce 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,
95} 95}
96 96
97 97
98/**
99 * Calculate IPv6 TCP checksum.
100 *
101 * @param ipv6 header fully initialized
102 * @param tcp header (initialized except for CRC)
103 * @param payload the TCP payload
104 * @param payload_length number of bytes of TCP payload
105 */
106void
107GNUNET_TUN_calculate_tcp6_checksum (const struct GNUNET_TUN_IPv6Header *ip,
108 struct GNUNET_TUN_TcpHeader *tcp,
109 const void *payload,
110 uint16_t payload_length)
111{
112 uint32_t sum;
113 uint32_t tmp;
114
115 GNUNET_assert (payload_length + sizeof (struct GNUNET_TUN_IPv6Header) + sizeof (struct GNUNET_TUN_TcpHeader) ==
116 ntohs (ip->payload_length));
117 tcp->crc = 0;
118 sum = GNUNET_CRYPTO_crc16_step (0, &ip->source_address, 2 * sizeof (struct in6_addr));
119 tmp = htonl (sizeof (struct GNUNET_TUN_TcpHeader) + payload_length);
120 sum = GNUNET_CRYPTO_crc16_step (sum, &tmp, sizeof (uint32_t));
121 tmp = htonl (IPPROTO_TCP);
122 sum = GNUNET_CRYPTO_crc16_step (sum, &tmp, sizeof (uint32_t));
123 sum = GNUNET_CRYPTO_crc16_step (sum, tcp,
124 sizeof (struct GNUNET_TUN_TcpHeader));
125 sum = GNUNET_CRYPTO_crc16_step (sum, payload, payload_length);
126 tcp->crc = GNUNET_CRYPTO_crc16_finish (sum);
127}
128
129
98 130
99/* end of tun.c */ 131/* end of tun.c */