Merge branch 'net-flower-validate-encapsulation-control-flags'

Asbjørn Sloth Tønnesen says:

====================
net: flower: validate encapsulation control flags

Now that all drivers properly rejects unsupported flower control flags
used with FLOW_DISSECTOR_KEY_CONTROL, then time has come to add similar
checks to the drivers supporting FLOW_DISSECTOR_KEY_ENC_CONTROL.

There are currently just 4 drivers supporting this key, and
3 of those currently doesn't validate encapsulated control flags.

Encapsulation control flags may currently be unused, but they should
still be validated by the drivers, so that drivers will properly
reject any new flags when they are introduced.

This series adds some helper functions, and implements them in all
4 drivers.

NB: It is currently discussed[1] to use encapsulation control flags
for tunnel flags instead of the new FLOW_DISSECTOR_KEY_ENC_FLAGS.

[1] https://lore.kernel.org/netdev/ZmFuxElwZiYJzBkh@dcaratti.users.ipa.redhat.com/
====================

Link: https://lore.kernel.org/r/20240609173358.193178-1-ast@fiberby.net
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
This commit is contained in:
Jakub Kicinski 2024-06-12 17:56:54 -07:00
commit 6fc1b32291
5 changed files with 50 additions and 4 deletions

View File

@ -1353,6 +1353,7 @@ ice_parse_tunnel_attr(struct net_device *dev, struct flow_rule *rule,
struct ice_tc_flower_fltr *fltr)
{
struct ice_tc_flower_lyr_2_4_hdrs *headers = &fltr->outer_headers;
struct netlink_ext_ack *extack = fltr->extack;
struct flow_match_control enc_control;
fltr->tunnel_type = ice_tc_tun_get_type(dev);
@ -1373,6 +1374,9 @@ ice_parse_tunnel_attr(struct net_device *dev, struct flow_rule *rule,
flow_rule_match_enc_control(rule, &enc_control);
if (flow_rule_has_enc_control_flags(enc_control.mask->flags, extack))
return -EOPNOTSUPP;
if (enc_control.key->addr_type == FLOW_DISSECTOR_KEY_IPV4_ADDRS) {
struct flow_match_ipv4_addrs match;

View File

@ -850,6 +850,12 @@ int mlx5e_tc_tun_parse(struct net_device *filter_dev,
flow_rule_match_enc_control(rule, &match);
addr_type = match.key->addr_type;
if (flow_rule_has_enc_control_flags(match.mask->flags,
extack)) {
err = -EOPNOTSUPP;
goto out;
}
/* For tunnel addr_type used same key id`s as for non-tunnel */
if (addr_type == FLOW_DISSECTOR_KEY_IPV4_ADDRS) {
struct flow_match_ipv4_addrs match;

View File

@ -321,6 +321,10 @@ nfp_flower_calculate_key_layers(struct nfp_app *app,
flow_rule_match_enc_control(rule, &enc_ctl);
if (flow_rule_has_enc_control_flags(enc_ctl.mask->flags,
extack))
return -EOPNOTSUPP;
if (enc_ctl.mask->addr_type != 0xffff) {
NL_SET_ERR_MSG_MOD(extack, "unsupported offload: wildcarded protocols on tunnels are not supported");
return -EOPNOTSUPP;

View File

@ -387,11 +387,8 @@ static int efx_tc_flower_parse_match(struct efx_nic *efx,
struct flow_match_control fm;
flow_rule_match_enc_control(rule, &fm);
if (fm.mask->flags) {
NL_SET_ERR_MSG_FMT_MOD(extack, "Unsupported match on enc_control.flags %#x",
fm.mask->flags);
if (flow_rule_has_enc_control_flags(fm.mask->flags, extack))
return -EOPNOTSUPP;
}
if (!IS_ALL_ONES(fm.mask->addr_type)) {
NL_SET_ERR_MSG_FMT_MOD(extack, "Unsupported enc addr_type mask %u (key %u)",
fm.mask->addr_type,

View File

@ -471,6 +471,28 @@ static inline bool flow_rule_is_supp_control_flags(const u32 supp_flags,
return false;
}
/**
* flow_rule_is_supp_enc_control_flags() - check for supported control flags
* @supp_enc_flags: encapsulation control flags supported by driver
* @enc_ctrl_flags: encapsulation 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_enc_control_flags(const u32 supp_enc_flags,
const u32 enc_ctrl_flags,
struct netlink_ext_ack *extack)
{
if (likely((enc_ctrl_flags & ~supp_enc_flags) == 0))
return true;
NL_SET_ERR_MSG_FMT_MOD(extack,
"Unsupported match on enc_control.flags %#x",
enc_ctrl_flags);
return false;
}
/**
* flow_rule_has_control_flags() - check for presence of any control flags
* @ctrl_flags: control flags present in rule
@ -484,6 +506,19 @@ static inline bool flow_rule_has_control_flags(const u32 ctrl_flags,
return !flow_rule_is_supp_control_flags(0, ctrl_flags, extack);
}
/**
* flow_rule_has_enc_control_flags() - check for presence of any control flags
* @enc_ctrl_flags: encapsulation 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_enc_control_flags(const u32 enc_ctrl_flags,
struct netlink_ext_ack *extack)
{
return !flow_rule_is_supp_enc_control_flags(0, enc_ctrl_flags, extack);
}
/**
* flow_rule_match_has_control_flags() - match and check for any control flags
* @rule: The flow_rule under evaluation.