net/bridge/br_if.c
Source file repositories/reference/linux-study-clean/net/bridge/br_if.c
File Facts
- System
- Linux kernel
- Corpus path
net/bridge/br_if.c- Extension
.c- Size
- 17756 bytes
- Lines
- 767
- 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/kernel.hlinux/netdevice.hlinux/etherdevice.hlinux/netpoll.hlinux/ethtool.hlinux/if_arp.hlinux/module.hlinux/init.hlinux/rtnetlink.hlinux/if_ether.hlinux/slab.hnet/dsa.hnet/netdev_lock.hnet/sock.hlinux/if_vlan.hnet/switchdev.hnet/net_namespace.hbr_private.h
Detected Declarations
function port_costfunction br_port_carrier_checkfunction br_port_set_promiscfunction br_port_clear_promiscfunction br_manage_promiscfunction list_for_each_entryfunction nbp_backup_changefunction nbp_backup_clearfunction list_for_each_entryfunction nbp_update_port_countfunction list_for_each_entryfunction nbp_delete_promiscfunction release_nbpfunction brport_get_ownershipfunction destroy_nbpfunction destroy_nbp_rcufunction get_max_headroomfunction list_for_each_entryfunction update_headroomfunction del_nbpfunction br_dev_deletefunction list_for_each_entry_safefunction find_portnofunction br_add_bridgefunction br_del_bridgefunction br_mtu_minfunction br_mtu_auto_adjustfunction br_features_recomputefunction list_for_each_entryfunction br_add_iffunction br_del_iffunction br_port_flags_changefunction br_port_flag_is_setexport br_port_flag_is_set
Annotated Snippet
switch (ecmd.base.speed) {
case SPEED_10000:
return 2;
case SPEED_5000:
return 3;
case SPEED_2500:
return 4;
case SPEED_1000:
return 5;
case SPEED_100:
return 19;
case SPEED_10:
return 100;
case SPEED_UNKNOWN:
return 100;
default:
if (ecmd.base.speed > SPEED_10000)
return 1;
}
}
/* Old silly heuristics based on name */
if (!strncmp(dev->name, "lec", 3))
return 7;
if (!strncmp(dev->name, "plip", 4))
return 2500;
return 100; /* assume old 10Mbps */
}
/* Check for port carrier transitions. */
void br_port_carrier_check(struct net_bridge_port *p, bool *notified)
{
struct net_device *dev = p->dev;
struct net_bridge *br = p->br;
if (!test_bit(BR_ADMIN_COST_BIT, &p->flags) &&
netif_running(dev) && netif_oper_up(dev))
WRITE_ONCE(p->path_cost, port_cost(dev));
*notified = false;
if (!netif_running(br->dev))
return;
spin_lock_bh(&br->lock);
if (netif_running(dev) && netif_oper_up(dev)) {
if (p->state == BR_STATE_DISABLED) {
br_stp_enable_port(p);
*notified = true;
}
} else {
if (p->state != BR_STATE_DISABLED) {
br_stp_disable_port(p);
*notified = true;
}
}
spin_unlock_bh(&br->lock);
}
static void br_port_set_promisc(struct net_bridge_port *p)
{
int err = 0;
if (br_promisc_port(p))
return;
err = dev_set_promiscuity(p->dev, 1);
if (err)
return;
br_fdb_unsync_static(p->br, p);
set_bit(BR_PROMISC_BIT, &p->flags);
}
static void br_port_clear_promisc(struct net_bridge_port *p)
{
int err;
/* Check if the port is already non-promisc or if it doesn't
* support UNICAST filtering. Without unicast filtering support
* we'll end up re-enabling promisc mode anyway, so just check for
* it here.
*/
if (!br_promisc_port(p) || !(p->dev->priv_flags & IFF_UNICAST_FLT))
return;
/* Since we'll be clearing the promisc mode, program the port
* first so that we don't have interruption in traffic.
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/netdevice.h`, `linux/etherdevice.h`, `linux/netpoll.h`, `linux/ethtool.h`, `linux/if_arp.h`, `linux/module.h`, `linux/init.h`.
- Detected declarations: `function port_cost`, `function br_port_carrier_check`, `function br_port_set_promisc`, `function br_port_clear_promisc`, `function br_manage_promisc`, `function list_for_each_entry`, `function nbp_backup_change`, `function nbp_backup_clear`, `function list_for_each_entry`, `function nbp_update_port_count`.
- 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.