Remove unnecessary RTNL cache initialization 49/193549/2
authorYu <jiung.yu@samsung.com>
Thu, 22 Nov 2018 01:31:39 +0000 (10:31 +0900)
committerYu <jiung.yu@samsung.com>
Fri, 23 Nov 2018 05:26:15 +0000 (14:26 +0900)
Change-Id: I4ebbc009780a9b4c949309a2e91756893f0dd575
Signed-off-by: Yu Jiung <jiung.yu@samsung.com>
include/inm-util.h
src/inm-util.c

index f059a279d57d1a3730cf6680944643b5c5563223..5ba08f49b52cb5bf7ddc50b58bff227dc7015cbd 100644 (file)
@@ -119,8 +119,6 @@ typedef struct {
 } inm_util_icmp_data_s;
 
 typedef struct {
-       struct nl_sock *p_nl_sock;
-       struct nl_cache *p_nl_cache;
        struct nl_sock *p_nl_mgr_sock;
        struct nl_cache *p_nl_mgr_cache;
        struct nl_cache_mngr *p_nl_mgr;
index c67cadc8c3e6e1629bca1fcf41657ed6997dd5bd..da7681c089d7ac3a137e19f55840d62d43ceccc8 100644 (file)
@@ -876,114 +876,6 @@ static  void __rtnl_cache_change_cb(struct nl_cache *cache,
        __INM_FUNC_EXIT__;
 }
 
-static inline int __allocate_rtnl_cache_per_type(struct nl_sock *sk,
-               inm_util_rtnl_type_e type,
-               struct nl_cache **pp_nl_cache)
-{
-       int res = 0;
-       int ret = 0;
-
-       switch (type) {
-       case INM_UTIL_RTNL_TYPE_ADDR:
-       {
-               res = rtnl_addr_alloc_cache(sk, pp_nl_cache);
-               if (res < 0) {
-                       INM_LOGE("Failed to rtnl_addr_alloc_cache. [%s]", nl_geterror(res));
-                       ret = -1;
-               } else
-                       ret = 0;
-       }
-               break;
-       case INM_UTIL_RTNL_TYPE_LINK:
-       {
-#if LIBNL_VER_NUM >= 3
-               res = rtnl_link_alloc_cache(sk, AF_UNSPEC, pp_nl_cache);
-#else
-               res = rtnl_link_alloc_cache(sk, pp_nl_cache);
-#endif
-               if (res < 0) {
-                       INM_LOGE("Failed to rtnl_link_alloc_cache. [%s]", nl_geterror(res));
-                       ret = -1;
-               } else
-                       ret = 0;
-       }
-               break;
-       case INM_UTIL_RTNL_TYPE_NEIGH:
-       {
-               res = rtnl_neigh_alloc_cache(sk, pp_nl_cache);
-               if (res < 0) {
-                       INM_LOGE("Failed to rtnl_neigh_alloc_cache. [%s]", nl_geterror(res));
-                       ret = -1;
-               } else
-                       ret = 0;
-       }
-               break;
-       case INM_UTIL_RTNL_TYPE_ROUTE:
-       {
-               res = rtnl_route_alloc_cache(sk, AF_UNSPEC, 0, pp_nl_cache);
-               if (res < 0) {
-                       INM_LOGE("Failed to rtnl_route_alloc_cache. [%s]", nl_geterror(res));
-                       __INM_FUNC_EXIT__;
-                       ret = -1;
-               } else
-                       ret = 0;
-       }
-               break;
-       default:
-       {
-               INM_LOGW("Invalid type");
-               ret = -1;
-       }
-               break;
-       }
-
-       return ret;
-}
-
-static inline int __allocate_rtnl_cache(inm_util_nl_data_s *nl_data,
-               inm_util_rtnl_type_e type)
-{
-       struct nl_sock *p_nl_sock = NULL;
-       struct nl_cache *p_nl_cache = NULL;
-
-       int res;
-
-       __INM_FUNC_ENTER__;
-       if (!nl_data) {
-               INM_LOGW("Null data");
-               __INM_FUNC_EXIT__;
-               return 0;
-       }
-
-       p_nl_sock = nl_socket_alloc();
-       if (!p_nl_sock) {
-               INM_LOGE("Failed to create netlink socket.");
-               __INM_FUNC_EXIT__;
-               return -1;
-       }
-
-       res = nl_connect(p_nl_sock, NETLINK_ROUTE);
-       if (res < 0) {
-               INM_LOGE("Failed to connect netlink socket. [%s]", nl_geterror(res));
-               nl_socket_free(p_nl_sock);
-               __INM_FUNC_EXIT__;
-               return -1;
-       }
-
-       res = __allocate_rtnl_cache_per_type(p_nl_sock, type, &p_nl_cache);
-       if (res < 0) {
-               INM_LOGE("Failed to get cache");
-               nl_socket_free(p_nl_sock);
-               __INM_FUNC_EXIT__;
-               return -1;
-       }
-
-       nl_data->p_nl_sock = p_nl_sock;
-       nl_data->p_nl_cache = p_nl_cache;
-       __INM_FUNC_EXIT__;
-       return 0;
-}
-
 static gboolean __nl_cache_cb(GIOChannel *source,
                  GIOCondition condition, gpointer data)
 {
@@ -1123,27 +1015,6 @@ static inline int __allocate_nl_cache_mgr(inm_util_nl_data_s *nl_data,
        return 0;
 }
 
-static inline void __free_nl_cache(inm_util_nl_data_s *nl_data)
-{
-       __INM_FUNC_ENTER__;
-       if (!nl_data) {
-               INM_LOGW("Null data");
-               __INM_FUNC_EXIT__;
-               return;
-       }
-
-       INM_LOGI("free cache");
-       nl_cache_free(nl_data->p_nl_cache);
-       nl_data->p_nl_cache = NULL;
-
-       INM_LOGI("free sock");
-       nl_socket_free(nl_data->p_nl_sock);
-       nl_data->p_nl_sock = NULL;
-
-       __INM_FUNC_EXIT__;
-       return;
-}
-
 static inline void __free_nl_cache_mgr(inm_util_nl_data_s *nl_data)
 {
        __INM_FUNC_ENTER__;
@@ -1186,15 +1057,8 @@ int util_nl_data_create(inm_util_nl_data_s *nl_data,
                return 0;
        }
 
-       if (__allocate_rtnl_cache(nl_data, type) < 0) {
-               INM_LOGE("Failed to allocate rtnl cache");
-               __INM_FUNC_EXIT__;
-               return -1;
-       }
-
        if (__allocate_nl_cache_mgr(nl_data, type) < 0) {
                INM_LOGE("Failed to allocate nl cache mgr");
-               __free_nl_cache(nl_data);
                __INM_FUNC_EXIT__;
                return -1;
        }
@@ -1215,7 +1079,6 @@ void util_nl_data_destroy(inm_util_nl_data_s *nl_data)
        }
 
        __free_nl_cache_mgr(nl_data);
-       __free_nl_cache(nl_data);
 
        nl_data->obj_recv_func = NULL;
        nl_data->user_data = NULL;
@@ -1233,11 +1096,12 @@ void util_foreach_nl_data(inm_util_nl_data_s *nl_data,
        int i;
 
        __INM_FUNC_ENTER__;
-       if (!cb || !nl_data || !nl_data->p_nl_cache) {
+       if (!cb || !nl_data || !nl_data->p_nl_mgr_cache || !nl_data->p_nl_mgr) {
                INM_LOGW("Null data");
                __INM_FUNC_EXIT__;
                return;
        }
+
        /* TODO: this can be changed for nl 3.0 */
        p_nl_cache = nl_data->p_nl_mgr_cache;
        nl_cache_cnt = nl_cache_nitems(p_nl_cache);