From patchwork Wed Mar 23 10:56:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Boris Sukholitko X-Patchwork-Id: 12789677 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 C2EB9C433F5 for ; Wed, 23 Mar 2022 10:57:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233943AbiCWK7E (ORCPT ); Wed, 23 Mar 2022 06:59:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52268 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243667AbiCWK7D (ORCPT ); Wed, 23 Mar 2022 06:59:03 -0400 Received: from mail-pj1-x1030.google.com (mail-pj1-x1030.google.com [IPv6:2607:f8b0:4864:20::1030]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9CCB978063 for ; Wed, 23 Mar 2022 03:57:29 -0700 (PDT) Received: by mail-pj1-x1030.google.com with SMTP id mj15-20020a17090b368f00b001c637aa358eso6068971pjb.0 for ; Wed, 23 Mar 2022 03:57:29 -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=TSViUaYbE+wRlWDmACxL70V6MiV5smQwsgR8toRtEJo=; b=LYKZzUaJ8OPwwiSPIoRBdhHnxqXI0IJM1+D8KTPjSIPcP2yAorMAFaRwRMoEK2VCOX yPKg+mS3PWrsyG8nryrShuGaL8hvsu4yfuXzZmcMqUGTbD4IhnYMxTUV0BshWEPios/R OyPrRAiRtDEKW2C9uoeqmjIWUmg9ffFJLR5ko= 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=TSViUaYbE+wRlWDmACxL70V6MiV5smQwsgR8toRtEJo=; b=j/FK7d1R0kRjFCuSyyw/tapW0nVapjQQ4n6XuPPUJM+P6zk9JBNcgx/tKSOvd+rtZE TndtTPzS8G+B4zwIjwmDP7/x9D9t+FRepLvHYpfCa0YgFiCXsCt02eHpJ3ct9xIRfzVM 7GztZeLw8YcuTMGQ+o9jXhomgzwmrjfsHc3hlKAlWz99JjAdsGSbhpMKMCvufDBAOPmx dfHvvFBl97AvODMU8S+IW90pUS0AbCst75KrGk1Fi1bmzUwd8Q4ng9kxEv9oCJOB9H3S 4tnkMzQ/yxU0cDP9NM2UTYOthjAZ5ucQpKbsKIwa2HzbBBwI9xGGaImZXAJYpQl4XI5n APVg== X-Gm-Message-State: AOAM533cROanojBdmoi5lHW1DCzpU3taS1D2ijmm6LIpQU0lRdJfAvdJ Q9PxcGnUDc7TZeojfV/B/KVCZ02yJI5Qi8K/0CbN9r7CQS0M9/ILdgowBQtPjJdZvQrRhD6nRxO T56gD9LmPKU5piZQEE7ePYIrVSBzjHin9O+wR1Vw0cjxGVx/YV1EIKxKCfVOBM3i84Pkj1ORbp1 8zAUt/zTjosA== X-Google-Smtp-Source: ABdhPJxne2dL1/+G4N3uegLEd+Mu2SgBR0dB/ku0vaWnjS0MVbq/fi3/lDpaN963p/qT1wfycHW6ew== X-Received: by 2002:a17:90b:2486:b0:1bc:9d6a:f22 with SMTP id nt6-20020a17090b248600b001bc9d6a0f22mr10849884pjb.211.1648033048688; Wed, 23 Mar 2022 03:57:28 -0700 (PDT) Received: from localhost.localdomain ([192.19.250.250]) by smtp.gmail.com with ESMTPSA id d11-20020aa7868b000000b004f768dfe93asm25535927pfo.176.2022.03.23.03.57.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Mar 2022 03:57:28 -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: Wed, 23 Mar 2022 12:56:02 +0200 Message-Id: <20220323105602.30072-6-boris.sukholitko@broadcom.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20220323105602.30072-1-boris.sukholitko@broadcom.com> References: <20220323105602.30072-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,