diff options
author | Christian Grothoff <christian@grothoff.org> | 2012-01-17 19:39:52 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2012-01-17 19:39:52 +0000 |
commit | a1d0953d72d75d3fa53a308dd19e1e1bec371b53 (patch) | |
tree | 7de9ae93ccde2ec4ccaf11b590d9ec5c339e26a6 /src | |
parent | e0d8c3f1c05ab0cb218d7182c723298f7e981b58 (diff) | |
download | gnunet-a1d0953d72d75d3fa53a308dd19e1e1bec371b53.tar.gz gnunet-a1d0953d72d75d3fa53a308dd19e1e1bec371b53.zip |
-move IPv6-TCP checksum calculation to tun library
Diffstat (limited to 'src')
-rw-r--r-- | src/exit/gnunet-daemon-exit.c | 16 | ||||
-rw-r--r-- | src/include/gnunet_tun_lib.h | 14 | ||||
-rw-r--r-- | src/tun/tun.c | 32 | ||||
-rw-r--r-- | src/vpn/gnunet-service-vpn.c | 18 |
4 files changed, 55 insertions, 25 deletions
diff --git a/src/exit/gnunet-daemon-exit.c b/src/exit/gnunet-daemon-exit.c index 664a86f23..482eaae7e 100644 --- a/src/exit/gnunet-daemon-exit.c +++ b/src/exit/gnunet-daemon-exit.c | |||
@@ -1091,6 +1091,7 @@ prepare_ipv4_packet (const void *payload, size_t payload_length, | |||
1091 | memcpy (&pkt4_tcp[1], payload, payload_length); | 1091 | memcpy (&pkt4_tcp[1], payload, payload_length); |
1092 | pkt4_tcp->spt = htons (src_address->port); | 1092 | pkt4_tcp->spt = htons (src_address->port); |
1093 | pkt4_tcp->dpt = htons (dst_address->port); | 1093 | pkt4_tcp->dpt = htons (dst_address->port); |
1094 | |||
1094 | pkt4_tcp->crc = 0; | 1095 | pkt4_tcp->crc = 0; |
1095 | uint32_t sum = 0; | 1096 | uint32_t sum = 0; |
1096 | sum = GNUNET_CRYPTO_crc16_step (sum, | 1097 | sum = GNUNET_CRYPTO_crc16_step (sum, |
@@ -1194,19 +1195,12 @@ prepare_ipv6_packet (const void *payload, size_t payload_length, | |||
1194 | struct GNUNET_TUN_TcpHeader *pkt6_tcp = (struct GNUNET_TUN_TcpHeader *) pkt6; | 1195 | struct GNUNET_TUN_TcpHeader *pkt6_tcp = (struct GNUNET_TUN_TcpHeader *) pkt6; |
1195 | 1196 | ||
1196 | memcpy (pkt6_tcp, payload, payload_length); | 1197 | memcpy (pkt6_tcp, payload, payload_length); |
1197 | pkt6_tcp->crc = 0; | ||
1198 | pkt6_tcp->spt = htons (src_address->port); | 1198 | pkt6_tcp->spt = htons (src_address->port); |
1199 | pkt6_tcp->dpt = htons (dst_address->port); | 1199 | pkt6_tcp->dpt = htons (dst_address->port); |
1200 | 1200 | GNUNET_TUN_calculate_tcp6_checksum (pkt6, | |
1201 | uint32_t sum = 0; | 1201 | pkt6_tcp, |
1202 | sum = GNUNET_CRYPTO_crc16_step (sum, &pkt6->source_address, | 1202 | payload, |
1203 | sizeof (struct in6_addr) * 2); | 1203 | payload_length); |
1204 | uint32_t tmp = htonl (len); | ||
1205 | sum = GNUNET_CRYPTO_crc16_step (sum, &tmp, sizeof (uint32_t)); | ||
1206 | tmp = htonl (pkt6->next_header); | ||
1207 | sum = GNUNET_CRYPTO_crc16_step (sum, &tmp, sizeof (uint32_t)); | ||
1208 | sum = GNUNET_CRYPTO_crc16_step (sum, pkt6_tcp, len); | ||
1209 | pkt6_tcp->crc = GNUNET_CRYPTO_crc16_finish (sum); | ||
1210 | } | 1204 | } |
1211 | break; | 1205 | break; |
1212 | default: | 1206 | default: |
diff --git a/src/include/gnunet_tun_lib.h b/src/include/gnunet_tun_lib.h index 89cfdd2b3..b30b2b03a 100644 --- a/src/include/gnunet_tun_lib.h +++ b/src/include/gnunet_tun_lib.h | |||
@@ -181,5 +181,19 @@ GNUNET_TUN_initialize_ipv6_header (struct GNUNET_TUN_IPv6Header *ip, | |||
181 | const struct in6_addr *src, | 181 | const struct in6_addr *src, |
182 | const struct in6_addr *dst); | 182 | const struct in6_addr *dst); |
183 | 183 | ||
184 | /** | ||
185 | * Calculate IPv6 TCP checksum. | ||
186 | * | ||
187 | * @param ipv6 header fully initialized | ||
188 | * @param tcp header (initialized except for CRC) | ||
189 | * @param payload the TCP payload | ||
190 | * @param payload_length number of bytes of TCP payload | ||
191 | */ | ||
192 | void | ||
193 | GNUNET_TUN_calculate_tcp6_checksum (const struct GNUNET_TUN_IPv6Header *ip, | ||
194 | struct GNUNET_TUN_TcpHeader *tcp, | ||
195 | const void *payload, | ||
196 | uint16_t payload_length); | ||
197 | |||
184 | 198 | ||
185 | #endif | 199 | #endif |
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 | */ | ||
106 | void | ||
107 | GNUNET_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 */ |
diff --git a/src/vpn/gnunet-service-vpn.c b/src/vpn/gnunet-service-vpn.c index b352e216b..0d236975e 100644 --- a/src/vpn/gnunet-service-vpn.c +++ b/src/vpn/gnunet-service-vpn.c | |||
@@ -1643,20 +1643,10 @@ receive_tcp_back (void *cls GNUNET_UNUSED, struct GNUNET_MESH_Tunnel *tunnel, | |||
1643 | &ts->source_ip.v6); | 1643 | &ts->source_ip.v6); |
1644 | tcp->spt = htons (ts->destination_port); | 1644 | tcp->spt = htons (ts->destination_port); |
1645 | tcp->dpt = htons (ts->source_port); | 1645 | tcp->dpt = htons (ts->source_port); |
1646 | tcp->crc = 0; | 1646 | GNUNET_TUN_calculate_tcp6_checksum (ipv6, |
1647 | { | 1647 | tcp, |
1648 | uint32_t sum = 0; | 1648 | &tcp[1], |
1649 | uint32_t tmp; | 1649 | mlen); |
1650 | |||
1651 | sum = GNUNET_CRYPTO_crc16_step (sum, &ipv6->source_address, 2 * sizeof (struct in6_addr)); | ||
1652 | tmp = htonl (sizeof (struct GNUNET_TUN_TcpHeader) + mlen); | ||
1653 | sum = GNUNET_CRYPTO_crc16_step (sum, &tmp, sizeof (uint32_t)); | ||
1654 | tmp = htonl (IPPROTO_TCP); | ||
1655 | sum = GNUNET_CRYPTO_crc16_step (sum, &tmp, sizeof (uint32_t)); | ||
1656 | sum = GNUNET_CRYPTO_crc16_step (sum, tcp, | ||
1657 | sizeof (struct GNUNET_TUN_TcpHeader) + mlen); | ||
1658 | tcp->crc = GNUNET_CRYPTO_crc16_finish (sum); | ||
1659 | } | ||
1660 | (void) GNUNET_HELPER_send (helper_handle, | 1650 | (void) GNUNET_HELPER_send (helper_handle, |
1661 | msg, | 1651 | msg, |
1662 | GNUNET_YES, | 1652 | GNUNET_YES, |