Merge "Imported Upstream connman version 1.38" into tizen
[platform/upstream/connman.git] / src / rtnl.c
index d733288..7c8c68b 100644 (file)
@@ -167,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;
@@ -590,14 +591,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;
        }
 }
 
@@ -1381,10 +1383,10 @@ static void rtnl_newnduseropt(struct nlmsghdr *hdr)
                        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
@@ -1396,7 +1398,7 @@ 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 */
@@ -1531,7 +1533,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,
@@ -1585,8 +1587,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));
@@ -1599,11 +1608,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);
@@ -1747,19 +1766,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;
@@ -1769,7 +1803,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);