From 116501dbccf7139f942c77e71c4afb5f6d1af6a8 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 28 Apr 2014 11:18:05 +0200 Subject: [PATCH 1/2] core: add parameter to ignore error in add/remove pending action Add a parameter to nm_device_add_pending_action() to silently accept adding duplicate actions. Same for nm_device_remove_pending_action(), to silently ignore removing non-pending actions. Signed-off-by: Thomas Haller (cherry picked from commit a16faa3985042dadb34600cb0df2eefc61360340) --- src/devices/nm-device-olpc-mesh.c | 4 +- src/devices/nm-device-wifi.c | 8 ++-- src/devices/nm-device.c | 89 ++++++++++++++++++++++++++------------- src/devices/nm-device.h | 4 +- src/nm-active-connection.c | 8 ++-- src/nm-policy.c | 4 +- 6 files changed, 74 insertions(+), 43 deletions(-) diff --git a/src/devices/nm-device-olpc-mesh.c b/src/devices/nm-device-olpc-mesh.c index b85956e..52ba79a 100644 --- a/src/devices/nm-device-olpc-mesh.c +++ b/src/devices/nm-device-olpc-mesh.c @@ -627,7 +627,7 @@ check_companion_cb (gpointer user_data) } done: - nm_device_remove_pending_action (NM_DEVICE (self), "waiting for companion"); + nm_device_remove_pending_action (NM_DEVICE (self), "waiting for companion", TRUE); return FALSE; } @@ -645,7 +645,7 @@ state_changed (NMDevice *device, NMDeviceState new_state, * transition to DISCONNECTED otherwise wait for our companion. */ g_idle_add (check_companion_cb, self); - nm_device_add_pending_action (device, "waiting for companion"); + nm_device_add_pending_action (device, "waiting for companion", TRUE); break; case NM_DEVICE_STATE_ACTIVATED: break; diff --git a/src/devices/nm-device-wifi.c b/src/devices/nm-device-wifi.c index d539877..4b231ca 100644 --- a/src/devices/nm-device-wifi.c +++ b/src/devices/nm-device-wifi.c @@ -360,7 +360,7 @@ supplicant_interface_acquire (NMDeviceWifi *self) } if (nm_supplicant_interface_get_state (priv->supplicant.iface) < NM_SUPPLICANT_INTERFACE_STATE_READY) - nm_device_add_pending_action (NM_DEVICE (self), "waiting for supplicant"); + nm_device_add_pending_action (NM_DEVICE (self), "waiting for supplicant", TRUE); g_signal_connect (priv->supplicant.iface, NM_SUPPLICANT_INTERFACE_STATE, @@ -1722,7 +1722,7 @@ request_wireless_scan (gpointer user_data) /* success */ backoff = TRUE; priv->requested_scan = TRUE; - nm_device_add_pending_action (NM_DEVICE (self), "scan"); + nm_device_add_pending_action (NM_DEVICE (self), "scan", TRUE); } if (ssids) { @@ -1823,7 +1823,7 @@ supplicant_iface_scan_done_cb (NMSupplicantInterface *iface, if (priv->requested_scan) { priv->requested_scan = FALSE; - nm_device_remove_pending_action (NM_DEVICE (self), "scan"); + nm_device_remove_pending_action (NM_DEVICE (self), "scan", TRUE); } } @@ -2364,7 +2364,7 @@ supplicant_iface_state_cb (NMSupplicantInterface *iface, request_wireless_scan (self); if (old_state < NM_SUPPLICANT_INTERFACE_STATE_READY) - nm_device_remove_pending_action (device, "waiting for supplicant"); + nm_device_remove_pending_action (device, "waiting for supplicant", TRUE); break; case NM_SUPPLICANT_INTERFACE_STATE_COMPLETED: remove_supplicant_interface_error_handler (self); diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c index f16c4d4..b6e7ef2 100644 --- a/src/devices/nm-device.c +++ b/src/devices/nm-device.c @@ -1123,7 +1123,7 @@ nm_device_set_carrier (NMDevice *device, gboolean carrier) if (priv->carrier_wait_id) { g_source_remove (priv->carrier_wait_id); priv->carrier_wait_id = 0; - nm_device_remove_pending_action (device, "carrier wait"); + nm_device_remove_pending_action (device, "carrier wait", TRUE); } } else if (state <= NM_DEVICE_STATE_DISCONNECTED) { nm_log_info (LOGD_DEVICE, "(%s): link disconnected", iface); @@ -5539,7 +5539,7 @@ carrier_wait_timeout (gpointer user_data) NMDevice *self = NM_DEVICE (user_data); NM_DEVICE_GET_PRIVATE (self)->carrier_wait_id = 0; - nm_device_remove_pending_action (self, "carrier wait"); + nm_device_remove_pending_action (self, "carrier wait", TRUE); return G_SOURCE_REMOVE; } @@ -5587,10 +5587,10 @@ nm_device_bring_up (NMDevice *self, gboolean block, gboolean *no_firmware) if (device_has_capability (self, NM_DEVICE_CAP_CARRIER_DETECT)) { if (priv->carrier_wait_id) { g_source_remove (priv->carrier_wait_id); - nm_device_remove_pending_action (self, "carrier wait"); + nm_device_remove_pending_action (self, "carrier wait", TRUE); } priv->carrier_wait_id = g_timeout_add_seconds (5, carrier_wait_timeout, self); - nm_device_add_pending_action (self, "carrier wait"); + nm_device_add_pending_action (self, "carrier wait", TRUE); } /* Can only get HW address of some devices when they are up */ @@ -6852,7 +6852,7 @@ queued_set_state (gpointer user_data) nm_device_queued_state_clear (self); nm_device_state_changed (self, new_state, new_reason); - nm_device_remove_pending_action (self, queued_state_to_string (new_state)); + nm_device_remove_pending_action (self, queued_state_to_string (new_state), TRUE); } else { g_warn_if_fail (priv->queued_state.state == NM_DEVICE_STATE_UNKNOWN); g_warn_if_fail (priv->queued_state.reason == NM_DEVICE_STATE_REASON_NONE); @@ -6876,7 +6876,7 @@ nm_device_queue_state (NMDevice *self, /* Add pending action for the new state before clearing the queued states, so * that we don't accidently pop all pending states and reach 'startup complete' */ - nm_device_add_pending_action (self, queued_state_to_string (state)); + nm_device_add_pending_action (self, queued_state_to_string (state), TRUE); /* We should only ever have one delayed state transition at a time */ if (priv->queued_state.id) { @@ -6917,7 +6917,7 @@ nm_device_queued_state_clear (NMDevice *self) nm_log_dbg (LOGD_DEVICE, "(%s): clearing queued state transition (id %d)", nm_device_get_iface (self), priv->queued_state.id); g_source_remove (priv->queued_state.id); - nm_device_remove_pending_action (self, queued_state_to_string (priv->queued_state.state)); + nm_device_remove_pending_action (self, queued_state_to_string (priv->queued_state.state), TRUE); } memset (&priv->queued_state, 0, sizeof (priv->queued_state)); } @@ -7651,31 +7651,46 @@ nm_device_set_hw_addr (NMDevice *device, const guint8 *addr, * nm_device_add_pending_action(): * @device: the #NMDevice to add the pending action to * @action: a static string that identifies the action + * @assert_not_yet_pending: if %TRUE, assert that the @action is currently not yet pending. + * Otherwise, ignore duplicate scheduling of the same action silently. * * Adds a pending action to the device. + * + * Returns: %TRUE if the action was added (and not already added before). %FALSE + * if the same action is already scheduled. In the latter case, the action was not scheduled + * a second time. */ -void -nm_device_add_pending_action (NMDevice *device, const char *action) +gboolean +nm_device_add_pending_action (NMDevice *device, const char *action, gboolean assert_not_yet_pending) { NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (device); GSList *iter; - guint count; + guint count = 0; - g_return_if_fail (action); + g_return_val_if_fail (action, FALSE); - /* Shouldn't ever add the same pending action twice */ + /* Check if the action is already pending. Cannot add duplicate actions */ for (iter = priv->pending_actions; iter; iter = iter->next) { if (!strcmp (action, iter->data)) { - nm_log_warn (LOGD_DEVICE, "(%s): add_pending_action (%d): '%s' already added", - nm_device_get_iface (device), - g_slist_length (priv->pending_actions), - action); - g_return_if_reached (); + if (assert_not_yet_pending) { + nm_log_warn (LOGD_DEVICE, "(%s): add_pending_action (%d): '%s' already pending", + nm_device_get_iface (device), + count + g_slist_length (iter), + action); + g_return_val_if_reached (FALSE); + } else { + nm_log_dbg (LOGD_DEVICE, "(%s): add_pending_action (%d): '%s' already pending (expected)", + nm_device_get_iface (device), + count + g_slist_length (iter), + action); + } + return FALSE; } + count++; } priv->pending_actions = g_slist_append (priv->pending_actions, g_strdup (action)); - count = g_slist_length (priv->pending_actions); + count++; nm_log_dbg (LOGD_DEVICE, "(%s): add_pending_action (%d): '%s'", nm_device_get_iface (device), @@ -7684,44 +7699,60 @@ nm_device_add_pending_action (NMDevice *device, const char *action) if (count == 1) g_object_notify (G_OBJECT (device), NM_DEVICE_HAS_PENDING_ACTION); + + return TRUE; } /** * nm_device_remove_pending_action(): * @device: the #NMDevice to remove the pending action from * @action: a static string that identifies the action + * @assert_is_pending: if %TRUE, assert that the @action is pending. + * If %FALSE, don't do anything if the current action is not pending and + * return %FALSE. * * Removes a pending action previously added by nm_device_add_pending_action(). + * + * Returns: whether the @action was pending and is now removed. */ -void -nm_device_remove_pending_action (NMDevice *device, const char *action) +gboolean +nm_device_remove_pending_action (NMDevice *device, const char *action, gboolean assert_is_pending) { NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (device); GSList *iter; + guint count = 0; - g_return_if_fail (action); + g_return_val_if_fail (action, FALSE); - /* Shouldn't ever add the same pending action twice */ for (iter = priv->pending_actions; iter; iter = iter->next) { if (!strcmp (action, iter->data)) { g_free (iter->data); priv->pending_actions = g_slist_delete_link (priv->pending_actions, iter); nm_log_dbg (LOGD_DEVICE, "(%s): remove_pending_action (%d): '%s'", nm_device_get_iface (device), - g_slist_length (priv->pending_actions), + count + g_slist_length (iter), action); if (priv->pending_actions == NULL) g_object_notify (G_OBJECT (device), NM_DEVICE_HAS_PENDING_ACTION); - return; + return TRUE; } + count++; } - nm_log_warn (LOGD_DEVICE, "(%s): remove_pending_action (%d): '%s' never added", - nm_device_get_iface (device), - g_slist_length (priv->pending_actions), - action); - g_return_if_reached (); + if (assert_is_pending) { + nm_log_warn (LOGD_DEVICE, "(%s): remove_pending_action (%d): '%s' not pending", + nm_device_get_iface (device), + count, + action); + g_return_val_if_reached (FALSE); + } else { + nm_log_dbg (LOGD_DEVICE, "(%s): remove_pending_action (%d): '%s' not pending (expected)", + nm_device_get_iface (device), + count, + action); + } + return FALSE; } gboolean diff --git a/src/devices/nm-device.h b/src/devices/nm-device.h index 47d7856..935a448 100644 --- a/src/devices/nm-device.h +++ b/src/devices/nm-device.h @@ -328,8 +328,8 @@ void nm_device_queue_activation (NMDevice *device, NMActRequest *req); gboolean nm_device_supports_vlans (NMDevice *device); -void nm_device_add_pending_action (NMDevice *device, const char *action); -void nm_device_remove_pending_action (NMDevice *device, const char *action); +gboolean nm_device_add_pending_action (NMDevice *device, const char *action, gboolean assert_not_yet_pending); +gboolean nm_device_remove_pending_action (NMDevice *device, const char *action, gboolean assert_is_pending); gboolean nm_device_has_pending_action (NMDevice *device); GPtrArray *nm_device_get_available_connections (NMDevice *device, diff --git a/src/nm-active-connection.c b/src/nm-active-connection.c index 43f8189..172aa61 100644 --- a/src/nm-active-connection.c +++ b/src/nm-active-connection.c @@ -152,7 +152,7 @@ nm_active_connection_set_state (NMActiveConnection *self, && new_state >= NM_ACTIVE_CONNECTION_STATE_ACTIVATED && priv->pending_activation_id) { - nm_device_remove_pending_action (priv->device, priv->pending_activation_id); + nm_device_remove_pending_action (priv->device, priv->pending_activation_id, TRUE); g_clear_pointer (&priv->pending_activation_id, g_free); } } @@ -399,7 +399,7 @@ nm_active_connection_set_device (NMActiveConnection *self, NMDevice *device) if (!priv->assumed) { priv->pending_activation_id = g_strdup_printf ("activation::%p", (void *)self); - nm_device_add_pending_action (device, priv->pending_activation_id); + nm_device_add_pending_action (device, priv->pending_activation_id, TRUE); } } return TRUE; @@ -540,7 +540,7 @@ nm_active_connection_set_assumed (NMActiveConnection *self, gboolean assumed) priv->assumed = assumed; if (priv->pending_activation_id) { - nm_device_remove_pending_action (priv->device, priv->pending_activation_id); + nm_device_remove_pending_action (priv->device, priv->pending_activation_id, TRUE); g_clear_pointer (&priv->pending_activation_id, g_free); } } @@ -795,7 +795,7 @@ _device_cleanup (NMActiveConnection *self) } if (priv->pending_activation_id) { - nm_device_remove_pending_action (priv->device, priv->pending_activation_id); + nm_device_remove_pending_action (priv->device, priv->pending_activation_id, TRUE); g_clear_pointer (&priv->pending_activation_id, g_free); } diff --git a/src/nm-policy.c b/src/nm-policy.c index f569b75..b412427 100644 --- a/src/nm-policy.c +++ b/src/nm-policy.c @@ -941,7 +941,7 @@ activate_data_free (ActivateData *data) { NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE (data->policy); - nm_device_remove_pending_action (data->device, "autoactivate"); + nm_device_remove_pending_action (data->device, "autoactivate", TRUE); priv->pending_activation_checks = g_slist_remove (priv->pending_activation_checks, data); if (data->autoactivate_id) @@ -1223,7 +1223,7 @@ schedule_activate_check (NMPolicy *policy, NMDevice *device) return; } - nm_device_add_pending_action (device, "autoactivate"); + nm_device_add_pending_action (device, "autoactivate", TRUE); data = g_malloc0 (sizeof (ActivateData)); data->policy = policy; -- 1.9.0 From e20f6c63b0a5f0dfb2851d6f5a098f8bb1f5a1be Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 14 Apr 2014 17:57:56 +0200 Subject: [PATCH 2/2] core: wait with "startup complete" for both IPv4 and IPv6 dynamic configuration In case of DHCP4, DHCP6 and/or SLAAC, delay "startup complete" until both IPv4 and IPv6 are ready. This especially has an effect on nm-online/NetworkManager-wait-online.service, which blocks until configuration of both IPv4 and IPv6 is ready. We queue a pending_action when automatic configuration starts and remove it again, when we receive an address. Before, "startup complete" was reached when either one of the two IP protocols was configured. https://bugzilla.redhat.com/show_bug.cgi?id=1086906 Signed-off-by: Thomas Haller (cherry picked from commit 516d66210fbcc9897f60dc9145a477e91ff8bad5) --- man/nm-online.1.in | 7 ++++++- src/devices/nm-device.c | 28 ++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/man/nm-online.1.in b/man/nm-online.1.in index 941f006..86ed974 100644 --- a/man/nm-online.1.in +++ b/man/nm-online.1.in @@ -35,7 +35,12 @@ is a utility to find out whether we are online. It is done by asking NetworkManager about its status. When run, \fInm\-online\fP waits until NetworkManager reports an active connection, or specified timeout expires. On exit, the returned status code should be checked (see the return codes bellow). - +.P +By default NetworkManager waits for IPv4 dynamic addressing to complete but does +not wait for the "auto" IPv6 dynamic addressing. To wait for IPv6 addressing to +complete, either (1) change the network connection's IPv6 "may-fail" setting to "no", +and/or (2) change the IPv6 addressing method to "manual" or "dhcp", to indicate that +IPv6 connectivity is expected. .SH OPTIONS .TP .B \-t, \-\-timeout diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c index b6e7ef2..8399cf6 100644 --- a/src/devices/nm-device.c +++ b/src/devices/nm-device.c @@ -156,6 +156,10 @@ G_DEFINE_ABSTRACT_TYPE_WITH_CODE (NMDevice, nm_device, G_TYPE_OBJECT, #define NM_DEVICE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DEVICE, NMDevicePrivate)) +#define PENDING_ACTION_DHCP4 "dhcp4" +#define PENDING_ACTION_DHCP6 "dhcp6" +#define PENDING_ACTION_AUTOCONF6 "autoconf6" + typedef enum { IP_NONE = 0, IP_WAIT, @@ -2820,6 +2824,8 @@ dhcp4_start (NMDevice *self, G_CALLBACK (dhcp4_timeout), self); + nm_device_add_pending_action (self, PENDING_ACTION_DHCP4, TRUE); + /* DHCP devices will be notified by the DHCP manager when stuff happens */ return NM_ACT_STAGE_RETURN_POSTPONE; } @@ -3202,6 +3208,7 @@ dhcp6_start (NMDevice *self, guint32 dhcp_opt, NMDeviceStateReason *reason) { + NMSettingIP6Config *s_ip6; NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self); NMActStageReturn ret = NM_ACT_STAGE_RETURN_FAILURE; guint8 *anycast = NULL; @@ -3254,6 +3261,11 @@ dhcp6_start (NMDevice *self, G_CALLBACK (dhcp6_timeout), self); + s_ip6 = nm_connection_get_setting_ip6_config (connection); + if (!nm_setting_ip6_config_get_may_fail (s_ip6) || + !strcmp (nm_setting_ip6_config_get_method (s_ip6), NM_SETTING_IP6_CONFIG_METHOD_DHCP)) + nm_device_add_pending_action (self, PENDING_ACTION_DHCP6, TRUE); + /* DHCP devices will be notified by the DHCP manager when stuff happens */ ret = NM_ACT_STAGE_RETURN_POSTPONE; } else { @@ -3620,6 +3632,9 @@ addrconf6_start (NMDevice *self, NMSettingIP6ConfigPrivacy use_tempaddr) priv->rdisc_use_tempaddr = use_tempaddr; print_support_extended_ifa_flags (use_tempaddr); + if (!nm_setting_ip6_config_get_may_fail (nm_connection_get_setting_ip6_config (connection))) + nm_device_add_pending_action (self, PENDING_ACTION_AUTOCONF6, TRUE); + /* ensure link local is ready... */ ret = linklocal6_start (self); if (ret == NM_ACT_STAGE_RETURN_SUCCESS) @@ -3663,6 +3678,8 @@ addrconf6_cleanup (NMDevice *self) priv->rdisc_config_changed_sigid = 0; } + nm_device_remove_pending_action (self, PENDING_ACTION_AUTOCONF6, FALSE); + g_clear_object (&priv->ac_ip6_config); g_clear_object (&priv->rdisc); } @@ -4509,6 +4526,9 @@ nm_device_activate_ip4_config_commit (gpointer user_data) /* Enter the IP_CHECK state if this is the first method to complete */ priv->ip4_state = IP_DONE; + + nm_device_remove_pending_action (self, PENDING_ACTION_DHCP4, FALSE); + if (nm_device_get_state (self) == NM_DEVICE_STATE_IP_CONFIG) nm_device_state_changed (self, NM_DEVICE_STATE_IP_CHECK, NM_DEVICE_STATE_REASON_NONE); @@ -4598,6 +4618,10 @@ nm_device_activate_ip6_config_commit (gpointer user_data) /* Enter the IP_CHECK state if this is the first method to complete */ priv->ip6_state = IP_DONE; + + nm_device_remove_pending_action (self, PENDING_ACTION_DHCP6, FALSE); + nm_device_remove_pending_action (self, PENDING_ACTION_AUTOCONF6, FALSE); + if (nm_device_get_state (self) == NM_DEVICE_STATE_IP_CONFIG) nm_device_state_changed (self, NM_DEVICE_STATE_IP_CHECK, NM_DEVICE_STATE_REASON_NONE); } else { @@ -4683,6 +4707,8 @@ dhcp4_cleanup (NMDevice *self, gboolean stop, gboolean release) priv->dhcp4_timeout_sigid = 0; } + nm_device_remove_pending_action (self, PENDING_ACTION_DHCP4, FALSE); + if (stop) nm_dhcp_client_stop (priv->dhcp4_client, release); @@ -4720,6 +4746,8 @@ dhcp6_cleanup (NMDevice *self, gboolean stop, gboolean release) priv->dhcp6_timeout_sigid = 0; } + nm_device_remove_pending_action (self, PENDING_ACTION_DHCP6, FALSE); + if (stop) nm_dhcp_client_stop (priv->dhcp6_client, release); -- 1.9.0