* 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.
*/
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;
}
* 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
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));
}
* 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
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);
/**
* 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