core: let plugins indicate links which should be ignored

Instead of hacky stuff in the Manager, let plugins themselves indicate
which links should be ignored (because they are really child links that
are controlled by a different device that the plugin handles).

(cherry picked from commit 8fa0f4690f)
This commit is contained in:
Dan Williams 2015-05-06 09:53:44 -05:00 committed by Thomas Haller
parent d5e0a6ff86
commit ed0c228187
18 changed files with 51 additions and 28 deletions

View file

@ -38,6 +38,7 @@
#include "nm-device-bt.h"
#include "nm-dbus-manager.h"
#include "nm-platform.h"
typedef struct {
int bluez_version;
@ -370,6 +371,7 @@ start (NMDeviceFactory *factory)
}
NM_DEVICE_FACTORY_DECLARE_TYPES (
NM_DEVICE_FACTORY_DECLARE_LINK_TYPES (NM_LINK_TYPE_BNEP)
NM_DEVICE_FACTORY_DECLARE_SETTING_TYPES (NM_SETTING_BLUETOOTH_SETTING_NAME)
)
@ -404,10 +406,19 @@ nm_bluez_manager_init (NMBluezManager *self)
g_assert (priv->provider);
}
static NMDevice *
new_link (NMDeviceFactory *factory, NMPlatformLink *plink, gboolean *out_ignore, GError **error)
{
g_warn_if_fail (plink->type == NM_LINK_TYPE_BNEP);
*out_ignore = TRUE;
return NULL;
}
static void
device_factory_interface_init (NMDeviceFactory *factory_iface)
{
factory_iface->get_supported_types = get_supported_types;
factory_iface->new_link = new_link;
factory_iface->start = start;
}

View file

