mlxsw: spectrum_acl: Support FLOW_ACTION_MANGLE for TCP, UDP ports
Spectrum-2 supports an ACL action L4_PORT, which allows TCP and UDP source and destination port number change. Offload suitable mangles to this action. Signed-off-by: Petr Machata <petrm@mellanox.com> Reviewed-by: Jiri Pirko <jiri@mellanox.com> Signed-off-by: Ido Schimmel <idosch@mellanox.com> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
parent
faad0525c0
commit
ce10d7d4ad
|
@ -1710,3 +1710,28 @@ MLXSW_ITEM32(afa, l4port, s_d, 0x00, 31, 1);
|
||||||
* Number of port to change to.
|
* Number of port to change to.
|
||||||
*/
|
*/
|
||||||
MLXSW_ITEM32(afa, l4port, l4_port, 0x08, 0, 16);
|
MLXSW_ITEM32(afa, l4port, l4_port, 0x08, 0, 16);
|
||||||
|
|
||||||
|
static void mlxsw_afa_l4port_pack(char *payload, enum mlxsw_afa_l4port_s_d s_d, u16 l4_port)
|
||||||
|
{
|
||||||
|
mlxsw_afa_l4port_s_d_set(payload, s_d);
|
||||||
|
mlxsw_afa_l4port_l4_port_set(payload, l4_port);
|
||||||
|
}
|
||||||
|
|
||||||
|
int mlxsw_afa_block_append_l4port(struct mlxsw_afa_block *block, bool is_dport, u16 l4_port,
|
||||||
|
struct netlink_ext_ack *extack)
|
||||||
|
{
|
||||||
|
enum mlxsw_afa_l4port_s_d s_d = is_dport ? MLXSW_AFA_L4PORT_S_D_DST :
|
||||||
|
MLXSW_AFA_L4PORT_S_D_SRC;
|
||||||
|
char *act = mlxsw_afa_block_append_action(block,
|
||||||
|
MLXSW_AFA_L4PORT_CODE,
|
||||||
|
MLXSW_AFA_L4PORT_SIZE);
|
||||||
|
|
||||||
|
if (IS_ERR(act)) {
|
||||||
|
NL_SET_ERR_MSG_MOD(extack, "Cannot append L4_PORT action");
|
||||||
|
return PTR_ERR(act);
|
||||||
|
}
|
||||||
|
|
||||||
|
mlxsw_afa_l4port_pack(act, s_d, l4_port);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
EXPORT_SYMBOL(mlxsw_afa_block_append_l4port);
|
||||||
|
|
|
@ -82,5 +82,7 @@ int mlxsw_afa_block_append_fid_set(struct mlxsw_afa_block *block, u16 fid,
|
||||||
int mlxsw_afa_block_append_mcrouter(struct mlxsw_afa_block *block,
|
int mlxsw_afa_block_append_mcrouter(struct mlxsw_afa_block *block,
|
||||||
u16 expected_irif, u16 min_mtu,
|
u16 expected_irif, u16 min_mtu,
|
||||||
bool rmid_valid, u32 kvdl_index);
|
bool rmid_valid, u32 kvdl_index);
|
||||||
|
int mlxsw_afa_block_append_l4port(struct mlxsw_afa_block *block, bool is_dport, u16 l4_port,
|
||||||
|
struct netlink_ext_ack *extack);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -508,6 +508,8 @@ enum mlxsw_sp_acl_mangle_field {
|
||||||
MLXSW_SP_ACL_MANGLE_FIELD_IP_DSFIELD,
|
MLXSW_SP_ACL_MANGLE_FIELD_IP_DSFIELD,
|
||||||
MLXSW_SP_ACL_MANGLE_FIELD_IP_DSCP,
|
MLXSW_SP_ACL_MANGLE_FIELD_IP_DSCP,
|
||||||
MLXSW_SP_ACL_MANGLE_FIELD_IP_ECN,
|
MLXSW_SP_ACL_MANGLE_FIELD_IP_ECN,
|
||||||
|
MLXSW_SP_ACL_MANGLE_FIELD_IP_SPORT,
|
||||||
|
MLXSW_SP_ACL_MANGLE_FIELD_IP_DPORT,
|
||||||
};
|
};
|
||||||
|
|
||||||
struct mlxsw_sp_acl_mangle_action {
|
struct mlxsw_sp_acl_mangle_action {
|
||||||
|
@ -538,13 +540,26 @@ struct mlxsw_sp_acl_mangle_action {
|
||||||
MLXSW_SP_ACL_MANGLE_ACTION(FLOW_ACT_MANGLE_HDR_TYPE_IP6, \
|
MLXSW_SP_ACL_MANGLE_ACTION(FLOW_ACT_MANGLE_HDR_TYPE_IP6, \
|
||||||
_offset, _mask, _shift, _field)
|
_offset, _mask, _shift, _field)
|
||||||
|
|
||||||
|
#define MLXSW_SP_ACL_MANGLE_ACTION_TCP(_offset, _mask, _shift, _field) \
|
||||||
|
MLXSW_SP_ACL_MANGLE_ACTION(FLOW_ACT_MANGLE_HDR_TYPE_TCP, _offset, _mask, _shift, _field)
|
||||||
|
|
||||||
|
#define MLXSW_SP_ACL_MANGLE_ACTION_UDP(_offset, _mask, _shift, _field) \
|
||||||
|
MLXSW_SP_ACL_MANGLE_ACTION(FLOW_ACT_MANGLE_HDR_TYPE_UDP, _offset, _mask, _shift, _field)
|
||||||
|
|
||||||
static struct mlxsw_sp_acl_mangle_action mlxsw_sp_acl_mangle_actions[] = {
|
static struct mlxsw_sp_acl_mangle_action mlxsw_sp_acl_mangle_actions[] = {
|
||||||
MLXSW_SP_ACL_MANGLE_ACTION_IP4(0, 0xff00ffff, 16, IP_DSFIELD),
|
MLXSW_SP_ACL_MANGLE_ACTION_IP4(0, 0xff00ffff, 16, IP_DSFIELD),
|
||||||
MLXSW_SP_ACL_MANGLE_ACTION_IP4(0, 0xff03ffff, 18, IP_DSCP),
|
MLXSW_SP_ACL_MANGLE_ACTION_IP4(0, 0xff03ffff, 18, IP_DSCP),
|
||||||
MLXSW_SP_ACL_MANGLE_ACTION_IP4(0, 0xfffcffff, 16, IP_ECN),
|
MLXSW_SP_ACL_MANGLE_ACTION_IP4(0, 0xfffcffff, 16, IP_ECN),
|
||||||
|
|
||||||
MLXSW_SP_ACL_MANGLE_ACTION_IP6(0, 0xf00fffff, 20, IP_DSFIELD),
|
MLXSW_SP_ACL_MANGLE_ACTION_IP6(0, 0xf00fffff, 20, IP_DSFIELD),
|
||||||
MLXSW_SP_ACL_MANGLE_ACTION_IP6(0, 0xf03fffff, 22, IP_DSCP),
|
MLXSW_SP_ACL_MANGLE_ACTION_IP6(0, 0xf03fffff, 22, IP_DSCP),
|
||||||
MLXSW_SP_ACL_MANGLE_ACTION_IP6(0, 0xffcfffff, 20, IP_ECN),
|
MLXSW_SP_ACL_MANGLE_ACTION_IP6(0, 0xffcfffff, 20, IP_ECN),
|
||||||
|
|
||||||
|
MLXSW_SP_ACL_MANGLE_ACTION_TCP(0, 0x0000ffff, 16, IP_SPORT),
|
||||||
|
MLXSW_SP_ACL_MANGLE_ACTION_TCP(0, 0xffff0000, 0, IP_DPORT),
|
||||||
|
|
||||||
|
MLXSW_SP_ACL_MANGLE_ACTION_UDP(0, 0x0000ffff, 16, IP_SPORT),
|
||||||
|
MLXSW_SP_ACL_MANGLE_ACTION_UDP(0, 0xffff0000, 0, IP_DPORT),
|
||||||
};
|
};
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
@ -594,6 +609,15 @@ static int mlxsw_sp2_acl_rulei_act_mangle_field(struct mlxsw_sp *mlxsw_sp,
|
||||||
if (err != -EOPNOTSUPP)
|
if (err != -EOPNOTSUPP)
|
||||||
return err;
|
return err;
|
||||||
|
|
||||||
|
switch (mact->field) {
|
||||||
|
case MLXSW_SP_ACL_MANGLE_FIELD_IP_SPORT:
|
||||||
|
return mlxsw_afa_block_append_l4port(rulei->act_block, false, val, extack);
|
||||||
|
case MLXSW_SP_ACL_MANGLE_FIELD_IP_DPORT:
|
||||||
|
return mlxsw_afa_block_append_l4port(rulei->act_block, true, val, extack);
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
NL_SET_ERR_MSG_MOD(extack, "Unsupported mangle field");
|
NL_SET_ERR_MSG_MOD(extack, "Unsupported mangle field");
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue