device: merge branch 'bg/mtu-rh1586191'

https://bugzilla.redhat.com/show_bug.cgi?id=1586191
This commit is contained in:
Beniamino Galvani 2018-06-20 19:05:34 +02:00
commit cbfe9a6e16
11 changed files with 129 additions and 141 deletions

View file

@ -1317,13 +1317,13 @@ act_stage3_ip4_config_start (NMDevice *device,
}
static guint32
get_configured_mtu (NMDevice *device, gboolean *out_is_user_config)
get_configured_mtu (NMDevice *device, NMDeviceMtuSource *out_source)
{
/* MTU only set for plain ethernet */
if (NM_DEVICE_ETHERNET_GET_PRIVATE ((NMDeviceEthernet *) device)->ppp_manager)
return 0;
return nm_device_get_configured_mtu_for_wired (device, out_is_user_config);
return nm_device_get_configured_mtu_for_wired (device, out_source);
}
static void

View file

@ -115,29 +115,11 @@ act_stage1_prepare (NMDevice *device, NMDeviceStateReason *out_failure_reason)
}
static guint32
get_configured_mtu (NMDevice *device, gboolean *out_is_user_config)
get_configured_mtu (NMDevice *device, NMDeviceMtuSource *out_source)
{
NMSettingInfiniband *setting;
gint64 mtu_default;
guint32 mtu;
nm_assert (NM_IS_DEVICE (device));
nm_assert (out_is_user_config);
setting = NM_SETTING_INFINIBAND (nm_device_get_applied_setting (device, NM_TYPE_SETTING_INFINIBAND));
if (!setting)
g_return_val_if_reached (0);
mtu = nm_setting_infiniband_get_mtu (setting);
if (mtu == 0) {
mtu_default = nm_device_get_configured_mtu_from_connection_default (device, "infiniband.mtu");
if (mtu_default >= 0) {
*out_is_user_config = TRUE;
return (guint32) mtu_default;
}
}
*out_is_user_config = (mtu != 0);
return mtu;
return nm_device_get_configured_mtu_from_connection (device,
NM_TYPE_SETTING_INFINIBAND,
out_source);
}
static gboolean

View file

@ -741,33 +741,15 @@ create_and_realize (NMDevice *device,
}
static guint32
get_configured_mtu (NMDevice *self, gboolean *out_is_user_config)
get_configured_mtu (NMDevice *device, NMDeviceMtuSource *out_source)
{
NMSettingIPTunnel *setting;
gint64 mtu_default;
guint32 mtu;
nm_assert (NM_IS_DEVICE (self));
nm_assert (out_is_user_config);
setting = NM_SETTING_IP_TUNNEL (nm_device_get_applied_setting (self, NM_TYPE_SETTING_IP_TUNNEL));
if (!setting)
g_return_val_if_reached (0);
mtu = nm_setting_ip_tunnel_get_mtu (setting);
if (mtu == 0) {
mtu_default = nm_device_get_configured_mtu_from_connection_default (self, "ip-tunnel.mtu");
if (mtu_default >= 0) {
*out_is_user_config = TRUE;
return (guint32) mtu_default;
}
}
*out_is_user_config = (mtu != 0);
return mtu;
return nm_device_get_configured_mtu_from_connection (device,
NM_TYPE_SETTING_IP_TUNNEL,
out_source);
}
static NMDeviceCapabilities
get_generic_capabilities (NMDevice *dev)
get_generic_capabilities (NMDevice *device)
{
return NM_DEVICE_CAP_IS_SOFTWARE;
}

View file

