From patchwork Tue Feb 9 15:00:28 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bill Fischofer X-Patchwork-Id: 61539 Delivered-To: patch@linaro.org Received: by 10.112.43.199 with SMTP id y7csp2094381lbl; Tue, 9 Feb 2016 07:02:44 -0800 (PST) X-Received: by 10.140.42.20 with SMTP id b20mr41649551qga.16.1455030163945; Tue, 09 Feb 2016 07:02:43 -0800 (PST) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id l62si36001282qhc.126.2016.02.09.07.02.43; Tue, 09 Feb 2016 07:02:43 -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 79019617C6; Tue, 9 Feb 2016 15:02:43 +0000 (UTC) Authentication-Results: lists.linaro.org; dkim=fail reason="verification failed; unprotected key" header.d=linaro.org header.i=@linaro.org header.b=CLzbG+h+; dkim-adsp=none (unprotected policy); dkim-atps=neutral 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.5 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, T_DKIM_INVALID, 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 802F461797; Tue, 9 Feb 2016 15:00:53 +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 CF7726178E; Tue, 9 Feb 2016 15:00:42 +0000 (UTC) Received: from mail-oi0-f53.google.com (mail-oi0-f53.google.com [209.85.218.53]) by lists.linaro.org (Postfix) with ESMTPS id 197CC6178E for ; Tue, 9 Feb 2016 15:00:40 +0000 (UTC) Received: by mail-oi0-f53.google.com with SMTP id s4so16373089oif.3 for ; Tue, 09 Feb 2016 07:00:40 -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=llu3z+TISQfqaehZFZI334YkzLkOyjYpdo0AgQwo+Yg=; b=CLzbG+h+aRSGvKfJCukfVI32wXnzzlCkcIJMzGg3xbh9CcOWIHg6aw8d8Zsk+sPcHy N7hTyYMr4oqnf4/3inlNqRcYeWOiLYqXoBruP2dqQV+m6Z7/5nyM3op/t2BKe1QBeG7T Kj36Dg4fJJwKwffzXVA5yR2s8WOmJqXqqhiqs= 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=llu3z+TISQfqaehZFZI334YkzLkOyjYpdo0AgQwo+Yg=; b=dowCKUakrH+tZ0bvSRgrmMpDaabkIOpqMqCgNIqSBJNPv9zzfHmzIXmBiWSni62vZG SBv7j7lcugV2IxGOd0tKwjpe6++9N0PCirCk+d7G2hox7kBcYXchTm2WNmci61HYd6MJ Q0yh94gmZ6RAta5zjN154Pooxs/AQMdc9hrq1hr3z8N6x64Fe88nBY/JWkRvsucBbSlD 3n/JKJRKb+58Qyl4dazYTQs4HVpdYELtnPG1AP6Hu2OKk+3KSNBiTz4H8uUOsCEh8kRo HwGFpHt+kPjXqYBOjst8Bxxeh3PvU1Gbe3eLF0oeh1oJmVzwBWK6JJZsGJJ9vkzSDjCh PAkA== X-Gm-Message-State: AG10YOThTlUKMVGp8UOEk6GBD/93N3CUbQPSpPTbJCFG0+nHEZ68O6FV1KLpx572bfWMDAzw3d4= X-Received: by 10.202.3.136 with SMTP id 130mr2472223oid.13.1455030039675; Tue, 09 Feb 2016 07:00:39 -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 k1sm20168269obz.22.2016.02.09.07.00.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 09 Feb 2016 07:00:39 -0800 (PST) From: Bill Fischofer To: lng-odp@lists.linaro.org Date: Tue, 9 Feb 2016 09:00:28 -0600 Message-Id: <1455030031-4495-4-git-send-email-bill.fischofer@linaro.org> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1455030031-4495-1-git-send-email-bill.fischofer@linaro.org> References: <1455030031-4495-1-git-send-email-bill.fischofer@linaro.org> X-Topics: patch Subject: [lng-odp] [API-NEXT PATCHv6 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 Reviewed-by: Petri Savolainen --- platform/linux-generic/odp_packet.c | 45 ++++++++++++++++++++++++++++--------- 1 file changed, 34 insertions(+), 11 deletions(-) diff --git a/platform/linux-generic/odp_packet.c b/platform/linux-generic/odp_packet.c index db85b5e..9b070a0 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,36 @@ 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 *) + (const void *)eth + 1)); + macaddr4 = + odp_be_to_cpu_16(*((const uint16_t *) + (const void *)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) {