From ffe16c958f61b77583976b7b6a5c4793a389f461 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20Klime=C5=A1?= Date: Wed, 16 Sep 2015 09:34:33 +0200 Subject: [PATCH 1/4] libnm-core: add vpn.timeout property for establishing connections [1] https://mail.gnome.org/archives/networkmanager-list/2015-April/msg00007.html --- libnm-core/nm-setting-vpn.c | 44 +++++++++++++++++++++++++++++++++++++ libnm-core/nm-setting-vpn.h | 3 +++ libnm/libnm.ver | 1 + 3 files changed, 48 insertions(+) diff --git a/libnm-core/nm-setting-vpn.c b/libnm-core/nm-setting-vpn.c index 50385112e9..aae8ae13b9 100644 --- a/libnm-core/nm-setting-vpn.c +++ b/libnm-core/nm-setting-vpn.c @@ -80,6 +80,9 @@ typedef struct { * freed with g_free(). Should contain secrets only. */ GHashTable *secrets; + + /* Timeout for the VPN service to establish the connection */ + guint32 timeout; } NMSettingVpnPrivate; enum { @@ -89,6 +92,7 @@ enum { PROP_PERSISTENT, PROP_DATA, PROP_SECRETS, + PROP_TIMEOUT, LAST_PROP }; @@ -387,6 +391,22 @@ nm_setting_vpn_foreach_secret (NMSettingVpn *setting, foreach_item_helper (NM_SETTING_VPN_GET_PRIVATE (setting)->secrets, func, user_data); } +/** + * nm_setting_vpn_get_timeout: + * @setting: the #NMSettingVpn + * + * Returns: the #NMSettingVpn:timeout property of the setting + * + * Since: 1.2 + **/ +guint32 +nm_setting_vpn_get_timeout (NMSettingVpn *setting) +{ + g_return_val_if_fail (NM_IS_SETTING_VPN (setting), 0); + + return NM_SETTING_VPN_GET_PRIVATE (setting)->timeout; +} + static gboolean verify (NMSetting *setting, NMConnection *connection, GError **error) { @@ -753,6 +773,9 @@ set_property (GObject *object, guint prop_id, g_hash_table_unref (priv->secrets); priv->secrets = _nm_utils_copy_strdict (g_value_get_boxed (value)); break; + case PROP_TIMEOUT: + priv->timeout = g_value_get_uint (value); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; @@ -782,6 +805,9 @@ get_property (GObject *object, guint prop_id, case PROP_SECRETS: g_value_take_boxed (value, _nm_utils_copy_strdict (priv->secrets)); break; + case PROP_TIMEOUT: + g_value_set_uint (value, nm_setting_vpn_get_timeout (setting)); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; @@ -909,4 +935,22 @@ nm_setting_vpn_class_init (NMSettingVpnClass *setting_class) G_VARIANT_TYPE ("a{ss}"), _nm_utils_strdict_to_dbus, _nm_utils_strdict_from_dbus); + + /** + * NMSettingVpn:timeout: + * + * Timeout for the VPN service to establish the connection. Some services + * may take quite a long time to connect. + * Value of 0 means a default timeout, which is 60 seconds (unless overriden + * by vpn.timeout in configuration file). Values greater than zero mean + * timeout in seconds. + * + * Since: 1.2 + **/ + g_object_class_install_property + (object_class, PROP_TIMEOUT, + g_param_spec_uint (NM_SETTING_VPN_TIMEOUT, "", "", + 0, G_MAXUINT32, 0, + G_PARAM_READWRITE | + G_PARAM_STATIC_STRINGS)); } diff --git a/libnm-core/nm-setting-vpn.h b/libnm-core/nm-setting-vpn.h index 487549afaa..31f3c7b87a 100644 --- a/libnm-core/nm-setting-vpn.h +++ b/libnm-core/nm-setting-vpn.h @@ -45,6 +45,7 @@ G_BEGIN_DECLS #define NM_SETTING_VPN_PERSISTENT "persistent" #define NM_SETTING_VPN_DATA "data" #define NM_SETTING_VPN_SECRETS "secrets" +#define NM_SETTING_VPN_TIMEOUT "timeout" struct _NMSettingVpn { NMSetting parent; @@ -96,6 +97,8 @@ gboolean nm_setting_vpn_remove_secret (NMSettingVpn *setting, void nm_setting_vpn_foreach_secret (NMSettingVpn *setting, NMVpnIterFunc func, gpointer user_data); +NM_AVAILABLE_IN_1_2 +guint32 nm_setting_vpn_get_timeout (NMSettingVpn *setting); G_END_DECLS diff --git a/libnm/libnm.ver b/libnm/libnm.ver index efe182daeb..6551bc3863 100644 --- a/libnm/libnm.ver +++ b/libnm/libnm.ver @@ -876,6 +876,7 @@ global: nm_setting_ip_config_has_dns_options; nm_setting_ip_config_remove_dns_option; nm_setting_ip_config_remove_dns_option_by_value; + nm_setting_vpn_get_timeout; nm_setting_wired_get_wake_on_lan; nm_setting_wired_get_wake_on_lan_password; nm_setting_wired_wake_on_lan_get_type; From 431cc8a517de1a1b26c8e9082502c5eb55c1ba73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20Klime=C5=A1?= Date: Wed, 16 Sep 2015 09:39:37 +0200 Subject: [PATCH 2/4] cli: support vpn.timeout property in nmcli --- clients/cli/settings.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/clients/cli/settings.c b/clients/cli/settings.c index 30acd7f20d..67d19a25ae 100644 --- a/clients/cli/settings.c +++ b/clients/cli/settings.c @@ -516,6 +516,7 @@ NmcOutputField nmc_fields_setting_vpn[] = { SETTING_FIELD (NM_SETTING_VPN_DATA, 30), /* 3 */ SETTING_FIELD (NM_SETTING_VPN_SECRETS, 15), /* 4 */ SETTING_FIELD (NM_SETTING_VPN_PERSISTENT, 15), /* 5 */ + SETTING_FIELD (NM_SETTING_VPN_TIMEOUT, 10), /* 6 */ {NULL, NULL, 0, NULL, FALSE, FALSE, 0} }; #define NMC_FIELDS_SETTING_VPN_ALL "name"","\ @@ -523,7 +524,8 @@ NmcOutputField nmc_fields_setting_vpn[] = { NM_SETTING_VPN_USER_NAME","\ NM_SETTING_VPN_DATA","\ NM_SETTING_VPN_SECRETS","\ - NM_SETTING_VPN_PERSISTENT + NM_SETTING_VPN_PERSISTENT","\ + NM_SETTING_VPN_TIMEOUT #define NMC_FIELDS_SETTING_VPN_COMMON NMC_FIELDS_SETTING_VPN_ALL /* Available fields for NM_SETTING_WIMAX_SETTING_NAME */ @@ -1522,6 +1524,7 @@ nmc_property_vpn_get_secrets (NMSetting *setting, NmcPropertyGetType get_type) } DEFINE_GETTER (nmc_property_vpn_get_persistent, NM_SETTING_VPN_PERSISTENT) +DEFINE_GETTER (nmc_property_vpn_get_timeout, NM_SETTING_VPN_TIMEOUT) /* --- NM_SETTING_WIMAX_SETTING_NAME property get functions --- */ DEFINE_GETTER (nmc_property_wimax_get_network_name, NM_SETTING_WIMAX_NETWORK_NAME) @@ -6352,6 +6355,14 @@ nmc_properties_init (void) NULL, NULL); + nmc_add_prop_funcs (GLUE (VPN, TIMEOUT), + nmc_property_vpn_get_timeout, + nmc_property_set_uint, + NULL, + NULL, + NULL, + NULL); + /* Add editable properties for NM_SETTING_WIMAX_SETTING_NAME */ nmc_add_prop_funcs (GLUE (WIMAX, NETWORK_NAME), nmc_property_wimax_get_network_name, @@ -7520,6 +7531,7 @@ setting_vpn_details (NMSetting *setting, NmCli *nmc, const char *one_prop, gboo set_val_str (arr, 3, nmc_property_vpn_get_data (setting, NMC_PROPERTY_GET_PRETTY)); set_val_str (arr, 4, GET_SECRET (secrets, setting, nmc_property_vpn_get_secrets)); set_val_str (arr, 5, nmc_property_vpn_get_persistent (setting, NMC_PROPERTY_GET_PRETTY)); + set_val_str (arr, 6, nmc_property_vpn_get_timeout (setting, NMC_PROPERTY_GET_PRETTY)); g_ptr_array_add (nmc->output_data, arr); print_data (nmc); /* Print all data */ From bbc772521816d57ba103ae092a07a692fafcf485 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20Klime=C5=A1?= Date: Wed, 16 Sep 2015 09:45:56 +0200 Subject: [PATCH 3/4] vpn: use vpn.timeout property as timeout value for IP config (bgo #754754) Some VPN services may take their time when establishing a connection. Let's make our timeout configurable to be able to give such services a chance. https://mail.gnome.org/archives/networkmanager-list/2015-April/msg00007.html https://bugzilla.gnome.org/show_bug.cgi?id=754754 --- src/vpn-manager/nm-vpn-connection.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/vpn-manager/nm-vpn-connection.c b/src/vpn-manager/nm-vpn-connection.c index 881751b77a..4141d3f7af 100644 --- a/src/vpn-manager/nm-vpn-connection.c +++ b/src/vpn-manager/nm-vpn-connection.c @@ -42,6 +42,7 @@ #include "nm-default-route-manager.h" #include "nm-route-manager.h" #include "nm-firewall-manager.h" +#include "nm-config.h" #include "nmdbus-vpn-connection.h" @@ -1605,9 +1606,25 @@ static void connect_success (NMVpnConnection *self) { NMVpnConnectionPrivate *priv = NM_VPN_CONNECTION_GET_PRIVATE (self); + NMSettingVpn *s_vpn; + guint32 timeout; - /* 40 second timeout waiting for IP config signal from VPN service */ - priv->connect_timeout = g_timeout_add_seconds (40, connect_timeout_cb, self); + s_vpn = nm_connection_get_setting_vpn (_get_applied_connection (self)); + g_assert (s_vpn); + + /* Timeout waiting for IP config signal from VPN service + * It is a configured value or 60 seconds */ + timeout = nm_setting_vpn_get_timeout (s_vpn); + if (timeout == 0) { + char *value; + + value = nm_config_data_get_connection_default (NM_CONFIG_GET_DATA, + "vpn.timeout", NULL); + timeout = _nm_utils_ascii_str_to_int64 (value, 10, 0, G_MAXUINT32, 60); + timeout = timeout == 0 ? 60 : timeout; + g_free (value); + } + priv->connect_timeout = g_timeout_add_seconds (timeout, connect_timeout_cb, self); g_clear_pointer (&priv->connect_hash, g_variant_unref); } From 9f1e9913b98d7227ba546d0727ce22a906aefbbb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20Klime=C5=A1?= Date: Thu, 17 Sep 2015 12:39:56 +0200 Subject: [PATCH 4/4] man: document that vpn.timeout property supports a default value --- man/NetworkManager.conf.xml.in | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/man/NetworkManager.conf.xml.in b/man/NetworkManager.conf.xml.in index ccef393084..3dcf97e082 100644 --- a/man/NetworkManager.conf.xml.in +++ b/man/NetworkManager.conf.xml.in @@ -511,6 +511,7 @@ unmanaged-devices=mac:00:22:68:1c:59:b1;mac:00:1E:65:30:D1:C4;interface-name:eth [connection] ipv6.ip6-privacy=0 connection.autoconnect-slaves=1 +vpn.timeout=120 [connection-wifi-wlan0] match-device=interface-name:wlan0 @@ -589,6 +590,10 @@ ipv6.ip6-privacy=1 ipv6.route-metric + + vpn.timeout + If left unspecified, default value of 60 seconds is used. +