From patchwork Fri Aug 21 11:32:10 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Pfeiffer X-Patchwork-Id: 75815 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id C28B5A04AF; Fri, 21 Aug 2020 13:32:22 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 24893AAD5; Fri, 21 Aug 2020 13:32:22 +0200 (CEST) Received: from smail.rz.tu-ilmenau.de (smail.rz.tu-ilmenau.de [141.24.186.67]) by dpdk.org (Postfix) with ESMTP id A6F462C27 for ; Fri, 21 Aug 2020 13:32:20 +0200 (CEST) Received: from localhost.localdomain (unknown [91.137.63.238]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smail.rz.tu-ilmenau.de (Postfix) with ESMTPSA id 4D64E580090; Fri, 21 Aug 2020 13:32:20 +0200 (CEST) From: Michael Pfeiffer To: Olivier Matz Cc: dev@dpdk.org, Michael Pfeiffer Date: Fri, 21 Aug 2020 13:32:10 +0200 Message-Id: <20200821113210.307175-1-michael.pfeiffer@tu-ilmenau.de> X-Mailer: git-send-email 2.28.0 MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH] net: calculate checksums for packets with IPv4 options X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Currently, rte_ipv4_cksum() and rte_ipv4_udptcp_cksum() assume all IPv4 headers have sizeof(struct rte_ipv4_hdr) bytes. This is not true for those (rare) packets with IPv4 options. Thus, both IPv4 and TCP/UDP checksums are calculated wrong. This patch fixes the issue by using the actual IPv4 header length from the packet's IHL field. Signed-off-by: Michael Pfeiffer --- lib/librte_net/rte_ip.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/librte_net/rte_ip.h b/lib/librte_net/rte_ip.h index fcd1eb342..6c3ff2603 100644 --- a/lib/librte_net/rte_ip.h +++ b/lib/librte_net/rte_ip.h @@ -269,7 +269,7 @@ static inline uint16_t rte_ipv4_cksum(const struct rte_ipv4_hdr *ipv4_hdr) { uint16_t cksum; - cksum = rte_raw_cksum(ipv4_hdr, sizeof(struct rte_ipv4_hdr)); + cksum = rte_raw_cksum(ipv4_hdr, (ipv4_hdr->version_ihl & 0xf) * 4); return (uint16_t)~cksum; } @@ -311,7 +311,7 @@ rte_ipv4_phdr_cksum(const struct rte_ipv4_hdr *ipv4_hdr, uint64_t ol_flags) } else { psd_hdr.len = rte_cpu_to_be_16( (uint16_t)(rte_be_to_cpu_16(ipv4_hdr->total_length) - - sizeof(struct rte_ipv4_hdr))); + - ((ipv4_hdr->version_ihl & 0xf) * 4))); } return rte_raw_cksum(&psd_hdr, sizeof(psd_hdr)); } @@ -319,8 +319,8 @@ rte_ipv4_phdr_cksum(const struct rte_ipv4_hdr *ipv4_hdr, uint64_t ol_flags) /** * Process the IPv4 UDP or TCP checksum. * - * The IPv4 header should not contains options. The IP and layer 4 - * checksum must be set to 0 in the packet by the caller. + * The IP and layer 4 checksum must be set to 0 in the packet by + * the caller. * * @param ipv4_hdr * The pointer to the contiguous IPv4 header. @@ -339,7 +339,7 @@ rte_ipv4_udptcp_cksum(const struct rte_ipv4_hdr *ipv4_hdr, const void *l4_hdr) if (l3_len < sizeof(struct rte_ipv4_hdr)) return 0; - l4_len = l3_len - sizeof(struct rte_ipv4_hdr); + l4_len = l3_len - ((ipv4_hdr->version_ihl & 0xf) * 4); cksum = rte_raw_cksum(l4_hdr, l4_len); cksum += rte_ipv4_phdr_cksum(ipv4_hdr, 0);