Merge tag 'upstream/1.40' into tizen.
[platform/upstream/connman.git] / src / rtnl.c
old mode 100755 (executable)
new mode 100644 (file)
index 5690c48..40ede4f
@@ -159,6 +159,7 @@ static void read_uevent(struct interface_data *interface)
        if (__connman_rtnl_is_cellular_device(name)) {
                interface->service_type = CONNMAN_SERVICE_TYPE_CELLULAR;
                interface->device_type = CONNMAN_DEVICE_TYPE_CELLULAR;
+               g_free(name);
                return;
        }
 #endif
@@ -166,6 +167,7 @@ static void read_uevent(struct interface_data *interface)
        if (ether_blacklisted(name)) {
                interface->service_type = CONNMAN_SERVICE_TYPE_UNKNOWN;
                interface->device_type = CONNMAN_DEVICE_TYPE_UNKNOWN;
+               goto out;
        } else {
                interface->service_type = CONNMAN_SERVICE_TYPE_ETHERNET;
                interface->device_type = CONNMAN_DEVICE_TYPE_ETHERNET;
@@ -212,7 +214,12 @@ static void read_uevent(struct interface_data *interface)
                } else if (strcmp(line + 8, "vlan") == 0) {
                        interface->service_type = CONNMAN_SERVICE_TYPE_ETHERNET;
                        interface->device_type = CONNMAN_DEVICE_TYPE_ETHERNET;
-
+               } else if (strcmp(line + 8, "bond") == 0) {
+                       interface->service_type = CONNMAN_SERVICE_TYPE_ETHERNET;
+                       interface->device_type = CONNMAN_DEVICE_TYPE_ETHERNET;
+               } else if (strcmp(line + 8, "dsa") == 0) {
+                       interface->service_type = CONNMAN_SERVICE_TYPE_ETHERNET;
+                       interface->device_type = CONNMAN_DEVICE_TYPE_ETHERNET;
                } else {
                        interface->service_type = CONNMAN_SERVICE_TYPE_UNKNOWN;
                        interface->device_type = CONNMAN_DEVICE_TYPE_UNKNOWN;
@@ -459,6 +466,20 @@ static void process_newlink(unsigned short type, int index, unsigned flags,
        if (!extract_link(msg, bytes, &address, &ifname, &mtu, &operstate, &stats))
                return;
 
+#if defined TIZEN_EXT_WIFI_MESH
+       /* Do not accept Wi-Fi Mesh interface */
+       if (g_strrstr(ifname, "mesh") != NULL) {
+               DBG("Newlink event for Wi-Fi Mesh interface ignored");
+               return;
+       }
+
+       /* Do not accept Wi-Fi WLAN1 interface "dedicated for softAP */
+       if (!g_strcmp0(ifname, "wlan1")) {
+               DBG("Newlink event for Wi-Fi WLAN1 interface ignored");
+               return;
+       }
+#endif
+
 #if defined TIZEN_EXT
        /* Do not accept Wi-Fi P2P interface */
        if (g_strrstr(ifname, "p2p") != NULL) {
@@ -551,7 +572,9 @@ static void process_newlink(unsigned short type, int index, unsigned flags,
 
                interface = NULL;
 #endif
-       } else
+       } else if (type == ARPHRD_ETHER && interface->device_type == CONNMAN_DEVICE_TYPE_UNKNOWN)
+               read_uevent(interface);
+       else
                interface = NULL;
 
        for (list = rtnl_list; list; list = list->next) {
@@ -571,14 +594,15 @@ static void process_newlink(unsigned short type, int index, unsigned flags,
                __connman_technology_add_interface(interface->service_type,
                        interface->index, interface->ident);
 
-       for (list = watch_list; list; list = list->next) {
+       list = watch_list;
+       while (list) {
+               GSList *next = list->next;
                struct watch_data *watch = list->data;
 
-               if (watch->index != index)
-                       continue;
-
-               if (watch->newlink)
+               if (watch->index == index && watch->newlink)
                        watch->newlink(flags, change, watch->user_data);
+
+               list = next;
        }
 }
 
@@ -1355,12 +1379,17 @@ static void rtnl_newnduseropt(struct nlmsghdr *hdr)
 
                if (opt->nd_opt_type == 25) { /* ND_OPT_RDNSS */
                        char buf[40];
+#if defined TIZEN_EXT
+                       struct connman_service *service;
 
+                       service = __connman_service_lookup_from_index(index);
+                       DBG("service: %p\n",service);
+#endif
                        servers = rtnl_nd_opt_rdnss(opt, &lifetime,
-                                       &nr_servers);
+                                                               &nr_servers);
                        for (i = 0; i < nr_servers; i++) {
                                if (!inet_ntop(AF_INET6, servers + i, buf,
-                                                       sizeof(buf)))
+                                                               sizeof(buf)))
                                        continue;
 
 #if defined TIZEN_EXT
@@ -1372,8 +1401,9 @@ static void rtnl_newnduseropt(struct nlmsghdr *hdr)
                                                CONNMAN_IPCONFIG_TYPE_IPV6);
 #endif
                                connman_resolver_append_lifetime(index,
-                                               NULL, buf, lifetime);
+                                                       NULL, buf, lifetime);
                        }