@ -555,7 +555,7 @@ nm_device_bond_class_init (NMDeviceBondClass *klass)
#define NM_BOND_FACTORY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_BOND_FACTORY, NMBondFactory))
static NMDevice *
new_link (NMDeviceFactory *factory, NMPlatformLink *plink, GError **error)
new_link (NMDeviceFactory *factory, NMPlatformLink *plink, gboolean *out_ignore, GError **error)
{
return (NMDevice *) g_object_new (NM_TYPE_DEVICE_BOND,
NM_DEVICE_PLATFORM_DEVICE, plink,

View file

@ -478,7 +478,7 @@ nm_device_bridge_class_init (NMDeviceBridgeClass *klass)
#define NM_BRIDGE_FACTORY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_BRIDGE_FACTORY, NMBridgeFactory))
static NMDevice *
new_link (NMDeviceFactory *factory, NMPlatformLink *plink, GError **error)
new_link (NMDeviceFactory *factory, NMPlatformLink *plink, gboolean *out_ignore, GError **error)
{
return (NMDevice *) g_object_new (NM_TYPE_DEVICE_BRIDGE,
NM_DEVICE_PLATFORM_DEVICE, plink,

View file

@ -1693,7 +1693,7 @@ nm_device_ethernet_class_init (NMDeviceEthernetClass *klass)
#define NM_ETHERNET_FACTORY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_ETHERNET_FACTORY, NMEthernetFactory))
static NMDevice *
new_link (NMDeviceFactory *factory, NMPlatformLink *plink, GError **error)
new_link (NMDeviceFactory *factory, NMPlatformLink *plink, gboolean *out_ignore, GError **error)
{
return (NMDevice *) g_object_new (NM_TYPE_DEVICE_ETHERNET,
NM_DEVICE_PLATFORM_DEVICE, plink,

View file

@ -81,6 +81,7 @@ nm_device_factory_start (NMDeviceFactory *factory)
NMDevice *
nm_device_factory_new_link (NMDeviceFactory *factory,
NMPlatformLink *plink,
gboolean *out_ignore,
GError **error)
{
NMDeviceFactory *interface;
@ -114,7 +115,7 @@ nm_device_factory_new_link (NMDeviceFactory *factory,
return NULL;
}
return interface->new_link (factory, plink, error);
return interface->new_link (factory, plink, out_ignore, error);
}
NMDevice *

View file

@ -93,6 +93,7 @@ struct _NMDeviceFactory {
* new_link:
* @factory: the #NMDeviceFactory
* @plink: the new link
* @out_ignore: on return, %TRUE if the link should be ignored
* @error: error if the link could be claimed but an error occurred
*
* The NetworkManager core was notified of a new link which the plugin
@ -101,6 +102,9 @@ struct _NMDeviceFactory {
* is supported but the device could not be created, %NULL should be
* returned and @error should be set.
*
* If the plugin cannot create a #NMDevice for the link and wants the
* core to ignore it, set @out_ignore to %TRUE and return no error.
*
* @plink is guaranteed to be one of the types the factory returns in
* get_supported_types().
*
@ -108,6 +112,7 @@ struct _NMDeviceFactory {
*/
NMDevice * (*new_link) (NMDeviceFactory *factory,
NMPlatformLink *plink,
gboolean *out_ignore,
GError **error);
/**
@ -201,6 +206,7 @@ void nm_device_factory_start (NMDeviceFactory *factory);
NMDevice * nm_device_factory_new_link (NMDeviceFactory *factory,
NMPlatformLink *plink,
gboolean *out_ignore,
GError **error);
NMDevice * nm_device_factory_create_virtual_device_for_connection (NMDeviceFactory *factory,

View file

@ -267,7 +267,7 @@ nm_device_gre_class_init (NMDeviceGreClass *klass)
#define NM_GRE_FACTORY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_GRE_FACTORY, NMGreFactory))
static NMDevice *
new_link (NMDeviceFactory *factory, NMPlatformLink *plink, GError **error)
new_link (NMDeviceFactory *factory, NMPlatformLink *plink, gboolean *out_ignore, GError **error)
{
return (NMDevice *) g_object_new (NM_TYPE_DEVICE_GRE,
NM_DEVICE_PLATFORM_DEVICE, plink,

View file

@ -293,7 +293,7 @@ nm_device_infiniband_class_init (NMDeviceInfinibandClass *klass)
#define NM_INFINIBAND_FACTORY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_INFINIBAND_FACTORY, NMInfinibandFactory))
static NMDevice *
new_link (NMDeviceFactory *factory, NMPlatformLink *plink, GError **error)
new_link (NMDeviceFactory *factory, NMPlatformLink *plink, gboolean *out_ignore, GError **error)
{
return (NMDevice *) g_object_new (NM_TYPE_DEVICE_INFINIBAND,
NM_DEVICE_PLATFORM_DEVICE, plink,

View file

@ -175,7 +175,7 @@ nm_device_macvlan_class_init (NMDeviceMacvlanClass *klass)
#define NM_MACVLAN_FACTORY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_MACVLAN_FACTORY, NMMacvlanFactory))
static NMDevice *
new_link (NMDeviceFactory *factory, NMPlatformLink *plink, GError **error)
new_link (NMDeviceFactory *factory, NMPlatformLink *plink, gboolean *out_ignore, GError **error)
{
return (NMDevice *) g_object_new (NM_TYPE_DEVICE_MACVLAN,
NM_DEVICE_PLATFORM_DEVICE, plink,

View file

@ -270,7 +270,7 @@ nm_device_tun_class_init (NMDeviceTunClass *klass)
#define NM_TUN_FACTORY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_TUN_FACTORY, NMTunFactory))
static NMDevice *
new_link (NMDeviceFactory *factory, NMPlatformLink *plink, GError **error)
new_link (NMDeviceFactory *factory, NMPlatformLink *plink, gboolean *out_ignore, GError **error)
{
const char *mode = NULL;

View file

@ -165,7 +165,7 @@ nm_device_veth_class_init (NMDeviceVethClass *klass)
#define NM_VETH_FACTORY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_VETH_FACTORY, NMVethFactory))
static NMDevice *
new_link (NMDeviceFactory *factory, NMPlatformLink *plink, GError **error)
new_link (NMDeviceFactory *factory, NMPlatformLink *plink, gboolean *out_ignore, GError **error)
{
return (NMDevice *) g_object_new (NM_TYPE_DEVICE_VETH,
NM_DEVICE_PLATFORM_DEVICE, plink,

View file

@ -628,7 +628,7 @@ nm_device_vlan_class_init (NMDeviceVlanClass *klass)
#define NM_VLAN_FACTORY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_VLAN_FACTORY, NMVlanFactory))
static NMDevice *
new_link (NMDeviceFactory *factory, NMPlatformLink *plink, GError **error)
new_link (NMDeviceFactory *factory, NMPlatformLink *plink, gboolean *out_ignore, GError **error)
{
int parent_ifindex = -1;
NMDevice *parent, *device;

View file

@ -353,7 +353,7 @@ nm_device_vxlan_class_init (NMDeviceVxlanClass *klass)
#define NM_VXLAN_FACTORY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_VXLAN_FACTORY, NMVxlanFactory))
static NMDevice *
new_link (NMDeviceFactory *factory, NMPlatformLink *plink, GError **error)
new_link (NMDeviceFactory *factory, NMPlatformLink *plink, gboolean *out_ignore, GError **error)
{
return (NMDevice *) g_object_new (NM_TYPE_DEVICE_VXLAN,
NM_DEVICE_PLATFORM_DEVICE, plink,

View file

@ -48,7 +48,7 @@ nm_device_factory_create (GError **error)
/************************************************************************/
static NMDevice *
new_link (NMDeviceFactory *factory, NMPlatformLink *plink, GError **error)
new_link (NMDeviceFactory *factory, NMPlatformLink *plink, gboolean *out_ignore, GError **error)
{
return nm_device_team_new (plink);
}

View file

@ -59,7 +59,7 @@ nm_device_factory_create (GError **error)
/**************************************************************************/
static NMDevice *
new_link (NMDeviceFactory *factory, NMPlatformLink *plink, GError **error)
new_link (NMDeviceFactory *factory, NMPlatformLink *plink, gboolean *out_ignore, GError **error)
{
if (plink->type == NM_LINK_TYPE_WIFI)
return nm_device_wifi_new (plink);

View file

@ -56,7 +56,7 @@ nm_device_factory_create (GError **error)
/**************************************************************************/
static NMDevice *
new_link (NMDeviceFactory *factory, NMPlatformLink *plink, GError **error)
new_link (NMDeviceFactory *factory, NMPlatformLink *plink, gboolean *out_ignore, GError **error)
{
/* FIXME: check udev 'DEVTYPE' instead; but since we only support Intel
* WiMAX devices for now this is appropriate.

View file

@ -30,6 +30,7 @@
#include "nm-modem-manager.h"
#include "nm-device-modem.h"
#include "nm-logging.h"
#include "nm-platform.h"
static GType nm_wwan_factory_get_type (void);
@ -94,6 +95,14 @@ NM_DEVICE_FACTORY_DECLARE_TYPES (
NM_DEVICE_FACTORY_DECLARE_SETTING_TYPES (NM_SETTING_GSM_SETTING_NAME, NM_SETTING_CDMA_SETTING_NAME)
)
static NMDevice *
new_link (NMDeviceFactory *factory, NMPlatformLink *plink, gboolean *out_ignore, GError **error)
{
g_warn_if_fail (plink->type == NM_LINK_TYPE_WWAN_ETHERNET);
*out_ignore = TRUE;
return NULL;
}
static void
start (NMDeviceFactory *factory)
{
@ -117,6 +126,7 @@ static void
device_factory_interface_init (NMDeviceFactory *factory_iface)
{
factory_iface->get_supported_types = get_supported_types;
factory_iface->new_link = new_link;
factory_iface->start = start;
}

View file

@ -1910,20 +1910,18 @@ platform_link_added (NMManager *self,
if (nm_manager_get_device_by_ifindex (self, ifindex))
return;
/* Ignore Bluetooth PAN interfaces; they are handled by their NMDeviceBt
* parent and don't get a separate interface.
*/
if (plink->type == NM_LINK_TYPE_BNEP)
return;
/* Try registered device factories */
factory = nm_device_factory_manager_find_factory_for_link_type (plink->type);
if (factory) {
device = nm_device_factory_new_link (factory, plink, &error);
gboolean ignore = FALSE;
device = nm_device_factory_new_link (factory, plink, &ignore, &error);
if (!device) {
nm_log_warn (LOGD_HW, "%s: factory failed to create device: %s",
plink->name, error->message);
g_clear_error (&error);
if (!ignore) {
nm_log_warn (LOGD_HW, "%s: factory failed to create device: %s",
plink->name, error->message);
g_clear_error (&error);
}
return;
}
}
@ -1931,10 +1929,7 @@ platform_link_added (NMManager *self,
if (device == NULL) {
switch (plink->type) {
case NM_LINK_TYPE_WWAN_ETHERNET:
/* WWAN pseudo-ethernet interfaces are handled automatically by
* their NMDeviceModem and don't get a separate NMDevice object.
*/
break;
case NM_LINK_TYPE_BNEP:
case NM_LINK_TYPE_OLPC_MESH:
case NM_LINK_TYPE_TEAM:
case NM_LINK_TYPE_WIFI: