From patchwork Fri Nov 13 14:03:32 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Pfeiffer X-Patchwork-Id: 84145 X-Patchwork-Delegate: ferruh.yigit@amd.com 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 8D3AFA09E0; Fri, 13 Nov 2020 15:03:46 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 70545C868; Fri, 13 Nov 2020 15:03:45 +0100 (CET) Received: from smail.rz.tu-ilmenau.de (smail.rz.tu-ilmenau.de [141.24.186.67]) by dpdk.org (Postfix) with ESMTP id EF9134C96 for ; Fri, 13 Nov 2020 15:03:42 +0100 (CET) Received: from tyrion.fritz.box (unknown [5.10.0.144]) (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 6833958007D; Fri, 13 Nov 2020 15:03:41 +0100 (CET) From: Michael Pfeiffer To: Ferruh Yigit Cc: Keith Wiles , dev@dpdk.org, Michael Pfeiffer Date: Fri, 13 Nov 2020 15:03:32 +0100 Message-Id: <20201113140332.14730-1-michael.pfeiffer@tu-ilmenau.de> X-Mailer: git-send-email 2.20.1 In-Reply-To: <036c2d5f-107b-bb5b-1893-9c3cdd26a1da@intel.com> References: <036c2d5f-107b-bb5b-1893-9c3cdd26a1da@intel.com> MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH v2] net/tap: Allow all-zero checksum for UDP over IPv4 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" Unlike TCP, UDP checksums are optional and may be zero to indicate "not set" [RFC 768] (except for IPv6, where this prohibited [RFC 8200]). Add this special case to the checksum offload emulation in net/tap. Signed-off-by: Michael Pfeiffer Reviewed-by: Ferruh Yigit --- v2: * Added comment. drivers/net/tap/rte_eth_tap.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/drivers/net/tap/rte_eth_tap.c b/drivers/net/tap/rte_eth_tap.c index 2f8abb12c..2542de306 100644 --- a/drivers/net/tap/rte_eth_tap.c +++ b/drivers/net/tap/rte_eth_tap.c @@ -303,6 +303,7 @@ tap_verify_csum(struct rte_mbuf *mbuf) uint16_t cksum = 0; void *l3_hdr; void *l4_hdr; + struct rte_udp_hdr *udp_hdr; if (l2 == RTE_PTYPE_L2_ETHER_VLAN) l2_len += 4; @@ -349,10 +350,23 @@ tap_verify_csum(struct rte_mbuf *mbuf) /* Don't verify checksum for multi-segment packets. */ if (mbuf->nb_segs > 1) return; - if (l3 == RTE_PTYPE_L3_IPV4) + if (l3 == RTE_PTYPE_L3_IPV4) { + if (l4 == RTE_PTYPE_L4_UDP) { + udp_hdr = (struct rte_udp_hdr *)l4_hdr; + if (udp_hdr->dgram_cksum == 0) { + /* + * For IPv4, a zero UDP checksum + * indicates that the sender did not + * generate one [RFC 768]. + */ + mbuf->ol_flags |= PKT_RX_L4_CKSUM_NONE; + return; + } + } cksum = ~rte_ipv4_udptcp_cksum(l3_hdr, l4_hdr); - else if (l3 == RTE_PTYPE_L3_IPV6) + } else if (l3 == RTE_PTYPE_L3_IPV6) { cksum = ~rte_ipv6_udptcp_cksum(l3_hdr, l4_hdr); + } mbuf->ol_flags |= cksum ? PKT_RX_L4_CKSUM_BAD : PKT_RX_L4_CKSUM_GOOD;