From 941b368b03f2fc26538bba3e7e4c9c36841b3456 Mon Sep 17 00:00:00 2001 From: nanger Date: Tue, 21 Aug 2018 09:54:07 +0800 Subject: Refactor: remove rd-table share memory DMM should not share rd table with protocol stack. Change-Id: I8e1afb708c9b785a382c157102ebbc228e550ea5 Signed-off-by: nanger --- CMakeLists.txt | 1 - src/adapt/nstack_dmm_adpt.c | 13 - src/adapt/nstack_rd_mng.c | 317 --------------------- src/adapt/nstack_rd_mng.h | 27 -- .../common/mem_mgr/nsfw_shmem/nsfw_shmem_mng.c | 1 + src/nSocket/nstack/nstack.c | 12 - src/nSocket/nstack/nstack_module.c | 2 - stacks/lwip_stack/lwip_src/api/spl_tcpip.c | 1 - .../lwip_stack/lwip_src/ip_module/container_ip.c | 36 --- stacks/lwip_stack/lwip_src/ip_module/network.c | 60 ---- 10 files changed, 1 insertion(+), 469 deletions(-) delete mode 100644 src/adapt/nstack_rd_mng.c delete mode 100644 src/adapt/nstack_rd_mng.h diff --git a/CMakeLists.txt b/CMakeLists.txt index cf17c75..7f91be0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -113,7 +113,6 @@ FILE(APPEND ${post_compile} cp -f ${CMAKE_CURRENT_LIST_DIR}/src/nSocket/include/nstack_dmm_api.h ${CMAKE_CURRENT_LIST_DIR}/release/include/ cp -f ${CMAKE_CURRENT_LIST_DIR}/src/adapt/nstack_dmm_adpt.h ${CMAKE_CURRENT_LIST_DIR}/release/include/ cp -f ${CMAKE_CURRENT_LIST_DIR}/src/adapt/nstack_share_res.h ${CMAKE_CURRENT_LIST_DIR}/release/include/ -cp -f ${CMAKE_CURRENT_LIST_DIR}/src/adapt/nstack_rd_mng.h ${CMAKE_CURRENT_LIST_DIR}/release/include/ cp -f ${CMAKE_CURRENT_LIST_DIR}/src/nSocket/include/declare_syscalls.h ${CMAKE_CURRENT_LIST_DIR}/release/include/ cp -f ${CMAKE_CURRENT_LIST_DIR}/src/framework/include/* ${CMAKE_CURRENT_LIST_DIR}/release/include/ cp -rf ${CMAKE_CURRENT_LIST_DIR}/src/framework/common/base/include/*.h ${CMAKE_CURRENT_LIST_DIR}/release/include/ diff --git a/src/adapt/nstack_dmm_adpt.c b/src/adapt/nstack_dmm_adpt.c index 637301b..652d0e2 100644 --- a/src/adapt/nstack_dmm_adpt.c +++ b/src/adapt/nstack_dmm_adpt.c @@ -32,7 +32,6 @@ extern "C" { #include "nstack_eventpoll.h" #include "nstack_dmm_api.h" #include "nstack_dmm_adpt.h" -#include "nstack_rd_mng.h" #include "mgr_com.h" int g_same_process = 1; @@ -173,12 +172,6 @@ nstack_adpt_init (nstack_dmm_para * para) NSFW_LOGERR ("nsep_create_memory failed"); return -1; } - - if (nstack_rd_mng_int (0) != 0) - { - NSFW_LOGERR ("nstack_rd_mng_int failed"); - return -1; - } } else { @@ -197,12 +190,6 @@ nstack_adpt_init (nstack_dmm_para * para) NSFW_LOGERR ("nsep_adpt_attach_memory failed"); return -1; } - - if (nstack_rd_mng_int (1) != 0) - { - NSFW_LOGERR ("nstack_rd_mng_int failed"); - return -1; - } } void *pret = diff --git a/src/adapt/nstack_rd_mng.c b/src/adapt/nstack_rd_mng.c deleted file mode 100644 index cb6a9b1..0000000 --- a/src/adapt/nstack_rd_mng.c +++ /dev/null @@ -1,317 +0,0 @@ -/* -* -* Copyright (c) 2018 Huawei Technologies Co.,Ltd. -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at: -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include -#include "nstack_rd_data.h" -#include "nsfw_mem_api.h" -#include "nstack_log.h" -#include "nstack_securec.h" - -#define RD_SHMEM_NAME "rd_table" - -#define RD_AGE_MAX_TIME 3 - -rd_route_table *g_rd_table_handle = NULL; - -#define RD_IP_ROUTE_CPY(pnode, name, data) { \ - if (EOK != STRCPY_S((pnode)->data.stack_name, RD_PLANE_NAMELEN, (name))) \ - { \ - NSSOC_LOGERR("STRCPY_S failed]copy_name=%s", name); \ - } \ - (pnode)->data.type = RD_DATA_TYPE_IP; \ - (pnode)->agetime = 0; \ - (pnode)->data.ipdata.addr = (data)->addr; \ - (pnode)->data.ipdata.masklen = (data)->masklen; \ - (pnode)->data.ipdata.resev[0] = 0; \ - (pnode)->data.ipdata.resev[1] = 0; \ -} - -/***************************************************************************** -* Prototype : nstack_rd_mng_int -* Description : rd mng module init, create a block memory -* Input : int flag -* Output : None -* Return Value : int -* Calls : -* Called By : nStackMain -*****************************************************************************/ -int -nstack_rd_mng_int (int flag) -{ - int ret; - nsfw_mem_zone zname = { - {NSFW_SHMEM, NSFW_PROC_MAIN, RD_SHMEM_NAME}, - sizeof (rd_route_table), - NSFW_SOCKET_ANY, - 0 - }; - NSSOC_LOGINF ("nstack rd mng init begin]flag=%d", flag); - /*nstack main create, app lookup */ - if (0 == flag) - { - g_rd_table_handle = (rd_route_table *) nsfw_mem_zone_create (&zname); - if (!g_rd_table_handle) - { - NSSOC_LOGERR ("mem create fail]mem name=%s", RD_SHMEM_NAME); - return -1; - } - ret = - MEMSET_S (&(g_rd_table_handle->node[0]), sizeof (rd_route_node), 0, - sizeof (rd_route_node)); - if (EOK != ret) - { - NSSOC_LOGERR ("MEMSET_S failed]ret=%d", ret); - return -1; - } - g_rd_table_handle->size = NSTACK_RD_DATA_MAX; - g_rd_table_handle->icnt = 0; - } - else /* static data will not be erased in fault case */ - { - g_rd_table_handle = - (rd_route_table *) nsfw_mem_zone_lookup (&(zname.stname)); - if (!g_rd_table_handle) - { - NSSOC_LOGERR ("mem lookup fail]mem name=%s", RD_SHMEM_NAME); - return -1; - } - } - NSSOC_LOGINF ("nstack rd mng init end flag"); - return 0; -} - -/***************************************************************************** -* Prototype : nstack_rd_ip_node_insert -* Description : insert a rd_ip_data into list -* Input : char *name -* rd_ip_data *data -* Output : None -* Return Value : int -* Calls : -* Called By : nStackMain -*****************************************************************************/ -int -nstack_rd_ip_node_insert (char *name, rd_ip_data * data) -{ - if (!g_rd_table_handle) - { - NSSOC_LOGERR ("nstack rd mng not inited"); - return -1; - } - int iindex = 0; - rd_route_node *pnode = NULL; - int agetime = 0; - int ageindex = -1; - int freeindex = -1; - int repeatflag = 0; - - for (iindex = 0; iindex < NSTACK_RD_DATA_MAX; iindex++) - { - pnode = &(g_rd_table_handle->node[iindex]); - /*record the index of first free element */ - if (RD_NODE_USELESS == pnode->flag) - { - if (-1 == freeindex) - { - freeindex = iindex; - NSSOC_LOGINF ("nstack rd ip free element index:%d was found", - iindex); - } - continue; - } - - /*if is using, and repeat just set flag */ - if (RD_NODE_USING == pnode->flag) - { - if (MASK_V (pnode->data.ipdata.addr, pnode->data.ipdata.masklen) == - MASK_V (data->addr, data->masklen)) - { - NSSOC_LOGWAR - ("nstack:%s, old_addr:0x%x index:%d new_addr:0x%x, masklen:%u was repeat", - name, pnode->data.ipdata.addr, iindex, data->addr, - data->masklen); - repeatflag = 1; - } - continue; - } - - /*if flag is deleting, just update the age time, if agetime is on, just set flag to free */ - if (RD_NODE_DELETING == pnode->flag) - { - pnode->agetime++; - if (pnode->agetime >= RD_AGE_MAX_TIME) - { - pnode->flag = RD_NODE_USELESS; - NSSOC_LOGINF - ("nstack rd ip element index:%d addr:0x%x, masklen:%u was delete and set to free", - iindex, pnode->data.ipdata.addr, pnode->data.ipdata.masklen); - } - /*record delete time */ - if (agetime < pnode->agetime) - { - agetime = pnode->agetime; - ageindex = iindex; - } - continue; - } - } - - /*if repeat, just return */ - if (1 == repeatflag) - { - return 0; - } - if (-1 == freeindex) - { - if (-1 != ageindex) - { - freeindex = ageindex; - } - else - { - NSSOC_LOGERR - ("the rd table is full,nstack:%s, rd addr:0x%x, masklen:%u can't be inserted", - name, data->addr, data->masklen); - return -1; - } - } - pnode = &(g_rd_table_handle->node[freeindex]); - /*if no free found, just reuse the big agetime */ - RD_IP_ROUTE_CPY (pnode, name, data); - pnode->flag = RD_NODE_USING; /*last set */ - g_rd_table_handle->icnt++; - NSSOC_LOGINF ("nstack:%s, rd addr:0x%x, masklen:%u index was inserted", - name, data->addr, data->masklen); - return 0; -} - -/***************************************************************************** -* Prototype : nstack_rd_ip_node_delete -* Description : rd data delete -* Input : rd_ip_data *data -* Output : None -* Return Value : int -* Calls : -* Called By : nStackMain -* just set delete flag, because -*****************************************************************************/ -int -nstack_rd_ip_node_delete (rd_ip_data * data) -{ - int iindex = 0; - rd_route_node *pnode = NULL; - - if (!g_rd_table_handle) - { - NSSOC_LOGERR ("nstack rd mng not inited"); - return -1; - } - - for (iindex = 0; iindex < NSTACK_RD_DATA_MAX; iindex++) - { - pnode = &(g_rd_table_handle->node[iindex]); - if ((RD_NODE_USING == pnode->flag) - && (MASK_V (pnode->data.ipdata.addr, pnode->data.ipdata.masklen) == - MASK_V (data->addr, data->masklen))) - { - pnode->flag = RD_NODE_DELETING; /*just set deleting state */ - pnode->agetime = 0; - g_rd_table_handle->icnt--; - NSSOC_LOGINF - ("nstack rd delete:%s, addr:0x%x, masklen:%u index:%d was delete", - pnode->data.stack_name, data->addr, data->masklen, iindex); - return 0; - } - } - NSSOC_LOGINF ("nstack rd delete, addr:0x%x, masklen:%u index was not found", - data->addr, data->masklen); - return 0; -} - -/***************************************************************************** -* Prototype : nstack_rd_ip_get -* Description : get rd data from rd table -* Input : char *planename -* rd_route_data **data -* int *num -* Output : None -* Return Value : int -* Calls : -* Called By : -* Note : a block memory was alloc and return by data, -* this need free by caller if return 0, otherwise no need -*****************************************************************************/ -int -nstack_rd_ip_get (rd_route_data ** data, int *num) -{ - rd_route_data *pdata = NULL; - rd_route_node *pnode = NULL; - int size = 0; - int icnt = 0; - int idex = 0; - int ret; - - if (!g_rd_table_handle || !data || !num) - { - NSSOC_LOGERR ("nstack rd mng not inited or input err"); - return -1; - } - size = sizeof (rd_route_data) * g_rd_table_handle->size; - pdata = (rd_route_data *) malloc (size); - if (!pdata) - { - NSSOC_LOGERR ("rd route data malloc fail"); - return -1; - } - ret = MEMSET_S (pdata, size, 0, size); - if (EOK != ret) - { - NSSOC_LOGERR ("MEMSET_S failed]ret=%d", ret); - free (pdata); - return -1; - } - for (icnt = 0; icnt < g_rd_table_handle->size; icnt++) - { - pnode = &(g_rd_table_handle->node[icnt]); - if (RD_NODE_USING == pnode->flag) - { - pdata[idex].type = pnode->data.type; - pdata[idex].ipdata.addr = pnode->data.ipdata.addr; - pdata[idex].ipdata.masklen = pnode->data.ipdata.masklen; - pdata[idex].ipdata.resev[0] = pnode->data.ipdata.resev[0]; - pdata[idex].ipdata.resev[1] = pnode->data.ipdata.resev[1]; - ret = - STRCPY_S (pdata[idex].stack_name, RD_PLANE_NAMELEN, - pnode->data.stack_name); - if (EOK != ret) - { - NSSOC_LOGERR ("STRCPY_S failed]ret=%d", ret); - free (pdata); - return -1; - } - idex++; - } - } - /*if no data fetched , just return fail */ - if (idex == 0) - { - free (pdata); - return -1; - } - *data = pdata; - *num = idex; - return 0; -} diff --git a/src/adapt/nstack_rd_mng.h b/src/adapt/nstack_rd_mng.h deleted file mode 100644 index f1fe7a3..0000000 --- a/src/adapt/nstack_rd_mng.h +++ /dev/null @@ -1,27 +0,0 @@ -/* -* -* Copyright (c) 2018 Huawei Technologies Co.,Ltd. -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at: -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#ifndef __NSTACK_RD_MNG_H -#define __NSTACK_RD_MNG_H -#include -#include "nstack_rd_data.h" - -int nstack_rd_mng_int (int flag); -int nstack_rd_ip_node_insert (char *name, rd_ip_data * data); -int nstack_rd_ip_node_delete (rd_ip_data * data); -int nstack_rd_ip_get (rd_route_data ** data, int *num); - -#endif diff --git a/src/framework/common/mem_mgr/nsfw_shmem/nsfw_shmem_mng.c b/src/framework/common/mem_mgr/nsfw_shmem/nsfw_shmem_mng.c index abd6ce0..5af828f 100644 --- a/src/framework/common/mem_mgr/nsfw_shmem/nsfw_shmem_mng.c +++ b/src/framework/common/mem_mgr/nsfw_shmem/nsfw_shmem_mng.c @@ -38,6 +38,7 @@ #define NSFW_SHMEM_FLAG (g_shmem_localdata->enflag) extern u8 app_mode; +u8 app_mode = 0; nsfw_mem_localdata *g_shmem_localdata = NULL; /*check g_mem_localdata*/ diff --git a/src/nSocket/nstack/nstack.c b/src/nSocket/nstack/nstack.c index 8718091..4b01961 100644 --- a/src/nSocket/nstack/nstack.c +++ b/src/nSocket/nstack/nstack.c @@ -34,7 +34,6 @@ #include "nstack_fd_mng.h" #include "nstack_info_parse.h" #include "nstack_dmm_adpt.h" -#include "nstack_rd_mng.h" #include "nstack_rd.h" #include "nstack_module.h" #include "nstack_select.h" @@ -447,16 +446,13 @@ nstack_init_shmem () NSTACK_STATIC int nstack_init_mem (void) { - int ret = ns_fail; - int initflag = 0; int deploytype = nstack_get_deploy_type (); /* record unmatched app version*/ /* check lib version match - Begin */ if (deploytype != NSTACK_MODEL_TYPE1 && deploytype != NSTACK_MODEL_TYPE_SIMPLE_STACK ) { check_main_version (); - initflag = 1; } ret = nstack_init_shmem (); @@ -466,14 +462,6 @@ nstack_init_mem (void) return ns_fail; } - /*stack-x rd mng init*/ - ret = nstack_rd_mng_int(initflag); - if (ns_success != ret) - { - NSSOC_LOGERR("nstack_rd_mng_int fail"); - return ns_fail; - } - /*rd info sys*/ ret = nstack_rd_sys(); if (ns_success != ret) diff --git a/src/nSocket/nstack/nstack_module.c b/src/nSocket/nstack/nstack_module.c index 91eda84..bef91e5 100644 --- a/src/nSocket/nstack/nstack_module.c +++ b/src/nSocket/nstack/nstack_module.c @@ -36,7 +36,6 @@ #include "nstack_dmm_adpt.h" #include "nstack_rd_init.h" #include "nstack_info_parse.h" -#include "nstack_rd_mng.h" /* *INDENT-OFF* */ nstack_module_info g_nstack_modules = { @@ -176,7 +175,6 @@ nstack_register_module () nstack_get_route_data rd_fun[] = { nstack_stack_rd_parse, - nstack_rd_ip_get }; pstacks = diff --git a/stacks/lwip_stack/lwip_src/api/spl_tcpip.c b/stacks/lwip_stack/lwip_src/api/spl_tcpip.c index 688c34b..b627bcf 100644 --- a/stacks/lwip_stack/lwip_src/api/spl_tcpip.c +++ b/stacks/lwip_stack/lwip_src/api/spl_tcpip.c @@ -134,7 +134,6 @@ u8_t ip_tos2prio[(IPTOS_TOS_MASK >> 1) + 1] = { /********************/ extern err_t ethernetif_init (struct netif *pnetif); extern int nstack_stackx_init (int flag); -extern int nstack_rd_mng_int (int flag); extern void tcp_sys_rmem_init (); extern void ethernetif_packets_input (struct netif *pstnetif); diff --git a/stacks/lwip_stack/lwip_src/ip_module/container_ip.c b/stacks/lwip_stack/lwip_src/ip_module/container_ip.c index 3cbe9b9..decc52c 100644 --- a/stacks/lwip_stack/lwip_src/ip_module/container_ip.c +++ b/stacks/lwip_stack/lwip_src/ip_module/container_ip.c @@ -28,7 +28,6 @@ #include "netif.h" #include "nstack_log.h" #include "nstack_securec.h" -#include "nstack_rd_mng.h" #include "config_common.h" #include "igmp.h" #include "spl_def.h" @@ -164,38 +163,6 @@ free_container_port_ip_cidr (struct container_port_ip_cidr *ip_cidr, } } -/*note:::the ip must be local order*/ -void -container_multicast_rd (unsigned int ip, int op) -{ - rd_ip_data rd_ip = { 0 }; - int ret = 0; - - rd_ip.addr = ip; - rd_ip.masklen = 32; - if (0 == op) - { - ret = nstack_rd_ip_node_insert ("nstack-dpdk", &rd_ip); - } - else - { - ret = nstack_rd_ip_node_delete (&rd_ip); - } - - if (0 != ret) - { - NSOPR_LOGERR ("nstack rd multicast ip:0x%x %s fail", ip, - (0 == op ? "insert" : "delete")); - } - else - { - NSOPR_LOGDBG ("nstack rd multicast ip:0x%x %s success", ip, - (0 == op ? "insert" : "delete")); - } - - return; -} - static void free_container_multicast (struct container_multicast_id *multicast, bool_t only_free) @@ -208,9 +175,6 @@ free_container_multicast (struct container_multicast_id *multicast, multicast = multicast->next; if (!only_free) { - /*note:::multicast ip is network, need to change to local order, delete multicast ip from rd. */ - container_multicast_rd (spl_ntohl (tmp->ip), 1); - trp_rb_erase ((void *) (u64_t) tmp->ip, &g_container_multicast_root, ip_compare); } diff --git a/stacks/lwip_stack/lwip_src/ip_module/network.c b/stacks/lwip_stack/lwip_src/ip_module/network.c index 83fbb7c..ef0d9a7 100644 --- a/stacks/lwip_stack/lwip_src/ip_module/network.c +++ b/stacks/lwip_stack/lwip_src/ip_module/network.c @@ -26,7 +26,6 @@ #include "stackx/spl_api.h" #include "sharedmemory.h" #include "nstack_securec.h" -#include "nstack_rd_mng.h" #include "spl_hal.h" #include "inet.h" @@ -441,59 +440,6 @@ nic_already_bond (struct network_configuration *pnetwork, return 0; } -/*add network to rd*/ -void -network_rd_proc (struct network_configuration *network, int op) -{ - struct ip_subnet *ptsubnet = NULL; - struct network_configuration *pn = NULL; - rd_ip_data rd_ip = { 0 }; - int ret = 0; - - pn = network; - - while (pn) - { - if (0 == strcmp ("nstack-dpdk", pn->type_name)) - { - ptsubnet = network->ip_subnet; - while (ptsubnet) - { - rd_ip.addr = ptsubnet->subnet; - rd_ip.masklen = ptsubnet->mask_len; - if (0 == op) - { - ret = nstack_rd_ip_node_insert (network->type_name, &rd_ip); - } - else - { - ret = nstack_rd_ip_node_delete (&rd_ip); - } - - if (0 != ret) - { - NSOPR_LOGERR ("nstack rd subnet:0x%x, masklen:0x%x %s fail", - rd_ip.addr, rd_ip.masklen, - (0 == op ? "insert" : "delete")); - } - else - { - NSOPR_LOGDBG - ("nstack rd subnet:0x%x, masklen:0x%x %s success", - rd_ip.addr, rd_ip.masklen, - (0 == op ? "insert" : "delete")); - } - - ptsubnet = ptsubnet->next; - } - } - - pn = pn->next; - } - - return; -} - /* add network to list in descending sort */ void add_network_to_list (struct network_configuration *network) @@ -503,9 +449,6 @@ add_network_to_list (struct network_configuration *network) network->next = NULL; - /*add network to rd */ - network_rd_proc (network, 0); - while (curr) { if (network->ip_subnet->mask_len >= curr->ip_subnet->mask_len) @@ -1089,9 +1032,6 @@ del_network_by_name (char *name) *ref = network->next; network->next = NULL; - /*delete netework from rd */ - network_rd_proc (network, 1); - free_network_configuration (network, IP_MODULE_FALSE); return 0; } -- cgit 1.2.3-korg