Commit 810dc260 authored by Lubomir Rintel's avatar Lubomir Rintel 🥕 Committed by Thomas Haller

core: track origin of MTU

Only override MTU if it came from a source of higher priority or is of equal
priority but of lower value.
parent 33866e40
......@@ -1354,7 +1354,7 @@ ip4_config_pre_commit (NMDevice *device, NMIP4Config *config)
/* MTU override */
mtu = nm_setting_wired_get_mtu (s_wired);
if (mtu)
nm_ip4_config_set_mtu (config, mtu);
nm_ip4_config_set_mtu (config, mtu, NM_IP_CONFIG_SOURCE_USER);
}
static void
......
......@@ -142,7 +142,7 @@ ip4_config_pre_commit (NMDevice *self, NMIP4Config *config)
/* MTU override */
mtu = nm_setting_infiniband_get_mtu (s_infiniband);
if (mtu)
nm_ip4_config_set_mtu (config, mtu);
nm_ip4_config_set_mtu (config, mtu, NM_IP_CONFIG_SOURCE_USER);
}
static gboolean
......
......@@ -390,7 +390,7 @@ ip4_config_pre_commit (NMDevice *device, NMIP4Config *config)
if (s_wired) {
mtu = nm_setting_wired_get_mtu (s_wired);
if (mtu)
nm_ip4_config_set_mtu (config, mtu);
nm_ip4_config_set_mtu (config, mtu, NM_IP_CONFIG_SOURCE_USER);
}
}
......
......@@ -2883,7 +2883,7 @@ ip4_config_pre_commit (NMDevice *device, NMIP4Config *config)
/* MTU override */
mtu = nm_setting_wireless_get_mtu (s_wifi);
if (mtu)
nm_ip4_config_set_mtu (config, mtu);
nm_ip4_config_set_mtu (config, mtu, NM_IP_CONFIG_SOURCE_USER);
}
static gboolean
......
......@@ -542,7 +542,7 @@ nm_dhcp_utils_ip4_config_from_options (const char *iface,
goto error;
if (int_mtu > 576)
nm_ip4_config_set_mtu (ip4_config, int_mtu);
nm_ip4_config_set_mtu (ip4_config, int_mtu, NM_IP_CONFIG_SOURCE_DHCP);
}
str = g_hash_table_lookup (options, "nis_domain");
......
......@@ -49,6 +49,7 @@ typedef struct {
char *nis_domain;
GArray *wins;
guint32 mtu;
NMIPConfigSource mtu_source;
} NMIP4ConfigPrivate;
/* internal guint32 are assigned to gobject properties of type uint. Ensure, that uint is large enough */
......@@ -516,7 +517,8 @@ nm_ip4_config_merge (NMIP4Config *dst, const NMIP4Config *src)
/* MTU */
if (!nm_ip4_config_get_mtu (dst))
nm_ip4_config_set_mtu (dst, nm_ip4_config_get_mtu (src));
nm_ip4_config_set_mtu (dst, nm_ip4_config_get_mtu (src),
nm_ip4_config_get_mtu_source (src));
/* NIS */
for (i = 0; i < nm_ip4_config_get_num_nis_servers (src); i++)
......@@ -630,7 +632,7 @@ nm_ip4_config_subtract (NMIP4Config *dst, const NMIP4Config *src)
/* MTU */
if (nm_ip4_config_get_mtu (src) == nm_ip4_config_get_mtu (dst))
nm_ip4_config_set_mtu (dst, 0);
nm_ip4_config_set_mtu (dst, 0, NM_IP_CONFIG_SOURCE_UNKNOWN);
/* NIS */
for (i = 0; i < nm_ip4_config_get_num_nis_servers (src); i++) {
......@@ -870,7 +872,7 @@ nm_ip4_config_replace (NMIP4Config *dst, const NMIP4Config *src, gboolean *relev
/* mtu */
if (src_priv->mtu != dst_priv->mtu) {
nm_ip4_config_set_mtu (dst, src_priv->mtu);
nm_ip4_config_set_mtu (dst, src_priv->mtu, src_priv->mtu_source);
has_minor_changes = TRUE;
}
......@@ -1502,11 +1504,15 @@ nm_ip4_config_get_wins (const NMIP4Config *config, guint i)
/******************************************************************/
void
nm_ip4_config_set_mtu (NMIP4Config *config, guint32 mtu)
nm_ip4_config_set_mtu (NMIP4Config *config, guint32 mtu, NMIPConfigSource source)
{
NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (config);
priv->mtu = mtu;
if (source > priv->mtu_source) {
priv->mtu = mtu;
priv->mtu_source = source;
} else if (source == priv->mtu_source && (!priv->mtu || priv->mtu > mtu))
priv->mtu = mtu;
}
guint32
......@@ -1517,6 +1523,14 @@ nm_ip4_config_get_mtu (const NMIP4Config *config)
return priv->mtu;
}
NMIPConfigSource
nm_ip4_config_get_mtu_source (const NMIP4Config *config)
{
NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (config);
return priv->mtu_source;
}
/******************************************************************/
static inline void
......
......@@ -134,8 +134,9 @@ guint32 nm_ip4_config_get_num_wins (const NMIP4Config *config);
guint32 nm_ip4_config_get_wins (const NMIP4Config *config, guint i);
/* MTU */
void nm_ip4_config_set_mtu (NMIP4Config *config, guint32 mtu);
void nm_ip4_config_set_mtu (NMIP4Config *config, guint32 mtu, NMIPConfigSource source);
guint32 nm_ip4_config_get_mtu (const NMIP4Config *config);
NMIPConfigSource nm_ip4_config_get_mtu_source (const NMIP4Config *config);
void nm_ip4_config_hash (const NMIP4Config *config, GChecksum *sum, gboolean dns_only);
gboolean nm_ip4_config_equal (const NMIP4Config *a, const NMIP4Config *b);
......
......@@ -610,7 +610,7 @@ impl_ppp_manager_set_ip4_config (NMPPPManager *manager,
goto out;
if (mtu)
nm_ip4_config_set_mtu (config, mtu);
nm_ip4_config_set_mtu (config, mtu, NM_IP_CONFIG_SOURCE_PPP);
/* Push the IP4 config up to the device */
g_signal_emit (manager, signals[IP4_CONFIG], 0, priv->ip_iface, config);
......
......@@ -139,7 +139,7 @@ test_subtract (void)
nm_ip4_config_add_wins (dst, expected_wins);
nm_ip4_config_set_mss (dst, expected_mss);
nm_ip4_config_set_mtu (dst, expected_mtu);
nm_ip4_config_set_mtu (dst, expected_mtu, NM_IP_CONFIG_SOURCE_UNKNOWN);
nm_ip4_config_subtract (dst, src);
......@@ -310,9 +310,9 @@ test_merge_subtract_mss_mtu (void)
/* add MSS, MTU to configs to test them */
nm_ip4_config_set_mss (cfg2, expected_mss2);
nm_ip4_config_set_mtu (cfg2, expected_mtu2);
nm_ip4_config_set_mtu (cfg2, expected_mtu2, NM_IP_CONFIG_SOURCE_UNKNOWN);
nm_ip4_config_set_mss (cfg3, expected_mss3);
nm_ip4_config_set_mtu (cfg3, expected_mtu3);
nm_ip4_config_set_mtu (cfg3, expected_mtu3, NM_IP_CONFIG_SOURCE_UNKNOWN);
nm_ip4_config_merge (cfg1, cfg2);
/* ensure MSS and MTU are in cfg1 */
......
......@@ -1160,7 +1160,7 @@ nm_vpn_connection_ip4_config_get (DBusGProxy *proxy,
nm_ip4_config_set_mss (config, g_value_get_uint (val));
if (priv->mtu)
nm_ip4_config_set_mtu (config, priv->mtu);
nm_ip4_config_set_mtu (config, priv->mtu, NM_IP_CONFIG_SOURCE_VPN);
val = (GValue *) g_hash_table_lookup (config_hash, NM_VPN_PLUGIN_IP4_CONFIG_DOMAIN);
if (val)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment