summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Williams <dcbw@redhat.com>2014-10-03 13:41:49 -0500
committerThomas Haller <thaller@redhat.com>2015-06-17 16:19:19 +0200
commitc7ce5612ca2450ecce2e2d87260806425bf1fc6a (patch)
treec89b367814c339e4343d4a261825c4c2ec34b7d7
parent081aeaf3e6faa48824fdae9a6ee90253f3e34336 (diff)
downloadNetworkManager-c7ce5612ca2450ecce2e2d87260806425bf1fc6a.tar.gz
platform: move driver & firmware version reading into the platform
(cherry picked from commit ddaea22332907c05222cbec1e1b4365689fbda9f)
-rw-r--r--src/devices/nm-device.c53
-rw-r--r--src/platform/nm-fake-platform.c21
-rw-r--r--src/platform/nm-linux-platform.c56
-rw-r--r--src/platform/nm-platform.c32
-rw-r--r--src/platform/nm-platform.h10
5 files changed, 114 insertions, 58 deletions
diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c
index b96b45a458..c16b892eab 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>
@@ -8382,46 +8380,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,
@@ -8457,10 +8415,13 @@ 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 && !nm_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 (NM_PLATFORM_GET,
+ priv->ifindex,
+ NULL,
+ &priv->driver_version,
+ &priv->firmware_version);
+ }
/* Watch for external IP config changes */
platform = nm_platform_get ();
diff --git a/src/platform/nm-fake-platform.c b/src/platform/nm-fake-platform.c
index 1d74a3c5e7..4cf2e46452 100644
--- a/src/platform/nm-fake-platform.c
+++ b/src/platform/nm-fake-platform.c
@@ -503,6 +503,26 @@ link_get_wake_on_lan (NMPlatform *platform, int ifindex)
}
static gboolean
+link_get_driver_info (NMPlatform *platform,
+ int ifindex,
+ char **out_driver_name,
+ char **out_driver_version,
+ char **out_fw_version)
+{
+ if (out_driver_name)
+ *out_driver_name = NULL;
+ if (out_driver_version)
+ *out_driver_version = NULL;
+ if (out_fw_version)
+ *out_fw_version = NULL;
+
+ /* 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);
@@ -1418,6 +1438,7 @@ nm_fake_platform_class_init (NMFakePlatformClass *klass)
platform_class->link_get_physical_port_id = link_get_physical_port_id;
platform_class->link_get_dev_id = link_get_dev_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 67e93c001f..e13addc600 100644
--- a/src/platform/nm-linux-platform.c
+++ b/src/platform/nm-linux-platform.c
@@ -372,6 +372,9 @@ ethtool_get (const char *name, gpointer edata)
struct ifreq ifr;
int fd;
+ if (!name || !*name)
+ return FALSE;
+
memset (&ifr, 0, sizeof (ifr));
strncpy (ifr.ifr_name, name, IFNAMSIZ);
ifr.ifr_data = edata;
@@ -426,21 +429,29 @@ ethtool_get_stringset_index (const char *ifname, int stringset_id, const char *s
return -1;
}
-static const char *
-ethtool_get_driver (const char *ifname)
+static gboolean
+ethtool_get_driver_info (const char *ifname,
+ char **out_driver_name,
+ char **out_driver_version,
+ char **out_fw_version)
{
struct ethtool_drvinfo drvinfo = { 0 };
- g_return_val_if_fail (ifname != NULL, NULL);
+ if (!ifname)
+ return FALSE;
drvinfo.cmd = ETHTOOL_GDRVINFO;
if (!ethtool_get (ifname, &drvinfo))
- return NULL;
+ return FALSE;
- if (!*drvinfo.driver)
- return NULL;
+ if (out_driver_name)
+ *out_driver_name = g_strdup (drvinfo.driver);
+ if (out_driver_version)
+ *out_driver_version = g_strdup (drvinfo.version);
+ if (out_fw_version)
+ *out_fw_version = g_strdup (drvinfo.fw_version);
- return g_intern_string (drvinfo.driver);
+ return TRUE;
}
/******************************************************************
@@ -983,7 +994,7 @@ link_extract_type (NMPlatform *platform, struct rtnl_link *rtnllink)
ifname = rtnl_link_get_name (rtnllink);
if (ifname) {
- const char *driver = ethtool_get_driver (ifname);
+ gs_free char *driver = NULL;
gs_free char *sysfs_path = NULL;
gs_free char *anycast_mask = NULL;
gs_free char *devtype = NULL;
@@ -997,8 +1008,10 @@ link_extract_type (NMPlatform *platform, struct rtnl_link *rtnllink)
}
/* Fallback OVS detection for kernel <= 3.16 */
- if (!g_strcmp0 (driver, "openvswitch"))
- return NM_LINK_TYPE_OPENVSWITCH;
+ if (ethtool_get_driver_info (ifname, &driver, NULL, NULL)) {
+ if (!g_strcmp0 (driver, "openvswitch"))
+ return NM_LINK_TYPE_OPENVSWITCH;
+ }
sysfs_path = g_strdup_printf ("/sys/class/net/%s", ifname);
anycast_mask = g_strdup_printf ("%s/anycast_mask", sysfs_path);
@@ -1041,6 +1054,7 @@ init_link (NMPlatform *platform, NMPlatformLink *info, struct rtnl_link *rtnllin
NMLinuxPlatformPrivate *priv = NM_LINUX_PLATFORM_GET_PRIVATE (platform);
GUdevDevice *udev_device;
const char *name;
+ char *tmp;
g_return_val_if_fail (rtnllink, FALSE);
@@ -1070,8 +1084,12 @@ init_link (NMPlatform *platform, NMPlatformLink *info, struct rtnl_link *rtnllin
if (!info->driver)
info->driver = info->kind;
- if (!info->driver)
- info->driver = ethtool_get_driver (info->name);
+ if (!info->driver) {
+ if (ethtool_get_driver_info (name, &tmp, NULL, NULL)) {
+ info->driver = g_intern_string (tmp);
+ g_free (tmp);
+ }
+ }
if (!info->driver)
info->driver = "unknown";
@@ -3659,6 +3677,19 @@ link_get_wake_on_lan (NMPlatform *platform, int ifindex)
return FALSE;
}
+static gboolean
+link_get_driver_info (NMPlatform *platform,
+ int ifindex,
+ char **out_driver_name,
+ char **out_driver_version,
+ char **out_fw_version)
+{
+ return ethtool_get_driver_info (nm_platform_link_get_name (platform, ifindex),
+ out_driver_name,
+ out_driver_version,
+ out_fw_version);
+}
+
/******************************************************************/
static gboolean
@@ -4762,6 +4793,7 @@ nm_linux_platform_class_init (NMLinuxPlatformClass *klass)
platform_class->link_get_physical_port_id = link_get_physical_port_id;
platform_class->link_get_dev_id = link_get_dev_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 9ce677ee18..c1d2f4a184 100644
--- a/src/platform/nm-platform.c
+++ b/src/platform/nm-platform.c
@@ -1244,6 +1244,38 @@ nm_platform_link_get_wake_on_lan (NMPlatform *self, int ifindex)
}
/**
+ * nm_platform_link_get_driver_info:
+ * @self: platform instance
+ * @ifindex: Interface index
+ * @out_driver_name: (transfer full): on success, the driver name if available
+ * @out_driver_version: (transfer full): on success, the driver version if available
+ * @out_fw_version: (transfer full): on success, the firmware version if available
+ *
+ * Returns: %TRUE on success (though @out_driver_name, @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 (NMPlatform *self,
+ int ifindex,
+ char **out_driver_name,
+ char **out_driver_version,
+ char **out_fw_version)
+{
+ _CHECK_SELF (self, klass, FALSE);
+ reset_error (self);
+
+ 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 (self,
+ ifindex,
+ out_driver_name,
+ out_driver_version,
+ out_fw_version);
+}
+
+/**
* nm_platform_link_enslave:
* @self: platform instance
* @master: Interface index of the master
diff --git a/src/platform/nm-platform.h b/src/platform/nm-platform.h
index 6d8d1cfede..bec976ab5b 100644
--- a/src/platform/nm-platform.h
+++ b/src/platform/nm-platform.h
@@ -412,6 +412,11 @@ typedef struct {
char * (*link_get_physical_port_id) (NMPlatform *, int ifindex);
guint (*link_get_dev_id) (NMPlatform *, int ifindex);
gboolean (*link_get_wake_on_lan) (NMPlatform *, int ifindex);
+ gboolean (*link_get_driver_info) (NMPlatform *,
+ int ifindex,
+ char **out_driver_name,
+ char **out_driver_version,
+ char **out_fw_version);
gboolean (*link_supports_carrier_detect) (NMPlatform *, int ifindex);
gboolean (*link_supports_vlans) (NMPlatform *, int ifindex);
@@ -569,6 +574,11 @@ gboolean nm_platform_link_set_mtu (NMPlatform *self, int ifindex, guint32 mtu);
char *nm_platform_link_get_physical_port_id (NMPlatform *self, int ifindex);
guint nm_platform_link_get_dev_id (NMPlatform *self, int ifindex);
gboolean nm_platform_link_get_wake_on_lan (NMPlatform *self, int ifindex);
+gboolean nm_platform_link_get_driver_info (NMPlatform *self,
+ int ifindex,
+ char **out_driver_name,
+ char **out_driver_version,
+ char **out_fw_version);
gboolean nm_platform_link_supports_carrier_detect (NMPlatform *self, int ifindex);
gboolean nm_platform_link_supports_vlans (NMPlatform *self, int ifindex);