net/core/dev.c
Source file repositories/reference/linux-study-clean/net/core/dev.c
File Facts
- System
- Linux kernel
- Corpus path
net/core/dev.c- Extension
.c- Size
- 346929 bytes
- Lines
- 13333
- Domain
- Networking Core
- Bucket
- Sockets, Protocols, Packet Path, And Network Policy
- Inferred role
- Networking Core: operation-table or driver-model contract
- Status
- pattern 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.
- Defines an operation table; this is where Linux turns generic core objects into subsystem-specific behavior.
- 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.
- 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/uaccess.hlinux/bitmap.hlinux/capability.hlinux/cpu.hlinux/types.hlinux/kernel.hlinux/hash.hlinux/slab.hlinux/sched.hlinux/sched/isolation.hlinux/sched/mm.hlinux/smpboot.hlinux/mutex.hlinux/rwsem.hlinux/string.hlinux/mm.hlinux/socket.hlinux/sockios.hlinux/errno.hlinux/interrupt.hlinux/if_ether.hlinux/netdevice.hlinux/etherdevice.hlinux/ethtool.hlinux/ethtool_netlink.hlinux/skbuff.hlinux/kthread.hlinux/bpf.hlinux/bpf_trace.hnet/net_namespace.hnet/sock.hnet/busy_poll.h
Detected Declarations
struct dev_kfree_skb_cbstruct flush_backlogsstruct netdev_adjacentstruct netdev_notifier_offload_xstats_rustruct netdev_notifier_offload_xstats_rdstruct bpf_xdp_linkfunction dev_base_seq_incfunction setup_backlog_napi_threadsfunction use_backlog_threadsfunction use_backlog_threadsfunction backlog_lock_irq_savefunction backlog_lock_irq_disablefunction backlog_unlock_irq_restorefunction backlog_unlock_irq_enablefunction netdev_name_node_head_allocfunction netdev_name_node_freefunction netdev_name_node_addfunction netdev_name_node_delfunction netdev_name_in_usefunction netdev_name_node_alt_createfunction netdev_name_node_alt_freefunction __netdev_name_node_alt_destroyfunction netdev_name_node_alt_destroyfunction netdev_name_node_alt_flushfunction list_for_each_entry_safefunction list_netdevicefunction unlist_netdevicefunction netdev_lock_posfunction netdev_set_xmit_lockdep_classfunction netdev_set_addr_lockdep_classfunction netdev_set_xmit_lockdep_classfunction typefunction dev_add_packfunction list_for_each_entryfunction dev_add_packfunction dev_get_iflinkfunction dev_fill_metadata_dstfunction dev_fill_forward_pathfunction netdev_napi_by_idfunction netdev_napi_by_id_lockfunction netdev_get_by_namefunction netdev_get_by_indexfunction returnedfunction __netdev_put_lock_ops_compatfunction netdev_get_by_index_lockfunction netdev_get_by_index_lock_ops_compatfunction netdev_xa_find_lockfunction netdev_xa_find_lock_ops_compat
Annotated Snippet
const struct net_device_ops *ops = dev->netdev_ops;
int ret;
ASSERT_RTNL();
dev_addr_check(dev);
if (!netif_device_present(dev)) {
/* may be detached because parent is runtime-suspended */
if (dev->dev.parent)
pm_runtime_resume(dev->dev.parent);
if (!netif_device_present(dev))
return -ENODEV;
}
/* Block netpoll from trying to do any rx path servicing.
* If we don't do this there is a chance ndo_poll_controller
* or ndo_poll may be running while we open the device
*/
netpoll_poll_disable(dev);
ret = call_netdevice_notifiers_extack(NETDEV_PRE_UP, dev, extack);
ret = notifier_to_errno(ret);
if (ret)
return ret;
set_bit(__LINK_STATE_START, &dev->state);
netdev_assert_locked_ops_compat(dev);
if (ops->ndo_validate_addr)
ret = ops->ndo_validate_addr(dev);
if (!ret && ops->ndo_open)
ret = ops->ndo_open(dev);
netpoll_poll_enable(dev);
if (ret)
clear_bit(__LINK_STATE_START, &dev->state);
else {
netif_set_up(dev, true);
dev_set_rx_mode(dev);
dev_activate(dev);
add_device_randomness(dev->dev_addr, dev->addr_len);
}
return ret;
}
int netif_open(struct net_device *dev, struct netlink_ext_ack *extack)
{
int ret;
if (dev->flags & IFF_UP)
return 0;
ret = __dev_open(dev, extack);
if (ret < 0)
return ret;
rtmsg_ifinfo(RTM_NEWLINK, dev, IFF_UP | IFF_RUNNING, GFP_KERNEL, 0, NULL);
call_netdevice_notifiers(NETDEV_UP, dev);
return ret;
}
EXPORT_SYMBOL(netif_open);
static void __dev_close_many(struct list_head *head)
{
struct net_device *dev;
ASSERT_RTNL();
might_sleep();
list_for_each_entry(dev, head, close_list) {
/* Temporarily disable netpoll until the interface is down */
netpoll_poll_disable(dev);
call_netdevice_notifiers(NETDEV_GOING_DOWN, dev);
clear_bit(__LINK_STATE_START, &dev->state);
/* Synchronize to scheduled poll. We cannot touch poll list, it
* can be even on different cpu. So just clear netif_running().
*
* dev->stop() will invoke napi_disable() on all of it's
* napi_struct instances on this device.
*/
smp_mb__after_atomic(); /* Commit netif_running(). */
}
Annotation
- Immediate include surface: `linux/uaccess.h`, `linux/bitmap.h`, `linux/capability.h`, `linux/cpu.h`, `linux/types.h`, `linux/kernel.h`, `linux/hash.h`, `linux/slab.h`.
- Detected declarations: `struct dev_kfree_skb_cb`, `struct flush_backlogs`, `struct netdev_adjacent`, `struct netdev_notifier_offload_xstats_ru`, `struct netdev_notifier_offload_xstats_rd`, `struct bpf_xdp_link`, `function dev_base_seq_inc`, `function setup_backlog_napi_threads`, `function use_backlog_threads`, `function use_backlog_threads`.
- Atlas domain: Networking Core / Sockets, Protocols, Packet Path, And Network Policy.
- Implementation status: pattern 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.