From patchwork Thu Nov 9 12:00:12 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Github ODP bot X-Patchwork-Id: 118441 Delivered-To: patch@linaro.org Received: by 10.140.22.164 with SMTP id 33csp6505518qgn; Thu, 9 Nov 2017 04:07:18 -0800 (PST) X-Google-Smtp-Source: AGs4zMbWh7peGet9mKuE/UKM3KIgPOKrf0TuE0Ef+6gaZ/jQFYVtsw3Z4uJg9xbNCMhXq2g+dcge X-Received: by 10.200.33.199 with SMTP id 7mr347251qtz.35.1510229238874; Thu, 09 Nov 2017 04:07:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1510229238; cv=none; d=google.com; s=arc-20160816; b=h2UknLSF5UCxxxGm9v0vYU44547heattCoIFztuPmNcxhfiuIlW0r+eGuzQXVGn3Kk ei0pTDTsSDjX/MBrb66KroQtpGIEQ+qPlt1F4ac7Oo5KQR362Hel5FsOM6s0W/B0RMJd iWQ0hqNfI+C+AeCEzAmLLJfqDkxOzS1NzNKEYFjvnnCDuG7mJ2l0Qay/2W93EwgLSZtv R910B0c+qc4FQAR1RBWfz4eFvSA+Nj66SU6J4Pb4YdfVSKzOKEJH+z08D2BfmgZBrh15 ZIEfdBk1uEFyWX/c5CEKJoYnuurpOjsOZQt3+MKToyhE9AWXlEiJ7WBhbCeqYM1T9/Ed NSNw== 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=8kMOoQpf2EvEup3dRCrKMKpJKlc6g9CzLdOGFcuT3jY=; b=dv0xXgrJ99jo1Il67wktFUShXEBbVTNI7g1gfNjW17IY/jeLka5vVTsHP34zdSjAIZ WekWtuO2FUQ4ft0CrvFApfGhHTmG5RN5z/rZwdjR/ZiTElW1NPUeYUKfXnCmO7KiOb4K sL0en4wanIops3QY/YPzRSiFawSD8XmEv0ANL4EB4uciP/oP0/f6cCXdo36KdinIOyjt F3Yy2XrkHcdXR/WT6818WbEQl2fsSctbI8EDYntWz2tExgieEGkUWlbp5iS2r9Xogndw 5srij0X8v3XpEWI7WoTj2CesSpOSBMGBJQp1jeFLKd6wdyLNxs6NM8tHrqH3o+eqGmg/ pbVA== 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 w31si6239904qtb.74.2017.11.09.04.07.18; Thu, 09 Nov 2017 04:07:18 -0800 (PST) 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 8111260D77; Thu, 9 Nov 2017 12:07:18 +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=-5.4 required=5.0 tests=BAYES_00,FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, URIBL_BLOCKED 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 38E6C6100A; Thu, 9 Nov 2017 12:02:56 +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 F41EE60CCA; Thu, 9 Nov 2017 12:02:26 +0000 (UTC) Received: from forward106p.mail.yandex.net (forward106p.mail.yandex.net [77.88.28.109]) by lists.linaro.org (Postfix) with ESMTPS id 2FA6D60FFD for ; Thu, 9 Nov 2017 12:00:22 +0000 (UTC) Received: from mxback9g.mail.yandex.net (mxback9g.mail.yandex.net [IPv6:2a02:6b8:0:1472:2741:0:8b7:170]) by forward106p.mail.yandex.net (Yandex) with ESMTP id ADB972D84C8F for ; Thu, 9 Nov 2017 15:00:20 +0300 (MSK) Received: from smtp4o.mail.yandex.net (smtp4o.mail.yandex.net [2a02:6b8:0:1a2d::28]) by mxback9g.mail.yandex.net (nwsmtp/Yandex) with ESMTP id 4sHIrXqs6R-0KgKGLkP; Thu, 09 Nov 2017 15:00:20 +0300 Received: by smtp4o.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id bxb2c43GJ0-0JiCDXVj; Thu, 09 Nov 2017 15: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, 9 Nov 2017 15:00:12 +0300 Message-Id: <1510228814-21692-5-git-send-email-odpbot@yandex.ru> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1510228814-21692-1-git-send-email-odpbot@yandex.ru> References: <1510228814-21692-1-git-send-email-odpbot@yandex.ru> Github-pr-num: 273 Subject: [lng-odp] [PATCH API-NEXT v5 4/6] linux-gen: packet: add parse API 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: Petri Savolainen Implemented new API functions for packet parsing. Signed-off-by: Petri Savolainen --- /** Email created from pull request 273 (psavol:next-packet-parse) ** https://github.com/Linaro/odp/pull/273 ** Patch: https://github.com/Linaro/odp/pull/273.patch ** Base sha: d22c949cc466bf28de559855a1cb525740578137 ** Merge commit sha: 5ed52232b041f855c0e109143480b16ea467c7da **/ .../linux-generic/include/odp_packet_internal.h | 3 +- platform/linux-generic/odp_packet.c | 62 ++++++++++++++++++++-- 2 files changed, 60 insertions(+), 5 deletions(-) diff --git a/platform/linux-generic/include/odp_packet_internal.h b/platform/linux-generic/include/odp_packet_internal.h index fed562aa3..97efcec4b 100644 --- a/platform/linux-generic/include/odp_packet_internal.h +++ b/platform/linux-generic/include/odp_packet_internal.h @@ -322,8 +322,7 @@ static inline void packet_set_ts(odp_packet_hdr_t *pkt_hdr, odp_time_t *ts) } int packet_parse_common(packet_parser_t *pkt_hdr, const uint8_t *ptr, - uint32_t pkt_len, uint32_t seg_len, - odp_pktio_parser_layer_t layer); + uint32_t pkt_len, uint32_t seg_len, int layer); int _odp_cls_parse(odp_packet_hdr_t *pkt_hdr, const uint8_t *parseptr); diff --git a/platform/linux-generic/odp_packet.c b/platform/linux-generic/odp_packet.c index 3b2fac212..0bba30986 100644 --- a/platform/linux-generic/odp_packet.c +++ b/platform/linux-generic/odp_packet.c @@ -2098,8 +2098,7 @@ static inline int packet_parse_common_l3_l4(packet_parser_t *prs, const uint8_t *parseptr, uint32_t offset, uint32_t frame_len, uint32_t seg_len, - odp_pktio_parser_layer_t layer, - uint16_t ethtype) + int layer, uint16_t ethtype) { uint8_t ip_proto; @@ -2199,7 +2198,7 @@ int packet_parse_common_l3_l4(packet_parser_t *prs, const uint8_t *parseptr, */ int packet_parse_common(packet_parser_t *prs, const uint8_t *ptr, uint32_t frame_len, uint32_t seg_len, - odp_pktio_parser_layer_t layer) + int layer) { uint32_t offset; uint16_t ethtype; @@ -2252,6 +2251,63 @@ int packet_parse_l3_l4(odp_packet_hdr_t *pkt_hdr, layer, ethtype); } +int odp_packet_parse(odp_packet_t pkt, uint32_t offset, + const odp_packet_parse_param_t *param) +{ + odp_packet_hdr_t *pkt_hdr = packet_hdr(pkt); + void *data; + uint32_t seg_len; + uint32_t packet_len = pkt_hdr->frame_len; + odp_proto_t proto = param->proto; + odp_proto_layer_t layer = param->layer; + int ret; + uint16_t ethtype; + + if (proto == ODP_PROTO_NONE || layer == ODP_PROTO_LAYER_NONE) + return -1; + + data = packet_map(pkt_hdr, offset, &seg_len, NULL); + + if (data == NULL) + return -1; + + packet_parse_reset(pkt_hdr); + + if (proto == ODP_PROTO_ETH) { + ret = packet_parse_common(&pkt_hdr->p, data, packet_len, + seg_len, layer); + + if (ret) + return -1; + } else { + if (proto == ODP_PROTO_IPV4) + ethtype = _ODP_ETHTYPE_IPV4; + else + ethtype = _ODP_ETHTYPE_IPV6; + + ret = packet_parse_common_l3_l4(&pkt_hdr->p, data, offset, + packet_len, seg_len, + layer, ethtype); + + if (ret) + return -1; + } + + return 0; +} + +int odp_packet_parse_multi(const odp_packet_t pkt[], const uint32_t offset[], + int num, const odp_packet_parse_param_t *param) +{ + int i; + + for (i = 0; i < num; i++) + if (odp_packet_parse(pkt[i], offset[i], param)) + return i; + + return num; +} + uint64_t odp_packet_to_u64(odp_packet_t hdl) { return _odp_pri(hdl);