Fix some issues

This commit is contained in:
emanuele-f
2016-04-19 23:35:35 +02:00
parent 7964e11c7f
commit d7548e72b2
3 changed files with 17 additions and 15 deletions
+13 -13
View File
@@ -109,7 +109,6 @@ static u_int32_t num_flows;
struct reader_thread { struct reader_thread {
struct ndpi_workflow * workflow; struct ndpi_workflow * workflow;
pthread_t pthread; pthread_t pthread;
pcap_t * pcap_handle;
}; };
static struct reader_thread ndpi_thread_info[MAX_NUM_READER_THREADS]; static struct reader_thread ndpi_thread_info[MAX_NUM_READER_THREADS];
@@ -945,8 +944,8 @@ static void printResults(u_int64_t tot_usec) {
/* ***************************************************** */ /* ***************************************************** */
static void breakPcapLoop(u_int16_t thread_id) { static void breakPcapLoop(u_int16_t thread_id) {
if(ndpi_thread_info[thread_id].pcap_handle != NULL) { if(ndpi_thread_info[thread_id].workflow->pcap_handle != NULL) {
pcap_breakloop(ndpi_thread_info[thread_id].pcap_handle); pcap_breakloop(ndpi_thread_info[thread_id].workflow->pcap_handle);
} }
} }
@@ -1062,9 +1061,14 @@ static void pcap_packet_callback_checked(u_char *args,
const u_char *packet) { const u_char *packet) {
u_int16_t thread_id = *((u_int16_t*)args); u_int16_t thread_id = *((u_int16_t*)args);
/* allocate an exact size buffer to check overflows */
uint8_t *packet_checked = malloc(header->caplen);
memcpy(packet_checked, packet, header->caplen);
ndpi_workflow_process_packet(ndpi_thread_info[thread_id].workflow, header, packet_checked);
if((capture_until != 0) && (header->ts.tv_sec >= capture_until)) { if((capture_until != 0) && (header->ts.tv_sec >= capture_until)) {
if(ndpi_thread_info[thread_id].pcap_handle != NULL) if(ndpi_thread_info[thread_id].workflow->pcap_handle != NULL)
pcap_breakloop(ndpi_thread_info[thread_id].pcap_handle); pcap_breakloop(ndpi_thread_info[thread_id].workflow->pcap_handle);
return; return;
} }
@@ -1074,10 +1078,6 @@ static void pcap_packet_callback_checked(u_char *args,
pcap_end.tv_sec = header->ts.tv_sec, pcap_end.tv_usec = header->ts.tv_usec; pcap_end.tv_sec = header->ts.tv_sec, pcap_end.tv_usec = header->ts.tv_usec;
} }
/* allocate an exact size buffer to check overflows */
uint8_t *packet_checked = malloc(header->caplen);
memcpy(packet_checked, packet, header->caplen);
ndpi_workflow_process_packet(ndpi_thread_info[thread_id].workflow, header, packet_checked);
/* check for buffer changes */ /* check for buffer changes */
if(memcmp(packet, packet_checked, header->caplen) != 0) if(memcmp(packet, packet_checked, header->caplen) != 0)
printf("INTERNAL ERROR: ingress packet was nodified by nDPI: this should not happen [thread_id=%u, packetId=%lu]\n", printf("INTERNAL ERROR: ingress packet was nodified by nDPI: this should not happen [thread_id=%u, packetId=%lu]\n",
@@ -1088,8 +1088,8 @@ static void pcap_packet_callback_checked(u_char *args,
/* ******************************************************************** */ /* ******************************************************************** */
static void runPcapLoop(u_int16_t thread_id) { static void runPcapLoop(u_int16_t thread_id) {
if((!shutdown_app) && (ndpi_thread_info[thread_id].pcap_handle != NULL)) if((!shutdown_app) && (ndpi_thread_info[thread_id].workflow->pcap_handle != NULL))
pcap_loop(ndpi_thread_info[thread_id].pcap_handle, -1, &pcap_packet_callback_checked, (u_char*)&thread_id); pcap_loop(ndpi_thread_info[thread_id].workflow->pcap_handle, -1, &pcap_packet_callback_checked, (u_char*)&thread_id);
} }
/* ******************************************************************** */ /* ******************************************************************** */
@@ -1120,8 +1120,8 @@ void *processing_thread(void *_thread_id) {
char filename[256]; char filename[256];
if(getNextPcapFileFromPlaylist(thread_id, filename, sizeof(filename)) == 0 && if(getNextPcapFileFromPlaylist(thread_id, filename, sizeof(filename)) == 0 &&
(ndpi_thread_info[thread_id].pcap_handle = pcap_open_offline(filename, pcap_error_buffer)) != NULL) { (ndpi_thread_info[thread_id].workflow->pcap_handle = pcap_open_offline(filename, pcap_error_buffer)) != NULL) {
configurePcapHandle(ndpi_thread_info[thread_id].pcap_handle); configurePcapHandle(ndpi_thread_info[thread_id].workflow->pcap_handle);
goto pcap_loop; goto pcap_loop;
} }
} }
+1
View File
@@ -16,6 +16,7 @@ libndpi_la_include_HEADERS = ../include/ndpi_api.h \
libndpi_la_SOURCES = ndpi_content_match.c.inc \ libndpi_la_SOURCES = ndpi_content_match.c.inc \
ndpi_main.c \ ndpi_main.c \
ndpi_util.c \
protocols/afp.c \ protocols/afp.c \
protocols/aimini.c \ protocols/aimini.c \
protocols/applejuice.c \ protocols/applejuice.c \
+1
View File
@@ -149,6 +149,7 @@ struct ndpi_workflow * ndpi_workflow_init(const struct ndpi_workflow_prefs * pre
workflow->idle_flows = ndpi_malloc(sizeof(struct ndpi_flow_info *) * workflow->num_idle_flows); workflow->idle_flows = ndpi_malloc(sizeof(struct ndpi_flow_info *) * workflow->num_idle_flows);
workflow->ndpi_flows_root = ndpi_malloc(sizeof(void *) * workflow->prefs.num_roots); workflow->ndpi_flows_root = ndpi_malloc(sizeof(void *) * workflow->prefs.num_roots);
return workflow;
} }
void ndpi_workflow_free(struct ndpi_workflow * workflow) { void ndpi_workflow_free(struct ndpi_workflow * workflow) {