merge: create internal device types with factories too (bgo #736289)
https://bugzilla.gnome.org/show_bug.cgi?id=736289
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -235,7 +235,6 @@ valgrind-*.log
|
||||
/src/settings/plugins/ifnet/tests/check_ifnet
|
||||
/src/settings/plugins/ifupdown/tests/test-ifupdown
|
||||
/src/settings/plugins/keyfile/tests/test-keyfile
|
||||
/src/settings/tests/test-wired-defname
|
||||
/src/supplicant-manager/tests/test-supplicant-config
|
||||
/src/tests/config/test-config
|
||||
/src/tests/test-dcb
|
||||
@@ -244,5 +243,6 @@ valgrind-*.log
|
||||
/src/tests/test-ip4-config
|
||||
/src/tests/test-ip6-config
|
||||
/src/tests/test-resolvconf-capture
|
||||
/src/tests/test-wired-defname
|
||||
|
||||
/vapi/*.vapi
|
||||
|
@@ -114,6 +114,7 @@ src/devices/bluetooth/nm-device-bt.c
|
||||
src/devices/nm-device-bond.c
|
||||
src/devices/nm-device-bridge.c
|
||||
src/devices/nm-device-ethernet.c
|
||||
src/devices/nm-device-ethernet-utils.c
|
||||
src/devices/nm-device-infiniband.c
|
||||
src/devices/nm-device-vlan.c
|
||||
src/devices/team/nm-device-team.c
|
||||
@@ -125,4 +126,3 @@ src/nm-manager.c
|
||||
src/nm-sleep-monitor-systemd.c
|
||||
src/settings/plugins/ibft/plugin.c
|
||||
src/settings/plugins/ifcfg-rh/reader.c
|
||||
src/settings/nm-settings-utils.c
|
||||
|
@@ -30,7 +30,6 @@ SUBDIRS += \
|
||||
dnsmasq-manager/tests \
|
||||
platform \
|
||||
rdisc \
|
||||
settings/tests \
|
||||
supplicant-manager/tests \
|
||||
tests
|
||||
endif
|
||||
@@ -56,41 +55,50 @@ AM_CPPFLAGS += $(foreach d,$(sort $(dir $(libNetworkManager_la_SOURCES))),-I$(to
|
||||
sbin_PROGRAMS = NetworkManager
|
||||
|
||||
NetworkManager_SOURCES = \
|
||||
$(nm_device_sources) $(nm_device_headers) \
|
||||
main.c
|
||||
|
||||
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-gre.c \
|
||||
devices/nm-device-infiniband.c \
|
||||
devices/nm-device-macvlan.c \
|
||||
devices/nm-device-tun.c \
|
||||
devices/nm-device-veth.c \
|
||||
devices/nm-device-vlan.c \
|
||||
devices/nm-device-vxlan.c \
|
||||
$(NULL)
|
||||
|
||||
nm_device_headers = \
|
||||
devices/nm-device-bond.h \
|
||||
devices/nm-device-bridge.h \
|
||||
devices/nm-device-ethernet.h \
|
||||
devices/nm-device-gre.h \
|
||||
devices/nm-device-infiniband.h \
|
||||
devices/nm-device-macvlan.h \
|
||||
devices/nm-device-tun.h \
|
||||
devices/nm-device-veth.h \
|
||||
devices/nm-device-vlan.h \
|
||||
devices/nm-device-vxlan.h
|
||||
|
||||
nm_sources = \
|
||||
$(nm_device_headers) \
|
||||
devices/nm-device.c \
|
||||
devices/nm-device.h \
|
||||
devices/nm-device-bond.c \
|
||||
devices/nm-device-bond.h \
|
||||
devices/nm-device-bridge.c \
|
||||
devices/nm-device-bridge.h \
|
||||
devices/nm-device-ethernet.c \
|
||||
devices/nm-device-ethernet.h \
|
||||
devices/nm-device-ethernet-utils.c \
|
||||
devices/nm-device-ethernet-utils.h \
|
||||
devices/nm-device-factory.c \
|
||||
devices/nm-device-factory.h \
|
||||
devices/nm-device-generic.c \
|
||||
devices/nm-device-generic.h \
|
||||
devices/nm-device-gre.c \
|
||||
devices/nm-device-gre.h \
|
||||
devices/nm-device-infiniband.c \
|
||||
devices/nm-device-infiniband.h \
|
||||
devices/nm-device-logging.h \
|
||||
devices/nm-device-macvlan.c \
|
||||
devices/nm-device-macvlan.h \
|
||||
devices/nm-device-private.h \
|
||||
devices/nm-device-tun.c \
|
||||
devices/nm-device-tun.h \
|
||||
devices/nm-device-veth.c \
|
||||
devices/nm-device-veth.h \
|
||||
devices/nm-device-vlan.c \
|
||||
devices/nm-device-vlan.h \
|
||||
devices/nm-device-vxlan.c \
|
||||
devices/nm-device-vxlan.h \
|
||||
\
|
||||
dhcp-manager/nm-dhcp-client.c \
|
||||
dhcp-manager/nm-dhcp-client.h \
|
||||
@@ -157,8 +165,6 @@ nm_sources = \
|
||||
settings/nm-settings-connection.h \
|
||||
settings/nm-settings-error.c \
|
||||
settings/nm-settings-error.h \
|
||||
settings/nm-settings-utils.c \
|
||||
settings/nm-settings-utils.h \
|
||||
settings/nm-settings.c \
|
||||
settings/nm-settings.h \
|
||||
settings/nm-system-config-interface.c \
|
||||
|
@@ -1,7 +1,6 @@
|
||||
{
|
||||
global:
|
||||
nm_device_factory_create;
|
||||
nm_device_factory_get_device_type;
|
||||
local:
|
||||
*;
|
||||
};
|
||||
|
@@ -32,7 +32,6 @@
|
||||
typedef struct {
|
||||
GUdevClient *client;
|
||||
GSList *devices;
|
||||
guint start_id;
|
||||
} NMAtmManagerPrivate;
|
||||
|
||||
#define NM_ATM_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_ATM_MANAGER, NMAtmManagerPrivate))
|
||||
@@ -46,20 +45,12 @@ G_DEFINE_TYPE_EXTENDED (NMAtmManager, nm_atm_manager, G_TYPE_OBJECT, 0,
|
||||
|
||||
/**************************************************************************/
|
||||
|
||||
#define PLUGIN_TYPE NM_DEVICE_TYPE_ADSL
|
||||
|
||||
G_MODULE_EXPORT NMDeviceFactory *
|
||||
nm_device_factory_create (GError **error)
|
||||
{
|
||||
return (NMDeviceFactory *) g_object_new (NM_TYPE_ATM_MANAGER, NULL);
|
||||
}
|
||||
|
||||
G_MODULE_EXPORT NMDeviceType
|
||||
nm_device_factory_get_device_type (void)
|
||||
{
|
||||
return PLUGIN_TYPE;
|
||||
}
|
||||
|
||||
/************************************************************************/
|
||||
|
||||
static gboolean
|
||||
@@ -163,9 +154,10 @@ adsl_remove (NMAtmManager *self, GUdevDevice *udev_device)
|
||||
}
|
||||
}
|
||||
|
||||
static gboolean
|
||||
query_devices (NMAtmManager *self)
|
||||
static void
|
||||
start (NMDeviceFactory *factory)
|
||||
{
|
||||
NMAtmManager *self = NM_ATM_MANAGER (factory);
|
||||
NMAtmManagerPrivate *priv = NM_ATM_MANAGER_GET_PRIVATE (self);
|
||||
GUdevEnumerator *enumerator;
|
||||
GList *devices, *iter;
|
||||
@@ -180,8 +172,6 @@ query_devices (NMAtmManager *self)
|
||||
}
|
||||
g_list_free (devices);
|
||||
g_object_unref (enumerator);
|
||||
|
||||
return G_SOURCE_REMOVE;
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -212,6 +202,12 @@ handle_uevent (GUdevClient *client,
|
||||
adsl_remove (self, device);
|
||||
}
|
||||
|
||||
static NMDeviceType
|
||||
get_device_type (NMDeviceFactory *factory)
|
||||
{
|
||||
return NM_DEVICE_TYPE_ADSL;
|
||||
}
|
||||
|
||||
/*********************************************************************/
|
||||
|
||||
static void
|
||||
@@ -222,13 +218,13 @@ nm_atm_manager_init (NMAtmManager *self)
|
||||
|
||||
priv->client = g_udev_client_new (subsys);
|
||||
g_signal_connect (priv->client, "uevent", G_CALLBACK (handle_uevent), self);
|
||||
|
||||
priv->start_id = g_idle_add ((GSourceFunc) query_devices, self);
|
||||
}
|
||||
|
||||
static void
|
||||
device_factory_interface_init (NMDeviceFactory *factory_iface)
|
||||
{
|
||||
factory_iface->get_device_type = get_device_type;
|
||||
factory_iface->start = start;
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -242,11 +238,6 @@ dispose (GObject *object)
|
||||
g_signal_handlers_disconnect_by_func (priv->client, handle_uevent, self);
|
||||
g_clear_object (&priv->client);
|
||||
|
||||
if (priv->start_id) {
|
||||
g_source_remove (priv->start_id);
|
||||
priv->start_id = 0;
|
||||
}
|
||||
|
||||
for (iter = priv->devices; iter; iter = iter->next)
|
||||
g_object_weak_unref (G_OBJECT (iter->data), device_destroyed, self);
|
||||
g_clear_pointer (&priv->devices, g_slist_free);
|
||||
|
@@ -1,7 +1,6 @@
|
||||
{
|
||||
global:
|
||||
nm_device_factory_create;
|
||||
nm_device_factory_get_device_type;
|
||||
local:
|
||||
*;
|
||||
};
|
||||
|
@@ -62,20 +62,12 @@ static void check_bluez_and_try_setup (NMBluezManager *self);
|
||||
|
||||
/**************************************************************************/
|
||||
|
||||
#define PLUGIN_TYPE NM_DEVICE_TYPE_BT
|
||||
|
||||
G_MODULE_EXPORT NMDeviceFactory *
|
||||
nm_device_factory_create (GError **error)
|
||||
{
|
||||
return (NMDeviceFactory *) g_object_new (NM_TYPE_BLUEZ_MANAGER, NULL);
|
||||
}
|
||||
|
||||
G_MODULE_EXPORT NMDeviceType
|
||||
nm_device_factory_get_device_type (void)
|
||||
{
|
||||
return PLUGIN_TYPE;
|
||||
}
|
||||
|
||||
/************************************************************************/
|
||||
|
||||
struct AsyncData {
|
||||
@@ -368,6 +360,18 @@ check_bluez_and_try_setup (NMBluezManager *self)
|
||||
async_data_pack (self));
|
||||
}
|
||||
|
||||
static void
|
||||
start (NMDeviceFactory *factory)
|
||||
{
|
||||
check_bluez_and_try_setup (NM_BLUEZ_MANAGER (factory));
|
||||
}
|
||||
|
||||
static NMDeviceType
|
||||
get_device_type (NMDeviceFactory *factory)
|
||||
{
|
||||
return NM_DEVICE_TYPE_BT;
|
||||
}
|
||||
|
||||
/*********************************************************************/
|
||||
|
||||
static void
|
||||
@@ -390,16 +394,6 @@ dispose (GObject *object)
|
||||
priv->bluez_version = 0;
|
||||
}
|
||||
|
||||
static void
|
||||
constructed (GObject *object)
|
||||
{
|
||||
NMBluezManager *self = NM_BLUEZ_MANAGER (object);
|
||||
|
||||
G_OBJECT_CLASS (nm_bluez_manager_parent_class)->constructed (object);
|
||||
|
||||
check_bluez_and_try_setup (self);
|
||||
}
|
||||
|
||||
static void
|
||||
nm_bluez_manager_init (NMBluezManager *self)
|
||||
{
|
||||
@@ -412,6 +406,8 @@ nm_bluez_manager_init (NMBluezManager *self)
|
||||
static void
|
||||
device_factory_interface_init (NMDeviceFactory *factory_iface)
|
||||
{
|
||||
factory_iface->get_device_type = get_device_type;
|
||||
factory_iface->start = start;
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -423,6 +419,5 @@ nm_bluez_manager_class_init (NMBluezManagerClass *klass)
|
||||
|
||||
/* virtual methods */
|
||||
object_class->dispose = dispose;
|
||||
object_class->constructed = constructed;
|
||||
}
|
||||
|
||||
|
@@ -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 */
|
||||
|
@@ -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;
|
||||
)
|
||||
|
||||
|
@@ -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 */
|
||||
|
@@ -21,35 +21,23 @@
|
||||
#include <glib/gi18n.h>
|
||||
|
||||
#include <nm-connection.h>
|
||||
#include "nm-settings-utils.h"
|
||||
#include "nm-device-ethernet-utils.h"
|
||||
|
||||
char *
|
||||
nm_settings_utils_get_default_wired_name (GHashTable *connections)
|
||||
nm_device_ethernet_utils_get_default_wired_name (const GSList *connections)
|
||||
{
|
||||
GHashTableIter iter;
|
||||
NMConnection *connection = NULL;
|
||||
GSList *names = NULL, *niter;
|
||||
const GSList *iter;
|
||||
char *cname = NULL;
|
||||
int i = 0;
|
||||
|
||||
/* Build up a list of all existing connection names for dupe checking */
|
||||
g_hash_table_iter_init (&iter, connections);
|
||||
while (g_hash_table_iter_next (&iter, NULL, (gpointer) &connection)) {
|
||||
const char *id;
|
||||
|
||||
id = nm_connection_get_id (connection);
|
||||
g_assert (id);
|
||||
names = g_slist_append (names, (gpointer) id);
|
||||
}
|
||||
|
||||
/* Find the next available unique connection name */
|
||||
while (!cname && (i++ < 10000)) {
|
||||
char *temp;
|
||||
gboolean found = FALSE;
|
||||
|
||||
temp = g_strdup_printf (_("Wired connection %d"), i);
|
||||
for (niter = names; niter; niter = g_slist_next (niter)) {
|
||||
if (g_strcmp0 (niter->data, temp) == 0) {
|
||||
for (iter = connections; iter; iter = iter->next) {
|
||||
if (g_strcmp0 (nm_connection_get_id (NM_CONNECTION (iter->data)), temp) == 0) {
|
||||
found = TRUE;
|
||||
g_free (temp);
|
||||
break;
|
||||
@@ -59,7 +47,6 @@ nm_settings_utils_get_default_wired_name (GHashTable *connections)
|
||||
if (found == FALSE)
|
||||
cname = temp;
|
||||
}
|
||||
g_slist_free (names);
|
||||
|
||||
return cname;
|
||||
}
|
@@ -16,11 +16,11 @@
|
||||
* (C) Copyright 2011 Red Hat, Inc.
|
||||
*/
|
||||
|
||||
#ifndef __NETWORKMANAGER_SETTINGS_UTILS_H__
|
||||
#define __NETWORKMANAGER_SETTINGS_UTILS_H__
|
||||
#ifndef __NETWORKMANAGER_DEVICE_ETHERNET_UTILS_H__
|
||||
#define __NETWORKMANAGER_DEVICE_ETHERNET_UTILS_H__
|
||||
|
||||
#include <glib.h>
|
||||
|
||||
char *nm_settings_utils_get_default_wired_name (GHashTable *connections);
|
||||
char *nm_device_ethernet_utils_get_default_wired_name (const GSList *connections);
|
||||
|
||||
#endif /* NM_SETTINGS_UTILS_H */
|
||||
#endif /* NETWORKMANAGER_DEVICE_ETHERNET_UTILS_H */
|
@@ -55,6 +55,10 @@
|
||||
#include "nm-platform.h"
|
||||
#include "nm-dcb.h"
|
||||
#include "nm-settings-connection.h"
|
||||
#include "nm-config.h"
|
||||
#include "nm-device-ethernet-utils.h"
|
||||
#include "nm-connection-provider.h"
|
||||
#include "nm-device-factory.h"
|
||||
|
||||
#include "nm-device-ethernet-glue.h"
|
||||
|
||||
@@ -319,18 +323,6 @@ nm_device_ethernet_init (NMDeviceEthernet *self)
|
||||
priv->s390_options = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
|
||||
}
|
||||
|
||||
NMDevice *
|
||||
nm_device_ethernet_new (NMPlatformLink *platform_device)
|
||||
{
|
||||
g_return_val_if_fail (platform_device != NULL, NULL);
|
||||
|
||||
return (NMDevice *) g_object_new (NM_TYPE_DEVICE_ETHERNET,
|
||||
NM_DEVICE_PLATFORM_DEVICE, platform_device,
|
||||
NM_DEVICE_TYPE_DESC, "Ethernet",
|
||||
NM_DEVICE_DEVICE_TYPE, NM_DEVICE_TYPE_ETHERNET,
|
||||
NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
update_permanent_hw_address (NMDevice *dev)
|
||||
{
|
||||
@@ -1473,6 +1465,51 @@ complete_connection (NMDevice *device,
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static NMConnection *
|
||||
new_default_connection (NMDevice *self)
|
||||
{
|
||||
NMConnection *connection;
|
||||
const GSList *connections;
|
||||
NMSetting *setting;
|
||||
const char *hw_address;
|
||||
char *defname, *uuid;
|
||||
GByteArray *mac;
|
||||
|
||||
if (!nm_config_get_ethernet_can_auto_default (nm_config_get (), self))
|
||||
return NULL;
|
||||
|
||||
hw_address = nm_device_get_hw_address (self);
|
||||
if (!hw_address)
|
||||
return NULL;
|
||||
|
||||
connection = nm_simple_connection_new ();
|
||||
setting = nm_setting_connection_new ();
|
||||
nm_connection_add_setting (connection, setting);
|
||||
|
||||
connections = nm_connection_provider_get_connections (nm_connection_provider_get ());
|
||||
defname = nm_device_ethernet_utils_get_default_wired_name (connections);
|
||||
uuid = nm_utils_uuid_generate ();
|
||||
g_object_set (setting,
|
||||
NM_SETTING_CONNECTION_ID, defname,
|
||||
NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRED_SETTING_NAME,
|
||||
NM_SETTING_CONNECTION_AUTOCONNECT, TRUE,
|
||||
NM_SETTING_CONNECTION_UUID, uuid,
|
||||
NM_SETTING_CONNECTION_TIMESTAMP, (guint64) time (NULL),
|
||||
NULL);
|
||||
g_free (uuid);
|
||||
g_free (defname);
|
||||
|
||||
/* Lock the connection to the device */
|
||||
setting = nm_setting_wired_new ();
|
||||
nm_connection_add_setting (connection, setting);
|
||||
|
||||
mac = nm_utils_hwaddr_atoba (hw_address, ETH_ALEN);
|
||||
g_object_set (setting, NM_SETTING_WIRED_MAC_ADDRESS, mac, NULL);
|
||||
g_byte_array_unref (mac);
|
||||
|
||||
return connection;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
spec_match_list (NMDevice *device, const GSList *specs)
|
||||
{
|
||||
@@ -1679,6 +1716,7 @@ nm_device_ethernet_class_init (NMDeviceEthernetClass *klass)
|
||||
parent_class->update_initial_hw_address = update_initial_hw_address;
|
||||
parent_class->check_connection_compatible = check_connection_compatible;
|
||||
parent_class->complete_connection = complete_connection;
|
||||
parent_class->new_default_connection = new_default_connection;
|
||||
|
||||
parent_class->act_stage1_prepare = act_stage1_prepare;
|
||||
parent_class->act_stage2_config = act_stage2_config;
|
||||
@@ -1712,3 +1750,26 @@ nm_device_ethernet_class_init (NMDeviceEthernetClass *klass)
|
||||
|
||||
dbus_g_error_domain_register (NM_ETHERNET_ERROR, NULL, NM_TYPE_ETHERNET_ERROR);
|
||||
}
|
||||
|
||||
/*************************************************************/
|
||||
|
||||
#define NM_TYPE_ETHERNET_FACTORY (nm_ethernet_factory_get_type ())
|
||||
#define NM_ETHERNET_FACTORY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_ETHERNET_FACTORY, NMEthernetFactory))
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
DEFINE_DEVICE_FACTORY_INTERNAL(ETHERNET, Ethernet, ethernet, \
|
||||
factory_iface->new_link = new_link; \
|
||||
)
|
||||
|
||||
|
@@ -45,21 +45,11 @@ typedef enum
|
||||
#define NM_DEVICE_ETHERNET_PERMANENT_HW_ADDRESS "perm-hw-address"
|
||||
#define NM_DEVICE_ETHERNET_SPEED "speed"
|
||||
|
||||
typedef struct {
|
||||
NMDevice parent;
|
||||
} NMDeviceEthernet;
|
||||
|
||||
typedef struct {
|
||||
NMDeviceClass parent;
|
||||
|
||||
} NMDeviceEthernetClass;
|
||||
|
||||
typedef NMDevice NMDeviceEthernet;
|
||||
typedef NMDeviceClass NMDeviceEthernetClass;
|
||||
|
||||
GType nm_device_ethernet_get_type (void);
|
||||
|
||||
|
||||
NMDevice *nm_device_ethernet_new (NMPlatformLink *platform_device);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* NM_DEVICE_ETHERNET_H */
|
||||
|
@@ -27,6 +27,21 @@ enum {
|
||||
};
|
||||
static guint signals[LAST_SIGNAL] = { 0 };
|
||||
|
||||
static GSList *internal_types = NULL;
|
||||
|
||||
void
|
||||
_nm_device_factory_internal_register_type (GType factory_type)
|
||||
{
|
||||
g_return_if_fail (g_slist_find (internal_types, GUINT_TO_POINTER (factory_type)) == NULL);
|
||||
internal_types = g_slist_prepend (internal_types, GUINT_TO_POINTER (factory_type));
|
||||
}
|
||||
|
||||
const GSList *
|
||||
nm_device_factory_get_internal_factory_types (void)
|
||||
{
|
||||
return internal_types;
|
||||
}
|
||||
|
||||
gboolean
|
||||
nm_device_factory_emit_component_added (NMDeviceFactory *factory, GObject *component)
|
||||
{
|
||||
@@ -91,6 +106,23 @@ nm_device_factory_get_type (void)
|
||||
return device_factory_type;
|
||||
}
|
||||
|
||||
NMDeviceType
|
||||
nm_device_factory_get_device_type (NMDeviceFactory *factory)
|
||||
{
|
||||
g_return_val_if_fail (factory != NULL, NM_DEVICE_TYPE_UNKNOWN);
|
||||
|
||||
return NM_DEVICE_FACTORY_GET_INTERFACE (factory)->get_device_type (factory);
|
||||
}
|
||||
|
||||
void
|
||||
nm_device_factory_start (NMDeviceFactory *factory)
|
||||
{
|
||||
g_return_if_fail (factory != NULL);
|
||||
|
||||
if (NM_DEVICE_FACTORY_GET_INTERFACE (factory)->start)
|
||||
NM_DEVICE_FACTORY_GET_INTERFACE (factory)->start (factory);
|
||||
}
|
||||
|
||||
NMDevice *
|
||||
nm_device_factory_new_link (NMDeviceFactory *factory,
|
||||
NMPlatformLink *plink,
|
||||
@@ -107,6 +139,7 @@ nm_device_factory_new_link (NMDeviceFactory *factory,
|
||||
NMDevice *
|
||||
nm_device_factory_create_virtual_device_for_connection (NMDeviceFactory *factory,
|
||||
NMConnection *connection,
|
||||
NMDevice *parent,
|
||||
GError **error)
|
||||
{
|
||||
NMDeviceFactory *interface;
|
||||
@@ -117,7 +150,7 @@ nm_device_factory_create_virtual_device_for_connection (NMDeviceFactory *factory
|
||||
|
||||
interface = NM_DEVICE_FACTORY_GET_INTERFACE (factory);
|
||||
if (interface->create_virtual_device_for_connection)
|
||||
return interface->create_virtual_device_for_connection (factory, connection, error);
|
||||
return interface->create_virtual_device_for_connection (factory, connection, parent, error);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@@ -42,7 +42,7 @@ typedef struct _NMDeviceFactory NMDeviceFactory;
|
||||
* Creates a #GObject that implements the #NMDeviceFactory interface. This
|
||||
* function must not emit any signals or perform any actions that would cause
|
||||
* devices or components to be created immediately. Instead these should be
|
||||
* deferred to an idle handler.
|
||||
* deferred to the "start" interface method.
|
||||
*
|
||||
* Returns: the #GObject implementing #NMDeviceFactory or %NULL
|
||||
*/
|
||||
@@ -51,16 +51,6 @@ NMDeviceFactory *nm_device_factory_create (GError **error);
|
||||
/* Should match nm_device_factory_create() */
|
||||
typedef NMDeviceFactory * (*NMDeviceFactoryCreateFunc) (GError **error);
|
||||
|
||||
/**
|
||||
* nm_device_factory_get_device_type:
|
||||
*
|
||||
* Returns: the #NMDeviceType that this plugin creates
|
||||
*/
|
||||
NMDeviceType nm_device_factory_get_device_type (void);
|
||||
|
||||
/* Should match nm_device_factory_get_device_type() */
|
||||
typedef NMDeviceType (*NMDeviceFactoryDeviceTypeFunc) (void);
|
||||
|
||||
/********************************************************************/
|
||||
|
||||
#define NM_TYPE_DEVICE_FACTORY (nm_device_factory_get_type ())
|
||||
@@ -75,6 +65,25 @@ typedef NMDeviceType (*NMDeviceFactoryDeviceTypeFunc) (void);
|
||||
struct _NMDeviceFactory {
|
||||
GTypeInterface g_iface;
|
||||
|
||||
/**
|
||||
* get_device_type:
|
||||
* @factory: the #NMDeviceFactory
|
||||
*
|
||||
* This function MUST be implemented.
|
||||
*
|
||||
* Returns: the #NMDeviceType that this plugin creates
|
||||
*/
|
||||
NMDeviceType (*get_device_type) (NMDeviceFactory *factory);
|
||||
|
||||
/**
|
||||
* start:
|
||||
* @factory: the #NMDeviceFactory
|
||||
*
|
||||
* Start the factory and discover any existing devices that the factory
|
||||
* can manage.
|
||||
*/
|
||||
void (*start) (NMDeviceFactory *factory);
|
||||
|
||||
/**
|
||||
* new_link:
|
||||
* @factory: the #NMDeviceFactory
|
||||
@@ -109,6 +118,7 @@ struct _NMDeviceFactory {
|
||||
*/
|
||||
NMDevice * (*create_virtual_device_for_connection) (NMDeviceFactory *factory,
|
||||
NMConnection *connection,
|
||||
NMDevice *parent,
|
||||
GError **error);
|
||||
|
||||
|
||||
@@ -141,17 +151,77 @@ struct _NMDeviceFactory {
|
||||
|
||||
GType nm_device_factory_get_type (void);
|
||||
|
||||
NMDeviceType nm_device_factory_get_device_type (NMDeviceFactory *factory);
|
||||
|
||||
void nm_device_factory_start (NMDeviceFactory *factory);
|
||||
|
||||
NMDevice * nm_device_factory_new_link (NMDeviceFactory *factory,
|
||||
NMPlatformLink *plink,
|
||||
GError **error);
|
||||
|
||||
NMDevice * nm_device_factory_create_virtual_device_for_connection (NMDeviceFactory *factory,
|
||||
NMConnection *connection,
|
||||
NMDevice *parent,
|
||||
GError **error);
|
||||
|
||||
/* For use by implementations */
|
||||
gboolean nm_device_factory_emit_component_added (NMDeviceFactory *factory,
|
||||
GObject *component);
|
||||
|
||||
#endif /* __NETWORKMANAGER_DEVICE_FACTORY_H__ */
|
||||
/**************************************************************************
|
||||
* INTERNAL DEVICE FACTORY FUNCTIONS - devices provided by plugins should
|
||||
* not use these functions.
|
||||
**************************************************************************/
|
||||
|
||||
#define DEFINE_DEVICE_FACTORY_INTERNAL(upper, mixed, lower, dfi_code) \
|
||||
DEFINE_DEVICE_FACTORY_INTERNAL_WITH_DEVTYPE(upper, mixed, lower, upper, dfi_code)
|
||||
|
||||
#define DEFINE_DEVICE_FACTORY_INTERNAL_WITH_DEVTYPE(upper, mixed, lower, devtype, dfi_code) \
|
||||
typedef GObject NM##mixed##Factory; \
|
||||
typedef GObjectClass NM##mixed##FactoryClass; \
|
||||
\
|
||||
static GType nm_##lower##_factory_get_type (void); \
|
||||
static void device_factory_interface_init (NMDeviceFactory *factory_iface); \
|
||||
\
|
||||
G_DEFINE_TYPE_EXTENDED (NM##mixed##Factory, nm_##lower##_factory, G_TYPE_OBJECT, 0, \
|
||||
G_IMPLEMENT_INTERFACE (NM_TYPE_DEVICE_FACTORY, device_factory_interface_init) \
|
||||
_nm_device_factory_internal_register_type (g_define_type_id);) \
|
||||
\
|
||||
/* Use a module constructor to register the factory's GType at load \
|
||||
* time, which then calls _nm_device_factory_internal_register_type() \
|
||||
* to register the factory's GType with the Manager. \
|
||||
*/ \
|
||||
static void __attribute__((constructor)) \
|
||||
register_device_factory_internal_##lower (void) \
|
||||
{ \
|
||||
g_type_init (); \
|
||||
g_type_ensure (NM_TYPE_##upper##_FACTORY); \
|
||||
} \
|
||||
\
|
||||
static NMDeviceType \
|
||||
get_device_type (NMDeviceFactory *factory) \
|
||||
{ \
|
||||
return NM_DEVICE_TYPE_##devtype; \
|
||||
} \
|
||||
\
|
||||
static void \
|
||||
device_factory_interface_init (NMDeviceFactory *factory_iface) \
|
||||
{ \
|
||||
factory_iface->get_device_type = get_device_type; \
|
||||
dfi_code \
|
||||
} \
|
||||
\
|
||||
static void \
|
||||
nm_##lower##_factory_init (NM##mixed##Factory *self) \
|
||||
{ \
|
||||
} \
|
||||
\
|
||||
static void \
|
||||
nm_##lower##_factory_class_init (NM##mixed##FactoryClass *lower##_class) \
|
||||
{ \
|
||||
}
|
||||
|
||||
void _nm_device_factory_internal_register_type (GType factory_type);
|
||||
const GSList *nm_device_factory_get_internal_factory_types (void);
|
||||
|
||||
#endif /* __NETWORKMANAGER_DEVICE_FACTORY_H__ */
|
||||
|
@@ -28,6 +28,7 @@
|
||||
#include "nm-logging.h"
|
||||
#include "nm-manager.h"
|
||||
#include "nm-platform.h"
|
||||
#include "nm-device-factory.h"
|
||||
|
||||
#include "nm-device-gre-glue.h"
|
||||
|
||||
@@ -110,18 +111,6 @@ link_changed (NMDevice *device, NMPlatformLink *info)
|
||||
|
||||
/**************************************************************/
|
||||
|
||||
NMDevice *
|
||||
nm_device_gre_new (NMPlatformLink *platform_device)
|
||||
{
|
||||
g_return_val_if_fail (platform_device != NULL, NULL);
|
||||
|
||||
return (NMDevice *) g_object_new (NM_TYPE_DEVICE_GRE,
|
||||
NM_DEVICE_PLATFORM_DEVICE, platform_device,
|
||||
NM_DEVICE_TYPE_DESC, "Gre",
|
||||
NM_DEVICE_DEVICE_TYPE, NM_DEVICE_TYPE_GENERIC,
|
||||
NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
nm_device_gre_init (NMDeviceGre *self)
|
||||
{
|
||||
@@ -269,3 +258,26 @@ nm_device_gre_class_init (NMDeviceGreClass *klass)
|
||||
G_TYPE_FROM_CLASS (klass),
|
||||
&dbus_glib_nm_device_gre_object_info);
|
||||
}
|
||||
|
||||
/*************************************************************/
|
||||
|
||||
#define NM_TYPE_GRE_FACTORY (nm_gre_factory_get_type ())
|
||||
#define NM_GRE_FACTORY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_GRE_FACTORY, NMGreFactory))
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
DEFINE_DEVICE_FACTORY_INTERNAL_WITH_DEVTYPE(GRE, Gre, gre, ETHERNET, \
|
||||
factory_iface->new_link = new_link; \
|
||||
)
|
||||
|
||||
|
@@ -45,19 +45,11 @@ G_BEGIN_DECLS
|
||||
#define NM_DEVICE_GRE_TOS "tos"
|
||||
#define NM_DEVICE_GRE_PATH_MTU_DISCOVERY "path-mtu-discovery"
|
||||
|
||||
typedef struct {
|
||||
NMDeviceGeneric parent;
|
||||
} NMDeviceGre;
|
||||
|
||||
typedef struct {
|
||||
NMDeviceGenericClass parent;
|
||||
|
||||
} NMDeviceGreClass;
|
||||
typedef NMDeviceGeneric NMDeviceGre;
|
||||
typedef NMDeviceGenericClass NMDeviceGreClass;
|
||||
|
||||
GType nm_device_gre_get_type (void);
|
||||
|
||||
NMDevice *nm_device_gre_new (NMPlatformLink *platform_device);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* NM_DEVICE_GRE_H */
|
||||
|
@@ -35,6 +35,7 @@
|
||||
#include "nm-activation-request.h"
|
||||
#include "nm-ip4-config.h"
|
||||
#include "nm-platform.h"
|
||||
#include "nm-device-factory.h"
|
||||
|
||||
#include "nm-device-infiniband-glue.h"
|
||||
|
||||
@@ -69,53 +70,6 @@ nm_device_infiniband_init (NMDeviceInfiniband * self)
|
||||
{
|
||||
}
|
||||
|
||||
NMDevice *
|
||||
nm_device_infiniband_new (NMPlatformLink *platform_device)
|
||||
{
|
||||
g_return_val_if_fail (platform_device != NULL, NULL);
|
||||
|
||||
return (NMDevice *) g_object_new (NM_TYPE_DEVICE_INFINIBAND,
|
||||
NM_DEVICE_PLATFORM_DEVICE, platform_device,
|
||||
NM_DEVICE_TYPE_DESC, "InfiniBand",
|
||||
NM_DEVICE_DEVICE_TYPE, NM_DEVICE_TYPE_INFINIBAND,
|
||||
NULL);
|
||||
}
|
||||
|
||||
NMDevice *
|
||||
nm_device_infiniband_new_partition (NMConnection *connection,
|
||||
NMDevice *parent)
|
||||
{
|
||||
NMSettingInfiniband *s_infiniband;
|
||||
int p_key, parent_ifindex;
|
||||
const char *iface;
|
||||
|
||||
g_return_val_if_fail (connection != NULL, NULL);
|
||||
g_return_val_if_fail (NM_IS_DEVICE_INFINIBAND (parent), NULL);
|
||||
|
||||
s_infiniband = nm_connection_get_setting_infiniband (connection);
|
||||
|
||||
iface = nm_setting_infiniband_get_virtual_interface_name (s_infiniband);
|
||||
g_return_val_if_fail (iface != NULL, NULL);
|
||||
|
||||
parent_ifindex = nm_device_get_ifindex (parent);
|
||||
p_key = nm_setting_infiniband_get_p_key (s_infiniband);
|
||||
|
||||
if ( !nm_platform_infiniband_partition_add (parent_ifindex, p_key)
|
||||
&& nm_platform_get_error () != NM_PLATFORM_ERROR_EXISTS) {
|
||||
nm_log_warn (LOGD_DEVICE | LOGD_INFINIBAND, "(%s): failed to add InfiniBand P_Key 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_INFINIBAND,
|
||||
NM_DEVICE_IFACE, iface,
|
||||
NM_DEVICE_DRIVER, nm_device_get_driver (parent),
|
||||
NM_DEVICE_TYPE_DESC, "InfiniBand",
|
||||
NM_DEVICE_DEVICE_TYPE, NM_DEVICE_TYPE_INFINIBAND,
|
||||
NULL);
|
||||
}
|
||||
|
||||
static guint32
|
||||
get_generic_capabilities (NMDevice *dev)
|
||||
{
|
||||
@@ -344,3 +298,66 @@ nm_device_infiniband_class_init (NMDeviceInfinibandClass *klass)
|
||||
|
||||
dbus_g_error_domain_register (NM_INFINIBAND_ERROR, NULL, NM_TYPE_INFINIBAND_ERROR);
|
||||
}
|
||||
|
||||
/*************************************************************/
|
||||
|
||||
#define NM_TYPE_INFINIBAND_FACTORY (nm_infiniband_factory_get_type ())
|
||||
#define NM_INFINIBAND_FACTORY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_INFINIBAND_FACTORY, NMInfinibandFactory))
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
static NMDevice *
|
||||
create_virtual_device_for_connection (NMDeviceFactory *factory,
|
||||
NMConnection *connection,
|
||||
NMDevice *parent,
|
||||
GError **error)
|
||||
{
|
||||
NMSettingInfiniband *s_infiniband;
|
||||
int p_key, parent_ifindex;
|
||||
const char *iface;
|
||||
|
||||
if (!nm_connection_is_type (connection, NM_SETTING_INFINIBAND_SETTING_NAME))
|
||||
return NULL;
|
||||
|
||||
g_return_val_if_fail (NM_IS_DEVICE_INFINIBAND (parent), NULL);
|
||||
|
||||
s_infiniband = nm_connection_get_setting_infiniband (connection);
|
||||
|
||||
iface = nm_setting_infiniband_get_virtual_interface_name (s_infiniband);
|
||||
g_return_val_if_fail (iface != NULL, NULL);
|
||||
|
||||
parent_ifindex = nm_device_get_ifindex (parent);
|
||||
p_key = nm_setting_infiniband_get_p_key (s_infiniband);
|
||||
|
||||
if ( !nm_platform_infiniband_partition_add (parent_ifindex, p_key)
|
||||
&& nm_platform_get_error () != NM_PLATFORM_ERROR_EXISTS) {
|
||||
nm_log_warn (LOGD_DEVICE | LOGD_INFINIBAND, "(%s): failed to add InfiniBand P_Key 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_INFINIBAND,
|
||||
NM_DEVICE_IFACE, iface,
|
||||
NM_DEVICE_DRIVER, nm_device_get_driver (parent),
|
||||
NM_DEVICE_TYPE_DESC, "InfiniBand",
|
||||
NM_DEVICE_DEVICE_TYPE, NM_DEVICE_TYPE_INFINIBAND,
|
||||
NULL);
|
||||
}
|
||||
|
||||
DEFINE_DEVICE_FACTORY_INTERNAL(INFINIBAND, Infiniband, infiniband, \
|
||||
factory_iface->new_link = new_link; \
|
||||
factory_iface->create_virtual_device_for_connection = create_virtual_device_for_connection;
|
||||
)
|
||||
|
||||
|
@@ -40,22 +40,11 @@ typedef enum {
|
||||
NM_INFINIBAND_ERROR_CONNECTION_INCOMPATIBLE, /*< nick=ConnectionIncompatible >*/
|
||||
} NMInfinibandError;
|
||||
|
||||
typedef struct {
|
||||
NMDevice parent;
|
||||
} NMDeviceInfiniband;
|
||||
|
||||
typedef struct {
|
||||
NMDeviceClass parent;
|
||||
|
||||
} NMDeviceInfinibandClass;
|
||||
|
||||
typedef NMDevice NMDeviceInfiniband;
|
||||
typedef NMDeviceClass NMDeviceInfinibandClass;
|
||||
|
||||
GType nm_device_infiniband_get_type (void);
|
||||
|
||||
NMDevice *nm_device_infiniband_new (NMPlatformLink *platform_device);
|
||||
NMDevice *nm_device_infiniband_new_partition (NMConnection *connection,
|
||||
NMDevice *parent);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* NM_DEVICE_INFINIBAND_H */
|
||||
|
@@ -28,6 +28,7 @@
|
||||
#include "nm-logging.h"
|
||||
#include "nm-manager.h"
|
||||
#include "nm-platform.h"
|
||||
#include "nm-device-factory.h"
|
||||
|
||||
#include "nm-device-macvlan-glue.h"
|
||||
|
||||
@@ -91,18 +92,6 @@ link_changed (NMDevice *device, NMPlatformLink *info)
|
||||
|
||||
/**************************************************************/
|
||||
|
||||
NMDevice *
|
||||
nm_device_macvlan_new (NMPlatformLink *platform_device)
|
||||
{
|
||||
g_return_val_if_fail (platform_device != NULL, NULL);
|
||||
|
||||
return (NMDevice *) g_object_new (NM_TYPE_DEVICE_MACVLAN,
|
||||
NM_DEVICE_PLATFORM_DEVICE, platform_device,
|
||||
NM_DEVICE_TYPE_DESC, "Macvlan",
|
||||
NM_DEVICE_DEVICE_TYPE, NM_DEVICE_TYPE_GENERIC,
|
||||
NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
nm_device_macvlan_init (NMDeviceMacvlan *self)
|
||||
{
|
||||
@@ -179,3 +168,26 @@ nm_device_macvlan_class_init (NMDeviceMacvlanClass *klass)
|
||||
G_TYPE_FROM_CLASS (klass),
|
||||
&dbus_glib_nm_device_macvlan_object_info);
|
||||
}
|
||||
|
||||
/*************************************************************/
|
||||
|
||||
#define NM_TYPE_MACVLAN_FACTORY (nm_macvlan_factory_get_type ())
|
||||
#define NM_MACVLAN_FACTORY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_MACVLAN_FACTORY, NMMacvlanFactory))
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
DEFINE_DEVICE_FACTORY_INTERNAL_WITH_DEVTYPE(MACVLAN, Macvlan, macvlan, ETHERNET, \
|
||||
factory_iface->new_link = new_link; \
|
||||
)
|
||||
|
||||
|
@@ -38,19 +38,11 @@ G_BEGIN_DECLS
|
||||
#define NM_DEVICE_MACVLAN_MODE "mode"
|
||||
#define NM_DEVICE_MACVLAN_NO_PROMISC "no-promisc"
|
||||
|
||||
typedef struct {
|
||||
NMDeviceGeneric parent;
|
||||
} NMDeviceMacvlan;
|
||||
|
||||
typedef struct {
|
||||
NMDeviceGenericClass parent;
|
||||
|
||||
} NMDeviceMacvlanClass;
|
||||
typedef NMDeviceGeneric NMDeviceMacvlan;
|
||||
typedef NMDeviceGenericClass NMDeviceMacvlanClass;
|
||||
|
||||
GType nm_device_macvlan_get_type (void);
|
||||
|
||||
NMDevice *nm_device_macvlan_new (NMPlatformLink *platform_device);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* NM_DEVICE_MACVLAN_H */
|
||||
|
@@ -28,6 +28,7 @@
|
||||
#include "nm-dbus-manager.h"
|
||||
#include "nm-logging.h"
|
||||
#include "nm-platform.h"
|
||||
#include "nm-device-factory.h"
|
||||
|
||||
#include "nm-device-tun-glue.h"
|
||||
|
||||
@@ -110,27 +111,6 @@ delay_tun_get_properties_cb (gpointer user_data)
|
||||
|
||||
/**************************************************************/
|
||||
|
||||
NMDevice *
|
||||
nm_device_tun_new (NMPlatformLink *platform_device)
|
||||
{
|
||||
const char *mode = NULL;
|
||||
|
||||
g_return_val_if_fail (platform_device != NULL, NULL);
|
||||
|
||||
if (platform_device->type == NM_LINK_TYPE_TUN)
|
||||
mode = "tun";
|
||||
else if (platform_device->type == NM_LINK_TYPE_TAP)
|
||||
mode = "tap";
|
||||
g_return_val_if_fail (mode != NULL, NULL);
|
||||
|
||||
return (NMDevice *) g_object_new (NM_TYPE_DEVICE_TUN,
|
||||
NM_DEVICE_PLATFORM_DEVICE, platform_device,
|
||||
NM_DEVICE_TYPE_DESC, "Tun",
|
||||
NM_DEVICE_DEVICE_TYPE, NM_DEVICE_TYPE_GENERIC,
|
||||
NM_DEVICE_TUN_MODE, mode,
|
||||
NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
nm_device_tun_init (NMDeviceTun *self)
|
||||
{
|
||||
@@ -282,3 +262,34 @@ nm_device_tun_class_init (NMDeviceTunClass *klass)
|
||||
G_TYPE_FROM_CLASS (klass),
|
||||
&dbus_glib_nm_device_tun_object_info);
|
||||
}
|
||||
|
||||
|
||||
/*************************************************************/
|
||||
|
||||
#define NM_TYPE_TUN_FACTORY (nm_tun_factory_get_type ())
|
||||
#define NM_TUN_FACTORY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_TUN_FACTORY, NMTunFactory))
|
||||
|
||||
static NMDevice *
|
||||
new_link (NMDeviceFactory *factory, NMPlatformLink *plink, GError **error)
|
||||
{
|
||||
const char *mode = NULL;
|
||||
|
||||
if (plink->type == NM_LINK_TYPE_TUN)
|
||||
mode = "tun";
|
||||
else if (plink->type == NM_LINK_TYPE_TAP)
|
||||
mode = "tap";
|
||||
else
|
||||
return NULL;
|
||||
|
||||
return (NMDevice *) g_object_new (NM_TYPE_DEVICE_TUN,
|
||||
NM_DEVICE_PLATFORM_DEVICE, plink,
|
||||
NM_DEVICE_TYPE_DESC, "Tun",
|
||||
NM_DEVICE_DEVICE_TYPE, NM_DEVICE_TYPE_GENERIC,
|
||||
NM_DEVICE_TUN_MODE, mode,
|
||||
NULL);
|
||||
}
|
||||
|
||||
DEFINE_DEVICE_FACTORY_INTERNAL_WITH_DEVTYPE(TUN, Tun, tun, GENERIC, \
|
||||
factory_iface->new_link = new_link; \
|
||||
)
|
||||
|
||||
|
@@ -41,19 +41,11 @@ G_BEGIN_DECLS
|
||||
#define NM_DEVICE_TUN_VNET_HDR "vnet-hdr"
|
||||
#define NM_DEVICE_TUN_MULTI_QUEUE "multi-queue"
|
||||
|
||||
typedef struct {
|
||||
NMDeviceGeneric parent;
|
||||
} NMDeviceTun;
|
||||
|
||||
typedef struct {
|
||||
NMDeviceGenericClass parent;
|
||||
|
||||
} NMDeviceTunClass;
|
||||
typedef NMDeviceGeneric NMDeviceTun;
|
||||
typedef NMDeviceGenericClass NMDeviceTunClass;
|
||||
|
||||
GType nm_device_tun_get_type (void);
|
||||
|
||||
NMDevice *nm_device_tun_new (NMPlatformLink *platform_device);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* NM_DEVICE_TUN_H */
|
||||
|
@@ -33,6 +33,7 @@
|
||||
#include "nm-manager.h"
|
||||
#include "nm-platform.h"
|
||||
#include "nm-dbus-manager.h"
|
||||
#include "nm-device-factory.h"
|
||||
|
||||
#include "nm-device-veth-glue.h"
|
||||
|
||||
@@ -98,18 +99,6 @@ get_peer (NMDeviceVeth *self)
|
||||
|
||||
/**************************************************************/
|
||||
|
||||
NMDevice *
|
||||
nm_device_veth_new (NMPlatformLink *platform_device)
|
||||
{
|
||||
g_return_val_if_fail (platform_device != NULL, NULL);
|
||||
|
||||
return (NMDevice *) g_object_new (NM_TYPE_DEVICE_VETH,
|
||||
NM_DEVICE_PLATFORM_DEVICE, platform_device,
|
||||
NM_DEVICE_TYPE_DESC, "Veth",
|
||||
NM_DEVICE_DEVICE_TYPE, NM_DEVICE_TYPE_ETHERNET,
|
||||
NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
nm_device_veth_init (NMDeviceVeth *self)
|
||||
{
|
||||
@@ -170,3 +159,26 @@ nm_device_veth_class_init (NMDeviceVethClass *klass)
|
||||
G_TYPE_FROM_CLASS (klass),
|
||||
&dbus_glib_nm_device_veth_object_info);
|
||||
}
|
||||
|
||||
/*************************************************************/
|
||||
|
||||
#define NM_TYPE_VETH_FACTORY (nm_veth_factory_get_type ())
|
||||
#define NM_VETH_FACTORY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_VETH_FACTORY, NMVethFactory))
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
DEFINE_DEVICE_FACTORY_INTERNAL_WITH_DEVTYPE(VETH, Veth, veth, ETHERNET, \
|
||||
factory_iface->new_link = new_link; \
|
||||
)
|
||||
|
||||
|
@@ -36,19 +36,11 @@ G_BEGIN_DECLS
|
||||
|
||||
#define NM_DEVICE_VETH_PEER "peer"
|
||||
|
||||
typedef struct {
|
||||
NMDeviceEthernet parent;
|
||||
} NMDeviceVeth;
|
||||
|
||||
typedef struct {
|
||||
NMDeviceEthernetClass parent;
|
||||
|
||||
} NMDeviceVethClass;
|
||||
typedef NMDeviceEthernet NMDeviceVeth;
|
||||
typedef NMDeviceEthernetClass NMDeviceVethClass;
|
||||
|
||||
GType nm_device_veth_get_type (void);
|
||||
|
||||
NMDevice *nm_device_veth_new (NMPlatformLink *platform_device);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* NM_DEVICE_VETH_H */
|
||||
|
@@ -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;
|
||||
)
|
||||
|
||||
|
@@ -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 */
|
||||
|
@@ -29,6 +29,7 @@
|
||||
#include "nm-manager.h"
|
||||
#include "nm-platform.h"
|
||||
#include "nm-utils.h"
|
||||
#include "nm-device-factory.h"
|
||||
|
||||
#include "nm-device-vxlan-glue.h"
|
||||
|
||||
@@ -133,18 +134,6 @@ link_changed (NMDevice *device, NMPlatformLink *info)
|
||||
|
||||
/**************************************************************/
|
||||
|
||||
NMDevice *
|
||||
nm_device_vxlan_new (NMPlatformLink *platform_device)
|
||||
{
|
||||
g_return_val_if_fail (platform_device != NULL, NULL);
|
||||
|
||||
return (NMDevice *) g_object_new (NM_TYPE_DEVICE_VXLAN,
|
||||
NM_DEVICE_PLATFORM_DEVICE, platform_device,
|
||||
NM_DEVICE_TYPE_DESC, "Vxlan",
|
||||
NM_DEVICE_DEVICE_TYPE, NM_DEVICE_TYPE_GENERIC,
|
||||
NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
nm_device_vxlan_init (NMDeviceVxlan *self)
|
||||
{
|
||||
@@ -357,3 +346,26 @@ nm_device_vxlan_class_init (NMDeviceVxlanClass *klass)
|
||||
G_TYPE_FROM_CLASS (klass),
|
||||
&dbus_glib_nm_device_vxlan_object_info);
|
||||
}
|
||||
|
||||
/*************************************************************/
|
||||
|
||||
#define NM_TYPE_VXLAN_FACTORY (nm_vxlan_factory_get_type ())
|
||||
#define NM_VXLAN_FACTORY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_VXLAN_FACTORY, NMVxlanFactory))
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
DEFINE_DEVICE_FACTORY_INTERNAL_WITH_DEVTYPE(VXLAN, Vxlan, vxlan, GENERIC, \
|
||||
factory_iface->new_link = new_link; \
|
||||
)
|
||||
|
||||
|
@@ -51,19 +51,11 @@ G_BEGIN_DECLS
|
||||
#define NM_DEVICE_VXLAN_L2MISS "l2miss"
|
||||
#define NM_DEVICE_VXLAN_L3MISS "l3miss"
|
||||
|
||||
typedef struct {
|
||||
NMDeviceGeneric parent;
|
||||
} NMDeviceVxlan;
|
||||
|
||||
typedef struct {
|
||||
NMDeviceGenericClass parent;
|
||||
|
||||
} NMDeviceVxlanClass;
|
||||
typedef NMDeviceGeneric NMDeviceVxlan;
|
||||
typedef NMDeviceGenericClass NMDeviceVxlanClass;
|
||||
|
||||
GType nm_device_vxlan_get_type (void);
|
||||
|
||||
NMDevice *nm_device_vxlan_new (NMPlatformLink *platform_device);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* NM_DEVICE_VXLAN_H */
|
||||
|
@@ -1215,6 +1215,14 @@ nm_device_owns_iface (NMDevice *self, const char *iface)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
NMConnection *
|
||||
nm_device_new_default_connection (NMDevice *self)
|
||||
{
|
||||
if (NM_DEVICE_GET_CLASS (self)->new_default_connection)
|
||||
return NM_DEVICE_GET_CLASS (self)->new_default_connection (self);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
slave_state_changed (NMDevice *slave,
|
||||
NMDeviceState slave_new_state,
|
||||
|
@@ -209,6 +209,8 @@ typedef struct {
|
||||
gboolean (* component_added) (NMDevice *self, GObject *component);
|
||||
|
||||
gboolean (* owns_iface) (NMDevice *self, const char *iface);
|
||||
|
||||
NMConnection * (* new_default_connection) (NMDevice *self);
|
||||
} NMDeviceClass;
|
||||
|
||||
|
||||
@@ -362,6 +364,8 @@ gboolean nm_device_notify_component_added (NMDevice *device, GObject *component)
|
||||
|
||||
gboolean nm_device_owns_iface (NMDevice *device, const char *iface);
|
||||
|
||||
NMConnection *nm_device_new_default_connection (NMDevice *self);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
/* For testing only */
|
||||
|
@@ -1,7 +1,6 @@
|
||||
{
|
||||
global:
|
||||
nm_device_factory_create;
|
||||
nm_device_factory_get_device_type;
|
||||
local:
|
||||
*;
|
||||
};
|
||||
|
@@ -35,12 +35,13 @@ static void device_factory_interface_init (NMDeviceFactory *factory_iface);
|
||||
G_DEFINE_TYPE_EXTENDED (NMTeamFactory, nm_team_factory, G_TYPE_OBJECT, 0,
|
||||
G_IMPLEMENT_INTERFACE (NM_TYPE_DEVICE_FACTORY, device_factory_interface_init))
|
||||
|
||||
#define NM_TEAM_FACTORY_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_TEAM_FACTORY, NMTeamFactoryPrivate))
|
||||
|
||||
typedef struct {
|
||||
char dummy;
|
||||
} NMTeamFactoryPrivate;
|
||||
/************************************************************************/
|
||||
|
||||
G_MODULE_EXPORT NMDeviceFactory *
|
||||
nm_device_factory_create (GError **error)
|
||||
{
|
||||
return (NMDeviceFactory *) g_object_new (NM_TYPE_TEAM_FACTORY, NULL);
|
||||
}
|
||||
|
||||
/************************************************************************/
|
||||
|
||||
@@ -55,6 +56,7 @@ new_link (NMDeviceFactory *factory, NMPlatformLink *plink, GError **error)
|
||||
static NMDevice *
|
||||
create_virtual_device_for_connection (NMDeviceFactory *factory,
|
||||
NMConnection *connection,
|
||||
NMDevice *parent,
|
||||
GError **error)
|
||||
{
|
||||
if (nm_connection_is_type (connection, NM_SETTING_TEAM_SETTING_NAME))
|
||||
@@ -62,20 +64,10 @@ create_virtual_device_for_connection (NMDeviceFactory *factory,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/************************************************************************/
|
||||
|
||||
#define PLUGIN_TYPE NM_DEVICE_TYPE_TEAM
|
||||
|
||||
G_MODULE_EXPORT NMDeviceFactory *
|
||||
nm_device_factory_create (GError **error)
|
||||
static NMDeviceType
|
||||
get_device_type (NMDeviceFactory *factory)
|
||||
{
|
||||
return (NMDeviceFactory *) g_object_new (NM_TYPE_TEAM_FACTORY, NULL);
|
||||
}
|
||||
|
||||
G_MODULE_EXPORT NMDeviceType
|
||||
nm_device_factory_get_device_type (void)
|
||||
{
|
||||
return PLUGIN_TYPE;
|
||||
return NM_DEVICE_TYPE_TEAM;
|
||||
}
|
||||
|
||||
/************************************************************************/
|
||||
@@ -90,21 +82,10 @@ device_factory_interface_init (NMDeviceFactory *factory_iface)
|
||||
{
|
||||
factory_iface->new_link = new_link;
|
||||
factory_iface->create_virtual_device_for_connection = create_virtual_device_for_connection;
|
||||
}
|
||||
|
||||
static void
|
||||
dispose (GObject *object)
|
||||
{
|
||||
/* Chain up to the parent class */
|
||||
G_OBJECT_CLASS (nm_team_factory_parent_class)->dispose (object);
|
||||
factory_iface->get_device_type = get_device_type;
|
||||
}
|
||||
|
||||
static void
|
||||
nm_team_factory_class_init (NMTeamFactoryClass *klass)
|
||||
{
|
||||
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
||||
|
||||
g_type_class_add_private (object_class, sizeof (NMTeamFactoryPrivate));
|
||||
|
||||
object_class->dispose = dispose;
|
||||
}
|
||||
|
@@ -1,7 +1,6 @@
|
||||
{
|
||||
global:
|
||||
nm_device_factory_create;
|
||||
nm_device_factory_get_device_type;
|
||||
local:
|
||||
*;
|
||||
};
|
||||
|
@@ -46,20 +46,12 @@ G_DEFINE_TYPE_EXTENDED (NMWifiFactory, nm_wifi_factory, G_TYPE_OBJECT, 0,
|
||||
|
||||
/**************************************************************************/
|
||||
|
||||
#define PLUGIN_TYPE NM_DEVICE_TYPE_WIFI
|
||||
|
||||
G_MODULE_EXPORT NMDeviceFactory *
|
||||
nm_device_factory_create (GError **error)
|
||||
{
|
||||
return (NMDeviceFactory *) g_object_new (NM_TYPE_WIFI_FACTORY, NULL);
|
||||
}
|
||||
|
||||
G_MODULE_EXPORT NMDeviceType
|
||||
nm_device_factory_get_device_type (void)
|
||||
{
|
||||
return PLUGIN_TYPE;
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
|
||||
static NMDevice *
|
||||
@@ -72,10 +64,17 @@ new_link (NMDeviceFactory *factory, NMPlatformLink *plink, GError **error)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static NMDeviceType
|
||||
get_device_type (NMDeviceFactory *factory)
|
||||
{
|
||||
return NM_DEVICE_TYPE_WIFI;
|
||||
}
|
||||
|
||||
static void
|
||||
device_factory_interface_init (NMDeviceFactory *factory_iface)
|
||||
{
|
||||
factory_iface->new_link = new_link;
|
||||
factory_iface->get_device_type = get_device_type;
|
||||
}
|
||||
|
||||
static void
|
||||
|
@@ -1,7 +1,6 @@
|
||||
{
|
||||
global:
|
||||
nm_device_factory_create;
|
||||
nm_device_factory_get_device_type;
|
||||
local:
|
||||
*;
|
||||
};
|
||||
|
@@ -44,20 +44,12 @@ G_DEFINE_TYPE_EXTENDED (NMWimaxFactory, nm_wimax_factory, G_TYPE_OBJECT, 0,
|
||||
|
||||
/**************************************************************************/
|
||||
|
||||
#define PLUGIN_TYPE NM_DEVICE_TYPE_WIMAX
|
||||
|
||||
G_MODULE_EXPORT NMDeviceFactory *
|
||||
nm_device_factory_create (GError **error)
|
||||
{
|
||||
return (NMDeviceFactory *) g_object_new (NM_TYPE_WIMAX_FACTORY, NULL);
|
||||
}
|
||||
|
||||
G_MODULE_EXPORT NMDeviceType
|
||||
nm_device_factory_get_device_type (void)
|
||||
{
|
||||
return PLUGIN_TYPE;
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
|
||||
static NMDevice *
|
||||
@@ -72,10 +64,17 @@ new_link (NMDeviceFactory *factory, NMPlatformLink *plink, GError **error)
|
||||
return (NMDevice *) nm_device_wimax_new (plink);
|
||||
}
|
||||
|
||||
static NMDeviceType
|
||||
get_device_type (NMDeviceFactory *factory)
|
||||
{
|
||||
return NM_DEVICE_TYPE_WIMAX;
|
||||
}
|
||||
|
||||
static void
|
||||
device_factory_interface_init (NMDeviceFactory *factory_iface)
|
||||
{
|
||||
factory_iface->new_link = new_link;
|
||||
factory_iface->get_device_type = get_device_type;
|
||||
}
|
||||
|
||||
static void
|
||||
|
@@ -1,7 +1,6 @@
|
||||
{
|
||||
global:
|
||||
nm_device_factory_create;
|
||||
nm_device_factory_get_device_type;
|
||||
local:
|
||||
*;
|
||||
};
|
||||
|
@@ -43,20 +43,12 @@ typedef struct {
|
||||
|
||||
/************************************************************************/
|
||||
|
||||
#define PLUGIN_TYPE NM_DEVICE_TYPE_MODEM
|
||||
|
||||
G_MODULE_EXPORT NMDeviceFactory *
|
||||
nm_device_factory_create (GError **error)
|
||||
{
|
||||
return (NMDeviceFactory *) g_object_new (NM_TYPE_WWAN_FACTORY, NULL);
|
||||
}
|
||||
|
||||
G_MODULE_EXPORT NMDeviceType
|
||||
nm_device_factory_get_device_type (void)
|
||||
{
|
||||
return PLUGIN_TYPE;
|
||||
}
|
||||
|
||||
/************************************************************************/
|
||||
|
||||
static void
|
||||
@@ -93,9 +85,17 @@ modem_added_cb (NMModemManager *manager,
|
||||
g_object_unref (device);
|
||||
}
|
||||
|
||||
static void
|
||||
nm_wwan_factory_init (NMWwanFactory *self)
|
||||
|
||||
static NMDeviceType
|
||||
get_device_type (NMDeviceFactory *factory)
|
||||
{
|
||||
return NM_DEVICE_TYPE_MODEM;
|
||||
}
|
||||
|
||||
static void
|
||||
start (NMDeviceFactory *factory)
|
||||
{
|
||||
NMWwanFactory *self = NM_WWAN_FACTORY (factory);
|
||||
NMWwanFactoryPrivate *priv = NM_WWAN_FACTORY_GET_PRIVATE (self);
|
||||
|
||||
priv->mm = g_object_new (NM_TYPE_MODEM_MANAGER, NULL);
|
||||
@@ -106,9 +106,16 @@ nm_wwan_factory_init (NMWwanFactory *self)
|
||||
self);
|
||||
}
|
||||
|
||||
static void
|
||||
nm_wwan_factory_init (NMWwanFactory *self)
|
||||
{
|
||||
}
|
||||
|
||||
static void
|
||||
device_factory_interface_init (NMDeviceFactory *factory_iface)
|
||||
{
|
||||
factory_iface->get_device_type = get_device_type;
|
||||
factory_iface->start = start;
|
||||
}
|
||||
|
||||
static void
|
||||
|
260
src/nm-manager.c
260
src/nm-manager.c
@@ -39,17 +39,7 @@
|
||||
#include "nm-dbus-manager.h"
|
||||
#include "nm-vpn-manager.h"
|
||||
#include "nm-device.h"
|
||||
#include "nm-device-ethernet.h"
|
||||
#include "nm-device-infiniband.h"
|
||||
#include "nm-device-bond.h"
|
||||
#include "nm-device-bridge.h"
|
||||
#include "nm-device-vlan.h"
|
||||
#include "nm-device-generic.h"
|
||||
#include "nm-device-veth.h"
|
||||
#include "nm-device-tun.h"
|
||||
#include "nm-device-macvlan.h"
|
||||
#include "nm-device-vxlan.h"
|
||||
#include "nm-device-gre.h"
|
||||
#include "nm-setting-connection.h"
|
||||
#include "nm-setting-wireless.h"
|
||||
#include "nm-setting-vpn.h"
|
||||
@@ -496,24 +486,6 @@ nm_manager_get_device_by_path (NMManager *manager, const char *path)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
NMDevice *
|
||||
nm_manager_get_device_by_master (NMManager *manager, const char *master, const char *driver)
|
||||
{
|
||||
GSList *iter;
|
||||
|
||||
g_return_val_if_fail (master != NULL, NULL);
|
||||
|
||||
for (iter = NM_MANAGER_GET_PRIVATE (manager)->devices; iter; iter = iter->next) {
|
||||
NMDevice *device = NM_DEVICE (iter->data);
|
||||
|
||||
if (!strcmp (nm_device_get_iface (device), master) &&
|
||||
(!driver || !strcmp (nm_device_get_driver (device), driver)))
|
||||
return device;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
NMDevice *
|
||||
nm_manager_get_device_by_ifindex (NMManager *manager, int ifindex)
|
||||
{
|
||||
@@ -1071,28 +1043,20 @@ 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_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 if (nm_connection_is_type (connection, NM_SETTING_INFINIBAND_SETTING_NAME)) {
|
||||
device = nm_device_infiniband_new_partition (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, &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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1864,20 +1828,7 @@ find_device_by_ip_iface (NMManager *self, const gchar *iface)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static NMDevice *
|
||||
find_device_by_ifindex (NMManager *self, guint32 ifindex)
|
||||
{
|
||||
NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self);
|
||||
GSList *iter;
|
||||
|
||||
for (iter = priv->devices; iter; iter = g_slist_next (iter)) {
|
||||
NMDevice *candidate = NM_DEVICE (iter->data);
|
||||
|
||||
if (ifindex == nm_device_get_ifindex (candidate))
|
||||
return candidate;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
/*******************************************************************/
|
||||
|
||||
static void
|
||||
factory_device_added_cb (NMDeviceFactory *factory,
|
||||
@@ -1904,7 +1855,6 @@ factory_component_added_cb (NMDeviceFactory *factory,
|
||||
|
||||
#define PLUGIN_PREFIX "libnm-device-plugin-"
|
||||
#define PLUGIN_PATH_TAG "NMManager-plugin-path"
|
||||
#define PLUGIN_TYPEFUNC_TAG "typefunc"
|
||||
|
||||
struct read_device_factory_paths_data {
|
||||
char *path;
|
||||
@@ -1995,26 +1945,76 @@ NEXT:
|
||||
return result;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
_register_device_factory (NMManager *self,
|
||||
NMDeviceFactory *factory,
|
||||
gboolean duplicate_check,
|
||||
const char *path,
|
||||
GError **error)
|
||||
{
|
||||
NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self);
|
||||
NMDeviceType ftype;
|
||||
GSList *iter;
|
||||
|
||||
if (duplicate_check) {
|
||||
/* Make sure we don't double-register factories */
|
||||
ftype = nm_device_factory_get_device_type (factory);
|
||||
for (iter = priv->factories; iter; iter = iter->next) {
|
||||
if (ftype == nm_device_factory_get_device_type (iter->data)) {
|
||||
g_set_error (error, NM_MANAGER_ERROR, NM_MANAGER_ERROR_INTERNAL,
|
||||
"multiple plugins for same type (using '%s' instead of '%s')",
|
||||
(char *) g_object_get_data (G_OBJECT (iter->data), PLUGIN_PATH_TAG),
|
||||
path);
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
priv->factories = g_slist_append (priv->factories, factory);
|
||||
|
||||
g_signal_connect (factory,
|
||||
NM_DEVICE_FACTORY_DEVICE_ADDED,
|
||||
G_CALLBACK (factory_device_added_cb),
|
||||
self);
|
||||
g_signal_connect (factory,
|
||||
NM_DEVICE_FACTORY_COMPONENT_ADDED,
|
||||
G_CALLBACK (factory_component_added_cb),
|
||||
self);
|
||||
g_object_set_data_full (G_OBJECT (factory), PLUGIN_PATH_TAG,
|
||||
g_strdup (path), g_free);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
load_device_factories (NMManager *self)
|
||||
{
|
||||
NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self);
|
||||
char **path;
|
||||
char **paths;
|
||||
NMDeviceFactory *factory;
|
||||
const GSList *iter;
|
||||
GError *error = NULL;
|
||||
char **path, **paths;
|
||||
|
||||
/* Register internal factories first */
|
||||
for (iter = nm_device_factory_get_internal_factory_types (); iter; iter = iter->next) {
|
||||
GType ftype = GPOINTER_TO_UINT (iter->data);
|
||||
|
||||
factory = (NMDeviceFactory *) g_object_new (ftype, NULL);
|
||||
g_assert (factory);
|
||||
if (_register_device_factory (self, factory, FALSE, "internal", &error)) {
|
||||
nm_log_dbg (LOGD_HW, "Loaded device plugin: %s", g_type_name (ftype));
|
||||
} else {
|
||||
nm_log_warn (LOGD_HW, "Loading device plugin failed: %s", error->message);
|
||||
g_object_unref (factory);
|
||||
g_clear_error (&error);
|
||||
}
|
||||
}
|
||||
|
||||
paths = read_device_factory_paths ();
|
||||
if (!paths)
|
||||
return;
|
||||
|
||||
for (path = paths; *path; path++) {
|
||||
GError *error = NULL;
|
||||
GModule *plugin;
|
||||
NMDeviceFactory *factory;
|
||||
NMDeviceFactoryCreateFunc create_func;
|
||||
NMDeviceFactoryDeviceTypeFunc type_func;
|
||||
NMDeviceType dev_type;
|
||||
const char *found = NULL;
|
||||
GSList *iter;
|
||||
const char *item;
|
||||
|
||||
item = strrchr (*path, '/');
|
||||
@@ -2027,30 +2027,6 @@ load_device_factories (NMManager *self)
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!g_module_symbol (plugin, "nm_device_factory_get_device_type", (gpointer) &type_func)) {
|
||||
nm_log_warn (LOGD_HW, "(%s): failed to find device factory type: %s", item, g_module_error ());
|
||||
g_module_close (plugin);
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Make sure we don't double-load plugins */
|
||||
dev_type = type_func ();
|
||||
for (iter = priv->factories; iter; iter = iter->next) {
|
||||
NMDeviceFactoryDeviceTypeFunc loaded_type_func;
|
||||
|
||||
loaded_type_func = g_object_get_data (G_OBJECT (iter->data), PLUGIN_TYPEFUNC_TAG);
|
||||
if (dev_type == loaded_type_func ()) {
|
||||
found = g_object_get_data (G_OBJECT (iter->data), PLUGIN_PATH_TAG);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (found) {
|
||||
nm_log_warn (LOGD_HW, "Found multiple device plugins for same type: use '%s' instead of '%s'",
|
||||
found, g_module_name (plugin));
|
||||
g_module_close (plugin);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!g_module_symbol (plugin, "nm_device_factory_create", (gpointer) &create_func)) {
|
||||
nm_log_warn (LOGD_HW, "(%s): failed to find device factory creator: %s", item, g_module_error ());
|
||||
g_module_close (plugin);
|
||||
@@ -2067,28 +2043,21 @@ load_device_factories (NMManager *self)
|
||||
}
|
||||
g_clear_error (&error);
|
||||
|
||||
g_module_make_resident (plugin);
|
||||
priv->factories = g_slist_prepend (priv->factories, factory);
|
||||
|
||||
g_signal_connect (factory,
|
||||
NM_DEVICE_FACTORY_DEVICE_ADDED,
|
||||
G_CALLBACK (factory_device_added_cb),
|
||||
self);
|
||||
g_signal_connect (factory,
|
||||
NM_DEVICE_FACTORY_COMPONENT_ADDED,
|
||||
G_CALLBACK (factory_component_added_cb),
|
||||
self);
|
||||
g_object_set_data_full (G_OBJECT (factory), PLUGIN_PATH_TAG,
|
||||
g_strdup (g_module_name (plugin)), g_free);
|
||||
g_object_set_data (G_OBJECT (factory), PLUGIN_TYPEFUNC_TAG, type_func);
|
||||
|
||||
nm_log_info (LOGD_HW, "Loaded device plugin: %s", g_module_name (plugin));
|
||||
};
|
||||
if (_register_device_factory (self, factory, TRUE, g_module_name (plugin), &error)) {
|
||||
nm_log_info (LOGD_HW, "Loaded device plugin: %s", g_module_name (plugin));
|
||||
g_module_make_resident (plugin);
|
||||
} else {
|
||||
nm_log_warn (LOGD_HW, "Loading device plugin failed: %s", error->message);
|
||||
g_object_unref (factory);
|
||||
g_module_close (plugin);
|
||||
g_clear_error (&error);
|
||||
}
|
||||
}
|
||||
g_strfreev (paths);
|
||||
|
||||
priv->factories = g_slist_reverse (priv->factories);
|
||||
}
|
||||
|
||||
/*******************************************************************/
|
||||
|
||||
static void
|
||||
platform_link_added (NMManager *self,
|
||||
int ifindex,
|
||||
@@ -2105,7 +2074,7 @@ platform_link_added (NMManager *self,
|
||||
if (priv->ignore_link_added_cb > 0)
|
||||
return;
|
||||
|
||||
if (find_device_by_ifindex (self, ifindex))
|
||||
if (nm_manager_get_device_by_ifindex (self, ifindex))
|
||||
return;
|
||||
|
||||
/* Try registered device factories */
|
||||
@@ -2135,57 +2104,7 @@ platform_link_added (NMManager *self,
|
||||
return;
|
||||
|
||||
if (device == NULL) {
|
||||
int parent_ifindex = -1;
|
||||
NMDevice *parent;
|
||||
|
||||
switch (plink->type) {
|
||||
case NM_LINK_TYPE_ETHERNET:
|
||||
device = nm_device_ethernet_new (plink);
|
||||
break;
|
||||
case NM_LINK_TYPE_INFINIBAND:
|
||||
device = nm_device_infiniband_new (plink);
|
||||
break;
|
||||
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)) {
|
||||
parent = find_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_VETH:
|
||||
device = nm_device_veth_new (plink);
|
||||
break;
|
||||
case NM_LINK_TYPE_TUN:
|
||||
case NM_LINK_TYPE_TAP:
|
||||
device = nm_device_tun_new (plink);
|
||||
break;
|
||||
case NM_LINK_TYPE_MACVLAN:
|
||||
case NM_LINK_TYPE_MACVTAP:
|
||||
device = nm_device_macvlan_new (plink);
|
||||
break;
|
||||
case NM_LINK_TYPE_VXLAN:
|
||||
device = nm_device_vxlan_new (plink);
|
||||
break;
|
||||
case NM_LINK_TYPE_GRE:
|
||||
case NM_LINK_TYPE_GRETAP:
|
||||
device = nm_device_gre_new (plink);
|
||||
break;
|
||||
|
||||
case NM_LINK_TYPE_WWAN_ETHERNET:
|
||||
/* WWAN pseudo-ethernet interfaces are handled automatically by
|
||||
@@ -2228,7 +2147,7 @@ platform_link_cb (NMPlatform *platform,
|
||||
NMManager *self = NM_MANAGER (user_data);
|
||||
NMDevice *device;
|
||||
|
||||
device = find_device_by_ifindex (self, ifindex);
|
||||
device = nm_manager_get_device_by_ifindex (self, ifindex);
|
||||
if (device)
|
||||
remove_device (self, device, FALSE);
|
||||
break;
|
||||
@@ -4175,6 +4094,7 @@ void
|
||||
nm_manager_start (NMManager *self)
|
||||
{
|
||||
NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self);
|
||||
GSList *iter;
|
||||
guint i;
|
||||
|
||||
/* Set initial radio enabled/disabled state */
|
||||
@@ -4205,6 +4125,10 @@ nm_manager_start (NMManager *self)
|
||||
system_unmanaged_devices_changed_cb (priv->settings, NULL, self);
|
||||
system_hostname_changed_cb (priv->settings, NULL, self);
|
||||
|
||||
/* Start device factories */
|
||||
for (iter = priv->factories; iter; iter = iter->next)
|
||||
nm_device_factory_start (iter->data);
|
||||
|
||||
nm_platform_query_devices ();
|
||||
|
||||
/*
|
||||
|
@@ -92,45 +92,38 @@ typedef struct {
|
||||
GType nm_manager_get_type (void);
|
||||
|
||||
/* nm_manager_new() should only be used by main.c */
|
||||
NMManager *nm_manager_new (NMSettings *settings,
|
||||
const char *state_file,
|
||||
gboolean initial_net_enabled,
|
||||
gboolean initial_wifi_enabled,
|
||||
gboolean initial_wwan_enabled,
|
||||
gboolean initial_wimax_enabled,
|
||||
GError **error);
|
||||
NMManager * nm_manager_new (NMSettings *settings,
|
||||
const char *state_file,
|
||||
gboolean initial_net_enabled,
|
||||
gboolean initial_wifi_enabled,
|
||||
gboolean initial_wwan_enabled,
|
||||
gboolean initial_wimax_enabled,
|
||||
GError **error);
|
||||
|
||||
NMManager *nm_manager_get (void);
|
||||
NMManager * nm_manager_get (void);
|
||||
|
||||
void nm_manager_start (NMManager *manager);
|
||||
|
||||
const GSList *nm_manager_get_active_connections (NMManager *manager);
|
||||
GSList *nm_manager_get_activatable_connections (NMManager *manager);
|
||||
void nm_manager_start (NMManager *manager);
|
||||
NMState nm_manager_get_state (NMManager *manager);
|
||||
const GSList *nm_manager_get_active_connections (NMManager *manager);
|
||||
GSList * nm_manager_get_activatable_connections (NMManager *manager);
|
||||
|
||||
/* Device handling */
|
||||
|
||||
const GSList *nm_manager_get_devices (NMManager *manager);
|
||||
const GSList * nm_manager_get_devices (NMManager *manager);
|
||||
|
||||
NMDevice *nm_manager_get_device_by_master (NMManager *manager,
|
||||
const char *master,
|
||||
const char *driver);
|
||||
NMDevice *nm_manager_get_device_by_ifindex (NMManager *manager,
|
||||
int ifindex);
|
||||
NMDevice * nm_manager_get_device_by_ifindex (NMManager *manager,
|
||||
int ifindex);
|
||||
|
||||
NMActiveConnection *nm_manager_activate_connection (NMManager *manager,
|
||||
NMConnection *connection,
|
||||
const char *specific_object,
|
||||
NMDevice *device,
|
||||
NMAuthSubject *subject,
|
||||
GError **error);
|
||||
NMActiveConnection *nm_manager_activate_connection (NMManager *manager,
|
||||
NMConnection *connection,
|
||||
const char *specific_object,
|
||||
NMDevice *device,
|
||||
NMAuthSubject *subject,
|
||||
GError **error);
|
||||
|
||||
gboolean nm_manager_deactivate_connection (NMManager *manager,
|
||||
const char *connection_path,
|
||||
NMDeviceStateReason reason,
|
||||
GError **error);
|
||||
|
||||
/* State handling */
|
||||
|
||||
NMState nm_manager_get_state (NMManager *manager);
|
||||
gboolean nm_manager_deactivate_connection (NMManager *manager,
|
||||
const char *connection_path,
|
||||
NMDeviceStateReason reason,
|
||||
GError **error);
|
||||
|
||||
#endif /* __NETWORKMANAGER_MANAGER_H__ */
|
||||
|
@@ -67,7 +67,6 @@
|
||||
#include "nm-session-monitor.h"
|
||||
#include "plugins/keyfile/plugin.h"
|
||||
#include "nm-agent-manager.h"
|
||||
#include "nm-settings-utils.h"
|
||||
#include "nm-connection-provider.h"
|
||||
#include "nm-config.h"
|
||||
#include "NetworkManagerUtils.h"
|
||||
@@ -1585,55 +1584,22 @@ default_wired_clear_tag (NMSettings *self,
|
||||
void
|
||||
nm_settings_device_added (NMSettings *self, NMDevice *device)
|
||||
{
|
||||
NMSettingsPrivate *priv = NM_SETTINGS_GET_PRIVATE (self);
|
||||
NMConnection *connection;
|
||||
NMSettingsConnection *added;
|
||||
NMSetting *setting;
|
||||
GError *error = NULL;
|
||||
const char *hw_address;
|
||||
char *defname, *uuid;
|
||||
GByteArray *mac;
|
||||
|
||||
if (!NM_IS_DEVICE_ETHERNET (device))
|
||||
return;
|
||||
|
||||
/* If the device isn't managed or it already has a default wired connection,
|
||||
* ignore it.
|
||||
*/
|
||||
if ( !nm_device_get_managed (device)
|
||||
|| g_object_get_data (G_OBJECT (device), DEFAULT_WIRED_CONNECTION_TAG)
|
||||
|| have_connection_for_device (self, device)
|
||||
|| !nm_config_get_ethernet_can_auto_default (priv->config, device))
|
||||
|| have_connection_for_device (self, device))
|
||||
return;
|
||||
|
||||
hw_address = nm_device_get_hw_address (device);
|
||||
if (!hw_address)
|
||||
connection = nm_device_new_default_connection (device);
|
||||
if (!connection)
|
||||
return;
|
||||
|
||||
connection = nm_simple_connection_new ();
|
||||
setting = nm_setting_connection_new ();
|
||||
nm_connection_add_setting (connection, setting);
|
||||
|
||||
defname = nm_settings_utils_get_default_wired_name (priv->connections);
|
||||
uuid = nm_utils_uuid_generate ();
|
||||
g_object_set (setting,
|
||||
NM_SETTING_CONNECTION_ID, defname,
|
||||
NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRED_SETTING_NAME,
|
||||
NM_SETTING_CONNECTION_AUTOCONNECT, TRUE,
|
||||
NM_SETTING_CONNECTION_UUID, uuid,
|
||||
NM_SETTING_CONNECTION_TIMESTAMP, (guint64) time (NULL),
|
||||
NULL);
|
||||
g_free (uuid);
|
||||
g_free (defname);
|
||||
|
||||
/* Lock the connection to the device */
|
||||
setting = nm_setting_wired_new ();
|
||||
nm_connection_add_setting (connection, setting);
|
||||
|
||||
mac = nm_utils_hwaddr_atoba (hw_address, ETH_ALEN);
|
||||
g_object_set (setting, NM_SETTING_WIRED_MAC_ADDRESS, mac, NULL);
|
||||
g_byte_array_unref (mac);
|
||||
|
||||
/* Add the connection */
|
||||
added = nm_settings_add_connection (self, connection, FALSE, &error);
|
||||
g_object_unref (connection);
|
||||
|
@@ -1,24 +0,0 @@
|
||||
AM_CPPFLAGS = \
|
||||
-I$(top_srcdir)/include \
|
||||
-I$(top_srcdir)/libnm-core \
|
||||
-I$(top_builddir)/libnm-core \
|
||||
-I$(top_srcdir)/src/settings \
|
||||
-DG_LOG_DOMAIN=\""NetworkManager"\" \
|
||||
-DNETWORKMANAGER_COMPILATION \
|
||||
-DNM_VERSION_MAX_ALLOWED=NM_VERSION_NEXT_STABLE \
|
||||
$(GLIB_CFLAGS)
|
||||
|
||||
noinst_PROGRAMS = \
|
||||
test-wired-defname
|
||||
|
||||
####### wired defname test #######
|
||||
|
||||
test_wired_defname_SOURCES = \
|
||||
test-wired-defname.c
|
||||
|
||||
test_wired_defname_LDADD = \
|
||||
$(top_builddir)/src/libNetworkManager.la
|
||||
|
||||
###########################################
|
||||
|
||||
TESTS = test-wired-defname
|
@@ -6,6 +6,7 @@ AM_CPPFLAGS = \
|
||||
-I$(top_builddir)/libnm-core \
|
||||
-I$(top_srcdir)/src/platform \
|
||||
-I$(top_srcdir)/src/dhcp-manager \
|
||||
-I$(top_srcdir)/src/devices \
|
||||
-I$(top_srcdir)/src \
|
||||
-I$(top_builddir)/src \
|
||||
-DG_LOG_DOMAIN=\""NetworkManager"\" \
|
||||
@@ -20,7 +21,8 @@ noinst_PROGRAMS = \
|
||||
test-ip4-config \
|
||||
test-ip6-config \
|
||||
test-dcb \
|
||||
test-resolvconf-capture
|
||||
test-resolvconf-capture \
|
||||
test-wired-defname
|
||||
|
||||
####### ip4 config test #######
|
||||
|
||||
@@ -70,11 +72,42 @@ test_general_with_expect_SOURCES = \
|
||||
test_general_with_expect_LDADD = \
|
||||
$(top_builddir)/src/libNetworkManager.la
|
||||
|
||||
####### wired defname test #######
|
||||
|
||||
test_wired_defname_SOURCES = \
|
||||
test-wired-defname.c
|
||||
|
||||
test_wired_defname_LDADD = \
|
||||
$(top_builddir)/src/libNetworkManager.la
|
||||
|
||||
####### secret agent interface test #######
|
||||
|
||||
EXTRA_DIST = test-secret-agent.py
|
||||
|
||||
###########################################
|
||||
|
||||
TESTS = test-ip4-config test-ip6-config test-dcb test-resolvconf-capture test-general test-general-with-expect
|
||||
TESTS = \
|
||||
test-ip4-config \
|
||||
test-ip6-config \
|
||||
test-dcb \
|
||||
test-resolvconf-capture \
|
||||
test-general \
|
||||
test-general-with-expect \
|
||||
test-wired-defname
|
||||
|
||||
|
||||
if ENABLE_TESTS
|
||||
|
||||
check-local:
|
||||
@for t in bond bridge ethernet gre infiniband macvlan tun veth vlan vxlan; 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 \
|
||||
echo "Testing device factory symbols... FAILED" ; \
|
||||
exit 1 ; \
|
||||
fi \
|
||||
done
|
||||
@echo -n "Testing device factory symbols... PASSED"
|
||||
|
||||
endif
|
||||
|
||||
|
@@ -23,7 +23,7 @@
|
||||
|
||||
#include <nm-simple-connection.h>
|
||||
#include <nm-setting-connection.h>
|
||||
#include "nm-settings-utils.h"
|
||||
#include "nm-device-ethernet-utils.h"
|
||||
|
||||
static NMConnection *
|
||||
_new_connection (const char *id)
|
||||
@@ -43,15 +43,10 @@ _new_connection (const char *id)
|
||||
static void
|
||||
test_defname_no_connections (void)
|
||||
{
|
||||
GHashTable *hash;
|
||||
char *name;
|
||||
|
||||
hash = g_hash_table_new (g_direct_hash, g_direct_equal);
|
||||
|
||||
name = nm_settings_utils_get_default_wired_name (hash);
|
||||
name = nm_device_ethernet_utils_get_default_wired_name (NULL);
|
||||
g_assert_cmpstr (name, ==, "Wired connection 1");
|
||||
|
||||
g_hash_table_destroy (hash);
|
||||
}
|
||||
|
||||
/*******************************************/
|
||||
@@ -59,19 +54,17 @@ test_defname_no_connections (void)
|
||||
static void
|
||||
test_defname_no_conflict (void)
|
||||
{
|
||||
GHashTable *hash;
|
||||
GSList *list = NULL;
|
||||
char *name;
|
||||
|
||||
hash = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, (GDestroyNotify) g_object_unref);
|
||||
list = g_slist_append (list, _new_connection ("asdfasdfasdfadf"));
|
||||
list = g_slist_append (list, _new_connection ("work wifi"));
|
||||
list = g_slist_append (list, _new_connection ("random gsm connection"));
|
||||
|
||||
g_hash_table_insert (hash, "a", _new_connection ("asdfasdfasdfadf"));
|
||||
g_hash_table_insert (hash, "b", _new_connection ("work wifi"));
|
||||
g_hash_table_insert (hash, "c", _new_connection ("random gsm connection"));
|
||||
|
||||
name = nm_settings_utils_get_default_wired_name (hash);
|
||||
name = nm_device_ethernet_utils_get_default_wired_name (list);
|
||||
g_assert_cmpstr (name, ==, "Wired connection 1");
|
||||
|
||||
g_hash_table_destroy (hash);
|
||||
g_slist_free_full (list, g_object_unref);
|
||||
}
|
||||
|
||||
/*******************************************/
|
||||
@@ -79,19 +72,17 @@ test_defname_no_conflict (void)
|
||||
static void
|
||||
test_defname_conflict (void)
|
||||
{
|
||||
GHashTable *hash;
|
||||
GSList *list = NULL;
|
||||
char *name;
|
||||
|
||||
hash = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, (GDestroyNotify) g_object_unref);
|
||||
list = g_slist_append (list, _new_connection ("asdfasdfasdfadf"));
|
||||
list = g_slist_append (list, _new_connection ("Wired connection 1"));
|
||||
list = g_slist_append (list, _new_connection ("random gsm connection"));
|
||||
|
||||
g_hash_table_insert (hash, "a", _new_connection ("asdfasdfasdfadf"));
|
||||
g_hash_table_insert (hash, "b", _new_connection ("Wired connection 1"));
|
||||
g_hash_table_insert (hash, "c", _new_connection ("random gsm connection"));
|
||||
|
||||
name = nm_settings_utils_get_default_wired_name (hash);
|
||||
name = nm_device_ethernet_utils_get_default_wired_name (list);
|
||||
g_assert_cmpstr (name, ==, "Wired connection 2");
|
||||
|
||||
g_hash_table_destroy (hash);
|
||||
g_slist_free_full (list, g_object_unref);
|
||||
}
|
||||
|
||||
/*******************************************/
|
||||
@@ -99,23 +90,21 @@ test_defname_conflict (void)
|
||||
static void
|
||||
test_defname_multiple_conflicts (void)
|
||||
{
|
||||
GHashTable *hash;
|
||||
GSList *list = NULL;
|
||||
char *name;
|
||||
|
||||
hash = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, (GDestroyNotify) g_object_unref);
|
||||
list = g_slist_append (list, _new_connection ("random gsm connection"));
|
||||
list = g_slist_append (list, _new_connection ("home wifi"));
|
||||
list = g_slist_append (list, _new_connection ("Wired connection 1"));
|
||||
list = g_slist_append (list, _new_connection ("Wired connection 2"));
|
||||
list = g_slist_append (list, _new_connection ("Wired connection 3"));
|
||||
list = g_slist_append (list, _new_connection ("work wifi"));
|
||||
list = g_slist_append (list, _new_connection ("a vpn"));
|
||||
|
||||
g_hash_table_insert (hash, "a", _new_connection ("random gsm connection"));
|
||||
g_hash_table_insert (hash, "b", _new_connection ("home wifi"));
|
||||
g_hash_table_insert (hash, "c", _new_connection ("Wired connection 1"));
|
||||
g_hash_table_insert (hash, "d", _new_connection ("Wired connection 2"));
|
||||
g_hash_table_insert (hash, "e", _new_connection ("Wired connection 3"));
|
||||
g_hash_table_insert (hash, "f", _new_connection ("work wifi"));
|
||||
g_hash_table_insert (hash, "g", _new_connection ("a vpn"));
|
||||
|
||||
name = nm_settings_utils_get_default_wired_name (hash);
|
||||
name = nm_device_ethernet_utils_get_default_wired_name (list);
|
||||
g_assert_cmpstr (name, ==, "Wired connection 4");
|
||||
|
||||
g_hash_table_destroy (hash);
|
||||
g_slist_free_full (list, g_object_unref);
|
||||
}
|
||||
|
||||
/*******************************************/
|
Reference in New Issue
Block a user