aboutsummaryrefslogtreecommitdiff
path: root/helper
diff options
context:
space:
mode:
authorMaxim Uvarov <maxim.uvarov@linaro.org>2015-12-07 14:35:35 +0300
committerMaxim Uvarov <maxim.uvarov@linaro.org>2015-12-07 14:43:18 +0300
commit6b57d13c75444a82b947d6cc26668c5ab3176cfb (patch)
treeeca4fe637626d2e1c3ab6beda3b3831d8373eba2 /helper
parent78b7f37a1ae30dd85f7b13492bbe402a591fae60 (diff)
Revert "helper : Fix UDP checksum computation"
This reverts commit 0043ff8f7dd86a0c1e143412ceb5a14c8ae9c727. Validation helper test fails. Revert root cause commit. Signed-off-by: Maxim Uvarov <maxim.uvarov@linaro.org>
Diffstat (limited to 'helper')
-rw-r--r--helper/include/odp/helper/udp.h32
1 files changed, 19 insertions, 13 deletions
diff --git a/helper/include/odp/helper/udp.h b/helper/include/odp/helper/udp.h
index 6fce3f21d..06c439b4b 100644
--- a/helper/include/odp/helper/udp.h
+++ b/helper/include/odp/helper/udp.h
@@ -44,16 +44,20 @@ typedef struct ODP_PACKED {
* This function uses odp packet to calc checksum
*
* @param pkt calculate chksum for pkt
- * @return checksum value in CPU endianness
+ * @return checksum value
*/
static inline uint16_t odph_ipv4_udp_chksum(odp_packet_t pkt)
{
- uint32_t sum;
+ uint32_t sum = 0;
odph_udphdr_t *udph;
odph_ipv4hdr_t *iph;
- uint16_t udplen, *buf;
+ uint16_t udplen;
+ uint8_t *buf;
- if (odp_packet_l4_offset(pkt) == ODP_PACKET_OFFSET_INVALID)
+ if (!odp_packet_l3_offset(pkt))
+ return 0;
+
+ if (!odp_packet_l4_offset(pkt))
return 0;
iph = (odph_ipv4hdr_t *)odp_packet_l3_ptr(pkt, NULL);
@@ -63,21 +67,23 @@ static inline uint16_t odph_ipv4_udp_chksum(odp_packet_t pkt)
/* 32-bit sum of all 16-bit words covered by UDP chksum */
sum = (iph->src_addr & 0xFFFF) + (iph->src_addr >> 16) +
(iph->dst_addr & 0xFFFF) + (iph->dst_addr >> 16) +
- odp_be_to_cpu_16(iph->proto) + udph->length;
- for (buf = (uint16_t *)((void *)udph); udplen > 1; udplen -= 2)
- sum += *buf++;
- if (udplen) /* If length is not a multiple of 2 bytes */
- sum += odp_be_to_cpu_16(*((uint8_t *)buf) << 8);
+ (uint16_t)iph->proto + udplen;
+ for (buf = (uint8_t *)udph; udplen > 1; udplen -= 2) {
+ sum += ((*buf << 8) + *(buf + 1));
+ buf += 2;
+ }
/* Fold sum to 16 bits: add carrier to result */
- sum = (sum & 0xFFFF) + (sum >> 16);
- sum += (sum >> 16);
+ while (sum >> 16)
+ sum = (sum & 0xFFFF) + (sum >> 16);
/* 1's complement */
sum = ~sum;
- /* set computation result in CPU endianness*/
- return (sum == 0x0) ? 0xFFFF : odp_be_to_cpu_16(sum);
+ /* set computation result */
+ sum = (sum == 0x0) ? 0xFFFF : sum;
+
+ return sum;
}
/** @internal Compile time assert */