From patchwork Thu Apr 14 12:51:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Boris Sukholitko X-Patchwork-Id: 12813493 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 5D3EEC433EF for ; Thu, 14 Apr 2022 12:52:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243627AbiDNMyh (ORCPT ); Thu, 14 Apr 2022 08:54:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50812 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240566AbiDNMyb (ORCPT ); Thu, 14 Apr 2022 08:54:31 -0400 Received: from mail-qt1-x836.google.com (mail-qt1-x836.google.com [IPv6:2607:f8b0:4864:20::836]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 06D0192320 for ; Thu, 14 Apr 2022 05:52:07 -0700 (PDT) Received: by mail-qt1-x836.google.com with SMTP id t2so3415869qtw.9 for ; Thu, 14 Apr 2022 05:52:06 -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=phmsGVxFARIdBuJu/YQGX4HGvJHHCFWteZnoiFypqS0=; b=OfTWOUodt6VHf0opxQ+u8QbI3/q/zTDMhMvy6Dm5NQU08Ao2eHWSPsh9Kxm1gvG/GB GNZpNjdrhKt1OGk/qqgKoB9bO7Y+M8/8mDrIhZLcc7eqYGjVaMiJ4OxkU03W8M7oMopF CclioIvkdRh47DyZpcFp3NZXH8Hh0uzIBE4J4= 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=phmsGVxFARIdBuJu/YQGX4HGvJHHCFWteZnoiFypqS0=; b=H/d5r/+gCf4NnFUKd4ufsQLmUFLAEU2g+w3uhbxmkuz5R4iW9kl2hpwW8QB4gOFrMc bfUtFWFiVw57HnOzRZBgRGuist+KpJVzZXcmc0/AjGGGKihsM6uvcHtNmFmPxy8QST9T wooS7djwID67T0KipGYks+7e5z+SyAKFXHixF0ISkbjNl4FzlojGznpvM7zs6ZET7iEK yAdtINyfgGozfywXkvNC1vhohLdOD9AOb1Xu1NG98xinCc56w7z1d1DY4oREsWFC3U/L pDqlAUisEhLcOaW0EQlS2ZBlQi6jTYxdeaZ5gxEq1wKD6D341Xyj9ykfGIi3Bv8kowor MVCw== X-Gm-Message-State: AOAM530iYJocs7pJCaA8257IOE0BbNnhqAt9qEh6zmsNgRtmv7a8AtX4 RA5ptfEr0glnWNa4TJTw2F/wkrnIfFX8huOBg6gi4RgHuhtb8WOkQIoP6rvy+u4et97c+Ha9A0F cZELbWsp32vXmSoZDi8v5TAO88JG1QBPDYgD3eruKGLJ/6ZFXE09NDSSZ6R7yLwnv/dDaf/627c OlnkOHesF/Ww== X-Google-Smtp-Source: ABdhPJyz4eX3h4eCabUmGAFQAnam2DLqVLngO92tf5pxpJH7jEYJ96ifpDOZWtQaCwgUiteeiGvGLA== X-Received: by 2002:ac8:5883:0:b0:2e1:c6f9:a12f with SMTP id t3-20020ac85883000000b002e1c6f9a12fmr1557741qta.439.1649940725771; Thu, 14 Apr 2022 05:52:05 -0700 (PDT) Received: from localhost.localdomain ([192.19.250.250]) by smtp.gmail.com with ESMTPSA id o10-20020a05620a15ca00b0069c39e2970bsm875910qkm.80.2022.04.14.05.52.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Apr 2022 05:52:05 -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 v3 1/5] net/sched: flower: Helper function for vlan ethtype checks Date: Thu, 14 Apr 2022 15:51:17 +0300 Message-Id: <20220414125121.13599-2-boris.sukholitko@broadcom.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20220414125121.13599-1-boris.sukholitko@broadcom.com> References: <20220414125121.13599-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 Thu Apr 14 12:51:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Boris Sukholitko X-Patchwork-Id: 12813494 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 EE546C433F5 for ; Thu, 14 Apr 2022 12:52:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243628AbiDNMyj (ORCPT ); Thu, 14 Apr 2022 08:54:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50842 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243280AbiDNMye (ORCPT ); Thu, 14 Apr 2022 08:54:34 -0400 Received: from mail-qt1-x82a.google.com (mail-qt1-x82a.google.com [IPv6:2607:f8b0:4864:20::82a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4DA3C92328 for ; Thu, 14 Apr 2022 05:52:10 -0700 (PDT) Received: by mail-qt1-x82a.google.com with SMTP id p1so3415582qtq.10 for ; Thu, 14 Apr 2022 05:52:10 -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=AqLfZi5/uSEUDrtJnA6UZjmX7SJi9XmknRX7cH2HBG0=; b=hy3cqG+aY7/3oVQC/6+uSfZt8lEL/JQrBNtyY1gt/aOQSKG/fMwUEVzp4DISxgezT/ daVfgmPIPLmqHOdTptosL9SG4E+aoqHxG1845x7hX5TJ/DVNajblRdd/98HV15hEnq2G omdlMoyAhUBxxqvUxLTrgYTYHzpILVk3Pin8g= 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=AqLfZi5/uSEUDrtJnA6UZjmX7SJi9XmknRX7cH2HBG0=; b=KNSGgFpuwCJUxb2e7JQhDtlUPm9gEWFjWPr0DfdzCNRyohNpHQTK+IvErYwh0FDUpD 3BpMxPmnx3qB9SfeNt0nUCs5prTiW5R1lMrubysUt2ze0PMjgmG4EnvboPyadVJ5XXe9 jeXtcq8ADGeZZQnlM7yO8HEe8jtfHb/Ss47ELJO4LqBR++J4jxhwQnAk2dRsOuVWwzr3 a5ubtlbYYSndvrl12RPWQBN6qakR3GfyHuX2Ym2wM5TbNhtJiRE4cxIhw51wsH0IM9GH eRDG/2BsOY1tqKA/7GgRBULyxmBCNQS3QtT6SNdzubziqoahPdVxqnr0fxgQIqxUhlPz 1yEQ== X-Gm-Message-State: AOAM531j8+2GPLUlqXdn51FCAW6zBbtAC1Z63Ba9FgAnD2bFct3sFq27 oHBHpwYO7cJtb5FNY+kCyBfKn87NFov4MwAbA8Tdde5i2qCHgt4HKp6QxY6Q435GlnszlM8rXkq 28+WX3r1j/Exs8ms3tGWrhQ4tCf5U7Pvh8UO9IOQVvzaclgvclP8/Pebdbghskl2RRH61pJWrnU xhazfpzcn1Yw== X-Google-Smtp-Source: ABdhPJz4FnEbE7x5HdYEgl8Qw1nBP+GEPquNNCAj1y18Rrgg6eJuRrXfuTn3B7IZqWYk3P+CDqIYFQ== X-Received: by 2002:ac8:59d4:0:b0:2e1:f86d:b38c with SMTP id f20-20020ac859d4000000b002e1f86db38cmr1595988qtf.285.1649940729142; Thu, 14 Apr 2022 05:52:09 -0700 (PDT) Received: from localhost.localdomain ([192.19.250.250]) by smtp.gmail.com with ESMTPSA id o10-20020a05620a15ca00b0069c39e2970bsm875910qkm.80.2022.04.14.05.52.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Apr 2022 05:52:08 -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 v3 2/5] net/sched: flower: Reduce identation after is_key_vlan refactoring Date: Thu, 14 Apr 2022 15:51:18 +0300 Message-Id: <20220414125121.13599-3-boris.sukholitko@broadcom.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20220414125121.13599-1-boris.sukholitko@broadcom.com> References: <20220414125121.13599-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 Thu Apr 14 12:51:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Boris Sukholitko X-Patchwork-Id: 12813495 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 8572EC433FE for ; Thu, 14 Apr 2022 12:52:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243630AbiDNMyl (ORCPT ); Thu, 14 Apr 2022 08:54:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50882 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243626AbiDNMyi (ORCPT ); Thu, 14 Apr 2022 08:54:38 -0400 Received: from mail-qt1-x836.google.com (mail-qt1-x836.google.com [IPv6:2607:f8b0:4864:20::836]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 95D9492327 for ; Thu, 14 Apr 2022 05:52:13 -0700 (PDT) Received: by mail-qt1-x836.google.com with SMTP id cp8so404221qtb.6 for ; Thu, 14 Apr 2022 05:52: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=EY8Fl9WKc/vRuSnp08VTVc4E8G8rP0zTcU+ndLth3eU=; b=BpxKg3mxitjYV5FK5FEKgPyXMFxbPw4ua6JzXdbmUQZr300kyTh3CQEYWWxgjOoE5S /ieKQaL31gz8dcnfNMaCvnvNBD9/uNdTRbZ0Z1TfQdqQO5pEETMd7sIqxNlnbg8nF+XS G4kYwdEYRLCnBPtNdjkbX45hl+9+czmG5ExJI= 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=EY8Fl9WKc/vRuSnp08VTVc4E8G8rP0zTcU+ndLth3eU=; b=qbXYu/xI0AAQ7uEgj4fcjFw4NNO0mSQRvfVdkJLGJKLvvPMyM1zl1QuJ0BWVq/G/4S BcNKI3QKpmOHh5RFFQwMpZSaSXEmz0/JMVGH0oxvXET+yAfakxz6HrELy2jcheTo4pMU IbPQ0OuGQpZ19EuLUozQQYhsHthX4J4sFBlVy0pBtQlDTBY3QakfVnWEwbiNgnFIYEiL P0jLxS3u7ucPET4okfje08Ze5oSL+xnLQzMuZ4N5PRHRF3zrARTUhvQMVjBkGRGvtlq9 7T9gRSx+KznKUndKfilE0ksl64ba4gG0xY8x1dD9eX+V2RVNa1StOj6uBqzoA4AzXLEr 9+fw== X-Gm-Message-State: AOAM532pSaEDa2zW0GdvRklKQDcFfARNZszW8r9VrhV3q3Czdho9Ha6G Kqx/3wmqSZWo6eGL/z2FOhqcT/NI7bywyKFRERiicdTwaHVheNLq+FDV0yuwDZDHc7hRqbzTDGL xUnnsPZeR1zXa1El4Tb6r0dKXCSvxE9fYBuinK+keOtDPCbtxeW6Q1ifuifjtZi0oTkobqJ3sWV LLmi/XbSBDuQ== X-Google-Smtp-Source: ABdhPJzP+npHYszcaiXe8UAiELMWaEECdSbhKfJtDzheXaR1JxqvbWIcqpRwQviwJglhr9i8F1hotw== X-Received: by 2002:ac8:5502:0:b0:2f1:e732:b3a6 with SMTP id j2-20020ac85502000000b002f1e732b3a6mr827681qtq.107.1649940732442; Thu, 14 Apr 2022 05:52:12 -0700 (PDT) Received: from localhost.localdomain ([192.19.250.250]) by smtp.gmail.com with ESMTPSA id o10-20020a05620a15ca00b0069c39e2970bsm875910qkm.80.2022.04.14.05.52.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Apr 2022 05:52:11 -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 v3 3/5] flow_dissector: Add number of vlan tags dissector Date: Thu, 14 Apr 2022 15:51:19 +0300 Message-Id: <20220414125121.13599-4-boris.sukholitko@broadcom.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20220414125121.13599-1-boris.sukholitko@broadcom.com> References: <20220414125121.13599-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 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 Thu Apr 14 12:51:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Boris Sukholitko X-Patchwork-Id: 12813496 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 3646EC433F5 for ; Thu, 14 Apr 2022 12:52:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243626AbiDNMyr (ORCPT ); Thu, 14 Apr 2022 08:54:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50930 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243629AbiDNMyl (ORCPT ); Thu, 14 Apr 2022 08:54:41 -0400 Received: from mail-qk1-x72c.google.com (mail-qk1-x72c.google.com [IPv6:2607:f8b0:4864:20::72c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D865A92327 for ; Thu, 14 Apr 2022 05:52:16 -0700 (PDT) Received: by mail-qk1-x72c.google.com with SMTP id g11so3763771qke.1 for ; Thu, 14 Apr 2022 05:52: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=Vxf2bnp5MyK457bWGLRm79FFdwVY+F5r9xX4hI/iqLM=; b=PzT6hGydJkMphtSnyGAAEBY5f8BUNw67lOg79scDkpgEVhy9KK0Ry9OOvh/N2Yx4qL UUpkLaXg3Ck4xEic71XplCoSuOBw2BA/Tj6CFqjuuvaub/NE1++X+H6xdmx4VdUnAFY1 cyz8LX4x/yOQRLhjhxc2W7IZPM+2vHNue/mBQ= 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=Vxf2bnp5MyK457bWGLRm79FFdwVY+F5r9xX4hI/iqLM=; b=SdBRd8hyY9OY+YfVS+ur/MoACOJtSzw3+LyHJEy4U3wEc0jNhMY5uI3PNzD68hLRqM fpb1Ot32btxbLeLiStq0LvSp51CBblzDWn15BRh825qLh4z3dpvRxskThR7lrls1mbhW rU6bKwsJjdkojyPe9Idxyobn3867BmLzQrmvKWm7PDyIv263u3pbzbA4hAPjs0Ly1tNf EPvaZ8i8UTJmrt5NFNX/bkby+kxOQGAShPBy6miqpW7oWHbnpu/OWttHXuGmLm0/2ca1 mDbk6w6p8oiG5o9PiCQUwdHO7N//88LtCiYNFfgjtPIhiOTDDF3fOzq1FYw+JpYSnWYy cFOA== X-Gm-Message-State: AOAM533Kt8BK8oDa16mWzX+5RofV7cvQLgu9zDtDBf1+avDOoVuCS5It PmWFLSptSGH/jVN+QdjO/6CK3qWL5EjjUtOFQd8x7ap8eJDgFBPT5TG6qM2T2Ktc5y9yeGPLKte LnAsXnMvIpWZDSC6cosgjJQkCltrY3r5WioQ77OA1y/v413pE66WUDCITFoQnyEYOUExghJYdRQ c0N7b0BIRL7g== X-Google-Smtp-Source: ABdhPJx0l6hVOs//CdQB0m0BXB78zj+eMYcOTxgsgoDyYCviaFs6aIPwpWNiexv5h/XRZAcDSv1pbg== X-Received: by 2002:ae9:f016:0:b0:69c:37ea:9b38 with SMTP id l22-20020ae9f016000000b0069c37ea9b38mr1629231qkg.335.1649940735661; Thu, 14 Apr 2022 05:52:15 -0700 (PDT) Received: from localhost.localdomain ([192.19.250.250]) by smtp.gmail.com with ESMTPSA id o10-20020a05620a15ca00b0069c39e2970bsm875910qkm.80.2022.04.14.05.52.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Apr 2022 05:52: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 , Paolo Abeni Cc: Ilya Lifshits , Boris Sukholitko Subject: [PATCH net-next v3 4/5] net/sched: flower: Add number of vlan tags filter Date: Thu, 14 Apr 2022 15:51:20 +0300 Message-Id: <20220414125121.13599-5-boris.sukholitko@broadcom.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20220414125121.13599-1-boris.sukholitko@broadcom.com> References: <20220414125121.13599-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 Thu Apr 14 12:51:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Boris Sukholitko X-Patchwork-Id: 12813497 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 20C38C433EF for ; Thu, 14 Apr 2022 12:52:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243633AbiDNMys (ORCPT ); Thu, 14 Apr 2022 08:54:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51044 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243641AbiDNMyq (ORCPT ); Thu, 14 Apr 2022 08:54:46 -0400 Received: from mail-qk1-x732.google.com (mail-qk1-x732.google.com [IPv6:2607:f8b0:4864:20::732]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1615D9233E for ; Thu, 14 Apr 2022 05:52:20 -0700 (PDT) Received: by mail-qk1-x732.google.com with SMTP id c1so3729223qkf.13 for ; Thu, 14 Apr 2022 05:52: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=qQP8Aj8EYzZG4Jzto486EAZJ9Lup717hPLdfMHb8Wu8=; b=EugKZQWJkpboLMvJpMi55C/C+yZ3X5/LAmX42n91r2BVjHAmamm5KuM6YtXZE4dQ++ +/AH5NWxNwhH2r7SjZdKqpVbuzHrC5TZyya2SQyEW+H2ouSzTdKwJi1BytJn4so1tuPt dOlf9tZ9tFHDeXWcGmr3dH/xbKhlHw1YGHMys= 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=qQP8Aj8EYzZG4Jzto486EAZJ9Lup717hPLdfMHb8Wu8=; b=tYhXdkFgeOVg9s1bU1hP6USIPVkB+8At0Da821ettXsjBu/wOoSu9bRSsmUgkt5gum U4et7ZdyaEjeznarXnXbSyzO8ll92tqF90YJ+tGUTgOK8NazkBIkl1IXNcR9a+Pcjhe8 0A7G5htWumSXfWEt9M7n22uNf51BMLHoeBQlk5TxmGtalk+0YBjNrCY0nvDkgBV/duE3 L+o0VH7ZIDNshkXMJRJec869Y93WRBVkSSnz5n/f3mYLlA9R4wpTnWWcl8MaK20aDqu0 ZDiy4ddq/gD441MYgdm1JqtxNHUug2XsQom7rZiZycGR0nDCiw1es7RqVw9mimouTlVu XhJA== X-Gm-Message-State: AOAM5303OCDbR+OqN/jrwEtM2LspWgfvK4aZKeG7fPLKJXcK3exv6tb9 4t4RJ2Q5UCQozUH4R1XE8bqhE/xwTWqS1lkocmfvnj0hYaBWEFsQcEuMsWww3iMISPaElud96eY xqNwNvRC/LGWq3ydtSNp+nRRJO2EMcVPuB3oHNH1hp1oDP92hXKBPQf+8qX4+pwYRnCt0kn29SC N76E8+h1IeOg== X-Google-Smtp-Source: ABdhPJwmhW0wqzsmfrTVksBdPH7bkn7y61/pEFHnPoaYJjp56x5GOmrQN+xYhKSDGtr3qZVa13WLRg== X-Received: by 2002:a05:620a:2802:b0:69c:3b5a:b264 with SMTP id f2-20020a05620a280200b0069c3b5ab264mr1666229qkp.668.1649940738837; Thu, 14 Apr 2022 05:52:18 -0700 (PDT) Received: from localhost.localdomain ([192.19.250.250]) by smtp.gmail.com with ESMTPSA id o10-20020a05620a15ca00b0069c39e2970bsm875910qkm.80.2022.04.14.05.52.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Apr 2022 05:52: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 , Paolo Abeni Cc: Ilya Lifshits , Boris Sukholitko Subject: [PATCH net-next v3 5/5] net/sched: flower: Consider the number of tags for vlan filters Date: Thu, 14 Apr 2022 15:51:21 +0300 Message-Id: <20220414125121.13599-6-boris.sukholitko@broadcom.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20220414125121.13599-1-boris.sukholitko@broadcom.com> References: <20220414125121.13599-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 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,