connman.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
From: "VAUTRIN Emmanuel (Canal Plus Prestataire)" <Emmanuel.VAUTRIN@cpexterne.org>
To: "connman@lists.linux.dev" <connman@lists.linux.dev>
Subject: [PATCH] wispr: Add online check url config options
Date: Tue, 15 Jun 2021 12:58:16 +0000	[thread overview]
Message-ID: <PR1PR02MB479412B2989FCCF93E4AE58F93309@PR1PR02MB4794.eurprd02.prod.outlook.com> (raw)

Global config options, which allow to set the urls (IPv4 and IPv6
respectively) used during the online status check.
Default values are http://ipv4.connman.net/online/status.html and
http://ipv6.connman.net/online/status.html respectively.
---
 README                |  9 +++++++++
 doc/connman.conf.5.in | 13 ++++++++-----
 src/main.c            | 33 +++++++++++++++++++++++++++++++++
 src/main.conf         | 14 +++++++++-----
 src/wispr.c           | 14 +++++++++-----
 5 files changed, 68 insertions(+), 15 deletions(-)

diff --git a/README b/README
index b8154e67a7ac..16f813928a16 100644
--- a/README
+++ b/README
@@ -408,8 +408,17 @@ from ipv4.connman.net (for IPv4 connectivity) and ipv6.connman.net
 (for IPv6 connectivity). The used URL looks like this
 http://ipv{4|6}.connman.net/online/status.html
 
+When an online check request fails, another one is triggered after a
+longer interval. The intervals follow the square series of numbers
+in a specific range, by default [1, 12], corresponding to the following
+intervals, in seconds: 1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121 and 144.
+
 See connman.conf(5) for the EnableOnlineCheck option, if you need to
 disable the feature.
+It is also possible to specify other URLs via OnlineCheckIPv4URL and
+OnlineCheckIPv6URL options.
+The range of intervals between two online check requests can be fine-tuned
+via OnlineCheckInitialInterval and OnlineCheckMaxInterval options.
 
 During the online check procedure, ConnMan will temporarily install
 a host route to both the ipv4.connman.net and ipv6.connman.net so that
diff --git a/doc/connman.conf.5.in b/doc/connman.conf.5.in
index 2e06b3ef1f3c..82cceb7298f1 100644
--- a/doc/connman.conf.5.in
+++ b/doc/connman.conf.5.in
@@ -167,13 +167,16 @@ transitioned to ONLINE state.
 If this setting is false, the default service will remain in READY state.
 Default value is true.
 .TP
+.BI OnlineCheckIPv4URL= url, OnlineCheckIPv6URL= url
+Urls (IPv4 and IPv6 respectively) used during the online status check.
+Please refer to the README for more detailed information.
+Default values are http://ipv4.connman.net/online/status.html and
+http://ipv6.connman.net/online/status.html respectively.
+.TP
 .BI OnlineCheckInitialInterval= secs, OnlineCheckMaxInterval= secs
 Range of intervals between two online check requests.
-When an online check request fails, another one is triggered after a
-longer interval. The intervals follow the power of two series of numbers
-between OnlineCheckInitialInterval and OnlineCheckMaxInterval.
-Default range is [1, 12], corresponding to the following intervals, in
-seconds: 1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121 and 144.
+Please refer to the README for more detailed information.
+Default values are 1 and 12 respectively.
 .TP
 .BI EnableOnlineToReadyTransition=true\ \fR|\fB\ false
 WARNING: Experimental feature!!!
diff --git a/src/main.c b/src/main.c
index 6480caa62980..407207fd4947 100644
--- a/src/main.c
+++ b/src/main.c
@@ -44,6 +44,9 @@
 #define DEFAULT_INPUT_REQUEST_TIMEOUT (120 * 1000)
 #define DEFAULT_BROWSER_LAUNCH_TIMEOUT (300 * 1000)
 
