From patchwork Tue Apr 12 10:02: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: 12810511 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 ADE93C433EF for ; Tue, 12 Apr 2022 11:13:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344936AbiDLLPk (ORCPT ); Tue, 12 Apr 2022 07:15:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49388 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1355129AbiDLLPP (ORCPT ); Tue, 12 Apr 2022 07:15:15 -0400 Received: from mail-pg1-x52f.google.com (mail-pg1-x52f.google.com [IPv6:2607:f8b0:4864:20::52f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 832B0252A4 for ; Tue, 12 Apr 2022 03:03:11 -0700 (PDT) Received: by mail-pg1-x52f.google.com with SMTP id 32so14669520pgl.4 for ; Tue, 12 Apr 2022 03:03:11 -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=J15r6CdbQlQ1MjQalRz71kYTjgOltdBXsSk3+PGN9OQ=; b=LXjP7KYFZ3ggXPzCgE6p0Rr0oczQIlzPmK03pWuhUmjiuXXsjUCgk90iiuES/zHe9F jIhzNS5zsFk3182SnXjmOTrcFKZ6B1Cl+7s8iciSqyW/sjG7Vm04A+EHUY6uU+lwWJjb AqtcpLbmF1r1O1MctcXR33wsuUReLw4IJJWBA= 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=J15r6CdbQlQ1MjQalRz71kYTjgOltdBXsSk3+PGN9OQ=; b=cumNagpQmfvWE7vLXBxFxjD7RnT3D8rT8wlznKcystjODUzV1CM9F2crwtGcmeugrE YcOAxLruidlfnE3iC2l2XTDwbln1hDNPC/yS+0lVbcXbh+U9mOTbbnbCpAgaGRupv2dJ DwhUGnY6PFBuuHahaI1ihr5z9nJecv4sUWZcgxxK3cTgMPjwSbBcRZ4KdXECuaULLA47 4ejnjJX13BDTEqL8aqgPpLsgGf9GF4YEPqgM6Arb2yfXgIlEn71k6ULBAxwSQ25PD1/9 j+hVRKmT/Pa+Ce19ZgZNPdikpDbXTubTWQ08e72UTg7PqCJY3MrdclPYGFkkTYlsOEFM zWuw== X-Gm-Message-State: AOAM533VgX/iEJNfoIjTXcFmQ78uRrbDYeytiZVrsWNV0bXlksr8tqhj zEYeDacHXXqKFgjFeNCZSs+f1PqcB+mgiZJo3DF1h3TztcHfMbvVTgs1fu8cW+WIsvBHspibKgb z6xx8tAk+CUn3NmFLhSxBuTyHZ82mczIQDnSo5eGW8Vf1TRC3C2jQryGMtjcTIAc1YFBItUgwp0 KHNviyuZs/9w== X-Google-Smtp-Source: ABdhPJw80j12qk/2mGiJvdcW1TVtmO97+Huroq57AT/r9eJEppFeK5jRa7enqmq2//h//pBK6kOltA== X-Received: by 2002:a63:1061:0:b0:399:5cd:3ddf with SMTP id 33-20020a631061000000b0039905cd3ddfmr29440152pgq.271.1649757790213; Tue, 12 Apr 2022 03:03:10 -0700 (PDT) Received: from localhost.localdomain ([192.19.250.250]) by smtp.gmail.com with ESMTPSA id u17-20020a056a00159100b004faef351ebcsm37020020pfk.45.2022.04.12.03.03.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Apr 2022 03:03:09 -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 v2 1/5] net/sched: flower: Helper function for vlan ethtype checks Date: Tue, 12 Apr 2022 13:02:32 +0300 Message-Id: <20220412100236.27244-2-boris.sukholitko@broadcom.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20220412100236.27244-1-boris.sukholitko@broadcom.com> References: <20220412100236.27244-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) ||