+
                } else if (opt->nd_opt_type == 31) { /* ND_OPT_DNSSL */
                        g_free(domains);
 
@@ -1499,8 +1529,6 @@ static int process_response(guint32 seq)
 
 static void rtnl_message(void *buf, size_t len)
 {
-       DBG("buf %p len %zd", buf, len);
-
        while (len > 0) {
                struct nlmsghdr *hdr = buf;
                struct nlmsgerr *err;
@@ -1508,7 +1536,7 @@ static void rtnl_message(void *buf, size_t len)
                if (!NLMSG_OK(hdr, len))
                        break;
 
-               DBG("%s len %d type %d flags 0x%04x seq %d pid %d",
+               DBG("%s len %u type %u flags 0x%04x seq %u pid %u",
                                        type2string(hdr->nlmsg_type),
                                        hdr->nlmsg_len, hdr->nlmsg_type,
                                        hdr->nlmsg_flags, hdr->nlmsg_seq,
@@ -1562,8 +1590,15 @@ static gboolean netlink_event(GIOChannel *chan, GIOCondition cond, gpointer data
        ssize_t status;
        int fd;
 
+#if defined TIZEN_EXT
+       if (cond & (G_IO_NVAL | G_IO_HUP | G_IO_ERR)) {
+               __connman_rtnl_init(GIO_SOCKET_RETRY_COUNT);
+               return FALSE;
+       }
+#else /* TIZEN_EXT */
        if (cond & (G_IO_NVAL | G_IO_HUP | G_IO_ERR))
                return FALSE;
+#endif /* TIZEN_EXT */
 
        memset(buf, 0, sizeof(buf));
        memset(&nladdr, 0, sizeof(nladdr));
@@ -1576,11 +1611,21 @@ static gboolean netlink_event(GIOChannel *chan, GIOCondition cond, gpointer data
                if (errno == EINTR || errno == EAGAIN)
                        return TRUE;
 
+#if defined TIZEN_EXT
+               __connman_rtnl_init(GIO_SOCKET_RETRY_COUNT);
+#endif /* TIZEN_EXT */
                return FALSE;
        }
 
+#if defined TIZEN_EXT
+       if (status == 0) {
+               __connman_rtnl_init(GIO_SOCKET_RETRY_COUNT);
+               return FALSE;
+       }
+#else /* TIZEN_EXT */
        if (status == 0)
                return FALSE;
+#endif /* TIZEN_EXT */
 
        if (nladdr.nl_pid != 0) { /* not sent by kernel, ignore */
                DBG("Received msg from %u, ignoring it", nladdr.nl_pid);
@@ -1724,19 +1769,34 @@ int __connman_rtnl_request_update(void)
        return send_getlink();
 }
 
+#if defined TIZEN_EXT
+int __connman_rtnl_init(int retry_count)
+#else /* TIZEN_EXT */
 int __connman_rtnl_init(void)
+#endif /* TIZEN_EXT */
 {
        struct sockaddr_nl addr;
        int sk;
 
+#if defined TIZEN_EXT
+       if (retry_count < 0)
+               return -1;
+
+       DBG("retry_count %d", retry_count);
+#else /* TIZEN_EXT */
        DBG("");
+#endif /* TIZEN_EXT */
 
        interface_list = g_hash_table_new_full(g_direct_hash, g_direct_equal,
                                                        NULL, free_interface);
 
        sk = socket(PF_NETLINK, SOCK_DGRAM | SOCK_CLOEXEC, NETLINK_ROUTE);
        if (sk < 0)
+#if defined TIZEN_EXT
+               return __connman_rtnl_init(retry_count - 1);
+#else /* TIZEN_EXT */
                return -1;
+#endif /* TIZEN_EXT */
 
        memset(&addr, 0, sizeof(addr));
        addr.nl_family = AF_NETLINK;
@@ -1746,7 +1806,11 @@ int __connman_rtnl_init(void)
 
        if (bind(sk, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
                close(sk);
+#if defined TIZEN_EXT
+               return __connman_rtnl_init(retry_count - 1);
+#else /* TIZEN_EXT */
                return -1;
+#endif /* TIZEN_EXT */
        }
 
        channel = g_io_channel_unix_new(sk);