diff options
author | charan makkina <charan795m@gmail.com> | 2019-04-30 17:40:53 +0530 |
---|---|---|
committer | charan makkina <charan795m@gmail.com> | 2019-05-20 18:14:40 +0530 |
commit | a826fe833d3f2a8fe2673fa05811fe1a22baf045 (patch) | |
tree | da11a17c46ca9b8a002a52a290628574fa3f5eda /src/nSocket/nstack_rd/nstack_rd_proto.c | |
parent | 3e6bf7b64eea418c59959c18750261b815b2892c (diff) |
Feature: 19.04 part 1
Change-Id: Ibba924b8deca1f246b9dcb12d89d085b6fd33046
Signed-off-by: charan makkina <charan795m@gmail.com>
Diffstat (limited to 'src/nSocket/nstack_rd/nstack_rd_proto.c')
-rw-r--r-- | src/nSocket/nstack_rd/nstack_rd_proto.c | 251 |
1 files changed, 143 insertions, 108 deletions
diff --git a/src/nSocket/nstack_rd/nstack_rd_proto.c b/src/nSocket/nstack_rd/nstack_rd_proto.c index 81246c0..e1c58e2 100644 --- a/src/nSocket/nstack_rd/nstack_rd_proto.c +++ b/src/nSocket/nstack_rd/nstack_rd_proto.c @@ -18,107 +18,111 @@ #include <arpa/inet.h> #include "nstack_rd_data.h" #include "nstack_rd.h" -#include "nstack_rd_init.h" #include "nstack_rd_priv.h" #include "nstack_rd_proto.h" #include "nstack_log.h" #include "nstack_securec.h" -#include "common_mem_common.h" /*copy rd data*/ -int -nstack_rd_proto_cpy (void *destdata, void *srcdata) +int nstack_rd_proto_data_cpy(void *destdata, void *srcdata) { - rd_data_item *pitem = (rd_data_item *) destdata; - rd_route_data *pdata = (rd_route_data *) srcdata; - pitem->type = pdata->type; - pitem->proto_type = pdata->proto_type; - return NSTACK_RD_SUCCESS; + rd_data_item *pitem = (rd_data_item *) destdata; + rd_route_data *pdata = (rd_route_data *) srcdata; + + pitem->type = pdata->type; + pitem->proto_data.value = pdata->proto_data.value; + pitem->proto_data.attr = pdata->proto_data.attr; + return NSTACK_RD_SUCCESS; } /* * Add an ip segment to the list and sort it in descending order of ip mask length * If the list already exists in the same list of ip side, then stack_id update - *ip is local byteorder + *ip is network byte order */ -int -nstack_rd_proto_item_insert (nstack_rd_list * hlist, void *rditem) +/*vars are used in macro*/ +int nstack_rd_proto_item_insert(nstack_rd_list * hlist, void *rditem) { - nstack_rd_node *pdatanode = NULL; - nstack_rd_node *tempdata = NULL; - struct hlist_node *tempnode = NULL; - rd_data_item *pitem = (rd_data_item *) rditem; + nstack_rd_node *pdatanode = NULL; + nstack_rd_node *tempdata = NULL; + struct hlist_node *tempnode = NULL; + rd_data_item *pitem = (rd_data_item *) rditem; - NSSOC_LOGDBG ("stackid:%d, protocol type:%d was inserted", pitem->stack_id, - pitem->proto_type); + NSSOC_LOGDBG("stackid:%d, proto value:%u proto attr:%u was inserted", + pitem->stack_id, pitem->proto_data.value, + pitem->proto_data.attr); - pdatanode = (nstack_rd_node *) malloc (sizeof (nstack_rd_node)); - if (!pdatanode) + pdatanode = (nstack_rd_node *) malloc(sizeof(nstack_rd_node)); /*this function is necessary */ + if (!pdatanode) { - NSSOC_LOGERR ("nstack rd item malloc fail"); - return NSTACK_RD_FAIL; + NSSOC_LOGERR("nstack rd item malloc fail"); + return NSTACK_RD_FAIL; } - int retVal = - MEMSET_S (pdatanode, sizeof (nstack_rd_node), 0, sizeof (nstack_rd_node)); - if (EOK != retVal) + /* add return value check */ + int retVal = memset_s(pdatanode, sizeof(nstack_rd_node), 0, + sizeof(nstack_rd_node)); + if (EOK != retVal) { - NSSOC_LOGERR ("MEMSET_S failed]retVal=%d", retVal); - free (pdatanode); - return NSTACK_RD_FAIL; + NSSOC_LOGERR("memset_s failed]retVal=%d", retVal); + free(pdatanode); /*this function is necessary */ + return NSTACK_RD_FAIL; } - INIT_HLIST_NODE (&pdatanode->rdnode); - NSTACK_RD_PROTO_ITEM_COPY (&(pdatanode->item), pitem); - if (hlist_empty (&(hlist->headlist))) + INIT_HLIST_NODE(&pdatanode->rdnode); + NSTACK_RD_PROTO_ITEM_COPY(&(pdatanode->item), pitem); + + if (hlist_empty(&(hlist->headlist))) { - hlist_add_head (&(pdatanode->rdnode), &(hlist->headlist)); + hlist_add_head(&(pdatanode->rdnode), &(hlist->headlist)); - return NSTACK_RD_SUCCESS; + return NSTACK_RD_SUCCESS; } - hlist_for_each_entry (tempdata, tempnode, &(hlist->headlist), rdnode) - { - if (tempdata->item.proto_type == pitem->proto_type) - - { - tempdata->item.stack_id = pitem->stack_id; - tempdata->item.agetime = NSTACK_RD_AGETIME_MAX; - free (pdatanode); - return NSTACK_RD_SUCCESS; - } - } - hlist_add_head (&(pdatanode->rdnode), &(hlist->headlist)); + hlist_for_each_entry(tempdata, tempnode, &(hlist->headlist), rdnode) + { + if (tempdata->item.proto_data.value == pitem->proto_data.value) + { + NSSOC_LOGDBG + ("find duplicate node, proto value:%u, old stack_id:%d, new stack_id:%d", + pitem->proto_data.value, tempdata->item.stack_id, + pitem->stack_id); + tempdata->item.stack_id = pitem->stack_id; + tempdata->item.agetime = NSTACK_RD_AGETIME_MAX; + free(pdatanode); /*this function is necessary */ + return NSTACK_RD_SUCCESS; + } + } + hlist_add_head(&(pdatanode->rdnode), &(hlist->headlist)); - return NSTACK_RD_SUCCESS; + return NSTACK_RD_SUCCESS; } /* *find stackid by ip - *input ip must netorder + *input ip must be network order */ -int -nstack_rd_proto_item_find (nstack_rd_list * hlist, void *rdkey, void *outitem) +int nstack_rd_proto_item_find(nstack_rd_list * hlist, void *rdkey, + void *outitem) { - struct hlist_node *tempnode = NULL; - nstack_rd_node *tempdata = NULL; - nstack_rd_key *key = (nstack_rd_key *) rdkey; - rd_data_item *pitem = (rd_data_item *) outitem; - hlist_for_each_entry (tempdata, tempnode, &(hlist->headlist), rdnode) - { - - /*if already exist, just return success */ - if (tempdata->item.proto_type == key->proto_type) - - { - NSTACK_RD_PROTO_ITEM_COPY (pitem, &(tempdata->item)); - return NSTACK_RD_SUCCESS; - } - } + struct hlist_node *tempnode = NULL; + nstack_rd_node *tempdata = NULL; + nstack_rd_key *key = (nstack_rd_key *) rdkey; + rd_data_item *pitem = (rd_data_item *) outitem; - NSSOC_LOGDBG ("protocol type item not found", key->proto_type); + hlist_for_each_entry(tempdata, tempnode, &(hlist->headlist), rdnode) + { + if (tempdata->item.proto_data.value == key->proto) + { + NSTACK_RD_PROTO_ITEM_COPY(pitem, &(tempdata->item)); + return NSTACK_RD_SUCCESS; + } + } - return NSTACK_RD_FAIL; + /* Optimize log */ + NSSOC_LOGDBG("proto:%u item not found", key->proto); + + return NSTACK_RD_FAIL; } /***************************************************************************** @@ -130,61 +134,92 @@ nstack_rd_proto_item_find (nstack_rd_list * hlist, void *rdkey, void *outitem) * Calls : * Called By : *****************************************************************************/ -int -nstack_rd_proto_item_age (nstack_rd_list * hlist) +int nstack_rd_proto_item_age(nstack_rd_list * hlist) { - struct hlist_node *tempnode = NULL; - nstack_rd_node *tempdata = NULL; - nstack_rd_node *prevdata = NULL; - struct hlist_node *prevnode = NULL; - NSSOC_LOGINF ("nstack rd ip age begin"); - hlist_for_each_entry (tempdata, tempnode, &(hlist->headlist), rdnode) - { - /*if agetime equal 0, remove it */ - if (tempdata->item.agetime <= 0) - { + struct hlist_node *tempnode = NULL; + nstack_rd_node *tempdata = NULL; + nstack_rd_node *prevdata = NULL; + struct hlist_node *prevnode = NULL; + NSSOC_LOGINF("nstack rd proto age begin"); + hlist_for_each_entry(tempdata, tempnode, &(hlist->headlist), rdnode) + { + /*if agetime equal 0, remove it */ + if (tempdata->item.agetime <= 0) + { + if (prevdata) + { + /* Optimize log */ + NSSOC_LOGDBG("stackid=%d, proto:%u was aged", + tempdata->item.stack_id, + tempdata->item.proto_data.value); + + hlist_del_init(prevnode); + free(prevdata); /*this function is necessary */ + } + prevdata = tempdata; + prevnode = tempnode; + } + else + { + tempdata->item.agetime--; + } + } + if (prevdata) + { + if (tempdata) + { + /* Optimize log */ + NSSOC_LOGDBG("stackid:%d, proto:%u was last aged", + tempdata->item.stack_id, + tempdata->item.proto_data.value); + } + hlist_del_init(prevnode); + free(prevdata); /*this function is necessary */ + } + NSSOC_LOGINF("nstack rd proto age end"); + return NSTACK_RD_SUCCESS; +} + +void nstack_rd_proto_item_clean(nstack_rd_list * hlist) +{ + struct hlist_node *tempnode = NULL; + nstack_rd_node *tempdata = NULL; + nstack_rd_node *prevdata = NULL; + struct hlist_node *prevnode = NULL; + NSSOC_LOGINF("nstack rd proto item clean begin"); + hlist_for_each_entry(tempdata, tempnode, &(hlist->headlist), rdnode) + { if (prevdata) - { - NSSOC_LOGDBG ("stackid:%d, protocol type was aged", - tempdata->item.stack_id, tempdata->item.proto_type); + { + NSSOC_LOGDBG("stackid=%d, proto:%u was cleaned", + tempdata->item.stack_id, + tempdata->item.proto_data.value); + hlist_del_init(prevnode); + free(prevdata); /*this function is necessary */ + } - hlist_del_init (prevnode); - free (prevdata); - } prevdata = tempdata; prevnode = tempnode; - } - else - { - tempdata->item.agetime--; - } - } - if (prevdata) + } + if (prevdata) { - if (tempdata) + if (tempdata) { - NSSOC_LOGDBG ("stackid:%d, protocol type was aged", - tempdata->item.stack_id, tempdata->item.proto_type); + NSSOC_LOGDBG("stackid=%d, proto:%u was last cleaned", + tempdata->item.stack_id, + tempdata->item.proto_data.value); } - hlist_del_init (prevnode); - free (prevdata); + hlist_del_init(prevnode); + free(prevdata); /*this function is necessary */ } - NSSOC_LOGINF ("nstack rd ip age end"); - return NSTACK_RD_SUCCESS; + NSSOC_LOGINF("nstack rd proto item clean end"); } /* *find stackid by spec ip(multicast ip) - *input ip must netorder + *input ip must be network order */ -int -nstack_rd_proto_spec (void *rdkey) -{ - return -1; -} - -int -nstack_rd_proto_default (void *rdkey) +int nstack_rd_proto_spec(void *rdkey) { - return -1; + return -1; } |