From patchwork Thu Nov 16 01:02:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Grant Erickson X-Patchwork-Id: 13457461 Received: from mohas.pair.com (mohas.pair.com [209.68.5.112]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BCFF9ECE for ; Thu, 16 Nov 2023 01:03:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=nuovations.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nuovations.com Authentication-Results: smtp.subspace.kernel.org; dkim=none Received: from mohas.pair.com (localhost [127.0.0.1]) by mohas.pair.com (Postfix) with ESMTP id 1CAF573207 for ; Wed, 15 Nov 2023 20:03:01 -0500 (EST) Received: from localhost.localdomain (unknown [IPv6:2601:647:5a00:15c1:230d:b2c9:c388:f96b]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mohas.pair.com (Postfix) with ESMTPSA id C18DC731BE for ; Wed, 15 Nov 2023 20:03:00 -0500 (EST) From: Grant Erickson To: connman@lists.linux.dev Subject: [PATCH 01/17] wispr: Rename context proxy-related data members. Date: Wed, 15 Nov 2023 17:02:42 -0800 Message-ID: <20231116010259.628527-2-gerickson@nuovations.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231116010259.628527-1-gerickson@nuovations.com> References: <20231116010259.628527-1-gerickson@nuovations.com> Precedence: bulk X-Mailing-List: connman@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: mailmunge 3.11 on 209.68.5.112 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(-) diff --git a/src/wispr.c b/src/wispr.c index ab763d5bada0..79cb713449bc 100644 --- a/src/wispr.c +++ b/src/wispr.c @@ -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: From patchwork Thu Nov 16 01:02:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Grant Erickson X-Patchwork-Id: 13457458 Received: from mohas.pair.com (mohas.pair.com [209.68.5.112]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BD02FEDF for ; Thu, 16 Nov 2023 01:03:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=nuovations.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nuovations.com Authentication-Results: smtp.subspace.kernel.org; dkim=none Received: from mohas.pair.com (localhost [127.0.0.1]) by mohas.pair.com (Postfix) with ESMTP id 85B9F731A4 for ; Wed, 15 Nov 2023 20:03:01 -0500 (EST) Received: from localhost.localdomain (unknown [IPv6:2601:647:5a00:15c1:230d:b2c9:c388:f96b]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mohas.pair.com (Postfix) with ESMTPSA id 3D5DC7321A for ; Wed, 15 Nov 2023 20:03:01 -0500 (EST) From: Grant Erickson To: connman@lists.linux.dev Subject: [PATCH 02/17] wispr: Add and leverage 'is_wispr_supported'. Date: Wed, 15 Nov 2023 17:02:43 -0800 Message-ID: <20231116010259.628527-3-gerickson@nuovations.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231116010259.628527-1-gerickson@nuovations.com> References: <20231116010259.628527-1-gerickson@nuovations.com> Precedence: bulk X-Mailing-List: connman@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: mailmunge 3.11 on 209.68.5.112 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(-) diff --git a/src/wispr.c b/src/wispr.c index 79cb713449bc..9c99402c8c6d 100644 --- a/src/wispr.c +++ b/src/wispr.c @@ -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) From patchwork Thu Nov 16 01:02:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Grant Erickson X-Patchwork-Id: 13457460 Received: from mohas.pair.com (mohas.pair.com [209.68.5.112]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BCFD7818 for ; Thu, 16 Nov 2023 01:03:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=nuovations.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nuovations.com Authentication-Results: smtp.subspace.kernel.org; dkim=none Received: from mohas.pair.com (localhost [127.0.0.1]) by mohas.pair.com (Postfix) with ESMTP id 049DB73208 for ; Wed, 15 Nov 2023 20:03:02 -0500 (EST) Received: from localhost.localdomain (unknown [IPv6:2601:647:5a00:15c1:230d:b2c9:c388:f96b]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mohas.pair.com (Postfix) with ESMTPSA id AC28673219 for ; Wed, 15 Nov 2023 20:03:01 -0500 (EST) From: Grant Erickson To: connman@lists.linux.dev Subject: [PATCH 03/17] wispr: Add documentation to 'is_wispr_supported'. Date: Wed, 15 Nov 2023 17:02:44 -0800 Message-ID: <20231116010259.628527-4-gerickson@nuovations.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231116010259.628527-1-gerickson@nuovations.com> References: <20231116010259.628527-1-gerickson@nuovations.com> Precedence: bulk X-Mailing-List: connman@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: mailmunge 3.11 on 209.68.5.112 This adds documentation to the 'is_wispr_supported' function. --- src/wispr.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/wispr.c b/src/wispr.c index 9c99402c8c6d..215c6217a02b 100644 --- a/src/wispr.c +++ b/src/wispr.c @@ -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) From patchwork Thu Nov 16 01:02:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Grant Erickson X-Patchwork-Id: 13457459 Received: from mohas.pair.com (mohas.pair.com [209.68.5.112]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BCFA5391 for ; Thu, 16 Nov 2023 01:03:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=nuovations.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nuovations.com Authentication-Results: smtp.subspace.kernel.org; dkim=none Received: from mohas.pair.com (localhost [127.0.0.1]) by mohas.pair.com (Postfix) with ESMTP id 700ED73206 for ; Wed, 15 Nov 2023 20:03:02 -0500 (EST) Received: from localhost.localdomain (unknown [IPv6:2601:647:5a00:15c1:230d:b2c9:c388:f96b]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mohas.pair.com (Postfix) with ESMTPSA id 2539D7321E for ; Wed, 15 Nov 2023 20:03:02 -0500 (EST) From: Grant Erickson To: connman@lists.linux.dev Subject: [PATCH 04/17] service: Document service unref calls in 'cancel_online_check'. Date: Wed, 15 Nov 2023 17:02:45 -0800 Message-ID: <20231116010259.628527-5-gerickson@nuovations.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231116010259.628527-1-gerickson@nuovations.com> References: <20231116010259.628527-1-gerickson@nuovations.com> Precedence: bulk X-Mailing-List: connman@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: mailmunge 3.11 on 209.68.5.112 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(+) diff --git a/src/service.c b/src/service.c index 075f3fba5abe..5fb53c2084f9 100644 --- a/src/service.c +++ b/src/service.c @@ -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); } } From patchwork Thu Nov 16 01:02:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Grant Erickson X-Patchwork-Id: 13457462 Received: from mohas.pair.com (mohas.pair.com [209.68.5.112]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 736B07E for ; Thu, 16 Nov 2023 01:03:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=nuovations.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nuovations.com Authentication-Results: smtp.subspace.kernel.org; dkim=none Received: from mohas.pair.com (localhost [127.0.0.1]) by mohas.pair.com (Postfix) with ESMTP id DA9FD73213 for ; Wed, 15 Nov 2023 20:03:02 -0500 (EST) Received: from localhost.localdomain (unknown [IPv6:2601:647:5a00:15c1:230d:b2c9:c388:f96b]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mohas.pair.com (Postfix) with ESMTPSA id 92BEC73224 for ; Wed, 15 Nov 2023 20:03:02 -0500 (EST) From: Grant Erickson To: connman@lists.linux.dev Subject: [PATCH 05/17] wispr: Add documentation to 'wispr_portal_detect'. Date: Wed, 15 Nov 2023 17:02:46 -0800 Message-ID: <20231116010259.628527-6-gerickson@nuovations.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231116010259.628527-1-gerickson@nuovations.com> References: <20231116010259.628527-1-gerickson@nuovations.com> Precedence: bulk X-Mailing-List: connman@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: mailmunge 3.11 on 209.68.5.112 This adds documentation to the 'wispr_portal_detect' function. --- src/wispr.c | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/src/wispr.c b/src/wispr.c index 215c6217a02b..972ef88cabd5 100644 --- a/src/wispr.c +++ b/src/wispr.c @@ -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) { From patchwork Thu Nov 16 01:02:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Grant Erickson X-Patchwork-Id: 13457463 Received: from mohas.pair.com (mohas.pair.com [209.68.5.112]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A7FE11361 for ; Thu, 16 Nov 2023 01:03:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=nuovations.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nuovations.com Authentication-Results: smtp.subspace.kernel.org; dkim=none Received: from mohas.pair.com (localhost [127.0.0.1]) by mohas.pair.com (Postfix) with ESMTP id 5386D73214 for ; Wed, 15 Nov 2023 20:03:03 -0500 (EST) Received: from localhost.localdomain (unknown [IPv6:2601:647:5a00:15c1:230d:b2c9:c388:f96b]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mohas.pair.com (Postfix) with ESMTPSA id 0CBB073225 for ; Wed, 15 Nov 2023 20:03:02 -0500 (EST) From: Grant Erickson To: connman@lists.linux.dev Subject: [PATCH 06/17] wispr: Add documentation to '__connman_wispr_stop'. Date: Wed, 15 Nov 2023 17:02:47 -0800 Message-ID: <20231116010259.628527-7-gerickson@nuovations.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231116010259.628527-1-gerickson@nuovations.com> References: <20231116010259.628527-1-gerickson@nuovations.com> Precedence: bulk X-Mailing-List: connman@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: mailmunge 3.11 on 209.68.5.112 This adds documentation to the '__connman_wispr_stop' function. --- src/wispr.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/wispr.c b/src/wispr.c index 972ef88cabd5..7018dbc7d302 100644 --- a/src/wispr.c +++ b/src/wispr.c @@ -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; From patchwork Thu Nov 16 01:02:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Grant Erickson X-Patchwork-Id: 13457464 Received: from mohas.pair.com (mohas.pair.com [209.68.5.112]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 676E2138A for ; Thu, 16 Nov 2023 01:03:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=nuovations.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nuovations.com Authentication-Results: smtp.subspace.kernel.org; dkim=none Received: from mohas.pair.com (localhost [127.0.0.1]) by mohas.pair.com (Postfix) with ESMTP id C164273218 for ; Wed, 15 Nov 2023 20:03:03 -0500 (EST) Received: from localhost.localdomain (unknown [IPv6:2601:647:5a00:15c1:230d:b2c9:c388:f96b]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mohas.pair.com (Postfix) with ESMTPSA id 79C2C73222 for ; Wed, 15 Nov 2023 20:03:03 -0500 (EST) From: Grant Erickson To: connman@lists.linux.dev Subject: [PATCH 07/17] wispr: Add and leverage 'cancel_connman_wispr_portal_context'. Date: Wed, 15 Nov 2023 17:02:48 -0800 Message-ID: <20231116010259.628527-8-gerickson@nuovations.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231116010259.628527-1-gerickson@nuovations.com> References: <20231116010259.628527-1-gerickson@nuovations.com> Precedence: bulk X-Mailing-List: connman@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: mailmunge 3.11 on 209.68.5.112 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(-) diff --git a/src/wispr.c b/src/wispr.c index 7018dbc7d302..84d4b1d0efb4 100644 --- a/src/wispr.c +++ b/src/wispr.c @@ -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); } From patchwork Thu Nov 16 01:02:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Grant Erickson X-Patchwork-Id: 13457465 Received: from mohas.pair.com (mohas.pair.com [209.68.5.112]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A010515A4 for ; Thu, 16 Nov 2023 01:03:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=nuovations.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nuovations.com Authentication-Results: smtp.subspace.kernel.org; dkim=none Received: from mohas.pair.com (localhost [127.0.0.1]) by mohas.pair.com (Postfix) with ESMTP id 3D15573219 for ; Wed, 15 Nov 2023 20:03:04 -0500 (EST) Received: from localhost.localdomain (unknown [IPv6:2601:647:5a00:15c1:230d:b2c9:c388:f96b]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mohas.pair.com (Postfix) with ESMTPSA id E886173227 for ; Wed, 15 Nov 2023 20:03:03 -0500 (EST) From: Grant Erickson To: connman@lists.linux.dev Subject: [PATCH 08/17] wispr: Add documentation to 'cancel_connman_wispr_portal_context'. Date: Wed, 15 Nov 2023 17:02:49 -0800 Message-ID: <20231116010259.628527-9-gerickson@nuovations.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231116010259.628527-1-gerickson@nuovations.com> References: <20231116010259.628527-1-gerickson@nuovations.com> Precedence: bulk X-Mailing-List: connman@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: mailmunge 3.11 on 209.68.5.112 This adds documentation to the 'cancel_connman_wispr_portal_context' function. --- src/wispr.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/wispr.c b/src/wispr.c index 84d4b1d0efb4..1e62e0cd2dee 100644 --- a/src/wispr.c +++ b/src/wispr.c @@ -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) { From patchwork Thu Nov 16 01:02:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Grant Erickson X-Patchwork-Id: 13457468 Received: from mohas.pair.com (mohas.pair.com [209.68.5.112]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 63B57818 for ; Thu, 16 Nov 2023 01:03:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=nuovations.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nuovations.com Authentication-Results: smtp.subspace.kernel.org; dkim=none Received: from mohas.pair.com (localhost [127.0.0.1]) by mohas.pair.com (Postfix) with ESMTP id AC4D77321A for ; Wed, 15 Nov 2023 20:03:04 -0500 (EST) Received: from localhost.localdomain (unknown [IPv6:2601:647:5a00:15c1:230d:b2c9:c388:f96b]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mohas.pair.com (Postfix) with ESMTPSA id 640A873229 for ; Wed, 15 Nov 2023 20:03:04 -0500 (EST) From: Grant Erickson To: connman@lists.linux.dev Subject: [PATCH 09/17] gweb: Add optional OS error status parameter to 'g_web_request_*'. Date: Wed, 15 Nov 2023 17:02:50 -0800 Message-ID: <20231116010259.628527-10-gerickson@nuovations.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231116010259.628527-1-gerickson@nuovations.com> References: <20231116010259.628527-1-gerickson@nuovations.com> Precedence: bulk X-Mailing-List: connman@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: mailmunge 3.11 on 209.68.5.112 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(-) diff --git a/gweb/gweb.c b/gweb/gweb.c index 1463b588d411..1cf830a46773 100644 --- a/gweb/gweb.c +++ b/gweb/gweb.c @@ -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); diff --git a/gweb/gweb.h b/gweb/gweb.h index 3c50979cfd0a..7c65aebf4698 100644 --- a/gweb/gweb.h +++ b/gweb/gweb.h @@ -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); diff --git a/src/6to4.c b/src/6to4.c index 71a288277104..5542b339691a 100644 --- a/src/6to4.c +++ b/src/6to4.c @@ -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); } diff --git a/src/wispr.c b/src/wispr.c index 1e62e0cd2dee..4b4c9c1e59ec 100644 --- a/src/wispr.c +++ b/src/wispr.c @@ -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: diff --git a/tools/web-test.c b/tools/web-test.c index 55c58af5a7dc..a65e6c115c41 100644 --- a/tools/web-test.c +++ b/tools/web-test.c @@ -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; } diff --git a/tools/wispr.c b/tools/wispr.c index e56dfc169411..ef7b60d3f5ca 100644 --- a/tools/wispr.c +++ b/tools/wispr.c @@ -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"); From patchwork Thu Nov 16 01:02:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Grant Erickson X-Patchwork-Id: 13457467 Received: from mohas.pair.com (mohas.pair.com [209.68.5.112]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 697EFECE for ; Thu, 16 Nov 2023 01:03:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=nuovations.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nuovations.com Authentication-Results: smtp.subspace.kernel.org; dkim=none Received: from mohas.pair.com (localhost [127.0.0.1]) by mohas.pair.com (Postfix) with ESMTP id 261D87321D for ; Wed, 15 Nov 2023 20:03:05 -0500 (EST) Received: from localhost.localdomain (unknown [IPv6:2601:647:5a00:15c1:230d:b2c9:c388:f96b]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mohas.pair.com (Postfix) with ESMTPSA id D2C267322A for ; Wed, 15 Nov 2023 20:03:04 -0500 (EST) From: Grant Erickson To: connman@lists.linux.dev Subject: [PATCH 10/17] wispr: Add and leverage an OS error parameter to '__connman_wispr_cb_t'. Date: Wed, 15 Nov 2023 17:02:51 -0800 Message-ID: <20231116010259.628527-11-gerickson@nuovations.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231116010259.628527-1-gerickson@nuovations.com> References: <20231116010259.628527-1-gerickson@nuovations.com> Precedence: bulk X-Mailing-List: connman@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: mailmunge 3.11 on 209.68.5.112 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(-) diff --git a/src/connman.h b/src/connman.h index 143a087701d8..d5aa6f5599e7 100644 --- a/src/connman.h +++ b/src/connman.h @@ -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); diff --git a/src/service.c b/src/service.c index 5fb53c2084f9..0882cd167699 100644 --- a/src/service.c +++ b/src/service.c @@ -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; diff --git a/src/wispr.c b/src/wispr.c index 4b4c9c1e59ec..9d471628e705 100644 --- a/src/wispr.c +++ b/src/wispr.c @@ -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; From patchwork Thu Nov 16 01:02:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Grant Erickson X-Patchwork-Id: 13457472 Received: from mohas.pair.com (mohas.pair.com [209.68.5.112]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 942DB17D3 for ; Thu, 16 Nov 2023 01:03:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=nuovations.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nuovations.com Authentication-Results: smtp.subspace.kernel.org; dkim=none Received: from mohas.pair.com (localhost [127.0.0.1]) by mohas.pair.com (Postfix) with ESMTP id 945087321E for ; Wed, 15 Nov 2023 20:03:05 -0500 (EST) Received: from localhost.localdomain (unknown [IPv6:2601:647:5a00:15c1:230d:b2c9:c388:f96b]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mohas.pair.com (Postfix) with ESMTPSA id 4C62B7322E for ; Wed, 15 Nov 2023 20:03:05 -0500 (EST) From: Grant Erickson To: connman@lists.linux.dev Subject: [PATCH 11/17] service: Add IP configuration type to 'cancel_online_check'. Date: Wed, 15 Nov 2023 17:02:52 -0800 Message-ID: <20231116010259.628527-12-gerickson@nuovations.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231116010259.628527-1-gerickson@nuovations.com> References: <20231116010259.628527-1-gerickson@nuovations.com> Precedence: bulk X-Mailing-List: connman@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: mailmunge 3.11 on 209.68.5.112 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(-) diff --git a/src/service.c b/src/service.c index 0882cd167699..d78ed0123160 100644 --- a/src/service.c +++ b/src/service.c @@ -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) From patchwork Thu Nov 16 01:02:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Grant Erickson X-Patchwork-Id: 13457466 Received: from mohas.pair.com (mohas.pair.com [209.68.5.112]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9432417E3 for ; Thu, 16 Nov 2023 01:03:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=nuovations.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nuovations.com Authentication-Results: smtp.subspace.kernel.org; dkim=none Received: from mohas.pair.com (localhost [127.0.0.1]) by mohas.pair.com (Postfix) with ESMTP id 0D80273222 for ; Wed, 15 Nov 2023 20:03:06 -0500 (EST) Received: from localhost.localdomain (unknown [IPv6:2601:647:5a00:15c1:230d:b2c9:c388:f96b]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mohas.pair.com (Postfix) with ESMTPSA id BA92373230 for ; Wed, 15 Nov 2023 20:03:05 -0500 (EST) From: Grant Erickson To: connman@lists.linux.dev Subject: [PATCH 12/17] gweb: Add reference count debug statements. Date: Wed, 15 Nov 2023 17:02:53 -0800 Message-ID: <20231116010259.628527-13-gerickson@nuovations.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231116010259.628527-1-gerickson@nuovations.com> References: <20231116010259.628527-1-gerickson@nuovations.com> Precedence: bulk X-Mailing-List: connman@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: mailmunge 3.11 on 209.68.5.112 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(+) diff --git a/gweb/gweb.c b/gweb/gweb.c index 1cf830a46773..994c33638e55 100644 --- a/gweb/gweb.c +++ b/gweb/gweb.c @@ -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; From patchwork Thu Nov 16 01:02:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Grant Erickson X-Patchwork-Id: 13457471 Received: from mohas.pair.com (mohas.pair.com [209.68.5.112]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C3C5517F4 for ; Thu, 16 Nov 2023 01:03:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=nuovations.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nuovations.com Authentication-Results: smtp.subspace.kernel.org; dkim=none Received: from mohas.pair.com (localhost [127.0.0.1]) by mohas.pair.com (Postfix) with ESMTP id 7E79973224 for ; Wed, 15 Nov 2023 20:03:06 -0500 (EST) Received: from localhost.localdomain (unknown [IPv6:2601:647:5a00:15c1:230d:b2c9:c388:f96b]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mohas.pair.com (Postfix) with ESMTPSA id 33CD67322A for ; Wed, 15 Nov 2023 20:03:06 -0500 (EST) From: Grant Erickson To: connman@lists.linux.dev Subject: [PATCH 13/17] gweb: Factor out GWeb destruction into 'g_web_free'. Date: Wed, 15 Nov 2023 17:02:54 -0800 Message-ID: <20231116010259.628527-14-gerickson@nuovations.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231116010259.628527-1-gerickson@nuovations.com> References: <20231116010259.628527-1-gerickson@nuovations.com> Precedence: bulk X-Mailing-List: connman@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: mailmunge 3.11 on 209.68.5.112 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(-) diff --git a/gweb/gweb.c b/gweb/gweb.c index 994c33638e55..96d543af8440 100644 --- a/gweb/gweb.c +++ b/gweb/gweb.c @@ -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(); From patchwork Thu Nov 16 01:02:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Grant Erickson X-Patchwork-Id: 13457469 Received: from mohas.pair.com (mohas.pair.com [209.68.5.112]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9F0F217F0 for ; Thu, 16 Nov 2023 01:03:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=nuovations.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nuovations.com Authentication-Results: smtp.subspace.kernel.org; dkim=none Received: from mohas.pair.com (localhost [127.0.0.1]) by mohas.pair.com (Postfix) with ESMTP id ECB8773225 for ; Wed, 15 Nov 2023 20:03:06 -0500 (EST) Received: from localhost.localdomain (unknown [IPv6:2601:647:5a00:15c1:230d:b2c9:c388:f96b]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mohas.pair.com (Postfix) with ESMTPSA id A3A7673233 for ; Wed, 15 Nov 2023 20:03:06 -0500 (EST) From: Grant Erickson To: connman@lists.linux.dev Subject: [PATCH 14/17] wispr: Add '__connman_wispr_cancel' interface. Date: Wed, 15 Nov 2023 17:02:55 -0800 Message-ID: <20231116010259.628527-15-gerickson@nuovations.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231116010259.628527-1-gerickson@nuovations.com> References: <20231116010259.628527-1-gerickson@nuovations.com> Precedence: bulk X-Mailing-List: connman@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: mailmunge 3.11 on 209.68.5.112 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(+) diff --git a/src/connman.h b/src/connman.h index d5aa6f5599e7..ae04cd9a26c6 100644 --- a/src/connman.h +++ b/src/connman.h @@ -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 diff --git a/src/wispr.c b/src/wispr.c index 9d471628e705..f42429f56e07 100644 --- a/src/wispr.c +++ b/src/wispr.c @@ -1340,6 +1340,61 @@ free_wp: return err; } +int __connman_wispr_cancel(struct connman_service *service, + enum connman_ipconfig_type type) +{ + struct connman_wispr_portal_context *wp_context = NULL; + struct connman_wispr_portal *wispr_portal = NULL; + int index; + + DBG("service %p (%s) type %d (%s)", + service, connman_service_get_identifier(service), + type, __connman_ipconfig_type2string(type)); + + if (!is_wispr_supported(service)) + return -EOPNOTSUPP; + + index = __connman_service_get_index(service); + if (index < 0) + return -EINVAL; + + DBG("index %d", index); + + if (!wispr_portal_hash) + return -ENOENT; + + wispr_portal = g_hash_table_lookup(wispr_portal_hash, + GINT_TO_POINTER(index)); + + DBG("wispr_portal %p", wispr_portal); + + if (!wispr_portal) + return -ENOENT; + + if (type == CONNMAN_IPCONFIG_TYPE_IPV4) + wp_context = wispr_portal->ipv4_context; + else if (type == CONNMAN_IPCONFIG_TYPE_IPV6) + wp_context = wispr_portal->ipv6_context; + else + return -EINVAL; + + DBG("wp_context %p", wp_context); + + if (!wp_context) + return -ENOENT; + + cancel_connman_wispr_portal_context(wp_context); + + wp_context->cb(wp_context->service, + wp_context->type, + false, + -ECANCELED); + + wispr_portal_context_unref(wp_context); + + return 0; +} + /** * @brief * Stop all HTTP-based Internet reachability checks for the specified From patchwork Thu Nov 16 01:02:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Grant Erickson X-Patchwork-Id: 13457473 Received: from mohas.pair.com (mohas.pair.com [209.68.5.112]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 88A771844 for ; Thu, 16 Nov 2023 01:03:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=nuovations.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nuovations.com Authentication-Results: smtp.subspace.kernel.org; dkim=none Received: from mohas.pair.com (localhost [127.0.0.1]) by mohas.pair.com (Postfix) with ESMTP id 63EF173226 for ; Wed, 15 Nov 2023 20:03:07 -0500 (EST) Received: from localhost.localdomain (unknown [IPv6:2601:647:5a00:15c1:230d:b2c9:c388:f96b]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mohas.pair.com (Postfix) with ESMTPSA id 1D9D673236 for ; Wed, 15 Nov 2023 20:03:07 -0500 (EST) From: Grant Erickson To: connman@lists.linux.dev Subject: [PATCH 15/17] wispr: Add documentation to '__connman_wispr_cancel'. Date: Wed, 15 Nov 2023 17:02:56 -0800 Message-ID: <20231116010259.628527-16-gerickson@nuovations.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231116010259.628527-1-gerickson@nuovations.com> References: <20231116010259.628527-1-gerickson@nuovations.com> Precedence: bulk X-Mailing-List: connman@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: mailmunge 3.11 on 209.68.5.112 This adds documentation to the '__connman_wispr_cancel' function. --- src/wispr.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/wispr.c b/src/wispr.c index f42429f56e07..8b555cfd5d6f 100644 --- a/src/wispr.c +++ b/src/wispr.c @@ -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) { From patchwork Thu Nov 16 01:02:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Grant Erickson X-Patchwork-Id: 13457470 Received: from mohas.pair.com (mohas.pair.com [209.68.5.112]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5ACE010F0 for ; Thu, 16 Nov 2023 01:03:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=nuovations.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nuovations.com Authentication-Results: smtp.subspace.kernel.org; dkim=none Received: from mohas.pair.com (localhost [127.0.0.1]) by mohas.pair.com (Postfix) with ESMTP id DA44773227 for ; Wed, 15 Nov 2023 20:03:07 -0500 (EST) Received: from localhost.localdomain (unknown [IPv6:2601:647:5a00:15c1:230d:b2c9:c388:f96b]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mohas.pair.com (Postfix) with ESMTPSA id 8A53773237 for ; Wed, 15 Nov 2023 20:03:07 -0500 (EST) From: Grant Erickson To: connman@lists.linux.dev Subject: [PATCH 16/17] wispr: Avoid double-free in 'free_wispr_routes'. Date: Wed, 15 Nov 2023 17:02:57 -0800 Message-ID: <20231116010259.628527-17-gerickson@nuovations.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231116010259.628527-1-gerickson@nuovations.com> References: <20231116010259.628527-1-gerickson@nuovations.com> Precedence: bulk X-Mailing-List: connman@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: mailmunge 3.11 on 209.68.5.112 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(+) diff --git a/src/wispr.c b/src/wispr.c index 8b555cfd5d6f..4a52b03c2ee7 100644 --- a/src/wispr.c +++ b/src/wispr.c @@ -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, From patchwork Thu Nov 16 01:02:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Grant Erickson X-Patchwork-Id: 13457474 Received: from mohas.pair.com (mohas.pair.com [209.68.5.112]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 887DE1361 for ; Thu, 16 Nov 2023 01:03:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=nuovations.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nuovations.com Authentication-Results: smtp.subspace.kernel.org; dkim=none Received: from mohas.pair.com (localhost [127.0.0.1]) by mohas.pair.com (Postfix) with ESMTP id 5756D7322E for ; Wed, 15 Nov 2023 20:03:08 -0500 (EST) Received: from localhost.localdomain (unknown [IPv6:2601:647:5a00:15c1:230d:b2c9:c388:f96b]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mohas.pair.com (Postfix) with ESMTPSA id 0C59273238 for ; Wed, 15 Nov 2023 20:03:07 -0500 (EST) From: Grant Erickson To: connman@lists.linux.dev Subject: [PATCH 17/17] service: Leverage '__connman_wispr_cancel'. Date: Wed, 15 Nov 2023 17:02:58 -0800 Message-ID: <20231116010259.628527-18-gerickson@nuovations.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231116010259.628527-1-gerickson@nuovations.com> References: <20231116010259.628527-1-gerickson@nuovations.com> Precedence: bulk X-Mailing-List: connman@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: mailmunge 3.11 on 209.68.5.112 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(+) diff --git a/src/service.c b/src/service.c index d78ed0123160..9f6e28d34be4 100644 --- a/src/service.c +++ b/src/service.c @@ -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;