summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLorenzo Colitti <lorenzo@google.com>2014-03-08 20:30:03 +0000
committerLorenzo Colitti <lorenzo@google.com>2014-03-08 20:30:03 +0000
commit09c026be0c23e3ab8086603a73c5ec5ff2af92b5 (patch)
tree5c362380f3ff1c02afd0bac9d1fc2b6ea16d205f
parentfea4efa398ff9c86c300f0c1be92611d1d1fd5ba (diff)
downloadandroid_external_android-clat-09c026be0c23e3ab8086603a73c5ec5ff2af92b5.tar.gz
android_external_android-clat-09c026be0c23e3ab8086603a73c5ec5ff2af92b5.tar.bz2
android_external_android-clat-09c026be0c23e3ab8086603a73c5ec5ff2af92b5.zip
Revert "DO NOT MERGE: Modify the pseudo-header checksum functions."
This reverts commit fea4efa398ff9c86c300f0c1be92611d1d1fd5ba. Change-Id: If8199246b3f921e862a5e5ca587d5120906946e0
-rw-r--r--checksum.c16
-rw-r--r--checksum.h4
-rw-r--r--dump.c8
-rw-r--r--ipv4.c4
-rw-r--r--ipv6.c4
5 files changed, 18 insertions, 18 deletions
diff --git a/checksum.c b/checksum.c
index 3dd1e00..099be6a 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
- * 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
+ * current - the current checksum or 0 to start a new checksum
+ * ip6 - the ipv6 header
+ * len - the transport length (transport header + payload)
*/
-uint32_t ipv6_pseudo_header_checksum(const struct ip6_hdr *ip6, uint16_t len, uint8_t protocol) {
+uint32_t ipv6_pseudo_header_checksum(uint32_t current, const struct ip6_hdr *ip6, uint16_t len) {
uint32_t checksum_len, checksum_next;
+
checksum_len = htonl((uint32_t) len);
- checksum_next = htonl(protocol);
+ checksum_next = htonl(ip6->ip6_nxt);
- 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(const struct ip6_hdr *ip6, uint16_t len, ui
/* 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(const struct iphdr *ip, uint16_t len) {
+uint32_t ipv4_pseudo_header_checksum(uint32_t current, 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));
diff --git a/checksum.h b/checksum.h
index 6195810..44921f0 100644
--- a/checksum.h
+++ b/checksum.h
@@ -22,8 +22,8 @@ uint32_t ip_checksum_add(uint32_t current, const void *data, int len);
uint16_t ip_checksum_finish(uint32_t temp_sum);
uint16_t ip_checksum(const void *data, int len);
-uint32_t ipv6_pseudo_header_checksum(const struct ip6_hdr *ip6, uint16_t len, uint8_t protocol);
-uint32_t ipv4_pseudo_header_checksum(const struct iphdr *ip, uint16_t len);
+uint32_t ipv6_pseudo_header_checksum(uint32_t current, const struct ip6_hdr *ip6, uint16_t len);
+uint32_t ipv4_pseudo_header_checksum(uint32_t current, const struct iphdr *ip, uint16_t len);
uint16_t ip_checksum_adjust(uint16_t checksum, uint32_t old_hdr_sum, uint32_t new_hdr_sum);
diff --git a/dump.c b/dump.c
index 94e4796..8567655 100644
--- a/dump.c
+++ b/dump.c
@@ -147,14 +147,14 @@ void dump_udp_generic(const struct udphdr *udp, uint32_t temp_checksum, const ch
/* print ipv4/udp header */
void dump_udp(const struct udphdr *udp, const struct iphdr *ip, const char *payload, size_t payload_size) {
uint32_t temp_checksum;
- temp_checksum = ipv4_pseudo_header_checksum(ip, sizeof(*udp) + payload_size);
+ temp_checksum = ipv4_pseudo_header_checksum(0, ip, sizeof(*udp) + payload_size);
dump_udp_generic(udp, temp_checksum, payload, payload_size);
}
/* print ipv6/udp header */
void dump_udp6(const struct udphdr *udp, const struct ip6_hdr *ip6, const char *payload, size_t payload_size) {
uint32_t temp_checksum;
- temp_checksum = ipv6_pseudo_header_checksum(ip6, sizeof(*udp) + payload_size, IPPROTO_UDP);
+ temp_checksum = ipv6_pseudo_header_checksum(0, ip6, sizeof(*udp) + payload_size);
dump_udp_generic(udp, temp_checksum, payload, payload_size);
}
@@ -203,7 +203,7 @@ void dump_tcp_generic(const struct tcphdr *tcp, const char *options, size_t opti
void dump_tcp(const struct tcphdr *tcp, const struct iphdr *ip, const char *payload, size_t payload_size, const char *options, size_t options_size) {
uint32_t temp_checksum;
- temp_checksum = ipv4_pseudo_header_checksum(ip, sizeof(*tcp) + options_size + payload_size);
+ temp_checksum = ipv4_pseudo_header_checksum(0, ip, sizeof(*tcp) + options_size + payload_size);
dump_tcp_generic(tcp, options, options_size, temp_checksum, payload, payload_size);
}
@@ -211,7 +211,7 @@ void dump_tcp(const struct tcphdr *tcp, const struct iphdr *ip, const char *payl
void dump_tcp6(const struct tcphdr *tcp, const struct ip6_hdr *ip6, const char *payload, size_t payload_size, const char *options, size_t options_size) {
uint32_t temp_checksum;
- temp_checksum = ipv6_pseudo_header_checksum(ip6, sizeof(*tcp) + options_size + payload_size, IPPROTO_TCP);
+ temp_checksum = ipv6_pseudo_header_checksum(0, ip6, sizeof(*tcp) + options_size + payload_size);
dump_tcp_generic(tcp, options, options_size, temp_checksum, payload, payload_size);
}
diff --git a/ipv4.c b/ipv4.c
index e2636b4..c828ffa 100644
--- a/ipv4.c
+++ b/ipv4.c
@@ -112,8 +112,8 @@ int ipv4_packet(clat_packet out, int pos, const char *packet, size_t len) {
out[pos].iov_len = sizeof(struct ip6_hdr);
// Calculate the pseudo-header checksum.
- old_sum = ipv4_pseudo_header_checksum(header, len_left);
- new_sum = ipv6_pseudo_header_checksum(ip6_targ, len_left, nxthdr);
+ old_sum = ipv4_pseudo_header_checksum(0, header, len_left);
+ new_sum = ipv6_pseudo_header_checksum(0, ip6_targ, len_left);
if (nxthdr == IPPROTO_ICMPV6) {
iov_len = icmp_packet(out, pos + 1, (const struct icmphdr *) next_header, new_sum, len_left);
diff --git a/ipv6.c b/ipv6.c
index d188e47..371d9e1 100644
--- a/ipv6.c
+++ b/ipv6.c
@@ -125,8 +125,8 @@ int ipv6_packet(clat_packet out, int pos, const char *packet, size_t len) {
out[pos].iov_len = sizeof(struct iphdr);
// Calculate the pseudo-header checksum.
- old_sum = ipv6_pseudo_header_checksum(ip6, len_left, protocol);
- new_sum = ipv4_pseudo_header_checksum(ip_targ, len_left);
+ old_sum = ipv6_pseudo_header_checksum(0, ip6, len_left);
+ new_sum = ipv4_pseudo_header_checksum(0, ip_targ, len_left);
// does not support IPv6 extension headers, this will drop any packet with them
if (protocol == IPPROTO_ICMP) {