diff options
author | Beniamino Galvani <bgalvani@redhat.com> | 2017-02-22 21:05:55 +0100 |
---|---|---|
committer | Beniamino Galvani <bgalvani@redhat.com> | 2017-02-22 21:05:55 +0100 |
commit | d5911fc5515bbfd66c99b6bb30b61034c256ef4e (patch) | |
tree | 83730e825e87b28ecbb5562fb62677c4fc6a3d2d | |
parent | f95b6cadd2cdd1c8e960f24db36d35833eed5d90 (diff) | |
parent | 4db7890faee9028b90f0d27dc7e1b3ed1c71382c (diff) | |
download | NetworkManager-d5911fc5515bbfd66c99b6bb30b61034c256ef4e.tar.gz |
merge: branch 'bg/dummy-bgo777863'
Implement a new connection type for dummy interfaces.
https://bugzilla.gnome.org/show_bug.cgi?id=777863
-rw-r--r-- | Makefile.am | 10 | ||||
-rw-r--r-- | clients/cli/connections.c | 10 | ||||
-rw-r--r-- | clients/cli/settings.c | 7 | ||||
-rw-r--r-- | clients/cli/settings.h | 1 | ||||
-rw-r--r-- | introspection/org.freedesktop.NetworkManager.Device.Dummy.xml | 15 | ||||
-rw-r--r-- | libnm-core/nm-connection.c | 19 | ||||
-rw-r--r-- | libnm-core/nm-connection.h | 2 | ||||
-rw-r--r-- | libnm-core/nm-core-internal.h | 1 | ||||
-rw-r--r-- | libnm-core/nm-core-types.h | 1 | ||||
-rw-r--r-- | libnm-core/nm-dbus-interface.h | 3 | ||||
-rw-r--r-- | libnm-core/nm-setting-dummy.c | 62 | ||||
-rw-r--r-- | libnm-core/nm-setting-dummy.h | 63 | ||||
-rw-r--r-- | libnm/NetworkManager.h | 2 | ||||
-rw-r--r-- | libnm/libnm.ver | 4 | ||||
-rw-r--r-- | libnm/nm-client.c | 3 | ||||
-rw-r--r-- | libnm/nm-device-dummy.c | 80 | ||||
-rw-r--r-- | libnm/nm-device-dummy.h | 57 | ||||
-rw-r--r-- | libnm/nm-device.c | 3 | ||||
-rw-r--r-- | libnm/nm-object.c | 2 | ||||
-rw-r--r-- | libnm/nm-types.h | 1 | ||||
-rw-r--r-- | man/nmcli.xml | 1 | ||||
-rw-r--r-- | po/POTFILES.in | 2 | ||||
-rw-r--r-- | src/devices/nm-device-dummy.c | 207 | ||||
-rw-r--r-- | src/devices/nm-device-dummy.h | 38 | ||||
-rw-r--r-- | src/devices/nm-device-factory.c | 1 | ||||
-rw-r--r-- | src/devices/nm-device.c | 2 |
26 files changed, 596 insertions, 1 deletions
diff --git a/Makefile.am b/Makefile.am index e88277f221..670fb9d54e 100644 --- a/Makefile.am +++ b/Makefile.am @@ -188,6 +188,8 @@ introspection_sources = \ introspection/org.freedesktop.NetworkManager.Device.Bridge.h \ introspection/org.freedesktop.NetworkManager.Device.Bluetooth.c \ 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.h \ introspection/org.freedesktop.NetworkManager.Device.Generic.c \ @@ -262,6 +264,7 @@ DBUS_INTERFACE_DOCS = \ docs/api/dbus-org.freedesktop.NetworkManager.Device.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.Dummy.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.Device.Bond.xml \ @@ -314,6 +317,7 @@ dbusinterfaces_DATA = \ introspection/org.freedesktop.NetworkManager.Device.Bond.xml \ introspection/org.freedesktop.NetworkManager.Device.Bridge.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.Generic.xml \ introspection/org.freedesktop.NetworkManager.Device.Infiniband.xml \ @@ -374,6 +378,7 @@ libnm_core_lib_h_pub_real = \ libnm-core/nm-setting-cdma.h \ libnm-core/nm-setting-connection.h \ libnm-core/nm-setting-dcb.h \ + libnm-core/nm-setting-dummy.h \ libnm-core/nm-setting-generic.h \ libnm-core/nm-setting-gsm.h \ libnm-core/nm-setting-infiniband.h \ @@ -439,6 +444,7 @@ libnm_core_lib_c_real = \ libnm-core/nm-setting-cdma.c \ libnm-core/nm-setting-connection.c \ libnm-core/nm-setting-dcb.c \ + libnm-core/nm-setting-dummy.c \ libnm-core/nm-setting-generic.c \ libnm-core/nm-setting-gsm.c \ libnm-core/nm-setting-infiniband.c \ @@ -679,6 +685,7 @@ libnm_lib_h_pub_real = \ libnm/nm-device-bond.h \ libnm/nm-device-bridge.h \ libnm/nm-device-bt.h \ + libnm/nm-device-dummy.h \ libnm/nm-device-ethernet.h \ libnm/nm-device-generic.h \ libnm/nm-device-infiniband.h \ @@ -729,6 +736,7 @@ libnm_lib_c_real = \ libnm/nm-device-bond.c \ libnm/nm-device-bridge.c \ libnm/nm-device-bt.c \ + libnm/nm-device-dummy.c \ libnm/nm-device-ethernet.c \ libnm/nm-device-generic.c \ libnm/nm-device-infiniband.c \ @@ -1302,6 +1310,8 @@ src_libNetworkManager_la_SOURCES = \ src/devices/nm-device-bond.h \ src/devices/nm-device-bridge.c \ 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.h \ src/devices/nm-device-infiniband.c \ diff --git a/clients/cli/connections.c b/clients/cli/connections.c index 2b87b32b6f..fd2b7e7232 100644 --- a/clients/cli/connections.c +++ b/clients/cli/connections.c @@ -183,6 +183,7 @@ NmcOutputField nmc_fields_settings_names[] = { SETTING_FIELD (NM_SETTING_MACVLAN_SETTING_NAME, nmc_fields_setting_macvlan + 1), /* 28 */ SETTING_FIELD (NM_SETTING_VXLAN_SETTING_NAME, nmc_fields_setting_vxlan + 1), /* 29 */ SETTING_FIELD (NM_SETTING_PROXY_SETTING_NAME, nmc_fields_setting_proxy + 1), /* 30 */ + SETTING_FIELD (NM_SETTING_DUMMY_SETTING_NAME, nmc_fields_setting_dummy + 1), /* 31 */ {NULL, NULL, 0, NULL, NULL, FALSE, FALSE, 0} }; #define NMC_FIELDS_SETTINGS_NAMES_ALL_X NM_SETTING_CONNECTION_SETTING_NAME","\ @@ -477,6 +478,7 @@ usage_connection_add (void) " [source-port-min <0-65535>]\n" " [source-port-max <0-65535>]\n" " [destination-port <0-65535>]\n\n" + " dummy: \n\n" " SLAVE_OPTIONS:\n" " bridge: [priority <0-63>]\n" " [path-cost <1-65535>]\n" @@ -3071,6 +3073,13 @@ static const NameItem nmc_vxlan_settings [] = { { NULL, NULL, NULL, FALSE } }; +static const NameItem nmc_dummy_settings [] = { + { NM_SETTING_CONNECTION_SETTING_NAME, NULL, NULL, TRUE }, + { NM_SETTING_DUMMY_SETTING_NAME, NULL, NULL, TRUE }, + { NM_SETTING_WIRED_SETTING_NAME, "ethernet", NULL, FALSE }, + { NULL, NULL, NULL, FALSE } +}; + /* Available connection types */ static const NameItem nmc_valid_connection_types[] = { { NM_SETTING_GENERIC_SETTING_NAME, NULL, nmc_generic_settings }, /* Needs to be first. */ @@ -3098,6 +3107,7 @@ static const NameItem nmc_valid_connection_types[] = { { NM_SETTING_MACSEC_SETTING_NAME, NULL, nmc_macsec_settings }, { NM_SETTING_MACVLAN_SETTING_NAME, NULL, nmc_macvlan_settings }, { NM_SETTING_VXLAN_SETTING_NAME, NULL, nmc_vxlan_settings }, + { NM_SETTING_DUMMY_SETTING_NAME, NULL, nmc_dummy_settings }, { NULL, NULL, NULL } }; diff --git a/clients/cli/settings.c b/clients/cli/settings.c index 3d3760dc62..047e50f616 100644 --- a/clients/cli/settings.c +++ b/clients/cli/settings.c @@ -717,6 +717,13 @@ NmcOutputField nmc_fields_setting_dcb[] = { NM_SETTING_DCB_PRIORITY_STRICT_BANDWIDTH","\ NM_SETTING_DCB_PRIORITY_TRAFFIC_CLASS +/* Available fields for NM_SETTING_DUMMY_SETTING_NAME */ +NmcOutputField nmc_fields_setting_dummy[] = { + SETTING_FIELD ("name"), /* 0 */ + {NULL, NULL, 0, NULL, FALSE, FALSE, 0} +}; +#define NMC_FIELDS_SETTING_DUMMY_ALL "name" + /* Available fields for NM_SETTING_TUN_SETTING_NAME */ NmcOutputField nmc_fields_setting_tun[] = { SETTING_FIELD ("name"), /* 0 */ diff --git a/clients/cli/settings.h b/clients/cli/settings.h index ad503f9ef6..f663aa46d4 100644 --- a/clients/cli/settings.h +++ b/clients/cli/settings.h @@ -95,5 +95,6 @@ extern NmcOutputField nmc_fields_setting_macvlan[]; extern NmcOutputField nmc_fields_setting_macsec[]; extern NmcOutputField nmc_fields_setting_vxlan[]; extern NmcOutputField nmc_fields_setting_proxy[]; +extern NmcOutputField nmc_fields_setting_dummy[]; #endif /* NMC_SETTINGS_H */ diff --git a/introspection/org.freedesktop.NetworkManager.Device.Dummy.xml b/introspection/org.freedesktop.NetworkManager.Device.Dummy.xml new file mode 100644 index 0000000000..7492c061bf --- /dev/null +++ b/introspection/org.freedesktop.NetworkManager.Device.Dummy.xml @@ -0,0 +1,15 @@ +<?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> diff --git a/libnm-core/nm-connection.c b/libnm-core/nm-connection.c index 98899ef7b7..ce6f405c35 100644 --- a/libnm-core/nm-connection.c +++ b/libnm-core/nm-connection.c @@ -1845,6 +1845,7 @@ nm_connection_is_virtual (NMConnection *connection) g_return_val_if_fail (type != NULL, FALSE); if ( !strcmp (type, NM_SETTING_BOND_SETTING_NAME) + || !strcmp (type, NM_SETTING_DUMMY_SETTING_NAME) || !strcmp (type, NM_SETTING_TEAM_SETTING_NAME) || !strcmp (type, NM_SETTING_BRIDGE_SETTING_NAME) || !strcmp (type, NM_SETTING_VLAN_SETTING_NAME) @@ -2055,6 +2056,24 @@ nm_connection_get_setting_dcb (NMConnection *connection) } /** + * nm_connection_get_setting_dummy: + * @connection: the #NMConnection + * + * A shortcut to return any #NMSettingDummy the connection might contain. + * + * Returns: (transfer none): an #NMSettingDummy if the connection contains one, otherwise %NULL + * + * Since: 1.8 + **/ +NMSettingDummy * +nm_connection_get_setting_dummy (NMConnection *connection) +{ + g_return_val_if_fail (NM_IS_CONNECTION (connection), NULL); + + return (NMSettingDummy *) nm_connection_get_setting (connection, NM_TYPE_SETTING_DUMMY); +} + +/** * nm_connection_get_setting_generic: * @connection: the #NMConnection * diff --git a/libnm-core/nm-connection.h b/libnm-core/nm-connection.h index 36ef7b6f34..032d9d7eb0 100644 --- a/libnm-core/nm-connection.h +++ b/libnm-core/nm-connection.h @@ -199,6 +199,8 @@ NMSettingBridgePort * nm_connection_get_setting_bridge_port (NMConnec NMSettingCdma * nm_connection_get_setting_cdma (NMConnection *connection); NMSettingConnection * nm_connection_get_setting_connection (NMConnection *connection); NMSettingDcb * nm_connection_get_setting_dcb (NMConnection *connection); +NM_AVAILABLE_IN_1_8 +NMSettingDummy * nm_connection_get_setting_dummy (NMConnection *connection); NMSettingGeneric * nm_connection_get_setting_generic (NMConnection *connection); NMSettingGsm * nm_connection_get_setting_gsm (NMConnection *connection); NMSettingInfiniband * nm_connection_get_setting_infiniband (NMConnection *connection); diff --git a/libnm-core/nm-core-internal.h b/libnm-core/nm-core-internal.h index f5b4184234..71e0ff893b 100644 --- a/libnm-core/nm-core-internal.h +++ b/libnm-core/nm-core-internal.h @@ -45,6 +45,7 @@ #include "nm-setting-cdma.h" #include "nm-setting-connection.h" #include "nm-setting-dcb.h" +#include "nm-setting-dummy.h" #include "nm-setting-generic.h" #include "nm-setting-gsm.h" #include "nm-setting-infiniband.h" diff --git a/libnm-core/nm-core-types.h b/libnm-core/nm-core-types.h index 2948b5f596..dc13cf0779 100644 --- a/libnm-core/nm-core-types.h +++ b/libnm-core/nm-core-types.h @@ -38,6 +38,7 @@ typedef struct _NMSettingBridgePort NMSettingBridgePort; typedef struct _NMSettingCdma NMSettingCdma; typedef struct _NMSettingConnection NMSettingConnection; typedef struct _NMSettingDcb NMSettingDcb; +typedef struct _NMSettingDummy NMSettingDummy; typedef struct _NMSettingGeneric NMSettingGeneric; typedef struct _NMSettingGsm NMSettingGsm; typedef struct _NMSettingInfiniband NMSettingInfiniband; diff --git a/libnm-core/nm-dbus-interface.h b/libnm-core/nm-dbus-interface.h index 51ecfab42c..89c2ab1628 100644 --- a/libnm-core/nm-dbus-interface.h +++ b/libnm-core/nm-dbus-interface.h @@ -58,6 +58,7 @@ #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_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_VLAN NM_DBUS_INTERFACE_DEVICE ".Vlan" #define NM_DBUS_INTERFACE_DEVICE_BRIDGE NM_DBUS_INTERFACE_DEVICE ".Bridge" @@ -200,6 +201,7 @@ typedef enum { * @NM_DEVICE_TYPE_VXLAN: a VXLAN interface * @NM_DEVICE_TYPE_VETH: a VETH 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 * device object. @@ -227,6 +229,7 @@ typedef enum { NM_DEVICE_TYPE_VXLAN = 19, NM_DEVICE_TYPE_VETH = 20, NM_DEVICE_TYPE_MACSEC = 21, + NM_DEVICE_TYPE_DUMMY = 22, } NMDeviceType; /** diff --git a/libnm-core/nm-setting-dummy.c b/libnm-core/nm-setting-dummy.c new file mode 100644 index 0000000000..0934e963ba --- /dev/null +++ b/libnm-core/nm-setting-dummy.c @@ -0,0 +1,62 @@ +/* -*- 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 "nm-setting-dummy.h" +#include "nm-setting-connection.h" +#include "nm-setting-private.h" + +/** + * SECTION:nm-setting-dummy + * @short_description: Describes connection properties for dummy interfaces + * + * The #NMSettingDummy object is a #NMSetting subclass that describes properties + * necessary for connection to dummy devices + **/ + +G_DEFINE_TYPE_WITH_CODE (NMSettingDummy, nm_setting_dummy, NM_TYPE_SETTING, + _nm_register_setting (DUMMY, 1)) +NM_SETTING_REGISTER_TYPE (NM_TYPE_SETTING_DUMMY) + +/** + * nm_setting_dummy_new: + * + * Creates a new #NMSettingDummy object with default values. + * + * Returns: (transfer full): the new empty #NMSettingDummy object + * + * Since: 1.8 + **/ +NMSetting * +nm_setting_dummy_new (void) +{ + return (NMSetting *) g_object_new (NM_TYPE_SETTING_DUMMY, NULL); +} + +static void +nm_setting_dummy_init (NMSettingDummy *setting) +{ +} + +static void +nm_setting_dummy_class_init (NMSettingDummyClass *setting_class) +{ +} diff --git a/libnm-core/nm-setting-dummy.h b/libnm-core/nm-setting-dummy.h new file mode 100644 index 0000000000..fdeb76059f --- /dev/null +++ b/libnm-core/nm-setting-dummy.h @@ -0,0 +1,63 @@ +/* -*- 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_SETTING_DUMMY_H__ +#define __NM_SETTING_DUMMY_H__ + +#if !defined (__NETWORKMANAGER_H_INSIDE__) && !defined (NETWORKMANAGER_COMPILATION) +#error "Only <NetworkManager.h> can be included directly." +#endif + +#include "nm-setting.h" + +G_BEGIN_DECLS + +#define NM_TYPE_SETTING_DUMMY (nm_setting_dummy_get_type ()) +#define NM_SETTING_DUMMY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_SETTING_DUMMY, NMSettingDummy)) +#define NM_SETTING_DUMMY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_SETTING_DUMMYCONFIG, NMSettingDummyClass)) +#define NM_IS_SETTING_DUMMY(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_SETTING_DUMMY)) +#define NM_IS_SETTING_DUMMY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_SETTING_DUMMY)) +#define NM_SETTING_DUMMY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_SETTING_DUMMY, NMSettingDummyClass)) + +#define NM_SETTING_DUMMY_SETTING_NAME "dummy" + +/** + * NMSettingDummy: + */ +struct _NMSettingDummy { + NMSetting parent; +}; + +typedef struct { + NMSettingClass parent; + + /*< private >*/ + gpointer padding[4]; +} NMSettingDummyClass; + +NM_AVAILABLE_IN_1_8 +GType nm_setting_dummy_get_type (void); +NM_AVAILABLE_IN_1_8 +NMSetting *nm_setting_dummy_new (void); + +G_END_DECLS + +#endif /* __NM_SETTING_DUMMY_H__ */ diff --git a/libnm/NetworkManager.h b/libnm/NetworkManager.h index d0dec1a019..4bf35df714 100644 --- a/libnm/NetworkManager.h +++ b/libnm/NetworkManager.h @@ -33,6 +33,7 @@ #include <nm-device-bond.h> #include <nm-device-bridge.h> #include <nm-device-bt.h> +#include <nm-device-dummy.h> #include <nm-device-ethernet.h> #include <nm-device-generic.h> #include <nm-device-infiniband.h> @@ -61,6 +62,7 @@ #include <nm-setting-cdma.h> #include <nm-setting-connection.h> #include <nm-setting-dcb.h> +#include <nm-setting-dummy.h> #include <nm-setting-generic.h> #include <nm-setting-gsm.h> #include <nm-setting-infiniband.h> diff --git a/libnm/libnm.ver b/libnm/libnm.ver index 5473ffaa2f..2d6f739e6e 100644 --- a/libnm/libnm.ver +++ b/libnm/libnm.ver @@ -1146,6 +1146,8 @@ global: libnm_1_8_0 { global: + nm_connection_get_setting_dummy; + nm_device_dummy_get_type; nm_setting_802_1x_auth_flags_get_type; nm_setting_802_1x_get_auth_timeout; nm_setting_802_1x_get_ca_cert_password; @@ -1158,5 +1160,7 @@ global: nm_setting_802_1x_get_phase2_client_cert_password; nm_setting_802_1x_get_phase2_client_cert_password_flags; nm_setting_cdma_get_mtu; + nm_setting_dummy_get_type; + nm_setting_dummy_new; nm_setting_gsm_get_mtu; } libnm_1_6_0; diff --git a/libnm/nm-client.c b/libnm/nm-client.c index cd54a88c70..17c31bf043 100644 --- a/libnm/nm-client.c +++ b/libnm/nm-client.c @@ -52,6 +52,7 @@ #include "nm-device-bond.h" #include "nm-device-bridge.h" #include "nm-device-bt.h" +#include "nm-device-dummy.h" #include "nm-device-ethernet.h" #include "nm-device-generic.h" #include "nm-device-infiniband.h" @@ -2046,6 +2047,8 @@ obj_nm_for_gdbus_object (GDBusObject *object, GDBusObjectManager *object_manager type = NM_TYPE_DEVICE_BRIDGE; else if (strcmp (ifname, NM_DBUS_INTERFACE_DEVICE_BLUETOOTH) == 0) 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) type = NM_TYPE_DEVICE_ETHERNET; else if (strcmp (ifname, NM_DBUS_INTERFACE_DEVICE_GENERIC) == 0) diff --git a/libnm/nm-device-dummy.c b/libnm/nm-device-dummy.c new file mode 100644 index 0000000000..f5910dc869 --- /dev/null +++ b/libnm/nm-device-dummy.c @@ -0,0 +1,80 @@ +/* -*- 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; +} diff --git a/libnm/nm-device-dummy.h b/libnm/nm-device-dummy.h new file mode 100644 index 0000000000..0d37e57557 --- /dev/null +++ b/libnm/nm-device-dummy.h @@ -0,0 +1,57 @@ +/* -*- 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__ */ diff --git a/libnm/nm-device.c b/libnm/nm-device.c index 85cd060b8f..02241567f9 100644 --- a/libnm/nm-device.c +++ b/libnm/nm-device.c @@ -277,6 +277,7 @@ coerce_type (NMDeviceType type) case NM_DEVICE_TYPE_UNUSED1: case NM_DEVICE_TYPE_UNUSED2: case NM_DEVICE_TYPE_UNKNOWN: + case NM_DEVICE_TYPE_DUMMY: return type; } return NM_DEVICE_TYPE_UNKNOWN; @@ -1696,6 +1697,8 @@ get_type_name (NMDevice *device) return _("Veth"); case NM_DEVICE_TYPE_MACSEC: return _("MACsec"); + case NM_DEVICE_TYPE_DUMMY: + return _("Dummy"); case NM_DEVICE_TYPE_GENERIC: case NM_DEVICE_TYPE_UNUSED1: case NM_DEVICE_TYPE_UNUSED2: diff --git a/libnm/nm-object.c b/libnm/nm-object.c index 0d85b6a3ed..1e8d83eb02 100644 --- a/libnm/nm-object.c +++ b/libnm/nm-object.c @@ -1054,7 +1054,7 @@ init_if (GDBusInterface *interface, gpointer user_data) props = g_dbus_proxy_get_cached_property_names (proxy); - for (prop = props; *prop; prop++) { + for (prop = props; prop && *prop; prop++) { val = g_dbus_proxy_get_cached_property (proxy, *prop); str = g_variant_print (val, TRUE); handle_property_changed (self, *prop, val); diff --git a/libnm/nm-types.h b/libnm/nm-types.h index 7d224c86fe..05fea1746b 100644 --- a/libnm/nm-types.h +++ b/libnm/nm-types.h @@ -34,6 +34,7 @@ typedef struct _NMDeviceAdsl NMDeviceAdsl; typedef struct _NMDeviceBond NMDeviceBond; typedef struct _NMDeviceBridge NMDeviceBridge; typedef struct _NMDeviceBt NMDeviceBt; +typedef struct _NMDeviceDummy NMDeviceDummy; typedef struct _NMDeviceEthernet NMDeviceEthernet; typedef struct _NMDeviceGeneric NMDeviceGeneric; typedef struct _NMDeviceInfiniband NMDeviceInfiniband; diff --git a/man/nmcli.xml b/man/nmcli.xml index d7610c8cce..a2d9223c3f 100644 --- a/man/nmcli.xml +++ b/man/nmcli.xml @@ -925,6 +925,7 @@ <listitem><para><literal>ip-tunnel</literal></para></listitem> <listitem><para><literal>macvlan</literal></para></listitem> <listitem><para><literal>vxlan</literal></para></listitem> + <listitem><para><literal>dummy</literal></para></listitem> </itemizedlist> <para>The most typical uses are described in the <link linkend='examples' endterm='examples.title' /> section.</para> diff --git a/po/POTFILES.in b/po/POTFILES.in index d9faa7b112..3bdf6d79b3 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -123,6 +123,7 @@ libnm/nm-device-adsl.c libnm/nm-device-bond.c libnm/nm-device-bridge.c libnm/nm-device-bt.c +libnm/nm-device-dummy.c libnm/nm-device-ethernet.c libnm/nm-device-generic.c libnm/nm-device-tun.c @@ -157,6 +158,7 @@ src/devices/bluetooth/nm-bluez-device.c src/devices/bluetooth/nm-device-bt.c src/devices/nm-device-bond.c src/devices/nm-device-bridge.c +src/devices/nm-device-dummy.c src/devices/nm-device-ethernet.c src/devices/nm-device-ethernet-utils.c src/devices/nm-device-infiniband.c diff --git a/src/devices/nm-device-dummy.c b/src/devices/nm-device-dummy.c new file mode 100644 index 0000000000..c05cc5681a --- /dev/null +++ b/src/devices/nm-device-dummy.c @@ -0,0 +1,207 @@ +/* -*- 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; +); diff --git a/src/devices/nm-device-dummy.h b/src/devices/nm-device-dummy.h new file mode 100644 index 0000000000..cc89a84736 --- /dev/null +++ b/src/devices/nm-device-dummy.h @@ -0,0 +1,38 @@ +/* -*- 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__ */ diff --git a/src/devices/nm-device-factory.c b/src/devices/nm-device-factory.c index dbe68048a9..f512b8b25d 100644 --- a/src/devices/nm-device-factory.c +++ b/src/devices/nm-device-factory.c @@ -403,6 +403,7 @@ nm_device_factory_manager_load_factories (NMDeviceFactoryManagerFactoryFunc call _ADD_INTERNAL (nm_bond_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_infiniband_device_factory_get_type); _ADD_INTERNAL (nm_ip_tunnel_device_factory_get_type); diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c index 006e523641..38e1453d47 100644 --- a/src/devices/nm-device.c +++ b/src/devices/nm-device.c @@ -1349,6 +1349,8 @@ nm_device_get_priority (NMDevice *self) return 450; case NM_DEVICE_TYPE_VXLAN: return 500; + case NM_DEVICE_TYPE_DUMMY: + return 550; case NM_DEVICE_TYPE_WIFI: return 600; case NM_DEVICE_TYPE_OLPC_MESH: |