summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Williams <dcbw@redhat.com>2014-09-08 10:12:28 -0500
committerDan Williams <dcbw@redhat.com>2014-09-11 12:50:16 -0500
commit097eb3a6af1f91324e75db04ac0422099fba1fc0 (patch)
tree63f6d6e786d8de36507dcdcbdc406f9e03cfb37c
parent6d190f92d5c040a9d05e61c8c006246bad1c132f (diff)
downloadNetworkManager-097eb3a6af1f91324e75db04ac0422099fba1fc0.tar.gz
bridge: port to internal device factory
-rw-r--r--src/Makefile.am2
-rw-r--r--src/devices/nm-device-bridge.c129
-rw-r--r--src/devices/nm-device-bridge.h14
-rw-r--r--src/nm-manager.c6
-rw-r--r--src/tests/Makefile.am2
5 files changed, 78 insertions, 75 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 8477d3caae..3e0424de03 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -63,6 +63,7 @@ NetworkManager_LDADD = libNetworkManager.la
noinst_LTLIBRARIES = libNetworkManager.la
nm_device_sources = \
+ devices/nm-device-bridge.c \
devices/nm-device-ethernet.c \
devices/nm-device-infiniband.c \
devices/nm-device-veth.c \
@@ -85,7 +86,6 @@ nm_sources = \
devices/nm-device.c \
devices/nm-device.h \
devices/nm-device-bond.c \
- devices/nm-device-bridge.c \
devices/nm-device-ethernet-utils.c \
devices/nm-device-ethernet-utils.h \
devices/nm-device-factory.c \
diff --git a/src/devices/nm-device-bridge.c b/src/devices/nm-device-bridge.c
index 76a9c89bcd..caf62d76d0 100644
--- a/src/devices/nm-device-bridge.c
+++ b/src/devices/nm-device-bridge.c
@@ -35,6 +35,7 @@
#include "nm-dbus-manager.h"
#include "nm-enum-types.h"
#include "nm-platform.h"
+#include "nm-device-factory.h"
#include "nm-device-bridge-glue.h"
@@ -404,61 +405,6 @@ release_slave (NMDevice *device,
/******************************************************************/
-NMDevice *
-nm_device_bridge_new (NMPlatformLink *platform_device)
-{
- g_return_val_if_fail (platform_device != NULL, NULL);
-
- return (NMDevice *) g_object_new (NM_TYPE_DEVICE_BRIDGE,
- NM_DEVICE_PLATFORM_DEVICE, platform_device,
- NM_DEVICE_DRIVER, "bridge",
- NM_DEVICE_TYPE_DESC, "Bridge",
- NM_DEVICE_DEVICE_TYPE, NM_DEVICE_TYPE_BRIDGE,
- NM_DEVICE_IS_MASTER, TRUE,
- NULL);
-}
-
-NMDevice *
-nm_device_bridge_new_for_connection (NMConnection *connection)
-{
- const char *iface;
- NMSettingBridge *s_bridge;
- const char *mac_address_str;
- guint8 mac_address[NM_UTILS_HWADDR_LEN_MAX];
-
- g_return_val_if_fail (connection != NULL, NULL);
-
- iface = nm_connection_get_interface_name (connection);
- g_return_val_if_fail (iface != NULL, NULL);
-
- s_bridge = nm_connection_get_setting_bridge (connection);
- g_return_val_if_fail (s_bridge, NULL);
-
- mac_address_str = nm_setting_bridge_get_mac_address (s_bridge);
- if (mac_address_str) {
- if (!nm_utils_hwaddr_aton (mac_address_str, mac_address, ETH_ALEN))
- mac_address_str = NULL;
- }
-
- if ( !nm_platform_bridge_add (iface,
- mac_address_str ? mac_address : NULL,
- mac_address_str ? ETH_ALEN : 0)
- && nm_platform_get_error () != NM_PLATFORM_ERROR_EXISTS) {
- nm_log_warn (LOGD_DEVICE | LOGD_BRIDGE, "(%s): failed to create bridge master interface for '%s': %s",
- iface, nm_connection_get_id (connection),
- nm_platform_get_error_msg ());
- return NULL;
- }
-
- return (NMDevice *) g_object_new (NM_TYPE_DEVICE_BRIDGE,
- NM_DEVICE_IFACE, iface,
- NM_DEVICE_DRIVER, "bridge",
- NM_DEVICE_TYPE_DESC, "Bridge",
- NM_DEVICE_DEVICE_TYPE, NM_DEVICE_TYPE_BRIDGE,
- NM_DEVICE_IS_MASTER, TRUE,
- NULL);
-}
-
static void
nm_device_bridge_init (NMDeviceBridge * self)
{
@@ -539,3 +485,76 @@ nm_device_bridge_class_init (NMDeviceBridgeClass *klass)
dbus_g_error_domain_register (NM_BRIDGE_ERROR, NULL, NM_TYPE_BRIDGE_ERROR);
}
+
+/*************************************************************/
+
+#define NM_TYPE_BRIDGE_FACTORY (nm_bridge_factory_get_type ())
+#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)
+{
+ 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;
+}
+
+static NMDevice *
+create_virtual_device_for_connection (NMDeviceFactory *factory,
+ NMConnection *connection,
+ NMDevice *parent,
+ GError **error)
+{
+ const char *iface;
+ NMSettingBridge *s_bridge;
+ const char *mac_address_str;
+ guint8 mac_address[NM_UTILS_HWADDR_LEN_MAX];
+
+ if (!nm_connection_is_type (connection, NM_SETTING_BRIDGE_SETTING_NAME))
+ return NULL;
+
+ g_return_val_if_fail (connection != NULL, NULL);
+
+ iface = nm_connection_get_interface_name (connection);
+ g_return_val_if_fail (iface != NULL, NULL);
+
+ s_bridge = nm_connection_get_setting_bridge (connection);
+ g_return_val_if_fail (s_bridge, NULL);
+
+ mac_address_str = nm_setting_bridge_get_mac_address (s_bridge);
+ if (mac_address_str) {
+ if (!nm_utils_hwaddr_aton (mac_address_str, mac_address, ETH_ALEN))
+ mac_address_str = NULL;
+ }
+
+ if ( !nm_platform_bridge_add (iface,
+ mac_address_str ? mac_address : NULL,
+ mac_address_str ? ETH_ALEN : 0)
+ && nm_platform_get_error () != NM_PLATFORM_ERROR_EXISTS) {
+ nm_log_warn (LOGD_DEVICE | LOGD_BRIDGE, "(%s): failed to create bridge master interface for '%s': %s",
+ iface, nm_connection_get_id (connection),
+ nm_platform_get_error_msg ());
+ return NULL;
+ }
+
+ return (NMDevice *) g_object_new (NM_TYPE_DEVICE_BRIDGE,
+ NM_DEVICE_IFACE, iface,
+ NM_DEVICE_DRIVER, "bridge",
+ NM_DEVICE_TYPE_DESC, "Bridge",
+ NM_DEVICE_DEVICE_TYPE, NM_DEVICE_TYPE_BRIDGE,
+ NM_DEVICE_IS_MASTER, TRUE,
+ NULL);
+}
+
+DEFINE_DEVICE_FACTORY_INTERNAL(BRIDGE, Bridge, bridge,
+ 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-bridge.h b/src/devices/nm-device-bridge.h
index d39d64e559..7c6d7c53af 100644
--- a/src/devices/nm-device-bridge.h
+++ b/src/devices/nm-device-bridge.h
@@ -42,21 +42,11 @@ typedef enum {
#define NM_DEVICE_BRIDGE_SLAVES "slaves"
-typedef struct {
- NMDevice parent;
-} NMDeviceBridge;
-
-typedef struct {
- NMDeviceClass parent;
-
-} NMDeviceBridgeClass;
-
+typedef NMDevice NMDeviceBridge;
+typedef NMDeviceClass NMDeviceBridgeClass;
GType nm_device_bridge_get_type (void);
-NMDevice *nm_device_bridge_new (NMPlatformLink *platform_device);
-NMDevice *nm_device_bridge_new_for_connection (NMConnection *connection);
-
G_END_DECLS
#endif /* NM_DEVICE_BRIDGE_H */
diff --git a/src/nm-manager.c b/src/nm-manager.c
index 4fa996d0d8..c360062656 100644
--- a/src/nm-manager.c
+++ b/src/nm-manager.c
@@ -40,7 +40,6 @@
#include "nm-vpn-manager.h"
#include "nm-device.h"
#include "nm-device-bond.h"
-#include "nm-device-bridge.h"
#include "nm-device-vlan.h"
#include "nm-device-generic.h"
#include "nm-device-tun.h"
@@ -1052,8 +1051,6 @@ system_create_virtual_device (NMManager *self, NMConnection *connection)
if (nm_connection_is_type (connection, NM_SETTING_BOND_SETTING_NAME)) {
device = nm_device_bond_new_for_connection (connection);
- } else if (nm_connection_is_type (connection, NM_SETTING_BRIDGE_SETTING_NAME)) {
- device = nm_device_bridge_new_for_connection (connection);
} else if (nm_connection_is_type (connection, NM_SETTING_VLAN_SETTING_NAME)) {
device = nm_device_vlan_new_for_connection (connection, parent);
} else {
@@ -2126,9 +2123,6 @@ platform_link_added (NMManager *self,
case NM_LINK_TYPE_BOND:
device = nm_device_bond_new (plink);
break;
- case NM_LINK_TYPE_BRIDGE:
- device = nm_device_bridge_new (plink);
- break;
case NM_LINK_TYPE_VLAN:
/* Have to find the parent device */
if (nm_platform_vlan_get_info (ifindex, &parent_ifindex, NULL)) {
diff --git a/src/tests/Makefile.am b/src/tests/Makefile.am
index 9dbc44eec2..635829db15 100644
--- a/src/tests/Makefile.am
+++ b/src/tests/Makefile.am
@@ -99,7 +99,7 @@ TESTS = \
if ENABLE_TESTS
check-local:
- @for t in ethernet infiniband veth; do \
+ @for t in bridge ethernet infiniband veth; 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 \