From patchwork Thu Dec 7 23:41:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Grant Erickson X-Patchwork-Id: 13484488 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 AD9C742ABB for ; Thu, 7 Dec 2023 23:41:39 +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 Received: from mohas.pair.com (localhost [127.0.0.1]) by mohas.pair.com (Postfix) with ESMTP id 93A8873118 for ; Thu, 7 Dec 2023 18:41:32 -0500 (EST) Received: from localhost.localdomain (unknown [IPv6:2601:647:5a00:15c1:851a:6a54:a980:b9a9]) (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 511987312C for ; Thu, 7 Dec 2023 18:41:32 -0500 (EST) From: Grant Erickson To: connman@lists.linux.dev Subject: [PATCH 1/4] connection: Colocate search functions. Date: Thu, 7 Dec 2023 15:41:27 -0800 Message-ID: <20231207234130.1093617-2-gerickson@nuovations.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231207234130.1093617-1-gerickson@nuovations.com> References: <20231207234130.1093617-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 relocates 'find_active_gateway' and 'find_default_gateway' such that they are colocated with other service/gateway map search functions. --- src/connection.c | 70 ++++++++++++++++++++++++------------------------ 1 file changed, 35 insertions(+), 35 deletions(-) diff --git a/src/connection.c b/src/connection.c index d4873861e0b6..c74dd0741995 100644 --- a/src/connection.c +++ b/src/connection.c @@ -241,6 +241,41 @@ static struct gateway_data *lookup_gateway_data(struct gateway_config *config) return NULL; } +static struct gateway_data *find_active_gateway(void) +{ + GHashTableIter iter; + gpointer value, key; + + DBG(""); + + g_hash_table_iter_init(&iter, gateway_hash); + + while (g_hash_table_iter_next(&iter, &key, &value)) { + struct gateway_data *data = value; + + if (data->ipv4_config && + data->ipv4_config->active) + return data; + + if (data->ipv6_config && + data->ipv6_config->active) + return data; + } + + return NULL; +} + +static struct gateway_data *find_default_gateway(void) +{ + struct connman_service *service; + + service = connman_service_get_default(); + if (!service) + return NULL; + + return g_hash_table_lookup(gateway_hash, service); +} + static struct gateway_data *find_vpn_gateway(int index, const char *gateway) { GHashTableIter iter; @@ -717,17 +752,6 @@ static void unset_default_gateway(struct gateway_data *data, data->ipv4_config->gateway); } -static struct gateway_data *find_default_gateway(void) -{ - struct connman_service *service; - - service = connman_service_get_default(); - if (!service) - return NULL; - - return g_hash_table_lookup(gateway_hash, service); -} - static bool choose_default_gateway(struct gateway_data *data, struct gateway_data *candidate) { @@ -968,30 +992,6 @@ static struct connman_rtnl connection_rtnl = { .delgateway = connection_delgateway, }; -static struct gateway_data *find_active_gateway(void) -{ - GHashTableIter iter; - gpointer value, key; - - DBG(""); - - g_hash_table_iter_init(&iter, gateway_hash); - - while (g_hash_table_iter_next(&iter, &key, &value)) { - struct gateway_data *data = value; - - if (data->ipv4_config && - data->ipv4_config->active) - return data; - - if (data->ipv6_config && - data->ipv6_config->active) - return data; - } - - return NULL; -} - static void add_host_route(int family, int index, const char *gateway, enum connman_service_type service_type) { From patchwork Thu Dec 7 23:41:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Grant Erickson X-Patchwork-Id: 13484489 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 4342057328 for ; Thu, 7 Dec 2023 23:41:40 +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 Received: from mohas.pair.com (localhost [127.0.0.1]) by mohas.pair.com (Postfix) with ESMTP id 01C7173123 for ; Thu, 7 Dec 2023 18:41:33 -0500 (EST) Received: from localhost.localdomain (unknown [IPv6:2601:647:5a00:15c1:851a:6a54:a980:b9a9]) (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 AFF7A7314B for ; Thu, 7 Dec 2023 18:41:32 -0500 (EST) From: Grant Erickson To: connman@lists.linux.dev Subject: [PATCH 2/4] service: Const-qualify 'lookup_gateway_data'. Date: Thu, 7 Dec 2023 15:41:28 -0800 Message-ID: <20231207234130.1093617-3-gerickson@nuovations.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231207234130.1093617-1-gerickson@nuovations.com> References: <20231207234130.1093617-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 Const-qualify the gateway configuration argument of 'lookup_gateway_data' to make it clear to the compiler, static analyzers, and human readers that the function is strictly a getter with no gateway configuration mutation side effects. --- src/connection.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/connection.c b/src/connection.c index c74dd0741995..c42988bf337d 100644 --- a/src/connection.c +++ b/src/connection.c @@ -216,7 +216,8 @@ static struct gateway_config *find_gateway(int index, const char *gateway) return NULL; } -static struct gateway_data *lookup_gateway_data(struct gateway_config *config) +static struct gateway_data *lookup_gateway_data( + const struct gateway_config *config) { GHashTableIter iter; gpointer value, key; From patchwork Thu Dec 7 23:41:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Grant Erickson X-Patchwork-Id: 13484491 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 4335D5646A for ; Thu, 7 Dec 2023 23:41:40 +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 Received: from mohas.pair.com (localhost [127.0.0.1]) by mohas.pair.com (Postfix) with ESMTP id 5E89A73140 for ; Thu, 7 Dec 2023 18:41:33 -0500 (EST) Received: from localhost.localdomain (unknown [IPv6:2601:647:5a00:15c1:851a:6a54:a980:b9a9]) (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 2153373147 for ; Thu, 7 Dec 2023 18:41:33 -0500 (EST) From: Grant Erickson To: connman@lists.linux.dev Subject: [PATCH 3/4] connection: Harmonize search function names. Date: Thu, 7 Dec 2023 15:41:29 -0800 Message-ID: <20231207234130.1093617-4-gerickson@nuovations.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231207234130.1093617-1-gerickson@nuovations.com> References: <20231207234130.1093617-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 Prior to this change, there were five service/gateway map search functions with inconsistent naming patterns: * Four of those five were named 'find_*' and only one 'lookup_*'. * Four of those five return a pointer to gateway_data but only one was suffixed with '_data'. This harmonizes the five service/gateway map search function names by: * Ensuring that they all start with 'find_'. * Ensuring that if they return a pointer to 'gateway_config' that they are suffixed with '_config' and if they return a pointer to 'gateway_data' that they are suffixed with '_data'. --- src/connection.c | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/src/connection.c b/src/connection.c index c42988bf337d..cd28f8e80ac6 100644 --- a/src/connection.c +++ b/src/connection.c @@ -189,7 +189,8 @@ static void gateway_data_debug(const char *function, } } -static struct gateway_config *find_gateway(int index, const char *gateway) +static struct gateway_config *find_gateway_config(int index, + const char *gateway) { GHashTableIter iter; gpointer value, key; @@ -216,7 +217,7 @@ static struct gateway_config *find_gateway(int index, const char *gateway) return NULL; } -static struct gateway_data *lookup_gateway_data( +static struct gateway_data *find_gateway_data( const struct gateway_config *config) { GHashTableIter iter; @@ -242,7 +243,7 @@ static struct gateway_data *lookup_gateway_data( return NULL; } -static struct gateway_data *find_active_gateway(void) +static struct gateway_data *find_active_gateway_data(void) { GHashTableIter iter; gpointer value, key; @@ -266,7 +267,7 @@ static struct gateway_data *find_active_gateway(void) return NULL; } -static struct gateway_data *find_default_gateway(void) +static struct gateway_data *find_default_gateway_data(void) { struct connman_service *service; @@ -277,7 +278,8 @@ static struct gateway_data *find_default_gateway(void) return g_hash_table_lookup(gateway_hash, service); } -static struct gateway_data *find_vpn_gateway(int index, const char *gateway) +static struct gateway_data *find_vpn_gateway_data(int index, + const char *gateway) { GHashTableIter iter; gpointer value, key; @@ -322,7 +324,7 @@ static void get_gateway_cb(const char *gateway, int index, void *user_data) DBG("phy index %d phy gw %s vpn index %d vpn gw %s", index, gateway, params->vpn_index, params->vpn_gateway); - data = find_vpn_gateway(params->vpn_index, params->vpn_gateway); + data = find_vpn_gateway_data(params->vpn_index, params->vpn_gateway); if (!data) { DBG("Cannot find VPN link route, index %d addr %s", params->vpn_index, params->vpn_gateway); @@ -844,7 +846,7 @@ static void connection_newgateway(int index, const char *gateway) * gateway, or default router, route we added or * set. Consequently, ignore it and return. */ - config = find_gateway(index, gateway); + config = find_gateway_config(index, gateway); if (!config) return; @@ -863,7 +865,7 @@ static void connection_newgateway(int index, const char *gateway) * if there are two gateways waiting rtnl activation at the * same time. */ - data = lookup_gateway_data(config); + data = find_gateway_data(config); if (!data) return; @@ -966,7 +968,7 @@ static void connection_delgateway(int index, const char *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); + config = find_gateway_config(index, gateway); if (config) { GATEWAY_CONFIG_DBG("config", config); @@ -979,7 +981,7 @@ static void connection_delgateway(int index, const char *gateway) * default service, if any. If so, ensure that service acquires * the high priority default route. */ - data = find_default_gateway(); + data = find_default_gateway_data(); if (data) { GATEWAY_DATA_DBG("data", data); @@ -1122,7 +1124,7 @@ int __connman_connection_gateway_add(struct connman_service *service, GATEWAY_DATA_DBG("new_gateway", new_gateway); - active_gateway = find_active_gateway(); + active_gateway = find_active_gateway_data(); DBG("active %p index %d new %p", active_gateway, active_gateway ? active_gateway->index : -1, new_gateway); @@ -1312,7 +1314,7 @@ void __connman_connection_gateway_remove(struct connman_service *service, * We hit the same issue if remove_gateway() fails. */ if (set_default4 || set_default6 || err < 0) { - data = find_default_gateway(); + data = find_default_gateway_data(); GATEWAY_DATA_DBG("default_data", data); @@ -1355,7 +1357,7 @@ bool __connman_connection_update_gateway(void) if (!gateway_hash) return updated; - default_gateway = find_default_gateway(); + default_gateway = find_default_gateway_data(); DBG("default_gateway %p", default_gateway); From patchwork Thu Dec 7 23:41:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Grant Erickson X-Patchwork-Id: 13484490 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 433A657320 for ; Thu, 7 Dec 2023 23:41:40 +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 Received: from mohas.pair.com (localhost [127.0.0.1]) by mohas.pair.com (Postfix) with ESMTP id BE0A673145 for ; Thu, 7 Dec 2023 18:41:33 -0500 (EST) Received: from localhost.localdomain (unknown [IPv6:2601:647:5a00:15c1:851a:6a54:a980:b9a9]) (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 7E52F73154 for ; Thu, 7 Dec 2023 18:41:33 -0500 (EST) From: Grant Erickson To: connman@lists.linux.dev Subject: [PATCH 4/4] connection: Document search functions. Date: Thu, 7 Dec 2023 15:41:30 -0800 Message-ID: <20231207234130.1093617-5-gerickson@nuovations.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231207234130.1093617-1-gerickson@nuovations.com> References: <20231207234130.1093617-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 service/gateway map search functions: * find_gateway_config * find_gateway_data * find_default_gateway_data --- src/connection.c | 66 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/src/connection.c b/src/connection.c index cd28f8e80ac6..deab2c034dc7 100644 --- a/src/connection.c +++ b/src/connection.c @@ -189,6 +189,35 @@ static void gateway_data_debug(const char *function, } } +/** + * @brief + * Find the gateway, or default router, configuration associated + * with a network interface index. + * + * This attempts to find a gateway, or default router, configuration + * associated with the specified network interface index. + * + * It is possible that there is both an IPv4 and IPv6 gateway, or + * default router, configuration exist for an index. The IP address + * family associated with @a gateway will uniqueify and select among + * them. + * + * @param[in] index The network interface index for which to find + * gateway, or default router, configuration. + * @param[in] gateway A pointer to an immutable null- + * terminated C string containing the + * text-formatted address of the gateway, or + * default router, for which to find its + * associated configuration. + * + * @returns + * A pointer to the gateway, or default router, configuration + * associated with the provided network interface index on success; + * otherwise, null. + * + * @sa find_gateway_data + * + */ static struct gateway_config *find_gateway_config(int index, const char *gateway) { @@ -217,6 +246,25 @@ static struct gateway_config *find_gateway_config(int index, return NULL; } +/** + * @brief + * Find the gateway, or default router, data associated + * with the configuration. + * + * This attempts to find a gateway, or default router, data + * associated with the specified configuration. + * + * @param[in] config A pointer to an immutable gateway, or + * default router, configuration for which to + * find the associated gateway data. + * + * @returns + * A pointer to the gateway, or default router, data associated + * with the provided configuration on success; otherwise, null. + * + * @sa find_gateway_config + * + */ static struct gateway_data *find_gateway_data( const struct gateway_config *config) { @@ -267,6 +315,24 @@ static struct gateway_data *find_active_gateway_data(void) return NULL; } +/** + * @brief + * Find the gateway, or default router, data associated with the + * default service. + * + * This attempts to find the gateway, or default router, data + * associated with default network service (that is, has the default + * route). + * + * @returns + * A pointer to the gateway, or default router, data associated + * with the default network service (that is, has the default + * route) on success; otherwise, null. + * + * @sa find_active_gateway_data + * @sa find_gateway_data + * + */ static struct gateway_data *find_default_gateway_data(void) { struct connman_service *service;