[PATCH 2/4] Reset the index of ipconfig in function connman_network_set_index()

martin.xu at intel.com martin.xu at intel.com
Sun Apr 11 23:35:04 PDT 2010


From: Martin Xu <martin.xu at intel.com>

Otherwise, the following operation of ipconfig will be wrong.
The issue was found when setting static ip of panu, the index of bnep
device may change, while the index was not be reset, conquently the
invalid index was used to set static ip and leaded to error.
---
 src/network.c |   19 ++++++++++++++-----
 1 files changed, 14 insertions(+), 5 deletions(-)

diff --git a/src/network.c b/src/network.c
index fc4cd01..6ee9af8 100644
--- a/src/network.c
+++ b/src/network.c
@@ -446,19 +446,28 @@ const char *connman_network_get_path(struct connman_network *network)
  */
 void connman_network_set_index(struct connman_network *network, int index)
 {
-	if (network->element.index < 0) {
-		struct connman_service *service;
+	struct connman_service *service;
 
+	service = __connman_service_lookup_from_network(network);
+	if (service == NULL)
+		goto done;
+
+	if (network->element.index < 0)
 		/*
 		 * This is needed for plugins that havent set their ipconfig
 		 * layer yet, due to not being able to get a network index
 		 * prior to creating a service.
 		 */
-		service = __connman_service_lookup_from_network(network);
-		if (service != NULL)
-			__connman_service_create_ipconfig(service, index);
+		__connman_service_create_ipconfig(service, index);
+	else {
+		struct connman_ipconfig *ipconfig;
+
+		/* If index changed, the index of ipconfig must be reset. */
+		ipconfig = __connman_service_get_ipconfig(service);
+		__connman_ipconfig_set_index(ipconfig, index);
 	}
 
+done:
 	network->element.index = index;
 }
 
-- 
1.6.1.3




More information about the connman mailing list