From 6fa2405997d8399c3af64dcbde02e31dc59cc1e8 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 15 Apr 2016 20:01:36 +0200 Subject: [PATCH] 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 (cherry picked from commit 35a7ea77b0dc5cddb8d8f0854499715ccf57287c) (cherry picked from commit 5367eac8146ef47f07f1bcfe1e3e74d381080706) --- src/devices/nm-device.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c index 4a28d8d266..e6c88dd3b8 100644 --- a/src/devices/nm-device.c +++ b/src/devices/nm-device.c @@ -370,6 +370,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 gboolean nm_device_master_add_slave (NMDevice *self, NMDevice *slave, gboolean configure); static void nm_device_slave_notify_enslave (NMDevice *self, gboolean success); @@ -1516,6 +1519,19 @@ device_link_changed (NMDevice *self) } } + 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; }