diff --git a/src/devices/nm-device-bond.c b/src/devices/nm-device-bond.c index cca76bfed3..5dba19d91c 100644 --- a/src/devices/nm-device-bond.c +++ b/src/devices/nm-device-bond.c @@ -383,25 +383,6 @@ act_stage1_prepare (NMDevice *dev, NMDeviceStateReason *reason) return ret; } -static void -ip4_config_pre_commit (NMDevice *self, NMIP4Config *config) -{ - NMConnection *connection; - NMSettingWired *s_wired; - guint32 mtu; - - connection = nm_device_get_applied_connection (self); - g_assert (connection); - s_wired = nm_connection_get_setting_wired (connection); - - if (s_wired) { - /* MTU override */ - mtu = nm_setting_wired_get_mtu (s_wired); - if (mtu) - nm_ip4_config_set_mtu (config, mtu, NM_IP_CONFIG_SOURCE_USER); - } -} - static gboolean enslave_slave (NMDevice *device, NMDevice *slave, @@ -523,7 +504,7 @@ nm_device_bond_class_init (NMDeviceBondClass *klass) parent_class->create_and_realize = create_and_realize; parent_class->act_stage1_prepare = act_stage1_prepare; - parent_class->ip4_config_pre_commit = ip4_config_pre_commit; + parent_class->get_configured_mtu = nm_device_get_configured_mtu_for_wired; parent_class->enslave_slave = enslave_slave; parent_class->release_slave = release_slave; diff --git a/src/devices/nm-device-ethernet.c b/src/devices/nm-device-ethernet.c index 8de4e3bcb5..0dc09762aa 100644 --- a/src/devices/nm-device-ethernet.c +++ b/src/devices/nm-device-ethernet.c @@ -1391,26 +1391,14 @@ act_stage3_ip4_config_start (NMDevice *device, return NM_DEVICE_CLASS (nm_device_ethernet_parent_class)->act_stage3_ip4_config_start (device, out_config, reason); } -static void -ip4_config_pre_commit (NMDevice *device, NMIP4Config *config) +static guint32 +get_configured_mtu (NMDevice *device, gboolean *out_is_user_config) { - NMConnection *connection; - NMSettingWired *s_wired; - guint32 mtu; - /* MTU only set for plain ethernet */ if (NM_DEVICE_ETHERNET_GET_PRIVATE ((NMDeviceEthernet *) device)->ppp_manager) - return; + return 0; - connection = nm_device_get_applied_connection (device); - g_assert (connection); - s_wired = nm_connection_get_setting_wired (connection); - g_assert (s_wired); - - /* MTU override */ - mtu = nm_setting_wired_get_mtu (s_wired); - if (mtu) - nm_ip4_config_set_mtu (config, mtu, NM_IP_CONFIG_SOURCE_USER); + return nm_device_get_configured_mtu_for_wired (device, out_is_user_config); } static void @@ -1774,7 +1762,7 @@ nm_device_ethernet_class_init (NMDeviceEthernetClass *klass) parent_class->act_stage1_prepare = act_stage1_prepare; parent_class->act_stage2_config = act_stage2_config; parent_class->act_stage3_ip4_config_start = act_stage3_ip4_config_start; - parent_class->ip4_config_pre_commit = ip4_config_pre_commit; + parent_class->get_configured_mtu = get_configured_mtu; parent_class->deactivate = deactivate; parent_class->spec_match_list = spec_match_list; parent_class->update_connection = update_connection; diff --git a/src/devices/nm-device-infiniband.c b/src/devices/nm-device-infiniband.c index b0871b0a95..4f07761aad 100644 --- a/src/devices/nm-device-infiniband.c +++ b/src/devices/nm-device-infiniband.c @@ -118,22 +118,22 @@ act_stage1_prepare (NMDevice *dev, NMDeviceStateReason *reason) return NM_ACT_STAGE_RETURN_SUCCESS; } -static void -ip4_config_pre_commit (NMDevice *self, NMIP4Config *config) +static guint32 +get_configured_mtu (NMDevice *device, gboolean *out_is_user_config) { - NMConnection *connection; - NMSettingInfiniband *s_infiniband; + NMSettingInfiniband *setting; guint32 mtu; - connection = nm_device_get_applied_connection (self); - g_assert (connection); - s_infiniband = nm_connection_get_setting_infiniband (connection); - g_assert (s_infiniband); + nm_assert (NM_IS_DEVICE (device)); + nm_assert (out_is_user_config); - /* MTU override */ - mtu = nm_setting_infiniband_get_mtu (s_infiniband); - if (mtu) - nm_ip4_config_set_mtu (config, mtu, NM_IP_CONFIG_SOURCE_USER); + 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); + *out_is_user_config = (mtu != 0); + return mtu ?: NM_DEVICE_DEFAULT_MTU_INFINIBAND; } static gboolean @@ -381,7 +381,7 @@ nm_device_infiniband_class_init (NMDeviceInfinibandClass *klass) parent_class->update_connection = update_connection; parent_class->act_stage1_prepare = act_stage1_prepare; - parent_class->ip4_config_pre_commit = ip4_config_pre_commit; + parent_class->get_configured_mtu = get_configured_mtu; obj_properties[PROP_IS_PARTITION] = g_param_spec_boolean (NM_DEVICE_INFINIBAND_IS_PARTITION, "", "", diff --git a/src/devices/nm-device-ip-tunnel.c b/src/devices/nm-device-ip-tunnel.c index 718876086e..9220c75201 100644 --- a/src/devices/nm-device-ip-tunnel.c +++ b/src/devices/nm-device-ip-tunnel.c @@ -744,22 +744,22 @@ create_and_realize (NMDevice *device, return TRUE; } -static void -ip4_config_pre_commit (NMDevice *device, NMIP4Config *config) +static guint32 +get_configured_mtu (NMDevice *self, gboolean *out_is_user_config) { - NMConnection *connection; - NMSettingIPTunnel *s_ip_tunnel; + NMSettingIPTunnel *setting; guint32 mtu; - connection = nm_device_get_applied_connection (device); - g_assert (connection); - s_ip_tunnel = nm_connection_get_setting_ip_tunnel (connection); - g_assert (s_ip_tunnel); + nm_assert (NM_IS_DEVICE (self)); + nm_assert (out_is_user_config); - /* MTU override */ - mtu = nm_setting_ip_tunnel_get_mtu (s_ip_tunnel); - if (mtu) - nm_ip4_config_set_mtu (config, mtu, NM_IP_CONFIG_SOURCE_USER); + 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); + *out_is_user_config = (mtu != 0); + return mtu ?: NM_DEVICE_DEFAULT_MTU_WIRED; } static NMDeviceCapabilities @@ -873,7 +873,7 @@ nm_device_ip_tunnel_class_init (NMDeviceIPTunnelClass *klass) device_class->check_connection_compatible = check_connection_compatible; device_class->create_and_realize = create_and_realize; device_class->get_generic_capabilities = get_generic_capabilities; - device_class->ip4_config_pre_commit = ip4_config_pre_commit; + device_class->get_configured_mtu = get_configured_mtu; device_class->unrealize_notify = unrealize_notify; NM_DEVICE_CLASS_DECLARE_TYPES (klass, diff --git a/src/devices/nm-device-macvlan.c b/src/devices/nm-device-macvlan.c index 6f9879c558..94206716b3 100644 --- a/src/devices/nm-device-macvlan.c +++ b/src/devices/nm-device-macvlan.c @@ -489,24 +489,6 @@ act_stage1_prepare (NMDevice *dev, NMDeviceStateReason *reason) return NM_ACT_STAGE_RETURN_SUCCESS; } -static void -ip4_config_pre_commit (NMDevice *device, NMIP4Config *config) -{ - NMConnection *connection; - NMSettingWired *s_wired; - guint32 mtu; - - connection = nm_device_get_applied_connection (device); - g_assert (connection); - - s_wired = nm_connection_get_setting_wired (connection); - if (s_wired) { - mtu = nm_setting_wired_get_mtu (s_wired); - if (mtu) - nm_ip4_config_set_mtu (config, mtu, NM_IP_CONFIG_SOURCE_USER); - } -} - /*****************************************************************************/ static void @@ -570,7 +552,7 @@ nm_device_macvlan_class_init (NMDeviceMacvlanClass *klass) device_class->connection_type = NM_SETTING_MACVLAN_SETTING_NAME; device_class->create_and_realize = create_and_realize; device_class->get_generic_capabilities = get_generic_capabilities; - device_class->ip4_config_pre_commit = ip4_config_pre_commit; + device_class->get_configured_mtu = nm_device_get_configured_mtu_for_wired; device_class->is_available = is_available; device_class->link_changed = link_changed; device_class->parent_changed_notify = parent_changed_notify; diff --git a/src/devices/nm-device-private.h b/src/devices/nm-device-private.h index c2ba98f387..7b36ba46f0 100644 --- a/src/devices/nm-device-private.h +++ b/src/devices/nm-device-private.h @@ -118,6 +118,16 @@ void nm_device_ip_method_failed (NMDevice *self, int family, NMDeviceStateReason gboolean nm_device_ipv6_sysctl_set (NMDevice *self, const char *property, const char *value); +/*****************************************************************************/ + +#define NM_DEVICE_DEFAULT_MTU_WIRED ((guint32) 1500) +#define NM_DEVICE_DEFAULT_MTU_WIRELESS ((guint32) 1500) +#define NM_DEVICE_DEFAULT_MTU_INFINIBAND ((guint32) 0) + +guint32 nm_device_get_configured_mtu_for_wired (NMDevice *self, gboolean *out_is_user_config); + +/*****************************************************************************/ + #define NM_DEVICE_CLASS_DECLARE_TYPES(klass, conn_type, ...) \ NM_DEVICE_CLASS (klass)->connection_type = conn_type; \ { \ diff --git a/src/devices/nm-device-tun.c b/src/devices/nm-device-tun.c index bb66c50f80..2f42269234 100644 --- a/src/devices/nm-device-tun.c +++ b/src/devices/nm-device-tun.c @@ -313,24 +313,6 @@ act_stage1_prepare (NMDevice *device, NMDeviceStateReason *reason) return NM_ACT_STAGE_RETURN_SUCCESS; } -static void -ip4_config_pre_commit (NMDevice *device, NMIP4Config *config) -{ - NMConnection *connection; - NMSettingWired *s_wired; - guint32 mtu; - - connection = nm_device_get_applied_connection (device); - g_assert (connection); - - s_wired = nm_connection_get_setting_wired (connection); - if (s_wired) { - mtu = nm_setting_wired_get_mtu (s_wired); - if (mtu) - nm_ip4_config_set_mtu (config, mtu, NM_IP_CONFIG_SOURCE_USER); - } -} - static void unrealize_notify (NMDevice *device) { @@ -434,7 +416,7 @@ nm_device_tun_class_init (NMDeviceTunClass *klass) device_class->unrealize_notify = unrealize_notify; device_class->update_connection = update_connection; device_class->act_stage1_prepare = act_stage1_prepare; - device_class->ip4_config_pre_commit = ip4_config_pre_commit; + device_class->get_configured_mtu = nm_device_get_configured_mtu_for_wired; obj_properties[PROP_OWNER] = g_param_spec_int64 (NM_DEVICE_TUN_OWNER, "", "", diff --git a/src/devices/nm-device-vlan.c b/src/devices/nm-device-vlan.c index d07e831850..3979c95d8d 100644 --- a/src/devices/nm-device-vlan.c +++ b/src/devices/nm-device-vlan.c @@ -572,24 +572,6 @@ act_stage1_prepare (NMDevice *device, NMDeviceStateReason *reason) return ret; } -static void -ip4_config_pre_commit (NMDevice *device, NMIP4Config *config) -{ - NMConnection *connection; - NMSettingWired *s_wired; - guint32 mtu; - - connection = nm_device_get_applied_connection (device); - g_assert (connection); - - s_wired = nm_connection_get_setting_wired (connection); - if (s_wired) { - mtu = nm_setting_wired_get_mtu (s_wired); - if (mtu) - nm_ip4_config_set_mtu (config, mtu, NM_IP_CONFIG_SOURCE_USER); - } -} - /*****************************************************************************/ static void @@ -630,7 +612,7 @@ nm_device_vlan_class_init (NMDeviceVlanClass *klass) parent_class->unrealize_notify = unrealize_notify; parent_class->get_generic_capabilities = get_generic_capabilities; parent_class->act_stage1_prepare = act_stage1_prepare; - parent_class->ip4_config_pre_commit = ip4_config_pre_commit; + parent_class->get_configured_mtu = nm_device_get_configured_mtu_for_wired; parent_class->is_available = is_available; parent_class->parent_changed_notify = parent_changed_notify; diff --git a/src/devices/nm-device-vxlan.c b/src/devices/nm-device-vxlan.c index 63961ae5a6..b450813377 100644 --- a/src/devices/nm-device-vxlan.c +++ b/src/devices/nm-device-vxlan.c @@ -512,24 +512,6 @@ act_stage1_prepare (NMDevice *device, NMDeviceStateReason *reason) return NM_ACT_STAGE_RETURN_SUCCESS; } -static void -ip4_config_pre_commit (NMDevice *device, NMIP4Config *config) -{ - NMConnection *connection; - NMSettingWired *s_wired; - guint32 mtu; - - connection = nm_device_get_applied_connection (device); - g_assert (connection); - - s_wired = nm_connection_get_setting_wired (connection); - if (s_wired) { - mtu = nm_setting_wired_get_mtu (s_wired); - if (mtu) - nm_ip4_config_set_mtu (config, mtu, NM_IP_CONFIG_SOURCE_USER); - } -} - /*****************************************************************************/ static void @@ -622,7 +604,7 @@ nm_device_vxlan_class_init (NMDeviceVxlanClass *klass) device_class->get_generic_capabilities = get_generic_capabilities; device_class->update_connection = update_connection; device_class->act_stage1_prepare = act_stage1_prepare; - device_class->ip4_config_pre_commit = ip4_config_pre_commit; + device_class->get_configured_mtu = nm_device_get_configured_mtu_for_wired; obj_properties[PROP_ID] = g_param_spec_uint (NM_DEVICE_VXLAN_ID, "", "", diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c index f0da55e129..22ffce34f9 100644 --- a/src/devices/nm-device.c +++ b/src/devices/nm-device.c @@ -5182,6 +5182,16 @@ END_ADD_DEFAULT_ROUTE: /* Allow setting MTU etc */ if (commit) { + gboolean mtu_is_user_config = FALSE; + guint32 mtu; + + if (NM_DEVICE_GET_CLASS (self)->get_configured_mtu) + mtu = NM_DEVICE_GET_CLASS (self)->get_configured_mtu (self, &mtu_is_user_config); + else + mtu = 0; + if (mtu && mtu_is_user_config) + nm_ip4_config_set_mtu (composite, mtu, NM_IP_CONFIG_SOURCE_USER); + if (NM_DEVICE_GET_CLASS (self)->ip4_config_pre_commit) NM_DEVICE_GET_CLASS (self)->ip4_config_pre_commit (self, composite); } @@ -6589,6 +6599,35 @@ linklocal6_start (NMDevice *self) /*****************************************************************************/ +guint32 +nm_device_get_configured_mtu_for_wired (NMDevice *self, gboolean *out_is_user_config) +{ + NMConnection *connection; + NMSettingWired *setting; + guint32 mtu; + + nm_assert (NM_IS_DEVICE (self)); + nm_assert (out_is_user_config); + + connection = nm_device_get_applied_connection (self); + if (!connection) + g_return_val_if_reached (0); + + setting = nm_connection_get_setting_wired (connection); + + if (setting) { + mtu = nm_setting_wired_get_mtu (setting); + if (mtu) { + *out_is_user_config = TRUE; + return mtu; + } + } + *out_is_user_config = FALSE; + return NM_DEVICE_DEFAULT_MTU_WIRED; +} + +/*****************************************************************************/ + static void _set_mtu (NMDevice *self) { diff --git a/src/devices/nm-device.h b/src/devices/nm-device.h index a3a7c51540..52a74d268a 100644 --- a/src/devices/nm-device.h +++ b/src/devices/nm-device.h @@ -232,6 +232,8 @@ typedef struct { NMConnection *connection, char **specific_object); + guint32 (*get_configured_mtu) (NMDevice *self, gboolean *out_is_user_config); + /* Checks whether the connection is compatible with the device using * only the devices type and characteristics. Does not use any live * network information like WiFi scan lists etc. @@ -275,7 +277,6 @@ typedef struct { NMActStageReturn (* act_stage4_ip6_config_timeout) (NMDevice *self, NMDeviceStateReason *reason); - /* Called right before IP config is set; use for setting MTU etc */ void (* ip4_config_pre_commit) (NMDevice *self, NMIP4Config *config); /* Async deactivating (in the DEACTIVATING phase) */ diff --git a/src/devices/team/nm-device-team.c b/src/devices/team/nm-device-team.c index d67fb6b23e..28d91ab33c 100644 --- a/src/devices/team/nm-device-team.c +++ b/src/devices/team/nm-device-team.c @@ -627,25 +627,6 @@ act_stage1_prepare (NMDevice *device, NMDeviceStateReason *reason) NM_ACT_STAGE_RETURN_POSTPONE : NM_ACT_STAGE_RETURN_FAILURE; } -static void -ip4_config_pre_commit (NMDevice *self, NMIP4Config *config) -{ - NMConnection *connection; - NMSettingWired *s_wired; - guint32 mtu; - - connection = nm_device_get_applied_connection (self); - g_assert (connection); - s_wired = nm_connection_get_setting_wired (connection); - - if (s_wired) { - /* MTU override */ - mtu = nm_setting_wired_get_mtu (s_wired); - if (mtu) - nm_ip4_config_set_mtu (config, mtu, NM_IP_CONFIG_SOURCE_USER); - } -} - static void deactivate (NMDevice *device) { @@ -876,7 +857,7 @@ nm_device_team_class_init (NMDeviceTeamClass *klass) parent_class->master_update_slave_connection = master_update_slave_connection; parent_class->act_stage1_prepare = act_stage1_prepare; - parent_class->ip4_config_pre_commit = ip4_config_pre_commit; + parent_class->get_configured_mtu = nm_device_get_configured_mtu_for_wired; parent_class->deactivate = deactivate; parent_class->enslave_slave = enslave_slave; parent_class->release_slave = release_slave; diff --git a/src/devices/wifi/nm-device-wifi.c b/src/devices/wifi/nm-device-wifi.c index 9556adfc2d..9d002e8362 100644 --- a/src/devices/wifi/nm-device-wifi.c +++ b/src/devices/wifi/nm-device-wifi.c @@ -2741,22 +2741,22 @@ act_stage3_ip6_config_start (NMDevice *device, return NM_DEVICE_CLASS (nm_device_wifi_parent_class)->act_stage3_ip6_config_start (device, out_config, reason); } -static void -ip4_config_pre_commit (NMDevice *device, NMIP4Config *config) +static guint32 +get_configured_mtu (NMDevice *device, gboolean *out_is_user_config) { - NMConnection *connection; - NMSettingWireless *s_wifi; + NMSettingWireless *setting; guint32 mtu; - connection = nm_device_get_applied_connection (device); - g_assert (connection); - s_wifi = nm_connection_get_setting_wireless (connection); - g_assert (s_wifi); + nm_assert (NM_IS_DEVICE (device)); + nm_assert (out_is_user_config); - /* MTU override */ - mtu = nm_setting_wireless_get_mtu (s_wifi); - if (mtu) - nm_ip4_config_set_mtu (config, mtu, NM_IP_CONFIG_SOURCE_USER); + 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); + *out_is_user_config = (mtu != 0); + return mtu ?: NM_DEVICE_DEFAULT_MTU_WIRELESS; } static gboolean @@ -3215,7 +3215,7 @@ nm_device_wifi_class_init (NMDeviceWifiClass *klass) parent_class->act_stage1_prepare = act_stage1_prepare; parent_class->act_stage2_config = act_stage2_config; - parent_class->ip4_config_pre_commit = ip4_config_pre_commit; + parent_class->get_configured_mtu = get_configured_mtu; parent_class->act_stage3_ip4_config_start = act_stage3_ip4_config_start; parent_class->act_stage3_ip6_config_start = act_stage3_ip6_config_start; parent_class->act_stage4_ip4_config_timeout = act_stage4_ip4_config_timeout;