From patchwork Mon Apr 20 16:27:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 220934 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.6 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 787FEC3815B for ; Mon, 20 Apr 2020 16:28:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 56A192074F for ; Mon, 20 Apr 2020 16:28:03 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="sUu/rdHw" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729526AbgDTQ2C (ORCPT ); Mon, 20 Apr 2020 12:28:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39858 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1729168AbgDTQ1w (ORCPT ); Mon, 20 Apr 2020 12:27:52 -0400 Received: from mail-wr1-x441.google.com (mail-wr1-x441.google.com [IPv6:2a00:1450:4864:20::441]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 52F4EC061A0F for ; Mon, 20 Apr 2020 09:27:52 -0700 (PDT) Received: by mail-wr1-x441.google.com with SMTP id i10so12933894wrv.10 for ; Mon, 20 Apr 2020 09:27:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=kq+6zKl2kH0cdZeUWR+SDjo+s3qmvpnmlPh76+3u24A=; b=sUu/rdHw/fPlEmCW1DlreiCrXdxVfLYW0KZbW7Df5zDdNRAEnAX1TTi1jcmy6Txzxh 9mVhvxQaeABcmqqgXJKIhFJeF2kw6SMS3oBs+SJBrfq4SjebvBRx6expuOJJXrpRhUge GAxPdvQnC6KRLKaOyMYPa6bdKr03YEEdXjLY8Itrmu+hhtNAQ21DunjMJTHrjl/IYxBg 0JjqlTiT9rI9R4eRE+gsXP6hKjQLZMUcv/VLiaG2xe0UYhzXcSD8c1RIYiWnbYYM0B9T 75Q8Si4JKe9bTqEKWXJXy+zrmNxXyVYrJH0/Ckw6Jb7Kuzdz8unfPG1ZVMp3tFVvKm5+ 5Qxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=kq+6zKl2kH0cdZeUWR+SDjo+s3qmvpnmlPh76+3u24A=; b=QJG4pPCVfPPmNPLFpJ98R3eW1UDSzkdj3BcsXvRl3XENB2YcO2fl+A1iA2WfkRY9Vj /bkQ8GLVDF95f2FcqaZ8H0AqdKRKa3OFt6bzmcQDIpo3sRliHsgnsII/tVUf99QNSu0O AnRc0L7K527m5OgbGHgm+fsdzme3TfJeGKOwON6lYlbdWnhvd+N7GJbOUQAMxp0uiFyW 7kA96qiZ42eUH1bFeWgBMEwhCxX/hG8MGQCGnTtHYCKYVJEh13BA0ptaMUka0lNOKTPv izUkILN9yLLHxm3AJHOGIRdFLHN/C2+GMj7ZEVBs2iF6xihhruyHoUxlqSTKwqzuf6FE vUoA== X-Gm-Message-State: AGi0PuYWjp+g24p9tAvyTmHLrqxhUVxM/Lpg7xh5A6sTsJ8E7LatZOzs i1/OT/20MxUDYyzHZQJXebE= X-Google-Smtp-Source: APiQypLtN3fyAoDN56PPKCcsFprDwsZGCurPqycAuOEFxWwwjyT0jWc/OkZr4LAn7ekLNxJ/cW5LXg== X-Received: by 2002:a5d:690a:: with SMTP id t10mr17758757wru.225.1587400071054; Mon, 20 Apr 2020 09:27:51 -0700 (PDT) Received: from localhost.localdomain ([188.25.102.96]) by smtp.gmail.com with ESMTPSA id 185sm146245wmc.32.2020.04.20.09.27.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Apr 2020 09:27:50 -0700 (PDT) From: Vladimir Oltean To: davem@davemloft.net, netdev@vger.kernel.org Cc: idosch@idosch.org, allan.nielsen@microchip.com, horatiu.vultur@microchip.com, alexandre.belloni@bootlin.com, antoine.tenart@bootlin.com, andrew@lunn.ch, f.fainelli@gmail.com, vivien.didelot@gmail.com, joergen.andreasen@microchip.com, claudiu.manoil@nxp.com, UNGLinuxDriver@microchip.com, alexandru.marginean@nxp.com, xiaoliang.yang_1@nxp.com, yangbo.lu@nxp.com, po.liu@nxp.com, jiri@mellanox.com, kuba@kernel.org Subject: [PATCH net-next 1/3] net: mscc: ocelot: support matching on EtherType Date: Mon, 20 Apr 2020 19:27:41 +0300 Message-Id: <20200420162743.15847-2-olteanv@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200420162743.15847-1-olteanv@gmail.com> References: <20200420162743.15847-1-olteanv@gmail.com> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Vladimir Oltean Currently, the filter's protocol is ignored except for a few special cases (IPv4 and IPv6). The EtherType can be matched inside VCAP IS2 by using a MAC_ETYPE key. So there are 2 cases in which EtherType matches are supported: - As part of a larger MAC_ETYPE rule, such as: tc filter add dev swp0 ingress protocol ip \ flower skip_sw src_mac 42:be:24:9b:76:20 action drop - Standalone (matching on protocol only): tc filter add dev swp0 ingress protocol arp \ flower skip_sw action drop As before, if the protocol is not specified, is it implicitly "all" and the EtherType mask in the MAC_ETYPE half key is set to zero. Signed-off-by: Vladimir Oltean --- drivers/net/ethernet/mscc/ocelot_flower.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/drivers/net/ethernet/mscc/ocelot_flower.c b/drivers/net/ethernet/mscc/ocelot_flower.c index 954cb67eeaa2..67f0f5455ff0 100644 --- a/drivers/net/ethernet/mscc/ocelot_flower.c +++ b/drivers/net/ethernet/mscc/ocelot_flower.c @@ -51,6 +51,8 @@ static int ocelot_flower_parse(struct flow_cls_offload *f, { struct flow_rule *rule = flow_cls_offload_flow_rule(f); struct flow_dissector *dissector = rule->match.dissector; + u16 proto = ntohs(f->common.protocol); + bool match_protocol = true; if (dissector->used_keys & ~(BIT(FLOW_DISSECTOR_KEY_CONTROL) | @@ -71,7 +73,6 @@ static int ocelot_flower_parse(struct flow_cls_offload *f, if (flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_ETH_ADDRS)) { struct flow_match_eth_addrs match; - u16 proto = ntohs(f->common.protocol); /* The hw support mac matches only for MAC_ETYPE key, * therefore if other matches(port, tcp flags, etc) are added @@ -114,6 +115,7 @@ static int ocelot_flower_parse(struct flow_cls_offload *f, match.key->ip_proto; ace->frame.ipv4.proto.mask[0] = match.mask->ip_proto; + match_protocol = false; } if (ntohs(match.key->n_proto) == ETH_P_IPV6) { ace->type = OCELOT_ACE_TYPE_IPV6; @@ -121,11 +123,12 @@ static int ocelot_flower_parse(struct flow_cls_offload *f, match.key->ip_proto; ace->frame.ipv6.proto.mask[0] = match.mask->ip_proto; + match_protocol = false; } } if (flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_IPV4_ADDRS) && - ntohs(f->common.protocol) == ETH_P_IP) { + proto == ETH_P_IP) { struct flow_match_ipv4_addrs match; u8 *tmp; @@ -141,10 +144,11 @@ static int ocelot_flower_parse(struct flow_cls_offload *f, tmp = &ace->frame.ipv4.dip.mask.addr[0]; memcpy(tmp, &match.mask->dst, 4); + match_protocol = false; } if (flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_IPV6_ADDRS) && - ntohs(f->common.protocol) == ETH_P_IPV6) { + proto == ETH_P_IPV6) { return -EOPNOTSUPP; } @@ -156,6 +160,7 @@ static int ocelot_flower_parse(struct flow_cls_offload *f, ace->frame.ipv4.sport.mask = ntohs(match.mask->src); ace->frame.ipv4.dport.value = ntohs(match.key->dst); ace->frame.ipv4.dport.mask = ntohs(match.mask->dst); + match_protocol = false; } if (flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_VLAN)) { @@ -167,9 +172,20 @@ static int ocelot_flower_parse(struct flow_cls_offload *f, ace->vlan.vid.mask = match.mask->vlan_id; ace->vlan.pcp.value[0] = match.key->vlan_priority; ace->vlan.pcp.mask[0] = match.mask->vlan_priority; + match_protocol = false; } finished_key_parsing: + if (match_protocol && proto != ETH_P_ALL) { + /* TODO: support SNAP, LLC etc */ + if (proto < ETH_P_802_3_MIN) + return -EOPNOTSUPP; + ace->type = OCELOT_ACE_TYPE_ETYPE; + *(u16 *)ace->frame.etype.etype.value = htons(proto); + *(u16 *)ace->frame.etype.etype.mask = 0xffff; + } + /* else, a rule of type OCELOT_ACE_TYPE_ANY is implicitly added */ + ace->prio = f->common.prio; ace->id = f->cookie; return ocelot_flower_parse_action(f, ace); From patchwork Mon Apr 20 16:27:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 220935 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.6 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D64B7C3815B for ; Mon, 20 Apr 2020 16:27:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B24392074F for ; Mon, 20 Apr 2020 16:27:58 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="hM0E8gJc" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729518AbgDTQ15 (ORCPT ); Mon, 20 Apr 2020 12:27:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39866 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1729526AbgDTQ1z (ORCPT ); Mon, 20 Apr 2020 12:27:55 -0400 Received: from mail-wr1-x443.google.com (mail-wr1-x443.google.com [IPv6:2a00:1450:4864:20::443]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F2E46C061A0C for ; Mon, 20 Apr 2020 09:27:53 -0700 (PDT) Received: by mail-wr1-x443.google.com with SMTP id u13so12973506wrp.3 for ; Mon, 20 Apr 2020 09:27:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=0JRG0YANHlaDrsdL6zAtAcfGdVROdNU0WIv4cLW5emg=; b=hM0E8gJc4Q8Yno/fYAZ9st6WbUWg23oOeWIU7wAKm4drSezQLBZnNpBKM4X1Ji0aiM Y+X2y9nqyx0HXBljKQ54DrhtGemfCUYLXrLIM0Al0Dc9PY1Dlw9K4Nos3n3kv1Fm3MiN aQ9MpPqM3H/uKG+NthVF4wcY4xlavXyp6m9btFbFiFmG0zgUuRvX1Y8vtJk3V6gb5DfK rPbvhG9gk/oBvONz56WKOdx67lWtJ0iY6F0bzQvJUFwTRLOz7w7qiAOxBnh0GIMqJiPG o6TMsny8GHFD3iQv6nW4/XA/ihWRYY34pRASDe84LrhBoxpgzsL55JcKo+IE2pAEcFmX EdDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=0JRG0YANHlaDrsdL6zAtAcfGdVROdNU0WIv4cLW5emg=; b=MAxhRZ6QNHNWNYn4vxuRHyKks1dhPjwXxlKqBA9mQN4GL3ngpbaH6HdpvsoomJpgJz eACCXQCskl6Y3QdYjsx7kiWZN3a9Zw0LG29ZaZKduKJnO9sQqd1S+ka5jQGkrUP2Qkyn 5hq6fX6oQc7vJ5sR3+8eFs8HR9s/OJvN+Tlrt7D9UxOO/jyyfpu15cTfgmnrFGpLUVdT yPE1mW1aOO58xePN5cIBkOPh0PRFBkWeVJPK/YT23ICOFjp6SqLKb4ZpKyX3VItsG3CR J6VBVEXANAUMvDY/4RV7cA5Wrt21JWHxScwtH24J2kHFLi5WMfDJgNqHzxUwNDmmQhEx sLxQ== X-Gm-Message-State: AGi0PuZbq0tgSOkuv12qmHo50gx2q9oQYeJnd4bti1NMbVrN+Oc/8LlF nmEkJtZw6AsYFHpcASLXhwXtXgVUX8I= X-Google-Smtp-Source: APiQypKH8xrYlvU8P62i4XC3yjztIFMbJ8tmhPee+gfkIaOt8rbff9BamAIdFAknYs6+NV351eVY3w== X-Received: by 2002:adf:fe03:: with SMTP id n3mr18970198wrr.315.1587400072627; Mon, 20 Apr 2020 09:27:52 -0700 (PDT) Received: from localhost.localdomain ([188.25.102.96]) by smtp.gmail.com with ESMTPSA id 185sm146245wmc.32.2020.04.20.09.27.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Apr 2020 09:27:52 -0700 (PDT) From: Vladimir Oltean To: davem@davemloft.net, netdev@vger.kernel.org Cc: idosch@idosch.org, allan.nielsen@microchip.com, horatiu.vultur@microchip.com, alexandre.belloni@bootlin.com, antoine.tenart@bootlin.com, andrew@lunn.ch, f.fainelli@gmail.com, vivien.didelot@gmail.com, joergen.andreasen@microchip.com, claudiu.manoil@nxp.com, UNGLinuxDriver@microchip.com, alexandru.marginean@nxp.com, xiaoliang.yang_1@nxp.com, yangbo.lu@nxp.com, po.liu@nxp.com, jiri@mellanox.com, kuba@kernel.org Subject: [PATCH net-next 2/3] net: mscc: ocelot: refine the ocelot_ace_is_problematic_mac_etype function Date: Mon, 20 Apr 2020 19:27:42 +0300 Message-Id: <20200420162743.15847-3-olteanv@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200420162743.15847-1-olteanv@gmail.com> References: <20200420162743.15847-1-olteanv@gmail.com> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Vladimir Oltean The commit mentioned below was a bit too harsh, and while it restricted the invalid key combinations which are known to not work, such as: tc filter add dev swp0 ingress proto ip \ flower src_ip 192.0.2.1 action drop tc filter add dev swp0 ingress proto all \ flower src_mac 00:11:22:33:44:55 action drop it also restricted some which still should work, such as: tc filter add dev swp0 ingress proto ip \ flower src_ip 192.0.2.1 action drop tc filter add dev swp0 ingress proto 0x22f0 \ flower src_mac 00:11:22:33:44:55 action drop What actually does not match "sanely" is a MAC_ETYPE rule on frames having an EtherType of ARP, IPv4, IPv6, in addition to SNAP and OAM frames (which the ocelot tc-flower implementation does not parse yet, so the function might need to be revisited again in the future). So just make the function recognize the problematic MAC_ETYPE rules by EtherType - thus the VCAP IS2 can be forced to match even on those packets. This patch makes it possible for IP rules to live on a port together with MAC_ETYPE rules that are non-all, non-arp, non-ip and non-ipv6. Fixes: d4d0cb741d7b ("net: mscc: ocelot: deal with problematic MAC_ETYPE VCAP IS2 rules") Reported-by: Allan W. Nielsen Signed-off-by: Vladimir Oltean --- drivers/net/ethernet/mscc/ocelot_ace.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/drivers/net/ethernet/mscc/ocelot_ace.c b/drivers/net/ethernet/mscc/ocelot_ace.c index 8a2f7d13ef6d..dfd82a3baab2 100644 --- a/drivers/net/ethernet/mscc/ocelot_ace.c +++ b/drivers/net/ethernet/mscc/ocelot_ace.c @@ -739,14 +739,24 @@ static void ocelot_match_all_as_mac_etype(struct ocelot *ocelot, int port, static bool ocelot_ace_is_problematic_mac_etype(struct ocelot_ace_rule *ace) { + u16 proto, mask; + if (ace->type != OCELOT_ACE_TYPE_ETYPE) return false; - if (ether_addr_to_u64(ace->frame.etype.dmac.value) & - ether_addr_to_u64(ace->frame.etype.dmac.mask)) + + proto = ntohs(*(u16 *)ace->frame.etype.etype.value); + mask = ntohs(*(u16 *)ace->frame.etype.etype.mask); + + /* ETH_P_ALL match, so all protocols below are included */ + if (mask == 0) return true; - if (ether_addr_to_u64(ace->frame.etype.smac.value) & - ether_addr_to_u64(ace->frame.etype.smac.mask)) + if (proto == ETH_P_ARP) return true; + if (proto == ETH_P_IP) + return true; + if (proto == ETH_P_IPV6) + return true; + return false; }