From patchwork Tue Apr 12 10:02:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Boris Sukholitko X-Patchwork-Id: 12810511 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 ADE93C433EF for ; Tue, 12 Apr 2022 11:13:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344936AbiDLLPk (ORCPT ); Tue, 12 Apr 2022 07:15:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49388 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1355129AbiDLLPP (ORCPT ); Tue, 12 Apr 2022 07:15:15 -0400 Received: from mail-pg1-x52f.google.com (mail-pg1-x52f.google.com [IPv6:2607:f8b0:4864:20::52f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 832B0252A4 for ; Tue, 12 Apr 2022 03:03:11 -0700 (PDT) Received: by mail-pg1-x52f.google.com with SMTP id 32so14669520pgl.4 for ; Tue, 12 Apr 2022 03:03:11 -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=J15r6CdbQlQ1MjQalRz71kYTjgOltdBXsSk3+PGN9OQ=; b=LXjP7KYFZ3ggXPzCgE6p0Rr0oczQIlzPmK03pWuhUmjiuXXsjUCgk90iiuES/zHe9F jIhzNS5zsFk3182SnXjmOTrcFKZ6B1Cl+7s8iciSqyW/sjG7Vm04A+EHUY6uU+lwWJjb AqtcpLbmF1r1O1MctcXR33wsuUReLw4IJJWBA= 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=J15r6CdbQlQ1MjQalRz71kYTjgOltdBXsSk3+PGN9OQ=; b=cumNagpQmfvWE7vLXBxFxjD7RnT3D8rT8wlznKcystjODUzV1CM9F2crwtGcmeugrE YcOAxLruidlfnE3iC2l2XTDwbln1hDNPC/yS+0lVbcXbh+U9mOTbbnbCpAgaGRupv2dJ DwhUGnY6PFBuuHahaI1ihr5z9nJecv4sUWZcgxxK3cTgMPjwSbBcRZ4KdXECuaULLA47 4ejnjJX13BDTEqL8aqgPpLsgGf9GF4YEPqgM6Arb2yfXgIlEn71k6ULBAxwSQ25PD1/9 j+hVRKmT/Pa+Ce19ZgZNPdikpDbXTubTWQ08e72UTg7PqCJY3MrdclPYGFkkTYlsOEFM zWuw== X-Gm-Message-State: AOAM533VgX/iEJNfoIjTXcFmQ78uRrbDYeytiZVrsWNV0bXlksr8tqhj zEYeDacHXXqKFgjFeNCZSs+f1PqcB+mgiZJo3DF1h3TztcHfMbvVTgs1fu8cW+WIsvBHspibKgb z6xx8tAk+CUn3NmFLhSxBuTyHZ82mczIQDnSo5eGW8Vf1TRC3C2jQryGMtjcTIAc1YFBItUgwp0 KHNviyuZs/9w== X-Google-Smtp-Source: ABdhPJw80j12qk/2mGiJvdcW1TVtmO97+Huroq57AT/r9eJEppFeK5jRa7enqmq2//h//pBK6kOltA== X-Received: by 2002:a63:1061:0:b0:399:5cd:3ddf with SMTP id 33-20020a631061000000b0039905cd3ddfmr29440152pgq.271.1649757790213; Tue, 12 Apr 2022 03:03:10 -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.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Apr 2022 03:03:09 -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 1/5] net/sched: flower: Helper function for vlan ethtype checks Date: Tue, 12 Apr 2022 13:02:32 +0300 Message-Id: <20220412100236.27244-2-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 There are somewhat repetitive ethertype checks in fl_set_key. Refactor them into is_vlan_key helper function. To make the changes clearer, avoid touching identation levels. This is the job for the next patch in the series. Signed-off-by: Boris Sukholitko --- net/sched/cls_flower.c | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/net/sched/cls_flower.c b/net/sched/cls_flower.c index 87e030dfc328..9a9b7849e657 100644 --- a/net/sched/cls_flower.c +++ b/net/sched/cls_flower.c @@ -1573,6 +1573,21 @@ static int fl_set_key_ct(struct nlattr **tb, return 0; } +static bool is_vlan_key(struct nlattr *tb, __be16 *ethertype, + struct fl_flow_key *key, struct fl_flow_key *mask) +{ + if (!tb) + return false; + + *ethertype = nla_get_be16(tb); + if (eth_type_vlan(*ethertype)) + return true; + + key->basic.n_proto = *ethertype; + mask->basic.n_proto = cpu_to_be16(~0); + return false; +} + static int fl_set_key(struct net *net, struct nlattr **tb, struct fl_flow_key *key, struct fl_flow_key *mask, struct netlink_ext_ack *extack) @@ -1595,17 +1610,12 @@ static int fl_set_key(struct net *net, struct nlattr **tb, mask->eth.src, TCA_FLOWER_KEY_ETH_SRC_MASK, sizeof(key->eth.src)); - if (tb[TCA_FLOWER_KEY_ETH_TYPE]) { - ethertype = nla_get_be16(tb[TCA_FLOWER_KEY_ETH_TYPE]); - - if (eth_type_vlan(ethertype)) { + if (is_vlan_key(tb[TCA_FLOWER_KEY_ETH_TYPE], ðertype, key, mask)) { fl_set_key_vlan(tb, ethertype, TCA_FLOWER_KEY_VLAN_ID, TCA_FLOWER_KEY_VLAN_PRIO, &key->vlan, &mask->vlan); - if (tb[TCA_FLOWER_KEY_VLAN_ETH_TYPE]) { - ethertype = nla_get_be16(tb[TCA_FLOWER_KEY_VLAN_ETH_TYPE]); - if (eth_type_vlan(ethertype)) { + if (is_vlan_key(tb[TCA_FLOWER_KEY_VLAN_ETH_TYPE], ðertype, key, mask)) { fl_set_key_vlan(tb, ethertype, TCA_FLOWER_KEY_CVLAN_ID, TCA_FLOWER_KEY_CVLAN_PRIO, @@ -1615,15 +1625,7 @@ static int fl_set_key(struct net *net, struct nlattr **tb, &mask->basic.n_proto, TCA_FLOWER_UNSPEC, sizeof(key->basic.n_proto)); - } else { - key->basic.n_proto = ethertype; - mask->basic.n_proto = cpu_to_be16(~0); - } } - } else { - key->basic.n_proto = ethertype; - mask->basic.n_proto = cpu_to_be16(~0); - } } if (key->basic.n_proto == htons(ETH_P_IP) || From patchwork Tue Apr 12 10:02:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Boris Sukholitko X-Patchwork-Id: 12810512 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 A5FDFC433FE for ; Tue, 12 Apr 2022 11:13:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345660AbiDLLPp (ORCPT ); Tue, 12 Apr 2022 07:15:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59044 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1355371AbiDLLPZ (ORCPT ); Tue, 12 Apr 2022 07:15:25 -0400 Received: from mail-pf1-x433.google.com (mail-pf1-x433.google.com [IPv6:2607:f8b0:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C4A4995A0A for ; Tue, 12 Apr 2022 03:03:15 -0700 (PDT) Received: by mail-pf1-x433.google.com with SMTP id bo5so17056036pfb.4 for ; Tue, 12 Apr 2022 03:03:15 -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=7HSa34Vzmptg/tOFFE7Ys9hDlo/RWae1LwIxkQPxykA=; b=Y++hKSB6AP+ZKzUjLy64gKZyuck0FOqkPrbkXURqBgQVXumG0W35ZSxFsvYJ8WClqG oNUMFhO6e4+AR3Shk5JjcPX8lC4n75KmVa9C/gj00A4Ujy88b61Pw6eaQOTHdC89DH8A G3PG16rMn5GeP1/RHmnuQ1lpfIA7yZUmFoMv8= 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=7HSa34Vzmptg/tOFFE7Ys9hDlo/RWae1LwIxkQPxykA=; b=hcbDD7wegTpbS77pJxwyuOlJMw4zwjG539yeBMDzvltwW8HGi8AjA4mpU2YCWNswYl OMHEvuk4IFGeuadNRRLmcKPI+WHjTN01DizPlGaRanVJVUFIrgbrIPsanqRziGtRrw46 AtQQ9ALE1nWeZurvw/uE93kRujHLxLpW59E1M9JoS0LeAid+MDpqgIQAkTNVzob/2SFv DQdBcNoaRJHltgNZGiOJUP7GberTGeU3mH36xDL8l836CNgXbewF4/7GJNUF31oOrtN1 I+dFDp6aMuIxz3pptVnEKg3jsOuppzSWbWABfup8Bv9jtHYli3dzyvX3KPVIdGkhVrOS A8jQ== X-Gm-Message-State: AOAM533KxykrziqnwPSFXcinzt2tSvsrc5wjIQ/rg4FJ1E4xrziBnqH3 xul3FFofyDr3Rp35i9izDJiOJvs3fK1OEkpir52ilps4Ylk+Oz5xzBDTqx3ZVXkm4O1ROSRLc0t zsDjyxHWfs0tLImhksTekqGxFesneZtGj9n+Y5eIt4891r4rFKGE6+NUByJ+vDan1r2WTFoWZEX uTqoUU/QWnnw== X-Google-Smtp-Source: ABdhPJzU1x+u0k+2/FEUgyKj8LZ8C2Y9erbuDw6TTmaICDgyLPrXUBxWyyN3LoQDwUQQ0NEjlwcnig== X-Received: by 2002:a65:5302:0:b0:39c:e41e:e8ff with SMTP id m2-20020a655302000000b0039ce41ee8ffmr19414978pgq.305.1649757794719; Tue, 12 Apr 2022 03:03:14 -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.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Apr 2022 03:03:14 -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 2/5] net/sched: flower: Reduce identation after is_key_vlan refactoring Date: Tue, 12 Apr 2022 13:02:33 +0300 Message-Id: <20220412100236.27244-3-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 Whitespace only. Signed-off-by: Boris Sukholitko --- net/sched/cls_flower.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/net/sched/cls_flower.c b/net/sched/cls_flower.c index 9a9b7849e657..8725aa1bb21e 100644 --- a/net/sched/cls_flower.c +++ b/net/sched/cls_flower.c @@ -1611,21 +1611,21 @@ static int fl_set_key(struct net *net, struct nlattr **tb, sizeof(key->eth.src)); if (is_vlan_key(tb[TCA_FLOWER_KEY_ETH_TYPE], ðertype, key, mask)) { - 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)) { - fl_set_key_vlan(tb, ethertype, - TCA_FLOWER_KEY_CVLAN_ID, - TCA_FLOWER_KEY_CVLAN_PRIO, - &key->cvlan, &mask->cvlan); - fl_set_key_val(tb, &key->basic.n_proto, - TCA_FLOWER_KEY_CVLAN_ETH_TYPE, - &mask->basic.n_proto, - TCA_FLOWER_UNSPEC, - sizeof(key->basic.n_proto)); - } + 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)) { + fl_set_key_vlan(tb, ethertype, + TCA_FLOWER_KEY_CVLAN_ID, + TCA_FLOWER_KEY_CVLAN_PRIO, + &key->cvlan, &mask->cvlan); + fl_set_key_val(tb, &key->basic.n_proto, + TCA_FLOWER_KEY_CVLAN_ETH_TYPE, + &mask->basic.n_proto, + TCA_FLOWER_UNSPEC, + sizeof(key->basic.n_proto)); + } } if (key->basic.n_proto == htons(ETH_P_IP) || From patchwork Tue Apr 12 10:02: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: 12810513 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 6361DC433F5 for ; Tue, 12 Apr 2022 11:13:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346004AbiDLLP4 (ORCPT ); Tue, 12 Apr 2022 07:15:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48476 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1355479AbiDLLP1 (ORCPT ); Tue, 12 Apr 2022 07:15:27 -0400 Received: from mail-pj1-x102a.google.com (mail-pj1-x102a.google.com [IPv6:2607:f8b0:4864:20::102a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C5EB79681A for ; Tue, 12 Apr 2022 03:03:20 -0700 (PDT) Received: by mail-pj1-x102a.google.com with SMTP id o5so5469729pjr.0 for ; Tue, 12 Apr 2022 03:03: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=IGf67+tppx6Iv0/Y/2I5BTA2mkX8qfpP/BpSd5StRlE=; b=DL2aQZCVz60QnPfgjhTW1HrdRxjMtOJGqMpK5037o6ChyYzBx7/DE+eudc79M+fzxk IVQRSOHNJVmwYArJWbdyTISHG7GiidTUlB3nLD+yrR/We5elmjnX9jJyZyQAph6vToqP vO08hFa1VpHdofeZe1uXbfgiLCXRSe/xIoDhc= 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=IGf67+tppx6Iv0/Y/2I5BTA2mkX8qfpP/BpSd5StRlE=; b=RmECpxBNnHOCXMIlxSA8fdT3JLonFrEUX01wewgy8op6vkr3OTWolnPLkyLJx6OKqr lQd7ByK/AVacRKVta6ElAI3NkenwzjQKni9NjsD78NgSDhI1+chGzyfKa6xFzyAQgk09 vM+VvySaxC7/9FJY1cdkrvnqqiJPH+tV0QIfMncb5Q9nkKW6JTBfVN8PUZfpVJjRh18p hX6Sqed2URyYuo7IGWzW5CVMBAYU9H1GFzuH5Rp/VYjhH9xyQDQC0bQdTvPK2zlhwlwE qnInbnWid1UXA5xSd2jU1fsk5EYZZVqgBnc3hCStMlG9SsB3S6vOS072+XwNseZMX0s5 IHhg== X-Gm-Message-State: AOAM530TsV593Hawhj/eOwlF+giWepVanoQ9CzGk25bKnr4hpc6QLeLH wPr/7HP0/xlVasVXCRQ8WaQ18LcAcBll3C/jFTeP4aLtMJ596wJa+jbUT7IWK6msFdvqq5+6Vlv aEbM4xaId7GnTHCJ1KxUtYEE4UodtHrZQCdYk21affOB7a+EHWnLkmlcJYMXgEUNZJyIc3lDtye DkxUkttoJQQw== X-Google-Smtp-Source: ABdhPJwaMpbUHv5+BXl489tR2WzJW5XMeIpwb49qKKLUXaRmsBiUYi0kB8s5uwDH7D6LB3C2HhPGAQ== X-Received: by 2002:a17:90b:2249:b0:1cc:d191:fc0a with SMTP id hk9-20020a17090b224900b001ccd191fc0amr1961078pjb.6.1649757799266; Tue, 12 Apr 2022 03:03:19 -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.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Apr 2022 03:03: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 Cc: Ilya Lifshits , Boris Sukholitko Subject: [PATCH net-next v2 3/5] flow_dissector: Add number of vlan tags dissector Date: Tue, 12 Apr 2022 13:02:34 +0300 Message-Id: <20220412100236.27244-4-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 Our customers in the fiber telecom world have network configurations where they would like to control their traffic according to the number of tags appearing in the packet. For example, TR247 GPON conformance test suite specification mostly talks about untagged, single, double tagged packets and gives lax guidelines on the vlan protocol vs. number of vlan tags. This is different from the common IT networks where 802.1Q and 802.1ad protocols are usually describe single and double tagged packet. GPON configurations that we work with have arbitrary mix the above protocols and number of vlan tags in the packet. This new dissector allows extracting the number of vlan tags existing in the packet. Signed-off-by: Boris Sukholitko --- include/net/flow_dissector.h | 9 +++++++++ net/core/flow_dissector.c | 20 ++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/include/net/flow_dissector.h b/include/net/flow_dissector.h index aa33e1092e2c..10b83e03af01 100644 --- a/include/net/flow_dissector.h +++ b/include/net/flow_dissector.h @@ -251,6 +251,14 @@ struct flow_dissector_key_hash { u32 hash; }; +/** + * struct flow_dissector_key_num_of_vlans: + * @num_of_vlans: num_of_vlans value + */ +struct flow_dissector_key_num_of_vlans { + u8 num_of_vlans; +}; + enum flow_dissector_key_id { FLOW_DISSECTOR_KEY_CONTROL, /* struct flow_dissector_key_control */ FLOW_DISSECTOR_KEY_BASIC, /* struct flow_dissector_key_basic */ @@ -280,6 +288,7 @@ enum flow_dissector_key_id { FLOW_DISSECTOR_KEY_META, /* struct flow_dissector_key_meta */ FLOW_DISSECTOR_KEY_CT, /* struct flow_dissector_key_ct */ FLOW_DISSECTOR_KEY_HASH, /* struct flow_dissector_key_hash */ + FLOW_DISSECTOR_KEY_NUM_OF_VLANS, /* struct flow_dissector_key_num_of_vlans */ FLOW_DISSECTOR_KEY_MAX, }; diff --git a/net/core/flow_dissector.c b/net/core/flow_dissector.c index 03b6e649c428..19015289c2eb 100644 --- a/net/core/flow_dissector.c +++ b/net/core/flow_dissector.c @@ -1035,6 +1035,16 @@ bool __skb_flow_dissect(const struct net *net, memcpy(key_eth_addrs, ð->h_dest, sizeof(*key_eth_addrs)); } + if (dissector_uses_key(flow_dissector, + FLOW_DISSECTOR_KEY_NUM_OF_VLANS)) { + struct flow_dissector_key_num_of_vlans *key_num_of_vlans; + + key_num_of_vlans = skb_flow_dissector_target(flow_dissector, + FLOW_DISSECTOR_KEY_NUM_OF_VLANS, + target_container); + key_num_of_vlans->num_of_vlans = 0; + } + proto_again: fdret = FLOW_DISSECT_RET_CONTINUE; @@ -1158,6 +1168,16 @@ bool __skb_flow_dissect(const struct net *net, nhoff += sizeof(*vlan); } + if (dissector_uses_key(flow_dissector, + FLOW_DISSECTOR_KEY_NUM_OF_VLANS)) { + struct flow_dissector_key_num_of_vlans *key_nvs; + + key_nvs = skb_flow_dissector_target(flow_dissector, + FLOW_DISSECTOR_KEY_NUM_OF_VLANS, + target_container); + key_nvs->num_of_vlans++; + } + if (dissector_vlan == FLOW_DISSECTOR_KEY_MAX) { dissector_vlan = FLOW_DISSECTOR_KEY_VLAN; } else if (dissector_vlan == FLOW_DISSECTOR_KEY_VLAN) { From patchwork Tue Apr 12 10:02:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Boris Sukholitko X-Patchwork-Id: 12810514 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 D87C6C433F5 for ; Tue, 12 Apr 2022 11:17:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243582AbiDLLTR (ORCPT ); Tue, 12 Apr 2022 07:19:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59218 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244144AbiDLLPh (ORCPT ); Tue, 12 Apr 2022 07:15:37 -0400 Received: from mail-pj1-x102c.google.com (mail-pj1-x102c.google.com [IPv6:2607:f8b0:4864:20::102c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DE99F97284 for ; Tue, 12 Apr 2022 03:03:24 -0700 (PDT) Received: by mail-pj1-x102c.google.com with SMTP id e8-20020a17090a118800b001cb13402ea2so2430633pja.0 for ; Tue, 12 Apr 2022 03:03:24 -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=jOJGBqZEtyYsHkVJQZiFwNhz1g9+NKml4SymNE647KM=; b=cDvMf/anklz/UYVLF5/+HSj8O2C4ypnVWt8GEnQcq+l/QIk7GERExDGaEAaFYP7NXX AdIFXxWFIvtIJ/lZJ3S4/TX+VEyh3zDlLNq+y3X6YOmu8ntvGMK/RLVVMf4iFPgnabr4 BhWVROlaR+MpRt77x9nBSw+HbN4hzT6KMj2Go= 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=jOJGBqZEtyYsHkVJQZiFwNhz1g9+NKml4SymNE647KM=; b=TokVWoCDsJg1nXTPnf3O4nE0cA9SazqMsA6RxisyRpF1GuIfpQDpgwZkTcXiLGKDrV 8k2TUk/p4BuxdnQbQ2hEMMiqtVgN4fCCc/nZJfZ5k2sQhED6YVaxj4V20SGfQpETTNc+ nSFi0w5bdaWOji0M37Eqg/oX9HJmmbxOsqjcmTNbMv3OAYwwihL87QISiVS10OUmx/np BH5zMY1U8oFUDF0Zf4yVF5XdZqYpIsdRnL5hnUSq2yxyZLjThXKHHzTv/78yvmwy6sHn Rp9lvKxoHJlURpXYMbmwbB9l7JJONCVdQIZv90QhmHtE6a/mneTjaZHlTJ9/5HQoSYYV dPGQ== X-Gm-Message-State: AOAM5338Z3TMzL/5D9PSw+HsNZjJG5rZUX7/mqQOv2hVORTMoWtrrnCQ gaeF7RC2dRfmO4qdel4AImNWyNkcJ8JKfmq0ckGj3mh/1kp2oQCKViIXPapUmh24OK1jrLGcXVF 4KtmC6ThVhIxwv7I9uLC9OryC8FhpTNhmaPIdaJvSni4MUu0SQWoKbag0hR62BGuPXQUQZisJ1z yGWmRIjSUWWA== X-Google-Smtp-Source: ABdhPJzJjo+e3SFgPHBsf0X+Gj8zb/OEAxvBgc1LkeQI4hM7QwAX4iYbsWRvdvM8dSW6xXcfbcQCyg== X-Received: by 2002:a17:902:b941:b0:14d:af72:3f23 with SMTP id h1-20020a170902b94100b0014daf723f23mr37457188pls.6.1649757803760; Tue, 12 Apr 2022 03:03:23 -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.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Apr 2022 03:03:23 -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 4/5] net/sched: flower: Add number of vlan tags filter Date: Tue, 12 Apr 2022 13:02:35 +0300 Message-Id: <20220412100236.27244-5-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 These are bookkeeping parts of the new num_of_vlans filter. Defines, dump, load and set are being done here. Signed-off-by: Boris Sukholitko --- include/uapi/linux/pkt_cls.h | 2 ++ net/sched/cls_flower.c | 14 ++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/include/uapi/linux/pkt_cls.h b/include/uapi/linux/pkt_cls.h index 404f97fb239c..9a2ee1e39fad 100644 --- a/include/uapi/linux/pkt_cls.h +++ b/include/uapi/linux/pkt_cls.h @@ -587,6 +587,8 @@ enum { TCA_FLOWER_KEY_HASH, /* u32 */ TCA_FLOWER_KEY_HASH_MASK, /* u32 */ + TCA_FLOWER_KEY_NUM_OF_VLANS, /* u8 */ + __TCA_FLOWER_MAX, }; diff --git a/net/sched/cls_flower.c b/net/sched/cls_flower.c index 8725aa1bb21e..fafb74198c8d 100644 --- a/net/sched/cls_flower.c +++ b/net/sched/cls_flower.c @@ -72,6 +72,7 @@ struct fl_flow_key { } tp_range; struct flow_dissector_key_ct ct; struct flow_dissector_key_hash hash; + struct flow_dissector_key_num_of_vlans num_of_vlans; } __aligned(BITS_PER_LONG / 8); /* Ensure that we can do comparisons as longs. */ struct fl_flow_mask_range { @@ -712,6 +713,7 @@ static const struct nla_policy fl_policy[TCA_FLOWER_MAX + 1] = { [TCA_FLOWER_FLAGS] = { .type = NLA_U32 }, [TCA_FLOWER_KEY_HASH] = { .type = NLA_U32 }, [TCA_FLOWER_KEY_HASH_MASK] = { .type = NLA_U32 }, + [TCA_FLOWER_KEY_NUM_OF_VLANS] = { .type = NLA_U8 }, }; @@ -1609,6 +1611,11 @@ static int fl_set_key(struct net *net, struct nlattr **tb, fl_set_key_val(tb, key->eth.src, TCA_FLOWER_KEY_ETH_SRC, mask->eth.src, TCA_FLOWER_KEY_ETH_SRC_MASK, sizeof(key->eth.src)); + fl_set_key_val(tb, &key->num_of_vlans, + TCA_FLOWER_KEY_NUM_OF_VLANS, + &mask->num_of_vlans, + TCA_FLOWER_UNSPEC, + sizeof(key->num_of_vlans)); if (is_vlan_key(tb[TCA_FLOWER_KEY_ETH_TYPE], ðertype, key, mask)) { fl_set_key_vlan(tb, ethertype, TCA_FLOWER_KEY_VLAN_ID, @@ -1898,6 +1905,8 @@ static void fl_init_dissector(struct flow_dissector *dissector, FLOW_DISSECTOR_KEY_CT, ct); FL_KEY_SET_IF_MASKED(mask, keys, cnt, FLOW_DISSECTOR_KEY_HASH, hash); + FL_KEY_SET_IF_MASKED(mask, keys, cnt, + FLOW_DISSECTOR_KEY_NUM_OF_VLANS, num_of_vlans); skb_flow_dissector_init(dissector, keys, cnt); } @@ -2986,6 +2995,11 @@ static int fl_dump_key(struct sk_buff *skb, struct net *net, sizeof(key->basic.n_proto))) goto nla_put_failure; + if (mask->num_of_vlans.num_of_vlans) { + if (nla_put_u8(skb, TCA_FLOWER_KEY_NUM_OF_VLANS, key->num_of_vlans.num_of_vlans)) + goto nla_put_failure; + } + if (fl_dump_key_mpls(skb, &key->mpls, &mask->mpls)) goto nla_put_failure; 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,