diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/adapt/nstack_dmm_adpt.c | 13 | ||||
-rw-r--r-- | src/adapt/nstack_rd_mng.c | 317 | ||||
-rw-r--r-- | src/adapt/nstack_rd_mng.h | 27 | ||||
-rw-r--r-- | src/framework/common/mem_mgr/nsfw_shmem/nsfw_shmem_mng.c | 1 | ||||
-rw-r--r-- | src/nSocket/nstack/nstack.c | 12 | ||||
-rw-r--r-- | src/nSocket/nstack/nstack_module.c | 2 |
6 files changed, 1 insertions, 371 deletions
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 <stdlib.h> -#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 <stdlib.h> -#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 = |