How to determine the speed of a network device from a Linux kernel module
1 answer
Each network driver has an "ethtool" implementation for these functions. But you probably want a general function that can give you speed for the overall netdev framework. You can take a look at net / core / net-sysfs.c and see how it implements the / sys / class / net interface. For instance:
static ssize_t show_speed(struct device *dev,
struct device_attribute *attr, char *buf)
{
struct net_device *netdev = to_net_dev(dev);
int ret = -EINVAL;
if (!rtnl_trylock())
return restart_syscall();
if (netif_running(netdev) &&
netdev->ethtool_ops &&
netdev->ethtool_ops->get_settings) {
struct ethtool_cmd cmd = { ETHTOOL_GSET };
if (!netdev->ethtool_ops->get_settings(netdev, &cmd))
ret = sprintf(buf, fmt_dec, ethtool_cmd_speed(&cmd));
}
rtnl_unlock();
return ret;
}
+4
a source to share