diff --git a/libnm-core/nm-setting-connection.c b/libnm-core/nm-setting-connection.c index 5812a0a44..6832a985d 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; @@ -91,6 +93,7 @@ enum { PROP_ZONE, PROP_MASTER, PROP_SLAVE_TYPE, + PROP_AUTOCONNECT_SLAVES, PROP_SECONDARIES, PROP_GATEWAY_PING_TIMEOUT, PROP_METERED, @@ -604,6 +607,25 @@ 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. + * + * Since: 1.2 + **/ +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 @@ -1153,6 +1175,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)); @@ -1227,6 +1252,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; @@ -1560,6 +1588,37 @@ 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. + * + * Since: 1.2 + **/ + /* ---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 1692fe2c5..0f502c955 100644 --- a/libnm-core/nm-setting-connection.h +++ b/libnm-core/nm-setting-connection.h @@ -56,10 +56,30 @@ 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" #define NM_SETTING_CONNECTION_METERED "metered" +/* 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: * @@ -112,6 +132,8 @@ 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); +NM_AVAILABLE_IN_1_2 +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 670a0f3e9..24128862b 100644 --- a/libnm-core/tests/test-general.c +++ b/libnm-core/tests/test-general.c @@ -1968,6 +1968,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 }, { NM_SETTING_CONNECTION_METERED, NM_SETTING_DIFF_RESULT_IN_A }, diff --git a/libnm/libnm.ver b/libnm/libnm.ver index 34890414c..e8990c3e9 100644 --- a/libnm/libnm.ver +++ b/libnm/libnm.ver @@ -853,6 +853,8 @@ global: nm_metered_get_type; nm_setting_802_1x_check_cert_scheme; nm_setting_bridge_get_multicast_snooping; + nm_setting_connection_autoconnect_slaves_get_type; + nm_setting_connection_get_autoconnect_slaves; nm_setting_connection_get_metered; nm_setting_ip_config_add_dns_option; nm_setting_ip_config_clear_dns_options;