From patchwork Wed Mar 23 10:55: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: 12789673 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 711BFC433F5 for ; Wed, 23 Mar 2022 10:57:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243302AbiCWK6o (ORCPT ); Wed, 23 Mar 2022 06:58:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51822 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236170AbiCWK6l (ORCPT ); Wed, 23 Mar 2022 06:58:41 -0400 Received: from mail-pj1-x1036.google.com (mail-pj1-x1036.google.com [IPv6:2607:f8b0:4864:20::1036]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0EBDA5E15A for ; Wed, 23 Mar 2022 03:57:12 -0700 (PDT) Received: by mail-pj1-x1036.google.com with SMTP id mp11-20020a17090b190b00b001c79aa8fac4so380558pjb.0 for ; Wed, 23 Mar 2022 03:57:12 -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=FmtL821K/N0EGMt+A8DFR8q/xWlOwRnc5XzdUrGidr8=; b=G5PxUh9Sc5PmxzoxWtZxwy9MVjgn+rRnhiIUunGXDPL+57z28ZHyC/MSmhiwUwWJq/ ag69j3gni5fkjj0rSksSknvNNefF7ig6lt5itcruuthexudzbyaZcV+LsZ0Nz0kSSIR7 gbqHMxxo7PI9FRPnQzDvTUQxwezGFMx6tGt7o= 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=FmtL821K/N0EGMt+A8DFR8q/xWlOwRnc5XzdUrGidr8=; b=Q7DVkGSROt4gSg5VEWtMkG6KycT7C8ASo9a5SZJ3/VFU9t4Im4gcVwH7+mTULEIFTH iCTKar1hYjJ9yw1o6GXhpvLP7VQeGiEFB9WbbcdAlA0BflRZw30ybCOkSn+TU+LaHWHY vEFff7V3zHY9ePTVWn3/sFJIuhz5FBpjCt9V1+PslruCDRrcGW7qV8uQPuZm0bQBuXjE JuaH6GoE9Leyvr6YSs5FWFJjtfkupkURAJJmuNsDSsiNDJFT6tPE4QrFNVy+jeD6hEbM ampcBx3DuPDKbJpqFN2ILbzZwOU7Mrqk+zRvZa2DMkqA3eADI4dfuUjupHUUh9iTwcii pNqQ== X-Gm-Message-State: AOAM532LwOjTgk1yi+0XLHipAl/AT3r6VSxGLo8p7yftKx0+ONWWnXNF xpzyDalFA6puTFnNcl7pmpsIfYqgs8HE61t5ZhnR2UG0hzTtQrTmombhW4mk9WFTfQi/Moahe65 8ceT1ajBJSLDiY0SliMEAlOJjK7TkuDDlAS0dwgjpQ3EmPcAVbCI2RswYcp6whvi85UFma5vXoa 175uuZ1NnpdQ== X-Google-Smtp-Source: ABdhPJxwEs/fFVaL74GzLSsAALIC0xNO04Nb1I/bUImUUALgGLbvIbSeyOs0OHjdMw0s1wjnt3y99w== X-Received: by 2002:a17:902:e803:b0:154:2699:7f39 with SMTP id u3-20020a170902e80300b0015426997f39mr22330226plg.172.1648033031150; Wed, 23 Mar 2022 03:57:11 -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.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Mar 2022 03:57:10 -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: Wed, 23 Mar 2022 12:55:58 +0200 Message-Id: <20220323105602.30072-2-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 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 Wed Mar 23 10:55: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: 12789674 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 D7AF4C433F5 for ; Wed, 23 Mar 2022 10:57:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243635AbiCWK6s (ORCPT ); Wed, 23 Mar 2022 06:58:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51874 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236170AbiCWK6p (ORCPT ); Wed, 23 Mar 2022 06:58:45 -0400 Received: from mail-pg1-x52c.google.com (mail-pg1-x52c.google.com [IPv6:2607:f8b0:4864:20::52c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5FFD05F8CD for ; Wed, 23 Mar 2022 03:57:16 -0700 (PDT) Received: by mail-pg1-x52c.google.com with SMTP id z128so813323pgz.2 for ; Wed, 23 Mar 2022 03:57:16 -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=cbE4kL7VCryp+0XBxWUBmI8bbdZbrOSKHdwl74h8AIc=; b=HBIRcCjOqea65d6IBWbNaHkSiDDQ57Xwj6Q7jtoirHe4XMNagiCahtcfwMYpUu0VfU QqbMPm/teFg0paVjGBBEFut6phDLlPTZ+o2O6j1Rm5JZkwkvB5ZOtPFkfAiDrRRGb53t Gq+qtaXZu7b+C5b+Hh9HjaAwaX57CJrfjKpj0= 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=cbE4kL7VCryp+0XBxWUBmI8bbdZbrOSKHdwl74h8AIc=; b=LnUPs4te8dJlgXJPptLwp/TDa0hMwQWdcUt7LUNdLiIHucZrkC80XtIcwIFldt0mfG qwwYzPQ6/b6v+nrGCb2aCdM39xU8QZYahOtB1v/7FGV8ERyD+nuTtdJ9XkIHYxeUsekl 5Sqgds+rebmbPflVvTX7FPEyK/twv3t/igisRqeUS0Hijx2QUGJIwB+l6AyK+Dlxkr20 Hkgqr7ypsDLKd6svt75lOujgWn00szl14EIlLtpUfpp6S7qKKSVGHVIDypKyWkYDXBG4 iMPqtuNlSKyf4FGJMNIC19HFmt8vpaUlqMDdX75z0v+fTdVdPg7TUdBNKKcnq6NhzBOM SaHg== X-Gm-Message-State: AOAM530GkYzHi5sWTURya85IIf5gkIRdVovxcwrPMy9m3q3cRIKG7GRS 4hg0NMLHh24vRojMbGbLJiq07cwvAfsMXV0cBha3tf8wAf8egxHvlnt1/jSX6q0y25a4jJP82Ba DDCKL1lTELInejxIBGQZTmaRmIiPrv+ExxO10fIvW/F39niqY9E3RcljRqqtSR1OPbBhiOQ354+ 28cTWA++FOAg== X-Google-Smtp-Source: ABdhPJwtSaWppfMG6wKHyuHOUT1iYYtoHkJ8pZTxzN7T5l3q+5QhN4whVDqkvE5ly0n4LH0pS7sK8g== X-Received: by 2002:a05:6a00:1f08:b0:4fa:8a47:cf35 with SMTP id be8-20020a056a001f0800b004fa8a47cf35mr19432254pfb.22.1648033035520; Wed, 23 Mar 2022 03:57:15 -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.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Mar 2022 03:57:15 -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: Wed, 23 Mar 2022 12:55:59 +0200 Message-Id: <20220323105602.30072-3-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 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 Wed Mar 23 10:56: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: 12789675 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 51404C433F5 for ; Wed, 23 Mar 2022 10:57:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243650AbiCWK64 (ORCPT ); Wed, 23 Mar 2022 06:58:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52046 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243653AbiCWK6x (ORCPT ); Wed, 23 Mar 2022 06:58:53 -0400 Received: from mail-pg1-x530.google.com (mail-pg1-x530.google.com [IPv6:2607:f8b0:4864:20::530]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D1C71E0B2 for ; Wed, 23 Mar 2022 03:57:20 -0700 (PDT) Received: by mail-pg1-x530.google.com with SMTP id s72so804885pgc.5 for ; Wed, 23 Mar 2022 03:57: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=aK38zu/2Mu+Y7RpHPWRyO4IfzwCIUy/CJrY/LjbOk+4=; b=G2Mj4Co7ZfwZg3rOLz5EAtWgds7atpi4blMN8ZSgiF4TnNTBmk7/AQJ+lZJdgRC6GV 9GpNb12VypYI2Mrf9frlAfg36sAVm4hha1qX1CfT21Mt/1u0KkCctTFUllSuM8wDhY0g o1lSKGStbo2SLkDw5Ee+EfKDVPZFin72+3YYs= 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=aK38zu/2Mu+Y7RpHPWRyO4IfzwCIUy/CJrY/LjbOk+4=; b=C1SV905Z2Hb3mvHYvxM/MDlpuSTtpmm/Mjc/NS97IT2nQbt1jShL2/qBXVe+k6hynG 2hDqAakGv1FP/myAu/ulAmrWbr/yTSUthdkch6E0TJxtvDVwwxZTiZ2Y5C6hDbKYBicQ phLO7TUcnWmD5akbNBd44sJ8B87QNQIRgnPKkxz6+ptAWTFst+DPWE1rtRHc5vdHAgx6 Ar98SfZIypDj0x8rgsIs0rjz1MDQCafOC8GiB4XirhiexN8CUcrp/6hxrYr1VAaACrM9 jkRLpGMmk7gl0tW831ecbDHglfihBIhzDrezByqIetdRPD/+oZpCJo3Siye9+RhU3l0B MLOQ== X-Gm-Message-State: AOAM530f/QJzXDbyOUZbNLzbBgTjPDdqptTXBIqWSQe2/KsHR2GD+pqh BFCDzNlLkjK2a+++NrbEr9z9M7J7GEPrrOobykjD9brXBHexKDRaNm+5unfOBhUIr7tXdfGczPu 3DrgL+unEspSqtZ4MUs6b8Q17SjnFy3fMKpRRDHWel1GsHj/nCiFqZarsKST65mRNGZ2RFeNbgy 4ssbNgOV/jew== X-Google-Smtp-Source: ABdhPJy0/dIKtZcyCS1vGKNm8D2hL5b2tC3nAwxusLpYh+FG4LFPbTxyPF8m6WEAv4OlZQTUPdJHRQ== X-Received: by 2002:aa7:88c1:0:b0:4fa:7031:895a with SMTP id k1-20020aa788c1000000b004fa7031895amr26794950pff.22.1648033039962; Wed, 23 Mar 2022 03:57:19 -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.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Mar 2022 03:57:19 -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: Wed, 23 Mar 2022 12:56:00 +0200 Message-Id: <20220323105602.30072-4-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 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 Wed Mar 23 10:56:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Boris Sukholitko X-Patchwork-Id: 12789676 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 4C4C4C433F5 for ; Wed, 23 Mar 2022 10:57:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243658AbiCWK65 (ORCPT ); Wed, 23 Mar 2022 06:58:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52080 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237751AbiCWK6z (ORCPT ); Wed, 23 Mar 2022 06:58:55 -0400 Received: from mail-pl1-x636.google.com (mail-pl1-x636.google.com [IPv6:2607:f8b0:4864:20::636]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2CCEA5E15A for ; Wed, 23 Mar 2022 03:57:25 -0700 (PDT) Received: by mail-pl1-x636.google.com with SMTP id c23so1183941plo.0 for ; Wed, 23 Mar 2022 03:57:25 -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=TP9lZYu9/4UOvGogYOUdC98gvB2K8ztoBK9THxnsg6c=; b=AZwBT9IfS8m/iPFVf+m3739+kKa3gndOE8d85oNoKHl8LVY4zrAdvfoyup0s0HNvGb ev1Kz9gw77chjqZ+/0zDwdU2Hht69pzvKTilWfzeBadpGwsTUUGsNTlu8lFqnh/8Ql6m JAt/bdLxwxS2j2AAmABunJ0e0V2X3vIRwEdpo= 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=TP9lZYu9/4UOvGogYOUdC98gvB2K8ztoBK9THxnsg6c=; b=UnaIP9DbLN8Fn/RzHuhNbrF5aMxL4aYmqx9JhPb5MqHK/VkaxXFUL8aqDmUasEi+XH hBjqVfea/aTKT38fnLtKoWpyug1tRENnwu2sybUpy7Kuilq1gM6b/IesksIGErANA132 l0eNZaiUP6pV+sTG2Gx9OLP/y8g/SxEWjkhJoCYVgkCge8gvin/S2o/4NC+g94nV/J2O opBZHZZHfgTaYJyAolOrCKhTURah7CQT2CdGY8j1Fac2bA+Xft9A0iOhzcNdovmEoo79 /othIr+94iaNdf4ahK/9En/4Q1KPZShbzBLUkT/JkoxCNERXuB+wUrC7kd1b6UAygYgy 2qWw== X-Gm-Message-State: AOAM532AfAtYMExBbpLGIHE2U3k9ti+SAmWUE4QdWTM8OFm1B8RED5SY qOXUTj/j107z524onFAP2Uw+gAth+aZnZ4I5SxJKoRVwmE6OSaI6CO/U5lfJV7Opzz5zB/yNROp ovBY1D4scK3ZyZAsxCJ6O+DB7SS794u8PMnBIjjxC+kFb6qYa8w61NR6GzdSjasZqdXvGQnXQJb hTI0+Czp4eYA== X-Google-Smtp-Source: ABdhPJxqLBsTe7fuNArzgeDyzR78sKxUo5bcSUIvCx2Ee7mJESapflyYCVNrVqoPyDzGjrPwccoyTQ== X-Received: by 2002:a17:90b:1d84:b0:1c7:880b:9efc with SMTP id pf4-20020a17090b1d8400b001c7880b9efcmr3437359pjb.90.1648033044344; Wed, 23 Mar 2022 03:57:24 -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.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Mar 2022 03:57:24 -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: Wed, 23 Mar 2022 12:56:01 +0200 Message-Id: <20220323105602.30072-5-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 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 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,