bridge: port to internal device factory

This commit is contained in:
Dan Williams 2014-09-08 10:12:28 -05:00
parent 6d190f92d5
commit 097eb3a6af
5 changed files with 78 additions and 75 deletions

View file

@ -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 \

View file

@ -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;
)

View file

@ -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 */

View file

@ -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)) {

View file

@ -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 \