net/dsa/port.c
Source file repositories/reference/linux-study-clean/net/dsa/port.c
File Facts
- System
- Linux kernel
- Corpus path
net/dsa/port.c- Extension
.c- Size
- 47751 bytes
- Lines
- 1956
- 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/if_bridge.hlinux/netdevice.hlinux/notifier.hlinux/of_mdio.hlinux/of_net.hdsa.hport.hswitch.htag_8021q.huser.h
Detected Declarations
function Copyrightfunction dsa_port_notify_bridge_fdb_flushfunction dsa_port_fast_agefunction dsa_port_vlan_fast_agefunction dsa_port_msti_fast_agefunction for_each_set_bitfunction dsa_port_can_configure_learningfunction dsa_port_supports_hwtstampfunction dsa_port_set_statefunction dsa_port_set_state_nowfunction dsa_port_set_mst_statefunction dsa_port_enable_rtfunction dsa_port_enablefunction dsa_port_disable_rtfunction dsa_port_disablefunction dsa_port_reset_vlan_filteringfunction br_vlan_enabledfunction dsa_switch_for_each_portfunction dsa_port_inherit_brport_flagsfunction for_each_set_bitfunction dsa_port_clear_brport_flagsfunction for_each_set_bitfunction dsa_port_switchdev_sync_attrsfunction dsa_port_switchdev_unsync_attrsfunction reasonfunction dsa_port_bridge_destroyfunction dsa_port_supports_mstfunction dsa_port_bridge_joinfunction dsa_port_pre_bridge_leavefunction dsa_port_bridge_leavefunction dsa_port_lag_changefunction dsa_port_lag_createfunction dsa_port_lag_destroyfunction dsa_port_lag_joinfunction dsa_port_pre_lag_leavefunction dsa_port_lag_leavefunction dsa_port_can_apply_vlan_filteringfunction netdev_for_each_upper_dev_rcufunction dsa_port_vlan_filteringfunction dsa_switch_for_each_user_portfunction dsa_port_skip_vlan_configurationfunction dsa_port_ageing_timefunction dsa_port_mst_enablefunction dsa_port_pre_bridge_flagsfunction dsa_port_bridge_flagsfunction dsa_port_set_host_floodfunction dsa_port_vlan_mstifunction dsa_port_mtu_change
Annotated Snippet
br_vlan_enabled(bridge.dev)) {
change_vlan_filtering = true;
vlan_filtering = false;
}
/* If the bridge was vlan_filtering, the bridge core doesn't trigger an
* event for changing vlan_filtering setting upon user ports leaving
* it. That is a good thing, because that lets us handle it and also
* handle the case where the switch's vlan_filtering setting is global
* (not per port). When that happens, the correct moment to trigger the
* vlan_filtering callback is only when the last port leaves the last
* VLAN-aware bridge.
*/
if (change_vlan_filtering && ds->vlan_filtering_is_global) {
dsa_switch_for_each_port(other_dp, ds) {
struct net_device *br = dsa_port_bridge_dev_get(other_dp);
if (br && br_vlan_enabled(br)) {
change_vlan_filtering = false;
break;
}
}
}
if (!change_vlan_filtering)
return;
err = dsa_port_vlan_filtering(dp, vlan_filtering, &extack);
if (extack._msg) {
dev_err(ds->dev, "port %d: %s\n", dp->index,
extack._msg);
}
if (err && err != -EOPNOTSUPP) {
dev_err(ds->dev,
"port %d failed to reset VLAN filtering to %d: %pe\n",
dp->index, vlan_filtering, ERR_PTR(err));
}
}
static int dsa_port_inherit_brport_flags(struct dsa_port *dp,
struct netlink_ext_ack *extack)
{
const unsigned long mask = BR_LEARNING | BR_FLOOD | BR_MCAST_FLOOD |
BR_BCAST_FLOOD | BR_PORT_LOCKED;
struct net_device *brport_dev = dsa_port_to_bridge_port(dp);
int flag, err;
for_each_set_bit(flag, &mask, 32) {
struct switchdev_brport_flags flags = {0};
flags.mask = BIT(flag);
if (br_port_flag_is_set(brport_dev, BIT(flag)))
flags.val = BIT(flag);
err = dsa_port_bridge_flags(dp, flags, extack);
if (err && err != -EOPNOTSUPP)
return err;
}
return 0;
}
static void dsa_port_clear_brport_flags(struct dsa_port *dp)
{
const unsigned long val = BR_FLOOD | BR_MCAST_FLOOD | BR_BCAST_FLOOD;
const unsigned long mask = BR_LEARNING | BR_FLOOD | BR_MCAST_FLOOD |
BR_BCAST_FLOOD | BR_PORT_LOCKED;
int flag, err;
for_each_set_bit(flag, &mask, 32) {
struct switchdev_brport_flags flags = {0};
flags.mask = BIT(flag);
flags.val = val & BIT(flag);
err = dsa_port_bridge_flags(dp, flags, NULL);
if (err && err != -EOPNOTSUPP)
dev_err(dp->ds->dev,
"failed to clear bridge port flag %lu: %pe\n",
flags.val, ERR_PTR(err));
}
}
static int dsa_port_switchdev_sync_attrs(struct dsa_port *dp,
struct netlink_ext_ack *extack)
{
struct net_device *brport_dev = dsa_port_to_bridge_port(dp);
struct net_device *br = dsa_port_bridge_dev_get(dp);
int err;
Annotation
- Immediate include surface: `linux/if_bridge.h`, `linux/netdevice.h`, `linux/notifier.h`, `linux/of_mdio.h`, `linux/of_net.h`, `dsa.h`, `port.h`, `switch.h`.
- Detected declarations: `function Copyright`, `function dsa_port_notify_bridge_fdb_flush`, `function dsa_port_fast_age`, `function dsa_port_vlan_fast_age`, `function dsa_port_msti_fast_age`, `function for_each_set_bit`, `function dsa_port_can_configure_learning`, `function dsa_port_supports_hwtstamp`, `function dsa_port_set_state`, `function dsa_port_set_state_now`.
- 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.