Commit 3ce6cbb4 authored by Thomas Haller's avatar Thomas Haller

core/dispatcher: pass act-request to device dispatcher calls

Currently, we determine NMD_CONNECTION_PROPS_EXTERNAL based
on the settings connection. That is not optimal, because whether
a connection is assumed or externally managed, should be really a
property of the active-connection. So, in the this will change soon
and we would need yet another argument to nm_dispatcher_call().

Instead, drop the settings-connection and applied-connection
arguments and fetch them from the device as needed (but allow
to pass a specific act-request argument to explicitly state
which active connection to use).

Also, rename nm_dispatcher_call() to nm_dispatcher_call_device(),
it this is not a generic dispatcher call, but it is particularly
related to device events. Likewise, rename nm_dispatcher_call_sync()
to nm_dispatcher_call_device_sync().
parent 8987de7c
......@@ -1535,7 +1535,7 @@ nm_device_has_carrier (NMDevice *self)
NMActRequest *
nm_device_get_act_request (NMDevice *self)
{
g_return_val_if_fail (self != NULL, NULL);
g_return_val_if_fail (NM_IS_DEVICE (self), NULL);
return NM_DEVICE_GET_PRIVATE (self)->act_request;
}
......@@ -5237,14 +5237,10 @@ dhcp4_lease_change (NMDevice *self, NMIP4Config *config)
return FALSE;
}
/* Notify dispatcher scripts of new DHCP4 config */
nm_dispatcher_call (NM_DISPATCHER_ACTION_DHCP4_CHANGE,
nm_device_get_settings_connection (self),
nm_device_get_applied_connection (self),
self,
NULL,
NULL,
NULL);
nm_dispatcher_call_device (NM_DISPATCHER_ACTION_DHCP4_CHANGE,
self,
NULL,
NULL, NULL, NULL);
nm_device_remove_pending_action (self, NM_PENDING_ACTION_DHCP4, FALSE);
......@@ -6005,11 +6001,10 @@ dhcp6_lease_change (NMDevice *self)
return FALSE;
}
/* Notify dispatcher scripts of new DHCPv6 config */
nm_dispatcher_call (NM_DISPATCHER_ACTION_DHCP6_CHANGE,
settings_connection,
nm_device_get_applied_connection (self),
self, NULL, NULL, NULL);
nm_dispatcher_call_device (NM_DISPATCHER_ACTION_DHCP6_CHANGE,
self,
NULL,
NULL, NULL, NULL);
nm_device_remove_pending_action (self, NM_PENDING_ACTION_DHCP6, FALSE);
......@@ -7946,14 +7941,10 @@ activate_stage5_ip4_config_commit (NMDevice *self)
if ( priv->dhcp4.client
&& nm_device_activate_ip4_state_in_conf (self)
&& (nm_device_get_state (self) > NM_DEVICE_STATE_IP_CONFIG)) {
/* Notify dispatcher scripts of new DHCP4 config */
nm_dispatcher_call (NM_DISPATCHER_ACTION_DHCP4_CHANGE,
nm_device_get_settings_connection (self),
nm_device_get_applied_connection (self),
self,
NULL,
NULL,
NULL);
nm_dispatcher_call_device (NM_DISPATCHER_ACTION_DHCP4_CHANGE,
self,
NULL,
NULL, NULL, NULL);
}
arp_announce (self);
......@@ -8082,13 +8073,10 @@ activate_stage5_ip6_config_commit (NMDevice *self)
/* If IPv6 wasn't the first IP to complete, and DHCP was used,
* then ensure dispatcher scripts get the DHCP lease information.
*/
nm_dispatcher_call (NM_DISPATCHER_ACTION_DHCP6_CHANGE,
nm_device_get_settings_connection (self),
nm_device_get_applied_connection (self),
self,
NULL,
NULL,
NULL);
nm_dispatcher_call_device (NM_DISPATCHER_ACTION_DHCP6_CHANGE,
self,
NULL,
NULL, NULL, NULL);
} else {
/* still waiting for first dhcp6 lease. */
return;
......@@ -9617,13 +9605,12 @@ ip_check_pre_up (NMDevice *self)
priv->dispatcher.post_state = NM_DEVICE_STATE_SECONDARIES;
priv->dispatcher.post_state_reason = NM_DEVICE_STATE_REASON_NONE;
if (!nm_dispatcher_call (NM_DISPATCHER_ACTION_PRE_UP,
nm_device_get_settings_connection (self),
nm_device_get_applied_connection (self),
self,
dispatcher_complete_proceed_state,
self,
&priv->dispatcher.call_id)) {
if (!nm_dispatcher_call_device (NM_DISPATCHER_ACTION_PRE_UP,
self,
NULL,
dispatcher_complete_proceed_state,
self,
&priv->dispatcher.call_id)) {
/* Just proceed on errors */
dispatcher_complete_proceed_state (0, self);
}
......@@ -12139,20 +12126,17 @@ _set_state_full (NMDevice *self,
priv->ignore_carrier = nm_config_data_get_ignore_carrier (NM_CONFIG_GET_DATA, self);
if (quitting) {
nm_dispatcher_call_sync (NM_DISPATCHER_ACTION_PRE_DOWN,
nm_act_request_get_settings_connection (req),
nm_act_request_get_applied_connection (req),
self);
nm_dispatcher_call_device_sync (NM_DISPATCHER_ACTION_PRE_DOWN,
self, req);
} else {
priv->dispatcher.post_state = NM_DEVICE_STATE_DISCONNECTED;
priv->dispatcher.post_state_reason = reason;
if (!nm_dispatcher_call (NM_DISPATCHER_ACTION_PRE_DOWN,
nm_act_request_get_settings_connection (req),
nm_act_request_get_applied_connection (req),
self,
deactivate_dispatcher_complete,
self,
&priv->dispatcher.call_id)) {
if (!nm_dispatcher_call_device (NM_DISPATCHER_ACTION_PRE_DOWN,
self,
req,
deactivate_dispatcher_complete,
self,
&priv->dispatcher.call_id)) {
/* Just proceed on errors */
deactivate_dispatcher_complete (0, self);
}
......@@ -12179,10 +12163,10 @@ _set_state_full (NMDevice *self,
case NM_DEVICE_STATE_ACTIVATED:
_LOGI (LOGD_DEVICE, "Activation: successful, device activated.");
nm_device_update_metered (self);
nm_dispatcher_call (NM_DISPATCHER_ACTION_UP,
nm_act_request_get_settings_connection (req),
nm_act_request_get_applied_connection (req),
self, NULL, NULL, NULL);
nm_dispatcher_call_device (NM_DISPATCHER_ACTION_UP,
self,
req,
NULL, NULL, NULL);
if (priv->proxy_config) {
nm_pacrunner_manager_send (priv->pacrunner_manager,
......@@ -12274,15 +12258,13 @@ _set_state_full (NMDevice *self,
if ( (old_state == NM_DEVICE_STATE_ACTIVATED || old_state == NM_DEVICE_STATE_DEACTIVATING)
&& (state != NM_DEVICE_STATE_DEACTIVATING)) {
if (quitting) {
nm_dispatcher_call_sync (NM_DISPATCHER_ACTION_DOWN,
nm_act_request_get_settings_connection (req),
nm_act_request_get_applied_connection (req),
self);
nm_dispatcher_call_device_sync (NM_DISPATCHER_ACTION_DOWN,
self, req);
} else {
nm_dispatcher_call (NM_DISPATCHER_ACTION_DOWN,
nm_act_request_get_settings_connection (req),
nm_act_request_get_applied_connection (req),
self, NULL, NULL, NULL);
nm_dispatcher_call_device (NM_DISPATCHER_ACTION_DOWN,
self,
req,
NULL, NULL, NULL);
}
}
......
......@@ -21,14 +21,16 @@
#include "nm-default.h"
#include "nm-dispatcher.h"
#include <string.h>
#include <errno.h>
#include "nm-dispatcher.h"
#include "nm-dispatcher-api.h"
#include "NetworkManagerUtils.h"
#include "nm-utils.h"
#include "nm-connectivity.h"
#include "nm-act-request.h"
#include "devices/nm-device.h"
#include "nm-dhcp4-config.h"
#include "nm-dhcp6-config.h"
......@@ -715,41 +717,50 @@ nm_dispatcher_call_hostname (NMDispatcherFunc callback,
}
/**
* nm_dispatcher_call:
* nm_dispatcher_call_device:
* @action: the %NMDispatcherAction
* @settings_connection: the #NMSettingsConnection the action applies to
* @applied_connection: the currently applied connection
* @device: the #NMDevice the action applies to
* @act_request: the #NMActRequest for the action. If %NULL, use the
* current request of the device.
* @callback: a caller-supplied callback to execute when done
* @user_data: caller-supplied pointer passed to @callback
* @out_call_id: on success, a call identifier which can be passed to
* nm_dispatcher_call_cancel()
*
* This method always invokes the dispatcher action asynchronously. To ignore
* This method always invokes the device dispatcher action asynchronously. To ignore
* the result, pass %NULL to @callback.
*
* Returns: %TRUE if the action was dispatched, %FALSE on failure
*/
gboolean
nm_dispatcher_call (NMDispatcherAction action,
NMSettingsConnection *settings_connection,
NMConnection *applied_connection,
NMDevice *device,
NMDispatcherFunc callback,
gpointer user_data,
guint *out_call_id)
nm_dispatcher_call_device (NMDispatcherAction action,
NMDevice *device,
NMActRequest *act_request,
NMDispatcherFunc callback,
gpointer user_data,
guint *out_call_id)
{
return _dispatcher_call (action, FALSE, settings_connection, applied_connection, device,
nm_assert (NM_IS_DEVICE (device));
if (!act_request) {
act_request = nm_device_get_act_request (device);
if (!act_request)
return FALSE;
}
nm_assert (NM_IN_SET (nm_active_connection_get_device (NM_ACTIVE_CONNECTION (act_request)), NULL, device));
return _dispatcher_call (action, FALSE,
nm_act_request_get_settings_connection (act_request),
nm_act_request_get_applied_connection (act_request),
device,
NM_CONNECTIVITY_UNKNOWN, NULL, NULL, NULL, NULL,
callback, user_data, out_call_id);
}
/**
* nm_dispatcher_call_sync():
* nm_dispatcher_call_device_sync():
* @action: the %NMDispatcherAction
* @settings_connection: the #NMSettingsConnection the action applies to
* @applied_connection: the currently applied connection
* @device: the #NMDevice the action applies to
* @act_request: the #NMActRequest for the action. If %NULL, use the
* current request of the device.
*
* This method always invokes the dispatcher action synchronously and it may
* take a long time to return.
......@@ -757,13 +768,23 @@ nm_dispatcher_call (NMDispatcherAction action,
* Returns: %TRUE if the action was dispatched, %FALSE on failure
*/
gboolean
nm_dispatcher_call_sync (NMDispatcherAction action,
NMSettingsConnection *settings_connection,
NMConnection *applied_connection,
NMDevice *device)
nm_dispatcher_call_device_sync (NMDispatcherAction action,
NMDevice *device,
NMActRequest *act_request)
{
return _dispatcher_call (action, TRUE, settings_connection, applied_connection, device,
NM_CONNECTIVITY_UNKNOWN, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
nm_assert (NM_IS_DEVICE (device));
if (!act_request) {
act_request = nm_device_get_act_request (device);
if (!act_request)
return FALSE;
}
nm_assert (NM_IN_SET (nm_active_connection_get_device (NM_ACTIVE_CONNECTION (act_request)), NULL, device));
return _dispatcher_call (action, TRUE,
nm_act_request_get_settings_connection (act_request),
nm_act_request_get_applied_connection (act_request),
device,
NM_CONNECTIVITY_UNKNOWN, NULL, NULL, NULL, NULL,
NULL, NULL, NULL);
}
/**
......
......@@ -45,18 +45,16 @@ gboolean nm_dispatcher_call_hostname (NMDispatcherFunc callback,
gpointer user_data,
guint *out_call_id);
gboolean nm_dispatcher_call (NMDispatcherAction action,
NMSettingsConnection *settings_connection,
NMConnection *applied_connection,
NMDevice *device,
NMDispatcherFunc callback,
gpointer user_data,
guint *out_call_id);
gboolean nm_dispatcher_call_device (NMDispatcherAction action,
NMDevice *device,
NMActRequest *act_request,
NMDispatcherFunc callback,
gpointer user_data,
guint *out_call_id);
gboolean nm_dispatcher_call_sync (NMDispatcherAction action,
NMSettingsConnection *settings_connection,
NMConnection *applied_connection,
NMDevice *device);
gboolean nm_dispatcher_call_device_sync (NMDispatcherAction action,
NMDevice *device,
NMActRequest *act_request);
gboolean nm_dispatcher_call_vpn (NMDispatcherAction action,
NMSettingsConnection *settings_connection,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment