Skip to contentSkip to conversation

Address Redundant IPv4 Reachability Checks

PATCH Superseded Grant Erickson 2 participants 39 messages Nov 16, 2023 – Nov 23, 2023

lore
Share & tools
lore
#0 lore raw

cover Address Redundant IPv4 Reachability Checks

This addresses an issue in which, when 'EnableOnlineCheck' is asserted, two (2) concurrent IPv4 and one (1) IPv6 reachability checks get queued.

The issue is addressed by introducing and leveraging '__connman_wispr_cancel' in 'cancel_online_check' to ensure that a pending or in-flight WISPr portal detection request or an "online" HTTP-based Internet reachability check is canceled not only in the service module but in the WISPr module as well.

This prevents two concurrent, outstanding, and redundant IPv4 WISPr requests from being in-flight when EnableOnlineCheck is asserted.

Prior to these changes, this redundancy was set in motion by:

1. The two back-to-back IPv4 probes get triggered by both of the following paths:

a. Triggered from 'default_changed' and
'start_wispr_if_connected'. This is the newer path, chronologically, in the code base.

b. Triggered from 'service_ip_bound', 'address_updated', and
'start_online_check'. This is the older path, chronologically, in the code base.

2. With the following commits addressed:

a. 812e171 ("Close three '__connman_wisp_start' failure closure
holes.")

* With this fix alone, at minimum, the first probe above (1) would have resulted, eventually in a failure closure with 'complete_online_check'.

b. 5f95851 ("wispr: Avoid 'connman_proxy_lookup' call for
'UNKNOWN' proxy method.") fixed, the first IPv4 probe from
(1) no longer "falls down a 'hole'" and gets lost (closure- and accounting-wise).

* With this fix, the first IPv4 probe is no longer a complete throwaway--it actually succeeds. However, since it does so, it becomes the first of the two redundant IPv4 checks.

By employing '__connman_wispr_cancel', 'cancel_online_check' quells the first IPv4 check triggered from 'default_changed' and 'start_wispr_if_connected' and replaces it, fully (in both the service and WISpr modules), with the second IPv4 check triggered from 'service_ip_bound', 'address_updated', and 'start_online_check'.

Grant Erickson (17):
wispr: Rename context proxy-related data members.
wispr: Add and leverage 'is_wispr_supported'.
wispr: Add documentation to 'is_wispr_supported'.
service: Document service unref calls in 'cancel_online_check'.
wispr: Add documentation to 'wispr_portal_detect'.
wispr: Add documentation to '__connman_wispr_stop'.
wispr: Add and leverage 'cancel_connman_wispr_portal_context'.
wispr: Add documentation to 'cancel_connman_wispr_portal_context'.
gweb: Add optional OS error status parameter to 'g_web_request_*'.
wispr: Add and leverage an OS error parameter to

    '__connman_wispr_cb_t'.

service: Add IP configuration type to 'cancel_online_check'.
gweb: Add reference count debug statements.
gweb: Factor out GWeb destruction into 'g_web_free'.
wispr: Add '__connman_wispr_cancel' interface.
wispr: Add documentation to '__connman_wispr_cancel'.
wispr: Avoid double-free in 'free_wispr_routes'.
service: Leverage '__connman_wispr_cancel'.

 gweb/gweb.c      |  88 ++++++++----
 gweb/gweb.h      |   8 +-
 src/6to4.c       |   2 +-
 src/connman.h    |   5 +-
 src/service.c    |  70 ++++++++--
 src/wispr.c      | 341 ++++++++++++++++++++++++++++++++++++++++-------
 tools/web-test.c |   3 +-
 tools/wispr.c    |   8 +-
 8 files changed, 433 insertions(+), 92 deletions(-)
Signature · 1 line
2.42.0
#1 lore raw

PATCH 1/17 wispr: Rename context proxy-related data members.

This renames the WISPr/portal context structure proxy-related data members 'token' and 'timeout' as 'proxy_token' and 'proxy_timeout', respectively, to make it clearer in what context they are used.

---
 src/wispr.c | 25 +++++++++++++------------
 1 file changed, 13 insertions(+), 12 deletions(-)
src/wispr.c +13 -12
index ab763d5bada0..79cb713449bc 100644
@@ -64,7 +64,7 @@ struct connman_wispr_portal_context {
 
 	/* Portal/WISPr common */
 	GWeb *web;
-	unsigned int token;
+	unsigned int proxy_token;
 	guint request_id;
 
 	const char *status_url;
@@ -83,7 +83,7 @@ struct connman_wispr_portal_context {
 
 	GSList *route_list;
 
-	guint timeout;
+	guint proxy_timeout;
 };
 
 struct connman_wispr_portal {
@@ -184,14 +184,14 @@ static void free_connman_wispr_portal_context(
 			wp_context->wispr_portal->ipv6_context = NULL;
 	}
 
-	if (wp_context->token > 0)
-		connman_proxy_lookup_cancel(wp_context->token);
+	if (wp_context->proxy_token > 0)
+		connman_proxy_lookup_cancel(wp_context->proxy_token);
 
 	if (wp_context->request_id > 0)
 		g_web_cancel_request(wp_context->web, wp_context->request_id);
 
-	if (wp_context->timeout > 0)
-		g_source_remove(wp_context->timeout);
+	if (wp_context->proxy_timeout > 0)
+		g_source_remove(wp_context->proxy_timeout);
 
 	if (wp_context->web)
 		g_web_unref(wp_context->web);
@@ -934,7 +934,7 @@ static void proxy_callback(const char *proxy, void *user_data)
 
 	DBG("proxy %s", proxy);
 
-	wp_context->token = 0;
+	wp_context->proxy_token = 0;
 
 	proxy_server = parse_proxy(proxy);
 	if (proxy_server) {
@@ -961,7 +961,7 @@ static gboolean no_proxy_callback(gpointer user_data)
 {
 	struct connman_wispr_portal_context *wp_context = user_data;
 
-	wp_context->timeout = 0;
+	wp_context->proxy_timeout = 0;
 
 	proxy_callback("DIRECT", wp_context);
 
@@ -1049,19 +1049,20 @@ static int wispr_portal_detect(struct connman_wispr_portal_context *wp_context,
 			proxy_method != CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN) {
 		wispr_portal_context_ref(wp_context);
 
-		wp_context->token = connman_proxy_lookup(interface,
+		wp_context->proxy_token = connman_proxy_lookup(interface,
 						wp_context->status_url,
 						wp_context->service,
 						proxy_callback, wp_context);
 
-		if (wp_context->token == 0) {
+		if (wp_context->proxy_token == 0) {
 			err = -EINVAL;
 			wispr_portal_context_unref(wp_context);
 		}
-	} else if (wp_context->timeout == 0) {
+	} else if (wp_context->proxy_timeout == 0) {
 		wispr_portal_context_ref(wp_context);
 
-		wp_context->timeout = g_idle_add(no_proxy_callback, wp_context);
+		wp_context->proxy_timeout = g_idle_add(no_proxy_callback,
+						wp_context);
 	}
 
 done:
Signature · 1 line
2.42.0
#2 lore raw

PATCH 2/17 wispr: Add and leverage 'is_wispr_supported'.

In reply to Grant Erickson

This factors out from '__connman_wispr_start', adds, and leverages as an independent, file-scoped function 'is_wispr_supported'. It determines and returns Boolean status whether WISPr requests / HTTP-based Internet reachability check are supported for the specified network service based on its associated technology type.

---
 src/wispr.c | 35 ++++++++++++++++++++++-------------
 1 file changed, 22 insertions(+), 13 deletions(-)
src/wispr.c +22 -13
index 79cb713449bc..9c99402c8c6d 100644
@@ -1072,6 +1072,27 @@ done:
 	return err;
 }
 
+static bool is_wispr_supported(const struct connman_service *service)
+{
+	if (!service)
+		return false;
+
+	switch (connman_service_get_type(service)) {
+	case CONNMAN_SERVICE_TYPE_ETHERNET:
+	case CONNMAN_SERVICE_TYPE_WIFI:
+	case CONNMAN_SERVICE_TYPE_BLUETOOTH:
+	case CONNMAN_SERVICE_TYPE_CELLULAR:
+	case CONNMAN_SERVICE_TYPE_GADGET:
+		return true;
+	case CONNMAN_SERVICE_TYPE_UNKNOWN:
+	case CONNMAN_SERVICE_TYPE_SYSTEM:
+	case CONNMAN_SERVICE_TYPE_GPS:
+	case CONNMAN_SERVICE_TYPE_VPN:
+	case CONNMAN_SERVICE_TYPE_P2P:
+		return false;
+	}
+}
+
 /**
  *  @brief
  *    Start a HTTP-based Internet reachability check for the specified
@@ -1132,20 +1153,8 @@ int __connman_wispr_start(struct connman_service *service,
 	if (!wispr_portal_hash || !callback)
 		return -EINVAL;
 
-	switch (connman_service_get_type(service)) {
-	case CONNMAN_SERVICE_TYPE_ETHERNET:
-	case CONNMAN_SERVICE_TYPE_WIFI:
-	case CONNMAN_SERVICE_TYPE_BLUETOOTH:
-	case CONNMAN_SERVICE_TYPE_CELLULAR:
-	case CONNMAN_SERVICE_TYPE_GADGET:
-		break;
-	case CONNMAN_SERVICE_TYPE_UNKNOWN:
-	case CONNMAN_SERVICE_TYPE_SYSTEM:
-	case CONNMAN_SERVICE_TYPE_GPS:
-	case CONNMAN_SERVICE_TYPE_VPN:
-	case CONNMAN_SERVICE_TYPE_P2P:
+	if (!is_wispr_supported(service))
 		return -EOPNOTSUPP;
-	}
 
 	index = __connman_service_get_index(service);
 	if (index < 0)
Signature · 1 line
2.42.0
#3 lore raw

PATCH 3/17 wispr: Add documentation to 'is_wispr_supported'.

In reply to Grant Erickson

This adds documentation to the 'is_wispr_supported' function.

---
 src/wispr.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
src/wispr.c +19 -0
index 9c99402c8c6d..215c6217a02b 100644
@@ -1072,6 +1072,25 @@ done:
 	return err;
 }
 
+/**
+ *  @brief
+ *    Return whether WISPr requests / HTTP-based Internet reachability
+ *    checks are supported.
+ *
+ *  This determines whether WISPr requests / HTTP-based Internet
+ *  reachability check are supported for the specified network service
+ *  based on its associated technology type.
+ *
+ *  @param[in]  service  A pointer to the immutable network service
+ *                       for which to check WISPr requests / HTTP-based
+ *                       Internet reachability check support.
+ *
+ *  @returns
+ *    True if the network service technology type supports WISPr
+ *    requests / HTTP-based Internet reachability checks; otherwise,
+ *    false.
+ *
+ */
 static bool is_wispr_supported(const struct connman_service *service)
 {
 	if (!service)
Signature · 1 line
2.42.0
#4 lore raw

PATCH 4/17 service: Document service unref calls in 'cancel_online_check'.

In reply to Grant Erickson

This adds a comment to the two calls to 'connman_service_unref' in 'cancel_online_check' to help aid present and future readers in identifying where the balacing reference retain occurs.

---
 src/service.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
src/service.c +12 -0
index 075f3fba5abe..5fb53c2084f9 100644
@@ -1590,11 +1590,23 @@ static void cancel_online_check(struct connman_service *service)
 	if (service->online_timeout_ipv4) {
 		g_source_remove(service->online_timeout_ipv4);
 		service->online_timeout_ipv4 = 0;
+
+		/*
+		 * This balances the retained referece made when
+		 * g_timeout_add_seconds was called to schedule this
+		 * now-cancelled scheduled online check.
+		 */
 		connman_service_unref(service);
 	}
 	if (service->online_timeout_ipv6) {
 		g_source_remove(service->online_timeout_ipv6);
 		service->online_timeout_ipv6 = 0;
+
+		/*
+		 * This balances the retained referece made when
+		 * g_timeout_add_seconds was called to schedule this
+		 * now-cancelled scheduled online check.
+		 */
 		connman_service_unref(service);
 	}
 }
Signature · 1 line
2.42.0
#5 lore raw

PATCH 5/17 wispr: Add documentation to 'wispr_portal_detect'.

In reply to Grant Erickson

This adds documentation to the 'wispr_portal_detect' function.

---
 src/wispr.c | 40 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 40 insertions(+)
src/wispr.c +40 -0
index 215c6217a02b..972ef88cabd5 100644
@@ -968,6 +968,46 @@ static gboolean no_proxy_callback(gpointer user_data)
 	return FALSE;
 }
 
+/**
+ *  @brief
+ *    Start a WISPr / portal detection request / HTTP-based Internet
+ *    reachability check for the specified WISPr / portal context.
+ *
+ *  This attempts to start a WISPr / portal detection request /
+ *  HTTP-based Internet reachability check for the network service IP
+ *  configuration type associated with the provided WISPr / portal
+ *  context with the provided connection timeout.
+ *
+ *  @param[in,out]  wp_context          A pointer to the mutable WISPr
+ *                                      / portal context to supporting
+ *                                      running the WISPr request /
+ *                                      HTTP-based Internet
+ *                                      reachability check.
+ *  param[in]       connect_timeout_ms  The time, in milliseconds, for
+ *                                      the TCP connection timeout.
+ *                                      Connections that take longer
+ *                                      than this will be aborted. A
+ *                                      value of zero ('0') indicates
+ *                                      that no explicit connection
+ *                                      timeout will be used, leaving
+ *                                      the timeout to the underlying
+ *                                      operating system and its
+ *                                      network stack.
+ *
+ *  @retval  0        If the WISPr request / HTTP-based Internet
+ *                    reachability check was successfully queued.
+ *  @retval  -EINVAL  If the network interface or network interface
+ *                    index associated with @a wp_context->service is
+ *                    invalid, if @a wp_context->service has no name
+ *                    servers, or if a proxy could not be successfully
+ *                    associated with @a wp_context->service.
+ *  @retval  -ENOMEM  If a GWeb instance could not be allocated for
+ *                    the WISPr request / HTTP-based Internet
+ *                    reachability check.
+ *
+ *  @sa __connman_wispr_start
+ *
+ */
 static int wispr_portal_detect(struct connman_wispr_portal_context *wp_context,
 						guint connect_timeout_ms)
 {
Signature · 1 line
2.42.0
#6 lore raw

PATCH 6/17 wispr: Add documentation to '__connman_wispr_stop'.

In reply to Grant Erickson

This adds documentation to the '__connman_wispr_stop' function.

---
 src/wispr.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
src/wispr.c +16 -0
index 972ef88cabd5..7018dbc7d302 100644
@@ -1267,6 +1267,22 @@ free_wp:
 	return err;
 }
 
+/**
+ *  @brief
+ *    Stop all HTTP-based Internet reachability checks for the specified
+ *    network service.
+ *
+ *  This attempts to stop all HTTP-based Internet reachability checks
+ *  for the specified network service.
+ *
+ *  @param[in,out]  service  A pointer to the mutable network service
+ *                           for which to stop all reachability
+ *                           checks.
+ *
+ *  @sa __connman_wispr_start
+ *  @sa __connman_wispr_cancel
+ *
+ */
 void __connman_wispr_stop(struct connman_service *service)
 {
 	struct connman_wispr_portal *wispr_portal;
Signature · 1 line
2.42.0
#7 lore raw

PATCH 7/17 wispr: Add and leverage 'cancel_connman_wispr_portal_context'.

In reply to Grant Erickson

This factors out from 'free_connman_wispr_portal_context', adds, and leverages as an independent, file-scoped function 'cancel_connman_wispr_portal_context'. It attempts to cancel any outstanding WISPr request associated with the specified WISPr/portal context, deallocating any resources associated with the context, except for the context itself which still requires invoking 'free_connman_wispr_portal_context'.

---
 src/wispr.c | 60 ++++++++++++++++++++++++++++++++++++++++-------------
 1 file changed, 46 insertions(+), 14 deletions(-)
src/wispr.c +46 -14
index 7018dbc7d302..84d4b1d0efb4 100644
@@ -166,9 +166,12 @@ static void free_wispr_routes(struct connman_wispr_portal_context *wp_context)
 	}
 }
 
-static void free_connman_wispr_portal_context(
+static void cancel_connman_wispr_portal_context(
 		struct connman_wispr_portal_context *wp_context)
 {
+	if (!wp_context)
+		return;
+
 	DBG("wispr/portal context %p service %p (%s) type %d (%s)",
 		wp_context,
 		wp_context->service,
@@ -176,38 +179,67 @@ static void free_connman_wispr_portal_context(
 		wp_context->type,
 		__connman_ipconfig_type2string(wp_context->type));
 
-	if (wp_context->wispr_portal) {
-		if (wp_context->wispr_portal->ipv4_context == wp_context)
-			wp_context->wispr_portal->ipv4_context = NULL;
-
-		if (wp_context->wispr_portal->ipv6_context == wp_context)
-			wp_context->wispr_portal->ipv6_context = NULL;
-	}
-
-	if (wp_context->proxy_token > 0)
+	if (wp_context->proxy_token > 0) {
 		connman_proxy_lookup_cancel(wp_context->proxy_token);
+		wp_context->proxy_token = 0;
+	}
 
-	if (wp_context->request_id > 0)
+	if (wp_context->request_id > 0) {
 		g_web_cancel_request(wp_context->web, wp_context->request_id);
+		wp_context->request_id = 0;
+	}
 
-	if (wp_context->proxy_timeout > 0)
+	if (wp_context->proxy_timeout > 0) {
 		g_source_remove(wp_context->proxy_timeout);
+		wp_context->proxy_timeout = 0;
+	}
 
-	if (wp_context->web)
+	if (wp_context->web) {
 		g_web_unref(wp_context->web);
+		wp_context->web = NULL;
+	}
 
 	g_free(wp_context->redirect_url);
+	wp_context->redirect_url = NULL;
 
-	if (wp_context->wispr_parser)
+	if (wp_context->wispr_parser) {
 		g_web_parser_unref(wp_context->wispr_parser);
+		wp_context->wispr_parser = NULL;
+	}
 
 	connman_wispr_message_init(&wp_context->wispr_msg);
 
 	g_free(wp_context->wispr_username);
+	wp_context->wispr_username = NULL;
+
 	g_free(wp_context->wispr_password);
+	wp_context->wispr_password = NULL;
+
 	g_free(wp_context->wispr_formdata);
+	wp_context->wispr_formdata = NULL;
 
 	free_wispr_routes(wp_context);
+}
+
+static void free_connman_wispr_portal_context(
+		struct connman_wispr_portal_context *wp_context)
+{
+	DBG("wispr/portal context %p service %p (%s) type %d (%s)",
+		wp_context,
+		wp_context->service,
+		connman_service_get_identifier(wp_context->service),
+		wp_context->type,
+		__connman_ipconfig_type2string(wp_context->type));
+
+	if (wp_context->wispr_portal) {
+		if (wp_context->wispr_portal->ipv4_context == wp_context)
+			wp_context->wispr_portal->ipv4_context = NULL;
+
+		if (wp_context->wispr_portal->ipv6_context == wp_context)
+			wp_context->wispr_portal->ipv6_context = NULL;
+	}
+
+	cancel_connman_wispr_portal_context(wp_context);
 
 	g_free(wp_context);
 }
Signature · 1 line
2.42.0
#8 lore raw

PATCH 8/17 wispr: Add documentation to 'cancel_connman_wispr_portal_context'.

In reply to Grant Erickson

This adds documentation to the 'cancel_connman_wispr_portal_context' function.

---
 src/wispr.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
src/wispr.c +18 -0
index 84d4b1d0efb4..1e62e0cd2dee 100644
@@ -166,6 +166,24 @@ static void free_wispr_routes(struct connman_wispr_portal_context *wp_context)
 	}
 }
 
+/**
+ *  @brief
+ *    Cancel a WISPr/portal request.
+ *
+ *  This attempts to cancel any outstanding request associated with
+ *  the specified WISPr/portal context. This deallocates any resources
+ *  associated with the context, except for the context itself which
+ *  requires invoking #free_connman_wispr_portal_context.
+ *
+ *  @param[in,out]  wp_context  A pointer to the mutable WISPr/portal
+ *                              context for which to cancel an outstanding
+ *                              request, whether a reachability check
+ *                              or otherwise.
+ *
+ *  @sa create_connman_wispr_portal_context
+ *  @sa free_connman_wispr_portal_context
+ *
+ */
 static void cancel_connman_wispr_portal_context(
 		struct connman_wispr_portal_context *wp_context)
 {
Signature · 1 line
2.42.0
#9 lore raw

PATCH 9/17 gweb: Add optional OS error status parameter to 'g_web_request_*'.

In reply to Grant Erickson

This adds an optional operating system error status parameter to 'g_web_request_{get,post,post_file}' allowing callers, so interested, to obtain the underlying failure status for a failed GWeb request.

---
 gweb/gweb.c      | 59 +++++++++++++++++++++++++++++++++---------------
 gweb/gweb.h      |  8 ++++---
 src/6to4.c       |  2 +-
 src/wispr.c      |  6 ++---
 tools/web-test.c |  3 ++-
 tools/wispr.c    |  8 +++----
 6 files changed, 56 insertions(+), 30 deletions(-)
gweb/gweb.c +41 -18
index 1463b588d411..1cf830a46773 100644
@@ -2255,23 +2255,31 @@ static bool is_ip_address(const char *host)
 static guint do_request(GWeb *web, const char *url,
 				const char *type, GWebInputFunc input,
 				int fd, gsize length, GWebResultFunc func,
-				GWebRouteFunc route, gpointer user_data)
+				GWebRouteFunc route, gpointer user_data,
+				int *err)
 {
 	struct web_session *session;
 	const gchar *host;
+	int request_id = 0;
+	int status = 0;
 
-	if (!web || !url)
-		return 0;
+	if (!web || !url) {
+		status = -EINVAL;
+		goto done;
+	}
 
 	debug(web, "request %s", url);
 
 	session = g_try_new0(struct web_session, 1);
-	if (!session)
-		return 0;
+	if (!session) {
+		status = -ENOMEM;
+		goto done;
+	}
 
-	if (parse_request_and_proxy_urls(session, url, web->proxy) < 0) {
+	status = parse_request_and_proxy_urls(session, url, web->proxy);
+	if (status < 0) {
 		free_session(session);
-		return 0;
+		goto done;
 	}
 
 	debug(web, "proxy host %s", session->address);
@@ -2299,14 +2307,16 @@ static guint do_request(GWeb *web, const char *url,
 	session->receive_buffer = g_try_malloc(DEFAULT_BUFFER_SIZE);
 	if (!session->receive_buffer) {
 		free_session(session);
-		return 0;
+		status = -ENOMEM;
+		goto done;
 	}
 
 	session->result.headers = g_hash_table_new_full(g_str_hash, g_str_equal,
 							g_free, g_free);
 	if (!session->result.headers) {
 		free_session(session);
-		return 0;
+		status = -ENOMEM;
+		goto done;
 	}
 
 	session->receive_space = DEFAULT_BUFFER_SIZE;
@@ -2325,33 +2335,46 @@ static guint do_request(GWeb *web, const char *url,
 	} else {
 		session->resolv_action = g_resolv_lookup_hostname(web->resolv,
 					host, resolv_result, session);
-		if (session->resolv_action == 0) {
+		if (session->resolv_action <= 0) {
 			free_session(session);
-			return 0;
+			status = session->resolv_action < 0 ?
+						session->resolv_action :
+						-ENOENT;
+			goto done;
 		}
 	}
 
 	web->session_list = g_list_append(web->session_list, session);
 
-	return web->next_query_id++;
+	request_id = web->next_query_id++;
+
+done:
+	if (err)
+		*err = status;
+
+	return request_id;
 }
 
 guint g_web_request_get(GWeb *web, const char *url, GWebResultFunc func,
-		GWebRouteFunc route, gpointer user_data)
+		GWebRouteFunc route, gpointer user_data, int *err)
 {
-	return do_request(web, url, NULL, NULL, -1, 0, func, route, user_data);
+	return do_request(web, url, NULL, NULL, -1, 0,
+		func, route, user_data, err);
 }
 
 guint g_web_request_post(GWeb *web, const char *url,
 				const char *type, GWebInputFunc input,
-				GWebResultFunc func, gpointer user_data)
+				GWebResultFunc func, gpointer user_data,
+				int *err)
 {
-	return do_request(web, url, type, input, -1, 0, func, NULL, user_data);
+	return do_request(web, url, type, input, -1, 0,
+		func, NULL, user_data, err);
 }
 
 guint g_web_request_post_file(GWeb *web, const char *url,
 				const char *type, const char *file,
-				GWebResultFunc func, gpointer user_data)
+				GWebResultFunc func, gpointer user_data,
+				int *err)
 {
 	struct stat st;
 	int fd;
@@ -2365,7 +2388,7 @@ guint g_web_request_post_file(GWeb *web, const char *url,
 		return 0;
 
 	ret = do_request(web, url, type, NULL, fd, st.st_size, func, NULL,
-			user_data);
+			user_data, err);
 	if (ret == 0)
 		close(fd);
 
gweb/gweb.h +5 -3
index 3c50979cfd0a..7c65aebf4698 100644
@@ -150,13 +150,15 @@ bool g_web_get_close_connection(GWeb *web);
 
 guint g_web_request_get(GWeb *web, const char *url,
 				GWebResultFunc func, GWebRouteFunc route,
-				gpointer user_data);
+				gpointer user_data, int *err);
 guint g_web_request_post(GWeb *web, const char *url,
 				const char *type, GWebInputFunc input,
-				GWebResultFunc func, gpointer user_data);
+				GWebResultFunc func, gpointer user_data,
+				int *err);
 guint g_web_request_post_file(GWeb *web, const char *url,
 				const char *type, const char *file,
-				GWebResultFunc func, gpointer user_data);
+				GWebResultFunc func, gpointer user_data,
+				int *err);
 
 bool g_web_cancel_request(GWeb *web, guint id);
 
src/6to4.c +1 -1
index 71a288277104..5542b339691a 100644
@@ -318,7 +318,7 @@ static void tun_newlink(unsigned flags, unsigned change, void *user_data)
 			g_web_set_debug(web, web_debug, "6to4");
 
 		web_request_id = g_web_request_get(web, STATUS_URL,
-				web_result, NULL,  NULL);
+				web_result, NULL,  NULL, NULL);
 
 		newlink_timeout(NULL);
 	}
src/wispr.c +3 -3
index 1e62e0cd2dee..4b4c9c1e59ec 100644
@@ -634,7 +634,7 @@ static void wispr_portal_request_portal(
 					wp_context->status_url,
 					wispr_portal_web_result,
 					wispr_route_request,
-					wp_context);
+					wp_context, NULL);
 
 	if (wp_context->request_id == 0) {
 		wp_context->cb(wp_context->service, wp_context->type, false);
@@ -751,7 +751,7 @@ static void wispr_portal_request_wispr_login(struct connman_service *service,
 					wp_context->wispr_msg.login_url,
 					"application/x-www-form-urlencoded",
 					wispr_input, wispr_portal_web_result,
-					wp_context);
+					wp_context, NULL);
 
 	connman_wispr_message_init(&wp_context->wispr_msg);
 }
