mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-02-04 15:20:28 +01:00
bond: port to internal device factory
This commit is contained in:
parent
097eb3a6af
commit
1553b3e223
5 changed files with 63 additions and 62 deletions
|
|
@ -63,6 +63,7 @@ NetworkManager_LDADD = libNetworkManager.la
|
|||
noinst_LTLIBRARIES = libNetworkManager.la
|
||||
|
||||
nm_device_sources = \
|
||||
devices/nm-device-bond.c \
|
||||
devices/nm-device-bridge.c \
|
||||
devices/nm-device-ethernet.c \
|
||||
devices/nm-device-infiniband.c \
|
||||
|
|
@ -85,7 +86,6 @@ nm_sources = \
|
|||
$(nm_device_headers) \
|
||||
devices/nm-device.c \
|
||||
devices/nm-device.h \
|
||||
devices/nm-device-bond.c \
|
||||
devices/nm-device-ethernet-utils.c \
|
||||
devices/nm-device-ethernet-utils.h \
|
||||
devices/nm-device-factory.c \
|
||||
|
|
|
|||
|
|
@ -36,6 +36,7 @@
|
|||
#include "nm-dbus-glib-types.h"
|
||||
#include "nm-dbus-manager.h"
|
||||
#include "nm-enum-types.h"
|
||||
#include "nm-device-factory.h"
|
||||
|
||||
#include "nm-device-bond-glue.h"
|
||||
|
||||
|
|
@ -454,47 +455,6 @@ release_slave (NMDevice *device,
|
|||
|
||||
/******************************************************************/
|
||||
|
||||
NMDevice *
|
||||
nm_device_bond_new (NMPlatformLink *platform_device)
|
||||
{
|
||||
g_return_val_if_fail (platform_device != NULL, NULL);
|
||||
|
||||
return (NMDevice *) g_object_new (NM_TYPE_DEVICE_BOND,
|
||||
NM_DEVICE_PLATFORM_DEVICE, platform_device,
|
||||
NM_DEVICE_DRIVER, "bonding",
|
||||
NM_DEVICE_TYPE_DESC, "Bond",
|
||||
NM_DEVICE_DEVICE_TYPE, NM_DEVICE_TYPE_BOND,
|
||||
NM_DEVICE_IS_MASTER, TRUE,
|
||||
NULL);
|
||||
}
|
||||
|
||||
NMDevice *
|
||||
nm_device_bond_new_for_connection (NMConnection *connection)
|
||||
{
|
||||
const char *iface;
|
||||
|
||||
g_return_val_if_fail (connection != NULL, NULL);
|
||||
|
||||
iface = nm_connection_get_interface_name (connection);
|
||||
g_return_val_if_fail (iface != NULL, NULL);
|
||||
|
||||
if ( !nm_platform_bond_add (iface)
|
||||
&& nm_platform_get_error () != NM_PLATFORM_ERROR_EXISTS) {
|
||||
nm_log_warn (LOGD_DEVICE | LOGD_BOND, "(%s): failed to create bonding 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_BOND,
|
||||
NM_DEVICE_IFACE, iface,
|
||||
NM_DEVICE_DRIVER, "bonding",
|
||||
NM_DEVICE_TYPE_DESC, "Bond",
|
||||
NM_DEVICE_DEVICE_TYPE, NM_DEVICE_TYPE_BOND,
|
||||
NM_DEVICE_IS_MASTER, TRUE,
|
||||
NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
nm_device_bond_init (NMDeviceBond * self)
|
||||
{
|
||||
|
|
@ -575,3 +535,60 @@ nm_device_bond_class_init (NMDeviceBondClass *klass)
|
|||
|
||||
dbus_g_error_domain_register (NM_BOND_ERROR, NULL, NM_TYPE_BOND_ERROR);
|
||||
}
|
||||
|
||||
/*************************************************************/
|
||||
|
||||
#define NM_TYPE_BOND_FACTORY (nm_bond_factory_get_type ())
|
||||
#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)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
static NMDevice *
|
||||
create_virtual_device_for_connection (NMDeviceFactory *factory,
|
||||
NMConnection *connection,
|
||||
NMDevice *parent,
|
||||
GError **error)
|
||||
{
|
||||
const char *iface;
|
||||
|
||||
if (!nm_connection_is_type (connection, NM_SETTING_BOND_SETTING_NAME))
|
||||
return NULL;
|
||||
|
||||
iface = nm_connection_get_interface_name (connection);
|
||||
g_return_val_if_fail (iface != NULL, NULL);
|
||||
|
||||
if ( !nm_platform_bond_add (iface)
|
||||
&& nm_platform_get_error () != NM_PLATFORM_ERROR_EXISTS) {
|
||||
nm_log_warn (LOGD_DEVICE | LOGD_BOND, "(%s): failed to create bonding 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_BOND,
|
||||
NM_DEVICE_IFACE, iface,
|
||||
NM_DEVICE_DRIVER, "bonding",
|
||||
NM_DEVICE_TYPE_DESC, "Bond",
|
||||
NM_DEVICE_DEVICE_TYPE, NM_DEVICE_TYPE_BOND,
|
||||
NM_DEVICE_IS_MASTER, TRUE,
|
||||
NULL);
|
||||
}
|
||||
|
||||
DEFINE_DEVICE_FACTORY_INTERNAL(BOND, Bond, bond,
|
||||
factory_iface->new_link = new_link;
|
||||
factory_iface->create_virtual_device_for_connection = create_virtual_device_for_connection;
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -42,21 +42,11 @@ typedef enum {
|
|||
|
||||
#define NM_DEVICE_BOND_SLAVES "slaves"
|
||||
|
||||
typedef struct {
|
||||
NMDevice parent;
|
||||
} NMDeviceBond;
|
||||
|
||||
typedef struct {
|
||||
NMDeviceClass parent;
|
||||
|
||||
} NMDeviceBondClass;
|
||||
|
||||
typedef NMDevice NMDeviceBond;
|
||||
typedef NMDeviceClass NMDeviceBondClass;
|
||||
|
||||
GType nm_device_bond_get_type (void);
|
||||
|
||||
NMDevice *nm_device_bond_new (NMPlatformLink *platform_device);
|
||||
NMDevice *nm_device_bond_new_for_connection (NMConnection *connection);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* NM_DEVICE_BOND_H */
|
||||
|
|
|
|||
|
|
@ -39,7 +39,6 @@
|
|||
#include "nm-dbus-manager.h"
|
||||
#include "nm-vpn-manager.h"
|
||||
#include "nm-device.h"
|
||||
#include "nm-device-bond.h"
|
||||
#include "nm-device-vlan.h"
|
||||
#include "nm-device-generic.h"
|
||||
#include "nm-device-tun.h"
|
||||
|
|
@ -1049,9 +1048,7 @@ system_create_virtual_device (NMManager *self, NMConnection *connection)
|
|||
|
||||
nm_owned = !nm_platform_link_exists (iface);
|
||||
|
||||
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_VLAN_SETTING_NAME)) {
|
||||
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) {
|
||||
|
|
@ -2120,9 +2117,6 @@ platform_link_added (NMManager *self,
|
|||
NMDevice *parent;
|
||||
|
||||
switch (plink->type) {
|
||||
case NM_LINK_TYPE_BOND:
|
||||
device = nm_device_bond_new (plink);
|
||||
break;
|
||||
case NM_LINK_TYPE_VLAN:
|
||||
/* Have to find the parent device */
|
||||
if (nm_platform_vlan_get_info (ifindex, &parent_ifindex, NULL)) {
|
||||
|
|
|
|||
|
|
@ -99,7 +99,7 @@ TESTS = \
|
|||
if ENABLE_TESTS
|
||||
|
||||
check-local:
|
||||
@for t in bridge ethernet infiniband veth; do \
|
||||
@for t in bond 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 \
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue