net/bridge/br_stp_if.c
Source file repositories/reference/linux-study-clean/net/bridge/br_stp_if.c
File Facts
- System
- Linux kernel
- Corpus path
net/bridge/br_stp_if.c- Extension
.c- Size
- 8961 bytes
- Lines
- 357
- Domain
- Networking Core
- Bucket
- Sockets, Protocols, Packet Path, And Network Policy
- Inferred role
- Networking Core: implementation source
- Status
- source 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.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/kernel.hlinux/kmod.hlinux/etherdevice.hlinux/rtnetlink.hnet/switchdev.hbr_private.hbr_private_stp.h
Detected Declarations
function br_make_port_idfunction br_init_portfunction br_stp_enable_bridgefunction list_for_each_entryfunction br_stp_disable_bridgefunction br_stp_enable_portfunction br_stp_disable_portfunction br_stp_call_userfunction br_stp_startfunction br_stp_stopfunction br_stp_set_enabledfunction br_stp_change_bridge_idfunction list_for_each_entryfunction br_stp_recalculate_bridge_idfunction list_for_each_entryfunction br_stp_set_bridge_priorityfunction list_for_each_entryfunction br_stp_set_port_priorityfunction br_stp_set_path_costfunction br_show_bridge_id
Annotated Snippet
if (br->stp_helper_active) {
int err = br_stp_call_user(br, "stop");
if (err)
br_err(br, "failed to stop userspace STP (%d)\n", err);
br->stp_helper_active = false;
}
/* To start timers on any ports left in blocking */
spin_lock_bh(&br->lock);
br_port_state_selection(br);
spin_unlock_bh(&br->lock);
}
br->stp_enabled = BR_NO_STP;
}
int br_stp_set_enabled(struct net_bridge *br, unsigned long val,
struct netlink_ext_ack *extack)
{
ASSERT_RTNL();
if (br_mrp_enabled(br)) {
NL_SET_ERR_MSG_MOD(extack,
"STP can't be enabled if MRP is already enabled");
return -EINVAL;
}
if (val) {
if (br->stp_enabled == BR_NO_STP)
br_stp_start(br);
} else {
if (br->stp_enabled != BR_NO_STP)
br_stp_stop(br);
}
return 0;
}
/* called under bridge lock */
void br_stp_change_bridge_id(struct net_bridge *br, const unsigned char *addr)
{
/* should be aligned on 2 bytes for ether_addr_equal() */
unsigned short oldaddr_aligned[ETH_ALEN >> 1];
unsigned char *oldaddr = (unsigned char *)oldaddr_aligned;
struct net_bridge_port *p;
int wasroot;
wasroot = br_is_root_bridge(br);
br_fdb_change_mac_address(br, addr);
memcpy(oldaddr, br->bridge_id.addr, ETH_ALEN);
memcpy(br->bridge_id.addr, addr, ETH_ALEN);
eth_hw_addr_set(br->dev, addr);
list_for_each_entry(p, &br->port_list, list) {
if (ether_addr_equal(p->designated_bridge.addr, oldaddr))
memcpy(p->designated_bridge.addr, addr, ETH_ALEN);
if (ether_addr_equal(p->designated_root.addr, oldaddr))
memcpy(p->designated_root.addr, addr, ETH_ALEN);
}
br_configuration_update(br);
br_port_state_selection(br);
if (br_is_root_bridge(br) && !wasroot)
br_become_root_bridge(br);
}
/* should be aligned on 2 bytes for ether_addr_equal() */
static const unsigned short br_mac_zero_aligned[ETH_ALEN >> 1];
/* called under bridge lock */
bool br_stp_recalculate_bridge_id(struct net_bridge *br)
{
const unsigned char *br_mac_zero =
(const unsigned char *)br_mac_zero_aligned;
const unsigned char *addr = br_mac_zero;
struct net_bridge_port *p;
/* user has chosen a value so keep it */
if (br->dev->addr_assign_type == NET_ADDR_SET)
return false;
list_for_each_entry(p, &br->port_list, list) {
if (addr == br_mac_zero ||
memcmp(p->dev->dev_addr, addr, ETH_ALEN) < 0)
addr = p->dev->dev_addr;
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/kmod.h`, `linux/etherdevice.h`, `linux/rtnetlink.h`, `net/switchdev.h`, `br_private.h`, `br_private_stp.h`.
- Detected declarations: `function br_make_port_id`, `function br_init_port`, `function br_stp_enable_bridge`, `function list_for_each_entry`, `function br_stp_disable_bridge`, `function br_stp_enable_port`, `function br_stp_disable_port`, `function br_stp_call_user`, `function br_stp_start`, `function br_stp_stop`.
- Atlas domain: Networking Core / Sockets, Protocols, Packet Path, And Network Policy.
- Implementation status: source 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.