From patchwork Thu Aug 16 10: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: 144339 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp1868820ljj; Thu, 16 Aug 2018 03:02:12 -0700 (PDT) X-Google-Smtp-Source: AA+uWPyiJdnPNYyHxP5mXe+HiY0e7N6e7+wgcrBHGUSTqXR6MOP4Iu0bMyupV7Gp19hqDQ1yOkUo X-Received: by 2002:ac8:3251:: with SMTP id y17-v6mr29594889qta.334.1534413732790; Thu, 16 Aug 2018 03:02:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534413732; cv=none; d=google.com; s=arc-20160816; b=fJLNELEbO/H7VAR08EPGlSBOjZMCr5OocOBrIQmpoHgUbX1lK6geoiG4GW0zd0nSLB 2uDxGPllUMOl9+N9tD9u0zB0zvuulD3H7hS0gWbRkog3161TCg6SZAzO6imbTwrqQEBg xHRnGTlB8Xn7XiftyGWlzVoSB0fPx+RaPCguCU2k999YgQECLdT23q7UGfyQgMsKhpDu ePp/Ae3BxQFnEmiQ1IDFdqSdMFheAmmlzQ9a/7L6r6NFk1Of2XMirV4deCXaLvD1mGo2 S0sM5cnKXXSjCABGh6yIOqoLUZYvNasLNWE9kcBqDFS4vIHhnsoUWKW7qzVYV28DwWDa 8Rlw== 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=Asje99w6V+NueZCwa42JlP3RLHoh32CB5TnOLOTsw1g=; b=AywL7HmZiUqGDXErMhWt7DujHSXCm5LvGNHDeQgrLEvg9Fae1rvCo6mOzJ+rp64wib pmyb6Ec4ov6CxYswA375fqWs2wZ9RXo5FCk6nmimnzvwUQFtu1/l7NHx558zkSmwR0yy RfPv9D72TLFa2tXn1RM1NUxZ3NxrgiJz6/t7V4pr0G+20WzHbYhMKmMLF8y2uqLY641C MDIZb7uK0r4eaWqvSbHgiqkmDaUhgNzMcwRtSz8n6ZoPU16rerQoOgVAHLw0XA9g691T KcyYhAAcLTBKyxN0uJhMhQNIwx1sDXk1zAekXPCebJQ5SG8tle42+ABqRhK9YGHoT4w7 C5jw== 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 r6-v6si608758qvb.185.2018.08.16.03.02.12; Thu, 16 Aug 2018 03:02:12 -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 783886862F; Thu, 16 Aug 2018 10:02:12 +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 88BC36861C; Thu, 16 Aug 2018 10:01:29 +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 314E368633; Thu, 16 Aug 2018 10:01:21 +0000 (UTC) Received: from forward105o.mail.yandex.net (forward105o.mail.yandex.net [37.140.190.183]) by lists.linaro.org (Postfix) with ESMTPS id 6E6B06861F for ; Thu, 16 Aug 2018 10:00:20 +0000 (UTC) Received: from mxback15g.mail.yandex.net (mxback15g.mail.yandex.net [IPv6:2a02:6b8:0:1472:2741:0:8b7:94]) by forward105o.mail.yandex.net (Yandex) with ESMTP id DCBA34443AA5 for ; Thu, 16 Aug 2018 13:00:18 +0300 (MSK) Received: from smtp1p.mail.yandex.net (smtp1p.mail.yandex.net [2a02:6b8:0:1472:2741:0:8b6:6]) by mxback15g.mail.yandex.net (nwsmtp/Yandex) with ESMTP id YVuslB9iAr-0ISuV0dP; Thu, 16 Aug 2018 13:00:18 +0300 Received: by smtp1p.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id LpjbZWHmdB-0IrSQd5P; Thu, 16 Aug 2018 13:00:18 +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: Thu, 16 Aug 2018 10:00:01 +0000 Message-Id: <1534413607-8630-6-git-send-email-odpbot@yandex.ru> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1534413607-8630-1-git-send-email-odpbot@yandex.ru> References: <1534413607-8630-1-git-send-email-odpbot@yandex.ru> Github-pr-num: 674 Subject: [lng-odp] [PATCH v2 5/11] 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: dc28824415ea510e3ef62e47f7640bf4a8420fde ** Merge commit sha: 44d3d4f3c02fc6f3ee9811bc4dc5f01561e519a4 **/ 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..ac273dd01 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; +} diff --git a/helper/include/odp/helper/chksum.h b/helper/include/odp/helper/chksum.h index c03abeb7b..28695ea88 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. + * @return 0 upon success and < 0 upon 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. + * @return Returns < 0 upon an error. Returns 1 upon no error and + * the incoming chksum field is 0 (disabled), else returns 0 + * if the incoming chksum field is correct, else returns 2 + * when the chksum field is incorrect. + */ +int odph_sctp_chksum_verify(odp_packet_t odp_pkt); + /** * @} */