@ -120,7 +120,11 @@ gboolean nm_device_ipv6_sysctl_set (NMDevice *self, const char *property, const
gint64 nm_device_get_configured_mtu_from_connection_default (NMDevice *self,
const char *property_name);
guint32 nm_device_get_configured_mtu_for_wired (NMDevice *self, gboolean *out_is_user_config);
guint32 nm_device_get_configured_mtu_from_connection (NMDevice *device,
GType setting_type,
NMDeviceMtuSource *out_source);
guint32 nm_device_get_configured_mtu_for_wired (NMDevice *self, NMDeviceMtuSource *out_source);
void nm_device_commit_mtu (NMDevice *self);

View file

@ -534,19 +534,21 @@ act_stage1_prepare (NMDevice *device, NMDeviceStateReason *out_failure_reason)
}
static guint32
get_configured_mtu (NMDevice *self, gboolean *out_is_user_config)
get_configured_mtu (NMDevice *self, NMDeviceMtuSource *out_source)
{
guint32 mtu = 0;
int ifindex;
mtu = nm_device_get_configured_mtu_for_wired (self, out_is_user_config);
if (*out_is_user_config)
mtu = nm_device_get_configured_mtu_for_wired (self, out_source);
if (*out_source != NM_DEVICE_MTU_SOURCE_NONE)
return mtu;
/* Inherit the MTU from parent device, if any */
ifindex = nm_device_parent_get_ifindex (self);
if (ifindex > 0)
if (ifindex > 0) {
mtu = nm_platform_link_get_mtu (nm_device_get_platform (NM_DEVICE (self)), ifindex);
*out_source = NM_DEVICE_MTU_SOURCE_PARENT;
}
return mtu;
}

View file

