From 225db1966cfdc3ca0a9e4e913ec66f6e52cf2d47 Mon Sep 17 00:00:00 2001 From: swarupn Date: Fri, 2 Nov 2018 17:54:07 +0530 Subject: Fix: Ip route RD has higher priority than protocol route for now. RD resloution move to bind/connect. Change-Id: I1224233c488db41d3655d986b22ac00b819329cb Signed-off-by: swarupn --- src/nSocket/nstack/nstack_socket.c | 95 +++++++++++++++++++++++++++++------- src/nSocket/nstack_rd/nstack_rd_ip.c | 7 +-- 2 files changed, 81 insertions(+), 21 deletions(-) diff --git a/src/nSocket/nstack/nstack_socket.c b/src/nSocket/nstack/nstack_socket.c index c967d64..210e29d 100644 --- a/src/nSocket/nstack/nstack_socket.c +++ b/src/nSocket/nstack/nstack_socket.c @@ -141,12 +141,10 @@ int nstack_socket (int domain, int itype, int protocol) { int ret = -1; //tmp ret of a Single proctol mode. - int rdret = -1; //the final Return judge vale. int modInx; nstack_socket_ops *ops; int ret_fd = -1; int protoFD[NSTACK_MAX_MODULE_NUM]; - nstack_rd_key rdkey = { 0 }; int selectmod = -1; /*check whether module init finish or not */ @@ -183,22 +181,6 @@ nstack_socket (int domain, int itype, int protocol) nstack_fd_local_lock_info_t *lock_info = get_fd_local_lock_info (ret_fd); LOCK_FOR_EP (lock_info); - - /*check wether select stack create success, if no return fail */ - rdkey.type = RD_DATA_TYPE_PROTO; - rdkey.proto_type = itype; - rdret = nstack_rd_get_stackid (&rdkey, &selectmod); - if ((0 != rdret) || (selectmod < 0) || (selectmod >= nstack_get_modNum ())) - { - NSSOC_LOGERR ("protocol:%d select stack fail", protocol); - selectmod = -1; - } - else - { - NSSOC_LOGINF ("Create socket of]select modName=%s", - nstack_get_module_name_by_idx (selectmod)); - } - /*create socket by calling select module or all module */ nstack_each_modOps (modInx, ops) { @@ -389,6 +371,26 @@ nstack_bind (int fd, const struct sockaddr *addr, socklen_t addrlen) nstack_get_module_name_by_idx (selectmod)); } + if (selectmod == -1) + { + rdkey.type = RD_DATA_TYPE_PROTO; + rdkey.proto_type = fdInf->type; + retval = nstack_rd_get_stackid (&rdkey, &selectmod); + if ((0 != retval) || (selectmod < 0) + || (selectmod >= nstack_get_modNum ())) + { + NSSOC_LOGWAR + ("fd Can't select any module for]fd=%d,IP==%s using proto route", + fd, inet_ntoa ((iaddr->sin_addr))); + selectmod = -1; + } + else + { + NSSOC_LOGINF ("Bind socket of]select modName=%s", + nstack_get_module_name_by_idx (selectmod)); + } + } + retval = -1; nstack_each_modInx (modIdx) { @@ -902,6 +904,25 @@ nstack_connect (int fd, const struct sockaddr *addr, socklen_t addrlen) rdkey.type = RD_DATA_TYPE_IP; rdkey.ip_addr = iaddr->sin_addr.s_addr; retval = nstack_rd_get_stackid (&rdkey, &selectmod); + if ((0 != retval) || (selectmod == -1)) + { + rdkey.type = RD_DATA_TYPE_PROTO; + rdkey.proto_type = fdInf->type; + retval = nstack_rd_get_stackid (&rdkey, &selectmod); + if ((0 != retval) || (selectmod < 0) + || (selectmod >= nstack_get_modNum ())) + { + NSSOC_LOGINF ("fd=%d addr=%s Select module=%s", + fd, inet_ntoa (iaddr->sin_addr), + nstack_get_module_name_by_idx (selectmod)); + selectmod = -1; + } + else + { + NSSOC_LOGINF ("Connect socket of]select modName=%s", + nstack_get_module_name_by_idx (selectmod)); + } + } if (ns_success == retval && selectmod >= 0) { NSSOC_LOGINF ("fd=%d addr=%s Select module=%s", @@ -1385,6 +1406,25 @@ nstack_sendto (int fd, const void *buf, size_t len, int flags, rdkey.type = RD_DATA_TYPE_IP; rdkey.ip_addr = iaddr->sin_addr.s_addr; retval = nstack_rd_get_stackid (&rdkey, &selectmod); + if ((0 != retval) || (selectmod == -1)) + { + rdkey.type = RD_DATA_TYPE_PROTO; + rdkey.proto_type = fdInf->type; + retval = nstack_rd_get_stackid (&rdkey, &selectmod); + if ((0 != retval) || (selectmod < 0) + || (selectmod >= nstack_get_modNum ())) + { + NSSOC_LOGINF ("fd=%d addr=%s Select module=%s", + fd, inet_ntoa (iaddr->sin_addr), + nstack_get_module_name_by_idx (selectmod)); + selectmod = -1; + } + else + { + NSSOC_LOGINF ("sendto socket of]select modName=%s", + nstack_get_module_name_by_idx (selectmod)); + } + } if ((ns_success == retval) && (selectmod >= 0)) { NSSOC_LOGINF ("fd=%d,addr=%s,select_module=%s", @@ -1472,6 +1512,25 @@ nstack_sendmsg (int fd, const struct msghdr * msg, int flags) rdkey.type = RD_DATA_TYPE_IP; rdkey.ip_addr = iaddr->sin_addr.s_addr; retval = nstack_rd_get_stackid (&rdkey, &selectmod); + if ((0 != retval) || (selectmod == -1)) + { + rdkey.type = RD_DATA_TYPE_PROTO; + rdkey.proto_type = fdInf->type; + retval = nstack_rd_get_stackid (&rdkey, &selectmod); + if ((0 != retval) || (selectmod < 0) + || (selectmod >= nstack_get_modNum ())) + { + NSSOC_LOGINF ("fd=%d addr=%s Select module=%s", + fd, inet_ntoa (iaddr->sin_addr), + nstack_get_module_name_by_idx (selectmod)); + selectmod = -1; + } + else + { + NSSOC_LOGINF ("Connect socket of]select modName=%s", + nstack_get_module_name_by_idx (selectmod)); + } + } if (ns_success == retval) { NSSOC_LOGINF ("fd=%d,addr=%s,select_module=%s", diff --git a/src/nSocket/nstack_rd/nstack_rd_ip.c b/src/nSocket/nstack_rd/nstack_rd_ip.c index c9246c0..82035d1 100644 --- a/src/nSocket/nstack_rd/nstack_rd_ip.c +++ b/src/nSocket/nstack_rd/nstack_rd_ip.c @@ -64,12 +64,13 @@ nstack_rd_ip_item_insert (nstack_rd_list * hlist, void *rditem) nstack_rd_node *tempdata = NULL; struct hlist_node *tempnode = NULL; struct hlist_node *tem = NULL; - unsigned int ip_addr = 0; - unsigned int ip_masklen = 0; - unsigned int ip_maskv = MASK_V (ip_addr, ip_masklen); + unsigned int tempip_addr = 0; unsigned int tempip_masklen = 0; rd_data_item *pitem = (rd_data_item *) rditem; + unsigned int ip_addr = pitem->ipdata.addr; + unsigned int ip_masklen = pitem->ipdata.masklen; + unsigned int ip_maskv = MASK_V (ip_addr, ip_masklen); ip_masklen = pitem->ipdata.masklen; NSSOC_LOGDBG ("stackid:%d, ipaddr:%u.%u.%u.%u masklen:0x%x was inserted", -- cgit 1.2.3-korg