net/core/dev_ioctl.c
Source file repositories/reference/linux-study-clean/net/core/dev_ioctl.c
File Facts
- System
- Linux kernel
- Corpus path
net/core/dev_ioctl.c- Extension
.c- Size
- 20206 bytes
- Lines
- 850
- 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.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- 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/kmod.hlinux/netdevice.hlinux/inetdevice.hlinux/etherdevice.hlinux/rtnetlink.hlinux/net_tstamp.hlinux/phylib_stubs.hlinux/ptp_clock_kernel.hlinux/wireless.hlinux/if_bridge.hnet/dsa_stubs.hnet/netdev_lock.hnet/wext.hdev.h
Detected Declarations
function namefunction dev_ifconffunction dev_getifmapfunction netif_setifmapfunction dev_ifsioc_lockedfunction net_hwtstamp_validatefunction dev_get_hwtstamp_phylibfunction dev_get_hwtstampfunction copy_to_userfunction dev_set_hwtstamp_phylibfunction dev_set_hwtstampfunction generic_hwtstamp_get_lowerfunction generic_hwtstamp_set_lowerfunction dev_siocbondfunction dev_siocdevprivatefunction dev_siocwandevfunction dev_ifsiocfunction dev_loadfunction dev_ioctlexport generic_hwtstamp_get_lowerexport generic_hwtstamp_set_lowerexport dev_load
Annotated Snippet
const struct net_device_ops *ops = dev->netdev_ops;
struct kernel_hwtstamp_config kernel_cfg = {};
struct hwtstamp_config cfg;
int err;
if (!ops->ndo_hwtstamp_get)
return -EOPNOTSUPP;
if (!netif_device_present(dev))
return -ENODEV;
kernel_cfg.ifr = ifr;
netdev_lock_ops(dev);
err = dev_get_hwtstamp_phylib(dev, &kernel_cfg);
netdev_unlock_ops(dev);
if (err)
return err;
/* If the request was resolved through an unconverted driver, omit
* the copy_to_user(), since the implementation has already done that
*/
if (!kernel_cfg.copied_to_user) {
hwtstamp_config_from_kernel(&cfg, &kernel_cfg);
if (copy_to_user(ifr->ifr_data, &cfg, sizeof(cfg)))
return -EFAULT;
}
return 0;
}
/**
* dev_set_hwtstamp_phylib() - Change hardware timestamping of NIC
* or of attached phylib PHY
* @dev: Network device
* @cfg: Timestamping configuration structure
* @extack: Netlink extended ack message structure, for error reporting
*
* Helper for enforcing a common policy that phylib timestamping, if available,
* should take precedence in front of hardware timestamping provided by the
* netdev. If the netdev driver needs to perform specific actions even for PHY
* timestamping to work properly (a switch port must trap the timestamped
* frames and not forward them), it must set dev->see_all_hwtstamp_requests.
*/
int dev_set_hwtstamp_phylib(struct net_device *dev,
struct kernel_hwtstamp_config *cfg,
struct netlink_ext_ack *extack)
{
const struct net_device_ops *ops = dev->netdev_ops;
struct kernel_hwtstamp_config old_cfg = {};
struct hwtstamp_provider *hwprov;
struct phy_device *phydev;
bool changed = false;
bool phy_ts;
int err;
hwprov = netdev_ops_lock_dereference(dev->hwprov, dev);
if (hwprov) {
if (hwprov->source == HWTSTAMP_SOURCE_PHYLIB &&
hwprov->phydev) {
phy_ts = true;
phydev = hwprov->phydev;
} else if (hwprov->source == HWTSTAMP_SOURCE_NETDEV) {
phy_ts = false;
} else {
return -EOPNOTSUPP;
}
cfg->qualifier = hwprov->desc.qualifier;
} else {
phy_ts = phy_is_default_hwtstamp(dev->phydev);
if (phy_ts)
phydev = dev->phydev;
}
cfg->source = phy_ts ? HWTSTAMP_SOURCE_PHYLIB : HWTSTAMP_SOURCE_NETDEV;
if (phy_ts && dev->see_all_hwtstamp_requests) {
err = ops->ndo_hwtstamp_get(dev, &old_cfg);
if (err)
return err;
}
if (!phy_ts || dev->see_all_hwtstamp_requests) {
err = ops->ndo_hwtstamp_set(dev, cfg, extack);
if (err) {
if (extack->_msg)
netdev_err(dev, "%s\n", extack->_msg);
return err;
}
Annotation
- Immediate include surface: `linux/kmod.h`, `linux/netdevice.h`, `linux/inetdevice.h`, `linux/etherdevice.h`, `linux/rtnetlink.h`, `linux/net_tstamp.h`, `linux/phylib_stubs.h`, `linux/ptp_clock_kernel.h`.
- Detected declarations: `function name`, `function dev_ifconf`, `function dev_getifmap`, `function netif_setifmap`, `function dev_ifsioc_locked`, `function net_hwtstamp_validate`, `function dev_get_hwtstamp_phylib`, `function dev_get_hwtstamp`, `function copy_to_user`, `function dev_set_hwtstamp_phylib`.
- Atlas domain: Networking Core / Sockets, Protocols, Packet Path, And Network Policy.
- Implementation status: pattern implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
- 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.