net/bridge/br_multicast.c
Source file repositories/reference/linux-study-clean/net/bridge/br_multicast.c
File Facts
- System
- Linux kernel
- Corpus path
net/bridge/br_multicast.c- Extension
.c- Size
- 142196 bytes
- Lines
- 5250
- Domain
- Networking Core
- Bucket
- Sockets, Protocols, Packet Path, And Network Policy
- Inferred role
- Networking Core: exported/initcall integration point
- Status
- integration implementation candidate
Why This File Exists
Networking stack implementation surface: socket APIs, protocol dispatch, packet flow, routing, filtering, and network namespaces.
- Networking stack implementation surface: socket APIs, protocol dispatch, packet flow, routing, filtering, and network namespaces.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/err.hlinux/export.hlinux/if_ether.hlinux/igmp.hlinux/in.hlinux/jhash.hlinux/kernel.hlinux/log2.hlinux/netdevice.hlinux/netfilter_bridge.hlinux/random.hlinux/rculist.hlinux/skbuff.hlinux/slab.hlinux/timer.hlinux/inetdevice.hlinux/mroute.hnet/ip.hnet/switchdev.hlinux/icmpv6.hnet/ipv6.hnet/mld.hnet/ip6_checksum.hnet/addrconf.htrace/events/bridge.hbr_private.hbr_private_mcast_eht.h
Detected Declarations
function br_sg_port_findfunction br_mdb_entry_skb_getfunction downfunction br_multicast_port_vid_to_port_ctxfunction br_multicast_ctx_should_usefunction br_port_group_equalfunction __fwd_add_star_exclfunction __fwd_del_star_exclfunction beforefunction hlist_for_each_entryfunction br_multicast_sg_host_statefunction br_multicast_star_g_host_statefunction hlist_for_each_entryfunction br_multicast_sg_del_exclude_portsfunction br_multicast_sg_add_exclude_portsfunction br_multicast_fwd_src_addfunction br_multicast_fwd_src_removefunction br_multicast_fwd_src_handlefunction br_multicast_destroy_mdb_entryfunction br_multicast_del_mdb_entryfunction br_multicast_group_expiredfunction br_multicast_destroy_group_srcfunction __br_multicast_del_group_srcfunction br_multicast_del_group_srcfunction br_multicast_port_ngroups_inc_onefunction br_multicast_port_ngroups_dec_onefunction br_multicast_port_ngroups_incfunction br_multicast_port_ngroups_decfunction br_multicast_ngroups_getfunction br_multicast_ngroups_set_maxfunction br_multicast_ngroups_get_maxfunction br_multicast_destroy_port_groupfunction br_multicast_del_pgfunction br_multicast_find_del_pgfunction br_multicast_port_group_expiredfunction br_multicast_gcfunction hlist_for_each_entry_safefunction __br_multicast_query_handle_vlanfunction hlist_for_each_entryfunction hlist_for_each_entryfunction hlist_for_each_entryfunction hlist_for_each_entryfunction br_multicast_group_src_expiredfunction br_multicast_find_group_srcfunction br_multicast_new_group_srcfunction br_multicast_del_port_groupfunction br_multicast_host_joinfunction br_multicast_host_leave
Annotated Snippet
if (brmctx->multicast_igmp_version == 3) {
struct net_bridge_mdb_entry *mdb;
ip.src.ip4 = ip_hdr(skb)->saddr;
mdb = br_mdb_ip_get_rcu(br, &ip);
if (mdb)
return mdb;
ip.src.ip4 = 0;
}
break;
#if IS_ENABLED(CONFIG_IPV6)
case htons(ETH_P_IPV6):
ip.dst.ip6 = ipv6_hdr(skb)->daddr;
if (brmctx->multicast_mld_version == 2) {
struct net_bridge_mdb_entry *mdb;
ip.src.ip6 = ipv6_hdr(skb)->saddr;
mdb = br_mdb_ip_get_rcu(br, &ip);
if (mdb)
return mdb;
memset(&ip.src.ip6, 0, sizeof(ip.src.ip6));
}
break;
#endif
default:
ip.proto = 0;
ether_addr_copy(ip.dst.mac_addr, eth_hdr(skb)->h_dest);
}
return br_mdb_ip_get_rcu(br, &ip);
}
/* IMPORTANT: this function must be used only when the contexts cannot be
* passed down (e.g. timer) and must be used for read-only purposes because
* the vlan snooping option can change, so it can return any context
* (non-vlan or vlan). Its initial intended purpose is to read timer values
* from the *current* context based on the option. At worst that could lead
* to inconsistent timers when the contexts are changed, i.e. src timer
* which needs to re-arm with a specific delay taken from the old context
*/
static struct net_bridge_mcast_port *
br_multicast_pg_to_port_ctx(const struct net_bridge_port_group *pg)
{
struct net_bridge_mcast_port *pmctx = &pg->key.port->multicast_ctx;
struct net_bridge_vlan *vlan;
lockdep_assert_held_once(&pg->key.port->br->multicast_lock);
/* if vlan snooping is disabled use the port's multicast context */
if (!pg->key.addr.vid ||
!br_opt_get(pg->key.port->br, BROPT_MCAST_VLAN_SNOOPING_ENABLED))
goto out;
/* locking is tricky here, due to different rules for multicast and
* vlans we need to take rcu to find the vlan and make sure it has
* the BR_VLFLAG_MCAST_ENABLED flag set, it can only change under
* multicast_lock which must be already held here, so the vlan's pmctx
* can safely be used on return
*/
rcu_read_lock();
vlan = br_vlan_find(nbp_vlan_group_rcu(pg->key.port), pg->key.addr.vid);
if (vlan && !br_multicast_port_ctx_vlan_disabled(&vlan->port_mcast_ctx))
pmctx = &vlan->port_mcast_ctx;
else
pmctx = NULL;
rcu_read_unlock();
out:
return pmctx;
}
static struct net_bridge_mcast_port *
br_multicast_port_vid_to_port_ctx(struct net_bridge_port *port, u16 vid)
{
struct net_bridge_mcast_port *pmctx = NULL;
struct net_bridge_vlan *vlan;
lockdep_assert_held_once(&port->br->multicast_lock);
/* Take RCU to access the vlan. */
rcu_read_lock();
vlan = br_vlan_find(nbp_vlan_group_rcu(port), vid);
if (vlan)
pmctx = &vlan->port_mcast_ctx;
rcu_read_unlock();
return pmctx;
}
Annotation
- Immediate include surface: `linux/err.h`, `linux/export.h`, `linux/if_ether.h`, `linux/igmp.h`, `linux/in.h`, `linux/jhash.h`, `linux/kernel.h`, `linux/log2.h`.
- Detected declarations: `function br_sg_port_find`, `function br_mdb_entry_skb_get`, `function down`, `function br_multicast_port_vid_to_port_ctx`, `function br_multicast_ctx_should_use`, `function br_port_group_equal`, `function __fwd_add_star_excl`, `function __fwd_del_star_excl`, `function before`, `function hlist_for_each_entry`.
- Atlas domain: Networking Core / Sockets, Protocols, Packet Path, And Network Policy.
- Implementation status: integration implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.