Added -m for splitting analysis in sub-analysis steps
This commit is contained in:
+46
-18
@@ -69,10 +69,12 @@ static u_int8_t live_capture = 0;
|
|||||||
static u_int8_t undetected_flows_deleted = 0;
|
static u_int8_t undetected_flows_deleted = 0;
|
||||||
/** User preferences **/
|
/** User preferences **/
|
||||||
static u_int8_t enable_protocol_guess = 1, verbose = 0, nDPI_traceLevel = 0, json_flag = 0;
|
static u_int8_t enable_protocol_guess = 1, verbose = 0, nDPI_traceLevel = 0, json_flag = 0;
|
||||||
|
static u_int32_t pcap_analysis_duration = (u_int32_t)-1;
|
||||||
static u_int16_t decode_tunnels = 0;
|
static u_int16_t decode_tunnels = 0;
|
||||||
static u_int16_t num_loops = 1;
|
static u_int16_t num_loops = 1;
|
||||||
static u_int8_t shutdown_app = 0, quiet_mode = 0;
|
static u_int8_t shutdown_app = 0, quiet_mode = 0;
|
||||||
static u_int8_t num_threads = 1;
|
static u_int8_t num_threads = 1;
|
||||||
|
static struct timeval begin, end;
|
||||||
#ifdef linux
|
#ifdef linux
|
||||||
static int core_affinity[MAX_NUM_READER_THREADS];
|
static int core_affinity[MAX_NUM_READER_THREADS];
|
||||||
#endif
|
#endif
|
||||||
@@ -146,13 +148,14 @@ static void setupDetection(u_int16_t thread_id, pcap_t * pcap_handle);
|
|||||||
static void help(u_int long_help) {
|
static void help(u_int long_help) {
|
||||||
printf("Welcome to nDPI %s\n\n", ndpi_revision());
|
printf("Welcome to nDPI %s\n\n", ndpi_revision());
|
||||||
|
|
||||||
printf("ndpiReader -i <file|device> [-f <filter>][-s <duration>]\n"
|
printf("ndpiReader -i <file|device> [-f <filter>][-s <duration>][-m <duration>]\n"
|
||||||
" [-p <protos>][-l <loops> [-q][-d][-h][-t][-v <level>]\n"
|
" [-p <protos>][-l <loops> [-q][-d][-h][-t][-v <level>]\n"
|
||||||
" [-n <threads>] [-w <file>] [-j <file>]\n\n"
|
" [-n <threads>] [-w <file>] [-j <file>]\n\n"
|
||||||
"Usage:\n"
|
"Usage:\n"
|
||||||
" -i <file.pcap|device> | Specify a pcap file/playlist to read packets from or a device for live capture (comma-separated list)\n"
|
" -i <file.pcap|device> | Specify a pcap file/playlist to read packets from or a device for live capture (comma-separated list)\n"
|
||||||
" -f <BPF filter> | Specify a BPF filter for filtering selected traffic\n"
|
" -f <BPF filter> | Specify a BPF filter for filtering selected traffic\n"
|
||||||
" -s <duration> | Maximum capture duration in seconds (live traffic capture only)\n"
|
" -s <duration> | Maximum capture duration in seconds (live traffic capture only)\n"
|
||||||
|
" -m <duration> | Split analysis duration in <duration> max seconds\n"
|
||||||
" -p <file>.protos | Specify a protocol file (eg. protos.txt)\n"
|
" -p <file>.protos | Specify a protocol file (eg. protos.txt)\n"
|
||||||
" -l <num loops> | Number of detection loops (test only)\n"
|
" -l <num loops> | Number of detection loops (test only)\n"
|
||||||
" -n <num threads> | Number of threads. Default: number of interfaces in -i. Ignored with pcap files.\n"
|
" -n <num threads> | Number of threads. Default: number of interfaces in -i. Ignored with pcap files.\n"
|
||||||
@@ -341,7 +344,7 @@ static void parseOptions(int argc, char **argv) {
|
|||||||
if(trace) fprintf(trace, " #### %s #### \n", __FUNCTION__);
|
if(trace) fprintf(trace, " #### %s #### \n", __FUNCTION__);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
while ((opt = getopt_long(argc, argv, "df:g:i:hp:l:s:tv:V:n:j:rp:w:q0123:456:7:89:", longopts, &option_idx)) != EOF) {
|
while ((opt = getopt_long(argc, argv, "df:g:i:hp:l:s:tv:V:n:j:rp:w:q0123:456:7:89:m:", longopts, &option_idx)) != EOF) {
|
||||||
#ifdef DEBUG_TRACE
|
#ifdef DEBUG_TRACE
|
||||||
if(trace) fprintf(trace, " #### -%c [%s] #### \n", opt, optarg ? optarg : "");
|
if(trace) fprintf(trace, " #### -%c [%s] #### \n", opt, optarg ? optarg : "");
|
||||||
#endif
|
#endif
|
||||||
@@ -356,6 +359,10 @@ static void parseOptions(int argc, char **argv) {
|
|||||||
_pcap_file[0] = optarg;
|
_pcap_file[0] = optarg;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'm':
|
||||||
|
pcap_analysis_duration = atol(optarg);
|
||||||
|
break;
|
||||||
|
|
||||||
case 'f':
|
case 'f':
|
||||||
case '6':
|
case '6':
|
||||||
_bpf_filter = optarg;
|
_bpf_filter = optarg;
|
||||||
@@ -937,7 +944,6 @@ static void setupDetection(u_int16_t thread_id, pcap_t * pcap_handle) {
|
|||||||
* @brief End of detection and free flow
|
* @brief End of detection and free flow
|
||||||
*/
|
*/
|
||||||
static void terminateDetection(u_int16_t thread_id) {
|
static void terminateDetection(u_int16_t thread_id) {
|
||||||
|
|
||||||
ndpi_workflow_free(ndpi_thread_info[thread_id].workflow);
|
ndpi_workflow_free(ndpi_thread_info[thread_id].workflow);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1061,7 +1067,6 @@ void printPortStats(struct port_stats *stats) {
|
|||||||
* @brief Print result
|
* @brief Print result
|
||||||
*/
|
*/
|
||||||
static void printResults(u_int64_t tot_usec) {
|
static void printResults(u_int64_t tot_usec) {
|
||||||
|
|
||||||
u_int32_t i;
|
u_int32_t i;
|
||||||
u_int64_t total_flow_bytes = 0;
|
u_int64_t total_flow_bytes = 0;
|
||||||
u_int32_t avg_pkt_size = 0;
|
u_int32_t avg_pkt_size = 0;
|
||||||
@@ -1117,6 +1122,8 @@ static void printResults(u_int64_t tot_usec) {
|
|||||||
cumulative_stats.max_packet_len += ndpi_thread_info[thread_id].workflow->stats.max_packet_len;
|
cumulative_stats.max_packet_len += ndpi_thread_info[thread_id].workflow->stats.max_packet_len;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(cumulative_stats.total_wire_bytes == 0) return;
|
||||||
|
|
||||||
if(!quiet_mode) {
|
if(!quiet_mode) {
|
||||||
printf("\nnDPI Memory statistics:\n");
|
printf("\nnDPI Memory statistics:\n");
|
||||||
printf("\tnDPI Memory (once): %-13s\n", formatBytes(sizeof(struct ndpi_detection_module_struct), buf, sizeof(buf)));
|
printf("\tnDPI Memory (once): %-13s\n", formatBytes(sizeof(struct ndpi_detection_module_struct), buf, sizeof(buf)));
|
||||||
@@ -1155,7 +1162,7 @@ static void printResults(u_int64_t tot_usec) {
|
|||||||
printf("\tPacket Len > 1500: %-13lu\n", (unsigned long)cumulative_stats.packet_len[5]);
|
printf("\tPacket Len > 1500: %-13lu\n", (unsigned long)cumulative_stats.packet_len[5]);
|
||||||
|
|
||||||
if(tot_usec > 0) {
|
if(tot_usec > 0) {
|
||||||
char buf[32], buf1[32];
|
char buf[32], buf1[32], when[64];
|
||||||
float t = (float)(cumulative_stats.ip_packet_count*1000000)/(float)tot_usec;
|
float t = (float)(cumulative_stats.ip_packet_count*1000000)/(float)tot_usec;
|
||||||
float b = (float)(cumulative_stats.total_wire_bytes * 8 *1000000)/(float)tot_usec;
|
float b = (float)(cumulative_stats.total_wire_bytes * 8 *1000000)/(float)tot_usec;
|
||||||
float traffic_duration;
|
float traffic_duration;
|
||||||
@@ -1164,6 +1171,11 @@ static void printResults(u_int64_t tot_usec) {
|
|||||||
printf("\tnDPI throughput: %s pps / %s/sec\n", formatPackets(t, buf), formatTraffic(b, 1, buf1));
|
printf("\tnDPI throughput: %s pps / %s/sec\n", formatPackets(t, buf), formatTraffic(b, 1, buf1));
|
||||||
t = (float)(cumulative_stats.ip_packet_count*1000000)/(float)traffic_duration;
|
t = (float)(cumulative_stats.ip_packet_count*1000000)/(float)traffic_duration;
|
||||||
b = (float)(cumulative_stats.total_wire_bytes * 8 *1000000)/(float)traffic_duration;
|
b = (float)(cumulative_stats.total_wire_bytes * 8 *1000000)/(float)traffic_duration;
|
||||||
|
|
||||||
|
strftime(when, sizeof(when), "%d/%b/%Y %H:%M:%S", localtime(&pcap_start.tv_sec));
|
||||||
|
printf("\tAnalysis begin: %s\n", when);
|
||||||
|
strftime(when, sizeof(when), "%d/%b/%Y %H:%M:%S", localtime(&pcap_end.tv_sec));
|
||||||
|
printf("\tAnalysis end: %s\n", when);
|
||||||
printf("\tTraffic throughput: %s pps / %s/sec\n", formatPackets(t, buf), formatTraffic(b, 1, buf1));
|
printf("\tTraffic throughput: %s pps / %s/sec\n", formatPackets(t, buf), formatTraffic(b, 1, buf1));
|
||||||
printf("\tTraffic duration: %.3f sec\n", traffic_duration/1000000);
|
printf("\tTraffic duration: %.3f sec\n", traffic_duration/1000000);
|
||||||
}
|
}
|
||||||
@@ -1320,6 +1332,7 @@ static void printResults(u_int64_t tot_usec) {
|
|||||||
printPortStats(dstStats);
|
printPortStats(dstStats);
|
||||||
|
|
||||||
deletePortsStats(srcStats), deletePortsStats(dstStats);
|
deletePortsStats(srcStats), deletePortsStats(dstStats);
|
||||||
|
srcStats = NULL, dstStats = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1328,14 +1341,11 @@ static void printResults(u_int64_t tot_usec) {
|
|||||||
* @brief Force a pcap_dispatch() or pcap_loop() call to return
|
* @brief Force a pcap_dispatch() or pcap_loop() call to return
|
||||||
*/
|
*/
|
||||||
static void breakPcapLoop(u_int16_t thread_id) {
|
static void breakPcapLoop(u_int16_t thread_id) {
|
||||||
|
|
||||||
if(ndpi_thread_info[thread_id].workflow->pcap_handle != NULL) {
|
if(ndpi_thread_info[thread_id].workflow->pcap_handle != NULL) {
|
||||||
pcap_breakloop(ndpi_thread_info[thread_id].workflow->pcap_handle);
|
pcap_breakloop(ndpi_thread_info[thread_id].workflow->pcap_handle);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Sigproc is executed for each packet in the pcap file
|
* @brief Sigproc is executed for each packet in the pcap file
|
||||||
*/
|
*/
|
||||||
@@ -1453,9 +1463,9 @@ static pcap_t * openPcapFileOrDevice(u_int16_t thread_id, const u_char * pcap_fi
|
|||||||
/**
|
/**
|
||||||
* @brief Check pcap packet
|
* @brief Check pcap packet
|
||||||
*/
|
*/
|
||||||
static void pcap_packet_callback_checked(u_char *args,
|
static void pcap_process_packet(u_char *args,
|
||||||
const struct pcap_pkthdr *header,
|
const struct pcap_pkthdr *header,
|
||||||
const u_char *packet) {
|
const u_char *packet) {
|
||||||
struct ndpi_proto p;
|
struct ndpi_proto p;
|
||||||
u_int16_t thread_id = *((u_int16_t*)args);
|
u_int16_t thread_id = *((u_int16_t*)args);
|
||||||
|
|
||||||
@@ -1546,6 +1556,28 @@ static void pcap_packet_callback_checked(u_char *args,
|
|||||||
printf("INTERNAL ERROR: ingress packet was modified by nDPI: this should not happen [thread_id=%u, packetId=%lu, caplen=%u]\n",
|
printf("INTERNAL ERROR: ingress packet was modified by nDPI: this should not happen [thread_id=%u, packetId=%lu, caplen=%u]\n",
|
||||||
thread_id, (unsigned long)ndpi_thread_info[thread_id].workflow->stats.raw_packet_count, header->caplen);
|
thread_id, (unsigned long)ndpi_thread_info[thread_id].workflow->stats.raw_packet_count, header->caplen);
|
||||||
free(packet_checked);
|
free(packet_checked);
|
||||||
|
|
||||||
|
if((pcap_end.tv_sec-pcap_start.tv_sec) > pcap_analysis_duration) {
|
||||||
|
int i;
|
||||||
|
u_int64_t tot_usec;
|
||||||
|
|
||||||
|
gettimeofday(&end, NULL);
|
||||||
|
tot_usec = end.tv_sec*1000000 + end.tv_usec - (begin.tv_sec*1000000 + begin.tv_usec);
|
||||||
|
|
||||||
|
printResults(tot_usec);
|
||||||
|
|
||||||
|
for(i=0; i<ndpi_thread_info[thread_id].workflow->prefs.num_roots; i++) {
|
||||||
|
ndpi_tdestroy(ndpi_thread_info[thread_id].workflow->ndpi_flows_root[i], ndpi_flow_info_freer);
|
||||||
|
ndpi_thread_info[thread_id].workflow->ndpi_flows_root[i] = NULL;
|
||||||
|
|
||||||
|
memset(&ndpi_thread_info[thread_id].workflow->stats, 0, sizeof(struct ndpi_stats));
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("\n-------------------------------------------\n\n");
|
||||||
|
|
||||||
|
memcpy(&begin, &end, sizeof(begin));
|
||||||
|
memcpy(&pcap_start, &pcap_end, sizeof(pcap_start));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -1553,12 +1585,10 @@ static void pcap_packet_callback_checked(u_char *args,
|
|||||||
* @brief Call pcap_loop() to process packets from a live capture or savefile
|
* @brief Call pcap_loop() to process packets from a live capture or savefile
|
||||||
*/
|
*/
|
||||||
static void runPcapLoop(u_int16_t thread_id) {
|
static void runPcapLoop(u_int16_t thread_id) {
|
||||||
|
|
||||||
if((!shutdown_app) && (ndpi_thread_info[thread_id].workflow->pcap_handle != NULL))
|
if((!shutdown_app) && (ndpi_thread_info[thread_id].workflow->pcap_handle != NULL))
|
||||||
pcap_loop(ndpi_thread_info[thread_id].workflow->pcap_handle, -1, &pcap_packet_callback_checked, (u_char*)&thread_id);
|
pcap_loop(ndpi_thread_info[thread_id].workflow->pcap_handle, -1, &pcap_process_packet, (u_char*)&thread_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Process a running thread
|
* @brief Process a running thread
|
||||||
*/
|
*/
|
||||||
@@ -1583,7 +1613,7 @@ void * processing_thread(void *_thread_id) {
|
|||||||
if((!json_flag) && (!quiet_mode)) printf("Running thread %ld...\n", thread_id);
|
if((!json_flag) && (!quiet_mode)) printf("Running thread %ld...\n", thread_id);
|
||||||
|
|
||||||
pcap_loop:
|
pcap_loop:
|
||||||
runPcapLoop(thread_id);
|
runPcapLoop(thread_id);
|
||||||
|
|
||||||
if(playlist_fp[thread_id] != NULL) { /* playlist: read next file */
|
if(playlist_fp[thread_id] != NULL) { /* playlist: read next file */
|
||||||
char filename[256];
|
char filename[256];
|
||||||
@@ -1603,7 +1633,7 @@ void * processing_thread(void *_thread_id) {
|
|||||||
* @brief Begin, process, end detection process
|
* @brief Begin, process, end detection process
|
||||||
*/
|
*/
|
||||||
void test_lib() {
|
void test_lib() {
|
||||||
struct timeval begin, end;
|
struct timeval end;
|
||||||
u_int64_t tot_usec;
|
u_int64_t tot_usec;
|
||||||
long thread_id;
|
long thread_id;
|
||||||
|
|
||||||
@@ -1690,8 +1720,6 @@ int main(int argc, char **argv) {
|
|||||||
automataUnitTest();
|
automataUnitTest();
|
||||||
|
|
||||||
memset(ndpi_thread_info, 0, sizeof(ndpi_thread_info));
|
memset(ndpi_thread_info, 0, sizeof(ndpi_thread_info));
|
||||||
memset(&pcap_start, 0, sizeof(pcap_start));
|
|
||||||
memset(&pcap_end, 0, sizeof(pcap_end));
|
|
||||||
|
|
||||||
parseOptions(argc, argv);
|
parseOptions(argc, argv);
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -129,7 +129,7 @@ struct ndpi_workflow * ndpi_workflow_init(const struct ndpi_workflow_prefs * pre
|
|||||||
|
|
||||||
/* ***************************************************** */
|
/* ***************************************************** */
|
||||||
|
|
||||||
static void ndpi_flow_info_freer(void *node) {
|
void ndpi_flow_info_freer(void *node) {
|
||||||
struct ndpi_flow_info *flow = (struct ndpi_flow_info*)node;
|
struct ndpi_flow_info *flow = (struct ndpi_flow_info*)node;
|
||||||
|
|
||||||
ndpi_free_flow_info_half(flow);
|
ndpi_free_flow_info_half(flow);
|
||||||
|
|||||||
@@ -161,4 +161,5 @@ static inline void ndpi_workflow_set_flow_giveup_callback(struct ndpi_workflow *
|
|||||||
int ndpi_workflow_node_cmp(const void *a, const void *b);
|
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);
|
void process_ndpi_collected_info(struct ndpi_workflow * workflow, struct ndpi_flow_info *flow);
|
||||||
void ethernet_crc32(const void* data, size_t n_bytes, uint32_t* crc);
|
void ethernet_crc32(const void* data, size_t n_bytes, uint32_t* crc);
|
||||||
|
void ndpi_flow_info_freer(void *node);
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user