device: set a per-device default MTU on activation
In absence of an explicit MTU (either via user configuration, PPP or DHCP), set a default MTU on activation that depends on the device type. We only want to do that on the very first call to _commit_mtu(). Later calls (for example in response to new DHCP leases) skip over this step. This means, on activation the MTU will always be reset to a sensible value instead of preserving whatever was left from a previous configuration. This does not cover setting the MTU from the VPN plugin :(
This commit is contained in:
@@ -310,7 +310,9 @@ typedef struct _NMDevicePrivate {
|
|||||||
guint32 mtu_initial;
|
guint32 mtu_initial;
|
||||||
guint32 ip6_mtu_initial;
|
guint32 ip6_mtu_initial;
|
||||||
|
|
||||||
bool up; /* IFF_UP */
|
bool mtu_initialized:1;
|
||||||
|
|
||||||
|
bool up:1; /* IFF_UP */
|
||||||
|
|
||||||
/* Generic DHCP stuff */
|
/* Generic DHCP stuff */
|
||||||
guint32 dhcp_timeout;
|
guint32 dhcp_timeout;
|
||||||
@@ -2573,6 +2575,7 @@ realize_start_setup (NMDevice *self, const NMPlatformLink *plink)
|
|||||||
/* Balanced by a thaw in nm_device_realize_finish() */
|
/* Balanced by a thaw in nm_device_realize_finish() */
|
||||||
g_object_freeze_notify (G_OBJECT (self));
|
g_object_freeze_notify (G_OBJECT (self));
|
||||||
|
|
||||||
|
priv->mtu_initialized = FALSE;
|
||||||
priv->mtu_initial = 0;
|
priv->mtu_initial = 0;
|
||||||
priv->ip6_mtu_initial = 0;
|
priv->ip6_mtu_initial = 0;
|
||||||
priv->ip6_mtu = 0;
|
priv->ip6_mtu = 0;
|
||||||
@@ -6625,10 +6628,9 @@ _commit_mtu (NMDevice *self, const NMIP4Config *config)
|
|||||||
gboolean mtu_is_user_config = FALSE;
|
gboolean mtu_is_user_config = FALSE;
|
||||||
guint32 mtu = 0;
|
guint32 mtu = 0;
|
||||||
|
|
||||||
/* preferably, get the MTU from explict user-configuration. If that fails,
|
/* preferably, get the MTU from explict user-configuration.
|
||||||
* look at the current @config (which contains MTUs from DHCP/PPP.
|
* Only if that fails, look at the current @config (which contains
|
||||||
*
|
* MTUs from DHCP/PPP) or maybe fallback to a device-specific MTU. */
|
||||||
* Finally, assume no MTU change. */
|
|
||||||
|
|
||||||
if (NM_DEVICE_GET_CLASS (self)->get_configured_mtu)
|
if (NM_DEVICE_GET_CLASS (self)->get_configured_mtu)
|
||||||
mtu = NM_DEVICE_GET_CLASS (self)->get_configured_mtu (self, &mtu_is_user_config);
|
mtu = NM_DEVICE_GET_CLASS (self)->get_configured_mtu (self, &mtu_is_user_config);
|
||||||
@@ -6640,10 +6642,27 @@ _commit_mtu (NMDevice *self, const NMIP4Config *config)
|
|||||||
mtu_desired = nm_ip4_config_get_mtu (config);
|
mtu_desired = nm_ip4_config_get_mtu (config);
|
||||||
else
|
else
|
||||||
mtu_desired = 0;
|
mtu_desired = 0;
|
||||||
|
if (!mtu_desired && !priv->mtu_initialized) {
|
||||||
|
/* there is no MTU specified, and this is the first commit of the MTU.
|
||||||
|
* Reset a per-device MTU default, as returned from get_configured_mtu().
|
||||||
|
*
|
||||||
|
* The device might choose not to return a default MTU via get_configured_mtu()
|
||||||
|
* to suppress this behavior. */
|
||||||
|
mtu_desired = mtu;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ip6_mtu = priv->ip6_mtu;
|
ip6_mtu = priv->ip6_mtu;
|
||||||
|
if (!ip6_mtu && !priv->mtu_initialized) {
|
||||||
|
/* initially, if the IPv6 MTU is not specified, grow it as large as the
|
||||||
|
* link MTU @mtu_desired. Only exception is, if @mtu_desired is so small
|
||||||
|
* to disable IPv6. */
|
||||||
|
if (mtu_desired >= 1280)
|
||||||
|
ip6_mtu = mtu_desired;
|
||||||
|
}
|
||||||
|
|
||||||
|
priv->mtu_initialized = TRUE;
|
||||||
|
|
||||||
if (!ip6_mtu && !mtu_desired)
|
if (!ip6_mtu && !mtu_desired)
|
||||||
return;
|
return;
|
||||||
@@ -11455,6 +11474,7 @@ nm_device_cleanup (NMDevice *self, NMDeviceStateReason reason, CleanupType clean
|
|||||||
NM_DEVICE_GET_CLASS (self)->deactivate_reset_hw_addr (self);
|
NM_DEVICE_GET_CLASS (self)->deactivate_reset_hw_addr (self);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
priv->mtu_initialized = FALSE;
|
||||||
if (priv->mtu_initial || priv->ip6_mtu_initial) {
|
if (priv->mtu_initial || priv->ip6_mtu_initial) {
|
||||||
ifindex = nm_device_get_ip_ifindex (self);
|
ifindex = nm_device_get_ip_ifindex (self);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user