Commit b42f780e authored by Beniamino Galvani's avatar Beniamino Galvani

core: add support for dummy devices

Add support for creating dummy devices. This commit adds a D-Bus
interface 'org.freedesktop.NetworkManager.Device.Dummy' which is used
primarily for determining the device type but does not carry any
properties.
parent 1bf2d3b0
...@@ -188,6 +188,8 @@ introspection_sources = \ ...@@ -188,6 +188,8 @@ introspection_sources = \
introspection/org.freedesktop.NetworkManager.Device.Bridge.h \ introspection/org.freedesktop.NetworkManager.Device.Bridge.h \
introspection/org.freedesktop.NetworkManager.Device.Bluetooth.c \ introspection/org.freedesktop.NetworkManager.Device.Bluetooth.c \
introspection/org.freedesktop.NetworkManager.Device.Bluetooth.h \ introspection/org.freedesktop.NetworkManager.Device.Bluetooth.h \
introspection/org.freedesktop.NetworkManager.Device.Dummy.c \
introspection/org.freedesktop.NetworkManager.Device.Dummy.h \
introspection/org.freedesktop.NetworkManager.Device.Wired.c \ introspection/org.freedesktop.NetworkManager.Device.Wired.c \
introspection/org.freedesktop.NetworkManager.Device.Wired.h \ introspection/org.freedesktop.NetworkManager.Device.Wired.h \
introspection/org.freedesktop.NetworkManager.Device.Generic.c \ introspection/org.freedesktop.NetworkManager.Device.Generic.c \
...@@ -262,6 +264,7 @@ DBUS_INTERFACE_DOCS = \ ...@@ -262,6 +264,7 @@ DBUS_INTERFACE_DOCS = \
docs/api/dbus-org.freedesktop.NetworkManager.Device.xml \ docs/api/dbus-org.freedesktop.NetworkManager.Device.xml \
docs/api/dbus-org.freedesktop.NetworkManager.VPN.Plugin.xml \ docs/api/dbus-org.freedesktop.NetworkManager.VPN.Plugin.xml \
docs/api/dbus-org.freedesktop.NetworkManager.Device.Bluetooth.xml \ docs/api/dbus-org.freedesktop.NetworkManager.Device.Bluetooth.xml \
docs/api/dbus-org.freedesktop.NetworkManager.Device.Dummy.xml \
docs/api/dbus-org.freedesktop.NetworkManager.Device.Vxlan.xml \ docs/api/dbus-org.freedesktop.NetworkManager.Device.Vxlan.xml \
docs/api/dbus-org.freedesktop.NetworkManager.Settings.Connection.xml \ docs/api/dbus-org.freedesktop.NetworkManager.Settings.Connection.xml \
docs/api/dbus-org.freedesktop.NetworkManager.Device.Bond.xml \ docs/api/dbus-org.freedesktop.NetworkManager.Device.Bond.xml \
...@@ -314,6 +317,7 @@ dbusinterfaces_DATA = \ ...@@ -314,6 +317,7 @@ dbusinterfaces_DATA = \
introspection/org.freedesktop.NetworkManager.Device.Bond.xml \ introspection/org.freedesktop.NetworkManager.Device.Bond.xml \
introspection/org.freedesktop.NetworkManager.Device.Bridge.xml \ introspection/org.freedesktop.NetworkManager.Device.Bridge.xml \
introspection/org.freedesktop.NetworkManager.Device.Bluetooth.xml \ introspection/org.freedesktop.NetworkManager.Device.Bluetooth.xml \
introspection/org.freedesktop.NetworkManager.Device.Dummy.xml \
introspection/org.freedesktop.NetworkManager.Device.Wired.xml \ introspection/org.freedesktop.NetworkManager.Device.Wired.xml \
introspection/org.freedesktop.NetworkManager.Device.Generic.xml \ introspection/org.freedesktop.NetworkManager.Device.Generic.xml \
introspection/org.freedesktop.NetworkManager.Device.Infiniband.xml \ introspection/org.freedesktop.NetworkManager.Device.Infiniband.xml \
...@@ -681,6 +685,7 @@ libnm_lib_h_pub_real = \ ...@@ -681,6 +685,7 @@ libnm_lib_h_pub_real = \
libnm/nm-device-bond.h \ libnm/nm-device-bond.h \
libnm/nm-device-bridge.h \ libnm/nm-device-bridge.h \
libnm/nm-device-bt.h \ libnm/nm-device-bt.h \
libnm/nm-device-dummy.h \
libnm/nm-device-ethernet.h \ libnm/nm-device-ethernet.h \
libnm/nm-device-generic.h \ libnm/nm-device-generic.h \
libnm/nm-device-infiniband.h \ libnm/nm-device-infiniband.h \
...@@ -731,6 +736,7 @@ libnm_lib_c_real = \ ...@@ -731,6 +736,7 @@ libnm_lib_c_real = \
libnm/nm-device-bond.c \ libnm/nm-device-bond.c \
libnm/nm-device-bridge.c \ libnm/nm-device-bridge.c \
libnm/nm-device-bt.c \ libnm/nm-device-bt.c \
libnm/nm-device-dummy.c \
libnm/nm-device-ethernet.c \ libnm/nm-device-ethernet.c \
libnm/nm-device-generic.c \ libnm/nm-device-generic.c \
libnm/nm-device-infiniband.c \ libnm/nm-device-infiniband.c \
...@@ -1304,6 +1310,8 @@ src_libNetworkManager_la_SOURCES = \ ...@@ -1304,6 +1310,8 @@ src_libNetworkManager_la_SOURCES = \
src/devices/nm-device-bond.h \ src/devices/nm-device-bond.h \
src/devices/nm-device-bridge.c \ src/devices/nm-device-bridge.c \
src/devices/nm-device-bridge.h \ src/devices/nm-device-bridge.h \
src/devices/nm-device-dummy.c \
src/devices/nm-device-dummy.h \
src/devices/nm-device-ethernet.c \ src/devices/nm-device-ethernet.c \
src/devices/nm-device-ethernet.h \ src/devices/nm-device-ethernet.h \
src/devices/nm-device-infiniband.c \ src/devices/nm-device-infiniband.c \
......
<?xml version="1.0" encoding="UTF-8"?>
<node name="/">
<interface name="org.freedesktop.NetworkManager.Device.Dummy">
<!--
PropertiesChanged:
@properties: A dictionary mapping property names to variant boxed values
DEPRECATED. Use the standard "PropertiesChanged" signal from "org.freedesktop.DBus.Properties" instead which exists since version NetworkManager 1.2.0.
-->
<signal name="PropertiesChanged">
<arg name="properties" type="a{sv}"/>
</signal>
</interface>
</node>
...@@ -58,6 +58,7 @@ ...@@ -58,6 +58,7 @@
#define NM_DBUS_INTERFACE_DHCP6_CONFIG NM_DBUS_INTERFACE ".DHCP6Config" #define NM_DBUS_INTERFACE_DHCP6_CONFIG NM_DBUS_INTERFACE ".DHCP6Config"
#define NM_DBUS_INTERFACE_DEVICE_INFINIBAND NM_DBUS_INTERFACE_DEVICE ".Infiniband" #define NM_DBUS_INTERFACE_DEVICE_INFINIBAND NM_DBUS_INTERFACE_DEVICE ".Infiniband"
#define NM_DBUS_INTERFACE_DEVICE_BOND NM_DBUS_INTERFACE_DEVICE ".Bond" #define NM_DBUS_INTERFACE_DEVICE_BOND NM_DBUS_INTERFACE_DEVICE ".Bond"
#define NM_DBUS_INTERFACE_DEVICE_DUMMY NM_DBUS_INTERFACE_DEVICE ".Dummy"
#define NM_DBUS_INTERFACE_DEVICE_TEAM NM_DBUS_INTERFACE_DEVICE ".Team" #define NM_DBUS_INTERFACE_DEVICE_TEAM NM_DBUS_INTERFACE_DEVICE ".Team"
#define NM_DBUS_INTERFACE_DEVICE_VLAN NM_DBUS_INTERFACE_DEVICE ".Vlan" #define NM_DBUS_INTERFACE_DEVICE_VLAN NM_DBUS_INTERFACE_DEVICE ".Vlan"
#define NM_DBUS_INTERFACE_DEVICE_BRIDGE NM_DBUS_INTERFACE_DEVICE ".Bridge" #define NM_DBUS_INTERFACE_DEVICE_BRIDGE NM_DBUS_INTERFACE_DEVICE ".Bridge"
...@@ -200,6 +201,7 @@ typedef enum { ...@@ -200,6 +201,7 @@ typedef enum {
* @NM_DEVICE_TYPE_VXLAN: a VXLAN interface * @NM_DEVICE_TYPE_VXLAN: a VXLAN interface
* @NM_DEVICE_TYPE_VETH: a VETH interface * @NM_DEVICE_TYPE_VETH: a VETH interface
* @NM_DEVICE_TYPE_MACSEC: a MACsec interface * @NM_DEVICE_TYPE_MACSEC: a MACsec interface
* @NM_DEVICE_TYPE_DUMMY: a dummy interface
* *
* #NMDeviceType values indicate the type of hardware represented by a * #NMDeviceType values indicate the type of hardware represented by a
* device object. * device object.
...@@ -227,6 +229,7 @@ typedef enum { ...@@ -227,6 +229,7 @@ typedef enum {
NM_DEVICE_TYPE_VXLAN = 19, NM_DEVICE_TYPE_VXLAN = 19,
NM_DEVICE_TYPE_VETH = 20, NM_DEVICE_TYPE_VETH = 20,
NM_DEVICE_TYPE_MACSEC = 21, NM_DEVICE_TYPE_MACSEC = 21,
NM_DEVICE_TYPE_DUMMY = 22,
} NMDeviceType; } NMDeviceType;
/** /**
......
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
#include <nm-device-bond.h> #include <nm-device-bond.h>
#include <nm-device-bridge.h> #include <nm-device-bridge.h>
#include <nm-device-bt.h> #include <nm-device-bt.h>
#include <nm-device-dummy.h>
#include <nm-device-ethernet.h> #include <nm-device-ethernet.h>
#include <nm-device-generic.h> #include <nm-device-generic.h>
#include <nm-device-infiniband.h> #include <nm-device-infiniband.h>
......
...@@ -1147,6 +1147,7 @@ global: ...@@ -1147,6 +1147,7 @@ global:
libnm_1_8_0 { libnm_1_8_0 {
global: global:
nm_connection_get_setting_dummy; nm_connection_get_setting_dummy;
nm_device_dummy_get_type;
nm_setting_802_1x_auth_flags_get_type; nm_setting_802_1x_auth_flags_get_type;
nm_setting_802_1x_get_auth_timeout; nm_setting_802_1x_get_auth_timeout;
nm_setting_802_1x_get_ca_cert_password; nm_setting_802_1x_get_ca_cert_password;
......
...@@ -52,6 +52,7 @@ ...@@ -52,6 +52,7 @@
#include "nm-device-bond.h" #include "nm-device-bond.h"
#include "nm-device-bridge.h" #include "nm-device-bridge.h"
#include "nm-device-bt.h" #include "nm-device-bt.h"
#include "nm-device-dummy.h"
#include "nm-device-ethernet.h" #include "nm-device-ethernet.h"
#include "nm-device-generic.h" #include "nm-device-generic.h"
#include "nm-device-infiniband.h" #include "nm-device-infiniband.h"
...@@ -2046,6 +2047,8 @@ obj_nm_for_gdbus_object (GDBusObject *object, GDBusObjectManager *object_manager ...@@ -2046,6 +2047,8 @@ obj_nm_for_gdbus_object (GDBusObject *object, GDBusObjectManager *object_manager
type = NM_TYPE_DEVICE_BRIDGE; type = NM_TYPE_DEVICE_BRIDGE;
else if (strcmp (ifname, NM_DBUS_INTERFACE_DEVICE_BLUETOOTH) == 0) else if (strcmp (ifname, NM_DBUS_INTERFACE_DEVICE_BLUETOOTH) == 0)
type = NM_TYPE_DEVICE_BT; type = NM_TYPE_DEVICE_BT;
else if (strcmp (ifname, NM_DBUS_INTERFACE_DEVICE_DUMMY) == 0)
type = NM_TYPE_DEVICE_DUMMY;
else if (strcmp (ifname, NM_DBUS_INTERFACE_DEVICE_WIRED) == 0) else if (strcmp (ifname, NM_DBUS_INTERFACE_DEVICE_WIRED) == 0)
type = NM_TYPE_DEVICE_ETHERNET; type = NM_TYPE_DEVICE_ETHERNET;
else if (strcmp (ifname, NM_DBUS_INTERFACE_DEVICE_GENERIC) == 0) else if (strcmp (ifname, NM_DBUS_INTERFACE_DEVICE_GENERIC) == 0)
......
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
* Copyright 2017 Red Hat, Inc.
*/
#include "nm-default.h"
#include <string.h>
#include "nm-device-dummy.h"
#include "nm-object-private.h"
#include "nm-setting-dummy.h"
#include "nm-setting-connection.h"
G_DEFINE_TYPE (NMDeviceDummy, nm_device_dummy, NM_TYPE_DEVICE)
#define NM_DEVICE_DUMMY_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DEVICE_DUMMY, NMDeviceDummyPrivate))
/*****************************************************************************/
static gboolean
connection_compatible (NMDevice *device, NMConnection *connection, GError **error)
{
const char *iface_name;
if (!NM_DEVICE_CLASS (nm_device_dummy_parent_class)->connection_compatible (device, connection, error))
return FALSE;
if (!nm_connection_is_type (connection, NM_SETTING_DUMMY_SETTING_NAME)) {
g_set_error_literal (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_INCOMPATIBLE_CONNECTION,
_("The connection was not a dummy connection."));
return FALSE;
}
iface_name = nm_connection_get_interface_name (connection);
if (!iface_name) {
g_set_error_literal (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_INVALID_CONNECTION,
_("The connection did not specify an interface name."));
return FALSE;
}
return TRUE;
}
static GType
get_setting_type (NMDevice *device)
{
return NM_TYPE_SETTING_DUMMY;
}
/*****************************************************************************/
static void
nm_device_dummy_init (NMDeviceDummy *device)
{
}
static void
nm_device_dummy_class_init (NMDeviceDummyClass *klass)
{
NMDeviceClass *device_class = NM_DEVICE_CLASS (klass);
device_class->connection_compatible = connection_compatible;
device_class->get_setting_type = get_setting_type;
}
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
* Copyright 2017 Red Hat, Inc.
*/
#ifndef __NM_DEVICE_DUMMY_H__
#define __NM_DEVICE_DUMMY_H__
#if !defined (__NETWORKMANAGER_H_INSIDE__) && !defined (NETWORKMANAGER_COMPILATION)
#error "Only <NetworkManager.h> can be included directly."
#endif
#include <nm-device.h>
G_BEGIN_DECLS
#define NM_TYPE_DEVICE_DUMMY (nm_device_dummy_get_type ())
#define NM_DEVICE_DUMMY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_DEVICE_DUMMY, NMDeviceDummy))
#define NM_DEVICE_DUMMY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_DEVICE_DUMMY, NMDeviceDummyClass))
#define NM_IS_DEVICE_DUMMY(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_DEVICE_DUMMY))
#define NM_IS_DEVICE_DUMMY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_DEVICE_DUMMY))
#define NM_DEVICE_DUMMY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_DEVICE_DUMMY, NMDeviceDummyClass))
/**
* NMDeviceDummy:
*/
struct _NMDeviceDummy {
NMDevice parent;
};
typedef struct {
NMDeviceClass parent;
/*< private >*/
gpointer padding[4];
} NMDeviceDummyClass;
GType nm_device_dummy_get_type (void);
G_END_DECLS
#endif /* __NM_DEVICE_DUMMY_H__ */
...@@ -277,6 +277,7 @@ coerce_type (NMDeviceType type) ...@@ -277,6 +277,7 @@ coerce_type (NMDeviceType type)
case NM_DEVICE_TYPE_UNUSED1: case NM_DEVICE_TYPE_UNUSED1:
case NM_DEVICE_TYPE_UNUSED2: case NM_DEVICE_TYPE_UNUSED2:
case NM_DEVICE_TYPE_UNKNOWN: case NM_DEVICE_TYPE_UNKNOWN:
case NM_DEVICE_TYPE_DUMMY:
return type; return type;
} }
return NM_DEVICE_TYPE_UNKNOWN; return NM_DEVICE_TYPE_UNKNOWN;
...@@ -1696,6 +1697,8 @@ get_type_name (NMDevice *device) ...@@ -1696,6 +1697,8 @@ get_type_name (NMDevice *device)
return _("Veth"); return _("Veth");
case NM_DEVICE_TYPE_MACSEC: case NM_DEVICE_TYPE_MACSEC:
return _("MACsec"); return _("MACsec");
case NM_DEVICE_TYPE_DUMMY:
return _("Dummy");
case NM_DEVICE_TYPE_GENERIC: case NM_DEVICE_TYPE_GENERIC:
case NM_DEVICE_TYPE_UNUSED1: case NM_DEVICE_TYPE_UNUSED1:
case NM_DEVICE_TYPE_UNUSED2: case NM_DEVICE_TYPE_UNUSED2:
......
...@@ -34,6 +34,7 @@ typedef struct _NMDeviceAdsl NMDeviceAdsl; ...@@ -34,6 +34,7 @@ typedef struct _NMDeviceAdsl NMDeviceAdsl;
typedef struct _NMDeviceBond NMDeviceBond; typedef struct _NMDeviceBond NMDeviceBond;
typedef struct _NMDeviceBridge NMDeviceBridge; typedef struct _NMDeviceBridge NMDeviceBridge;
typedef struct _NMDeviceBt NMDeviceBt; typedef struct _NMDeviceBt NMDeviceBt;
typedef struct _NMDeviceDummy NMDeviceDummy;
typedef struct _NMDeviceEthernet NMDeviceEthernet; typedef struct _NMDeviceEthernet NMDeviceEthernet;
typedef struct _NMDeviceGeneric NMDeviceGeneric; typedef struct _NMDeviceGeneric NMDeviceGeneric;
typedef struct _NMDeviceInfiniband NMDeviceInfiniband; typedef struct _NMDeviceInfiniband NMDeviceInfiniband;
......
...@@ -123,6 +123,7 @@ libnm/nm-device-adsl.c ...@@ -123,6 +123,7 @@ libnm/nm-device-adsl.c
libnm/nm-device-bond.c libnm/nm-device-bond.c
libnm/nm-device-bridge.c libnm/nm-device-bridge.c
libnm/nm-device-bt.c libnm/nm-device-bt.c
libnm/nm-device-dummy.c
libnm/nm-device-ethernet.c libnm/nm-device-ethernet.c
libnm/nm-device-generic.c libnm/nm-device-generic.c
libnm/nm-device-tun.c libnm/nm-device-tun.c
...@@ -157,6 +158,7 @@ src/devices/bluetooth/nm-bluez-device.c ...@@ -157,6 +158,7 @@ src/devices/bluetooth/nm-bluez-device.c
src/devices/bluetooth/nm-device-bt.c src/devices/bluetooth/nm-device-bt.c
src/devices/nm-device-bond.c src/devices/nm-device-bond.c
src/devices/nm-device-bridge.c src/devices/nm-device-bridge.c
src/devices/nm-device-dummy.c
src/devices/nm-device-ethernet.c src/devices/nm-device-ethernet.c
src/devices/nm-device-ethernet-utils.c src/devices/nm-device-ethernet-utils.c
src/devices/nm-device-infiniband.c src/devices/nm-device-infiniband.c
......
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/* NetworkManager -- Network link manager
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Copyright 2017 Red Hat, Inc.
*/
#include "nm-default.h"
#include "nm-device-dummy.h"
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include "nm-act-request.h"
#include "nm-device-private.h"
#include "nm-ip4-config.h"
#include "platform/nm-platform.h"
#include "nm-device-factory.h"
#include "nm-setting-dummy.h"
#include "nm-core-internal.h"
#include "introspection/org.freedesktop.NetworkManager.Device.Dummy.h"
#include "nm-device-logging.h"
_LOG_DECLARE_SELF(NMDeviceDummy);
/*****************************************************************************/
struct _NMDeviceDummy {
NMDevice parent;
};
struct _NMDeviceDummyClass {
NMDeviceClass parent;
};
G_DEFINE_TYPE (NMDeviceDummy, nm_device_dummy, NM_TYPE_DEVICE)
/*****************************************************************************/
static NMDeviceCapabilities
get_generic_capabilities (NMDevice *dev)
{
return NM_DEVICE_CAP_IS_SOFTWARE;
}
static gboolean
complete_connection (NMDevice *device,
NMConnection *connection,
const char *specific_object,
const GSList *existing_connections,
GError **error)
{
NMSettingDummy *s_dummy;
nm_utils_complete_generic (NM_PLATFORM_GET,
connection,
NM_SETTING_DUMMY_SETTING_NAME,
existing_connections,
NULL,
_("Dummy connection"),
NULL,
TRUE);
s_dummy = nm_connection_get_setting_dummy (connection);
if (!s_dummy) {
g_set_error_literal (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_INVALID_CONNECTION,
"A 'dummy' setting is required.");
return FALSE;
}
return TRUE;
}
static void
update_connection (NMDevice *device, NMConnection *connection)
{
NMSettingDummy *s_dummy = nm_connection_get_setting_dummy (connection);
if (!s_dummy) {
s_dummy = (NMSettingDummy *) nm_setting_dummy_new ();
nm_connection_add_setting (connection, (NMSetting *) s_dummy);
}
}
static gboolean
create_and_realize (NMDevice *device,
NMConnection *connection,
NMDevice *parent,
const NMPlatformLink **out_plink,
GError **error)
{
const char *iface = nm_device_get_iface (device);
NMPlatformError plerr;
NMSettingDummy *s_dummy;
s_dummy = nm_connection_get_setting_dummy (connection);
g_assert (s_dummy);
plerr = nm_platform_link_dummy_add (NM_PLATFORM_GET, iface, out_plink);
if (plerr != NM_PLATFORM_ERROR_SUCCESS) {
g_set_error (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_CREATION_FAILED,
"Failed to create dummy interface '%s' for '%s': %s",
iface,
nm_connection_get_id (connection),
nm_platform_error_to_string (plerr));
return FALSE;
}
return TRUE;
}
static gboolean
check_connection_compatible (NMDevice *device, NMConnection *connection)
{
NMSettingDummy *s_dummy;
if (!NM_DEVICE_CLASS (nm_device_dummy_parent_class)->check_connection_compatible (device, connection))
return FALSE;
s_dummy = nm_connection_get_setting_dummy (connection);
if (!s_dummy)
return FALSE;
return TRUE;
}
static NMActStageReturn
act_stage1_prepare (NMDevice *device, NMDeviceStateReason *reason)
{
NMActStageReturn ret;
g_return_val_if_fail (reason != NULL, NM_ACT_STAGE_RETURN_FAILURE);
ret = NM_DEVICE_CLASS (nm_device_dummy_parent_class)->act_stage1_prepare (device, reason);
if (ret != NM_ACT_STAGE_RETURN_SUCCESS)
return ret;
if (!nm_device_hw_addr_set_cloned (device, nm_device_get_applied_connection (device), FALSE))
return NM_ACT_STAGE_RETURN_FAILURE;
return NM_ACT_STAGE_RETURN_SUCCESS;
}
/*****************************************************************************/
static void
nm_device_dummy_init (NMDeviceDummy *self)
{
}
static void
nm_device_dummy_class_init (NMDeviceDummyClass *klass)
{
NMDeviceClass *device_class = NM_DEVICE_CLASS (klass);
NM_DEVICE_CLASS_DECLARE_TYPES (klass, NULL, NM_LINK_TYPE_DUMMY)
device_class->connection_type = NM_SETTING_DUMMY_SETTING_NAME;
device_class->complete_connection = complete_connection;
device_class->check_connection_compatible = check_connection_compatible;
device_class->create_and_realize = create_and_realize;
device_class->get_generic_capabilities = get_generic_capabilities;
device_class->update_connection = update_connection;
device_class->act_stage1_prepare = act_stage1_prepare;
device_class->get_configured_mtu = nm_device_get_configured_mtu_for_wired;
nm_exported_object_class_add_interface (NM_EXPORTED_OBJECT_CLASS (klass),
NMDBUS_TYPE_DEVICE_DUMMY_SKELETON,
NULL);
}
/*****************************************************************************/
#define NM_TYPE_DUMMY_DEVICE_FACTORY (nm_dummy_device_factory_get_type ())
#define NM_DUMMY_DEVICE_FACTORY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_DUMMY_DEVICE_FACTORY, NMDummyDeviceFactory))
static NMDevice *
create_device (NMDeviceFactory *factory,
const char *iface,
const NMPlatformLink *plink,
NMConnection *connection,
gboolean *out_ignore)
{
return (NMDevice *) g_object_new (NM_TYPE_DEVICE_DUMMY,
NM_DEVICE_IFACE, iface,
NM_DEVICE_TYPE_DESC, "Dummy",
NM_DEVICE_DEVICE_TYPE, NM_DEVICE_TYPE_DUMMY,
NM_DEVICE_LINK_TYPE, NM_LINK_TYPE_DUMMY,
NULL);
}
NM_DEVICE_FACTORY_DEFINE_INTERNAL (DUMMY, Dummy, dummy,
NM_DEVICE_FACTORY_DECLARE_LINK_TYPES (NM_LINK_TYPE_DUMMY)
NM_DEVICE_FACTORY_DECLARE_SETTING_TYPES (NM_SETTING_DUMMY_SETTING_NAME),
factory_class->create_device = create_device;
);
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/* NetworkManager -- Network link manager
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Copyright 2017 Red Hat, Inc.
*/
#ifndef __NETWORKMANAGER_DEVICE_DUMMY_H__
#define __NETWORKMANAGER_DEVICE_DUMMY_H__
#include "nm-device-generic.h"
#define NM_TYPE_DEVICE_DUMMY (nm_device_dummy_get_type ())
#define NM_DEVICE_DUMMY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_DEVICE_DUMMY, NMDeviceDummy))
#define NM_DEVICE_DUMMY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_DEVICE_DUMMY, NMDeviceDummyClass))
#define NM_IS_DEVICE_DUMMY(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_DEVICE_DUMMY))
#define NM_IS_DEVICE_DUMMY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_DEVICE_DUMMY))
#define NM_DEVICE_DUMMY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_DEVICE_DUMMY, NMDeviceDummyClass))
typedef struct _NMDeviceDummy NMDeviceDummy;
typedef struct _NMDeviceDummyClass NMDeviceDummyClass;
GType nm_device_dummy_get_type (void);
#endif /* __NETWORKMANAGER_DEVICE_DUMMY_H__ */
...@@ -403,6 +403,7 @@ nm_device_factory_manager_load_factories (NMDeviceFactoryManagerFactoryFunc call ...@@ -403,6 +403,7 @@ nm_device_factory_manager_load_factories (NMDeviceFactoryManagerFactoryFunc call
_ADD_INTERNAL (nm_bond_device_factory_get_type); _ADD_INTERNAL (nm_bond_device_factory_get_type);
_ADD_INTERNAL (nm_bridge_device_factory_get_type); _ADD_INTERNAL (nm_bridge_device_factory_get_type);
_ADD_INTERNAL (nm_dummy_device_factory_get_type);
_ADD_INTERNAL (nm_ethernet_device_factory_get_type); _ADD_INTERNAL (nm_ethernet_device_factory_get_type);
_ADD_INTERNAL (nm_infiniband_device_factory_get_type); _ADD_INTERNAL (nm_infiniband_device_factory_get_type);
_ADD_INTERNAL (nm_ip_tunnel_device_factory_get_type); _ADD_INTERNAL (nm_ip_tunnel_device_factory_get_type);
......
...@@ -1349,6 +1349,8 @@ nm_device_get_priority (NMDevice *self) ...@@ -1349,6 +1349,8 @@ nm_device_get_priority (NMDevice *self)
return 450; return 450;
case NM_DEVICE_TYPE_VXLAN: case NM_DEVICE_TYPE_VXLAN:
return 500; return 500;
case NM_DEVICE_TYPE_DUMMY:
return 550;
case NM_DEVICE_TYPE_WIFI: case NM_DEVICE_TYPE_WIFI:
return 600; return 600;
case NM_DEVICE_TYPE_OLPC_MESH: case NM_DEVICE_TYPE_OLPC_MESH:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment