bridge: multicast: per vlan query improvement when port or vlan state changes
Subsystems (3)
cover bridge: multicast: per vlan query improvement when port or vlan state changes
The current implementation of br_multicast_enable_port() only operates on port's multicast context, which doesn't take into account in case of vlan snooping, one downside is the port's igmp query timer will NOT resume when port state gets changed from BR_STATE_BLOCKING to BR_STATE_FORWARDING etc.
Such code flow will briefly look like:
1.vlan snooping
--> br_multicast_port_query_expired with per vlan port_mcast_ctx --> port in BR_STATE_BLOCKING state --> then one-shot timer discontinued
The port state could be changed by STP daemon or kernel STP, taking mstpd as example:
2.mstpd --> netlink_sendmsg --> br_setlink --> br_set_port_state with non
blocking states, i.e. BR_STATE_LEARNING or BR_STATE_FORWARDING --> br_port_state_selection --> br_multicast_enable_port --> enable multicast with port's multicast_ctx
Here for per vlan query, the port_mcast_ctx of each vlan should be used instead of port's multicast_ctx. The first patch corrects such behavior.
Similarly, vlan state could also impact multicast behavior, the 2nd patch adds function to update the corresponding multicast context when vlan state changes.
Yong Wang (2):
net: bridge: multicast: re-implement port multicast enable/disable
functions
net: bridge: multicast: update multicast contex when vlan state gets
changed
net/bridge/br_mst.c | 4 +- net/bridge/br_multicast.c | 96 +++++++++++++++++++++++++++++++++++---- net/bridge/br_private.h | 10 +++- 3 files changed, 99 insertions(+), 11 deletions(-)
base-commit: 3272040790eb4b6cafe6c30ec05049e9599ec456
Signature · 1 line
2.34.1
PATCH 1/2 net: bridge: multicast: re-implement port multicast enable/disable functions
Re-implement br_multicast_enable_port() / br_multicast_disable_port() by adding br_multicast_toggle_port() helper function in order to support per vlan multicast context enabling/disabling for bridge ports. As the port state could be changed by STP, that impacts multicast behaviors like igmp query. The corresponding context should be used either for per port context or per vlan context accordingly.
--- net/bridge/br_multicast.c | 72 ++++++++++++++++++++++++++++++++++----- 1 file changed, 64 insertions(+), 8 deletions(-)
net/bridge/br_multicast.c +64 -8
@@ -2105,12 +2105,17 @@ static void __br_multicast_enable_port_ctx(struct net_bridge_mcast_port *pmctx) } } -void br_multicast_enable_port (struct net_bridge_port *port) +static void br_multicast_enable_port_ctx (struct net_bridge_mcast_port *pmctx) { -struct net_bridge *br = port->br; +struct net_bridge *br = pmctx->port->br;spin_lock_bh (&br->multicast_lock); -__br_multicast_enable_port_ctx (&port->multicast_ctx); +if (br_multicast_port_ctx_is_vlan (pmctx) && + !(pmctx->vlan->priv_flags &BR_VLFLAG_MCAST_ENABLED )) { +spin_unlock_bh (&br->multicast_lock); +return ; + } +__br_multicast_enable_port_ctx (pmctx);spin_unlock_bh (&br->multicast_lock); }
@@ -2137,11 +2142,62 @@ static void __br_multicast_disable_port_ctx(struct net_bridge_mcast_port *pmctx)br_multicast_rport_del_notify (pmctx, del); } +static void br_multicast_disable_port_ctx (struct net_bridge_mcast_port *pmctx) +{ +struct net_bridge *br = pmctx->port->br; + +spin_lock_bh (&br->multicast_lock); +if (br_multicast_port_ctx_is_vlan (pmctx) && + !(pmctx->vlan->priv_flags &BR_VLFLAG_MCAST_ENABLED )) { +spin_unlock_bh (&br->multicast_lock); +return ; + } + +__br_multicast_disable_port_ctx (pmctx); +spin_unlock_bh (&br->multicast_lock); +} + +static void br_multicast_toggle_port (struct net_bridge_port *port,bool on) +{ +struct net_bridge *br = port->br; + +if (br_opt_get (br,BROPT_MCAST_VLAN_SNOOPING_ENABLED )) { +struct net_bridge_vlan_group *vg; +struct net_bridge_vlan *vlan; + +rcu_read_lock (); + vg =nbp_vlan_group_rcu (port); +if (!vg) { +rcu_read_unlock (); +return ; + } + +/* iterate each vlan of the port, toggle port_mcast_ctx per vlan */ +list_for_each_entry_rcu (vlan, &vg->vlan_list, vlist) { +/* enable port_mcast_ctx when vlan is LEARNING or FORWARDING */ +if (on &&br_vlan_state_allowed (br_vlan_get_state (vlan), true)) +br_multicast_enable_port_ctx (&vlan->port_mcast_ctx); +else +br_multicast_disable_port_ctx (&vlan->port_mcast_ctx); + } +rcu_read_unlock (); + }else { +/* use the port's multicast context when vlan snooping is disabled */ +if (on) +br_multicast_enable_port_ctx (&port->multicast_ctx); +else +br_multicast_disable_port_ctx (&port->multicast_ctx); + } +} + +void br_multicast_enable_port (struct net_bridge_port *port) +{ +br_multicast_toggle_port (port, true); +} +void br_multicast_disable_port (struct net_bridge_port *port) { -spin_lock_bh (&port->br->multicast_lock); -__br_multicast_disable_port_ctx (&port->multicast_ctx); -spin_unlock_bh (&port->br->multicast_lock); +br_multicast_toggle_port (port, false); }static int __grp_src_delete_marked (struct net_bridge_port_group *pg)
@@ -4304,9 +4360,9 @@ int br_multicast_toggle_vlan_snooping(struct net_bridge *br, bool on,__br_multicast_open (&br->multicast_ctx);list_for_each_entry (p, &br->port_list, list) {if (on) -br_multicast_disable_port (p); +br_multicast_disable_port_ctx (&p->multicast_ctx);else -br_multicast_enable_port (p); +br_multicast_enable_port_ctx (&p->multicast_ctx); }list_for_each_entry (vlan, &vg->vlan_list, vlist)
Signature · 1 line
2.34.1
kernel test robot
build botRe: [PATCH net-next 1/2] net: bridge: multicast: re-implement port multicast enable/disable functions
kernel test robot noticed the following build errors:
Hi Yong,
kernel test robot noticed the following build errors:
[auto build test ERROR on 3272040790eb4b6cafe6c30ec05049e9599ec456]
url: https://github.com/intel-lab-lkp/linux/commits/Yong-Wang/net-bridge-multicast-re-implement-port-multicast-enable-disable-functions/20241221-060848 base: 3272040790eb4b6cafe6c30ec05049e9599ec456 patch link: https://lore.kernel.org/r/20241220220604.1430728-2-yongwang%40nvidia.com patch subject: [PATCH net-next 1/2] net: bridge: multicast: re-implement port multicast enable/disable functions config: nios2-randconfig-r071-20241221 (https://download.01.org/0day-ci/archive/20241222/[email protected]/config) compiler: nios2-linux-gcc (GCC) 14.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20241222/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>):
net/bridge/br_multicast.c: In function 'br_multicast_toggle_port':
>> net/bridge/br_multicast.c:2178:35: error: implicit declaration of function 'br_vlan_state_allowed' [-Wimplicit-function-declaration]
2178 | if (on && br_vlan_state_allowed(br_vlan_get_state(vlan), true))
| ^~~~~~~~~~~~~~~~~~~~~
>> net/bridge/br_multicast.c:2178:57: error: implicit declaration of function 'br_vlan_get_state'; did you mean 'br_vlan_get_stats'? [-Wimplicit-function-declaration]
2178 | if (on && br_vlan_state_allowed(br_vlan_get_state(vlan), true))
| ^~~~~~~~~~~~~~~~~
| br_vlan_get_statsvim +/br_vlan_state_allowed +2178 net/bridge/br_multicast.c
2159
2160 static void br_multicast_toggle_port(struct net_bridge_port *port, bool on)
2161 {
2162 struct net_bridge *br = port->br;
2163
2164 if (br_opt_get(br, BROPT_MCAST_VLAN_SNOOPING_ENABLED)) {
2165 struct net_bridge_vlan_group *vg;
2166 struct net_bridge_vlan *vlan;
2167
2168 rcu_read_lock();
2169 vg = nbp_vlan_group_rcu(port);
2170 if (!vg) {
2171 rcu_read_unlock();
2172 return;
2173 }
2174
2175 /* iterate each vlan of the port, toggle port_mcast_ctx per vlan */
2176 list_for_each_entry_rcu(vlan, &vg->vlan_list, vlist) {
2177 /* enable port_mcast_ctx when vlan is LEARNING or FORWARDING */
> 2178 if (on && br_vlan_state_allowed(br_vlan_get_state(vlan), true))
2179 br_multicast_enable_port_ctx(&vlan->port_mcast_ctx);
2180 else
2181 br_multicast_disable_port_ctx(&vlan->port_mcast_ctx);
2182 }
2183 rcu_read_unlock();
2184 } else {
2185 /* use the port's multicast context when vlan snooping is disabled */
2186 if (on)
2187 br_multicast_enable_port_ctx(&port->multicast_ctx);
2188 else
2189 br_multicast_disable_port_ctx(&port->multicast_ctx);
2190 }
2191 }
2192
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
kernel test robot
build botRe: [PATCH net-next 1/2] net: bridge: multicast: re-implement port multicast enable/disable functions
In reply to Yong Wangkernel test robot noticed the following build errors:
Hi Yong,
kernel test robot noticed the following build errors:
[auto build test ERROR on 3272040790eb4b6cafe6c30ec05049e9599ec456]
url: https://github.com/intel-lab-lkp/linux/commits/Yong-Wang/net-bridge-multicast-re-implement-port-multicast-enable-disable-functions/20241221-060848 base: 3272040790eb4b6cafe6c30ec05049e9599ec456 patch link: https://lore.kernel.org/r/20241220220604.1430728-2-yongwang%40nvidia.com patch subject: [PATCH net-next 1/2] net: bridge: multicast: re-implement port multicast enable/disable functions config: i386-randconfig-011-20241225 (https://download.01.org/0day-ci/archive/20241225/[email protected]/config) compiler: clang version 19.1.3 (https://github.com/llvm/llvm-project ab51eccf88f5321e7c60591c5546b254b6afab99) reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20241225/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>):
In file included from net/bridge/br_multicast.c:10:
In file included from include/linux/if_ether.h:19:
In file included from include/linux/skbuff.h:17:
In file included from include/linux/bvec.h:10:
In file included from include/linux/highmem.h:8:
In file included from include/linux/cacheflush.h:5:
In file included from arch/x86/include/asm/cacheflush.h:5:
In file included from include/linux/mm.h:2223:
include/linux/vmstat.h:518:36: warning: arithmetic between different enumeration types ('enum node_stat_item' and 'enum lru_list') [-Wenum-enum-conversion]
518 | return node_stat_name(NR_LRU_BASE + lru) + 3; // skip "nr_"
| ~~~~~~~~~~~ ^ ~~~
>> net/bridge/br_multicast.c:2178:14: error: call to undeclared function 'br_vlan_state_allowed'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
2178 | if (on && br_vlan_state_allowed(br_vlan_get_state(vlan), true))
| ^
>> net/bridge/br_multicast.c:2178:36: error: call to undeclared function 'br_vlan_get_state'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
2178 | if (on && br_vlan_state_allowed(br_vlan_get_state(vlan), true))
| ^ net/bridge/br_multicast.c:2178:36: note: did you mean 'br_vlan_get_stats'? include/trace/events/../../../net/bridge/br_private.h:1792:20: note: 'br_vlan_get_stats' declared here
1792 | static inline void br_vlan_get_stats(const struct net_bridge_vlan *v,
| ^
1 warning and 2 errors generated.
vim +/br_vlan_state_allowed +2178 net/bridge/br_multicast.c
2159
2160 static void br_multicast_toggle_port(struct net_bridge_port *port, bool on)
2161 {
2162 struct net_bridge *br = port->br;
2163
2164 if (br_opt_get(br, BROPT_MCAST_VLAN_SNOOPING_ENABLED)) {
2165 struct net_bridge_vlan_group *vg;
2166 struct net_bridge_vlan *vlan;
2167
2168 rcu_read_lock();
2169 vg = nbp_vlan_group_rcu(port);
2170 if (!vg) {
2171 rcu_read_unlock();
2172 return;
2173 }
2174
2175 /* iterate each vlan of the port, toggle port_mcast_ctx per vlan */
2176 list_for_each_entry_rcu(vlan, &vg->vlan_list, vlist) {
2177 /* enable port_mcast_ctx when vlan is LEARNING or FORWARDING */
> 2178 if (on && br_vlan_state_allowed(br_vlan_get_state(vlan), true))
2179 br_multicast_enable_port_ctx(&vlan->port_mcast_ctx);
2180 else
2181 br_multicast_disable_port_ctx(&vlan->port_mcast_ctx);
2182 }
2183 rcu_read_unlock();
2184 } else {
2185 /* use the port's multicast context when vlan snooping is disabled */
2186 if (on)
2187 br_multicast_enable_port_ctx(&port->multicast_ctx);
2188 else
2189 br_multicast_disable_port_ctx(&port->multicast_ctx);
2190 }
2191 }
2192
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
PATCH 2/2 net: bridge: multicast: update multicast contex when vlan state gets changed
In reply to Yong WangUpdate br_vlan_set_state() function to enable the corresponding multicast context when vlan state gets changed. Similar to port state, vlan state could impact multicast behaviors such as igmp query. In the scenario, when bridge is running with userspace STP, vlan state could be manipulated by "bridge vlan" commands. There's the need to update the corresponding multicast context to ensure the port query timer to continue when vlan state gets changed to those "allowed" values like "forwarding" etc.
--- net/bridge/br_mst.c | 4 ++-- net/bridge/br_multicast.c | 24 ++++++++++++++++++++++++ net/bridge/br_private.h | 10 +++++++++- 3 files changed, 35 insertions(+), 3 deletions(-)
net/bridge/br_mst.c +2 -2
@@ -80,10 +80,10 @@ static void br_mst_vlan_set_state(struct net_bridge_vlan_group *vg,if (br_vlan_get_state (v) == state)return ; -br_vlan_set_state (v, state); -if (v->vid == vg->pvid)br_vlan_set_pvid_state (vg, state); + +br_vlan_set_state (v, state); } int br_mst_set_state(struct net_bridge_port *p, u16 msti, u8 state,
net/bridge/br_multicast.c +24 -0
@@ -4267,6 +4267,30 @@ static void __br_multicast_stop(struct net_bridge_mcast *brmctx)#endif } +void br_multicast_update_vlan_mcast_ctx (struct net_bridge_vlan *v,u8 state) +{ +struct net_bridge *br; + +if (!br_vlan_should_use (v)) +return ; + +if (br_vlan_is_master (v)) +return ; + + br = v->port->br; + +if (!br_opt_get (br,BROPT_MCAST_VLAN_SNOOPING_ENABLED )) +return ; + +if (br_vlan_state_allowed (state, true)) +br_multicast_enable_port_ctx (&v->port_mcast_ctx); + +/* Multicast is not disabled for the vlan when it goes in +* blocking state because the timers will expire and stop by +* themselves without sending more queries. +*/ +} +void br_multicast_toggle_one_vlan (struct net_bridge_vlan *vlan,bool on) {struct net_bridge *br;
net/bridge/br_private.h +9 -1
@@ -1052,6 +1052,7 @@ void br_multicast_port_ctx_init(struct net_bridge_port *port,struct net_bridge_vlan *vlan, struct net_bridge_mcast_port *pmctx);void br_multicast_port_ctx_deinit (struct net_bridge_mcast_port *pmctx); +void br_multicast_update_vlan_mcast_ctx (struct net_bridge_vlan *v,u8 state);void br_multicast_toggle_one_vlan (struct net_bridge_vlan *vlan,bool on);int br_multicast_toggle_vlan_snooping (struct net_bridge *br,bool on,struct netlink_ext_ack *extack);
@@ -1502,6 +1503,10 @@ static inline void br_multicast_port_ctx_deinit(struct net_bridge_mcast_port *pm { } +static inline void br_multicast_update_vlan_mcast_ctx (struct net_bridge_vlan *v,u8 state) +{ +} +static inline void br_multicast_toggle_one_vlan (struct net_bridge_vlan *vlan,bool on) {
@@ -1862,7 +1867,9 @@ bool br_vlan_global_opts_can_enter_range(const struct net_bridge_vlan *v_curr,bool br_vlan_global_opts_fill (struct sk_buff *skb,u16 vid,u16 vid_range,const struct net_bridge_vlan *v_opts); -/* vlan state manipulation helpers using *_ONCE to annotate lock-free access */ +/* vlan state manipulation helpers using *_ONCE to annotate lock-free access, +* while br_vlan_set_state() may access data protected by multicast_lock. +*/ static inline u8 br_vlan_get_state (const struct net_bridge_vlan *v) {return READ_ONCE (v->state);
@@ -1871,6 +1878,7 @@ static inline u8 br_vlan_get_state(const struct net_bridge_vlan *v)static inline void br_vlan_set_state (struct net_bridge_vlan *v,u8 state) {WRITE_ONCE (v->state, state); +br_multicast_update_vlan_mcast_ctx (v, state); }static inline u8 br_vlan_get_pvid_state (const struct net_bridge_vlan_group *vg)
Signature · 1 line
2.34.1
Nikolay Aleksandrov
maintainerQuoted 32 lines · Yong Wang
The current implementation of
br_multicast_enable_port()only operates on port's multicast context, which doesn't take into account in case of vlan snooping, one downside is the port's igmp query timer will NOT resume when port state gets changed fromBR_STATE_BLOCKINGtoBR_STATE_FORWARDINGetc.Such code flow will briefly look like:
1.vlan snooping
-->br_multicast_port_query_expiredwith per vlanport_mcast_ctx--> port inBR_STATE_BLOCKINGstate --> then one-shot timer discontinuedThe port state could be changed by STP daemon or kernel STP, taking mstpd as example:
2.mstpd -->
netlink_sendmsg-->br_setlink-->br_set_port_statewith non
blocking states, i.e.BR_STATE_LEARNINGorBR_STATE_FORWARDING-->br_port_state_selection-->br_multicast_enable_port--> enable multicast with port'smulticast_ctxHere for per vlan query, the
port_mcast_ctxof each vlan should be used instead of port'smulticast_ctx. The first patch corrects such behavior.Similarly, vlan state could also impact multicast behavior, the 2nd patch adds function to update the corresponding multicast context when vlan state changes.
Yong Wang (2):
net: bridge: multicast: re-implement port multicast enable/disable
functions
net: bridge: multicast: update multicast contex when vlan state gets
changed
Quoted 6 lines
net/bridge/br_mst.c | 4 +- net/bridge/br_multicast.c | 96 +++++++++++++++++++++++++++++++++++---- net/bridge/br_private.h | 10 +++- 3 files changed, 99 insertions(+), 11 deletions(-)
Hi,
It seems there will be another version (see kernel robot), can you please add selftests that verify the new and old behaviour?
Thanks,
Nik
Quoted 40 lines · On 12/22/24, 1:48 AM, "Nikolay Aleksandrov" <[email protected]…
Quoted 32 lines · Yong Wang
The current implementation of
br_multicast_enable_port()only operates on port's multicast context, which doesn't take into account in case of vlan snooping, one downside is the port's igmp query timer will NOT resume when port state gets changed fromBR_STATE_BLOCKINGtoBR_STATE_FORWARDINGetc.Such code flow will briefly look like:
1.vlan snooping
-->br_multicast_port_query_expiredwith per vlanport_mcast_ctx--> port inBR_STATE_BLOCKINGstate --> then one-shot timer discontinuedThe port state could be changed by STP daemon or kernel STP, taking mstpd as example:
2.mstpd -->
netlink_sendmsg-->br_setlink-->br_set_port_statewith non
blocking states, i.e.BR_STATE_LEARNINGorBR_STATE_FORWARDING-->br_port_state_selection-->br_multicast_enable_port--> enable multicast with port'smulticast_ctxHere for per vlan query, the
port_mcast_ctxof each vlan should be used instead of port'smulticast_ctx. The first patch corrects such behavior.Similarly, vlan state could also impact multicast behavior, the 2nd patch adds function to update the corresponding multicast context when vlan state changes.
Yong Wang (2):
net: bridge: multicast: re-implement port multicast enable/disable
functions
net: bridge: multicast: update multicast contex when vlan state gets
changedQuoted 6 lines
net/bridge/br_mst.c | 4 +- net/bridge/br_multicast.c | 96 +++++++++++++++++++++++++++++++++++---- net/bridge/br_private.h | 10 +++- 3 files changed, 99 insertions(+), 11 deletions(-)
Quoted 6 lines
Hi,
It seems there will be another version (see kernel robot), can you please add selftests that verify the new and old behaviour?Thanks,
Nik
Sounds good, we can work on selftests, will probably follow up after next week. Happy holidays!
Thanks,
Yong