From patchwork Mon Aug 20 11:00:05 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: 144601 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp3828953ljj; Mon, 20 Aug 2018 04:04:38 -0700 (PDT) X-Google-Smtp-Source: ANB0Vdb+JKUJZq8iADAJcnFEwyf9Lu/88+U0Tm9ssNnzyKecgMXggrtL75Mz0CUNcK7mwfJzTjfv X-Received: by 2002:a37:547:: with SMTP id 68-v6mr6972750qkf.423.1534763078484; Mon, 20 Aug 2018 04:04:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534763078; cv=none; d=google.com; s=arc-20160816; b=Ppnw81hfSuNquoFE6RmwUwojmMaSlCX0R2FosnR3P78nWpxA3c3yHsXJT9hTsQiDsY eBN/Kh7um3KUq+K2fA2GeJoToLOswgxWeMu0HSvcebPFsASFXot8jFrhubfEdLPgTgzg LFDWNba4ns28T4VubfV6fuejwCzqFtoY2wgB07qp/MNE2DCZ9ZybEsZ/gOn1mEQGuLm+ YRBWYLM68nsDrn2kpEJfL9Xq6iCNoHNSfo0Zh4Q0tp9++pqbNPkui1/36KP/upRvBywe tq+XgB4HNJMG2CPw+Zqa6ua1letNqj8Ltm4jtDqS8w2/lQLEPOWvmJjUzVQV2yTLC2Rj tD4g== 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=DUKurrB61Qg5cSEKLRWTGZ2ulQGq2ivyaD9KHB4JZUI=; b=qcCdIlUTXXaanz54WOfCuOBaBVQhHT4rajEvpX48jUsPdI1DlVJjvhMuKLUGI3O8fb ZJzZS3pZtI1Q8XBzGLfQqbiWrxYqtqShOnlAQQNPf69SSX3RgPj6bNRlaC5HfmHi64bG MX1nKAewiSkL/SACc/jv1OcG1imxGCvFclXwBBoIAm4QmvvHMwmxfflC9+ph9FU8e6Ak RFsHKonzS/ZaLoV2b+4kFfDcm2gs6Lrl15X9Af0lnVrnxzbjPOYQ4yFAyZDbJytTL/wD V6cwN8R5tyWrpyiaEqNasn+kBSRsVQRSDuIDsFSH280wk7URaKgpntYkMLdZTck7t3Rj c4PA== 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 o70-v6si4688459qka.195.2018.08.20.04.04.38; Mon, 20 Aug 2018 04:04:38 -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 2C11C6863A; Mon, 20 Aug 2018 11:04:38 +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 B0AA06170C; Mon, 20 Aug 2018 11:01:10 +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 A665768644; Mon, 20 Aug 2018 11:00:58 +0000 (UTC) Received: from forward104p.mail.yandex.net (forward104p.mail.yandex.net [77.88.28.107]) by lists.linaro.org (Postfix) with ESMTPS id AAD566170C for ; Mon, 20 Aug 2018 11:00:17 +0000 (UTC) Received: from mxback6o.mail.yandex.net (mxback6o.mail.yandex.net [IPv6:2a02:6b8:0:1a2d::20]) by forward104p.mail.yandex.net (Yandex) with ESMTP id D967A18543E for ; Mon, 20 Aug 2018 14:00:15 +0300 (MSK) Received: from smtp1j.mail.yandex.net (smtp1j.mail.yandex.net [2a02:6b8:0:801::ab]) by mxback6o.mail.yandex.net (nwsmtp/Yandex) with ESMTP id OTDacyTepK-0Fbqk5xA; Mon, 20 Aug 2018 14:00:15 +0300 Received: by smtp1j.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id x8w3cLDY5J-0Ftud8eK; Mon, 20 Aug 2018 14:00:15 +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: Mon, 20 Aug 2018 11:00:05 +0000 Message-Id: <1534762808-15588-9-git-send-email-odpbot@yandex.ru> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1534762808-15588-1-git-send-email-odpbot@yandex.ru> References: <1534762808-15588-1-git-send-email-odpbot@yandex.ru> Github-pr-num: 674 Subject: [lng-odp] [PATCH v3 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: b482f9618a6edb2a2f2491ee5a7af757eab93b24 **/ .../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)