@@ -906,7 +906,7 @@ static bool wispr_portal_web_result(GWebResult *result, gpointer user_data)
 		wispr_portal_context_ref(wp_context);
 		wp_context->request_id = g_web_request_get(wp_context->web,
 				redirect, wispr_portal_web_result,
-				wispr_route_request, wp_context);
+				wispr_route_request, wp_context, NULL);
 
 		goto done;
 	case GWEB_HTTP_STATUS_CODE_BAD_REQUEST:
tools/web-test.c +2 -1
index 55c58af5a7dc..a65e6c115c41 100644
@@ -150,7 +150,8 @@ int main(int argc, char *argv[])
 
 	timer = g_timer_new();
 
-	if (g_web_request_get(web, argv[1], web_result, NULL,  NULL) == 0) {
+	if (g_web_request_get(web, argv[1], web_result,
+			NULL, NULL, NULL) == 0) {
 		fprintf(stderr, "Failed to start request\n");
 		return 1;
 	}
tools/wispr.c +4 -4
index e56dfc169411..ef7b60d3f5ca 100644
@@ -531,7 +531,7 @@ static bool wispr_result(GWebResult *result, gpointer user_data)
 		printf("\n");
 
 		wispr->request = g_web_request_get(wispr->web, redirect,
-				wispr_result, wispr_route, wispr);
+				wispr_result, wispr_route, wispr, NULL);
 
 		return false;
 	}
