diff options
author | Vishwesh M Rudramuni <vishwesh.m.rudramuni@intel.com> | 2017-10-05 03:37:35 +0530 |
---|---|---|
committer | Deepak S <deepak.s@linux.intel.com> | 2017-10-06 17:41:18 -0700 |
commit | 2280f91c9c4a2261f44e19dadb4f450ef6c92e77 (patch) | |
tree | a71278588d30257e00660fe9ee05708c392ac70e | |
parent | cd3527b101c97a66d02069a0d60c4e53b4a7d863 (diff) |
common code: KW fixes for common code
This patch fixes KW issues seen with the common code.
Change-Id: I4f90369152345ea2ea9316b04ac946c0c69fd7d1
Signed-off-by: Vishwesh M Rudramuni <vishwesh.m.rudramuni@intel.com>
-rw-r--r-- | common/VIL/alg/lib_ftp_alg.c | 69 | ||||
-rw-r--r-- | common/VIL/alg/lib_sip_alg.c | 23 | ||||
-rw-r--r-- | common/VIL/l2l3_stack/lib_arp.c | 93 | ||||
-rw-r--r-- | common/VIL/l2l3_stack/lib_icmpv6.c | 2 | ||||
-rw-r--r-- | common/VIL/pipeline_arpicmp/pipeline_arpicmp.c | 18 | ||||
-rw-r--r-- | common/VIL/pipeline_arpicmp/pipeline_arpicmp_be.c | 6 | ||||
-rw-r--r-- | common/vnf_common/rest_api.c | 110 | ||||
-rw-r--r-- | common/vnf_common/thread.c | 5 | ||||
-rw-r--r-- | common/vnf_common/vnf_common.c | 5 |
9 files changed, 208 insertions, 123 deletions
diff --git a/common/VIL/alg/lib_ftp_alg.c b/common/VIL/alg/lib_ftp_alg.c index 7e8e43f1..f653de8b 100644 --- a/common/VIL/alg/lib_ftp_alg.c +++ b/common/VIL/alg/lib_ftp_alg.c @@ -174,7 +174,13 @@ populate_ftp_alg_entry(uint32_t ipaddr, uint8_t portid) return; } new_alg_data = (struct ftp_alg_table_entry *) - malloc(sizeof(new_alg_data)); + malloc(sizeof(struct ftp_alg_table_entry)); + + if (!new_alg_data) { + printf("new_alg_data could not be allocated\n"); + return; + } + //new_alg_data->status = INCOMPLETE; new_alg_data->l4port = rte_bswap16(portid); new_alg_data->ip_address = rte_bswap32(ipaddr); @@ -482,18 +488,18 @@ void ftp_alg_dpi( uint16_t private_port_number; uint16_t public_port_number; uint16_t ip1, ip2, ip3, ip4, port1, port2; - int16_t tcpSeqdiff; + int16_t tcpSeqdiff = 0; int16_t ackSeqdiff, ackAdjust; uint32_t private_address; uint32_t public_address; uint8_t *bptr_private_address; /* also for PASV string */ - char port_string[FTP_MAXIMUM_PORT_STRING_LENGTH]; + char port_string[65]; char port_string_translated[FTP_MAXIMUM_PORT_STRING_LENGTH]; - int16_t new_port_string_length; + int16_t new_port_string_length = 0; int16_t old_port_string_length; int dummy_value; - struct cgnapt_table_entry *egress_entry, *ingress_entry; + struct cgnapt_table_entry *egress_entry = NULL, *ingress_entry; uint32_t ct_key[10]; uint8_t key_direction; /*Since v6 is not supported now*/ @@ -597,7 +603,7 @@ void ftp_alg_dpi( &ip1, &ip2, &ip3, &ip4, &port1, &port2) == FTP_PASV_PARAMETER_COUNT){ - sprintf (port_string, FTP_PASV_PARAMETER_STRING, FTP_PASV_RETURN_CODE, + snprintf (port_string, sizeof(port_string), FTP_PASV_PARAMETER_STRING, FTP_PASV_RETURN_CODE, ip1, ip2, ip3, ip4, port1, port2); int i = 0; @@ -672,22 +678,25 @@ void ftp_alg_dpi( ((thdr->data_off & 0xf0) >> 2) - ip_hdr_size_bytes; cgnat_cnxn_tracker->hash_table_entries[ct_position]. tcp_payload_size = tmp_tcp_paylod_size; + if(egress_entry) { - /*Adding ALG entry , params to be derived from egress entry*/ - populate_ftp_alg_entry(egress_entry->data.pub_ip, - egress_entry->data.pub_port); - /* payload modification */ - new_port_string_length = ftp_alg_modify_payload(egress_entry, - port_string, - port_string_translated, 1); - strncpy(tcp_header_end, port_string_translated, - strlen(port_string_translated)); - tcpSeqdiff = ftp_alg_delta_tcp_sequence( pkt, port_string, + /*Adding ALG entry , params to be derived from egress entry*/ + populate_ftp_alg_entry(egress_entry->data.pub_ip, + egress_entry->data.pub_port); + + /* payload modification */ + new_port_string_length = ftp_alg_modify_payload(egress_entry, + port_string, + port_string_translated, 1); + strncpy(tcp_header_end, port_string_translated, + strlen(port_string_translated)); + tcpSeqdiff = ftp_alg_delta_tcp_sequence( pkt, port_string, cgnat_cnxn_tracker->hash_table_entries [ct_position].tcpSeqdiff, old_port_string_length, new_port_string_length); + } /* same as rte_synproxy_adjust_pkt_length() in ct */ ftp_alg_modify_pkt_len(pkt); /* @@ -822,19 +831,21 @@ void ftp_alg_dpi( tcp_payload_size = tmp_tcp_paylod_size; /*ALG entry add, params to be derived from egress entry*/ - populate_ftp_alg_entry(egress_entry->data.pub_ip, - egress_entry->data.pub_port); - /* payload modification */ - new_port_string_length = ftp_alg_modify_payload(egress_entry, - port_string, - port_string_translated, 0); - strncpy(tcp_header_end, port_string_translated, - strlen(port_string_translated)); - tcpSeqdiff = ftp_alg_delta_tcp_sequence( pkt, port_string, - cgnat_cnxn_tracker->hash_table_entries - [ct_position].tcpSeqdiff, - old_port_string_length, - new_port_string_length); + if(egress_entry) { + populate_ftp_alg_entry(egress_entry->data.pub_ip, + egress_entry->data.pub_port); + /* payload modification */ + new_port_string_length = ftp_alg_modify_payload(egress_entry, + port_string, + port_string_translated, 0); + strncpy(tcp_header_end, port_string_translated, + strlen(port_string_translated)); + tcpSeqdiff = ftp_alg_delta_tcp_sequence( pkt, port_string, + cgnat_cnxn_tracker->hash_table_entries + [ct_position].tcpSeqdiff, + old_port_string_length, + new_port_string_length); + } /* same as rte_synproxy_adjust_pkt_length() in ct */ ftp_alg_modify_pkt_len(pkt); diff --git a/common/VIL/alg/lib_sip_alg.c b/common/VIL/alg/lib_sip_alg.c index 9940d59a..0e281200 100644 --- a/common/VIL/alg/lib_sip_alg.c +++ b/common/VIL/alg/lib_sip_alg.c @@ -162,6 +162,7 @@ void lib_sip_alg_init(void) } char *itoa(long n); +char itoa_buf[25]; char *itoa(long n) { int len = n == 0 ? 1 : floor(log10l(labs(n))) + 1; @@ -169,10 +170,8 @@ char *itoa(long n) if (n < 0) len++; /* room for negative sign '-' */ - char *buf = calloc(sizeof(char), len + 1); // +1 for null - if(buf != NULL) - snprintf(buf, len + 1, "%ld", n); - return buf; + snprintf(itoa_buf, len + 1, "%ld", n); + return (char *)&itoa_buf; } struct sip_alg_table_entry *retrieve_sip_alg_entry( @@ -340,6 +339,10 @@ int sip_alg_dpi(struct rte_mbuf *pkt, enum pkt_dir pkt_direction, sip_call_id = getSipCallIdStr(pSipMsg + pos + TAG_TO_DATAPOS(SIP_ALG_CALLID)); + if (!sip_call_id) { + printf("sip_call_id returned is NULL\n"); + return 0; + } if (ALG_DEBUG) printf("sipalgdpi: %d call id %s\n", __LINE__, @@ -572,6 +575,9 @@ char *sip_alg_process(struct rte_mbuf *pkt, uint16_t pkt_direction, int sipMsgLen = (pTmpSipMsg - pSipMsg); + if ((sipMsgLen + sdpDataLen) > strlen(pSipMsg)) + return NULL; + char *pSipMsgEnd = pSipMsg + sipMsgLen + sdpDataLen; if (ALG_DEBUG) @@ -1889,7 +1895,11 @@ SipMsgAdvance2: sdpMsgLen += sdpDataLen; tmpSdpLen = itoa(sdpMsgLen); - int tmpStrLen = strlen(tmpSdpLen); + int tmpStrLen; + if (tmpSdpLen) + tmpStrLen = strlen(tmpSdpLen); + else + tmpStrLen = 0; /* move to Content length field & change the length to sipMsgLen */ if (natSipAlgMsgFieldPos(pSipMsg, SIP_ALG_CONTENT_LEN, &pos, 0) @@ -2225,6 +2235,9 @@ char *natSipAlgModifyPayloadAddrPort( if (newStrLen > oldStrLen) *diffLen = newStrLen - oldStrLen; + if (tmpPort) + free(tmpPort); + return pSipMsg; /* modified SIP Msg */ } diff --git a/common/VIL/l2l3_stack/lib_arp.c b/common/VIL/l2l3_stack/lib_arp.c index 42a619d7..39a740dd 100644 --- a/common/VIL/l2l3_stack/lib_arp.c +++ b/common/VIL/l2l3_stack/lib_arp.c @@ -294,13 +294,20 @@ struct arp_entry_data *get_dest_mac_addr_ipv4(const uint32_t nhip, uint32_t phy_port, struct ether_addr *hw_addr) { struct arp_entry_data *ret_arp_data = NULL; + struct ether_addr *x; uint8_t index; /* as part of optimization we store mac address in cache * & thus can be sent without having to retrieve */ if (arp_cache_dest_mac_present(phy_port)) { - ether_addr_copy(get_local_cache_hw_addr(phy_port, nhip), hw_addr); + x = get_local_cache_hw_addr(phy_port, nhip); + if (!x) { + printf("local copy of address not stored\n"); + return NULL; + } + + ether_addr_copy(x, hw_addr); return &arp_entry_data_default; } @@ -352,11 +359,17 @@ struct nd_entry_data *get_dest_mac_addr_ipv6(uint8_t nhipv6[], struct nd_entry_data *ret_nd_data = NULL; struct nd_key_ipv6 tmp_nd_key; + struct ether_addr *addr; tmp_nd_key.port_id = phy_port; if (nd_cache_dest_mac_present(phy_port)) { - ether_addr_copy(get_nd_local_link_hw_addr( - (uint8_t)phy_port, nhipv6), hw_addr); + addr = get_nd_local_link_hw_addr((uint8_t)phy_port, nhipv6); + if (!addr) { + printf("local copy not stored\n"); + return NULL; + } + + ether_addr_copy(addr, hw_addr); return &nd_entry_data_default; } @@ -743,6 +756,7 @@ struct arp_entry_data *retrieve_arp_entry(struct arp_key_ipv4 arp_key, uint8_t m struct nd_entry_data *retrieve_nd_entry(struct nd_key_ipv6 nd_key, uint8_t mode) { struct nd_entry_data *ret_nd_data = NULL; + l2_phy_interface_t *port; nd_key.filler1 = 0; nd_key.filler2 = 0; nd_key.filler3 = 0; @@ -822,7 +836,14 @@ struct nd_entry_data *retrieve_nd_entry(struct nd_key_ipv6 nd_key, uint8_t mode) ret_nd_data->timer_key = callback_key; /* send nd request */ - request_nd(callback_key->ipv6, ifm_get_port(callback_key->port_id)); + port = ifm_get_port(callback_key->port_id); + if (!port) { + printf("port returned is NULL inside retrieve_nd_entry\n"); + rte_rwlock_write_unlock(&ret_nd_data->queue_lock); + return NULL; + } + + request_nd(callback_key->ipv6, port); rte_rwlock_write_unlock(&ret_nd_data->queue_lock); } else { if (ret_nd_data && @@ -849,7 +870,14 @@ struct nd_entry_data *retrieve_nd_entry(struct nd_key_ipv6 nd_key, uint8_t mode) ret_nd_data->timer_key = callback_key; /* send nd request */ - request_nd(callback_key->ipv6, ifm_get_port(callback_key->port_id)); + port = ifm_get_port(callback_key->port_id); + if (!port) { + printf("port returned is NULL inside retrieve_nd_entry\n"); + rte_rwlock_write_unlock(&ret_nd_data->queue_lock); + return NULL; + } + + request_nd(callback_key->ipv6, port); rte_rwlock_write_unlock(&ret_nd_data->queue_lock); } } @@ -911,7 +939,7 @@ void print_arp_table(void) lib_arp_populate_called, lib_arp_delete_called, lib_arp_duplicate_found); - printf("ARP table key len is %lu\n", sizeof(struct arp_key_ipv4)); + printf("ARP table key len is %d\n", (uint32_t) sizeof(struct arp_key_ipv4)); } /* ND IPv6 */ @@ -974,7 +1002,7 @@ void print_nd_table(void) lib_nd_nd_entry_found, lib_nd_no_arp_entry_found, lib_nd_populate_called, lib_nd_delete_called, lib_nd_duplicate_found); - printf("ND table key len is %lu\n\n", sizeof(struct nd_key_ipv6)); + printf("ND table key len is %d\n\n", (uint32_t) sizeof(struct nd_key_ipv6)); } void remove_arp_entry(struct arp_entry_data *ret_arp_data, void *arg) @@ -1052,7 +1080,7 @@ arp_send_buffered_pkts(struct arp_entry_data *ret_arp_data, int i; - if (!hw_addr || !ret_arp_data) + if (!hw_addr || !ret_arp_data || !port) return; rte_rwlock_write_lock(&ret_arp_data->queue_lock); @@ -1097,7 +1125,7 @@ nd_send_buffered_pkts(struct nd_entry_data *ret_nd_data, uint8_t *eth_dest, *eth_src; int i; - if (!hw_addr || !ret_nd_data) + if (!hw_addr || !ret_nd_data || !port) return; rte_rwlock_write_lock(&ret_nd_data->queue_lock); @@ -1193,8 +1221,8 @@ populate_arp_entry(const struct ether_addr *hw_addr, uint32_t ipaddr, } else { rte_rwlock_write_lock(&new_arp_data->queue_lock); ether_addr_copy(hw_addr, &new_arp_data->eth_addr); - if ((new_arp_data->status == INCOMPLETE) || - (new_arp_data->status == PROBE)) { + if (new_arp_data && ((new_arp_data->status == INCOMPLETE) || + (new_arp_data->status == PROBE))) { new_arp_data->status = COMPLETE; new_arp_data->mode = mode; new_arp_data->n_confirmed = rte_rdtsc(); @@ -1295,6 +1323,7 @@ void populate_nd_entry(const struct ether_addr *hw_addr, uint8_t ipv6[], uint8_t i, val = 0; struct nd_key_ipv6 nd_key; nd_key.port_id = portid; + l2_phy_interface_t *port; for (i = 0; i < ND_IPV6_ADDR_SIZE; i++) { nd_key.ipv6[i] = ipv6[i]; @@ -1342,8 +1371,10 @@ void populate_nd_entry(const struct ether_addr *hw_addr, uint8_t ipv6[], if (new_nd_data->status == STALE) { new_nd_data->retry_count = 0; // Reset new_nd_data->status = PROBE; - request_nd(new_nd_data->ipv6, - ifm_get_port(new_nd_data->port)); + port = ifm_get_port(new_nd_data->port); + + if (port) + request_nd(new_nd_data->ipv6, port); if (rte_timer_reset(new_nd_data->timer, (arp_timeout * rte_get_tsc_hz()), @@ -1360,8 +1391,8 @@ void populate_nd_entry(const struct ether_addr *hw_addr, uint8_t ipv6[], } else { rte_rwlock_write_lock(&new_nd_data->queue_lock); ether_addr_copy(hw_addr, &new_nd_data->eth_addr); - if ((new_nd_data->status == INCOMPLETE) || - (new_nd_data->status == PROBE)) { + if (new_nd_data && ((new_nd_data->status == INCOMPLETE) || + (new_nd_data->status == PROBE))) { new_nd_data->status = COMPLETE; new_nd_data->mode = mode; new_nd_data->n_confirmed = rte_rdtsc(); @@ -2092,6 +2123,12 @@ static int arp_parse_args(struct pipeline_params *params) RTE_SET_USED(nd_route_tbl_present); RTE_SET_USED(arp_route_tbl_present); for (numArg = 0; numArg < params->n_args; numArg++) { + + if(strlen(params->args_value[numArg]) > PIPELINE_MAX_ARGS) { + /* KW Fix */ + printf("WARNING: Non-Null terminated Parameter not processed\n"); + continue; + } char *arg_name = params->args_name[numArg]; char *arg_value = params->args_value[numArg]; @@ -2192,12 +2229,15 @@ static int arp_parse_args(struct pipeline_params *params) tx_phy_port_num, txport); if ((rxport >= PIPELINE_MAX_PORT_IN) || - (txport >= PIPELINE_MAX_PORT_IN) || - (in_port_dir_a[rxport] != 1)) { + (txport >= PIPELINE_MAX_PORT_IN)) { printf - ("CG-NAPT parse error - incorrect prv-pub translation. Rx %d, Tx %d, Rx Dir %d\n", - rxport, txport, - in_port_dir_a[rxport]); + ("CG-NAPT parse error - incorrect prv-pub translation. Rx %d, Tx %d\n", + rxport, txport); + return -1; + } + + if (in_port_dir_a[rxport] != 1) { + printf("CG-NAPT parse error - incorrect rx_port supplied\n"); return -1; } @@ -2271,6 +2311,10 @@ static int arp_parse_args(struct pipeline_params *params) } tx_port_str[k] = '\0'; tx_port = strtoul(tx_port_str, NULL, 16); //atoi(tx_port_str); + if (tx_port > MAX_ROUTE_ENTRY_SIZE) { + printf("tx_port is greater than route entry max size\n"); + continue; + } k++; l = 0; @@ -2710,6 +2754,7 @@ void nd_timer_callback(struct rte_timer *timer, void *arg) int j; struct nd_entry_data *ret_nd_data = NULL; uint64_t now; + l2_phy_interface_t *port; nd_key.port_id = timer_key->port_id; nd_key.filler1 = 0; @@ -2755,9 +2800,13 @@ void nd_timer_callback(struct rte_timer *timer, void *arg) "TIMER STARTED FOR %u seconds\n", ARP_TIMER_EXPIRY); } + port = ifm_get_port(ret_nd_data->port); + if (!port) { + printf("port is NULL in nd_timer_callback\n"); + return; + } - request_nd(ret_nd_data->ipv6, - ifm_get_port(ret_nd_data->port)); + request_nd(ret_nd_data->ipv6, port); if (rte_timer_reset(ret_nd_data->timer, (PROBE_TIME * rte_get_tsc_hz()/ 1000), diff --git a/common/VIL/l2l3_stack/lib_icmpv6.c b/common/VIL/l2l3_stack/lib_icmpv6.c index eea67b0d..d516717e 100644 --- a/common/VIL/l2l3_stack/lib_icmpv6.c +++ b/common/VIL/l2l3_stack/lib_icmpv6.c @@ -363,7 +363,7 @@ struct rte_mbuf *request_nd(uint8_t ipv6[], l2_phy_interface_t *port) int i; struct rte_mbuf *icmpv6_pkt = lib_nd_pkt[port->pmdid]; - if (icmpv6_pkt == NULL) { + if ((icmpv6_pkt == NULL) || (port == NULL)) { if (ARPICMP_DEBUG) printf("Error allocating icmpv6_pkt rte_mbuf\n"); return NULL; diff --git a/common/VIL/pipeline_arpicmp/pipeline_arpicmp.c b/common/VIL/pipeline_arpicmp/pipeline_arpicmp.c index 607d13d1..847e2936 100644 --- a/common/VIL/pipeline_arpicmp/pipeline_arpicmp.c +++ b/common/VIL/pipeline_arpicmp/pipeline_arpicmp.c @@ -70,10 +70,10 @@ struct cmd_arp_add_result { }; -uint16_t str2flowtype(char *string); +uint16_t str2flowtype(const char *string); int parse_flexbytes(const char *q_arg, uint8_t *flexbytes, uint16_t max_num); -enum rte_eth_input_set_field str2inset(char *string); +enum rte_eth_input_set_field str2inset(const char *string); int app_pipeline_arpicmp_entry_dbg(struct app_params *app, uint32_t pipeline_id, uint8_t *msg); @@ -168,6 +168,11 @@ cmd_arp_del_parsed(void *parsed_result, arp_key.filler2 = 0; arp_key.filler3 = 0; struct arp_entry_data *new_arp_data = retrieve_arp_entry(arp_key, STATIC_ARP); + if(new_arp_data == NULL) { + /* KW Fix */ + printf("Retrieve arp returned NULL\n"); + return; + } remove_arp_entry(new_arp_data, &arp_key); } else { struct nd_key_ipv6 nd_key; @@ -177,6 +182,11 @@ cmd_arp_del_parsed(void *parsed_result, nd_key.filler2 = 0; nd_key.filler3 = 0; struct nd_entry_data *new_nd_data = retrieve_nd_entry(nd_key, STATIC_ND); + if(new_nd_data == NULL) { + /* KW Fix */ + printf("Retrieve ND returned NULL\n"); + return; + } remove_nd_entry_ipv6(new_nd_data, &nd_key); } } @@ -960,7 +970,7 @@ cmdline_parse_inst_t cmd_set_fwd_mode = { #if 1 -uint16_t str2flowtype(char *string) +uint16_t str2flowtype(const char *string) { uint8_t i = 0; static const struct { @@ -1450,7 +1460,7 @@ struct cmd_set_hash_input_set_result { }; enum rte_eth_input_set_field -str2inset(char *string) +str2inset(const char *string) { uint16_t i; diff --git a/common/VIL/pipeline_arpicmp/pipeline_arpicmp_be.c b/common/VIL/pipeline_arpicmp/pipeline_arpicmp_be.c index 481f8521..61768130 100644 --- a/common/VIL/pipeline_arpicmp/pipeline_arpicmp_be.c +++ b/common/VIL/pipeline_arpicmp/pipeline_arpicmp_be.c @@ -210,7 +210,7 @@ void register_pipeline_Qs(uint8_t pipeline_num, struct pipeline *p) switch (myApp->pipeline_params[pipeline_num]. pktq_in[port_count].type){ - case APP_PKTQ_OUT_HWQ: + case APP_PKTQ_IN_HWQ: hwq = rte->ports_in[port_count].h_port; out_swq = rte->ports_out[port_count].h_port; printf("out_swq: %s\n", @@ -230,7 +230,7 @@ void register_pipeline_Qs(uint8_t pipeline_num, struct pipeline *p) } break; - case APP_PKTQ_OUT_SWQ: + case APP_PKTQ_IN_SWQ: in_swq = rte->ports_in[port_count].h_port; out_swq = rte->ports_out[port_count].h_port; printf("in_swq : %s\n", @@ -432,7 +432,7 @@ void set_phy_inport_id(uint8_t pipeline_num, struct pipeline *p, uint8_t *map) switch (myApp->pipeline_params[pipeline_num]. pktq_in[port_count].type) { - case APP_PKTQ_OUT_HWQ: + case APP_PKTQ_IN_HWQ: hwq = rte->ports_in[port_count].h_port; map[hwq->port_id] = index++; printf("outport_id[%d]:%d\n", index - 1, diff --git a/common/vnf_common/rest_api.c b/common/vnf_common/rest_api.c index 62e9646a..7acbc36b 100644 --- a/common/vnf_common/rest_api.c +++ b/common/vnf_common/rest_api.c @@ -163,7 +163,7 @@ extern int USE_RTM_LOCKS; extern rte_rwlock_t rwlock; extern interface_main_t ifm; extern struct cmdline *pipe_cl; -extern uint16_t str2flowtype(char *string); +extern uint16_t str2flowtype(const char *string); extern void app_run_file(cmdline_parse_ctx_t *ctx, const char *file_name); extern int parse_flexbytes(const char *q_arg, uint8_t *flexbytes, uint16_t max_num); @@ -179,7 +179,7 @@ extern int app_routeadd_config_ipv6(__attribute__((unused)) uint32_t port_id, uint8_t ipv6[], uint32_t depth); -enum rte_eth_input_set_field str2inset(char *string); +enum rte_eth_input_set_field str2inset(const char *string); enum { MASTER = 0, @@ -381,11 +381,17 @@ int get_pipelines_tokens(char *buf) uint32_t id; token = strtok(buf, "/ "); + if (!token) + return -1; + if (strcmp(token, "pipelines")) { return -1; } token = strtok(NULL, "/ "); + if (!token) + return -1; + id = atoi(token); if (id > rapp->n_pipelines) { return -1; @@ -594,6 +600,11 @@ int set_hash_input_set_2(struct mg_connection *conn, uint32_t port_id, mg_printf(conn, "<html><body>"); mg_printf(conn, "</body></html>\n"); + if (!inset_field0 || !inset_field1 || !flow_type) { + mg_printf(conn, "inset_field0/1 or flow_type may be NULL!\n"); + return 1; + } + if (enable_flow_dir) { mg_printf(conn, "FDIR Filter is Defined!\n"); mg_printf(conn, "Please undefine FDIR_FILTER flag and define " @@ -610,10 +621,13 @@ int set_hash_input_set_2(struct mg_connection *conn, uint32_t port_id, memset(&info, 0, sizeof(info)); info.info_type = RTE_ETH_HASH_FILTER_INPUT_SET_SELECT; - info.info.input_set_conf.flow_type = str2flowtype(strdup(flow_type)); + info.info.input_set_conf.flow_type = str2flowtype(flow_type); + + if (inset_field0) + info.info.input_set_conf.field[0] = str2inset(inset_field0); - info.info.input_set_conf.field[0] = str2inset(strdup(inset_field0)); - info.info.input_set_conf.field[1] = str2inset(strdup(inset_field1)); + if (inset_field1) + info.info.input_set_conf.field[1] = str2inset(inset_field1); info.info.input_set_conf.inset_size = 2; @@ -830,11 +844,17 @@ int get_link_tokens(char *buf) int linkid; token = strtok(buf, "/ "); + if (!token) + return -1; + if (strcmp(token, "link")) { return -1; } token = strtok(NULL, "/ "); + if (!token) + return -1; + linkid = atoi(token); if (linkid > current_cfg.num_ports) { return -1; @@ -966,8 +986,8 @@ int arpls_handler(struct mg_connection *conn, __rte_unused void *cbdata) lib_arp_populate_called, lib_arp_delete_called, lib_arp_duplicate_found); - len += sprintf(buf + len, "ARP table key len is %lu\n<br/>", - sizeof(struct arp_key_ipv4)); + len += sprintf(buf + len, "ARP table key len is %d\n<br/>", + (uint32_t) sizeof(struct arp_key_ipv4)); mg_printf(conn, "%s\n<br/>", &buf[0]); return 1; } @@ -994,6 +1014,7 @@ void get_mac(struct ether_addr *mac_addr, char *buf) for (i = 0; i < MAC_NUM_BYTES; i++) { mac_addr->addr_bytes[i] = strtoul(byteStr[i], NULL, 16); } + free(buf); } int arp_handler(struct mg_connection *conn, __rte_unused void *cbdata) @@ -1126,7 +1147,14 @@ int arp_handler(struct mg_connection *conn, __rte_unused void *cbdata) nd_key.filler2 = 0; nd_key.filler3 = 0; new_nd_data = retrieve_nd_entry(nd_key, STATIC_ND); + + if(new_nd_data == NULL) { + /* KW Fix */ + mg_printf(conn,"Retrieve ND returned NULL\n"); + return 1; + } remove_nd_entry_ipv6(new_nd_data, &nd_key); + break; case 3: mg_printf(conn, "<p>ND REQ is not supported Yet!!!</p>"); break; @@ -1205,7 +1233,7 @@ int route_handler(struct mg_connection *conn, __rte_unused void *cbdata) json_object_object_foreach(jobj, key, val) { if (!strcmp(key, "portid")) { portid = atoi(json_object_get_string(val)); - if (portid > 64) { + if (portid >= 64) { mg_printf(conn, "Port not supported!!!\n"); return 1; } else if (current_route_parms[portid].enable) { @@ -1295,7 +1323,7 @@ int link_handler(struct mg_connection *conn, __rte_unused void *cbdata) if (!strcmp(key, "linkid")) { link = atoi(json_object_get_string(val)); mg_printf(conn, "linkid:%d \n", link); - if (link > 64) { + if (link >= 64) { mg_printf(conn, "Link id not supported beyond 64\n"); return 1; } @@ -1543,7 +1571,6 @@ int static_cfg_handler(struct mg_connection *conn, __rte_unused void *cbdata) json_object * jobj = json_tokener_parse(buf); len = 0; struct json_object *values; - char *str; i = 0; json_object_object_foreach(jobj, key, val) { @@ -1563,75 +1590,50 @@ int static_cfg_handler(struct mg_connection *conn, __rte_unused void *cbdata) json_object_object_get_ex(jobj, "num_worker", &values); if (values) { - str = strdup(json_object_get_string(values)); - if (str) - memcpy(¤t_cfg.ip_range[pub_ip++].value, str, - sizeof(str)); - } - - json_object_object_get_ex(jobj, "num_worker", &values); - if (values) { - str = strdup(json_object_get_string(values)); - if (str) - current_cfg.num_workers = atoi(str); + memcpy(¤t_cfg.ip_range[pub_ip++].value, json_object_get_string(values), + strlen(json_object_get_string(values))); } json_object_object_get_ex(jobj, "pkt_type", &values); if (values) { - str = strdup(json_object_get_string(values)); - if (str) - memcpy(¤t_cfg.pkt_type, str, - sizeof(current_cfg.pkt_type)); + memcpy(¤t_cfg.pkt_type, json_object_get_string(values), + sizeof(current_cfg.pkt_type)); } json_object_object_get_ex(jobj, "num_lb", &values); if (values) { - str = strdup(json_object_get_string(values)); - if (str) - current_cfg.num_lb = atoi(str); + current_cfg.num_lb = atoi(json_object_get_string(values)); } json_object_object_get_ex(jobj, "num_ports", &values); if (values) { - str = strdup(json_object_get_string(values)); - if (str) - current_cfg.num_ports = atoi(str); + current_cfg.num_ports = atoi(json_object_get_string(values)); } json_object_object_get_ex(jobj, "sw_lb", &values); if (values) { - str = strdup(json_object_get_string(values)); - if (str) - current_cfg.sw_lb = atoi(str); + current_cfg.sw_lb = atoi(json_object_get_string(values)); } json_object_object_get_ex(jobj, "sock_in", &values); if (values) { - str = strdup(json_object_get_string(values)); - if (str) - current_cfg.sock_in = atoi(str); + current_cfg.sock_in = atoi(json_object_get_string(values)); } json_object_object_get_ex(jobj, "hyperthread", &values); if (values) { - str = strdup(json_object_get_string(values)); - if (str) - current_cfg.hyper_thread = atoi(str); + current_cfg.hyper_thread = atoi(json_object_get_string(values)); } json_object_object_get_ex(jobj, "vnf_type", &values); if (values) { - str = strdup(json_object_get_string(values)); - if (str) - memcpy(¤t_cfg.vnf_type, str, - sizeof(current_cfg.vnf_type)); + memcpy(¤t_cfg.vnf_type, json_object_get_string(values), + sizeof(current_cfg.vnf_type)); } json_object_object_get_ex(jobj, "pci_white_list", &values); if (values) { - str = strdup(json_object_get_string(values)); - if (str) - memcpy(¤t_cfg.pci_white_list, str, + memcpy(¤t_cfg.pci_white_list, json_object_get_string(values), sizeof(current_cfg.pci_white_list)); mg_printf(conn, " Binding the ports \n"); bind_the_ports(conn, ¤t_cfg.pci_white_list[0]); @@ -1728,8 +1730,7 @@ void fix_pipelines_data_types(FILE *f, const char *sect_name, struct rte_cfgfile if (strncmp(entries[i].name, "pkt_type", strlen("pkt_type")) == 0) { - memcpy(entries[i].value, current_cfg.pkt_type, - strlen(entries[i].value)); + memcpy(entries[i].value, current_cfg.pkt_type, 24); if (!strcmp(current_cfg.pkt_type, "ipv4")) memcpy(&traffic_type, "4", 1); else @@ -1784,7 +1785,7 @@ void fix_pipelines_data_types(FILE *f, const char *sect_name, struct rte_cfgfile (strncmp(static_cfg[j].key, "nd_route_tbl", strlen(static_cfg[j].key)) == 0)) { memcpy(&entries[i].name, &static_cfg[j].key, - strlen(static_cfg[j].key)); + strlen(entries[i].name)); memcpy(&entries[i].value, &static_cfg[j].value, strlen(static_cfg[j].value)); i++; @@ -1976,8 +1977,6 @@ void fix_pipelines_data_types(FILE *f, const char *sect_name, struct rte_cfgfile workers = 0; } } else { - //if (((workers % (current_cfg.num_workers/current_cfg.num_lb)) == 0) && - // (workers != current_cfg.num_workers)) { if (workers == (current_cfg.num_workers/current_cfg.num_lb)) { tx_start_port += 2; rx_start_port += 2; @@ -2160,8 +2159,8 @@ int flow_director_handler(struct mg_connection *conn, __rte_unused void *cbdata) /* Handler may access the request info using mg_get_request_info */ const struct mg_request_info *req_info = mg_get_request_info(conn); uint32_t port_id = 0, tuple = 0; - char trans_type[24], buf[MAX_BUF_SIZE]; - char *str, field0[MAX_SIZE], field1[MAX_SIZE], field2[MAX_SIZE], + char buf[MAX_BUF_SIZE]; + char field0[MAX_SIZE], field1[MAX_SIZE], field2[MAX_SIZE], field3[MAX_SIZE], flow_type[MAX_SIZE]; if (!strcmp(req_info->request_method, "GET")) { @@ -2192,7 +2191,6 @@ int flow_director_handler(struct mg_connection *conn, __rte_unused void *cbdata) json_object * jobj = json_tokener_parse(buf); json_object_object_foreach(jobj, key, val) { if (!strcmp(key, "trans_type")) { - memcpy(&trans_type, str, sizeof(trans_type)); if (!strcmp(key, "udp")) { memcpy(field2,"udp-src-port", sizeof("udp-src-port")); memcpy(field3,"udp-dst-port", sizeof("udp-dst-port")); @@ -2441,8 +2439,6 @@ rest_api_init(struct app_params *app) app->config_file = strdup(buf); app->parser_file = strdup(buf); - printf("Config file loaded :%s %s\n", app->config_file, traffic_type); - end: return ctx; } diff --git a/common/vnf_common/thread.c b/common/vnf_common/thread.c index dcf272ff..f6f1105f 100644 --- a/common/vnf_common/thread.c +++ b/common/vnf_common/thread.c @@ -59,6 +59,8 @@ do { \ #endif +uint32_t exit_app_thread = 0; + static inline void * thread_msg_recv(struct rte_ring *r) { @@ -226,6 +228,9 @@ app_thread(void *arg) uint32_t n_regular = RTE_MIN(t->n_regular, RTE_DIM(t->regular)); uint32_t n_custom = RTE_MIN(t->n_custom, RTE_DIM(t->custom)); + if (exit_app_thread) + break; + /* Run regular pipelines */ for (j = 0; j < n_regular; j++) { struct app_thread_pipeline_data *data = &t->regular[j]; diff --git a/common/vnf_common/vnf_common.c b/common/vnf_common/vnf_common.c index 93687fd6..ff0039bc 100644 --- a/common/vnf_common/vnf_common.c +++ b/common/vnf_common/vnf_common.c @@ -141,10 +141,11 @@ void trim(char *input) char result[len + 1]; memset(result, 0, sizeof(result)); - for (i = 0; input[i] != '\0'; i++) { + for (i = 0; (input[i] != '\0') && (i < PIPELINE_MAX_ARGS); i++) { if (!isspace(input[i])) result[j++] = input[i]; } + result[j] = '\0'; - strncpy(input, result, len); + strncpy(input, result, strlen(result)); } |