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