summaryrefslogtreecommitdiff
path: root/src/nm-connectivity.c
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2018-02-20 21:41:14 +0100
committerThomas Haller <thaller@redhat.com>2018-04-10 15:11:23 +0200
commit0a62a0e9039e49e05dae6af9a96c381629bccd58 (patch)
tree6a02f0caf28a33b5f7ed6678ed200e244ae29c2b /src/nm-connectivity.c
parente8e0ef6300526ab64eaba534c6b22b23631cf8a9 (diff)
downloadNetworkManager-0a62a0e9039e49e05dae6af9a96c381629bccd58.tar.gz
connectivity: schedule connectivity timers per-device and probe for short outages
It might happen, that connectivitiy is lost only for a moment and returns soon after. Based on that assumption, when we loose connectivity we want to have a probe interval where we check for returning connectivity more frequently. For that, we handle tracking of the timeouts per-device. The intervall shall start with 1 seconds, and double the interval time until the full interval is reached. Actually, due to the implementation, it's unlikely that we already perform the second check 1 second later. That is because commonly the first check returns before the one second timeout is reached and bumps the interval to 2 seconds right away. Also, we go through extra lengths so that manual connectivity check delay the periodic checks. By being more smart about that, we can reduce the number of connectivity checks, but still keeping the promise to check at least within the requested interval. The complexity of book keeping the timeouts is remarkable. But I think it is worth the effort and we should try hard to - have a connectivity state as accurate as possible. Clearly, connectivity checking means that we probing, so being more intelligent about timeout and backoff timers can result in a better connectivity state. The connectivity state is important because we use it for the default-route penaly and the GUI indicates bad connectivity. - be intelligent about avoiding redundant connectivity checks. While we want to check often to get an accurate connectivity state, we also want to minimize the number of HTTP requests, in case the connectivity is established and suppossedly stable. Also, perform connectivity checks in every state of the device. Even if a device is disconnected, it still might have connectivity, for example if the user externally adds an IP address on an unmanaged device. https://bugzilla.gnome.org/show_bug.cgi?id=792240
Diffstat (limited to 'src/nm-connectivity.c')
-rw-r--r--src/nm-connectivity.c33
1 files changed, 13 insertions, 20 deletions
diff --git a/src/nm-connectivity.c b/src/nm-connectivity.c
index 039ff71d05..d46b7d2859 100644
--- a/src/nm-connectivity.c
+++ b/src/nm-connectivity.c
@@ -81,7 +81,7 @@ struct _NMConnectivityCheckHandle {
};
enum {
- PERIODIC_CHECK,
+ CONFIG_CHANGED,
LAST_SIGNAL
};
@@ -99,7 +99,6 @@ typedef struct {
struct {
CURLM *curl_mhandle;
guint curl_timer;
- guint periodic_check_id;
} concheck;
#endif
} NMConnectivityPrivate;
@@ -539,21 +538,20 @@ nm_connectivity_check_cancel (NMConnectivityCheckHandle *cb_data)
gboolean
nm_connectivity_check_enabled (NMConnectivity *self)
{
- NMConnectivityPrivate *priv = NM_CONNECTIVITY_GET_PRIVATE (self);
+ g_return_val_if_fail (NM_IS_CONNECTIVITY (self), FALSE);
- return priv->enabled;
+ return NM_CONNECTIVITY_GET_PRIVATE (self)->enabled;
}
/*****************************************************************************/
-#if WITH_CONCHECK
-static gboolean
-periodic_check (gpointer user_data)
+guint
+nm_connectivity_get_interval (NMConnectivity *self)
{
- g_signal_emit (NM_CONNECTIVITY (user_data), signals[PERIODIC_CHECK], 0);
- return G_SOURCE_CONTINUE;
+ return nm_connectivity_check_enabled (self)
+ ? NM_CONNECTIVITY_GET_PRIVATE (self)->interval
+ : 0;
}
-#endif
static void
update_config (NMConnectivity *self, NMConfigData *config_data)
@@ -592,6 +590,7 @@ update_config (NMConnectivity *self, NMConfigData *config_data)
/* Set the interval. */
interval = nm_config_data_get_connectivity_interval (config_data);
+ interval = MIN (interval, (7 * 24 * 3600));
if (priv->interval != interval) {
priv->interval = interval;
changed = TRUE;
@@ -622,13 +621,8 @@ update_config (NMConnectivity *self, NMConfigData *config_data)
changed = TRUE;
}
-#if WITH_CONCHECK
- if (changed) {
- nm_clear_g_source (&priv->concheck.periodic_check_id);
- if (nm_connectivity_check_enabled (self))
- priv->concheck.periodic_check_id = g_timeout_add_seconds (priv->interval, periodic_check, self);
- }
-#endif
+ if (changed)
+ g_signal_emit (self, signals[CONFIG_CHANGED], 0);
}
static void
@@ -699,7 +693,6 @@ again:
curl_multi_cleanup (priv->concheck.curl_mhandle);
curl_global_cleanup ();
- nm_clear_g_source (&priv->concheck.periodic_check_id);
#endif
if (priv->config) {
@@ -715,8 +708,8 @@ nm_connectivity_class_init (NMConnectivityClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
- signals[PERIODIC_CHECK] =
- g_signal_new (NM_CONNECTIVITY_PERIODIC_CHECK,
+ signals[CONFIG_CHANGED] =
+ g_signal_new (NM_CONNECTIVITY_CONFIG_CHANGED,
G_OBJECT_CLASS_TYPE (object_class),
G_SIGNAL_RUN_FIRST,
0, NULL, NULL, NULL,