From patchwork Mon Apr 11 13:30:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Boris Sukholitko X-Patchwork-Id: 12809104 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 CB78FC433F5 for ; Mon, 11 Apr 2022 13:31:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346509AbiDKNdw (ORCPT ); Mon, 11 Apr 2022 09:33:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51138 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346494AbiDKNdu (ORCPT ); Mon, 11 Apr 2022 09:33:50 -0400 Received: from mail-pj1-x1031.google.com (mail-pj1-x1031.google.com [IPv6:2607:f8b0:4864:20::1031]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D6FD63BA79 for ; Mon, 11 Apr 2022 06:31:35 -0700 (PDT) Received: by mail-pj1-x1031.google.com with SMTP id o5-20020a17090ad20500b001ca8a1dc47aso18399279pju.1 for ; Mon, 11 Apr 2022 06:31:35 -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=676tlC8V+fD6Y2L0zNJ5Godg1bIryaH83HQ0927Kk8I=; b=DbI9qIVL7zGvHPBGxDpfDCNYoOJzAm0g4hDgprtOF7jNymRTzYYv+WWtEX4w24XYph eRYEh6jJyB0BVAz551pPTb0lQo4eHbE4cobje6IIjRR2eWcMQpusqSss0hBly336V9al hKNU5UKs4UTUe1MVTk/3hGTmJCw3nmUR+d8c0= 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=676tlC8V+fD6Y2L0zNJ5Godg1bIryaH83HQ0927Kk8I=; b=ziWZR26IL0jB03/lJOxeBZMHkw7ZCFGwUJ0nBGx+q7iJ2xTCeNCZQMBqRcIzoAcUUH F73O86ce9OF0L9LoW9AfIjwyZdjV3QFSF8pNKhzyjk6sW7ivPEfxARjdRZZOIPx0N0VE CAxXEvdHPRL6QkFun9vaDNW1y4GFCY01XVK3VjI/XVpGRJlTxYouriDHbuRxMSfKvays GjXxWqp4GsVUvhJmTRk7O5Q4BNE1C3143r4qDCgJndSr15Bg5sTe+CFhosUGrX2KgP7c /ZK/5uWg30nfucofEVKVG80mRTIpTyfHW64N+PDGs9CKfuodyt3hb4vHnvhTxbaaBq2c 8Tew== X-Gm-Message-State: AOAM530hBUkPdL8Yan4mOdQqXeILk+A/Eely296VyHIneo+GPy794kXt sx2AYsm6fRsFA/ZSkar9/KmLxiL0OC6/xhaZJU/WJEY7js5JG3jJL5gY4mY12NEch/TXPpttuZn EmcWEH6zUt0qGvF/FkQV327o2GZb6eQA61AHZrVQOvmBYXm6E+zaDkNAqW+MDJSJAkc+CThwbtJ 72pD/13hc+0g== X-Google-Smtp-Source: ABdhPJxavH6riJJDLDKFXdm0x0RfVb1zEyBJdDyB4ucC9xB4m5jWyBduKe6r206gZO6uql4ehkjMsg== X-Received: by 2002:a17:902:ecc4:b0:156:b8ab:3ad with SMTP id a4-20020a170902ecc400b00156b8ab03admr32694565plh.132.1649683894892; Mon, 11 Apr 2022 06:31:34 -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.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Apr 2022 06:31:34 -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 1/5] Helper function for vlan ethtype checks Date: Mon, 11 Apr 2022 16:30:56 +0300 Message-Id: <20220411133100.18126-2-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 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 1a9b1f140f9e..6c355b293f02 100644 --- a/net/sched/cls_flower.c +++ b/net/sched/cls_flower.c @@ -1492,6 +1492,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) @@ -1514,17 +1529,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, @@ -1534,15 +1544,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 Mon Apr 11 13:30:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Boris Sukholitko X-Patchwork-Id: 12809105 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 556A2C433F5 for ; Mon, 11 Apr 2022 13:31:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346511AbiDKNd6 (ORCPT ); Mon, 11 Apr 2022 09:33:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51234 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346494AbiDKNdy (ORCPT ); Mon, 11 Apr 2022 09:33:54 -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 6A9953BA79 for ; Mon, 11 Apr 2022 06:31:40 -0700 (PDT) Received: by mail-pj1-x102c.google.com with SMTP id h23-20020a17090a051700b001c9c1dd3acbso16834995pjh.3 for ; Mon, 11 Apr 2022 06:31:40 -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=2iKk1NC5vu/go8aiYfz/cKZD1nvWmZy1aYMh9FXVXKU=; b=G4VL1zYVABri8ocaw29zhhnXaRj+k5eBrTT+4pdp0TG28/Hz0GSQN1JIXq1AoN57By X6HRQQI3HAtMpn+5ehOYZbjKuKgxGTgTlhYposN/FbfphjpB27iddA+LRlIBhXluB9Eu CbFGv6Sbu1WBLmrRD8s4HRmJoCGrVKsXey0V0= 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=2iKk1NC5vu/go8aiYfz/cKZD1nvWmZy1aYMh9FXVXKU=; b=VLuNnQ3mfNWdMxs4kqgSEzkTVu9SnKNJomj7NQ97vkMsMo+1cErf66ff4KyC763ehZ Kvg/PD25vqZ9bYasIQ5oQB6dN50iJkmdA+KRsN/n9jWXmT9YuAUx2v1C+bDQUNNyOMwk 1g39dZZ6tv2+pBioybG5rRRb62DVURl8HWOU1Mdolobbd0Y5HEfXNoXIemz+pE24P5RP Lyxku1y3nmEWnZAgt3x/EgGpRx4JYYVc+QInGPxEIzmgSOdw8qPemQmyz8fYhmHC79i6 he7TxuCGPrgh63RtOIv2kfhFGG7+AsJd4oKks7m4wjv8UxORWpEF3xezZvk1RpmxkC2E W13Q== X-Gm-Message-State: AOAM533kN5G1dGMhdleVcMlu/yTvDeSfkPWeQBbzshceXUf9fd2B6JJV iOPSmVxVFMcnEgt0lswt5LJtL8PwFpXQpqdlRTqaiTZgt2tTzw+bh/xZNGo7HfQPhKZsIK3jlr/ xsZIOU0MhrfJlV0R5J7vEn+YWA0hqro4cHbZ+a88ToZTOixuqksSlmqeMxwxcrMVmhI6mIM7+L7 SbulSxu1fxlA== X-Google-Smtp-Source: ABdhPJyYdASWvbkCAN+dyKWtwzjAycG0iazT/L8+EXDRJ+xQ9xbSWdZAErXS7HhMwj6UUgYQyUFBcA== X-Received: by 2002:a17:90b:3ecb:b0:1c7:74f6:ae73 with SMTP id rm11-20020a17090b3ecb00b001c774f6ae73mr36617633pjb.236.1649683899263; Mon, 11 Apr 2022 06:31:39 -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.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Apr 2022 06:31:38 -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 2/5] Reduce identation after is_key_vlan refactoring Date: Mon, 11 Apr 2022 16:30:57 +0300 Message-Id: <20220411133100.18126-3-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 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 6c355b293f02..e073787dfd1d 100644 --- a/net/sched/cls_flower.c +++ b/net/sched/cls_flower.c @@ -1530,21 +1530,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 Mon Apr 11 13:30:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Boris Sukholitko X-Patchwork-Id: 12809106 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 2CAB8C433EF for ; Mon, 11 Apr 2022 13:31:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346512AbiDKNeC (ORCPT ); Mon, 11 Apr 2022 09:34:02 -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 S1346513AbiDKNeA (ORCPT ); Mon, 11 Apr 2022 09:34:00 -0400 Received: from mail-pj1-x102f.google.com (mail-pj1-x102f.google.com [IPv6:2607:f8b0:4864:20::102f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B5EA93BBC4 for ; Mon, 11 Apr 2022 06:31:44 -0700 (PDT) Received: by mail-pj1-x102f.google.com with SMTP id a16-20020a17090a6d9000b001c7d6c1bb13so16825137pjk.4 for ; Mon, 11 Apr 2022 06:31:44 -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=HEoyXaWkvnAxKhM21UuxTaOS4Bto0EbDHpM2P0C/hW4=; b=JtFAmekAW4Pk79HTrF5X8OyElhanENYP/VGd/2qKcw37+dkYCteqrUAP2F8qN56Ria Ycc2iJ1+v7KRZwa2H176tFnoIHIEcb+eNRWz46McZlOsK/u1m7YJuNwmEu+e6BjjZj7E PtCVRBFtsXEl00rEY6E44Z4oSKvIJcLlmrtI4= 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=HEoyXaWkvnAxKhM21UuxTaOS4Bto0EbDHpM2P0C/hW4=; b=oF9YdxGc85XwTgsNJUI34viF22FFNhdRN0KhGiETSMKyMIfD9sNomvnQgVjPtKSCNZ rERPX01jIONOjpE3cTlb0syduXcT2YjOoSqg7ubMuuL/EO8X9Jw11ab5J/kW+Gwa5O3s TViSPXFzmWT5Z+GFbdcfTnyaLNsnPY6zf+K+7+GsSW9hoqTpcLTLzktA/Xs46CQio3+O F8Mw2eyoRSHCnB2NCU/r2j9Uf/YKfuLl3VsBK65S3PGcKMZz/Jrl6UMned9NTCIj08FF oJpCmPqLalBC2bYPrHli7PWIR7sqVP+P2R82tK9BD8HJV6RnSBDCKEc7sTn1LSJsKJqo eJOw== X-Gm-Message-State: AOAM532nBEgsTN3FHTnQaumcsokjZ5lOGyp2KnM6/PWFAqdB2vhNZDhI 1WUbYc9m4R2LMRlZazRIOapS7tNK2ykrpVO85PzLWuFpbYgUJ5YyoWJMG8uLIOWmZVwHrj8Jxu9 houUgYBQD3fqMK4n8IowfoHqrd9Erb+8WJgFt4gYZ1g044p0UQ57XclhaEno9hovXq1kWAkN5Ec Xw0k2aN3WnEw== X-Google-Smtp-Source: ABdhPJzEEQeDseIWfNEWbom4iMMycKmnsfyPq25mGtC+n35UGEte2Krv1zHJ9bM0fRnlwArAfuZCYQ== X-Received: by 2002:a17:902:e84d:b0:156:bf35:6449 with SMTP id t13-20020a170902e84d00b00156bf356449mr32325397plg.26.1649683903606; Mon, 11 Apr 2022 06:31:43 -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.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Apr 2022 06:31:43 -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 3/5] Add number of vlan tags dissector Date: Mon, 11 Apr 2022 16:30:58 +0300 Message-Id: <20220411133100.18126-4-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 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 15833e1d6ea1..2027e8e72aad 100644 --- a/net/core/flow_dissector.c +++ b/net/core/flow_dissector.c @@ -1034,6 +1034,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; @@ -1157,6 +1167,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 Mon Apr 11 13:30:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Boris Sukholitko X-Patchwork-Id: 12809107 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 B44E4C433EF for ; Mon, 11 Apr 2022 13:31:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241803AbiDKNeJ (ORCPT ); Mon, 11 Apr 2022 09:34:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51290 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346507AbiDKNeC (ORCPT ); Mon, 11 Apr 2022 09:34:02 -0400 Received: from mail-pg1-x533.google.com (mail-pg1-x533.google.com [IPv6:2607:f8b0:4864:20::533]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 15BBE3BBC3 for ; Mon, 11 Apr 2022 06:31:48 -0700 (PDT) Received: by mail-pg1-x533.google.com with SMTP id z128so14216530pgz.2 for ; Mon, 11 Apr 2022 06:31:48 -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=Wx8ep305yjHFiSP++PmsCE+3L8e4J5OhxQAcm9o7JjU=; b=fPg0KoEeDqBOh+k7EHbFL3TzRk6AEiAOIkcTHVk+EQG7qbXgV873Ce8Kel8CMTGLmp nbqo5ioErsO6p3YIqX3deWceOMozWBlOxe1ZckAjqOIAWjWBfGSrp+wIBkZ1sIe6zNcf afh6dgdKY7D8ODIJk/bwZtgDNyR5uuW/fcrfc= 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=Wx8ep305yjHFiSP++PmsCE+3L8e4J5OhxQAcm9o7JjU=; b=Nq6ev6LCa2QX7vkcqxqGCinesfHBiguVB8cz8lCkoAf+b76UABj0+7EfPpfMroqorQ UbTHqxfRBy6YTYLG5K1pnnMh2VC6oMW7olUa+BC/pXEl5ZvVQf8339L0HPxd7z9NJ9N1 SVFoWZm8dLcWtcZ+Vd3QAg9AOsOhygboiy+REwWZAu2FxRvuUkByMKDSNNQ+aZb2mueV TngSykkb8qJdEsR/A4a7HKzJq51RVpQUkVLlmuMzhZO++9c6vAC5rZ8tcs1FvUfkUwis A5FiTA5tyAUnL2S41ZHsuWY9flr13K5eiXUmoHjOcuTNbfNsdZup0Ywl/8F/REWwBiuX kBew== X-Gm-Message-State: AOAM532XDl7q8RLwKZEnzIDDORDMLtGodZSyPOXsqRR9EKAo2jarp6Ik fkwcLZ/dIcDn23Qqx+DeQ+MZE02PlDCEipNMqxBngWH2ptF6mbxeh34/z9+cfFvLYvvtbobomLg 5qr4lwbNXKP9/JGA7ld+uTCWTv6pobJMi5KPQIvWzL/vT72Rpr1GDSCeloaU3kkjaMDlgByznf5 nr9I7CLyGRFQ== X-Google-Smtp-Source: ABdhPJypUPQCb8eNwKjoAwGO0+RgJ3RpjKddrQ7w90P+wGX8ak62mz1TXNBKdJAbEul4RgGWtWOhaQ== X-Received: by 2002:a63:d906:0:b0:39c:c4ca:32b1 with SMTP id r6-20020a63d906000000b0039cc4ca32b1mr18512851pgg.408.1649683907886; Mon, 11 Apr 2022 06:31:47 -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.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Apr 2022 06:31:47 -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 4/5] Add number of vlan tags filter to the flower Date: Mon, 11 Apr 2022 16:30:59 +0300 Message-Id: <20220411133100.18126-5-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 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 ee38b35c3f57..5b14380adb2b 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 e073787dfd1d..42dd84f5a037 100644 --- a/net/sched/cls_flower.c +++ b/net/sched/cls_flower.c @@ -71,6 +71,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 { @@ -713,6 +714,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 }, }; @@ -1528,6 +1530,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, @@ -1817,6 +1824,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); } @@ -2872,6 +2881,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 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,