+#define DEFAULT_ONLINE_CHECK_IPV4_URL "http://ipv4.connman.net/online/status.html"
+#define DEFAULT_ONLINE_CHECK_IPV6_URL "http://ipv6.connman.net/online/status.html"
+
 /*
  * We set the integer to 1 sec so that we have a chance to get
  * necessary IPv6 router advertisement messages that might have
@@ -97,6 +100,8 @@ static struct {
 	char *vendor_class_id;
 	bool enable_online_check;
 	bool enable_online_to_ready_transition;
+	char *online_check_ipv4_url;
+	char *online_check_ipv6_url;
 	unsigned int online_check_initial_interval;
 	unsigned int online_check_max_interval;
 	bool auto_connect_roaming_services;
@@ -122,6 +127,8 @@ static struct {
 	.vendor_class_id = NULL,
 	.enable_online_check = true,
 	.enable_online_to_ready_transition = false,
+	.online_check_ipv4_url = DEFAULT_ONLINE_CHECK_IPV4_URL,
+	.online_check_ipv6_url = DEFAULT_ONLINE_CHECK_IPV6_URL,
 	.online_check_initial_interval = DEFAULT_ONLINE_CHECK_INITIAL_INTERVAL,
 	.online_check_max_interval = DEFAULT_ONLINE_CHECK_MAX_INTERVAL,
 	.auto_connect_roaming_services = false,
@@ -148,6 +155,8 @@ static struct {
 #define CONF_VENDOR_CLASS_ID            "VendorClassID"
 #define CONF_ENABLE_ONLINE_CHECK        "EnableOnlineCheck"
 #define CONF_ENABLE_ONLINE_TO_READY_TRANSITION "EnableOnlineToReadyTransition"
+#define CONF_ONLINE_CHECK_IPV4_URL      "OnlineCheckIPv4URL"
+#define CONF_ONLINE_CHECK_IPV6_URL      "OnlineCheckIPv6URL"
 #define CONF_ONLINE_CHECK_INITIAL_INTERVAL "OnlineCheckInitialInterval"
 #define CONF_ONLINE_CHECK_MAX_INTERVAL     "OnlineCheckMaxInterval"
 #define CONF_AUTO_CONNECT_ROAMING_SERVICES "AutoConnectRoamingServices"
@@ -174,6 +183,8 @@ static const char *supported_options[] = {
 	CONF_VENDOR_CLASS_ID,
 	CONF_ENABLE_ONLINE_CHECK,
 	CONF_ENABLE_ONLINE_TO_READY_TRANSITION,
+	CONF_ONLINE_CHECK_IPV4_URL,
+	CONF_ONLINE_CHECK_IPV6_URL,
 	CONF_ONLINE_CHECK_INITIAL_INTERVAL,
 	CONF_ONLINE_CHECK_MAX_INTERVAL,
 	CONF_AUTO_CONNECT_ROAMING_SERVICES,
@@ -486,6 +497,20 @@ static void parse_config(GKeyFile *config)
 
 	g_clear_error(&error);
 
+	string = __connman_config_get_string(config, "General",
+					CONF_ONLINE_CHECK_IPV4_URL, &error);
+	if (!error)
+		connman_settings.online_check_ipv4_url = string;
+
+	g_clear_error(&error);
+
+	string = __connman_config_get_string(config, "General",
+					CONF_ONLINE_CHECK_IPV6_URL, &error);
+	if (!error)
+		connman_settings.online_check_ipv6_url = string;
+
+	g_clear_error(&error);
+
 	integer = g_key_file_get_integer(config, "General",
 			CONF_ONLINE_CHECK_INITIAL_INTERVAL, &error);
 	if (!error && integer >= 0)
@@ -708,6 +733,12 @@ char *connman_setting_get_string(const char *key)
 	if (g_str_equal(key, CONF_VENDOR_CLASS_ID))
 		return connman_settings.vendor_class_id;
 
+	if (g_str_equal(key, CONF_ONLINE_CHECK_IPV4_URL))
+		return connman_settings.online_check_ipv4_url;
+
+	if (g_str_equal(key, CONF_ONLINE_CHECK_IPV6_URL))
+		return connman_settings.online_check_ipv6_url;
+
 	if (g_strcmp0(key, "wifi") == 0) {
 		if (!option_wifi)
 			return "nl80211,wext";
@@ -989,6 +1020,8 @@ int main(int argc, char *argv[])
 	g_strfreev(connman_settings.blacklisted_interfaces);
 	g_strfreev(connman_settings.tethering_technologies);
 	g_free(connman_settings.vendor_class_id);
+	g_free(connman_settings.online_check_ipv4_url);
+	g_free(connman_settings.online_check_ipv6_url);
 
 	g_free(option_debug);
 	g_free(option_wifi);
diff --git a/src/main.conf b/src/main.conf
index df70e178742a..ddd5799610da 100644
--- a/src/main.conf
+++ b/src/main.conf
@@ -125,12 +125,16 @@
 # Default value is true.
 # EnableOnlineCheck = false
 
+# Urls (IPv4 and IPv6 respectively) used during the online status check.
+# Please refer to the README for more detailed information.
+# Default values are http://ipv4.connman.net/online/status.html and
+# http://ipv6.connman.net/online/status.html respectively.
+# OnlineCheckIPv4URL= http://ipv4.connman.net/online/status.html
+# OnlineCheckIPv6URL= http://ipv6.connman.net/online/status.html
+
 # Range of intervals between two online check requests.
-# When an online check request fails, another one is triggered after a
-# longer interval. The intervals follow the power of two series of numbers
-# between OnlineCheckInitialInterval and OnlineCheckMaxInterval.
-# Default range is [1, 12], corresponding to the following intervals, in
-# seconds: 1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121 and 144.
+# Please refer to the README for more detailed information.
+# Default values are 1 and 12 respectively.
 # OnlineCheckInitialInterval = 1
 # OnlineCheckMaxInterval = 12
 
diff --git a/src/wispr.c b/src/wispr.c
index c63dc8195fde..56007a379327 100644
--- a/src/wispr.c
+++ b/src/wispr.c
@@ -30,9 +30,6 @@
 
 #include "connman.h"
 
-#define STATUS_URL_IPV4  "http://ipv4.connman.net/online/status.html"
-#define STATUS_URL_IPV6  "http://ipv6.connman.net/online/status.html"
-
 struct connman_wispr_message {
 	bool has_error;
 	const char *current_element;
@@ -96,6 +93,8 @@ static bool wispr_portal_web_result(GWebResult *result, gpointer user_data);
 
 static GHashTable *wispr_portal_list = NULL;
 
+static char *online_check_ipv4_url = NULL;
+static char *online_check_ipv6_url = NULL;
 static bool enable_online_to_ready_transition = false;
 
 static void connman_wispr_message_init(struct connman_wispr_message *msg)
@@ -910,10 +909,10 @@ static int wispr_portal_detect(struct connman_wispr_portal_context *wp_context)
 
 	if (wp_context->type == CONNMAN_IPCONFIG_TYPE_IPV4) {
 		g_web_set_address_family(wp_context->web, AF_INET);
-		wp_context->status_url = STATUS_URL_IPV4;
+		wp_context->status_url = online_check_ipv4_url;
 	} else {
 		g_web_set_address_family(wp_context->web, AF_INET6);
-		wp_context->status_url = STATUS_URL_IPV6;
+		wp_context->status_url = online_check_ipv6_url;
 	}
 
 	for (i = 0; nameservers[i]; i++)
@@ -1036,6 +1035,11 @@ int __connman_wispr_init(void)
 						g_direct_equal, NULL,
 						free_connman_wispr_portal);
 
+	online_check_ipv4_url =
+		connman_setting_get_string("OnlineCheckIPv4URL");
+	online_check_ipv6_url =
+		connman_setting_get_string("OnlineCheckIPv6URL");
+
 	enable_online_to_ready_transition =
 		connman_setting_get_bool("EnableOnlineToReadyTransition");
 
-- 
2.25.1

------------------------------------------------------------------------------------------------------------------
Hi Ryan,

> Nice work on improving ConnMan.
Thank you, much appreciated.

> I've just noticed that the documentation incorrectly states that the backoff period follows the power of two series.
> It seems that this must have been intended to say that it follows the series of squares, as it is clearly not the power of two series.
> Alternatively, maybe the code does follow the power of two series
> but the intervals listed in the documentation incorrectly are listed as a series of squares.
> [...]
> I know that this wording preexists your changes, but this seems like a good opportunity to fix it.
Yes, it makes sense. It was my mistake on the previous version.


Best Regards,

Emmanuel

             reply	other threads:[~2021-06-15 12:58 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-15 12:58 VAUTRIN Emmanuel (Canal Plus Prestataire) [this message]
2021-06-15 13:02 ` VAUTRIN Emmanuel (Canal Plus Prestataire)
2021-08-25 12:45   ` VAUTRIN Emmanuel (Canal Plus Prestataire)
2021-08-29 19:15     ` Daniel Wagner
2021-08-30  7:38       ` VAUTRIN Emmanuel (Canal Plus Prestataire)

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=PR1PR02MB479412B2989FCCF93E4AE58F93309@PR1PR02MB4794.eurprd02.prod.outlook.com \
    --to=emmanuel.vautrin@cpexterne.org \
    --cc=connman@lists.linux.dev \
    --subject='Re: [PATCH] wispr: Add online check url config options' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).