From patchwork Tue Apr 19 08:14:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Boris Sukholitko X-Patchwork-Id: 12817585 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 9BFD4C433F5 for ; Tue, 19 Apr 2022 08:16:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349837AbiDSISk (ORCPT ); Tue, 19 Apr 2022 04:18:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41028 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349951AbiDSISP (ORCPT ); Tue, 19 Apr 2022 04:18:15 -0400 Received: from mail-pl1-x633.google.com (mail-pl1-x633.google.com [IPv6:2607:f8b0:4864:20::633]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7B0AC7671 for ; Tue, 19 Apr 2022 01:15:03 -0700 (PDT) Received: by mail-pl1-x633.google.com with SMTP id c12so14694254plr.6 for ; Tue, 19 Apr 2022 01:15:03 -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=gzW2nAi4a4O0mFRk/KK7hjRGtZWZywdqhNwWLW/Lu5A=; b=YLnW7t6v7VZS2YIR5E9ZWXvP0SsWP1t4gQT1LzLfrpgWwzt9wCaVVeoFQ7BYOjfDP0 1F16fxaZIx9DZBghHX/4221/V+A2FXtZHRBMJH9/Qt41LoaIsLzWtOmsXYEliJNI4fL3 bRGVLTJDuJ6BZi7MTIwSmLUqyhzQ19FRUK7w8= 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=gzW2nAi4a4O0mFRk/KK7hjRGtZWZywdqhNwWLW/Lu5A=; b=PfnhM810oxvzEz9ieKeCSLKK7/oNiS5nGn1zsrCg1UVm0FmRABp3XzpSjET1eOdAuA CBhdwhHt3iOcnJJg0+fRJ8OfwfXdXOZmw0+Sf8O/YlkxMqhgUWChgdIHgrXb26u9bKOl 7kWwUakIPvtB9oXWEBPQC5E41Wj6l+xw+WldaSX5QYcu306W+BAYPbwyNcGg/ZmVi7cx vf+D3lDMvB8MaIrotSTwfYQZZVehUwynWNuN2jUa0TvOcbM/3Tb804LoQh4Cldfo016b Cm3N68gUNnVML9mzaPrw1w5INcARBktVHY0B6KMFg0Up/FtFnaKFg0nDCdCqqCQC5s8M X/TQ== X-Gm-Message-State: AOAM531zMuLubUeoi0eQnq2XQoE+1Z+G6PiH1doEMRgm5VQww3iAlro6 fAvkkO6TnnjT2GTy5+is43L1BWtemO2Pdc/YZo5KngfWS13vbjbJt701EIJV3UC+1pKJsfQKUVf k6hTAxqSk9wDpNGgq2AaQbfGUWvsp5s33m72KhtA+1zkSAMEtgQxdaBUe/FaMMamdTOe4HzF6P2 CDB+iW9vZTbg== X-Google-Smtp-Source: ABdhPJxqborsaFEEdXpnJbdm34iGIukpmiPmGGlPNf7qT5TejGxKOuXrrBqSHGATNXCyjyrxD/ysvA== X-Received: by 2002:a17:902:e0c1:b0:158:e03c:fc82 with SMTP id e1-20020a170902e0c100b00158e03cfc82mr14424051pla.134.1650356102383; Tue, 19 Apr 2022 01:15:02 -0700 (PDT) Received: from localhost.localdomain ([192.19.250.250]) by smtp.gmail.com with ESMTPSA id cp19-20020a056a00349300b0050a890c8c16sm4284570pfb.19.2022.04.19.01.14.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Apr 2022 01:15:01 -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 , Paolo Abeni Cc: Ilya Lifshits , Boris Sukholitko Subject: [PATCH net-next v4 1/5] net/sched: flower: Helper function for vlan ethtype checks Date: Tue, 19 Apr 2022 11:14:30 +0300 Message-Id: <20220419081434.5192-2-boris.sukholitko@broadcom.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20220419081434.5192-1-boris.sukholitko@broadcom.com> References: <20220419081434.5192-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 222b0b8fac7a..c88d69ebe2c8 100644 --- a/net/sched/cls_flower.c +++ b/net/sched/cls_flower.c @@ -1579,6 +1579,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) @@ -1601,18 +1616,13 @@ 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, TCA_FLOWER_KEY_VLAN_ETH_TYPE, &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, @@ -1623,15 +1633,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 19 08:14:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Boris Sukholitko X-Patchwork-Id: 12817586 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 5EFF2C433EF for ; Tue, 19 Apr 2022 08:16:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344958AbiDSISm (ORCPT ); Tue, 19 Apr 2022 04:18:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42238 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349832AbiDSISQ (ORCPT ); Tue, 19 Apr 2022 04:18:16 -0400 Received: from mail-pl1-x633.google.com (mail-pl1-x633.google.com [IPv6:2607:f8b0:4864:20::633]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 49FFADF20 for ; Tue, 19 Apr 2022 01:15:08 -0700 (PDT) Received: by mail-pl1-x633.google.com with SMTP id be5so14668626plb.13 for ; Tue, 19 Apr 2022 01:15:08 -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=wMrfpHIoM6DCuiIz+x80fs9sMOyAP6IpMayogaNTw8A=; b=SMT2lS/I6u+xyfAMMWSkhQi3cMVTYijhD2cKlHtgVYLoaCLqnnZPX1wXzdjrYTTwU+ ROl2XQ0nWbzjnbtgGzg0Lfcjh3GpNHjJOSwk4xyHJGigLlOXXcIKDtuaflU2N0qRLkBy 1fGrXD0GHnjjLWhnlWCH4i8GYLoXl3Zcdeydg= 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=wMrfpHIoM6DCuiIz+x80fs9sMOyAP6IpMayogaNTw8A=; b=yLBFxYBlYX3baaT/9HM2fvIJ3u1rIaccKSVJArp2gVe7waRYBQfAeX8LGNqe+1UKoz boUJ/r+EbYPq+I97MosJn6HGJMgVRYBOYQ535zUwHWFczspRDkArcTtxul0+3h7JKb/1 c28gR0l9wZCPQdNeVtPbKNzyzKneJlSaZV5/c1cwjuVEdjLYNwHJ3q2XlB4x5JxkB8qP 4Ve1IHMEevObRQgLtH85pms7uB1gP8MIkWteC3YeSyLXHYBitMvPll8HE/8wRxF8hYhg bK52x/Y88/AR61OFWmH9UegVhmQq91RdF512GkCJfj6Ohp7dW1hSrRyjbE6zvWQTwRz7 cxEQ== X-Gm-Message-State: AOAM530VW+HIaFZGyscOvr3rYV1p7uOsizGfq1Q+ZihVbi/Vx2ls48Mw BvX+S6GmTv9/WQ0h/ZL0ftzEXxQIG1pbPU3d4czopIX0x5Dhj8Z1hCdaLB8TkGHktXA1iGw8ag6 hLnUJ53v2OrnDaKqpWLC+6Jr1mJUMZPozacH8vejkcFP5XhVw5bkmwxYjGzX0rdvGml6UTAEN9f 3wSvPd4p0F+g== X-Google-Smtp-Source: ABdhPJxWvXKWn82jBeTZotUaNId/ksw5LTH/hkoOQ1bStBhREFoyEX5zAoI7Hxw1PY+YyQbUvXbOTQ== X-Received: by 2002:a17:902:e743:b0:159:40a:a156 with SMTP id p3-20020a170902e74300b00159040aa156mr7450199plf.89.1650356107476; Tue, 19 Apr 2022 01:15:07 -0700 (PDT) Received: from localhost.localdomain ([192.19.250.250]) by smtp.gmail.com with ESMTPSA id cp19-20020a056a00349300b0050a890c8c16sm4284570pfb.19.2022.04.19.01.15.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Apr 2022 01:15:06 -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 , Paolo Abeni Cc: Ilya Lifshits , Boris Sukholitko Subject: [PATCH net-next v4 2/5] net/sched: flower: Reduce identation after is_key_vlan refactoring Date: Tue, 19 Apr 2022 11:14:31 +0300 Message-Id: <20220419081434.5192-3-boris.sukholitko@broadcom.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20220419081434.5192-1-boris.sukholitko@broadcom.com> References: <20220419081434.5192-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 | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/net/sched/cls_flower.c b/net/sched/cls_flower.c index c88d69ebe2c8..86fd0420ac4f 100644 --- a/net/sched/cls_flower.c +++ b/net/sched/cls_flower.c @@ -1617,23 +1617,23 @@ 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, - TCA_FLOWER_KEY_VLAN_ETH_TYPE, - &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, - TCA_FLOWER_KEY_CVLAN_ETH_TYPE, - &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, + TCA_FLOWER_KEY_VLAN_ETH_TYPE, + &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, + TCA_FLOWER_KEY_CVLAN_ETH_TYPE, + &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 19 08:14: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: 12817588 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 00679C433F5 for ; Tue, 19 Apr 2022 08:16:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349900AbiDSIS4 (ORCPT ); Tue, 19 Apr 2022 04:18:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41584 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349953AbiDSISQ (ORCPT ); Tue, 19 Apr 2022 04:18:16 -0400 Received: from mail-pl1-x62b.google.com (mail-pl1-x62b.google.com [IPv6:2607:f8b0:4864:20::62b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4AE78DF36 for ; Tue, 19 Apr 2022 01:15:13 -0700 (PDT) Received: by mail-pl1-x62b.google.com with SMTP id j8so14666879pll.11 for ; Tue, 19 Apr 2022 01:15:13 -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=r98GFgL1vPFduI/1UNny7wA3xIIYn23353PVZy3Cvd8=; b=Mbxp9zp2z/IcznWH8rWiTdcHu7zU48fs75NJAc2WPFr7E0YuajcwIMKq9zGsE0Op1Z CJJqRBnoo2kA+TTQiXjwdvEG/tIflT635t5opPn6pNKthnidVMb/N4RSE0HuRnVOqO5v kf+8BnKRSMo74rsVEnmUR1F6GKAb5x/B8kUVA= 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=r98GFgL1vPFduI/1UNny7wA3xIIYn23353PVZy3Cvd8=; b=XxqE0e7WlVnf+VA48O3AvztTg1zOdXKPtoxcZM9xjnp8HPA6844sw2nLd57qJESkRU z6L2anoVCBtQDIr0qD9jfIhQLP3ncTUqOWwnd/dLI3TIWYgC1UJthU7ctxfGkoZJbrOW +EgHYwtBNQiippMp+f4JpQIuskrpigwuKfVHzW5PHxrcQWlE79wswC+7DFetZjDuGJ8g 3gfQPIEdZ3dVFCXWvStgQIv3/SoCrdi2IImbo6okoByo61tBln7cmSaURaqKCS8uro0k kJAcbYj64nkc7J1tM5k+JenDqTqTY7wu2N+H0UASsoyrHXzJnKaqifJxEE5Q1hq2IJBT ToMw== X-Gm-Message-State: AOAM532oo18IHyFzuCHs+5YkTcpMLxYORk+RcT4aBKGqJUAtIg0/HC+V Lrc9+/1zDaxnUGskD+AxNtZNeGDrVvfXxAGOE8Il8YNSSsWSO6Gm3z8Y5zS4UERMlLOz6g2Tv03 62wAcOI2tb1gFK4bXg+PLWJR2TyIayOdkNnP5wg3eZ4s46SzD4FZDkDEaIVUUMBA193qpDLBEHX laBzxEVUNTlw== X-Google-Smtp-Source: ABdhPJxmSu7hu/C5oNJ0d1hbCjKUfZ4RxR8iPeePfmpiOGHT1dOuLVr2wc6fAY/GlxNDLdneeCdePg== X-Received: by 2002:a17:903:32d0:b0:158:fe2e:d2a7 with SMTP id i16-20020a17090332d000b00158fe2ed2a7mr8190787plr.93.1650356112493; Tue, 19 Apr 2022 01:15:12 -0700 (PDT) Received: from localhost.localdomain ([192.19.250.250]) by smtp.gmail.com with ESMTPSA id cp19-20020a056a00349300b0050a890c8c16sm4284570pfb.19.2022.04.19.01.15.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Apr 2022 01:15:12 -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 , Paolo Abeni Cc: Ilya Lifshits , Boris Sukholitko Subject: [PATCH net-next v4 3/5] flow_dissector: Add number of vlan tags dissector Date: Tue, 19 Apr 2022 11:14:32 +0300 Message-Id: <20220419081434.5192-4-boris.sukholitko@broadcom.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20220419081434.5192-1-boris.sukholitko@broadcom.com> References: <20220419081434.5192-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. The goal is to make the following TC commands possible: tc filter add dev eth1 ingress flower \ num_of_vlans 1 vlan_prio 5 action drop From our logs, we have redirect rules such that: tc filter add dev $GPON ingress flower num_of_vlans $N \ action mirred egress redirect dev $DEV where N can range from 0 to 3 and $DEV is the function of $N. Also there are rules setting skb mark based on the number of vlans: tc filter add dev $GPON ingress flower num_of_vlans $N vlan_prio \ $P action skbedit mark $M 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 9f65f1bfbd24..a4c6057c7097 100644 --- a/include/net/flow_dissector.h +++ b/include/net/flow_dissector.h @@ -253,6 +253,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 */ @@ -282,6 +290,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 6f7ec72016dc..6aee04f75e3e 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, eth, 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 19 08:14: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: 12817589 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 330F5C433FE for ; Tue, 19 Apr 2022 08:16:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349912AbiDSIS6 (ORCPT ); Tue, 19 Apr 2022 04:18:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42240 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349954AbiDSISQ (ORCPT ); Tue, 19 Apr 2022 04:18:16 -0400 Received: from mail-pl1-x631.google.com (mail-pl1-x631.google.com [IPv6:2607:f8b0:4864:20::631]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6DDE8E0AD for ; Tue, 19 Apr 2022 01:15:18 -0700 (PDT) Received: by mail-pl1-x631.google.com with SMTP id n8so14714909plh.1 for ; Tue, 19 Apr 2022 01:15:18 -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=Dv/gjXAbHV0aJeQBkiI22YJ46DKVdZ4jwHxAeGQVUnQ=; b=BxSYF11IfOsPy2aX6brnnZTp78qxq6jBDkOUxf7o/SLP4FGjRCuzQ9E4lOdnQiPbwo EXvmXrlVDnZXtAFWVGi9+E2uxOUGLwPYvrdpr0m276U62nkJF3g/iZQx8jn8fK3K0WK3 YmaiOqDSOZnej4dsQ3+sS78mW5pMVXlksoze0= 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=Dv/gjXAbHV0aJeQBkiI22YJ46DKVdZ4jwHxAeGQVUnQ=; b=lL1blnQ0lbyxCy616N4Ji8pNiu8i8aonrpDIF8pW7j2fhPRbie45O6eznMwUXLb4jd EAZJszcSCyAuUX5GrbwBHuI9le//2pf58cfbCSkbLu82xw5MZkU9oHnnDdxS6O3kkL7c AUz0xju74hdRzNwa+nSK4bDcHi1e5G1xRH3nlqKr1Vm0uW/pZrpq1a63fWSGOK69r0RF CMLhogrYfPTKg9YuHMYq4JksK/Wx7MLb7ZqaTiiiXR32Y/xl8EtAqgk79u7+qp1Klse8 kMWgFU1utSTTpthhqqZCyAAEBPf2NnK4o2stzb0t0C9lFIzWpLTf8tOKLCfApY/JdlWV mc4w== X-Gm-Message-State: AOAM532GO+S9Fmt5xTttug1xv4rCV5/+4uCOa+UsZFvNEDrYHSQHhIt7 zuPfeWwfQTuGL9LLP5pzM2QT+jI7jp3s/1qBWm4+s8+57kD69l8rLsbSKXN9FzevT9NclB3tNYV 32T2qnZ3AHuePBN5Fso7Ds6XnGgWU+sF3GNT6pgLn+3nYxX7lhDql0n59HRhO8FAONcZXyG2oOx uJek/lj05QtA== X-Google-Smtp-Source: ABdhPJziwPmH9ZaxQXiXWDc6OwqlvrnevXdrDqFwdezfT3TrQcKSqxMyaR4qCRG8iyOU8Iejn4ZHOQ== X-Received: by 2002:a17:902:7088:b0:156:1aa9:79eb with SMTP id z8-20020a170902708800b001561aa979ebmr14568780plk.71.1650356117575; Tue, 19 Apr 2022 01:15:17 -0700 (PDT) Received: from localhost.localdomain ([192.19.250.250]) by smtp.gmail.com with ESMTPSA id cp19-20020a056a00349300b0050a890c8c16sm4284570pfb.19.2022.04.19.01.15.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Apr 2022 01:15:17 -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 , Paolo Abeni Cc: Ilya Lifshits , Boris Sukholitko Subject: [PATCH net-next v4 4/5] net/sched: flower: Add number of vlan tags filter Date: Tue, 19 Apr 2022 11:14:33 +0300 Message-Id: <20220419081434.5192-5-boris.sukholitko@broadcom.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20220419081434.5192-1-boris.sukholitko@broadcom.com> References: <20220419081434.5192-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 86fd0420ac4f..4ec4d742e82f 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 }, }; @@ -1615,6 +1617,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, @@ -1906,6 +1913,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); } @@ -2994,6 +3003,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 19 08:14: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: 12817587 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 258A4C433F5 for ; Tue, 19 Apr 2022 08:16:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244623AbiDSISn (ORCPT ); Tue, 19 Apr 2022 04:18:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41040 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349865AbiDSISR (ORCPT ); Tue, 19 Apr 2022 04:18:17 -0400 Received: from mail-pl1-x632.google.com (mail-pl1-x632.google.com [IPv6:2607:f8b0:4864:20::632]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D0CA129C96 for ; Tue, 19 Apr 2022 01:15:23 -0700 (PDT) Received: by mail-pl1-x632.google.com with SMTP id v12so14703258plv.4 for ; Tue, 19 Apr 2022 01:15:23 -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=O6JK3QRCrAxB5Zk4fKxsfTVoI0q1aMb6cuoiguD2iWs=; b=QMH8ACBazzaiUynBglt2Pu7HDYZxSUUIvFcSN5twuLVnq1RjP8KKnUvBXNStUSyyr4 WZrsI3PVUo5dDO0zY31V2+toUgwU19a10OOo3M7bE6XT3RkdCZxF0gklW/AEvh78bw8M knQhbJ622KtzHcEJ4rKnqrB1fSIve6olM6KLg= 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=O6JK3QRCrAxB5Zk4fKxsfTVoI0q1aMb6cuoiguD2iWs=; b=sfio1ONYMY2kHukQG9bUIR0JApz4ltvPCWbIJv6cwNSxhsipHYveSTOIjA/E680zws 4JHNb/tTFMXiq5GvhclvSAjtU8Yy8iSCrVxEQKQo0lj3zhOihOuWW3ntzPmzkLFugG9a jZeRp8Sa7VXVsutSg4IK5tKjaNfAIHL8tihQ6gk+gYd1oeH8oWBaA1/t/+RI14T4akj7 exwYiFFjfT/U3r6hiyjl1LG/g223x2DgJqD5NFmO6FnCjaAflVWhQ3HfqN9Mlq8NS9fj B5lekkObSY7Q7yfqp6QckxrPPsnhXFtmVX1Rw1DpSWTJDE2G8qygGatDP5bOQ0L/g026 NecQ== X-Gm-Message-State: AOAM532FTYmzYNhwi0zFBHB4kweGyYm8OorERQKWenZq7mKLvXaNtXO2 Wc6g1e1yAiFIr3r2qqJ98qVe1LgygGLjtFprz1UPEIvT9g/3bbitueHLNfl6tE2uN2HYm1hEB81 KyJcUatrnKt7cH/y0uWJndIXP50GT3i8ZhZc1oc4B1hx5jWiWTtGpsakXqpMWfyu0Xxi1hzqIMP rUVMBHyGwKHQ== X-Google-Smtp-Source: ABdhPJyv4AOnECkWs2cXU1O0GCp14MvSVf92gwEZxiPHrgU6y/Ua+NNVMxKr04yow322hOBSc5tE9g== X-Received: by 2002:a17:90a:384d:b0:1d2:97de:eb8c with SMTP id l13-20020a17090a384d00b001d297deeb8cmr9911611pjf.208.1650356122666; Tue, 19 Apr 2022 01:15:22 -0700 (PDT) Received: from localhost.localdomain ([192.19.250.250]) by smtp.gmail.com with ESMTPSA id cp19-20020a056a00349300b0050a890c8c16sm4284570pfb.19.2022.04.19.01.15.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Apr 2022 01:15:22 -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 , Paolo Abeni Cc: Ilya Lifshits , Boris Sukholitko Subject: [PATCH net-next v4 5/5] net/sched: flower: Consider the number of tags for vlan filters Date: Tue, 19 Apr 2022 11:14:34 +0300 Message-Id: <20220419081434.5192-6-boris.sukholitko@broadcom.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20220419081434.5192-1-boris.sukholitko@broadcom.com> References: <20220419081434.5192-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 Before this patch the existence of vlan filters was conditional on the vlan protocol being matched in the tc rule. For example, the following rule: tc filter add dev eth1 ingress flower vlan_prio 5 was illegal because vlan protocol (e.g. 802.1q) does not appear in the rule. Remove the above restriction by looking at the num_of_vlans filter to allow further matching on vlan attributes. The following rule becomes legal as a result of this commit: tc filter add dev eth1 ingress flower num_of_vlans 1 vlan_prio 5 because having num_of_vlans==1 implies that the packet is single tagged. Change is_vlan_key helper to look at the number of vlans in addition to the vlan ethertype. The outcome of this change is that outer (e.g. vlan_prio) and inner (e.g. cvlan_prio) tag vlan filters require the number of vlan tags to be greater then 0 and 1 accordingly. As a result of is_vlan_key change, the ethertype may be set to 0 when matching on the number of vlans. Update fl_set_key_vlan to avoid setting key, mask vlan_tpid for the 0 ethertype. 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 4ec4d742e82f..dcca70144dff 100644 --- a/net/sched/cls_flower.c +++ b/net/sched/cls_flower.c @@ -1030,8 +1030,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); + } if (tb[vlan_next_eth_type_key]) { key_val->vlan_eth_type = nla_get_be16(tb[vlan_next_eth_type_key]); @@ -1582,13 +1584,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; @@ -1623,13 +1630,14 @@ 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, TCA_FLOWER_KEY_VLAN_ETH_TYPE, &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,