device: allow reapply when the device is activating

Allow a reapply of the connection when the device is still activating
and ensure that each reapply action is performed only at a given
activation stage. For example, the IP configuration is not reactivated
if the device is in the prepare stage.

https://bugzilla.redhat.com/show_bug.cgi?id=1763062
This commit is contained in:
Beniamino Galvani 2019-10-22 16:55:55 +02:00
parent dab1d780fd
commit 01920d3d52
4 changed files with 48 additions and 30 deletions

View file

@ -1696,6 +1696,7 @@ static void
reapply_connection (NMDevice *device, NMConnection *con_old, NMConnection *con_new)
{
NMDeviceEthernet *self = NM_DEVICE_ETHERNET (device);
NMDeviceState state = nm_device_get_state (device);
NM_DEVICE_CLASS (nm_device_ethernet_parent_class)->reapply_connection (device,
con_old,
@ -1703,8 +1704,10 @@ reapply_connection (NMDevice *device, NMConnection *con_old, NMConnection *con_n
_LOGD (LOGD_DEVICE, "reapplying wired settings");
link_negotiation_set (device);
wake_on_lan_enable (device);
if (state >= NM_DEVICE_STATE_PREPARE)
link_negotiation_set (device);
if (state >= NM_DEVICE_STATE_CONFIG)
wake_on_lan_enable (device);
}
static void

View file

@ -1787,23 +1787,27 @@ reapply_connection (NMDevice *device,
NMDeviceWireGuardPrivate *priv = NM_DEVICE_WIREGUARD_GET_PRIVATE (self);
gs_unref_object NMIPConfig *ip4_config = NULL;
gs_unref_object NMIPConfig *ip6_config = NULL;
priv->auto_default_route_refresh = TRUE;
ip4_config = _get_dev2_ip_config (self, AF_INET);
ip6_config = _get_dev2_ip_config (self, AF_INET6);
nm_device_set_dev2_ip_config (device, AF_INET, ip4_config);
nm_device_set_dev2_ip_config (device, AF_INET6, ip6_config);
NMDeviceState state = nm_device_get_state (device);
NM_DEVICE_CLASS (nm_device_wireguard_parent_class)->reapply_connection (device,
con_old,
con_new);
link_config (NM_DEVICE_WIREGUARD (device),
"reapply",
LINK_CONFIG_MODE_REAPPLY,
NULL);
if (state >= NM_DEVICE_STATE_CONFIG) {
priv->auto_default_route_refresh = TRUE;
link_config (NM_DEVICE_WIREGUARD (device),
"reapply",
LINK_CONFIG_MODE_REAPPLY,
NULL);
}
if (state >= NM_DEVICE_STATE_IP_CONFIG) {
ip4_config = _get_dev2_ip_config (self, AF_INET);
ip6_config = _get_dev2_ip_config (self, AF_INET6);
nm_device_set_dev2_ip_config (device, AF_INET, ip4_config);
nm_device_set_dev2_ip_config (device, AF_INET6, ip6_config);
}
}
/*****************************************************************************/

View file

@ -11561,7 +11561,8 @@ check_and_reapply_connection (NMDevice *self,
NMSettingIPConfig *s_ip6_old, *s_ip6_new;
GHashTableIter iter;
if (priv->state != NM_DEVICE_STATE_ACTIVATED) {
if ( priv->state < NM_DEVICE_STATE_PREPARE
|| priv->state > NM_DEVICE_STATE_ACTIVATED) {
g_set_error_literal (error,
NM_DEVICE_ERROR,
NM_DEVICE_ERROR_NOT_ACTIVE,
@ -11674,24 +11675,31 @@ check_and_reapply_connection (NMDevice *self,
*************************************************************************/
klass->reapply_connection (self, con_old, con_new);
nm_device_update_firewall_zone (self);
nm_device_update_metered (self);
lldp_init (self, FALSE);
if (priv->state >= NM_DEVICE_STATE_CONFIG)
lldp_init (self, FALSE);
s_ip4_old = nm_connection_get_setting_ip4_config (con_old);
s_ip4_new = nm_connection_get_setting_ip4_config (con_new);
s_ip6_old = nm_connection_get_setting_ip6_config (con_old);
s_ip6_new = nm_connection_get_setting_ip6_config (con_new);
if (priv->state >= NM_DEVICE_STATE_IP_CONFIG) {
s_ip4_old = nm_connection_get_setting_ip4_config (con_old);
s_ip4_new = nm_connection_get_setting_ip4_config (con_new);
s_ip6_old = nm_connection_get_setting_ip6_config (con_old);
s_ip6_new = nm_connection_get_setting_ip6_config (con_new);
/* Allow reapply of MTU */
priv->mtu_source = NM_DEVICE_MTU_SOURCE_NONE;
/* Allow reapply of MTU */
priv->mtu_source = NM_DEVICE_MTU_SOURCE_NONE;
nm_device_reactivate_ip4_config (self, s_ip4_old, s_ip4_new);
nm_device_reactivate_ip6_config (self, s_ip6_old, s_ip6_new);
nm_device_reactivate_ip4_config (self, s_ip4_old, s_ip4_new);
nm_device_reactivate_ip6_config (self, s_ip6_old, s_ip6_new);
_routing_rules_sync (self, NM_TERNARY_TRUE);
_routing_rules_sync (self, NM_TERNARY_TRUE);
reactivate_proxy_config (self);
reactivate_proxy_config (self);
}
if (priv->state >= NM_DEVICE_STATE_IP_CHECK)
nm_device_update_firewall_zone (self);
if (priv->state >= NM_DEVICE_STATE_ACTIVATED)
nm_device_update_metered (self);
return TRUE;
}
@ -11788,7 +11796,8 @@ impl_device_reapply (NMDBusObject *obj,
return;
}
if (priv->state != NM_DEVICE_STATE_ACTIVATED) {
if ( priv->state < NM_DEVICE_STATE_PREPARE
|| priv->state > NM_DEVICE_STATE_ACTIVATED) {
error = g_error_new_literal (NM_DEVICE_ERROR,
NM_DEVICE_ERROR_NOT_ACTIVE,
"Device is not activated");

View file

@ -3209,6 +3209,7 @@ static void
reapply_connection (NMDevice *device, NMConnection *con_old, NMConnection *con_new)
{
NMDeviceWifi *self = NM_DEVICE_WIFI (device);
NMDeviceState state = nm_device_get_state (device);
NM_DEVICE_CLASS (nm_device_wifi_parent_class)->reapply_connection (device,
con_old,
@ -3216,7 +3217,8 @@ reapply_connection (NMDevice *device, NMConnection *con_old, NMConnection *con_n
_LOGD (LOGD_DEVICE, "reapplying wireless settings");
if (!wake_on_wlan_enable (self))
if ( state >= NM_DEVICE_STATE_CONFIG
&& !wake_on_wlan_enable (self))
_LOGW (LOGD_DEVICE | LOGD_WIFI, "Cannot configure WoWLAN.");
}