summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Williams <dcbw@redhat.com>2015-04-07 12:32:55 -0500
committerThomas Haller <thaller@redhat.com>2015-04-29 10:12:21 +0200
commit5353faa2dfccfdbc3414803ce9f44881fcf7ac9a (patch)
tree99b807adbff26c09e88c1c13778dbb7b87b3f56d
parent1fc4a04ee2de610e5519edb6b686888004d32993 (diff)
downloadNetworkManager-5353faa2dfccfdbc3414803ce9f44881fcf7ac9a.tar.gz
fixup! core: let device plugins advertise supported link and setting types
Always return either a device or an error from nm_device_factory_new_link()
-rw-r--r--src/devices/nm-device-bond.c17
-rw-r--r--src/devices/nm-device-bridge.c17
-rw-r--r--src/devices/nm-device-ethernet.c13
-rw-r--r--src/devices/nm-device-factory.c33
-rw-r--r--src/devices/nm-device-factory.h12
-rw-r--r--src/devices/nm-device-gre.c13
-rw-r--r--src/devices/nm-device-infiniband.c13
-rw-r--r--src/devices/nm-device-macvlan.c13
-rw-r--r--src/devices/nm-device-tun.c6
-rw-r--r--src/devices/nm-device-veth.c13
-rw-r--r--src/devices/nm-device-vlan.c20
-rw-r--r--src/devices/nm-device-vxlan.c13
-rw-r--r--src/devices/team/nm-device-team.c2
-rw-r--r--src/devices/team/nm-team-factory.c4
-rw-r--r--src/devices/wifi/nm-wifi-factory.c2
-rw-r--r--src/nm-manager.c10
16 files changed, 95 insertions, 106 deletions
diff --git a/src/devices/nm-device-bond.c b/src/devices/nm-device-bond.c
index df40d2a4f0..3356125b7c 100644
--- a/src/devices/nm-device-bond.c
+++ b/src/devices/nm-device-bond.c
@@ -555,16 +555,13 @@ nm_device_bond_class_init (NMDeviceBondClass *klass)
static NMDevice *
new_link (NMDeviceFactory *factory, NMPlatformLink *plink, GError **error)
{
- if (plink->type == NM_LINK_TYPE_BOND) {
- return (NMDevice *) g_object_new (NM_TYPE_DEVICE_BOND,
- NM_DEVICE_PLATFORM_DEVICE, plink,
- NM_DEVICE_DRIVER, "bonding",
- NM_DEVICE_TYPE_DESC, "Bond",
- NM_DEVICE_DEVICE_TYPE, NM_DEVICE_TYPE_BOND,
- NM_DEVICE_IS_MASTER, TRUE,
- NULL);
- }
- return NULL;
+ return (NMDevice *) g_object_new (NM_TYPE_DEVICE_BOND,
+ NM_DEVICE_PLATFORM_DEVICE, plink,
+ NM_DEVICE_DRIVER, "bonding",
+ NM_DEVICE_TYPE_DESC, "Bond",
+ NM_DEVICE_DEVICE_TYPE, NM_DEVICE_TYPE_BOND,
+ NM_DEVICE_IS_MASTER, TRUE,
+ NULL);
}
static NMDevice *
diff --git a/src/devices/nm-device-bridge.c b/src/devices/nm-device-bridge.c
index b052a62993..f5219b02dd 100644
--- a/src/devices/nm-device-bridge.c
+++ b/src/devices/nm-device-bridge.c
@@ -479,16 +479,13 @@ nm_device_bridge_class_init (NMDeviceBridgeClass *klass)
static NMDevice *
new_link (NMDeviceFactory *factory, NMPlatformLink *plink, GError **error)
{
- if (plink->type == NM_LINK_TYPE_BRIDGE) {
- return (NMDevice *) g_object_new (NM_TYPE_DEVICE_BRIDGE,
- NM_DEVICE_PLATFORM_DEVICE, plink,
- NM_DEVICE_DRIVER, "bridge",
- NM_DEVICE_TYPE_DESC, "Bridge",
- NM_DEVICE_DEVICE_TYPE, NM_DEVICE_TYPE_BRIDGE,
- NM_DEVICE_IS_MASTER, TRUE,
- NULL);
- }
- return NULL;
+ return (NMDevice *) g_object_new (NM_TYPE_DEVICE_BRIDGE,
+ NM_DEVICE_PLATFORM_DEVICE, plink,
+ NM_DEVICE_DRIVER, "bridge",
+ NM_DEVICE_TYPE_DESC, "Bridge",
+ NM_DEVICE_DEVICE_TYPE, NM_DEVICE_TYPE_BRIDGE,
+ NM_DEVICE_IS_MASTER, TRUE,
+ NULL);
}
static NMDevice *
diff --git a/src/devices/nm-device-ethernet.c b/src/devices/nm-device-ethernet.c
index 582a84df2e..c498219928 100644
--- a/src/devices/nm-device-ethernet.c
+++ b/src/devices/nm-device-ethernet.c
@@ -1745,14 +1745,11 @@ nm_device_ethernet_class_init (NMDeviceEthernetClass *klass)
static NMDevice *
new_link (NMDeviceFactory *factory, NMPlatformLink *plink, GError **error)
{
- if (plink->type == NM_LINK_TYPE_ETHERNET) {
- return (NMDevice *) g_object_new (NM_TYPE_DEVICE_ETHERNET,
- NM_DEVICE_PLATFORM_DEVICE, plink,
- NM_DEVICE_TYPE_DESC, "Ethernet",
- NM_DEVICE_DEVICE_TYPE, NM_DEVICE_TYPE_ETHERNET,
- NULL);
- }
- return NULL;
+ return (NMDevice *) g_object_new (NM_TYPE_DEVICE_ETHERNET,
+ NM_DEVICE_PLATFORM_DEVICE, plink,
+ NM_DEVICE_TYPE_DESC, "Ethernet",
+ NM_DEVICE_DEVICE_TYPE, NM_DEVICE_TYPE_ETHERNET,
+ NULL);
}
NM_DEVICE_FACTORY_DEFINE_INTERNAL (ETHERNET, Ethernet, ethernet,
diff --git a/src/devices/nm-device-factory.c b/src/devices/nm-device-factory.c
index 84e4ce7398..7ee7a5d0f5 100644
--- a/src/devices/nm-device-factory.c
+++ b/src/devices/nm-device-factory.c
@@ -28,6 +28,7 @@
#include "nm-device-factory.h"
#include "nm-logging.h"
+#include "nm-platform.h"
enum {
DEVICE_ADDED,
@@ -126,12 +127,38 @@ nm_device_factory_new_link (NMDeviceFactory *factory,
NMPlatformLink *plink,
GError **error)
{
+ NMDeviceFactory *interface;
+ const NMLinkType *link_types = NULL;
+ const char **setting_types = NULL;
+ int i;
+
g_return_val_if_fail (factory != NULL, NULL);
g_return_val_if_fail (plink != NULL, NULL);
- if (NM_DEVICE_FACTORY_GET_INTERFACE (factory)->new_link)
- return NM_DEVICE_FACTORY_GET_INTERFACE (factory)->new_link (factory, plink, error);
- return NULL;
+ /* Ensure the factory can create interfaces for this connection */
+ nm_device_factory_get_supported_types (factory, &link_types, &setting_types);
+ for (i = 0; link_types[i] > NM_LINK_TYPE_UNKNOWN; i++) {
+ if (plink->type == link_types[i])
+ break;
+ }
+
+ if (link_types[i] == NM_LINK_TYPE_UNKNOWN) {
+ g_set_error (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_CREATION_FAILED,
+ "Device factory %s does not support link type %s (%d)",
+ G_OBJECT_TYPE_NAME (factory),
+ plink->type_name, plink->type);
+ return NULL;
+ }
+
+ interface = NM_DEVICE_FACTORY_GET_INTERFACE (factory);
+ if (!interface->new_link) {
+ g_set_error (error, NM_MANAGER_ERROR, NM_MANAGER_ERROR_FAILED,
+ "Device factory %s cannot manage new devices",
+ G_OBJECT_TYPE_NAME (factory));
+ return NULL;
+ }
+
+ return interface->new_link (factory, plink, error);
}
NMDevice *
diff --git a/src/devices/nm-device-factory.h b/src/devices/nm-device-factory.h
index 46770bb4d8..879c1a5fa9 100644
--- a/src/devices/nm-device-factory.h
+++ b/src/devices/nm-device-factory.h
@@ -92,15 +92,17 @@ struct _NMDeviceFactory {
/**
* new_link:
* @factory: the #NMDeviceFactory
- * @link: the new link
+ * @plink: the new link
* @error: error if the link could be claimed but an error occurred
*
* The NetworkManager core was notified of a new link which the plugin
* may want to claim and create a #NMDevice subclass for. If the link
- * represents a device the factory is capable of claiming, but the device
- * could not be created, %NULL should be returned and @error should be set.
- * %NULL should always be returned and @error should never be set if the
- * factory cannot create devices for the type which @link represents.
+ * represents a device which the factory does not support, or the link
+ * is supported but the device could not be created, %NULL should be
+ * returned and @error should be set.
+ *
+ * @plink is guaranteed to be one of the types the factory returns in
+ * get_supported_types().
*
* Returns: the #NMDevice if the link was claimed and created, %NULL if not
*/
diff --git a/src/devices/nm-device-gre.c b/src/devices/nm-device-gre.c
index f754a39b31..9e592b51f9 100644
--- a/src/devices/nm-device-gre.c
+++ b/src/devices/nm-device-gre.c
@@ -269,14 +269,11 @@ nm_device_gre_class_init (NMDeviceGreClass *klass)
static NMDevice *
new_link (NMDeviceFactory *factory, NMPlatformLink *plink, GError **error)
{
- if (plink->type == NM_LINK_TYPE_GRE || plink->type == NM_LINK_TYPE_GRETAP) {
- return (NMDevice *) g_object_new (NM_TYPE_DEVICE_GRE,
- NM_DEVICE_PLATFORM_DEVICE, plink,
- NM_DEVICE_TYPE_DESC, "Gre",
- NM_DEVICE_DEVICE_TYPE, NM_DEVICE_TYPE_GENERIC,
- NULL);
- }
- return NULL;
+ return (NMDevice *) g_object_new (NM_TYPE_DEVICE_GRE,
+ NM_DEVICE_PLATFORM_DEVICE, plink,
+ NM_DEVICE_TYPE_DESC, "Gre",
+ NM_DEVICE_DEVICE_TYPE, NM_DEVICE_TYPE_GENERIC,
+ NULL);
}
NM_DEVICE_FACTORY_DEFINE_INTERNAL (GRE, Gre, gre,
diff --git a/src/devices/nm-device-infiniband.c b/src/devices/nm-device-infiniband.c
index 2b97c2f328..9f2119abac 100644
--- a/src/devices/nm-device-infiniband.c
+++ b/src/devices/nm-device-infiniband.c
@@ -295,14 +295,11 @@ nm_device_infiniband_class_init (NMDeviceInfinibandClass *klass)
static NMDevice *
new_link (NMDeviceFactory *factory, NMPlatformLink *plink, GError **error)
{
- if (plink->type == NM_LINK_TYPE_INFINIBAND) {
- return (NMDevice *) g_object_new (NM_TYPE_DEVICE_INFINIBAND,
- NM_DEVICE_PLATFORM_DEVICE, plink,
- NM_DEVICE_TYPE_DESC, "InfiniBand",
- NM_DEVICE_DEVICE_TYPE, NM_DEVICE_TYPE_INFINIBAND,
- NULL);
- }
- return NULL;
+ return (NMDevice *) g_object_new (NM_TYPE_DEVICE_INFINIBAND,
+ NM_DEVICE_PLATFORM_DEVICE, plink,
+ NM_DEVICE_TYPE_DESC, "InfiniBand",
+ NM_DEVICE_DEVICE_TYPE, NM_DEVICE_TYPE_INFINIBAND,
+ NULL);
}
static NMDevice *
diff --git a/src/devices/nm-device-macvlan.c b/src/devices/nm-device-macvlan.c
index 0b20a7e1c4..4235b62783 100644
--- a/src/devices/nm-device-macvlan.c
+++ b/src/devices/nm-device-macvlan.c
@@ -177,14 +177,11 @@ nm_device_macvlan_class_init (NMDeviceMacvlanClass *klass)
static NMDevice *
new_link (NMDeviceFactory *factory, NMPlatformLink *plink, GError **error)
{
- if (plink->type == NM_LINK_TYPE_MACVLAN || plink->type == NM_LINK_TYPE_MACVTAP) {
- return (NMDevice *) g_object_new (NM_TYPE_DEVICE_MACVLAN,
- NM_DEVICE_PLATFORM_DEVICE, plink,
- NM_DEVICE_TYPE_DESC, "Macvlan",
- NM_DEVICE_DEVICE_TYPE, NM_DEVICE_TYPE_GENERIC,
- NULL);
- }
- return NULL;
+ return (NMDevice *) g_object_new (NM_TYPE_DEVICE_MACVLAN,
+ NM_DEVICE_PLATFORM_DEVICE, plink,
+ NM_DEVICE_TYPE_DESC, "Macvlan",
+ NM_DEVICE_DEVICE_TYPE, NM_DEVICE_TYPE_GENERIC,
+ NULL);
}
NM_DEVICE_FACTORY_DEFINE_INTERNAL (MACVLAN, Macvlan, macvlan,
diff --git a/src/devices/nm-device-tun.c b/src/devices/nm-device-tun.c
index eeca616687..54cbbf82f3 100644
--- a/src/devices/nm-device-tun.c
+++ b/src/devices/nm-device-tun.c
@@ -278,8 +278,10 @@ new_link (NMDeviceFactory *factory, NMPlatformLink *plink, GError **error)
mode = "tun";
else if (plink->type == NM_LINK_TYPE_TAP)
mode = "tap";
- else
- return NULL;
+ else {
+ g_warn_if_reached ();
+ mode = "unknown";
+ }
return (NMDevice *) g_object_new (NM_TYPE_DEVICE_TUN,
NM_DEVICE_PLATFORM_DEVICE, plink,
diff --git a/src/devices/nm-device-veth.c b/src/devices/nm-device-veth.c
index 9de06da752..bb3d4af941 100644
--- a/src/devices/nm-device-veth.c
+++ b/src/devices/nm-device-veth.c
@@ -179,14 +179,11 @@ nm_device_veth_class_init (NMDeviceVethClass *klass)
static NMDevice *
new_link (NMDeviceFactory *factory, NMPlatformLink *plink, GError **error)
{
- if (plink->type == NM_LINK_TYPE_VETH) {
- return (NMDevice *) g_object_new (NM_TYPE_DEVICE_VETH,
- NM_DEVICE_PLATFORM_DEVICE, plink,
- NM_DEVICE_TYPE_DESC, "Veth",
- NM_DEVICE_DEVICE_TYPE, NM_DEVICE_TYPE_ETHERNET,
- NULL);
- }
- return NULL;
+ return (NMDevice *) g_object_new (NM_TYPE_DEVICE_VETH,
+ NM_DEVICE_PLATFORM_DEVICE, plink,
+ NM_DEVICE_TYPE_DESC, "Veth",
+ NM_DEVICE_DEVICE_TYPE, NM_DEVICE_TYPE_ETHERNET,
+ NULL);
}
NM_DEVICE_FACTORY_DEFINE_INTERNAL (VETH, Veth, veth,
diff --git a/src/devices/nm-device-vlan.c b/src/devices/nm-device-vlan.c
index c83be3f479..969b324d8a 100644
--- a/src/devices/nm-device-vlan.c
+++ b/src/devices/nm-device-vlan.c
@@ -664,25 +664,13 @@ new_link (NMDeviceFactory *factory, NMPlatformLink *plink, GError **error)
int parent_ifindex = -1;
NMDevice *parent, *device;
- if (plink->type != NM_LINK_TYPE_VLAN)
- return NULL;
-
- /* Have to find the parent device */
+ /* Find the parent device */
if (!nm_platform_vlan_get_info (NM_PLATFORM_GET, plink->ifindex, &parent_ifindex, NULL)) {
- nm_log_err (LOGD_HW, "(%s): failed to get VLAN parent ifindex", plink->name);
+ g_set_error_literal (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_CREATION_FAILED,
+ "VLAN parent ifindex unknown");
return NULL;
}
-
parent = nm_manager_get_device_by_ifindex (nm_manager_get (), parent_ifindex);
- if (!parent) {
- /* If udev signaled the VLAN interface before it signaled
- * the VLAN's parent at startup we may not know about the
- * parent device yet. But we'll find it on the second pass
- * from nm_manager_start().
- */
- nm_log_dbg (LOGD_HW, "(%s): VLAN parent interface unknown", plink->name);
- return NULL;
- }
device = (NMDevice *) g_object_new (NM_TYPE_DEVICE_VLAN,
NM_DEVICE_PLATFORM_DEVICE, plink,
@@ -692,6 +680,8 @@ new_link (NMDeviceFactory *factory, NMPlatformLink *plink, GError **error)
NM_DEVICE_DEVICE_TYPE, NM_DEVICE_TYPE_VLAN,
NULL);
if (NM_DEVICE_VLAN_GET_PRIVATE (device)->invalid) {
+ g_set_error_literal (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_CREATION_FAILED,
+ "VLAN initialization failed");
g_object_unref (device);
device = NULL;
}
diff --git a/src/devices/nm-device-vxlan.c b/src/devices/nm-device-vxlan.c
index f2b00765ea..c0492aee34 100644
--- a/src/devices/nm-device-vxlan.c
+++ b/src/devices/nm-device-vxlan.c
@@ -355,14 +355,11 @@ nm_device_vxlan_class_init (NMDeviceVxlanClass *klass)
static NMDevice *
new_link (NMDeviceFactory *factory, NMPlatformLink *plink, GError **error)
{
- if (plink->type == NM_LINK_TYPE_VXLAN) {
- return (NMDevice *) g_object_new (NM_TYPE_DEVICE_VXLAN,
- NM_DEVICE_PLATFORM_DEVICE, plink,
- NM_DEVICE_TYPE_DESC, "Vxlan",
- NM_DEVICE_DEVICE_TYPE, NM_DEVICE_TYPE_GENERIC,
- NULL);
- }
- return NULL;
+ return (NMDevice *) g_object_new (NM_TYPE_DEVICE_VXLAN,
+ NM_DEVICE_PLATFORM_DEVICE, plink,
+ NM_DEVICE_TYPE_DESC, "Vxlan",
+ NM_DEVICE_DEVICE_TYPE, NM_DEVICE_TYPE_GENERIC,
+ NULL);
}
NM_DEVICE_FACTORY_DEFINE_INTERNAL (VXLAN, Vxlan, vxlan,
diff --git a/src/devices/team/nm-device-team.c b/src/devices/team/nm-device-team.c
index 77a74db21d..5cefde770c 100644
--- a/src/devices/team/nm-device-team.c
+++ b/src/devices/team/nm-device-team.c
@@ -676,8 +676,6 @@ release_slave (NMDevice *device,
NMDevice *
nm_device_team_new (NMPlatformLink *platform_device)
{
- g_return_val_if_fail (platform_device != NULL, NULL);
-
return (NMDevice *) g_object_new (NM_TYPE_DEVICE_TEAM,
NM_DEVICE_PLATFORM_DEVICE, platform_device,
NM_DEVICE_DRIVER, "team",
diff --git a/src/devices/team/nm-team-factory.c b/src/devices/team/nm-team-factory.c
index 1d3e961778..f21f07502c 100644
--- a/src/devices/team/nm-team-factory.c
+++ b/src/devices/team/nm-team-factory.c
@@ -50,9 +50,7 @@ nm_device_factory_create (GError **error)
static NMDevice *
new_link (NMDeviceFactory *factory, NMPlatformLink *plink, GError **error)
{
- if (plink->type == NM_LINK_TYPE_TEAM)
- return nm_device_team_new (plink);
- return NULL;
+ return nm_device_team_new (plink);
}
static NMDevice *
diff --git a/src/devices/wifi/nm-wifi-factory.c b/src/devices/wifi/nm-wifi-factory.c
index ac54a66051..19578b3d58 100644
--- a/src/devices/wifi/nm-wifi-factory.c
+++ b/src/devices/wifi/nm-wifi-factory.c
@@ -65,7 +65,7 @@ new_link (NMDeviceFactory *factory, NMPlatformLink *plink, GError **error)
return nm_device_wifi_new (plink);
else if (plink->type == NM_LINK_TYPE_OLPC_MESH)
return nm_device_olpc_mesh_new (plink);
- return NULL;
+ g_assert_not_reached ();
}
NM_DEVICE_FACTORY_DECLARE_TYPES (
diff --git a/src/nm-manager.c b/src/nm-manager.c
index 88efec5ec9..9996ab6ad6 100644
--- a/src/nm-manager.c
+++ b/src/nm-manager.c
@@ -1971,13 +1971,9 @@ platform_link_added (NMManager *self,
factory = nm_device_factory_manager_find_factory (ltypes, NULL);
if (factory) {
device = nm_device_factory_new_link (factory, plink, &error);
- if (device && NM_IS_DEVICE (device)) {
- g_assert_no_error (error);
- } else if (error) {
- nm_log_warn (LOGD_HW, "%s: factory failed to create device: (%d) %s",
- plink->udi,
- error ? error->code : -1,
- error ? error->message : "(unknown)");
+ if (!device) {
+ nm_log_warn (LOGD_HW, "%s: factory failed to create device: %s",
+ plink->name, error->message);
g_clear_error (&error);
return;
}