X-Git-Url: https://vcs.maemo.org/git/?a=blobdiff_plain;f=plugins%2Frtnllink.c;h=8ac071587d682ba2bb854e03a347996fff1489d1;hb=899be488360ad24f079bbb204dc32a47c6aae093;hp=14bb34374823448eb2675049dfbc2d9950415ce3;hpb=6578ac5c8229d509af2347a77f806e6818599518;p=connman diff --git a/plugins/rtnllink.c b/plugins/rtnllink.c index 14bb343..8ac0715 100644 --- a/plugins/rtnllink.c +++ b/plugins/rtnllink.c @@ -33,43 +33,42 @@ #include #include -#include +#include #include #include #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, - unsigned flags, unsigned change) +static struct connman_device *find_device(int index) { - enum connman_element_subtype subtype = CONNMAN_ELEMENT_SUBTYPE_UNKNOWN; - struct connman_element *device; GSList *list; - gboolean exists = FALSE; - gchar *name; - - DBG("index %d", index); - - g_static_mutex_lock(&device_mutex); for (list = device_list; list; list = list->next) { - struct connman_element *device = list->data; + struct connman_device *device = list->data; - if (device->index == index) { - exists = TRUE; - break; - } + if (connman_device_get_index(device) == index) + return device; } - g_static_mutex_unlock(&device_mutex); + return NULL; +} - if (exists == TRUE) +static void rtnllink_newlink(unsigned short type, int index, + unsigned flags, unsigned change) +{ + enum connman_device_type devtype = CONNMAN_DEVICE_TYPE_UNKNOWN; + struct connman_device *device; + gchar *name, *devname; + + DBG("index %d", index); + + device = find_device(index); + if (device != NULL) return; - name = inet_index2name(index); + devname = inet_index2name(index); if (type == ARPHRD_ETHER) { char bridge_path[PATH_MAX], wimax_path[PATH_MAX]; @@ -78,70 +77,72 @@ 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); - if (g_str_has_prefix(name, "bnep") == TRUE) - subtype = CONNMAN_ELEMENT_SUBTYPE_UNKNOWN; + if (g_str_has_prefix(devname, "bnep") == TRUE) + devtype = CONNMAN_DEVICE_TYPE_UNKNOWN; else if (stat(bridge_path, &st) == 0 && (st.st_mode & S_IFDIR)) - subtype = CONNMAN_ELEMENT_SUBTYPE_UNKNOWN; + devtype = CONNMAN_DEVICE_TYPE_UNKNOWN; else if (stat(wimax_path, &st) == 0 && (st.st_mode & S_IFDIR)) - subtype = CONNMAN_ELEMENT_SUBTYPE_WIMAX; + devtype = CONNMAN_DEVICE_TYPE_WIMAX; else if (ioctl(sk, SIOCGIWNAME, &iwr) == 0) - subtype = CONNMAN_ELEMENT_SUBTYPE_UNKNOWN; + devtype = CONNMAN_DEVICE_TYPE_UNKNOWN; else - subtype = CONNMAN_ELEMENT_SUBTYPE_ETHERNET; + devtype = CONNMAN_DEVICE_TYPE_ETHERNET; close(sk); } - if (subtype == CONNMAN_ELEMENT_SUBTYPE_UNKNOWN) { + if (devtype == CONNMAN_DEVICE_TYPE_UNKNOWN) { + g_free(devname); + return; + } + + name = inet_index2ident(index, "dev_"); + + device = connman_device_create(name, devtype); + if (device == NULL) { + g_free(devname); g_free(name); return; } - device = connman_element_create(NULL); - device->type = CONNMAN_ELEMENT_TYPE_DEVICE; - device->subtype = subtype; + connman_device_set_index(device, index); + connman_device_set_interface(device, devname); - device->index = index; - device->name = name; + g_free(devname); + g_free(name); - g_static_mutex_lock(&device_mutex); + if (connman_device_register(device) < 0) { + connman_device_unref(device); + return; + } - 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, unsigned flags, unsigned change) { - GSList *list; + struct connman_device *device; DBG("index %d", index); - g_static_mutex_lock(&device_mutex); + device = find_device(index); + if (device == NULL) + return; - for (list = device_list; list; list = list->next) { - struct connman_element *device = list->data; - - if (device->index == index) { - device_list = g_slist_remove(device_list, device); - connman_element_unregister(device); - connman_element_unref(device); - break; - } - } + device_list = g_slist_remove(device_list, device); - g_static_mutex_unlock(&device_mutex); + connman_device_unregister(device); + connman_device_unref(device); } static struct connman_rtnl rtnllink_rtnl = { @@ -169,20 +170,16 @@ 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; + struct connman_device *device = list->data; - connman_element_unregister(device); - connman_element_unref(device); + connman_device_unregister(device); + connman_device_unref(device); } 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)