platform: move driver & firmware version reading into the platform
This commit is contained in:
@@ -28,8 +28,6 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <linux/sockios.h>
|
|
||||||
#include <linux/ethtool.h>
|
|
||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
@@ -8504,46 +8502,6 @@ nm_device_init (NMDevice *self)
|
|||||||
priv->default_route.v6_is_assumed = TRUE;
|
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*
|
static GObject*
|
||||||
constructor (GType type,
|
constructor (GType type,
|
||||||
guint n_construct_params,
|
guint n_construct_params,
|
||||||
@@ -8579,10 +8537,13 @@ constructor (GType type,
|
|||||||
if (NM_DEVICE_GET_CLASS (self)->get_generic_capabilities)
|
if (NM_DEVICE_GET_CLASS (self)->get_generic_capabilities)
|
||||||
priv->capabilities |= NM_DEVICE_GET_CLASS (self)->get_generic_capabilities (self);
|
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))
|
if (priv->ifindex > 0) {
|
||||||
_LOGW (LOGD_HW, "failed to look up interface index");
|
nm_platform_link_get_driver_info (NM_PLATFORM_GET,
|
||||||
|
priv->ifindex,
|
||||||
device_get_driver_info (self, priv->iface, &priv->driver_version, &priv->firmware_version);
|
NULL,
|
||||||
|
&priv->driver_version,
|
||||||
|
&priv->firmware_version);
|
||||||
|
}
|
||||||
|
|
||||||
/* Watch for external IP config changes */
|
/* Watch for external IP config changes */
|
||||||
platform = nm_platform_get ();
|
platform = nm_platform_get ();
|
||||||
|
@@ -502,6 +502,26 @@ link_get_wake_on_lan (NMPlatform *platform, int ifindex)
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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
|
static gboolean
|
||||||
link_supports_carrier_detect (NMPlatform *platform, int ifindex)
|
link_supports_carrier_detect (NMPlatform *platform, int 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_physical_port_id = link_get_physical_port_id;
|
||||||
platform_class->link_get_dev_id = link_get_dev_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_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_carrier_detect = link_supports_carrier_detect;
|
||||||
platform_class->link_supports_vlans = link_supports_vlans;
|
platform_class->link_supports_vlans = link_supports_vlans;
|
||||||
|
@@ -372,6 +372,9 @@ ethtool_get (const char *name, gpointer edata)
|
|||||||
struct ifreq ifr;
|
struct ifreq ifr;
|
||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
|
if (!name || !*name)
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
memset (&ifr, 0, sizeof (ifr));
|
memset (&ifr, 0, sizeof (ifr));
|
||||||
strncpy (ifr.ifr_name, name, IFNAMSIZ);
|
strncpy (ifr.ifr_name, name, IFNAMSIZ);
|
||||||
ifr.ifr_data = edata;
|
ifr.ifr_data = edata;
|
||||||
@@ -426,21 +429,29 @@ ethtool_get_stringset_index (const char *ifname, int stringset_id, const char *s
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char *
|
static gboolean
|
||||||
ethtool_get_driver (const char *ifname)
|
ethtool_get_driver_info (const char *ifname,
|
||||||
|
char **out_driver_name,
|
||||||
|
char **out_driver_version,
|
||||||
|
char **out_fw_version)
|
||||||
{
|
{
|
||||||
struct ethtool_drvinfo drvinfo = { 0 };
|
struct ethtool_drvinfo drvinfo = { 0 };
|
||||||
|
|
||||||
g_return_val_if_fail (ifname != NULL, NULL);
|
if (!ifname)
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
drvinfo.cmd = ETHTOOL_GDRVINFO;
|
drvinfo.cmd = ETHTOOL_GDRVINFO;
|
||||||
if (!ethtool_get (ifname, &drvinfo))
|
if (!ethtool_get (ifname, &drvinfo))
|
||||||
return NULL;
|
return FALSE;
|
||||||
|
|
||||||
if (!*drvinfo.driver)
|
if (out_driver_name)
|
||||||
return NULL;
|
*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);
|
ifname = rtnl_link_get_name (rtnllink);
|
||||||
if (ifname) {
|
if (ifname) {
|
||||||
const char *driver = ethtool_get_driver (ifname);
|
gs_free char *driver = NULL;
|
||||||
gs_free char *sysfs_path = NULL;
|
gs_free char *sysfs_path = NULL;
|
||||||
gs_free char *anycast_mask = NULL;
|
gs_free char *anycast_mask = NULL;
|
||||||
gs_free char *devtype = 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 */
|
/* Fallback OVS detection for kernel <= 3.16 */
|
||||||
if (!g_strcmp0 (driver, "openvswitch"))
|
if (ethtool_get_driver_info (ifname, &driver, NULL, NULL)) {
|
||||||
return NM_LINK_TYPE_OPENVSWITCH;
|
if (!g_strcmp0 (driver, "openvswitch"))
|
||||||
|
return NM_LINK_TYPE_OPENVSWITCH;
|
||||||
|
}
|
||||||
|
|
||||||
sysfs_path = g_strdup_printf ("/sys/class/net/%s", ifname);
|
sysfs_path = g_strdup_printf ("/sys/class/net/%s", ifname);
|
||||||
anycast_mask = g_strdup_printf ("%s/anycast_mask", sysfs_path);
|
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);
|
NMLinuxPlatformPrivate *priv = NM_LINUX_PLATFORM_GET_PRIVATE (platform);
|
||||||
GUdevDevice *udev_device;
|
GUdevDevice *udev_device;
|
||||||
const char *name;
|
const char *name;
|
||||||
|
char *tmp;
|
||||||
|
|
||||||
g_return_val_if_fail (rtnllink, FALSE);
|
g_return_val_if_fail (rtnllink, FALSE);
|
||||||
|
|
||||||
@@ -1070,8 +1084,12 @@ init_link (NMPlatform *platform, NMPlatformLink *info, struct rtnl_link *rtnllin
|
|||||||
|
|
||||||
if (!info->driver)
|
if (!info->driver)
|
||||||
info->driver = info->kind;
|
info->driver = info->kind;
|
||||||
if (!info->driver)
|
if (!info->driver) {
|
||||||
info->driver = ethtool_get_driver (info->name);
|
if (ethtool_get_driver_info (name, &tmp, NULL, NULL)) {
|
||||||
|
info->driver = g_intern_string (tmp);
|
||||||
|
g_free (tmp);
|
||||||
|
}
|
||||||
|
}
|
||||||
if (!info->driver)
|
if (!info->driver)
|
||||||
info->driver = "unknown";
|
info->driver = "unknown";
|
||||||
|
|
||||||
@@ -3658,6 +3676,19 @@ link_get_wake_on_lan (NMPlatform *platform, int ifindex)
|
|||||||
return FALSE;
|
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
|
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_physical_port_id = link_get_physical_port_id;
|
||||||
platform_class->link_get_dev_id = link_get_dev_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_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_carrier_detect = link_supports_carrier_detect;
|
||||||
platform_class->link_supports_vlans = link_supports_vlans;
|
platform_class->link_supports_vlans = link_supports_vlans;
|
||||||
|
@@ -1241,6 +1241,38 @@ nm_platform_link_get_wake_on_lan (NMPlatform *self, int ifindex)
|
|||||||
return klass->link_get_wake_on_lan (self, ifindex);
|
return klass->link_get_wake_on_lan (self, 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:
|
* nm_platform_link_enslave:
|
||||||
* @self: platform instance
|
* @self: platform instance
|
||||||
|
@@ -412,6 +412,11 @@ typedef struct {
|
|||||||
char * (*link_get_physical_port_id) (NMPlatform *, int ifindex);
|
char * (*link_get_physical_port_id) (NMPlatform *, int ifindex);
|
||||||
guint (*link_get_dev_id) (NMPlatform *, int ifindex);
|
guint (*link_get_dev_id) (NMPlatform *, int ifindex);
|
||||||
gboolean (*link_get_wake_on_lan) (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_carrier_detect) (NMPlatform *, int ifindex);
|
||||||
gboolean (*link_supports_vlans) (NMPlatform *, int ifindex);
|
gboolean (*link_supports_vlans) (NMPlatform *, int ifindex);
|
||||||
@@ -570,6 +575,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);
|
char *nm_platform_link_get_physical_port_id (NMPlatform *self, int ifindex);
|
||||||
guint nm_platform_link_get_dev_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_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_carrier_detect (NMPlatform *self, int ifindex);
|
||||||
gboolean nm_platform_link_supports_vlans (NMPlatform *self, int ifindex);
|
gboolean nm_platform_link_supports_vlans (NMPlatform *self, int ifindex);
|
||||||
|
Reference in New Issue
Block a user