devices: make constructors take an NMPlatformLink

Rather than passing UDI, ifname, and driver name to the device
constructors as separate arguments, just pass the NMPlatformLink
instead and let it parse them out.

Virtual types still take UDI and ifname separately, since we create
fake NMDevices for them for autoactivating connections. That's weird
in other ways too though, so perhaps this should be revisted.
This commit is contained in:
Dan Winship 2013-05-29 12:57:13 -03:00
parent 05216f67d6
commit b322c0dc81
27 changed files with 111 additions and 153 deletions

View file

@ -321,18 +321,12 @@ take_down (NMDevice *dev)
}
NMDevice *
nm_device_ethernet_new (const char *udi,
const char *iface,
const char *driver)
nm_device_ethernet_new (NMPlatformLink *platform_device)
{
g_return_val_if_fail (udi != NULL, NULL);
g_return_val_if_fail (iface != NULL, NULL);
g_return_val_if_fail (driver != NULL, NULL);
g_return_val_if_fail (platform_device != NULL, NULL);
return (NMDevice *) g_object_new (NM_TYPE_DEVICE_ETHERNET,
NM_DEVICE_UDI, udi,
NM_DEVICE_IFACE, iface,
NM_DEVICE_DRIVER, driver,
NM_DEVICE_PLATFORM_DEVICE, platform_device,
NM_DEVICE_TYPE_DESC, "Ethernet",
NM_DEVICE_DEVICE_TYPE, NM_DEVICE_TYPE_ETHERNET,
NULL);

View file

@ -58,9 +58,7 @@ typedef struct {
GType nm_device_ethernet_get_type (void);
NMDevice *nm_device_ethernet_new (const char *udi,
const char *iface,
const char *driver);
NMDevice *nm_device_ethernet_new (NMPlatformLink *platform_device);
G_END_DECLS

View file

@ -25,6 +25,7 @@
#include <glib-object.h>
#include "NetworkManager.h"
#include "nm-platform.h"
/* WARNING: this file is private API between NetworkManager and its internal
* device plugins. Its API can change at any time and is not guaranteed to be
@ -49,15 +50,11 @@
*
* Returns: the device object (a subclass of #NMDevice) or %NULL
*/
GObject *nm_device_factory_create_device (const char *devpath,
const char *ifname,
const char *driver,
GObject *nm_device_factory_create_device (NMPlatformLink *platform_device,
GError **error);
/* Should match nm_device_factory() */
typedef GObject * (*NMDeviceFactoryCreateFunc) (const char *devpath,
const char *ifname,
const char *driver,
typedef GObject * (*NMDeviceFactoryCreateFunc) (NMPlatformLink *platform_device,
GError **error);
/**

View file

@ -104,16 +104,12 @@ check_connection_compatible (NMDevice *device,
/**************************************************************/
NMDevice *
nm_device_generic_new (const char *udi,
const char *iface,
const char *driver)
nm_device_generic_new (NMPlatformLink *platform_device)
{
g_return_val_if_fail (udi != NULL, NULL);
g_return_val_if_fail (platform_device != NULL, NULL);
return (NMDevice *) g_object_new (NM_TYPE_DEVICE_GENERIC,
NM_DEVICE_UDI, udi,
NM_DEVICE_IFACE, iface,
NM_DEVICE_DRIVER, driver,
NM_DEVICE_PLATFORM_DEVICE, platform_device,
NM_DEVICE_TYPE_DESC, "Generic",
NM_DEVICE_DEVICE_TYPE, NM_DEVICE_TYPE_GENERIC,
NULL);

View file

@ -54,9 +54,7 @@ typedef struct {
GType nm_device_generic_get_type (void);
NMDevice *nm_device_generic_new (const char *udi,
const char *iface,
const char *driver);
NMDevice *nm_device_generic_new (NMPlatformLink *platform_device);
G_END_DECLS

View file

@ -23,6 +23,7 @@
#include <string.h>
#include "nm-device-gre.h"
#include "nm-device-private.h"
#include "nm-dbus-manager.h"
#include "nm-logging.h"
#include "nm-manager.h"
@ -108,16 +109,12 @@ link_changed (NMDevice *device)
/**************************************************************/
NMDevice *
nm_device_gre_new (const char *udi,
const char *iface,
const char *driver)
nm_device_gre_new (NMPlatformLink *platform_device)
{
g_return_val_if_fail (udi != NULL, NULL);
g_return_val_if_fail (platform_device != NULL, NULL);
return (NMDevice *) g_object_new (NM_TYPE_DEVICE_GRE,
NM_DEVICE_UDI, udi,
NM_DEVICE_IFACE, iface,
NM_DEVICE_DRIVER, driver,
NM_DEVICE_PLATFORM_DEVICE, platform_device,
NM_DEVICE_TYPE_DESC, "Gre",
NM_DEVICE_DEVICE_TYPE, NM_DEVICE_TYPE_GENERIC,
NULL);

View file

@ -56,9 +56,7 @@ typedef struct {
GType nm_device_gre_get_type (void);
NMDevice *nm_device_gre_new (const char *udi,
const char *iface,
const char *driver);
NMDevice *nm_device_gre_new (NMPlatformLink *platform_device);
G_END_DECLS

View file

@ -93,18 +93,12 @@ nm_device_infiniband_init (NMDeviceInfiniband * self)
}
NMDevice *
nm_device_infiniband_new (const char *udi,
const char *iface,
const char *driver)
nm_device_infiniband_new (NMPlatformLink *platform_device)
{
g_return_val_if_fail (udi != NULL, NULL);
g_return_val_if_fail (iface != NULL, NULL);
g_return_val_if_fail (driver != NULL, NULL);
g_return_val_if_fail (platform_device != NULL, NULL);
return (NMDevice *) g_object_new (NM_TYPE_DEVICE_INFINIBAND,
NM_DEVICE_UDI, udi,
NM_DEVICE_IFACE, iface,
NM_DEVICE_DRIVER, driver,
NM_DEVICE_PLATFORM_DEVICE, platform_device,
NM_DEVICE_TYPE_DESC, "InfiniBand",
NM_DEVICE_DEVICE_TYPE, NM_DEVICE_TYPE_INFINIBAND,
NULL);

View file

@ -52,9 +52,7 @@ typedef struct {
GType nm_device_infiniband_get_type (void);
NMDevice *nm_device_infiniband_new (const char *udi,
const char *iface,
const char *driver);
NMDevice *nm_device_infiniband_new (NMPlatformLink *platform_device);
G_END_DECLS

View file

@ -23,6 +23,7 @@
#include <string.h>
#include "nm-device-macvlan.h"
#include "nm-device-private.h"
#include "nm-dbus-manager.h"
#include "nm-logging.h"
#include "nm-manager.h"
@ -88,16 +89,12 @@ link_changed (NMDevice *device)
/**************************************************************/
NMDevice *
nm_device_macvlan_new (const char *udi,
const char *iface,
const char *driver)
nm_device_macvlan_new (NMPlatformLink *platform_device)
{
g_return_val_if_fail (udi != NULL, NULL);
g_return_val_if_fail (platform_device != NULL, NULL);
return (NMDevice *) g_object_new (NM_TYPE_DEVICE_MACVLAN,
NM_DEVICE_UDI, udi,
NM_DEVICE_IFACE, iface,
NM_DEVICE_DRIVER, driver,
NM_DEVICE_PLATFORM_DEVICE, platform_device,
NM_DEVICE_TYPE_DESC, "Macvlan",
NM_DEVICE_DEVICE_TYPE, NM_DEVICE_TYPE_GENERIC,
NULL);

View file

@ -49,9 +49,7 @@ typedef struct {
GType nm_device_macvlan_get_type (void);
NMDevice *nm_device_macvlan_new (const char *udi,
const char *iface,
const char *driver);
NMDevice *nm_device_macvlan_new (NMPlatformLink *platform_device);
G_END_DECLS

View file

@ -707,18 +707,12 @@ state_changed (NMDevice *device, NMDeviceState new_state,
NMDevice *
nm_device_olpc_mesh_new (const char *udi,
const char *iface,
const char *driver)
nm_device_olpc_mesh_new (NMPlatformLink *platform_device)
{
g_return_val_if_fail (udi != NULL, NULL);
g_return_val_if_fail (iface != NULL, NULL);
g_return_val_if_fail (driver != NULL, NULL);
g_return_val_if_fail (platform_device != NULL, NULL);
return (NMDevice *) g_object_new (NM_TYPE_DEVICE_OLPC_MESH,
NM_DEVICE_UDI, udi,
NM_DEVICE_IFACE, iface,
NM_DEVICE_DRIVER, driver,
NM_DEVICE_PLATFORM_DEVICE, platform_device,
NM_DEVICE_TYPE_DESC, "802.11 OLPC Mesh",
NM_DEVICE_DEVICE_TYPE, NM_DEVICE_TYPE_OLPC_MESH,
NULL);

View file

@ -75,9 +75,7 @@ struct _NMDeviceOlpcMeshClass
GType nm_device_olpc_mesh_get_type (void);
NMDevice *nm_device_olpc_mesh_new (const char *udi,
const char *iface,
const char *driver);
NMDevice *nm_device_olpc_mesh_new (NMPlatformLink *platform_device);
G_END_DECLS

View file

@ -26,6 +26,8 @@
/* This file should only be used by subclasses of NMDevice */
#define NM_DEVICE_PLATFORM_DEVICE "platform-device"
enum NMActStageReturn {
NM_ACT_STAGE_RETURN_FAILURE = 0,
NM_ACT_STAGE_RETURN_SUCCESS, /* Activation stage done */

View file

@ -24,6 +24,7 @@
#include <string.h>
#include "nm-device-tun.h"
#include "nm-device-private.h"
#include "nm-dbus-manager.h"
#include "nm-logging.h"
#include "nm-platform.h"
@ -87,16 +88,12 @@ link_changed (NMDevice *device)
/**************************************************************/
NMDevice *
nm_device_tun_new (const char *udi,
const char *iface,
const char *driver)
nm_device_tun_new (NMPlatformLink *platform_device)
{
g_return_val_if_fail (udi != NULL, NULL);
g_return_val_if_fail (platform_device != NULL, NULL);
return (NMDevice *) g_object_new (NM_TYPE_DEVICE_TUN,
NM_DEVICE_UDI, udi,
NM_DEVICE_IFACE, iface,
NM_DEVICE_DRIVER, driver,
NM_DEVICE_PLATFORM_DEVICE, platform_device,
NM_DEVICE_TYPE_DESC, "Tun",
NM_DEVICE_DEVICE_TYPE, NM_DEVICE_TYPE_GENERIC,
NULL);

View file

@ -52,9 +52,7 @@ typedef struct {
GType nm_device_tun_get_type (void);
NMDevice *nm_device_tun_new (const char *udi,
const char *iface,
const char *driver);
NMDevice *nm_device_tun_new (NMPlatformLink *platform_device);
G_END_DECLS

View file

@ -28,6 +28,7 @@
#include <sys/ioctl.h>
#include "nm-device-veth.h"
#include "nm-device-private.h"
#include "nm-logging.h"
#include "nm-manager.h"
#include "nm-platform.h"
@ -96,16 +97,12 @@ get_peer (NMDeviceVeth *self)
/**************************************************************/
NMDevice *
nm_device_veth_new (const char *udi,
const char *iface,
const char *driver)
nm_device_veth_new (NMPlatformLink *platform_device)
{
g_return_val_if_fail (udi != NULL, NULL);
g_return_val_if_fail (platform_device != NULL, NULL);
return (NMDevice *) g_object_new (NM_TYPE_DEVICE_VETH,
NM_DEVICE_UDI, udi,
NM_DEVICE_IFACE, iface,
NM_DEVICE_DRIVER, driver ? driver : "veth",
NM_DEVICE_PLATFORM_DEVICE, platform_device,
NM_DEVICE_TYPE_DESC, "Veth",
NM_DEVICE_DEVICE_TYPE, NM_DEVICE_TYPE_ETHERNET,
NULL);

View file

@ -47,9 +47,7 @@ typedef struct {
GType nm_device_veth_get_type (void);
NMDevice *nm_device_veth_new (const char *udi,
const char *iface,
const char *driver);
NMDevice *nm_device_veth_new (NMPlatformLink *platform_device);
G_END_DECLS

View file

@ -3504,18 +3504,12 @@ set_enabled (NMDevice *device, gboolean enabled)
/********************************************************************/
NMDevice *
nm_device_wifi_new (const char *udi,
const char *iface,
const char *driver)
nm_device_wifi_new (NMPlatformLink *platform_device)
{
g_return_val_if_fail (udi != NULL, NULL);
g_return_val_if_fail (iface != NULL, NULL);
g_return_val_if_fail (driver != NULL, NULL);
g_return_val_if_fail (platform_device != NULL, NULL);
return (NMDevice *) g_object_new (NM_TYPE_DEVICE_WIFI,
NM_DEVICE_UDI, udi,
NM_DEVICE_IFACE, iface,
NM_DEVICE_DRIVER, driver,
NM_DEVICE_PLATFORM_DEVICE, platform_device,
NM_DEVICE_TYPE_DESC, "802.11 WiFi",
NM_DEVICE_DEVICE_TYPE, NM_DEVICE_TYPE_WIFI,
NM_DEVICE_RFKILL_TYPE, RFKILL_TYPE_WLAN,

View file

@ -89,9 +89,7 @@ struct _NMDeviceWifiClass
GType nm_device_wifi_get_type (void);
NMDevice *nm_device_wifi_new (const char *udi,
const char *iface,
const char *driver);
NMDevice *nm_device_wifi_new (NMPlatformLink *platform_device);
NMAccessPoint * nm_device_wifi_get_activation_ap (NMDeviceWifi *self);

View file

@ -107,6 +107,7 @@ static guint signals[LAST_SIGNAL] = { 0 };
enum {
PROP_0,
PROP_PLATFORM_DEVICE,
PROP_UDI,
PROP_IFACE,
PROP_IP_IFACE,
@ -4702,34 +4703,51 @@ set_property (GObject *object, guint prop_id,
const GValue *value, GParamSpec *pspec)
{
NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (object);
NMPlatformLink *platform_device;
const char *hw_addr;
int hw_addr_type;
switch (prop_id) {
case PROP_UDI:
g_free (priv->udi);
priv->udi = g_strdup (g_value_get_string (value));
break;
case PROP_IFACE:
g_free (priv->iface);
priv->ifindex = 0;
priv->iface = g_value_dup_string (value);
/* Only look up the ifindex if it appears to be an actual kernel
* interface name. eg Bluetooth devices won't have one until we know
* the IP interface.
*/
if (priv->iface && !strchr (priv->iface, ':')) {
priv->ifindex = nm_platform_link_get_ifindex (priv->iface);
if (priv->ifindex <= 0)
nm_log_warn (LOGD_HW, "(%s): failed to look up interface index", priv->iface);
case PROP_PLATFORM_DEVICE:
platform_device = g_value_get_pointer (value);
if (platform_device) {
g_free (priv->udi);
priv->udi = g_strdup (platform_device->udi);
g_free (priv->iface);
priv->iface = g_strdup (platform_device->name);
priv->ifindex = platform_device->ifindex;
g_free (priv->driver);
priv->driver = g_strdup (platform_device->driver);
}
break;
case PROP_IP_IFACE:
case PROP_UDI:
if (g_value_get_string (value)) {
g_free (priv->udi);
priv->udi = g_value_dup_string (value);
}
break;
case PROP_IFACE:
if (g_value_get_string (value)) {
g_free (priv->iface);
priv->ifindex = 0;
priv->iface = g_value_dup_string (value);
/* Only look up the ifindex if it appears to be an actual kernel
* interface name. eg Bluetooth devices won't have one until we know
* the IP interface.
*/
if (priv->iface && !strchr (priv->iface, ':')) {
priv->ifindex = nm_platform_link_get_ifindex (priv->iface);
if (priv->ifindex <= 0)
nm_log_warn (LOGD_HW, "(%s): failed to look up interface index", priv->iface);
}
}
break;
case PROP_DRIVER:
g_free (priv->driver);
priv->driver = g_strdup (g_value_get_string (value));
if (g_value_get_string (value)) {
g_free (priv->driver);
priv->driver = g_value_dup_string (value);
}
break;
case PROP_DRIVER_VERSION:
g_free (priv->driver_version);
@ -4958,6 +4976,13 @@ nm_device_class_init (NMDeviceClass *klass)
klass->can_interrupt_activation = can_interrupt_activation;
/* Properties */
g_object_class_install_property
(object_class, PROP_PLATFORM_DEVICE,
g_param_spec_pointer (NM_DEVICE_PLATFORM_DEVICE,
"Platform Device",
"NMPlatform device object",
G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
g_object_class_install_property
(object_class, PROP_UDI,
g_param_spec_string (NM_DEVICE_UDI,
@ -4980,7 +5005,7 @@ nm_device_class_init (NMDeviceClass *klass)
"IP Interface",
"IP Interface",
NULL,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
G_PARAM_READABLE | G_PARAM_CONSTRUCT_ONLY));
g_object_class_install_property
(object_class, PROP_DRIVER,

View file

@ -36,6 +36,7 @@
#include "nm-connection.h"
#include "nm-rfkill-manager.h"
#include "nm-connection-provider.h"
#include "nm-platform.h"
/* Properties */
#define NM_DEVICE_UDI "udi"

View file

@ -3,6 +3,7 @@ INCLUDES = \
-I${top_builddir}/src \
-I${top_srcdir}/src/logging \
-I${top_srcdir}/src/devices \
-I${top_srcdir}/src/platform \
-I${top_builddir}/include \
-I${top_srcdir}/include \
-I${top_builddir}/libnm-util \

View file

@ -1270,20 +1270,14 @@ wmx_new_sdk_cb (struct wmxsdk *sdk, void *user_data)
/*************************************************************************/
NMDevice *
nm_device_wimax_new (const char *udi,
const char *iface,
const char *driver)
nm_device_wimax_new (NMPlatformLink *platform_device)
{
NMDevice *device;
g_return_val_if_fail (udi != NULL, NULL);
g_return_val_if_fail (iface != NULL, NULL);
g_return_val_if_fail (driver != NULL, NULL);
g_return_val_if_fail (platform_device != NULL, NULL);
device = (NMDevice *) g_object_new (NM_TYPE_DEVICE_WIMAX,
NM_DEVICE_UDI, udi,
NM_DEVICE_IFACE, iface,
NM_DEVICE_DRIVER, driver,
NM_DEVICE_PLATFORM_DEVICE, platform_device,
NM_DEVICE_TYPE_DESC, "WiMAX",
NM_DEVICE_DEVICE_TYPE, NM_DEVICE_TYPE_WIMAX,
NM_DEVICE_RFKILL_TYPE, RFKILL_TYPE_WIMAX,
@ -1294,7 +1288,7 @@ nm_device_wimax_new (const char *udi,
nm_wimax_util_sdk_ref ();
/* See if the SDK already knows about this interface */
sdk = iwmx_sdk_get_wmxsdk_for_iface (iface);
sdk = iwmx_sdk_get_wmxsdk_for_iface (platform_device->name);
if (sdk)
wmx_new_sdk_cb (sdk, device);

View file

@ -65,9 +65,7 @@ typedef struct {
GType nm_device_wimax_get_type (void);
NMDevice *nm_device_wimax_new (const char *udi,
const char *iface,
const char *driver);
NMDevice *nm_device_wimax_new (NMPlatformLink *platform_device);
NMWimaxNsp *nm_device_wimax_get_active_nsp (NMDeviceWimax *self);

View file

@ -24,18 +24,16 @@
#include "nm-device-wimax.h"
G_MODULE_EXPORT GObject *
nm_device_factory_create_device (const char *devpath,
const char *ifname,
const char *driver,
nm_device_factory_create_device (NMPlatformLink *platform_device,
GError **error)
{
/* FIXME: check udev 'DEVTYPE' instead; but since we only support Intel
* WiMAX devices for now this is appropriate.
*/
if (g_strcmp0 (driver, "i2400m_usb") != 0)
if (g_strcmp0 (platform_device->driver, "i2400m_usb") != 0)
return NULL; /* unsupported */
return (GObject *) nm_device_wimax_new (devpath, ifname, driver);
return (GObject *) nm_device_wimax_new (platform_device);
}
G_MODULE_EXPORT guint32

View file

@ -2199,7 +2199,7 @@ platform_link_added_cb (NMPlatform *platform,
NMDeviceFactoryCreateFunc create_func = iter->data;
g_clear_error (&error);
device = (NMDevice *) create_func (link->udi, link->name, link->driver, &error);
device = (NMDevice *) create_func (link, &error);
if (device && NM_IS_DEVICE (device)) {
g_assert_no_error (error);
break; /* success! */
@ -2221,16 +2221,16 @@ platform_link_added_cb (NMPlatform *platform,
switch (link->type) {
case NM_LINK_TYPE_ETHERNET:
device = nm_device_ethernet_new (link->udi, link->name, link->driver);
device = nm_device_ethernet_new (link);
break;
case NM_LINK_TYPE_INFINIBAND:
device = nm_device_infiniband_new (link->udi, link->name, link->driver);
device = nm_device_infiniband_new (link);
break;
case NM_LINK_TYPE_OLPC_MESH:
device = nm_device_olpc_mesh_new (link->udi, link->name, link->driver);
device = nm_device_olpc_mesh_new (link);
break;
case NM_LINK_TYPE_WIFI:
device = nm_device_wifi_new (link->udi, link->name, link->driver);
device = nm_device_wifi_new (link);
break;
case NM_LINK_TYPE_BOND:
device = nm_device_bond_new (link->udi, link->name);
@ -2260,23 +2260,23 @@ platform_link_added_cb (NMPlatform *platform,
nm_log_err (LOGD_HW, "(%s): failed to get VLAN parent ifindex", link->name);
break;
case NM_LINK_TYPE_VETH:
device = nm_device_veth_new (link->udi, link->name, link->driver);
device = nm_device_veth_new (link);
break;
case NM_LINK_TYPE_TUN:
case NM_LINK_TYPE_TAP:
device = nm_device_tun_new (link->udi, link->name, link->driver);
device = nm_device_tun_new (link);
break;
case NM_LINK_TYPE_MACVLAN:
case NM_LINK_TYPE_MACVTAP:
device = nm_device_macvlan_new (link->udi, link->name, link->driver);
device = nm_device_macvlan_new (link);
break;
case NM_LINK_TYPE_GRE:
case NM_LINK_TYPE_GRETAP:
device = nm_device_gre_new (link->udi, link->name, link->driver);
device = nm_device_gre_new (link);
break;
default:
device = nm_device_generic_new (link->udi, link->name, link->driver);
device = nm_device_generic_new (link);
break;
}
}