From 53dfaddda2adad15f4fbf35780bc03503cc45a63 Mon Sep 17 00:00:00 2001 From: Beniamino Galvani Date: Thu, 17 Mar 2016 14:17:32 +0100 Subject: [PATCH] device: apply MTU setting also to devices without IPv4 configuration Usually the MTU in the ethernet.mtu property is applied to the device during the commit of IPv4 configuration. For devices with ipv4.method=disabled or slave devices that phase is skipped and so the setting does not have effect. Apply the MTU explicitly in such cases. https://bugzilla.redhat.com/show_bug.cgi?id=1303968 https://bugzilla.redhat.com/show_bug.cgi?id=1303731 --- src/devices/nm-device.c | 41 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c index ae1711df17..4bc1b1079d 100644 --- a/src/devices/nm-device.c +++ b/src/devices/nm-device.c @@ -413,6 +413,7 @@ static NMActStageReturn dhcp4_start (NMDevice *self, NMConnection *connection, N static gboolean dhcp6_start (NMDevice *self, gboolean wait_for_ll, NMDeviceStateReason *reason); static void nm_device_start_ip_check (NMDevice *self); static void realize_start_setup (NMDevice *self, const NMPlatformLink *plink); +static void nm_device_set_mtu (NMDevice *self, guint32 mtu); /***********************************************************/ @@ -1063,6 +1064,38 @@ find_slave_info (NMDevice *self, NMDevice *slave) return NULL; } +static void +apply_mtu_from_config (NMDevice *self) +{ + const char *method = NM_SETTING_IP4_CONFIG_METHOD_DISABLED; + NMSettingIPConfig *s_ip4; + NMSettingWired *s_wired; + guint32 mtu; + + /* Devices having an IPv4 configuration will set MTU during the commit + * stage, so it is an error to call this function if the IPv4 method is not + * 'disabled'. + */ + s_ip4 = (NMSettingIPConfig *) + nm_device_get_applied_setting (self, NM_TYPE_SETTING_IP4_CONFIG); + if (s_ip4) + method = nm_setting_ip_config_get_method (s_ip4); + g_return_if_fail (nm_streq (method, NM_SETTING_IP4_CONFIG_METHOD_DISABLED)); + + s_wired = (NMSettingWired *) + nm_device_get_applied_setting (self, NM_TYPE_SETTING_WIRED); + + if (s_wired) { + mtu = nm_setting_wired_get_mtu (s_wired); + if (mtu) { + _LOGD (LOGD_DEVICE | LOGD_IP, + "setting MTU of device without IP4 config to %u", + mtu); + nm_device_set_mtu (self, mtu); + } + } +} + /** * nm_device_master_enslave_slave: * @self: the master device @@ -1120,6 +1153,11 @@ nm_device_master_enslave_slave (NMDevice *self, NMDevice *slave, NMConnection *c nm_device_activate_stage3_ip6_start (self); } + /* Since slave devices don't have their own IP configuration, + * set the MTU here. + */ + apply_mtu_from_config (slave); + return success; } @@ -4908,7 +4946,8 @@ act_stage3_ip4_config_start (NMDevice *self, } else ret = NM_ACT_STAGE_RETURN_FAILURE; } else if (strcmp (method, NM_SETTING_IP4_CONFIG_METHOD_DISABLED) == 0) { - /* Nothing to do... */ + apply_mtu_from_config (self); + /* Nothing else to do... */ ret = NM_ACT_STAGE_RETURN_STOP; } else _LOGW (LOGD_IP4, "unhandled IPv4 config method '%s'; will fail", method);