platform: move ethtool_get_link_speed() to nm-platform-utils

This commit is contained in:
Thomas Haller 2015-06-01 12:06:12 +02:00
parent 299af02e40
commit 95333d84bc
3 changed files with 28 additions and 32 deletions

View file

@ -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;

View file

@ -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
******************************************************************/

View file

@ -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,