diff options
author | Thomas Haller <thaller@redhat.com> | 2015-06-01 12:06:12 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2015-06-05 16:52:50 +0200 |
commit | 95333d84bcaef7b450293b8fbc4550a30fad2df3 (patch) | |
tree | 05f1e4cf511d25ddb0a162da977269f079cbb8ef | |
parent | 299af02e40bc0a19d4a2e021cd7250adf1cfbb86 (diff) | |
download | NetworkManager-95333d84bcaef7b450293b8fbc4550a30fad2df3.tar.gz |
platform: move ethtool_get_link_speed() to nm-platform-utils
-rw-r--r-- | src/devices/nm-device-ethernet.c | 34 | ||||
-rw-r--r-- | src/platform/nm-platform-utils.c | 25 | ||||
-rw-r--r-- | src/platform/nm-platform-utils.h | 1 |
3 files changed, 28 insertions, 32 deletions
diff --git a/src/devices/nm-device-ethernet.c b/src/devices/nm-device-ethernet.c index 8520ee7364..a0aa02d1ac 100644 --- a/src/devices/nm-device-ethernet.c +++ b/src/devices/nm-device-ethernet.c @@ -26,10 +26,6 @@ #include <netinet/in.h> #include <string.h> #include <stdlib.h> -#include <linux/sockios.h> -#include <linux/ethtool.h> -#include <linux/version.h> -#include <sys/ioctl.h> #include <unistd.h> #include <errno.h> @@ -48,6 +44,7 @@ #include "nm-enum-types.h" #include "nm-dbus-manager.h" #include "nm-platform.h" +#include "nm-platform-utils.h" #include "nm-dcb.h" #include "nm-settings-connection.h" #include "nm-config.h" @@ -1533,37 +1530,10 @@ get_link_speed (NMDevice *device) { NMDeviceEthernet *self = NM_DEVICE_ETHERNET (device); NMDeviceEthernetPrivate *priv = NM_DEVICE_ETHERNET_GET_PRIVATE (self); - struct ifreq ifr; - struct ethtool_cmd edata = { - .cmd = ETHTOOL_GSET, - }; guint32 speed; - int fd; - fd = socket (PF_INET, SOCK_DGRAM, 0); - if (fd < 0) { - _LOGW (LOGD_HW | LOGD_ETHER, "couldn't open ethtool control socket."); + if (!nmp_utils_ethtool_get_link_speed (nm_device_get_iface (device), &speed)) return; - } - - memset (&ifr, 0, sizeof (struct ifreq)); - strncpy (ifr.ifr_name, nm_device_get_iface (device), IFNAMSIZ); - ifr.ifr_data = (char *) &edata; - - if (ioctl (fd, SIOCETHTOOL, &ifr) < 0) { - close (fd); - return; - } - close (fd); - -#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,27) - speed = edata.speed; -#else - speed = ethtool_cmd_speed (&edata); -#endif - if (speed == G_MAXUINT16 || speed == G_MAXUINT32) - speed = 0; - if (priv->speed == speed) return; diff --git a/src/platform/nm-platform-utils.c b/src/platform/nm-platform-utils.c index 17a82c1a56..407b91fbcc 100644 --- a/src/platform/nm-platform-utils.c +++ b/src/platform/nm-platform-utils.c @@ -27,6 +27,7 @@ #include <linux/ethtool.h> #include <linux/sockios.h> #include <linux/mii.h> +#include <linux/version.h> #include "gsystem-local-alloc.h" #include "nm-utils.h" @@ -232,6 +233,30 @@ nmp_utils_ethtool_get_wake_on_lan (const char *ifname) return wol.wolopts != 0; } +gboolean +nmp_utils_ethtool_get_link_speed (const char *ifname, guint32 *out_speed) +{ + struct ethtool_cmd edata = { + .cmd = ETHTOOL_GSET, + }; + guint32 speed; + + if (!ethtool_get (ifname, &edata)) + return FALSE; + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,27) + speed = edata.speed; +#else + speed = ethtool_cmd_speed (&edata); +#endif + if (speed == G_MAXUINT16 || speed == G_MAXUINT32) + speed = 0; + + if (out_speed) + *out_speed = speed; + return TRUE; +} + /****************************************************************** * mii ******************************************************************/ diff --git a/src/platform/nm-platform-utils.h b/src/platform/nm-platform-utils.h index edc55c09cd..d0032f5d69 100644 --- a/src/platform/nm-platform-utils.h +++ b/src/platform/nm-platform-utils.h @@ -33,6 +33,7 @@ gboolean nmp_utils_ethtool_supports_carrier_detect (const char *ifname); gboolean nmp_utils_ethtool_supports_vlans (const char *ifname); int nmp_utils_ethtool_get_peer_ifindex (const char *ifname); gboolean nmp_utils_ethtool_get_wake_on_lan (const char *ifname); +gboolean nmp_utils_ethtool_get_link_speed (const char *ifname, guint32 *out_speed); gboolean nmp_utils_ethtool_get_driver_info (const char *ifname, char **out_driver_name, |