2018-08-09 08:59:11 +00:00
|
|
|
// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
|
|
|
|
/* Copyright (c) 2017-2018 Mellanox Technologies. All rights reserved */
|
2017-02-03 09:29:09 +00:00
|
|
|
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/errno.h>
|
|
|
|
#include <linux/netdevice.h>
|
2018-01-17 10:46:56 +00:00
|
|
|
#include <net/net_namespace.h>
|
2017-02-03 09:29:09 +00:00
|
|
|
#include <net/flow_dissector.h>
|
|
|
|
#include <net/pkt_cls.h>
|
|
|
|
#include <net/tc_act/tc_gact.h>
|
|
|
|
#include <net/tc_act/tc_mirred.h>
|
2017-03-09 08:25:19 +00:00
|
|
|
#include <net/tc_act/tc_vlan.h>
|
2017-02-03 09:29:09 +00:00
|
|
|
|
|
|
|
#include "spectrum.h"
|
|
|
|
#include "core_acl_flex_keys.h"
|
|
|
|
|
|
|
|
static int mlxsw_sp_flower_parse_actions(struct mlxsw_sp *mlxsw_sp,
|
2018-01-17 10:46:56 +00:00
|
|
|
struct mlxsw_sp_acl_block *block,
|
2017-02-03 09:29:09 +00:00
|
|
|
struct mlxsw_sp_acl_rule_info *rulei,
|
2019-02-02 11:50:48 +00:00
|
|
|
struct flow_action *flow_action,
|
2018-07-24 14:13:11 +00:00
|
|
|
struct netlink_ext_ack *extack)
|
2017-02-03 09:29:09 +00:00
|
|
|
{
|
2019-02-02 11:50:48 +00:00
|
|
|
const struct flow_action_entry *act;
|
2019-09-26 11:43:40 +00:00
|
|
|
int mirror_act_count = 0;
|
2018-08-19 19:22:09 +00:00
|
|
|
int err, i;
|
2017-02-03 09:29:09 +00:00
|
|
|
|
2019-02-02 11:50:48 +00:00
|
|
|
if (!flow_action_has_entries(flow_action))
|
2017-02-03 09:29:09 +00:00
|
|
|
return 0;
|
|
|
|
|
2017-03-11 08:42:59 +00:00
|
|
|
/* Count action is inserted first */
|
2018-07-24 14:13:11 +00:00
|
|
|
err = mlxsw_sp_acl_rulei_act_count(mlxsw_sp, rulei, extack);
|
2017-03-11 08:42:59 +00:00
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
2019-02-02 11:50:48 +00:00
|
|
|
flow_action_for_each(i, act, flow_action) {
|
|
|
|
switch (act->id) {
|
|
|
|
case FLOW_ACTION_ACCEPT:
|
2018-03-09 13:33:52 +00:00
|
|
|
err = mlxsw_sp_acl_rulei_act_terminate(rulei);
|
2018-07-24 14:13:14 +00:00
|
|
|
if (err) {
|
|
|
|
NL_SET_ERR_MSG_MOD(extack, "Cannot append terminate action");
|
2017-09-25 08:58:22 +00:00
|
|
|
return err;
|
2018-07-24 14:13:14 +00:00
|
|
|
}
|
2019-02-02 11:50:48 +00:00
|
|
|
break;
|
|
|
|
case FLOW_ACTION_DROP:
|
2017-02-03 09:29:09 +00:00
|
|
|
err = mlxsw_sp_acl_rulei_act_drop(rulei);
|
2018-07-24 14:13:14 +00:00
|
|
|
if (err) {
|
|
|
|
NL_SET_ERR_MSG_MOD(extack, "Cannot append drop action");
|
2017-02-03 09:29:09 +00:00
|
|
|
return err;
|
2018-07-24 14:13:14 +00:00
|
|
|
}
|
2019-02-02 11:50:48 +00:00
|
|
|
break;
|
|
|
|
case FLOW_ACTION_TRAP:
|
2017-06-06 12:12:07 +00:00
|
|
|
err = mlxsw_sp_acl_rulei_act_trap(rulei);
|
2018-07-24 14:13:14 +00:00
|
|
|
if (err) {
|
|
|
|
NL_SET_ERR_MSG_MOD(extack, "Cannot append trap action");
|
2017-06-06 12:12:07 +00:00
|
|
|
return err;
|
2018-07-24 14:13:14 +00:00
|
|
|
}
|
2019-02-02 11:50:48 +00:00
|
|
|
break;
|
|
|
|
case FLOW_ACTION_GOTO: {
|
|
|
|
u32 chain_index = act->chain_index;
|
2017-08-23 08:08:22 +00:00
|
|
|
struct mlxsw_sp_acl_ruleset *ruleset;
|
|
|
|
u16 group_id;
|
|
|
|
|
2018-01-17 10:46:56 +00:00
|
|
|
ruleset = mlxsw_sp_acl_ruleset_lookup(mlxsw_sp, block,
|
2017-08-23 08:08:22 +00:00
|
|
|
chain_index,
|
|
|
|
MLXSW_SP_ACL_PROFILE_FLOWER);
|
|
|
|
if (IS_ERR(ruleset))
|
|
|
|
return PTR_ERR(ruleset);
|
|
|
|
|
|
|
|
group_id = mlxsw_sp_acl_ruleset_group_id(ruleset);
|
2017-09-25 08:58:20 +00:00
|
|
|
err = mlxsw_sp_acl_rulei_act_jump(rulei, group_id);
|
2018-07-24 14:13:14 +00:00
|
|
|
if (err) {
|
|
|
|
NL_SET_ERR_MSG_MOD(extack, "Cannot append jump action");
|
2017-09-25 08:58:20 +00:00
|
|
|
return err;
|
2018-07-24 14:13:14 +00:00
|
|
|
}
|
2019-02-02 11:50:48 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case FLOW_ACTION_REDIRECT: {
|
2017-02-03 09:29:09 +00:00
|
|
|
struct net_device *out_dev;
|
2017-05-26 06:37:39 +00:00
|
|
|
struct mlxsw_sp_fid *fid;
|
|
|
|
u16 fid_index;
|
2017-02-03 09:29:09 +00:00
|
|
|
|
2019-07-27 17:32:55 +00:00
|
|
|
if (mlxsw_sp_acl_block_is_egress_bound(block)) {
|
|
|
|
NL_SET_ERR_MSG_MOD(extack, "Redirect action is not supported on egress");
|
|
|
|
return -EOPNOTSUPP;
|
|
|
|
}
|
|
|
|
|
2019-07-27 17:32:56 +00:00
|
|
|
/* Forbid block with this rulei to be bound
|
|
|
|
* to egress in future.
|
|
|
|
*/
|
|
|
|
rulei->egress_bind_blocker = 1;
|
|
|
|
|
2017-05-26 06:37:39 +00:00
|
|
|
fid = mlxsw_sp_acl_dummy_fid(mlxsw_sp);
|
|
|
|
fid_index = mlxsw_sp_fid_index(fid);
|
2017-04-18 14:55:34 +00:00
|
|
|
err = mlxsw_sp_acl_rulei_act_fid_set(mlxsw_sp, rulei,
|
2018-07-24 14:13:11 +00:00
|
|
|
fid_index, extack);
|
2017-04-18 14:55:34 +00:00
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
2019-02-02 11:50:48 +00:00
|
|
|
out_dev = act->dev;
|
2017-02-03 09:29:09 +00:00
|
|
|
err = mlxsw_sp_acl_rulei_act_fwd(mlxsw_sp, rulei,
|
2018-07-24 14:13:11 +00:00
|
|
|
out_dev, extack);
|
2017-02-03 09:29:09 +00:00
|
|
|
if (err)
|
|
|
|
return err;
|
2019-02-02 11:50:48 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case FLOW_ACTION_MIRRED: {
|
|
|
|
struct net_device *out_dev = act->dev;
|
2018-01-19 08:24:52 +00:00
|
|
|
|
2019-09-26 11:43:40 +00:00
|
|
|
if (mirror_act_count++) {
|
|
|
|
NL_SET_ERR_MSG_MOD(extack, "Multiple mirror actions per rule are not supported");
|
|
|
|
return -EOPNOTSUPP;
|
|
|
|
}
|
|
|
|
|
2018-01-19 08:24:52 +00:00
|
|
|
err = mlxsw_sp_acl_rulei_act_mirror(mlxsw_sp, rulei,
|
2018-07-24 14:13:11 +00:00
|
|
|
block, out_dev,
|
|
|
|
extack);
|
2018-01-19 08:24:52 +00:00
|
|
|
if (err)
|
|
|
|
return err;
|
2019-02-02 11:50:48 +00:00
|
|
|
}
|
|
|
|
break;
|
2019-02-12 16:29:53 +00:00
|
|
|
case FLOW_ACTION_VLAN_MANGLE: {
|
2019-02-02 11:50:48 +00:00
|
|
|
u16 proto = be16_to_cpu(act->vlan.proto);
|
|
|
|
u8 prio = act->vlan.prio;
|
|
|
|
u16 vid = act->vlan.vid;
|
2017-03-09 08:25:19 +00:00
|
|
|
|
|
|
|
return mlxsw_sp_acl_rulei_act_vlan(mlxsw_sp, rulei,
|
2019-02-02 11:50:48 +00:00
|
|
|
act->id, vid,
|
2018-07-24 14:13:11 +00:00
|
|
|
proto, prio, extack);
|
2019-02-02 11:50:48 +00:00
|
|
|
}
|
|
|
|
default:
|
2018-07-24 14:13:14 +00:00
|
|
|
NL_SET_ERR_MSG_MOD(extack, "Unsupported action");
|
2017-02-03 09:29:09 +00:00
|
|
|
dev_err(mlxsw_sp->bus_info->dev, "Unsupported action\n");
|
|
|
|
return -EOPNOTSUPP;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-06-19 06:41:08 +00:00
|
|
|
static int mlxsw_sp_flower_parse_meta(struct mlxsw_sp_acl_rule_info *rulei,
|
2019-07-09 20:55:49 +00:00
|
|
|
struct flow_cls_offload *f,
|
2019-06-19 06:41:08 +00:00
|
|
|
struct mlxsw_sp_acl_block *block)
|
|
|
|
{
|
2019-07-09 20:55:49 +00:00
|
|
|
struct flow_rule *rule = flow_cls_offload_flow_rule(f);
|
2019-06-19 06:41:08 +00:00
|
|
|
struct mlxsw_sp_port *mlxsw_sp_port;
|
|
|
|
struct net_device *ingress_dev;
|
|
|
|
struct flow_match_meta match;
|
|
|
|
|
|
|
|
if (!flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_META))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
flow_rule_match_meta(rule, &match);
|
|
|
|
if (match.mask->ingress_ifindex != 0xFFFFFFFF) {
|
|
|
|
NL_SET_ERR_MSG_MOD(f->common.extack, "Unsupported ingress ifindex mask");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
ingress_dev = __dev_get_by_index(block->net,
|
|
|
|
match.key->ingress_ifindex);
|
|
|
|
if (!ingress_dev) {
|
|
|
|
NL_SET_ERR_MSG_MOD(f->common.extack, "Can't find specified ingress port to match on");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mlxsw_sp_port_dev_check(ingress_dev)) {
|
|
|
|
NL_SET_ERR_MSG_MOD(f->common.extack, "Can't match on non-mlxsw ingress port");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
mlxsw_sp_port = netdev_priv(ingress_dev);
|
|
|
|
if (mlxsw_sp_port->mlxsw_sp != block->mlxsw_sp) {
|
|
|
|
NL_SET_ERR_MSG_MOD(f->common.extack, "Can't match on a port from different device");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
mlxsw_sp_acl_rulei_keymask_u32(rulei,
|
|
|
|
MLXSW_AFK_ELEMENT_SRC_SYS_PORT,
|
|
|
|
mlxsw_sp_port->local_port,
|
|
|
|
0xFFFFFFFF);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-02-03 09:29:09 +00:00
|
|
|
static void mlxsw_sp_flower_parse_ipv4(struct mlxsw_sp_acl_rule_info *rulei,
|
2019-07-09 20:55:49 +00:00
|
|
|
struct flow_cls_offload *f)
|
2017-02-03 09:29:09 +00:00
|
|
|
{
|
2019-02-02 11:50:43 +00:00
|
|
|
struct flow_match_ipv4_addrs match;
|
|
|
|
|
|
|
|
flow_rule_match_ipv4_addrs(f->rule, &match);
|
2017-02-03 09:29:09 +00:00
|
|
|
|
2018-07-08 07:00:17 +00:00
|
|
|
mlxsw_sp_acl_rulei_keymask_buf(rulei, MLXSW_AFK_ELEMENT_SRC_IP_0_31,
|
2019-02-02 11:50:43 +00:00
|
|
|
(char *) &match.key->src,
|
|
|
|
(char *) &match.mask->src, 4);
|
2018-07-08 07:00:17 +00:00
|
|
|
mlxsw_sp_acl_rulei_keymask_buf(rulei, MLXSW_AFK_ELEMENT_DST_IP_0_31,
|
2019-02-02 11:50:43 +00:00
|
|
|
(char *) &match.key->dst,
|
|
|
|
(char *) &match.mask->dst, 4);
|
2017-02-03 09:29:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void mlxsw_sp_flower_parse_ipv6(struct mlxsw_sp_acl_rule_info *rulei,
|
2019-07-09 20:55:49 +00:00
|
|
|
struct flow_cls_offload *f)
|
2017-02-03 09:29:09 +00:00
|
|
|
{
|
2019-02-02 11:50:43 +00:00
|
|
|
struct flow_match_ipv6_addrs match;
|
|
|
|
|
|
|
|
flow_rule_match_ipv6_addrs(f->rule, &match);
|
2018-07-08 07:00:17 +00:00
|
|
|
|
|
|
|
mlxsw_sp_acl_rulei_keymask_buf(rulei, MLXSW_AFK_ELEMENT_SRC_IP_96_127,
|
2019-02-02 11:50:43 +00:00
|
|
|
&match.key->src.s6_addr[0x0],
|
|
|
|
&match.mask->src.s6_addr[0x0], 4);
|
2018-07-08 07:00:17 +00:00
|
|
|
mlxsw_sp_acl_rulei_keymask_buf(rulei, MLXSW_AFK_ELEMENT_SRC_IP_64_95,
|
2019-02-02 11:50:43 +00:00
|
|
|
&match.key->src.s6_addr[0x4],
|
|
|
|
&match.mask->src.s6_addr[0x4], 4);
|
2018-07-08 07:00:17 +00:00
|
|
|
mlxsw_sp_acl_rulei_keymask_buf(rulei, MLXSW_AFK_ELEMENT_SRC_IP_32_63,
|
2019-02-02 11:50:43 +00:00
|
|
|
&match.key->src.s6_addr[0x8],
|
|
|
|
&match.mask->src.s6_addr[0x8], 4);
|
2018-07-08 07:00:17 +00:00
|
|
|
mlxsw_sp_acl_rulei_keymask_buf(rulei, MLXSW_AFK_ELEMENT_SRC_IP_0_31,
|
2019-02-02 11:50:43 +00:00
|
|
|
&match.key->src.s6_addr[0xC],
|
|
|
|
&match.mask->src.s6_addr[0xC], 4);
|
2018-07-08 07:00:17 +00:00
|
|
|
mlxsw_sp_acl_rulei_keymask_buf(rulei, MLXSW_AFK_ELEMENT_DST_IP_96_127,
|
2019-02-02 11:50:43 +00:00
|
|
|
&match.key->dst.s6_addr[0x0],
|
|
|
|
&match.mask->dst.s6_addr[0x0], 4);
|
2018-07-08 07:00:17 +00:00
|
|
|
mlxsw_sp_acl_rulei_keymask_buf(rulei, MLXSW_AFK_ELEMENT_DST_IP_64_95,
|
2019-02-02 11:50:43 +00:00
|
|
|
&match.key->dst.s6_addr[0x4],
|
|
|
|
&match.mask->dst.s6_addr[0x4], 4);
|
2018-07-08 07:00:17 +00:00
|
|
|
mlxsw_sp_acl_rulei_keymask_buf(rulei, MLXSW_AFK_ELEMENT_DST_IP_32_63,
|
2019-02-02 11:50:43 +00:00
|
|
|
&match.key->dst.s6_addr[0x8],
|
|
|
|
&match.mask->dst.s6_addr[0x8], 4);
|
2018-07-08 07:00:17 +00:00
|
|
|
mlxsw_sp_acl_rulei_keymask_buf(rulei, MLXSW_AFK_ELEMENT_DST_IP_0_31,
|
2019-02-02 11:50:43 +00:00
|
|
|
&match.key->dst.s6_addr[0xC],
|
|
|
|
&match.mask->dst.s6_addr[0xC], 4);
|
2017-02-03 09:29:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int mlxsw_sp_flower_parse_ports(struct mlxsw_sp *mlxsw_sp,
|
|
|
|
struct mlxsw_sp_acl_rule_info *rulei,
|
2019-07-09 20:55:49 +00:00
|
|
|
struct flow_cls_offload *f,
|
2017-02-03 09:29:09 +00:00
|
|
|
u8 ip_proto)
|
|
|
|
{
|
2019-07-09 20:55:49 +00:00
|
|
|
const struct flow_rule *rule = flow_cls_offload_flow_rule(f);
|
2019-02-02 11:50:43 +00:00
|
|
|
struct flow_match_ports match;
|
2017-02-03 09:29:09 +00:00
|
|
|
|
2019-02-02 11:50:43 +00:00
|
|
|
if (!flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_PORTS))
|
2017-02-03 09:29:09 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (ip_proto != IPPROTO_TCP && ip_proto != IPPROTO_UDP) {
|
2018-07-24 14:13:14 +00:00
|
|
|
NL_SET_ERR_MSG_MOD(f->common.extack, "Only UDP and TCP keys are supported");
|
2017-02-03 09:29:09 +00:00
|
|
|
dev_err(mlxsw_sp->bus_info->dev, "Only UDP and TCP keys are supported\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2019-02-02 11:50:43 +00:00
|
|
|
flow_rule_match_ports(rule, &match);
|
2017-02-03 09:29:09 +00:00
|
|
|
mlxsw_sp_acl_rulei_keymask_u32(rulei, MLXSW_AFK_ELEMENT_DST_L4_PORT,
|
2019-02-02 11:50:43 +00:00
|
|
|
ntohs(match.key->dst),
|
|
|
|
ntohs(match.mask->dst));
|
2017-02-03 09:29:09 +00:00
|
|
|
mlxsw_sp_acl_rulei_keymask_u32(rulei, MLXSW_AFK_ELEMENT_SRC_L4_PORT,
|
2019-02-02 11:50:43 +00:00
|
|
|
ntohs(match.key->src),
|
|
|
|
ntohs(match.mask->src));
|
2017-02-03 09:29:09 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-05-23 16:40:48 +00:00
|
|
|
static int mlxsw_sp_flower_parse_tcp(struct mlxsw_sp *mlxsw_sp,
|
|
|
|
struct mlxsw_sp_acl_rule_info *rulei,
|
2019-07-09 20:55:49 +00:00
|
|
|
struct flow_cls_offload *f,
|
2017-05-23 16:40:48 +00:00
|
|
|
u8 ip_proto)
|
|
|
|
{
|
2019-07-09 20:55:49 +00:00
|
|
|
const struct flow_rule *rule = flow_cls_offload_flow_rule(f);
|
2019-02-02 11:50:43 +00:00
|
|
|
struct flow_match_tcp match;
|
2017-05-23 16:40:48 +00:00
|
|
|
|
2019-02-02 11:50:43 +00:00
|
|
|
if (!flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_TCP))
|
2017-05-23 16:40:48 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (ip_proto != IPPROTO_TCP) {
|
2018-07-24 14:13:14 +00:00
|
|
|
NL_SET_ERR_MSG_MOD(f->common.extack, "TCP keys supported only for TCP");
|
2017-05-23 16:40:48 +00:00
|
|
|
dev_err(mlxsw_sp->bus_info->dev, "TCP keys supported only for TCP\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2019-02-02 11:50:43 +00:00
|
|
|
flow_rule_match_tcp(rule, &match);
|
|
|
|
|
2019-07-27 17:32:57 +00:00
|
|
|
if (match.mask->flags & htons(0x0E00)) {
|
|
|
|
NL_SET_ERR_MSG_MOD(f->common.extack, "TCP flags match not supported on reserved bits");
|
|
|
|
dev_err(mlxsw_sp->bus_info->dev, "TCP flags match not supported on reserved bits\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2017-05-23 16:40:48 +00:00
|
|
|
mlxsw_sp_acl_rulei_keymask_u32(rulei, MLXSW_AFK_ELEMENT_TCP_FLAGS,
|
2019-02-02 11:50:43 +00:00
|
|
|
ntohs(match.key->flags),
|
|
|
|
ntohs(match.mask->flags));
|
2017-05-23 16:40:48 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-07-17 12:07:28 +00:00
|
|
|
static int mlxsw_sp_flower_parse_ip(struct mlxsw_sp *mlxsw_sp,
|
|
|
|
struct mlxsw_sp_acl_rule_info *rulei,
|
2019-07-09 20:55:49 +00:00
|
|
|
struct flow_cls_offload *f,
|
2017-07-17 12:07:28 +00:00
|
|
|
u16 n_proto)
|
|
|
|
{
|
2019-07-09 20:55:49 +00:00
|
|
|
const struct flow_rule *rule = flow_cls_offload_flow_rule(f);
|
2019-02-02 11:50:43 +00:00
|
|
|
struct flow_match_ip match;
|
2017-07-17 12:07:28 +00:00
|
|
|
|
2019-02-02 11:50:43 +00:00
|
|
|
if (!flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_IP))
|
2017-07-17 12:07:28 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (n_proto != ETH_P_IP && n_proto != ETH_P_IPV6) {
|
2018-07-24 14:13:14 +00:00
|
|
|
NL_SET_ERR_MSG_MOD(f->common.extack, "IP keys supported only for IPv4/6");
|
2017-07-17 12:07:28 +00:00
|
|
|
dev_err(mlxsw_sp->bus_info->dev, "IP keys supported only for IPv4/6\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2019-02-02 11:50:43 +00:00
|
|
|
flow_rule_match_ip(rule, &match);
|
|
|
|
|
2017-07-17 12:07:28 +00:00
|
|
|
mlxsw_sp_acl_rulei_keymask_u32(rulei, MLXSW_AFK_ELEMENT_IP_TTL_,
|
2019-02-02 11:50:43 +00:00
|
|
|
match.key->ttl, match.mask->ttl);
|
2017-07-17 12:07:31 +00:00
|
|
|
|
|
|
|
mlxsw_sp_acl_rulei_keymask_u32(rulei, MLXSW_AFK_ELEMENT_IP_ECN,
|
2019-02-02 11:50:43 +00:00
|
|
|
match.key->tos & 0x3,
|
|
|
|
match.mask->tos & 0x3);
|
2017-07-17 12:07:31 +00:00
|
|
|
|
|
|
|
mlxsw_sp_acl_rulei_keymask_u32(rulei, MLXSW_AFK_ELEMENT_IP_DSCP,
|
2019-06-11 07:19:43 +00:00
|
|
|
match.key->tos >> 2,
|
|
|
|
match.mask->tos >> 2);
|
2017-07-17 12:07:31 +00:00
|
|
|
|
2017-07-17 12:07:28 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-02-03 09:29:09 +00:00
|
|
|
static int mlxsw_sp_flower_parse(struct mlxsw_sp *mlxsw_sp,
|
2018-01-17 10:46:56 +00:00
|
|
|
struct mlxsw_sp_acl_block *block,
|
2017-02-03 09:29:09 +00:00
|
|
|
struct mlxsw_sp_acl_rule_info *rulei,
|
2019-07-09 20:55:49 +00:00
|
|
|
struct flow_cls_offload *f)
|
2017-02-03 09:29:09 +00:00
|
|
|
{
|
2019-07-09 20:55:49 +00:00
|
|
|
struct flow_rule *rule = flow_cls_offload_flow_rule(f);
|
2019-02-02 11:50:43 +00:00
|
|
|
struct flow_dissector *dissector = rule->match.dissector;
|
2017-07-17 12:07:28 +00:00
|
|
|
u16 n_proto_mask = 0;
|
|
|
|
u16 n_proto_key = 0;
|
2017-02-03 09:29:09 +00:00
|
|
|
u16 addr_type = 0;
|
|
|
|
u8 ip_proto = 0;
|
|
|
|
int err;
|
|
|
|
|
2019-02-02 11:50:43 +00:00
|
|
|
if (dissector->used_keys &
|
2019-06-19 06:41:08 +00:00
|
|
|
~(BIT(FLOW_DISSECTOR_KEY_META) |
|
|
|
|
BIT(FLOW_DISSECTOR_KEY_CONTROL) |
|
2017-02-03 09:29:09 +00:00
|
|
|
BIT(FLOW_DISSECTOR_KEY_BASIC) |
|
|
|
|
BIT(FLOW_DISSECTOR_KEY_ETH_ADDRS) |
|
|
|
|
BIT(FLOW_DISSECTOR_KEY_IPV4_ADDRS) |
|
|
|
|
BIT(FLOW_DISSECTOR_KEY_IPV6_ADDRS) |
|
2017-03-09 08:25:20 +00:00
|
|
|
BIT(FLOW_DISSECTOR_KEY_PORTS) |
|
2017-05-23 16:40:46 +00:00
|
|
|
BIT(FLOW_DISSECTOR_KEY_TCP) |
|
2017-07-17 12:07:28 +00:00
|
|
|
BIT(FLOW_DISSECTOR_KEY_IP) |
|
2017-03-09 08:25:20 +00:00
|
|
|
BIT(FLOW_DISSECTOR_KEY_VLAN))) {
|
2017-02-03 09:29:09 +00:00
|
|
|
dev_err(mlxsw_sp->bus_info->dev, "Unsupported key\n");
|
2018-07-24 14:13:14 +00:00
|
|
|
NL_SET_ERR_MSG_MOD(f->common.extack, "Unsupported key");
|
2017-02-03 09:29:09 +00:00
|
|
|
return -EOPNOTSUPP;
|
|
|
|
}
|
|
|
|
|
2017-08-07 08:15:30 +00:00
|
|
|
mlxsw_sp_acl_rulei_priority(rulei, f->common.prio);
|
2017-02-03 09:29:09 +00:00
|
|
|
|
2019-06-19 06:41:08 +00:00
|
|
|
err = mlxsw_sp_flower_parse_meta(rulei, f, block);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
2019-02-02 11:50:43 +00:00
|
|
|
if (flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_CONTROL)) {
|
|
|
|
struct flow_match_control match;
|
|
|
|
|
|
|
|
flow_rule_match_control(rule, &match);
|
|
|
|
addr_type = match.key->addr_type;
|
2017-02-03 09:29:09 +00:00
|
|
|
}
|
|
|
|
|
2019-02-02 11:50:43 +00:00
|
|
|
if (flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_BASIC)) {
|
|
|
|
struct flow_match_basic match;
|
|
|
|
|
|
|
|
flow_rule_match_basic(rule, &match);
|
|
|
|
n_proto_key = ntohs(match.key->n_proto);
|
|
|
|
n_proto_mask = ntohs(match.mask->n_proto);
|
2017-02-09 13:42:03 +00:00
|
|
|
|
|
|
|
if (n_proto_key == ETH_P_ALL) {
|
|
|
|
n_proto_key = 0;
|
|
|
|
n_proto_mask = 0;
|
|
|
|
}
|
2017-02-03 09:29:09 +00:00
|
|
|
mlxsw_sp_acl_rulei_keymask_u32(rulei,
|
|
|
|
MLXSW_AFK_ELEMENT_ETHERTYPE,
|
2017-02-09 13:42:03 +00:00
|
|
|
n_proto_key, n_proto_mask);
|
|
|
|
|
2019-02-02 11:50:43 +00:00
|
|
|
ip_proto = match.key->ip_proto;
|
2017-02-03 09:29:09 +00:00
|
|
|
mlxsw_sp_acl_rulei_keymask_u32(rulei,
|
|
|
|
MLXSW_AFK_ELEMENT_IP_PROTO,
|
2019-02-02 11:50:43 +00:00
|
|
|
match.key->ip_proto,
|
|
|
|
match.mask->ip_proto);
|
2017-02-03 09:29:09 +00:00
|
|
|
}
|
|
|
|
|
2019-02-02 11:50:43 +00:00
|
|
|
if (flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_ETH_ADDRS)) {
|
|
|
|
struct flow_match_eth_addrs match;
|
2017-02-03 09:29:09 +00:00
|
|
|
|
2019-02-02 11:50:43 +00:00
|
|
|
flow_rule_match_eth_addrs(rule, &match);
|
2017-02-03 09:29:09 +00:00
|
|
|
mlxsw_sp_acl_rulei_keymask_buf(rulei,
|
2018-07-08 07:00:17 +00:00
|
|
|
MLXSW_AFK_ELEMENT_DMAC_32_47,
|
2019-02-02 11:50:43 +00:00
|
|
|
match.key->dst,
|
|
|
|
match.mask->dst, 2);
|
2018-07-08 07:00:17 +00:00
|
|
|
mlxsw_sp_acl_rulei_keymask_buf(rulei,
|
|
|
|
MLXSW_AFK_ELEMENT_DMAC_0_31,
|
2019-02-02 11:50:43 +00:00
|
|
|
match.key->dst + 2,
|
|
|
|
match.mask->dst + 2, 4);
|
2018-07-08 07:00:17 +00:00
|
|
|
mlxsw_sp_acl_rulei_keymask_buf(rulei,
|
|
|
|
MLXSW_AFK_ELEMENT_SMAC_32_47,
|
2019-02-02 11:50:43 +00:00
|
|
|
match.key->src,
|
|
|
|
match.mask->src, 2);
|
2017-02-03 09:29:09 +00:00
|
|
|
mlxsw_sp_acl_rulei_keymask_buf(rulei,
|
2018-07-08 07:00:17 +00:00
|
|
|
MLXSW_AFK_ELEMENT_SMAC_0_31,
|
2019-02-02 11:50:43 +00:00
|
|
|
match.key->src + 2,
|
|
|
|
match.mask->src + 2, 4);
|
2017-02-03 09:29:09 +00:00
|
|
|
}
|
|
|
|
|
2019-02-02 11:50:43 +00:00
|
|
|
if (flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_VLAN)) {
|
|
|
|
struct flow_match_vlan match;
|
2018-08-09 08:59:07 +00:00
|
|
|
|
2019-02-02 11:50:43 +00:00
|
|
|
flow_rule_match_vlan(rule, &match);
|
2018-08-09 08:59:07 +00:00
|
|
|
if (mlxsw_sp_acl_block_is_egress_bound(block)) {
|
|
|
|
NL_SET_ERR_MSG_MOD(f->common.extack, "vlan_id key is not supported on egress");
|
|
|
|
return -EOPNOTSUPP;
|
|
|
|
}
|
2019-07-27 17:32:56 +00:00
|
|
|
|
|
|
|
/* Forbid block with this rulei to be bound
|
|
|
|
* to egress in future.
|
|
|
|
*/
|
|
|
|
rulei->egress_bind_blocker = 1;
|
|
|
|
|
2019-02-02 11:50:43 +00:00
|
|
|
if (match.mask->vlan_id != 0)
|
2017-03-09 08:25:20 +00:00
|
|
|
mlxsw_sp_acl_rulei_keymask_u32(rulei,
|
|
|
|
MLXSW_AFK_ELEMENT_VID,
|
2019-02-02 11:50:43 +00:00
|
|
|
match.key->vlan_id,
|
|
|
|
match.mask->vlan_id);
|
|
|
|
if (match.mask->vlan_priority != 0)
|
2017-03-09 08:25:20 +00:00
|
|
|
mlxsw_sp_acl_rulei_keymask_u32(rulei,
|
|
|
|
MLXSW_AFK_ELEMENT_PCP,
|
2019-02-02 11:50:43 +00:00
|
|
|
match.key->vlan_priority,
|
|
|
|
match.mask->vlan_priority);
|
2017-03-09 08:25:20 +00:00
|
|
|
}
|
|
|
|
|
2017-02-03 09:29:09 +00:00
|
|
|
if (addr_type == FLOW_DISSECTOR_KEY_IPV4_ADDRS)
|
|
|
|
mlxsw_sp_flower_parse_ipv4(rulei, f);
|
|
|
|
|
|
|
|
if (addr_type == FLOW_DISSECTOR_KEY_IPV6_ADDRS)
|
|
|
|
mlxsw_sp_flower_parse_ipv6(rulei, f);
|
|
|
|
|
|
|
|
err = mlxsw_sp_flower_parse_ports(mlxsw_sp, rulei, f, ip_proto);
|
2017-05-23 16:40:48 +00:00
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
err = mlxsw_sp_flower_parse_tcp(mlxsw_sp, rulei, f, ip_proto);
|
2017-02-03 09:29:09 +00:00
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
2017-07-17 12:07:28 +00:00
|
|
|
err = mlxsw_sp_flower_parse_ip(mlxsw_sp, rulei, f, n_proto_key & n_proto_mask);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
2019-02-02 11:50:48 +00:00
|
|
|
return mlxsw_sp_flower_parse_actions(mlxsw_sp, block, rulei,
|
|
|
|
&f->rule->action,
|
2018-07-24 14:13:11 +00:00
|
|
|
f->common.extack);
|
2017-02-03 09:29:09 +00:00
|
|
|
}
|
|
|
|
|
2018-01-17 10:46:56 +00:00
|
|
|
int mlxsw_sp_flower_replace(struct mlxsw_sp *mlxsw_sp,
|
|
|
|
struct mlxsw_sp_acl_block *block,
|
2019-07-09 20:55:49 +00:00
|
|
|
struct flow_cls_offload *f)
|
2017-02-03 09:29:09 +00:00
|
|
|
{
|
|
|
|
struct mlxsw_sp_acl_rule_info *rulei;
|
|
|
|
struct mlxsw_sp_acl_ruleset *ruleset;
|
|
|
|
struct mlxsw_sp_acl_rule *rule;
|
|
|
|
int err;
|
|
|
|
|
2018-01-17 10:46:56 +00:00
|
|
|
ruleset = mlxsw_sp_acl_ruleset_get(mlxsw_sp, block,
|
2017-08-23 08:08:18 +00:00
|
|
|
f->common.chain_index,
|
2018-07-23 07:23:12 +00:00
|
|
|
MLXSW_SP_ACL_PROFILE_FLOWER, NULL);
|
2017-02-03 09:29:09 +00:00
|
|
|
if (IS_ERR(ruleset))
|
|
|
|
return PTR_ERR(ruleset);
|
|
|
|
|
2018-12-10 07:11:43 +00:00
|
|
|
rule = mlxsw_sp_acl_rule_create(mlxsw_sp, ruleset, f->cookie, NULL,
|
2018-07-24 14:13:11 +00:00
|
|
|
f->common.extack);
|
2017-02-03 09:29:09 +00:00
|
|
|
if (IS_ERR(rule)) {
|
|
|
|
err = PTR_ERR(rule);
|
|
|
|
goto err_rule_create;
|
|
|
|
}
|
|
|
|
|
|
|
|
rulei = mlxsw_sp_acl_rule_rulei(rule);
|
2018-01-17 10:46:56 +00:00
|
|
|
err = mlxsw_sp_flower_parse(mlxsw_sp, block, rulei, f);
|
2017-02-03 09:29:09 +00:00
|
|
|
if (err)
|
|
|
|
goto err_flower_parse;
|
|
|
|
|
|
|
|
err = mlxsw_sp_acl_rulei_commit(rulei);
|
|
|
|
if (err)
|
|
|
|
goto err_rulei_commit;
|
|
|
|
|
|
|
|
err = mlxsw_sp_acl_rule_add(mlxsw_sp, rule);
|
|
|
|
if (err)
|
|
|
|
goto err_rule_add;
|
|
|
|
|
|
|
|
mlxsw_sp_acl_ruleset_put(mlxsw_sp, ruleset);
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
err_rule_add:
|
|
|
|
err_rulei_commit:
|
|
|
|
err_flower_parse:
|
|
|
|
mlxsw_sp_acl_rule_destroy(mlxsw_sp, rule);
|
|
|
|
err_rule_create:
|
|
|
|
mlxsw_sp_acl_ruleset_put(mlxsw_sp, ruleset);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2018-01-17 10:46:56 +00:00
|
|
|
void mlxsw_sp_flower_destroy(struct mlxsw_sp *mlxsw_sp,
|
|
|
|
struct mlxsw_sp_acl_block *block,
|
2019-07-09 20:55:49 +00:00
|
|
|
struct flow_cls_offload *f)
|
2017-02-03 09:29:09 +00:00
|
|
|
{
|
|
|
|
struct mlxsw_sp_acl_ruleset *ruleset;
|
|
|
|
struct mlxsw_sp_acl_rule *rule;
|
|
|
|
|
2018-01-17 10:46:56 +00:00
|
|
|
ruleset = mlxsw_sp_acl_ruleset_get(mlxsw_sp, block,
|
|
|
|
f->common.chain_index,
|
2018-07-23 07:23:12 +00:00
|
|
|
MLXSW_SP_ACL_PROFILE_FLOWER, NULL);
|
2017-03-06 20:22:09 +00:00
|
|
|
if (IS_ERR(ruleset))
|
2017-02-03 09:29:09 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
rule = mlxsw_sp_acl_rule_lookup(mlxsw_sp, ruleset, f->cookie);
|
2017-03-06 20:22:09 +00:00
|
|
|
if (rule) {
|
2017-02-03 09:29:09 +00:00
|
|
|
mlxsw_sp_acl_rule_del(mlxsw_sp, rule);
|
|
|
|
mlxsw_sp_acl_rule_destroy(mlxsw_sp, rule);
|
|
|
|
}
|
|
|
|
|
|
|
|
mlxsw_sp_acl_ruleset_put(mlxsw_sp, ruleset);
|
|
|
|
}
|
2017-03-11 08:42:59 +00:00
|
|
|
|
2018-01-17 10:46:56 +00:00
|
|
|
int mlxsw_sp_flower_stats(struct mlxsw_sp *mlxsw_sp,
|
|
|
|
struct mlxsw_sp_acl_block *block,
|
2019-07-09 20:55:49 +00:00
|
|
|
struct flow_cls_offload *f)
|
2017-03-11 08:42:59 +00:00
|
|
|
{
|
|
|
|
struct mlxsw_sp_acl_ruleset *ruleset;
|
|
|
|
struct mlxsw_sp_acl_rule *rule;
|
|
|
|
u64 packets;
|
|
|
|
u64 lastuse;
|
|
|
|
u64 bytes;
|
|
|
|
int err;
|
|
|
|
|
2018-01-17 10:46:56 +00:00
|
|
|
ruleset = mlxsw_sp_acl_ruleset_get(mlxsw_sp, block,
|
|
|
|
f->common.chain_index,
|
2018-07-23 07:23:12 +00:00
|
|
|
MLXSW_SP_ACL_PROFILE_FLOWER, NULL);
|
2017-03-11 08:42:59 +00:00
|
|
|
if (WARN_ON(IS_ERR(ruleset)))
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
rule = mlxsw_sp_acl_rule_lookup(mlxsw_sp, ruleset, f->cookie);
|
|
|
|
if (!rule)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2017-03-20 11:37:22 +00:00
|
|
|
err = mlxsw_sp_acl_rule_get_stats(mlxsw_sp, rule, &packets, &bytes,
|
2017-03-11 08:42:59 +00:00
|
|
|
&lastuse);
|
|
|
|
if (err)
|
|
|
|
goto err_rule_get_stats;
|
|
|
|
|
2019-02-02 11:50:47 +00:00
|
|
|
flow_stats_update(&f->stats, bytes, packets, lastuse);
|
2017-03-11 08:42:59 +00:00
|
|
|
|
|
|
|
mlxsw_sp_acl_ruleset_put(mlxsw_sp, ruleset);
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
err_rule_get_stats:
|
|
|
|
mlxsw_sp_acl_ruleset_put(mlxsw_sp, ruleset);
|
|
|
|
return err;
|
|
|
|
}
|
2018-07-23 07:23:12 +00:00
|
|
|
|
|
|
|
int mlxsw_sp_flower_tmplt_create(struct mlxsw_sp *mlxsw_sp,
|
|
|
|
struct mlxsw_sp_acl_block *block,
|
2019-07-09 20:55:49 +00:00
|
|
|
struct flow_cls_offload *f)
|
2018-07-23 07:23:12 +00:00
|
|
|
{
|
|
|
|
struct mlxsw_sp_acl_ruleset *ruleset;
|
|
|
|
struct mlxsw_sp_acl_rule_info rulei;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
memset(&rulei, 0, sizeof(rulei));
|
|
|
|
err = mlxsw_sp_flower_parse(mlxsw_sp, block, &rulei, f);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
ruleset = mlxsw_sp_acl_ruleset_get(mlxsw_sp, block,
|
|
|
|
f->common.chain_index,
|
|
|
|
MLXSW_SP_ACL_PROFILE_FLOWER,
|
|
|
|
&rulei.values.elusage);
|
2018-08-08 12:29:08 +00:00
|
|
|
|
2018-07-23 07:23:12 +00:00
|
|
|
/* keep the reference to the ruleset */
|
2018-08-08 12:29:08 +00:00
|
|
|
return PTR_ERR_OR_ZERO(ruleset);
|
2018-07-23 07:23:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void mlxsw_sp_flower_tmplt_destroy(struct mlxsw_sp *mlxsw_sp,
|
|
|
|
struct mlxsw_sp_acl_block *block,
|
2019-07-09 20:55:49 +00:00
|
|
|
struct flow_cls_offload *f)
|
2018-07-23 07:23:12 +00:00
|
|
|
{
|
|
|
|
struct mlxsw_sp_acl_ruleset *ruleset;
|
|
|
|
|
|
|
|
ruleset = mlxsw_sp_acl_ruleset_get(mlxsw_sp, block,
|
|
|
|
f->common.chain_index,
|
|
|
|
MLXSW_SP_ACL_PROFILE_FLOWER, NULL);
|
|
|
|
if (IS_ERR(ruleset))
|
|
|
|
return;
|
|
|
|
/* put the reference to the ruleset kept in create */
|
|
|
|
mlxsw_sp_acl_ruleset_put(mlxsw_sp, ruleset);
|
|
|
|
mlxsw_sp_acl_ruleset_put(mlxsw_sp, ruleset);
|
|
|
|
}
|