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) ||