From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 5D188A00C3; Wed, 15 Dec 2021 12:34:00 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id D771940688; Wed, 15 Dec 2021 12:33:59 +0100 (CET) Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by mails.dpdk.org (Postfix) with ESMTP id 7450A40041 for ; Wed, 15 Dec 2021 12:33:58 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1639568038; x=1671104038; h=message-id:date:subject:to:cc:references:from: in-reply-to:content-transfer-encoding:mime-version; bh=l9ATdxeHaun3ujCaaYFCYWxdC2lpeAs5YkbOBgY+Tmo=; b=X9WDTV6sxHzfG8wXIExpiuuALOjGmj5bzXC4vRYi33UW7I/pWf6Q767q ssBjGlLUEkTjlzuFE0Gbr/FX9ure2Yfc+jOK8/r84iL90IHbFCdW7Wr+2 Rrz23myQ2SrqvUj2m6tdMixTs4uVsmbltdR4O6LK3hHscHiaNX7oEFPj8 2Tk6ON9DqFjZB2EIPt/G5MQ0A5YQhSTjbyBoPfn97Y3K7AOwYgCAXofgc S5TnKBXMwkL0W1nUKjt7er+R06GwT/Jh7qY/z1E2jvnh5PRmyMSOmHABv ZNUrJaH6hqg2y4MF/WXFK95ACrrejrFlk8j0HfLEww2KYZEVpUF1e18Ph Q==; X-IronPort-AV: E=McAfee;i="6200,9189,10198"; a="239427677" X-IronPort-AV: E=Sophos;i="5.88,207,1635231600"; d="scan'208";a="239427677" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Dec 2021 03:33:57 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.88,207,1635231600"; d="scan'208";a="682458016" Received: from fmsmsx601.amr.corp.intel.com ([10.18.126.81]) by orsmga005.jf.intel.com with ESMTP; 15 Dec 2021 03:33:56 -0800 Received: from fmsmsx612.amr.corp.intel.com (10.18.126.92) by fmsmsx601.amr.corp.intel.com (10.18.126.81) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.20; Wed, 15 Dec 2021 03:33:56 -0800 Received: from fmsmsx603.amr.corp.intel.com (10.18.126.83) by fmsmsx612.amr.corp.intel.com (10.18.126.92) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.20; Wed, 15 Dec 2021 03:33:55 -0800 Received: from fmsedg602.ED.cps.intel.com (10.1.192.136) by fmsmsx603.amr.corp.intel.com (10.18.126.83) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.20 via Frontend Transport; Wed, 15 Dec 2021 03:33:55 -0800 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (104.47.57.177) by edgegateway.intel.com (192.55.55.71) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2308.20; Wed, 15 Dec 2021 03:33:55 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ZJURtNOFpSadQMbTUXpBq9d1308gl0SEdT4Nq2l4Eqw9AAzpma+Dcr5P1U+wlrCb+aNUmUM94OqFVfhxQdT3YYiFgWXjqgK5C4Jcq8WdpoLKWAxE5Wy6RMaHv+DgeEIUfMWz5vOOVu46UCh3Aqpoi8xX8Fyi5CQt73UpszmwUaKrzTfS4wFhljxXteWrfc9zQG7UkMWppSjv02QDj8LjZj2kl+i9tXqwmUw/Ear14w3F97As6mIOsikZnUnWYJPdQsG9wqzBneWtb/RtJGTYMljxQ42tZOM+EhrHYHa10QAWSYNENwisg1AELxwhlN4czQCNWFIZq//dGrIoEt/LGg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=1E0v3XTZntgs2aC2q58wzCSe076+3hFt4S6bqxdUTJs=; b=Q8cXhT54+z48n5TBppIu8pJ3kr3z0q7NExQBzyN7HbUpyWNnBJYs0symZtt4QcI8gz4MaBbGZ3/9NTs4+9d+BN/1J61xdZ6FrClCqllEc+bCx0GHHe6vr6ofh4KPMKYojvbcuejgsq6//KhGdUoPXwfVM0IoPHBFzOOKZe2cUiTEKv71ymNGNL43pIzLqAs994929Oul6+hH2wosX6FUe8lyQfy7lhf9/hG+M6FTHzrphWMS+j2TQcFzHjYgjqhOdQ0yka/s7W24TQ+TBBXhU0M+g3EfK5aBlp9y2Ko9oSTRYFUtsNndzQX2bieUyT4pTmZ2mO6zuxuJR1g1Z18Tgg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=intel.com; Received: from MWHPR11MB0062.namprd11.prod.outlook.com (2603:10b6:301:67::34) by MW3PR11MB4764.namprd11.prod.outlook.com (2603:10b6:303:5a::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4778.17; Wed, 15 Dec 2021 11:33:54 +0000 Received: from MWHPR11MB0062.namprd11.prod.outlook.com ([fe80::10c4:88fd:5820:cc2c]) by MWHPR11MB0062.namprd11.prod.outlook.com ([fe80::10c4:88fd:5820:cc2c%5]) with mapi id 15.20.4801.014; Wed, 15 Dec 2021 11:33:53 +0000 Message-ID: <7ff44b44-ad45-f435-1563-55a80282c210@intel.com> Date: Wed, 15 Dec 2021 17:03:42 +0530 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Firefox/91.0 Thunderbird/91.4.0 Subject: Re: [PATCH v4 1/2] net: add functions to calculate UDP/TCP cksum in mbuf To: Xiaoyun Li , , , , , , CC: References: <20211015051306.320328-1-xiaoyun.li@intel.com> <20211203113805.1025301-1-xiaoyun.li@intel.com> <20211203113805.1025301-2-xiaoyun.li@intel.com> From: "Singh, Aman Deep" In-Reply-To: <20211203113805.1025301-2-xiaoyun.li@intel.com> Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 7bit X-ClientProxiedBy: PN3PR01CA0044.INDPRD01.PROD.OUTLOOK.COM (2603:1096:c01:98::21) To MWHPR11MB0062.namprd11.prod.outlook.com (2603:10b6:301:67::34) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 14b8eecf-1f42-46a2-ed28-08d9bfbec5de X-MS-TrafficTypeDiagnostic: MW3PR11MB4764:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:10000; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 9pEwQkz5VVm7qPE5tVb1fmWXoSofPGuafJr7rRER1lm8Uyj679rVXLOICqkHiUoHwIJyKI8S49rWAJcNN/Ylrw27TEIwNel92Ar4nxf+hYqwUsIEoBA6Scqb5uSWzCiuedgaB+Gv+cCbI7UjkmzNHqFGNylImD3/r67ai8V+J520cO6VJ2ylPvcOgmaXEabR+AQ+qATw1r/2EO228BGYDmQKFztTX+uNPamB9x7AAh+Kh1CpUkpPJkhkVr3QhF1YdjcvO6eqkKv5+OANwvNK4W5iwQ/FOBEH7/yIO+T+Yu4oixl2scLh/j794dNhjqf9zMHx41mDfpGCVCLQjpZgyes9bzlr874ZjX9xpvwIWq17UGlw/joKEKRZEs4A0OIsNA/p4DYbefaahJJGrJU6Iei3PNzgoGwqA311fXPJpF6S1TRNAHWiq+habjTRhAn8UsfX9dcsRXSZ8QE7iS6NI9IPLKDIZkr7h7SmZMeE/NFqMJcPZwv9M/1rD4pCRfw2gWm5EJK3DIGGruThlooAjww5IZYgZLnyYqxK4Em6ar6s/gJ3qJFW8w5AI+fEkkqu9+pRNqIjirHSMtu53eIPKA+7J6qChYzoiS9A26UQnVxtr+eyOwvcfbH3yYynZDcZTJIn+tbFBzx5ME7aHkYq8tlJIYqhhI+2FsG/wAIihLu0lcDqMPeWJTEa0NGScJ0b7MbhsQkdD+XfNVWmi3qRHbNBRTAD8srZmgm31cANBHM= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:MWHPR11MB0062.namprd11.prod.outlook.com; PTR:; CAT:NONE; SFS:(366004)(26005)(38100700002)(2906002)(6512007)(53546011)(6636002)(6506007)(5660300002)(31696002)(86362001)(8936002)(6486002)(2616005)(186003)(8676002)(36756003)(66556008)(31686004)(66476007)(66946007)(6666004)(82960400001)(316002)(4326008)(508600001)(83380400001)(45980500001)(43740500002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?YndKc01xL2hnWHZiV3NjU0FKZFZDN2xBSGxPYnZIRWFwdW9WT2FzNzNvZUlH?= =?utf-8?B?KzhicmNta0ZxQXM5RXN3WllPbmp5cEtVVWY2akNEcFBSU0RhTFJxeU80ZGl1?= =?utf-8?B?OVIvTll1TW4wZDdpQVRsbG9SSzdXUER6TXRhWndkYmdGUktsL256YkQ5djJ5?= =?utf-8?B?RmZ6WDRhaSsrUWVORDNhWkthMUZ4K3RvMVkzWVBWWFlaY1JsUFRpeUd6VHpT?= =?utf-8?B?aG92S0I3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bFE0a0MyRDhUZTl4?= =?utf-8?B?T3d3cFdwWFpXV3VOd2JGMTdVWHBBdkhkY2YyWkFQYlZCUFdpTGlaSVNxT1I2?= =?utf-8?B?YmJjSUZQa2dQZ1l2M2lpdnU3MWw4U01tUzNWNDl4YVJqcE44V0E1Y1ZiRVlv?= =?utf-8?B?WDZ1N1ZnNUZFSTgxb0h3dHVKcERHR09hUnJrOGlxeVpuTE5aMnZ6ZW5uN0JM?= =?utf-8?Q?QvmvpteRd5CYSNK9ITpU00gYtfGj+jc6sD2i5cBFjc=3D?= X-MS-Exchange-CrossTenant-Network-Message-Id: 14b8eecf-1f42-46a2-ed28-08d9bfbec5de X-MS-Exchange-CrossTenant-AuthSource: MWHPR11MB0062.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Dec 2021 11:33:53.8110 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: ucLiX6ekotIk34yK373IdmlDDM0c38ju8LUsHzG6J8DLEMaC1J+0VOnqy4Q/fZNxqKa59QTmY09Upy5UaNtemffOb3w6hbBqBr3qJqBfC8c= X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW3PR11MB4764 X-OriginatorOrg: intel.com X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org On 12/3/2021 5:08 PM, Xiaoyun Li wrote: > Add functions to call rte_raw_cksum_mbuf() to calculate IPv4/6 > UDP/TCP checksum in mbuf which can be over multi-segments. > > Signed-off-by: Xiaoyun Li > --- > doc/guides/rel_notes/release_22_03.rst | 10 ++ > lib/net/rte_ip.h | 186 +++++++++++++++++++++++++ > lib/net/version.map | 10 ++ > 3 files changed, 206 insertions(+) > > diff --git a/doc/guides/rel_notes/release_22_03.rst b/doc/guides/rel_notes/release_22_03.rst > index 6d99d1eaa9..7a082c4427 100644 > --- a/doc/guides/rel_notes/release_22_03.rst > +++ b/doc/guides/rel_notes/release_22_03.rst > @@ -55,6 +55,13 @@ New Features > Also, make sure to start the actual text at the margin. > ======================================================= > > +* **Added functions to calculate UDP/TCP checksum in mbuf.** > + * Added the following functions to calculate UDP/TCP checksum of packets > + which can be over multi-segments: > + - ``rte_ipv4_udptcp_cksum_mbuf()`` > + - ``rte_ipv4_udptcp_cksum_mbuf_verify()`` > + - ``rte_ipv6_udptcp_cksum_mbuf()`` > + - ``rte_ipv6_udptcp_cksum_mbuf_verify()`` > > Removed Items > ------------- > @@ -84,6 +91,9 @@ API Changes > Also, make sure to start the actual text at the margin. > ======================================================= > > +* net: added experimental functions ``rte_ipv4_udptcp_cksum_mbuf()``, > + ``rte_ipv4_udptcp_cksum_mbuf_verify()``, ``rte_ipv6_udptcp_cksum_mbuf()``, > + ``rte_ipv6_udptcp_cksum_mbuf_verify()`` > > ABI Changes > ----------- > diff --git a/lib/net/rte_ip.h b/lib/net/rte_ip.h > index c575250852..534f401d26 100644 > --- a/lib/net/rte_ip.h > +++ b/lib/net/rte_ip.h > @@ -400,6 +400,65 @@ rte_ipv4_udptcp_cksum(const struct rte_ipv4_hdr *ipv4_hdr, const void *l4_hdr) > return cksum; > } > > +/** > + * @internal Calculate the non-complemented IPv4 L4 checksum of a packet > + */ > +static inline uint16_t > +__rte_ipv4_udptcp_cksum_mbuf(const struct rte_mbuf *m, > + const struct rte_ipv4_hdr *ipv4_hdr, > + uint16_t l4_off) > +{ > + uint16_t raw_cksum; > + uint32_t cksum; > + > + if (l4_off > m->pkt_len) > + return 0; > + > + if (rte_raw_cksum_mbuf(m, l4_off, m->pkt_len - l4_off, &raw_cksum)) > + return 0; > + > + cksum = raw_cksum + rte_ipv4_phdr_cksum(ipv4_hdr, 0); > + > + cksum = ((cksum & 0xffff0000) >> 16) + (cksum & 0xffff); At times, even after above operation "cksum" might stay above 16-bits, ex "cksum = 0x1FFFF" to start with. Can we consider using "return __rte_raw_cksum_reduce(cksum);" > + > + return (uint16_t)cksum; > +} > + > +/** > + * @warning > + * @b EXPERIMENTAL: this API may change without prior notice. > + * > + * Compute the IPv4 UDP/TCP checksum of a packet. > + * > + * @param m > + * The pointer to the mbuf. > + * @param ipv4_hdr > + * The pointer to the contiguous IPv4 header. > + * @param l4_off > + * The offset in bytes to start L4 checksum. > + * @return > + * The complemented checksum to set in the L4 header. > + */ > +__rte_experimental > +static inline uint16_t > +rte_ipv4_udptcp_cksum_mbuf(const struct rte_mbuf *m, > + const struct rte_ipv4_hdr *ipv4_hdr, uint16_t l4_off) > +{ > + uint16_t cksum = __rte_ipv4_udptcp_cksum_mbuf(m, ipv4_hdr, l4_off); > + > + cksum = ~cksum; > + > + /* > + * Per RFC 768: If the computed checksum is zero for UDP, > + * it is transmitted as all ones > + * (the equivalent in one's complement arithmetic). > + */ > + if (cksum == 0 && ipv4_hdr->next_proto_id == IPPROTO_UDP) > + cksum = 0xffff; > + > + return cksum; > +} > + > /** > * Validate the IPv4 UDP or TCP checksum. > * > @@ -426,6 +485,38 @@ rte_ipv4_udptcp_cksum_verify(const struct rte_ipv4_hdr *ipv4_hdr, > return 0; > } > > +/** > + * @warning > + * @b EXPERIMENTAL: this API may change without prior notice. > + * > + * Verify the IPv4 UDP/TCP checksum of a packet. > + * > + * In case of UDP, the caller must first check if udp_hdr->dgram_cksum is 0 > + * (i.e. no checksum). > + * > + * @param m > + * The pointer to the mbuf. > + * @param ipv4_hdr > + * The pointer to the contiguous IPv4 header. > + * @param l4_off > + * The offset in bytes to start L4 checksum. > + * @return > + * Return 0 if the checksum is correct, else -1. > + */ > +__rte_experimental > +static inline uint16_t > +rte_ipv4_udptcp_cksum_mbuf_verify(const struct rte_mbuf *m, > + const struct rte_ipv4_hdr *ipv4_hdr, > + uint16_t l4_off) > +{ > + uint16_t cksum = __rte_ipv4_udptcp_cksum_mbuf(m, ipv4_hdr, l4_off); > + > + if (cksum != 0xffff) > + return -1; cksum other than 0xffff, should return error. Is that the intent or I am missing something obvious. > + > + return 0; > +} > + > /** > * IPv6 Header > */ > @@ -538,6 +629,68 @@ rte_ipv6_udptcp_cksum(const struct rte_ipv6_hdr *ipv6_hdr, const void *l4_hdr) > return cksum; > } > > +/** > + * @internal Calculate the non-complemented IPv6 L4 checksum of a packet > + */ > +static inline uint16_t > +__rte_ipv6_udptcp_cksum_mbuf(const struct rte_mbuf *m, > + const struct rte_ipv6_hdr *ipv6_hdr, > + uint16_t l4_off) > +{ > + uint16_t raw_cksum; > + uint32_t cksum; > + > + if (l4_off > m->pkt_len) > + return 0; > + > + if (rte_raw_cksum_mbuf(m, l4_off, m->pkt_len - l4_off, &raw_cksum)) > + return 0; > + > + cksum = raw_cksum + rte_ipv6_phdr_cksum(ipv6_hdr, 0); > + > + cksum = ((cksum & 0xffff0000) >> 16) + (cksum & 0xffff); Same, please check if we can opt for __rte_raw_cksum_reduce(cksum) > + > + return (uint16_t)cksum; > +} > + > +/** > + * @warning > + * @b EXPERIMENTAL: this API may change without prior notice. > + * > + * Process the IPv6 UDP or TCP checksum of a packet. > + * > + * The IPv6 header must not be followed by extension headers. The layer 4 > + * checksum must be set to 0 in the L4 header by the caller. > + * > + * @param m > + * The pointer to the mbuf. > + * @param ipv6_hdr > + * The pointer to the contiguous IPv6 header. > + * @param l4_off > + * The offset in bytes to start L4 checksum. > + * @return > + * The complemented checksum to set in the L4 header. > + */ > +__rte_experimental > +static inline uint16_t > +rte_ipv6_udptcp_cksum_mbuf(const struct rte_mbuf *m, > + const struct rte_ipv6_hdr *ipv6_hdr, uint16_t l4_off) > +{ > + uint16_t cksum = __rte_ipv6_udptcp_cksum_mbuf(m, ipv6_hdr, l4_off); > + > + cksum = ~cksum; > + > + /* > + * Per RFC 768: If the computed checksum is zero for UDP, > + * it is transmitted as all ones > + * (the equivalent in one's complement arithmetic). > + */ > + if (cksum == 0 && ipv6_hdr->proto == IPPROTO_UDP) > + cksum = 0xffff; > + > + return cksum; > +} > + > /** > * Validate the IPv6 UDP or TCP checksum. > * > @@ -565,6 +718,39 @@ rte_ipv6_udptcp_cksum_verify(const struct rte_ipv6_hdr *ipv6_hdr, > return 0; > } > > +/** > + * @warning > + * @b EXPERIMENTAL: this API may change without prior notice. > + * > + * Validate the IPv6 UDP or TCP checksum of a packet. > + * > + * In case of UDP, the caller must first check if udp_hdr->dgram_cksum is 0: > + * this is either invalid or means no checksum in some situations. See 8.1 > + * (Upper-Layer Checksums) in RFC 8200. > + * > + * @param m > + * The pointer to the mbuf. > + * @param ipv6_hdr > + * The pointer to the contiguous IPv6 header. > + * @param l4_off > + * The offset in bytes to start L4 checksum. > + * @return > + * Return 0 if the checksum is correct, else -1. > + */ > +__rte_experimental > +static inline int > +rte_ipv6_udptcp_cksum_mbuf_verify(const struct rte_mbuf *m, > + const struct rte_ipv6_hdr *ipv6_hdr, > + uint16_t l4_off) > +{ > + uint16_t cksum = __rte_ipv6_udptcp_cksum_mbuf(m, ipv6_hdr, l4_off); > + > + if (cksum != 0xffff) > + return -1; > + > + return 0; > +} > + > /** IPv6 fragment extension header. */ > #define RTE_IPV6_EHDR_MF_SHIFT 0 > #define RTE_IPV6_EHDR_MF_MASK 1 > diff --git a/lib/net/version.map b/lib/net/version.map > index 4f4330d1c4..0f2aacdef8 100644 > --- a/lib/net/version.map > +++ b/lib/net/version.map > @@ -12,3 +12,13 @@ DPDK_22 { > > local: *; > }; > + > +EXPERIMENTAL { > + global: > + > + # added in 22.03 > + rte_ipv4_udptcp_cksum_mbuf; > + rte_ipv4_udptcp_cksum_mbuf_verify; > + rte_ipv6_udptcp_cksum_mbuf; > + rte_ipv6_udptcp_cksum_mbuf_verify; > +};