diff options
author | Beniamino Galvani <bgalvani@redhat.com> | 2021-08-06 09:01:37 +0200 |
---|---|---|
committer | Beniamino Galvani <bgalvani@redhat.com> | 2021-08-06 15:41:57 +0200 |
commit | 9121b961eb31c79557e30dfc4dd5c5b6ea4b8f5f (patch) | |
tree | 9eddc0849857033a5718df3284a4aeb9075c60d4 | |
parent | ca122d1a148334b1487116c3dc7bffeec58e629d (diff) | |
download | NetworkManager-9121b961eb31c79557e30dfc4dd5c5b6ea4b8f5f.tar.gz |
device: store the original MTU before force-setting it
In case the MTU is force-set (e.g. for bridges), priv->mtu_initial and
priv->ip6_mtu_initial must be initialized before changing the MTU,
otherwise the wrong value will be restored on deactivation.
Fixes: e23798a5e5e8 ('bridge: force (hack)-set of the MTU when explicitly set in the profile')
https://bugzilla.redhat.com/show_bug.cgi?id=1973536
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/955
(cherry picked from commit 3f42e2005aa768c73d6c455f57ac2753c9fd97c2)
(cherry picked from commit 77305477211bdc003c7b34138f693589c73db325)
-rw-r--r-- | src/core/devices/nm-device.c | 36 |
1 files changed, 21 insertions, 15 deletions
diff --git a/src/core/devices/nm-device.c b/src/core/devices/nm-device.c index 3874e58636..55f689f308 100644 --- a/src/core/devices/nm-device.c +++ b/src/core/devices/nm-device.c @@ -10522,10 +10522,30 @@ _commit_mtu(NMDevice *self, const NMIP4Config *config) } } +#define _IP6_MTU_SYS() \ + ({ \ + if (!ip6_mtu_sysctl.initialized) { \ + ip6_mtu_sysctl.value = nm_device_sysctl_ip_conf_get_int_checked(self, \ + AF_INET6, \ + "mtu", \ + 10, \ + 0, \ + G_MAXUINT32, \ + 0); \ + ip6_mtu_sysctl.initialized = TRUE; \ + } \ + ip6_mtu_sysctl.value; \ + }) + if (mtu_desired && NM_DEVICE_GET_CLASS(self)->mtu_force_set && !priv->mtu_force_set_done) { priv->mtu_force_set_done = TRUE; - if (mtu_desired == mtu_plat) { + if (!priv->mtu_initial && !priv->ip6_mtu_initial) { + /* before touching any of the MTU parameters, record the + * original setting to restore on deactivation. */ + priv->mtu_initial = mtu_plat; + priv->ip6_mtu_initial = _IP6_MTU_SYS(); + } mtu_plat--; if (NM_DEVICE_GET_CLASS(self)->set_platform_mtu(self, mtu_desired - 1)) { _LOGD(LOGD_DEVICE, "mtu: force-set MTU to %u", mtu_desired - 1); @@ -10544,20 +10564,6 @@ _commit_mtu(NMDevice *self, const NMIP4Config *config) ip6_mtu == ip6_mtu_orig ? "" : nm_sprintf_buf(sbuf2, " (was %u)", (guint) ip6_mtu_orig), ifindex); -#define _IP6_MTU_SYS() \ - ({ \ - if (!ip6_mtu_sysctl.initialized) { \ - ip6_mtu_sysctl.value = nm_device_sysctl_ip_conf_get_int_checked(self, \ - AF_INET6, \ - "mtu", \ - 10, \ - 0, \ - G_MAXUINT32, \ - 0); \ - ip6_mtu_sysctl.initialized = TRUE; \ - } \ - ip6_mtu_sysctl.value; \ - }) if ((mtu_desired && mtu_desired != mtu_plat) || (ip6_mtu && ip6_mtu != _IP6_MTU_SYS())) { gboolean anticipated_failure = FALSE; |