diff options
Diffstat (limited to 'src/nm-active-connection.c')
| -rw-r--r-- | src/nm-active-connection.c | 94 |
1 files changed, 78 insertions, 16 deletions
diff --git a/src/nm-active-connection.c b/src/nm-active-connection.c index a2f9ae4a..7b9f2cc7 100644 --- a/src/nm-active-connection.c +++ b/src/nm-active-connection.c @@ -30,6 +30,7 @@ #include "nm-auth-utils.h" #include "nm-auth-manager.h" #include "nm-auth-subject.h" +#include "nm-keep-alive.h" #include "NetworkManagerUtils.h" #include "nm-core-internal.h" @@ -75,6 +76,7 @@ typedef struct _NMActiveConnectionPrivate { gpointer user_data; } auth; + NMKeepAlive *keep_alive; } NMActiveConnectionPrivate; NM_GOBJECT_PROPERTIES_DEFINE (NMActiveConnection, @@ -159,16 +161,21 @@ NM_UTILS_LOOKUP_STR_DEFINE_STATIC (_state_to_string, NMActiveConnectionState, NM_UTILS_LOOKUP_STR_ITEM (NM_ACTIVE_CONNECTION_STATE_DEACTIVATING, "deactivating"), NM_UTILS_LOOKUP_STR_ITEM (NM_ACTIVE_CONNECTION_STATE_DEACTIVATED, "deactivated"), ); -#define state_to_string(state) NM_UTILS_LOOKUP_STR (_state_to_string, state) + +#define state_to_string_a(state) NM_UTILS_LOOKUP_STR_A (_state_to_string, state) + +/* the maximum required buffer size for _state_flags_to_string(). */ +#define _NM_ACTIVATION_STATE_FLAG_TO_STRING_BUFSIZE (255) NM_UTILS_FLAGS2STR_DEFINE_STATIC (_state_flags_to_string, NMActivationStateFlags, - NM_UTILS_FLAGS2STR (NM_ACTIVATION_STATE_FLAG_NONE, "none"), - NM_UTILS_FLAGS2STR (NM_ACTIVATION_STATE_FLAG_IS_MASTER, "is-master"), - NM_UTILS_FLAGS2STR (NM_ACTIVATION_STATE_FLAG_IS_SLAVE, "is-slave"), - NM_UTILS_FLAGS2STR (NM_ACTIVATION_STATE_FLAG_LAYER2_READY, "layer2-ready"), - NM_UTILS_FLAGS2STR (NM_ACTIVATION_STATE_FLAG_IP4_READY, "ip4-ready"), - NM_UTILS_FLAGS2STR (NM_ACTIVATION_STATE_FLAG_IP6_READY, "ip6-ready"), - NM_UTILS_FLAGS2STR (NM_ACTIVATION_STATE_FLAG_MASTER_HAS_SLAVES, "master-has-slaves"), + NM_UTILS_FLAGS2STR (NM_ACTIVATION_STATE_FLAG_NONE, "none"), + NM_UTILS_FLAGS2STR (NM_ACTIVATION_STATE_FLAG_IS_MASTER, "is-master"), + NM_UTILS_FLAGS2STR (NM_ACTIVATION_STATE_FLAG_IS_SLAVE, "is-slave"), + NM_UTILS_FLAGS2STR (NM_ACTIVATION_STATE_FLAG_LAYER2_READY, "layer2-ready"), + NM_UTILS_FLAGS2STR (NM_ACTIVATION_STATE_FLAG_IP4_READY, "ip4-ready"), + NM_UTILS_FLAGS2STR (NM_ACTIVATION_STATE_FLAG_IP6_READY, "ip6-ready"), + NM_UTILS_FLAGS2STR (NM_ACTIVATION_STATE_FLAG_MASTER_HAS_SLAVES, "master-has-slaves"), + NM_UTILS_FLAGS2STR (NM_ACTIVATION_STATE_FLAG_LIFETIME_BOUND_TO_PROFILE_VISIBILITY, "lifetime-bound-to-profile-visibility"), ); /*****************************************************************************/ @@ -250,8 +257,14 @@ nm_active_connection_set_state (NMActiveConnection *self, return; _LOGD ("set state %s (was %s)", - state_to_string (new_state), - state_to_string (priv->state)); + state_to_string_a (new_state), + state_to_string_a (priv->state)); + + if (new_state > NM_ACTIVE_CONNECTION_STATE_ACTIVATED) { + /* once we are about to deactivate, we don't need the keep-alive instance + * anymore. Freeze/disarm it. */ + nm_keep_alive_disarm (priv->keep_alive); + } if ( new_state == NM_ACTIVE_CONNECTION_STATE_ACTIVATED && priv->activation_type == NM_ACTIVATION_TYPE_ASSUME) { @@ -353,14 +366,20 @@ nm_active_connection_set_state_flags_full (NMActiveConnection *self, f = (priv->state_flags & ~mask) | (state_flags & mask); if (f != priv->state_flags) { - char buf1[G_N_ELEMENTS (_nm_utils_to_string_buffer)]; - char buf2[G_N_ELEMENTS (_nm_utils_to_string_buffer)]; + char buf1[_NM_ACTIVATION_STATE_FLAG_TO_STRING_BUFSIZE]; + char buf2[_NM_ACTIVATION_STATE_FLAG_TO_STRING_BUFSIZE]; _LOGD ("set state-flags %s (was %s)", _state_flags_to_string (f, buf1, sizeof (buf1)), _state_flags_to_string (priv->state_flags, buf2, sizeof (buf2))); priv->state_flags = f; _notify (self, PROP_STATE_FLAGS); + + nm_keep_alive_set_settings_connection_watch_visible (priv->keep_alive, + NM_FLAGS_HAS (priv->state_flags, + NM_ACTIVATION_STATE_FLAG_LIFETIME_BOUND_TO_PROFILE_VISIBILITY) + ? priv->settings_connection.obj + : NULL); } } @@ -768,11 +787,11 @@ check_master_ready (NMActiveConnection *self) signalling ? "signal" : (priv->master_ready ? "already signalled" : "not signalling"), - state_to_string (priv->state), + state_to_string_a (priv->state), priv->master ? nm_sprintf_bufa (128, "master %p is in state %s", priv->master, - state_to_string (nm_active_connection_get_state (priv->master))) + state_to_string_a (nm_active_connection_get_state (priv->master))) : "no master"); if (signalling) { @@ -836,7 +855,7 @@ nm_active_connection_set_master (NMActiveConnection *self, NMActiveConnection *m _LOGD ("set master %p, %s, state %s", master, nm_active_connection_get_settings_connection_id (master), - state_to_string (nm_active_connection_get_state (master))); + state_to_string_a (nm_active_connection_get_state (master))); priv->master = g_object_ref (master); g_signal_connect (priv->master, @@ -906,6 +925,32 @@ nm_active_connection_get_activation_reason (NMActiveConnection *self) /*****************************************************************************/ +/** + * nm_active_connection_get_keep_alive: + * @self: the #NMActiveConnection instance + * + * Gives the #NMKeepAlive instance of the active connection. Note that + * @self is guaranteed not to swap the keep-alive instance, so it is + * in particular safe to assume that the keep-alive instance is alive + * as long as @self, and that nm_active_connection_get_keep_alive() + * will return always the same instance. + * + * In particular this means, that it is safe and encouraged, that you + * register to the notify:alive property changed signal of the returned + * instance. + * + * Returns: the #NMKeepAlive instance. + */ +NMKeepAlive * +nm_active_connection_get_keep_alive (NMActiveConnection *self) +{ + g_return_val_if_fail (NM_IS_ACTIVE_CONNECTION (self), NULL); + + return NM_ACTIVE_CONNECTION_GET_PRIVATE (self)->keep_alive; +} + +/*****************************************************************************/ + static void _settings_connection_flags_changed (NMSettingsConnection *settings_connection, NMActiveConnection *self) @@ -1350,6 +1395,12 @@ set_property (GObject *object, guint prop_id, g_return_if_reached (); _set_activation_type (self, (NMActivationType) i); break; + case PROP_STATE_FLAGS: + /* construct-only */ + priv->state_flags = g_value_get_uint (value); + nm_assert ((guint) priv->state_flags == g_value_get_uint (value)); + nm_assert (!NM_FLAGS_ANY (priv->state_flags, ~NM_ACTIVATION_STATE_FLAG_LIFETIME_BOUND_TO_PROFILE_VISIBILITY)); + break; case PROP_INT_ACTIVATION_REASON: /* construct-only */ i = g_value_get_int (value); @@ -1400,6 +1451,10 @@ nm_active_connection_init (NMActiveConnection *self) priv->activation_type = NM_ACTIVATION_TYPE_MANAGED; priv->version_id = _version_id_new (); + + /* the keep-alive instance must never change. Callers rely on that. */ + priv->keep_alive = nm_keep_alive_new (); + _nm_keep_alive_set_owner (priv->keep_alive, G_OBJECT (self)); } static void @@ -1429,6 +1484,10 @@ constructed (GObject *object) g_steal_pointer (&priv->applied_connection)); } + if (NM_FLAGS_HAS (priv->state_flags, + NM_ACTIVATION_STATE_FLAG_LIFETIME_BOUND_TO_PROFILE_VISIBILITY)) + nm_keep_alive_set_settings_connection_watch_visible (priv->keep_alive, priv->settings_connection.obj); + g_return_if_fail (priv->subject); g_return_if_fail (priv->activation_reason != NM_ACTIVATION_REASON_UNSET); } @@ -1475,6 +1534,9 @@ finalize (GObject *object) nm_dbus_track_obj_path_set (&priv->settings_connection, NULL, FALSE); + _nm_keep_alive_set_owner (priv->keep_alive, NULL); + g_clear_object (&priv->keep_alive); + G_OBJECT_CLASS (nm_active_connection_parent_class)->finalize (object); } @@ -1579,7 +1641,7 @@ nm_active_connection_class_init (NMActiveConnectionClass *ac_class) obj_properties[PROP_STATE_FLAGS] = g_param_spec_uint (NM_ACTIVE_CONNECTION_STATE_FLAGS, "", "", 0, G_MAXUINT32, NM_ACTIVATION_STATE_FLAG_NONE, - G_PARAM_READABLE | + G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); obj_properties[PROP_DEFAULT] = |