From patchwork Wed Nov 29 19:20: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: 13473363 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 792EF5DF2C for ; Wed, 29 Nov 2023 19:21:09 +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 8F79573222 for ; Wed, 29 Nov 2023 14:21:08 -0500 (EST) Received: from localhost.localdomain (unknown [IPv6:2601:647:5a00:15c1:230d:b2c9:c388:f96b]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mohas.pair.com (Postfix) with ESMTPSA id 4689973232 for ; Wed, 29 Nov 2023 14:21:08 -0500 (EST) From: Grant Erickson To: connman@lists.linux.dev Subject: [PATCH v2 1/8] log: Refactor debugging preprocessor macros. Date: Wed, 29 Nov 2023 11:20:59 -0800 Message-ID: <20231129192106.1295868-2-gerickson@nuovations.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231129192106.1295868-1-gerickson@nuovations.com> References: <20231128230847.1224497-1-gerickson@nuovations.com> <20231129192106.1295868-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 refactors the debugging / debug log preprocessor-related macros. In particular, it: * Introduces CONNMAN_DEBUG_DESC_INSTANTIATE which declares and instantiates an instance of 'connman_debug_desc'. * Replaces CONNMAN_DEBUG_DEFINE with CONNMAN_DEBUG_ALIAS which declares and instantiates an alias (that is, asserts the CONNMAN_DEBUG_FLAG_ALIAS flag) instance of 'connmand_debug_desc', using CONNMAN_DEBUG_DESC_INSTANTIATE. * Redefines 'DBG' against 'CONNMAN_DEBUG_DESC_INSTANTIATE' with '__func__' as the function parameter. --- include/log.h | 28 +++++++++++++++++----------- src/log.c | 2 +- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/include/log.h b/include/log.h index 8b00e9dc979c..a9b0f17f392b 100644 --- a/include/log.h +++ b/include/log.h @@ -58,11 +58,17 @@ struct connman_debug_desc { unsigned int flags; } __attribute__((aligned(8))); -#define CONNMAN_DEBUG_DEFINE(name) \ - static struct connman_debug_desc __debug_alias_ ## name \ +#define CONNMAN_DEBUG_DESC_INSTANTIATE(symbol, _name, _file, _flags) \ + static struct connman_debug_desc symbol \ __attribute__((used, section("__debug"), aligned(8))) = { \ - #name, __FILE__, CONNMAN_DEBUG_FLAG_ALIAS \ - }; + .name = _name, .file = _file, .flags = _flags \ + } + +#define CONNMAN_DEBUG_ALIAS(suffix) \ + CONNMAN_DEBUG_DESC_INSTANTIATE(__debug_alias_##suffix, \ + #suffix, \ + __FILE__, \ + CONNMAN_DEBUG_FLAG_ALIAS) /** * DBG: @@ -73,13 +79,13 @@ struct connman_debug_desc { * name it is called in. */ #define DBG(fmt, arg...) do { \ - static struct connman_debug_desc __connman_debug_desc \ - __attribute__((used, section("__debug"), aligned(8))) = { \ - .file = __FILE__, .flags = CONNMAN_DEBUG_FLAG_DEFAULT, \ - }; \ - if (__connman_debug_desc.flags & CONNMAN_DEBUG_FLAG_PRINT) \ - connman_debug("%s:%s() " fmt, \ - __FILE__, __FUNCTION__ , ## arg); \ + CONNMAN_DEBUG_DESC_INSTANTIATE(__connman_debug_desc, \ + 0, \ + __FILE__, \ + CONNMAN_DEBUG_FLAG_DEFAULT); \ + if (__connman_debug_desc.flags & CONNMAN_DEBUG_FLAG_PRINT) \ + connman_debug("%s:%s() " fmt, \ + __FILE__, __func__, ##arg); \ } while (0) #ifdef __cplusplus diff --git a/src/log.c b/src/log.c index 554b046b07fa..f7483194b230 100644 --- a/src/log.c +++ b/src/log.c @@ -38,7 +38,7 @@ static const char *program_exec; static const char *program_path; /* This makes sure we always have a __debug section. */ -CONNMAN_DEBUG_DEFINE(dummy); +CONNMAN_DEBUG_ALIAS(dummy); /** * connman_info: From patchwork Wed Nov 29 19:21: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: 13473365 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 0D0CE5DF30 for ; Wed, 29 Nov 2023 19:21:09 +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 0703C7322A for ; Wed, 29 Nov 2023 14:21:09 -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 B403773248 for ; Wed, 29 Nov 2023 14:21:08 -0500 (EST) From: Grant Erickson To: connman@lists.linux.dev Subject: [PATCH v2 2/8] log: Document debugging preprocessor macros. Date: Wed, 29 Nov 2023 11:21:00 -0800 Message-ID: <20231129192106.1295868-3-gerickson@nuovations.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231129192106.1295868-1-gerickson@nuovations.com> References: <20231128230847.1224497-1-gerickson@nuovations.com> <20231129192106.1295868-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 following debugging- / debug logging-related data types and preprocessor macros: * connman_debug_desc * CONNMAN_DEBUG_DESC_INSTANTIATE * CONNMAN_DEBUG_ALIAS and expands the existing documentation for the 'DBG' preprocessor macro. --- include/log.h | 69 +++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 64 insertions(+), 5 deletions(-) diff --git a/include/log.h b/include/log.h index a9b0f17f392b..f4e1e3a10fde 100644 --- a/include/log.h +++ b/include/log.h @@ -49,6 +49,10 @@ void connman_debug(const char *format, ...) } \ } while (0) +/** + * Debug-level logging descriptor that may be used to control debug + * output on a per-file or -symbol basis. + */ struct connman_debug_desc { const char *name; const char *file; @@ -58,12 +62,45 @@ struct connman_debug_desc { unsigned int flags; } __attribute__((aligned(8))); +/** + * @def CONNMAN_DEBUG_DESC_INSTANTIATE(symbol, _name, _file, _flags) + * + * @brief + * Convenience preprocessor macro for declaring and instantiating an + * instance of #connmand_debug_desc. + * + * @param[in] symbol The name of the #connman_debug_desc instance + * to instantiate. + * @param[in] _name An optional pointer to an immutable null- + * terminated C string containing the name of + * the #connman_debug_desc- controlled symbol. + * @param[in] _file A pointer to an immutable null-terminated C + * string containing the name of the + * #connman_debug_desc-controlled source file. + * @param[in] _flags Flags that control the interpretation and + * behavior of the instantiated + * #connman_debug_desc instance. + * + */ #define CONNMAN_DEBUG_DESC_INSTANTIATE(symbol, _name, _file, _flags) \ static struct connman_debug_desc symbol \ __attribute__((used, section("__debug"), aligned(8))) = { \ .name = _name, .file = _file, .flags = _flags \ } +/** + * @def CONNMAN_DEBUG_ALIAS(suffix) + * + * @brief + * Convenience preprocessor macro for declaring and instantiating + * an alias (see #CONNMAN_DEBUG_FLAG_ALIAS) instance of + * #connmand_debug_desc. + * + * @param[in] suffix The suffix to concatenate to the name of the + * #connman_debug_desc alias instance to + * instantiate. + * + */ #define CONNMAN_DEBUG_ALIAS(suffix) \ CONNMAN_DEBUG_DESC_INSTANTIATE(__debug_alias_##suffix, \ #suffix, \ @@ -71,12 +108,34 @@ struct connman_debug_desc { CONNMAN_DEBUG_FLAG_ALIAS) /** - * DBG: - * @fmt: format string - * @arg...: list of arguments + * @def DBG(fmt, arg...) + * + * @brief + * Convenience preprocessor macro for declaring an instance of + * #connmand_debug_desc for controlling an invocation of + * #connman_debug with it that includes both the file and function + * name the macro was invoked in. + * + * This instantiates a scoped-instance of #connmand_debug_desc and + * then, if that instance has its #CONNMAN_DEBUG_FLAG_PRINT flag + * asserted, invokes a call to #connman_debug with the format: + * + * ":() ..." + * + * where is the preprocessor symbol __FILE__, is + * the preprocessor symbol __func__, is from @a fmt, and + * '...' is from @a 'arg...'. + * + * @param[in] fmt A pointer to an immutable null-terminated C + * string container the log message, consisting + * of a printf-style format string composed of + * zero or more output conversion directives. + * @param[in] arg... A variadic argument list, where each + * argument corresponds with its peer output + * conversion directive in @a fmt. + * + * @sa connman_debug * - * Simple macro around connman_debug() which also include the function - * name it is called in. */ #define DBG(fmt, arg...) do { \ CONNMAN_DEBUG_DESC_INSTANTIATE(__connman_debug_desc, \ From patchwork Wed Nov 29 19:21: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: 13473368 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 609A45DF34 for ; Wed, 29 Nov 2023 19:21:10 +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 736FC73233 for ; Wed, 29 Nov 2023 14:21:09 -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 2D2477324A for ; Wed, 29 Nov 2023 14:21:09 -0500 (EST) From: Grant Erickson To: connman@lists.linux.dev Subject: [PATCH v2 3/8] connection: Introduce and leverage 'gateway_{config,data}_debug'. Date: Wed, 29 Nov 2023 11:21:01 -0800 Message-ID: <20231129192106.1295868-4-gerickson@nuovations.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231129192106.1295868-1-gerickson@nuovations.com> References: <20231128230847.1224497-1-gerickson@nuovations.com> <20231129192106.1295868-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 introduces and leverages two functions 'gateway_{config,data}_debug' to conditionally log gateway data and configuration at the debug level. --- src/connection.c | 119 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 117 insertions(+), 2 deletions(-) diff --git a/src/connection.c b/src/connection.c index 9d2c6961306d..586c44330e89 100644 --- a/src/connection.c +++ b/src/connection.c @@ -32,6 +32,12 @@ #include "connman.h" +#define GATEWAY_CONFIG_DBG(description, config) \ + gateway_config_debug(__func__, description, config) + +#define GATEWAY_DATA_DBG(description, data) \ + gateway_data_debug(__func__, description, data) + struct gateway_config { bool active; char *gateway; @@ -53,6 +59,79 @@ struct gateway_data { static GHashTable *gateway_hash = NULL; +static const char *maybe_null(const void *pointer) +{ + return pointer ? pointer : ""; +} + +static void gateway_config_debug(const char *function, + const char *description, + const struct gateway_config *config) +{ + g_autofree char *vpn_phy_interface = NULL; + + if (!function || !description) + return; + + if (!config) + DBG("from %s %s %p", function, description, config); + else { + if (config->vpn_phy_index >= 0) + vpn_phy_interface = + connman_inet_ifname(config->vpn_phy_index); + + DBG("from %s %s %p: { active: %u, gateway: %p (%s), " + "vpn: %u, vpn_ip: %p (%s), vpn_phy_index: %d (%s), " + "vpn_phy_ip: %p (%s) }", + function, + description, + config, + config->active, + config->gateway, maybe_null(config->gateway), + config->vpn, + config->vpn_ip, maybe_null(config->vpn_ip), + config->vpn_phy_index, maybe_null(vpn_phy_interface), + config->vpn_phy_ip, maybe_null(config->vpn_phy_ip)); + } +} + +static void gateway_data_debug(const char *function, + const char *description, + const struct gateway_data *data) +{ + g_autofree char *interface = NULL; + + if (!function || !description) + return; + + if (!data) + DBG("from %s %s %p", function, description, data); + else { + interface = connman_inet_ifname(data->index); + + DBG("from %s %s %p: { index: %d (%s), service: %p (%s), " + "ipv4_gateway: %p, ipv6_gateway: %p, default_checked: %u }", + function, + description, + data, + data->index, + maybe_null(interface), + data->service, + connman_service_get_identifier(data->service), + data->ipv4_gateway, + data->ipv6_gateway, + data->default_checked); + + if (data->ipv4_gateway) + gateway_config_debug(function, "ipv4_gateway", + data->ipv4_gateway); + + if (data->ipv6_gateway) + gateway_config_debug(function, "ipv6_gateway", + data->ipv6_gateway); + } +} + static struct gateway_config *find_gateway(int index, const char *gateway) { GHashTableIter iter; @@ -282,6 +361,8 @@ static int del_routes(struct gateway_data *data, int status4 = 0, status6 = 0; bool do_ipv4 = false, do_ipv6 = false; + GATEWAY_DATA_DBG("data", data); + if (type == CONNMAN_IPCONFIG_TYPE_IPV4) do_ipv4 = true; else if (type == CONNMAN_IPCONFIG_TYPE_IPV6) @@ -334,6 +415,8 @@ static int disable_gateway(struct gateway_data *data, { bool active = false; + GATEWAY_DATA_DBG("data", data); + if (type == CONNMAN_IPCONFIG_TYPE_IPV4) { if (data->ipv4_gateway) active = data->ipv4_gateway->active; @@ -426,6 +509,8 @@ static void set_default_gateway(struct gateway_data *data, int status4 = 0, status6 = 0; bool do_ipv4 = false, do_ipv6 = false; + GATEWAY_DATA_DBG("data", data); + if (type == CONNMAN_IPCONFIG_TYPE_IPV4) do_ipv4 = true; else if (type == CONNMAN_IPCONFIG_TYPE_IPV6) @@ -507,6 +592,8 @@ static void unset_default_gateway(struct gateway_data *data, int index; bool do_ipv4 = false, do_ipv6 = false; + GATEWAY_DATA_DBG("data", data); + if (type == CONNMAN_IPCONFIG_TYPE_IPV4) do_ipv4 = true; else if (type == CONNMAN_IPCONFIG_TYPE_IPV6) @@ -586,6 +673,9 @@ static bool choose_default_gateway(struct gateway_data *data, { bool downgraded = false; + GATEWAY_DATA_DBG("data", data); + GATEWAY_DATA_DBG("candidate", candidate); + /* * If the current default is not active, then we mark * this one as default. If the other one is already active @@ -641,6 +731,8 @@ static void connection_newgateway(int index, const char *gateway) if (!config) return; + GATEWAY_CONFIG_DBG("config", config); + config->active = true; /* @@ -652,6 +744,8 @@ static void connection_newgateway(int index, const char *gateway) if (!data) return; + GATEWAY_DATA_DBG("data", data); + if (data->default_checked) return; @@ -690,6 +784,8 @@ static void remove_gateway(gpointer user_data) DBG("gateway ipv4 %p ipv6 %p", data->ipv4_gateway, data->ipv6_gateway); + GATEWAY_DATA_DBG("data", data); + if (data->ipv4_gateway) { g_free(data->ipv4_gateway->gateway); g_free(data->ipv4_gateway->vpn_ip); @@ -717,12 +813,18 @@ static void connection_delgateway(int index, const char *gateway) DBG("index %d gateway %s", index, gateway); config = find_gateway(index, gateway); - if (config) + if (config) { + GATEWAY_CONFIG_DBG("config", config); + config->active = false; + } data = find_default_gateway(); - if (data) + if (data) { + GATEWAY_DATA_DBG("data", data); + set_default_gateway(data, CONNMAN_IPCONFIG_TYPE_ALL); + } } static struct connman_rtnl connection_rtnl = { @@ -836,11 +938,15 @@ int __connman_connection_gateway_add(struct connman_service *service, if (!new_gateway) return -EINVAL; + GATEWAY_DATA_DBG("new_gateway", new_gateway); + active_gateway = find_active_gateway(); DBG("active %p index %d new %p", active_gateway, active_gateway ? active_gateway->index : -1, new_gateway); + GATEWAY_DATA_DBG("active_gateway", active_gateway); + if (type == CONNMAN_IPCONFIG_TYPE_IPV4 && new_gateway->ipv4_gateway) { add_host_route(AF_INET, index, gateway, service_type); @@ -931,6 +1037,8 @@ void __connman_connection_gateway_remove(struct connman_service *service, if (!data) return; + GATEWAY_DATA_DBG("service_data", data); + if (do_ipv4 && data->ipv4_gateway) set_default4 = data->ipv4_gateway->vpn; @@ -977,6 +1085,9 @@ void __connman_connection_gateway_remove(struct connman_service *service, */ if (set_default4 || set_default6 || err < 0) { data = find_default_gateway(); + + GATEWAY_DATA_DBG("default_data", data); + if (data) set_default_gateway(data, type); } @@ -996,6 +1107,8 @@ bool __connman_connection_update_gateway(void) DBG("default %p", default_gateway); + GATEWAY_DATA_DBG("default_gateway", default_gateway); + /* * There can be multiple active gateways so we need to * check them all. @@ -1005,6 +1118,8 @@ bool __connman_connection_update_gateway(void) while (g_hash_table_iter_next(&iter, &key, &value)) { struct gateway_data *active_gateway = value; + GATEWAY_DATA_DBG("active_gateway", active_gateway); + if (active_gateway == default_gateway) continue; From patchwork Wed Nov 29 19:21: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: 13473364 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 BF74A5DF35 for ; Wed, 29 Nov 2023 19:21:10 +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 E06C673227 for ; Wed, 29 Nov 2023 14:21:09 -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 9947A73247 for ; Wed, 29 Nov 2023 14:21:09 -0500 (EST) From: Grant Erickson To: connman@lists.linux.dev Subject: [PATCH v2 4/8] connection: Document 'gateway_{config,data}_debug'. Date: Wed, 29 Nov 2023 11:21:02 -0800 Message-ID: <20231129192106.1295868-5-gerickson@nuovations.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231129192106.1295868-1-gerickson@nuovations.com> References: <20231128230847.1224497-1-gerickson@nuovations.com> <20231129192106.1295868-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 'gateway_{config,data}_debug' functions. --- src/connection.c | 57 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/src/connection.c b/src/connection.c index 586c44330e89..7b530f26c2f2 100644 --- a/src/connection.c +++ b/src/connection.c @@ -59,11 +59,45 @@ struct gateway_data { static GHashTable *gateway_hash = NULL; +/** + * @brief + * Return the specified pointer if non-null; otherwise, the + * immutable "" string. + * + * @param[in] pointer The pointer to be returned if non-null. + * + * @returns + * @a pointer if non-null; otherwise the "" immutable + * null-terminated C string. + * + */ static const char *maybe_null(const void *pointer) { return pointer ? pointer : ""; } +/** + * @brief + * Conditionally log the specified gateway configuration. + * + * This conditionally logs at the debug level the specified + * #gateway_config gateway configuration, @a config, with the + * provided description, @a description, attributed to the provided + * function name, @a function. + * + * @param[in] function A pointer to an immutable null-terminated + * C string containing the function name to + * which the call to this function should be + * attributed. + * @param[in] description A pointer to an immutable null-terminated + * C string briefly describing @a + * config. For example, "ipv4_config". + * @param[in] config A pointer to the immutable gateway + * configuration to conditionally log. + * + * @sa DBG + * + */ static void gateway_config_debug(const char *function, const char *description, const struct gateway_config *config) @@ -95,6 +129,29 @@ static void gateway_config_debug(const char *function, } } +/** + * @brief + * Conditionally log the specified gateway data. + * + * This conditionally logs at the debug level the specified + * #gateway_data gateway data, @a data, with the provided + * description, @a description, attributed to the provided function + * name, @a function. + * + * @param[in] function A pointer to an immutable null-terminated + * C string containing the function name to + * which the call to this function should be + * attributed. + * @param[in] description A pointer to an immutable null-terminated + * C string briefly describing @a + * data. For example, "default_gateway". + * @param[in] data A pointer to the immutable gateway + * data to conditionally log. + * + * @sa DBG + * @sa gateway_config_debug + * + */ static void gateway_data_debug(const char *function, const char *description, const struct gateway_data *data) From patchwork Wed Nov 29 19:21: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: 13473369 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 320C55DF3C for ; Wed, 29 Nov 2023 19:21:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=nuovations.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nuovations.com Authentication-Results: smtp.subspace.kernel.org; dkim=none Received: from mohas.pair.com (localhost [127.0.0.1]) by mohas.pair.com (Postfix) with ESMTP id 584EF73225 for ; Wed, 29 Nov 2023 14:21:10 -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 1203473232 for ; Wed, 29 Nov 2023 14:21:09 -0500 (EST) From: Grant Erickson To: connman@lists.linux.dev Subject: [PATCH v2 5/8] connection: Expand, Enhance, and Refactor 'DBG'. Date: Wed, 29 Nov 2023 11:21:03 -0800 Message-ID: <20231129192106.1295868-6-gerickson@nuovations.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231129192106.1295868-1-gerickson@nuovations.com> References: <20231128230847.1224497-1-gerickson@nuovations.com> <20231129192106.1295868-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 expands, exhances, and refactors 'DBG' statements throughout the module to improve symmetry in content, aid in debugging, and to reflect the newly-leveraged 'GATEWAY_CONFIG_DBG' and 'GATEWAY_DATA_DBG' macros. --- src/connection.c | 52 ++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 44 insertions(+), 8 deletions(-) diff --git a/src/connection.c b/src/connection.c index 7b530f26c2f2..b772a6367570 100644 --- a/src/connection.c +++ b/src/connection.c @@ -566,6 +566,9 @@ static void set_default_gateway(struct gateway_data *data, int status4 = 0, status6 = 0; bool do_ipv4 = false, do_ipv6 = false; + DBG("data %p type %d (%s)", data, + type, __connman_ipconfig_type2string(type)); + GATEWAY_DATA_DBG("data", data); if (type == CONNMAN_IPCONFIG_TYPE_IPV4) @@ -575,9 +578,6 @@ static void set_default_gateway(struct gateway_data *data, else do_ipv4 = do_ipv6 = true; - DBG("type %d gateway ipv4 %p ipv6 %p", type, data->ipv4_gateway, - data->ipv6_gateway); - if (do_ipv4 && data->ipv4_gateway && data->ipv4_gateway->vpn) { connman_inet_set_gateway_interface(data->index); @@ -649,6 +649,9 @@ static void unset_default_gateway(struct gateway_data *data, int index; bool do_ipv4 = false, do_ipv6 = false; + DBG("data %p type %d (%s)", data, + type, __connman_ipconfig_type2string(type)); + GATEWAY_DATA_DBG("data", data); if (type == CONNMAN_IPCONFIG_TYPE_IPV4) @@ -776,13 +779,17 @@ static bool choose_default_gateway(struct gateway_data *data, static void connection_newgateway(int index, const char *gateway) { + g_autofree char *interface = NULL; struct gateway_config *config; struct gateway_data *data; GHashTableIter iter; gpointer value, key; bool found = false; - DBG("index %d gateway %s", index, gateway); + interface = connman_inet_ifname(index); + + DBG("index %d (%s) gateway %s", index, maybe_null(interface), + gateway); config = find_gateway(index, gateway); if (!config) @@ -839,7 +846,7 @@ static void remove_gateway(gpointer user_data) { struct gateway_data *data = user_data; - DBG("gateway ipv4 %p ipv6 %p", data->ipv4_gateway, data->ipv6_gateway); + DBG("data %p", data); GATEWAY_DATA_DBG("data", data); @@ -864,10 +871,14 @@ static void remove_gateway(gpointer user_data) static void connection_delgateway(int index, const char *gateway) { + g_autofree char *interface = NULL; struct gateway_config *config; struct gateway_data *data; - DBG("index %d gateway %s", index, gateway); + interface = connman_inet_ifname(index); + + DBG("index %d (%s) gateway %s", index, maybe_null(interface), + gateway); config = find_gateway(index, gateway); if (config) { @@ -974,9 +985,20 @@ int __connman_connection_gateway_add(struct connman_service *service, enum connman_service_type service_type = connman_service_get_type(service); int index; + g_autofree char *interface = NULL; + + DBG("service %p (%s) gateway %p (%s) type %d (%s) peer %p (%s)", + service, maybe_null(connman_service_get_identifier(service)), + gateway, maybe_null(gateway), + type, __connman_ipconfig_type2string(type), + peer, maybe_null(peer)); index = __connman_service_get_index(service); + interface = connman_inet_ifname(index); + + DBG("index %d (%s)", index, maybe_null(interface)); + /* * If gateway is NULL, it's a point to point link and the default * gateway for ipv4 is 0.0.0.0 and for ipv6 is ::, meaning the @@ -1077,9 +1099,21 @@ void __connman_connection_gateway_remove(struct connman_service *service, struct gateway_data *data = NULL; bool set_default4 = false, set_default6 = false; bool do_ipv4 = false, do_ipv6 = false; + int index; + g_autofree char *interface = NULL; int err; - DBG("service %p type %d", service, type); + DBG("service %p (%s) type %d (%s)", + service, maybe_null(connman_service_get_identifier(service)), + type, __connman_ipconfig_type2string(type)); + + index = __connman_service_get_index(service); + if (index < 0) + return; + + interface = connman_inet_ifname(index); + + DBG("index %d (%s)", index, maybe_null(interface)); if (type == CONNMAN_IPCONFIG_TYPE_IPV4) do_ipv4 = true; @@ -1157,12 +1191,14 @@ bool __connman_connection_update_gateway(void) GHashTableIter iter; gpointer value, key; + DBG(""); + if (!gateway_hash) return updated; default_gateway = find_default_gateway(); - DBG("default %p", default_gateway); + DBG("default_gateway %p", default_gateway); GATEWAY_DATA_DBG("default_gateway", default_gateway); From patchwork Wed Nov 29 19:21: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: 13473366 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 D84575DF2C for ; Wed, 29 Nov 2023 19:21:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=nuovations.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nuovations.com Authentication-Results: smtp.subspace.kernel.org; dkim=none Received: from mohas.pair.com (localhost [127.0.0.1]) by mohas.pair.com (Postfix) with ESMTP id C5B0B7322E for ; Wed, 29 Nov 2023 14:21:10 -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 7E6307324C for ; Wed, 29 Nov 2023 14:21:10 -0500 (EST) From: Grant Erickson To: connman@lists.linux.dev Subject: [PATCH v2 6/8] connection: Document 'connection_{add,del}gateway'. Date: Wed, 29 Nov 2023 11:21:04 -0800 Message-ID: <20231129192106.1295868-7-gerickson@nuovations.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231129192106.1295868-1-gerickson@nuovations.com> References: <20231128230847.1224497-1-gerickson@nuovations.com> <20231129192106.1295868-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 'connection_{add,del}gateway' functions. --- src/connection.c | 67 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/src/connection.c b/src/connection.c index b772a6367570..a4610202d0ba 100644 --- a/src/connection.c +++ b/src/connection.c @@ -777,6 +777,29 @@ static bool choose_default_gateway(struct gateway_data *data, return downgraded; } +/** + * @brief + * Handler for gateway, or default route, -specific routes newly + * added to the Linux kernel routing tables. + * + * This is the Linux Routing Netlink (rtnl) handler for gateway, or + * default route, -specific routes newly-added to the Linux kernel + * routing tables. Its primary role and goal is to serve as a + * round-trip acknowledgement that gateway-, or default route, + * related routes added or set to the kernel are now active and in + * use. + * + * @param[in] index The network interface index associated with + * the newly-added gateway, or default router. + * @param[in] gateway An pointer to an immutable null-terminated + * C string containing the text- + * formatted address of the gateway, or default + * router, that was added. + * + * @sa set_default_gateway + * @sa connection_delgateway + * + */ static void connection_newgateway(int index, const char *gateway) { g_autofree char *interface = NULL; @@ -791,12 +814,23 @@ static void connection_newgateway(int index, const char *gateway) DBG("index %d (%s) gateway %s", index, maybe_null(interface), gateway); + /* + * If there is no gateway configuration, then this is not a + * gateway, or default router, route we added or + * set. Consequently, ignore it and return. + */ config = find_gateway(index, gateway); if (!config) return; GATEWAY_CONFIG_DBG("config", config); + /* + * Otherwise, this is a gateway, or default router, route we added + * or set and it is now acknowledged by the kernel. Consequently, + * prospectively mark it as active; however, this may be + * subsequently modified as default route determinations are made. + */ config->active = true; /* @@ -869,6 +903,29 @@ static void remove_gateway(gpointer user_data) g_free(data); } +/** + * @brief + * Handler for gateway, or default route, -specific routes newly + * removed from the Linux kernel routing tables. + * + * This is the Linux Routing Netlink (rtnl) handler for gateway, or + * default route, -specific routes newly-removed from the Linux + * kernel routing tables. Its primary role and goal is to serve as + * a round-trip acknowledgement that gateway-, or default route, + * related routes removed or cleared from the kernel are now inactive + * and are no longer in use. + * + * @param[in] index The network interface index associated with + * the newly-removed gateway, or default router. + * @param[in] gateway An pointer to an immutable null-terminated + * C string containing the text- + * formatted address of the gateway, or default + * router, that was removed. + * + * @sa connection_newgateway + * @sa set_default_gateway + * + */ static void connection_delgateway(int index, const char *gateway) { g_autofree char *interface = NULL; @@ -880,6 +937,10 @@ static void connection_delgateway(int index, const char *gateway) DBG("index %d (%s) gateway %s", index, maybe_null(interface), gateway); + /* + * This ends the lifecycle of the gateway associated with the + * newly-removed route; mark it as no longer active. + */ config = find_gateway(index, gateway); if (config) { GATEWAY_CONFIG_DBG("config", config); @@ -887,6 +948,12 @@ static void connection_delgateway(int index, const char *gateway) config->active = false; } + /* + * Due to the newly-removed gateway route, there may have been a + * concomitant change in service order that has resulted in a new, + * default service, if any. If so, ensure that service acquires + * the high priority default route. + */ data = find_default_gateway(); if (data) { GATEWAY_DATA_DBG("data", data); From patchwork Wed Nov 29 19:21: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: 13473367 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 E752F5DF3B for ; Wed, 29 Nov 2023 19:21:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=nuovations.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nuovations.com Authentication-Results: smtp.subspace.kernel.org; dkim=none Received: from mohas.pair.com (localhost [127.0.0.1]) by mohas.pair.com (Postfix) with ESMTP id 3E6E573230 for ; Wed, 29 Nov 2023 14:21:11 -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 EB86073249 for ; Wed, 29 Nov 2023 14:21:10 -0500 (EST) From: Grant Erickson To: connman@lists.linux.dev Subject: [PATCH v2 7/8] connection: Document '__connman_connection_gateway_{add,remove}'. Date: Wed, 29 Nov 2023 11:21:05 -0800 Message-ID: <20231129192106.1295868-8-gerickson@nuovations.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231129192106.1295868-1-gerickson@nuovations.com> References: <20231128230847.1224497-1-gerickson@nuovations.com> <20231129192106.1295868-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_connection_gateway_{add,remove}' functions. --- src/connection.c | 73 ++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 71 insertions(+), 2 deletions(-) diff --git a/src/connection.c b/src/connection.c index a4610202d0ba..58abf2ae1925 100644 --- a/src/connection.c +++ b/src/connection.c @@ -1040,6 +1040,41 @@ static void add_host_route(int family, int index, const char *gateway, } } +/** + * @brief + * Add, or set, the gateway, or default router, for a network + * service. + * + * This attempts to add, or set, the gateway, or default router, for + * a network service using the specified IP configuration gateway + * address and network interface index as the lookup key for the + * network service. + * + * @param[in,out] service A pointer to the mutable network service + * for which to add a gateway, or default + * router. + * @param[in] gateway An optional pointer to an immutable null- + * terminated C string containing the + * text-formatted address of the gateway, or + * default router, to add to or associate + * with @a service. + * @param[in] type The IP configuration type for which + * gateway, or default router, is to be + * added. + * @param[in] peer An optional pointer to an immutable null- + * terminated C string containing the + * text-formatted address of the network + * peer, for point-to-point links, + * associated with the gateway. + * + * @retval 0 If successful. + * @retval -EINVAL If service is null or if network interface + * index associated with @a service is invalid. + * + * @sa __connman_connection_gateway_remove + * @sa __connman_connection_update_gateway + * + */ int __connman_connection_gateway_add(struct connman_service *service, const char *gateway, enum connman_ipconfig_type type, @@ -1160,6 +1195,30 @@ done: return 0; } +/** + * @brief + * Remove, or clear, the gateway, or default router, for a network + * service. + * + * This attempts to remove, or clear, the gateway, or default router, + * for a network service using the specified network service and IP + * configuration type. + * + * @param[in,out] service A pointer to the mutable network service + * for which to remove, or clear, a gateway, + * or default router. + * @param[in] type The IP configuration type for which + * gateway, or default router, is to be + * removed. + * + * @retval 0 If successful. + * @retval -EINVAL If service is null or if network interface + * index associated with @a service is invalid. + * + * @sa __connman_connection_gateway_add + * @sa __connman_connection_update_gateway + * + */ void __connman_connection_gateway_remove(struct connman_service *service, enum connman_ipconfig_type type) { @@ -1189,8 +1248,14 @@ void __connman_connection_gateway_remove(struct connman_service *service, else do_ipv4 = do_ipv6 = true; + /* Delete any routes associated with this service's nameservers. */ + __connman_service_nameserver_del_routes(service, type); + /* + * If there is no hash table / map entry for this service, then + * there are no gateways associated with it; simply return. + */ data = g_hash_table_lookup(gateway_hash, service); if (!data) return; @@ -1208,6 +1273,8 @@ void __connman_connection_gateway_remove(struct connman_service *service, data->ipv6_gateway ? data->ipv6_gateway->gateway : "", set_default4, set_default6); + /* If necessary, delete any VPN-related host routes. */ + if (do_ipv4 && data->ipv4_gateway && data->ipv4_gateway->vpn && data->index >= 0) connman_inet_del_host_route(data->ipv4_gateway->vpn_phy_index, @@ -1219,11 +1286,13 @@ void __connman_connection_gateway_remove(struct connman_service *service, data->ipv6_gateway->vpn_phy_index, data->ipv6_gateway->gateway); + /* Remove all active routes associated with this gateway data. */ + err = disable_gateway(data, type); /* - * We remove the service from the hash only if all the gateway - * settings are to be removed. + * We remove the service from the service/gateway map only if ALL + * of the gateway settings are to be removed. */ if (do_ipv4 == do_ipv6 || (data->ipv4_gateway && !data->ipv6_gateway From patchwork Wed Nov 29 19:21: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: 13473370 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 4FD075DF3D for ; Wed, 29 Nov 2023 19:21:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=nuovations.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nuovations.com Authentication-Results: smtp.subspace.kernel.org; dkim=none Received: from mohas.pair.com (localhost [127.0.0.1]) by mohas.pair.com (Postfix) with ESMTP id AC8E073232 for ; Wed, 29 Nov 2023 14:21:11 -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 643957324A for ; Wed, 29 Nov 2023 14:21:11 -0500 (EST) From: Grant Erickson To: connman@lists.linux.dev Subject: [PATCH v2 8/8] connection: Document '__connman_connection_update_gateway'. Date: Wed, 29 Nov 2023 11:21:06 -0800 Message-ID: <20231129192106.1295868-9-gerickson@nuovations.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231129192106.1295868-1-gerickson@nuovations.com> References: <20231128230847.1224497-1-gerickson@nuovations.com> <20231129192106.1295868-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_connection_update_gateway' function. --- src/connection.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/connection.c b/src/connection.c index 58abf2ae1925..7c65b0951243 100644 --- a/src/connection.c +++ b/src/connection.c @@ -1320,6 +1320,24 @@ void __connman_connection_gateway_remove(struct connman_service *service, } } +/** + * @brief + * Handle a potential change in gateways. + * + * This may be invoked by other modules in the event of service and + * technology changes to reexamine and, if necessary, update active + * network interface gateways and their associated routing table + * entries. + * + * @returns + * True if an active gateway was updated; otherwise, false. + * + * @sa __connman_connection_gateway_add + * @sa __connman_connection_gateway_remove + * @sa set_default_gateway + * @sa unset_default_gateway + * + */ bool __connman_connection_update_gateway(void) { struct gateway_data *default_gateway; @@ -1329,6 +1347,10 @@ bool __connman_connection_update_gateway(void) DBG(""); + /* + * If there is no service-to-gateway data hash, then there is + * nothing to update and do; simply return. + */ if (!gateway_hash) return updated;