net/bridge/br_sysfs_if.c
Source file repositories/reference/linux-study-clean/net/bridge/br_sysfs_if.c
File Facts
- System
- Linux kernel
- Corpus path
net/bridge/br_sysfs_if.c- Extension
.c- Size
- 11458 bytes
- Lines
- 431
- 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.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/capability.hlinux/kernel.hlinux/netdevice.hlinux/if_bridge.hlinux/rtnetlink.hlinux/spinlock.hlinux/sched/signal.hbr_private.h
Detected Declarations
struct brport_attributefunction BRPORT_ATTRfunction show_path_costfunction store_path_costfunction show_priorityfunction store_priorityfunction show_designated_rootfunction show_designated_bridgefunction show_designated_portfunction show_designated_costfunction show_port_idfunction show_port_nofunction show_change_ackfunction show_config_pendingfunction show_port_statefunction show_message_age_timerfunction show_forward_delay_timerfunction show_hold_timerfunction store_flushfunction show_group_fwd_maskfunction store_group_fwd_maskfunction show_backup_portfunction store_backup_portfunction show_multicast_routerfunction store_multicast_routerfunction brport_showfunction brport_storefunction br_sysfs_addiffunction br_sysfs_renameif
Annotated Snippet
struct brport_attribute {
struct attribute attr;
ssize_t (*show)(struct net_bridge_port *, char *);
int (*store)(struct net_bridge_port *, unsigned long);
int (*store_raw)(struct net_bridge_port *, char *);
};
#define BRPORT_ATTR_RAW(_name, _mode, _show, _store) \
const struct brport_attribute brport_attr_##_name = { \
.attr = {.name = __stringify(_name), \
.mode = _mode }, \
.show = _show, \
.store_raw = _store, \
};
#define BRPORT_ATTR(_name, _mode, _show, _store) \
const struct brport_attribute brport_attr_##_name = { \
.attr = {.name = __stringify(_name), \
.mode = _mode }, \
.show = _show, \
.store = _store, \
};
#define BRPORT_ATTR_FLAG(_name, _bitnr) \
static ssize_t show_##_name(struct net_bridge_port *p, char *buf) \
{ \
return sysfs_emit(buf, "%d\n", test_bit(_bitnr, &p->flags)); \
} \
static int store_##_name(struct net_bridge_port *p, unsigned long v) \
{ \
return store_flag(p, v, _bitnr); \
} \
static BRPORT_ATTR(_name, 0644, \
show_##_name, store_##_name)
static int store_flag(struct net_bridge_port *p, unsigned long v,
unsigned long bitnr)
{
unsigned long oflags, flags = READ_ONCE(p->flags);
struct netlink_ext_ack extack = {0};
int err;
oflags = flags;
if (v)
__set_bit(bitnr, &flags);
else
__clear_bit(bitnr, &flags);
if (flags == oflags)
return 0;
err = br_switchdev_set_port_flag(p, flags, BIT(bitnr), &extack);
if (err) {
netdev_err(p->dev, "%s\n", extack._msg);
return err;
}
if (v)
set_bit(bitnr, &p->flags);
else
clear_bit(bitnr, &p->flags);
br_port_flags_change(p, BIT(bitnr));
return 0;
}
static ssize_t show_path_cost(struct net_bridge_port *p, char *buf)
{
return sysfs_emit(buf, "%d\n", READ_ONCE(p->path_cost));
}
static int store_path_cost(struct net_bridge_port *p, unsigned long v)
{
int ret;
spin_lock_bh(&p->br->lock);
ret = br_stp_set_path_cost(p, v);
spin_unlock_bh(&p->br->lock);
return ret;
}
static BRPORT_ATTR(path_cost, 0644, show_path_cost, store_path_cost);
static ssize_t show_priority(struct net_bridge_port *p, char *buf)
{
return sysfs_emit(buf, "%d\n", READ_ONCE(p->priority));
}
static int store_priority(struct net_bridge_port *p, unsigned long v)
{
int ret;
Annotation
- Immediate include surface: `linux/capability.h`, `linux/kernel.h`, `linux/netdevice.h`, `linux/if_bridge.h`, `linux/rtnetlink.h`, `linux/spinlock.h`, `linux/sched/signal.h`, `br_private.h`.
- Detected declarations: `struct brport_attribute`, `function BRPORT_ATTR`, `function show_path_cost`, `function store_path_cost`, `function show_priority`, `function store_priority`, `function show_designated_root`, `function show_designated_bridge`, `function show_designated_port`, `function show_designated_cost`.
- 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.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
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.