From: Olivier Matz Date: Tue, 23 Oct 2018 08:49:44 +0000 (+0200) Subject: net: take ip options in account when computing checksum X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=96a6978ef6814e1450e1bd65fbce91c3d85b3121;p=dpdk.git net: take ip options in account when computing checksum Signed-off-by: Olivier Matz --- diff --git a/lib/librte_net/rte_ip.h b/lib/librte_net/rte_ip.h index f2a8904a2a..ef671c5bcb 100644 --- a/lib/librte_net/rte_ip.h +++ b/lib/librte_net/rte_ip.h @@ -244,7 +244,7 @@ rte_raw_cksum_mbuf(const struct rte_mbuf *m, uint32_t off, uint32_t len, * The checksum field must be set to 0 by the caller. * * @param ipv4_hdr - * The pointer to the contiguous IPv4 header. + * The pointer to the contiguous IPv4 header, that may contain options. * @return * The complemented checksum to set in the IP packet. */ @@ -252,7 +252,7 @@ static inline uint16_t rte_ipv4_cksum(const struct ipv4_hdr *ipv4_hdr) { uint16_t cksum; - cksum = rte_raw_cksum(ipv4_hdr, sizeof(struct ipv4_hdr)); + cksum = rte_raw_cksum(ipv4_hdr, (ipv4_hdr->version_ihl & 0xf) * 4); return (cksum == 0xffff) ? cksum : (uint16_t)~cksum; } @@ -268,7 +268,7 @@ rte_ipv4_cksum(const struct ipv4_hdr *ipv4_hdr) * When ol_flags is 0, it computes the standard pseudo-header checksum. * * @param ipv4_hdr - * The pointer to the contiguous IPv4 header. + * The pointer to the contiguous IPv4 header, that may contain options. * @param ol_flags * The ol_flags of the associated mbuf. * @return @@ -292,9 +292,9 @@ rte_ipv4_phdr_cksum(const struct ipv4_hdr *ipv4_hdr, uint64_t ol_flags) if (ol_flags & PKT_TX_TCP_SEG) { psd_hdr.len = 0; } else { - psd_hdr.len = rte_cpu_to_be_16( - (uint16_t)(rte_be_to_cpu_16(ipv4_hdr->total_length) - - sizeof(struct ipv4_hdr))); + uint16_t l4_len = rte_be_to_cpu_16(ipv4_hdr->total_length) - + (ipv4_hdr->version_ihl & 0xf) * 4; + psd_hdr.len = rte_cpu_to_be_16(l4_len); } return rte_raw_cksum(&psd_hdr, sizeof(psd_hdr)); } @@ -306,7 +306,7 @@ rte_ipv4_phdr_cksum(const struct ipv4_hdr *ipv4_hdr, uint64_t ol_flags) * checksum must be set to 0 in the packet by the caller. * * @param ipv4_hdr - * The pointer to the contiguous IPv4 header. + * The pointer to the contiguous IPv4 header, that may contain options. * @param l4_hdr * The pointer to the beginning of the L4 header. * @return @@ -318,8 +318,8 @@ rte_ipv4_udptcp_cksum(const struct ipv4_hdr *ipv4_hdr, const void *l4_hdr) uint32_t cksum; uint32_t l4_len; - l4_len = (uint32_t)(rte_be_to_cpu_16(ipv4_hdr->total_length) - - sizeof(struct ipv4_hdr)); + l4_len = rte_be_to_cpu_16(ipv4_hdr->total_length) - + (ipv4_hdr->version_ihl & 0xf) * 4; cksum = rte_raw_cksum(l4_hdr, l4_len); cksum += rte_ipv4_phdr_cksum(ipv4_hdr, 0); @@ -392,7 +392,7 @@ rte_ipv6_phdr_cksum(const struct ipv6_hdr *ipv6_hdr, uint64_t ol_flags) /** * Process the IPv6 UDP or TCP checksum. * - * The IPv4 header should not contains options. The layer 4 checksum + * The IPv6 header should not contains options. The layer 4 checksum * must be set to 0 in the packet by the caller. * * @param ipv6_hdr