From patchwork Thu Apr 14 12:51:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Boris Sukholitko X-Patchwork-Id: 12813497 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 20C38C433EF for ; Thu, 14 Apr 2022 12:52:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243633AbiDNMys (ORCPT ); Thu, 14 Apr 2022 08:54:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51044 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243641AbiDNMyq (ORCPT ); Thu, 14 Apr 2022 08:54:46 -0400 Received: from mail-qk1-x732.google.com (mail-qk1-x732.google.com [IPv6:2607:f8b0:4864:20::732]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1615D9233E for ; Thu, 14 Apr 2022 05:52:20 -0700 (PDT) Received: by mail-qk1-x732.google.com with SMTP id c1so3729223qkf.13 for ; Thu, 14 Apr 2022 05:52:20 -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=qQP8Aj8EYzZG4Jzto486EAZJ9Lup717hPLdfMHb8Wu8=; b=EugKZQWJkpboLMvJpMi55C/C+yZ3X5/LAmX42n91r2BVjHAmamm5KuM6YtXZE4dQ++ +/AH5NWxNwhH2r7SjZdKqpVbuzHrC5TZyya2SQyEW+H2ouSzTdKwJi1BytJn4so1tuPt dOlf9tZ9tFHDeXWcGmr3dH/xbKhlHw1YGHMys= 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=qQP8Aj8EYzZG4Jzto486EAZJ9Lup717hPLdfMHb8Wu8=; b=tYhXdkFgeOVg9s1bU1hP6USIPVkB+8At0Da821ettXsjBu/wOoSu9bRSsmUgkt5gum U4et7ZdyaEjeznarXnXbSyzO8ll92tqF90YJ+tGUTgOK8NazkBIkl1IXNcR9a+Pcjhe8 0A7G5htWumSXfWEt9M7n22uNf51BMLHoeBQlk5TxmGtalk+0YBjNrCY0nvDkgBV/duE3 L+o0VH7ZIDNshkXMJRJec869Y93WRBVkSSnz5n/f3mYLlA9R4wpTnWWcl8MaK20aDqu0 ZDiy4ddq/gD441MYgdm1JqtxNHUug2XsQom7rZiZycGR0nDCiw1es7RqVw9mimouTlVu XhJA== X-Gm-Message-State: AOAM5303OCDbR+OqN/jrwEtM2LspWgfvK4aZKeG7fPLKJXcK3exv6tb9 4t4RJ2Q5UCQozUH4R1XE8bqhE/xwTWqS1lkocmfvnj0hYaBWEFsQcEuMsWww3iMISPaElud96eY xqNwNvRC/LGWq3ydtSNp+nRRJO2EMcVPuB3oHNH1hp1oDP92hXKBPQf+8qX4+pwYRnCt0kn29SC N76E8+h1IeOg== X-Google-Smtp-Source: ABdhPJwmhW0wqzsmfrTVksBdPH7bkn7y61/pEFHnPoaYJjp56x5GOmrQN+xYhKSDGtr3qZVa13WLRg== X-Received: by 2002:a05:620a:2802:b0:69c:3b5a:b264 with SMTP id f2-20020a05620a280200b0069c3b5ab264mr1666229qkp.668.1649940738837; Thu, 14 Apr 2022 05:52:18 -0700 (PDT) Received: from localhost.localdomain ([192.19.250.250]) by smtp.gmail.com with ESMTPSA id o10-20020a05620a15ca00b0069c39e2970bsm875910qkm.80.2022.04.14.05.52.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Apr 2022 05:52:18 -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 v3 5/5] net/sched: flower: Consider the number of tags for vlan filters Date: Thu, 14 Apr 2022 15:51:21 +0300 Message-Id: <20220414125121.13599-6-boris.sukholitko@broadcom.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20220414125121.13599-1-boris.sukholitko@broadcom.com> References: <20220414125121.13599-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 fafb74198c8d..9bf15b44292c 100644 --- a/net/sched/cls_flower.c +++ b/net/sched/cls_flower.c @@ -1029,8 +1029,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); + } } static void fl_set_key_flag(u32 flower_key, u32 flower_mask, @@ -1576,13 +1578,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; @@ -1617,12 +1624,13 @@ 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, &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,