Commit 9a58ee07 authored by James Henstridge's avatar James Henstridge Committed by Thomas Haller

config: add an API to disable connectivity check via internal config file.

https://bugzilla.gnome.org/show_bug.cgi?id=785117
parent c0ac4a2f
......@@ -65,6 +65,7 @@ NM_GOBJECT_PROPERTIES_DEFINE_BASE (
PROP_CONFIG_DESCRIPTION,
PROP_KEYFILE_USER,
PROP_KEYFILE_INTERN,
PROP_CONNECTIVITY_ENABLED,
PROP_CONNECTIVITY_URI,
PROP_CONNECTIVITY_INTERVAL,
PROP_CONNECTIVITY_RESPONSE,
......@@ -88,6 +89,7 @@ typedef struct {
MatchSectionInfo *device_infos;
struct {
gboolean enabled;
char *uri;
char *response;
guint interval;
......@@ -238,6 +240,14 @@ nm_config_data_get_plugins (const NMConfigData *self, gboolean allow_default)
return _nm_utils_strv_cleanup (list, TRUE, TRUE, TRUE);
}
gboolean
nm_config_data_get_connectivity_enabled (const NMConfigData *self)
{
g_return_val_if_fail (self, FALSE);
return NM_CONFIG_DATA_GET_PRIVATE (self)->connectivity.enabled;
}
const char *
nm_config_data_get_connectivity_uri (const NMConfigData *self)
{
......@@ -1380,7 +1390,8 @@ nm_config_data_diff (NMConfigData *old_data, NMConfigData *new_data)
|| g_strcmp0 (nm_config_data_get_config_description (old_data), nm_config_data_get_config_description (new_data)) != 0)
changes |= NM_CONFIG_CHANGE_CONFIG_FILES;
if ( nm_config_data_get_connectivity_interval (old_data) != nm_config_data_get_connectivity_interval (new_data)
if ( nm_config_data_get_connectivity_enabled (old_data) != nm_config_data_get_connectivity_enabled (new_data)
|| nm_config_data_get_connectivity_interval (old_data) != nm_config_data_get_connectivity_interval (new_data)
|| g_strcmp0 (nm_config_data_get_connectivity_uri (old_data), nm_config_data_get_connectivity_uri (new_data))
|| g_strcmp0 (nm_config_data_get_connectivity_response (old_data), nm_config_data_get_connectivity_response (new_data)))
changes |= NM_CONFIG_CHANGE_CONNECTIVITY;
......@@ -1420,6 +1431,9 @@ get_property (GObject *object,
case PROP_CONFIG_DESCRIPTION:
g_value_set_string (value, nm_config_data_get_config_description (self));
break;
case PROP_CONNECTIVITY_ENABLED:
g_value_set_boolean (value, nm_config_data_get_connectivity_enabled (self));
break;
case PROP_CONNECTIVITY_URI:
g_value_set_string (value, nm_config_data_get_connectivity_uri (self));
break;
......@@ -1517,6 +1531,7 @@ constructed (GObject *object)
priv->connection_infos = _match_section_infos_construct (priv->keyfile, NM_CONFIG_KEYFILE_GROUPPREFIX_CONNECTION);
priv->device_infos = _match_section_infos_construct (priv->keyfile, NM_CONFIG_KEYFILE_GROUPPREFIX_DEVICE);
priv->connectivity.enabled = nm_config_keyfile_get_boolean (priv->keyfile, NM_CONFIG_KEYFILE_GROUP_CONNECTIVITY, "enabled", TRUE);
priv->connectivity.uri = nm_strstrip (g_key_file_get_string (priv->keyfile, NM_CONFIG_KEYFILE_GROUP_CONNECTIVITY, "uri", NULL));
priv->connectivity.response = g_key_file_get_string (priv->keyfile, NM_CONFIG_KEYFILE_GROUP_CONNECTIVITY, "response", NULL);
......@@ -1663,6 +1678,12 @@ nm_config_data_class_init (NMConfigDataClass *config_class)
G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS);
obj_properties[PROP_CONNECTIVITY_ENABLED] =
g_param_spec_string (NM_CONFIG_DATA_CONNECTIVITY_ENABLED, "", "",
NULL,
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS);
obj_properties[PROP_CONNECTIVITY_URI] =
g_param_spec_string (NM_CONFIG_DATA_CONNECTIVITY_URI, "", "",
NULL,
......
......@@ -32,6 +32,7 @@
#define NM_CONFIG_DATA_CONFIG_DESCRIPTION "config-description"
#define NM_CONFIG_DATA_KEYFILE_USER "keyfile-user"
#define NM_CONFIG_DATA_KEYFILE_INTERN "keyfile-intern"
#define NM_CONFIG_DATA_CONNECTIVITY_ENABLED "connectivity-enabled"
#define NM_CONFIG_DATA_CONNECTIVITY_URI "connectivity-uri"
#define NM_CONFIG_DATA_CONNECTIVITY_INTERVAL "connectivity-interval"
#define NM_CONFIG_DATA_CONNECTIVITY_RESPONSE "connectivity-response"
......@@ -159,6 +160,7 @@ const char *nm_config_data_get_value_cached (const NMConfigData *config_data, co
gint nm_config_data_get_value_boolean (const NMConfigData *self, const char *group, const char *key, gint default_value);
char **nm_config_data_get_plugins (const NMConfigData *config_data, gboolean allow_default);
gboolean nm_config_data_get_connectivity_enabled (const NMConfigData *config_data);
const char *nm_config_data_get_connectivity_uri (const NMConfigData *config_data);
guint nm_config_data_get_connectivity_interval (const NMConfigData *config_data);
const char *nm_config_data_get_connectivity_response (const NMConfigData *config_data);
......
......@@ -1590,6 +1590,33 @@ done:
return TRUE;
}
/*****************************************************************************/
void nm_config_set_connectivity_check_enabled (NMConfig *self,
gboolean enabled)
{
NMConfigPrivate *priv;
GKeyFile *keyfile;
g_return_if_fail (NM_IS_CONFIG (self));
priv = NM_CONFIG_GET_PRIVATE (self);
g_return_if_fail (priv->config_data);
keyfile = nm_config_data_clone_keyfile_intern (priv->config_data);
/* Remove existing groups */
g_key_file_remove_group (keyfile, NM_CONFIG_KEYFILE_GROUP_CONNECTIVITY, NULL);
if (!enabled) {
g_key_file_set_value (keyfile, NM_CONFIG_KEYFILE_GROUP_CONNECTIVITY,
"enabled", "false");
}
nm_config_set_values (self, keyfile, TRUE, FALSE);
g_key_file_unref (keyfile);
}
/**
* nm_config_set_values:
* @self: the NMConfig instance
......
......@@ -179,6 +179,8 @@ void _nm_config_sort_groups (char **groups, gsize ngroups);
gboolean nm_config_set_global_dns (NMConfig *self, NMGlobalDnsConfig *global_dns, GError **error);
void nm_config_set_connectivity_check_enabled (NMConfig *self, gboolean enabled);
/* internal defines ... */
extern guint _nm_config_match_nm_version;
extern char *_nm_config_match_env;
......
......@@ -35,6 +35,7 @@
typedef struct {
char *uri;
char *response;
gboolean enabled;
guint interval;
NMConfig *config;
guint periodic_check_id;
......@@ -343,7 +344,7 @@ nm_connectivity_check_async (NMConnectivity *self,
simple = g_simple_async_result_new (G_OBJECT (self), callback, user_data,
nm_connectivity_check_async);
if (priv->uri && priv->interval && priv->curl_mhandle)
if (priv->enabled)
ehandle = curl_easy_init ();
if (ehandle) {
......@@ -401,7 +402,7 @@ nm_connectivity_check_enabled (NMConnectivity *self)
{
NMConnectivityPrivate *priv = NM_CONNECTIVITY_GET_PRIVATE (self);
return (priv->uri && priv->interval && priv->curl_mhandle);
return priv->enabled;
}
/*****************************************************************************/
......@@ -419,6 +420,7 @@ update_config (NMConnectivity *self, NMConfigData *config_data)
NMConnectivityPrivate *priv = NM_CONNECTIVITY_GET_PRIVATE (self);
const char *uri, *response;
guint interval;
gboolean enabled;
gboolean changed = FALSE;
/* Set the URI. */
......@@ -454,6 +456,18 @@ update_config (NMConnectivity *self, NMConfigData *config_data)
changed = TRUE;
}
/* Set enabled flag. */
enabled = nm_config_data_get_connectivity_enabled (config_data);
/* connectivity checking also requires a valid URI, interval and
* curl_mhandle */
if (!(priv->uri && priv->interval && priv->curl_mhandle)) {
enabled = FALSE;
}
if (priv->enabled != enabled) {
priv->enabled = enabled;
changed = TRUE;
}
/* Set the response. */
response = nm_config_data_get_connectivity_response (config_data);
if (g_strcmp0 (response, priv->response) != 0) {
......
......@@ -26,6 +26,7 @@
#include "nm-test-device.h"
#include "platform/nm-fake-platform.h"
#include "nm-bus-manager.h"
#include "nm-connectivity.h"
#include "nm-test-utils-core.h"
......@@ -317,6 +318,38 @@ test_config_global_dns (void)
g_object_unref (config);
}
static void
test_config_connectivity_check (void)
{
const char *CONFIG_INTERN = BUILDDIR"/test-connectivity-check-intern.conf";
NMConfig *config;
NMConnectivity *connectivity;
g_assert (g_file_set_contents (CONFIG_INTERN, "", 0, NULL));
config = setup_config (NULL, SRCDIR "/NetworkManager.conf", CONFIG_INTERN, NULL,
"/no/such/dir", "", NULL);
connectivity = nm_connectivity_get();
g_assert (nm_connectivity_check_enabled (connectivity));
/* disable connectivity checking */
g_test_expect_message ("NetworkManager", G_LOG_LEVEL_INFO, "*config: signal *");
nm_config_set_connectivity_check_enabled (config, FALSE);
g_test_assert_expected_messages ();
g_assert (!nm_connectivity_check_enabled (connectivity));
/* re-enable connectivity checking */
g_test_expect_message ("NetworkManager", G_LOG_LEVEL_INFO, "*config: signal *");
nm_config_set_connectivity_check_enabled (config, TRUE);
g_test_assert_expected_messages ();
g_assert (nm_connectivity_check_enabled (connectivity));
g_object_unref (connectivity);
g_object_unref (config);
}
static void
test_config_no_auto_default (void)
{
......@@ -1018,6 +1051,7 @@ main (int argc, char **argv)
g_test_add_func ("/config/set-values", test_config_set_values);
g_test_add_func ("/config/global-dns", test_config_global_dns);
g_test_add_func ("/config/connectivity-check", test_config_connectivity_check);
g_test_add_func ("/config/signal", test_config_signal);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment