Skip to contentSkip to conversation

net: bridge: mcast: don't delete permanent entries when fast leave is enabled

PATCH In review Nikolay Aleksandrov 3 participants 7 messages Jul 30, 2019 – Jul 31, 2019

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net: bridge: mcast: don't delete permanent entries when fast leave is enabled

When permanent entries were introduced by the commit below, they were exempt from timing out and thus igmp leave wouldn't affect them unless fast leave was enabled on the port which was added before permanent entries existed. It shouldn't matter if fast leave is enabled or not if the user added a permanent entry it shouldn't be deleted on igmp leave.

Before:

$ echo 1 > /sys/class/net/eth4/brport/multicast_fast_leave
$ bridge mdb add dev br0 port eth4 grp 229.1.1.1 permanent
$ bridge mdb show
dev br0 port eth4 grp 229.1.1.1 permanent

< join and leave 229.1.1.1 on eth4 >

$ bridge mdb show
$

After:

$ echo 1 > /sys/class/net/eth4/brport/multicast_fast_leave
$ bridge mdb add dev br0 port eth4 grp 229.1.1.1 permanent
$ bridge mdb show
dev br0 port eth4 grp 229.1.1.1 permanent

< join and leave 229.1.1.1 on eth4 >

$ bridge mdb show
dev br0 port eth4 grp 229.1.1.1 permanent
Fixes ccb1c31a7a87 ("bridge: add flags to distinguish permanent mdb entires")

---
I'll re-work this code in net-next as there's a lot of duplication.

 net/bridge/br_multicast.c | 3 +++
 1 file changed, 3 insertions(+)
net/bridge/br_multicast.c +3 -0
index 3d8deac2353d..f8cac3702712 100644
@@ -1388,6 +1388,9 @@ br_multicast_leave_group(struct net_bridge *br,
 			if (!br_port_group_equal(p, port, src))
 				continue;
 
+			if (p->flags & MDB_PG_FLAGS_PERMANENT)
+				break;
+
 			rcu_assign_pointer(*pp, p->next);
 			hlist_del_init(&p->mglist);
 			del_timer(&p->timer);
Signature · 1 line
2.21.0
#1 lore raw
Quoted 5 lines · Nikolay Aleksandrov
net/bridge/br_multicast.c +0 -0
index 3d8deac2353d..f8cac3702712 100644

net/bridge/br_multicast.c br_multicast_leave_group(struct net_bridge *br, · line 1396

Quoted 9 lines
net/bridge/br_multicast.c +3 -0
@@ -1388,6 +1388,9 @@ br_multicast_leave_group(struct net_bridge *br,
 			if (!br_port_group_equal(p, port, src))
 				continue;
 
+			if (p->flags & MDB_PG_FLAGS_PERMANENT)
+				break;
+
 			rcu_assign_pointer(*pp, p->next);
 			hlist_del_init(&p->mglist);
 			del_timer(&p->timer);

Why 'break' and not 'continue' like you have with

	if (!br_port_group_equal(p, port, src))
#2 lore raw
Quoted 17 lines · David Ahern
Quoted 5 lines · Nikolay Aleksandrov
net/bridge/br_multicast.c +0 -0
index 3d8deac2353d..f8cac3702712 100644

net/bridge/br_multicast.c br_multicast_leave_group(struct net_bridge *br, · line 1396

Quoted 9 lines
net/bridge/br_multicast.c +3 -0
@@ -1388,6 +1388,9 @@ br_multicast_leave_group(struct net_bridge *br,
 			if (!br_port_group_equal(p, port, src))
 				continue;
 
+			if (p->flags & MDB_PG_FLAGS_PERMANENT)
+				break;
+
 			rcu_assign_pointer(*pp, p->next);
 			hlist_del_init(&p->mglist);
 			del_timer(&p->timer);

Why 'break' and not 'continue' like you have with

Quoted 2 lines
	if (!br_port_group_equal(p, port, src))

Because we'll hit the goto out after this hunk always, no point in continuing if we matched a group and it's permanent, the break might as well be a goto out.

maintainer
#3 lore raw
In reply to Nikolay Aleksandrov

From: Nikolay Aleksandrov <[email protected]>
Date: Tue, 30 Jul 2019 14:21:00 +0300

net/bridge/br_multicast.c br_multicast_leave_group(struct net_bridge *br, · line 1393

Quoted 11 lines
net/bridge/br_multicast.c +3 -0
index 3d8deac2353d..f8cac3702712 100644
@@ -1388,6 +1388,9 @@ br_multicast_leave_group(struct net_bridge *br,
 			if (!br_port_group_equal(p, port, src))
 				continue;
 
+			if (p->flags & MDB_PG_FLAGS_PERMANENT)
+				break;
+

Like David, I also don't understand why this can be a break. Is it because permanent entries are always the last on the list? Why will there be no other entries that might need to be processed on the list?

#4 lore raw
Quoted 11 lines · David Miller

From: Nikolay Aleksandrov <[email protected]>
Date: Tue, 30 Jul 2019 14:21:00 +0300

Quoted 8 lines
net/bridge/br_multicast.c +0 -0
index 3d8deac2353d..f8cac3702712 100644
@@ -1388,6 +1388,9 @@ br_multicast_leave_group(struct net_bridge *br,
 			if (!br_port_group_equal(p, port, src))
 				continue;
 
Quoted 8 lines

net/bridge/br_multicast.c br_multicast_leave_group(struct net_bridge *br, · line 1393

Quoted 3 lines
net/bridge/br_multicast.c +3 -0
+			if (p->flags & MDB_PG_FLAGS_PERMANENT)
+				break;
+

Like David, I also don't understand why this can be a break. Is it because permanent entries are always the last on the list? Why will there be no other entries that might need to be processed on the list?

The reason is that only one port can match. See the first clause of br_port_group_equal, that port can participate only once. We could easily add a break statement in the end when a match is found and it will be correct. Even in the presence of MULTICAST_TO_UNICAST flag, the port must match and can be added only once.

#5 lore raw
Quoted 21 lines · Nikolay Aleksandrov
Quoted 11 lines · David Miller

From: Nikolay Aleksandrov <[email protected]>
Date: Tue, 30 Jul 2019 14:21:00 +0300

Quoted 8 lines
net/bridge/br_multicast.c +0 -0
index 3d8deac2353d..f8cac3702712 100644
@@ -1388,6 +1388,9 @@ br_multicast_leave_group(struct net_bridge *br,
 			if (!br_port_group_equal(p, port, src))
 				continue;
 
Quoted 8 lines

net/bridge/br_multicast.c br_multicast_leave_group(struct net_bridge *br, · line 1393

Quoted 3 lines
net/bridge/br_multicast.c +3 -0
+			if (p->flags & MDB_PG_FLAGS_PERMANENT)
+				break;
+

Like David, I also don't understand why this can be a break. Is it because permanent entries are always the last on the list? Why will there be no other entries that might need to be processed on the list?

Quoted 5 lines

The reason is that only one port can match. See the first clause of br_port_group_equal, that port can participate only once. We could easily add a break statement in the end when a match is found and it will be correct. Even in the presence of MULTICAST_TO_UNICAST flag, the port must match and can be added only once.

Like I wrote in the patch I plan to re-work that code in net-next to remove the duplication and make it more understandable to avoid such confusions. This code will be functionally equivalent if I put continue there, we'll just walk over all of them even after a match or permanent are found. There can only be one match though as I said, so walking the rest of the ports is a waste.

maintainer
#6 lore raw
In reply to Nikolay Aleksandrov

From: Nikolay Aleksandrov <[email protected]>
Date: Tue, 30 Jul 2019 14:21:00 +0300

Quoted 6 lines

When permanent entries were introduced by the commit below, they were exempt from timing out and thus igmp leave wouldn't affect them unless fast leave was enabled on the port which was added before permanent entries existed. It shouldn't matter if fast leave is enabled or not if the user added a permanent entry it shouldn't be deleted on igmp leave.

...

Quoted 2 lines
Fixes ccb1c31a7a87 ("bridge: add flags to distinguish permanent mdb entires")

Applied and queued up for -stable.