diff options
-rw-r--r-- | src/devices/nm-device.c | 93 |
1 files changed, 63 insertions, 30 deletions
diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c index fbd5294ead..f4a113634d 100644 --- a/src/devices/nm-device.c +++ b/src/devices/nm-device.c @@ -307,7 +307,10 @@ typedef struct _NMDevicePrivate { /* IP4 configuration info */ NMIP4Config * ip4_config; /* Combined config from VPN, settings, and device */ - IpState ip4_state; + union { + const IpState ip4_state; + IpState ip4_state_; + }; NMIP4Config * con_ip4_config; /* config from the setting */ NMIP4Config * dev_ip4_config; /* Config from DHCP, PPP, LLv4, etc */ NMIP4Config * ext_ip4_config; /* Stuff added outside NM */ @@ -356,7 +359,10 @@ typedef struct _NMDevicePrivate { /* IP6 configuration info */ NMIP6Config * ip6_config; - IpState ip6_state; + union { + const IpState ip6_state; + IpState ip6_state_; + }; NMIP6Config * con_ip6_config; /* config from the setting */ NMIP6Config * wwan_ip6_config; NMIP6Config * ext_ip6_config; /* Stuff added outside NM */ @@ -665,6 +671,34 @@ _get_stable_id (NMConnection *connection, NMUtilsStableType *out_stable_type) /***********************************************************/ +NM_UTILS_LOOKUP_STR_DEFINE_STATIC (_ip_state_to_string, IpState, + NM_UTILS_LOOKUP_DEFAULT_WARN ("unknown"), + NM_UTILS_LOOKUP_STR_ITEM (IP_NONE, "none"), + NM_UTILS_LOOKUP_STR_ITEM (IP_WAIT, "wait"), + NM_UTILS_LOOKUP_STR_ITEM (IP_CONF, "conf"), + NM_UTILS_LOOKUP_STR_ITEM (IP_DONE, "done"), + NM_UTILS_LOOKUP_STR_ITEM (IP_FAIL, "fail"), +); + +static void +_set_ip_state (NMDevice *self, int addr_family, IpState new_state) +{ + IpState *p; + NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self); + + nm_assert (NM_IN_SET (addr_family, AF_INET, AF_INET6)); + + p = addr_family == AF_INET ? &priv->ip4_state_ : &priv->ip6_state_; + + if (*p != new_state) { + _LOGT (LOGD_DEVICE, "ip%c-state: set to %d (%s)", addr_family == AF_INET ? '4' : '6', + (int) new_state, _ip_state_to_string (new_state)); + *p = new_state; + } +} + +/*****************************************************************************/ + const char * nm_device_get_udi (NMDevice *self) { @@ -2903,8 +2937,8 @@ nm_device_slave_notify_enslave (NMDevice *self, gboolean success) } if (activating) { - priv->ip4_state = IP_DONE; - priv->ip6_state = IP_DONE; + _set_ip_state (self, AF_INET, IP_DONE); + _set_ip_state (self, AF_INET6, IP_DONE); if (success) nm_device_queue_state (self, NM_DEVICE_STATE_SECONDARIES, NM_DEVICE_STATE_REASON_NONE); else @@ -3944,7 +3978,8 @@ activate_stage1_device_prepare (NMDevice *self) NMDeviceStateReason reason = NM_DEVICE_STATE_REASON_NONE; NMActiveConnection *active = NM_ACTIVE_CONNECTION (priv->act_request); - priv->ip4_state = priv->ip6_state = IP_NONE; + _set_ip_state (self, AF_INET, IP_NONE); + _set_ip_state (self, AF_INET6, IP_NONE); /* Notify the new ActiveConnection along with the state change */ _notify (self, PROP_ACTIVE_CONNECTION); @@ -4141,7 +4176,8 @@ check_ip_failed (NMDevice *self, gboolean may_fail) if (nm_device_uses_assumed_connection (self)) { /* We have assumed configuration, but couldn't * redo it. No problem, move to check state. */ - priv->ip4_state = priv->ip6_state = IP_DONE; + _set_ip_state (self, AF_INET, IP_DONE); + _set_ip_state (self, AF_INET6, IP_DONE); state = NM_DEVICE_STATE_IP_CHECK; } else if ( may_fail && get_ip_config_may_fail (self, AF_INET) @@ -4166,12 +4202,10 @@ nm_device_ip_method_failed (NMDevice *self, int family, NMDeviceStateReason reas g_return_if_fail (NM_IS_DEVICE (self)); g_return_if_fail (family == AF_INET || family == AF_INET6); + priv = NM_DEVICE_GET_PRIVATE (self); - if (family == AF_INET) - priv->ip4_state = IP_FAIL; - else - priv->ip6_state = IP_FAIL; + _set_ip_state (self, family, IP_FAIL); if (get_ip_config_may_fail (self, family)) check_ip_failed (self, FALSE); @@ -6815,7 +6849,7 @@ nm_device_activate_stage3_ip4_start (NMDevice *self) g_assert (priv->ip4_state == IP_WAIT); - priv->ip4_state = IP_CONF; + _set_ip_state (self, AF_INET, IP_CONF); ret = NM_DEVICE_GET_CLASS (self)->act_stage3_ip4_config_start (self, &ip4_config, &reason); if (ret == NM_ACT_STAGE_RETURN_SUCCESS) { g_assert (ip4_config); @@ -6826,10 +6860,10 @@ nm_device_activate_stage3_ip4_start (NMDevice *self) return FALSE; } else if (ret == NM_ACT_STAGE_RETURN_STOP) { /* Early finish */ - priv->ip4_state = IP_FAIL; + _set_ip_state (self, AF_INET, IP_FAIL); } else if (ret == NM_ACT_STAGE_RETURN_WAIT) { /* Wait for something to try IP config again */ - priv->ip4_state = IP_WAIT; + _set_ip_state (self, AF_INET, IP_WAIT); } else g_assert (ret == NM_ACT_STAGE_RETURN_POSTPONE); @@ -6852,7 +6886,7 @@ nm_device_activate_stage3_ip6_start (NMDevice *self) g_assert (priv->ip6_state == IP_WAIT); - priv->ip6_state = IP_CONF; + _set_ip_state (self, AF_INET6, IP_CONF); ret = NM_DEVICE_GET_CLASS (self)->act_stage3_ip6_config_start (self, &ip6_config, &reason); if (ret == NM_ACT_STAGE_RETURN_SUCCESS) { g_assert (ip6_config); @@ -6867,14 +6901,14 @@ nm_device_activate_stage3_ip6_start (NMDevice *self) return FALSE; } else if (ret == NM_ACT_STAGE_RETURN_STOP) { /* Activation not wanted */ - priv->ip6_state = IP_FAIL; + _set_ip_state (self, AF_INET6, IP_FAIL); } else if (ret == NM_ACT_STAGE_RETURN_FINISH) { /* Early finish, nothing more to do */ - priv->ip6_state = IP_DONE; + _set_ip_state (self, AF_INET6, IP_DONE); check_ip_done (self); } else if (ret == NM_ACT_STAGE_RETURN_WAIT) { /* Wait for something to try IP config again */ - priv->ip6_state = IP_WAIT; + _set_ip_state (self, AF_INET6, IP_WAIT); } else g_assert (ret == NM_ACT_STAGE_RETURN_POSTPONE); @@ -6894,7 +6928,8 @@ activate_stage3_ip_config_start (NMDevice *self) NMActiveConnection *master; NMDevice *master_device; - priv->ip4_state = priv->ip6_state = IP_WAIT; + _set_ip_state (self, AF_INET, IP_WAIT); + _set_ip_state (self, AF_INET6, IP_WAIT); nm_device_state_changed (self, NM_DEVICE_STATE_IP_CONFIG, NM_DEVICE_STATE_REASON_NONE); @@ -7051,7 +7086,6 @@ act_stage4_ip4_config_timeout (NMDevice *self, NMDeviceStateReason *reason) static void activate_stage4_ip4_config_timeout (NMDevice *self) { - NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self); NMActStageReturn ret = NM_ACT_STAGE_RETURN_FAILURE; NMDeviceStateReason reason = NM_DEVICE_STATE_REASON_NONE; @@ -7064,7 +7098,7 @@ activate_stage4_ip4_config_timeout (NMDevice *self) } g_assert (ret == NM_ACT_STAGE_RETURN_SUCCESS); - priv->ip4_state = IP_FAIL; + _set_ip_state (self, AF_INET, IP_FAIL); check_ip_failed (self, FALSE); } @@ -7108,7 +7142,6 @@ act_stage4_ip6_config_timeout (NMDevice *self, NMDeviceStateReason *reason) static void activate_stage4_ip6_config_timeout (NMDevice *self) { - NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self); NMActStageReturn ret = NM_ACT_STAGE_RETURN_FAILURE; NMDeviceStateReason reason = NM_DEVICE_STATE_REASON_NONE; @@ -7121,7 +7154,7 @@ activate_stage4_ip6_config_timeout (NMDevice *self) } g_assert (ret == NM_ACT_STAGE_RETURN_SUCCESS); - priv->ip6_state = IP_FAIL; + _set_ip_state (self, AF_INET6, IP_FAIL); check_ip_failed (self, FALSE); } @@ -7361,7 +7394,7 @@ activate_stage5_ip4_config_commit (NMDevice *self) nm_device_remove_pending_action (self, PENDING_ACTION_DHCP4, FALSE); /* Enter the IP_CHECK state if this is the first method to complete */ - priv->ip4_state = IP_DONE; + _set_ip_state (self, AF_INET, IP_DONE); check_ip_done (self); } @@ -7503,7 +7536,7 @@ activate_stage5_ip6_config_commit (NMDevice *self) _LOGD (LOGD_DEVICE | LOGD_IP6, "IPv6 DAD: waiting termination"); } else { /* No tentative addresses, proceed right away */ - priv->ip6_state = IP_DONE; + _set_ip_state (self, AF_INET6, IP_DONE); check_ip_done (self); } } @@ -7524,7 +7557,7 @@ nm_device_activate_schedule_ip6_config_result (NMDevice *self) * clearly now have configuration. */ if (priv->ip6_state == IP_FAIL) - priv->ip6_state = IP_CONF; + _set_ip_state (self, AF_INET6, IP_CONF); activation_source_schedule (self, activate_stage5_ip6_config_commit, AF_INET6); } @@ -7693,7 +7726,7 @@ _cleanup_ip4_pre (NMDevice *self, CleanupType cleanup_type) { NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self); - priv->ip4_state = IP_NONE; + _set_ip_state (self, AF_INET, IP_NONE); if (nm_clear_g_source (&priv->queued_ip4_config_id)) _LOGD (LOGD_DEVICE, "clearing queued IP4 config change"); @@ -7709,7 +7742,7 @@ _cleanup_ip6_pre (NMDevice *self, CleanupType cleanup_type) { NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self); - priv->ip6_state = IP_NONE; + _set_ip_state (self, AF_INET6, IP_NONE); if (nm_clear_g_source (&priv->queued_ip6_config_id)) _LOGD (LOGD_DEVICE, "clearing queued IP6 config change"); @@ -7807,7 +7840,7 @@ nm_device_reactivate_ip4_config (NMDevice *self, if (strcmp (nm_setting_ip_config_get_method (s_ip4_new), nm_setting_ip_config_get_method (s_ip4_old))) { _cleanup_ip4_pre (self, CLEANUP_TYPE_DECONFIGURE); - priv->ip4_state = IP_WAIT; + _set_ip_state (self, AF_INET, IP_WAIT); if (!nm_device_activate_stage3_ip4_start (self)) _LOGW (LOGD_IP4, "Failed to apply IPv4 configuration"); } else { @@ -7838,7 +7871,7 @@ nm_device_reactivate_ip6_config (NMDevice *self, if (strcmp (nm_setting_ip_config_get_method (s_ip6_new), nm_setting_ip_config_get_method (s_ip6_old))) { _cleanup_ip6_pre (self, CLEANUP_TYPE_DECONFIGURE); - priv->ip6_state = IP_WAIT; + _set_ip_state (self, AF_INET6, IP_WAIT); if (!nm_device_activate_stage3_ip6_start (self)) _LOGW (LOGD_IP6, "Failed to apply IPv6 configuration"); } else { @@ -9637,7 +9670,7 @@ queued_ip6_config_change (gpointer user_data) priv->dad6_ip6_config)) { _LOGD (LOGD_DEVICE | LOGD_IP6, "IPv6 DAD terminated"); g_clear_object (&priv->dad6_ip6_config); - priv->ip6_state = IP_DONE; + _set_ip_state (self, AF_INET6, IP_DONE); check_ip_done (self); } } |