Fix bridge and WiMAX device detection
[connman] / plugins / rtnllink.c
index 14bb343..b0ed247 100644 (file)
@@ -39,7 +39,6 @@
 
 #include "inet.h"
 
-static GStaticMutex device_mutex = G_STATIC_MUTEX_INIT;
 static GSList *device_list = NULL;
 
 static void rtnllink_newlink(unsigned short type, int index,
@@ -49,12 +48,10 @@ static void rtnllink_newlink(unsigned short type, int index,
        struct connman_element *device;
        GSList *list;
        gboolean exists = FALSE;
-       gchar *name;
+       gchar *name, *devname;
 
        DBG("index %d", index);
 
-       g_static_mutex_lock(&device_mutex);
-
        for (list = device_list; list; list = list->next) {
                struct connman_element *device = list->data;
 
@@ -64,12 +61,11 @@ static void rtnllink_newlink(unsigned short type, int index,
                }
        }
 
-       g_static_mutex_unlock(&device_mutex);
-
        if (exists == TRUE)
                return;
 
-       name = inet_index2name(index);
+       name = inet_index2ident(index, "dev_");
+       devname = inet_index2name(index);
 
        if (type == ARPHRD_ETHER) {
                char bridge_path[PATH_MAX], wimax_path[PATH_MAX];
@@ -78,12 +74,12 @@ static void rtnllink_newlink(unsigned short type, int index,
                int sk;
 
                snprintf(bridge_path, PATH_MAX,
-                                       "/sys/class/net/%s/bridge", name);
+                                       "/sys/class/net/%s/bridge", devname);
                snprintf(wimax_path, PATH_MAX,
-                                       "/sys/class/net/%s/wimax", name);
+                                       "/sys/class/net/%s/wimax", devname);
 
                memset(&iwr, 0, sizeof(iwr));
-               strncpy(iwr.ifr_ifrn.ifrn_name, name, IFNAMSIZ);
+               strncpy(iwr.ifr_ifrn.ifrn_name, devname, IFNAMSIZ);
 
                sk = socket(PF_INET, SOCK_DGRAM, 0);
 
@@ -112,13 +108,10 @@ static void rtnllink_newlink(unsigned short type, int index,
 
        device->index = index;
        device->name = name;
-
-       g_static_mutex_lock(&device_mutex);
+       device->devname = devname;
 
        connman_element_register(device, NULL);
        device_list = g_slist_append(device_list, device);
-
-       g_static_mutex_unlock(&device_mutex);
 }
 
 static void rtnllink_dellink(unsigned short type, int index,
@@ -128,8 +121,6 @@ static void rtnllink_dellink(unsigned short type, int index,
 
        DBG("index %d", index);
 
-       g_static_mutex_lock(&device_mutex);
-
        for (list = device_list; list; list = list->next) {
                struct connman_element *device = list->data;
 
@@ -140,8 +131,6 @@ static void rtnllink_dellink(unsigned short type, int index,
                        break;
                }
        }
-
-       g_static_mutex_unlock(&device_mutex);
 }
 
 static struct connman_rtnl rtnllink_rtnl = {
@@ -169,8 +158,6 @@ static void rtnllink_exit(void)
 
        connman_rtnl_unregister(&rtnllink_rtnl);
 
-       g_static_mutex_lock(&device_mutex);
-
        for (list = device_list; list; list = list->next) {
                struct connman_element *device = list->data;
 
@@ -180,9 +167,7 @@ static void rtnllink_exit(void)
 
        g_slist_free(device_list);
        device_list = NULL;
-
-       g_static_mutex_unlock(&device_mutex);
 }
 
-CONNMAN_PLUGIN_DEFINE("rtnllink", "RTNL link detection plugin", VERSION,
+CONNMAN_PLUGIN_DEFINE(rtnllink, "RTNL link detection plugin", VERSION,
                                                rtnllink_init, rtnllink_exit)