mlxsw: Support FLOW_ACTION_MANGLE for SIP and DIP IPv6 addresses

Spectrum-2 supports an ACL action SIP_DIP, which allows IPv4 and IPv6
source and destination addresses change. Offload suitable mangles to
the IPv6 address change action.

Signed-off-by: Danielle Ratson <danieller@nvidia.com>
Reviewed-by: Petr Machata <petrm@nvidia.com>
Signed-off-by: Ido Schimmel <idosch@nvidia.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
Danielle Ratson 2022-02-06 17:36:12 +02:00 committed by David S. Miller
parent d7809b620f
commit 463e1ab82a
3 changed files with 103 additions and 11 deletions

View File

@ -820,6 +820,24 @@ int mlxsw_sp1_kvdl_resources_register(struct mlxsw_core *mlxsw_core);
/* spectrum2_kvdl.c */
extern const struct mlxsw_sp_kvdl_ops mlxsw_sp2_kvdl_ops;
enum mlxsw_sp_acl_mangle_field {
MLXSW_SP_ACL_MANGLE_FIELD_IP_DSFIELD,
MLXSW_SP_ACL_MANGLE_FIELD_IP_DSCP,
MLXSW_SP_ACL_MANGLE_FIELD_IP_ECN,
MLXSW_SP_ACL_MANGLE_FIELD_IP_SPORT,
MLXSW_SP_ACL_MANGLE_FIELD_IP_DPORT,
MLXSW_SP_ACL_MANGLE_FIELD_IP4_SIP,
MLXSW_SP_ACL_MANGLE_FIELD_IP4_DIP,
MLXSW_SP_ACL_MANGLE_FIELD_IP6_SIP_1,
MLXSW_SP_ACL_MANGLE_FIELD_IP6_SIP_2,
MLXSW_SP_ACL_MANGLE_FIELD_IP6_SIP_3,
MLXSW_SP_ACL_MANGLE_FIELD_IP6_SIP_4,
MLXSW_SP_ACL_MANGLE_FIELD_IP6_DIP_1,
MLXSW_SP_ACL_MANGLE_FIELD_IP6_DIP_2,
MLXSW_SP_ACL_MANGLE_FIELD_IP6_DIP_3,
MLXSW_SP_ACL_MANGLE_FIELD_IP6_DIP_4,
};
struct mlxsw_sp_acl_rule_info {
unsigned int priority;
struct mlxsw_afk_element_values values;
@ -828,9 +846,14 @@ struct mlxsw_sp_acl_rule_info {
ingress_bind_blocker:1,
egress_bind_blocker:1,
counter_valid:1,
policer_index_valid:1;
policer_index_valid:1,
ipv6_valid:1;
unsigned int counter_index;
u16 policer_index;
struct {
u32 prev_val;
enum mlxsw_sp_acl_mangle_field prev_field;
} ipv6;
};
/* spectrum_flow.c */

View File

@ -505,16 +505,6 @@ int mlxsw_sp_acl_rulei_act_priority(struct mlxsw_sp *mlxsw_sp,
extack);
}
enum mlxsw_sp_acl_mangle_field {
MLXSW_SP_ACL_MANGLE_FIELD_IP_DSFIELD,
MLXSW_SP_ACL_MANGLE_FIELD_IP_DSCP,
MLXSW_SP_ACL_MANGLE_FIELD_IP_ECN,
MLXSW_SP_ACL_MANGLE_FIELD_IP_SPORT,
MLXSW_SP_ACL_MANGLE_FIELD_IP_DPORT,
MLXSW_SP_ACL_MANGLE_FIELD_IP4_SIP,
MLXSW_SP_ACL_MANGLE_FIELD_IP4_DIP,
};
struct mlxsw_sp_acl_mangle_action {
enum flow_action_mangle_base htype;
/* Offset is u32-aligned. */
@ -566,6 +556,15 @@ static struct mlxsw_sp_acl_mangle_action mlxsw_sp_acl_mangle_actions[] = {
MLXSW_SP_ACL_MANGLE_ACTION_IP4(12, 0x00000000, 0, IP4_SIP),
MLXSW_SP_ACL_MANGLE_ACTION_IP4(16, 0x00000000, 0, IP4_DIP),
MLXSW_SP_ACL_MANGLE_ACTION_IP6(8, 0x00000000, 0, IP6_SIP_1),
MLXSW_SP_ACL_MANGLE_ACTION_IP6(12, 0x00000000, 0, IP6_SIP_2),
MLXSW_SP_ACL_MANGLE_ACTION_IP6(16, 0x00000000, 0, IP6_SIP_3),
MLXSW_SP_ACL_MANGLE_ACTION_IP6(20, 0x00000000, 0, IP6_SIP_4),
MLXSW_SP_ACL_MANGLE_ACTION_IP6(24, 0x00000000, 0, IP6_DIP_1),
MLXSW_SP_ACL_MANGLE_ACTION_IP6(28, 0x00000000, 0, IP6_DIP_2),
MLXSW_SP_ACL_MANGLE_ACTION_IP6(32, 0x00000000, 0, IP6_DIP_3),
MLXSW_SP_ACL_MANGLE_ACTION_IP6(36, 0x00000000, 0, IP6_DIP_4),
};
static int
@ -604,6 +603,22 @@ static int mlxsw_sp1_acl_rulei_act_mangle_field(struct mlxsw_sp *mlxsw_sp,
return err;
}
static int
mlxsw_sp2_acl_rulei_act_mangle_field_ip_odd(struct mlxsw_sp_acl_rule_info *rulei,
enum mlxsw_sp_acl_mangle_field field,
u32 val, struct netlink_ext_ack *extack)
{
if (!rulei->ipv6_valid) {
rulei->ipv6.prev_val = val;
rulei->ipv6_valid = true;
rulei->ipv6.prev_field = field;
return 0;
}
NL_SET_ERR_MSG_MOD(extack, "Unsupported mangle field order");
return -EOPNOTSUPP;
}
static int mlxsw_sp2_acl_rulei_act_mangle_field(struct mlxsw_sp *mlxsw_sp,
struct mlxsw_sp_acl_rule_info *rulei,
struct mlxsw_sp_acl_mangle_action *mact,
@ -627,6 +642,54 @@ static int mlxsw_sp2_acl_rulei_act_mangle_field(struct mlxsw_sp *mlxsw_sp,
case MLXSW_SP_ACL_MANGLE_FIELD_IP4_DIP:
return mlxsw_afa_block_append_ip(rulei->act_block, true,
true, val, 0, extack);
/* IPv6 fields */
case MLXSW_SP_ACL_MANGLE_FIELD_IP6_SIP_1:
case MLXSW_SP_ACL_MANGLE_FIELD_IP6_SIP_3:
case MLXSW_SP_ACL_MANGLE_FIELD_IP6_DIP_1:
case MLXSW_SP_ACL_MANGLE_FIELD_IP6_DIP_3:
return mlxsw_sp2_acl_rulei_act_mangle_field_ip_odd(rulei,
mact->field,
val, extack);
case MLXSW_SP_ACL_MANGLE_FIELD_IP6_SIP_2:
if (rulei->ipv6_valid &&
rulei->ipv6.prev_field == MLXSW_SP_ACL_MANGLE_FIELD_IP6_SIP_1) {
rulei->ipv6_valid = false;
return mlxsw_afa_block_append_ip(rulei->act_block,
false, false, val,
rulei->ipv6.prev_val,
extack);
}
break;
case MLXSW_SP_ACL_MANGLE_FIELD_IP6_SIP_4:
if (rulei->ipv6_valid &&
rulei->ipv6.prev_field == MLXSW_SP_ACL_MANGLE_FIELD_IP6_SIP_3) {
rulei->ipv6_valid = false;
return mlxsw_afa_block_append_ip(rulei->act_block,
false, true, val,
rulei->ipv6.prev_val,
extack);
}
break;
case MLXSW_SP_ACL_MANGLE_FIELD_IP6_DIP_2:
if (rulei->ipv6_valid &&
rulei->ipv6.prev_field == MLXSW_SP_ACL_MANGLE_FIELD_IP6_DIP_1) {
rulei->ipv6_valid = false;
return mlxsw_afa_block_append_ip(rulei->act_block,
true, false, val,
rulei->ipv6.prev_val,
extack);
}
break;
case MLXSW_SP_ACL_MANGLE_FIELD_IP6_DIP_4:
if (rulei->ipv6_valid &&
rulei->ipv6.prev_field == MLXSW_SP_ACL_MANGLE_FIELD_IP6_DIP_3) {
rulei->ipv6_valid = false;
return mlxsw_afa_block_append_ip(rulei->act_block,
true, true, val,
rulei->ipv6.prev_val,
extack);
}
break;
default:
break;
}

View File

@ -233,6 +233,12 @@ static int mlxsw_sp_flower_parse_actions(struct mlxsw_sp *mlxsw_sp,
return -EOPNOTSUPP;
}
}
if (rulei->ipv6_valid) {
NL_SET_ERR_MSG_MOD(extack, "Unsupported mangle field");
return -EOPNOTSUPP;
}
return 0;
}