net/dsa/switch.c
Source file repositories/reference/linux-study-clean/net/dsa/switch.c
File Facts
- System
- Linux kernel
- Corpus path
net/dsa/switch.c- Extension
.c- Size
- 26792 bytes
- Lines
- 1135
- 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.
- 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/if_vlan.hnet/switchdev.hdsa.hnetlink.hport.hswitch.htag_8021q.htrace.huser.h
Detected Declarations
function Copyrightfunction dsa_switch_ageing_timefunction dsa_port_mtu_matchfunction dsa_switch_mtufunction dsa_switch_for_each_portfunction dsa_switch_bridge_joinfunction dsa_switch_bridge_leavefunction dsa_port_host_address_matchfunction dsa_port_do_mdb_addfunction dsa_port_do_mdb_delfunction dsa_port_do_fdb_addfunction dsa_port_do_fdb_delfunction dsa_switch_do_lag_fdb_addfunction dsa_switch_do_lag_fdb_delfunction dsa_switch_host_fdb_addfunction dsa_switch_for_each_portfunction dsa_switch_host_fdb_delfunction dsa_switch_for_each_portfunction dsa_switch_fdb_addfunction dsa_switch_fdb_delfunction dsa_switch_lag_fdb_addfunction dsa_switch_lag_fdb_delfunction dsa_switch_lag_changefunction dsa_switch_lag_joinfunction dsa_switch_lag_leavefunction dsa_switch_mdb_addfunction dsa_switch_mdb_delfunction dsa_switch_host_mdb_addfunction dsa_switch_for_each_portfunction dsa_switch_host_mdb_delfunction dsa_switch_for_each_portfunction dsa_port_vlan_matchfunction dsa_port_host_vlan_matchfunction dsa_port_do_vlan_addfunction dsa_port_do_vlan_delfunction dsa_switch_vlan_addfunction dsa_switch_for_each_portfunction dsa_switch_vlan_delfunction dsa_switch_for_each_portfunction dsa_switch_host_vlan_addfunction dsa_switch_for_each_portfunction dsa_switch_host_vlan_delfunction dsa_switch_for_each_portfunction dsa_switch_change_tag_protofunction dsa_switch_connect_tag_protofunction dsa_switch_disconnect_tag_protofunction dsa_switch_conduit_state_changefunction dsa_switch_event
Annotated Snippet
if (dsa_port_mtu_match(dp, info)) {
ret = ds->ops->port_change_mtu(ds, dp->index,
info->mtu);
if (ret)
return ret;
}
}
return 0;
}
static int dsa_switch_bridge_join(struct dsa_switch *ds,
struct dsa_notifier_bridge_info *info)
{
int err;
if (info->dp->ds == ds) {
if (!ds->ops->port_bridge_join)
return -EOPNOTSUPP;
err = ds->ops->port_bridge_join(ds, info->dp->index,
info->bridge,
&info->tx_fwd_offload,
info->extack);
if (err)
return err;
}
if (info->dp->ds != ds && ds->ops->crosschip_bridge_join) {
err = ds->ops->crosschip_bridge_join(ds,
info->dp->ds->dst->index,
info->dp->ds->index,
info->dp->index,
info->bridge,
info->extack);
if (err)
return err;
}
return 0;
}
static int dsa_switch_bridge_leave(struct dsa_switch *ds,
struct dsa_notifier_bridge_info *info)
{
if (info->dp->ds == ds && ds->ops->port_bridge_leave)
ds->ops->port_bridge_leave(ds, info->dp->index, info->bridge);
if (info->dp->ds != ds && ds->ops->crosschip_bridge_leave)
ds->ops->crosschip_bridge_leave(ds, info->dp->ds->dst->index,
info->dp->ds->index,
info->dp->index,
info->bridge);
return 0;
}
/* Matches for all upstream-facing ports (the CPU port and all upstream-facing
* DSA links) that sit between the targeted port on which the notifier was
* emitted and its dedicated CPU port.
*/
static bool dsa_port_host_address_match(struct dsa_port *dp,
const struct dsa_port *targeted_dp)
{
struct dsa_port *cpu_dp = targeted_dp->cpu_dp;
if (dsa_switch_is_upstream_of(dp->ds, targeted_dp->ds))
return dp->index == dsa_towards_port(dp->ds, cpu_dp->ds->index,
cpu_dp->index);
return false;
}
static struct dsa_mac_addr *dsa_mac_addr_find(struct list_head *addr_list,
const unsigned char *addr, u16 vid,
struct dsa_db db)
{
struct dsa_mac_addr *a;
list_for_each_entry(a, addr_list, list)
if (ether_addr_equal(a->addr, addr) && a->vid == vid &&
dsa_db_equal(&a->db, &db))
return a;
return NULL;
}
static int dsa_port_do_mdb_add(struct dsa_port *dp,
const struct switchdev_obj_port_mdb *mdb,
struct dsa_db db)
Annotation
- Immediate include surface: `linux/if_bridge.h`, `linux/netdevice.h`, `linux/notifier.h`, `linux/if_vlan.h`, `net/switchdev.h`, `dsa.h`, `netlink.h`, `port.h`.
- Detected declarations: `function Copyright`, `function dsa_switch_ageing_time`, `function dsa_port_mtu_match`, `function dsa_switch_mtu`, `function dsa_switch_for_each_port`, `function dsa_switch_bridge_join`, `function dsa_switch_bridge_leave`, `function dsa_port_host_address_match`, `function dsa_port_do_mdb_add`, `function dsa_port_do_mdb_del`.
- 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.