From patchwork Tue Aug 21 17:00:04 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: 144758 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp5521525ljj; Tue, 21 Aug 2018 10:06:12 -0700 (PDT) X-Google-Smtp-Source: AA+uWPz4CtIltqMMFA9smWMGDeo7G4DPHSru5mZikfhSSMEPm2zq7DfdienbUaUD4nQJfn65hVNB X-Received: by 2002:ac8:1846:: with SMTP id n6-v6mr4615719qtk.85.1534871172107; Tue, 21 Aug 2018 10:06:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534871172; cv=none; d=google.com; s=arc-20160816; b=Rd7wAyyDizpHX5h/Oiy9/EmTFJ8YOxMbuNxPkh/bpYAWBDdSH+H2KL/itr4metW9+T OdGEcNj8vZ2zwlHGwe9jsR8EZfBT82QmzjejPcTFSxJpH2FcK4p0yFi8rdJQpKVtBGoa 31zltKsbJH8nVSDSDrahaN2IPMmRxfT2PuKvxkmz+ruY3JdHQjW5CMQCI01GjFTfpcIN +IifbluKpKmlarslXx3q4nToc0Dz0OUTaYXOVUn52qj4tmoaCRNDhzBjIQiY4pqZqSg9 VdE/5VQsAtVq6xmKGb7US0mdWP/83KSRyNxsemrAE1ZUBz8nn9aYUOR3kxkF65qFMLr2 1usA== 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=6VootljFmxXmzZYyAoadttcZLOLlCU+vuse2XsYN5G0=; b=YBXI5YKejH76vsIYpI9FyQ6jB0WXN0pYiOjqjCj2FyvVbE3uUoy1zmThCVu57xg8/4 GBvAuThDAdwcj+UI5yz5Ojj1Y53kowl2kwjpkzgZBJAFJYjJj6OywRMAfMMNJvZIrfN4 CJhE5LJEUMnDSPhYUgjvO7HvOUAPp3ZhUYLmfRhh+6WLj5r/wWeCMpqdVdaEkemMI1zs 8JToPQUNZp4EsVjWRTJQQTjSa7ZofvH29Mg7NawPa2MwIrv3dbpaDYIR0WT4tuQhCbkV GuNEAO1wsTcBGAQCdILFZ3oryuuv+J8o7dX1vQKQyjSRABrKi84WEUniS2kcaYlh8F3E 2CWA== 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 t28-v6si4369327qta.348.2018.08.21.10.06.11; Tue, 21 Aug 2018 10:06: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 CA2E1685F1; Tue, 21 Aug 2018 17:06:11 +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 4163B60AA8; Tue, 21 Aug 2018 17:02:35 +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 C308961706; Tue, 21 Aug 2018 17:02:24 +0000 (UTC) Received: from forward103o.mail.yandex.net (forward103o.mail.yandex.net [37.140.190.177]) by lists.linaro.org (Postfix) with ESMTPS id E1FFF685D5 for ; Tue, 21 Aug 2018 17:00:38 +0000 (UTC) Received: from mxback3j.mail.yandex.net (mxback3j.mail.yandex.net [IPv6:2a02:6b8:0:1619::10c]) by forward103o.mail.yandex.net (Yandex) with ESMTP id D53A358838F9 for ; Tue, 21 Aug 2018 20:00:36 +0300 (MSK) Received: from smtp1j.mail.yandex.net (smtp1j.mail.yandex.net [2a02:6b8:0:801::ab]) by mxback3j.mail.yandex.net (nwsmtp/Yandex) with ESMTP id iB1trISa3Y-0YcaWmml; Tue, 21 Aug 2018 20:00:34 +0300 Received: by smtp1j.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id PfJmBMqdLe-0XVaT3AM; Tue, 21 Aug 2018 20:00:34 +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:04 +0000 Message-Id: <1534870807-18456-10-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 9/12] linux-gen: packet: support SCTP packet insertion 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 support for insertion of checksum into SCTP packets. 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 **/ .../include/odp_packet_internal.h | 2 + platform/linux-generic/odp_packet.c | 49 +++++++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/platform/linux-generic/include/odp_packet_internal.h b/platform/linux-generic/include/odp_packet_internal.h index 4b5127d93..0dccc97da 100644 --- a/platform/linux-generic/include/odp_packet_internal.h +++ b/platform/linux-generic/include/odp_packet_internal.h @@ -308,6 +308,8 @@ int _odp_packet_cmp_data(odp_packet_t pkt, uint32_t offset, int _odp_packet_ipv4_chksum_insert(odp_packet_t pkt); int _odp_packet_tcp_chksum_insert(odp_packet_t pkt); int _odp_packet_udp_chksum_insert(odp_packet_t pkt); +int _odp_packet_sctp_chksum_insert(odp_packet_t pkt); + #ifdef __cplusplus } diff --git a/platform/linux-generic/odp_packet.c b/platform/linux-generic/odp_packet.c index 885aec8d8..ae63ef4a3 100644 --- a/platform/linux-generic/odp_packet.c +++ b/platform/linux-generic/odp_packet.c @@ -2017,6 +2017,31 @@ static uint16_t packet_sum_ones_comp16(odp_packet_hdr_t *pkt_hdr, return sum; } +static uint32_t packet_sum_crc32c(odp_packet_hdr_t *pkt_hdr, + uint32_t offset, + uint32_t len, + uint32_t init_val) +{ + uint32_t sum = init_val; + + if (offset + len > pkt_hdr->frame_len) + return sum; + + while (len > 0) { + uint32_t seglen = 0; /* GCC */ + void *mapaddr = packet_map(pkt_hdr, offset, &seglen, NULL); + + if (seglen > len) + seglen = len; + + sum = odp_hash_crc32c(mapaddr, seglen, sum); + len -= seglen; + offset += seglen; + } + + return sum; +} + /** Parser helper function for Ethernet packets */ static inline uint16_t parse_eth(packet_parser_t *prs, const uint8_t **parseptr, uint32_t *offset, uint32_t frame_len) @@ -2617,6 +2642,30 @@ int _odp_packet_udp_chksum_insert(odp_packet_t pkt) return _odp_packet_tcp_udp_chksum_insert(pkt, _ODP_IPPROTO_UDP); } +/** + * Calculate and fill in SCTP checksum + * + * @param pkt ODP packet + * + * @retval 0 on success + * @retval <0 on failure + */ +int _odp_packet_sctp_chksum_insert(odp_packet_t pkt) +{ + odp_packet_hdr_t *pkt_hdr = packet_hdr(pkt); + uint32_t sum; + + if (pkt_hdr->p.l4_offset == ODP_PACKET_OFFSET_INVALID) + return -1; + + sum = 0; + odp_packet_copy_from_mem(pkt, pkt_hdr->p.l4_offset + 8, 4, &sum); + sum = ~packet_sum_crc32c(pkt_hdr, pkt_hdr->p.l4_offset, + pkt_hdr->frame_len - pkt_hdr->p.l4_offset, + ~0); + return odp_packet_copy_from_mem(pkt, pkt_hdr->p.l4_offset + 8, 4, &sum); +} + static int packet_l4_chksum(odp_packet_hdr_t *pkt_hdr, odp_proto_chksums_t chksums, uint32_t l4_part_sum)