Skip to content

Commit 353def8

Browse files
idoschdavem330
authored andcommitted
mlxsw: spectrum_span: Prevent duplicate mirrors
In net commit 8175f7c4736f ("mlxsw: spectrum: Prevent duplicate mirrors") we prevented the user from mirroring more than once from a single binding point (port-direction pair). The fix was essentially reverted in a merge conflict resolution when net was merged into net-next. Restore it. Fixes: 03fe2de ("Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net") Signed-off-by: Petr Machata <[email protected]> Signed-off-by: Ido Schimmel <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent f452518 commit 353def8

File tree

1 file changed

+24
-4
lines changed

1 file changed

+24
-4
lines changed

drivers/net/ethernet/mellanox/mlxsw/spectrum_span.c

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -600,13 +600,17 @@ int mlxsw_sp_span_port_mtu_update(struct mlxsw_sp_port *port, u16 mtu)
600600
}
601601

602602
static struct mlxsw_sp_span_inspected_port *
603-
mlxsw_sp_span_entry_bound_port_find(struct mlxsw_sp_port *port,
604-
struct mlxsw_sp_span_entry *span_entry)
603+
mlxsw_sp_span_entry_bound_port_find(struct mlxsw_sp_span_entry *span_entry,
604+
enum mlxsw_sp_span_type type,
605+
struct mlxsw_sp_port *port,
606+
bool bind)
605607
{
606608
struct mlxsw_sp_span_inspected_port *p;
607609

608610
list_for_each_entry(p, &span_entry->bound_ports_list, list)
609-
if (port->local_port == p->local_port)
611+
if (type == p->type &&
612+
port->local_port == p->local_port &&
613+
bind == p->bound)
610614
return p;
611615
return NULL;
612616
}
@@ -636,8 +640,22 @@ mlxsw_sp_span_inspected_port_add(struct mlxsw_sp_port *port,
636640
struct mlxsw_sp_span_inspected_port *inspected_port;
637641
struct mlxsw_sp *mlxsw_sp = port->mlxsw_sp;
638642
char sbib_pl[MLXSW_REG_SBIB_LEN];
643+
int i;
639644
int err;
640645

646+
/* A given (source port, direction) can only be bound to one analyzer,
647+
* so if a binding is requested, check for conflicts.
648+
*/
649+
if (bind)
650+
for (i = 0; i < mlxsw_sp->span.entries_count; i++) {
651+
struct mlxsw_sp_span_entry *curr =
652+
&mlxsw_sp->span.entries[i];
653+
654+
if (mlxsw_sp_span_entry_bound_port_find(curr, type,
655+
port, bind))
656+
return -EEXIST;
657+
}
658+
641659
/* if it is an egress SPAN, bind a shared buffer to it */
642660
if (type == MLXSW_SP_SPAN_EGRESS) {
643661
u32 buffsize = mlxsw_sp_span_mtu_to_buffsize(mlxsw_sp,
@@ -665,6 +683,7 @@ mlxsw_sp_span_inspected_port_add(struct mlxsw_sp_port *port,
665683
}
666684
inspected_port->local_port = port->local_port;
667685
inspected_port->type = type;
686+
inspected_port->bound = bind;
668687
list_add_tail(&inspected_port->list, &span_entry->bound_ports_list);
669688

670689
return 0;
@@ -691,7 +710,8 @@ mlxsw_sp_span_inspected_port_del(struct mlxsw_sp_port *port,
691710
struct mlxsw_sp *mlxsw_sp = port->mlxsw_sp;
692711
char sbib_pl[MLXSW_REG_SBIB_LEN];
693712

694-
inspected_port = mlxsw_sp_span_entry_bound_port_find(port, span_entry);
713+
inspected_port = mlxsw_sp_span_entry_bound_port_find(span_entry, type,
714+
port, bind);
695715
if (!inspected_port)
696716
return;
697717

0 commit comments

Comments
 (0)