2017-02-03 16:29:09 +07:00
|
|
|
/*
|
|
|
|
* drivers/net/ethernet/mellanox/mlxsw/spectrum_flower.c
|
|
|
|
* Copyright (c) 2017 Mellanox Technologies. All rights reserved.
|
|
|
|
* Copyright (c) 2017 Jiri Pirko <jiri@mellanox.com>
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions are met:
|
|
|
|
*
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. Neither the names of the copyright holders nor the names of its
|
|
|
|
* contributors may be used to endorse or promote products derived from
|
|
|
|
* this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* Alternatively, this software may be distributed under the terms of the
|
|
|
|
* GNU General Public License ("GPL") version 2 as published by the Free
|
|
|
|
* Software Foundation.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
|
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
|
|
|
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/errno.h>
|
|
|
|
#include <linux/netdevice.h>
|
2018-01-17 17:46:56 +07:00
|
|
|
#include <net/net_namespace.h>
|
2017-02-03 16:29:09 +07: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 15:25:19 +07:00
|
|
|
#include <net/tc_act/tc_vlan.h>
|
2017-02-03 16:29:09 +07: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 17:46:56 +07:00
|
|
|
struct mlxsw_sp_acl_block *block,
|
2017-02-03 16:29:09 +07:00
|
|
|
struct mlxsw_sp_acl_rule_info *rulei,
|
|
|
|
struct tcf_exts *exts)
|
|
|
|
{
|
|
|
|
const struct tc_action *a;
|
|
|
|
LIST_HEAD(actions);
|
|
|
|
int err;
|
|
|
|
|
2017-08-04 19:28:58 +07:00
|
|
|
if (!tcf_exts_has_actions(exts))
|
2017-02-03 16:29:09 +07:00
|
|
|
return 0;
|
|
|
|
|
2017-03-11 15:42:59 +07:00
|
|
|
/* Count action is inserted first */
|
|
|
|
err = mlxsw_sp_acl_rulei_act_count(mlxsw_sp, rulei);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
2017-02-03 16:29:09 +07:00
|
|
|
tcf_exts_to_list(exts, &actions);
|
|
|
|
list_for_each_entry(a, &actions, list) {
|
2017-09-25 15:58:22 +07:00
|
|
|
if (is_tcf_gact_ok(a)) {
|
2018-03-09 20:33:52 +07:00
|
|
|
err = mlxsw_sp_acl_rulei_act_terminate(rulei);
|
2017-09-25 15:58:22 +07:00
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
} else if (is_tcf_gact_shot(a)) {
|
2017-02-03 16:29:09 +07:00
|
|
|
err = mlxsw_sp_acl_rulei_act_drop(rulei);
|
|
|
|
if (err)
|
|
|
|
return err;
|
2017-06-06 19:12:07 +07:00
|
|
|
} else if (is_tcf_gact_trap(a)) {
|
|
|
|
err = mlxsw_sp_acl_rulei_act_trap(rulei);
|
|
|
|
if (err)
|
|
|
|
return err;
|
2017-08-23 15:08:22 +07:00
|
|
|
} else if (is_tcf_gact_goto_chain(a)) {
|
|
|
|
u32 chain_index = tcf_gact_goto_chain_index(a);
|
|
|
|
struct mlxsw_sp_acl_ruleset *ruleset;
|
|
|
|
u16 group_id;
|
|
|
|
|
2018-01-17 17:46:56 +07:00
|
|
|
ruleset = mlxsw_sp_acl_ruleset_lookup(mlxsw_sp, block,
|
2017-08-23 15:08:22 +07: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 15:58:20 +07:00
|
|
|
err = mlxsw_sp_acl_rulei_act_jump(rulei, group_id);
|
|
|
|
if (err)
|
|
|
|
return err;
|
2017-02-03 16:29:09 +07:00
|
|
|
} else if (is_tcf_mirred_egress_redirect(a)) {
|
|
|
|
struct net_device *out_dev;
|
2017-05-26 13:37:39 +07:00
|
|
|
struct mlxsw_sp_fid *fid;
|
|
|
|
u16 fid_index;
|
2017-02-03 16:29:09 +07:00
|
|
|
|
2017-05-26 13:37:39 +07:00
|
|
|
fid = mlxsw_sp_acl_dummy_fid(mlxsw_sp);
|
|
|
|
fid_index = mlxsw_sp_fid_index(fid);
|
2017-04-18 21:55:34 +07:00
|
|
|
err = mlxsw_sp_acl_rulei_act_fid_set(mlxsw_sp, rulei,
|
2017-05-26 13:37:39 +07:00
|
|
|
fid_index);
|
2017-04-18 21:55:34 +07:00
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
2017-12-06 07:17:26 +07:00
|
|
|
out_dev = tcf_mirred_dev(a);
|
2017-02-03 16:29:09 +07:00
|
|
|
err = mlxsw_sp_acl_rulei_act_fwd(mlxsw_sp, rulei,
|
|
|
|
out_dev);
|
|
|
|
if (err)
|
|
|
|
return err;
|
2018-01-19 15:24:52 +07:00
|
|
|
} else if (is_tcf_mirred_egress_mirror(a)) {
|
|
|
|
struct net_device *out_dev = tcf_mirred_dev(a);
|
|
|
|
|
|
|
|
err = mlxsw_sp_acl_rulei_act_mirror(mlxsw_sp, rulei,
|
|
|
|
block, out_dev);
|
|
|
|
if (err)
|
|
|
|
return err;
|
2017-03-09 15:25:19 +07:00
|
|
|
} else if (is_tcf_vlan(a)) {
|
|
|
|
u16 proto = be16_to_cpu(tcf_vlan_push_proto(a));
|
|
|
|
u32 action = tcf_vlan_action(a);
|
|
|
|
u8 prio = tcf_vlan_push_prio(a);
|
|
|
|
u16 vid = tcf_vlan_push_vid(a);
|
|
|
|
|
|
|
|
return mlxsw_sp_acl_rulei_act_vlan(mlxsw_sp, rulei,
|
|
|
|
action, vid,
|
|
|
|
proto, prio);
|
2017-02-03 16:29:09 +07:00
|
|
|
} else {
|
|
|
|
dev_err(mlxsw_sp->bus_info->dev, "Unsupported action\n");
|
|
|
|
return -EOPNOTSUPP;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void mlxsw_sp_flower_parse_ipv4(struct mlxsw_sp_acl_rule_info *rulei,
|
|
|
|
struct tc_cls_flower_offload *f)
|
|
|
|
{
|
|
|
|
struct flow_dissector_key_ipv4_addrs *key =
|
|
|
|
skb_flow_dissector_target(f->dissector,
|
|
|
|
FLOW_DISSECTOR_KEY_IPV4_ADDRS,
|
|
|
|
f->key);
|
|
|
|
struct flow_dissector_key_ipv4_addrs *mask =
|
|
|
|
skb_flow_dissector_target(f->dissector,
|
|
|
|
FLOW_DISSECTOR_KEY_IPV4_ADDRS,
|
|
|
|
f->mask);
|
|
|
|
|
2018-07-08 14:00:17 +07:00
|
|
|
mlxsw_sp_acl_rulei_keymask_buf(rulei, MLXSW_AFK_ELEMENT_SRC_IP_0_31,
|
|
|
|
(char *) &key->src,
|
|
|
|
(char *) &mask->src, 4);
|
|
|
|
mlxsw_sp_acl_rulei_keymask_buf(rulei, MLXSW_AFK_ELEMENT_DST_IP_0_31,
|
|
|
|
(char *) &key->dst,
|
|
|
|
(char *) &mask->dst, 4);
|
2017-02-03 16:29:09 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void mlxsw_sp_flower_parse_ipv6(struct mlxsw_sp_acl_rule_info *rulei,
|
|
|
|
struct tc_cls_flower_offload *f)
|
|
|
|
{
|
|
|
|
struct flow_dissector_key_ipv6_addrs *key =
|
|
|
|
skb_flow_dissector_target(f->dissector,
|
|
|
|
FLOW_DISSECTOR_KEY_IPV6_ADDRS,
|
|
|
|
f->key);
|
|
|
|
struct flow_dissector_key_ipv6_addrs *mask =
|
|
|
|
skb_flow_dissector_target(f->dissector,
|
|
|
|
FLOW_DISSECTOR_KEY_IPV6_ADDRS,
|
|
|
|
f->mask);
|
2018-07-08 14:00:17 +07:00
|
|
|
|
|
|
|
mlxsw_sp_acl_rulei_keymask_buf(rulei, MLXSW_AFK_ELEMENT_SRC_IP_96_127,
|
|
|
|
&key->src.s6_addr[0x0],
|
|
|
|
&mask->src.s6_addr[0x0], 4);
|
|
|
|
mlxsw_sp_acl_rulei_keymask_buf(rulei, MLXSW_AFK_ELEMENT_SRC_IP_64_95,
|
|
|
|
&key->src.s6_addr[0x4],
|
|
|
|
&mask->src.s6_addr[0x4], 4);
|
|
|
|
mlxsw_sp_acl_rulei_keymask_buf(rulei, MLXSW_AFK_ELEMENT_SRC_IP_32_63,
|
|
|
|
&key->src.s6_addr[0x8],
|
|
|
|
&mask->src.s6_addr[0x8], 4);
|
|
|
|
mlxsw_sp_acl_rulei_keymask_buf(rulei, MLXSW_AFK_ELEMENT_SRC_IP_0_31,
|
|
|
|
&key->src.s6_addr[0xC],
|
|
|
|
&mask->src.s6_addr[0xC], 4);
|
|
|
|
mlxsw_sp_acl_rulei_keymask_buf(rulei, MLXSW_AFK_ELEMENT_DST_IP_96_127,
|
|
|
|
&key->dst.s6_addr[0x0],
|
|
|
|
&mask->dst.s6_addr[0x0], 4);
|
|
|
|
mlxsw_sp_acl_rulei_keymask_buf(rulei, MLXSW_AFK_ELEMENT_DST_IP_64_95,
|
|
|
|
&key->dst.s6_addr[0x4],
|
|
|
|
&mask->dst.s6_addr[0x4], 4);
|
|
|
|
mlxsw_sp_acl_rulei_keymask_buf(rulei, MLXSW_AFK_ELEMENT_DST_IP_32_63,
|
|
|
|
&key->dst.s6_addr[0x8],
|
|
|
|
&mask->dst.s6_addr[0x8], 4);
|
|
|
|
mlxsw_sp_acl_rulei_keymask_buf(rulei, MLXSW_AFK_ELEMENT_DST_IP_0_31,
|
|
|
|
&key->dst.s6_addr[0xC],
|
|
|
|
&mask->dst.s6_addr[0xC], 4);
|
2017-02-03 16:29:09 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static int mlxsw_sp_flower_parse_ports(struct mlxsw_sp *mlxsw_sp,
|
|
|
|
struct mlxsw_sp_acl_rule_info *rulei,
|
|
|
|
struct tc_cls_flower_offload *f,
|
|
|
|
u8 ip_proto)
|
|
|
|
{
|
|
|
|
struct flow_dissector_key_ports *key, *mask;
|
|
|
|
|
|
|
|
if (!dissector_uses_key(f->dissector, FLOW_DISSECTOR_KEY_PORTS))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (ip_proto != IPPROTO_TCP && ip_proto != IPPROTO_UDP) {
|
|
|
|
dev_err(mlxsw_sp->bus_info->dev, "Only UDP and TCP keys are supported\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
key = skb_flow_dissector_target(f->dissector,
|
|
|
|
FLOW_DISSECTOR_KEY_PORTS,
|
|
|
|
f->key);
|
|
|
|
mask = skb_flow_dissector_target(f->dissector,
|
|
|
|
FLOW_DISSECTOR_KEY_PORTS,
|
|
|
|
f->mask);
|
|
|
|
mlxsw_sp_acl_rulei_keymask_u32(rulei, MLXSW_AFK_ELEMENT_DST_L4_PORT,
|
|
|
|
ntohs(key->dst), ntohs(mask->dst));
|
|
|
|
mlxsw_sp_acl_rulei_keymask_u32(rulei, MLXSW_AFK_ELEMENT_SRC_L4_PORT,
|
|
|
|
ntohs(key->src), ntohs(mask->src));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-05-23 23:40:48 +07:00
|
|
|
static int mlxsw_sp_flower_parse_tcp(struct mlxsw_sp *mlxsw_sp,
|
|
|
|
struct mlxsw_sp_acl_rule_info *rulei,
|
|
|
|
struct tc_cls_flower_offload *f,
|
|
|
|
u8 ip_proto)
|
|
|
|
{
|
|
|
|
struct flow_dissector_key_tcp *key, *mask;
|
|
|
|
|
|
|
|
if (!dissector_uses_key(f->dissector, FLOW_DISSECTOR_KEY_TCP))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (ip_proto != IPPROTO_TCP) {
|
|
|
|
dev_err(mlxsw_sp->bus_info->dev, "TCP keys supported only for TCP\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
key = skb_flow_dissector_target(f->dissector,
|
|
|
|
FLOW_DISSECTOR_KEY_TCP,
|
|
|
|
f->key);
|
|
|
|
mask = skb_flow_dissector_target(f->dissector,
|
|
|
|
FLOW_DISSECTOR_KEY_TCP,
|
|
|
|
f->mask);
|
|
|
|
mlxsw_sp_acl_rulei_keymask_u32(rulei, MLXSW_AFK_ELEMENT_TCP_FLAGS,
|
|
|
|
ntohs(key->flags), ntohs(mask->flags));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-07-17 19:07:28 +07:00
|
|
|
static int mlxsw_sp_flower_parse_ip(struct mlxsw_sp *mlxsw_sp,
|
|
|
|
struct mlxsw_sp_acl_rule_info *rulei,
|
|
|
|
struct tc_cls_flower_offload *f,
|
|
|
|
u16 n_proto)
|
|
|
|
{
|
|
|
|
struct flow_dissector_key_ip *key, *mask;
|
|
|
|
|
|
|
|
if (!dissector_uses_key(f->dissector, FLOW_DISSECTOR_KEY_IP))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (n_proto != ETH_P_IP && n_proto != ETH_P_IPV6) {
|
|
|
|
dev_err(mlxsw_sp->bus_info->dev, "IP keys supported only for IPv4/6\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
key = skb_flow_dissector_target(f->dissector,
|
|
|
|
FLOW_DISSECTOR_KEY_IP,
|
|
|
|
f->key);
|
|
|
|
mask = skb_flow_dissector_target(f->dissector,
|
|
|
|
FLOW_DISSECTOR_KEY_IP,
|
|
|
|
f->mask);
|
|
|
|
mlxsw_sp_acl_rulei_keymask_u32(rulei, MLXSW_AFK_ELEMENT_IP_TTL_,
|
|
|
|
key->ttl, mask->ttl);
|
2017-07-17 19:07:31 +07:00
|
|
|
|
|
|
|
mlxsw_sp_acl_rulei_keymask_u32(rulei, MLXSW_AFK_ELEMENT_IP_ECN,
|
|
|
|
key->tos & 0x3, mask->tos & 0x3);
|
|
|
|
|
|
|
|
mlxsw_sp_acl_rulei_keymask_u32(rulei, MLXSW_AFK_ELEMENT_IP_DSCP,
|
|
|
|
key->tos >> 6, mask->tos >> 6);
|
|
|
|
|
2017-07-17 19:07:28 +07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-02-03 16:29:09 +07:00
|
|
|
static int mlxsw_sp_flower_parse(struct mlxsw_sp *mlxsw_sp,
|
2018-01-17 17:46:56 +07:00
|
|
|
struct mlxsw_sp_acl_block *block,
|
2017-02-03 16:29:09 +07:00
|
|
|
struct mlxsw_sp_acl_rule_info *rulei,
|
|
|
|
struct tc_cls_flower_offload *f)
|
|
|
|
{
|
2017-07-17 19:07:28 +07:00
|
|
|
u16 n_proto_mask = 0;
|
|
|
|
u16 n_proto_key = 0;
|
2017-02-03 16:29:09 +07:00
|
|
|
u16 addr_type = 0;
|
|
|
|
u8 ip_proto = 0;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
if (f->dissector->used_keys &
|
|
|
|
~(BIT(FLOW_DISSECTOR_KEY_CONTROL) |
|
|
|
|
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 15:25:20 +07:00
|
|
|
BIT(FLOW_DISSECTOR_KEY_PORTS) |
|
2017-05-23 23:40:46 +07:00
|
|
|
BIT(FLOW_DISSECTOR_KEY_TCP) |
|
2017-07-17 19:07:28 +07:00
|
|
|
BIT(FLOW_DISSECTOR_KEY_IP) |
|
2017-03-09 15:25:20 +07:00
|
|
|
BIT(FLOW_DISSECTOR_KEY_VLAN))) {
|
2017-02-03 16:29:09 +07:00
|
|
|
dev_err(mlxsw_sp->bus_info->dev, "Unsupported key\n");
|
|
|
|
return -EOPNOTSUPP;
|
|
|
|
}
|
|
|
|
|
2017-08-07 15:15:30 +07:00
|
|
|
mlxsw_sp_acl_rulei_priority(rulei, f->common.prio);
|
2017-02-03 16:29:09 +07:00
|
|
|
|
|
|
|
if (dissector_uses_key(f->dissector, FLOW_DISSECTOR_KEY_CONTROL)) {
|
|
|
|
struct flow_dissector_key_control *key =
|
|
|
|
skb_flow_dissector_target(f->dissector,
|
|
|
|
FLOW_DISSECTOR_KEY_CONTROL,
|
|
|
|
f->key);
|
|
|
|
addr_type = key->addr_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dissector_uses_key(f->dissector, FLOW_DISSECTOR_KEY_BASIC)) {
|
|
|
|
struct flow_dissector_key_basic *key =
|
|
|
|
skb_flow_dissector_target(f->dissector,
|
|
|
|
FLOW_DISSECTOR_KEY_BASIC,
|
|
|
|
f->key);
|
|
|
|
struct flow_dissector_key_basic *mask =
|
|
|
|
skb_flow_dissector_target(f->dissector,
|
|
|
|
FLOW_DISSECTOR_KEY_BASIC,
|
|
|
|
f->mask);
|
2017-07-17 19:07:28 +07:00
|
|
|
n_proto_key = ntohs(key->n_proto);
|
|
|
|
n_proto_mask = ntohs(mask->n_proto);
|
2017-02-09 20:42:03 +07:00
|
|
|
|
|
|
|
if (n_proto_key == ETH_P_ALL) {
|
|
|
|
n_proto_key = 0;
|
|
|
|
n_proto_mask = 0;
|
|
|
|
}
|
2017-02-03 16:29:09 +07:00
|
|
|
mlxsw_sp_acl_rulei_keymask_u32(rulei,
|
|
|
|
MLXSW_AFK_ELEMENT_ETHERTYPE,
|
2017-02-09 20:42:03 +07:00
|
|
|
n_proto_key, n_proto_mask);
|
|
|
|
|
|
|
|
ip_proto = key->ip_proto;
|
2017-02-03 16:29:09 +07:00
|
|
|
mlxsw_sp_acl_rulei_keymask_u32(rulei,
|
|
|
|
MLXSW_AFK_ELEMENT_IP_PROTO,
|
|
|
|
key->ip_proto, mask->ip_proto);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dissector_uses_key(f->dissector, FLOW_DISSECTOR_KEY_ETH_ADDRS)) {
|
|
|
|
struct flow_dissector_key_eth_addrs *key =
|
|
|
|
skb_flow_dissector_target(f->dissector,
|
|
|
|
FLOW_DISSECTOR_KEY_ETH_ADDRS,
|
|
|
|
f->key);
|
|
|
|
struct flow_dissector_key_eth_addrs *mask =
|
|
|
|
skb_flow_dissector_target(f->dissector,
|
|
|
|
FLOW_DISSECTOR_KEY_ETH_ADDRS,
|
|
|
|
f->mask);
|
|
|
|
|
|
|
|
mlxsw_sp_acl_rulei_keymask_buf(rulei,
|
2018-07-08 14:00:17 +07:00
|
|
|
MLXSW_AFK_ELEMENT_DMAC_32_47,
|
|
|
|
key->dst, mask->dst, 2);
|
|
|
|
mlxsw_sp_acl_rulei_keymask_buf(rulei,
|
|
|
|
MLXSW_AFK_ELEMENT_DMAC_0_31,
|
|
|
|
key->dst + 2, mask->dst + 2, 4);
|
|
|
|
mlxsw_sp_acl_rulei_keymask_buf(rulei,
|
|
|
|
MLXSW_AFK_ELEMENT_SMAC_32_47,
|
|
|
|
key->src, mask->src, 2);
|
2017-02-03 16:29:09 +07:00
|
|
|
mlxsw_sp_acl_rulei_keymask_buf(rulei,
|
2018-07-08 14:00:17 +07:00
|
|
|
MLXSW_AFK_ELEMENT_SMAC_0_31,
|
|
|
|
key->src + 2, mask->src + 2, 4);
|
2017-02-03 16:29:09 +07:00
|
|
|
}
|
|
|
|
|
2017-03-09 15:25:20 +07:00
|
|
|
if (dissector_uses_key(f->dissector, FLOW_DISSECTOR_KEY_VLAN)) {
|
|
|
|
struct flow_dissector_key_vlan *key =
|
|
|
|
skb_flow_dissector_target(f->dissector,
|
|
|
|
FLOW_DISSECTOR_KEY_VLAN,
|
|
|
|
f->key);
|
|
|
|
struct flow_dissector_key_vlan *mask =
|
|
|
|
skb_flow_dissector_target(f->dissector,
|
|
|
|
FLOW_DISSECTOR_KEY_VLAN,
|
|
|
|
f->mask);
|
|
|
|
if (mask->vlan_id != 0)
|
|
|
|
mlxsw_sp_acl_rulei_keymask_u32(rulei,
|
|
|
|
MLXSW_AFK_ELEMENT_VID,
|
|
|
|
key->vlan_id,
|
|
|
|
mask->vlan_id);
|
|
|
|
if (mask->vlan_priority != 0)
|
|
|
|
mlxsw_sp_acl_rulei_keymask_u32(rulei,
|
|
|
|
MLXSW_AFK_ELEMENT_PCP,
|
|
|
|
key->vlan_priority,
|
|
|
|
mask->vlan_priority);
|
|
|
|
}
|
|
|
|
|
2017-02-03 16:29:09 +07: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 23:40:48 +07:00
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
err = mlxsw_sp_flower_parse_tcp(mlxsw_sp, rulei, f, ip_proto);
|
2017-02-03 16:29:09 +07:00
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
2017-07-17 19:07:28 +07:00
|
|
|
err = mlxsw_sp_flower_parse_ip(mlxsw_sp, rulei, f, n_proto_key & n_proto_mask);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
2018-01-17 17:46:56 +07:00
|
|
|
return mlxsw_sp_flower_parse_actions(mlxsw_sp, block, rulei, f->exts);
|
2017-02-03 16:29:09 +07:00
|
|
|
}
|
|
|
|
|
2018-01-17 17:46:56 +07:00
|
|
|
int mlxsw_sp_flower_replace(struct mlxsw_sp *mlxsw_sp,
|
|
|
|
struct mlxsw_sp_acl_block *block,
|
2017-08-07 15:15:29 +07:00
|
|
|
struct tc_cls_flower_offload *f)
|
2017-02-03 16:29:09 +07: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 17:46:56 +07:00
|
|
|
ruleset = mlxsw_sp_acl_ruleset_get(mlxsw_sp, block,
|
2017-08-23 15:08:18 +07:00
|
|
|
f->common.chain_index,
|
2017-02-03 16:29:09 +07:00
|
|
|
MLXSW_SP_ACL_PROFILE_FLOWER);
|
|
|
|
if (IS_ERR(ruleset))
|
|
|
|
return PTR_ERR(ruleset);
|
|
|
|
|
|
|
|
rule = mlxsw_sp_acl_rule_create(mlxsw_sp, ruleset, f->cookie);
|
|
|
|
if (IS_ERR(rule)) {
|
|
|
|
err = PTR_ERR(rule);
|
|
|
|
goto err_rule_create;
|
|
|
|
}
|
|
|
|
|
|
|
|
rulei = mlxsw_sp_acl_rule_rulei(rule);
|
2018-01-17 17:46:56 +07:00
|
|
|
err = mlxsw_sp_flower_parse(mlxsw_sp, block, rulei, f);
|
2017-02-03 16:29:09 +07: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 17:46:56 +07:00
|
|
|
void mlxsw_sp_flower_destroy(struct mlxsw_sp *mlxsw_sp,
|
|
|
|
struct mlxsw_sp_acl_block *block,
|
2017-02-03 16:29:09 +07:00
|
|
|
struct tc_cls_flower_offload *f)
|
|
|
|
{
|
|
|
|
struct mlxsw_sp_acl_ruleset *ruleset;
|
|
|
|
struct mlxsw_sp_acl_rule *rule;
|
|
|
|
|
2018-01-17 17:46:56 +07:00
|
|
|
ruleset = mlxsw_sp_acl_ruleset_get(mlxsw_sp, block,
|
|
|
|
f->common.chain_index,
|
2017-02-03 16:29:09 +07:00
|
|
|
MLXSW_SP_ACL_PROFILE_FLOWER);
|
2017-03-07 03:22:09 +07:00
|
|
|
if (IS_ERR(ruleset))
|
2017-02-03 16:29:09 +07:00
|
|
|
return;
|
|
|
|
|
|
|
|
rule = mlxsw_sp_acl_rule_lookup(mlxsw_sp, ruleset, f->cookie);
|
2017-03-07 03:22:09 +07:00
|
|
|
if (rule) {
|
2017-02-03 16:29:09 +07: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 15:42:59 +07:00
|
|
|
|
2018-01-17 17:46:56 +07:00
|
|
|
int mlxsw_sp_flower_stats(struct mlxsw_sp *mlxsw_sp,
|
|
|
|
struct mlxsw_sp_acl_block *block,
|
2017-03-11 15:42:59 +07:00
|
|
|
struct tc_cls_flower_offload *f)
|
|
|
|
{
|
|
|
|
struct mlxsw_sp_acl_ruleset *ruleset;
|
|
|
|
struct mlxsw_sp_acl_rule *rule;
|
|
|
|
u64 packets;
|
|
|
|
u64 lastuse;
|
|
|
|
u64 bytes;
|
|
|
|
int err;
|
|
|
|
|
2018-01-17 17:46:56 +07:00
|
|
|
ruleset = mlxsw_sp_acl_ruleset_get(mlxsw_sp, block,
|
|
|
|
f->common.chain_index,
|
2017-03-11 15:42:59 +07:00
|
|
|
MLXSW_SP_ACL_PROFILE_FLOWER);
|
|
|
|
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 18:37:22 +07:00
|
|
|
err = mlxsw_sp_acl_rule_get_stats(mlxsw_sp, rule, &packets, &bytes,
|
2017-03-11 15:42:59 +07:00
|
|
|
&lastuse);
|
|
|
|
if (err)
|
|
|
|
goto err_rule_get_stats;
|
|
|
|
|
2017-05-31 22:06:43 +07:00
|
|
|
tcf_exts_stats_update(f->exts, bytes, packets, lastuse);
|
2017-03-11 15:42:59 +07: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;
|
|
|
|
}
|