@ -349,8 +349,9 @@ typedef struct _NMDevicePrivate {
gulong config_changed_id;
guint32 mtu;
guint32 ip6_mtu;
guint32 mtu_initial;
guint32 ip6_mtu_initial;
guint32 mtu_initial;
guint32 ip6_mtu_initial;
NMDeviceMtuSource mtu_source;
guint32 v4_route_table;
guint32 v6_route_table;
@ -366,8 +367,6 @@ typedef struct _NMDevicePrivate {
bool carrier:1;
bool ignore_carrier:1;
bool mtu_initialized:1;
bool up:1; /* IFF_UP */
bool v4_commit_first_time:1;
@ -735,6 +734,14 @@ NM_UTILS_LOOKUP_STR_DEFINE (nm_device_state_reason_to_str, NMDeviceStateReason,
#define reason_to_string(reason) \
NM_UTILS_LOOKUP_STR (nm_device_state_reason_to_str, reason)
NM_UTILS_LOOKUP_STR_DEFINE_STATIC (mtu_source_to_str, NMDeviceMtuSource,
NM_UTILS_LOOKUP_DEFAULT_NM_ASSERT ("unknown"),
NM_UTILS_LOOKUP_STR_ITEM (NM_DEVICE_MTU_SOURCE_NONE, "none"),
NM_UTILS_LOOKUP_STR_ITEM (NM_DEVICE_MTU_SOURCE_PARENT, "parent"),
NM_UTILS_LOOKUP_STR_ITEM (NM_DEVICE_MTU_SOURCE_IP_CONFIG, "ip-config"),
NM_UTILS_LOOKUP_STR_ITEM (NM_DEVICE_MTU_SOURCE_CONNECTION, "connection"),
);
/*****************************************************************************/
NMSettings *
@ -4001,7 +4008,7 @@ realize_start_setup (NMDevice *self,
/* Balanced by a thaw in nm_device_realize_finish() */
g_object_freeze_notify (G_OBJECT (self));
priv->mtu_initialized = FALSE;
priv->mtu_source = NM_DEVICE_MTU_SOURCE_NONE;
priv->mtu_initial = 0;
priv->ip6_mtu_initial = 0;
priv->ip6_mtu = 0;
@ -8371,40 +8378,68 @@ nm_device_get_configured_mtu_from_connection_default (NMDevice *self,
}
guint32
nm_device_get_configured_mtu_for_wired (NMDevice *self, gboolean *out_is_user_config)
nm_device_get_configured_mtu_from_connection (NMDevice *self,
GType setting_type,
NMDeviceMtuSource *out_source)
{
const char *global_property_name;
NMConnection *connection;
NMSettingWired *setting;
NMSetting *setting;
gint64 mtu_default;
guint32 mtu;
guint32 mtu = 0;
nm_assert (NM_IS_DEVICE (self));
nm_assert (out_is_user_config);
nm_assert (out_source);
connection = nm_device_get_applied_connection (self);
if (!connection)
g_return_val_if_reached (0);
setting = nm_connection_get_setting_wired (connection);
setting = nm_connection_get_setting (connection, setting_type);
if (setting) {
mtu = nm_setting_wired_get_mtu (setting);
if (mtu) {
*out_is_user_config = TRUE;
return mtu;
}
if (setting_type == NM_TYPE_SETTING_WIRED) {
if (setting)
mtu = nm_setting_wired_get_mtu (NM_SETTING_WIRED (setting));
global_property_name = "ethernet.mtu";
} else if (setting_type == NM_TYPE_SETTING_WIRELESS) {
if (setting)
mtu = nm_setting_wireless_get_mtu (NM_SETTING_WIRELESS (setting));
global_property_name = "wifi.mtu";
} else if (setting_type == NM_TYPE_SETTING_INFINIBAND) {
if (setting)
mtu = nm_setting_infiniband_get_mtu (NM_SETTING_INFINIBAND (setting));
global_property_name = "infiniband.mtu";
} else if (setting_type == NM_TYPE_SETTING_IP_TUNNEL) {
if (setting)
mtu = nm_setting_ip_tunnel_get_mtu (NM_SETTING_IP_TUNNEL (setting));
global_property_name = "ip-tunnel.mtu";
} else
g_return_val_if_reached (0);
if (mtu) {
*out_source = NM_DEVICE_MTU_SOURCE_CONNECTION;
return mtu;
}
mtu_default = nm_device_get_configured_mtu_from_connection_default (self, "ethernet.mtu");
mtu_default = nm_device_get_configured_mtu_from_connection_default (self, global_property_name);
if (mtu_default >= 0) {
*out_is_user_config = TRUE;
*out_source = NM_DEVICE_MTU_SOURCE_CONNECTION;
return (guint32) mtu_default;
}
*out_is_user_config = FALSE;
*out_source = NM_DEVICE_MTU_SOURCE_NONE;
return 0;
}
guint32
nm_device_get_configured_mtu_for_wired (NMDevice *self, NMDeviceMtuSource *out_source)
{
return nm_device_get_configured_mtu_from_connection (self,
NM_TYPE_SETTING_WIRED,
out_source);
}
/*****************************************************************************/
static void
@ -8431,6 +8466,7 @@ static void
_commit_mtu (NMDevice *self, const NMIP4Config *config)
{
NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
NMDeviceMtuSource source = NM_DEVICE_MTU_SOURCE_NONE;
guint32 ip6_mtu, ip6_mtu_orig;
guint32 mtu_desired, mtu_desired_orig;
guint32 mtu_plat;
@ -8440,6 +8476,7 @@ _commit_mtu (NMDevice *self, const NMIP4Config *config)
} ip6_mtu_sysctl = { 0, };
int ifindex;
char sbuf[64], sbuf1[64], sbuf2[64];
gboolean success = TRUE;
ifindex = nm_device_get_ip_ifindex (self);
if (ifindex <= 0)
@ -8453,7 +8490,6 @@ _commit_mtu (NMDevice *self, const NMIP4Config *config)
}
{
gboolean mtu_is_user_config = FALSE;
guint32 mtu = 0;
/* preferably, get the MTU from explict user-configuration.
@ -8461,23 +8497,30 @@ _commit_mtu (NMDevice *self, const NMIP4Config *config)
* MTUs from DHCP/PPP) or maybe fallback to a device-specific 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, &source);
if (mtu_is_user_config)
if ( config
&& source < NM_DEVICE_MTU_SOURCE_IP_CONFIG
&& nm_ip4_config_get_mtu (config)) {
mtu = nm_ip4_config_get_mtu (config);
source = NM_DEVICE_MTU_SOURCE_IP_CONFIG;
}
if (mtu != 0) {
_LOGT (LOGD_DEVICE,
"mtu: value %u from source '%s' (%u), current source '%s' (%u)",
(guint) mtu,
mtu_source_to_str (source), (guint) source,
mtu_source_to_str (priv->mtu_source), (guint) priv->mtu_source);
}
if ( mtu != 0
&& ( source > priv->mtu_source
|| (priv->mtu_source == NM_DEVICE_MTU_SOURCE_PARENT && source == priv->mtu_source)))
mtu_desired = mtu;
else {
if (config)
mtu_desired = nm_ip4_config_get_mtu (config);
else
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;
}
mtu_desired = 0;
source = NM_DEVICE_MTU_SOURCE_NONE;
}
}
@ -8499,7 +8542,7 @@ _commit_mtu (NMDevice *self, const NMIP4Config *config)
}
ip6_mtu = priv->ip6_mtu;
if (!ip6_mtu && !priv->mtu_initialized) {
if (!ip6_mtu && priv->mtu_source == NM_DEVICE_MTU_SOURCE_NONE) {
/* 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. */
@ -8507,8 +8550,6 @@ _commit_mtu (NMDevice *self, const NMIP4Config *config)
ip6_mtu = mtu_desired;
}
priv->mtu_initialized = TRUE;
if (!ip6_mtu && !mtu_desired)
return;
@ -8560,6 +8601,7 @@ _commit_mtu (NMDevice *self, const NMIP4Config *config)
if (mtu_desired && mtu_desired != mtu_plat) {
if (nm_platform_link_set_mtu (nm_device_get_platform (self), ifindex, mtu_desired) == NM_PLATFORM_ERROR_CANT_SET_MTU) {
anticipated_failure = TRUE;
success = FALSE;
_LOGW (LOGD_DEVICE, "mtu: failure to set MTU. %s",
NM_IS_DEVICE_VLAN (self)
? "Is the parent's MTU size large enough?"
@ -8581,10 +8623,15 @@ _commit_mtu (NMDevice *self, const NMIP4Config *config)
anticipated_failure && errsv == EINVAL
? ": Is the underlying MTU value successfully set?"
: "");
success = FALSE;
}
priv->carrier_wait_until_ms = nm_utils_get_monotonic_timestamp_ms () + CARRIER_WAIT_TIME_AFTER_MTU_MS;
}
}
if (success && source != NM_DEVICE_MTU_SOURCE_NONE)
priv->mtu_source = source;
#undef _IP6_MTU_SYS
}
@ -13623,7 +13670,7 @@ nm_device_cleanup (NMDevice *self, NMDeviceStateReason reason, CleanupType clean
NM_DEVICE_GET_CLASS (self)->deactivate_reset_hw_addr (self);
}
priv->mtu_initialized = FALSE;
priv->mtu_source = NM_DEVICE_MTU_SOURCE_NONE;
if (priv->mtu_initial || priv->ip6_mtu_initial) {
ifindex = nm_device_get_ip_ifindex (self);

View file

@ -44,6 +44,13 @@ typedef enum {
NM_DEVICE_SYS_IFACE_STATE_REMOVED,
} NMDeviceSysIfaceState;
typedef enum {
NM_DEVICE_MTU_SOURCE_NONE,
NM_DEVICE_MTU_SOURCE_PARENT,
NM_DEVICE_MTU_SOURCE_IP_CONFIG,
NM_DEVICE_MTU_SOURCE_CONNECTION,
} NMDeviceMtuSource;
static inline NMDeviceStateReason
nm_device_state_reason_check (NMDeviceStateReason reason)
{
@ -287,7 +294,7 @@ typedef struct _NMDeviceClass {
NMConnection *connection,
char **specific_object);
guint32 (*get_configured_mtu) (NMDevice *self, gboolean *out_is_user_config);
guint32 (*get_configured_mtu) (NMDevice *self, NMDeviceMtuSource *out_source);
/* Checks whether the connection is compatible with the device using
* only the devices type and characteristics. Does not use any live

View file

@ -1316,29 +1316,11 @@ out:
}
static guint32
get_configured_mtu (NMDevice *device, gboolean *out_is_user_config)
get_configured_mtu (NMDevice *device, NMDeviceMtuSource *out_source)
{
NMSettingWireless *setting;
gint64 mtu_default;
guint32 mtu;
nm_assert (NM_IS_DEVICE (device));
nm_assert (out_is_user_config);
setting = NM_SETTING_WIRELESS (nm_device_get_applied_setting (device, NM_TYPE_SETTING_WIRELESS));
if (!setting)
g_return_val_if_reached (0);
mtu = nm_setting_wireless_get_mtu (setting);
if (mtu == 0) {
mtu_default = nm_device_get_configured_mtu_from_connection_default (device, "wifi.mtu");
if (mtu_default >= 0) {
*out_is_user_config = TRUE;
return (guint32) mtu_default;
}
}
*out_is_user_config = (mtu != 0);
return mtu;
return nm_device_get_configured_mtu_from_connection (device,
NM_TYPE_SETTING_WIRELESS,
out_source);
}
static gboolean

View file

@ -2786,29 +2786,11 @@ act_stage3_ip6_config_start (NMDevice *device,
}
static guint32
get_configured_mtu (NMDevice *device, gboolean *out_is_user_config)
get_configured_mtu (NMDevice *device, NMDeviceMtuSource *out_source)
{
NMSettingWireless *setting;
gint64 mtu_default;
guint32 mtu;
nm_assert (NM_IS_DEVICE (device));
nm_assert (out_is_user_config);
setting = NM_SETTING_WIRELESS (nm_device_get_applied_setting (device, NM_TYPE_SETTING_WIRELESS));
if (!setting)
g_return_val_if_reached (0);
mtu = nm_setting_wireless_get_mtu (setting);
if (mtu == 0) {
mtu_default = nm_device_get_configured_mtu_from_connection_default (device, "wifi.mtu");
if (mtu_default >= 0) {
*out_is_user_config = TRUE;
return (guint32) mtu_default;
}
}
*out_is_user_config = (mtu != 0);
return mtu;
return nm_device_get_configured_mtu_from_connection (device,
NM_TYPE_SETTING_WIRELESS,
out_source);
}
static gboolean

View file

@ -859,7 +859,7 @@ nm_modem_stage3_ip6_config_start (NMModem *self,
}
guint32
nm_modem_get_configured_mtu (NMDevice *self, gboolean *out_is_user_config)
nm_modem_get_configured_mtu (NMDevice *self, NMDeviceMtuSource *out_source)
{
NMConnection *connection;
NMSetting *setting;
@ -868,7 +868,7 @@ nm_modem_get_configured_mtu (NMDevice *self, gboolean *out_is_user_config)
const char *property_name;
nm_assert (NM_IS_DEVICE (self));
nm_assert (out_is_user_config);
nm_assert (out_source);
connection = nm_device_get_applied_connection (self);
if (!connection)
@ -881,19 +881,19 @@ nm_modem_get_configured_mtu (NMDevice *self, gboolean *out_is_user_config)
if (setting) {
g_object_get (setting, "mtu", &mtu, NULL);
if (mtu) {
*out_is_user_config = TRUE;
*out_source = NM_DEVICE_MTU_SOURCE_CONNECTION;
return mtu;
}
property_name = NM_IS_SETTING_GSM (setting) ? "gsm.mtu" : "cdma.mtu";
mtu_default = nm_device_get_configured_mtu_from_connection_default (self, property_name);
if (mtu_default >= 0) {
*out_is_user_config = TRUE;
*out_source = NM_DEVICE_MTU_SOURCE_CONNECTION;
return (guint32) mtu_default;
}
}
*out_is_user_config = FALSE;
*out_source = NM_DEVICE_MTU_SOURCE_NONE;
return 0;
}

View file

@ -275,6 +275,6 @@ void nm_modem_emit_ip6_config_result (NMModem *self,
const gchar *nm_modem_ip_type_to_string (NMModemIPType ip_type);
guint32 nm_modem_get_configured_mtu (NMDevice *self, gboolean *out_is_user_config);
guint32 nm_modem_get_configured_mtu (NMDevice *self, NMDeviceMtuSource *out_source);
#endif /* __NETWORKMANAGER_MODEM_H__ */