device: merge nm_device_activate_stage3_ip[46]_start()

This commit is contained in:
Thomas Haller 2020-10-29 17:14:32 +01:00
parent 85a60f9d53
commit 101b031807
No known key found for this signature in database
GPG key ID: 29C2366E4DFC5728
2 changed files with 46 additions and 97 deletions

View file

@ -54,17 +54,7 @@ gboolean nm_device_set_ip_iface(NMDevice *self, const char *iface);
void nm_device_activate_schedule_stage3_ip_config_start(NMDevice *device);
gboolean nm_device_activate_stage3_ip4_start(NMDevice *self);
gboolean nm_device_activate_stage3_ip6_start(NMDevice *self);
static inline gboolean
nm_device_activate_stage3_ip_start(NMDevice *self, int addr_family)
{
if (NM_IS_IPv4(addr_family))
return nm_device_activate_stage3_ip4_start(self);
return nm_device_activate_stage3_ip6_start(self);
}
gboolean nm_device_activate_stage3_ip_start(NMDevice *self, int addr_family);
gboolean nm_device_bring_up(NMDevice *self, gboolean wait, gboolean *no_firmware);

View file

@ -4653,10 +4653,10 @@ nm_device_master_enslave_slave(NMDevice *self, NMDevice *slave, NMConnection *co
*/
if (success) {
if (priv->ip_state_4 == NM_DEVICE_IP_STATE_WAIT)
nm_device_activate_stage3_ip4_start(self);
nm_device_activate_stage3_ip_start(self, AF_INET);
if (priv->ip_state_6 == NM_DEVICE_IP_STATE_WAIT)
nm_device_activate_stage3_ip6_start(self);
nm_device_activate_stage3_ip_start(self, AF_INET6);
}
/* Since slave devices don't have their own IP configuration,
@ -4887,9 +4887,9 @@ carrier_changed(NMDevice *self, gboolean carrier)
/* If needed, also resume IP configuration that is
* waiting for carrier. */
if (nm_device_activate_ip4_state_in_wait(self))
nm_device_activate_stage3_ip4_start(self);
nm_device_activate_stage3_ip_start(self, AF_INET);
if (nm_device_activate_ip6_state_in_wait(self))
nm_device_activate_stage3_ip6_start(self);
nm_device_activate_stage3_ip_start(self, AF_INET6);
return;
}
/* fall-through and change state of device */
@ -11200,104 +11200,63 @@ act_stage3_ip_config_start(NMDevice * self,
}
}
/**
* nm_device_activate_stage3_ip4_start:
* @self: the device
*
* Try starting IPv4 configuration.
*/
gboolean
nm_device_activate_stage3_ip4_start(NMDevice *self)
nm_device_activate_stage3_ip_start(NMDevice *self, int addr_family)
{
NMDevicePrivate * priv = NM_DEVICE_GET_PRIVATE(self);
const int IS_IPv4 = NM_IS_IPv4(addr_family);
NMDevicePrivate * priv = NM_DEVICE_GET_PRIVATE(self);
NMActStageReturn ret;
NMDeviceStateReason failure_reason = NM_DEVICE_STATE_REASON_NONE;
gs_unref_object NMIP4Config *ip4_config = NULL;
NMDeviceStateReason failure_reason = NM_DEVICE_STATE_REASON_NONE;
gs_unref_object NMIPConfig *ip_config = NULL;
g_assert(priv->ip_state_4 == NM_DEVICE_IP_STATE_WAIT);
g_assert(priv->ip_state_x[IS_IPv4] == NM_DEVICE_IP_STATE_WAIT);
if (nm_device_sys_iface_state_is_external(self)) {
_set_ip_state(self, AF_INET, NM_DEVICE_IP_STATE_DONE);
_set_ip_state(self, addr_family, NM_DEVICE_IP_STATE_DONE);
check_ip_state(self, FALSE, TRUE);
return TRUE;
}
_set_ip_state(self, AF_INET, NM_DEVICE_IP_STATE_CONF);
_set_ip_state(self, addr_family, NM_DEVICE_IP_STATE_CONF);
ret = NM_DEVICE_GET_CLASS(self)->act_stage3_ip_config_start(self,
AF_INET,
(gpointer *) &ip4_config,
addr_family,
(gpointer *) &ip_config,
&failure_reason);
if (ret == NM_ACT_STAGE_RETURN_SUCCESS)
nm_device_activate_schedule_ip_config_result(self, AF_INET, NM_IP_CONFIG_CAST(ip4_config));
else if (ret == NM_ACT_STAGE_RETURN_IP_DONE) {
_set_ip_state(self, AF_INET, NM_DEVICE_IP_STATE_DONE);
switch (ret) {
case NM_ACT_STAGE_RETURN_SUCCESS:
if (!IS_IPv4) {
/* Here we get a static IPv6 config, like for Shared where it's
* autogenerated or from modems where it comes from ModemManager.
*/
if (!ip_config)
ip_config = nm_device_ip_config_new(self, addr_family);
nm_assert(!applied_config_get_current(&priv->ac_ip6_config));
applied_config_init(&priv->ac_ip6_config, ip_config);
ip_config = NULL;
}
nm_device_activate_schedule_ip_config_result(self, addr_family, ip_config);
break;
case NM_ACT_STAGE_RETURN_IP_DONE:
_set_ip_state(self, addr_family, NM_DEVICE_IP_STATE_DONE);
check_ip_state(self, FALSE, TRUE);
} else if (ret == NM_ACT_STAGE_RETURN_FAILURE) {
break;
case NM_ACT_STAGE_RETURN_FAILURE:
nm_device_state_changed(self, NM_DEVICE_STATE_FAILED, failure_reason);
return FALSE;
} else if (ret == NM_ACT_STAGE_RETURN_IP_FAIL) {
case NM_ACT_STAGE_RETURN_IP_FAIL:
/* Activation not wanted */
_set_ip_state(self, AF_INET, NM_DEVICE_IP_STATE_FAIL);
} else if (ret == NM_ACT_STAGE_RETURN_IP_WAIT) {
_set_ip_state(self, addr_family, NM_DEVICE_IP_STATE_FAIL);
break;
case NM_ACT_STAGE_RETURN_IP_WAIT:
/* Wait for something to try IP config again */
_set_ip_state(self, AF_INET, NM_DEVICE_IP_STATE_WAIT);
} else
_set_ip_state(self, addr_family, NM_DEVICE_IP_STATE_WAIT);
break;
default:
g_assert(ret == NM_ACT_STAGE_RETURN_POSTPONE);
return TRUE;
}
/**
* nm_device_activate_stage3_ip6_start:
* @self: the device
*
* Try starting IPv6 configuration.
*/
gboolean
nm_device_activate_stage3_ip6_start(NMDevice *self)
{
NMDevicePrivate * priv = NM_DEVICE_GET_PRIVATE(self);
NMActStageReturn ret;
NMDeviceStateReason failure_reason = NM_DEVICE_STATE_REASON_NONE;
gs_unref_object NMIP6Config *ip6_config = NULL;
g_assert(priv->ip_state_6 == NM_DEVICE_IP_STATE_WAIT);
if (nm_device_sys_iface_state_is_external(self)) {
_set_ip_state(self, AF_INET6, NM_DEVICE_IP_STATE_DONE);
check_ip_state(self, FALSE, TRUE);
return TRUE;
}
_set_ip_state(self, AF_INET6, NM_DEVICE_IP_STATE_CONF);
ret = NM_DEVICE_GET_CLASS(self)->act_stage3_ip_config_start(self,
AF_INET6,
(gpointer *) &ip6_config,
&failure_reason);
if (ret == NM_ACT_STAGE_RETURN_SUCCESS) {
if (!ip6_config)
ip6_config = nm_device_ip6_config_new(self);
/* Here we get a static IPv6 config, like for Shared where it's
* autogenerated or from modems where it comes from ModemManager.
*/
nm_assert(!applied_config_get_current(&priv->ac_ip6_config));
applied_config_init(&priv->ac_ip6_config, ip6_config);
nm_device_activate_schedule_ip_config_result(self, AF_INET6, NULL);
} else if (ret == NM_ACT_STAGE_RETURN_IP_DONE) {
_set_ip_state(self, AF_INET6, NM_DEVICE_IP_STATE_DONE);
check_ip_state(self, FALSE, TRUE);
} else if (ret == NM_ACT_STAGE_RETURN_FAILURE) {
nm_device_state_changed(self, NM_DEVICE_STATE_FAILED, failure_reason);
return FALSE;
} else if (ret == NM_ACT_STAGE_RETURN_IP_FAIL) {
/* Activation not wanted */
_set_ip_state(self, AF_INET6, NM_DEVICE_IP_STATE_FAIL);
} else if (ret == NM_ACT_STAGE_RETURN_IP_WAIT) {
/* Wait for something to try IP config again */
_set_ip_state(self, AF_INET6, NM_DEVICE_IP_STATE_WAIT);
} else
g_assert(ret == NM_ACT_STAGE_RETURN_POSTPONE);
return TRUE;
}
@ -11326,12 +11285,12 @@ activate_stage3_ip_config_start(NMDevice *self)
"interface %s not up for IP configuration",
nm_device_get_ip_iface(self));
/* IPv4 */
if (nm_device_activate_ip4_state_in_wait(self) && !nm_device_activate_stage3_ip4_start(self))
if (nm_device_activate_ip4_state_in_wait(self)
&& !nm_device_activate_stage3_ip_start(self, AF_INET))
return;
/* IPv6 */
if (nm_device_activate_ip6_state_in_wait(self) && !nm_device_activate_stage3_ip6_start(self))
if (nm_device_activate_ip6_state_in_wait(self)
&& !nm_device_activate_stage3_ip_start(self, AF_INET6))
return;
/* Proxy */