static void device_master_changed (GObject *object, GParamSpec *pspec, gpointer user_data) { NMDevice *device = NM_DEVICE (object); NMActiveConnection *self = NM_ACTIVE_CONNECTION (user_data); NMActiveConnection *master; NMActiveConnectionState master_state; if (NM_ACTIVE_CONNECTION (nm_device_get_act_request (device)) != self) return; if (!nm_device_get_master (device)) return; if (!nm_active_connection_get_master (self)) return; g_signal_handlers_disconnect_by_func (device, G_CALLBACK (device_master_changed), self); master = nm_active_connection_get_master (self); master_state = nm_active_connection_get_state (master); if (master_state >= NM_ACTIVE_CONNECTION_STATE_DEACTIVATING) { /* Master failed before attaching the slave */ if (NM_ACTIVE_CONNECTION_GET_CLASS (self)->master_failed) NM_ACTIVE_CONNECTION_GET_CLASS (self)->master_failed (self); } }
static void device_state_changed (NMDevice *device, NMDeviceState new_state, NMDeviceState old_state, NMDeviceStateReason reason, gpointer user_data) { NMActRequest *self = NM_ACT_REQUEST (user_data); NMActiveConnectionState new_ac_state; /* Set NMActiveConnection state based on the device's state */ switch (new_state) { case NM_DEVICE_STATE_PREPARE: case NM_DEVICE_STATE_CONFIG: case NM_DEVICE_STATE_NEED_AUTH: case NM_DEVICE_STATE_IP_CONFIG: case NM_DEVICE_STATE_IP_CHECK: case NM_DEVICE_STATE_SECONDARIES: new_ac_state = NM_ACTIVE_CONNECTION_STATE_ACTIVATING; break; case NM_DEVICE_STATE_ACTIVATED: new_ac_state = NM_ACTIVE_CONNECTION_STATE_ACTIVATED; break; case NM_DEVICE_STATE_DEACTIVATING: new_ac_state = NM_ACTIVE_CONNECTION_STATE_DEACTIVATING; break; default: new_ac_state = NM_ACTIVE_CONNECTION_STATE_UNKNOWN; nm_active_connection_set_default (NM_ACTIVE_CONNECTION (self), FALSE); nm_active_connection_set_default6 (NM_ACTIVE_CONNECTION (self), FALSE); break; } nm_active_connection_set_state (NM_ACTIVE_CONNECTION (self), new_ac_state); }
NMConnection * nm_act_request_get_connection (NMActRequest *req) { g_return_val_if_fail (NM_IS_ACT_REQUEST (req), NULL); return nm_active_connection_get_connection (NM_ACTIVE_CONNECTION (req)); }
/** * nm_act_request_new: * * @connection: the connection to activate @device with * @specific_object: the object path of the specific object (ie, WiFi access point, * etc) that will be used to activate @connection and @device * @user_requested: pass %TRUE if the activation was requested via D-Bus, * otherwise %FALSE if requested internally by NM (ie, autoconnect) * @user_uid: if @user_requested is %TRUE, the Unix UID of the user that requested * @dbus_sender: if @user_requested is %TRUE, the D-BUS sender that requested * the activation * @assumed: pass %TRUE if the activation should "assume" (ie, taking over) an * existing connection made before this instance of NM started * @device: the device/interface to configure according to @connection * @master: if the activation depends on another device (ie, bond or bridge * master to which this device will be enslaved) pass the #NMDevice that this * activation request be enslaved to * * Begins activation of @device using the given @connection and other details. * * Returns: the new activation request on success, %NULL on error. */ NMActRequest * nm_act_request_new (NMConnection *connection, const char *specific_object, gboolean user_requested, gulong user_uid, const char *dbus_sender, gboolean assumed, NMDevice *device, NMDevice *master) { GObject *object; g_return_val_if_fail (NM_IS_CONNECTION (connection), NULL); g_return_val_if_fail (NM_DEVICE (device), NULL); object = g_object_new (NM_TYPE_ACT_REQUEST, NM_ACTIVE_CONNECTION_INT_CONNECTION, connection, NM_ACTIVE_CONNECTION_INT_DEVICE, device, NM_ACTIVE_CONNECTION_SPECIFIC_OBJECT, specific_object, NM_ACTIVE_CONNECTION_INT_USER_REQUESTED, user_requested, NM_ACTIVE_CONNECTION_INT_USER_UID, user_uid, NM_ACTIVE_CONNECTION_INT_ASSUMED, assumed, NM_ACTIVE_CONNECTION_INT_MASTER, master, NULL); if (object) { nm_active_connection_export (NM_ACTIVE_CONNECTION (object)); NM_ACT_REQUEST_GET_PRIVATE (object)->dbus_sender = g_strdup (dbus_sender); } return (NMActRequest *) object; }
static void get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { NMDevice *device; device = nm_active_connection_get_device (NM_ACTIVE_CONNECTION (object)); if (!device) { g_value_set_string (value, "/"); return; } switch (prop_id) { case PROP_IP4_CONFIG: g_object_get_property (G_OBJECT (device), NM_DEVICE_IP4_CONFIG, value); break; case PROP_DHCP4_CONFIG: g_object_get_property (G_OBJECT (device), NM_DEVICE_DHCP4_CONFIG, value); break; case PROP_IP6_CONFIG: g_object_get_property (G_OBJECT (device), NM_DEVICE_IP6_CONFIG, value); break; case PROP_DHCP6_CONFIG: g_object_get_property (G_OBJECT (device), NM_DEVICE_DHCP6_CONFIG, value); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; } }
static void get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { NMActiveConnection *self = NM_ACTIVE_CONNECTION (object); switch (prop_id) { case PROP_SERVICE_NAME: g_value_set_string (value, nm_active_connection_get_service_name (self)); break; case PROP_CONNECTION: g_value_set_boxed (value, nm_active_connection_get_connection (self)); break; case PROP_SPECIFIC_OBJECT: g_value_set_boxed (value, nm_active_connection_get_specific_object (self)); break; case PROP_DEVICES: g_value_set_boxed (value, nm_active_connection_get_devices (self)); break; case PROP_STATE: g_value_set_uint (value, nm_active_connection_get_state (self)); break; case PROP_DEFAULT: g_value_set_boolean (value, nm_active_connection_get_default (self)); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; } }
static GObject* constructor (GType type, guint n_construct_params, GObjectConstructParam *construct_params) { NMObject *object; NMActiveConnectionPrivate *priv; object = (NMObject *) G_OBJECT_CLASS (nm_active_connection_parent_class)->constructor (type, n_construct_params, construct_params); if (!object) return NULL; priv = NM_ACTIVE_CONNECTION_GET_PRIVATE (object); priv->proxy = dbus_g_proxy_new_for_name (nm_object_get_connection (object), NM_DBUS_SERVICE, nm_object_get_path (object), NM_DBUS_INTERFACE_ACTIVE_CONNECTION); register_for_property_changed (NM_ACTIVE_CONNECTION (object)); return G_OBJECT (object); }
static void dispose (GObject *object) { NMActiveConnection *self = NM_ACTIVE_CONNECTION (object); NMActiveConnectionPrivate *priv = NM_ACTIVE_CONNECTION_GET_PRIVATE (self); _LOGD ("disposing"); if (priv->chain) { nm_auth_chain_unref (priv->chain); priv->chain = NULL; } g_free (priv->specific_object); priv->specific_object = NULL; _set_settings_connection (self, NULL); g_clear_object (&priv->applied_connection); _device_cleanup (self); if (priv->master) { g_signal_handlers_disconnect_by_func (priv->master, (GCallback) master_state_cb, self); } g_clear_object (&priv->master); if (priv->parent) unwatch_parent (self); g_clear_object (&priv->subject); G_OBJECT_CLASS (nm_active_connection_parent_class)->dispose (object); }
static gboolean match_parent (NMDeviceVlan *self, const char *parent) { NMDeviceVlanPrivate *priv = NM_DEVICE_VLAN_GET_PRIVATE (self); g_return_val_if_fail (parent != NULL, FALSE); if (nm_utils_is_uuid (parent)) { NMActRequest *parent_req; NMConnection *parent_connection; /* If the parent is a UUID, the connection matches if our parent * device has that connection activated. */ parent_req = nm_device_get_act_request (priv->parent); if (!parent_req) return FALSE; parent_connection = nm_active_connection_get_connection (NM_ACTIVE_CONNECTION (parent_req)); if (!parent_connection) return FALSE; if (g_strcmp0 (parent, nm_connection_get_uuid (parent_connection)) != 0) return FALSE; } else { /* interface name */ if (g_strcmp0 (parent, nm_device_get_ip_iface (priv->parent)) != 0) return FALSE; } return TRUE; }
static gboolean match_parent (NMDevice *dev_parent, const char *setting_parent) { g_return_val_if_fail (setting_parent, FALSE); if (!dev_parent) return FALSE; if (nm_utils_is_uuid (setting_parent)) { NMActRequest *parent_req; NMConnection *parent_connection; /* If the parent is a UUID, the connection matches if our parent * device has that connection activated. */ parent_req = nm_device_get_act_request (dev_parent); if (!parent_req) return FALSE; parent_connection = nm_active_connection_get_applied_connection (NM_ACTIVE_CONNECTION (parent_req)); if (!parent_connection) return FALSE; if (g_strcmp0 (setting_parent, nm_connection_get_uuid (parent_connection)) != 0) return FALSE; } else { /* interface name */ if (g_strcmp0 (setting_parent, nm_device_get_ip_iface (dev_parent)) != 0) return FALSE; } return TRUE; }
static void device_state_changed (NMDevice *device, GParamSpec *pspec, NMActRequest *self) { NMActRequestPrivate *priv = NM_ACT_REQUEST_GET_PRIVATE (self); NMActiveConnectionState ac_state = NM_ACTIVE_CONNECTION_STATE_UNKNOWN; /* Set NMActiveConnection state based on the device's state */ switch (nm_device_get_state (device)) { case NM_DEVICE_STATE_PREPARE: case NM_DEVICE_STATE_CONFIG: case NM_DEVICE_STATE_NEED_AUTH: case NM_DEVICE_STATE_IP_CONFIG: case NM_DEVICE_STATE_IP_CHECK: case NM_DEVICE_STATE_SECONDARIES: ac_state = NM_ACTIVE_CONNECTION_STATE_ACTIVATING; break; case NM_DEVICE_STATE_ACTIVATED: ac_state = NM_ACTIVE_CONNECTION_STATE_ACTIVATED; break; case NM_DEVICE_STATE_DEACTIVATING: ac_state = NM_ACTIVE_CONNECTION_STATE_DEACTIVATING; break; case NM_DEVICE_STATE_FAILED: case NM_DEVICE_STATE_DISCONNECTED: case NM_DEVICE_STATE_UNMANAGED: case NM_DEVICE_STATE_UNAVAILABLE: ac_state = NM_ACTIVE_CONNECTION_STATE_DEACTIVATED; /* No longer need to pay attention to device state */ if (priv->device && priv->device_state_id) { g_signal_handler_disconnect (priv->device, priv->device_state_id); priv->device_state_id = 0; } g_clear_object (&priv->device); break; default: break; } if ( ac_state == NM_ACTIVE_CONNECTION_STATE_DEACTIVATED || ac_state == NM_ACTIVE_CONNECTION_STATE_UNKNOWN) { nm_active_connection_set_default (NM_ACTIVE_CONNECTION (self), FALSE); nm_active_connection_set_default6 (NM_ACTIVE_CONNECTION (self), FALSE); } nm_active_connection_set_state (NM_ACTIVE_CONNECTION (self), ac_state); }
guint32 nm_act_request_get_secrets (NMActRequest *self, const char *setting_name, NMSettingsGetSecretsFlags flags, const char *hint, NMActRequestSecretsFunc callback, gpointer callback_data) { NMActRequestPrivate *priv; GetSecretsInfo *info; guint32 call_id; NMConnection *connection; gboolean user_requested; g_return_val_if_fail (self, 0); g_return_val_if_fail (NM_IS_ACT_REQUEST (self), 0); priv = NM_ACT_REQUEST_GET_PRIVATE (self); info = g_malloc0 (sizeof (GetSecretsInfo)); info->self = self; info->callback = callback; info->callback_data = callback_data; user_requested = nm_active_connection_get_user_requested (NM_ACTIVE_CONNECTION (self)); if (user_requested) flags |= NM_SETTINGS_GET_SECRETS_FLAG_USER_REQUESTED; connection = nm_active_connection_get_connection (NM_ACTIVE_CONNECTION (self)); call_id = nm_settings_connection_get_secrets (NM_SETTINGS_CONNECTION (connection), user_requested, nm_active_connection_get_user_uid (NM_ACTIVE_CONNECTION (self)), setting_name, flags, hint, get_secrets_cb, info, NULL); if (call_id > 0) { info->call_id = call_id; priv->secrets_calls = g_slist_append (priv->secrets_calls, info); } else g_free (info); return call_id; }
static void auth_done (NMAuthChain *chain, GError *error, GDBusMethodInvocation *unused, gpointer user_data) { NMActiveConnection *self = NM_ACTIVE_CONNECTION (user_data); NMActiveConnectionPrivate *priv = NM_ACTIVE_CONNECTION_GET_PRIVATE (self); NMAuthCallResult result; g_assert (priv->chain == chain); g_assert (priv->result_func != NULL); /* Must stay alive over the callback */ g_object_ref (self); if (error) { priv->result_func (self, FALSE, error->message, priv->user_data1, priv->user_data2); goto done; } /* Caller has had a chance to obtain authorization, so we only need to * check for 'yes' here. */ result = nm_auth_chain_get_result (chain, NM_AUTH_PERMISSION_NETWORK_CONTROL); if (result != NM_AUTH_CALL_RESULT_YES) { priv->result_func (self, FALSE, "Not authorized to control networking.", priv->user_data1, priv->user_data2); goto done; } if (priv->wifi_shared_permission) { result = nm_auth_chain_get_result (chain, priv->wifi_shared_permission); if (result != NM_AUTH_CALL_RESULT_YES) { priv->result_func (self, FALSE, "Not authorized to share connections via wifi.", priv->user_data1, priv->user_data2); goto done; } } /* Otherwise authorized and available to activate */ priv->result_func (self, TRUE, NULL, priv->user_data1, priv->user_data2); done: nm_auth_chain_unref (chain); priv->chain = NULL; priv->result_func = NULL; priv->user_data1 = NULL; priv->user_data2 = NULL; g_object_unref (self); }
static void device_state_changed (NMDevice *device, GParamSpec *pspec, NMActRequest *self) { NMActiveConnectionState ac_state = NM_ACTIVE_CONNECTION_STATE_UNKNOWN; NMActiveConnectionState prev_ac_state = nm_active_connection_get_state (NM_ACTIVE_CONNECTION (self)); /* Set NMActiveConnection state based on the device's state */ switch (nm_device_get_state (device)) { case NM_DEVICE_STATE_PREPARE: case NM_DEVICE_STATE_CONFIG: case NM_DEVICE_STATE_NEED_AUTH: case NM_DEVICE_STATE_IP_CONFIG: case NM_DEVICE_STATE_IP_CHECK: case NM_DEVICE_STATE_SECONDARIES: ac_state = NM_ACTIVE_CONNECTION_STATE_ACTIVATING; break; case NM_DEVICE_STATE_ACTIVATED: ac_state = NM_ACTIVE_CONNECTION_STATE_ACTIVATED; break; case NM_DEVICE_STATE_DEACTIVATING: ac_state = NM_ACTIVE_CONNECTION_STATE_DEACTIVATING; break; case NM_DEVICE_STATE_FAILED: case NM_DEVICE_STATE_DISCONNECTED: ac_state = NM_ACTIVE_CONNECTION_STATE_DEACTIVATED; break; default: break; } if ( ac_state == NM_ACTIVE_CONNECTION_STATE_DEACTIVATED || ac_state == NM_ACTIVE_CONNECTION_STATE_UNKNOWN) { nm_active_connection_set_default (NM_ACTIVE_CONNECTION (self), FALSE); nm_active_connection_set_default6 (NM_ACTIVE_CONNECTION (self), FALSE); } /* Only set new state if we are not in DEACTIVATED. Those connections * will be removed. See _active_connection_cleanup() in nm-manager.c */ if (prev_ac_state != NM_ACTIVE_CONNECTION_STATE_DEACTIVATED) nm_active_connection_set_state (NM_ACTIVE_CONNECTION (self), ac_state); }
gboolean nm_vpn_manager_activate_connection (NMVpnManager *manager, NMVpnConnection *vpn, GError **error) { NMConnection *connection; NMSettingVpn *s_vpn; NMVpnService *service; const char *service_name; NMDevice *device; g_return_val_if_fail (NM_IS_VPN_MANAGER (manager), FALSE); g_return_val_if_fail (NM_IS_VPN_CONNECTION (vpn), FALSE); g_return_val_if_fail (error != NULL, FALSE); g_return_val_if_fail (*error == NULL, FALSE); device = nm_active_connection_get_device (NM_ACTIVE_CONNECTION (vpn)); g_assert (device); if ( nm_device_get_state (device) != NM_DEVICE_STATE_ACTIVATED && nm_device_get_state (device) != NM_DEVICE_STATE_SECONDARIES) { g_set_error_literal (error, NM_VPN_MANAGER_ERROR, NM_VPN_MANAGER_ERROR_DEVICE_NOT_ACTIVE, "The base device for the VPN connection was not active."); return FALSE; } connection = nm_active_connection_get_connection (NM_ACTIVE_CONNECTION (vpn)); g_assert (connection); s_vpn = nm_connection_get_setting_vpn (connection); g_assert (s_vpn); service_name = nm_setting_vpn_get_service_type (s_vpn); g_assert (service_name); service = g_hash_table_lookup (NM_VPN_MANAGER_GET_PRIVATE (manager)->services, service_name); if (!service) { g_set_error (error, NM_VPN_MANAGER_ERROR, NM_VPN_MANAGER_ERROR_SERVICE_INVALID, "The VPN service '%s' was not installed.", service_name); return FALSE; } return nm_vpn_service_activate (service, vpn, error); }
gboolean nm_vpn_manager_activate_connection (NMVpnManager *manager, NMVpnConnection *vpn, GError **error) { NMVpnManagerPrivate *priv; NMVpnPluginInfo *plugin_info; const char *service_name; NMDevice *device; g_return_val_if_fail (NM_IS_VPN_MANAGER (manager), FALSE); g_return_val_if_fail (NM_IS_VPN_CONNECTION (vpn), FALSE); g_return_val_if_fail (!error || !*error, FALSE); priv = NM_VPN_MANAGER_GET_PRIVATE (manager); device = nm_active_connection_get_device (NM_ACTIVE_CONNECTION (vpn)); g_assert (device); if ( nm_device_get_state (device) != NM_DEVICE_STATE_ACTIVATED && nm_device_get_state (device) != NM_DEVICE_STATE_SECONDARIES) { g_set_error_literal (error, NM_MANAGER_ERROR, NM_MANAGER_ERROR_DEPENDENCY_FAILED, "The base device for the VPN connection was not active."); return FALSE; } service_name = nm_vpn_connection_get_service (vpn); plugin_info = nm_vpn_plugin_info_list_find_by_service (priv->plugins, service_name); if (!plugin_info) { g_set_error (error, NM_MANAGER_ERROR, NM_MANAGER_ERROR_CONNECTION_NOT_AVAILABLE, "The VPN service '%s' was not installed.", service_name); return FALSE; } if ( !nm_vpn_plugin_info_supports_multiple (plugin_info) && g_hash_table_contains (priv->active_services, service_name)) { g_set_error (error, NM_MANAGER_ERROR, NM_MANAGER_ERROR_CONNECTION_NOT_AVAILABLE, "The '%s' plugin only supports a single active connection.", nm_vpn_plugin_info_get_name (plugin_info)); return FALSE; } nm_vpn_connection_activate (vpn, plugin_info); if (!nm_vpn_plugin_info_supports_multiple (plugin_info)) { /* Block activations of the connections of the same service type. */ g_hash_table_add (priv->active_services, g_strdup (service_name)); g_signal_connect (vpn, "notify::" NM_ACTIVE_CONNECTION_STATE, G_CALLBACK (vpn_state_changed), g_object_ref (manager)); } return TRUE; }
/** * nm_act_request_get_secrets: * @self: * @setting_name: * @flags: * @hint: * @callback: * @callback_data: * * Asnychronously starts the request for secrets. This function cannot * fail. * * The return call-id can be used to cancel the request. You are * only allowed to cancel a still pending operation (once). * The callback will always be invoked once, even for canceling * or disposing of NMActRequest. * * Returns: a call-id. */ NMActRequestGetSecretsCallId nm_act_request_get_secrets (NMActRequest *self, const char *setting_name, NMSecretAgentGetSecretsFlags flags, const char *hint, NMActRequestSecretsFunc callback, gpointer callback_data) { NMActRequestPrivate *priv; GetSecretsInfo *info; NMSettingsConnectionCallId call_id_s; NMSettingsConnection *settings_connection; NMConnection *applied_connection; const char *hints[2] = { hint, NULL }; g_return_val_if_fail (NM_IS_ACT_REQUEST (self), 0); priv = NM_ACT_REQUEST_GET_PRIVATE (self); settings_connection = nm_act_request_get_settings_connection (self); applied_connection = nm_act_request_get_applied_connection (self); info = _get_secrets_info_new (self, callback, callback_data); priv->secrets_calls = g_slist_append (priv->secrets_calls, info); if (nm_active_connection_get_user_requested (NM_ACTIVE_CONNECTION (self))) flags |= NM_SECRET_AGENT_GET_SECRETS_FLAG_USER_REQUESTED; call_id_s = nm_settings_connection_get_secrets (settings_connection, applied_connection, nm_active_connection_get_subject (NM_ACTIVE_CONNECTION (self)), setting_name, flags, hints, get_secrets_cb, info); info->call_id = call_id_s; g_return_val_if_fail (call_id_s, NULL); return info; }
/** * nm_act_request_new: * * @connection: the connection to activate @device with * @specific_object: the object path of the specific object (ie, WiFi access point, * etc) that will be used to activate @connection and @device * @user_requested: pass %TRUE if the activation was requested via D-Bus, * otherwise %FALSE if requested internally by NM (ie, autoconnect) * @user_uid: if @user_requested is %TRUE, the Unix UID of the user that requested * @dbus_sender: if @user_requested is %TRUE, the D-BUS sender that requested * the activation * @assumed: pass %TRUE if the activation should "assume" (ie, taking over) an * existing connection made before this instance of NM started * @device: the device/interface to configure according to @connection * @dependency: if the activation depends on another device (ie, VLAN slave, * bond slave, etc) pass the #NMActiveConnection that this activation request * should wait for before proceeding * * Begins activation of @device using the given @connection and other details. * * Returns: the new activation request on success, %NULL on error. */ NMActRequest * nm_act_request_new (NMConnection *connection, const char *specific_object, gboolean user_requested, gulong user_uid, const char *dbus_sender, gboolean assumed, gpointer *device, NMActiveConnection *dependency) { GObject *object; NMActRequestPrivate *priv; g_return_val_if_fail (NM_IS_CONNECTION (connection), NULL); g_return_val_if_fail (NM_DEVICE (device), NULL); object = g_object_new (NM_TYPE_ACT_REQUEST, NM_ACTIVE_CONNECTION_SPECIFIC_OBJECT, specific_object, NULL); if (!object) return NULL; priv = NM_ACT_REQUEST_GET_PRIVATE (object); priv->connection = g_object_ref (connection); priv->device = NM_DEVICE (device); g_signal_connect (device, "state-changed", G_CALLBACK (device_state_changed), NM_ACT_REQUEST (object)); priv->user_uid = user_uid; priv->user_requested = user_requested; priv->dbus_sender = g_strdup (dbus_sender); priv->assumed = assumed; if (dependency) { priv->dep = dependency; g_object_weak_ref (G_OBJECT (dependency), (GWeakNotify) dep_gone, object); priv->dep_state_id = g_signal_connect (dependency, "notify::" NM_ACTIVE_CONNECTION_STATE, G_CALLBACK (dep_state_changed), object); } if (!nm_active_connection_export (NM_ACTIVE_CONNECTION (object), connection, nm_device_get_path (NM_DEVICE (device)))) { g_object_unref (object); object = NULL; } return (NMActRequest *) object; }
static void constructed (GObject *object) { NMActRequestPrivate *priv = NM_ACT_REQUEST_GET_PRIVATE (object); NMConnection *connection; NMDevice *device; G_OBJECT_CLASS (nm_act_request_parent_class)->constructed (object); connection = nm_active_connection_get_connection (NM_ACTIVE_CONNECTION (object)); priv->connection = g_object_ref (connection); device = nm_active_connection_get_device (NM_ACTIVE_CONNECTION (object)); if (device) { priv->device = g_object_ref (device); priv->device_state_id = g_signal_connect (priv->device, "notify::" NM_DEVICE_STATE, G_CALLBACK (device_state_changed), NM_ACT_REQUEST (object)); } }
static void impl_ppp_manager_need_secrets (NMPPPManager *manager, GDBusMethodInvocation *context) { NMPPPManagerPrivate *priv = NM_PPP_MANAGER_GET_PRIVATE (manager); NMConnection *applied_connection; const char *username = NULL; const char *password = NULL; guint32 tries; GPtrArray *hints = NULL; GError *error = NULL; NMSecretAgentGetSecretsFlags flags = NM_SECRET_AGENT_GET_SECRETS_FLAG_ALLOW_INTERACTION; nm_active_connection_clear_secrets (NM_ACTIVE_CONNECTION (priv->act_req)); applied_connection = nm_act_request_get_applied_connection (priv->act_req); priv->secrets_setting_name = nm_connection_need_secrets (applied_connection, &hints); if (!priv->secrets_setting_name) { /* Use existing secrets from the connection */ if (extract_details_from_connection (applied_connection, NULL, &username, &password, &error)) { /* Send existing secrets to the PPP plugin */ priv->pending_secrets_context = context; ppp_secrets_cb (priv->act_req, priv->secrets_id, NULL, NULL, manager); } else { _LOGW ("%s", error->message); g_dbus_method_invocation_take_error (priv->pending_secrets_context, error); } return; } /* Only ask for completely new secrets after retrying them once; some devices * appear to ask a few times when they actually don't even care what you * pass back. */ tries = GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (applied_connection), PPP_MANAGER_SECRET_TRIES)); if (tries > 1) flags |= NM_SECRET_AGENT_GET_SECRETS_FLAG_REQUEST_NEW; priv->secrets_id = nm_act_request_get_secrets (priv->act_req, priv->secrets_setting_name, flags, hints ? g_ptr_array_index (hints, 0) : NULL, ppp_secrets_cb, manager); g_object_set_data (G_OBJECT (applied_connection), PPP_MANAGER_SECRET_TRIES, GUINT_TO_POINTER (++tries)); priv->pending_secrets_context = context; if (hints) g_ptr_array_free (hints, TRUE); }
static void vpn_state_changed (NMVpnConnection *vpn, GParamSpec *pspec, NMVpnManager *manager) { NMVpnManagerPrivate *priv = NM_VPN_MANAGER_GET_PRIVATE (manager); NMActiveConnectionState state = nm_active_connection_get_state (NM_ACTIVE_CONNECTION (vpn)); const char *service_name = nm_vpn_connection_get_service (vpn); if (state == NM_ACTIVE_CONNECTION_STATE_DEACTIVATED) { g_hash_table_remove (priv->active_services, service_name); g_signal_handlers_disconnect_by_func (vpn, vpn_state_changed, manager); g_object_unref (manager); } }
static NMActStageReturn act_stage1_prepare (NMDevice *device, NMDeviceStateReason *reason) { NMDeviceWimaxPrivate *priv = NM_DEVICE_WIMAX_GET_PRIVATE (device); NMActRequest *req; GSList *iter; const char *path; NMWimaxNsp *nsp = NULL; clear_link_timeout (NM_DEVICE_WIMAX (device)); *reason = NM_DEVICE_STATE_REASON_NONE; req = nm_device_get_act_request (device); if (!req) return NM_ACT_STAGE_RETURN_FAILURE; path = nm_active_connection_get_specific_object (NM_ACTIVE_CONNECTION (req)); if (!path) return NM_ACT_STAGE_RETURN_FAILURE; /* Find the NSP in the scan list */ for (iter = priv->nsp_list; iter; iter = iter->next) { NMWimaxNsp *candidate = NM_WIMAX_NSP (iter->data); if (!strcmp (path, nm_wimax_nsp_get_dbus_path (candidate))) { nsp = candidate; break; } } /* Couldn't find the NSP for some reason */ if (nsp == NULL) return NM_ACT_STAGE_RETURN_FAILURE; set_current_nsp (NM_DEVICE_WIMAX (device), nsp); priv->prepare_done = TRUE; /* If the device is scanning, it won't connect, so we have to wait until * it's not scanning to proceed to stage 2. */ if (priv->status == WIMAX_API_DEVICE_STATUS_Scanning) return NM_ACT_STAGE_RETURN_POSTPONE; return NM_ACT_STAGE_RETURN_SUCCESS; }
static void master_state_cb (NMActiveConnection *master, GParamSpec *pspec, gpointer user_data) { NMActiveConnection *self = NM_ACTIVE_CONNECTION (user_data); NMActiveConnectionState master_state = nm_active_connection_get_state (master); NMDevice *master_device = nm_active_connection_get_device (master); check_master_ready (self); if ( master_state == NM_ACTIVE_CONNECTION_STATE_DEACTIVATING && (!master_device || !nm_device_is_real (master_device))) { /* Master failed without ever creating or realizing its device */ if (NM_ACTIVE_CONNECTION_GET_CLASS (self)->master_failed) NM_ACTIVE_CONNECTION_GET_CLASS (self)->master_failed (self); } }
static void detail_vpn (gpointer data, gpointer user_data) { NMActiveConnection *active = NM_ACTIVE_CONNECTION (data); NMConnection *connection; NMSettingConnection *s_con; NMVPNConnectionState state; const char *banner; if (!NM_IS_VPN_CONNECTION (active)) return; connection = get_connection_for_active (active); g_return_if_fail (connection != NULL); s_con = (NMSettingConnection *) nm_connection_get_setting (connection, NM_TYPE_SETTING_CONNECTION); g_return_if_fail (s_con != NULL); print_header ("VPN", NULL, nm_setting_connection_get_id (s_con)); state = nm_vpn_connection_get_vpn_state (NM_VPN_CONNECTION (active)); print_string ("State", get_vpn_state_string (state)); if (nm_active_connection_get_default (active)) print_string ("Default", "yes"); else print_string ("Default", "no"); banner = nm_vpn_connection_get_banner (NM_VPN_CONNECTION (active)); if (banner) { char **lines, **iter; printf ("\n Message:\n"); lines = g_strsplit_set (banner, "\n\r", -1); for (iter = lines; *iter; iter++) { if (*iter && strlen (*iter)) printf (" %s\n", *iter); } g_strfreev (lines); } printf ("\n\n"); }
static void device_state_changed (NMDevice *device, NMDeviceState new_state, NMDeviceState old_state, NMDeviceStateReason reason, gpointer user_data) { NMActiveConnection *self = NM_ACTIVE_CONNECTION (user_data); NMActiveConnectionPrivate *priv = NM_ACTIVE_CONNECTION_GET_PRIVATE (self); /* When already deactivated or before activation, device state changes are useless */ if (priv->state >= NM_ACTIVE_CONNECTION_STATE_DEACTIVATED) return; if (old_state < NM_DEVICE_STATE_DISCONNECTED) return; /* Let subclasses handle the state change */ if (NM_ACTIVE_CONNECTION_GET_CLASS (self)->device_state_changed) NM_ACTIVE_CONNECTION_GET_CLASS (self)->device_state_changed (self, device, new_state, old_state); }
static void activate_ac_state_changed (GObject *object, GParamSpec *pspec, gpointer user_data) { NmtSyncOp *op = user_data; NMActiveConnectionState state; GError *error = NULL; state = nm_active_connection_get_state (NM_ACTIVE_CONNECTION (object)); if (state == NM_ACTIVE_CONNECTION_STATE_ACTIVATING) return; if (state != NM_ACTIVE_CONNECTION_STATE_ACTIVATED) { error = g_error_new_literal (NM_CLIENT_ERROR, NM_CLIENT_ERROR_FAILED, _("Activation failed")); } nmt_sync_op_complete_boolean (op, error == NULL, error); g_clear_error (&error); }
static void get_devices (NAApplication *application) { int i; NMClient *nm_client = nm_client_new (); const GPtrArray *nm_connections = nm_client_get_active_connections (nm_client); for (i = 0; i < nm_connections->len; i++) { NMActiveConnection *active_conn = NM_ACTIVE_CONNECTION (g_ptr_array_index (nm_connections, i)); g_debug ("Active connection: %s", nm_active_connection_get_connection (active_conn)); } const GPtrArray *nm_devices = nm_client_get_devices (nm_client); for (i = 0; i < nm_devices->len; i++) { NMDevice *nm_device = NM_DEVICE (g_ptr_array_index (nm_devices, i)); if (nm_device_get_state (nm_device) == NM_DEVICE_STATE_ACTIVATED) { const char *iface = nm_device_get_iface (nm_device); const char *ip_iface = nm_device_get_ip_iface (nm_device); g_debug ("Active device found: %s with ip iface %s", iface, ip_iface); NMIP4Config *ip4_config = nm_device_get_ip4_config (nm_device); if (ip4_config != NULL) { const GSList *ip4_addresses = nm_ip4_config_get_addresses (ip4_config); const GSList *iter = ip4_addresses; while (iter != NULL) { guint32 address = nm_ip4_address_get_address ((NMIP4Address *)iter->data); struct in_addr addr = { address, }; char *str_addr = g_new (char, INET_ADDRSTRLEN); inet_ntop (AF_INET, &addr, str_addr, INET_ADDRSTRLEN); add_local_address (str_addr); g_debug ("Adding local IP4 address %s", str_addr); iter = iter->next; } } NMIP6Config *ip6_config = nm_device_get_ip6_config (nm_device); if (ip6_config != NULL) { const GSList *ip6_addresses = nm_ip6_config_get_addresses (ip6_config); const GSList *iter = ip6_addresses; while (iter != NULL) { const struct in6_addr *address = nm_ip6_address_get_address ((NMIP6Address *)iter->data); char *str_addr = g_new (char, INET6_ADDRSTRLEN); inet_ntop (AF_INET6, address, str_addr, INET6_ADDRSTRLEN); add_local_address (str_addr); g_debug ("Adding local IP6 address %s", str_addr); iter = iter->next; } } GError *error = NULL; NAPCapHandle *handle = na_pcap_open (iface, &error); if (handle != NULL) { application->priv->iface_handles = g_slist_append (application->priv->iface_handles, handle); } else { g_debug ("Error opening handler for interface %s: %s\n", iface, error->message); g_error_free (error); } } } }
static void device_state_changed (NMActiveConnection *active, NMDevice *device, NMDeviceState new_state, NMDeviceState old_state) { NMActiveConnectionState cur_ac_state = nm_active_connection_get_state (active); NMActiveConnectionState ac_state = NM_ACTIVE_CONNECTION_STATE_UNKNOWN; /* Decide which device state changes to handle when this active connection * is not the device's current request. Two cases here: (a) the AC is * pending and not yet active, and (b) the AC was active but the device is * entering DISCONNECTED state (which clears the device's current AC before * emitting the state change signal). */ if (NM_ACTIVE_CONNECTION (nm_device_get_act_request (device)) != active) { /* Some other request is activating; this one must be pending */ if (new_state >= NM_DEVICE_STATE_PREPARE) return; else if (new_state == NM_DEVICE_STATE_DISCONNECTED) { /* This request hasn't started activating yet; the device is * disconnecting and cleaning up a previous activation request. */ if (cur_ac_state < NM_ACTIVE_CONNECTION_STATE_ACTIVATING) return; /* Catch device disconnections after this request has been active */ } /* All states < DISCONNECTED are fatal and handled */ } /* Set NMActiveConnection state based on the device's state */ switch (new_state) { case NM_DEVICE_STATE_PREPARE: case NM_DEVICE_STATE_CONFIG: case NM_DEVICE_STATE_NEED_AUTH: case NM_DEVICE_STATE_IP_CONFIG: case NM_DEVICE_STATE_IP_CHECK: case NM_DEVICE_STATE_SECONDARIES: ac_state = NM_ACTIVE_CONNECTION_STATE_ACTIVATING; break; case NM_DEVICE_STATE_ACTIVATED: ac_state = NM_ACTIVE_CONNECTION_STATE_ACTIVATED; g_signal_connect (device, "notify::" NM_DEVICE_IP4_CONFIG, G_CALLBACK (device_notify), active); g_signal_connect (device, "notify::" NM_DEVICE_DHCP4_CONFIG, G_CALLBACK (device_notify), active); g_signal_connect (device, "notify::" NM_DEVICE_IP6_CONFIG, G_CALLBACK (device_notify), active); g_signal_connect (device, "notify::" NM_DEVICE_DHCP6_CONFIG, G_CALLBACK (device_notify), active); break; case NM_DEVICE_STATE_DEACTIVATING: ac_state = NM_ACTIVE_CONNECTION_STATE_DEACTIVATING; break; case NM_DEVICE_STATE_FAILED: case NM_DEVICE_STATE_DISCONNECTED: case NM_DEVICE_STATE_UNMANAGED: case NM_DEVICE_STATE_UNAVAILABLE: ac_state = NM_ACTIVE_CONNECTION_STATE_DEACTIVATED; g_signal_handlers_disconnect_by_func (device, G_CALLBACK (device_notify), active); break; default: break; } if ( ac_state == NM_ACTIVE_CONNECTION_STATE_DEACTIVATED || ac_state == NM_ACTIVE_CONNECTION_STATE_UNKNOWN) { nm_active_connection_set_default (active, FALSE); nm_active_connection_set_default6 (active, FALSE); } nm_active_connection_set_state (active, ac_state); }