Skip to content

Commit

Permalink
net: hns3: flower: validate control flags
Browse files Browse the repository at this point in the history
This driver currently doesn't support any control flags.

Use flow_rule_has_control_flags() to check for control flags,
such as can be set through `tc flower ... ip_flags frag`.

In case any control flags are masked, flow_rule_has_control_flags()
sets a NL extended error message, and we return -EOPNOTSUPP.

Also propagate extack to hclge_get_cls_key_ip(), and convert it to
return error code.

Only compile-tested.

Signed-off-by: Asbjørn Sloth Tønnesen <ast@fiberby.net>
Reviewed-by: Jiri Pirko <jiri@nvidia.com>
Tested-by: Jijie Shao <shaojijie@huawei.com>
Link: https://lore.kernel.org/r/20240422152717.175659-1-ast@fiberby.net
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
  • Loading branch information
Asbjørn Sloth Tønnesen authored and Jakub Kicinski committed Apr 25, 2024
1 parent f97e0a5 commit e199a5b
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -7222,8 +7222,9 @@ static void hclge_get_cls_key_vlan(const struct flow_rule *flow,
}
}

static void hclge_get_cls_key_ip(const struct flow_rule *flow,
struct hclge_fd_rule *rule)
static int hclge_get_cls_key_ip(const struct flow_rule *flow,
struct hclge_fd_rule *rule,
struct netlink_ext_ack *extack)
{
u16 addr_type = 0;

Expand All @@ -7232,6 +7233,9 @@ static void hclge_get_cls_key_ip(const struct flow_rule *flow,

flow_rule_match_control(flow, &match);
addr_type = match.key->addr_type;

if (flow_rule_has_control_flags(match.mask->flags, extack))
return -EOPNOTSUPP;
}

if (addr_type == FLOW_DISSECTOR_KEY_IPV4_ADDRS) {
Expand Down Expand Up @@ -7260,6 +7264,8 @@ static void hclge_get_cls_key_ip(const struct flow_rule *flow,
rule->unused_tuple |= BIT(INNER_SRC_IP);
rule->unused_tuple |= BIT(INNER_DST_IP);
}

return 0;
}

static void hclge_get_cls_key_port(const struct flow_rule *flow,
Expand All @@ -7285,7 +7291,9 @@ static int hclge_parse_cls_flower(struct hclge_dev *hdev,
struct hclge_fd_rule *rule)
{
struct flow_rule *flow = flow_cls_offload_flow_rule(cls_flower);
struct netlink_ext_ack *extack = cls_flower->common.extack;
struct flow_dissector *dissector = flow->match.dissector;
int ret;

if (dissector->used_keys &
~(BIT_ULL(FLOW_DISSECTOR_KEY_CONTROL) |
Expand All @@ -7303,7 +7311,11 @@ static int hclge_parse_cls_flower(struct hclge_dev *hdev,
hclge_get_cls_key_basic(flow, rule);
hclge_get_cls_key_mac(flow, rule);
hclge_get_cls_key_vlan(flow, rule);
hclge_get_cls_key_ip(flow, rule);

ret = hclge_get_cls_key_ip(flow, rule, extack);
if (ret)
return ret;

hclge_get_cls_key_port(flow, rule);

return 0;
Expand Down

0 comments on commit e199a5b

Please sign in to comment.