From patchwork Tue Aug 1 07: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: 109104 Delivered-To: patch@linaro.org Received: by 10.140.101.6 with SMTP id t6csp1139061qge; Tue, 1 Aug 2017 00:00:55 -0700 (PDT) X-Received: by 10.200.40.10 with SMTP id 10mr26050433qtq.295.1501570855791; Tue, 01 Aug 2017 00:00:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1501570855; cv=none; d=google.com; s=arc-20160816; b=QAr28ct56VmQEBCQYzd/F69qM6fgoNkzt9vQd3FXe8ZFzeSxO8nqmGlJUM1UMGfwh9 K28hNQClfyWed3E9nOfyW1mprWqJUOvkpq9+pXtqCU2aWMbzvsIBkWdgt95YB8OMITsh g3RdS9kObE/Y1+Xk9Hrmkn4gqH5nfRW8CBODxnKhA6eD4WbEZxl1V44YypKGCUTTLrZV lFvqzj8lrWeOFMiDOeviOKHT5wLe//hYA4oxofUyanfc6k1PttYBjR8Clq2q0iaTlYl8 u0Iaa6Pr9n2fOTwbp/h1dEQ/JhU+e7V57DyUPEt1HDT6G44EXw5LuJPQxPrQiImyc0NF l1HQ== 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=XBLCovUe83ZXvg22Jt2jTwPhY/R8wxxhxa/G57u/wRM=; b=DPMQmTaMdIHNzBjv7Rx84vNX93eZ/Qg4aoU5rUvkfTTN2PVf1tK7hyykneNnoyEbCN SueTmtH5JZg5J4JzdwOZiZPl/7tZx0CaB40zZ8Jt6z1w8WRqyFw5M7NnDNbm+o67Dd6K YeIohv24oLpqJlXImYxXDkM0Siw9JHnsLPuGo8XzZIKXrZSSHpqY+JvLBMfY7r51exhv zfn1Rd+RyZ4g+HvcUsnIkKkjyVdF1RVdAcmX6fAQZIOxW/+gP0yxWPSA/Ddy6pllmnha U6hJlq4NLY4ZYwS1rnK7L1EgfFV6sudA6EMRqZkigTCDpiMqKavrUlKMbPR5j59Gj06L dehQ== 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 f4si14602376qtd.475.2017.08.01.00.00.54; Tue, 01 Aug 2017 00:00:55 -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 025A1609F2; Tue, 1 Aug 2017 07:00:53 +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 73D9C6085C; Tue, 1 Aug 2017 07:00:44 +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 8154360843; Tue, 1 Aug 2017 07:00:42 +0000 (UTC) Received: from forward1h.cmail.yandex.net (forward1h.cmail.yandex.net [87.250.230.16]) by lists.linaro.org (Postfix) with ESMTPS id C1F9365D1C for ; Tue, 1 Aug 2017 07:00:40 +0000 (UTC) Received: from smtp1p.mail.yandex.net (smtp1p.mail.yandex.net [IPv6:2a02:6b8:0:1472:2741:0:8b6:6]) by forward1h.cmail.yandex.net (Yandex) with ESMTP id DF9802112C for ; Tue, 1 Aug 2017 10:00:38 +0300 (MSK) Received: from smtp1p.mail.yandex.net (localhost.localdomain [127.0.0.1]) by smtp1p.mail.yandex.net (Yandex) with ESMTP id B98DE1780DB8 for ; Tue, 1 Aug 2017 10:00:32 +0300 (MSK) Received: by smtp1p.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id Ca8Lni7XUb-0VYqSULp; Tue, 01 Aug 2017 10:00:31 +0300 (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (Client certificate not present) X-Yandex-Suid-Status: 1 0 From: Github ODP bot To: lng-odp@lists.linaro.org Date: Tue, 1 Aug 2017 10:00:12 +0300 Message-Id: <1501570817-9260-4-git-send-email-odpbot@yandex.ru> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1501570817-9260-1-git-send-email-odpbot@yandex.ru> References: <1501570817-9260-1-git-send-email-odpbot@yandex.ru> Github-pr-num: 81 Subject: [lng-odp] [PATCH API-NEXT v11 3/8] linux-gen: packet: factor out L2 header parsing 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 Function parse_packet_common() now becomes just a multiplexer calling other low-level parsing functions. 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: c16f1363303cd5fc11324acbc4dfebe0a9680a41 ** Merge commit sha: 38d17798a2db32c26fbd413245d59dde8e3011d9 **/ platform/linux-generic/odp_packet.c | 139 ++++++++++++++++++++---------------- 1 file changed, 77 insertions(+), 62 deletions(-) diff --git a/platform/linux-generic/odp_packet.c b/platform/linux-generic/odp_packet.c index 88032cf2..1971fdc0 100644 --- a/platform/linux-generic/odp_packet.c +++ b/platform/linux-generic/odp_packet.c @@ -1746,6 +1746,78 @@ int _odp_packet_copy_md_to_packet(odp_packet_t srcpkt, odp_packet_t dstpkt) return dsthdr->buf_hdr.uarea_size < srchdr->buf_hdr.uarea_size; } +/** 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) +{ + uint16_t ethtype; + const _odp_ethhdr_t *eth; + uint16_t macaddr0, macaddr2, macaddr4; + const _odp_vlanhdr_t *vlan; + + /* Detect jumbo frames */ + if (frame_len > _ODP_ETH_LEN_MAX) + prs->input_flags.jumbo = 1; + + eth = (const _odp_ethhdr_t *)*parseptr; + + /* Handle Ethernet broadcast/multicast addresses */ + macaddr0 = odp_be_to_cpu_16(*((const uint16_t *)(const void *)eth)); + prs->input_flags.eth_mcast = (macaddr0 & 0x0100) == 0x0100; + + if (macaddr0 == 0xffff) { + macaddr2 = + odp_be_to_cpu_16(*((const uint16_t *) + (const void *)eth + 1)); + macaddr4 = + odp_be_to_cpu_16(*((const uint16_t *) + (const void *)eth + 2)); + prs->input_flags.eth_bcast = + (macaddr2 == 0xffff) && (macaddr4 == 0xffff); + } else { + prs->input_flags.eth_bcast = 0; + } + + /* Get Ethertype */ + ethtype = odp_be_to_cpu_16(eth->type); + *offset += sizeof(*eth); + *parseptr += sizeof(*eth); + + /* Check for SNAP vs. DIX */ + if (ethtype < _ODP_ETH_LEN_MAX) { + prs->input_flags.snap = 1; + if (ethtype > frame_len - *offset) { + prs->error_flags.snap_len = 1; + return 0; + } + ethtype = odp_be_to_cpu_16(*((const uint16_t *)(uintptr_t) + (parseptr + 6))); + *offset += 8; + *parseptr += 8; + } + + /* Parse the VLAN header(s), if present */ + if (ethtype == _ODP_ETHTYPE_VLAN_OUTER) { + prs->input_flags.vlan_qinq = 1; + prs->input_flags.vlan = 1; + + vlan = (const _odp_vlanhdr_t *)*parseptr; + ethtype = odp_be_to_cpu_16(vlan->type); + *offset += sizeof(_odp_vlanhdr_t); + *parseptr += sizeof(_odp_vlanhdr_t); + } + + if (ethtype == _ODP_ETHTYPE_VLAN) { + prs->input_flags.vlan = 1; + vlan = (const _odp_vlanhdr_t *)*parseptr; + ethtype = odp_be_to_cpu_16(vlan->type); + *offset += sizeof(_odp_vlanhdr_t); + *parseptr += sizeof(_odp_vlanhdr_t); + } + + return ethtype; +} + /** * Parser helper function for IPv4 */ @@ -1900,9 +1972,9 @@ int packet_parse_common(packet_parser_t *prs, const uint8_t *ptr, uint16_t ethtype; const uint8_t *parseptr; uint8_t ip_proto; - const _odp_ethhdr_t *eth; - uint16_t macaddr0, macaddr2, macaddr4; - const _odp_vlanhdr_t *vlan; + + parseptr = ptr; + offset = 0; if (layer == ODP_PKTIO_PARSER_LAYER_NONE) return 0; @@ -1911,65 +1983,8 @@ int packet_parse_common(packet_parser_t *prs, const uint8_t *ptr, prs->input_flags.eth = 1; /* Assume valid L2 header, no CRC/FCS check in SW */ prs->input_flags.l2 = 1; - /* Detect jumbo frames */ - if (frame_len > _ODP_ETH_LEN_MAX) - prs->input_flags.jumbo = 1; - - offset = sizeof(_odp_ethhdr_t); - eth = (const _odp_ethhdr_t *)ptr; - /* Handle Ethernet broadcast/multicast addresses */ - macaddr0 = odp_be_to_cpu_16(*((const uint16_t *)(const void *)eth)); - prs->input_flags.eth_mcast = (macaddr0 & 0x0100) == 0x0100; - - if (macaddr0 == 0xffff) { - macaddr2 = - odp_be_to_cpu_16(*((const uint16_t *) - (const void *)eth + 1)); - macaddr4 = - odp_be_to_cpu_16(*((const uint16_t *) - (const void *)eth + 2)); - prs->input_flags.eth_bcast = - (macaddr2 == 0xffff) && (macaddr4 == 0xffff); - } else { - prs->input_flags.eth_bcast = 0; - } - - /* Get Ethertype */ - ethtype = odp_be_to_cpu_16(eth->type); - parseptr = (const uint8_t *)(eth + 1); - - /* Check for SNAP vs. DIX */ - if (ethtype < _ODP_ETH_LEN_MAX) { - prs->input_flags.snap = 1; - if (ethtype > frame_len - offset) { - prs->error_flags.snap_len = 1; - goto parse_exit; - } - ethtype = odp_be_to_cpu_16(*((const uint16_t *)(uintptr_t) - (parseptr + 6))); - offset += 8; - parseptr += 8; - } - - /* Parse the VLAN header(s), if present */ - if (ethtype == _ODP_ETHTYPE_VLAN_OUTER) { - prs->input_flags.vlan_qinq = 1; - prs->input_flags.vlan = 1; - - vlan = (const _odp_vlanhdr_t *)parseptr; - ethtype = odp_be_to_cpu_16(vlan->type); - offset += sizeof(_odp_vlanhdr_t); - parseptr += sizeof(_odp_vlanhdr_t); - } - - if (ethtype == _ODP_ETHTYPE_VLAN) { - prs->input_flags.vlan = 1; - vlan = (const _odp_vlanhdr_t *)parseptr; - ethtype = odp_be_to_cpu_16(vlan->type); - offset += sizeof(_odp_vlanhdr_t); - parseptr += sizeof(_odp_vlanhdr_t); - } + ethtype = parse_eth(prs, &parseptr, &offset, frame_len); if (layer == ODP_PKTIO_PARSER_LAYER_L2) return prs->error_flags.all != 0; @@ -2051,7 +2066,7 @@ int packet_parse_common(packet_parser_t *prs, const uint8_t *ptr, prs->l4_offset = ODP_PACKET_OFFSET_INVALID; break; } -parse_exit: + return prs->error_flags.all != 0; }