From 408b6316734e3dc5ce17ee66193d0c86ded91d96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20Klime=C5=A1?= Date: Wed, 6 May 2015 10:54:35 +0200 Subject: [PATCH] libnm: add autoconnect-slaves property to NMSettingConnection The property is used for controlling whether slaves should be brought up with a master connection. If 0, activating the master will not activate slaves. But if set to 1, activating the master will bring up slaves as well. The property can have the third state (-1), meaning that the value is default. That is either a value set in the configuration file for the property, or 0. (cherry picked from commit 6caafab258762713a354cf37591510b6ac29936c) --- libnm-core/nm-setting-connection.c | 55 ++++++++++++++++++++++++++++++ libnm-core/nm-setting-connection.h | 21 ++++++++++++ libnm-core/tests/test-general.c | 1 + libnm/libnm.ver | 2 ++ 4 files changed, 79 insertions(+) diff --git a/libnm-core/nm-setting-connection.c b/libnm-core/nm-setting-connection.c index 7bc927bc1d..9749d31915 100644 --- a/libnm-core/nm-setting-connection.c +++ b/libnm-core/nm-setting-connection.c @@ -27,6 +27,7 @@ #include "nm-utils.h" #include "nm-utils-private.h" +#include "nm-core-enum-types.h" #include "nm-setting-connection.h" #include "nm-connection-private.h" #include "nm-setting-bond.h" @@ -66,6 +67,7 @@ typedef struct { char *type; char *master; char *slave_type; + NMSettingConnectionAutoconnectSlaves autoconnect_slaves; GSList *permissions; /* list of Permission structs */ gboolean autoconnect; gint autoconnect_priority; @@ -90,6 +92,7 @@ enum { PROP_ZONE, PROP_MASTER, PROP_SLAVE_TYPE, + PROP_AUTOCONNECT_SLAVES, PROP_SECONDARIES, PROP_GATEWAY_PING_TIMEOUT, @@ -602,6 +605,23 @@ nm_setting_connection_is_slave_type (NMSettingConnection *setting, return !g_strcmp0 (NM_SETTING_CONNECTION_GET_PRIVATE (setting)->slave_type, type); } +/** + * nm_setting_connection_get_autoconnect_slaves: + * @setting: the #NMSettingConnection + * + * Returns the #NMSettingConnection:autoconnect-slaves property of the connection. + * + * Returns: whether slaves of the connection should be activated together + * with the connection. + **/ +NMSettingConnectionAutoconnectSlaves +nm_setting_connection_get_autoconnect_slaves (NMSettingConnection *setting) +{ + g_return_val_if_fail (NM_IS_SETTING_CONNECTION (setting), NM_SETTING_CONNECTION_AUTOCONNECT_SLAVES_DEFAULT); + + return NM_SETTING_CONNECTION_GET_PRIVATE (setting)->autoconnect_slaves; +} + /** * nm_setting_connection_get_num_secondaries: * @setting: the #NMSettingConnection @@ -1122,6 +1142,9 @@ set_property (GObject *object, guint prop_id, g_free (priv->slave_type); priv->slave_type = g_value_dup_string (value); break; + case PROP_AUTOCONNECT_SLAVES: + priv->autoconnect_slaves = g_value_get_enum (value); + break; case PROP_SECONDARIES: g_slist_free_full (priv->secondaries, g_free); priv->secondaries = _nm_utils_strv_to_slist (g_value_get_boxed (value)); @@ -1193,6 +1216,9 @@ get_property (GObject *object, guint prop_id, case PROP_SLAVE_TYPE: g_value_set_string (value, nm_setting_connection_get_slave_type (setting)); break; + case PROP_AUTOCONNECT_SLAVES: + g_value_set_enum (value, nm_setting_connection_get_autoconnect_slaves (setting)); + break; case PROP_SECONDARIES: g_value_take_boxed (value, _nm_utils_slist_to_strv (priv->secondaries)); break; @@ -1523,6 +1549,35 @@ nm_setting_connection_class_init (NMSettingConnectionClass *setting_class) NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS)); + /** + * NMSettingConnection:autoconnect-slaves: + * + * Whether or not slaves of this connection should be automatically brought up + * when NetworkManager activates this connection. This only has a real effect + * for master connections. + * The permitted values are: 0: leave slave connections untouched, + * 1: activate all the slave connections with this connection, -1: default. + * If -1 (default) is set, global connection.autoconnect-slaves is read to + * determine the real value. If it is default as well, this fallbacks to 0. + **/ + /* ---ifcfg-rh--- + * property: autoconnect-slaves + * variable: AUTOCONNECT-SLAVES(+) + * default: no + * description: Whether slaves of this connection should be auto-connected + * when this connection is activated. + * ---end--- + */ + g_object_class_install_property + (object_class, PROP_AUTOCONNECT_SLAVES, + g_param_spec_enum (NM_SETTING_CONNECTION_AUTOCONNECT_SLAVES, "", "", + NM_TYPE_SETTING_CONNECTION_AUTOCONNECT_SLAVES, + NM_SETTING_CONNECTION_AUTOCONNECT_SLAVES_DEFAULT, + G_PARAM_READWRITE | + G_PARAM_CONSTRUCT | + NM_SETTING_PARAM_FUZZY_IGNORE | + G_PARAM_STATIC_STRINGS)); + /** * NMSettingConnection:secondaries: * diff --git a/libnm-core/nm-setting-connection.h b/libnm-core/nm-setting-connection.h index d1ad0fe1e5..1e365dd3ca 100644 --- a/libnm-core/nm-setting-connection.h +++ b/libnm-core/nm-setting-connection.h @@ -56,9 +56,29 @@ G_BEGIN_DECLS #define NM_SETTING_CONNECTION_ZONE "zone" #define NM_SETTING_CONNECTION_MASTER "master" #define NM_SETTING_CONNECTION_SLAVE_TYPE "slave-type" +#define NM_SETTING_CONNECTION_AUTOCONNECT_SLAVES "autoconnect-slaves" #define NM_SETTING_CONNECTION_SECONDARIES "secondaries" #define NM_SETTING_CONNECTION_GATEWAY_PING_TIMEOUT "gateway-ping-timeout" +/* Types for property values */ +/** + * NMSettingConnectionAutoconnectSlaves: + * @NM_SETTING_CONNECTION_AUTOCONNECT_SLAVES_DEFAULT: default value + * @NM_SETTING_CONNECTION_AUTOCONNECT_SLAVES_NO: slaves are not brought up when + * master is activated + * @NM_SETTING_CONNECTION_AUTOCONNECT_SLAVES_YES: slaves are brought up when + * master is activated + * + * #NMSettingConnectionAutoconnectSlaves values indicate whether slave connections + * should be activated when master is activated. + */ +typedef enum { + NM_SETTING_CONNECTION_AUTOCONNECT_SLAVES_DEFAULT = -1, + NM_SETTING_CONNECTION_AUTOCONNECT_SLAVES_NO = 0, + NM_SETTING_CONNECTION_AUTOCONNECT_SLAVES_YES = 1, +} NMSettingConnectionAutoconnectSlaves; + + /** * NMSettingConnection: * @@ -111,6 +131,7 @@ const char *nm_setting_connection_get_master (NMSettingConnection *set gboolean nm_setting_connection_is_slave_type (NMSettingConnection *setting, const char *type); const char *nm_setting_connection_get_slave_type (NMSettingConnection *setting); +NMSettingConnectionAutoconnectSlaves nm_setting_connection_get_autoconnect_slaves (NMSettingConnection *setting); guint32 nm_setting_connection_get_num_secondaries (NMSettingConnection *setting); const char *nm_setting_connection_get_secondary (NMSettingConnection *setting, guint32 idx); diff --git a/libnm-core/tests/test-general.c b/libnm-core/tests/test-general.c index 202326ffa5..b686f6ce26 100644 --- a/libnm-core/tests/test-general.c +++ b/libnm-core/tests/test-general.c @@ -1963,6 +1963,7 @@ test_connection_diff_a_only (void) { NM_SETTING_CONNECTION_ZONE, NM_SETTING_DIFF_RESULT_IN_A }, { NM_SETTING_CONNECTION_MASTER, NM_SETTING_DIFF_RESULT_IN_A }, { NM_SETTING_CONNECTION_SLAVE_TYPE, NM_SETTING_DIFF_RESULT_IN_A }, + { NM_SETTING_CONNECTION_AUTOCONNECT_SLAVES, NM_SETTING_DIFF_RESULT_IN_A }, { NM_SETTING_CONNECTION_SECONDARIES, NM_SETTING_DIFF_RESULT_IN_A }, { NM_SETTING_CONNECTION_GATEWAY_PING_TIMEOUT, NM_SETTING_DIFF_RESULT_IN_A }, { NULL, NM_SETTING_DIFF_RESULT_UNKNOWN } diff --git a/libnm/libnm.ver b/libnm/libnm.ver index 82bcdb9f07..88a79a88b8 100644 --- a/libnm/libnm.ver +++ b/libnm/libnm.ver @@ -466,8 +466,10 @@ global: nm_setting_compare_flags_get_type; nm_setting_connection_add_permission; nm_setting_connection_add_secondary; + nm_setting_connection_autoconnect_slaves_get_type; nm_setting_connection_get_autoconnect; nm_setting_connection_get_autoconnect_priority; + nm_setting_connection_get_autoconnect_slaves; nm_setting_connection_get_connection_type; nm_setting_connection_get_gateway_ping_timeout; nm_setting_connection_get_id;