diff mbox series

[net-next,v2,1/4] flow_offload: add control flag checking helpers

Message ID 20240410093235.5334-2-ast@fiberby.net (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series flower: validate control flags | expand

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Clearly marked for net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 2765 this patch: 2765
netdev/build_tools success Errors and warnings before: 0 this patch: 0
netdev/cc_maintainers success CCed 4 of 4 maintainers
netdev/build_clang success Errors and warnings before: 989 this patch: 989
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 2974 this patch: 2974
netdev/checkpatch warning WARNING: line length of 82 exceeds 80 columns WARNING: line length of 84 exceeds 80 columns
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc fail Errors and warnings before: 1 this patch: 4
netdev/source_inline success Was 0 now: 0

Commit Message

Asbjørn Sloth Tønnesen April 10, 2024, 9:32 a.m. UTC
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 <ast@fiberby.net>
---
 include/net/flow_offload.h | 55 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 55 insertions(+)

Comments

Asbjørn Sloth Tønnesen April 10, 2024, 11:27 a.m. UTC | #1
On 4/10/24 9:32 AM, Asbjørn Sloth Tønnesen wrote:
> 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 <ast@fiberby.net>
> ---
>   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.
> + */


The kdoc test failed:
 > include/net/flow_offload.h:463: warning: No description found for return value of 'flow_rule_is_supp_control_flags'

For some reason I didn't find kernel-doc.rst, because I searched for autodoc sphinx stuff.

Will do proper "Return:" in v3.

I wasn't able to reproduce the kdoc failure[1] locally:

$ ./scripts/kernel-doc -none include/net/flow_offload.h
$ ./scripts/kernel-doc -none -v include/net/flow_offload.h
include/net/flow_offload.h:345: info: Scanning doc for function flow_offload_has_one_action
include/net/flow_offload.h:453: info: Scanning doc for function flow_rule_is_supp_control_flags
include/net/flow_offload.h:475: info: Scanning doc for function flow_rule_has_control_flags
include/net/flow_offload.h:488: info: Scanning doc for function flow_rule_match_has_control_flags

[1] https://netdev.bots.linux.dev/static/nipa/843159/13623977/kdoc/

pw-bot: changes-requested


> +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;
Louis Peens April 11, 2024, 6:24 a.m. UTC | #2
On Wed, Apr 10, 2024 at 09:32:22AM +0000, Asbjørn Sloth Tønnesen wrote:
> 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 <ast@fiberby.net>
> ---

Looks good from my perspective, thanks for the naming updates:
Reviewed-by: Louis Peens <louis.peens@corigine.com>
diff mbox series

Patch

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;