osaf/services/infrastructure/dtms/dtm/dtm_inter_svc.c | 5 +- osaf/services/infrastructure/dtms/dtm/dtm_intra.c | 10 +- osaf/services/infrastructure/dtms/dtm/dtm_intra_svc.c | 18 +- osaf/services/infrastructure/dtms/dtm/dtm_main.c | 18 - osaf/services/infrastructure/dtms/dtm/dtm_node.c | 96 ------ osaf/services/infrastructure/dtms/dtm/dtm_node_db.c | 94 ----- osaf/services/infrastructure/dtms/dtm/dtm_node_sockets.c | 236 +-------------- osaf/services/infrastructure/dtms/dtm/dtm_read_config.c | 41 +- osaf/services/infrastructure/dtms/include/dtm.h | 3 - osaf/services/infrastructure/dtms/include/dtm_cb.h | 2 +- osaf/services/infrastructure/dtms/include/dtm_node.h | 2 - 11 files changed, 49 insertions(+), 476 deletions(-)
The following warnings, reported by cppcheck version 1.75, have been fixed: [osaf/services/infrastructure/dtms/dtm/dtm_inter_svc.c:342]: (style) The scope of the variable 'buffer' can be reduced. [osaf/services/infrastructure/dtms/dtm/dtm_intra.c:95]: (style) The scope of the variable 'servlen' can be reduced. [osaf/services/infrastructure/dtms/dtm/dtm_intra.c:97]: (style) The scope of the variable 'server_ux_name' can be reduced. [osaf/services/infrastructure/dtms/dtm/dtm_intra.c:155]: (style) Obsolescent function 'bzero' called. It is recommended to use 'memset' instead. [osaf/services/infrastructure/dtms/dtm/dtm_intra.c:207]: (error) Uninitialized variable: serveraddr [osaf/services/infrastructure/dtms/dtm/dtm_intra_svc.c:139]: (style) The scope of the variable 'del_ptr' can be reduced. [osaf/services/infrastructure/dtms/dtm/dtm_intra_svc.c:243]: (style) The scope of the variable 'tmp' can be reduced. [osaf/services/infrastructure/dtms/dtm/dtm_intra_svc.c:1836]: (style) The scope of the variable 'local_svc_node' can be reduced. [osaf/services/infrastructure/dtms/dtm/dtm_intra_svc.c:710]: (style) Variable 'node_id' is assigned a value that is never used. [osaf/services/infrastructure/dtms/dtm/dtm_intra_svc.c:320]: (error) Memory leak: svc_node [osaf/services/infrastructure/dtms/dtm/dtm_intra_svc.c:512]: (error) Memory leak: subscr_node [osaf/services/infrastructure/dtms/dtm/dtm_intra_svc.c:516]: (error) Memory leak: subscr_info [osaf/services/infrastructure/dtms/dtm/dtm_intra_svc.c:1728]: (error) Memory leak: svc_info [osaf/services/infrastructure/dtms/dtm/dtm_intra_svc.c:1754]: (error) Memory leak: local_svc_info [osaf/services/infrastructure/dtms/dtm/dtm_node_sockets.c:54]: (style) Assignment of function parameter has no effect outside the function. [osaf/services/infrastructure/dtms/dtm/dtm_node_sockets.c:74]: (style) The scope of the variable 'optlen' can be reduced. [osaf/services/infrastructure/dtms/dtm/dtm_node_sockets.c:423]: (style) The scope of the variable 'err' can be reduced. [osaf/services/infrastructure/dtms/dtm/dtm_node_sockets.c:617]: (style) The scope of the variable 'ip_addr_eth' can be reduced. [osaf/services/infrastructure/dtms/dtm/dtm_node_sockets.c:720]: (style) The scope of the variable 'mcast_addr_eth' can be reduced. [osaf/services/infrastructure/dtms/dtm/dtm_node_sockets.c:812]: (style) The scope of the variable 'mcast_addr_eth' can be reduced. [osaf/services/infrastructure/dtms/dtm/dtm_node_sockets.c:1428]: (style) The scope of the variable 'numericAddress' can be reduced. [osaf/services/infrastructure/dtms/dtm/dtm_node_sockets.c:1429]: (style) The scope of the variable 'addrBuffer' can be reduced. [osaf/services/infrastructure/dtms/dtm/dtm_node_sockets.c:191]: (error) Uninitialized variable: join_request [osaf/services/infrastructure/dtms/dtm/dtm_node_sockets.c:192]: (error) Uninitialized variable: join_request [osaf/services/infrastructure/dtms/dtm/dtm_node_sockets.c:950]: (error) Uninitialized variable: addr_list [osaf/services/infrastructure/dtms/dtm/dtm_node_sockets.c:1014]: (error) Uninitialized variable: maddr [osaf/services/infrastructure/dtms/dtm/dtm_node_sockets.c:1015]: (error) Uninitialized variable: maddr [osaf/services/infrastructure/dtms/dtm/dtm_node_sockets.c:1144]: (error) Uninitialized variable: maddr [osaf/services/infrastructure/dtms/dtm/dtm_node_sockets.c:1145]: (error) Uninitialized variable: maddr [osaf/services/infrastructure/dtms/dtm/dtm_read_config.c:139]: (style) The scope of the variable 'tmp' can be reduced. [osaf/services/infrastructure/dtms/dtm/dtm_read_config.c:140]: (style) The scope of the variable 'buf' can be reduced. [osaf/services/infrastructure/dtms/dtm/dtm_read_config.c:271]: (warning) fscanf() without field width limits can crash with huge input data. [osaf/services/infrastructure/dtms/dtm/dtm_read_config.c:327]: (error) Resource leak: dtm_conf_file [osaf/services/infrastructure/dtms/dtm/dtm_node.c:155]: (style) The function 'add_self_node' is never used. [osaf/services/infrastructure/dtms/dtm/dtm_node.c:230]: (style) The function 'datagram_buff_dump' is never used. [osaf/services/infrastructure/dtms/dtm/dtm_node_sockets.c:421]: (style) The function 'dtm_comm_socket_recv' is never used. [osaf/services/infrastructure/dtms/dtm/dtm_node_db.c:252]: (style) The function 'dtm_node_get_by_node_ip' is never used. [osaf/services/infrastructure/dtms/dtm/dtm_node_db.c:219]: (style) The function 'dtm_node_getnext_by_comm_socket' is never used. [osaf/services/infrastructure/dtms/dtm/dtm_node_db.c:280]: (style) The function 'dtm_node_getnext_by_nodeaddr' is never used. [osaf/services/infrastructure/dtms/dtm/dtm_main.c:403]: (style) The function 'dtms_cb_dump' is never used. [osaf/services/infrastructure/dtms/dtm/dtm_node_sockets.c:886]: (style) The function 'get_in_addr' is never used. diff --git a/osaf/services/infrastructure/dtms/dtm/dtm_inter_svc.c b/osaf/services/infrastructure/dtms/dtm/dtm_inter_svc.c --- a/osaf/services/infrastructure/dtms/dtm/dtm_inter_svc.c +++ b/osaf/services/infrastructure/dtms/dtm/dtm_inter_svc.c @@ -15,6 +15,7 @@ * */ +#include <stdlib.h> #include "usrbuf.h" #include "dtm.h" #include "dtm_cb.h" @@ -339,7 +340,6 @@ uint32_t dtm_internode_add_to_svc_dist_l */ uint32_t dtm_internode_del_from_svc_dist_list(uint32_t server_type, uint32_t server_inst, uint32_t pid) { - uint8_t *buffer = NULL; DTM_SVC_DATA *back = NULL, *mov_ptr = NULL; int check_val = 0; TRACE_ENTER(); @@ -380,7 +380,8 @@ uint32_t dtm_internode_del_from_svc_dist } if (1 == check_val) { - if (NULL == (buffer = calloc(1, DTM_DOWN_MSG_SIZE_FULL))) { + uint8_t *buffer = calloc(1, DTM_DOWN_MSG_SIZE_FULL); + if (buffer == NULL) { TRACE("DTM :CALLOC FAILED FOR buffer, unable to send down to all nodes"); TRACE_LEAVE(); return NCSCC_RC_FAILURE; diff --git a/osaf/services/infrastructure/dtms/dtm/dtm_intra.c b/osaf/services/infrastructure/dtms/dtm/dtm_intra.c --- a/osaf/services/infrastructure/dtms/dtm/dtm_intra.c +++ b/osaf/services/infrastructure/dtms/dtm/dtm_intra.c @@ -25,6 +25,7 @@ #include <sys/time.h> #include <arpa/inet.h> #include <netdb.h> +#include <netinet/in.h> #include <configmake.h> #include "ncs_main_papi.h" @@ -92,9 +93,7 @@ uint32_t dtm_service_discovery_init(DTM_ uint32_t dtm_intra_processing_init(char *node_name, char *node_ip, DTM_IP_ADDR_TYPE i_addr_family, int32_t sndbuf_size, int32_t rcvbuf_size) { - int servlen; /* For socket fd and server len */ struct sockaddr_un serv_addr; /* For Unix Sock address */ - char server_ux_name[255]; NCS_PATRICIA_PARAMS pat_tree_params; struct sockaddr_in serveraddr; struct sockaddr_in6 serveraddr6; @@ -152,18 +151,19 @@ uint32_t dtm_intra_processing_init(char dtm_intranode_cb->nodeid = m_NCS_GET_NODE_ID; - bzero((char *)&serv_addr, sizeof(serv_addr)); + memset((char *)&serv_addr, 0, sizeof(serv_addr)); if (dtm_socket_domain == AF_UNIX) { #define UX_SOCK_NAME_PREFIX PKGLOCALSTATEDIR "/osaf_dtm_intra_server" + char server_ux_name[255]; sprintf(server_ux_name, "%s", UX_SOCK_NAME_PREFIX); serv_addr.sun_family = AF_UNIX; strcpy(serv_addr.sun_path, server_ux_name); unlink(serv_addr.sun_path); - servlen = strlen(serv_addr.sun_path) + sizeof(serv_addr.sun_family); + int servlen = strlen(serv_addr.sun_path) + sizeof(serv_addr.sun_family); /* Bind the created socket here with the address NODEID, * if bind fails return error by the closing the @@ -204,7 +204,7 @@ uint32_t dtm_intra_processing_init(char } else { memset(&serveraddr6, 0, sizeof(serveraddr6)); serveraddr6.sin6_family = AF_INET6; - serveraddr.sin_port = htons(DTM_INTRA_SERVER_PORT); + serveraddr6.sin6_port = htons(DTM_INTRA_SERVER_PORT); inet_pton(AF_INET6, "localhost", &serveraddr6.sin6_addr); if (bind(dtm_intranode_cb->server_sockfd, (struct sockaddr *)&serveraddr6, sizeof(serveraddr6) ) < 0) { diff --git a/osaf/services/infrastructure/dtms/dtm/dtm_intra_svc.c b/osaf/services/infrastructure/dtms/dtm/dtm_intra_svc.c --- a/osaf/services/infrastructure/dtms/dtm/dtm_intra_svc.c +++ b/osaf/services/infrastructure/dtms/dtm/dtm_intra_svc.c @@ -136,7 +136,7 @@ uint32_t dtm_intranode_process_pid_down( LOG_ER("DTM INTRA: PID info coressponding to fd doesnt exist, database mismatch. fd :%d",fd); osafassert(0); /* This condition should never come,database mismatch */ } else { - DTM_PID_SVC_INSTALLED_INFO *svc_list = pid_node->svc_installed_list, *del_ptr = NULL; + DTM_PID_SVC_INSTALLED_INFO *svc_list = pid_node->svc_installed_list; DTM_INTRANODE_PID_INFO *pid_node1 = NULL; DTM_PID_SVC_SUSBCR_INFO *subscr_data = pid_node->subscr_list; DTM_NODE_SUBSCR_INFO *node_subscr = NULL; @@ -224,7 +224,7 @@ uint32_t dtm_intranode_process_pid_down( subscr_list = subscr_list->next; } } - del_ptr = svc_list; + DTM_PID_SVC_INSTALLED_INFO* del_ptr = svc_list; svc_list = svc_list->next; dtm_intranode_del_svclist_from_pid_tree(pid_node, del_ptr); @@ -240,9 +240,8 @@ uint32_t dtm_intranode_process_pid_down( m_NCS_IPC_RELEASE(&pid_node->mbx, NULL); close(pid_node->mbx_fd); - DTM_INTRANODE_UNSENT_MSGS *tmp = NULL; while(pid_node->msgs_hdr != NULL) { - tmp = pid_node->msgs_hdr; + DTM_INTRANODE_UNSENT_MSGS* tmp = pid_node->msgs_hdr; if (tmp->buffer != NULL) free(tmp->buffer); pid_node->msgs_hdr = pid_node->msgs_hdr->next; @@ -317,6 +316,7 @@ uint32_t dtm_intranode_process_bind_msg( if (NULL == (svc_list = calloc(1, sizeof(DTM_SVC_LIST)))) { TRACE("DTM :calloc failed for DTM_SVC_LIST"); dtm_intranode_del_svclist_from_pid_tree(pid_node, svc_install_info); + // cppcheck-suppress memleak return NCSCC_RC_FAILURE; } svc_list->server_inst_lower = svc_install_info->server_instance_lower; @@ -509,10 +509,12 @@ uint32_t dtm_intranode_process_subscribe if (NULL == (subscr_info = calloc(1, sizeof(DTM_SUBSCRIBER_LIST)))) { TRACE("DTM :calloc failed for DTM_SUBSCRIBER_LIST"); + // cppcheck-suppress memleak return NCSCC_RC_FAILURE; } if (NULL == (subscr_data = calloc(1, sizeof(DTM_PID_SVC_SUSBCR_INFO)))) { TRACE("DTM :calloc failed for DTM_PID_SVC_SUSBCR_INFO"); + free(subscr_info); return NCSCC_RC_FAILURE; } @@ -707,7 +709,7 @@ uint32_t dtm_intranode_process_node_unsu NODE_ID node_id = ncs_decode_32bit(&data); uint32_t process_id = ncs_decode_32bit(&data); uint64_t ref_val = ncs_decode_64bit(&data); - node_id = node_id; /* Just to avoid compilation error */ + (void) node_id; TRACE_1("DTM: INTRA: node unsubscribe pid=%d", pid_node->pid); dtm_del_from_node_subscr_list(process_id, ref_val); } @@ -1725,6 +1727,7 @@ uint32_t dtm_process_internode_service_u } if (NULL == (svc_list = calloc(1, sizeof(DTM_SVC_LIST)))) { + // cppcheck-suppress memleak return NCSCC_RC_FAILURE; } svc_list->server_inst_lower = ncs_decode_32bit(&data); @@ -1751,6 +1754,7 @@ uint32_t dtm_process_internode_service_u } if (NULL == (svc_list_local = calloc(1, sizeof(DTM_SVC_LIST)))) { + // cppcheck-suppress memleak return NCSCC_RC_FAILURE; } svc_list_local->server_inst_lower = svc_list->server_inst_lower; @@ -1833,7 +1837,7 @@ uint32_t dtm_process_internode_service_d while (0 != num_of_elements) { - DTM_SVC_INSTALL_INFO *svc_info = NULL, *local_svc_node = NULL; + DTM_SVC_INSTALL_INFO *svc_info = NULL; DTM_SVC_LIST svc_list = { 0 }; DTM_SVC_SUBSCR_INFO *subscr_node = NULL; @@ -1853,7 +1857,7 @@ uint32_t dtm_process_internode_service_d dtm_internode_del_svclist_from_svc_tree(node_info, svc_info, &svc_list); /* local node delete */ - local_svc_node = dtm_intranode_get_svc_node(server_type); + DTM_SVC_INSTALL_INFO* local_svc_node = dtm_intranode_get_svc_node(server_type); if (NULL == local_svc_node) { LOG_ER("DTM INTRA: Data base mismatch, local_svc_node doesn't exist \n"); osafassert(0); diff --git a/osaf/services/infrastructure/dtms/dtm/dtm_main.c b/osaf/services/infrastructure/dtms/dtm/dtm_main.c --- a/osaf/services/infrastructure/dtms/dtm/dtm_main.c +++ b/osaf/services/infrastructure/dtms/dtm/dtm_main.c @@ -391,21 +391,3 @@ int main(int argc, char *argv[]) exit(1); } - -/** - * DTMS CB dump - * - * - * @return NCSCC_RC_SUCCESS - * @return NCSCC_RC_FAILURE - * - */ -void dtms_cb_dump(void) -{ - - TRACE("DTM : ***************************************************************************************"); - - TRACE("DTM: My DB Snapshot "); - - TRACE("DTM : ***********************************************************************************"); -} diff --git a/osaf/services/infrastructure/dtms/dtm/dtm_node.c b/osaf/services/infrastructure/dtms/dtm/dtm_node.c --- a/osaf/services/infrastructure/dtms/dtm/dtm_node.c +++ b/osaf/services/infrastructure/dtms/dtm/dtm_node.c @@ -144,95 +144,6 @@ uint32_t dtm_process_node_info(DTM_INTER } /** - * Function to add self node - * - * @param dtms_cb - * - * @return NCSCC_RC_SUCCESS - * @return NCSCC_RC_FAILURE - * - */ -uint32_t add_self_node(DTM_INTERNODE_CB * dtms_cb) -{ - - uint32_t rc = NCSCC_RC_SUCCESS; - DTM_NODE_DB tmp_node; - DTM_NODE_DB *node; - - memset(&tmp_node, 0, sizeof(DTM_NODE_DB)); - - tmp_node.cluster_id = dtms_cb->cluster_id; - tmp_node.node_id = dtms_cb->node_id; - memcpy(tmp_node.node_ip, (uint8_t *)dtms_cb->ip_addr, INET6_ADDRSTRLEN); - tmp_node.i_addr_family = dtms_cb->i_addr_family; - strncpy(tmp_node.node_name, dtms_cb->node_name, strlen(dtms_cb->node_name)); - tmp_node.comm_status = true; - tmp_node.comm_socket = 0; - - node = dtm_node_new(&tmp_node); - - if (node == NULL) { - LOG_ER("DTM: dtm_node_new failed .node_ip : %s ", tmp_node.node_ip); - goto node_fail; - } - - rc = dtm_node_add(node, 0); - if (rc != NCSCC_RC_SUCCESS) { - LOG_ER("DTM: dtm_node_add fail rc : %d node->node_id : %d node->node_ip : %s", rc, node->node_id, - node->node_ip); - rc = NCSCC_RC_FAILURE; - free(node); - goto done; - } - - rc = dtm_node_add(node, 1); - if (rc != NCSCC_RC_SUCCESS) { - LOG_ER("DTM: dtm_node_add fail rc : %d node->node_id : %d node->node_ip : %s", rc, node->node_id, - node->node_ip); - if (dtm_node_delete(node, 0) != NCSCC_RC_SUCCESS) { - LOG_ER("DTM :dtm_node_delete failed "); - rc = NCSCC_RC_FAILURE; - free(node); - goto done; - } - - } - - rc = dtm_node_add(node, 2); - if (rc != NCSCC_RC_SUCCESS) { - LOG_ER("DTM: dtm_node_add fail rc : %d node->node_id : %d node->node_ip : %s", rc, node->node_id, - node->node_ip); - if (dtm_node_delete(node, 0) != NCSCC_RC_SUCCESS) { - LOG_ER("DTM :dtm_node_delete failed "); - } - if (dtm_node_delete(node, 1) != NCSCC_RC_SUCCESS) { - LOG_ER("DTM :dtm_node_delete failed"); - } - free(node); - rc = NCSCC_RC_FAILURE; - } - - done: - node_fail: - return rc; - -} - -/** - * Function to take dump of datagram - * - * @param buff len max - * - * @return NCSCC_RC_SUCCESS - * @return NCSCC_RC_FAILURE - * - */ -void datagram_buff_dump(uint8_t *buff, uint32_t len, uint32_t max) -{ - /* TBD */ -} - -/** * Function to process node up and down * * @param node_id node_name comm_status @@ -552,13 +463,6 @@ void node_discovery_process(void *arg) LOG_ER("DTM: Set up the initial stream nonblocking serv failed"); exit(1); } -#if 0 - - if (add_self_node(dtms_cb) != NCSCC_RC_SUCCESS) { - LOG_ER("DTM: add_self_node failed"); - exit(1); - } -#endif /*************************************************************/ /* Initialize the pollfd structure */ diff --git a/osaf/services/infrastructure/dtms/dtm/dtm_node_db.c b/osaf/services/infrastructure/dtms/dtm/dtm_node_db.c --- a/osaf/services/infrastructure/dtms/dtm/dtm_node_db.c +++ b/osaf/services/infrastructure/dtms/dtm/dtm_node_db.c @@ -208,100 +208,6 @@ DTM_NODE_DB *dtm_node_get_by_comm_socket } /** - * Retrieve next node from node db by comm_socket - * - * @param comm_socket - * - * @return NCSCC_RC_SUCCESS - * @return NCSCC_RC_FAILURE - * - */ -DTM_NODE_DB *dtm_node_getnext_by_comm_socket(uint32_t comm_socket) -{ - DTM_NODE_DB *node = NULL; - DTM_INTERNODE_CB *dtms_cb = dtms_gl_cb; - TRACE_ENTER(); - - if (comm_socket == 0) { - - node = (DTM_NODE_DB *) ncs_patricia_tree_getnext(&dtms_cb->comm_sock_tree, (uint8_t *)0); - } else - node = (DTM_NODE_DB *) ncs_patricia_tree_getnext(&dtms_cb->comm_sock_tree, (uint8_t *)&comm_socket); - - if (node != (DTM_NODE_DB *) NULL) { - /* Adjust the pointer */ - node = (DTM_NODE_DB *) (((char *)node) - - (((char *)&(((DTM_NODE_DB *) 0)->pat_comm_socket)) - - ((char *)((DTM_NODE_DB *) 0)))); - TRACE("DTM:Node found %d", node->comm_socket); - } - - TRACE_LEAVE(); - return node; -} - -/** - * Retrieve node from node db by node_ip - * - * @param comm_socket - * - * @return NCSCC_RC_SUCCESS - * @return NCSCC_RC_FAILURE - * - */ -DTM_NODE_DB *dtm_node_get_by_node_ip(uint8_t *node_ip) -{ - DTM_NODE_DB *node = NULL; - DTM_INTERNODE_CB *dtms_cb = dtms_gl_cb; - TRACE_ENTER(); - - node = (DTM_NODE_DB *) ncs_patricia_tree_get(&dtms_cb->ip_addr_tree, (uint8_t *)node_ip); - if (node != (DTM_NODE_DB *) NULL) { - /* Adjust the pointer */ - node = (DTM_NODE_DB *) (((char *)node) - - (((char *)&(((DTM_NODE_DB *) 0)->pat_ip_address)) - - ((char *)((DTM_NODE_DB *) 0)))); - TRACE("DTM:Node found %s", node_ip); - } - - TRACE_LEAVE(); - return node; -} - -/** - * Retrieve next node from node db by node_ip - * - * @param node_ip - * - * @return NCSCC_RC_SUCCESS - * @return NCSCC_RC_FAILURE - * - */ -DTM_NODE_DB *dtm_node_getnext_by_nodeaddr(uint8_t *node_ip) -{ - DTM_NODE_DB *node = NULL; - DTM_INTERNODE_CB *dtms_cb = dtms_gl_cb; - TRACE_ENTER(); - - if (node_ip == NULL) { - - node = (DTM_NODE_DB *) ncs_patricia_tree_getnext(&dtms_cb->ip_addr_tree, (uint8_t *)0); - } else { - node = (DTM_NODE_DB *) ncs_patricia_tree_getnext(&dtms_cb->ip_addr_tree, (uint8_t *)node_ip); - } - if (node != (DTM_NODE_DB *) NULL) { - /* Adjust the pointer */ - node = (DTM_NODE_DB *) (((char *)node) - - (((char *)&(((DTM_NODE_DB *) 0)->pat_ip_address)) - - ((char *)((DTM_NODE_DB *) 0)))); - TRACE("DTM:Node found %s", node_ip); - } - - TRACE_LEAVE(); - return node; -} - -/** * Adds the node to patricia tree * * @param node diff --git a/osaf/services/infrastructure/dtms/dtm/dtm_node_sockets.c b/osaf/services/infrastructure/dtms/dtm/dtm_node_sockets.c --- a/osaf/services/infrastructure/dtms/dtm/dtm_node_sockets.c +++ b/osaf/services/infrastructure/dtms/dtm/dtm_node_sockets.c @@ -18,6 +18,9 @@ #include <netdb.h> #include <netinet/tcp.h> #include <arpa/inet.h> +#include <sys/socket.h> +#include <netinet/in.h> +#include <string.h> #include "ncsencdec_pub.h" #include "usrbuf.h" #include "dtm.h" @@ -51,7 +54,6 @@ uint32_t dtm_sockdesc_close(int sock_des LOG_ER("DTM : dtm_sockdesc_close err :%s", strerror(errno)); return NCSCC_RC_FAILURE; } - sock_desc = -1; TRACE_LEAVE2("rc :%d", NCSCC_RC_SUCCESS); return NCSCC_RC_SUCCESS; @@ -71,7 +73,6 @@ static uint32_t set_keepalive(DTM_INTERN { TRACE_ENTER(); - socklen_t optlen; int comm_keepidle_time, comm_keepalive_intvl, comm_keepalive_probes; int so_keepalive; int smode = 1; @@ -83,6 +84,8 @@ static uint32_t set_keepalive(DTM_INTERN comm_keepalive_probes = dtms_cb->comm_keepalive_probes; if (so_keepalive == true) { + socklen_t optlen; + /* Set SO_KEEPALIVE */ optlen = sizeof(so_keepalive); if (setsockopt(sock_desc, SOL_SOCKET, SO_KEEPALIVE, &so_keepalive, optlen) < 0) { @@ -188,6 +191,7 @@ static uint32_t dgram_join_mcast_group(D /* Now join the mcast "group" */ struct ip_mreq join_request; + memset(&join_request, 0, sizeof(join_request)); join_request.imr_multiaddr = ((struct sockaddr_in *)mcast_receiver_addr->ai_addr)->sin_addr; join_request.imr_interface.s_addr = inet_addr(dtms_cb->ip_addr); TRACE("DTM :Joining IPv4 mcast group..."); @@ -410,55 +414,6 @@ uint32_t dtm_comm_socket_send(int sock_d } /** - * Rcv the message from the socket - * - * @param sock_desc buffer buffer_len - * - * @return NCSCC_RC_SUCCESS - * @return NCSCC_RC_FAILURE - * - */ -uint32_t dtm_comm_socket_recv(int sock_desc, void *buffer, int buffer_len) -{ - int rtn = 0, err = 0; - int rc = NCSCC_RC_SUCCESS; - TRACE_ENTER(); - if ((rtn = recv(sock_desc, (raw_type *) buffer, buffer_len, 0)) < 0) { - err = errno; - LOG_ER("DTM :dtm_comm_socket_recv failed err :%s", strerror(err)); - rc = NCSCC_RC_FAILURE; - } - TRACE_LEAVE2("rc : %d", rc); - return rc; -} - -#if 0 -/********************************************************* - - Function NAME: - DESCRIPTION: - - ARGUMENTS: - - RETURNS: - -*********************************************************/ -static char *comm_get_foreign_address(int sock_desc) -{ - struct addrinfo addr; - unsigned int addr_len = sizeof(addr); - TRACE_ENTER(); - - if (getpeername(sock_desc, (sockaddr *) & addr, (socklen_t *)&addr_len) < 0) { - LOG_ER("DTM :Fetch of foreign address failed (getpeername()) err :%s", strerror(errno)); - return NULL; - } - TRACE_LEAVE(); - return inet_ntoa(addr.ai_addr); -} -#endif - -/** * Setup the new communication socket * * @param dtms_cb foreign_address foreign_port ip_addr_type @@ -614,7 +569,6 @@ uint32_t dtm_stream_nonblocking_listener struct addrinfo *addr_list = NULL, *p;; /* List of serv addresses */ int sndbuf_size = dtms_cb->sock_sndbuf_size, rcvbuf_size = dtms_cb->sock_rcvbuf_size; int rv; - char ip_addr_eth[INET6_ADDRSTRLEN + IFNAMSIZ]; dtms_cb->stream_sock = -1; TRACE_ENTER(); /* Construct the serv address structure */ @@ -632,6 +586,7 @@ uint32_t dtm_stream_nonblocking_listener /* For link-local address, need to set sin6_scope_id to match the device index of the network device on it has to connecct */ if (dtms_cb->scope_link == true) { + char ip_addr_eth[INET6_ADDRSTRLEN + IFNAMSIZ]; memset(ip_addr_eth, 0, (INET6_ADDRSTRLEN + IFNAMSIZ)); sprintf(ip_addr_eth,"%s%s%s", dtms_cb->ip_addr, "%", dtms_cb->ifname); rv = getaddrinfo(ip_addr_eth, local_port_str, &addr_criteria, &addr_list); @@ -717,7 +672,6 @@ uint32_t dtm_dgram_mcast_listener(DTM_IN char local_port_str[INET6_ADDRSTRLEN]; int rv; struct addrinfo *addr_list; /* Holder serv address */ - char mcast_addr_eth[INET6_ADDRSTRLEN + IFNAMSIZ]; TRACE_ENTER(); TRACE("DTM :dgram_port_rcvr :%d", dtms_cb->dgram_port_rcvr); @@ -734,6 +688,7 @@ uint32_t dtm_dgram_mcast_listener(DTM_IN /* For link-local address, need to set sin6_scope_id to match the device index of the network device on it has to connecct */ if (dtms_cb->scope_link == true) { + char mcast_addr_eth[INET6_ADDRSTRLEN + IFNAMSIZ]; memset(mcast_addr_eth, 0, (INET6_ADDRSTRLEN + IFNAMSIZ)); sprintf(mcast_addr_eth,"%s%s%s", dtms_cb->mcast_addr, "%", dtms_cb->ifname); rv = getaddrinfo(mcast_addr_eth, local_port_str, &addr_criteria, &addr_list); @@ -809,7 +764,6 @@ uint32_t dtm_dgram_mcast_sender(DTM_INTE struct addrinfo addr_criteria, *p; // Criteria for address match char local_port_str[INET6_ADDRSTRLEN]; int rv; - char mcast_addr_eth[INET6_ADDRSTRLEN + IFNAMSIZ]; TRACE_ENTER(); dtms_cb->dgram_sock_sndr = -1; @@ -826,6 +780,7 @@ uint32_t dtm_dgram_mcast_sender(DTM_INTE /* For link-local address, need to set sin6_scope_id to match the device index of the network device on it has to connecct */ if (dtms_cb->scope_link == true) { + char mcast_addr_eth[INET6_ADDRSTRLEN + IFNAMSIZ]; memset(mcast_addr_eth, 0, (INET6_ADDRSTRLEN + IFNAMSIZ)); sprintf(mcast_addr_eth,"%s%s%s",dtms_cb->mcast_addr,"%",dtms_cb->ifname); rv = getaddrinfo(mcast_addr_eth, local_port_str, &addr_criteria, &mcast_sender_addr); @@ -875,24 +830,6 @@ uint32_t dtm_dgram_mcast_sender(DTM_INTE } /** - * Function to get the address - * - * @param sa - * - * @return NCSCC_RC_SUCCESS - * @return NCSCC_RC_FAILURE - * - */ -void *get_in_addr(struct sockaddr *sa) -{ - if (sa->sa_family == AF_INET) { - return &(((struct sockaddr_in *)sa)->sin_addr); - } - - return &(((struct sockaddr_in6 *)sa)->sin6_addr); -} - -/** * Function to listen to the bcast message * * @param dtms_cb @@ -904,7 +841,7 @@ void *get_in_addr(struct sockaddr *sa) uint32_t dtm_dgram_bcast_listener(DTM_INTERNODE_CB * dtms_cb) { - struct addrinfo addr_criteria, *addr_list, *p; // Criteria for address + struct addrinfo addr_criteria, *addr_list = NULL, *p; // Criteria for address char local_port_str[INET6_ADDRSTRLEN]; int rv; char bcast_addr_eth[INET6_ADDRSTRLEN + IFNAMSIZ]; @@ -1011,6 +948,7 @@ uint32_t dtm_dgram_bcast_listener(DTM_IN struct ipv6_mreq maddr; struct sockaddr_in6 *ipv6_mr = (struct sockaddr_in6 *)p->ai_addr; + memset(&maddr, 0, sizeof(maddr)); maddr.ipv6mr_multiaddr = ipv6_mr->sin6_addr; maddr.ipv6mr_interface = if_nametoindex(dtms_cb->ifname); if (setsockopt(dtms_cb->dgram_sock_rcvr, IPPROTO_IPV6, IPV6_ADD_MEMBERSHIP, &maddr, @@ -1141,6 +1079,7 @@ uint32_t dtm_dgram_bcast_sender(DTM_INTE } struct ipv6_mreq maddr; + memset(&maddr, 0, sizeof(maddr)); maddr.ipv6mr_multiaddr = bcast_sender_addr_in6->sin6_addr; maddr.ipv6mr_interface = if_nametoindex(dtms_cb->ifname); if (setsockopt (dtms_cb->dgram_sock_sndr, IPPROTO_IPV6, IPV6_ADD_MEMBERSHIP, &maddr, sizeof maddr) < 0) { @@ -1425,8 +1364,6 @@ int dtm_process_accept(DTM_INTERNODE_CB int dtm_dgram_recvfrom_bmcast(DTM_INTERNODE_CB * dtms_cb, char *node_ip, void *buffer, int buffer_len) { struct sockaddr_storage clnt_addr; - void *numericAddress = NULL; /* Pointer to binary address */ - char addrBuffer[INET6_ADDRSTRLEN]; socklen_t addrLen = sizeof(clnt_addr); int rtn; TRACE_ENTER(); @@ -1440,6 +1377,7 @@ int dtm_dgram_recvfrom_bmcast(DTM_INTERN } else { const struct sockaddr *clnt_addr1 = (struct sockaddr *)&clnt_addr; + void *numericAddress = NULL; /* Pointer to binary address */ if (clnt_addr1->sa_family == AF_INET) { numericAddress = &((struct sockaddr_in *)clnt_addr1)->sin_addr; @@ -1454,6 +1392,7 @@ int dtm_dgram_recvfrom_bmcast(DTM_INTERN } /* Convert binary to printable address */ + char addrBuffer[INET6_ADDRSTRLEN]; if (inet_ntop(clnt_addr1->sa_family, numericAddress, addrBuffer, sizeof(addrBuffer)) == NULL) { TRACE("DTM: invalid address :%s", addrBuffer); } else { @@ -1464,150 +1403,3 @@ int dtm_dgram_recvfrom_bmcast(DTM_INTERN TRACE_LEAVE2("rc :%d", rtn); return rtn; } - -#if 0 -/********************************************************* - - Function NAME: -DESCRIPTION: - -ARGUMENTS: - -RETURNS: - - *********************************************************/ - -uint32_t dtm_get_sa_family(DTM_INTERNODE_CB * dtms_cb) -{ - - uint32_t rc = NCSCC_RC_SUCCESS; - char local_port_str[INET6_ADDRSTRLEN]; - struct addrinfo addr_criteria; /* Criteria for address match */ - - TRACE_ENTER(); - - char *addr_string = dtms_cb->ip_addr; /* Server address/name */ - - TRACE("DTM :stream_port :%d", dtms_cb->stream_port); - snprintf(local_port_str, sizeof(local_port_str), "%d", (dtms_cb->stream_port)); - - /* Tell the system what kind(s) of address info we want */ - memset(&addr_criteria, 0, sizeof(addr_criteria)); /* Zero out structure */ - addr_criteria.ai_family = AF_UNSPEC; /* Any address family */ - addr_criteria.ai_socktype = SOCK_STREAM; /* Only stream sockets */ - addr_criteria.ai_protocol = IPPROTO_TCP; /* Only TCP protocol */ - addr_criteria.ai_flags |= AI_NUMERICHOST; - - /* Get address(es) associated with the specified name/service */ - struct addrinfo *addr_list; /* Holder for list of addresses returned */ - /* Modify servAddr contents to reference linked list of addresses */ - TRACE("DTM :addr_string : %s local_port_str :%s", addr_string, local_port_str); - int rtn_val = getaddrinfo(addr_string, local_port_str, &addr_criteria, &addr_list); - if (rtn_val != 0) - LOG_ER("getaddrinfo() failed %d", rtn_val); - - /* Display returned addresses */ - struct addrinfo *addr; - for (addr = addr_list; addr != NULL; addr = addr->ai_next) { - - if (addr->ai_addr->sa_family == AF_INET) { - dtms_cb->i_addr_family = DTM_IP_ADDR_TYPE_IPV4; - TRACE("DTM :dtms_cb->i_addr_family :%d", dtms_cb->i_addr_family); - goto done; - } else if (addr->ai_addr->sa_family == AF_INET6) { - dtms_cb->i_addr_family = DTM_IP_ADDR_TYPE_IPV6; - TRACE("DTM :dtms_cb->i_addr_family :%d", dtms_cb->i_addr_family); - goto done; - } - - else - continue; - - } - - rc = NCSCC_RC_FAILURE; - done: - /* Free address structure(s) allocated by getaddrinfo() */ - freeaddrinfo(addr_list); - TRACE_LEAVE2("rc :%d", rc); - return rc; - -} - -/********************************************************* - - Function NAME: -DESCRIPTION: - -ARGUMENTS: - -RETURNS: - - *********************************************************/ - -char *get_local_address(int sock_desc) -{ - TRACE_ENTER(); - struct addrinfo addr; - unsigned int addr_len = sizeof(addr); - - if (getsockname(sock_desc, (sockaddr *) & addr, (socklen_t *)&addr_len) < 0) { - LOG_ER("DTM :Fetch of local address failed (getsockname())"); - return NULL; - } - TRACE_LEAVE(); - return inet_ntoa(addr.sin_addr); -} - -unsigned short get_local_port(int sock_desc) -{ - TRACE_ENTER(); - struct addrinfo addr; - unsigned int addr_len = sizeof(addr); - - if (getsockname(sock_desc, (sockaddr *) & addr, (socklen_t *)&addr_len) < 0) { - LOG_ER("DTM :Fetch of local port failed (getsockname())"); - return 0; - } - TRACE_LEAVE(); - return ntohs(addr.sin_port); -} - -/********************************************************* - - Function NAME: -DESCRIPTION: - -ARGUMENTS: - -RETURNS: - - *********************************************************/ -uint32_t dgram_set_mcastloop(bool x) -{ - - TRACE_ENTER(); - if (mcast_sender_addr->ai_family == AF_INET6) { - int val = x ? 1 : 0; - if (setsockopt(dtms_cb->dgram_sock_rcvr, IPPROTO_IPV6, IPV6_MULTICAST_LOOP, (char *)&val, sizeof(int)) - == -1) { - LOG_ER("DTM:SetMulticastLoop(ipv6)"); - } - return; - } else if (mcast_sender_addr->ai_family == AF_INET) { - - int val = x ? 1 : 0; - if (setsockopt(dtms_cb->dgram_sock_rcvr, SOL_IP, IP_MULTICAST_LOOP, (char *)&val, sizeof(int)) == -1) { - LOG_ER("DTM:SetMulticastLoop(ipv4)"); - } - - } else { - LOG_ER("DTM:Unable to set set_mcastloop invalid address family"); - } - - TRACE_LEAVE(); - return NCSCC_RC_SUCCESS; - -} - -#endif diff --git a/osaf/services/infrastructure/dtms/dtm/dtm_read_config.c b/osaf/services/infrastructure/dtms/dtm/dtm_read_config.c --- a/osaf/services/infrastructure/dtms/dtm/dtm_read_config.c +++ b/osaf/services/infrastructure/dtms/dtm/dtm_read_config.c @@ -22,6 +22,7 @@ #include <netinet/in.h> #include <netinet/ip.h> #include <sys/socket.h> +#include <stdio.h> #include <configmake.h> #include "logtrace.h" #include "ncs_main_papi.h" @@ -136,8 +137,6 @@ char *dtm_validate_listening_ip_addr(DTM { struct ifaddrs *if_addrs = NULL; struct ifaddrs *if_addr = NULL; - void *tmp = NULL; - char buf[INET6_ADDRSTRLEN]; memset(match_ip, 0, INET6_ADDRSTRLEN); if (0 == getifaddrs(&if_addrs)) { @@ -149,6 +148,7 @@ char *dtm_validate_listening_ip_addr(DTM continue; // Address + void *tmp = NULL; if (if_addr->ifa_addr->sa_family == AF_INET) { tmp = &((struct sockaddr_in *)if_addr->ifa_addr)->sin_addr; } else if (if_addr->ifa_addr->sa_family == AF_INET6) { @@ -191,7 +191,7 @@ char *dtm_validate_listening_ip_addr(DTM inet_ntop(if_addr->ifa_addr->sa_family, &broadaddr, config->bcast_addr, - sizeof(buf)); + sizeof(config->bcast_addr)); } else if (if_addr->ifa_addr->sa_family == AF_INET6) { struct sockaddr_in6 *addr = (struct sockaddr_in6 *)if_addr->ifa_addr; memset(config->bcast_addr, 0, INET6_ADDRSTRLEN); @@ -268,7 +268,7 @@ int dtm_read_config(DTM_INTERNODE_CB * c LOG_ER("DTM: Could not open file node_name "); return errno; } - if (EOF == fscanf(fp, "%s", config->node_name)) { + if (EOF == fscanf(fp, "%255s", config->node_name)) { fclose(fp); LOG_ER("DTM: Could not get node name "); return errno; @@ -324,6 +324,7 @@ int dtm_read_config(DTM_INTERNODE_CB * c config->cluster_id = atoi(&line[tag_len]); if (config->cluster_id < 1) { LOG_ER("DTM:cluster_id must be a positive integer"); + fclose(dtm_conf_file); return -1; } tag = 0; @@ -335,6 +336,7 @@ int dtm_read_config(DTM_INTERNODE_CB * c strncpy(config->ip_addr, &line[tag_len], INET6_ADDRSTRLEN - 1); /* ipv4 ipv6 addrBuffer */ if (strlen(config->ip_addr) == 0) { LOG_ER("DTM:ip_addr Shouldn't be NULL"); + fclose(dtm_conf_file); return -1; } @@ -360,6 +362,7 @@ int dtm_read_config(DTM_INTERNODE_CB * c if (config->stream_port < 1) { LOG_ER("DTM:stream_port must be a positive integer"); + fclose(dtm_conf_file); return -1; } @@ -372,6 +375,7 @@ int dtm_read_config(DTM_INTERNODE_CB * c config->dgram_port_sndr = ((in_port_t)atoi(&line[tag_len])); if (config->dgram_port_sndr < 1) { LOG_ER("DTM:dgram_port_sndr must be a positive integer"); + fclose(dtm_conf_file); return -1; } @@ -385,6 +389,7 @@ int dtm_read_config(DTM_INTERNODE_CB * c TRACE("DTM:dgram_port_rcvr :%d", config->dgram_port_rcvr); if (config->dgram_port_rcvr < 1) { LOG_ER("DTM:dgram_port_rcvr t must be a positive integer"); + fclose(dtm_conf_file); return -1; } @@ -397,6 +402,7 @@ int dtm_read_config(DTM_INTERNODE_CB * c config->bcast_msg_freq = atoi(&line[tag_len]); if (config->bcast_msg_freq < 1) { LOG_ER("DTM:bcast_msg_freq must be a positive integer"); + fclose(dtm_conf_file); return -1; } @@ -409,6 +415,7 @@ int dtm_read_config(DTM_INTERNODE_CB * c config->initial_dis_timeout = atoi(&line[tag_len]); if (config->initial_dis_timeout < 1) { LOG_ER("DTM:initial_dis_timeout must be a positive integer"); + fclose(dtm_conf_file); return -1; } @@ -421,6 +428,7 @@ int dtm_read_config(DTM_INTERNODE_CB * c config->so_keepalive = atoi(&line[tag_len]); if (config->so_keepalive < 0 || config->so_keepalive > 1) { LOG_ER("DTM: so_keepalive needs to be 0 or 1"); + fclose(dtm_conf_file); return -1; } @@ -433,6 +441,7 @@ int dtm_read_config(DTM_INTERNODE_CB * c config->comm_keepidle_time = atoi(&line[tag_len]); if (config->comm_keepidle_time < 1) { LOG_ER("DTM:comm_keepidle_time must be a positive integer"); + fclose(dtm_conf_file); return -1; } @@ -445,6 +454,7 @@ int dtm_read_config(DTM_INTERNODE_CB * c config->comm_keepalive_intvl = atoi(&line[tag_len]); if (config->comm_keepalive_intvl < 1) { LOG_ER("DTM:comm_keepalive_intvl must be a positive integer"); + fclose(dtm_conf_file); return -1; } @@ -457,6 +467,7 @@ int dtm_read_config(DTM_INTERNODE_CB * c config->comm_keepalive_probes = atoi(&line[tag_len]); if (config->comm_keepalive_probes < 1) { LOG_ER("DTM:comm_keepalive_probes must be a positive integer"); + fclose(dtm_conf_file); return -1; } @@ -554,25 +565,3 @@ int dtm_read_config(DTM_INTERNODE_CB * c TRACE_LEAVE(); return (err); } - -#if 0 -static int checkfile(char *buf) -{ - struct stat statbuf; - int ii; - char cmd[DTM_MAX_TAG_LEN]; - - strncpy(cmd, buf, DTM_MAX_TAG_LEN - 1); - for (ii = 0; ii < strlen(cmd); ii++) - if (cmd[ii] == ' ') - cmd[ii] = '\0'; - - if (stat(cmd, &statbuf) == -1) { - LOG_ER("DTM: dtm_read_config: File does not exsist: %s", cmd); - return -1; - } - - return 0; -} - -#endif diff --git a/osaf/services/infrastructure/dtms/include/dtm.h b/osaf/services/infrastructure/dtms/include/dtm.h --- a/osaf/services/infrastructure/dtms/include/dtm.h +++ b/osaf/services/infrastructure/dtms/include/dtm.h @@ -106,9 +106,6 @@ extern uint32_t dtm_cb_init(DTM_INTERNOD extern DTM_NODE_DB *dtm_node_get_by_id(uint32_t nodeid); extern DTM_NODE_DB *dtm_node_getnext_by_id(uint32_t node_id); extern DTM_NODE_DB *dtm_node_get_by_comm_socket(uint32_t comm_socket); -extern DTM_NODE_DB *dtm_node_getnext_by_comm_socket(uint32_t comm_socket); -extern DTM_NODE_DB *dtm_node_get_by_node_ip(uint8_t *node_ip); -extern DTM_NODE_DB *dtm_node_getnext_by_nodeaddr(uint8_t *node_ip); extern uint32_t dtm_node_add(DTM_NODE_DB * node, int i); extern uint32_t dtm_node_delete(DTM_NODE_DB * nnode, int i); extern DTM_NODE_DB *dtm_node_new(DTM_NODE_DB * new_node); diff --git a/osaf/services/infrastructure/dtms/include/dtm_cb.h b/osaf/services/infrastructure/dtms/include/dtm_cb.h --- a/osaf/services/infrastructure/dtms/include/dtm_cb.h +++ b/osaf/services/infrastructure/dtms/include/dtm_cb.h @@ -37,7 +37,7 @@ typedef struct dtm_internode_unsent_msgs typedef struct node_list { uint16_t cluster_id; NODE_ID node_id; - char node_name[_POSIX_HOST_NAME_MAX]; + char node_name[256]; char node_ip[INET6_ADDRSTRLEN]; DTM_IP_ADDR_TYPE i_addr_family; /* Indicates V4 or V6 */ int comm_socket; diff --git a/osaf/services/infrastructure/dtms/include/dtm_node.h b/osaf/services/infrastructure/dtms/include/dtm_node.h --- a/osaf/services/infrastructure/dtms/include/dtm_node.h +++ b/osaf/services/infrastructure/dtms/include/dtm_node.h @@ -31,9 +31,7 @@ extern uint32_t dtm_sockdesc_close(int s extern int dtm_process_connect(DTM_INTERNODE_CB * dtms_cb, char *node_ip, uint8_t *buffer, uint16_t len); extern int dtm_process_accept(DTM_INTERNODE_CB * dtms_cb, int stream_sock); extern int dtm_dgram_recvfrom_bmcast(DTM_INTERNODE_CB * dtms_cb, char *node_ip, void *buffer, int buffer_len); -/*extern uint32_t dtm_get_sa_family(DTM_INTERNODE_CB * dtms_cb);*/ extern uint32_t dtm_comm_socket_send(int sock_desc, const void *buffer, int buffer_len); -extern uint32_t dtm_comm_socket_recv(int sock_desc, void *buffer, int buffer_len); extern uint32_t dtm_comm_socket_close(int *comm_socket); extern uint32_t dtm_process_node_up_down(NODE_ID node_id, char *node_name, char *node_ip, DTM_IP_ADDR_TYPE i_addr_family, uint8_t comm_status); uint32_t dtm_internode_set_poll_fdlist(int fd, uint16_t event); ------------------------------------------------------------------------------ _______________________________________________ Opensaf-devel mailing list Opensaf-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/opensaf-devel