__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)
{
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__;
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;
}
}
__free_nl_cache_mgr(nl_data);
- __free_nl_cache(nl_data);
nl_data->obj_recv_func = NULL;
nl_data->user_data = NULL;
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);