diff mbox series

[2/2] connection: Remove unnecessary '__connman_service_get_index' calls.

Message ID 20231129231706.1306676-3-gerickson@nuovations.com (mailing list archive)
State Not Applicable, archived
Headers show
Series connection: Remove Unnecessary '__connman_service_get_index' Calls | expand

Commit Message

Grant Erickson Nov. 29, 2023, 11:17 p.m. UTC
In both 'set_default_gateway' and 'unset_default_gateway' there are
unnecessary, redundant, and, per the below, circular calls to
'__connman_service_get_index' to get the network interface index from
the 'service' field of the gateway 'data' parameter passed to these
functions.

However, in 'add_gateway', the gateway data 'index' field is assigned
as follows:

    temp_data->index = index;

where 'index' comes from a parameter passed to 'add_gateway', from
'__connman_connection_gateway_add':

    index = __connman_service_get_index(service);

that was sourced from the network service from which a strong
reference was retained when the gateway data was initialized.

Consequently, the network interface index sought may simply be
accessed from the 'index' field of the gateway data as:

    data->index
---
 src/connection.c | 22 ++++++++--------------
 1 file changed, 8 insertions(+), 14 deletions(-)
diff mbox series

Patch

diff --git a/src/connection.c b/src/connection.c
index 5a98b8d57c84..91ce39adc167 100644
--- a/src/connection.c
+++ b/src/connection.c
@@ -859,7 +859,6 @@  static int add_gateway(struct connman_service *service,
 static void set_default_gateway(struct gateway_data *data,
 				enum connman_ipconfig_type type)
 {
-	int index;
 	int status4 = 0, status6 = 0;
 	bool do_ipv4 = false, do_ipv6 = false;
 
@@ -905,11 +904,9 @@  static void set_default_gateway(struct gateway_data *data,
 		return;
 	}
 
-	index = __connman_service_get_index(data->service);
-
 	if (do_ipv4 && data->ipv4_config &&
 			is_ipv4_addr_any_str(data->ipv4_config->gateway)) {
-		if (connman_inet_set_gateway_interface(index) < 0)
+		if (connman_inet_set_gateway_interface(data->index) < 0)
 			return;
 		data->ipv4_config->active = true;
 		goto done;
@@ -917,7 +914,7 @@  static void set_default_gateway(struct gateway_data *data,
 
 	if (do_ipv6 && data->ipv6_config &&
 			is_ipv6_addr_any_str(data->ipv6_config->gateway)) {
-		if (connman_inet_set_ipv6_gateway_interface(index) < 0)
+		if (connman_inet_set_ipv6_gateway_interface(data->index) < 0)
 			return;
 		data->ipv6_config->active = true;
 		goto done;
@@ -925,11 +922,11 @@  static void set_default_gateway(struct gateway_data *data,
 
 	if (do_ipv6 && data->ipv6_config)
 		status6 = __connman_inet_add_default_to_table(RT_TABLE_MAIN,
-					index, data->ipv6_config->gateway);
+					data->index, data->ipv6_config->gateway);
 
 	if (do_ipv4 && data->ipv4_config)
 		status4 = __connman_inet_add_default_to_table(RT_TABLE_MAIN,
-					index, data->ipv4_config->gateway);
+					data->index, data->ipv4_config->gateway);
 
 	if (status4 < 0 || status6 < 0)
 		return;
@@ -941,7 +938,6 @@  done:
 static void unset_default_gateway(struct gateway_data *data,
 				enum connman_ipconfig_type type)
 {
-	int index;
 	bool do_ipv4 = false, do_ipv6 = false;
 
 	DBG("data %p type %d (%s)", data,
@@ -985,28 +981,26 @@  static void unset_default_gateway(struct gateway_data *data,
 		return;
 	}
 
-	index = __connman_service_get_index(data->service);
-
 	if (do_ipv4 && data->ipv4_config &&
 			is_ipv4_addr_any_str(data->ipv4_config->gateway)) {
-		connman_inet_clear_gateway_interface(index);
+		connman_inet_clear_gateway_interface(data->index);
 		data->ipv4_config->active = false;
 		return;
 	}
 
 	if (do_ipv6 && data->ipv6_config &&
 			is_ipv6_addr_any_str(data->ipv6_config->gateway)) {
-		connman_inet_clear_ipv6_gateway_interface(index);
+		connman_inet_clear_ipv6_gateway_interface(data->index);
 		data->ipv6_config->active = false;
 		return;
 	}
 
 	if (do_ipv6 && data->ipv6_config)
-		connman_inet_clear_ipv6_gateway_address(index,
+		connman_inet_clear_ipv6_gateway_address(data->index,
 						data->ipv6_config->gateway);
 
 	if (do_ipv4 && data->ipv4_config)
-		connman_inet_clear_gateway_address(index,
+		connman_inet_clear_gateway_address(data->index,
 						data->ipv4_config->gateway);
 }