@@ -591,7 +591,7 @@ static bool wispr_result(GWebResult *result, gpointer user_data)
 		printf("\n");
 
 		wispr->request = g_web_request_get(wispr->web, redirect,
-				wispr_result, NULL, wispr);
+				wispr_result, NULL, wispr, NULL);
 
 		return false;
 	}
@@ -608,7 +608,7 @@ static gboolean execute_login(gpointer user_data)
 
 	wispr->request = g_web_request_post(wispr->web, wispr->msg.login_url,
 					"application/x-www-form-urlencoded",
-					wispr_input, wispr_result, wispr);
+					wispr_input, wispr_result, wispr, NULL);
 
 	wispr_msg_init(&wispr->msg);
 
@@ -694,7 +694,7 @@ int main(int argc, char *argv[])
 						parser_callback, &wispr);
 
 	wispr.request = g_web_request_get(wispr.web, option_url,
-			wispr_result, wispr_route, &wispr);
+			wispr_result, wispr_route, &wispr, NULL);
 
 	if (wispr.request == 0) {
 		fprintf(stderr, "Failed to start request\n");
Signature · 1 line
2.42.0
#10 lore raw

PATCH 10/17 wispr: Add and leverage an OS error parameter to '__connman_wispr_cb_t'.

In reply to Grant Erickson

This adds and leverages an operating system error parameter to '__connman_wispr_cb_t' such that such callbacks can leverage the error status when 'success' is false to either log the status or take conditional action.

---
 src/connman.h |  3 ++-
 src/service.c | 15 +++++++++++----
 src/wispr.c   | 37 ++++++++++++++++++++++++++++++-------
 3 files changed, 43 insertions(+), 12 deletions(-)
src/connman.h +2 -1
index 143a087701d8..d5aa6f5599e7 100644
@@ -525,7 +525,8 @@ void __connman_wpad_stop(struct connman_service *service);
 
 typedef void (*__connman_wispr_cb_t) (struct connman_service *service,
 				enum connman_ipconfig_type type,
-				bool success);
+				bool success,
+				int err);
 
 int __connman_wispr_init(void);
 void __connman_wispr_cleanup(void);
