Commit 71329c49 authored by David S. Miller's avatar David S. Miller

Merge branch 'flower-control-flags'

Asbjørn Sloth Tønnesen says:

====================
flower: validate control flags

I have reviewed the flower control flags code.
In all, but one (sfc), the flags field wasn't
checked properly for unsupported flags.

In this series I have only included a single example
user for each helper function. Once the helpers are in,
I will submit patches for all other drivers implementing
flower.

After which there will be:
- 6 drivers using flow_rule_is_supp_control_flags()
- 8 drivers using flow_rule_has_control_flags()
- 11 drivers using flow_rule_match_has_control_flags()

---
Changelog:

v3:
- Added Reviewed-by from Louis Peens (first two patches)
- Properly fixed kernel-doc format

v2: https://lore.kernel.org/netdev/20240410093235.5334-1-ast@fiberby.net/
- Squashed the 3 helper functions to one commmit (requested by Baowen Zheng)
- Renamed helper functions to avoid double negatives (suggested by Louis Peens)
- Reverse booleans in some functions and callsites to align with new names
- Fix autodoc format

v1: https://lore.kernel.org/netdev/20240408130927.78594-1-ast@fiberby.net/
====================
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents 3db3b629 d9a1249e
......@@ -124,6 +124,9 @@ static int ksz9477_flower_parse_key(struct ksz_device *dev, int port,
return -EOPNOTSUPP;
}
if (flow_rule_match_has_control_flags(rule, extack))
return -EOPNOTSUPP;
if (flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_BASIC) ||
flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_ETH_ADDRS)) {
ret = ksz9477_flower_parse_key_l2(dev, port, extack, rule,
......
......@@ -229,6 +229,10 @@ static int prestera_flower_parse(struct prestera_flow_block *block,
flow_rule_match_control(f_rule, &match);
addr_type = match.key->addr_type;
if (flow_rule_has_control_flags(match.mask->flags,
f->common.extack))
return -EOPNOTSUPP;
}
if (flow_rule_match_key(f_rule, FLOW_DISSECTOR_KEY_BASIC)) {
......
......@@ -527,10 +527,10 @@ nfp_flower_calculate_key_layers(struct nfp_app *app,
struct flow_match_control ctl;
flow_rule_match_control(rule, &ctl);
if (ctl.key->flags & ~NFP_FLOWER_SUPPORTED_CTLFLAGS) {
NL_SET_ERR_MSG_MOD(extack, "unsupported offload: match on unknown control flag");
if (!flow_rule_is_supp_control_flags(NFP_FLOWER_SUPPORTED_CTLFLAGS,
ctl.mask->flags, extack))
return -EOPNOTSUPP;
}
}
ret_key_ls->key_layer = key_layer;
......
......@@ -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.
*
* Return: 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.
*
* Return: 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.
*
* Return: 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;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment