net/switchdev/switchdev.c
Source file repositories/reference/linux-study-clean/net/switchdev/switchdev.c
File Facts
- System
- Linux kernel
- Corpus path
net/switchdev/switchdev.c- Extension
.c- Size
- 32048 bytes
- Lines
- 1065
- 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/types.hlinux/init.hlinux/mutex.hlinux/notifier.hlinux/netdevice.hlinux/etherdevice.hlinux/if_bridge.hlinux/list.hlinux/workqueue.hlinux/if_vlan.hlinux/rtnetlink.hnet/switchdev.h
Detected Declarations
struct switchdev_deferred_itemstruct switchdev_nested_privfunction Copyrightfunction switchdev_deferred_processfunction switchdev_deferred_process_workfunction switchdev_deferred_enqueuefunction switchdev_port_attr_notifyfunction switchdev_port_attr_set_nowfunction switchdev_port_attr_set_deferredfunction switchdev_port_attr_set_deferfunction switchdev_port_attr_setfunction switchdev_obj_sizefunction switchdev_port_obj_notifyfunction switchdev_obj_id_to_helpful_msgfunction switchdev_port_obj_add_deferredfunction switchdev_port_obj_add_deferfunction switchdev_port_obj_addfunction switchdev_port_obj_del_nowfunction switchdev_port_obj_del_deferredfunction switchdev_port_obj_del_deferfunction switchdev_port_obj_delfunction switchdev_port_obj_act_is_deferredfunction list_for_each_entryfunction register_switchdev_notifierfunction unregister_switchdev_notifierfunction call_switchdev_notifiersfunction register_switchdev_blocking_notifierfunction unregister_switchdev_blocking_notifierfunction call_switchdev_blocking_notifiersfunction switchdev_lower_dev_walkfunction switchdev_lower_dev_find_rcufunction switchdev_lower_dev_findfunction __switchdev_handle_fdb_event_to_devicefunction switchdev_handle_fdb_event_to_devicefunction __switchdev_handle_port_obj_addfunction switchdev_handle_port_obj_addfunction switchdev_handle_port_obj_add_foreignfunction __switchdev_handle_port_obj_delfunction switchdev_handle_port_obj_delfunction switchdev_handle_port_obj_del_foreignfunction __switchdev_handle_port_attr_setfunction switchdev_handle_port_attr_setfunction switchdev_bridge_port_offloadfunction switchdev_bridge_port_unoffloadfunction switchdev_bridge_port_replayexport switchdev_deferred_processexport switchdev_port_attr_setexport switchdev_port_obj_add
Annotated Snippet
struct switchdev_deferred_item {
struct list_head list;
struct net_device *dev;
netdevice_tracker dev_tracker;
switchdev_deferred_func_t *func;
unsigned long data[];
};
static struct switchdev_deferred_item *switchdev_deferred_dequeue(void)
{
struct switchdev_deferred_item *dfitem;
spin_lock_bh(&deferred_lock);
if (list_empty(&deferred)) {
dfitem = NULL;
goto unlock;
}
dfitem = list_first_entry(&deferred,
struct switchdev_deferred_item, list);
list_del(&dfitem->list);
unlock:
spin_unlock_bh(&deferred_lock);
return dfitem;
}
/**
* switchdev_deferred_process - Process ops in deferred queue
*
* Called to flush the ops currently queued in deferred ops queue.
* rtnl_lock must be held.
*/
void switchdev_deferred_process(void)
{
struct switchdev_deferred_item *dfitem;
ASSERT_RTNL();
while ((dfitem = switchdev_deferred_dequeue())) {
dfitem->func(dfitem->dev, dfitem->data);
netdev_put(dfitem->dev, &dfitem->dev_tracker);
kfree(dfitem);
}
}
EXPORT_SYMBOL_GPL(switchdev_deferred_process);
static void switchdev_deferred_process_work(struct work_struct *work)
{
rtnl_lock();
switchdev_deferred_process();
rtnl_unlock();
}
static DECLARE_WORK(deferred_process_work, switchdev_deferred_process_work);
static int switchdev_deferred_enqueue(struct net_device *dev,
const void *data, size_t data_len,
switchdev_deferred_func_t *func)
{
struct switchdev_deferred_item *dfitem;
dfitem = kmalloc_flex(*dfitem, data, data_len, GFP_ATOMIC);
if (!dfitem)
return -ENOMEM;
dfitem->dev = dev;
dfitem->func = func;
memcpy(dfitem->data, data, data_len);
netdev_hold(dev, &dfitem->dev_tracker, GFP_ATOMIC);
spin_lock_bh(&deferred_lock);
list_add_tail(&dfitem->list, &deferred);
spin_unlock_bh(&deferred_lock);
schedule_work(&deferred_process_work);
return 0;
}
static int switchdev_port_attr_notify(enum switchdev_notifier_type nt,
struct net_device *dev,
const struct switchdev_attr *attr,
struct netlink_ext_ack *extack)
{
int err;
int rc;
struct switchdev_notifier_port_attr_info attr_info = {
.attr = attr,
.handled = false,
};
rc = call_switchdev_blocking_notifiers(nt, dev,
&attr_info.info, extack);
err = notifier_to_errno(rc);
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/types.h`, `linux/init.h`, `linux/mutex.h`, `linux/notifier.h`, `linux/netdevice.h`, `linux/etherdevice.h`, `linux/if_bridge.h`.
- Detected declarations: `struct switchdev_deferred_item`, `struct switchdev_nested_priv`, `function Copyright`, `function switchdev_deferred_process`, `function switchdev_deferred_process_work`, `function switchdev_deferred_enqueue`, `function switchdev_port_attr_notify`, `function switchdev_port_attr_set_now`, `function switchdev_port_attr_set_deferred`, `function switchdev_port_attr_set_defer`.
- 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.