summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Williams <dcbw@redhat.com>2014-10-03 13:41:49 -0500
committerDan Williams <dcbw@redhat.com>2014-12-11 09:38:45 -0600
commit5abc8b71d499ca3e6cf629cf540b2b6e40ab6055 (patch)
treea0f5420159655e83161d3ed611fcfd9d5859e7ec
parent67eac79ece000535ba2e5944b7c7823d1a710162 (diff)
downloadNetworkManager-5abc8b71d499ca3e6cf629cf540b2b6e40ab6055.tar.gz
platform: move driver & firmware version reading into the platform
-rw-r--r--src/devices/nm-device.c50
-rw-r--r--src/platform/nm-fake-platform.c13
-rw-r--r--src/platform/nm-linux-platform.c27
-rw-r--r--src/platform/nm-platform.c22
-rw-r--r--src/platform/nm-platform.h7
5 files changed, 73 insertions, 46 deletions
diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c
index 1581335abd..1fcbfd2bc0 100644
--- a/src/devices/nm-device.c
+++ b/src/devices/nm-device.c
@@ -28,8 +28,6 @@
#include <string.h>
#include <unistd.h>
#include <errno.h>
-#include <linux/sockios.h>
-#include <linux/ethtool.h>
#include <sys/ioctl.h>
#include <signal.h>
#include <sys/types.h>
@@ -7890,46 +7888,6 @@ nm_device_init (NMDevice *self)
priv->default_route.v6_is_assumed = TRUE;
}
-/*
- * Get driver info from SIOCETHTOOL ioctl() for 'iface'
- * Returns driver and firmware versions to 'driver_version and' 'firmware_version'
- */
-static gboolean
-device_get_driver_info (NMDevice *self, const char *iface, char **driver_version, char **firmware_version)
-{
- struct ethtool_drvinfo drvinfo;
- struct ifreq req;
- int fd;
-
- fd = socket (PF_INET, SOCK_DGRAM, 0);
- if (fd < 0) {
- _LOGW (LOGD_HW, "couldn't open control socket.");
- return FALSE;
- }
-
- /* Get driver and firmware version info */
- memset (&drvinfo, 0, sizeof (drvinfo));
- memset (&req, 0, sizeof (struct ifreq));
- strncpy (req.ifr_name, iface, IFNAMSIZ);
- drvinfo.cmd = ETHTOOL_GDRVINFO;
- req.ifr_data = &drvinfo;
-
- errno = 0;
- if (ioctl (fd, SIOCETHTOOL, &req) < 0) {
- _LOGD (LOGD_HW, "SIOCETHTOOL ioctl() failed: cmd=ETHTOOL_GDRVINFO, iface=%s, errno=%d",
- iface, errno);
- close (fd);
- return FALSE;
- }
- if (driver_version)
- *driver_version = g_strdup (drvinfo.version);
- if (firmware_version)
- *firmware_version = g_strdup (drvinfo.fw_version);
-
- close (fd);
- return TRUE;
-}
-
static GObject*
constructor (GType type,
guint n_construct_params,
@@ -7965,10 +7923,8 @@ constructor (GType type,
if (NM_DEVICE_GET_CLASS (self)->get_generic_capabilities)
priv->capabilities |= NM_DEVICE_GET_CLASS (self)->get_generic_capabilities (self);
- if (priv->ifindex <= 0 && !device_has_capability (self, NM_DEVICE_CAP_IS_NON_KERNEL))
- _LOGW (LOGD_HW, "failed to look up interface index");
-
- device_get_driver_info (self, priv->iface, &priv->driver_version, &priv->firmware_version);
+ if (priv->ifindex > 0)
+ nm_platform_link_get_driver_info (priv->ifindex, &priv->driver_version, &priv->firmware_version);
/* Watch for external IP config changes */
platform = nm_platform_get ();
@@ -8174,6 +8130,8 @@ set_property (GObject *object, guint prop_id,
g_free (priv->iface);
priv->iface = g_value_dup_string (value);
priv->ifindex = nm_platform_link_get_ifindex (priv->iface);
+ if (priv->ifindex <= 0 && !device_has_capability (self, NM_DEVICE_CAP_IS_NON_KERNEL))
+ _LOGW (LOGD_HW, "failed to look up interface index");
}
break;
case PROP_DRIVER:
diff --git a/src/platform/nm-fake-platform.c b/src/platform/nm-fake-platform.c
index ff93045c26..7e3b6eb072 100644
--- a/src/platform/nm-fake-platform.c
+++ b/src/platform/nm-fake-platform.c
@@ -495,6 +495,18 @@ link_get_wake_on_lan (NMPlatform *platform, int ifindex)
}
static gboolean
+link_get_driver_info (NMPlatform *platform,
+ int ifindex,
+ char **out_driver_version,
+ char **out_fw_version)
+{
+ /* We call link_get just to cause an error to be set if @ifindex is bad. */
+ link_get (platform, ifindex);
+
+ return TRUE;
+}
+
+static gboolean
link_supports_carrier_detect (NMPlatform *platform, int ifindex)
{
NMFakePlatformLink *device = link_get (platform, ifindex);
@@ -1334,6 +1346,7 @@ nm_fake_platform_class_init (NMFakePlatformClass *klass)
platform_class->link_get_physical_port_id = link_get_physical_port_id;
platform_class->link_get_wake_on_lan = link_get_wake_on_lan;
+ platform_class->link_get_driver_info = link_get_driver_info;
platform_class->link_supports_carrier_detect = link_supports_carrier_detect;
platform_class->link_supports_vlans = link_supports_vlans;
diff --git a/src/platform/nm-linux-platform.c b/src/platform/nm-linux-platform.c
index 4591e7b2cf..4405848ee6 100644
--- a/src/platform/nm-linux-platform.c
+++ b/src/platform/nm-linux-platform.c
@@ -2752,6 +2752,32 @@ link_get_physical_port_id (NMPlatform *platform, int ifindex)
return id;
}
+static gboolean
+link_get_driver_info (NMPlatform *platform,
+ int ifindex,
+ char **out_driver_version,
+ char **out_fw_version)
+{
+ gs_free struct ethtool_drvinfo *info = NULL;
+ const char *ifname;
+
+ ifname = nm_platform_link_get_name (ifindex);
+ if (!ifname)
+ return FALSE;
+
+ info = g_malloc0 (sizeof (*info) + sizeof (guint32));
+ info->cmd = ETHTOOL_GDRVINFO;
+ if (!ethtool_get (ifname, info))
+ return FALSE;
+
+ if (out_driver_version)
+ *out_driver_version = g_strdup (info->version);
+ if (out_fw_version)
+ *out_fw_version = g_strdup (info->fw_version);
+
+ return TRUE;
+}
+
static int
vlan_add (NMPlatform *platform,
const char *name,
@@ -4547,6 +4573,7 @@ nm_linux_platform_class_init (NMLinuxPlatformClass *klass)
platform_class->link_get_physical_port_id = link_get_physical_port_id;
platform_class->link_get_wake_on_lan = link_get_wake_on_lan;
+ platform_class->link_get_driver_info = link_get_driver_info;
platform_class->link_supports_carrier_detect = link_supports_carrier_detect;
platform_class->link_supports_vlans = link_supports_vlans;
diff --git a/src/platform/nm-platform.c b/src/platform/nm-platform.c
index d2073d3e86..f794a634cb 100644
--- a/src/platform/nm-platform.c
+++ b/src/platform/nm-platform.c
@@ -1039,6 +1039,28 @@ nm_platform_link_get_wake_on_lan (int ifindex)
}
/**
+ * nm_platform_link_get_driver_info:
+ * @ifindex: Interface index
+ * @out_driver_version: on success, the driver version if available
+ * @out_fw_version: on success, the firmware version if available
+ *
+ * Returns: %TRUE on success (though @out_driver_version and @out_fw_version
+ * can be %NULL if no information was available), %FALSE on failure
+ */
+gboolean
+nm_platform_link_get_driver_info (int ifindex,
+ char **out_driver_version,
+ char **out_fw_version)
+{
+ reset_error ();
+
+ g_return_val_if_fail (ifindex >= 0, FALSE);
+ g_return_val_if_fail (klass->link_get_driver_info, FALSE);
+
+ return klass->link_get_driver_info (platform, ifindex, out_driver_version, out_fw_version);
+}
+
+/**
* nm_platform_link_enslave:
* @master: Interface index of the master
* @slave: Interface index of the slave
diff --git a/src/platform/nm-platform.h b/src/platform/nm-platform.h
index 49bb4260db..8c7706cf3a 100644
--- a/src/platform/nm-platform.h
+++ b/src/platform/nm-platform.h
@@ -375,6 +375,10 @@ typedef struct {
char * (*link_get_physical_port_id) (NMPlatform *, int ifindex);
gboolean (*link_get_wake_on_lan) (NMPlatform *, int ifindex);
+ gboolean (*link_get_driver_info) (NMPlatform *,
+ int ifindex,
+ char **out_driver_version,
+ char **out_fw_version);
gboolean (*link_supports_carrier_detect) (NMPlatform *, int ifindex);
gboolean (*link_supports_vlans) (NMPlatform *, int ifindex);
@@ -522,6 +526,9 @@ gboolean nm_platform_link_set_mtu (int ifindex, guint32 mtu);
char *nm_platform_link_get_physical_port_id (int ifindex);
gboolean nm_platform_link_get_wake_on_lan (int ifindex);
+gboolean nm_platform_link_get_driver_info (int ifindex,
+ char **out_driver_version,
+ char **out_fw_version);
gboolean nm_platform_link_supports_carrier_detect (int ifindex);
gboolean nm_platform_link_supports_vlans (int ifindex);