From patchwork Sun Nov 19 17:06: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: 13460614 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 CE7BE1428C for ; Sun, 19 Nov 2023 17:07:22 +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 972D173104 for ; Sun, 19 Nov 2023 12:07:16 -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 50B2F73118 for ; Sun, 19 Nov 2023 12:07:16 -0500 (EST) From: Grant Erickson To: connman@lists.linux.dev Subject: [PATCH v2 01/17] wispr: Rename context proxy-related data members. Date: Sun, 19 Nov 2023 09:06:57 -0800 Message-ID: <20231119170714.775270-2-gerickson@nuovations.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231119170714.775270-1-gerickson@nuovations.com> References: <20231116010259.628527-1-gerickson@nuovations.com> <20231119170714.775270-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 Sun Nov 19 17:06: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: 13460617 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 DF6F0179BE for ; Sun, 19 Nov 2023 17:07:23 +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 19AF573108 for ; Sun, 19 Nov 2023 12:07:17 -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 BE66A73145 for ; Sun, 19 Nov 2023 12:07:16 -0500 (EST) From: Grant Erickson To: connman@lists.linux.dev Subject: [PATCH v2 02/17] wispr: Add and leverage 'is_wispr_supported'. Date: Sun, 19 Nov 2023 09:06:58 -0800 Message-ID: <20231119170714.775270-3-gerickson@nuovations.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231119170714.775270-1-gerickson@nuovations.com> References: <20231116010259.628527-1-gerickson@nuovations.com> <20231119170714.775270-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 | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/src/wispr.c b/src/wispr.c index 79cb713449bc..ae33a68ebbce 100644 --- a/src/wispr.c +++ b/src/wispr.c @@ -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) From patchwork Sun Nov 19 17:06:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Grant Erickson X-Patchwork-Id: 13460618 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 D78EE18040 for ; Sun, 19 Nov 2023 17:07:24 +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 7F6FC73122 for ; Sun, 19 Nov 2023 12:07:17 -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 3801A73174 for ; Sun, 19 Nov 2023 12:07:17 -0500 (EST) From: Grant Erickson To: connman@lists.linux.dev Subject: [PATCH v2 03/17] wispr: Add documentation to 'is_wispr_supported'. Date: Sun, 19 Nov 2023 09:06:59 -0800 Message-ID: <20231119170714.775270-4-gerickson@nuovations.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231119170714.775270-1-gerickson@nuovations.com> References: <20231116010259.628527-1-gerickson@nuovations.com> <20231119170714.775270-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 ae33a68ebbce..1370c93a0e9f 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 Sun Nov 19 17:07:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Grant Erickson X-Patchwork-Id: 13460616 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 D79171804D for ; Sun, 19 Nov 2023 17:07:24 +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 EA1957310A for ; Sun, 19 Nov 2023 12:07:17 -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 A435673154 for ; Sun, 19 Nov 2023 12:07:17 -0500 (EST) From: Grant Erickson To: connman@lists.linux.dev Subject: [PATCH v2 04/17] service: Document service unref calls in 'cancel_online_check'. Date: Sun, 19 Nov 2023 09:07:00 -0800 Message-ID: <20231119170714.775270-5-gerickson@nuovations.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231119170714.775270-1-gerickson@nuovations.com> References: <20231116010259.628527-1-gerickson@nuovations.com> <20231119170714.775270-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 Sun Nov 19 17:07:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Grant Erickson X-Patchwork-Id: 13460620 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 DAEA014291 for ; Sun, 19 Nov 2023 17:07:26 +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 6138573144 for ; Sun, 19 Nov 2023 12:07:18 -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 1BCA2731BE for ; Sun, 19 Nov 2023 12:07:18 -0500 (EST) From: Grant Erickson To: connman@lists.linux.dev Subject: [PATCH v2 05/17] wispr: Add documentation to 'wispr_portal_detect'. Date: Sun, 19 Nov 2023 09:07:01 -0800 Message-ID: <20231119170714.775270-6-gerickson@nuovations.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231119170714.775270-1-gerickson@nuovations.com> References: <20231116010259.628527-1-gerickson@nuovations.com> <20231119170714.775270-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 1370c93a0e9f..84ad21c2d6fb 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 Sun Nov 19 17:07:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Grant Erickson X-Patchwork-Id: 13460619 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 A144413AE3 for ; Sun, 19 Nov 2023 17:07:26 +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 CC17273174 for ; Sun, 19 Nov 2023 12:07:18 -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 869EA731A8 for ; Sun, 19 Nov 2023 12:07:18 -0500 (EST) From: Grant Erickson To: connman@lists.linux.dev Subject: [PATCH v2 06/17] wispr: Add documentation to '__connman_wispr_stop'. Date: Sun, 19 Nov 2023 09:07:02 -0800 Message-ID: <20231119170714.775270-7-gerickson@nuovations.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231119170714.775270-1-gerickson@nuovations.com> References: <20231116010259.628527-1-gerickson@nuovations.com> <20231119170714.775270-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 84ad21c2d6fb..41f5d462da41 100644 --- a/src/wispr.c +++ b/src/wispr.c @@ -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; From patchwork Sun Nov 19 17:07:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Grant Erickson X-Patchwork-Id: 13460622 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 9EBBC1865E for ; Sun, 19 Nov 2023 17:07:27 +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 44CBD731A4 for ; Sun, 19 Nov 2023 12:07:19 -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 F1A06731F8 for ; Sun, 19 Nov 2023 12:07:18 -0500 (EST) From: Grant Erickson To: connman@lists.linux.dev Subject: [PATCH v2 07/17] wispr: Add and leverage 'cancel_connman_wispr_portal_context'. Date: Sun, 19 Nov 2023 09:07:03 -0800 Message-ID: <20231119170714.775270-8-gerickson@nuovations.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231119170714.775270-1-gerickson@nuovations.com> References: <20231116010259.628527-1-gerickson@nuovations.com> <20231119170714.775270-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 41f5d462da41..8ec2b78e8e5f 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 Sun Nov 19 17:07:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Grant Erickson X-Patchwork-Id: 13460621 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 513991804F for ; Sun, 19 Nov 2023 17:07:27 +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 B116F731D1 for ; Sun, 19 Nov 2023 12:07:19 -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 696A1731F7 for ; Sun, 19 Nov 2023 12:07:19 -0500 (EST) From: Grant Erickson To: connman@lists.linux.dev Subject: [PATCH v2 08/17] wispr: Add documentation to 'cancel_connman_wispr_portal_context'. Date: Sun, 19 Nov 2023 09:07:04 -0800 Message-ID: <20231119170714.775270-9-gerickson@nuovations.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231119170714.775270-1-gerickson@nuovations.com> References: <20231116010259.628527-1-gerickson@nuovations.com> <20231119170714.775270-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 8ec2b78e8e5f..c15880e9c8a2 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 Sun Nov 19 17:07:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Grant Erickson X-Patchwork-Id: 13460627 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 5C48518C0A for ; Sun, 19 Nov 2023 17:07:28 +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 2C01E731F6 for ; Sun, 19 Nov 2023 12:07:20 -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 D6A1B731FE for ; Sun, 19 Nov 2023 12:07:19 -0500 (EST) From: Grant Erickson To: connman@lists.linux.dev Subject: [PATCH v2 09/17] gweb: Add optional OS error status parameter to 'g_web_request_*'. Date: Sun, 19 Nov 2023 09:07:05 -0800 Message-ID: <20231119170714.775270-10-gerickson@nuovations.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231119170714.775270-1-gerickson@nuovations.com> References: <20231116010259.628527-1-gerickson@nuovations.com> <20231119170714.775270-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 | 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(-) diff --git a/gweb/gweb.c b/gweb/gweb.c index 1463b588d411..0270531a982f 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,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); 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 c15880e9c8a2..1bf63866009a 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 Sun Nov 19 17:07:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Grant Erickson X-Patchwork-Id: 13460626 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 5C3D41804D for ; Sun, 19 Nov 2023 17:07:28 +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 9464F731FD for ; Sun, 19 Nov 2023 12:07:20 -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 4E48373204 for ; Sun, 19 Nov 2023 12:07:20 -0500 (EST) From: Grant Erickson To: connman@lists.linux.dev Subject: [PATCH v2 10/17] wispr: Add and leverage an OS error parameter to '__connman_wispr_cb_t'. Date: Sun, 19 Nov 2023 09:07:06 -0800 Message-ID: <20231119170714.775270-11-gerickson@nuovations.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231119170714.775270-1-gerickson@nuovations.com> References: <20231116010259.628527-1-gerickson@nuovations.com> <20231119170714.775270-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 1bf63866009a..396891c98153 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; } @@ -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; From patchwork Sun Nov 19 17:07:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Grant Erickson X-Patchwork-Id: 13460623 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 3771418040 for ; Sun, 19 Nov 2023 17:07:28 +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 0CD9D73200 for ; Sun, 19 Nov 2023 12:07:21 -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 B9F3C73206 for ; Sun, 19 Nov 2023 12:07:20 -0500 (EST) From: Grant Erickson To: connman@lists.linux.dev Subject: [PATCH v2 11/17] service: Add IP configuration type to 'cancel_online_check'. Date: Sun, 19 Nov 2023 09:07:07 -0800 Message-ID: <20231119170714.775270-12-gerickson@nuovations.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231119170714.775270-1-gerickson@nuovations.com> References: <20231116010259.628527-1-gerickson@nuovations.com> <20231119170714.775270-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 Sun Nov 19 17:07:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Grant Erickson X-Patchwork-Id: 13460624 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 5C42618B14 for ; Sun, 19 Nov 2023 17:07:28 +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 7A8A073203 for ; Sun, 19 Nov 2023 12:07:21 -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 32C2773213 for ; Sun, 19 Nov 2023 12:07:21 -0500 (EST) From: Grant Erickson To: connman@lists.linux.dev Subject: [PATCH v2 12/17] gweb: Add reference count debug statements. Date: Sun, 19 Nov 2023 09:07:08 -0800 Message-ID: <20231119170714.775270-13-gerickson@nuovations.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231119170714.775270-1-gerickson@nuovations.com> References: <20231116010259.628527-1-gerickson@nuovations.com> <20231119170714.775270-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 0270531a982f..7a25fe4c8cc3 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 Sun Nov 19 17:07:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Grant Erickson X-Patchwork-Id: 13460625 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 B367918C10 for ; Sun, 19 Nov 2023 17:07:28 +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 E52E673202 for ; Sun, 19 Nov 2023 12:07:21 -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 9FE0873219 for ; Sun, 19 Nov 2023 12:07:21 -0500 (EST) From: Grant Erickson To: connman@lists.linux.dev Subject: [PATCH v2 13/17] gweb: Factor out GWeb destruction into 'g_web_free'. Date: Sun, 19 Nov 2023 09:07:09 -0800 Message-ID: <20231119170714.775270-14-gerickson@nuovations.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231119170714.775270-1-gerickson@nuovations.com> References: <20231116010259.628527-1-gerickson@nuovations.com> <20231119170714.775270-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 7a25fe4c8cc3..ce49e8d3dfc1 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 Sun Nov 19 17:07:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Grant Erickson X-Patchwork-Id: 13460631 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 01E4418C30 for ; Sun, 19 Nov 2023 17:07:28 +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 5D2CC73204 for ; Sun, 19 Nov 2023 12:07:22 -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 16D637321D for ; Sun, 19 Nov 2023 12:07:22 -0500 (EST) From: Grant Erickson To: connman@lists.linux.dev Subject: [PATCH v2 14/17] wispr: Add '__connman_wispr_cancel' interface. Date: Sun, 19 Nov 2023 09:07:10 -0800 Message-ID: <20231119170714.775270-15-gerickson@nuovations.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231119170714.775270-1-gerickson@nuovations.com> References: <20231116010259.628527-1-gerickson@nuovations.com> <20231119170714.775270-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 396891c98153..9f995060a6c0 100644 --- a/src/wispr.c +++ b/src/wispr.c @@ -1341,6 +1341,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 Sun Nov 19 17:07:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Grant Erickson X-Patchwork-Id: 13460628 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 9DC9B14291 for ; Sun, 19 Nov 2023 17:07:29 +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 C9EBB73207 for ; Sun, 19 Nov 2023 12:07:22 -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 82E847321A for ; Sun, 19 Nov 2023 12:07:22 -0500 (EST) From: Grant Erickson To: connman@lists.linux.dev Subject: [PATCH v2 15/17] wispr: Add documentation to '__connman_wispr_cancel'. Date: Sun, 19 Nov 2023 09:07:11 -0800 Message-ID: <20231119170714.775270-16-gerickson@nuovations.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231119170714.775270-1-gerickson@nuovations.com> References: <20231116010259.628527-1-gerickson@nuovations.com> <20231119170714.775270-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 9f995060a6c0..3837a87811a9 100644 --- a/src/wispr.c +++ b/src/wispr.c @@ -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) { From patchwork Sun Nov 19 17:07:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Grant Erickson X-Patchwork-Id: 13460629 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 9F2931804F for ; Sun, 19 Nov 2023 17:07:29 +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 4DE1073206 for ; Sun, 19 Nov 2023 12:07:23 -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 EDD9D73222 for ; Sun, 19 Nov 2023 12:07:22 -0500 (EST) From: Grant Erickson To: connman@lists.linux.dev Subject: [PATCH v2 16/17] wispr: Avoid double-free in 'free_wispr_routes'. Date: Sun, 19 Nov 2023 09:07:12 -0800 Message-ID: <20231119170714.775270-17-gerickson@nuovations.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231119170714.775270-1-gerickson@nuovations.com> References: <20231116010259.628527-1-gerickson@nuovations.com> <20231119170714.775270-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 3837a87811a9..9cd1e7db501d 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 Sun Nov 19 17:07:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Grant Erickson X-Patchwork-Id: 13460630 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 203841865E for ; Sun, 19 Nov 2023 17:07:29 +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 B463D73208 for ; Sun, 19 Nov 2023 12:07:23 -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 6E7E873224 for ; Sun, 19 Nov 2023 12:07:23 -0500 (EST) From: Grant Erickson To: connman@lists.linux.dev Subject: [PATCH v2 17/17] service: Leverage '__connman_wispr_cancel'. Date: Sun, 19 Nov 2023 09:07:13 -0800 Message-ID: <20231119170714.775270-18-gerickson@nuovations.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231119170714.775270-1-gerickson@nuovations.com> References: <20231116010259.628527-1-gerickson@nuovations.com> <20231119170714.775270-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;