From 175ef8f611888c23736d0d593e1512ac2770ea48 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sat, 14 Jan 2017 16:36:33 +0100 Subject: ppp: use defines for signal names --- src/devices/adsl/nm-device-adsl.c | 4 ++-- src/devices/nm-device-ethernet.c | 4 ++-- src/devices/nm-device-macvlan.c | 2 +- src/devices/wwan/nm-modem.c | 8 ++++---- src/ppp/nm-ppp-manager.c | 8 ++++---- src/ppp/nm-ppp-manager.h | 6 +++++- 6 files changed, 18 insertions(+), 14 deletions(-) diff --git a/src/devices/adsl/nm-device-adsl.c b/src/devices/adsl/nm-device-adsl.c index 9af6e69035..82974be31c 100644 --- a/src/devices/adsl/nm-device-adsl.c +++ b/src/devices/adsl/nm-device-adsl.c @@ -482,10 +482,10 @@ act_stage3_ip4_config_start (NMDevice *device, && nm_ppp_manager_start (priv->ppp_manager, req, nm_setting_adsl_get_username (s_adsl), 30, 0, &err)) { - g_signal_connect (priv->ppp_manager, NM_PPP_MANAGER_STATE_CHANGED, + g_signal_connect (priv->ppp_manager, NM_PPP_MANAGER_SIGNAL_STATE_CHANGED, G_CALLBACK (ppp_state_changed), self); - g_signal_connect (priv->ppp_manager, "ip4-config", + g_signal_connect (priv->ppp_manager, NM_PPP_MANAGER_SIGNAL_IP4_CONFIG, G_CALLBACK (ppp_ip4_config), self); ret = NM_ACT_STAGE_RETURN_POSTPONE; diff --git a/src/devices/nm-device-ethernet.c b/src/devices/nm-device-ethernet.c index 07f60d05b8..8de4e3bcb5 100644 --- a/src/devices/nm-device-ethernet.c +++ b/src/devices/nm-device-ethernet.c @@ -1055,10 +1055,10 @@ pppoe_stage3_ip4_config_start (NMDeviceEthernet *self, NMDeviceStateReason *reas && nm_ppp_manager_start (priv->ppp_manager, req, nm_setting_pppoe_get_username (s_pppoe), 30, 0, &err)) { - g_signal_connect (priv->ppp_manager, NM_PPP_MANAGER_STATE_CHANGED, + g_signal_connect (priv->ppp_manager, NM_PPP_MANAGER_SIGNAL_STATE_CHANGED, G_CALLBACK (ppp_state_changed), self); - g_signal_connect (priv->ppp_manager, "ip4-config", + g_signal_connect (priv->ppp_manager, NM_PPP_MANAGER_SIGNAL_IP4_CONFIG, G_CALLBACK (ppp_ip4_config), self); ret = NM_ACT_STAGE_RETURN_POSTPONE; diff --git a/src/devices/nm-device-macvlan.c b/src/devices/nm-device-macvlan.c index 9d3c3c370b..6f9879c558 100644 --- a/src/devices/nm-device-macvlan.c +++ b/src/devices/nm-device-macvlan.c @@ -156,7 +156,7 @@ parent_changed_notify (NMDevice *device, if (new_parent) { priv->parent_state_id = g_signal_connect (new_parent, - "state-changed", + NM_DEVICE_STATE_CHANGED, G_CALLBACK (parent_state_changed), device); diff --git a/src/devices/wwan/nm-modem.c b/src/devices/wwan/nm-modem.c index 4a8e9094ad..04c95a2bed 100644 --- a/src/devices/wwan/nm-modem.c +++ b/src/devices/wwan/nm-modem.c @@ -563,16 +563,16 @@ ppp_stage3_ip_config_start (NMModem *self, if ( priv->ppp_manager && nm_ppp_manager_start (priv->ppp_manager, req, ppp_name, ip_timeout, baud_override, &error)) { - g_signal_connect (priv->ppp_manager, NM_PPP_MANAGER_STATE_CHANGED, + g_signal_connect (priv->ppp_manager, NM_PPP_MANAGER_SIGNAL_STATE_CHANGED, G_CALLBACK (ppp_state_changed), self); - g_signal_connect (priv->ppp_manager, "ip4-config", + g_signal_connect (priv->ppp_manager, NM_PPP_MANAGER_SIGNAL_IP4_CONFIG, G_CALLBACK (ppp_ip4_config), self); - g_signal_connect (priv->ppp_manager, "ip6-config", + g_signal_connect (priv->ppp_manager, NM_PPP_MANAGER_SIGNAL_IP6_CONFIG, G_CALLBACK (ppp_ip6_config), self); - g_signal_connect (priv->ppp_manager, "stats", + g_signal_connect (priv->ppp_manager, NM_PPP_MANAGER_SIGNAL_STATS, G_CALLBACK (ppp_stats), self); diff --git a/src/ppp/nm-ppp-manager.c b/src/ppp/nm-ppp-manager.c index cc7451c97b..1bbe29d46b 100644 --- a/src/ppp/nm-ppp-manager.c +++ b/src/ppp/nm-ppp-manager.c @@ -1243,7 +1243,7 @@ nm_ppp_manager_class_init (NMPPPManagerClass *manager_class) g_object_class_install_properties (object_class, _PROPERTY_ENUMS_LAST, obj_properties); signals[STATE_CHANGED] = - g_signal_new (NM_PPP_MANAGER_STATE_CHANGED, + g_signal_new (NM_PPP_MANAGER_SIGNAL_STATE_CHANGED, G_OBJECT_CLASS_TYPE (object_class), G_SIGNAL_RUN_FIRST, 0, @@ -1252,7 +1252,7 @@ nm_ppp_manager_class_init (NMPPPManagerClass *manager_class) G_TYPE_UINT); signals[IP4_CONFIG] = - g_signal_new ("ip4-config", + g_signal_new (NM_PPP_MANAGER_SIGNAL_IP4_CONFIG, G_OBJECT_CLASS_TYPE (object_class), G_SIGNAL_RUN_FIRST, 0, @@ -1262,7 +1262,7 @@ nm_ppp_manager_class_init (NMPPPManagerClass *manager_class) G_TYPE_OBJECT); signals[IP6_CONFIG] = - g_signal_new ("ip6-config", + g_signal_new (NM_PPP_MANAGER_SIGNAL_IP6_CONFIG, G_OBJECT_CLASS_TYPE (object_class), G_SIGNAL_RUN_FIRST, 0, @@ -1270,7 +1270,7 @@ nm_ppp_manager_class_init (NMPPPManagerClass *manager_class) G_TYPE_NONE, 3, G_TYPE_STRING, G_TYPE_POINTER, G_TYPE_OBJECT); signals[STATS] = - g_signal_new ("stats", + g_signal_new (NM_PPP_MANAGER_SIGNAL_STATS, G_OBJECT_CLASS_TYPE (object_class), G_SIGNAL_RUN_FIRST, 0, diff --git a/src/ppp/nm-ppp-manager.h b/src/ppp/nm-ppp-manager.h index a86fe26ae5..b1a7bb609a 100644 --- a/src/ppp/nm-ppp-manager.h +++ b/src/ppp/nm-ppp-manager.h @@ -23,7 +23,11 @@ #define __NM_PPP_MANAGER_H__ #define NM_PPP_MANAGER_PARENT_IFACE "parent-iface" -#define NM_PPP_MANAGER_STATE_CHANGED "state-changed" + +#define NM_PPP_MANAGER_SIGNAL_STATE_CHANGED "state-changed" +#define NM_PPP_MANAGER_SIGNAL_IP4_CONFIG "ip4-config" +#define NM_PPP_MANAGER_SIGNAL_IP6_CONFIG "ip6-config" +#define NM_PPP_MANAGER_SIGNAL_STATS "stats" typedef struct _NMPPPManager NMPPPManager; -- cgit v1.2.3 From 0bb1e9a116dba2f48a08155b1680b6c64c001449 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sun, 15 Jan 2017 12:15:58 +0100 Subject: ip[46]-config/trivial: move code around Move the GObject related functions to the end of the source file. Similar to how it's done for most other implementations. --- src/devices/adsl/nm-device-adsl.c | 2 +- src/devices/bluetooth/nm-bluez-device.c | 2 +- src/devices/bluetooth/nm-bluez4-adapter.c | 2 +- src/dhcp/nm-dhcp-client.c | 2 +- src/nm-auth-manager.c | 2 +- src/nm-config.c | 4 +- src/nm-ip4-config.c | 137 ++++++++++++++++-------------- src/nm-ip6-config.c | 113 ++++++++++++------------ src/platform/nmp-netns.c | 4 +- 9 files changed, 141 insertions(+), 127 deletions(-) diff --git a/src/devices/adsl/nm-device-adsl.c b/src/devices/adsl/nm-device-adsl.c index 82974be31c..53841a7fc2 100644 --- a/src/devices/adsl/nm-device-adsl.c +++ b/src/devices/adsl/nm-device-adsl.c @@ -577,7 +577,7 @@ set_property (GObject *object, guint prop_id, { switch (prop_id) { case PROP_ATM_INDEX: - /* construct only */ + /* construct-only */ NM_DEVICE_ADSL_GET_PRIVATE ((NMDeviceAdsl *) object)->atm_index = g_value_get_int (value); break; default: diff --git a/src/devices/bluetooth/nm-bluez-device.c b/src/devices/bluetooth/nm-bluez-device.c index 4d2e9b1d7e..92b2c91895 100644 --- a/src/devices/bluetooth/nm-bluez-device.c +++ b/src/devices/bluetooth/nm-bluez-device.c @@ -1077,7 +1077,7 @@ set_property (GObject *object, guint prop_id, switch (prop_id) { case PROP_PATH: - /* construct only */ + /* construct-only */ priv->path = g_value_dup_string (value); break; default: diff --git a/src/devices/bluetooth/nm-bluez4-adapter.c b/src/devices/bluetooth/nm-bluez4-adapter.c index b781def3a7..c0c1be30b7 100644 --- a/src/devices/bluetooth/nm-bluez4-adapter.c +++ b/src/devices/bluetooth/nm-bluez4-adapter.c @@ -281,7 +281,7 @@ set_property (GObject *object, guint prop_id, switch (prop_id) { case PROP_PATH: - /* construct only */ + /* construct-only */ priv->path = g_value_dup_string (value); break; default: diff --git a/src/dhcp/nm-dhcp-client.c b/src/dhcp/nm-dhcp-client.c index 31eb8276c5..ba7c6dbf0e 100644 --- a/src/dhcp/nm-dhcp-client.c +++ b/src/dhcp/nm-dhcp-client.c @@ -851,7 +851,7 @@ set_property (GObject *object, guint prop_id, g_warn_if_fail (priv->ifindex > 0); break; case PROP_HWADDR: - /* construct only */ + /* construct-only */ priv->hwaddr = g_value_dup_boxed (value); break; case PROP_IPV6: diff --git a/src/nm-auth-manager.c b/src/nm-auth-manager.c index 73063b9b92..4359d8f187 100644 --- a/src/nm-auth-manager.c +++ b/src/nm-auth-manager.c @@ -509,7 +509,7 @@ set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *p switch (prop_id) { case PROP_POLKIT_ENABLED: - /* construct only */ + /* construct-only */ priv->polkit_enabled = !!g_value_get_boolean (value); break; default: diff --git a/src/nm-config.c b/src/nm-config.c index 2d61b92961..87d0c8a7b9 100644 --- a/src/nm-config.c +++ b/src/nm-config.c @@ -2232,7 +2232,7 @@ set_property (GObject *object, guint prop_id, switch (prop_id) { case PROP_CMD_LINE_OPTIONS: - /* construct only */ + /* construct-only */ cli = g_value_get_pointer (value); if (!cli) _nm_config_cmd_line_options_clear (&priv->cli); @@ -2240,7 +2240,7 @@ set_property (GObject *object, guint prop_id, _nm_config_cmd_line_options_copy (cli, &priv->cli); break; case PROP_ATOMIC_SECTION_PREFIXES: - /* construct only */ + /* construct-only */ priv->atomic_section_prefixes = g_strdupv (g_value_get_boxed (value)); break; default: diff --git a/src/nm-ip4-config.c b/src/nm-ip4-config.c index 2bd0d36cb3..310ce41943 100644 --- a/src/nm-ip4-config.c +++ b/src/nm-ip4-config.c @@ -35,6 +35,29 @@ #include "introspection/org.freedesktop.NetworkManager.IP4Config.h" +/*****************************************************************************/ + +/* internal guint32 are assigned to gobject properties of type uint. Ensure, that uint is large enough */ +G_STATIC_ASSERT (sizeof (uint) >= sizeof (guint32)); +G_STATIC_ASSERT (G_MAXUINT >= 0xFFFFFFFF); + +/*****************************************************************************/ + +NM_GOBJECT_PROPERTIES_DEFINE (NMIP4Config, + PROP_IFINDEX, + PROP_ADDRESS_DATA, + PROP_ADDRESSES, + PROP_ROUTE_DATA, + PROP_ROUTES, + PROP_GATEWAY, + PROP_NAMESERVERS, + PROP_DOMAINS, + PROP_SEARCHES, + PROP_DNS_OPTIONS, + PROP_WINS_SERVERS, + PROP_DNS_PRIORITY, +); + typedef struct { gboolean never_default; guint32 gateway; @@ -72,33 +95,7 @@ G_DEFINE_TYPE (NMIP4Config, nm_ip4_config, NM_TYPE_EXPORTED_OBJECT) #define NM_IP4_CONFIG_GET_PRIVATE(self) _NM_GET_PRIVATE(self, NMIP4Config, NM_IS_IP4_CONFIG) -/* internal guint32 are assigned to gobject properties of type uint. Ensure, that uint is large enough */ -G_STATIC_ASSERT (sizeof (uint) >= sizeof (guint32)); -G_STATIC_ASSERT (G_MAXUINT >= 0xFFFFFFFF); - -NM_GOBJECT_PROPERTIES_DEFINE (NMIP4Config, - PROP_IFINDEX, - PROP_ADDRESS_DATA, - PROP_ADDRESSES, - PROP_ROUTE_DATA, - PROP_ROUTES, - PROP_GATEWAY, - PROP_NAMESERVERS, - PROP_DOMAINS, - PROP_SEARCHES, - PROP_DNS_OPTIONS, - PROP_WINS_SERVERS, - PROP_DNS_PRIORITY, -); - -NMIP4Config * -nm_ip4_config_new (int ifindex) -{ - g_return_val_if_fail (ifindex >= -1, NULL); - return (NMIP4Config *) g_object_new (NM_TYPE_IP4_CONFIG, - NM_IP4_CONFIG_IFINDEX, ifindex, - NULL); -} +/*****************************************************************************/ int nm_ip4_config_get_ifindex (const NMIP4Config *config) @@ -2233,43 +2230,6 @@ nm_ip4_config_equal (const NMIP4Config *a, const NMIP4Config *b) /*****************************************************************************/ -static void -nm_ip4_config_init (NMIP4Config *config) -{ - NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (config); - - priv->addresses = g_array_new (FALSE, FALSE, sizeof (NMPlatformIP4Address)); - priv->routes = g_array_new (FALSE, FALSE, sizeof (NMPlatformIP4Route)); - priv->nameservers = g_array_new (FALSE, FALSE, sizeof (guint32)); - priv->domains = g_ptr_array_new_with_free_func (g_free); - priv->searches = g_ptr_array_new_with_free_func (g_free); - priv->dns_options = g_ptr_array_new_with_free_func (g_free); - priv->nis = g_array_new (FALSE, TRUE, sizeof (guint32)); - priv->wins = g_array_new (FALSE, TRUE, sizeof (guint32)); - priv->route_metric = -1; -} - -static void -finalize (GObject *object) -{ - NMIP4Config *self = NM_IP4_CONFIG (object); - NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (self); - - nm_clear_g_variant (&priv->address_data_variant); - nm_clear_g_variant (&priv->addresses_variant); - g_array_unref (priv->addresses); - g_array_unref (priv->routes); - g_array_unref (priv->nameservers); - g_ptr_array_unref (priv->domains); - g_ptr_array_unref (priv->searches); - g_ptr_array_unref (priv->dns_options); - g_array_unref (priv->nis); - g_free (priv->nis_domain); - g_array_unref (priv->wins); - - G_OBJECT_CLASS (nm_ip4_config_parent_class)->finalize (object); -} - static void get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) @@ -2459,6 +2419,7 @@ set_property (GObject *object, switch (prop_id) { case PROP_IFINDEX: + /* construct-only */ priv->ifindex = g_value_get_int (value); break; default: @@ -2467,6 +2428,54 @@ set_property (GObject *object, } } +/*****************************************************************************/ + +static void +nm_ip4_config_init (NMIP4Config *config) +{ + NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (config); + + priv->addresses = g_array_new (FALSE, FALSE, sizeof (NMPlatformIP4Address)); + priv->routes = g_array_new (FALSE, FALSE, sizeof (NMPlatformIP4Route)); + priv->nameservers = g_array_new (FALSE, FALSE, sizeof (guint32)); + priv->domains = g_ptr_array_new_with_free_func (g_free); + priv->searches = g_ptr_array_new_with_free_func (g_free); + priv->dns_options = g_ptr_array_new_with_free_func (g_free); + priv->nis = g_array_new (FALSE, TRUE, sizeof (guint32)); + priv->wins = g_array_new (FALSE, TRUE, sizeof (guint32)); + priv->route_metric = -1; +} + +NMIP4Config * +nm_ip4_config_new (int ifindex) +{ + g_return_val_if_fail (ifindex >= -1, NULL); + return (NMIP4Config *) g_object_new (NM_TYPE_IP4_CONFIG, + NM_IP4_CONFIG_IFINDEX, ifindex, + NULL); +} + +static void +finalize (GObject *object) +{ + NMIP4Config *self = NM_IP4_CONFIG (object); + NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (self); + + nm_clear_g_variant (&priv->address_data_variant); + nm_clear_g_variant (&priv->addresses_variant); + g_array_unref (priv->addresses); + g_array_unref (priv->routes); + g_array_unref (priv->nameservers); + g_ptr_array_unref (priv->domains); + g_ptr_array_unref (priv->searches); + g_ptr_array_unref (priv->dns_options); + g_array_unref (priv->nis); + g_free (priv->nis_domain); + g_array_unref (priv->wins); + + G_OBJECT_CLASS (nm_ip4_config_parent_class)->finalize (object); +} + static void nm_ip4_config_class_init (NMIP4ConfigClass *config_class) { diff --git a/src/nm-ip6-config.c b/src/nm-ip6-config.c index 713e2c12a0..2e6faf5617 100644 --- a/src/nm-ip6-config.c +++ b/src/nm-ip6-config.c @@ -35,6 +35,8 @@ #include "introspection/org.freedesktop.NetworkManager.IP6Config.h" +/*****************************************************************************/ + typedef struct { gboolean never_default; struct in6_addr gateway; @@ -80,26 +82,7 @@ NM_GOBJECT_PROPERTIES_DEFINE (NMIP6Config, PROP_DNS_PRIORITY, ); -NMIP6Config * -nm_ip6_config_new (int ifindex) -{ - g_return_val_if_fail (ifindex >= -1, NULL); - return (NMIP6Config *) g_object_new (NM_TYPE_IP6_CONFIG, - NM_IP6_CONFIG_IFINDEX, ifindex, - NULL); -} - -NMIP6Config * -nm_ip6_config_new_cloned (const NMIP6Config *src) -{ - NMIP6Config *new; - - g_return_val_if_fail (NM_IS_IP6_CONFIG (src), NULL); - - new = nm_ip6_config_new (nm_ip6_config_get_ifindex (src)); - nm_ip6_config_replace (new, src, NULL); - return new; -} +/*****************************************************************************/ int nm_ip6_config_get_ifindex (const NMIP6Config *config) @@ -1999,38 +1982,6 @@ nm_ip6_config_equal (const NMIP6Config *a, const NMIP6Config *b) /*****************************************************************************/ -static void -nm_ip6_config_init (NMIP6Config *config) -{ - NMIP6ConfigPrivate *priv = NM_IP6_CONFIG_GET_PRIVATE (config); - - priv->addresses = g_array_new (FALSE, TRUE, sizeof (NMPlatformIP6Address)); - priv->routes = g_array_new (FALSE, TRUE, sizeof (NMPlatformIP6Route)); - priv->nameservers = g_array_new (FALSE, TRUE, sizeof (struct in6_addr)); - priv->domains = g_ptr_array_new_with_free_func (g_free); - priv->searches = g_ptr_array_new_with_free_func (g_free); - priv->dns_options = g_ptr_array_new_with_free_func (g_free); - priv->route_metric = -1; -} - -static void -finalize (GObject *object) -{ - NMIP6Config *self = NM_IP6_CONFIG (object); - NMIP6ConfigPrivate *priv = NM_IP6_CONFIG_GET_PRIVATE (self); - - g_array_unref (priv->addresses); - g_array_unref (priv->routes); - g_array_unref (priv->nameservers); - g_ptr_array_unref (priv->domains); - g_ptr_array_unref (priv->searches); - g_ptr_array_unref (priv->dns_options); - nm_clear_g_variant (&priv->address_data_variant); - nm_clear_g_variant (&priv->addresses_variant); - - G_OBJECT_CLASS (nm_ip6_config_parent_class)->finalize (object); -} - static void nameservers_to_gvalue (GArray *array, GValue *value) { @@ -2223,6 +2174,7 @@ set_property (GObject *object, switch (prop_id) { case PROP_IFINDEX: + /* construct-only */ priv->ifindex = g_value_get_int (value); break; default: @@ -2231,6 +2183,61 @@ set_property (GObject *object, } } +/*****************************************************************************/ + +static void +nm_ip6_config_init (NMIP6Config *config) +{ + NMIP6ConfigPrivate *priv = NM_IP6_CONFIG_GET_PRIVATE (config); + + priv->addresses = g_array_new (FALSE, TRUE, sizeof (NMPlatformIP6Address)); + priv->routes = g_array_new (FALSE, TRUE, sizeof (NMPlatformIP6Route)); + priv->nameservers = g_array_new (FALSE, TRUE, sizeof (struct in6_addr)); + priv->domains = g_ptr_array_new_with_free_func (g_free); + priv->searches = g_ptr_array_new_with_free_func (g_free); + priv->dns_options = g_ptr_array_new_with_free_func (g_free); + priv->route_metric = -1; +} + +NMIP6Config * +nm_ip6_config_new (int ifindex) +{ + g_return_val_if_fail (ifindex >= -1, NULL); + return (NMIP6Config *) g_object_new (NM_TYPE_IP6_CONFIG, + NM_IP6_CONFIG_IFINDEX, ifindex, + NULL); +} + +NMIP6Config * +nm_ip6_config_new_cloned (const NMIP6Config *src) +{ + NMIP6Config *new; + + g_return_val_if_fail (NM_IS_IP6_CONFIG (src), NULL); + + new = nm_ip6_config_new (nm_ip6_config_get_ifindex (src)); + nm_ip6_config_replace (new, src, NULL); + return new; +} + +static void +finalize (GObject *object) +{ + NMIP6Config *self = NM_IP6_CONFIG (object); + NMIP6ConfigPrivate *priv = NM_IP6_CONFIG_GET_PRIVATE (self); + + g_array_unref (priv->addresses); + g_array_unref (priv->routes); + g_array_unref (priv->nameservers); + g_ptr_array_unref (priv->domains); + g_ptr_array_unref (priv->searches); + g_ptr_array_unref (priv->dns_options); + nm_clear_g_variant (&priv->address_data_variant); + nm_clear_g_variant (&priv->addresses_variant); + + G_OBJECT_CLASS (nm_ip6_config_parent_class)->finalize (object); +} + static void nm_ip6_config_class_init (NMIP6ConfigClass *config_class) { @@ -2239,12 +2246,10 @@ nm_ip6_config_class_init (NMIP6ConfigClass *config_class) exported_object_class->export_path = NM_EXPORT_PATH_NUMBERED (NM_DBUS_PATH"/IP6Config"); - /* virtual methods */ object_class->get_property = get_property; object_class->set_property = set_property; object_class->finalize = finalize; - /* properties */ obj_properties[PROP_IFINDEX] = g_param_spec_int (NM_IP6_CONFIG_IFINDEX, "", "", -1, G_MAXINT, -1, diff --git a/src/platform/nmp-netns.c b/src/platform/nmp-netns.c index 232c6efc9e..c9c6850d54 100644 --- a/src/platform/nmp-netns.c +++ b/src/platform/nmp-netns.c @@ -676,12 +676,12 @@ set_property (GObject *object, guint prop_id, switch (prop_id) { case PROP_FD_NET: - /* construct only */ + /* construct-only */ priv->fd_net = g_value_get_int (value); g_return_if_fail (priv->fd_net > 0); break; case PROP_FD_MNT: - /* construct only */ + /* construct-only */ priv->fd_mnt = g_value_get_int (value); g_return_if_fail (priv->fd_mnt > 0); break; -- cgit v1.2.3 From 2802e823fc6b8618aada9f52ccc93137dfd5d16d Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sun, 15 Jan 2017 12:33:10 +0100 Subject: ip[46]-config: reorder fields in private struct and use bool bitfield bool:1 bitfields allow for tighter packing and are guaranteed to be strictly 0 or 1 (contrary to gboolean's typedef for int). Not that it matters too much, but it's favorable. Especially, because each device has several of these ip-config instances, we might save a few bytes for no(?) downsides. --- src/nm-ip4-config.c | 22 +++++++++++----------- src/nm-ip6-config.c | 14 +++++++------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/nm-ip4-config.c b/src/nm-ip4-config.c index 310ce41943..ea6468bbb3 100644 --- a/src/nm-ip4-config.c +++ b/src/nm-ip4-config.c @@ -59,25 +59,25 @@ NM_GOBJECT_PROPERTIES_DEFINE (NMIP4Config, ); typedef struct { - gboolean never_default; + bool never_default:1; + bool metered:1; + bool has_gateway:1; guint32 gateway; - gboolean has_gateway; + guint32 mss; + guint32 mtu; + int ifindex; + NMIPConfigSource mtu_source; + gint dns_priority; + gint64 route_metric; GArray *addresses; GArray *routes; GArray *nameservers; GPtrArray *domains; GPtrArray *searches; GPtrArray *dns_options; - guint32 mss; GArray *nis; char *nis_domain; GArray *wins; - guint32 mtu; - NMIPConfigSource mtu_source; - int ifindex; - gint64 route_metric; - gboolean metered; - gint dns_priority; GVariant *address_data_variant; GVariant *addresses_variant; } NMIP4ConfigPrivate; @@ -1382,7 +1382,7 @@ nm_ip4_config_set_never_default (NMIP4Config *config, gboolean never_default) { NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (config); - priv->never_default = !!never_default; + priv->never_default = never_default; } gboolean @@ -2110,7 +2110,7 @@ nm_ip4_config_set_metered (NMIP4Config *config, gboolean metered) { NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (config); - priv->metered = !!metered; + priv->metered = metered; } gboolean diff --git a/src/nm-ip6-config.c b/src/nm-ip6-config.c index 2e6faf5617..c90d04aa5e 100644 --- a/src/nm-ip6-config.c +++ b/src/nm-ip6-config.c @@ -38,7 +38,12 @@ /*****************************************************************************/ typedef struct { - gboolean never_default; + bool never_default:1; + guint32 mss; + int ifindex; + int dns_priority; + NMSettingIP6ConfigPrivacy privacy; + gint64 route_metric; struct in6_addr gateway; GArray *addresses; GArray *routes; @@ -46,13 +51,8 @@ typedef struct { GPtrArray *domains; GPtrArray *searches; GPtrArray *dns_options; - guint32 mss; - int ifindex; - gint64 route_metric; - gint dns_priority; GVariant *address_data_variant; GVariant *addresses_variant; - NMSettingIP6ConfigPrivacy privacy; } NMIP6ConfigPrivate; struct _NMIP6Config { @@ -1239,7 +1239,7 @@ nm_ip6_config_set_never_default (NMIP6Config *config, gboolean never_default) { NMIP6ConfigPrivate *priv = NM_IP6_CONFIG_GET_PRIVATE (config); - priv->never_default = !!never_default; + priv->never_default = never_default; } gboolean -- cgit v1.2.3 From f0cd2403d4bd16168c1e43e367e2e8e9b8297d55 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sat, 14 Jan 2017 12:51:01 +0100 Subject: device: fix sysctl getter for MTU using guint32 type The only caller wants to read the MTU, which is more type guint32 then gint32. --- src/devices/nm-device.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c index fe5e930e41..0cd5007ee6 100644 --- a/src/devices/nm-device.c +++ b/src/devices/nm-device.c @@ -643,9 +643,14 @@ nm_device_ipv6_sysctl_set (NMDevice *self, const char *property, const char *val } static guint32 -nm_device_ipv6_sysctl_get_int32 (NMDevice *self, const char *property, gint32 fallback) +nm_device_ipv6_sysctl_get_uint32 (NMDevice *self, const char *property, guint32 fallback) { - return nm_platform_sysctl_get_int32 (NM_PLATFORM_GET, NMP_SYSCTL_PATHID_ABSOLUTE (nm_utils_ip6_property_path (nm_device_get_ip_iface (self), property)), fallback); + return nm_platform_sysctl_get_int_checked (NM_PLATFORM_GET, + NMP_SYSCTL_PATHID_ABSOLUTE (nm_utils_ip6_property_path (nm_device_get_ip_iface (self), property)), + 10, + 0, + G_MAXUINT32, + fallback); } gboolean @@ -6635,7 +6640,7 @@ nm_device_ipv6_set_mtu (NMDevice *self, guint32 mtu) { NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self); guint32 ip_mtu = get_ip_mtu (self); - guint32 plat_mtu = nm_device_ipv6_sysctl_get_int32 (self, "mtu", ip_mtu); + guint32 plat_mtu = nm_device_ipv6_sysctl_get_uint32 (self, "mtu", ip_mtu); priv->ip6_mtu = mtu ?: plat_mtu; -- cgit v1.2.3 From c69ad50b0784683647f337bd05a667f9c969ae15 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 13 Jan 2017 17:13:24 +0100 Subject: device: fix indention and assertion in apply_mtu_from_config() For the assertion use nm_streq0(). If we bother checking for invalid values (that are supposed to never happen), avoid a possible crash too. --- src/devices/nm-device.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c index 0cd5007ee6..3d3525e00d 100644 --- a/src/devices/nm-device.c +++ b/src/devices/nm-device.c @@ -1648,14 +1648,13 @@ apply_mtu_from_config (NMDevice *self) * stage, so it is an error to call this function if the IPv4 method is not * 'disabled'. */ - s_ip4 = (NMSettingIPConfig *) - nm_device_get_applied_setting (self, NM_TYPE_SETTING_IP4_CONFIG); + s_ip4 = (NMSettingIPConfig *) nm_device_get_applied_setting (self, NM_TYPE_SETTING_IP4_CONFIG); if (s_ip4) method = nm_setting_ip_config_get_method (s_ip4); - g_return_if_fail (nm_streq (method, NM_SETTING_IP4_CONFIG_METHOD_DISABLED)); - s_wired = (NMSettingWired *) - nm_device_get_applied_setting (self, NM_TYPE_SETTING_WIRED); + g_return_if_fail (nm_streq0 (method, NM_SETTING_IP4_CONFIG_METHOD_DISABLED)); + + s_wired = (NMSettingWired *) nm_device_get_applied_setting (self, NM_TYPE_SETTING_WIRED); if (s_wired) { mtu = nm_setting_wired_get_mtu (s_wired); -- cgit v1.2.3 From 5051a04d818894453171df390861df19b1eac2ab Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sat, 14 Jan 2017 22:50:26 +0100 Subject: device: drop unused virtual function NMDevice:ip6_config_pre_commit --- src/devices/nm-device.c | 3 --- src/devices/nm-device.h | 1 - 2 files changed, 4 deletions(-) diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c index 3d3525e00d..4c93c0e26b 100644 --- a/src/devices/nm-device.c +++ b/src/devices/nm-device.c @@ -5948,9 +5948,6 @@ END_ADD_DEFAULT_ROUTE: nm_device_get_ip_ifindex (self), iid); } - - if (NM_DEVICE_GET_CLASS (self)->ip6_config_pre_commit) - NM_DEVICE_GET_CLASS (self)->ip6_config_pre_commit (self, composite); } routes_full_sync = commit diff --git a/src/devices/nm-device.h b/src/devices/nm-device.h index 904c7d2390..a3a7c51540 100644 --- a/src/devices/nm-device.h +++ b/src/devices/nm-device.h @@ -277,7 +277,6 @@ typedef struct { /* Called right before IP config is set; use for setting MTU etc */ void (* ip4_config_pre_commit) (NMDevice *self, NMIP4Config *config); - void (* ip6_config_pre_commit) (NMDevice *self, NMIP6Config *config); /* Async deactivating (in the DEACTIVATING phase) */ void (* deactivate_async) (NMDevice *self, -- cgit v1.2.3 From be4442bd0dc3d846272ed1891771a41cc6c420c7 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 13 Jan 2017 15:55:48 +0100 Subject: device: cleanup setting of mtu in NMDevice Mark priv->mtu/priv->ip_mtu/ priv->ip6_mtu as const to highlight the places that explicitly set their mutable aliases priv->mtu_/ priv->ip_mtu_/priv->ip6_mtu_. Also, NM_DEVICE_MTU property is read-only. It cannot be set via g_object_set(). Also, clear priv->mtu in nm_device_unrealize(). --- src/devices/nm-device.c | 54 ++++++++++++++++++++++++++++--------------------- 1 file changed, 31 insertions(+), 23 deletions(-) diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c index 4c93c0e26b..b8a9fb57be 100644 --- a/src/devices/nm-device.c +++ b/src/devices/nm-device.c @@ -307,6 +307,7 @@ typedef struct _NMDevicePrivate { gulong ignore_carrier_id; guint32 mtu; guint32 ip_mtu; + guint32 ip6_mtu; bool up; /* IFF_UP */ /* Generic DHCP stuff */ @@ -383,7 +384,6 @@ typedef struct _NMDevicePrivate { NMIP6Config * ext_ip6_config_captured; /* Configuration captured from platform. */ GSList * vpn6_configs; /* VPNs which use this device */ bool nm_ipv6ll; /* TRUE if NM handles the device's IPv6LL address */ - guint32 ip6_mtu; NMIP6Config * dad6_ip6_config; NMNDisc * ndisc; @@ -2175,7 +2175,6 @@ device_link_changed (NMDevice *self) _notify (self, PROP_DRIVER); } - /* Update MTU if it has changed. */ if (priv->mtu != info.mtu) { priv->mtu = info.mtu; _notify (self, PROP_MTU); @@ -2322,8 +2321,7 @@ device_ip_link_changed (NMDevice *self) _stats_update_counters_from_pllink (self, pllink); - if (priv->ip_mtu != pllink->mtu) - priv->ip_mtu = pllink->mtu; + priv->ip_mtu = pllink->mtu; if (_ip_iface_update (self, pllink->name)) nm_device_update_dynamic_ip_setup (self); @@ -2588,6 +2586,7 @@ realize_start_setup (NMDevice *self, const NMPlatformLink *plink) NMDeviceCapabilities capabilities = 0; NMConfig *config; guint real_rate; + guint32 mtu; g_return_if_fail (NM_IS_DEVICE (self)); @@ -2608,6 +2607,13 @@ realize_start_setup (NMDevice *self, const NMPlatformLink *plink) /* Balanced by a thaw in nm_device_realize_finish() */ g_object_freeze_notify (G_OBJECT (self)); + priv->ip6_mtu = 0; + priv->ip_mtu = 0; + if (priv->mtu) { + priv->mtu = 0; + _notify (self, PROP_MTU); + } + if (plink) { g_return_if_fail (link_type_compatible (self, plink->type, NULL, NULL)); update_device_from_platform_link (self, plink); @@ -2623,8 +2629,11 @@ realize_start_setup (NMDevice *self, const NMPlatformLink *plink) if (nm_platform_link_is_software (NM_PLATFORM_GET, priv->ifindex)) capabilities |= NM_DEVICE_CAP_IS_SOFTWARE; - priv->mtu = nm_platform_link_get_mtu (NM_PLATFORM_GET, priv->ifindex); - _notify (self, PROP_MTU); + mtu = nm_platform_link_get_mtu (NM_PLATFORM_GET, priv->ifindex); + if (priv->mtu != mtu) { + priv->mtu = mtu; + _notify (self, PROP_MTU); + } nm_platform_link_get_driver_info (NM_PLATFORM_GET, priv->ifindex, @@ -2835,6 +2844,11 @@ nm_device_unrealize (NMDevice *self, gboolean remove_resources, GError **error) if (nm_clear_g_free (&priv->ip_iface)) _notify (self, PROP_IP_IFACE); + if (priv->mtu != 0) { + priv->mtu = 0; + _notify (self, PROP_MTU); + } + if (priv->driver_version) { g_clear_pointer (&priv->driver_version, g_free); _notify (self, PROP_DRIVER_VERSION); @@ -6590,23 +6604,12 @@ linklocal6_start (NMDevice *self) static void nm_device_ipv6_set_mtu (NMDevice *self, guint32 mtu); -static void -set_ip_mtu (NMDevice *self, guint32 mtu) -{ - NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self); - - if (priv->ip_ifindex) - priv->ip_mtu = mtu; - else - priv->mtu = mtu; -} - static guint32 get_ip_mtu (NMDevice *self) { NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self); - if (priv->ip_ifindex) + if (priv->ip_ifindex > 0) return priv->ip_mtu; else return priv->mtu; @@ -6619,8 +6622,16 @@ nm_device_set_mtu (NMDevice *self, guint32 mtu) int ifindex = nm_device_get_ip_ifindex (self); guint32 ip_mtu; - if (mtu) - set_ip_mtu (self, mtu); + if (mtu) { + if (priv->ip_ifindex > 0) + priv->ip_mtu = mtu; + else { + if (priv->mtu != mtu) { + priv->mtu = mtu; + _notify (self, PROP_MTU); + } + } + } /* Ensure the IPv6 MTU is still alright. */ if (priv->ip6_mtu) @@ -13083,9 +13094,6 @@ set_property (GObject *object, guint prop_id, g_free (priv->firmware_version); priv->firmware_version = g_value_dup_string (value); break; - case PROP_MTU: - priv->mtu = g_value_get_uint (value); - break; case PROP_IP4_ADDRESS: priv->ip4_address = g_value_get_uint (value); break; -- cgit v1.2.3 From 0210754f18454353f58223a277831a973da3d435 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 13 Jan 2017 18:40:50 +0100 Subject: device: refactor handling of MTU in device The field priv->mtu should contain what is actually configured on the device, as that field is also exposed on D-Bus as NM_DEVICE_MTU property. That shall be handled distinct from what we want to configure as MTU on the device. Refactor the handling of MTU with a new functoin _set_mtu() which looks at the desired paramters and compares it with what is configured (in platform and sysctl). Then it makes a decision what to configure. --- src/devices/nm-device.c | 129 ++++++++++++++++++++---------------------------- 1 file changed, 53 insertions(+), 76 deletions(-) diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c index b8a9fb57be..f0da55e129 100644 --- a/src/devices/nm-device.c +++ b/src/devices/nm-device.c @@ -306,8 +306,8 @@ typedef struct _NMDevicePrivate { bool ignore_carrier; gulong ignore_carrier_id; guint32 mtu; - guint32 ip_mtu; guint32 ip6_mtu; + guint32 mtu_desired; bool up; /* IFF_UP */ /* Generic DHCP stuff */ @@ -915,9 +915,6 @@ nm_device_set_ip_iface (NMDevice *self, const char *iface) /* We don't care about any saved values from the old iface */ g_hash_table_remove_all (priv->ip6_saved_properties); - if (priv->ip_ifindex) - priv->ip_mtu = nm_platform_link_get_mtu (NM_PLATFORM_GET, priv->ip_ifindex); - _notify (self, PROP_IP_IFACE); return TRUE; } @@ -1642,7 +1639,6 @@ apply_mtu_from_config (NMDevice *self) const char *method = NM_SETTING_IP4_CONFIG_METHOD_DISABLED; NMSettingIPConfig *s_ip4; NMSettingWired *s_wired; - guint32 mtu; /* Devices having an IPv4 configuration will set MTU during the commit * stage, so it is an error to call this function if the IPv4 method is not @@ -1656,15 +1652,8 @@ apply_mtu_from_config (NMDevice *self) s_wired = (NMSettingWired *) nm_device_get_applied_setting (self, NM_TYPE_SETTING_WIRED); - if (s_wired) { - mtu = nm_setting_wired_get_mtu (s_wired); - if (mtu) { - _LOGD (LOGD_DEVICE | LOGD_IP, - "setting MTU of device without IP4 config to %u", - mtu); - nm_device_set_mtu (self, mtu); - } - } + if (s_wired) + nm_device_set_mtu (self, nm_setting_wired_get_mtu (s_wired)); } /** @@ -2321,8 +2310,6 @@ device_ip_link_changed (NMDevice *self) _stats_update_counters_from_pllink (self, pllink); - priv->ip_mtu = pllink->mtu; - if (_ip_iface_update (self, pllink->name)) nm_device_update_dynamic_ip_setup (self); @@ -2608,7 +2595,7 @@ realize_start_setup (NMDevice *self, const NMPlatformLink *plink) g_object_freeze_notify (G_OBJECT (self)); priv->ip6_mtu = 0; - priv->ip_mtu = 0; + priv->mtu_desired = 0; if (priv->mtu) { priv->mtu = 0; _notify (self, PROP_MTU); @@ -6602,79 +6589,65 @@ linklocal6_start (NMDevice *self) /*****************************************************************************/ -static void nm_device_ipv6_set_mtu (NMDevice *self, guint32 mtu); - -static guint32 -get_ip_mtu (NMDevice *self) +static void +_set_mtu (NMDevice *self) { NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self); + guint32 ip6_mtu; + guint32 mtu_desired; + guint32 mtu_plat; + int ifindex; + char sbuf[64]; - if (priv->ip_ifindex > 0) - return priv->ip_mtu; - else - return priv->mtu; -} + ifindex = nm_device_get_ip_ifindex (self); + if (ifindex <= 0) + return; -static void -nm_device_set_mtu (NMDevice *self, guint32 mtu) -{ - NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self); - int ifindex = nm_device_get_ip_ifindex (self); - guint32 ip_mtu; + ip6_mtu = priv->ip6_mtu; + mtu_desired = priv->mtu_desired; - if (mtu) { - if (priv->ip_ifindex > 0) - priv->ip_mtu = mtu; - else { - if (priv->mtu != mtu) { - priv->mtu = mtu; - _notify (self, PROP_MTU); - } - } - } + if (!ip6_mtu && !mtu_desired) + return; - /* Ensure the IPv6 MTU is still alright. */ - if (priv->ip6_mtu) - nm_device_ipv6_set_mtu (self, priv->ip6_mtu); + mtu_plat = nm_platform_link_get_mtu (NM_PLATFORM_GET, ifindex); - ip_mtu = get_ip_mtu (self); - if (ip_mtu && ip_mtu != nm_platform_link_get_mtu (NM_PLATFORM_GET, ifindex)) - nm_platform_link_set_mtu (NM_PLATFORM_GET, ifindex, ip_mtu); -} + if (ip6_mtu) { + ip6_mtu = NM_MAX (1280, ip6_mtu); -static void -nm_device_ipv6_set_mtu (NMDevice *self, guint32 mtu) -{ - NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self); - guint32 ip_mtu = get_ip_mtu (self); - guint32 plat_mtu = nm_device_ipv6_sysctl_get_uint32 (self, "mtu", ip_mtu); + if (!mtu_desired) + mtu_desired = mtu_plat; - priv->ip6_mtu = mtu ?: plat_mtu; + if (mtu_desired) { + mtu_desired = NM_MAX (1280, mtu_desired); - if (priv->ip6_mtu && ip_mtu && ip_mtu < priv->ip6_mtu) { - _LOGI (LOGD_DEVICE | LOGD_IP6, "Lowering IPv6 MTU (%d) to match device MTU (%d)", - priv->ip6_mtu, ip_mtu); - priv->ip6_mtu = ip_mtu; + if (mtu_desired < ip6_mtu) + ip6_mtu = mtu_desired; + } } - if (priv->ip6_mtu && priv->ip6_mtu < 1280) { - _LOGI (LOGD_DEVICE | LOGD_IP6, "IPv6 MTU (%d) smaller than 1280, adjusting", - priv->ip6_mtu); - priv->ip6_mtu = 1280; + if (mtu_desired) { + if (mtu_desired != mtu_plat) + nm_platform_link_set_mtu (NM_PLATFORM_GET, ifindex, mtu_desired); } - if (priv->ip6_mtu && ip_mtu && ip_mtu < priv->ip6_mtu) { - _LOGI (LOGD_DEVICE | LOGD_IP6, "Raising device MTU (%d) to match IPv6 MTU (%d)", - ip_mtu, priv->ip6_mtu); - nm_device_set_mtu (self, priv->ip6_mtu); + if (ip6_mtu) { + if (ip6_mtu != nm_device_ipv6_sysctl_get_uint32 (self, "mtu", 0)) { + nm_device_ipv6_sysctl_set (self, "mtu", + nm_sprintf_buf (sbuf, "%u", (unsigned) ip6_mtu)); + } } +} - if (priv->ip6_mtu != plat_mtu) { - char val[64]; +static void +nm_device_set_mtu (NMDevice *self, guint32 mtu) +{ + NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self); - nm_device_ipv6_sysctl_set (self, "mtu", - nm_sprintf_buf (val, "%u", (unsigned) mtu)); + if (priv->mtu_desired != mtu) { + _LOGD (LOGD_DEVICE, "mtu: set MTU to %u", (unsigned) mtu); + priv->mtu_desired = mtu; } + _set_mtu (self); } static void @@ -6800,8 +6773,12 @@ ndisc_config_changed (NMNDisc *ndisc, const NMNDiscData *rdata, guint changed_in if (changed & NM_NDISC_CONFIG_HOP_LIMIT) nm_platform_sysctl_set_ip6_hop_limit_safe (NM_PLATFORM_GET, nm_device_get_ip_iface (self), rdata->hop_limit); - if (changed & NM_NDISC_CONFIG_MTU) - priv->ip6_mtu = rdata->mtu; + if (changed & NM_NDISC_CONFIG_MTU) { + if (priv->ip6_mtu != rdata->mtu) { + _LOGD (LOGD_DEVICE, "mtu: set IPv6 MTU to %u", (guint) rdata->mtu); + priv->ip6_mtu = rdata->mtu; + } + } nm_device_activate_schedule_ip6_config_result (self); } @@ -7217,7 +7194,7 @@ act_stage3_ip6_config_start (NMDevice *self, * including LL, which * would make it impossible to autoconfigure MTU to a * correct value. */ if (!nm_device_uses_assumed_connection (self)) - nm_device_ipv6_set_mtu (self, priv->ip6_mtu); + _set_mtu (self); /* Any method past this point requires an IPv6LL address. Use NM-controlled * IPv6LL if this is not an assumed connection, since assumed connections @@ -9262,7 +9239,7 @@ nm_device_set_ip6_config (NMDevice *self, /* Always commit to nm-platform to update lifetimes */ if (commit && new_config) { - nm_device_ipv6_set_mtu (self, priv->ip6_mtu); + _set_mtu (self); success = nm_ip6_config_commit (new_config, ip_ifindex, routes_full_sync); -- cgit v1.2.3 From 6e52efe950783751f57cf97e31eb47046e58f498 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sat, 14 Jan 2017 17:04:17 +0100 Subject: device: refactor setting user-configured MTU during config commit Instead of overwriting ip4_config_pre_commit(), add a new function get_mtu(). This also adds a default value in case there is no user-configuration. This will allow us later to reset a default MTU based on the device type. --- src/devices/nm-device-bond.c | 21 +------------------- src/devices/nm-device-ethernet.c | 22 +++++---------------- src/devices/nm-device-infiniband.c | 26 ++++++++++++------------- src/devices/nm-device-ip-tunnel.c | 26 ++++++++++++------------- src/devices/nm-device-macvlan.c | 20 +------------------ src/devices/nm-device-private.h | 10 ++++++++++ src/devices/nm-device-tun.c | 20 +------------------ src/devices/nm-device-vlan.c | 20 +------------------ src/devices/nm-device-vxlan.c | 20 +------------------ src/devices/nm-device.c | 39 ++++++++++++++++++++++++++++++++++++++ src/devices/nm-device.h | 3 ++- src/devices/team/nm-device-team.c | 21 +------------------- src/devices/wifi/nm-device-wifi.c | 26 ++++++++++++------------- 13 files changed, 101 insertions(+), 173 deletions(-) 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; - - connection = nm_device_get_applied_connection (device); - g_assert (connection); - s_wired = nm_connection_get_setting_wired (connection); - g_assert (s_wired); + return 0; - /* 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); + + setting = NM_SETTING_INFINIBAND (nm_device_get_applied_setting (device, NM_TYPE_SETTING_INFINIBAND)); + if (!setting) + g_return_val_if_reached (0); - /* MTU override */ - mtu = nm_setting_infiniband_get_mtu (s_infiniband); - if (mtu) - nm_ip4_config_set_mtu (config, mtu, NM_IP_CONFIG_SOURCE_USER); + 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); + + 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 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); + 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); + + setting = NM_SETTING_WIRELESS (nm_device_get_applied_setting (device, NM_TYPE_SETTING_WIRELESS)); + if (!setting) + g_return_val_if_reached (0); - /* MTU override */ - mtu = nm_setting_wireless_get_mtu (s_wifi); - if (mtu) - nm_ip4_config_set_mtu (config, mtu, NM_IP_CONFIG_SOURCE_USER); + 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; -- cgit v1.2.3 From 797ad260e6a7c925d53eb206eac90c6b7837490e Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sun, 15 Jan 2017 14:10:50 +0100 Subject: device/bridge: support setting bridge MTU via wired setting The problem is that the bridge's MTU cannot be larger then the slaves'. Configuring such a setting results in an error being logged and the activation proceeds (without applying the desired MTU). Unclear how to fix that best. --- src/devices/nm-device-bridge.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/devices/nm-device-bridge.c b/src/devices/nm-device-bridge.c index a610997c77..613d59cd76 100644 --- a/src/devices/nm-device-bridge.c +++ b/src/devices/nm-device-bridge.c @@ -445,6 +445,7 @@ nm_device_bridge_class_init (NMDeviceBridgeClass *klass) parent_class->act_stage1_prepare = act_stage1_prepare; parent_class->enslave_slave = enslave_slave; parent_class->release_slave = release_slave; + parent_class->get_configured_mtu = nm_device_get_configured_mtu_for_wired; nm_exported_object_class_add_interface (NM_EXPORTED_OBJECT_CLASS (klass), NMDBUS_TYPE_DEVICE_BRIDGE_SKELETON, -- cgit v1.2.3 From b3a89dc1538febffe354ad77fe1054aea9785ee0 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sun, 15 Jan 2017 12:57:50 +0100 Subject: ip4-config: cleanup MTU handling It is wrong that nm_ip4_config_set_mtu() tries to ~merge~ the new MTU with the existing. All callers of nm_ip4_config_set_mtu() want that the new value prevails. That is also already the case because the DHCP clients and PPP manager set the MTU on a newly created NMIP4Config instance, thus their value is taken. Similarly, the final merge with NM_IP_CONFIG_SOURCE_USER also prevails as the source has the highest priority. The setter should just set. The only place where we want the merge behavior is in nm_ip4_config_merge(), where it is now implemented in-place. For example, nm_ip4_config_replace() very much wants that the new value wins, regardless of the previous setting. Using nm_ip4_config_set_mtu() with the merge behavior was wrong because it means that the MTU of NMDevice's composite can never be raised again (for example with a new DHCP event). --- src/nm-ip4-config.c | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/src/nm-ip4-config.c b/src/nm-ip4-config.c index ea6468bbb3..1486edccc7 100644 --- a/src/nm-ip4-config.c +++ b/src/nm-ip4-config.c @@ -702,9 +702,11 @@ nm_ip4_config_merge (NMIP4Config *dst, const NMIP4Config *src, NMIPConfigMergeFl nm_ip4_config_set_mss (dst, nm_ip4_config_get_mss (src)); /* MTU */ - if (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)); + if ( src_priv->mtu_source > dst_priv->mtu_source + || ( src_priv->mtu_source == dst_priv->mtu_source + && ( (!dst_priv->mtu && src_priv->mtu) + || (dst_priv->mtu && src_priv->mtu < dst_priv->mtu)))) + nm_ip4_config_set_mtu (dst, src_priv->mtu, src_priv->mtu_source); /* NIS */ if (!NM_FLAGS_HAS (merge_flags, NM_IP_CONFIG_MERGE_NO_DNS)) { @@ -932,7 +934,8 @@ nm_ip4_config_subtract (NMIP4Config *dst, const NMIP4Config *src) nm_ip4_config_set_mss (dst, 0); /* MTU */ - if (nm_ip4_config_get_mtu (src) == nm_ip4_config_get_mtu (dst)) + if ( nm_ip4_config_get_mtu (src) == nm_ip4_config_get_mtu (dst) + && nm_ip4_config_get_mtu_source (src) == nm_ip4_config_get_mtu_source (dst)) nm_ip4_config_set_mtu (dst, 0, NM_IP_CONFIG_SOURCE_UNKNOWN); /* NIS */ @@ -1252,7 +1255,8 @@ nm_ip4_config_replace (NMIP4Config *dst, const NMIP4Config *src, gboolean *relev } /* mtu */ - if (src_priv->mtu != dst_priv->mtu) { + if ( src_priv->mtu != dst_priv->mtu + || src_priv->mtu_source != dst_priv->mtu_source) { nm_ip4_config_set_mtu (dst, src_priv->mtu, src_priv->mtu_source); has_minor_changes = TRUE; } @@ -1329,7 +1333,7 @@ nm_ip4_config_dump (const NMIP4Config *config, const char *detail) g_message (" dnspri: %d", nm_ip4_config_get_dns_priority (config)); g_message (" mss: %"G_GUINT32_FORMAT, nm_ip4_config_get_mss (config)); - g_message (" mtu: %"G_GUINT32_FORMAT, nm_ip4_config_get_mtu (config)); + g_message (" mtu: %"G_GUINT32_FORMAT" (source: %d)", nm_ip4_config_get_mtu (config), (int) nm_ip4_config_get_mtu_source (config)); /* NIS */ for (i = 0; i < nm_ip4_config_get_num_nis_servers (config); i++) { @@ -2080,11 +2084,11 @@ nm_ip4_config_set_mtu (NMIP4Config *config, guint32 mtu, NMIPConfigSource source { NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (config); - 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; + if (!mtu) + source = NM_IP_CONFIG_SOURCE_UNKNOWN; + + priv->mtu = mtu; + priv->mtu_source = source; } guint32 -- cgit v1.2.3 From b5fcbdf5940d2b9e353fca393af694c02b466d0a Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sun, 15 Jan 2017 13:38:33 +0100 Subject: device: refactor configuring MTU by dropping mtu_desired Don't have this mtu_desired variable. All the data is readily available without redundancy. E.g. the applied-connection contains everything we need to know. Just get it as needed. Also drop apply_mtu_from_config(). It didn't take into account the MTU settings beside NMSettingWired. Also, no longer merge the NM_IP_CONFIG_SOURCE_USER MTU value into priv->ip4_config. NMIP4Config now only tracks the MTU from the various non-user-config sources, but the user config is no longer merged back into the composite. --- src/devices/nm-device.c | 108 +++++++++++++++++++++--------------------------- 1 file changed, 47 insertions(+), 61 deletions(-) diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c index 22ffce34f9..638b9d8320 100644 --- a/src/devices/nm-device.c +++ b/src/devices/nm-device.c @@ -307,7 +307,6 @@ typedef struct _NMDevicePrivate { gulong ignore_carrier_id; guint32 mtu; guint32 ip6_mtu; - guint32 mtu_desired; bool up; /* IFF_UP */ /* Generic DHCP stuff */ @@ -492,7 +491,7 @@ static NMActStageReturn dhcp4_start (NMDevice *self, NMConnection *connection, N static gboolean dhcp6_start (NMDevice *self, gboolean wait_for_ll, NMDeviceStateReason *reason); static void nm_device_start_ip_check (NMDevice *self); static void realize_start_setup (NMDevice *self, const NMPlatformLink *plink); -static void nm_device_set_mtu (NMDevice *self, guint32 mtu); +static void _commit_mtu (NMDevice *self, const NMIP4Config *config); static void dhcp_schedule_restart (NMDevice *self, int family, const char *reason); static void _cancel_activation (NMDevice *self); @@ -1633,29 +1632,6 @@ find_slave_info (NMDevice *self, NMDevice *slave) return NULL; } -static void -apply_mtu_from_config (NMDevice *self) -{ - const char *method = NM_SETTING_IP4_CONFIG_METHOD_DISABLED; - NMSettingIPConfig *s_ip4; - NMSettingWired *s_wired; - - /* Devices having an IPv4 configuration will set MTU during the commit - * stage, so it is an error to call this function if the IPv4 method is not - * 'disabled'. - */ - s_ip4 = (NMSettingIPConfig *) nm_device_get_applied_setting (self, NM_TYPE_SETTING_IP4_CONFIG); - if (s_ip4) - method = nm_setting_ip_config_get_method (s_ip4); - - g_return_if_fail (nm_streq0 (method, NM_SETTING_IP4_CONFIG_METHOD_DISABLED)); - - s_wired = (NMSettingWired *) nm_device_get_applied_setting (self, NM_TYPE_SETTING_WIRED); - - if (s_wired) - nm_device_set_mtu (self, nm_setting_wired_get_mtu (s_wired)); -} - /** * nm_device_master_enslave_slave: * @self: the master device @@ -1716,7 +1692,7 @@ nm_device_master_enslave_slave (NMDevice *self, NMDevice *slave, NMConnection *c /* Since slave devices don't have their own IP configuration, * set the MTU here. */ - apply_mtu_from_config (slave); + _commit_mtu (slave, NM_DEVICE_GET_PRIVATE (slave)->ip4_config); return success; } @@ -2595,7 +2571,6 @@ realize_start_setup (NMDevice *self, const NMPlatformLink *plink) g_object_freeze_notify (G_OBJECT (self)); priv->ip6_mtu = 0; - priv->mtu_desired = 0; if (priv->mtu) { priv->mtu = 0; _notify (self, PROP_MTU); @@ -5180,18 +5155,7 @@ END_ADD_DEFAULT_ROUTE: priv->default_route.v4_has = _device_get_default_route_from_platform (self, AF_INET, (NMPlatformIPRoute *) &priv->default_route.v4); } - /* 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); } @@ -5725,7 +5689,7 @@ act_stage3_ip4_config_start (NMDevice *self, } else g_return_val_if_reached (NM_ACT_STAGE_RETURN_FAILURE); } else if (strcmp (method, NM_SETTING_IP4_CONFIG_METHOD_DISABLED) == 0) { - apply_mtu_from_config (self); + _commit_mtu (self, priv->ip4_config); ret = NM_ACT_STAGE_RETURN_SUCCESS; } else _LOGW (LOGD_IP4, "unhandled IPv4 config method '%s'; will fail", method); @@ -6629,25 +6593,55 @@ nm_device_get_configured_mtu_for_wired (NMDevice *self, gboolean *out_is_user_co /*****************************************************************************/ static void -_set_mtu (NMDevice *self) +_commit_mtu (NMDevice *self, const NMIP4Config *config) { NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self); - guint32 ip6_mtu; - guint32 mtu_desired; + guint32 ip6_mtu, ip6_mtu_orig; + guint32 mtu_desired, mtu_desired_orig; guint32 mtu_plat; int ifindex; - char sbuf[64]; + char sbuf[64], sbuf1[64], sbuf2[64]; ifindex = nm_device_get_ip_ifindex (self); if (ifindex <= 0) return; + if (nm_device_uses_assumed_connection (self)) { + /* for assumed connections we don't tamper with the MTU. This is + * a bug and supposed to be fixed by the unmanaged/assumed rework. */ + return; + } + + { + gboolean mtu_is_user_config = FALSE; + guint32 mtu = 0; + + /* preferably, get the MTU from explict user-configuration. If that fails, + * look at the current @config (which contains MTUs from DHCP/PPP. + * + * Finally, assume no MTU change. */ + + if (NM_DEVICE_GET_CLASS (self)->get_configured_mtu) + mtu = NM_DEVICE_GET_CLASS (self)->get_configured_mtu (self, &mtu_is_user_config); + + if (mtu && mtu_is_user_config) + mtu_desired = mtu; + else { + if (config) + mtu_desired = nm_ip4_config_get_mtu (config); + else + mtu_desired = 0; + } + } + ip6_mtu = priv->ip6_mtu; - mtu_desired = priv->mtu_desired; if (!ip6_mtu && !mtu_desired) return; + mtu_desired_orig = mtu_desired; + ip6_mtu_orig = ip6_mtu; + mtu_plat = nm_platform_link_get_mtu (NM_PLATFORM_GET, ifindex); if (ip6_mtu) { @@ -6664,6 +6658,12 @@ _set_mtu (NMDevice *self) } } + _LOGT (LOGD_DEVICE, "mtu: device-mtu: %u%s, ipv6-mtu: %u%s", + (guint) mtu_desired, + mtu_desired == mtu_desired_orig ? "" : nm_sprintf_buf (sbuf1, " (was %u)", (guint) mtu_desired_orig), + (guint) ip6_mtu, + ip6_mtu == ip6_mtu_orig ? "" : nm_sprintf_buf (sbuf2, " (was %u)", (guint) ip6_mtu_orig)); + if (mtu_desired) { if (mtu_desired != mtu_plat) nm_platform_link_set_mtu (NM_PLATFORM_GET, ifindex, mtu_desired); @@ -6677,18 +6677,6 @@ _set_mtu (NMDevice *self) } } -static void -nm_device_set_mtu (NMDevice *self, guint32 mtu) -{ - NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self); - - if (priv->mtu_desired != mtu) { - _LOGD (LOGD_DEVICE, "mtu: set MTU to %u", (unsigned) mtu); - priv->mtu_desired = mtu; - } - _set_mtu (self); -} - static void ndisc_config_changed (NMNDisc *ndisc, const NMNDiscData *rdata, guint changed_int, NMDevice *self) { @@ -7232,8 +7220,7 @@ act_stage3_ip6_config_start (NMDevice *self, * expose any ipv6 sysctls or allow presence of any addresses on the interface, * including LL, which * would make it impossible to autoconfigure MTU to a * correct value. */ - if (!nm_device_uses_assumed_connection (self)) - _set_mtu (self); + _commit_mtu (self, priv->ip4_config); /* Any method past this point requires an IPv6LL address. Use NM-controlled * IPv6LL if this is not an assumed connection, since assumed connections @@ -9109,8 +9096,7 @@ nm_device_set_ip4_config (NMDevice *self, if (commit && new_config) { gboolean assumed = nm_device_uses_assumed_connection (self); - nm_device_set_mtu (self, nm_ip4_config_get_mtu (new_config)); - + _commit_mtu (self, new_config); /* For assumed devices we must not touch the kernel-routes, such as the device-route. * FIXME: this is wrong in case where "assumed" means "take-over-seamlessly". In this * case, we should manage the device route, for example on new DHCP lease. */ @@ -9278,7 +9264,7 @@ nm_device_set_ip6_config (NMDevice *self, /* Always commit to nm-platform to update lifetimes */ if (commit && new_config) { - _set_mtu (self); + _commit_mtu (self, priv->ip4_config); success = nm_ip6_config_commit (new_config, ip_ifindex, routes_full_sync); -- cgit v1.2.3 From 1e67c7ac0b63021ef6a7b669645a0da29f3ed1b9 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 16 Jan 2017 10:20:26 +0100 Subject: device: reset previous MTU when device disconnects When you have a connection with "ethernet.mtu=0 (auto)", the MTU is not set during activation. That means, the effective MTU depends on the previous MTU configuration of the device. Which in turn, depends on the previously active connection, as we don't reset the MTU on deactivation. Restore the previous MTU on deactivation iff NetworkManager changed the MTU during device activation. --- src/devices/nm-device.c | 63 ++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 55 insertions(+), 8 deletions(-) diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c index 638b9d8320..3d4a96368a 100644 --- a/src/devices/nm-device.c +++ b/src/devices/nm-device.c @@ -307,6 +307,9 @@ typedef struct _NMDevicePrivate { gulong ignore_carrier_id; guint32 mtu; guint32 ip6_mtu; + guint32 mtu_initial; + guint32 ip6_mtu_initial; + bool up; /* IFF_UP */ /* Generic DHCP stuff */ @@ -2570,6 +2573,8 @@ realize_start_setup (NMDevice *self, const NMPlatformLink *plink) /* Balanced by a thaw in nm_device_realize_finish() */ g_object_freeze_notify (G_OBJECT (self)); + priv->mtu_initial = 0; + priv->ip6_mtu_initial = 0; priv->ip6_mtu = 0; if (priv->mtu) { priv->mtu = 0; @@ -6599,6 +6604,10 @@ _commit_mtu (NMDevice *self, const NMIP4Config *config) guint32 ip6_mtu, ip6_mtu_orig; guint32 mtu_desired, mtu_desired_orig; guint32 mtu_plat; + struct { + gboolean initialized; + guint32 value; + } ip6_mtu_sysctl; int ifindex; char sbuf[64], sbuf1[64], sbuf2[64]; @@ -6658,23 +6667,41 @@ _commit_mtu (NMDevice *self, const NMIP4Config *config) } } - _LOGT (LOGD_DEVICE, "mtu: device-mtu: %u%s, ipv6-mtu: %u%s", + _LOGT (LOGD_DEVICE, "mtu: device-mtu: %u%s, ipv6-mtu: %u%s, ifindex: %d", (guint) mtu_desired, mtu_desired == mtu_desired_orig ? "" : nm_sprintf_buf (sbuf1, " (was %u)", (guint) mtu_desired_orig), (guint) ip6_mtu, - ip6_mtu == ip6_mtu_orig ? "" : nm_sprintf_buf (sbuf2, " (was %u)", (guint) ip6_mtu_orig)); - - if (mtu_desired) { - if (mtu_desired != mtu_plat) + ip6_mtu == ip6_mtu_orig ? "" : nm_sprintf_buf (sbuf2, " (was %u)", (guint) ip6_mtu_orig), + ifindex); + + ip6_mtu_sysctl.initialized = FALSE; +#define _IP6_MTU_SYS() \ + ({ \ + if (!ip6_mtu_sysctl.initialized) { \ + ip6_mtu_sysctl.value = nm_device_ipv6_sysctl_get_uint32 (self, "mtu", 0); \ + ip6_mtu_sysctl.initialized = TRUE; \ + } \ + ip6_mtu_sysctl.value; \ + }) + if ( (mtu_desired && mtu_desired != mtu_plat) + || (ip6_mtu && ip6_mtu != _IP6_MTU_SYS ())) { + + if (!priv->mtu_initial && !priv->ip6_mtu_initial) { + /* before touching any of the MTU paramters, record the + * original setting to restore on deactivation. */ + priv->mtu_initial = mtu_plat; + priv->ip6_mtu_initial = _IP6_MTU_SYS (); + } + + if (mtu_desired && mtu_desired != mtu_plat) nm_platform_link_set_mtu (NM_PLATFORM_GET, ifindex, mtu_desired); - } - if (ip6_mtu) { - if (ip6_mtu != nm_device_ipv6_sysctl_get_uint32 (self, "mtu", 0)) { + if (ip6_mtu && ip6_mtu != _IP6_MTU_SYS ()) { nm_device_ipv6_sysctl_set (self, "mtu", nm_sprintf_buf (sbuf, "%u", (unsigned) ip6_mtu)); } } +#undef _IP6_MTU_SYS } static void @@ -11428,6 +11455,26 @@ nm_device_cleanup (NMDevice *self, NMDeviceStateReason reason, CleanupType clean NM_DEVICE_GET_CLASS (self)->deactivate_reset_hw_addr (self); } + if (priv->mtu_initial || priv->ip6_mtu_initial) { + ifindex = nm_device_get_ip_ifindex (self); + + if ( ifindex > 0 + && cleanup_type == CLEANUP_TYPE_DECONFIGURE) { + _LOGT (LOGD_DEVICE, "mtu: reset device-mtu: %u, ipv6-mtu: %u, ifindex: %d", + (guint) priv->mtu_initial, (guint) priv->ip6_mtu_initial, ifindex); + if (priv->mtu_initial) + nm_platform_link_set_mtu (NM_PLATFORM_GET, ifindex, priv->mtu_initial); + if (priv->ip6_mtu_initial) { + char sbuf[64]; + + nm_device_ipv6_sysctl_set (self, "mtu", + nm_sprintf_buf (sbuf, "%u", (unsigned) priv->ip6_mtu_initial)); + } + } + priv->mtu_initial = 0; + priv->ip6_mtu_initial = 0; + } + _cleanup_generic_post (self, cleanup_type); } -- cgit v1.2.3 From 22e8af6242853397e91f648458f23200f8fac178 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 16 Jan 2017 12:18:51 +0100 Subject: 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 :( --- src/devices/nm-device.c | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c index 3d4a96368a..911ebff64d 100644 --- a/src/devices/nm-device.c +++ b/src/devices/nm-device.c @@ -310,7 +310,9 @@ typedef struct _NMDevicePrivate { guint32 mtu_initial; guint32 ip6_mtu_initial; - bool up; /* IFF_UP */ + bool mtu_initialized:1; + + bool up:1; /* IFF_UP */ /* Generic DHCP stuff */ guint32 dhcp_timeout; @@ -2573,6 +2575,7 @@ realize_start_setup (NMDevice *self, const NMPlatformLink *plink) /* Balanced by a thaw in nm_device_realize_finish() */ g_object_freeze_notify (G_OBJECT (self)); + priv->mtu_initialized = FALSE; priv->mtu_initial = 0; priv->ip6_mtu_initial = 0; priv->ip6_mtu = 0; @@ -6625,10 +6628,9 @@ _commit_mtu (NMDevice *self, const NMIP4Config *config) gboolean mtu_is_user_config = FALSE; guint32 mtu = 0; - /* preferably, get the MTU from explict user-configuration. If that fails, - * look at the current @config (which contains MTUs from DHCP/PPP. - * - * Finally, assume no MTU change. */ + /* preferably, get the MTU from explict user-configuration. + * Only if that fails, look at the current @config (which contains + * 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); @@ -6640,10 +6642,27 @@ _commit_mtu (NMDevice *self, const NMIP4Config *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; + } } } 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) return; @@ -11455,6 +11474,7 @@ nm_device_cleanup (NMDevice *self, NMDeviceStateReason reason, CleanupType clean NM_DEVICE_GET_CLASS (self)->deactivate_reset_hw_addr (self); } + priv->mtu_initialized = FALSE; if (priv->mtu_initial || priv->ip6_mtu_initial) { ifindex = nm_device_get_ip_ifindex (self); -- cgit v1.2.3 From 665e3980221c04c327b3c165f4a3f82fe470e87e Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 16 Jan 2017 14:58:11 +0100 Subject: device: enforce a link MTU of at least 1280 for connections with IPv6 --- src/devices/nm-device.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c index 911ebff64d..c236a85803 100644 --- a/src/devices/nm-device.c +++ b/src/devices/nm-device.c @@ -6653,6 +6653,22 @@ _commit_mtu (NMDevice *self, const NMIP4Config *config) } } + if (mtu_desired && mtu_desired < 1280) { + NMSettingIPConfig *s_ip6; + + s_ip6 = (NMSettingIPConfig *) nm_device_get_applied_setting (self, NM_TYPE_SETTING_IP6_CONFIG); + if (s_ip6 && nm_streq0 (nm_setting_ip_config_get_method (s_ip6), + NM_SETTING_IP6_CONFIG_METHOD_IGNORE)) { + /* the interface has IPv6 enabled. The MTU with IPv6 cannot be smaller + * then 1280. + * + * For slave-devices (that don't have @s_ip6 we) don't do this fixup because + * it's anyway an unsolved problem when the slave configures a conflicting + * MTU. */ + mtu_desired = 1280; + } + } + 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 -- cgit v1.2.3