device: restore IP configuration when link comes up

This is especially important, because changing MTU takes the
link down for a moment. Taking a link down deletes IP routes and
IPv6 addresses. Thus, when the link comes up again, we must restore
them.

Otherwise, we don't call merge_and_apply() until the next DHCP lease
(or possibly never in case of static addressing).

https://bugzilla.redhat.com/show_bug.cgi?id=1309899
This commit is contained in:
Thomas Haller 2016-04-15 20:01:36 +02:00
parent f50e39fc98
commit 35a7ea77b0

View file

@ -397,6 +397,9 @@ static gboolean nm_device_set_ip6_config (NMDevice *self,
gboolean commit,
gboolean routes_full_sync,
NMDeviceStateReason *reason);
static gboolean ip6_config_merge_and_apply (NMDevice *self,
gboolean commit,
NMDeviceStateReason *out_reason);
static void nm_device_master_add_slave (NMDevice *self, NMDevice *slave, gboolean configure);
static void nm_device_slave_notify_enslave (NMDevice *self, gboolean success);
@ -1561,6 +1564,7 @@ device_link_changed (NMDevice *self)
NMPlatformLink info;
const NMPlatformLink *pllink;
int ifindex;
gboolean was_up;
priv->device_link_changed_id = 0;
@ -1633,6 +1637,7 @@ device_link_changed (NMDevice *self)
if (ip_ifname_changed)
nm_device_update_dynamic_ip_setup (self);
was_up = priv->up;
priv->up = NM_FLAGS_HAS (info.n_ifi_flags, IFF_UP);
if ( info.initialized
@ -1665,6 +1670,20 @@ device_link_changed (NMDevice *self)
set_unmanaged_external_down (self, FALSE);
device_recheck_slave_status (self, &info);
if (priv->up && !was_up) {
/* the link was down and just came up. That happens for example, while changing MTU.
* We must restore IP configuration. */
if (priv->ip4_state == IP_DONE) {
if (!ip4_config_merge_and_apply (self, NULL, TRUE, NULL))
_LOGW (LOGD_IP4, "failed applying IP4 config after link comes up again");
}
if (priv->ip6_state == IP_DONE) {
if (!ip6_config_merge_and_apply (self, TRUE, NULL))
_LOGW (LOGD_IP6, "failed applying IP6 config after link comes up again");
}
}
return G_SOURCE_REMOVE;
}