From patchwork Tue Apr 19 08:14:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Boris Sukholitko X-Patchwork-Id: 12817587 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 258A4C433F5 for ; Tue, 19 Apr 2022 08:16:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244623AbiDSISn (ORCPT ); Tue, 19 Apr 2022 04:18:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41040 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349865AbiDSISR (ORCPT ); Tue, 19 Apr 2022 04:18:17 -0400 Received: from mail-pl1-x632.google.com (mail-pl1-x632.google.com [IPv6:2607:f8b0:4864:20::632]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D0CA129C96 for ; Tue, 19 Apr 2022 01:15:23 -0700 (PDT) Received: by mail-pl1-x632.google.com with SMTP id v12so14703258plv.4 for ; Tue, 19 Apr 2022 01:15:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version; bh=O6JK3QRCrAxB5Zk4fKxsfTVoI0q1aMb6cuoiguD2iWs=; b=QMH8ACBazzaiUynBglt2Pu7HDYZxSUUIvFcSN5twuLVnq1RjP8KKnUvBXNStUSyyr4 WZrsI3PVUo5dDO0zY31V2+toUgwU19a10OOo3M7bE6XT3RkdCZxF0gklW/AEvh78bw8M knQhbJ622KtzHcEJ4rKnqrB1fSIve6olM6KLg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version; bh=O6JK3QRCrAxB5Zk4fKxsfTVoI0q1aMb6cuoiguD2iWs=; b=sfio1ONYMY2kHukQG9bUIR0JApz4ltvPCWbIJv6cwNSxhsipHYveSTOIjA/E680zws 4JHNb/tTFMXiq5GvhclvSAjtU8Yy8iSCrVxEQKQo0lj3zhOihOuWW3ntzPmzkLFugG9a jZeRp8Sa7VXVsutSg4IK5tKjaNfAIHL8tihQ6gk+gYd1oeH8oWBaA1/t/+RI14T4akj7 exwYiFFjfT/U3r6hiyjl1LG/g223x2DgJqD5NFmO6FnCjaAflVWhQ3HfqN9Mlq8NS9fj B5lekkObSY7Q7yfqp6QckxrPPsnhXFtmVX1Rw1DpSWTJDE2G8qygGatDP5bOQ0L/g026 NecQ== X-Gm-Message-State: AOAM532FTYmzYNhwi0zFBHB4kweGyYm8OorERQKWenZq7mKLvXaNtXO2 Wc6g1e1yAiFIr3r2qqJ98qVe1LgygGLjtFprz1UPEIvT9g/3bbitueHLNfl6tE2uN2HYm1hEB81 KyJcUatrnKt7cH/y0uWJndIXP50GT3i8ZhZc1oc4B1hx5jWiWTtGpsakXqpMWfyu0Xxi1hzqIMP rUVMBHyGwKHQ== X-Google-Smtp-Source: ABdhPJyv4AOnECkWs2cXU1O0GCp14MvSVf92gwEZxiPHrgU6y/Ua+NNVMxKr04yow322hOBSc5tE9g== X-Received: by 2002:a17:90a:384d:b0:1d2:97de:eb8c with SMTP id l13-20020a17090a384d00b001d297deeb8cmr9911611pjf.208.1650356122666; Tue, 19 Apr 2022 01:15:22 -0700 (PDT) Received: from localhost.localdomain ([192.19.250.250]) by smtp.gmail.com with ESMTPSA id cp19-20020a056a00349300b0050a890c8c16sm4284570pfb.19.2022.04.19.01.15.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Apr 2022 01:15:22 -0700 (PDT) From: Boris Sukholitko To: netdev@vger.kernel.org, "David S . Miller" , Jakub Kicinski , Jamal Hadi Salim , Cong Wang , Jiri Pirko , "Gustavo A . R . Silva" , Vladimir Oltean , Eric Dumazet , zhang kai , Yoshiki Komachi , Paolo Abeni Cc: Ilya Lifshits , Boris Sukholitko Subject: [PATCH net-next v4 5/5] net/sched: flower: Consider the number of tags for vlan filters Date: Tue, 19 Apr 2022 11:14:34 +0300 Message-Id: <20220419081434.5192-6-boris.sukholitko@broadcom.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20220419081434.5192-1-boris.sukholitko@broadcom.com> References: <20220419081434.5192-1-boris.sukholitko@broadcom.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Before this patch the existence of vlan filters was conditional on the vlan protocol being matched in the tc rule. For example, the following rule: tc filter add dev eth1 ingress flower vlan_prio 5 was illegal because vlan protocol (e.g. 802.1q) does not appear in the rule. Remove the above restriction by looking at the num_of_vlans filter to allow further matching on vlan attributes. The following rule becomes legal as a result of this commit: tc filter add dev eth1 ingress flower num_of_vlans 1 vlan_prio 5 because having num_of_vlans==1 implies that the packet is single tagged. Change is_vlan_key helper to look at the number of vlans in addition to the vlan ethertype. The outcome of this change is that outer (e.g. vlan_prio) and inner (e.g. cvlan_prio) tag vlan filters require the number of vlan tags to be greater then 0 and 1 accordingly. As a result of is_vlan_key change, the ethertype may be set to 0 when matching on the number of vlans. Update fl_set_key_vlan to avoid setting key, mask vlan_tpid for the 0 ethertype. Signed-off-by: Boris Sukholitko --- net/sched/cls_flower.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/net/sched/cls_flower.c b/net/sched/cls_flower.c index 4ec4d742e82f..dcca70144dff 100644 --- a/net/sched/cls_flower.c +++ b/net/sched/cls_flower.c @@ -1030,8 +1030,10 @@ static void fl_set_key_vlan(struct nlattr **tb, VLAN_PRIORITY_MASK; key_mask->vlan_priority = VLAN_PRIORITY_MASK; } - key_val->vlan_tpid = ethertype; - key_mask->vlan_tpid = cpu_to_be16(~0); + if (ethertype) { + key_val->vlan_tpid = ethertype; + key_mask->vlan_tpid = cpu_to_be16(~0); + } if (tb[vlan_next_eth_type_key]) { key_val->vlan_eth_type = nla_get_be16(tb[vlan_next_eth_type_key]); @@ -1582,13 +1584,18 @@ static int fl_set_key_ct(struct nlattr **tb, } static bool is_vlan_key(struct nlattr *tb, __be16 *ethertype, - struct fl_flow_key *key, struct fl_flow_key *mask) + struct fl_flow_key *key, struct fl_flow_key *mask, + int vthresh) { - if (!tb) - return false; + const bool good_num_of_vlans = key->num_of_vlans.num_of_vlans > vthresh; + + if (!tb) { + *ethertype = 0; + return good_num_of_vlans; + } *ethertype = nla_get_be16(tb); - if (eth_type_vlan(*ethertype)) + if (good_num_of_vlans || eth_type_vlan(*ethertype)) return true; key->basic.n_proto = *ethertype; @@ -1623,13 +1630,14 @@ static int fl_set_key(struct net *net, struct nlattr **tb, TCA_FLOWER_UNSPEC, sizeof(key->num_of_vlans)); - if (is_vlan_key(tb[TCA_FLOWER_KEY_ETH_TYPE], ðertype, key, mask)) { + if (is_vlan_key(tb[TCA_FLOWER_KEY_ETH_TYPE], ðertype, key, mask, 0)) { fl_set_key_vlan(tb, ethertype, TCA_FLOWER_KEY_VLAN_ID, TCA_FLOWER_KEY_VLAN_PRIO, TCA_FLOWER_KEY_VLAN_ETH_TYPE, &key->vlan, &mask->vlan); - if (is_vlan_key(tb[TCA_FLOWER_KEY_VLAN_ETH_TYPE], ðertype, key, mask)) { + if (is_vlan_key(tb[TCA_FLOWER_KEY_VLAN_ETH_TYPE], + ðertype, key, mask, 1)) { fl_set_key_vlan(tb, ethertype, TCA_FLOWER_KEY_CVLAN_ID, TCA_FLOWER_KEY_CVLAN_PRIO,