diff mbox series

[5/8] main: Introduce the 'OnlineCheckConnectTimeout' setting.

Message ID 23685D88-4C18-4B9D-A011-44B0AEBEF953@nuovations.com (mailing list archive)
State Not Applicable, archived
Headers show
Series Add Configurable Online Check TCP Connect Timeout | expand

Commit Message

Grant Erickson Nov. 11, 2023, 6:59 p.m. UTC
This introduces the 'OnlineCheckConnectTimeout' setting which is the
time, in decimal seconds (for example, 12.3), to wait for a successful
TCP connection to the host associated with "OnlineCheckIPv4URL" or
"OnlineCheckIPv6URL". Connections that take longer than this will be
aborted. The default value is zero ('0') which indicates that no explicit
connection timeout will be used, leaving the timeout to the underlying
operating system and network stack.
---
 src/main.c | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)
diff mbox series

Patch

diff --git a/src/main.c b/src/main.c
index d6863e668b38..e9419a603eba 100644
--- a/src/main.c
+++ b/src/main.c
@@ -47,6 +47,7 @@ 
 #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"
 
+#define DEFAULT_ONLINE_CHECK_CONNECT_TIMEOUT (0 * 1000)
 /*
  * We set the integer to 1 sec so that we have a chance to get
  * necessary IPv6 router advertisement messages that might have
@@ -110,6 +111,7 @@  static struct {
 	bool enable_online_to_ready_transition;
 	char *online_check_ipv4_url;
 	char *online_check_ipv6_url;
+	unsigned int online_check_connect_timeout_ms;
 	unsigned int online_check_initial_interval;
 	unsigned int online_check_max_interval;
 	char *online_check_interval_style;
@@ -141,6 +143,7 @@  static struct {
 	.enable_online_to_ready_transition = false,
 	.online_check_ipv4_url = NULL,
 	.online_check_ipv6_url = NULL,
+	.online_check_connect_timeout_ms = DEFAULT_ONLINE_CHECK_CONNECT_TIMEOUT,
 	.online_check_initial_interval = DEFAULT_ONLINE_CHECK_INITIAL_INTERVAL,
 	.online_check_max_interval = DEFAULT_ONLINE_CHECK_MAX_INTERVAL,
 	.online_check_interval_style = NULL,
@@ -172,6 +175,7 @@  static struct {
 #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_CONNECT_TIMEOUT "OnlineCheckConnectTimeout"
 #define CONF_ONLINE_CHECK_INITIAL_INTERVAL "OnlineCheckInitialInterval"
 #define CONF_ONLINE_CHECK_MAX_INTERVAL     "OnlineCheckMaxInterval"
 #define CONF_ONLINE_CHECK_INTERVAL_STYLE "OnlineCheckIntervalStyle"
@@ -204,6 +208,7 @@  static const char *supported_options[] = {
 	CONF_ENABLE_ONLINE_TO_READY_TRANSITION,
 	CONF_ONLINE_CHECK_IPV4_URL,
 	CONF_ONLINE_CHECK_IPV6_URL,
+	CONF_ONLINE_CHECK_CONNECT_TIMEOUT,
 	CONF_ONLINE_CHECK_INITIAL_INTERVAL,
 	CONF_ONLINE_CHECK_MAX_INTERVAL,
 	CONF_ONLINE_CHECK_INTERVAL_STYLE,
@@ -338,6 +343,7 @@  static void parse_config(GKeyFile *config)
 	char *string;
 	gsize len;
 	int integer;
+	double real;
 
 	if (!config) {
 		connman_settings.auto_connect =
@@ -530,6 +536,27 @@  static void parse_config(GKeyFile *config)
 
 	g_clear_error(&error);
 
+	/* OnlineCheckConnecTimeout */
+
+	real = g_key_file_get_double(config, "General",
+			CONF_ONLINE_CHECK_CONNECT_TIMEOUT, &error);
+	if (!error) {
+		if (real < 0) {
+			connman_warn("Incorrect online check connect timeout %f",
+				real);
+			connman_settings.online_check_connect_timeout_ms =
+				DEFAULT_ONLINE_CHECK_CONNECT_TIMEOUT;
+		} else
+			connman_settings.online_check_connect_timeout_ms =
+				real * 1000;
+	}
+
+	if (connman_settings.online_check_connect_timeout_ms)
+		connman_info("Online check connect timeout %ums",
+			connman_settings.online_check_connect_timeout_ms);
+
+	g_clear_error(&error);
+
 	string = __connman_config_get_string(config, "General",
 					CONF_ONLINE_CHECK_IPV4_URL, &error);
 	if (!error)
@@ -885,6 +912,9 @@  bool connman_setting_get_bool(const char *key)
 
 unsigned int connman_setting_get_uint(const char *key)
 {
+	if (g_str_equal(key, CONF_ONLINE_CHECK_CONNECT_TIMEOUT))
+		return connman_settings.online_check_connect_timeout_ms;
+
 	if (g_str_equal(key, CONF_ONLINE_CHECK_INITIAL_INTERVAL))
 		return connman_settings.online_check_initial_interval;