From patchwork Mon Sep 25 22:00:23 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: 114193 Delivered-To: patch@linaro.org Received: by 10.140.106.117 with SMTP id d108csp3116026qgf; Mon, 25 Sep 2017 15:15:59 -0700 (PDT) X-Google-Smtp-Source: AOwi7QDjQXyJSWDF+4z4F0hGKk2fS804BgabrqD7gRNvGmYc67aOW0Ec7esPblAPQgnWEqrkd4iR X-Received: by 10.107.181.196 with SMTP id e187mr11515108iof.178.1506377758956; Mon, 25 Sep 2017 15:15:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1506377758; cv=none; d=google.com; s=arc-20160816; b=hVYU92zhA8sogOWbPNECOpeD9mIlOCUWc2Q7B9gzKZ2k0KFPCfskms9DSy84GYg1nd srU4Vc40hOIDfhzfXEZ9hcReUZK3sRSA/haUidMYM7cc9lbs0xbFEoeVqQ2olSTFO7QM sGkR81EknbUR1IXSHQh46nSYL/89Iox/lKta8FffKbHZQDkqUGPcZlSkZSJ+1VvMR6kf Bgs5OhyJbQMN7kNSSTDmk0iTGkVuuzWBsYJYjtkrCm0PWUIr5mChS7LQQiUvvdFsA159 CLFjLZR6ODsgPdTfJbDS8982U8hTV3Je+YR57447TZFC4QT22RC1Jd204jBt9oQ7gnmn FBvA== 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=7uB44XJzvGvfZd7ojKHRO0HxZ5QXvRSb4gfZaxKHOFw=; b=alSczguThBGWOsQ6lWdHflVX05ojahOprOJ9HcIkNzmUD3Sbhvw9gNxUJISv6sQwO0 ak4bcULbtYarzxfzsTlI/Xeb3Xdfjy52ZRRiBUi3rr0YVB8xVYAzPqIiIrsiv6yQrer9 tFl7fDiTb6MjhJr6y5f4AvxF5sh1SrsFIS1p1WXA6ZkXr9aGWzcDDc0HTdDZMDGy4uBf Zc/HWDf46xTrQUztQtDWYns7p0tgU6/6uUf8+ROWV4mX1EQn4G8JOU80lW8wupwqu96I 0xn3iwrbE4S4KCSEEYXYP9XBfx29cSEwaSUIZl5z/UomrFD5f7D6obTax8+7sOaRVdvU 3nwQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 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 (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id t125si423927itg.166.2017.09.25.15.15.55; Mon, 25 Sep 2017 15:15:58 -0700 (PDT) Received-SPF: pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) client-ip=54.225.227.206; Authentication-Results: mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 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 AF6BE60B59; Mon, 25 Sep 2017 22:15:55 +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=-2.6 required=5.0 tests=BAYES_00,FREEMAIL_FROM, RCVD_IN_DNSWL_LOW,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 49FB360AF4; Mon, 25 Sep 2017 22:03:36 +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 D4AEE607E6; Mon, 25 Sep 2017 22:03: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 828D06071B for ; Mon, 25 Sep 2017 22:01:29 +0000 (UTC) Received: from mxback18j.mail.yandex.net (mxback18j.mail.yandex.net [IPv6:2a02:6b8:0:1619::94]) by forward106p.mail.yandex.net (Yandex) with ESMTP id 065B52D83959 for ; Tue, 26 Sep 2017 01:01:28 +0300 (MSK) Received: from smtp2o.mail.yandex.net (smtp2o.mail.yandex.net [2a02:6b8:0:1a2d::26]) by mxback18j.mail.yandex.net (nwsmtp/Yandex) with ESMTP id aUiPcOoGZI-1R4eHgRV; Tue, 26 Sep 2017 01:01:27 +0300 Received: by smtp2o.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id y0gxWEywlF-1R4OOiUh; Tue, 26 Sep 2017 01:01:27 +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, 26 Sep 2017 01:00:23 +0300 Message-Id: <1506376827-27848-6-git-send-email-odpbot@yandex.ru> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1506376827-27848-1-git-send-email-odpbot@yandex.ru> References: <1506376827-27848-1-git-send-email-odpbot@yandex.ru> Github-pr-num: 81 Subject: [lng-odp] [PATCH API-NEXT v19 5/9] linux-gen: packet: support parsing of just L3/L4 headers 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 IPsec packet postprocessing needs parsing of packets which guarantee only L3/L4 headers. Separate parsing function doing L3/L4 headers parsing. Signed-off-by: Dmitry Eremin-Solenikov --- /** Email created from pull request 81 (lumag:ipsec-packet-impl-2) ** https://github.com/Linaro/odp/pull/81 ** Patch: https://github.com/Linaro/odp/pull/81.patch ** Base sha: 13322ca632f8ffba292bec058e597719bc54142d ** Merge commit sha: 04f37d8f29d26df3744151a85a19ef9b55b3d1f7 **/ .../linux-generic/include/odp_packet_internal.h | 6 ++ platform/linux-generic/odp_packet.c | 83 +++++++++++++++------- 2 files changed, 62 insertions(+), 27 deletions(-) diff --git a/platform/linux-generic/include/odp_packet_internal.h b/platform/linux-generic/include/odp_packet_internal.h index 097264236..e29e7e85f 100644 --- a/platform/linux-generic/include/odp_packet_internal.h +++ b/platform/linux-generic/include/odp_packet_internal.h @@ -279,6 +279,12 @@ int packet_alloc_multi(odp_pool_t pool_hdl, uint32_t len, int packet_parse_layer(odp_packet_hdr_t *pkt_hdr, odp_pktio_parser_layer_t layer); +/* Perform L3 and L4 parsing up to a given protocol layer */ +int packet_parse_l3_l4(odp_packet_hdr_t *pkt_hdr, + odp_pktio_parser_layer_t layer, + uint32_t l3_offset, + uint16_t ethtype); + /* Reset parser metadata for a new parse */ void packet_parse_reset(odp_packet_hdr_t *pkt_hdr); diff --git a/platform/linux-generic/odp_packet.c b/platform/linux-generic/odp_packet.c index 515a5e169..2208614c6 100644 --- a/platform/linux-generic/odp_packet.c +++ b/platform/linux-generic/odp_packet.c @@ -330,7 +330,7 @@ void packet_parse_reset(odp_packet_hdr_t *pkt_hdr) pkt_hdr->p.error_flags.all = 0; pkt_hdr->p.input_flags.all = 0; pkt_hdr->p.output_flags.all = 0; - pkt_hdr->p.l2_offset = 0; + pkt_hdr->p.l2_offset = ODP_PACKET_OFFSET_INVALID; pkt_hdr->p.l3_offset = ODP_PACKET_OFFSET_INVALID; pkt_hdr->p.l4_offset = ODP_PACKET_OFFSET_INVALID; } @@ -2006,35 +2006,16 @@ static inline void parse_udp(packet_parser_t *prs, *parseptr += sizeof(_odp_udphdr_t); } -/** - * Parse common packet headers up to given layer - * - * The function expects at least PACKET_PARSE_SEG_LEN bytes of data to be - * available from the ptr. - */ -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) +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) { - uint32_t offset; - uint16_t ethtype; - const uint8_t *parseptr; uint8_t ip_proto; - parseptr = ptr; - offset = 0; - - if (layer == ODP_PKTIO_PARSER_LAYER_NONE) - return 0; - - /* We only support Ethernet for now */ - prs->input_flags.eth = 1; - /* Assume valid L2 header, no CRC/FCS check in SW */ - prs->input_flags.l2 = 1; - - ethtype = parse_eth(prs, &parseptr, &offset, frame_len); - - if (layer == ODP_PKTIO_PARSER_LAYER_L2) + if (layer <= ODP_PKTIO_PARSER_LAYER_L2) return prs->error_flags.all != 0; /* Set l3_offset+flag only for known ethtypes */ @@ -2119,6 +2100,38 @@ int packet_parse_common(packet_parser_t *prs, const uint8_t *ptr, } /** + * Parse common packet headers up to given layer + * + * The function expects at least PACKET_PARSE_SEG_LEN bytes of data to be + * available from the ptr. + */ +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) +{ + uint32_t offset; + uint16_t ethtype; + const uint8_t *parseptr; + + parseptr = ptr; + offset = 0; + + if (layer == ODP_PKTIO_PARSER_LAYER_NONE) + return 0; + + /* Assume valid L2 header, no CRC/FCS check in SW */ + prs->l2_offset = offset; + prs->input_flags.l2 = 1; + /* We only support Ethernet for now */ + prs->input_flags.eth = 1; + + ethtype = parse_eth(prs, &parseptr, &offset, frame_len); + + return packet_parse_common_l3_l4(prs, parseptr, offset, frame_len, + seg_len, layer, ethtype); +} + +/** * Simple packet parser */ int packet_parse_layer(odp_packet_hdr_t *pkt_hdr, @@ -2131,6 +2144,22 @@ int packet_parse_layer(odp_packet_hdr_t *pkt_hdr, seg_len, layer); } +int packet_parse_l3_l4(odp_packet_hdr_t *pkt_hdr, + odp_pktio_parser_layer_t layer, + uint32_t l3_offset, + uint16_t ethtype) +{ + uint32_t seg_len = 0; + void *base = packet_map(pkt_hdr, l3_offset, &seg_len, NULL); + + if (seg_len == 0) + return -1; + + return packet_parse_common_l3_l4(&pkt_hdr->p, base, l3_offset, + pkt_hdr->frame_len, seg_len, + layer, ethtype); +} + uint64_t odp_packet_to_u64(odp_packet_t hdl) { return _odp_pri(hdl);