Received: by 2002:ab2:4a89:0:b0:1f4:a8b6:6e69 with SMTP id w9csp22975lqj; Wed, 10 Apr 2024 02:38:53 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVtd0UdXYTMX3I/cTMBv0HUKH5UVwxNofhfcirFSr1xc0Ow4FV0ax518sXN8gF1hw/4mbxn5IGTbuy+L2yJgyUKdGtjxw0RjuW3QlSh8g== X-Google-Smtp-Source: AGHT+IFE1FsGJd5T+Wq6I6c40tYZeMLQpHjAd8Do8bznTx0ytIiTMqe7LOBTHCOz+6AL02O88o8n X-Received: by 2002:a05:6a21:1f1e:b0:1a7:a411:e1eb with SMTP id ry30-20020a056a211f1e00b001a7a411e1ebmr2055672pzb.59.1712741933669; Wed, 10 Apr 2024 02:38:53 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712741933; cv=pass; d=google.com; s=arc-20160816; b=geMXXaw2NaqVy/s3uLm5FaZC3Cmlwyv/fQI0OMHfeRk/6arXCkeCZlyO4sQ/qUNqOL duXimLY914eP1p0UUuk+/+iRasSaHm721pZgqY9Gz01X/nY4fiB8XFNBwvU4s4suHm32 Tn3l0Qv/+SfqQOOkmHpJy47R5Ax6yEB7696CiCko9PcjjjaSLe2PbQ2U3VUkYSUIbBwN QR2k226XbOwmUYb9rLaGvIJNrB9dw17tmqFyQLgWN01vashnn/IGu/uXgbKRExsArdQR 8D/8AgsRYdzTqWG1ylH63O6LF3jygQg6QgAHktWQv8gqGcYZsWYIi2DpHnfc7T9tt/uV fmOg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=07hd/iZbO+oq1JDGMfSG46I3D8ypcZVew344a53ecyI=; fh=ymilCVC6zcVXBsRWgTaQwNQko51561pjqSmDEoQse7M=; b=XBfHuVelAqAj4UfpSCztmDhWT6IzNSS3mMZB+ADX5pABqkiO+LIGgr0EGjBnFuzqNX 51ZyRm1o8/kssOZ+z3uEaxm5EV7dP47nnZc9ygPlGwoHSaurklEIfETQXgCSs/lD3ix1 zy3Qnu0148iZiuKvUpQpCtbSDTEG2VhTlNRFgZ/vDGqkOVNphPuAWn2L3cuG5at1psp4 yrxsB5AaNdSD3uiqSQQ+uLPviU47BQGXziBYByKpzPgPgBs7czlU7ZCNGspra3Onui7L 7cR6JRiVxpfxL0BIWd+zuueuj3h4ARDasZ2OjQgTFKy/n94Xyoh15HKH7CJ7Jzd702a6 glSg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@fiberby.net header.s=202008 header.b=FX71Y6W6; arc=pass (i=1 spf=pass spfdomain=fiberby.net dkim=pass dkdomain=fiberby.net dmarc=pass fromdomain=fiberby.net); spf=pass (google.com: domain of linux-kernel+bounces-138261-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-138261-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=fiberby.net Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id k3-20020a170902f28300b001e23066e237si10026131plc.233.2024.04.10.02.38.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Apr 2024 02:38:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-138261-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@fiberby.net header.s=202008 header.b=FX71Y6W6; arc=pass (i=1 spf=pass spfdomain=fiberby.net dkim=pass dkdomain=fiberby.net dmarc=pass fromdomain=fiberby.net); spf=pass (google.com: domain of linux-kernel+bounces-138261-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-138261-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=fiberby.net Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 12E7DB249FD for ; Wed, 10 Apr 2024 09:33:30 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2B019158206; Wed, 10 Apr 2024 09:33:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=fiberby.net header.i=@fiberby.net header.b="FX71Y6W6" Received: from mail1.fiberby.net (mail1.fiberby.net [193.104.135.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8962C144312; Wed, 10 Apr 2024 09:32:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.104.135.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712741581; cv=none; b=uV8Lbw3DYgVwWavdBz/m6i+soYsiuexwWu1CMFHMLQXpGpwXEHc0uKhIbydmu8fCi8/PoF0aLmP2mWIyJ1VVm8tXZYCs3G9EWhlQmfnjPUmk9nwMvBEoD/LGMEylTXg3rxDhuPCX76zWwITOi7pwYs0kTaLF8X1S3D3aceW2P+s= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712741581; c=relaxed/simple; bh=dz2ZRjqTz89ZMEMlnTX6GlK7nVgj8fTZW8/LNxn/yyo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=aaVsKRNJCHp/G4tdcOXStMNsujJFe36ClWklmj+iu1kVNPAzkl2BWql6B24KVPDHRRmyiVXRND9t3fOasv40mr63izcQyEVfwATuzUDU+RGcPyF/K6s4wrom47/kAv7MgxB7yjZWuwMBx63ARmZbmWskYkrkiuRI1ecSQuk5FQE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=fiberby.net; spf=pass smtp.mailfrom=fiberby.net; dkim=pass (2048-bit key) header.d=fiberby.net header.i=@fiberby.net header.b=FX71Y6W6; arc=none smtp.client-ip=193.104.135.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=fiberby.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=fiberby.net Received: from x201s (193-104-135-243.ip4.fiberby.net [193.104.135.243]) by mail1.fiberby.net (Postfix) with ESMTPSA id C7AA4600A9; Wed, 10 Apr 2024 09:32:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=fiberby.net; s=202008; t=1712741568; bh=dz2ZRjqTz89ZMEMlnTX6GlK7nVgj8fTZW8/LNxn/yyo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FX71Y6W6XKB/HF9n8dBmNZuiUpUkRHrzi9ypWd4iqYandQNSHpRZ5fRiHwPmFdxte g2Y4mUX9/k1u2IJFUUsUcmHLGZGaah20geWMXzivCTVLO7yuLDUjkNfL/deKxlyF7O CHoE9LhtNixMXetnfTgQHb/LIeynzlRZPhqBkKx8mFNMCEZANjorxN0p15xpr3J1Q6 bjqQ1I8Fkt/JbrMDCxeXr01TmnhcADmWsy4LnZAZQzm8YT9HeN7rfuS6uT+rGbIXj7 kMuFEI4JfF+XiJOTfiDtzqEZ/fjHDfj9zL2Rv/03RU5pI7OHTk3KnvvTx4lnJZu7ZV VtR5HPXh23rGg== Received: by x201s (Postfix, from userid 1000) id A92CE20B99F; Wed, 10 Apr 2024 09:32:39 +0000 (UTC) From: =?UTF-8?q?Asbj=C3=B8rn=20Sloth=20T=C3=B8nnesen?= To: netdev@vger.kernel.org Cc: =?UTF-8?q?Asbj=C3=B8rn=20Sloth=20T=C3=B8nnesen?= , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , linux-kernel@vger.kernel.org, Louis Peens , Yanguo Li , oss-drivers@corigine.com, Taras Chornyi , Woojung Huh , UNGLinuxDriver@microchip.com, Andrew Lunn , Florian Fainelli , Vladimir Oltean , Edward Cree , Jamal Hadi Salim , Cong Wang , Jiri Pirko Subject: [PATCH net-next v2 1/4] flow_offload: add control flag checking helpers Date: Wed, 10 Apr 2024 09:32:22 +0000 Message-ID: <20240410093235.5334-2-ast@fiberby.net> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240410093235.5334-1-ast@fiberby.net> References: <20240410093235.5334-1-ast@fiberby.net> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit These helpers aim to help drivers, with checking for the presence of unsupported control flags. For drivers supporting at least one control flag: flow_rule_is_supp_control_flags() For drivers using flow_rule_match_control(), but not using flags: flow_rule_has_control_flags() For drivers not using flow_rule_match_control(): flow_rule_match_has_control_flags() While primarily aimed at FLOW_DISSECTOR_KEY_CONTROL and flow_rule_match_control(), then the first two can also be used with FLOW_DISSECTOR_KEY_ENC_CONTROL and flow_rule_match_enc_control(). These helpers mirrors the existing check done in sfc: drivers/net/ethernet/sfc/tc.c +276 Only compile-tested. Signed-off-by: Asbjørn Sloth Tønnesen --- include/net/flow_offload.h | 55 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/include/net/flow_offload.h b/include/net/flow_offload.h index 314087a5e1818..9ee3ad4a308a8 100644 --- a/include/net/flow_offload.h +++ b/include/net/flow_offload.h @@ -449,6 +449,61 @@ static inline bool flow_rule_match_key(const struct flow_rule *rule, return dissector_uses_key(rule->match.dissector, key); } +/** + * flow_rule_is_supp_control_flags() - check for supported control flags + * @supp_flags: control flags supported by driver + * @ctrl_flags: control flags present in rule + * @extack: The netlink extended ACK for reporting errors. + * + * @returns true if only supported control flags are set, false otherwise. + */ +static inline bool flow_rule_is_supp_control_flags(const u32 supp_flags, + const u32 ctrl_flags, + struct netlink_ext_ack *extack) +{ + if (likely((ctrl_flags & ~supp_flags) == 0)) + return true; + + NL_SET_ERR_MSG_FMT_MOD(extack, + "Unsupported match on control.flags %#x", + ctrl_flags); + + return false; +} + +/** + * flow_rule_has_control_flags() - check for presence of any control flags + * @ctrl_flags: control flags present in rule + * @extack: The netlink extended ACK for reporting errors. + * + * @returns true if control flags are set, false otherwise. + */ +static inline bool flow_rule_has_control_flags(const u32 ctrl_flags, + struct netlink_ext_ack *extack) +{ + return !flow_rule_is_supp_control_flags(0, ctrl_flags, extack); +} + +/** + * flow_rule_match_has_control_flags() - match and check for any control flags + * @rule: The flow_rule under evaluation. + * @extack: The netlink extended ACK for reporting errors. + * + * @returns true if control flags are set, false otherwise. + */ +static inline bool flow_rule_match_has_control_flags(struct flow_rule *rule, + struct netlink_ext_ack *extack) +{ + struct flow_match_control match; + + if (!flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_CONTROL)) + return false; + + flow_rule_match_control(rule, &match); + + return flow_rule_has_control_flags(match.mask->flags, extack); +} + struct flow_stats { u64 pkts; u64 bytes; -- 2.43.0