connection: Harmonize Search Function Names and Document Search Functions
cover connection: Harmonize Search Function Names and Document Search Functions
This colocates service/gateway search functions, harmonizes their names, and documents them.
Grant Erickson (4):
connection: Colocate search functions.
service: Const-qualify 'lookup_gateway_data'.
connection: Harmonize search function names.
connection: Document search functions.
src/connection.c | 161 +++++++++++++++++++++++++++++++++-------------- 1 file changed, 115 insertions(+), 46 deletions(-)
Signature · 1 line
2.42.0
PATCH 1/4 connection: Colocate search functions.
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(-)
src/connection.c +35 -35
@@ -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) {
Signature · 1 line
2.42.0
PATCH 2/4 service: Const-qualify 'lookup_gateway_data'.
In reply to Grant EricksonConst-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(-)
src/connection.c +2 -1
@@ -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;
Signature · 1 line
2.42.0
PATCH 3/4 connection: Harmonize search function names.
In reply to Grant EricksonPrior 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(-)
src/connection.c +15 -13
@@ -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);
Signature · 1 line
2.42.0
PATCH 4/4 connection: Document search functions.
In reply to Grant EricksonThis 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(+)
src/connection.c +66 -0
@@ -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;
Signature · 1 line
2.42.0