From patchwork Sat Nov 11 18:58:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Grant Erickson X-Patchwork-Id: 13453163 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 0A7131B28C for ; Sat, 11 Nov 2023 18:58:37 +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 147B27310B for ; Sat, 11 Nov 2023 13:58:37 -0500 (EST) Received: from [IPv6:2601:647:5a00:15c1:34e1:cabf:fe5f:4f18] (unknown [IPv6:2601:647:5a00:15c1:34e1:cabf:fe5f:4f18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mohas.pair.com (Postfix) with ESMTPSA id D31717313E for ; Sat, 11 Nov 2023 13:58:36 -0500 (EST) From: Grant Erickson Precedence: bulk X-Mailing-List: connman@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 (Mac OS X Mail 13.4 \(3608.120.23.2.4\)) Subject: [PATCH 1/8] gweb: Add TCP connect timeout member and getter/setter. Date: Sat, 11 Nov 2023 10:58:35 -0800 References: <7931960F-4A3F-448E-BDDE-773E48A1789B@nuovations.com> To: connman@lists.linux.dev In-Reply-To: <7931960F-4A3F-448E-BDDE-773E48A1789B@nuovations.com> Message-Id: X-Mailer: Apple Mail (2.3608.120.23.2.4) X-Scanned-By: mailmunge 3.11 on 209.68.5.112 This adds a TCP connect timeout member, getter, and setter. Collectively, these manage the TCP connection timeout, in milliseconds, for a specified GWeb object. 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. --- gweb/gweb.c | 24 ++++++++++++++++++++++++ gweb/gweb.h | 3 +++ 2 files changed, 27 insertions(+) diff --git a/gweb/gweb.c b/gweb/gweb.c index 65c075d2128e..bc0aa7a801a6 100644 --- a/gweb/gweb.c +++ b/gweb/gweb.c @@ -124,6 +124,7 @@ struct _GWeb { char *user_agent_profile; char *http_version; bool close_connection; + guint connect_timeout_ms; GWebDebugFunc debug_func; gpointer debug_data; @@ -445,6 +446,29 @@ bool g_web_get_close_connection(GWeb *web) return web->close_connection; } +void g_web_set_connect_timeout(GWeb *web, guint timeout_ms) +{ + if (!web) + return; + + debug(web, "timeout %ums", timeout_ms); + + web->connect_timeout_ms = timeout_ms; +} + +guint g_web_get_connect_timeout(const GWeb *web) +{ + guint timeout_ms = 0; + + if (!web) + goto done; + + timeout_ms = web->connect_timeout_ms; + +done: + return timeout_ms; +} + static inline void call_result_func(struct web_session *session, guint16 status) { diff --git a/gweb/gweb.h b/gweb/gweb.h index 8a6304e3014f..3c50979cfd0a 100644 --- a/gweb/gweb.h +++ b/gweb/gweb.h @@ -142,6 +142,9 @@ bool g_web_set_ua_profile(GWeb *web, const char *profile); bool g_web_set_http_version(GWeb *web, const char *version); +void g_web_set_connect_timeout(GWeb *web, guint timeout_ms); +guint g_web_get_connect_timeout(const GWeb *web); + void g_web_set_close_connection(GWeb *web, bool enabled); bool g_web_get_close_connection(GWeb *web); From patchwork Sat Nov 11 18:58: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: 13453164 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 623561C29E for ; Sat, 11 Nov 2023 18:58:57 +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 1FE28730FE for ; Sat, 11 Nov 2023 13:58:56 -0500 (EST) Received: from [IPv6:2601:647:5a00:15c1:34e1:cabf:fe5f:4f18] (unknown [IPv6:2601:647:5a00:15c1:34e1:cabf:fe5f:4f18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mohas.pair.com (Postfix) with ESMTPSA id E01F47313B for ; Sat, 11 Nov 2023 13:58:55 -0500 (EST) From: Grant Erickson Precedence: bulk X-Mailing-List: connman@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 (Mac OS X Mail 13.4 \(3608.120.23.2.4\)) Subject: [PATCH 2/8] gweb: Factor out session transport closure. Date: Sat, 11 Nov 2023 10:58:55 -0800 References: <7931960F-4A3F-448E-BDDE-773E48A1789B@nuovations.com> To: connman@lists.linux.dev In-Reply-To: <7931960F-4A3F-448E-BDDE-773E48A1789B@nuovations.com> Message-Id: X-Mailer: Apple Mail (2.3608.120.23.2.4) X-Scanned-By: mailmunge 3.11 on 209.68.5.112 This factors out the three actions undertake to close a GWeb session TCP tranport into a function, 'close_session_transport', that can be reused both at object destruction time, when the reference count reaches zero, but also when a TCP connection timeout occurs and the connection needs to be aborted. --- gweb/gweb.c | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/gweb/gweb.c b/gweb/gweb.c index bc0aa7a801a6..5f09cb3a99cf 100644 --- a/gweb/gweb.c +++ b/gweb/gweb.c @@ -154,6 +154,29 @@ static void _debug(GWeb *web, const char *file, const char *caller, va_end(ap); } +static void close_session_transport(struct web_session *session) +{ + if (!session) + return; + + debug(session->web, "closing session transport"); + + if (session->transport_watch > 0) { + g_source_remove(session->transport_watch); + session->transport_watch = 0; + } + + if (session->send_watch > 0) { + g_source_remove(session->send_watch); + session->send_watch = 0; + } + + if (session->transport_channel) { + g_io_channel_unref(session->transport_channel); + session->transport_channel = NULL; + } +} + static void free_session(struct web_session *session) { GWeb *web; @@ -171,14 +194,7 @@ static void free_session(struct web_session *session) if (session->resolv_action > 0) g_resolv_cancel_lookup(web->resolv, session->resolv_action); - if (session->transport_watch > 0) - g_source_remove(session->transport_watch); - - if (session->send_watch > 0) - g_source_remove(session->send_watch); - - if (session->transport_channel) - g_io_channel_unref(session->transport_channel); + close_session_transport(session); g_free(session->result.last_key); From patchwork Sat Nov 11 18:59:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Grant Erickson X-Patchwork-Id: 13453165 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 4255F1B28C for ; Sat, 11 Nov 2023 18:59:16 +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 A8B5B730CE for ; Sat, 11 Nov 2023 13:59:15 -0500 (EST) Received: from [IPv6:2601:647:5a00:15c1:34e1:cabf:fe5f:4f18] (unknown [IPv6:2601:647:5a00:15c1:34e1:cabf:fe5f:4f18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mohas.pair.com (Postfix) with ESMTPSA id 7386773108 for ; Sat, 11 Nov 2023 13:59:15 -0500 (EST) From: Grant Erickson Precedence: bulk X-Mailing-List: connman@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 (Mac OS X Mail 13.4 \(3608.120.23.2.4\)) Subject: [PATCH 3/8] gweb: Leverage TCP connect timeout. Date: Sat, 11 Nov 2023 10:59:15 -0800 References: <7931960F-4A3F-448E-BDDE-773E48A1789B@nuovations.com> To: connman@lists.linux.dev In-Reply-To: <7931960F-4A3F-448E-BDDE-773E48A1789B@nuovations.com> Message-Id: <13557DEE-684A-4575-B186-47F3D8069C1B@nuovations.com> X-Mailer: Apple Mail (2.3608.120.23.2.4) X-Scanned-By: mailmunge 3.11 on 209.68.5.112 This leverages the GWeb TCP connect timeout member and getter and adds a new GLib TCP connect timeout identifier to the GWeb session object. If the GWeb TCP connect timeout is greater than zero, a GLib connection timeout timer and callback are added to the session such that, when they expire, the in flight TCP connection is aborted and the session closure function invoked with 'GWEB_HTTP_STATUS_CODE_REQUEST_TIMEOUT'. A TCP connect timeout of zero ('0') indicates that no explicit connection timeout will be used and no timer or callback added to the session, leaving the timeout to the underlying operating system and its network stack. --- gweb/gweb.c | 99 +++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 77 insertions(+), 22 deletions(-) diff --git a/gweb/gweb.c b/gweb/gweb.c index 5f09cb3a99cf..584f0106c5ee 100644 --- a/gweb/gweb.c +++ b/gweb/gweb.c @@ -75,6 +75,7 @@ struct web_session { char *content_type; GIOChannel *transport_channel; + guint connect_timeout; guint transport_watch; guint send_watch; @@ -133,6 +134,8 @@ struct _GWeb { #define debug(web, format, arg...) \ _debug(web, __FILE__, __func__, format, ## arg) +static void close_session_transport(struct web_session *session); + static void _debug(GWeb *web, const char *file, const char *caller, const char *format, ...) { @@ -154,6 +157,70 @@ static void _debug(GWeb *web, const char *file, const char *caller, va_end(ap); } +static inline void call_result_func(struct web_session *session, guint16 status) +{ + + if (!session->result_func) + return; + + if (status != GWEB_HTTP_STATUS_CODE_UNKNOWN) + session->result.status = status; + + session->result_func(&session->result, session->user_data); + +} + +static inline void call_route_func(struct web_session *session) +{ + if (session->route_func) + session->route_func(session->address, session->addr->ai_family, + session->web->index, session->user_data); +} + +static gboolean connect_timeout_cb(gpointer user_data) +{ + struct web_session *session = user_data; + + debug(session->web, "session %p connect timeout after %ums", + session, g_web_get_connect_timeout(session->web)); + + session->connect_timeout = 0; + + close_session_transport(session); + + session->result.buffer = NULL; + session->result.length = 0; + + call_result_func(session, GWEB_HTTP_STATUS_CODE_REQUEST_TIMEOUT); + + return G_SOURCE_REMOVE; +} + +static void add_connect_timeout(struct web_session *session, + guint timeout_ms) +{ + if (!session || !timeout_ms) + return; + + debug(session->web, "add connect timeout %u ms", timeout_ms); + + session->connect_timeout = g_timeout_add(timeout_ms, + connect_timeout_cb, session); +} + +static void cancel_connect_timeout(struct web_session *session) +{ + if (!session) + return; + + if (session->connect_timeout > 0) { + g_source_remove(session->connect_timeout); + session->connect_timeout = 0; + + debug(session->web, "cancelled connect timeout"); + } +} + static void close_session_transport(struct web_session *session) { if (!session) @@ -194,6 +261,8 @@ static void free_session(struct web_session *session) if (session->resolv_action > 0) g_resolv_cancel_lookup(web->resolv, session->resolv_action); + cancel_connect_timeout(session); + close_session_transport(session); g_free(session->result.last_key); @@ -485,26 +554,6 @@ done: return timeout_ms; } -static inline void call_result_func(struct web_session *session, guint16 status) -{ - - if (!session->result_func) - return; - - if (status != GWEB_HTTP_STATUS_CODE_UNKNOWN) - session->result.status = status; - - session->result_func(&session->result, session->user_data); - -} - -static inline void call_route_func(struct web_session *session) -{ - if (session->route_func) - session->route_func(session->address, session->addr->ai_family, - session->web->index, session->user_data); -} - static bool process_send_buffer(struct web_session *session) { GString *buf; @@ -915,6 +964,8 @@ static gboolean received_data(GIOChannel *channel, GIOCondition cond, gsize bytes_read; GIOStatus status; + cancel_connect_timeout(session); + if (cond & (G_IO_NVAL | G_IO_ERR | G_IO_HUP)) { session->transport_watch = 0; session->result.buffer = NULL; @@ -1075,7 +1126,8 @@ static inline int bind_socket(int sk, int index, int family) return err; } -static int connect_session_transport(struct web_session *session) +static int connect_session_transport(struct web_session *session, + guint connect_timeout_ms) { GIOFlags flags; int sk; @@ -1133,6 +1185,8 @@ static int connect_session_transport(struct web_session *session) G_IO_OUT | G_IO_HUP | G_IO_NVAL | G_IO_ERR, send_data, session); + add_connect_timeout(session, connect_timeout_ms); + return 0; } @@ -1140,7 +1194,8 @@ static int create_transport(struct web_session *session) { int err; - err = connect_session_transport(session); + err = connect_session_transport(session, + g_web_get_connect_timeout(session->web)); if (err < 0) return err; From patchwork Sat Nov 11 18:59:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Grant Erickson X-Patchwork-Id: 13453166 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 2E9791B28C for ; Sat, 11 Nov 2023 18:59:37 +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 84BBD730FB for ; Sat, 11 Nov 2023 13:59:36 -0500 (EST) Received: from [IPv6:2601:647:5a00:15c1:34e1:cabf:fe5f:4f18] (unknown [IPv6:2601:647:5a00:15c1:34e1:cabf:fe5f:4f18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mohas.pair.com (Postfix) with ESMTPSA id 3B3E573122 for ; Sat, 11 Nov 2023 13:59:36 -0500 (EST) From: Grant Erickson Precedence: bulk X-Mailing-List: connman@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 (Mac OS X Mail 13.4 \(3608.120.23.2.4\)) Subject: [PATCH 4/8] gweb: Add documentation to TCP connect timeout-related functions. Date: Sat, 11 Nov 2023 10:59:36 -0800 References: <7931960F-4A3F-448E-BDDE-773E48A1789B@nuovations.com> To: connman@lists.linux.dev In-Reply-To: <7931960F-4A3F-448E-BDDE-773E48A1789B@nuovations.com> Message-Id: <39D91814-3E36-4DD1-A16A-C8ED4C637103@nuovations.com> X-Mailer: Apple Mail (2.3608.120.23.2.4) X-Scanned-By: mailmunge 3.11 on 209.68.5.112 This adds function documentation to the following TCP connect timeout- related functions: * connect_timeout_cb * add_connect_timeout * cancel_connect_timeout * close_session_transport * connect_session_transport * g_web_set_connect_timeout * g_web_get_connect_timeout --- gweb/gweb.c | 151 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 151 insertions(+) diff --git a/gweb/gweb.c b/gweb/gweb.c index 584f0106c5ee..1463b588d411 100644 --- a/gweb/gweb.c +++ b/gweb/gweb.c @@ -177,6 +177,27 @@ static inline void call_route_func(struct web_session *session) session->web->index, session->user_data); } +/** + * @brief + * Handle a TCP connection timeout. + * + * This callback handles a TCP connection timeout for a GWeb + * connection. The session transport is closed and the GWeb + * transaction is terminated with + * #GWEB_HTTP_STATUS_CODE_REQUEST_TIMEOUT status. + * + * param[in,out] user_data A pointer to the mutable GWeb session + * for which the TCP connection timed out. + * + * @returns + * G_SOURCE_REMOVE (that is, FALSE) unconditionally, indicating + * that the timeout source that triggered this callback should be + * removed on callback completion. + * + * @sa add_connect_timeout + * @sa cancel_connect_timeout + * + */ static gboolean connect_timeout_cb(gpointer user_data) { struct web_session *session = user_data; @@ -196,6 +217,30 @@ static gboolean connect_timeout_cb(gpointer user_data) return G_SOURCE_REMOVE; } +/** + * @brief + * Add a TCP connection timeout. + * + * This attempts to add TCP connection timeout and callback to the + * specified GWeb session. The timeout is successfully added if @a + * session is non-null and @a timeout_ms is greater than zero. + * + * @param[in,out] session A pointer to the mutable GWeb session + * to add the TCP connection timeout + * callback to. + * param[in] 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. + * + * @sa cancel_connect_timeout + * @sa connect_timeout_cb + * + */ static void add_connect_timeout(struct web_session *session, guint timeout_ms) { @@ -208,6 +253,22 @@ static void add_connect_timeout(struct web_session *session, connect_timeout_cb, session); } +/** + * @brief + * Cancel a TCP connection timeout. + * + * This attempts to cancel a TCP connection timeout and callback from + * the specified GWeb session. The timeout is successfully cancelled + * if @a session is non-null and its associated connect timeout + * identifier is valid. + * + * @param[in,out] session A pointer to the mutable GWeb session + * on which to cancel the TCP connection + * timeout. + * + * @sa add_connect_timeout + * + */ static void cancel_connect_timeout(struct web_session *session) { if (!session) @@ -221,6 +282,21 @@ static void cancel_connect_timeout(struct web_session *session) } } +/** + * @brief + * Close the TCP transport a GWeb sesssion. + * + * This closes the TCP transport associated with the specified GWeb + * session, removing its transport and send watches and releasing the + * reference to the transport channel. + * + * @param[in,out] session A pointer to the mutable GWeb session + * for which to close the session + * transport. + * + * @sa connect_session_transport + * + */ static void close_session_transport(struct web_session *session) { if (!session) @@ -531,6 +607,28 @@ bool g_web_get_close_connection(GWeb *web) return web->close_connection; } +/** + * @brief + * Set the TCP connection timeout. + * + * This sets the TCP connection timeout, in milliseconds, for the + * specified GWeb object. + * + * param[in,out] web A pointer to the mutable GWeb object + * for which the TCP connection timeout is + * to be set. + * param[in] 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. + * + * @sa g_web_get_connect_timeout + * + */ void g_web_set_connect_timeout(GWeb *web, guint timeout_ms) { if (!web) @@ -541,6 +639,26 @@ void g_web_set_connect_timeout(GWeb *web, guint timeout_ms) web->connect_timeout_ms = timeout_ms; } +/** + * @brief + * Set the TCP connection timeout. + * + * This sets the TCP connection timeout, in milliseconds, for the + * specified GWeb object. + * + * param[in] web A pointer to the immutable GWeb object + * for which the TCP connection timeout is + * to be returned. + * + * @returns + * The TCP connection timeout, in milliseconds. A value of zero + * ('0') indicates that no explicit connection timeout has been + * set, leaving the timeout to the underlying operating system and + * its network stack. + * + * @sa g_web_set_connect_timeout + * + */ guint g_web_get_connect_timeout(const GWeb *web) { guint timeout_ms = 0; @@ -1126,6 +1244,39 @@ static inline int bind_socket(int sk, int index, int family) return err; } +/** + * @brief + * Establish TCP connection for a GWeb session. + * + * This attempts to establish a TCP connection for the specified GWeb + * session with the session-specified address family, peer address, + * and bound network interface. + * + * @param[in,out] session A pointer to the mutable GWeb + * session for which to establish + * the session transport. + * 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 successful. + * @retval -EIO If a socket could not be created for the specified + * session address family, the socket could not be + * bound to the specified session network + * interface, or the socket could not connect to + * the specified session peer address. + * @retval -ENOMEM If a GLib transport channel could not be created. + * + * @sa close_session_transport + * + */ static int connect_session_transport(struct web_session *session, guint connect_timeout_ms) { From patchwork Sat Nov 11 18:59: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: 13453167 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 065131C291 for ; Sat, 11 Nov 2023 18:59:55 +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 35CBB730F3 for ; Sat, 11 Nov 2023 13:59:55 -0500 (EST) Received: from [IPv6:2601:647:5a00:15c1:34e1:cabf:fe5f:4f18] (unknown [IPv6:2601:647:5a00:15c1:34e1:cabf:fe5f:4f18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mohas.pair.com (Postfix) with ESMTPSA id F32DE7310B for ; Sat, 11 Nov 2023 13:59:54 -0500 (EST) From: Grant Erickson Precedence: bulk X-Mailing-List: connman@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 (Mac OS X Mail 13.4 \(3608.120.23.2.4\)) Subject: [PATCH 5/8] main: Introduce the 'OnlineCheckConnectTimeout' setting. Date: Sat, 11 Nov 2023 10:59:54 -0800 References: <7931960F-4A3F-448E-BDDE-773E48A1789B@nuovations.com> To: connman@lists.linux.dev In-Reply-To: <7931960F-4A3F-448E-BDDE-773E48A1789B@nuovations.com> Message-Id: <23685D88-4C18-4B9D-A011-44B0AEBEF953@nuovations.com> X-Mailer: Apple Mail (2.3608.120.23.2.4) X-Scanned-By: mailmunge 3.11 on 209.68.5.112 This introduces the 'OnlineCheckConnectTimeout' setting which is the time, in decimal seconds (for example, 12.3), to wait for a successful TCP connection to the host associated with "OnlineCheckIPv4URL" or "OnlineCheckIPv6URL". Connections that take longer than this will be aborted. The default value is zero ('0') which indicates that no explicit connection timeout will be used, leaving the timeout to the underlying operating system and network stack. --- src/main.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/main.c b/src/main.c index d6863e668b38..e9419a603eba 100644 --- a/src/main.c +++ b/src/main.c @@ -47,6 +47,7 @@ #define DEFAULT_ONLINE_CHECK_IPV4_URL "http://ipv4.connman.net/online/status.html" #define DEFAULT_ONLINE_CHECK_IPV6_URL "http://ipv6.connman.net/online/status.html" +#define DEFAULT_ONLINE_CHECK_CONNECT_TIMEOUT (0 * 1000) /* * We set the integer to 1 sec so that we have a chance to get * necessary IPv6 router advertisement messages that might have @@ -110,6 +111,7 @@ static struct { bool enable_online_to_ready_transition; char *online_check_ipv4_url; char *online_check_ipv6_url; + unsigned int online_check_connect_timeout_ms; unsigned int online_check_initial_interval; unsigned int online_check_max_interval; char *online_check_interval_style; @@ -141,6 +143,7 @@ static struct { .enable_online_to_ready_transition = false, .online_check_ipv4_url = NULL, .online_check_ipv6_url = NULL, + .online_check_connect_timeout_ms = DEFAULT_ONLINE_CHECK_CONNECT_TIMEOUT, .online_check_initial_interval = DEFAULT_ONLINE_CHECK_INITIAL_INTERVAL, .online_check_max_interval = DEFAULT_ONLINE_CHECK_MAX_INTERVAL, .online_check_interval_style = NULL, @@ -172,6 +175,7 @@ static struct { #define CONF_ENABLE_ONLINE_TO_READY_TRANSITION "EnableOnlineToReadyTransition" #define CONF_ONLINE_CHECK_IPV4_URL "OnlineCheckIPv4URL" #define CONF_ONLINE_CHECK_IPV6_URL "OnlineCheckIPv6URL" +#define CONF_ONLINE_CHECK_CONNECT_TIMEOUT "OnlineCheckConnectTimeout" #define CONF_ONLINE_CHECK_INITIAL_INTERVAL "OnlineCheckInitialInterval" #define CONF_ONLINE_CHECK_MAX_INTERVAL "OnlineCheckMaxInterval" #define CONF_ONLINE_CHECK_INTERVAL_STYLE "OnlineCheckIntervalStyle" @@ -204,6 +208,7 @@ static const char *supported_options[] = { CONF_ENABLE_ONLINE_TO_READY_TRANSITION, CONF_ONLINE_CHECK_IPV4_URL, CONF_ONLINE_CHECK_IPV6_URL, + CONF_ONLINE_CHECK_CONNECT_TIMEOUT, CONF_ONLINE_CHECK_INITIAL_INTERVAL, CONF_ONLINE_CHECK_MAX_INTERVAL, CONF_ONLINE_CHECK_INTERVAL_STYLE, @@ -338,6 +343,7 @@ static void parse_config(GKeyFile *config) char *string; gsize len; int integer; + double real; if (!config) { connman_settings.auto_connect = @@ -530,6 +536,27 @@ static void parse_config(GKeyFile *config) g_clear_error(&error); + /* OnlineCheckConnecTimeout */ + + real = g_key_file_get_double(config, "General", + CONF_ONLINE_CHECK_CONNECT_TIMEOUT, &error); + if (!error) { + if (real < 0) { + connman_warn("Incorrect online check connect timeout %f", + real); + connman_settings.online_check_connect_timeout_ms = + DEFAULT_ONLINE_CHECK_CONNECT_TIMEOUT; + } else + connman_settings.online_check_connect_timeout_ms = + real * 1000; + } + + if (connman_settings.online_check_connect_timeout_ms) + connman_info("Online check connect timeout %ums", + connman_settings.online_check_connect_timeout_ms); + + g_clear_error(&error); + string = __connman_config_get_string(config, "General", CONF_ONLINE_CHECK_IPV4_URL, &error); if (!error) @@ -885,6 +912,9 @@ bool connman_setting_get_bool(const char *key) unsigned int connman_setting_get_uint(const char *key) { + if (g_str_equal(key, CONF_ONLINE_CHECK_CONNECT_TIMEOUT)) + return connman_settings.online_check_connect_timeout_ms; + if (g_str_equal(key, CONF_ONLINE_CHECK_INITIAL_INTERVAL)) return connman_settings.online_check_initial_interval; From patchwork Sat Nov 11 19:00:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Grant Erickson X-Patchwork-Id: 13453168 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 0676E1B28C for ; Sat, 11 Nov 2023 19:00: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 1C2FC730FE for ; Sat, 11 Nov 2023 14:00:26 -0500 (EST) Received: from [IPv6:2601:647:5a00:15c1:34e1:cabf:fe5f:4f18] (unknown [IPv6:2601:647:5a00:15c1:34e1:cabf:fe5f:4f18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mohas.pair.com (Postfix) with ESMTPSA id D9ADD73122 for ; Sat, 11 Nov 2023 14:00:25 -0500 (EST) From: Grant Erickson Precedence: bulk X-Mailing-List: connman@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 (Mac OS X Mail 13.4 \(3608.120.23.2.4\)) Subject: [PATCH 6/8] Leverage GWeb connect timeout and 'OnlineCheckConnectTimeout'. Date: Sat, 11 Nov 2023 11:00:25 -0800 References: <7931960F-4A3F-448E-BDDE-773E48A1789B@nuovations.com> To: connman@lists.linux.dev In-Reply-To: <7931960F-4A3F-448E-BDDE-773E48A1789B@nuovations.com> Message-Id: X-Mailer: Apple Mail (2.3608.120.23.2.4) X-Scanned-By: mailmunge 3.11 on 209.68.5.112 This leverages both the GWeb TCP connect timeout setter and the newly- added 'OnlineCheckConnectTimeout' setting to support TCP connect timeouts different from the underlying operating system and network stack when so configured. --- src/connman.h | 1 + src/service.c | 10 ++++++++-- src/wispr.c | 14 ++++++++++---- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/connman.h b/src/connman.h index d3f2d0139f91..143a087701d8 100644 --- a/src/connman.h +++ b/src/connman.h @@ -531,6 +531,7 @@ int __connman_wispr_init(void); void __connman_wispr_cleanup(void); int __connman_wispr_start(struct connman_service *service, enum connman_ipconfig_type type, + guint connect_timeout_ms, __connman_wispr_cb_t callback); void __connman_wispr_stop(struct connman_service *service); diff --git a/src/service.c b/src/service.c index 81a1bebdc14b..075f3fba5abe 100644 --- a/src/service.c +++ b/src/service.c @@ -58,6 +58,7 @@ static unsigned int vpn_autoconnect_id = 0; static struct connman_service *current_default = NULL; static bool services_dirty = false; static bool enable_online_to_ready_transition = false; +static unsigned int online_check_connect_timeout_ms = 0; static unsigned int online_check_initial_interval = 0; static unsigned int online_check_max_interval = 0; static const char *online_check_timeout_interval_style = NULL; @@ -1700,7 +1701,8 @@ static void redo_wispr(struct connman_service *service, service, connman_service_get_identifier(service), type, __connman_ipconfig_type2string(type)); - __connman_wispr_start(service, type, complete_online_check); + __connman_wispr_start(service, type, + online_check_connect_timeout_ms, complete_online_check); // Release the reference to the service taken when // g_timeout_add_seconds was invoked with the callback @@ -2011,7 +2013,8 @@ void __connman_service_wispr_start(struct connman_service *service, service->online_check_interval_ipv6 = online_check_initial_interval; - __connman_wispr_start(service, type, complete_online_check); + __connman_wispr_start(service, type, + online_check_connect_timeout_ms, complete_online_check); } static void address_updated(struct connman_service *service, @@ -8496,6 +8499,9 @@ int __connman_service_init(void) else online_check_timeout_compute_func = online_check_timeout_compute_geometric; + online_check_connect_timeout_ms = + connman_setting_get_uint("OnlineCheckConnectTimeout"); + online_check_initial_interval = connman_setting_get_uint("OnlineCheckInitialInterval"); online_check_max_interval = diff --git a/src/wispr.c b/src/wispr.c index 8a5bbdcfe3d8..8618b5158b04 100644 --- a/src/wispr.c +++ b/src/wispr.c @@ -861,6 +861,7 @@ static bool wispr_portal_web_result(GWebResult *result, gpointer user_data) goto done; case GWEB_HTTP_STATUS_CODE_BAD_REQUEST: case GWEB_HTTP_STATUS_CODE_NOT_FOUND: + case GWEB_HTTP_STATUS_CODE_REQUEST_TIMEOUT: wp_context->cb(wp_context->service, wp_context->type, false); break; @@ -967,7 +968,8 @@ static gboolean no_proxy_callback(gpointer user_data) return FALSE; } -static int wispr_portal_detect(struct connman_wispr_portal_context *wp_context) +static int wispr_portal_detect(struct connman_wispr_portal_context *wp_context, + guint connect_timeout_ms) { enum connman_service_proxy_method proxy_method; char *interface = NULL; @@ -1012,6 +1014,8 @@ static int wispr_portal_detect(struct connman_wispr_portal_context *wp_context) if (getenv("CONNMAN_WEB_DEBUG")) g_web_set_debug(wp_context->web, web_debug, "WEB"); + g_web_set_connect_timeout(wp_context->web, connect_timeout_ms); + if (wp_context->type == CONNMAN_IPCONFIG_TYPE_IPV4) { g_web_set_address_family(wp_context->web, AF_INET); wp_context->status_url = online_check_ipv4_url; @@ -1069,15 +1073,17 @@ done: int __connman_wispr_start(struct connman_service *service, enum connman_ipconfig_type type, + guint connect_timeout_ms, __connman_wispr_cb_t callback) { struct connman_wispr_portal_context *wp_context = NULL; struct connman_wispr_portal *wispr_portal = NULL; int index, err; - DBG("service %p (%s) type %d (%s) callback %p", + DBG("service %p (%s) type %d (%s) connect_timeout %ums callback %p", service, connman_service_get_identifier(service), - type, __connman_ipconfig_type2string(type), callback); + type, __connman_ipconfig_type2string(type), + connect_timeout_ms, callback); if (!wispr_portal_hash || !callback) return -EINVAL; @@ -1137,7 +1143,7 @@ int __connman_wispr_start(struct connman_service *service, else wispr_portal->ipv6_context = wp_context; - err = wispr_portal_detect(wp_context); + err = wispr_portal_detect(wp_context, connect_timeout_ms); if (err) goto free_wp; return 0; From patchwork Sat Nov 11 19:00: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: 13453169 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 D6F5D19BB2 for ; Sat, 11 Nov 2023 19:00:44 +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 3B042730CE for ; Sat, 11 Nov 2023 14:00:44 -0500 (EST) Received: from [IPv6:2601:647:5a00:15c1:34e1:cabf:fe5f:4f18] (unknown [IPv6:2601:647:5a00:15c1:34e1:cabf:fe5f:4f18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mohas.pair.com (Postfix) with ESMTPSA id 07C9973108 for ; Sat, 11 Nov 2023 14:00:43 -0500 (EST) From: Grant Erickson Precedence: bulk X-Mailing-List: connman@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 (Mac OS X Mail 13.4 \(3608.120.23.2.4\)) Subject: [PATCH 7/8] Add documentation for 'OnlineCheckConnectTimeout'. Date: Sat, 11 Nov 2023 11:00:43 -0800 References: <7931960F-4A3F-448E-BDDE-773E48A1789B@nuovations.com> To: connman@lists.linux.dev In-Reply-To: <7931960F-4A3F-448E-BDDE-773E48A1789B@nuovations.com> Message-Id: X-Mailer: Apple Mail (2.3608.120.23.2.4) X-Scanned-By: mailmunge 3.11 on 209.68.5.112 This adds documentation for the 'OnlineCheckConnectTimeout' configuration key. --- doc/connman.conf.5.in | 9 +++++++++ src/main.conf | 9 +++++++++ 2 files changed, 18 insertions(+) diff --git a/doc/connman.conf.5.in b/doc/connman.conf.5.in index 75669abc5bcd..9049d7037623 100644 --- a/doc/connman.conf.5.in +++ b/doc/connman.conf.5.in @@ -174,6 +174,15 @@ Please refer to the README for more detailed information. Default values are http://ipv4.connman.net/online/status.html and http://ipv6.connman.net/online/status.html respectively. .TP +.BI OnlineCheckConnectTimeout= secs[.milliseconds] +The time, in decimal seconds (for example, 12.3), to wait for a +successful TCP connection to the host associated with +\fBOnlineCheckIPv4URL\fR or \fBOnlineCheckIPv6URL\fR (see above). Connections +that take longer than \fBOnlineCheckConnectTimeout\fR will be aborted. The +default value is zero ('0') which indicates that no explicit +connection timeout will be used, leaving the timeout to the underlying +operating system and network stack. +.TP .BI OnlineCheckInitialInterval= secs, OnlineCheckMaxInterval= secs Range of intervals between two online check requests. Please refer to the README for more detailed information. diff --git a/src/main.conf b/src/main.conf index ef1939cf5b6f..ddcb3564c246 100644 --- a/src/main.conf +++ b/src/main.conf @@ -132,6 +132,15 @@ # OnlineCheckIPv4URL= http://ipv4.connman.net/online/status.html # OnlineCheckIPv6URL= http://ipv6.connman.net/online/status.html +# The time, in decimal seconds (for example, 12.3), to wait for a +# successful TCP connection to the host associated with +# "OnlineCheckIPv4URL" or "OnlineCheckIPv6URL". Connections that take +# longer than "OnlineCheckConnectTimeout" will be aborted. The default +# value is zero ('0') which indicates that no explicit connection +# timeout will be used, leaving the timeout to the underlying operating +# system and network stack. +# OnlineCheckConnectTimeout=0 + # Range of intervals between two online check requests. # Please refer to the README for more detailed information. # Default values are 1 and 12 respectively. From patchwork Sat Nov 11 19:01: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: 13453170 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 0DA3119BB2 for ; Sat, 11 Nov 2023 19:01:04 +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 EE298730FB for ; Sat, 11 Nov 2023 14:01:03 -0500 (EST) Received: from [IPv6:2601:647:5a00:15c1:34e1:cabf:fe5f:4f18] (unknown [IPv6:2601:647:5a00:15c1:34e1:cabf:fe5f:4f18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mohas.pair.com (Postfix) with ESMTPSA id BA7DD7311A for ; Sat, 11 Nov 2023 14:01:03 -0500 (EST) From: Grant Erickson Precedence: bulk X-Mailing-List: connman@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 (Mac OS X Mail 13.4 \(3608.120.23.2.4\)) Subject: [PATCH 8/8] wispr: Add documentation to '__connman_wispr_start'. Date: Sat, 11 Nov 2023 11:01:03 -0800 References: <7931960F-4A3F-448E-BDDE-773E48A1789B@nuovations.com> To: connman@lists.linux.dev In-Reply-To: <7931960F-4A3F-448E-BDDE-773E48A1789B@nuovations.com> Message-Id: <38E5F8F5-2EB8-4FB4-A7CF-BA28054FE479@nuovations.com> X-Mailer: Apple Mail (2.3608.120.23.2.4) X-Scanned-By: mailmunge 3.11 on 209.68.5.112 This adds documentation to the '__connman_wispr_start' function. --- src/wispr.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/src/wispr.c b/src/wispr.c index 8618b5158b04..ab763d5bada0 100644 --- a/src/wispr.c +++ b/src/wispr.c @@ -1071,6 +1071,49 @@ done: return err; } +/** + * @brief + * Start a HTTP-based Internet reachability check for the specified + * network service IP configuration type. + * + * This attempts to start a HTTP-based Internet reachability check + * for the specified network service IP configuration type with the + * provided connection timeout and completion callback. + * + * @param[in,out] service A pointer to the mutable network + * service for which to start the + * reachability check. + * @param[in] type The IP configuration type for + * which the reachability check + * is to be started. + * 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. + * @param[in] callback The callback to be invoked when + * the reachability check + * terminates, either on failure + * or success. + * + * @retval 0 If successful. + * @retval -EINVAL If the reachability check subsystem is not + * properly initialized, @a callback is null, + * or if the network interface index associated + * with @a service is invalid. + * @retval -EOPNOTSUPP If a reachability check is not supported for + * the network service technology type. + * @retval -ENOMEM If resources could not be allocated for the + * reachability check. + * + * @sa __connman_wispr_stop + * + */ int __connman_wispr_start(struct connman_service *service, enum connman_ipconfig_type type, guint connect_timeout_ms,