From patchwork Thu Sep 7 11:00:19 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: 111879 Delivered-To: patch@linaro.org Received: by 10.140.94.239 with SMTP id g102csp647162qge; Thu, 7 Sep 2017 04:10:02 -0700 (PDT) X-Google-Smtp-Source: ADKCNb5+sM60ljbxBZbHR75Xlj8NvvrSDo8oSO/JNjY2n8nvKgpvDodv+VEdcAB7lpqauQkHoakB X-Received: by 10.237.62.176 with SMTP id n45mr3019590qtf.302.1504782602780; Thu, 07 Sep 2017 04:10:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1504782602; cv=none; d=google.com; s=arc-20160816; b=eTBc0bKq8MMPcHxC6jRjhYg7OC5PeX1jgauaudwCAP6eo6TtCMnx2wkKBteILqWUtq foSA7JU7EnKudlxtU1eZgPRkz9pjUWhQLacN2zIjORlcvxH8nJAo4f290d7CpKVNRILG lwBDFVS9YaoA1nLNr93TK1bqgslwCrbW0EAtb/DjRT880uBZWHbbeAl7VX/DLNkjPNEU 8NCqI/1agXSqqOvONrIblxhslb7ksenAkpkljRHGTe9m11CIzVI258o+RKoHfpxfUjeN vPEjNZP0gYwb5+wnQ4Jw3hcT3xPNpdbnfKYNYyto4+XqBvHZtXb9teRnPvkBZYNffu81 SdMA== 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=6TElfrJ9esgAynQBPw8QAv0MQyEVBlFOcgqNBcPh/Xs=; b=n/GzcP7kNFrg4/oHjcteptvhBAKMZbVxfeoYPScnhASKv4cD0rX5gq6YXUP7skySsn FiY32vqDGxHOm4vHIJ3L33G8R3uql3gpxZlw6MhNG3zVlZDSIPynjUtUW6imv6j4+2CI sU5HAoxEuhLvhSfFrEg0yDwgXgAESTM4B4Bqh/I1dD4fzv6z0LVAMbyHUa1amMeDdxPQ kSeqCDkD5cBSyNFiToUKLMzziyThNEVFX8wY0lb11vM6KPxUTqej2GjGgBuhh3Mcnjhg CuxDgAaBsQcPN0CEtsG7+efqZXeYmNo2nl+OTsVrTU/lvX/voG2ftWAPNb+8jzu9j6KW 6Tww== 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 z33si2655293qtg.282.2017.09.07.04.10.02; Thu, 07 Sep 2017 04:10:02 -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 3AB51644B9; Thu, 7 Sep 2017 11:10:02 +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=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,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 14A84644BB; Thu, 7 Sep 2017 11:02:21 +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 A3167636A2; Thu, 7 Sep 2017 11:01:45 +0000 (UTC) Received: from forward106o.mail.yandex.net (forward106o.mail.yandex.net [37.140.190.187]) by lists.linaro.org (Postfix) with ESMTPS id ABE6460D78 for ; Thu, 7 Sep 2017 11:00:50 +0000 (UTC) Received: from mxback16j.mail.yandex.net (mxback16j.mail.yandex.net [IPv6:2a02:6b8:0:1619::92]) by forward106o.mail.yandex.net (Yandex) with ESMTP id 3C1D778637C for ; Thu, 7 Sep 2017 14:00:49 +0300 (MSK) Received: from smtp1o.mail.yandex.net (smtp1o.mail.yandex.net [2a02:6b8:0:1a2d::25]) by mxback16j.mail.yandex.net (nwsmtp/Yandex) with ESMTP id iVh5tMell6-0nU4FO8M; Thu, 07 Sep 2017 14:00:49 +0300 Received: by smtp1o.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id r5PzEbFEu0-0mde7Itc; Thu, 07 Sep 2017 14:00:48 +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, 7 Sep 2017 14:00:19 +0300 Message-Id: <1504782024-26631-5-git-send-email-odpbot@yandex.ru> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1504782024-26631-1-git-send-email-odpbot@yandex.ru> References: <1504782024-26631-1-git-send-email-odpbot@yandex.ru> Github-pr-num: 81 Subject: [lng-odp] [PATCH API-NEXT v16 4/9] 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: 7fa8e2c97ed18f8dd6e95cbc78b7e668ccb98869 ** Merge commit sha: d0f4ea10655492b00c1a40e85a0ba837f06f97c5 **/ 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 bb0f2b89..2038f60d 100644 --- a/platform/linux-generic/odp_packet.c +++ b/platform/linux-generic/odp_packet.c @@ -2120,6 +2120,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 */ @@ -2274,9 +2346,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; @@ -2285,65 +2357,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; @@ -2425,7 +2440,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; }