From patchwork Tue Aug 21 17:00:01 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Github ODP bot X-Patchwork-Id: 144754 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp5518352ljj; Tue, 21 Aug 2018 10:03:41 -0700 (PDT) X-Google-Smtp-Source: AA+uWPy+m63IBSKaS4Od/6KcFA6ivlToowm6UGYtCagnbj4ymMtptEl//3w/iqKOW0dNQb4c/Brp X-Received: by 2002:a0c:fa4e:: with SMTP id k14-v6mr39719645qvo.35.1534871021386; Tue, 21 Aug 2018 10:03:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534871021; cv=none; d=google.com; s=arc-20160816; b=adRPAkf0AbbVg/omeZ+JrliN+tnBuBwzrvmGUz+sZpgV3WV6rVb5AtPyr1tRgNdwT+ Fl6Crk9K7Ky8FJD08XVE1eH58comI1resJXe+UVUJrzESly2U+NebCham0e+fh89p3yw f0MpjcKZmMCOr3vx1ENYshiBbKK8BZC5jyZVxM0PMQ2hwZx2SwCTIKayXMIIzAlWJoLY YOK4Pc6ZW3jbBqWWo85pWlNgwuGrsWNP0hwucsDlJYzaYii2DUAW/w9qf30yersTASLx 24gCAD5mf2vwACIanTdoWFl0l+6JEYXKGWlyZDz+xw6VeaAO4FrVUu9bPFBMECzB4CPm q7bQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:github-pr-num :references:in-reply-to:message-id:date:to:from:delivered-to :arc-authentication-results; bh=ClBWyQJkbq/Z92CosETKvpa1JqUi/ZNJApjGLu2TISg=; b=TQu46Z+Xhl2tzNbQzBl2NsbTOOAhUulLj+1naGxmmwoHjJvZERchb+ZzLlXlE2O4i8 1ceqv5xGP+GPT52xxC3+ZX5tFeqmGYJeBH3Yg+wIRlscZOhLL7mcr2h3xXTAHsXa7XXq SEjEmqQ/WjiQhDPOkJHYNXwlU/OmSbH5FqpE4KXeIWDTWjiNAj7rhiojmjHodzQlyp1y Z/Xx1zgF+HKsv4IyzqNY/36+EoI/lt1nnByuHRBWsIU+n+VsoFvi9KX71eHS4SesjTx3 jbmSN7mFXCmKt7P3dzA6b/xz+ALfrNLU1dNbfiUnTekvJ6SdJ75md2sh3+UksMP9WfJj 9MWA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.197.127.237 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=yandex.ru Return-Path: Received: from lists.linaro.org (ec2-54-197-127-237.compute-1.amazonaws.com. [54.197.127.237]) by mx.google.com with ESMTP id q14-v6si61512qta.98.2018.08.21.10.03.41; Tue, 21 Aug 2018 10:03:41 -0700 (PDT) Received-SPF: pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.197.127.237 as permitted sender) client-ip=54.197.127.237; Authentication-Results: mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.197.127.237 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=yandex.ru Received: by lists.linaro.org (Postfix, from userid 109) id 1337768612; Tue, 21 Aug 2018 17:03:41 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on ip-10-142-244-252 X-Spam-Level: X-Spam-Status: No, score=-3.6 required=5.0 tests=BAYES_00,FREEMAIL_FROM, MAILING_LIST_MULTI, RCVD_IN_DNSWL_LOW autolearn=disabled version=3.4.0 Received: from [127.0.0.1] (localhost [127.0.0.1]) by lists.linaro.org (Postfix) with ESMTP id 7D8BA607C7; Tue, 21 Aug 2018 17:02:02 +0000 (UTC) X-Original-To: lng-odp@lists.linaro.org Delivered-To: lng-odp@lists.linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id 68D3E685F8; Tue, 21 Aug 2018 17:01:51 +0000 (UTC) Received: from forward102p.mail.yandex.net (forward102p.mail.yandex.net [77.88.28.102]) by lists.linaro.org (Postfix) with ESMTPS id AD9F8685E1 for ; Tue, 21 Aug 2018 17:00:27 +0000 (UTC) Received: from mxback8g.mail.yandex.net (mxback8g.mail.yandex.net [IPv6:2a02:6b8:0:1472:2741:0:8b7:169]) by forward102p.mail.yandex.net (Yandex) with ESMTP id 6C9D64306340 for ; Tue, 21 Aug 2018 20:00:26 +0300 (MSK) Received: from smtp1j.mail.yandex.net (smtp1j.mail.yandex.net [2a02:6b8:0:801::ab]) by mxback8g.mail.yandex.net (nwsmtp/Yandex) with ESMTP id fPng1qQWBA-0QoaNBR6; Tue, 21 Aug 2018 20:00:26 +0300 Received: by smtp1j.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id PfJmBMqdLe-0PVadF1Q; Tue, 21 Aug 2018 20:00:25 +0300 (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (Client certificate not present) From: Github ODP bot To: lng-odp@lists.linaro.org Date: Tue, 21 Aug 2018 17:00:01 +0000 Message-Id: <1534870807-18456-7-git-send-email-odpbot@yandex.ru> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1534870807-18456-1-git-send-email-odpbot@yandex.ru> References: <1534870807-18456-1-git-send-email-odpbot@yandex.ru> Github-pr-num: 674 Subject: [lng-odp] [PATCH v6 6/12] helper: add SCTP handling functions X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: "The OpenDataPlane \(ODP\) List" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: lng-odp-bounces@lists.linaro.org Sender: "lng-odp" From: Dmitry Eremin-Solenikov Add functions to set and verify SCTP packet checksum. Signed-off-by: Dmitry Eremin-Solenikov --- /** Email created from pull request 674 (lumag:sctp-checksum) ** https://github.com/Linaro/odp/pull/674 ** Patch: https://github.com/Linaro/odp/pull/674.patch ** Base sha: f6c423a7d29e2c7d6d890cbc098a398d0d7e1288 ** Merge commit sha: d4f772b36da26684194cb0452a01b8da1ba7e3e1 **/ helper/chksum.c | 75 ++++++++++++++++++++++++++++++ helper/include/odp/helper/chksum.h | 42 +++++++++++++++++ 2 files changed, 117 insertions(+) diff --git a/helper/chksum.c b/helper/chksum.c index da5625a78..7c7c20a2f 100644 --- a/helper/chksum.c +++ b/helper/chksum.c @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -351,3 +352,77 @@ int odph_udp_tcp_chksum(odp_packet_t odp_pkt, return ret_code; } + +static uint32_t odph_packet_crc32c(odp_packet_t pkt, + uint32_t offset, + uint32_t length, + uint32_t init_val) +{ + uint32_t sum = init_val; + + if (offset + length > odp_packet_len(pkt)) + return sum; + + while (length > 0) { + uint32_t seg_len; + void *data = odp_packet_offset(pkt, offset, &seg_len, NULL); + + if (seg_len > length) + seg_len = length; + + sum = odp_hash_crc32c(data, seg_len, sum); + length -= seg_len; + offset += seg_len; + } + + return sum; +} + +int odph_sctp_chksum_set(odp_packet_t pkt) +{ + uint32_t l4_offset = odp_packet_l4_offset(pkt); + uint32_t sum = 0; + + if (!odp_packet_has_sctp(pkt)) + return -1; + + if (l4_offset == ODP_PACKET_OFFSET_INVALID) + return -1; + + odp_packet_copy_from_mem(pkt, + l4_offset + ODPH_SCTPHDR_LEN - 4, + 4, + &sum); + + sum = ~odph_packet_crc32c(pkt, l4_offset, + odp_packet_len(pkt) - l4_offset, + ~0); + return odp_packet_copy_from_mem(pkt, + l4_offset + ODPH_SCTPHDR_LEN - 4, + 4, + &sum); +} + +int odph_sctp_chksum_verify(odp_packet_t pkt) +{ + uint32_t l4_offset = odp_packet_l4_offset(pkt); + uint32_t sum; + uint32_t temp = 0; + + if (!odp_packet_has_sctp(pkt)) + return -1; + + sum = odph_packet_crc32c(pkt, l4_offset, + ODPH_SCTPHDR_LEN - 4, + ~0); + sum = odp_hash_crc32c(&temp, 4, sum); + sum = ~odph_packet_crc32c(pkt, l4_offset + ODPH_SCTPHDR_LEN, + odp_packet_len(pkt) - l4_offset - + ODPH_SCTPHDR_LEN, + sum); + + odp_packet_copy_to_mem(pkt, l4_offset + ODPH_SCTPHDR_LEN - 4, + 4, &temp); + + return (temp == sum) ? 0 : 2; +} diff --git a/helper/include/odp/helper/chksum.h b/helper/include/odp/helper/chksum.h index c03abeb7b..148b98601 100644 --- a/helper/include/odp/helper/chksum.h +++ b/helper/include/odp/helper/chksum.h @@ -189,6 +189,48 @@ static inline int odph_udp_chksum_verify(odp_packet_t odp_pkt) return odph_udp_tcp_chksum(odp_pkt, ODPH_CHKSUM_VERIFY, NULL); } +/** + * Generate SCTP checksum + * + * This function supports SCTP over either IPv4 or IPV6 - including handling + * any IPv4 header options and any IPv6 extension headers. However it + * does not handle tunneled pkts (i.e. any case where there is more than + * one IPv4/IPv6 header). + * This function also handles non-contiguous pkts. In particular it can + * handle arbitrary packet segmentation, including cases where the segments + * are not 2 byte aligned, nor have a length that is a multiple of 2. This + * function also can handle jumbo frames (at least up to 10K). + * + * This function will insert the calculated CRC32-c checksum into the proper + * location in the SCTP header. + * + * @param odp_pkt Calculate and insert chksum for this SCTP pkt, which can + * be over IPv4 or IPv6. + * @retval 0 on success + * @retval <0 on failure + */ +int odph_sctp_chksum_set(odp_packet_t odp_pkt); + +/** + * Verify SCTP checksum + * + * This function supports SCTP over either IPv4 or IPV6 - including handling + * any IPv4 header options and any IPv6 extension headers. However it + * does not handle tunneled pkts (i.e. any case where there is more than + * one IPv4/IPv6 header). + * This function also handles non-contiguous pkts. In particular it can + * handle arbitrary packet segmentation, including cases where the segments + * are not 2 byte aligned, nor have a length that is a multiple of 2. This + * function also can handle jumbo frames (at least up to 10K). + * + * @param odp_pkt Calculate and compare the chksum for this SCTP pkt, + * which can be over IPv4 or IPv6. + * @retval <0 on failure + * @retval 0 if the incoming chksum field is correct + * @retval 2 when the chksum field is incorrect + */ +int odph_sctp_chksum_verify(odp_packet_t odp_pkt); + /** * @} */