From 2effa57d8af2c2a459bcc6cb9f077aa247ea4f20 Mon Sep 17 00:00:00 2001 From: Nardi Ivan Date: Sat, 6 Jun 2020 16:06:46 +0200 Subject: ndpiReader: fix ports statistics They should take idle/expired flows into account, too --- example/ndpiReader.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'example') diff --git a/example/ndpiReader.c b/example/ndpiReader.c index 57f8048df..05dcf9524 100644 --- a/example/ndpiReader.c +++ b/example/ndpiReader.c @@ -1823,6 +1823,8 @@ static void node_idle_scan_walker(const void *node, ndpi_VISIT which, int depth, /* update stats */ node_proto_guess_walker(node, which, depth, user_data); + if(verbose == 3) + port_stats_walker(node, which, depth, user_data); if((flow->detected_protocol.app_protocol == NDPI_PROTOCOL_UNKNOWN) && !undetected_flows_deleted) undetected_flows_deleted = 1; -- cgit v1.2.3 From 2cdf7ce80635071dddc45ac2851ae353ae462ba7 Mon Sep 17 00:00:00 2001 From: Nardi Ivan Date: Wed, 10 Jun 2020 18:56:44 +0200 Subject: Fix startup when DPDK is enabled Fixes:a58c838c4 --- example/ndpiReader.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'example') diff --git a/example/ndpiReader.c b/example/ndpiReader.c index 05dcf9524..ba2df3234 100644 --- a/example/ndpiReader.c +++ b/example/ndpiReader.c @@ -843,9 +843,6 @@ static void parseOptions(int argc, char **argv) { } } - if(_pcap_file[0] == NULL) - help(0); - if(csv_fp) printCSVHeader(); @@ -855,6 +852,9 @@ static void parseOptions(int argc, char **argv) { extcap_capture(); } + if(_pcap_file[0] == NULL) + help(0); + if(strchr(_pcap_file[0], ',')) { /* multiple ingress interfaces */ num_threads = 0; /* setting number of threads = number of interfaces */ __pcap_file = strtok(_pcap_file[0], ","); -- cgit v1.2.3 From ece5d3e1991f92081ce9cc5db43ce202fc29638e Mon Sep 17 00:00:00 2001 From: Nardi Ivan Date: Wed, 10 Jun 2020 18:58:16 +0200 Subject: Fix (harmless) memory leaks when DPDK is enabled --- example/ndpiReader.c | 4 ++++ example/reader_util.c | 5 +++++ example/reader_util.h | 1 + 3 files changed, 10 insertions(+) (limited to 'example') diff --git a/example/ndpiReader.c b/example/ndpiReader.c index ba2df3234..d018c1672 100644 --- a/example/ndpiReader.c +++ b/example/ndpiReader.c @@ -3091,6 +3091,10 @@ void test_lib() { } } +#ifdef USE_DPDK + dpdk_port_deinit(dpdk_port_id); +#endif + gettimeofday(&end, NULL); processing_time_usec = end.tv_sec*1000000 + end.tv_usec - (begin.tv_sec*1000000 + begin.tv_usec); setup_time_usec = begin.tv_sec*1000000 + begin.tv_usec - (startup_time.tv_sec*1000000 + startup_time.tv_usec); diff --git a/example/reader_util.c b/example/reader_util.c index 753c78cf1..d48087f15 100644 --- a/example/reader_util.c +++ b/example/reader_util.c @@ -2032,4 +2032,9 @@ int dpdk_port_init(int port, struct rte_mempool *mbuf_pool) { return 0; } +int dpdk_port_deinit(int port) { + rte_eth_dev_stop(port); + rte_eth_dev_close(port); +} + #endif diff --git a/example/reader_util.h b/example/reader_util.h index 8298e2ef8..d49ba6392 100644 --- a/example/reader_util.h +++ b/example/reader_util.h @@ -50,6 +50,7 @@ #define PREFETCH_OFFSET 3 extern int dpdk_port_init(int port, struct rte_mempool *mbuf_pool); +extern int dpdk_port_deinit(int port); #endif /* ETTA Spec defiintions for feature readiness */ -- cgit v1.2.3 From b24f5c4c0af2df8fd519e79cbcdf699a3b7c38bd Mon Sep 17 00:00:00 2001 From: Nardi Ivan Date: Tue, 23 Jun 2020 19:32:33 +0200 Subject: Fix memory leak about purged/expired flows Create an helper to avoid similar errors in the future Fixes: 1a62f4c7 --- example/ndpiReader.c | 4 +--- example/reader_util.c | 32 +++++++++++++++++++------------- example/reader_util.h | 3 +-- 3 files changed, 21 insertions(+), 18 deletions(-) (limited to 'example') diff --git a/example/ndpiReader.c b/example/ndpiReader.c index d018c1672..2ded09888 100644 --- a/example/ndpiReader.c +++ b/example/ndpiReader.c @@ -1829,9 +1829,7 @@ static void node_idle_scan_walker(const void *node, ndpi_VISIT which, int depth, if((flow->detected_protocol.app_protocol == NDPI_PROTOCOL_UNKNOWN) && !undetected_flows_deleted) undetected_flows_deleted = 1; - ndpi_free_flow_info_half(flow); - ndpi_free_flow_data_analysis(flow); - ndpi_free_flow_tls_data(flow); + ndpi_flow_info_free_data(flow); ndpi_thread_info[thread_id].workflow->stats.ndpi_flow_count--; /* adding to a queue (we can't delete it from the tree inline ) */ diff --git a/example/reader_util.c b/example/reader_util.c index d48087f15..508777ec2 100644 --- a/example/reader_util.c +++ b/example/reader_util.c @@ -459,23 +459,13 @@ struct ndpi_workflow* ndpi_workflow_init(const struct ndpi_workflow_prefs * pref void ndpi_flow_info_freer(void *node) { struct ndpi_flow_info *flow = (struct ndpi_flow_info*)node; - ndpi_free_flow_info_half(flow); - ndpi_free_flow_data_analysis(flow); - ndpi_free_flow_tls_data(flow); - -#ifdef DIRECTION_BINS - ndpi_free_bin(&flow->payload_len_bin_src2dst); - ndpi_free_bin(&flow->payload_len_bin_dst2src); -#else - ndpi_free_bin(&flow->payload_len_bin); -#endif - + ndpi_flow_info_free_data(flow); ndpi_free(flow); } /* ***************************************************** */ -void ndpi_free_flow_tls_data(struct ndpi_flow_info *flow) { +static void ndpi_free_flow_tls_data(struct ndpi_flow_info *flow) { if(flow->ssh_tls.server_names) { ndpi_free(flow->ssh_tls.server_names); @@ -510,7 +500,7 @@ void ndpi_free_flow_tls_data(struct ndpi_flow_info *flow) { /* ***************************************************** */ -void ndpi_free_flow_data_analysis(struct ndpi_flow_info *flow) { +static void ndpi_free_flow_data_analysis(struct ndpi_flow_info *flow) { if(flow->iat_c_to_s) ndpi_free_data_analysis(flow->iat_c_to_s); if(flow->iat_s_to_c) ndpi_free_data_analysis(flow->iat_s_to_c); @@ -522,6 +512,22 @@ void ndpi_free_flow_data_analysis(struct ndpi_flow_info *flow) { /* ***************************************************** */ +void ndpi_flow_info_free_data(struct ndpi_flow_info *flow) { + + ndpi_free_flow_info_half(flow); + ndpi_free_flow_data_analysis(flow); + ndpi_free_flow_tls_data(flow); + +#ifdef DIRECTION_BINS + ndpi_free_bin(&flow->payload_len_bin_src2dst); + ndpi_free_bin(&flow->payload_len_bin_dst2src); +#else + ndpi_free_bin(&flow->payload_len_bin); +#endif +} + +/* ***************************************************** */ + void ndpi_workflow_free(struct ndpi_workflow * workflow) { u_int i; diff --git a/example/reader_util.h b/example/reader_util.h index d49ba6392..c94998496 100644 --- a/example/reader_util.h +++ b/example/reader_util.h @@ -329,9 +329,8 @@ static inline void ndpi_workflow_set_flow_giveup_callback(struct ndpi_workflow * int ndpi_workflow_node_cmp(const void *a, const void *b); void process_ndpi_collected_info(struct ndpi_workflow * workflow, struct ndpi_flow_info *flow); u_int32_t ethernet_crc32(const void* data, size_t n_bytes); +void ndpi_flow_info_free_data(struct ndpi_flow_info *flow); void ndpi_flow_info_freer(void *node); -void ndpi_free_flow_data_analysis(struct ndpi_flow_info *flow); -void ndpi_free_flow_tls_data(struct ndpi_flow_info *flow); const char* print_cipher_id(u_int32_t cipher); float ndpi_flow_get_byte_count_entropy(const uint32_t byte_count[256], unsigned int num_bytes); -- cgit v1.2.3