summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Williams <dcbw@redhat.com>2014-09-08 10:24:11 -0500
committerDan Williams <dcbw@redhat.com>2014-09-11 12:50:16 -0500
commit15db28e74b4aef9f536a578487eb172e3f132f48 (patch)
treed5f910ceda3bddd6be0cffa79940bc75d6e9d2b0
parent1553b3e2230d55765cf345e2b00c366009091b4e (diff)
downloadNetworkManager-15db28e74b4aef9f536a578487eb172e3f132f48.tar.gz
vlan: port to internal device factory
-rw-r--r--src/Makefile.am2
-rw-r--r--src/devices/nm-device-vlan.c174
-rw-r--r--src/devices/nm-device-vlan.h16
-rw-r--r--src/nm-manager.c51
-rw-r--r--src/tests/Makefile.am2
5 files changed, 122 insertions, 123 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 759d8765c4..9a9c2b052c 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -68,6 +68,7 @@ nm_device_sources = \
devices/nm-device-ethernet.c \
devices/nm-device-infiniband.c \
devices/nm-device-veth.c \
+ devices/nm-device-vlan.c \
$(NULL)
nm_device_headers = \
@@ -97,7 +98,6 @@ nm_sources = \
devices/nm-device-macvlan.c \
devices/nm-device-private.h \
devices/nm-device-tun.c \
- devices/nm-device-vlan.c \
devices/nm-device-vxlan.c \
\
dhcp-manager/nm-dhcp-client.c \
diff --git a/src/devices/nm-device-vlan.c b/src/devices/nm-device-vlan.c
index 2b2e5711e1..71013a99c8 100644
--- a/src/devices/nm-device-vlan.c
+++ b/src/devices/nm-device-vlan.c
@@ -38,6 +38,8 @@
#include "nm-ip4-config.h"
#include "nm-platform.h"
#include "nm-utils.h"
+#include "nm-device-factory.h"
+#include "nm-manager.h"
#include "nm-device-vlan-glue.h"
@@ -431,75 +433,6 @@ parent_state_changed (NMDevice *parent,
/******************************************************************/
-NMDevice *
-nm_device_vlan_new (NMPlatformLink *platform_device, NMDevice *parent)
-{
- NMDevice *device;
-
- g_return_val_if_fail (platform_device != NULL, NULL);
- g_return_val_if_fail (NM_IS_DEVICE (parent), NULL);
-
- device = (NMDevice *) g_object_new (NM_TYPE_DEVICE_VLAN,
- NM_DEVICE_PLATFORM_DEVICE, platform_device,
- NM_DEVICE_VLAN_PARENT, parent,
- NM_DEVICE_DRIVER, "8021q",
- NM_DEVICE_TYPE_DESC, "VLAN",
- NM_DEVICE_DEVICE_TYPE, NM_DEVICE_TYPE_VLAN,
- NULL);
- if (NM_DEVICE_VLAN_GET_PRIVATE (device)->invalid) {
- g_object_unref (device);
- device = NULL;
- }
-
- return device;
-}
-
-NMDevice *
-nm_device_vlan_new_for_connection (NMConnection *connection, NMDevice *parent)
-{
- NMDevice *device;
- NMSettingVlan *s_vlan;
- char *iface;
-
- g_return_val_if_fail (connection != NULL, NULL);
- g_return_val_if_fail (NM_IS_DEVICE (parent), NULL);
-
- s_vlan = nm_connection_get_setting_vlan (connection);
- g_return_val_if_fail (s_vlan != NULL, NULL);
-
- iface = g_strdup (nm_connection_get_interface_name (connection));
- if (!iface) {
- iface = nm_utils_new_vlan_name (nm_device_get_ip_iface (parent),
- nm_setting_vlan_get_id (s_vlan));
- }
-
- if ( !nm_platform_vlan_add (iface,
- nm_device_get_ifindex (parent),
- nm_setting_vlan_get_id (s_vlan),
- nm_setting_vlan_get_flags (s_vlan))
- && nm_platform_get_error () != NM_PLATFORM_ERROR_EXISTS) {
- nm_log_warn (LOGD_DEVICE | LOGD_VLAN, "(%s) failed to add VLAN interface for '%s'",
- iface, nm_connection_get_id (connection));
- g_free (iface);
- return NULL;
- }
-
- device = (NMDevice *) g_object_new (NM_TYPE_DEVICE_VLAN,
- NM_DEVICE_IFACE, iface,
- NM_DEVICE_VLAN_PARENT, parent,
- NM_DEVICE_DRIVER, "8021q",
- NM_DEVICE_TYPE_DESC, "VLAN",
- NM_DEVICE_DEVICE_TYPE, NM_DEVICE_TYPE_VLAN,
- NULL);
- g_free (iface);
- if (NM_DEVICE_VLAN_GET_PRIVATE (device)->invalid) {
- g_object_unref (device);
- device = NULL;
- }
-
- return device;
-}
-
static void
nm_device_vlan_init (NMDeviceVlan * self)
{
@@ -661,3 +594,106 @@ nm_device_vlan_class_init (NMDeviceVlanClass *klass)
dbus_g_error_domain_register (NM_VLAN_ERROR, NULL, NM_TYPE_VLAN_ERROR);
}
+
+/*************************************************************/
+
+#define NM_TYPE_VLAN_FACTORY (nm_vlan_factory_get_type ())
+#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)
+{
+ int parent_ifindex = -1;
+ NMDevice *parent, *device;
+
+ if (plink->type != NM_LINK_TYPE_VLAN)
+ return NULL;
+
+ /* Have to find the parent device */
+ if (!nm_platform_vlan_get_info (plink->ifindex, &parent_ifindex, NULL)) {
+ nm_log_err (LOGD_HW, "(%s): failed to get VLAN parent ifindex", plink->name);
+ 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,
+ NM_DEVICE_VLAN_PARENT, parent,
+ NM_DEVICE_DRIVER, "8021q",
+ NM_DEVICE_TYPE_DESC, "VLAN",
+ NM_DEVICE_DEVICE_TYPE, NM_DEVICE_TYPE_VLAN,
+ NULL);
+ if (NM_DEVICE_VLAN_GET_PRIVATE (device)->invalid) {
+ g_object_unref (device);
+ device = NULL;
+ }
+
+ return device;
+}
+
+static NMDevice *
+create_virtual_device_for_connection (NMDeviceFactory *factory,
+ NMConnection *connection,
+ NMDevice *parent,
+ GError **error)
+{
+ NMDevice *device;
+ NMSettingVlan *s_vlan;
+ char *iface;
+
+ if (!nm_connection_is_type (connection, NM_SETTING_VLAN_SETTING_NAME))
+ return NULL;
+
+ g_return_val_if_fail (NM_IS_DEVICE (parent), NULL);
+
+ s_vlan = nm_connection_get_setting_vlan (connection);
+ g_return_val_if_fail (s_vlan != NULL, NULL);
+
+ iface = g_strdup (nm_connection_get_interface_name (connection));
+ if (!iface) {
+ iface = nm_utils_new_vlan_name (nm_device_get_ip_iface (parent),
+ nm_setting_vlan_get_id (s_vlan));
+ }
+
+ if ( !nm_platform_vlan_add (iface,
+ nm_device_get_ifindex (parent),
+ nm_setting_vlan_get_id (s_vlan),
+ nm_setting_vlan_get_flags (s_vlan))
+ && nm_platform_get_error () != NM_PLATFORM_ERROR_EXISTS) {
+ nm_log_warn (LOGD_DEVICE | LOGD_VLAN, "(%s) failed to add VLAN interface for '%s'",
+ iface, nm_connection_get_id (connection));
+ g_free (iface);
+ return NULL;
+ }
+
+ device = (NMDevice *) g_object_new (NM_TYPE_DEVICE_VLAN,
+ NM_DEVICE_IFACE, iface,
+ NM_DEVICE_VLAN_PARENT, parent,
+ NM_DEVICE_DRIVER, "8021q",
+ NM_DEVICE_TYPE_DESC, "VLAN",
+ NM_DEVICE_DEVICE_TYPE, NM_DEVICE_TYPE_VLAN,
+ NULL);
+ g_free (iface);
+ if (NM_DEVICE_VLAN_GET_PRIVATE (device)->invalid) {
+ g_object_unref (device);
+ device = NULL;
+ }
+
+ return device;
+}
+
+DEFINE_DEVICE_FACTORY_INTERNAL(VLAN, Vlan, vlan, \
+ factory_iface->new_link = new_link; \
+ factory_iface->create_virtual_device_for_connection = create_virtual_device_for_connection;
+ )
+
diff --git a/src/devices/nm-device-vlan.h b/src/devices/nm-device-vlan.h
index b1d0ed9679..e1618db440 100644
--- a/src/devices/nm-device-vlan.h
+++ b/src/devices/nm-device-vlan.h
@@ -43,23 +43,11 @@ typedef enum {
#define NM_DEVICE_VLAN_PARENT "parent"
#define NM_DEVICE_VLAN_ID "vlan-id"
-typedef struct {
- NMDevice parent;
-} NMDeviceVlan;
-
-typedef struct {
- NMDeviceClass parent;
-
-} NMDeviceVlanClass;
-
+typedef NMDevice NMDeviceVlan;
+typedef NMDeviceClass NMDeviceVlanClass;
GType nm_device_vlan_get_type (void);
-NMDevice *nm_device_vlan_new (NMPlatformLink *platform_link,
- NMDevice *parent);
-NMDevice *nm_device_vlan_new_for_connection (NMConnection *connection,
- NMDevice *parent);
-
G_END_DECLS
#endif /* NM_DEVICE_VLAN_H */
diff --git a/src/nm-manager.c b/src/nm-manager.c
index 774abee390..e793867764 100644
--- a/src/nm-manager.c
+++ b/src/nm-manager.c
@@ -39,7 +39,6 @@
#include "nm-dbus-manager.h"
#include "nm-vpn-manager.h"
#include "nm-device.h"
-#include "nm-device-vlan.h"
#include "nm-device-generic.h"
#include "nm-device-tun.h"
#include "nm-device-macvlan.h"
@@ -1048,24 +1047,20 @@ system_create_virtual_device (NMManager *self, NMConnection *connection)
nm_owned = !nm_platform_link_exists (iface);
- if (nm_connection_is_type (connection, NM_SETTING_VLAN_SETTING_NAME)) {
- device = nm_device_vlan_new_for_connection (connection, parent);
- } else {
- for (iter = priv->factories; iter; iter = iter->next) {
- device = nm_device_factory_create_virtual_device_for_connection (NM_DEVICE_FACTORY (iter->data),
- connection,
- parent,
- &error);
- if (device || error) {
- if (device)
- g_assert_no_error (error);
- else {
- nm_log_err (LOGD_DEVICE, "(%s) failed to create virtual device: %s",
- nm_connection_get_id (connection), error ? error->message : "(unknown error)");
- g_clear_error (&error);
- }
- break;
+ for (iter = priv->factories; iter; iter = iter->next) {
+ device = nm_device_factory_create_virtual_device_for_connection (NM_DEVICE_FACTORY (iter->data),
+ connection,
+ parent,
+ &error);
+ if (device || error) {
+ if (device)
+ g_assert_no_error (error);
+ else {
+ nm_log_err (LOGD_DEVICE, "(%s) failed to create virtual device: %s",
+ nm_connection_get_id (connection), error ? error->message : "(unknown error)");
+ g_clear_error (&error);
}
+ break;
}
}
@@ -2113,27 +2108,7 @@ platform_link_added (NMManager *self,
return;
if (device == NULL) {
- int parent_ifindex = -1;
- NMDevice *parent;
-
switch (plink->type) {
- case NM_LINK_TYPE_VLAN:
- /* Have to find the parent device */
- if (nm_platform_vlan_get_info (ifindex, &parent_ifindex, NULL)) {
- parent = nm_manager_get_device_by_ifindex (self, parent_ifindex);
- if (parent)
- device = nm_device_vlan_new (plink, parent);
- else {
- /* 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);
- }
- } else
- nm_log_err (LOGD_HW, "(%s): failed to get VLAN parent ifindex", plink->name);
- break;
case NM_LINK_TYPE_TUN:
case NM_LINK_TYPE_TAP:
device = nm_device_tun_new (plink);
diff --git a/src/tests/Makefile.am b/src/tests/Makefile.am
index 5761aeb505..6a634f82ea 100644
--- a/src/tests/Makefile.am
+++ b/src/tests/Makefile.am
@@ -99,7 +99,7 @@ TESTS = \
if ENABLE_TESTS
check-local:
- @for t in bond bridge ethernet infiniband veth; do \
+ @for t in bond bridge ethernet infiniband veth vlan; do \
# Ensure the device subclass factory registration constructors exist \
# which could inadvertently break if src/Makefile.am gets changed \
if ! LC_ALL=C nm $(top_builddir)/src/NetworkManager | LC_ALL=C grep -q "register_device_factory_internal_$$t" ; then \