Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

mlxsw: spectrum_flower: Do not allow mixing sample and mirror actions

The device does not support multiple mirror actions per rule and the
driver rejects such configuration:

# tc filter add dev swp1 ingress pref 1 proto ip flower skip_sw action mirred egress mirror dev swp2 action mirred egress mirror dev swp3
Error: mlxsw_spectrum: Multiple mirror actions per rule are not supported.
We have an error talking to the kernel

Internally, the sample action is implemented by the device by mirroring
to the CPU port. Therefore, mixing sample and mirror actions in a single
rule does not work correctly and results in the last action effect.

Solve by rejecting such misconfiguration:

# tc filter add dev swp1 ingress pref 1 proto ip flower skip_sw action mirred egress mirror dev swp2 action sample rate 100 group 1
Error: mlxsw_spectrum: Sample action after mirror action is not supported.
We have an error talking to the kernel

# tc filter add dev swp1 ingress pref 1 proto ip flower skip_sw action sample rate 100 group 1 action mirred egress mirror dev swp2
Error: mlxsw_spectrum: Mirror action after sample action is not supported.
We have an error talking to the kernel

Reported-by: Vladyslav Mykhaliuk <vmykhaliuk@nvidia.com>
Signed-off-by: Ido Schimmel <idosch@nvidia.com>
Reviewed-by: Amit Cohen <amcohen@nvidia.com>
Reviewed-by: Jiri Pirko <jiri@nvidia.com>
Signed-off-by: Petr Machata <petrm@nvidia.com>
Reviewed-by: Michal Swiatkowski <michal.swiatkowski@linux.intel.com>
Reviewed-by: Kalesh AP <kalesh-anakkur.purayil@broadcom.com>
Link: https://patch.msgid.link/d6c979914e8706dbe1dedbaf29ffffb0b8d71166.1733822570.git.petrm@nvidia.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Ido Schimmel and committed by
Jakub Kicinski
175dd907 154dee7c

+10
+10
drivers/net/ethernet/mellanox/mlxsw/spectrum_flower.c
··· 192 192 return -EOPNOTSUPP; 193 193 } 194 194 195 + if (sample_act_count) { 196 + NL_SET_ERR_MSG_MOD(extack, "Mirror action after sample action is not supported"); 197 + return -EOPNOTSUPP; 198 + } 199 + 195 200 err = mlxsw_sp_acl_rulei_act_mirror(mlxsw_sp, rulei, 196 201 block, out_dev, 197 202 extack); ··· 267 262 case FLOW_ACTION_SAMPLE: { 268 263 if (sample_act_count++) { 269 264 NL_SET_ERR_MSG_MOD(extack, "Multiple sample actions per rule are not supported"); 265 + return -EOPNOTSUPP; 266 + } 267 + 268 + if (mirror_act_count) { 269 + NL_SET_ERR_MSG_MOD(extack, "Sample action after mirror action is not supported"); 270 270 return -EOPNOTSUPP; 271 271 } 272 272