summaryrefslogtreecommitdiffstats
path: root/checksum.c
diff options
context:
space:
mode:
authorLorenzo Colitti <lorenzo@google.com>2014-02-20 14:28:43 +0900
committerLorenzo Colitti <lorenzo@google.com>2014-02-22 12:46:06 +0900
commit07f0265830fcae2632159e9993b93a161d7ea23b (patch)
tree04699deb1961d1ca61261da7af83d1be29755a14 /checksum.c
parentfbef82d10366495bbd0dbb30cea015cb67c8105a (diff)
downloadandroid_external_android-clat-07f0265830fcae2632159e9993b93a161d7ea23b.tar.gz
android_external_android-clat-07f0265830fcae2632159e9993b93a161d7ea23b.tar.bz2
android_external_android-clat-07f0265830fcae2632159e9993b93a161d7ea23b.zip
Modify the pseudo-header checksum functions.
- Remove the initial checksum, which we don't use anywhere. - Add the upper-layer protocol to the IPv6 function. Currently this is always the same as the next header field in the IPv6 header, but technically it's the upper-layer header after all the extension headers. This is required to support fragments. Bug: 11542311 Change-Id: Ie1a20fa74ee5bc933c1014bab74ae2957979b2b8
Diffstat (limited to 'checksum.c')
-rw-r--r--checksum.c16
1 files changed, 8 insertions, 8 deletions
diff --git a/checksum.c b/checksum.c
index 099be6a..3dd1e00 100644
--- a/checksum.c
+++ b/checksum.c
@@ -84,16 +84,16 @@ uint16_t ip_checksum(const void *data, int len) {
/* function: ipv6_pseudo_header_checksum
* calculate the pseudo header checksum for use in tcp/udp/icmp headers
- * current - the current checksum or 0 to start a new checksum
- * ip6 - the ipv6 header
- * len - the transport length (transport header + payload)
+ * ip6 - the ipv6 header
+ * len - the transport length (transport header + payload)
+ * protocol - the transport layer protocol, can be different from ip6->ip6_nxt for fragments
*/
-uint32_t ipv6_pseudo_header_checksum(uint32_t current, const struct ip6_hdr *ip6, uint16_t len) {
+uint32_t ipv6_pseudo_header_checksum(const struct ip6_hdr *ip6, uint16_t len, uint8_t protocol) {
uint32_t checksum_len, checksum_next;
-
checksum_len = htonl((uint32_t) len);
- checksum_next = htonl(ip6->ip6_nxt);
+ checksum_next = htonl(protocol);
+ uint32_t current = 0;
current = ip_checksum_add(current, &(ip6->ip6_src), sizeof(struct in6_addr));
current = ip_checksum_add(current, &(ip6->ip6_dst), sizeof(struct in6_addr));
current = ip_checksum_add(current, &checksum_len, sizeof(checksum_len));
@@ -104,16 +104,16 @@ uint32_t ipv6_pseudo_header_checksum(uint32_t current, const struct ip6_hdr *ip6
/* function: ipv4_pseudo_header_checksum
* calculate the pseudo header checksum for use in tcp/udp headers
- * current - the current checksum or 0 to start a new checksum
* ip - the ipv4 header
* len - the transport length (transport header + payload)
*/
-uint32_t ipv4_pseudo_header_checksum(uint32_t current, const struct iphdr *ip, uint16_t len) {
+uint32_t ipv4_pseudo_header_checksum(const struct iphdr *ip, uint16_t len) {
uint16_t temp_protocol, temp_length;
temp_protocol = htons(ip->protocol);
temp_length = htons(len);
+ uint32_t current = 0;
current = ip_checksum_add(current, &(ip->saddr), sizeof(uint32_t));
current = ip_checksum_add(current, &(ip->daddr), sizeof(uint32_t));
current = ip_checksum_add(current, &temp_protocol, sizeof(uint16_t));