diff options
Diffstat (limited to 'src/nSocket/nstack_rd/nstack_rd.c')
-rw-r--r-- | src/nSocket/nstack_rd/nstack_rd.c | 776 |
1 files changed, 518 insertions, 258 deletions
diff --git a/src/nSocket/nstack_rd/nstack_rd.c b/src/nSocket/nstack_rd/nstack_rd.c index 650f165..0c7d127 100644 --- a/src/nSocket/nstack_rd/nstack_rd.c +++ b/src/nSocket/nstack_rd/nstack_rd.c @@ -15,58 +15,72 @@ */ #include <stdlib.h> -#include <sys/socket.h> -#include <netinet/in.h> -#include <arpa/inet.h> #include "nstack_rd.h" -#include "nstack_rd_init.h" #include "nstack_rd_priv.h" #include "nstack_rd_ip.h" +#include "nstack_rd_ip6.h" +#include "nstack_rd_type.h" #include "nstack_rd_proto.h" #include "nstack_log.h" -#include "nstack_info_parse.h" #include "nstack_securec.h" +#include <arpa/inet.h> -typedef struct __rd_data_defaut_ip -{ - char ip[RD_IP_STR_MAX_LEN]; - char stackname[RD_PLANE_NAMELEN]; - int masklent; -} rd_data_defaut_ip; +extern rd_route_table *g_rd_table_handle[]; -typedef struct __rd_data_defaut_protocol -{ - unsigned int proto_type; - char stackname[RD_PLANE_NAMELEN]; -} rd_data_defaut_protocol; +rd_local_data *g_rd_local_data = NULL; rd_data_proc g_rd_cpy[RD_DATA_TYPE_MAX] = { - { - nstack_rd_ipdata_cpy, - nstack_rd_ip_item_insert, - nstack_rd_ip_item_age, - nstack_rd_ip_item_find, - nstack_rd_ip_spec, - nstack_rd_ip_default, - }, - { - nstack_rd_proto_cpy, - nstack_rd_proto_item_insert, - nstack_rd_proto_item_age, - nstack_rd_proto_item_find, - nstack_rd_proto_spec, - nstack_rd_proto_default, - }, + { + nstack_rd_ip_data_cpy, + nstack_rd_ip_item_insert, + nstack_rd_ip_item_age, + nstack_rd_ip_item_clean, + nstack_rd_ip_item_find, + nstack_rd_ip_spec, + }, + { + nstack_rd_ip6_data_cpy, + nstack_rd_ip6_item_insert, + nstack_rd_ip6_item_age, + nstack_rd_ip6_item_clean, + nstack_rd_ip6_item_find, + nstack_rd_ip6_spec, + }, + { + nstack_rd_type_data_cpy, + nstack_rd_type_item_insert, + nstack_rd_type_item_age, + nstack_rd_type_item_clean, + nstack_rd_type_item_find, + nstack_rd_type_spec, + }, + { + nstack_rd_proto_data_cpy, + nstack_rd_proto_item_insert, + nstack_rd_proto_item_age, + nstack_rd_proto_item_clean, + nstack_rd_proto_item_find, + nstack_rd_proto_spec, + } }; -rd_data_defaut_ip g_default_ip_config[] = { - {{"127.0.0.1"}, {RD_KERNEL}, 32}, - {{"0.0.0.0"}, {RD_KERNEL}, 32}, -}; +int nstack_choose_highest_prio() +{ + int i; + int ret = 0; + int highest = 0x7FFFFFFF; + nstack_rd_stack_info *stack_info = g_rd_local_data->pstack_info; -rd_data_defaut_protocol g_default_protcol[] = { - {0xf001, {RD_LWIP}}, -}; + for (i = 0; i < NSTACK_NUM; i++) + { + if (stack_info[i].priority < highest) + { + highest = stack_info[i].priority; + ret = i; + } + } + return ret; +} /***************************************************************************** * Prototype : nstack_rd_get_stackid @@ -78,256 +92,414 @@ rd_data_defaut_protocol g_default_protcol[] = { * Calls : * Called By : *****************************************************************************/ -int -nstack_rd_get_stackid (nstack_rd_key * pkey, int *stackid) +int nstack_rd_get_stackid(nstack_rd_key * pkey, rd_data_item * item) { - int type = 0; - int ret = NSTACK_RD_SUCCESS; - rd_data_item item; - if ((!pkey) || (!stackid) || (pkey->type >= RD_DATA_TYPE_MAX)) + int accumulate = 0; + int icnt = 0; + int type = 0; + int ret = NSTACK_RD_SUCCESS; + int rdtbl_ver = 0; + if ((!pkey) || (!item) || (pkey->type >= RD_DATA_TYPE_MAX)) { - NSSOC_LOGERR ("input get stackid fail]addr=%p,stackid=%p,addr->type=%d", - pkey, stackid, !pkey ? RD_DATA_TYPE_MAX : pkey->type); - return NSTACK_RD_FAIL; + NSSOC_LOGERR("input get stackid fail]addr=%p,item=%p,addr->type=%d", + pkey, item, !pkey ? RD_DATA_TYPE_MAX : pkey->type); + return NSTACK_RD_FAIL; } - int retVal = MEMSET_S (&item, sizeof (item), 0, sizeof (item)); - if (EOK != retVal) + /*add return value check */ + int retVal = + memset_s(item, sizeof(rd_data_item), 0, sizeof(rd_data_item)); + if (EOK != retVal) { - NSSOC_LOGERR ("MEMSET_S failed]retVal=%d", retVal); - return NSTACK_RD_FAIL; + NSSOC_LOGERR("memset_s failed]retVal=%d", retVal); + return NSTACK_RD_FAIL; } - type = pkey->type; + item->stack_id = -1; + type = pkey->type; - /*specfic key find, for ip example: stack-x was chose if the key is multicast ip */ - if (g_rd_cpy[type].rd_item_spec) + /*specfic key find, for ip example: stackpool was chose if the key is multicast ip */ + if (g_rd_cpy[type].rd_item_spec) { - ret = g_rd_cpy[type].rd_item_spec ((void *) pkey); - if (ret >= 0) + ret = g_rd_cpy[type].rd_item_spec((void *) pkey); + if (ret >= 0) { - *stackid = ret; - return NSTACK_RD_SUCCESS; + item->stack_id = ret; + return NSTACK_RD_SUCCESS; } } - /*search the list */ - ret = - g_rd_cpy[type].rd_item_find (NSTACK_RD_LIST (type), (void *) pkey, &item); - if (NSTACK_RD_SUCCESS == ret) + /*check ver */ + for (icnt = 0; icnt < NSTACK_NUM; icnt++) { - NSSOC_LOGDBG ("item type=%d stackid=%d was found", pkey->type, - item.stack_id); - *stackid = item.stack_id; - return NSTACK_RD_SUCCESS; + retVal = + g_rd_local_data->rdtbl_ver_get_fun(&rdtbl_ver, + g_rd_table_handle[icnt]); + if (retVal) + { + NSSOC_LOGWAR("stackid=%d get rd table ver failed!", + g_rd_local_data->pstack_info->stack_id); + if (++accumulate < NSTACK_NUM) + { + continue; + } + NSSOC_LOGERR("rd table ver get failed"); + return NSTACK_RD_FAIL; + } + if (g_rd_local_data->rdlocal_ver[icnt] != rdtbl_ver) + { + NSSOC_LOGINF + ("RD table ver unmatch]new rd tlbver:%d,local rd tblver:%d,resync now", + rdtbl_ver, g_rd_local_data->rdlocal_ver[icnt]); + ret = nstack_rd_sys(); + if (ret != NSTACK_RD_SUCCESS) + { + item->stack_id = nstack_choose_highest_prio(); + NSSOC_LOGERR + ("sync RD INF failed, choose highest priority stack, stackid=%d", + item->stack_id); + return NSTACK_RD_SUCCESS; + } + } } - if (g_rd_cpy[type].rd_item_default) + + /*search the list */ + ret = + g_rd_cpy[type].rd_item_find(NSTACK_RD_LIST(type), (void *) pkey, + item); + if (NSTACK_RD_SUCCESS == ret) { - *stackid = g_rd_cpy[type].rd_item_default ((void *) pkey); + NSSOC_LOGDBG("item type=%d stackid=%d was found", pkey->type, + item->stack_id); + return NSTACK_RD_SUCCESS; } - else + item->stack_id = nstack_choose_highest_prio(); + NSSOC_LOGINF + ("item type=%d was not found, choose highest priority stack by default, stackid=%d", + pkey->type, item->stack_id); + return NSTACK_RD_SUCCESS; +} + +static char *nstack_rd_parse_ip(char *pos, unsigned int *ip) +{ + char buf[16]; + char *p; + int len, ret; + + if (!pos) + return NULL; + + p = strchr(pos, '/'); + if (!p) + return NULL; + + len = p - pos; + if (len >= 16) + return NULL; + + ret = memcpy_s(buf, sizeof(buf), pos, len); + if (EOK != ret) { - *stackid = -1; + return NULL; } - NSSOC_LOGINF ("item type=%d was not found, return default=%d", pkey->type, - *stackid); - return NSTACK_RD_SUCCESS; + + buf[len] = 0; + + ret = inet_pton(AF_INET, buf, ip); + if (ret == 1) + return p + 1; + + return NULL; + } -/***************************************************************************** -* Prototype : nstack_rd_sys_default -* Description : sys default rd info, -* Input : None -* Output : None -* Return Value : int -* Calls : -* Called By : -******************************************************************************/ -void -nstack_rd_sys_default () +static char *nstack_rd_parse_ip6(char *pos, unsigned int ip[4]) +{ + char buf[46]; + char *p; + int len, ret; + + p = strchr(pos, '/'); + if (!p) + return NULL; + + len = p - pos; + if (len >= 46) + return NULL; + + (void) memcpy_s(buf, sizeof(buf), pos, len); + buf[len] = 0; + + ret = inet_pton(AF_INET6, buf, ip); + if (ret == 1) + return p + 1; + + return NULL; +} + +static char *nstack_rd_parse_stackid(char *pos, int *stack_id) { - rd_data_item item; - rd_data_defaut_ip *pdata = NULL; - rd_data_defaut_protocol *pprotodata = NULL; - int icnt = 0, iindex = 0; - int stack_num = 0; + size_t n = 0; + int i; - stack_num = g_rd_local_data->stack_num; + while (pos[n] != ':' && pos[n] != 0) + n++; + if (n == 0 || n >= RD_PLANE_NAMELEN) + return NULL; - /*get the ip default route */ - for (icnt = 0; - icnt < sizeof (g_default_ip_config) / sizeof (rd_data_defaut_ip); - icnt++) + for (i = 0; i < g_rd_local_data->stack_num; ++i) { - pdata = &g_default_ip_config[icnt]; - for (iindex = 0; iindex < stack_num; iindex++) + /* params are not NULL */ + if (0 == strncmp(pos, g_rd_local_data->pstack_info[i].name, n)) { - if (0 == - strcmp (g_rd_local_data->pstack_info[iindex].name, - pdata->stackname)) - { - item.stack_id = g_rd_local_data->pstack_info[iindex].stack_id; - break; - } + *stack_id = g_rd_local_data->pstack_info[i].stack_id; + return pos + n; } - if (iindex >= stack_num) + } + + return NULL; +} + +static void nstack_rd_sys_load_default() +{ + char *env, *pos; + + env = getenv("NSTACK_RD"); /*this func can be used */ + + if (!env || !env[0]) + return; + + pos = env; + while (*pos) + { + rd_data_item item; + char *pos6 = pos; + + pos = nstack_rd_parse_ip(pos, &item.ipdata.addr); + if (pos) { - NSSOC_LOGINF - ("default stack name:%s was not fount, ip:%s msklen:%d was dropped", - pdata->stackname, pdata->ip, pdata->masklent); - continue; + item.type = RD_DATA_TYPE_IP; + item.agetime = NSTACK_RD_AGETIME_MAX; + item.ipdata.resev[0] = 0; + item.ipdata.resev[1] = 0; + item.ipdata.masklen = (unsigned int) strtoul(pos, &pos, 10); + if (item.ipdata.masklen > 32 || *pos++ != '=') + { + NSSOC_LOGERR("nstack rd sys config error '%s'", env); + return; + } } - item.type = RD_DATA_TYPE_IP; - item.ipdata.addr = ntohl (inet_addr (pdata->ip)); - item.ipdata.masklen = pdata->masklent; - item.ipdata.resev[0] = 0; - item.ipdata.resev[1] = 0; - item.agetime = NSTACK_RD_AGETIME_MAX; - /*insert to the list */ - g_rd_cpy[RD_DATA_TYPE_IP].rd_item_inset (NSTACK_RD_LIST - (RD_DATA_TYPE_IP), &item); - } - - /*get the protocol default route */ - (void) MEMSET_S (&item, sizeof (item), 0, sizeof (item)); - for (icnt = 0; - icnt < sizeof (g_default_protcol) / sizeof (rd_data_defaut_protocol); - icnt++) - { - pprotodata = &g_default_protcol[icnt]; - for (iindex = 0; iindex < stack_num; iindex++) + else if (NULL != + (pos = nstack_rd_parse_ip6(pos6, item.ip6data.addr.addr32))) { - if (0 == - strcmp (g_rd_local_data->pstack_info[iindex].name, - pprotodata->stackname)) + item.type = RD_DATA_TYPE_IP6; + item.agetime = NSTACK_RD_AGETIME_MAX; + item.ip6data.masklen = (unsigned int) strtoul(pos, &pos, 10); + if (item.ip6data.masklen > 128 || *pos++ != '=') { - item.stack_id = g_rd_local_data->pstack_info[iindex].stack_id; - break; + NSSOC_LOGERR("nstack rd sys config error '%s'", env); + return; } } - if (iindex >= stack_num) + else { - NSSOC_LOGINF - ("default stack name:%s was not fount, protocoltype:%d was dropped", - pprotodata->stackname, pprotodata->proto_type); - continue; + NSSOC_LOGERR("nstack rd sys config error '%s'", env); + return; } - item.type = RD_DATA_TYPE_PROTO; - item.proto_type = pprotodata->proto_type; - /*insert to the list */ - g_rd_cpy[RD_DATA_TYPE_PROTO].rd_item_inset (NSTACK_RD_LIST - (RD_DATA_TYPE_PROTO), + + pos = nstack_rd_parse_stackid(pos, &item.stack_id); + if (!pos) + { + NSSOC_LOGERR("nstack rd sys config error '%s'", env); + return; + } + + (void) g_rd_cpy[item.type].rd_item_insert(NSTACK_RD_LIST(item.type), &item); - } - return; -} -/***************************************************************************** -* Prototype : nstack_rd_save -* Description : save the rd data -* Input : None -* Output : None -* Return Value : int -* Calls : -* Called By : -*****************************************************************************/ -void -nstack_rd_save (rd_route_data * rd_data, int num) -{ - int icnt = 0; - int iindex = 0; - int stack_num = 0; - rd_data_item item; - rd_data_type type = RD_DATA_TYPE_MAX; + if (item.type == RD_DATA_TYPE_IP6) + { + char buf[46]; + NSSOC_LOGINF("insert one RD %d=%s/%u", item.stack_id, + inet_ntop(AF_INET6, &item.ip6data.addr, buf, + sizeof(buf)), item.ip6data.masklen); + } + else + { + NSSOC_LOGINF("insert one RD %d:%u.%u.%u.%u/%u", item.stack_id, + item.ipdata.addr >> 24, + (item.ipdata.addr >> 16) & 255, + (item.ipdata.addr >> 8) & 255, + item.ipdata.addr & 255, item.ipdata.masklen); + } - int retVal = MEMSET_S (&item, sizeof (item), 0, sizeof (item)); - if (EOK != retVal) - { - NSSOC_LOGERR ("MEMSET_S failed]retVal=%d", retVal); - return; + if (*pos == ':') + pos++; } +} - stack_num = g_rd_local_data->stack_num; - - for (iindex = 0; iindex < num; iindex++) +static void nstack_rd_sys_clean() +{ + int type; + for (type = 0; type < RD_DATA_TYPE_MAX; type++) { - if (rd_data[iindex].type >= RD_DATA_TYPE_MAX) + if (!hlist_empty(&(NSTACK_RD_LIST(type)->headlist))) { - NSSOC_LOGERR ("rd data type=%d unkown", rd_data[iindex].type); - continue; + g_rd_cpy[type].rd_item_clean(NSTACK_RD_LIST(type)); } + } +} - type = rd_data[iindex].type; +static int nstack_rd_ip_get(rd_route_data ** data, int *num, int *ver, + rd_route_table * handle) +{ + rd_route_data *pdata = NULL; + rd_route_node *pnode = NULL; + size_t size = 0; + int icnt = 0; + int idex = 0; + int ret; + int rdver = 0; - if (NSTACK_RD_SUCCESS == - g_rd_cpy[type].rd_item_cpy ((void *) &item, - (void *) &rd_data[iindex])) + if (!handle || !data || !num || !ver) + { + NSSOC_LOGERR("nstack rd mng not inited or input err"); + return -1; + } + dmm_spin_lock_with_pid(&handle->rd_lock); + size = sizeof(rd_route_data) * handle->size; + pdata = (rd_route_data *) malloc(size); + if (!pdata) + { + dmm_spin_unlock(&handle->rd_lock); + NSSOC_LOGERR("rd route data malloc fail"); + return -1; + } + ret = memset_s(pdata, size, 0, size); + if (EOK != ret) + { + dmm_spin_unlock(&handle->rd_lock); + NSSOC_LOGERR("memset_s failed]ret=%d", ret); + free(pdata); + return -1; + } + for (icnt = 0; icnt < handle->size; icnt++) + { + pnode = &(handle->node[icnt]); + if (RD_NODE_USING == pnode->flag) { - item.agetime = NSTACK_RD_AGETIME_MAX; - for (icnt = 0; icnt < stack_num; icnt++) - { - if (0 == - strcmp (g_rd_local_data->pstack_info[icnt].name, - rd_data[iindex].stack_name)) - { - item.stack_id = g_rd_local_data->pstack_info[icnt].stack_id; - break; - } - } - if (icnt >= stack_num) - { - NSSOC_LOGINF - ("plane name:%s was not fount, protocoltype:%d was dropped", - rd_data[iindex].stack_name); - continue; - } - /*insert to the list */ - g_rd_cpy[type].rd_item_inset (NSTACK_RD_LIST (type), &item); - continue; + pdata[idex] = pnode->data; + idex++; } + } + rdver = handle->rdtbl_ver; + dmm_spin_unlock(&handle->rd_lock); + /*if no data fetched , just return fail */ + if (idex == 0) + { + free(pdata); + return -1; + } + *data = pdata; + *num = idex; + *ver = rdver; + return 0; +} - NSSOC_LOGERR ("rd data type=%d cpy fail", rd_data[iindex].type); +static int nstack_rd_tblver_get(int *ver, rd_route_table * handle) +{ + if (!handle || !ver) + { + NSSOC_LOGERR("nstack rd mng not inited or input err"); + return -1; } - return; + *ver = handle->rdtbl_ver; + return 0; } -/***************************************************************************** -* Prototype : nstack_rd_data_get -* Description : rd data get, -* Input : None -* Output : None -* Return Value : int -* Calls : -* Called By : -*****************************************************************************/ -int -nstack_rd_data_get (nstack_get_route_data pfun) +int nstack_rd_init(nstack_rd_stack_info * pstack, int num) { - rd_route_data *rd_data = NULL; - int iret = NSTACK_RD_FAIL; - int inum = 0; + int icnt = 0; + nstack_rd_stack_info *ptemstack = NULL; + int *rd_ver = NULL; - /*get rd config */ - if (pfun && (NSTACK_RD_SUCCESS == pfun (&rd_data, &inum))) + if (!pstack) { - if (inum > 0) - { - nstack_rd_save (rd_data, inum); - iret = NSTACK_RD_SUCCESS; - } - else - { - NSSOC_LOGDBG ("no rd data got"); - } - if (rd_data) - { - free (rd_data); - rd_data = NULL; - } + NSSOC_LOGERR("input err pstack:%p", pstack); + return NSTACK_RD_FAIL; + } + g_rd_local_data = (rd_local_data *) malloc(sizeof(rd_local_data)); + if (!g_rd_local_data) + { + NSSOC_LOGERR("g_rd_local_data alloc fail"); + return NSTACK_RD_FAIL; + } + + /*add return value check */ + if (EOK != + memset_s((void *) g_rd_local_data, sizeof(rd_local_data), 0, + sizeof(rd_local_data))) + { + NSSOC_LOGERR("memset_s fail"); + goto ERR; + } + + g_rd_local_data->sys_fun = nstack_rd_ip_get; + g_rd_local_data->rdtbl_ver_get_fun = nstack_rd_tblver_get; + + ptemstack = + (nstack_rd_stack_info *) malloc(sizeof(nstack_rd_stack_info) * num); + if (!ptemstack) + { + NSSOC_LOGERR("rd stack info malloc fail"); + goto ERR; + } + + if (EOK != + memcpy_s(ptemstack, sizeof(nstack_rd_stack_info) * num, pstack, + sizeof(nstack_rd_stack_info) * num)) + { + NSSOC_LOGERR("memcpy_s failed!"); + goto ERR; + } + + g_rd_local_data->pstack_info = ptemstack; + g_rd_local_data->stack_num = num; + + rd_ver = (int *) malloc(sizeof(int) * NSTACK_NUM); /*this function is necessary */ + if (!rd_ver) + { + NSSOC_LOGERR("rd_ver alloc failed!"); + goto ERR; + } + if (EOK != + memset_s((void *) rd_ver, sizeof(int) * NSTACK_NUM, 0, + sizeof(int) * NSTACK_NUM)) + { + NSSOC_LOGERR("memset_s failed!"); + goto ERR; + } + g_rd_local_data->rdlocal_ver = rd_ver; + + for (icnt = 0; icnt < RD_DATA_TYPE_MAX; icnt++) + { + INIT_HLIST_HEAD(&(g_rd_local_data->route_list[icnt].headlist)); } - else + return NSTACK_RD_SUCCESS; + + ERR: + if (g_rd_local_data) + { + free(g_rd_local_data); + g_rd_local_data = NULL; + } + if (ptemstack) { - NSSOC_LOGERR ("nstack rd sys rd info fail"); + free(ptemstack); } - return iret; + if (rd_ver) + { + free(rd_ver); /*this function is necessary */ + } + return NSTACK_RD_FAIL; } /***************************************************************************** @@ -339,33 +511,92 @@ nstack_rd_data_get (nstack_get_route_data pfun) * Calls : * Called By : *****************************************************************************/ -int -nstack_rd_sys () +int nstack_rd_sys() { - int iret = NSTACK_RD_FAIL; - int icnt = 0; - if (!g_rd_local_data) + rd_route_data *rd_data = NULL; + nstack_rd_stack_info *prdstack = NULL; + int icnt = 0; + int inum = 0; + int iver = 0; + int iret = 0; + int iindex = 0; + rd_data_item item; + rd_data_type type = RD_DATA_TYPE_MAX; + + if (!g_rd_local_data) { - NSSOC_LOGERR ("rd have not been inited"); - return NSTACK_RD_FAIL; + NSSOC_LOGERR("rd have not been inited"); + return NSTACK_RD_FAIL; } + /*add return value check */ + int retVal = memset_s(&item, sizeof(item), 0, sizeof(item)); + if (EOK != retVal) + { + NSSOC_LOGERR("memset_s failed]retVal=%d", retVal); + return NSTACK_RD_FAIL; + } + nstack_rd_sys_clean(); - /*insert default rd info */ - nstack_rd_sys_default (); + nstack_rd_sys_load_default(); - /*get from config file */ - for (icnt = 0; icnt < g_rd_local_data->fun_num; icnt++) + prdstack = g_rd_local_data->pstack_info; + for (icnt = 0; icnt < NSTACK_NUM; icnt++) { - if (NSTACK_RD_SUCCESS == - nstack_rd_data_get (g_rd_local_data->sys_fun[icnt])) + if (!g_rd_table_handle[icnt]) { - iret = NSTACK_RD_SUCCESS; + continue; } - } + /*get from rd table */ + iret = + g_rd_local_data->sys_fun(&rd_data, &inum, &iver, + g_rd_table_handle[icnt]); + if (NSTACK_RD_SUCCESS != iret) + { + NSSOC_LOGERR("nstack rd sys rd info stack fail] stack=%s", + prdstack[icnt].name); + return NSTACK_RD_FAIL; + } + NSSOC_LOGINF + ("nstack rd sync sucess] stack=%s, rdtable ver:%d, rdtable size:%d", + prdstack[icnt].name, iver, inum); - /*age after sys */ - nstack_rd_age (); - return iret; + g_rd_local_data->rdlocal_ver[icnt] = iver; + if (inum <= 0) + { + NSSOC_LOGDBG("no rd data got"); + if (rd_data) + { + free(rd_data); /*this function is necessary */ + rd_data = NULL; + } + continue; + } + for (iindex = 0; iindex < inum; iindex++) + { + if (rd_data[iindex].type >= RD_DATA_TYPE_MAX) + { + NSSOC_LOGERR("rd data type=%d unkown", rd_data[iindex].type); + continue; + } + type = rd_data[iindex].type; + if (NSTACK_RD_SUCCESS == + g_rd_cpy[type].rd_item_copy((void *) &item, + (void *) &rd_data[iindex])) + { + item.agetime = NSTACK_RD_AGETIME_MAX; + item.stack_id = prdstack[icnt].stack_id; + /*insert to the list */ + g_rd_cpy[type].rd_item_insert(NSTACK_RD_LIST(type), &item); /*do not need return value */ + continue; + } + NSSOC_LOGERR("rd data type=%d cpy fail", rd_data[iindex].type); + } + free(rd_data); /*this function is necessary */ + rd_data = NULL; + } + /*age after sys */ + nstack_rd_age(); /*do not need return value */ + return NSTACK_RD_SUCCESS; } /***************************************************************************** @@ -378,13 +609,42 @@ nstack_rd_sys () * Calls : * Called By : *****************************************************************************/ -int -nstack_rd_age () +int nstack_rd_age() { - int icnt = 0; - for (icnt = 0; icnt < RD_DATA_TYPE_MAX; icnt++) + int icnt = 0; + for (icnt = 0; icnt < RD_DATA_TYPE_MAX; icnt++) { - (void) g_rd_cpy[icnt].rd_item_age (NSTACK_RD_LIST (icnt)); + if (g_rd_cpy[icnt].rd_item_age) + (void) g_rd_cpy[icnt].rd_item_age(NSTACK_RD_LIST(icnt)); } - return NSTACK_RD_SUCCESS; + return NSTACK_RD_SUCCESS; +} + +int nstack_rd_match_pre(int domain, int type, int protocol, + rd_data_item * item) +{ + int ret = -1; + nstack_rd_key key = { 0 }; + + key.type = RD_DATA_TYPE_TYPE; + key.socket_type = type; + ret = + g_rd_cpy[key.type].rd_item_find(NSTACK_RD_LIST(key.type), + (void *) &key, (void *) item); + if (ret == NSTACK_RD_SUCCESS) + { + return item->stack_id; + } + + key.type = RD_DATA_TYPE_PROTO; + key.proto = protocol; + ret = + g_rd_cpy[key.type].rd_item_find(NSTACK_RD_LIST(key.type), + (void *) &key, (void *) item); + if (ret == NSTACK_RD_SUCCESS) + { + return item->stack_id; + } + + return -1; } |