From patchwork Mon Apr 11 13:31:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Boris Sukholitko X-Patchwork-Id: 12809108 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 65B05C4332F for ; Mon, 11 Apr 2022 13:31:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346519AbiDKNeK (ORCPT ); Mon, 11 Apr 2022 09:34:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51334 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346494AbiDKNeH (ORCPT ); Mon, 11 Apr 2022 09:34:07 -0400 Received: from mail-pf1-x430.google.com (mail-pf1-x430.google.com [IPv6:2607:f8b0:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2765E3BBDC for ; Mon, 11 Apr 2022 06:31:53 -0700 (PDT) Received: by mail-pf1-x430.google.com with SMTP id p25so7857129pfn.13 for ; Mon, 11 Apr 2022 06:31:53 -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=ew7hF1GzKGo9CR1nu73VZ9XdC+QrOeR1AmdjTGGYwCs=; b=Izx0ruvc73MS5eozU8+6R/rerr/AdOWzy7mize3Xg7EIPUJA1HouujRsDohROgm4b8 F8dW8IL7+1KuVx/z7rpHqFnlTGwe5Nug1nM+TWtuarau3Q0H97mBmMY0ySiUhAUIoLaa WzAdTxYrs3/xbaS0b9QjjbxcTeDJVXTU7aLag= 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=ew7hF1GzKGo9CR1nu73VZ9XdC+QrOeR1AmdjTGGYwCs=; b=qoFJA0wEXr2rqwAlulhC7NdjYXgWvBL8Atr6VfaY2Urlnvrm5PVOMAeEVuCNHAWzD0 JRm/eN/ftVBF0jM4TFkp1FDTv3lHdDrKkZKPOM949t+QIreEsjFUHVTs0Uj5ehad78RB YDw/aY7WtLglOxnUspVgi6h9JsVVoab/5zcqCX0ZszI64AiF64mGoXmUZggxlJcwaHef HBk+uaBqmAoSy+qr97qRO5A4auAPQg68c5idrO32bUn42LppkEHjh805RJt/02eBY0Fc h3WOIEv+8jO59FwcTFpi3JoVeed2orNVSvEubg9vVCGxP8zZ1E3lmZshSOTMWCur20X6 2UnA== X-Gm-Message-State: AOAM530wZUrWRnwaE95iGnhD4VSIh+KOBcEjizRCEJbzu5IkC2rZ3GS+ 1ZQD2jWDGeMY05fQGalajHoR+5rRGKtDuCJupPF0konjEkKdA44J4deOTTq5hq8KULZJIlNgoYg Oo36wCstNuemfGeTJIpSesObFsfXi2YFEzwpEVMTb1/vOSKbrsOVFWKO/qebS/ibA6QboUTKFtb WenN0+8D/8ig== X-Google-Smtp-Source: ABdhPJxmMp+F68h1qeH4Omru21iAimGzBUC71239Voa2mMXnEAMe2mTtShDB5UiZVQyftOIIO7hwnQ== X-Received: by 2002:aa7:9019:0:b0:4fa:7532:9551 with SMTP id m25-20020aa79019000000b004fa75329551mr32974376pfo.26.1649683912213; Mon, 11 Apr 2022 06:31:52 -0700 (PDT) Received: from localhost.localdomain ([192.19.250.250]) by smtp.gmail.com with ESMTPSA id a38-20020a056a001d2600b004f70d5e92basm35716311pfx.34.2022.04.11.06.31.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Apr 2022 06:31:51 -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 Cc: Ilya Lifshits , Boris Sukholitko Subject: [PATCH net-next 5/5] Consider the number of vlan tags for vlan filters Date: Mon, 11 Apr 2022 16:31:00 +0300 Message-Id: <20220411133100.18126-6-boris.sukholitko@broadcom.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20220411133100.18126-1-boris.sukholitko@broadcom.com> References: <20220411133100.18126-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 Currently the existence of vlan filters is conditional on the vlan protocol being matched in the tc rule. I.e. the following rule: tc filter add dev eth1 ingress flower vlan_prio 5 is illegal because we lack protocol 802.1q in the rule. Having the num_of_vlans filter configured removes this restriction. The following rule becomes ok: tc filter add dev eth1 ingress flower num_of_vlans 1 vlan_prio 5 because we know that the packet is single tagged. 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 42dd84f5a037..464a91e64b5f 100644 --- a/net/sched/cls_flower.c +++ b/net/sched/cls_flower.c @@ -1023,8 +1023,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, @@ -1495,13 +1497,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; @@ -1536,12 +1543,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,