merge: make VPN timeout configurable - vpn.timeout property (bgo #754754)

https://bugzilla.gnome.org/show_bug.cgi?id=754754
This commit is contained in:
Jiří Klimeš 2015-09-21 16:59:46 +02:00
commit 32e783e753
6 changed files with 85 additions and 3 deletions

View file

@ -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 */

View file

@ -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));
}

View file

@ -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

View file

@ -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;

View file

@ -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
<term><varname>ipv6.route-metric</varname></term>
</varlistentry>
</variablelist>
<varlistentry>
<term><varname>vpn.timeout</varname></term>
<listitem><para>If left unspecified, default value of 60 seconds is used.</para></listitem>
</varlistentry>
</para>
</refsect1>

View file

@ -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);
}