src/service.c +11 -4
index 5fb53c2084f9..0882cd167699 100644
@@ -163,7 +163,8 @@ static void vpn_auto_connect(void);
 static void trigger_autoconnect(struct connman_service *service);
 static void complete_online_check(struct connman_service *service,
 					enum connman_ipconfig_type type,
-					bool success);
+					bool success,
+					int err);
 static bool service_downgrade_online_state(struct connman_service *service);
 
 struct find_data {
@@ -1902,6 +1903,11 @@ static void reschedule_online_check(struct connman_service *service,
  *                           check.
  *  @param[in]      success  A Boolean indicating whether the previously-
  *                           requested online check was successful.
+ *  @param[in]      err      The error status associated with previously-
+ *                           requested online check. This is expected
+ *                           to be zero ('0') if @a success is @a true
+ *                           and less than zero ('< 0') if @a success
+ *                           is @a false.
  *
  *  @sa cancel_online_check
  *  @sa start_online_check
@@ -1911,16 +1917,17 @@ static void reschedule_online_check(struct connman_service *service,
  */
 static void complete_online_check(struct connman_service *service,
 					enum connman_ipconfig_type type,
-					bool success)
+					bool success,
+					int err)
 {
 	unsigned int *interval;
 	guint *timeout;
 
-	DBG("service %p (%s) type %d (%s) success %d\n",
+	DBG("service %p (%s) type %d (%s) success %d err %d (%s)\n",
 		service,
 		connman_service_get_identifier(service),
 		type, __connman_ipconfig_type2string(type),
-		success);
+		success, err, strerror(-err));
 
 	if (type == CONNMAN_IPCONFIG_TYPE_IPV4) {
 		interval = &service->online_check_interval_ipv4;
src/wispr.c +30 -7
index 4b4c9c1e59ec..9d471628e705 100644
@@ -564,7 +564,7 @@ static void portal_manage_success_status(GWebResult *result,
 				&str))
 		connman_info("Client-Timezone: %s", str);
 
-	wp_context->cb(service, type, true);
+	wp_context->cb(service, type, true, 0);
 }
 
 static bool wispr_route_request(const char *address, int ai_family,
@@ -618,6 +618,8 @@ static bool wispr_route_request(const char *address, int ai_family,
 static void wispr_portal_request_portal(
 		struct connman_wispr_portal_context *wp_context)
 {
+	int err = 0;
+
 	DBG("wispr/portal context %p service %p (%s) type %d (%s)",
 		wp_context,
 		wp_context->service,
@@ -634,10 +636,13 @@ static void wispr_portal_request_portal(
 					wp_context->status_url,
 					wispr_portal_web_result,
 					wispr_route_request,
-					wp_context, NULL);
+					wp_context, &err);
 
 	if (wp_context->request_id == 0) {
-		wp_context->cb(wp_context->service, wp_context->type, false);
+		wp_context->cb(wp_context->service,
+						wp_context->type,
+						false,
+						err);
 		wispr_portal_error(wp_context);
 		wispr_portal_context_unref(wp_context);
 	}
@@ -910,11 +915,26 @@ static bool wispr_portal_web_result(GWebResult *result, gpointer user_data)
 
 		goto done;
 	case GWEB_HTTP_STATUS_CODE_BAD_REQUEST:
+		wp_context->cb(wp_context->service,
+				wp_context->type,
+				false,
+				-EINVAL);
+		break;
+
 	case GWEB_HTTP_STATUS_CODE_NOT_FOUND:
-	case GWEB_HTTP_STATUS_CODE_REQUEST_TIMEOUT:
-		wp_context->cb(wp_context->service, wp_context->type, false);
+		wp_context->cb(wp_context->service,
+				wp_context->type,
+				false,
+				-ENOENT);
+		break;
 
+	case GWEB_HTTP_STATUS_CODE_REQUEST_TIMEOUT:
+		wp_context->cb(wp_context->service,
+				wp_context->type,
+				false,
+				-ETIMEDOUT);
 		break;
+
 	case GWEB_HTTP_STATUS_CODE_HTTP_VERSION_NOT_SUPPORTED:
 		wispr_portal_context_ref(wp_context);
 		__connman_agent_request_browser(wp_context->service,
@@ -977,7 +997,10 @@ static void proxy_callback(const char *proxy, void *user_data)
 	if (!proxy) {
 		DBG("no valid proxy");
 
-		wp_context->cb(wp_context->service, wp_context->type, false);
+		wp_context->cb(wp_context->service,
+				wp_context->type,
+				false,
+				-EINVAL);
 
 		return;
 	}
@@ -1311,7 +1334,7 @@ int __connman_wispr_start(struct connman_service *service,
 	return 0;
 
 free_wp:
-	wp_context->cb(wp_context->service, wp_context->type, false);
+	wp_context->cb(wp_context->service, wp_context->type, false, err);
 
 	g_hash_table_remove(wispr_portal_hash, GINT_TO_POINTER(index));
 	return err;
Signature · 1 line
2.42.0
#11 lore raw

PATCH 11/17 service: Add IP configuration type to 'cancel_online_check'.

In reply to Grant Erickson

WISPr / portal detection and HTTP-based "online" Internet reachability checks are, by design, IP configuration-specific. There may be parallel, independent requests or checks in flight: one for IPv4 and one for IPv6. Consequently, when attempting to cancel such requests or checks, require the IP configuration type to indicate which specific request or check is to be canceled.

---
 src/service.c | 25 ++++++++++++++++---------
 1 file changed, 16 insertions(+), 9 deletions(-)
src/service.c +16 -9
index 0882cd167699..d78ed0123160 100644
@@ -1559,11 +1559,11 @@ static guint online_check_timeout_compute_geometric(unsigned int interval)
 /**
  *  @brief
  *    Cancel any "online" HTTP-based Internet reachability checks for
- *    the specified network service.
+ *    the specified network service IP configuration type.
  *
  *  This cancels any current or pending IPv4 and/or IPv6 "online"
  *  HTTP-based Internet reachability checks for the specified network
- *  service.
+ *  service IP configuration type.
  *
  *  @note
  *    Any lingering WISPr portal reachability context will be lazily
@@ -1574,6 +1574,9 @@ static guint online_check_timeout_compute_geometric(unsigned int interval)
  *                           for which any current or pending IPv4 or
  *                           IPv6 "online" reachability checks should
  *                           be canceled.
+ *  @param[in]      type     The IP configuration type for which the
+ *                           "online" reachability check is to be
+ *                           canceled.
  *
  *  @sa start_online_check
  *  @sa complete_online_check
@@ -1581,14 +1584,18 @@ static guint online_check_timeout_compute_geometric(unsigned int interval)
  *  @sa __connman_wispr_stop
  *
  */
-static void cancel_online_check(struct connman_service *service)
+static void cancel_online_check(struct connman_service *service,
+				enum connman_ipconfig_type type)
 {
-	DBG("service %p (%s) online_timeout_ipv4 %d online_timeout_ipv6 %d",
+	DBG("service %p (%s) type %d (%s) "
+		"online_timeout_ipv4 %d online_timeout_ipv6 %d",
 		service, connman_service_get_identifier(service),
+		type, __connman_ipconfig_type2string(type),
 		service->online_timeout_ipv4,
 		service->online_timeout_ipv6);
 
-	if (service->online_timeout_ipv4) {
+	if (type == CONNMAN_IPCONFIG_TYPE_IPV4 &&
+		service->online_timeout_ipv4) {
 		g_source_remove(service->online_timeout_ipv4);
 		service->online_timeout_ipv4 = 0;
 
@@ -1598,8 +1605,8 @@ static void cancel_online_check(struct connman_service *service)
 		 * now-cancelled scheduled online check.
 		 */
 		connman_service_unref(service);
-	}
-	if (service->online_timeout_ipv6) {
+	} else if (type == CONNMAN_IPCONFIG_TYPE_IPV6 &&
+		service->online_timeout_ipv6) {
 		g_source_remove(service->online_timeout_ipv6);
 		service->online_timeout_ipv6 = 0;
 
@@ -1683,7 +1690,7 @@ static void start_online_check(struct connman_service *service,
 		return;
 
 	if (type == CONNMAN_IPCONFIG_TYPE_IPV6 || check_proxy_setup(service)) {
-		cancel_online_check(service);
+		cancel_online_check(service, type);
 		__connman_service_wispr_start(service, type);
 	}
 }
@@ -7185,7 +7192,7 @@ int __connman_service_ipconfig_indicate_state(struct connman_service *service,
 
 	if (is_connected(old_state) && !is_connected(new_state)) {
 		nameserver_remove_all(service, type);
-		cancel_online_check(service);
+		cancel_online_check(service, type);
 	}
 
 	if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
Signature · 1 line
2.42.0
#12 lore raw

PATCH 12/17 gweb: Add reference count debug statements.

In reply to Grant Erickson

This adds reference count debugging statements in 'g_web_ref' and 'g_web_unref', similar but not identical to other modules in the project.

---
 gweb/gweb.c | 6 ++++++
 1 file changed, 6 insertions(+)
gweb/gweb.c +6 -0
index 1cf830a46773..994c33638e55 100644
@@ -414,6 +414,9 @@ GWeb *g_web_ref(GWeb *web)
 	if (!web)
 		return NULL;
 
+	debug(web, "ref %d",
+		web->ref_count + 1);
+
 	__sync_fetch_and_add(&web->ref_count, 1);
 
 	return web;
@@ -424,6 +427,9 @@ void g_web_unref(GWeb *web)
 	if (!web)
 		return;
 
+	debug(web, "ref %d",
+		web->ref_count - 1);
+
 	if (__sync_fetch_and_sub(&web->ref_count, 1) != 1)
 		return;
 
Signature · 1 line
2.42.0
#13 lore raw

PATCH 13/17 gweb: Factor out GWeb destruction into 'g_web_free'.

In reply to Grant Erickson

This factors out the destruction of a GWeb object into 'g_web_free' to make it clearer, during debugging and development, when destruction of the reference-counted object actually occurs and which aspects of the object are being destroyed.

---
 gweb/gweb.c | 29 ++++++++++++++++++++---------
 1 file changed, 20 insertions(+), 9 deletions(-)
gweb/gweb.c +20 -9
index 994c33638e55..96d543af8440 100644
@@ -327,6 +327,8 @@ static void free_session(struct web_session *session)
 	if (!session)
 		return;
 
+	debug(session->web, "session %p", session);
+
 	g_free(session->request);
 
 	web = session->web;
@@ -368,6 +370,8 @@ static void flush_sessions(GWeb *web)
 {
 	GList *list;
 
+	debug(web, "flushing sessions...");
+
 	for (list = g_list_first(web->session_list);
 					list; list = g_list_next(list))
 		free_session(list->data);
@@ -422,16 +426,9 @@ GWeb *g_web_ref(GWeb *web)
 	return web;
 }
 
-void g_web_unref(GWeb *web)
+static void g_web_free(GWeb *web)
 {
-	if (!web)
-		return;
-
-	debug(web, "ref %d",
-		web->ref_count - 1);
-
-	if (__sync_fetch_and_sub(&web->ref_count, 1) != 1)
-		return;
+	debug(web, "freeing...");
 
 	flush_sessions(web);
 
@@ -447,6 +444,20 @@ void g_web_unref(GWeb *web)
 	g_free(web);
 }
 
+void g_web_unref(GWeb *web)
+{
+	if (!web)
+		return;
+
+	debug(web, "ref %d",
+		web->ref_count - 1);
+
+	if (__sync_fetch_and_sub(&web->ref_count, 1) != 1)
+		return;
+
+	g_web_free(web);
+}
+
 bool g_web_supports_tls(void)
 {
 	return g_io_channel_supports_tls();
Signature · 1 line
2.42.0
#14 lore raw

PATCH 14/17 wispr: Add '__connman_wispr_cancel' interface.

In reply to Grant Erickson

This adds a heretofore-missing '__connman_wispr_cancel' interface. It attempts to cancel a HTTP-based Internet reachability check for the specified network service IP configuration type.

If a matching WISPr portal detect request or HTTP-based Internet reachability check is found, the original callback specified with '__connman_wispr_start' will be invoked with a success value of zero ('0') or false and an error value of -ECANCELED.

---
 src/connman.h |  2 ++
 src/wispr.c   | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 57 insertions(+)
src/connman.h +2 -0
index d5aa6f5599e7..ae04cd9a26c6 100644
@@ -534,6 +534,8 @@ int __connman_wispr_start(struct connman_service *service,
 					enum connman_ipconfig_type type,
 					guint connect_timeout_ms,
 					__connman_wispr_cb_t callback);
+int __connman_wispr_cancel(struct connman_service *service,
+					enum connman_ipconfig_type type);
 void __connman_wispr_stop(struct connman_service *service);
 
 #include <connman/technology.h>
src/wispr.c +55 -0

61 lines not on this page · raw message

Signature · 1 line
2.42.0
#15 lore raw

PATCH 15/17 wispr: Add documentation to '__connman_wispr_cancel'.

In reply to Grant Erickson

This adds documentation to the '__connman_wispr_cancel' function.

---
 src/wispr.c | 35 +++++++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)
src/wispr.c +35 -0
index f42429f56e07..8b555cfd5d6f 100644
@@ -1340,6 +1340,41 @@ free_wp:
 	return err;
 }
 
+/**
+ *  @brief
+ *    Cancel a HTTP-based Internet reachability check for the specified
+ *    network service IP configuration type.
+ *
+ *  This attempts to cancel a HTTP-based Internet reachability check
+ *  for the specified network service IP configuration type.
+ *
+ *  If a matching HTTP-based Internet reachability check is found, the
+ *  original callback specified with #__connman_wispr_start will be
+ *  invoked with a success value of zero ('0') or false and an error
+ *  value of -ECANCELED.
+ *
+ *  @param[in,out]  service             A pointer to the mutable network
+ *                                      service for which to cancel the
+ *                                      reachability check.
+ *  @param[in]      type                The IP configuration type for
+ *                                      which the reachability check
+ *                                      is to be cancelled.
+ *
+ *  @retval  0            If a matching HTTP-based Internet reachability
+ *                        check was successfully cancelled.
+ *  @retval  -EINVAL      If the IP configuration type is not X or Y or
+ *                        if the network interface index associated
+ *                        with @a service is invalid.
+ *  @retval  -ENOENT      If a matching HTTP-based Internet reachability
+ *                        check could not be found.
+ *  @retval  -EOPNOTSUPP  If HTTP-based Internet reachability checks are
+ *                        not supported for the technology type
+ *                        associated with @a service.
+ *
+ *  @sa __connman_wispr_start
+ *  @sa __connman_wispr_stop
+ *
+ */
 int __connman_wispr_cancel(struct connman_service *service,
 					enum connman_ipconfig_type type)
 {
Signature · 1 line
2.42.0
#16 lore raw

PATCH 16/17 wispr: Avoid double-free in 'free_wispr_routes'.

In reply to Grant Erickson

Now that 'free_wispr_routes' can be invoked in terminal free-only as well as cancel-latently-followed-by-free contexts, ensure that a double-free is avoided with both the 'route->address' and 'wp_context->route_list->data' by explicitly nulling them after calling 'g_free' on them.

---
 src/wispr.c | 3 +++
 1 file changed, 3 insertions(+)
src/wispr.c +3 -0
index 8b555cfd5d6f..4a52b03c2ee7 100644
@@ -158,7 +158,10 @@ static void free_wispr_routes(struct connman_wispr_portal_context *wp_context)
 		}
 
 		g_free(route->address);
+		route->address = NULL;
+
 		g_free(route);
+		wp_context->route_list->data = NULL;
 
 		wp_context->route_list =
 			g_slist_delete_link(wp_context->route_list,
Signature · 1 line
2.42.0
#17 lore raw

PATCH 17/17 service: Leverage '__connman_wispr_cancel'.

In reply to Grant Erickson

This leverages the newly-introduced '__connman_wispr_cancel' in 'cancel_online_check' to ensure that a pending or in-flight WISPr portal detection request or an "online" HTTP-based Internet reachability check is canceled not only in the service module but in the WISPr module as well.

This prevents two concurrent, outstanding, and redundant IPv4 WISPr requests from being in-flight when 'EnableOnlineCheck' is asserted.

Prior to this change, this redundancy was set in motion by:

1. The two back-to-back IPv4 probes get triggered by both of the following paths:

a. Triggered from 'default_changed' and 'start_wispr_if_connected'.
This is the newer path, chronologically, in the code base.

b. Triggered from 'service_ip_bound', 'address_updated', and
'start_online_check'. This is the older path, chronologically, in the code base.

2. With the following commits addressed:

a. 812e171 ("Close three '__connman_wisp_start' failure closure
holes.")

* With this fix alone, at minimum, the first probe above (1) would have resulted, eventually in a failure closure with 'complete_online_check'.

b. 5f95851 ("wispr: Avoid 'connman_proxy_lookup' call for UNKNOWN
proxy method.") fixed, the first IPv4 probe from (1) no longer "falls down a 'hole'" and gets lost (closure- and accounting- wise).

* With this fix, the first IPv4 probe is no longer a complete throwaway--it actually succeeds. However, since it does so, it becomes the first of the two redundant IPv4 checks.

By employing '__connman_wispr_cancel', 'cancel_online_check' quells the first IPv4 check triggered from 'default_changed' and 'start_wispr_if_connected' and replaces it, fully (in BOTH the service and WISpr modules), with the second IPv4 check triggered from 'service_ip_bound', 'address_updated', and 'start_online_check'.

---
 src/service.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
src/service.c +18 -0
index d78ed0123160..9f6e28d34be4 100644
@@ -1594,6 +1594,19 @@ static void cancel_online_check(struct connman_service *service,
 		service->online_timeout_ipv4,
 		service->online_timeout_ipv6);
 
+	/*
+	 * First, ensure that the reachability check is cancelled in the
+	 * WISPr module. This may fail, however, we ignore any such
+	 * failures as we still want to cancel any outstanding check from
+	 * this module as well.
+	 */
+	__connman_wispr_cancel(service, type);
+
+	/*
+	 * Now that the reachability check has been cancelled in the WISPr
+	 * module, cancel any outstanding check that may be scheduled in
+	 * this module.
+	 */
 	if (type == CONNMAN_IPCONFIG_TYPE_IPV4 &&
 		service->online_timeout_ipv4) {
 		g_source_remove(service->online_timeout_ipv4);
@@ -1936,6 +1949,11 @@ static void complete_online_check(struct connman_service *service,
 		type, __connman_ipconfig_type2string(type),
 		success, err, strerror(-err));
 
+	if (!success && err == -ECANCELED) {
+		DBG("online check was canceled; no action taken");
+		return;
+	}
+
 	if (type == CONNMAN_IPCONFIG_TYPE_IPV4) {
 		interval = &service->online_check_interval_ipv4;
 		timeout = &service->online_timeout_ipv4;
Signature · 1 line
2.42.0
#18 lore raw
In reply to Grant Erickson

Hi Grant,

Quoted 71 lines

This addresses an issue in which, when 'EnableOnlineCheck' is asserted, two (2) concurrent IPv4 and one (1) IPv6 reachability checks get queued.

The issue is addressed by introducing and leveraging '__connman_wispr_cancel' in 'cancel_online_check' to ensure that a pending or in-flight WISPr portal detection request or an "online" HTTP-based Internet reachability check is canceled not only in the service module but in the WISPr module as well.

This prevents two concurrent, outstanding, and redundant IPv4 WISPr requests from being in-flight when EnableOnlineCheck is asserted.

Prior to these changes, this redundancy was set in motion by:

1. The two back-to-back IPv4 probes get triggered by both of the following paths:

a. Triggered from 'default_changed' and
'start_wispr_if_connected'. This is the newer path, chronologically, in the code base.

b. Triggered from 'service_ip_bound', 'address_updated', and
'start_online_check'. This is the older path, chronologically, in the code base.

2. With the following commits addressed:

a. 812e171 ("Close three '__connman_wisp_start' failure closure
holes.")

* With this fix alone, at minimum, the first probe above (1) would have resulted, eventually in a failure closure with 'complete_online_check'.

b. 5f95851 ("wispr: Avoid 'connman_proxy_lookup' call for
'UNKNOWN' proxy method.") fixed, the first IPv4 probe from
(1) no longer "falls down a 'hole'" and gets lost (closure- and accounting-wise).

* With this fix, the first IPv4 probe is no longer a complete throwaway--it actually succeeds. However, since it does so, it becomes the first of the two redundant IPv4 checks.

By employing '__connman_wispr_cancel', 'cancel_online_check' quells the first IPv4 check triggered from 'default_changed' and 'start_wispr_if_connected' and replaces it, fully (in both the service and WISpr modules), with the second IPv4 check triggered from 'service_ip_bound', 'address_updated', and 'start_online_check'.

Grant Erickson (17):
wispr: Rename context proxy-related data members.
wispr: Add and leverage 'is_wispr_supported'.
wispr: Add documentation to 'is_wispr_supported'.
service: Document service unref calls in 'cancel_online_check'.
wispr: Add documentation to 'wispr_portal_detect'.
wispr: Add documentation to '__connman_wispr_stop'.
wispr: Add and leverage 'cancel_connman_wispr_portal_context'.
wispr: Add documentation to 'cancel_connman_wispr_portal_context'.
gweb: Add optional OS error status parameter to 'g_web_request_*'.
wispr: Add and leverage an OS error parameter to
'__connman_wispr_cb_t'.
service: Add IP configuration type to 'cancel_online_check'.
gweb: Add reference count debug statements.
gweb: Factor out GWeb destruction into 'g_web_free'.
wispr: Add '__connman_wispr_cancel' interface.
wispr: Add documentation to '__connman_wispr_cancel'.
wispr: Avoid double-free in 'free_wispr_routes'.
service: Leverage '__connman_wispr_cancel'.

Quoted 9 lines
gweb/gweb.c      |  88 ++++++++----
gweb/gweb.h      |   8 +-
src/6to4.c       |   2 +-
src/connman.h    |   5 +-
src/service.c    |  70 ++++++++--
src/wispr.c      | 341 ++++++++++++++++++++++++++++++++++++++++-------
tools/web-test.c |   3 +-
tools/wispr.c    |   8 +-
8 files changed, 433 insertions(+), 92 deletions(-)

I got this when trying to build the patch set.

CC gweb/gweb.o
gweb/gweb.c: In function ‘do_request’:
gweb/gweb.c:2357:57: error: comparison of unsigned expression in ‘< 0’ is always false [-Werror=type-limits]
2357 | status = session->resolv_action < 0 ?
| ^
gweb/gweb.c:2359:49: error: operand of ‘?:’ changes signedness from ‘int’ to ‘guint’ {aka ‘unsigned int’} due to unsignedness of other operand [-Werror=sign-compare]

 2359 |                                                 -ENOENT;
      |                                                 ^

cc1: all warnings being treated as errors

REgards

Marcel

#19 lore raw
Quoted 11 lines · Marcel Holtmann

[ ... ]

I got this when trying to build the patch set.

CC gweb/gweb.o
gweb/gweb.c: In function ‘do_request’:
gweb/gweb.c:2357:57: error: comparison of unsigned expression in ‘< 0’ is always false [-Werror=type-limits]
2357 | status = session->resolv_action < 0 ?
| ^
gweb/gweb.c:2359:49: error: operand of ‘?:’ changes signedness from ‘int’ to ‘guint’ {aka ‘unsigned int’} due to unsignedness of other operand [-Werror=sign-compare]

Quoted 3 lines
 2359 |                                                 -ENOENT;
      |                                                 ^

cc1: all warnings being treated as errors

Marcel,

Thank you; I've addressed this error and that in 'is_wispr_supported'. Submitted as a v2 on this thread.

Best,

Grant

#20 lore raw

v2 cover Address Redundant IPv4 Reachability Checks

In reply to Grant Erickson

This addresses an issue in which, when 'EnableOnlineCheck' is asserted, two (2) concurrent IPv4 and one (1) IPv6 reachability checks get queued.

The issue is addressed by introducing and leveraging '__connman_wispr_cancel' in 'cancel_online_check' to ensure that a pending or in-flight WISPr portal detection request or an "online" HTTP-based Internet reachability check is canceled not only in the service module but in the WISPr module as well.

This prevents two concurrent, outstanding, and redundant IPv4 WISPr requests from being in-flight when EnableOnlineCheck is asserted.

Prior to these changes, this redundancy was set in motion by:

1. The two back-to-back IPv4 probes get triggered by both of the following paths:

a. Triggered from 'default_changed' and
'start_wispr_if_connected'. This is the newer path, chronologically, in the code base.

b. Triggered from 'service_ip_bound', 'address_updated', and
'start_online_check'. This is the older path, chronologically, in the code base.

2. With the following commits addressed:

a. 812e171 ("Close three '__connman_wisp_start' failure closure
holes.")

* With this fix alone, at minimum, the first probe above (1) would have resulted, eventually in a failure closure with 'complete_online_check'.

b. 5f95851 ("wispr: Avoid 'connman_proxy_lookup' call for
'UNKNOWN' proxy method.") fixed, the first IPv4 probe from
(1) no longer "falls down a 'hole'" and gets lost (closure- and accounting-wise).

* With this fix, the first IPv4 probe is no longer a complete throwaway--it actually succeeds. However, since it does so, it becomes the first of the two redundant IPv4 checks.

By employing '__connman_wispr_cancel', 'cancel_online_check' quells the first IPv4 check triggered from 'default_changed' and 'start_wispr_if_connected' and replaces it, fully (in both the service and WISpr modules), with the second IPv4 check triggered from 'service_ip_bound', 'address_updated', and 'start_online_check'.

Grant Erickson (17):
wispr: Rename context proxy-related data members.
wispr: Add and leverage 'is_wispr_supported'.
wispr: Add documentation to 'is_wispr_supported'.
service: Document service unref calls in 'cancel_online_check'.
wispr: Add documentation to 'wispr_portal_detect'.
wispr: Add documentation to '__connman_wispr_stop'.
wispr: Add and leverage 'cancel_connman_wispr_portal_context'.
wispr: Add documentation to 'cancel_connman_wispr_portal_context'.
gweb: Add optional OS error status parameter to 'g_web_request_*'.
wispr: Add and leverage an OS error parameter to

    '__connman_wispr_cb_t'.

service: Add IP configuration type to 'cancel_online_check'.
gweb: Add reference count debug statements.
gweb: Factor out GWeb destruction into 'g_web_free'.
wispr: Add '__connman_wispr_cancel' interface.
wispr: Add documentation to '__connman_wispr_cancel'.
wispr: Avoid double-free in 'free_wispr_routes'.
service: Leverage '__connman_wispr_cancel'.

 gweb/gweb.c      |  94 +++++++++----
 gweb/gweb.h      |   8 +-
 src/6to4.c       |   2 +-
 src/connman.h    |   5 +-
 src/service.c    |  70 ++++++++--
 src/wispr.c      | 342 ++++++++++++++++++++++++++++++++++++++++-------
 tools/web-test.c |   3 +-
 tools/wispr.c    |   8 +-
 8 files changed, 440 insertions(+), 92 deletions(-)
Signature · 1 line
2.42.0
#21 lore raw

PATCH v2 1/17 wispr: Rename context proxy-related data members.

This renames the WISPr/portal context structure proxy-related data members 'token' and 'timeout' as 'proxy_token' and 'proxy_timeout', respectively, to make it clearer in what context they are used.

---
 src/wispr.c | 25 +++++++++++++------------
 1 file changed, 13 insertions(+), 12 deletions(-)
src/wispr.c +13 -12
index ab763d5bada0..79cb713449bc 100644
@@ -64,7 +64,7 @@ struct connman_wispr_portal_context {
 
 	/* Portal/WISPr common */
 	GWeb *web;
-	unsigned int token;
+	unsigned int proxy_token;
 	guint request_id;
 
 	const char *status_url;
@@ -83,7 +83,7 @@ struct connman_wispr_portal_context {
 
 	GSList *route_list;
 
-	guint timeout;
+	guint proxy_timeout;
 };
 
 struct connman_wispr_portal {
@@ -184,14 +184,14 @@ static void free_connman_wispr_portal_context(
 			wp_context->wispr_portal->ipv6_context = NULL;
 	}
 
-	if (wp_context->token > 0)
-		connman_proxy_lookup_cancel(wp_context->token);
+	if (wp_context->proxy_token > 0)
+		connman_proxy_lookup_cancel(wp_context->proxy_token);
 
 	if (wp_context->request_id > 0)
 		g_web_cancel_request(wp_context->web, wp_context->request_id);
 
-	if (wp_context->timeout > 0)
-		g_source_remove(wp_context->timeout);
+	if (wp_context->proxy_timeout > 0)
+		g_source_remove(wp_context->proxy_timeout);
 
 	if (wp_context->web)
 		g_web_unref(wp_context->web);
@@ -934,7 +934,7 @@ static void proxy_callback(const char *proxy, void *user_data)
 
 	DBG("proxy %s", proxy);
 
-	wp_context->token = 0;
+	wp_context->proxy_token = 0;
 
 	proxy_server = parse_proxy(proxy);
 	if (proxy_server) {
@@ -961,7 +961,7 @@ static gboolean no_proxy_callback(gpointer user_data)
 {
 	struct connman_wispr_portal_context *wp_context = user_data;
 
-	wp_context->timeout = 0;
+	wp_context->proxy_timeout = 0;
 
 	proxy_callback("DIRECT", wp_context);
 
@@ -1049,19 +1049,20 @@ static int wispr_portal_detect(struct connman_wispr_portal_context *wp_context,
 			proxy_method != CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN) {
 		wispr_portal_context_ref(wp_context);
 
-		wp_context->token = connman_proxy_lookup(interface,
+		wp_context->proxy_token = connman_proxy_lookup(interface,
 						wp_context->status_url,
 						wp_context->service,
 						proxy_callback, wp_context);
 
-		if (wp_context->token == 0) {
+		if (wp_context->proxy_token == 0) {
 			err = -EINVAL;
 			wispr_portal_context_unref(wp_context);
 		}
-	} else if (wp_context->timeout == 0) {
+	} else if (wp_context->proxy_timeout == 0) {
 		wispr_portal_context_ref(wp_context);
 
-		wp_context->timeout = g_idle_add(no_proxy_callback, wp_context);
+		wp_context->proxy_timeout = g_idle_add(no_proxy_callback,
+						wp_context);
 	}
 
 done:
Signature · 1 line
2.42.0
#22 lore raw

PATCH v2 2/17 wispr: Add and leverage 'is_wispr_supported'.

In reply to Grant Erickson

This factors out from '__connman_wispr_start', adds, and leverages as an independent, file-scoped function 'is_wispr_supported'. It determines and returns Boolean status whether WISPr requests / HTTP-based Internet reachability check are supported for the specified network service based on its associated technology type.

---
 src/wispr.c | 36 +++++++++++++++++++++++-------------
 1 file changed, 23 insertions(+), 13 deletions(-)
src/wispr.c +23 -13
index 79cb713449bc..ae33a68ebbce 100644
@@ -1072,6 +1072,28 @@ done:
 	return err;
 }
 
+static bool is_wispr_supported(const struct connman_service *service)
+{
+	if (!service)
+		return false;
+
+	switch (connman_service_get_type(service)) {
+	case CONNMAN_SERVICE_TYPE_ETHERNET:
+	case CONNMAN_SERVICE_TYPE_WIFI:
+	case CONNMAN_SERVICE_TYPE_BLUETOOTH:
+	case CONNMAN_SERVICE_TYPE_CELLULAR:
+	case CONNMAN_SERVICE_TYPE_GADGET:
+		return true;
+	case CONNMAN_SERVICE_TYPE_UNKNOWN:
+	case CONNMAN_SERVICE_TYPE_SYSTEM:
+	case CONNMAN_SERVICE_TYPE_GPS:
+	case CONNMAN_SERVICE_TYPE_VPN:
+	case CONNMAN_SERVICE_TYPE_P2P:
+	default:
+		return false;
+	}
+}
+
 /**
  *  @brief
  *    Start a HTTP-based Internet reachability check for the specified
@@ -1132,20 +1154,8 @@ int __connman_wispr_start(struct connman_service *service,
 	if (!wispr_portal_hash || !callback)
 		return -EINVAL;
 
-	switch (connman_service_get_type(service)) {
-	case CONNMAN_SERVICE_TYPE_ETHERNET:
-	case CONNMAN_SERVICE_TYPE_WIFI:
-	case CONNMAN_SERVICE_TYPE_BLUETOOTH:
-	case CONNMAN_SERVICE_TYPE_CELLULAR:
-	case CONNMAN_SERVICE_TYPE_GADGET:
-		break;
-	case CONNMAN_SERVICE_TYPE_UNKNOWN:
-	case CONNMAN_SERVICE_TYPE_SYSTEM:
-	case CONNMAN_SERVICE_TYPE_GPS:
-	case CONNMAN_SERVICE_TYPE_VPN:
-	case CONNMAN_SERVICE_TYPE_P2P:
+	if (!is_wispr_supported(service))
 		return -EOPNOTSUPP;
-	}
 
 	index = __connman_service_get_index(service);
 	if (index < 0)
Signature · 1 line
2.42.0
#23 lore raw

PATCH v2 3/17 wispr: Add documentation to 'is_wispr_supported'.

In reply to Grant Erickson

This adds documentation to the 'is_wispr_supported' function.

---
 src/wispr.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
src/wispr.c +19 -0
index ae33a68ebbce..1370c93a0e9f 100644
@@ -1072,6 +1072,25 @@ done:
 	return err;
 }
 
+/**
+ *  @brief
+ *    Return whether WISPr requests / HTTP-based Internet reachability
+ *    checks are supported.
+ *
+ *  This determines whether WISPr requests / HTTP-based Internet
+ *  reachability check are supported for the specified network service
+ *  based on its associated technology type.
+ *
+ *  @param[in]  service  A pointer to the immutable network service
+ *                       for which to check WISPr requests / HTTP-based
+ *                       Internet reachability check support.
+ *
+ *  @returns
+ *    True if the network service technology type supports WISPr
+ *    requests / HTTP-based Internet reachability checks; otherwise,
+ *    false.
+ *
+ */
 static bool is_wispr_supported(const struct connman_service *service)
 {
 	if (!service)
Signature · 1 line
2.42.0
#24 lore raw

PATCH v2 4/17 service: Document service unref calls in 'cancel_online_check'.

In reply to Grant Erickson

This adds a comment to the two calls to 'connman_service_unref' in 'cancel_online_check' to help aid present and future readers in identifying where the balacing reference retain occurs.

---
 src/service.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
src/service.c +12 -0
index 075f3fba5abe..5fb53c2084f9 100644
@@ -1590,11 +1590,23 @@ static void cancel_online_check(struct connman_service *service)
 	if (service->online_timeout_ipv4) {
 		g_source_remove(service->online_timeout_ipv4);
 		service->online_timeout_ipv4 = 0;
+
+		/*
+		 * This balances the retained referece made when
+		 * g_timeout_add_seconds was called to schedule this
+		 * now-cancelled scheduled online check.
+		 */
 		connman_service_unref(service);
 	}
 	if (service->online_timeout_ipv6) {
 		g_source_remove(service->online_timeout_ipv6);
 		service->online_timeout_ipv6 = 0;
+
+		/*
+		 * This balances the retained referece made when
+		 * g_timeout_add_seconds was called to schedule this
+		 * now-cancelled scheduled online check.
+		 */
 		connman_service_unref(service);
 	}
 }
Signature · 1 line
2.42.0
#25 lore raw

PATCH v2 5/17 wispr: Add documentation to 'wispr_portal_detect'.

In reply to Grant Erickson

This adds documentation to the 'wispr_portal_detect' function.

---
 src/wispr.c | 40 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 40 insertions(+)
src/wispr.c +40 -0
index 1370c93a0e9f..84ad21c2d6fb 100644
@@ -968,6 +968,46 @@ static gboolean no_proxy_callback(gpointer user_data)
 	return FALSE;
 }
 
+/**
+ *  @brief
+ *    Start a WISPr / portal detection request / HTTP-based Internet
+ *    reachability check for the specified WISPr / portal context.
+ *
+ *  This attempts to start a WISPr / portal detection request /
+ *  HTTP-based Internet reachability check for the network service IP
+ *  configuration type associated with the provided WISPr / portal
+ *  context with the provided connection timeout.
+ *
+ *  @param[in,out]  wp_context          A pointer to the mutable WISPr
+ *                                      / portal context to supporting
+ *                                      running the WISPr request /
+ *                                      HTTP-based Internet
+ *                                      reachability check.
+ *  param[in]       connect_timeout_ms  The time, in milliseconds, for
+ *                                      the TCP connection timeout.
+ *                                      Connections that take longer
+ *                                      than this will be aborted. A
+ *                                      value of zero ('0') indicates
+ *                                      that no explicit connection
+ *                                      timeout will be used, leaving
+ *                                      the timeout to the underlying
+ *                                      operating system and its
+ *                                      network stack.
+ *
+ *  @retval  0        If the WISPr request / HTTP-based Internet
+ *                    reachability check was successfully queued.
+ *  @retval  -EINVAL  If the network interface or network interface
+ *                    index associated with @a wp_context->service is
+ *                    invalid, if @a wp_context->service has no name
+ *                    servers, or if a proxy could not be successfully
+ *                    associated with @a wp_context->service.
+ *  @retval  -ENOMEM  If a GWeb instance could not be allocated for
+ *                    the WISPr request / HTTP-based Internet
+ *                    reachability check.
+ *
+ *  @sa __connman_wispr_start
+ *
+ */
 static int wispr_portal_detect(struct connman_wispr_portal_context *wp_context,
 						guint connect_timeout_ms)
 {
Signature · 1 line
2.42.0
#26 lore raw

PATCH v2 6/17 wispr: Add documentation to '__connman_wispr_stop'.

In reply to Grant Erickson

This adds documentation to the '__connman_wispr_stop' function.

---
 src/wispr.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
src/wispr.c +16 -0
index 84ad21c2d6fb..41f5d462da41 100644
@@ -1268,6 +1268,22 @@ free_wp:
 	return err;
 }
 
+/**
+ *  @brief
+ *    Stop all HTTP-based Internet reachability checks for the specified
+ *    network service.
+ *
+ *  This attempts to stop all HTTP-based Internet reachability checks
+ *  for the specified network service.
+ *
+ *  @param[in,out]  service  A pointer to the mutable network service
+ *                           for which to stop all reachability
+ *                           checks.
+ *
+ *  @sa __connman_wispr_start
+ *  @sa __connman_wispr_cancel
+ *
+ */
 void __connman_wispr_stop(struct connman_service *service)
 {
 	struct connman_wispr_portal *wispr_portal;
Signature · 1 line
2.42.0
#27 lore raw

PATCH v2 7/17 wispr: Add and leverage 'cancel_connman_wispr_portal_context'.

In reply to Grant Erickson

This factors out from 'free_connman_wispr_portal_context', adds, and leverages as an independent, file-scoped function 'cancel_connman_wispr_portal_context'. It attempts to cancel any outstanding WISPr request associated with the specified WISPr/portal context, deallocating any resources associated with the context, except for the context itself which still requires invoking 'free_connman_wispr_portal_context'.

---
 src/wispr.c | 60 ++++++++++++++++++++++++++++++++++++++++-------------
 1 file changed, 46 insertions(+), 14 deletions(-)
src/wispr.c +46 -14
index 41f5d462da41..8ec2b78e8e5f 100644
@@ -166,9 +166,12 @@ static void free_wispr_routes(struct connman_wispr_portal_context *wp_context)
 	}
 }
 
-static void free_connman_wispr_portal_context(
+static void cancel_connman_wispr_portal_context(
 		struct connman_wispr_portal_context *wp_context)
 {
+	if (!wp_context)
+		return;
+
 	DBG("wispr/portal context %p service %p (%s) type %d (%s)",
 		wp_context,
 		wp_context->service,
@@ -176,38 +179,67 @@ static void free_connman_wispr_portal_context(
 		wp_context->type,
 		__connman_ipconfig_type2string(wp_context->type));
 
-	if (wp_context->wispr_portal) {
-		if (wp_context->wispr_portal->ipv4_context == wp_context)
-			wp_context->wispr_portal->ipv4_context = NULL;
-
-		if (wp_context->wispr_portal->ipv6_context == wp_context)
-			wp_context->wispr_portal->ipv6_context = NULL;
-	}
-
-	if (wp_context->proxy_token > 0)
+	if (wp_context->proxy_token > 0) {
 		connman_proxy_lookup_cancel(wp_context->proxy_token);
+		wp_context->proxy_token = 0;
+	}
 
-	if (wp_context->request_id > 0)
+	if (wp_context->request_id > 0) {
 		g_web_cancel_request(wp_context->web, wp_context->request_id);
+		wp_context->request_id = 0;
+	}
 
-	if (wp_context->proxy_timeout > 0)
+	if (wp_context->proxy_timeout > 0) {
 		g_source_remove(wp_context->proxy_timeout);
+		wp_context->proxy_timeout = 0;
+	}
 
-	if (wp_context->web)
+	if (wp_context->web) {
 		g_web_unref(wp_context->web);
+		wp_context->web = NULL;
+	}
 
 	g_free(wp_context->redirect_url);
+	wp_context->redirect_url = NULL;
 
-	if (wp_context->wispr_parser)
+	if (wp_context->wispr_parser) {
 		g_web_parser_unref(wp_context->wispr_parser);
+		wp_context->wispr_parser = NULL;
+	}
 
 	connman_wispr_message_init(&wp_context->wispr_msg);
 
 	g_free(wp_context->wispr_username);
+	wp_context->wispr_username = NULL;
+
 	g_free(wp_context->wispr_password);
+	wp_context->wispr_password = NULL;
+
 	g_free(wp_context->wispr_formdata);
+	wp_context->wispr_formdata = NULL;
 
 	free_wispr_routes(wp_context);
+}
+
+static void free_connman_wispr_portal_context(
+		struct connman_wispr_portal_context *wp_context)
+{
+	DBG("wispr/portal context %p service %p (%s) type %d (%s)",
+		wp_context,
+		wp_context->service,
+		connman_service_get_identifier(wp_context->service),
+		wp_context->type,
+		__connman_ipconfig_type2string(wp_context->type));
+
+	if (wp_context->wispr_portal) {
+		if (wp_context->wispr_portal->ipv4_context == wp_context)
+			wp_context->wispr_portal->ipv4_context = NULL;
+
+		if (wp_context->wispr_portal->ipv6_context == wp_context)
+			wp_context->wispr_portal->ipv6_context = NULL;
+	}
+
+	cancel_connman_wispr_portal_context(wp_context);
 
 	g_free(wp_context);
 }
Signature · 1 line
2.42.0
#28 lore raw

PATCH v2 8/17 wispr: Add documentation to 'cancel_connman_wispr_portal_context'.

In reply to Grant Erickson

This adds documentation to the 'cancel_connman_wispr_portal_context' function.

---
 src/wispr.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
src/wispr.c +18 -0
index 8ec2b78e8e5f..c15880e9c8a2 100644
@@ -166,6 +166,24 @@ static void free_wispr_routes(struct connman_wispr_portal_context *wp_context)
 	}
 }
 
+/**
+ *  @brief
+ *    Cancel a WISPr/portal request.
+ *
+ *  This attempts to cancel any outstanding request associated with
+ *  the specified WISPr/portal context. This deallocates any resources
+ *  associated with the context, except for the context itself which
+ *  requires invoking #free_connman_wispr_portal_context.
+ *
+ *  @param[in,out]  wp_context  A pointer to the mutable WISPr/portal
+ *                              context for which to cancel an outstanding
+ *                              request, whether a reachability check
+ *                              or otherwise.
+ *
+ *  @sa create_connman_wispr_portal_context
+ *  @sa free_connman_wispr_portal_context
+ *
+ */
 static void cancel_connman_wispr_portal_context(
 		struct connman_wispr_portal_context *wp_context)
 {
Signature · 1 line
2.42.0
#29 lore raw

PATCH v2 9/17 gweb: Add optional OS error status parameter to 'g_web_request_*'.

In reply to Grant Erickson

This adds an optional operating system error status parameter to 'g_web_request_{get,post,post_file}' allowing callers, so interested, to obtain the underlying failure status for a failed GWeb request.

---
 gweb/gweb.c      | 65 ++++++++++++++++++++++++++++++++++--------------
 gweb/gweb.h      |  8 +++---
 src/6to4.c       |  2 +-
 src/wispr.c      |  6 ++---
 tools/web-test.c |  3 ++-
 tools/wispr.c    |  8 +++---
 6 files changed, 62 insertions(+), 30 deletions(-)
gweb/gweb.c +47 -18
index 1463b588d411..0270531a982f 100644
@@ -2255,23 +2255,31 @@ static bool is_ip_address(const char *host)
 static guint do_request(GWeb *web, const char *url,
 				const char *type, GWebInputFunc input,
 				int fd, gsize length, GWebResultFunc func,
-				GWebRouteFunc route, gpointer user_data)
+				GWebRouteFunc route, gpointer user_data,
+				int *err)
 {
 	struct web_session *session;
 	const gchar *host;
+	int request_id = 0;
+	int status = 0;
 
-	if (!web || !url)
-		return 0;
+	if (!web || !url) {
+		status = -EINVAL;
+		goto done;
+	}
 
 	debug(web, "request %s", url);
 
 	session = g_try_new0(struct web_session, 1);
-	if (!session)
-		return 0;
+	if (!session) {
+		status = -ENOMEM;
+		goto done;
+	}
 
-	if (parse_request_and_proxy_urls(session, url, web->proxy) < 0) {
+	status = parse_request_and_proxy_urls(session, url, web->proxy);
+	if (status < 0) {
 		free_session(session);
-		return 0;
+		goto done;
 	}
 
 	debug(web, "proxy host %s", session->address);
@@ -2299,14 +2307,16 @@ static guint do_request(GWeb *web, const char *url,
 	session->receive_buffer = g_try_malloc(DEFAULT_BUFFER_SIZE);
 	if (!session->receive_buffer) {
 		free_session(session);
-		return 0;
+		status = -ENOMEM;
+		goto done;
 	}
 
 	session->result.headers = g_hash_table_new_full(g_str_hash, g_str_equal,
 							g_free, g_free);
 	if (!session->result.headers) {
 		free_session(session);
-		return 0;
+		status = -ENOMEM;
+		goto done;
 	}
 
 	session->receive_space = DEFAULT_BUFFER_SIZE;
@@ -2325,33 +2335,52 @@ static guint do_request(GWeb *web, const char *url,
 	} else {
 		session->resolv_action = g_resolv_lookup_hostname(web->resolv,
 					host, resolv_result, session);
-		if (session->resolv_action == 0) {
+		if (session->resolv_action <= 0) {
 			free_session(session);
-			return 0;
+			/*
+			 * While the return signature of #g_resolv_lookup_hostname
+			 * is 'guint', it overloads this, treating it as 'int' and
+			 * does potentially return -EIO. Consequently, apply the
+			 * 'int' casts to handle these cases.
+			 */
+			status = (int)session->resolv_action < 0 ?
+						(int)session->resolv_action :
+						-ENOENT;
+			goto done;
 		}
 	}
 
 	web->session_list = g_list_append(web->session_list, session);
 
-	return web->next_query_id++;
+	request_id = web->next_query_id++;
+
+done:
+	if (err)
+		*err = status;
+
+	return request_id;
 }
 
 guint g_web_request_get(GWeb *web, const char *url, GWebResultFunc func,
-		GWebRouteFunc route, gpointer user_data)
+		GWebRouteFunc route, gpointer user_data, int *err)
 {
-	return do_request(web, url, NULL, NULL, -1, 0, func, route, user_data);
+	return do_request(web, url, NULL, NULL, -1, 0,
+		func, route, user_data, err);
 }
 
 guint g_web_request_post(GWeb *web, const char *url,
 				const char *type, GWebInputFunc input,
-				GWebResultFunc func, gpointer user_data)
+				GWebResultFunc func, gpointer user_data,
+				int *err)
 {
-	return do_request(web, url, type, input, -1, 0, func, NULL, user_data);
+	return do_request(web, url, type, input, -1, 0,
+		func, NULL, user_data, err);
 }
 
 guint g_web_request_post_file(GWeb *web, const char *url,
 				const char *type, const char *file,
-				GWebResultFunc func, gpointer user_data)
+				GWebResultFunc func, gpointer user_data,
+				int *err)
 {
 	struct stat st;
 	int fd;
@@ -2365,7 +2394,7 @@ guint g_web_request_post_file(GWeb *web, const char *url,
 		return 0;
 
 	ret = do_request(web, url, type, NULL, fd, st.st_size, func, NULL,
-			user_data);
+			user_data, err);
 	if (ret == 0)
 		close(fd);
 
gweb/gweb.h +5 -3
index 3c50979cfd0a..7c65aebf4698 100644
@@ -150,13 +150,15 @@ bool g_web_get_close_connection(GWeb *web);
 
 guint g_web_request_get(GWeb *web, const char *url,
 				GWebResultFunc func, GWebRouteFunc route,
-				gpointer user_data);
+				gpointer user_data, int *err);
 guint g_web_request_post(GWeb *web, const char *url,
 				const char *type, GWebInputFunc input,
-				GWebResultFunc func, gpointer user_data);
+				GWebResultFunc func, gpointer user_data,
+				int *err);
 guint g_web_request_post_file(GWeb *web, const char *url,
 				const char *type, const char *file,
-				GWebResultFunc func, gpointer user_data);
+				GWebResultFunc func, gpointer user_data,
+				int *err);
 
 bool g_web_cancel_request(GWeb *web, guint id);
 
src/6to4.c +1 -1
index 71a288277104..5542b339691a 100644
@@ -318,7 +318,7 @@ static void tun_newlink(unsigned flags, unsigned change, void *user_data)
 			g_web_set_debug(web, web_debug, "6to4");
 
 		web_request_id = g_web_request_get(web, STATUS_URL,
-				web_result, NULL,  NULL);
+				web_result, NULL,  NULL, NULL);
 
 		newlink_timeout(NULL);
 	}
src/wispr.c +3 -3
index c15880e9c8a2..1bf63866009a 100644
@@ -634,7 +634,7 @@ static void wispr_portal_request_portal(
 					wp_context->status_url,
 					wispr_portal_web_result,
 					wispr_route_request,
-					wp_context);
+					wp_context, NULL);
 
 	if (wp_context->request_id == 0) {
 		wp_context->cb(wp_context->service, wp_context->type, false);
@@ -751,7 +751,7 @@ static void wispr_portal_request_wispr_login(struct connman_service *service,
 					wp_context->wispr_msg.login_url,
 					"application/x-www-form-urlencoded",
 					wispr_input, wispr_portal_web_result,
-					wp_context);
+					wp_context, NULL);
 
 	connman_wispr_message_init(&wp_context->wispr_msg);
 }
@@ -906,7 +906,7 @@ static bool wispr_portal_web_result(GWebResult *result, gpointer user_data)
 		wispr_portal_context_ref(wp_context);
 		wp_context->request_id = g_web_request_get(wp_context->web,
 				redirect, wispr_portal_web_result,
-				wispr_route_request, wp_context);
+				wispr_route_request, wp_context, NULL);
 
 		goto done;
 	case GWEB_HTTP_STATUS_CODE_BAD_REQUEST:
tools/web-test.c +2 -1
index 55c58af5a7dc..a65e6c115c41 100644
@@ -150,7 +150,8 @@ int main(int argc, char *argv[])
 
 	timer = g_timer_new();
 
-	if (g_web_request_get(web, argv[1], web_result, NULL,  NULL) == 0) {
+	if (g_web_request_get(web, argv[1], web_result,
+			NULL, NULL, NULL) == 0) {
 		fprintf(stderr, "Failed to start request\n");
 		return 1;
 	}
tools/wispr.c +4 -4
index e56dfc169411..ef7b60d3f5ca 100644
@@ -531,7 +531,7 @@ static bool wispr_result(GWebResult *result, gpointer user_data)
 		printf("\n");
 
 		wispr->request = g_web_request_get(wispr->web, redirect,
-				wispr_result, wispr_route, wispr);
+				wispr_result, wispr_route, wispr, NULL);
 
 		return false;
 	}
@@ -591,7 +591,7 @@ static bool wispr_result(GWebResult *result, gpointer user_data)
 		printf("\n");
 
 		wispr->request = g_web_request_get(wispr->web, redirect,
-				wispr_result, NULL, wispr);
+				wispr_result, NULL, wispr, NULL);
 
 		return false;
 	}
@@ -608,7 +608,7 @@ static gboolean execute_login(gpointer user_data)
 
 	wispr->request = g_web_request_post(wispr->web, wispr->msg.login_url,
 					"application/x-www-form-urlencoded",
-					wispr_input, wispr_result, wispr);
+					wispr_input, wispr_result, wispr, NULL);
 
 	wispr_msg_init(&wispr->msg);
 
@@ -694,7 +694,7 @@ int main(int argc, char *argv[])
 						parser_callback, &wispr);
 
 	wispr.request = g_web_request_get(wispr.web, option_url,
-			wispr_result, wispr_route, &wispr);
+			wispr_result, wispr_route, &wispr, NULL);
 
 	if (wispr.request == 0) {
 		fprintf(stderr, "Failed to start request\n");
Signature · 1 line
2.42.0
#30 lore raw

PATCH v2 10/17 wispr: Add and leverage an OS error parameter to '__connman_wispr_cb_t'.

In reply to Grant Erickson

This adds and leverages an operating system error parameter to '__connman_wispr_cb_t' such that such callbacks can leverage the error status when 'success' is false to either log the status or take conditional action.

---
 src/connman.h |  3 ++-
 src/service.c | 15 +++++++++++----
 src/wispr.c   | 37 ++++++++++++++++++++++++++++++-------
 3 files changed, 43 insertions(+), 12 deletions(-)
src/connman.h +2 -1
index 143a087701d8..d5aa6f5599e7 100644
@@ -525,7 +525,8 @@ void __connman_wpad_stop(struct connman_service *service);
 
 typedef void (*__connman_wispr_cb_t) (struct connman_service *service,
 				enum connman_ipconfig_type type,
-				bool success);
+				bool success,
+				int err);
 
 int __connman_wispr_init(void);
 void __connman_wispr_cleanup(void);
src/service.c +11 -4
index 5fb53c2084f9..0882cd167699 100644
@@ -163,7 +163,8 @@ static void vpn_auto_connect(void);
 static void trigger_autoconnect(struct connman_service *service);
 static void complete_online_check(struct connman_service *service,
 					enum connman_ipconfig_type type,
-					bool success);
+					bool success,
+					int err);
 static bool service_downgrade_online_state(struct connman_service *service);
 
 struct find_data {
@@ -1902,6 +1903,11 @@ static void reschedule_online_check(struct connman_service *service,
  *                           check.
  *  @param[in]      success  A Boolean indicating whether the previously-
  *                           requested online check was successful.
+ *  @param[in]      err      The error status associated with previously-
+ *                           requested online check. This is expected
+ *                           to be zero ('0') if @a success is @a true
+ *                           and less than zero ('< 0') if @a success
+ *                           is @a false.
  *
  *  @sa cancel_online_check
  *  @sa start_online_check
@@ -1911,16 +1917,17 @@ static void reschedule_online_check(struct connman_service *service,
  */
 static void complete_online_check(struct connman_service *service,
 					enum connman_ipconfig_type type,
-					bool success)
+					bool success,
+					int err)
 {
 	unsigned int *interval;
 	guint *timeout;
 
-	DBG("service %p (%s) type %d (%s) success %d\n",
+	DBG("service %p (%s) type %d (%s) success %d err %d (%s)\n",
 		service,
 		connman_service_get_identifier(service),
 		type, __connman_ipconfig_type2string(type),
-		success);
+		success, err, strerror(-err));
 
 	if (type == CONNMAN_IPCONFIG_TYPE_IPV4) {
 		interval = &service->online_check_interval_ipv4;
src/wispr.c +30 -7
index 1bf63866009a..396891c98153 100644
@@ -564,7 +564,7 @@ static void portal_manage_success_status(GWebResult *result,
 				&str))
 		connman_info("Client-Timezone: %s", str);
 
-	wp_context->cb(service, type, true);
+	wp_context->cb(service, type, true, 0);
 }
 
 static bool wispr_route_request(const char *address, int ai_family,
@@ -618,6 +618,8 @@ static bool wispr_route_request(const char *address, int ai_family,
 static void wispr_portal_request_portal(
 		struct connman_wispr_portal_context *wp_context)
 {
+	int err = 0;
+
 	DBG("wispr/portal context %p service %p (%s) type %d (%s)",
 		wp_context,
 		wp_context->service,
@@ -634,10 +636,13 @@ static void wispr_portal_request_portal(
 					wp_context->status_url,
 					wispr_portal_web_result,
 					wispr_route_request,
-					wp_context, NULL);
+					wp_context, &err);
 
 	if (wp_context->request_id == 0) {
-		wp_context->cb(wp_context->service, wp_context->type, false);
+		wp_context->cb(wp_context->service,
+						wp_context->type,
+						false,
+						err);
 		wispr_portal_error(wp_context);
 		wispr_portal_context_unref(wp_context);
 	}
@@ -910,11 +915,26 @@ static bool wispr_portal_web_result(GWebResult *result, gpointer user_data)
 
 		goto done;
 	case GWEB_HTTP_STATUS_CODE_BAD_REQUEST:
+		wp_context->cb(wp_context->service,
+				wp_context->type,
+				false,
+				-EINVAL);
+		break;
+
 	case GWEB_HTTP_STATUS_CODE_NOT_FOUND:
-	case GWEB_HTTP_STATUS_CODE_REQUEST_TIMEOUT:
-		wp_context->cb(wp_context->service, wp_context->type, false);
+		wp_context->cb(wp_context->service,
+				wp_context->type,
+				false,
+				-ENOENT);
+		break;
 
+	case GWEB_HTTP_STATUS_CODE_REQUEST_TIMEOUT:
+		wp_context->cb(wp_context->service,
+				wp_context->type,
+				false,
+				-ETIMEDOUT);
 		break;
+
 	case GWEB_HTTP_STATUS_CODE_HTTP_VERSION_NOT_SUPPORTED:
 		wispr_portal_context_ref(wp_context);
 		__connman_agent_request_browser(wp_context->service,
@@ -977,7 +997,10 @@ static void proxy_callback(const char *proxy, void *user_data)
 	if (!proxy) {
 		DBG("no valid proxy");
 
-		wp_context->cb(wp_context->service, wp_context->type, false);
+		wp_context->cb(wp_context->service,
+				wp_context->type,
+				false,
+				-EINVAL);
 
 		return;
 	}
@@ -1312,7 +1335,7 @@ int __connman_wispr_start(struct connman_service *service,
 	return 0;
 
 free_wp:
-	wp_context->cb(wp_context->service, wp_context->type, false);
+	wp_context->cb(wp_context->service, wp_context->type, false, err);
 
 	g_hash_table_remove(wispr_portal_hash, GINT_TO_POINTER(index));
 	return err;
Signature · 1 line
2.42.0
#31 lore raw

PATCH v2 11/17 service: Add IP configuration type to 'cancel_online_check'.

In reply to Grant Erickson

WISPr / portal detection and HTTP-based "online" Internet reachability checks are, by design, IP configuration-specific. There may be parallel, independent requests or checks in flight: one for IPv4 and one for IPv6. Consequently, when attempting to cancel such requests or checks, require the IP configuration type to indicate which specific request or check is to be canceled.

---
 src/service.c | 25 ++++++++++++++++---------
 1 file changed, 16 insertions(+), 9 deletions(-)
src/service.c +16 -9
index 0882cd167699..d78ed0123160 100644
@@ -1559,11 +1559,11 @@ static guint online_check_timeout_compute_geometric(unsigned int interval)
 /**
  *  @brief
  *    Cancel any "online" HTTP-based Internet reachability checks for
- *    the specified network service.
+ *    the specified network service IP configuration type.
  *
  *  This cancels any current or pending IPv4 and/or IPv6 "online"
  *  HTTP-based Internet reachability checks for the specified network
- *  service.
+ *  service IP configuration type.
  *
  *  @note
  *    Any lingering WISPr portal reachability context will be lazily
@@ -1574,6 +1574,9 @@ static guint online_check_timeout_compute_geometric(unsigned int interval)
  *                           for which any current or pending IPv4 or
  *                           IPv6 "online" reachability checks should
  *                           be canceled.
+ *  @param[in]      type     The IP configuration type for which the
+ *                           "online" reachability check is to be
+ *                           canceled.
  *
  *  @sa start_online_check
  *  @sa complete_online_check
@@ -1581,14 +1584,18 @@ static guint online_check_timeout_compute_geometric(unsigned int interval)
  *  @sa __connman_wispr_stop
  *
  */
-static void cancel_online_check(struct connman_service *service)
+static void cancel_online_check(struct connman_service *service,
+				enum connman_ipconfig_type type)
 {
-	DBG("service %p (%s) online_timeout_ipv4 %d online_timeout_ipv6 %d",
+	DBG("service %p (%s) type %d (%s) "
+		"online_timeout_ipv4 %d online_timeout_ipv6 %d",
 		service, connman_service_get_identifier(service),
+		type, __connman_ipconfig_type2string(type),
 		service->online_timeout_ipv4,
 		service->online_timeout_ipv6);
 
-	if (service->online_timeout_ipv4) {
+	if (type == CONNMAN_IPCONFIG_TYPE_IPV4 &&
+		service->online_timeout_ipv4) {
 		g_source_remove(service->online_timeout_ipv4);
 		service->online_timeout_ipv4 = 0;
 
@@ -1598,8 +1605,8 @@ static void cancel_online_check(struct connman_service *service)
 		 * now-cancelled scheduled online check.
 		 */
 		connman_service_unref(service);
-	}
-	if (service->online_timeout_ipv6) {
+	} else if (type == CONNMAN_IPCONFIG_TYPE_IPV6 &&
+		service->online_timeout_ipv6) {
 		g_source_remove(service->online_timeout_ipv6);
 		service->online_timeout_ipv6 = 0;
 
@@ -1683,7 +1690,7 @@ static void start_online_check(struct connman_service *service,
 		return;
 
 	if (type == CONNMAN_IPCONFIG_TYPE_IPV6 || check_proxy_setup(service)) {
-		cancel_online_check(service);
+		cancel_online_check(service, type);
 		__connman_service_wispr_start(service, type);
 	}
 }
@@ -7185,7 +7192,7 @@ int __connman_service_ipconfig_indicate_state(struct connman_service *service,
 
 	if (is_connected(old_state) && !is_connected(new_state)) {
 		nameserver_remove_all(service, type);
-		cancel_online_check(service);
+		cancel_online_check(service, type);
 	}
 
 	if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
Signature · 1 line
2.42.0
#32 lore raw

PATCH v2 12/17 gweb: Add reference count debug statements.

In reply to Grant Erickson

This adds reference count debugging statements in 'g_web_ref' and 'g_web_unref', similar but not identical to other modules in the project.

---
 gweb/gweb.c | 6 ++++++
 1 file changed, 6 insertions(+)
gweb/gweb.c +6 -0
index 0270531a982f..7a25fe4c8cc3 100644
@@ -414,6 +414,9 @@ GWeb *g_web_ref(GWeb *web)
 	if (!web)
 		return NULL;
 
+	debug(web, "ref %d",
+		web->ref_count + 1);
+
 	__sync_fetch_and_add(&web->ref_count, 1);
 
 	return web;
@@ -424,6 +427,9 @@ void g_web_unref(GWeb *web)
 	if (!web)
 		return;
 
+	debug(web, "ref %d",
+		web->ref_count - 1);
+
 	if (__sync_fetch_and_sub(&web->ref_count, 1) != 1)
 		return;
 
Signature · 1 line
2.42.0
#33 lore raw

PATCH v2 13/17 gweb: Factor out GWeb destruction into 'g_web_free'.

In reply to Grant Erickson

This factors out the destruction of a GWeb object into 'g_web_free' to make it clearer, during debugging and development, when destruction of the reference-counted object actually occurs and which aspects of the object are being destroyed.

---
 gweb/gweb.c | 29 ++++++++++++++++++++---------
 1 file changed, 20 insertions(+), 9 deletions(-)
gweb/gweb.c +20 -9
index 7a25fe4c8cc3..ce49e8d3dfc1 100644
@@ -327,6 +327,8 @@ static void free_session(struct web_session *session)
 	if (!session)
 		return;
 
+	debug(session->web, "session %p", session);
+
 	g_free(session->request);
 
 	web = session->web;
@@ -368,6 +370,8 @@ static void flush_sessions(GWeb *web)
 {
 	GList *list;
 
+	debug(web, "flushing sessions...");
+
 	for (list = g_list_first(web->session_list);
 					list; list = g_list_next(list))
 		free_session(list->data);
@@ -422,16 +426,9 @@ GWeb *g_web_ref(GWeb *web)
 	return web;
 }
 
-void g_web_unref(GWeb *web)
+static void g_web_free(GWeb *web)
 {
-	if (!web)
-		return;
-
-	debug(web, "ref %d",
-		web->ref_count - 1);
-
-	if (__sync_fetch_and_sub(&web->ref_count, 1) != 1)
-		return;
+	debug(web, "freeing...");
 
 	flush_sessions(web);
 
@@ -447,6 +444,20 @@ void g_web_unref(GWeb *web)
 	g_free(web);
 }
 
+void g_web_unref(GWeb *web)
+{
+	if (!web)
+		return;
+
+	debug(web, "ref %d",
+		web->ref_count - 1);
+
+	if (__sync_fetch_and_sub(&web->ref_count, 1) != 1)
+		return;
+
+	g_web_free(web);
+}
+
 bool g_web_supports_tls(void)
 {
 	return g_io_channel_supports_tls();
Signature · 1 line
2.42.0
#34 lore raw

PATCH v2 14/17 wispr: Add '__connman_wispr_cancel' interface.

In reply to Grant Erickson

This adds a heretofore-missing '__connman_wispr_cancel' interface. It attempts to cancel a HTTP-based Internet reachability check for the specified network service IP configuration type.

If a matching WISPr portal detect request or HTTP-based Internet reachability check is found, the original callback specified with '__connman_wispr_start' will be invoked with a success value of zero ('0') or false and an error value of -ECANCELED.

---
 src/connman.h |  2 ++
 src/wispr.c   | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 57 insertions(+)
src/connman.h +2 -0
index d5aa6f5599e7..ae04cd9a26c6 100644
@@ -534,6 +534,8 @@ int __connman_wispr_start(struct connman_service *service,
 					enum connman_ipconfig_type type,
 					guint connect_timeout_ms,
 					__connman_wispr_cb_t callback);
+int __connman_wispr_cancel(struct connman_service *service,
+					enum connman_ipconfig_type type);
 void __connman_wispr_stop(struct connman_service *service);
 
 #include <connman/technology.h>
src/wispr.c +55 -0

61 lines not on this page · raw message

Signature · 1 line
2.42.0
#35 lore raw

PATCH v2 15/17 wispr: Add documentation to '__connman_wispr_cancel'.

In reply to Grant Erickson

This adds documentation to the '__connman_wispr_cancel' function.

---
 src/wispr.c | 35 +++++++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)
src/wispr.c +35 -0
index 9f995060a6c0..3837a87811a9 100644
@@ -1341,6 +1341,41 @@ free_wp:
 	return err;
 }
 
+/**
+ *  @brief
+ *    Cancel a HTTP-based Internet reachability check for the specified
+ *    network service IP configuration type.
+ *
+ *  This attempts to cancel a HTTP-based Internet reachability check
+ *  for the specified network service IP configuration type.
+ *
+ *  If a matching HTTP-based Internet reachability check is found, the
+ *  original callback specified with #__connman_wispr_start will be
+ *  invoked with a success value of zero ('0') or false and an error
+ *  value of -ECANCELED.
+ *
+ *  @param[in,out]  service             A pointer to the mutable network
+ *                                      service for which to cancel the
+ *                                      reachability check.
+ *  @param[in]      type                The IP configuration type for
+ *                                      which the reachability check
+ *                                      is to be cancelled.
+ *
+ *  @retval  0            If a matching HTTP-based Internet reachability
+ *                        check was successfully cancelled.
+ *  @retval  -EINVAL      If the IP configuration type is not X or Y or
+ *                        if the network interface index associated
+ *                        with @a service is invalid.
+ *  @retval  -ENOENT      If a matching HTTP-based Internet reachability
+ *                        check could not be found.
+ *  @retval  -EOPNOTSUPP  If HTTP-based Internet reachability checks are
+ *                        not supported for the technology type
+ *                        associated with @a service.
+ *
+ *  @sa __connman_wispr_start
+ *  @sa __connman_wispr_stop
+ *
+ */
 int __connman_wispr_cancel(struct connman_service *service,
 					enum connman_ipconfig_type type)
 {
Signature · 1 line
2.42.0
#36 lore raw

PATCH v2 16/17 wispr: Avoid double-free in 'free_wispr_routes'.

In reply to Grant Erickson

Now that 'free_wispr_routes' can be invoked in terminal free-only as well as cancel-latently-followed-by-free contexts, ensure that a double-free is avoided with both the 'route->address' and 'wp_context->route_list->data' by explicitly nulling them after calling 'g_free' on them.

---
 src/wispr.c | 3 +++
 1 file changed, 3 insertions(+)
src/wispr.c +3 -0
index 3837a87811a9..9cd1e7db501d 100644
@@ -158,7 +158,10 @@ static void free_wispr_routes(struct connman_wispr_portal_context *wp_context)
 		}
 
 		g_free(route->address);
+		route->address = NULL;
+
 		g_free(route);
+		wp_context->route_list->data = NULL;
 
 		wp_context->route_list =
 			g_slist_delete_link(wp_context->route_list,
Signature · 1 line
2.42.0
#37 lore raw

PATCH v2 17/17 service: Leverage '__connman_wispr_cancel'.

In reply to Grant Erickson

This leverages the newly-introduced '__connman_wispr_cancel' in 'cancel_online_check' to ensure that a pending or in-flight WISPr portal detection request or an "online" HTTP-based Internet reachability check is canceled not only in the service module but in the WISPr module as well.

This prevents two concurrent, outstanding, and redundant IPv4 WISPr requests from being in-flight when 'EnableOnlineCheck' is asserted.

Prior to this change, this redundancy was set in motion by:

1. The two back-to-back IPv4 probes get triggered by both of the following paths:

a. Triggered from 'default_changed' and 'start_wispr_if_connected'.
This is the newer path, chronologically, in the code base.

b. Triggered from 'service_ip_bound', 'address_updated', and
'start_online_check'. This is the older path, chronologically, in the code base.

2. With the following commits addressed:

a. 812e171 ("Close three '__connman_wisp_start' failure closure
holes.")

* With this fix alone, at minimum, the first probe above (1) would have resulted, eventually in a failure closure with 'complete_online_check'.

b. 5f95851 ("wispr: Avoid 'connman_proxy_lookup' call for UNKNOWN
proxy method.") fixed, the first IPv4 probe from (1) no longer "falls down a 'hole'" and gets lost (closure- and accounting- wise).

* With this fix, the first IPv4 probe is no longer a complete throwaway--it actually succeeds. However, since it does so, it becomes the first of the two redundant IPv4 checks.

By employing '__connman_wispr_cancel', 'cancel_online_check' quells the first IPv4 check triggered from 'default_changed' and 'start_wispr_if_connected' and replaces it, fully (in BOTH the service and WISpr modules), with the second IPv4 check triggered from 'service_ip_bound', 'address_updated', and 'start_online_check'.

---
 src/service.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
src/service.c +18 -0
index d78ed0123160..9f6e28d34be4 100644
@@ -1594,6 +1594,19 @@ static void cancel_online_check(struct connman_service *service,
 		service->online_timeout_ipv4,
 		service->online_timeout_ipv6);
 
+	/*
+	 * First, ensure that the reachability check is cancelled in the
+	 * WISPr module. This may fail, however, we ignore any such
+	 * failures as we still want to cancel any outstanding check from
+	 * this module as well.
+	 */
+	__connman_wispr_cancel(service, type);
+
+	/*
+	 * Now that the reachability check has been cancelled in the WISPr
+	 * module, cancel any outstanding check that may be scheduled in
+	 * this module.
+	 */
 	if (type == CONNMAN_IPCONFIG_TYPE_IPV4 &&
 		service->online_timeout_ipv4) {
 		g_source_remove(service->online_timeout_ipv4);
@@ -1936,6 +1949,11 @@ static void complete_online_check(struct connman_service *service,
 		type, __connman_ipconfig_type2string(type),
 		success, err, strerror(-err));
 
+	if (!success && err == -ECANCELED) {
+		DBG("online check was canceled; no action taken");
+		return;
+	}
+
 	if (type == CONNMAN_IPCONFIG_TYPE_IPV4) {
 		interval = &service->online_check_interval_ipv4;
 		timeout = &service->online_timeout_ipv4;
Signature · 1 line
2.42.0
#38 lore raw
In reply to Grant Erickson

Hi Grant,

Quoted 71 lines

This addresses an issue in which, when 'EnableOnlineCheck' is asserted, two (2) concurrent IPv4 and one (1) IPv6 reachability checks get queued.

The issue is addressed by introducing and leveraging '__connman_wispr_cancel' in 'cancel_online_check' to ensure that a pending or in-flight WISPr portal detection request or an "online" HTTP-based Internet reachability check is canceled not only in the service module but in the WISPr module as well.

This prevents two concurrent, outstanding, and redundant IPv4 WISPr requests from being in-flight when EnableOnlineCheck is asserted.

Prior to these changes, this redundancy was set in motion by:

1. The two back-to-back IPv4 probes get triggered by both of the following paths:

a. Triggered from 'default_changed' and
'start_wispr_if_connected'. This is the newer path, chronologically, in the code base.

b. Triggered from 'service_ip_bound', 'address_updated', and
'start_online_check'. This is the older path, chronologically, in the code base.

2. With the following commits addressed:

a. 812e171 ("Close three '__connman_wisp_start' failure closure
holes.")

* With this fix alone, at minimum, the first probe above (1) would have resulted, eventually in a failure closure with 'complete_online_check'.

b. 5f95851 ("wispr: Avoid 'connman_proxy_lookup' call for
'UNKNOWN' proxy method.") fixed, the first IPv4 probe from
(1) no longer "falls down a 'hole'" and gets lost (closure- and accounting-wise).

* With this fix, the first IPv4 probe is no longer a complete throwaway--it actually succeeds. However, since it does so, it becomes the first of the two redundant IPv4 checks.

By employing '__connman_wispr_cancel', 'cancel_online_check' quells the first IPv4 check triggered from 'default_changed' and 'start_wispr_if_connected' and replaces it, fully (in both the service and WISpr modules), with the second IPv4 check triggered from 'service_ip_bound', 'address_updated', and 'start_online_check'.

Grant Erickson (17):
wispr: Rename context proxy-related data members.
wispr: Add and leverage 'is_wispr_supported'.
wispr: Add documentation to 'is_wispr_supported'.
service: Document service unref calls in 'cancel_online_check'.
wispr: Add documentation to 'wispr_portal_detect'.
wispr: Add documentation to '__connman_wispr_stop'.
wispr: Add and leverage 'cancel_connman_wispr_portal_context'.
wispr: Add documentation to 'cancel_connman_wispr_portal_context'.
gweb: Add optional OS error status parameter to 'g_web_request_*'.
wispr: Add and leverage an OS error parameter to
'__connman_wispr_cb_t'.
service: Add IP configuration type to 'cancel_online_check'.
gweb: Add reference count debug statements.
gweb: Factor out GWeb destruction into 'g_web_free'.
wispr: Add '__connman_wispr_cancel' interface.
wispr: Add documentation to '__connman_wispr_cancel'.
wispr: Avoid double-free in 'free_wispr_routes'.
service: Leverage '__connman_wispr_cancel'.

Quoted 9 lines
gweb/gweb.c      |  94 +++++++++----
gweb/gweb.h      |   8 +-
src/6to4.c       |   2 +-
src/connman.h    |   5 +-
src/service.c    |  70 ++++++++--
src/wispr.c      | 342 ++++++++++++++++++++++++++++++++++++++++-------
tools/web-test.c |   3 +-
tools/wispr.c    |   8 +-
8 files changed, 440 insertions(+), 92 deletions(-)

all 17 patches have been applied.

Regards

Marcel