From patchwork Thu Jan 28 12:47:41 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bill Fischofer X-Patchwork-Id: 60727 Delivered-To: patch@linaro.org Received: by 10.112.130.2 with SMTP id oa2csp464607lbb; Thu, 28 Jan 2016 05:12:09 -0800 (PST) X-Received: by 10.140.19.148 with SMTP id 20mr3386788qgh.60.1453986729360; Thu, 28 Jan 2016 05:12:09 -0800 (PST) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id k102si12100640qgd.41.2016.01.28.05.12.09; Thu, 28 Jan 2016 05:12:09 -0800 (PST) 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; dkim=neutral (body hash did not verify) header.i=@linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id B167D6176E; Thu, 28 Jan 2016 13:12:08 +0000 (UTC) Authentication-Results: lists.linaro.org; dkim=fail reason="verification failed; unprotected key" header.d=linaro.org header.i=@linaro.org header.b=ekQ94p1o; dkim-adsp=none (unprotected policy); dkim-atps=neutral Received: from [127.0.0.1] (localhost [127.0.0.1]) by lists.linaro.org (Postfix) with ESMTP id 643B661981; Thu, 28 Jan 2016 13:00:43 +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 B5F4C61740; Thu, 28 Jan 2016 12:57:53 +0000 (UTC) Received: from mail-ob0-f172.google.com (mail-ob0-f172.google.com [209.85.214.172]) by lists.linaro.org (Postfix) with ESMTPS id 87F2061930 for ; Thu, 28 Jan 2016 12:47:53 +0000 (UTC) Received: by mail-ob0-f172.google.com with SMTP id wb13so1276902obb.1 for ; Thu, 28 Jan 2016 04:47:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=1Dl8NAR+BK4y1Veje3AYN8E7plyzFdiDRlqN54DxT3I=; b=ekQ94p1oPflPd7YTGyaQKf3FuaT7fpB6/1mvHay7yTsp2XtAJOokbA+3CtjRzdDymJ 6D/cb3bjShBXMqqqvLw7NUfHSPaV/P+/RnM1qW/pETsiqDpKvbGF/rkFJeqjQGpFCTWE cJ5j2Rw35uX2k6sDGSB/Q+rPs2N4iyyC7mo/Q= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=1Dl8NAR+BK4y1Veje3AYN8E7plyzFdiDRlqN54DxT3I=; b=YxKpxGGkrBT+OHAuYjGoMWo4kmjoW0pKeWSFyfC9qnsevWokxCgAIk23NpVkg9kfCJ xrVqJTWy+Ch2DYyWO7bh5Ry3Xb8bKyzF4Paxk6lDiT5irkT4cfI5xnD0WdY9C/gnKWNj b1bYRKzISQgnelbwiFSUIH3F/XppN1/V4LLDIqosy5rKAic/fnmvCd5Q+wX0483Y7+/c ZdWL1+k+SXV58SD+J4pjkUFkaykl0xJ58vqeO8Gi4+p7pLftHzYKgYhvsakUMKWvS050 LjeCk5Die0Dxq1eI7T7q7lx0PyT0ORU8EsMZRBeV/lVXFZ1lfMTfx8qUWuRhQbh0HmS1 ARFw== X-Gm-Message-State: AG10YOTyeWLCoWuYyJIvYtQf4ghdkq19JHk4qBAK9Ap1wHPqt1yMKg6QWRDRF7XKVGNP/6qLvWQ= X-Received: by 10.60.138.67 with SMTP id qo3mr1958068oeb.80.1453985273113; Thu, 28 Jan 2016 04:47:53 -0800 (PST) Received: from Ubuntu15.localdomain (cpe-66-68-129-43.austin.res.rr.com. [66.68.129.43]) by smtp.gmail.com with ESMTPSA id u18sm5343302oie.9.2016.01.28.04.47.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 28 Jan 2016 04:47:52 -0800 (PST) From: Bill Fischofer To: lng-odp@lists.linaro.org Date: Thu, 28 Jan 2016 06:47:41 -0600 Message-Id: <1453985264-3807-4-git-send-email-bill.fischofer@linaro.org> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1453985264-3807-1-git-send-email-bill.fischofer@linaro.org> References: <1453985264-3807-1-git-send-email-bill.fischofer@linaro.org> X-Topics: patch Subject: [lng-odp] [API-NEXT PATCHv4 3/6] linux-generic: packet: implement parser extensions for broadcast and multicast 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: , MIME-Version: 1.0 Errors-To: lng-odp-bounces@lists.linaro.org Sender: "lng-odp" Signed-off-by: Bill Fischofer --- platform/linux-generic/odp_packet.c | 41 +++++++++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 11 deletions(-) diff --git a/platform/linux-generic/odp_packet.c b/platform/linux-generic/odp_packet.c index db85b5e..a14135f 100644 --- a/platform/linux-generic/odp_packet.c +++ b/platform/linux-generic/odp_packet.c @@ -784,6 +784,7 @@ static inline uint8_t parse_ipv4(odp_packet_hdr_t *pkt_hdr, uint8_t ver = ODPH_IPV4HDR_VER(ipv4->ver_ihl); uint8_t ihl = ODPH_IPV4HDR_IHL(ipv4->ver_ihl); uint16_t frag_offset; + uint32_t dstaddr = odp_be_to_cpu_32(ipv4->dst_addr); pkt_hdr->l3_len = odp_be_to_cpu_16(ipv4->tot_len); @@ -809,6 +810,10 @@ static inline uint8_t parse_ipv4(odp_packet_hdr_t *pkt_hdr, if (odp_unlikely(ODPH_IPV4HDR_IS_FRAGMENT(frag_offset))) pkt_hdr->input_flags.ipfrag = 1; + /* Handle IPv4 broadcast / multicast */ + pkt_hdr->input_flags.ip_bcast = (dstaddr == 0xffffffff); + pkt_hdr->input_flags.ip_mcast = (dstaddr >> 28) == 0xd; + return ipv4->proto; } @@ -820,6 +825,7 @@ static inline uint8_t parse_ipv6(odp_packet_hdr_t *pkt_hdr, { const odph_ipv6hdr_t *ipv6 = (const odph_ipv6hdr_t *)*parseptr; const odph_ipv6hdr_ext_t *ipv6ext; + uint32_t dstaddr0 = odp_be_to_cpu_32(ipv6->dst_addr[0]); pkt_hdr->l3_len = odp_be_to_cpu_16(ipv6->payload_len); @@ -830,11 +836,14 @@ static inline uint8_t parse_ipv6(odp_packet_hdr_t *pkt_hdr, return 0; } + /* IPv6 broadcast / multicast flags */ + pkt_hdr->input_flags.ip_mcast = (dstaddr0 & 0xff000000) == 0xff000000; + pkt_hdr->input_flags.ip_bcast = 0; + /* Skip past IPv6 header */ *offset += sizeof(odph_ipv6hdr_t); *parseptr += sizeof(odph_ipv6hdr_t); - /* Skip past any IPv6 extension headers */ if (ipv6->next_hdr == ODPH_IPPROTO_HOPOPTS || ipv6->next_hdr == ODPH_IPPROTO_ROUTE) { @@ -850,7 +859,8 @@ static inline uint8_t parse_ipv6(odp_packet_hdr_t *pkt_hdr, ipv6ext->next_hdr == ODPH_IPPROTO_ROUTE) && *offset < pkt_hdr->frame_len); - if (*offset >= pkt_hdr->l3_offset + odp_be_to_cpu_16(ipv6->payload_len)) { + if (*offset >= pkt_hdr->l3_offset + + odp_be_to_cpu_16(ipv6->payload_len)) { pkt_hdr->error_flags.ip_err = 1; return 0; } @@ -938,23 +948,32 @@ int _odp_parse_common(odp_packet_hdr_t *pkt_hdr, const uint8_t *ptr) uint32_t offset, seglen; uint8_t ip_proto = 0; const uint8_t *parseptr; + uint16_t macaddr0, macaddr2, macaddr4; offset = sizeof(odph_ethhdr_t); if (packet_parse_l2_not_done(pkt_hdr)) packet_parse_l2(pkt_hdr); - if (ptr == NULL) { - eth = (odph_ethhdr_t *)packet_map(pkt_hdr, 0, &seglen); - parseptr = (const uint8_t *)ð->type; - ethtype = odp_be_to_cpu_16(*((const uint16_t *) - (const void *)parseptr)); + eth = ptr ? (const odph_ethhdr_t *)ptr : + (odph_ethhdr_t *)packet_map(pkt_hdr, 0, &seglen); + + /* Handle Ethernet broadcast/multicast addresses */ + macaddr0 = odp_be_to_cpu_16(*((const uint16_t *)(const void *)eth)); + pkt_hdr->input_flags.eth_mcast = (macaddr0 & 0x0100) == 0x0100; + + if (macaddr0 == 0xffff) { + macaddr2 = odp_be_to_cpu_16(*((const uint16_t *)eth + 1)); + macaddr4 = odp_be_to_cpu_16(*((const uint16_t *)eth + 2)); + pkt_hdr->input_flags.eth_bcast = + (macaddr2 == 0xffff) && (macaddr4 == 0xffff); } else { - eth = (const odph_ethhdr_t *)ptr; - parseptr = (const uint8_t *)ð->type; - ethtype = odp_be_to_cpu_16(*((const uint16_t *) - (const void *)parseptr)); + pkt_hdr->input_flags.eth_bcast = 0; } + /* Get Ethertype */ + parseptr = (const uint8_t *)ð->type; + ethtype = odp_be_to_cpu_16(*((const uint16_t *) + (const void *)parseptr)); /* Parse the VLAN header(s), if present */ if (ethtype == ODPH_ETHTYPE_VLAN_OUTER) {