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