From patchwork Thu Aug 16 10: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: 144342 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp1871077ljj; Thu, 16 Aug 2018 03:04:12 -0700 (PDT) X-Google-Smtp-Source: AA+uWPxF22zHhbwcu2ksg/itHHsYPmuqZprQh0MNcV9kmJFkzt3VGP6E2lNtx8HP66nTbombre+Z X-Received: by 2002:a0c:bd0e:: with SMTP id m14-v6mr26273833qvg.92.1534413852574; Thu, 16 Aug 2018 03:04:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534413852; cv=none; d=google.com; s=arc-20160816; b=VysyQRVh8T0Bti5cwbC8tPltbnQxLMjdiTNTbew8lIKlX8gThztIC2GyH/cy9/G+Yz uAcAneSVBnxhPPl2ILyMXP1hIcpmSn754kJ+dBbtE5cBvhicqLRqNY0VODG7h6u3brjl LRMjOEsOIe1Tpp/wHAa6+T0SNJ/1iSZmszM3/gl9RHImV2L/qlWTGY60O1eaZLJV5hgC K0SeuvkwqmQ2sfQzoFmSwKoOxoeVI+3NpGOrghoefAHKkBLpyp+p40tSD2f1hSWcXPrz 01b6jRvMk+CpNZSf5usJcaqKHBz039kvfVdPyysZmfHn8ra1daw4z2dNXM5aCXNlYmXq w+vQ== 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=yv1iDnA5dvRkN0iLelS90tN4+HdiQjripJtKqt7htHo=; b=saLBAV98jCjYTpchLBfqZjHifud51I8IFWUEEH+Z+9odhIYRd9Mlpd5nDc64pU4lvY P5jlyJR6UwqDGv2SqBQrmtzxQNK7xRyjRr5U+nHMUpYHq2q5mKDLa1LDYuF8eRndC3tC wt0Vv5AHc1oPgWICmdkKsoyNS6WpexLP++IHtBOX4dyKrVQObiBDe5oB8HjMSQcAmEW1 XwU/i364m4pHnELSOnMx5Bz5fpDYOQ1IiPVQVBqGxbPIjeMmOX0CZD6Hk8OwuuRjUp05 NErI0Y9PVn5DImGbMt51UEC0jsbM/FhOStY3CrbcIcru+FfYtEpNSsmkUGCNsaKikpT1 GgZw== 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 q20-v6si7235680qtc.328.2018.08.16.03.04.12; Thu, 16 Aug 2018 03:04: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 3A0246862E; Thu, 16 Aug 2018 10:04: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 9656B68621; Thu, 16 Aug 2018 10:01:40 +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 C81DB68621; Thu, 16 Aug 2018 10:01:30 +0000 (UTC) Received: from forward103o.mail.yandex.net (forward103o.mail.yandex.net [37.140.190.177]) by lists.linaro.org (Postfix) with ESMTPS id 780D768625 for ; Thu, 16 Aug 2018 10:00:22 +0000 (UTC) Received: from mxback20j.mail.yandex.net (mxback20j.mail.yandex.net [IPv6:2a02:6b8:0:1619::114]) by forward103o.mail.yandex.net (Yandex) with ESMTP id 1B43358850A9 for ; Thu, 16 Aug 2018 13:00:21 +0300 (MSK) Received: from smtp1p.mail.yandex.net (smtp1p.mail.yandex.net [2a02:6b8:0:1472:2741:0:8b6:6]) by mxback20j.mail.yandex.net (nwsmtp/Yandex) with ESMTP id gbR2Cq8ARF-0LpOD7mb; Thu, 16 Aug 2018 13:00:21 +0300 Received: by smtp1p.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id LpjbZWHmdB-0Kr0UfZL; Thu, 16 Aug 2018 13:00:20 +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:04 +0000 Message-Id: <1534413607-8630-9-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 8/11] 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: dc28824415ea510e3ef62e47f7640bf4a8420fde ** Merge commit sha: 44d3d4f3c02fc6f3ee9811bc4dc5f01561e519a4 **/ .../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 cd2db2ecd..90108c567 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)