[PATCH 0/2] Device detection upon systemd-udev renaming

2014-04-29 Thread Eduardo Abinader
The following two patches are related somehow in the
scenario where wifi dongle is removed and inserted again,
and systemd-udev renames device. 
Sytemd-udev may have predefined device names, which does 
not necessarily follow kernel device sequential 
numbering. The renaming of the device causes the kernel 
to issue a new RTM_NEWLINK, but keeping same ifindex, thus 
falling in a scenario where connman is unable to handle 
currently. Observe there is no RTM_DELLINK message being 
issued in this rename action.

Patch(1/2): tried to rely on ifi_change, but I do not feel
secure to use it, as it is still stated to be set as
0xfff and reserved for future use, although have found
a pattern for the values filled in by rtnetlink by running and 
also taking a look at kernel code. 
(refer also to this link: 
https://lists.connman.net/pipermail/connman/2012-September/011232.html)

Patch(2/2): while preparing this patch, noticed segfault in 
scan_callback, when removing wifi dongle. Thus the second 
patch refers to this occurrence.

Eduardo Abinader (2):
  Don't ignore RTM_NEWLINK, when ifname has changed
  Avoid invalid read in scan_callback

 gsupplicant/supplicant.c |  3 +++
 include/device.h |  1 +
 src/detect.c | 15 +--
 src/device.c | 20 
 4 files changed, 37 insertions(+), 2 deletions(-)

-- 
1.9.1

___
connman mailing list
connman@connman.net
https://lists.connman.net/mailman/listinfo/connman


[PATCH 1/2] Don't ignore RTM_NEWLINK, when ifname has changed

2014-04-29 Thread Eduardo Abinader
Whenever systemd-udev renames a device, the orginal ifindex
is kept and consequently connman is unable to issue a proper
create interface to reflect such device change.
---
 include/device.h |  1 +
 src/detect.c | 15 +--
 src/device.c | 20 
 3 files changed, 34 insertions(+), 2 deletions(-)

diff --git a/include/device.h b/include/device.h
index 57b925c..9d4fa35 100644
--- a/include/device.h
+++ b/include/device.h
@@ -114,6 +114,7 @@ void connman_device_regdom_notify(struct connman_device 
*device,
 struct connman_device *connman_device_create_from_index(int index);
 struct connman_device *connman_device_find_by_index(int index);
 int connman_device_reconnect_service(struct connman_device *device);
+bool connman_device_ifname_changed(struct connman_device *device, int index);
 
 struct connman_device_driver {
const char *name;
diff --git a/src/detect.c b/src/detect.c
index 6c03920..2fc7f0a 100644
--- a/src/detect.c
+++ b/src/detect.c
@@ -43,6 +43,9 @@ static struct connman_device *find_device(int index)
return NULL;
 }
 
+static void detect_dellink(unsigned short type, int index,
+   unsigned flags, unsigned change);
+
 static void detect_newlink(unsigned short type, int index,
unsigned flags, unsigned change)
 {
@@ -67,8 +70,16 @@ static void detect_newlink(unsigned short type, int index,
}
 
device = find_device(index);
-   if (device)
-   return;
+   if (device) {
+   /*
+* Detect if device name has changed, despite same index
+* If so, proceed with dellink and new device registering.
+*/
+   if (!connman_device_ifname_changed(device, index))
+   return;
+   else
+   detect_dellink(type, index, flags, change);
+   }
 
device = connman_device_create_from_index(index);
if (!device)
diff --git a/src/device.c b/src/device.c
index f0b7a4f..789c586 100644
--- a/src/device.c
+++ b/src/device.c
@@ -1456,3 +1456,23 @@ void __connman_device_cleanup(void)
g_strfreev(nodevice_filter);
g_strfreev(device_filter);
 }
+
+bool connman_device_ifname_changed(struct connman_device *device, int index)
+{
+   char *ifname;
+   bool ret = false;
+
+   DBG();
+
+   ifname = connman_inet_ifname(index);
+   if (!ifname)
+   return ret;
+
+   if (strcmp(device-interface, ifname) != 0) {
+   ret = true;
+   }
+
+   g_free(ifname);
+
+   return ret;
+}
-- 
1.9.1

___
connman mailing list
connman@connman.net
https://lists.connman.net/mailman/listinfo/connman


[PATCH 2/2] Avoid invalid read in scan_callback

2014-04-29 Thread Eduardo Abinader
If a pending scan_callback is called after a dongle removal,
invalid reads occur in connman_device_reset_scanning, for
instance. This patch cleans the callback, before dbus remove
interface is returned.
---
 gsupplicant/supplicant.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/gsupplicant/supplicant.c b/gsupplicant/supplicant.c
index 9734e48..8a16663 100644
--- a/gsupplicant/supplicant.c
+++ b/gsupplicant/supplicant.c
@@ -745,6 +745,9 @@ void g_supplicant_interface_set_data(GSupplicantInterface 
*interface,
return;
 
interface-data = data;
+
+   if (!data)
+   interface-scan_callback = NULL;
 }
 
 void *g_supplicant_interface_get_data(GSupplicantInterface *interface)
-- 
1.9.1

___
connman mailing list
connman@connman.net
https://lists.connman.net/mailman/listinfo/connman