summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJukka Rissanen <jukka.rissanen@linux.intel.com>2012-07-09 12:24:48 +0300
committerMarcel Holtmann <marcel@holtmann.org>2012-07-09 09:30:50 -0300
commit8b31871f2dd8210c6d40f90be456ccfbf790bd36 (patch)
treedc77464f060dd3c6d3e1ece73f278839174627a7 /src
parentdebd3f4f9865fdd5a998a3845c42fb1d415ceef6 (diff)
downloadconnman-8b31871f2dd8210c6d40f90be456ccfbf790bd36.tar.gz
connman-8b31871f2dd8210c6d40f90be456ccfbf790bd36.tar.bz2
connman-8b31871f2dd8210c6d40f90be456ccfbf790bd36.zip
device: Turn off all running interfaces at startup
Turning off running interfaces that have IP address, causes all routes related to those interfaces to be removed by kernel. This way connman will get a fresh start without any extra and obsolete routes around.
Diffstat (limited to 'src')
-rw-r--r--src/device.c50
1 files changed, 50 insertions, 0 deletions
diff --git a/src/device.c b/src/device.c
index ec732b83..75fa7f7c 100644
--- a/src/device.c
+++ b/src/device.c
@@ -1186,6 +1186,54 @@ list:
return FALSE;
}
+static void cleanup_devices(void)
+{
+ /*
+ * Check what interfaces are currently up and if connman is
+ * suppose to handle the interface, then cleanup the mess
+ * related to that interface. There might be weird routes etc
+ * that are related to that interface and that might confuse
+ * connmand. So in this case we just turn the interface down
+ * so that kernel removes routes/addresses automatically and
+ * then proceed the startup.
+ *
+ * Note that this cleanup must be done before rtnl/detect code
+ * has activated interface watches.
+ */
+
+ char **interfaces;
+ int i;
+
+ interfaces = __connman_inet_get_running_interfaces();
+
+ if (interfaces == NULL)
+ return;
+
+ for (i = 0; interfaces[i] != NULL; i++) {
+ connman_bool_t filtered;
+ int index;
+
+ filtered = __connman_device_isfiltered(interfaces[i]);
+ if (filtered == TRUE)
+ continue;
+
+ index = connman_inet_ifindex(interfaces[i]);
+ if (index < 0)
+ continue;
+
+ DBG("cleaning up %s index %d", interfaces[i], index);
+
+ connman_inet_ifdown(index);
+
+ /*
+ * ConnMan will turn the interface UP automatically so
+ * no need to do it here.
+ */
+ }
+
+ g_strfreev(interfaces);
+}
+
int __connman_device_init(const char *device, const char *nodevice)
{
DBG("");
@@ -1196,6 +1244,8 @@ int __connman_device_init(const char *device, const char *nodevice)
if (nodevice != NULL)
nodevice_filter = g_strsplit(nodevice, ",", -1);
+ cleanup_devices();
+
return 0;
}