aboutsummaryrefslogtreecommitdiff
path: root/example
diff options
context:
space:
mode:
Diffstat (limited to 'example')
-rw-r--r--example/ndpiReader.c63
-rw-r--r--example/reader_util.c39
-rw-r--r--example/reader_util.h4
3 files changed, 83 insertions, 23 deletions
diff --git a/example/ndpiReader.c b/example/ndpiReader.c
index 4be142d28..a03c461be 100644
--- a/example/ndpiReader.c
+++ b/example/ndpiReader.c
@@ -848,9 +848,6 @@ static void parseOptions(int argc, char **argv) {
}
}
- if(_pcap_file[0] == NULL)
- help(0);
-
if(csv_fp)
printCSVHeader();
@@ -860,6 +857,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], ",");
@@ -1828,13 +1828,13 @@ 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;
- 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 ) */
@@ -3094,6 +3094,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);
@@ -3111,6 +3115,31 @@ void test_lib() {
/* *********************************************** */
+static void binUnitTest() {
+ struct ndpi_bin b1, b2;
+ u_int8_t num_bins = 32;
+ u_int32_t i;
+ char out_buf[128];
+
+ srand(time(NULL));
+
+ ndpi_init_bin(&b1, ndpi_bin_family8, num_bins), ndpi_init_bin(&b2, ndpi_bin_family8, num_bins);
+
+ for(i=0; i<32; i++)
+ ndpi_inc_bin(&b1, rand() % num_bins), ndpi_inc_bin(&b2, rand() % num_bins);
+
+#if 0
+ printf("1) %s\n", ndpi_print_bin(&b1, 0, out_buf, sizeof(out_buf)));
+ printf("2) %s\n", ndpi_print_bin(&b2, 0, out_buf, sizeof(out_buf)));
+
+ printf("Similarity: %f\n\n", ndpi_bin_similarity(&b1, &b2, 1));
+#endif
+
+ ndpi_free_bin(&b1), ndpi_free_bin(&b2);
+}
+
+/* *********************************************** */
+
static void dgaUnitTest() {
const char *dga[] = {
"lbjamwptxz",
@@ -3474,6 +3503,25 @@ void bpf_filter_port_array_add(int filter_array[], int size, int port) {
/* *********************************************** */
+void analysisUnitTest() {
+ struct ndpi_analyze_struct *s = ndpi_alloc_data_analysis(32);
+ u_int32_t i;
+
+ for(i=0; i<256; i++)
+ ndpi_data_add_value(s, i);
+
+ if(0) {
+ ndpi_data_print_window_values(s);
+ printf("Average: [all: %f][window: %f]\n", ndpi_data_average(s), ndpi_data_window_average(s));
+ printf("Entropy: %f\n", ndpi_data_entropy(s));
+ printf("StdDev: %f\n", ndpi_data_stddev(s));
+ printf("Min/Max: %u/%u\n", ndpi_data_min(s), ndpi_data_max(s));
+ }
+
+ ndpi_free_data_analysis(s);
+}
+
+/* *********************************************** */
/**
@brief MAIN FUNCTION
@@ -3496,6 +3544,7 @@ int orginal_main(int argc, char **argv) {
if(ndpi_info_mod == NULL) return -1;
/* Internal checks */
+ binUnitTest();
dgaUnitTest();
hllUnitTest();
bitmapUnitTest();
@@ -3503,7 +3552,7 @@ int orginal_main(int argc, char **argv) {
serializerUnitTest();
analyzeUnitTest();
ndpi_self_check_host_match();
-
+ analysisUnitTest();
memset(ndpi_thread_info, 0, sizeof(ndpi_thread_info));
parseOptions(argc, argv);
diff --git a/example/reader_util.c b/example/reader_util.c
index fa90b7000..43afcd402 100644
--- a/example/reader_util.c
+++ b/example/reader_util.c
@@ -454,23 +454,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);
@@ -505,7 +495,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);
@@ -517,6 +507,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;
@@ -1708,7 +1714,7 @@ struct ndpi_proto ndpi_workflow_process_packet(struct ndpi_workflow * workflow,
workflow->stats.mpls_count++;
type = ETH_P_IP, ip_offset += 4;
- while(!mpls.mpls.s) {
+ while(!mpls.mpls.s && (((bpf_u_int32)ip_offset) + 4 < header->caplen)) {
mpls.u32 = *((uint32_t *) &packet[ip_offset]);
mpls.u32 = ntohl(mpls.u32);
ip_offset += 4;
@@ -2027,4 +2033,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 8e99bdbbb..75d66bfd4 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 */
@@ -328,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);