net/ethtool/ioctl.c
Source file repositories/reference/linux-study-clean/net/ethtool/ioctl.c
File Facts
- System
- Linux kernel
- Corpus path
net/ethtool/ioctl.c- Extension
.c- Size
- 103040 bytes
- Lines
- 3968
- 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.
- 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.
- 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/compat.hlinux/etherdevice.hlinux/module.hlinux/types.hlinux/capability.hlinux/errno.hlinux/ethtool.hlinux/netdevice.hlinux/net_tstamp.hlinux/phy.hlinux/bitops.hlinux/uaccess.hlinux/vmalloc.hlinux/sfp.hlinux/slab.hlinux/rtnetlink.hlinux/sched/signal.hlinux/net.hlinux/pm_runtime.hlinux/utsname.hlinux/ethtool_netlink.hnet/devlink.hnet/ipv6.hnet/flow_offload.hnet/netdev_lock.hnet/netdev_queues.hcommon.h
Detected Declarations
struct ethtool_devlink_compatstruct ethtool_link_usettingsstruct ethtool_rx_flow_keystruct ethtool_rx_flow_matchfunction dev_function ethtool_op_get_ts_infofunction ethtool_get_featuresfunction ethtool_set_featuresfunction __ethtool_get_sset_countfunction __ethtool_get_stringsfunction ethtool_get_feature_maskfunction ethtool_get_one_featurefunction ethtool_set_one_featurefunction __ethtool_get_flagsfunction __ethtool_set_flagsfunction ethtool_intersect_link_masksfunction ethtool_convert_legacy_u32_to_link_modefunction ethtool_convert_link_mode_to_legacy_u32function convert_link_ksettings_to_legacy_settingsfunction netif_get_link_ksettingsfunction __ethtool_get_link_ksettingsfunction load_link_ksettings_from_userfunction ethtool_virtdev_validate_cmdfunction store_link_ksettings_for_userfunction ethtool_get_link_ksettingsfunction ethtool_set_link_ksettingsfunction ethtool_virtdev_set_link_ksettingsfunction ethtool_cmdfunction fieldsfunction ethtool_get_drvinfofunction ethtool_get_sset_infofunction ethtool_rxnfc_copy_from_compatfunction ethtool_rxnfc_copy_from_userfunction ethtool_rxnfc_copy_to_compatfunction ethtool_rxnfc_copy_structfunction ethtool_rxnfc_copy_to_userfunction flow_type_hashablefunction flow_type_v6function ethtool_check_xfrm_rxfhfunction ethtool_check_flow_typesfunction ethtool_set_rxfh_fieldsfunction ethtool_get_rxfh_fieldsfunction ethtool_set_rxnfcfunction ethtool_get_rxringsfunction ethtool_get_rxnfcfunction ethtool_copy_validate_indirfunction netdev_rss_key_fillfunction ethtool_get_rxfh_indir
Annotated Snippet
struct ethtool_devlink_compat {
struct devlink *devlink;
union {
struct ethtool_flash efl;
struct ethtool_drvinfo info;
};
};
static struct devlink *netdev_to_devlink_get(struct net_device *dev)
{
if (!dev->devlink_port)
return NULL;
return devlink_try_get(dev->devlink_port->devlink);
}
/*
* Some useful ethtool_ops methods that're device independent.
* If we find that all drivers want to do the same thing here,
* we can turn these into dev_() function calls.
*/
u32 ethtool_op_get_link(struct net_device *dev)
{
/* Synchronize carrier state with link watch, see also rtnl_getlink() */
__linkwatch_sync_dev(dev);
return netif_carrier_ok(dev) ? 1 : 0;
}
EXPORT_SYMBOL(ethtool_op_get_link);
int ethtool_op_get_ts_info(struct net_device *dev,
struct kernel_ethtool_ts_info *info)
{
info->so_timestamping =
SOF_TIMESTAMPING_TX_SOFTWARE |
SOF_TIMESTAMPING_RX_SOFTWARE |
SOF_TIMESTAMPING_SOFTWARE;
info->phc_index = -1;
return 0;
}
EXPORT_SYMBOL(ethtool_op_get_ts_info);
/* Handlers for each ethtool command */
static int ethtool_get_features(struct net_device *dev, void __user *useraddr)
{
struct ethtool_gfeatures cmd = {
.cmd = ETHTOOL_GFEATURES,
.size = ETHTOOL_DEV_FEATURE_WORDS,
};
struct ethtool_get_features_block features[ETHTOOL_DEV_FEATURE_WORDS];
u32 __user *sizeaddr;
u32 copy_size;
int i;
/* in case feature bits run out again */
BUILD_BUG_ON(ETHTOOL_DEV_FEATURE_WORDS * sizeof(u32) > sizeof(netdev_features_t));
for (i = 0; i < ETHTOOL_DEV_FEATURE_WORDS; ++i) {
features[i].available = (u32)(dev->hw_features >> (32 * i));
features[i].requested = (u32)(dev->wanted_features >> (32 * i));
features[i].active = (u32)(dev->features >> (32 * i));
features[i].never_changed =
(u32)(NETIF_F_NEVER_CHANGE >> (32 * i));
}
sizeaddr = useraddr + offsetof(struct ethtool_gfeatures, size);
if (get_user(copy_size, sizeaddr))
return -EFAULT;
if (copy_size > ETHTOOL_DEV_FEATURE_WORDS)
copy_size = ETHTOOL_DEV_FEATURE_WORDS;
if (copy_to_user(useraddr, &cmd, sizeof(cmd)))
return -EFAULT;
useraddr += sizeof(cmd);
if (copy_to_user(useraddr, features,
array_size(copy_size, sizeof(*features))))
return -EFAULT;
return 0;
}
static int ethtool_set_features(struct net_device *dev, void __user *useraddr)
{
struct ethtool_sfeatures cmd;
struct ethtool_set_features_block features[ETHTOOL_DEV_FEATURE_WORDS];
netdev_features_t wanted = 0, valid = 0;
int i, ret = 0;
Annotation
- Immediate include surface: `linux/compat.h`, `linux/etherdevice.h`, `linux/module.h`, `linux/types.h`, `linux/capability.h`, `linux/errno.h`, `linux/ethtool.h`, `linux/netdevice.h`.
- Detected declarations: `struct ethtool_devlink_compat`, `struct ethtool_link_usettings`, `struct ethtool_rx_flow_key`, `struct ethtool_rx_flow_match`, `function dev_`, `function ethtool_op_get_ts_info`, `function ethtool_get_features`, `function ethtool_set_features`, `function __ethtool_get_sset_count`, `function __ethtool_get_strings`.
- Atlas domain: Networking Core / Sockets, Protocols, Packet Path, And Network Policy.
- Implementation status: integration 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.
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.