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