mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2025-12-25 06:00:08 +01:00
device: introduce nm_device_get_configured_mtu_from_connection()
Deduplicate similar code from devices.
This commit is contained in:
parent
94200b03fe
commit
d9df1f1d05
6 changed files with 56 additions and 97 deletions
|
|
@ -117,27 +117,9 @@ act_stage1_prepare (NMDevice *device, NMDeviceStateReason *out_failure_reason)
|
|||
static guint32
|
||||
get_configured_mtu (NMDevice *device, gboolean *out_is_user_config)
|
||||
{
|
||||
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_is_user_config);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
|
|
|
|||
|
|
@ -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, gboolean *out_is_user_config)
|
||||
{
|
||||
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_is_user_config);
|
||||
}
|
||||
|
||||
static NMDeviceCapabilities
|
||||
get_generic_capabilities (NMDevice *dev)
|
||||
get_generic_capabilities (NMDevice *device)
|
||||
{
|
||||
return NM_DEVICE_CAP_IS_SOFTWARE;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -120,6 +120,10 @@ 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_from_connection (NMDevice *device,
|
||||
GType setting_type,
|
||||
gboolean *out_is_user_config);
|
||||
|
||||
guint32 nm_device_get_configured_mtu_for_wired (NMDevice *self, gboolean *out_is_user_config);
|
||||
|
||||
void nm_device_commit_mtu (NMDevice *self);
|
||||
|
|
|
|||
|
|
@ -8371,12 +8371,15 @@ 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,
|
||||
gboolean *out_is_user_config)
|
||||
{
|
||||
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);
|
||||
|
|
@ -8385,17 +8388,33 @@ nm_device_get_configured_mtu_for_wired (NMDevice *self, gboolean *out_is_user_co
|
|||
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_is_user_config = TRUE;
|
||||
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;
|
||||
return (guint32) mtu_default;
|
||||
|
|
@ -8405,6 +8424,14 @@ nm_device_get_configured_mtu_for_wired (NMDevice *self, gboolean *out_is_user_co
|
|||
return 0;
|
||||
}
|
||||
|
||||
guint32
|
||||
nm_device_get_configured_mtu_for_wired (NMDevice *self, gboolean *out_is_user_config)
|
||||
{
|
||||
return nm_device_get_configured_mtu_from_connection (self,
|
||||
NM_TYPE_SETTING_WIRED,
|
||||
out_is_user_config);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
static void
|
||||
|
|
|
|||
|
|
@ -1318,27 +1318,9 @@ out:
|
|||
static guint32
|
||||
get_configured_mtu (NMDevice *device, gboolean *out_is_user_config)
|
||||
{
|
||||
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_is_user_config);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
|
|
|
|||
|
|
@ -2788,27 +2788,9 @@ act_stage3_ip6_config_start (NMDevice *device,
|
|||
static guint32
|
||||
get_configured_mtu (NMDevice *device, gboolean *out_is_user_config)
|
||||
{
|
||||
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_is_user_config);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue