Return the multicast port context when decoding a router-list node and pass its VLAN entry to the forwarding destination. With per-VLAN snooping, the context already identifies the egress port VLAN, so validation and tagging can use it directly. A per-VLAN router context is selected through the resolved ingress VLAN. Global router contexts have no VLAN pointer and resolve their VLAN during egress validation. During port VLAN deletion, a per-VLAN router context can remain on the router list after the VLAN has been unpublished. Forwarding can therefore still use its cached VLAN until router-list removal, whereas a fresh VLAN lookup would reject it. This is transient forwarding during teardown, consistent with the existing cached FDB destination behavior. RCU protects the VLAN's lifetime, and context cleanup removes it from the router lists. Signed-off-by: Nikolay Aleksandrov --- local Sashiko review says: [Severity: Medium] Can this forward multicast through a port VLAN after it is unpublished? CPU0 CPU1 nbp_vlan_delete() __vlan_unpublish(vg, v) br_multicast_flood() fwd.vlan = rpmctx->vlan should_deliver_vlan() br_handle_vlan() <-- forwards on removed VLAN br_multicast_port_ctx_deinit(...) Nik: this is already documented, it can forward for a short-while until ctx_deinit is called which is fine CC: Ido Schimmel CC: David S. Miller CC: Eric Dumazet CC: Jakub Kicinski CC: Paolo Abeni CC: Simon Horman CC: bridge@lists.linux.dev net/bridge/br_forward.c | 5 ++++- net/bridge/br_private.h | 19 +++++-------------- 2 files changed, 9 insertions(+), 15 deletions(-) diff --git a/net/bridge/br_forward.c b/net/bridge/br_forward.c index 54365c6104b5..b725e8f1b29a 100644 --- a/net/bridge/br_forward.c +++ b/net/bridge/br_forward.c @@ -412,10 +412,12 @@ void br_multicast_flood(struct net_bridge_mdb_entry *mdst, while (p || rp) { struct net_bridge_port *port, *lport, *rport; + struct net_bridge_mcast_port *rpmctx; struct br_fwd_dst fwd = {}; lport = p ? p->key.port : NULL; - rport = br_multicast_rport_from_node_skb(rp, skb); + rpmctx = br_multicast_rport_ctx_from_node_skb(rp, skb); + rport = rpmctx ? rpmctx->port : NULL; if ((unsigned long)lport > (unsigned long)rport) { port = lport; @@ -432,6 +434,7 @@ void br_multicast_flood(struct net_bridge_mdb_entry *mdst, goto delivered; } else { port = rport; + fwd.vlan = rpmctx->vlan; } fwd.port = port; diff --git a/net/bridge/br_private.h b/net/bridge/br_private.h index 014d0b8db8c7..20e423e22132 100644 --- a/net/bridge/br_private.h +++ b/net/bridge/br_private.h @@ -1244,24 +1244,15 @@ br_multicast_get_first_rport_node(struct net_bridge_mcast *brmctx, return rcu_dereference(hlist_first_rcu(&brmctx->ip4_mc_router_list)); } -static inline struct net_bridge_port * -br_multicast_rport_from_node_skb(struct hlist_node *rp, struct sk_buff *skb) +static inline struct net_bridge_mcast_port * +br_multicast_rport_ctx_from_node_skb(struct hlist_node *rp, struct sk_buff *skb) { - struct net_bridge_mcast_port *mctx; - #if IS_ENABLED(CONFIG_IPV6) if (skb->protocol == htons(ETH_P_IPV6)) - mctx = hlist_entry_safe(rp, struct net_bridge_mcast_port, - ip6_rlist); - else + return hlist_entry_safe(rp, struct net_bridge_mcast_port, + ip6_rlist); #endif - mctx = hlist_entry_safe(rp, struct net_bridge_mcast_port, - ip4_rlist); - - if (mctx) - return mctx->port; - else - return NULL; + return hlist_entry_safe(rp, struct net_bridge_mcast_port, ip4_rlist); } static inline bool br_ip4_multicast_is_router(struct net_bridge_mcast *brmctx) -- 2.47.3