diff options
author | Thomas Haller <thaller@redhat.com> | 2015-10-06 17:26:27 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2015-10-07 18:22:57 +0200 |
commit | 061028961a31e048aa7cf0d43ef071f52f7b2441 (patch) | |
tree | 33d4161bd0e995f7257891fa30468b6fb88176fc | |
parent | b343956d40fb53d3b4ff7002f8c84ff039dfff50 (diff) | |
download | NetworkManager-061028961a31e048aa7cf0d43ef071f52f7b2441.tar.gz |
device: refactor setting firewall zone during activation-stage2
schedule_stage3() used to set the firewall before really
scheduling the stage3. In that case, fw_change_zone_cb() would
then directly call:
activation_source_schedule (self, activate_stage3_ip_config_start, AF_INET);
This was different from all other places. Usually, only the
nm_device_schedule_*() functions would directly call to
activation_source_schedule().
Change this, to behave similar as when we wait for master-ready
while scheduling stage2. As such, it is more idiomatic, and
it would still work correctly even if there were multiple conditions
that would block scheduling-stage3.
-rw-r--r-- | src/devices/nm-device.c | 91 |
1 files changed, 59 insertions, 32 deletions
diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c index cd921b16e8..4c7d917418 100644 --- a/src/devices/nm-device.c +++ b/src/devices/nm-device.c @@ -297,6 +297,7 @@ typedef struct { gulong dnsmasq_state_id; /* Firewall */ + gboolean fw_ready; NMFirewallManagerCallId fw_call; /* IPv4LL stuff */ @@ -5581,34 +5582,56 @@ activate_stage3_ip_config_start (NMDevice *self) nm_device_check_ip_failed (self, TRUE); } +static gboolean +fw_change_zone_handle (NMDevice *self, + NMFirewallManagerCallId call_id, + GError *error) +{ + NMDevicePrivate *priv; + + g_return_val_if_fail (NM_IS_DEVICE (self), FALSE); + + priv = NM_DEVICE_GET_PRIVATE (self); + + g_return_val_if_fail (priv->fw_call == call_id, FALSE); + priv->fw_call = NULL; + + return !nm_utils_error_is_cancelled (error, FALSE); +} static void -fw_change_zone_cb (NMFirewallManager *firewall_manager, - NMFirewallManagerCallId call_id, - GError *error, - gpointer user_data) +fw_change_zone_cb_stage2 (NMFirewallManager *firewall_manager, + NMFirewallManagerCallId call_id, + GError *error, + gpointer user_data) { NMDevice *self = user_data; NMDevicePrivate *priv; - g_return_if_fail (NM_IS_DEVICE (self)); + if (!fw_change_zone_handle (self, call_id, error)) + return; + + /* FIXME: fail the device on error? */ priv = NM_DEVICE_GET_PRIVATE (self); + priv->fw_ready = TRUE; - g_return_if_fail (priv->fw_call == call_id); - priv->fw_call = NULL; + nm_device_activate_schedule_stage3_ip_config_start (self); +} - if (nm_utils_error_is_cancelled (error, FALSE)) - return; +static void +fw_change_zone_cb_ip_check (NMFirewallManager *firewall_manager, + NMFirewallManagerCallId call_id, + GError *error, + gpointer user_data) +{ + NMDevice *self = user_data; - if (error) { - /* FIXME: fail the device activation? */ - } + if (!fw_change_zone_handle (self, call_id, error)) + return; - if (priv->state == NM_DEVICE_STATE_IP_CHECK) - nm_device_start_ip_check (self); - else - activation_source_schedule (self, activate_stage3_ip_config_start, AF_INET); + /* FIXME: fail the device on error? */ + nm_device_start_ip_check (self); } /* @@ -5629,28 +5652,31 @@ nm_device_activate_schedule_stage3_ip_config_start (NMDevice *self) priv = NM_DEVICE_GET_PRIVATE (self); g_return_if_fail (priv->act_request); - g_return_if_fail (!priv->fw_call); - /* Add the interface to the specified firewall zone */ connection = nm_device_get_applied_connection (self); g_assert (connection); s_con = nm_connection_get_setting_connection (connection); - zone = nm_setting_connection_get_zone (s_con); - - if (nm_device_uses_assumed_connection (self)) { - _LOGD (LOGD_DEVICE, "Activation: skip setting firewall zone '%s' for assumed device", zone ? zone : "default"); - activation_source_schedule (self, activate_stage3_ip_config_start, AF_INET); - return; + if (!priv->fw_ready) { + if (nm_device_uses_assumed_connection (self)) + priv->fw_ready = TRUE; + else { + if (!priv->fw_call) { + zone = nm_setting_connection_get_zone (s_con); + + _LOGD (LOGD_DEVICE, "Activation: setting firewall zone '%s'", zone ? zone : "default"); + priv->fw_call = nm_firewall_manager_add_or_change_zone (nm_firewall_manager_get (), + nm_device_get_ip_iface (self), + zone, + FALSE, + fw_change_zone_cb_stage2, + self); + } + return; + } } - _LOGD (LOGD_DEVICE, "Activation: setting firewall zone '%s'", zone ? zone : "default"); - priv->fw_call = nm_firewall_manager_add_or_change_zone (nm_firewall_manager_get (), - nm_device_get_ip_iface (self), - zone, - FALSE, - fw_change_zone_cb, - self); + activation_source_schedule (self, activate_stage3_ip_config_start, AF_INET); } static NMActStageReturn @@ -8360,6 +8386,7 @@ _cancel_activation (NMDevice *self) g_warn_if_fail (!priv->fw_call); priv->fw_call = NULL; } + priv->fw_ready = FALSE; ip_check_gw_ping_cleanup (self); @@ -9049,7 +9076,7 @@ _set_state_full (NMDevice *self, nm_device_get_ip_iface (self), zone, FALSE, - fw_change_zone_cb, + fw_change_zone_cb_ip_check, self); } else nm_device_start_ip_check (self); |