From patchwork Thu Aug 16 10:00:03 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: 144343 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp1871130ljj; Thu, 16 Aug 2018 03:04:16 -0700 (PDT) X-Google-Smtp-Source: AA+uWPwcuGA9TLVKwN7s59q6PEqlr3vmchrshBKYxejWhtRGEzvNaZFXTsuZeSHnrpg9eS2t2gqu X-Received: by 2002:a37:b887:: with SMTP id i129-v6mr26877958qkf.310.1534413856450; Thu, 16 Aug 2018 03:04:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534413856; cv=none; d=google.com; s=arc-20160816; b=wLzvEStSUTqGUSnMGrL6iXkme1eqMLQ6oBsFgQREyDldnPZoOo7HWT0Yu8uTC5qj34 KBk4RmNOdIRVKNn1ynN76veVILqHY0mRexNFbEoAZM3vUhNAA5+JlQlQaTR5yKUoCSkl DYCggGEyjKaMzSCM7BW4HFsbzZmOvHX/R4h63uojJe2MToE7Ktwl5ZC9rOv83Wg9/8Nx ED/gkDAmJEpRIacalf99VF1jvKzUG86mBtfqP3SdkJVjV/1JKdstzuaXXqypcflGN+Ya NOY+fhdv0Yid/A8H6cCm9ShLcZzsUSRrRy2dEJ63ZMjeewi1vXrwJiFZPwd7cP9C/u/W hl/w== 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=4AmmBWeu0aSsjpkYe2ZAHcSllzZzGnhiS1KBs2v8DZY=; b=PR+WpVX4fkp8XnGAL11UVyoB6pMts6/Tv+7gD68Ukwid8vDLwOFrk7g1V6y8qHjYeM PU8DWGbwo8Hw+0GDw66s1pqjh9tPYVG99CGC97QkRBsaDcHTpGkq3zsoWo4tvqs1/0l8 sAYSZ3M98OFY6J0LCLk9O6yEupHUdsRkC8cjiTCdjqCFN2QmA23DJK2Xa/xWc/pswH5b 2q6T2hBqjB5ptKQhPHWy24XbxO9fZwFcHxckZlf9xcCs1VrXwisc6KbqvK6m4Q/u3FAP EL2lnlsLfMhPP7gTM79kcpR2DiQCbTv+VtdOF030fJspWWYFhFIfza2NqFH1c5KDyq8N YQEA== 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 o127-v6si1267501qkf.68.2018.08.16.03.04.16; Thu, 16 Aug 2018 03:04:16 -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 22BF96862E; Thu, 16 Aug 2018 10:04:16 +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 137BC6863B; Thu, 16 Aug 2018 10:01:49 +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 9376168621; Thu, 16 Aug 2018 10:01:31 +0000 (UTC) Received: from forward104j.mail.yandex.net (forward104j.mail.yandex.net [5.45.198.247]) by lists.linaro.org (Postfix) with ESMTPS id EFC0B60730 for ; Thu, 16 Aug 2018 10:00:21 +0000 (UTC) Received: from mxback9o.mail.yandex.net (mxback9o.mail.yandex.net [IPv6:2a02:6b8:0:1a2d::23]) by forward104j.mail.yandex.net (Yandex) with ESMTP id 6876944076 for ; Thu, 16 Aug 2018 13:00:20 +0300 (MSK) Received: from smtp1p.mail.yandex.net (smtp1p.mail.yandex.net [2a02:6b8:0:1472:2741:0:8b6:6]) by mxback9o.mail.yandex.net (nwsmtp/Yandex) with ESMTP id M4F534k9Ej-0K1W1smu; Thu, 16 Aug 2018 13:00:20 +0300 Received: by smtp1p.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id LpjbZWHmdB-0JreuF2V; Thu, 16 Aug 2018 13:00:19 +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:03 +0000 Message-Id: <1534413607-8630-8-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 7/11] linux-gen: packet: parse SCTP packets and verify checksum 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 Verify SCTP packet checksums. Use CRC32-c as requied by RFC3309 instead of original Adler-32. 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 **/ .../odp/api/plat/packet_inline_types.h | 7 +-- platform/linux-generic/odp_packet.c | 54 +++++++++++++++++++ 2 files changed, 58 insertions(+), 3 deletions(-) diff --git a/platform/linux-generic/include/odp/api/plat/packet_inline_types.h b/platform/linux-generic/include/odp/api/plat/packet_inline_types.h index 9a285fe4a..255102988 100644 --- a/platform/linux-generic/include/odp/api/plat/packet_inline_types.h +++ b/platform/linux-generic/include/odp/api/plat/packet_inline_types.h @@ -111,7 +111,7 @@ typedef union { uint32_t all_flags; struct { - uint32_t reserved1: 11; + uint32_t reserved1: 10; /* * Init flags @@ -135,6 +135,7 @@ typedef union { uint32_t l3_chksum_err: 1; /* L3 checksum error */ uint32_t tcp_err: 1; /* TCP error */ uint32_t udp_err: 1; /* UDP error */ + uint32_t sctp_err: 1; /* SCTP error */ uint32_t l4_chksum_err: 1; /* L4 checksum error */ uint32_t ipsec_err: 1; /* IPsec error */ uint32_t crypto_err: 1; /* Crypto packet operation error */ @@ -142,9 +143,9 @@ typedef union { /* Flag groups */ struct { - uint32_t reserved2: 11; + uint32_t reserved2: 10; uint32_t other: 13; /* All other flags */ - uint32_t error: 8; /* All error flags */ + uint32_t error: 9; /* All error flags */ } all; } _odp_packet_flags_t; diff --git a/platform/linux-generic/odp_packet.c b/platform/linux-generic/odp_packet.c index 11f8bd43d..885aec8d8 100644 --- a/platform/linux-generic/odp_packet.c +++ b/platform/linux-generic/odp_packet.c @@ -22,6 +22,7 @@ #include #include +#include #include #include @@ -2298,6 +2299,34 @@ static inline void parse_udp(packet_parser_t *prs, const uint8_t **parseptr, *parseptr += sizeof(_odp_udphdr_t); } +/** + * Parser helper function for SCTP + */ +static inline void parse_sctp(packet_parser_t *prs, const uint8_t **parseptr, + uint16_t sctp_len, + odp_proto_chksums_t chksums, + uint32_t *l4_part_sum) +{ + if (odp_unlikely(sctp_len < sizeof(_odp_sctphdr_t))) { + prs->flags.sctp_err = 1; + return; + } + + if (chksums.chksum.sctp && + !prs->input_flags.ipfrag) { + const _odp_sctphdr_t *sctp = + (const _odp_sctphdr_t *)*parseptr; + uint32_t crc = ~0; + uint32_t zero = 0; + + crc = odp_hash_crc32c(sctp, sizeof(*sctp) - 4, crc); + crc = odp_hash_crc32c(&zero, 4, crc); + *l4_part_sum = crc; + } + + *parseptr += sizeof(_odp_sctphdr_t); +} + static inline int packet_parse_common_l3_l4(packet_parser_t *prs, const uint8_t *parseptr, uint32_t offset, @@ -2388,6 +2417,8 @@ int packet_parse_common_l3_l4(packet_parser_t *prs, const uint8_t *parseptr, case _ODP_IPPROTO_SCTP: prs->input_flags.sctp = 1; + parse_sctp(prs, &parseptr, frame_len - prs->l4_offset, chksums, + l4_part_sum); break; case _ODP_IPPROTO_NO_NEXT: @@ -2626,6 +2657,29 @@ static int packet_l4_chksum(odp_packet_hdr_t *pkt_hdr, } } + if (chksums.chksum.sctp && + pkt_hdr->p.input_flags.sctp && + !pkt_hdr->p.input_flags.ipfrag) { + uint32_t sum = ~packet_sum_crc32c(pkt_hdr, + pkt_hdr->p.l4_offset + + _ODP_SCTPHDR_LEN, + pkt_hdr->frame_len - + pkt_hdr->p.l4_offset - + _ODP_SCTPHDR_LEN, + l4_part_sum); + _odp_sctphdr_t *sctp = packet_map(pkt_hdr, + pkt_hdr->p.l4_offset, + NULL, NULL); + + pkt_hdr->p.input_flags.l4_chksum_done = 1; + if (sum != sctp->chksum) { + pkt_hdr->p.flags.l4_chksum_err = 1; + pkt_hdr->p.flags.sctp_err = 1; + ODP_DBG("SCTP chksum fail (%x/%x)!\n", sum, + sctp->chksum); + } + } + return pkt_hdr->p.flags.all_flags != 0; }