From patchwork Tue Apr 12 10:02:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Boris Sukholitko X-Patchwork-Id: 12810516 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 A3B0FC433FE for ; Tue, 12 Apr 2022 11:17:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346166AbiDLLTX (ORCPT ); Tue, 12 Apr 2022 07:19:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35064 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241585AbiDLLRT (ORCPT ); Tue, 12 Apr 2022 07:17:19 -0400 Received: from mail-pj1-x102e.google.com (mail-pj1-x102e.google.com [IPv6:2607:f8b0:4864:20::102e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B03E3972C6 for ; Tue, 12 Apr 2022 03:03:29 -0700 (PDT) Received: by mail-pj1-x102e.google.com with SMTP id g12-20020a17090a640c00b001cb59d7a57cso1559841pjj.1 for ; Tue, 12 Apr 2022 03:03: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=V+nemT9Ud/JIWkiLHUEFLukYg/HG4bV42mp8IeM6TBQ=; b=dZRLxBiDxAgrqiS9CfmdzVKuKAuWND1p3Eth651w1kaf69U6v9uDtsFRBDlpzfPMbY pR6kl2Aj5nnO5V+wie3oQ90QcYqN6qbv7GFTCqxRLWujMQJARxjdS6FpK9aBb1Kb0AwK 893x4ER0Kn8+q4UvJYZ+vazBF8a+ip78FJLAA= 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=V+nemT9Ud/JIWkiLHUEFLukYg/HG4bV42mp8IeM6TBQ=; b=QsW5U105KGlM1CGAJ/gCocywKDY40diKlDDlCl2H/VBv+37sSckyMJvRK0s8NmTDwR jhcsK6VaamvuLeYB9LngKJAziiMkLXTZr9EezVLB5LnOLC6aVjboEHkbrcERpXnCGFas bO2iHFOAnVwlyMLxXM1YUYNUOeA5o63B/FYIJN83YjBkCvGNO85Nh1/FwA0A2JbOjMc2 5NLyzhcc3IvRf33zmMuR1cvg/r9LKUP5n4PaBN9VzXMskeg2MR3fQwVapksqktWaoRXI iVqcWpbg7FyHgA76CE7Tr553jiWvSh8Vd8ayE7hk3W4asscIrCGcbHBtwzJvqkzcKYKX tUaA== X-Gm-Message-State: AOAM5326q2a7/7JKSDjiF9Xnmy1s3xKC6FB1eaSRBps0T2dIe6nItSb5 IwBNykyQV/bMgp/2yoMPPwgCux8cpPfnItChjc59Usvh3WOmriRv6xqMFl4HsMnYchsxdbUfDj4 iK/+qYBzrRq1z02SvwlQcJqQ0pn+dYSdSftp6H7pcbSz1h8aWjU3KA3e4M94l/xy5Zn833W5b11 mwJ9HZ8Vg6/A== X-Google-Smtp-Source: ABdhPJxCKOf+Q2yEluCY2V6VvpJM0YYaRDK4ibkXHLEofr08/WIhp+ChwSHHeisnlkvnFMRcQ3QJxA== X-Received: by 2002:a17:90b:224f:b0:1c9:949e:2202 with SMTP id hk15-20020a17090b224f00b001c9949e2202mr4063031pjb.56.1649757808520; Tue, 12 Apr 2022 03:03:28 -0700 (PDT) Received: from localhost.localdomain ([192.19.250.250]) by smtp.gmail.com with ESMTPSA id u17-20020a056a00159100b004faef351ebcsm37020020pfk.45.2022.04.12.03.03.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Apr 2022 03:03:27 -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 v2 5/5] net/sched: flower: Consider the number of tags for vlan filters Date: Tue, 12 Apr 2022 13:02:36 +0300 Message-Id: <20220412100236.27244-6-boris.sukholitko@broadcom.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20220412100236.27244-1-boris.sukholitko@broadcom.com> References: <20220412100236.27244-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. We achieve the above by having is_vlan_key helper look at the number of vlans in addition to the vlan ethertype. Outer tag vlan filters (e.g. vlan_prio) require the number of vlan tags be greater than 0. Inner filters (e.g. cvlan_prio) require the number of vlan tags be greater than 1. Number of vlans filter may cause ethertype to be set to 0. Check this in fl_set_key_vlan. 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,