2
주어진 네트워크 인터페이스 (예 : "eth0")의 속도를 찾아야하는 linux 커널 모듈이 있습니다. 리눅스 2.6.31의 경우 어떻게 속도 (설정/협상)를 찾을 수 있습니까?리눅스 커널 모듈에서 네트워크 장치 속도를 결정하는 방법
주어진 네트워크 인터페이스 (예 : "eth0")의 속도를 찾아야하는 linux 커널 모듈이 있습니다. 리눅스 2.6.31의 경우 어떻게 속도 (설정/협상)를 찾을 수 있습니까?리눅스 커널 모듈에서 네트워크 장치 속도를 결정하는 방법
모든 네트워크 드라이버에는 이러한 기능을위한 "ethtool"구현이 있습니다. 하지만 일반적인 netdev 구조체의 속도를 줄 수있는 제네릭 함수가 필요할 것입니다. net/core/net-sysfs.c을보고 어떻게/sys/class/net 인터페이스를 구현하는지보십시오. 예 :
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;
}