diff --git a/example/ndpiReader.c b/example/ndpiReader.c index 7856ae1a0f6..20436edd86e 100644 --- a/example/ndpiReader.c +++ b/example/ndpiReader.c @@ -40,6 +40,7 @@ #else #include #include +#include #include #include #endif @@ -610,10 +611,10 @@ static void help(u_int long_help) { NDPI_BITMASK_SET_ALL(all); ndpi_set_protocol_detection_bitmask2(ndpi_info_mod, &all); - ndpi_dump_protocols(ndpi_info_mod); + ndpi_dump_protocols(ndpi_info_mod, stdout); printf("\n\nnDPI supported risks:\n"); - ndpi_dump_risks_score(); + ndpi_dump_risks_score(stdout); ndpi_exit_detection_module(ndpi_info_mod); } @@ -973,7 +974,7 @@ static void parseOptions(int argc, char **argv) { switch (opt) { case 'a': - ndpi_generate_options(atoi(optarg)); + ndpi_generate_options(atoi(optarg), stdout); exit(0); case 'A': @@ -2580,46 +2581,6 @@ static void node_idle_scan_walker(const void *node, ndpi_VISIT which, int depth, /* *********************************************** */ -#if 0 -/** - * @brief Print debug - */ -static void debug_printf(u_int32_t protocol, void *id_struct, - ndpi_log_level_t log_level, - const char *format, ...) { - va_list va_ap; - struct tm result; - - if(log_level <= nDPI_LogLevel) { - char buf[8192], out_buf[8192]; - char theDate[32]; - const char *extra_msg = ""; - time_t theTime = time(NULL); - - va_start (va_ap, format); - - if(log_level == NDPI_LOG_ERROR) - extra_msg = "ERROR: "; - else if(log_level == NDPI_LOG_TRACE) - extra_msg = "TRACE: "; - else - extra_msg = "DEBUG: "; - - memset(buf, 0, sizeof(buf)); - strftime(theDate, 32, "%d/%b/%Y %H:%M:%S", localtime_r(&theTime,&result)); - ndpi_snprintf(buf, sizeof(buf)-1, format, va_ap); - - ndpi_snprintf(out_buf, sizeof(out_buf), "%s %s%s", theDate, extra_msg, buf); - printf("%s", out_buf); - fflush(stdout); - } - - va_end(va_ap); -} -#endif - -/* *********************************************** */ - /** * @brief Setup for detection begin */ diff --git a/example/reader_util.c b/example/reader_util.c index 7144626cabd..296a9ae5ba0 100644 --- a/example/reader_util.c +++ b/example/reader_util.c @@ -40,6 +40,7 @@ #else #include #include +#include #endif #include "reader_util.h" diff --git a/src/include/ndpi_api.h b/src/include/ndpi_api.h index 121c3f7f853..e610dc04cc9 100644 --- a/src/include/ndpi_api.h +++ b/src/include/ndpi_api.h @@ -728,21 +728,22 @@ extern "C" { * * @par ndpi_mod = the detection module */ - void ndpi_dump_protocols(struct ndpi_detection_module_struct *mod); + void ndpi_dump_protocols(struct ndpi_detection_module_struct *mod, FILE *dump_out); /** * Generate Options list used in OPNsense firewall plugin * * @par opt = The Option list to generate + * @par dump_out = Output stream for generated options */ - void ndpi_generate_options(u_int opt); + void ndpi_generate_options(u_int opt, FILE *dump_out); /** * Write the list of the scores and their associated risks * - * @par ndpi_mod = the detection module + * @par dump_out = Output stream for dumped risk scores */ - void ndpi_dump_risks_score(void); + void ndpi_dump_risks_score(FILE *dump_out); /** * Read a file and load the protocols diff --git a/src/include/ndpi_define.h.in b/src/include/ndpi_define.h.in index 75f41dac2f3..8d3994637e3 100644 --- a/src/include/ndpi_define.h.in +++ b/src/include/ndpi_define.h.in @@ -164,12 +164,12 @@ #define MAX_DEFAULT_PORTS 5 #ifdef NDPI_ENABLE_DEBUG_MESSAGES - #define NDPI_LOG(proto, m, log_level, args...) \ + #define NDPI_LOG(proto, m, log_level, log_facility, args...) \ { \ struct ndpi_detection_module_struct *mod = (struct ndpi_detection_module_struct*) m; \ - if(mod && mod->ndpi_log_level >= log_level) { \ - if(mod != NULL && mod->ndpi_debug_printf != NULL) \ - (*(mod->ndpi_debug_printf))(proto, mod, log_level, __FILE__, __FUNCTION__, __LINE__, args); \ + if(mod != NULL && mod->ndpi_log_level >= log_level) { \ + if(mod->ndpi_debug_printf != NULL) \ + (*(mod->ndpi_debug_printf))(proto, mod, log_level, log_facility, __FILE__, __FUNCTION__, __LINE__, args); \ } \ } @@ -186,29 +186,33 @@ #endif #define NDPI_LOG_ERR(mod, args...) \ - if(mod && mod->ndpi_log_level >= NDPI_LOG_ERROR) { \ - if(mod != NULL && mod->ndpi_debug_printf != NULL) \ - (*(mod->ndpi_debug_printf))(NDPI_CURRENT_PROTO, mod, NDPI_LOG_ERROR , __FILE__, __FUNCTION__, __LINE__, args); \ + if(mod != NULL && mod->ndpi_log_level >= NDPI_LOG_ERROR) { \ + if(mod->ndpi_debug_printf != NULL) \ + (*(mod->ndpi_debug_printf))(NDPI_CURRENT_PROTO, mod, NDPI_LOG_ERROR , NDPI_FACILITY_CORE , __FILE__, __FUNCTION__, __LINE__, args); \ } #define NDPI_LOG_INFO(mod, args...) \ - if(mod && mod->ndpi_log_level >= NDPI_LOG_TRACE) { \ - if(mod != NULL && mod->ndpi_debug_printf != NULL) \ - (*(mod->ndpi_debug_printf))(NDPI_CURRENT_PROTO, mod, NDPI_LOG_TRACE , __FILE__, __FUNCTION__, __LINE__, args); \ + if(mod != NULL && mod->ndpi_log_level >= NDPI_LOG_TRACE) { \ + if(mod->ndpi_debug_printf != NULL) \ + (*(mod->ndpi_debug_printf))(NDPI_CURRENT_PROTO, mod, NDPI_LOG_TRACE , NDPI_FACILITY_CORE , __FILE__, __FUNCTION__, __LINE__, args); \ } #define NDPI_LOG_DBG(mod, args...) \ - if(mod && mod->ndpi_log_level >= NDPI_LOG_DEBUG) { \ - if(mod != NULL && mod->ndpi_debug_printf != NULL) \ - (*(mod->ndpi_debug_printf))(NDPI_CURRENT_PROTO, mod, NDPI_LOG_DEBUG , __FILE__, __FUNCTION__, __LINE__, args); \ + if(mod != NULL && mod->ndpi_log_level >= NDPI_LOG_DEBUG) { \ + if(mod->ndpi_debug_printf != NULL) \ + (*(mod->ndpi_debug_printf))(NDPI_CURRENT_PROTO, mod, NDPI_LOG_DEBUG , NDPI_FACILITY_CORE , __FILE__, __FUNCTION__, __LINE__, args); \ } #define NDPI_LOG_DBG2(mod, args...) \ - if(mod && mod->ndpi_log_level >= NDPI_LOG_DEBUG_EXTRA) { \ - if(mod != NULL && mod->ndpi_debug_printf != NULL) \ - (*(mod->ndpi_debug_printf))(NDPI_CURRENT_PROTO, mod, NDPI_LOG_DEBUG_EXTRA , __FILE__, __FUNCTION__, __LINE__, args); \ + if(mod != NULL && mod->ndpi_log_level >= NDPI_LOG_DEBUG_EXTRA) { \ + if(mod->ndpi_debug_printf != NULL) \ + (*(mod->ndpi_debug_printf))(NDPI_CURRENT_PROTO, mod, NDPI_LOG_DEBUG_EXTRA , NDPI_FACILITY_CORE , __FILE__, __FUNCTION__, __LINE__, args); \ } + #define NDPI_LOG_DGA(mod, args...) \ + if(ndpi_verbose_dga_detection && mod != NULL && mod->ndpi_debug_printf != NULL) \ + (*(mod->ndpi_debug_printf))(NDPI_CURRENT_PROTO, mod, NDPI_LOG_DEBUG_EXTRA , NDPI_FACILITY_DGA , __FILE__, __FUNCTION__, __LINE__, args); + #else /* not defined NDPI_ENABLE_DEBUG_MESSAGES */ # ifdef WIN32 # define NDPI_LOG(...) {} @@ -216,8 +220,9 @@ # define NDPI_LOG_INFO(...) {} # define NDPI_LOG_DBG(...) {} # define NDPI_LOG_DBG2(...) {} +# define NDPI_LOG_DGA(...) {} # else -# define NDPI_LOG(proto, mod, log_level, args...) { /* printf(args); */ } +# define NDPI_LOG(proto, mod, log_level, log_facility, args...) { /* printf(args); */ } # ifndef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION # define NDPI_LOG_ERR(mod, args...) { printf(args); } # else @@ -226,6 +231,7 @@ # define NDPI_LOG_INFO(mod, args...) { /* printf(args); */ } # define NDPI_LOG_DBG(mod, args...) { /* printf(args); */ } # define NDPI_LOG_DBG2(mod, args...) { /* printf(args); */ } +# define NDPI_LOG_DGA(mod, args...) { /* printf(args); */ } # endif #endif /* NDPI_ENABLE_DEBUG_MESSAGES */ diff --git a/src/include/ndpi_includes.h b/src/include/ndpi_includes.h index 27580a45e40..ae62309235d 100644 --- a/src/include/ndpi_includes.h +++ b/src/include/ndpi_includes.h @@ -41,11 +41,14 @@ #include #include #include +#include #include #include +#ifndef __APPLE__ #include #include #include +#endif #if !defined __APPLE__ && !defined __FreeBSD__ && !defined __NetBSD__ && !defined __OpenBSD__ #include diff --git a/src/include/ndpi_patricia_typedefs.h b/src/include/ndpi_patricia_typedefs.h index f062677bd12..41f15e79016 100644 --- a/src/include/ndpi_patricia_typedefs.h +++ b/src/include/ndpi_patricia_typedefs.h @@ -64,6 +64,10 @@ #ifndef _NDPI_PATRICIA_TYPEDEF_H_ #define _NDPI_PATRICIA_TYPEDEF_H_ +#ifndef NDPI_CFFI_PREPROCESSING +#include "ndpi_includes.h" +#endif + #define UV16_MAX_USER_VALUES 2 struct patricia_uv16 { diff --git a/src/include/ndpi_typedefs.h b/src/include/ndpi_typedefs.h index 15415526c00..c9c3dd852fe 100644 --- a/src/include/ndpi_typedefs.h +++ b/src/include/ndpi_typedefs.h @@ -25,6 +25,9 @@ #define __NDPI_TYPEDEFS_H__ #include "ndpi_define.h" +#ifndef NDPI_CFFI_PREPROCESSING +#include "ndpi_includes.h" +#endif #include "ndpi_protocol_ids.h" #include "ndpi_utils.h" @@ -53,6 +56,11 @@ typedef enum { NDPI_LOG_DEBUG_EXTRA } ndpi_log_level_t; +typedef enum { + NDPI_FACILITY_CORE, + NDPI_FACILITY_DGA +} ndpi_log_facility_t; + typedef enum { ndpi_multimedia_unknown_flow = 0, ndpi_multimedia_audio_flow, @@ -247,7 +255,8 @@ struct ndpi_detection_module_struct; /* NDPI_DEBUG_FUNCTION_PTR (cast) */ typedef void (*ndpi_debug_function_ptr) (u_int32_t protocol, struct ndpi_detection_module_struct *module_struct, - ndpi_log_level_t log_level, const char *file, + ndpi_log_level_t log_level, ndpi_log_facility_t log_facility, + const char *file, const char *func, unsigned line, const char *format, ...); diff --git a/src/include/ndpi_utils.h b/src/include/ndpi_utils.h index 492b46a478e..82804e467df 100644 --- a/src/include/ndpi_utils.h +++ b/src/include/ndpi_utils.h @@ -25,6 +25,9 @@ #define __NDPI_UTILS_H__ #include "ndpi_define.h" +#ifndef NDPI_CFFI_PREPROCESSING +#include "ndpi_includes.h" +#endif #ifndef NDPI_CFFI_PREPROCESSING extern u_int8_t ndpi_ends_with(char *str, char *ends); diff --git a/src/lib/Makefile.in b/src/lib/Makefile.in index 7867f542415..d267e47c7cf 100644 --- a/src/lib/Makefile.in +++ b/src/lib/Makefile.in @@ -17,12 +17,12 @@ includedir = @includedir@/ndpi ifneq ($(OS),Windows_NT) CFLAGS += -fPIC -DPIC endif -CFLAGS += -I../include -Ithird_party/include -DNDPI_LIB_COMPILATION @NDPI_CFLAGS@ @GPROF_CFLAGS@ @CUSTOM_NDPI@ @ADDITIONAL_INCS@ +CFLAGS += -I. -I../include -Ithird_party/include -DNDPI_LIB_COMPILATION @NDPI_CFLAGS@ @GPROF_CFLAGS@ @CUSTOM_NDPI@ @ADDITIONAL_INCS@ LDFLAGS += @NDPI_LDFLAGS@ LIBS = @ADDITIONAL_LIBS@ @LIBS@ @GPROF_LIBS@ OBJECTS = $(patsubst protocols/%.c, protocols/%.o, $(wildcard protocols/*.c)) $(patsubst third_party/src/%.c, third_party/src/%.o, $(wildcard third_party/src/*.c)) $(patsubst ./%.c, ./%.o, $(wildcard ./*.c)) -HEADERS = $(wildcard ../include/*.h) +HEADERS = $(wildcard *.h) $(wildcard ../include/*.h) NDPI_VERSION_MAJOR = @NDPI_MAJOR@ NDPI_LIB_STATIC = libndpi.a NDPI_LIB_SHARED_BASE = libndpi.so diff --git a/src/lib/ndpi_analyze.c b/src/lib/ndpi_analyze.c index 17f75502664..37c719eea69 100644 --- a/src/lib/ndpi_analyze.c +++ b/src/lib/ndpi_analyze.c @@ -31,6 +31,8 @@ #include "ndpi_api.h" #include "ndpi_config.h" +#include "ndpi_replace_printf.h" + /* ********************************************************************************* */ void ndpi_init_data_analysis(struct ndpi_analyze_struct *ret, u_int16_t _max_series_len) { @@ -728,6 +730,7 @@ int ndpi_cluster_bins(struct ndpi_bin *bins, u_int16_t num_bins, float *bin_score; u_int16_t num_cluster_elems[MAX_NUM_CLUSTERS] = { 0 }; + (void)out_buf; srand(time(NULL)); if(!bins || num_bins == 0 || !cluster_ids || num_clusters == 0) diff --git a/src/lib/ndpi_classify.c b/src/lib/ndpi_classify.c index 538eb2b8234..69be424585c 100644 --- a/src/lib/ndpi_classify.c +++ b/src/lib/ndpi_classify.c @@ -51,6 +51,8 @@ #include "ndpi_classify.h" #include "ndpi_includes.h" +#include "ndpi_replace_printf.h" + /** finds the minimum value between to inputs */ #ifndef min #define min(a,b) \ diff --git a/src/lib/ndpi_main.c b/src/lib/ndpi_main.c index 9b955e7a9c3..57574d1be01 100644 --- a/src/lib/ndpi_main.c +++ b/src/lib/ndpi_main.c @@ -25,6 +25,10 @@ #include #include +#ifdef __APPLE__ +#include +#endif + #define NDPI_CURRENT_PROTO NDPI_PROTOCOL_UNKNOWN #include "ndpi_config.h" @@ -35,7 +39,7 @@ #ifdef USE_HOST_LIBGCRYPT #include #else -#include +#include "gcrypt_light.h" #endif #include @@ -481,7 +485,7 @@ void ndpi_exclude_protocol(struct ndpi_detection_module_struct *ndpi_str, struct if(ndpi_is_valid_protoId(protocol_id)) { #ifdef NDPI_ENABLE_DEBUG_MESSAGES if(ndpi_str && ndpi_str->ndpi_log_level >= NDPI_LOG_DEBUG && ndpi_str->ndpi_debug_printf != NULL) { - (*(ndpi_str->ndpi_debug_printf))(protocol_id, ndpi_str, NDPI_LOG_DEBUG, _file, _func, _line, "exclude %s\n", + (*(ndpi_str->ndpi_debug_printf))(protocol_id, ndpi_str, NDPI_LOG_DEBUG, NDPI_FACILITY_CORE, _file, _func, _line, "exclude %s\n", ndpi_get_proto_name(ndpi_str, protocol_id)); } #endif @@ -2167,7 +2171,11 @@ static void ndpi_init_protocol_defaults(struct ndpi_detection_module_struct *ndp /* ****************************************************** */ +#ifdef NDPI_ENABLE_DEBUG_MESSAGES #define MATCH_DEBUG_INFO(fmt, ...) if(txt->option & AC_FEATURE_DEBUG) printf(fmt, ##__VA_ARGS__) +#else +#define MATCH_DEBUG_INFO(fmt, ...) +#endif /* No static because it is used by fuzzer, too */ int ac_domain_match_handler(AC_MATCH_t *m, AC_TEXT_t *txt, AC_REP_t *match) { @@ -2644,6 +2652,7 @@ void set_ndpi_flow_free(void (*__ndpi_flow_free)(void *ptr)) { } void ndpi_debug_printf(unsigned int proto, struct ndpi_detection_module_struct *ndpi_str, ndpi_log_level_t log_level, + ndpi_log_facility_t log_facility, const char *file_name, const char *func_name, int line_number, const char *format, ...) { #ifdef NDPI_ENABLE_DEBUG_MESSAGES va_list args; @@ -2656,7 +2665,7 @@ void ndpi_debug_printf(unsigned int proto, struct ndpi_detection_module_struct * ndpi_vsnprintf(str, sizeof(str) - 1, format, args); va_end(args); - if(ndpi_str != NULL) { + if(ndpi_str != NULL || (file_name != NULL && func_name != NULL)) { printf("%s:%s:%-3d - [%u]: %s", file_name, func_name, line_number, proto, str); } else { printf("Proto: %u, %s", proto, str); @@ -8557,13 +8566,13 @@ int ndpi_get_category_id(struct ndpi_detection_module_struct *ndpi_str, char *ca /* ****************************************************** */ -void ndpi_dump_protocols(struct ndpi_detection_module_struct *ndpi_str) { +void ndpi_dump_protocols(struct ndpi_detection_module_struct *ndpi_str, FILE *dump_out) { int i; - if(!ndpi_str) return; + if(!ndpi_str || !dump_out) return; for(i = 0; i < (int) ndpi_str->ndpi_num_supported_protocols; i++) - printf("%3d %-22s %-10s %-8s %-12s %s\n", + fprintf(dump_out, "%3d %-22s %-10s %-8s %-12s %s\n", i, ndpi_str->proto_defaults[i].protoName, ndpi_get_l4_proto_name(ndpi_get_l4_proto_info(ndpi_str, i)), ndpi_str->proto_defaults[i].isAppProtocol ? "" : "X", @@ -8575,11 +8584,12 @@ void ndpi_dump_protocols(struct ndpi_detection_module_struct *ndpi_str) { /* Helper function used to generate Options fields in OPNsense */ -void ndpi_generate_options(u_int opt) { +void ndpi_generate_options(u_int opt, FILE *options_out) { struct ndpi_detection_module_struct *ndpi_str; NDPI_PROTOCOL_BITMASK all; u_int i; + if (!options_out) return; ndpi_str = ndpi_init_detection_module(ndpi_no_prefs); NDPI_BITMASK_SET_ALL(all); @@ -8589,8 +8599,8 @@ void ndpi_generate_options(u_int opt) { case 0: /* List known protocols */ { for(i = 1 /* Skip unknown */; i < ndpi_str->ndpi_num_supported_protocols; i++) { - printf(" %s\n", - i, i, ndpi_str->proto_defaults[i].protoName, i); + fprintf(options_out, " %s\n", + i, i, ndpi_str->proto_defaults[i].protoName, i); } } break; @@ -8601,8 +8611,8 @@ void ndpi_generate_options(u_int opt) { const char *name = ndpi_category_get_name(ndpi_str, i); if((name != NULL) && (name[0] != '\0')) { - printf(" %s\n", - i, i, name, i); + fprintf(options_out, " %s\n", + i, i, name, i); } } } @@ -8611,26 +8621,26 @@ void ndpi_generate_options(u_int opt) { case 2: /* List known risks */ { for(i = 1 /* Skip no risk */; i < NDPI_MAX_RISK; i++) { - ndpi_risk_enum r = (ndpi_risk_enum)i; + ndpi_risk_enum r = (ndpi_risk_enum)i; - printf(" %s\n", - i, i, ndpi_risk2str(r), i); + fprintf(options_out, " %s\n", + i, i, ndpi_risk2str(r), i); } } break; default: - printf("WARNING: option -a out of range\n"); + fprintf(options_out, "%s\n", "WARNING: option -a out of range"); break; } } /* ****************************************************** */ -void ndpi_dump_risks_score() { +void ndpi_dump_risks_score(FILE *risk_out) { u_int i; - printf("%3s %-48s %-8s %s %-8s %-8s\n", + fprintf(risk_out, "%3s %-48s %-8s %s %-8s %-8s\n", "Id", "Risk", "Severity", "Score", "CliScore", "SrvScore"); for(i = 1; i < NDPI_MAX_RISK; i++) { @@ -8641,7 +8651,7 @@ void ndpi_dump_risks_score() { u_int16_t client_score, server_score; u_int16_t score = ndpi_risk2score(risk, &client_score, &server_score); - printf("%3d %-48s %-8s %-8u %-8u %-8u\n", + fprintf(risk_out, "%3d %-48s %-8s %-8u %-8u %-8u\n", i, ndpi_risk2str(r), ndpi_severity2str(s), score, @@ -9574,8 +9584,7 @@ int ndpi_check_dga_name(struct ndpi_detection_module_struct *ndpi_str, if(strncmp(name, "www.", 4) == 0) name = &name[4]; - if(ndpi_verbose_dga_detection) - printf("[DGA check] %s\n", name); + NDPI_LOG_DGA(ndpi_str, "[DGA check] %s\n", name); len = strlen(name); @@ -9589,8 +9598,7 @@ int ndpi_check_dga_name(struct ndpi_detection_module_struct *ndpi_str, len = ndpi_snprintf(tmp, max_tmp_len, "%s", name); if(len < 0) { - if(ndpi_verbose_dga_detection) - printf("[DGA] Too short"); + NDPI_LOG_DGA(ndpi_str, "[DGA] Too short"); return(0); } else @@ -9688,8 +9696,7 @@ int ndpi_check_dga_name(struct ndpi_detection_module_struct *ndpi_str, ndpi_set_risk(ndpi_str, flow, NDPI_SUSPICIOUS_DGA_DOMAIN, name); } - if(ndpi_verbose_dga_detection) - printf("[DGA] Found!"); + NDPI_LOG_DGA(ndpi_str, "[DGA] Found!"); return(1); } @@ -9711,8 +9718,7 @@ int ndpi_check_dga_name(struct ndpi_detection_module_struct *ndpi_str, if(strlen(word) < 5) continue; - if(ndpi_verbose_dga_detection) - printf("-> word(%s) [%s][len: %u]\n", word, name, (unsigned int)strlen(word)); + NDPI_LOG_DGA(ndpi_str, "-> word(%s) [%s][len: %u]\n", word, name, (unsigned int)strlen(word)); trigram_char_skip = 0; @@ -9750,12 +9756,10 @@ int ndpi_check_dga_name(struct ndpi_detection_module_struct *ndpi_str, num_bigram_checks++; - if(ndpi_verbose_dga_detection) - printf("-> Checking %c%c\n", word[i], word[i+1]); + NDPI_LOG_DGA(ndpi_str, "-> Checking %c%c\n", word[i], word[i+1]); if(ndpi_match_impossible_bigram(&word[i])) { - if(ndpi_verbose_dga_detection) - printf("IMPOSSIBLE %s\n", &word[i]); + NDPI_LOG_DGA(ndpi_str, "IMPOSSIBLE %s\n", &word[i]); num_impossible++; } else { @@ -9768,8 +9772,7 @@ int ndpi_check_dga_name(struct ndpi_detection_module_struct *ndpi_str, } if((num_trigram_dots < 2) && (word[i+2] != '\0')) { - if(ndpi_verbose_dga_detection) - printf("***> %s [trigram_char_skip: %u]\n", &word[i], trigram_char_skip); + NDPI_LOG_DGA(ndpi_str, "***> %s [trigram_char_skip: %u]\n", &word[i], trigram_char_skip); if(ndpi_is_trigram_char(word[i]) && ndpi_is_trigram_char(word[i+1]) && ndpi_is_trigram_char(word[i+2])) { if(trigram_char_skip) { @@ -9779,8 +9782,7 @@ int ndpi_check_dga_name(struct ndpi_detection_module_struct *ndpi_str, if(ndpi_match_trigram(&word[i])) num_trigram_found++, trigram_char_skip = 2 /* 1 char overlap */; - else if(ndpi_verbose_dga_detection) - printf("[NDPI] NO Trigram %c%c%c\n", word[i], word[i+1], word[i+2]); + else NDPI_LOG_DGA(ndpi_str, "[NDPI] NO Trigram %c%c%c\n", word[i], word[i+1], word[i+2]); /* Count vowels */ num_trigram_vowels += ndpi_is_vowel(word[i]) + ndpi_is_vowel(word[i+1]) + ndpi_is_vowel(word[i+2]); @@ -9833,17 +9835,11 @@ int ndpi_check_dga_name(struct ndpi_detection_module_struct *ndpi_str, /* Skip names whose first word item has at least 3 consecutive digits */ if(max_num_consecutive_digits_first_word > 2) - rc = 0; + rc = 0; - if(ndpi_verbose_dga_detection) { - if(rc) - printf("DGA %s [num_found: %u][num_impossible: %u]\n", - name, num_found, num_impossible); - } + if(rc) NDPI_LOG_DGA(ndpi_str, "DGA %s [num_found: %u][num_impossible: %u]\n", name, num_found, num_impossible); } - - if(ndpi_verbose_dga_detection) - printf("[DGA] Result: %u\n", rc); + NDPI_LOG_DGA(ndpi_str, "[DGA] Result: %u\n", rc); if(rc && flow) ndpi_set_risk(ndpi_str, flow, NDPI_SUSPICIOUS_DGA_DOMAIN, name); diff --git a/src/lib/ndpi_replace_printf.h b/src/lib/ndpi_replace_printf.h new file mode 100644 index 00000000000..8d6a72de9bb --- /dev/null +++ b/src/lib/ndpi_replace_printf.h @@ -0,0 +1,57 @@ +/* + * ndpi_replace_printf.h + * + * Copyright (C) 2023 - ntop.org and contributors + * + * This file is part of nDPI, an open source deep packet inspection + * library based on the OpenDPI and PACE technology by ipoque GmbH + * + * nDPI is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * nDPI is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with nDPI. If not, see . + * + */ + +// This file may be included in every *.c file that uses printf(...) except for ndpi_main.c ! + +#include "ndpi_config.h" + +#ifndef NDPI_CFFI_PREPROCESSING + +#undef printf +#undef fprintf + +#include "ndpi_typedefs.h" + +#ifdef NDPI_ENABLE_DEBUG_MESSAGES + +#define printf(...) ndpi_debug_printf(0, NULL, NDPI_LOG_DEBUG_EXTRA, __FILE__, __func__, __LINE__, __VA_ARGS__) + +#ifdef NDPI_REPLACE_FPRINTF +#define fprintf(stream, ...) ndpi_debug_printf(0, NULL, NDPI_LOG_ERROR, __FILE__, __func__, __LINE__, __VA_ARGS__) +#endif + +#else + +#define printf(...) do {} while(0); + +#ifdef NDPI_REPLACE_FPRINTF +#define fprintf(stream, ...) do {} while(0); +#endif + +#endif + +void ndpi_debug_printf(unsigned int proto, struct ndpi_detection_module_struct *ndpi_str, + ndpi_log_level_t log_level, ndpi_log_facility_t, log_facility, + const char *file_name, const char *func_name, int line_number, const char *format, ...); + +#endif diff --git a/src/lib/ndpi_utils.c b/src/lib/ndpi_utils.c index 35c0410e2a4..5a0dd584916 100644 --- a/src/lib/ndpi_utils.c +++ b/src/lib/ndpi_utils.c @@ -54,6 +54,8 @@ #include "third_party/include/uthash.h" #include "third_party/include/rce_injection.h" +#include "ndpi_replace_printf.h" + #define NDPI_CONST_GENERIC_PROTOCOL_NAME "GenericProtocol" // #define MATCH_DEBUG 1 diff --git a/src/lib/third_party/include/roaring.h b/src/lib/third_party/include/roaring.h index 117f861b48a..500ba9cb944 100644 --- a/src/lib/third_party/include/roaring.h +++ b/src/lib/third_party/include/roaring.h @@ -259,10 +259,13 @@ static inline void roaring_bitmap_set_copy_on_write(roaring_bitmap_t* r, roaring_bitmap_t *roaring_bitmap_add_offset(const roaring_bitmap_t *bm, int64_t offset); + +#ifdef NDPI_ENABLE_DEBUG_MESSAGES /** * Describe the inner structure of the bitmap. */ void roaring_bitmap_printf_describe(const roaring_bitmap_t *r); +#endif /** * Creates a new bitmap from a list of uint32_t integers @@ -286,10 +289,12 @@ roaring_bitmap_t *roaring_bitmap_copy(const roaring_bitmap_t *r); bool roaring_bitmap_overwrite(roaring_bitmap_t *dest, const roaring_bitmap_t *src); +#ifdef NDPI_ENABLE_DEBUG_MESSAGES /** * Print the content of the bitmap. */ void roaring_bitmap_printf(const roaring_bitmap_t *r); +#endif /** * Computes the intersection between two bitmaps and returns new bitmap. The diff --git a/src/lib/third_party/src/ahocorasick.c b/src/lib/third_party/src/ahocorasick.c index cade82bab42..12bc422ac88 100644 --- a/src/lib/third_party/src/ahocorasick.c +++ b/src/lib/third_party/src/ahocorasick.c @@ -43,6 +43,8 @@ typedef __kernel_size_t size_t; #include "ndpi_api.h" #include "ahocorasick.h" +#include "../../ndpi_replace_printf.h" + /* TODO: For different depth of node, number of outgoing edges differs considerably, It is efficient to use different chunk size for different depths */ @@ -482,6 +484,7 @@ int ac_automata_search (AC_AUTOMATA_t * thiz, if(match->match_map) { match->match_counter++; /* we have a matching */ #ifndef __KERNEL__ +#ifdef NDPI_ENABLE_DEBUG_MESSAGES if(debug) { int i; AC_PATTERN_t *patterns = curr->matched_patterns->patterns; @@ -494,6 +497,7 @@ int ac_automata_search (AC_AUTOMATA_t * thiz, patterns[i].rep.number); } } +#endif #endif if(thiz->match_handler) { /* We check 'next' to find out if we came here after a alphabet @@ -521,6 +525,7 @@ int ac_automata_search (AC_AUTOMATA_t * thiz, if(txt->match.matched[i]) { *param = (txt->match.matched[i])->rep; #ifndef __KERNEL__ +#ifdef NDPI_ENABLE_DEBUG_MESSAGES if(debug) { AC_PATTERN_t *pattern = txt->match.matched[i]; printf("best match: %c%.*s%c [%u]\n", @@ -529,6 +534,7 @@ int ac_automata_search (AC_AUTOMATA_t * thiz, pattern->rep.at_end ? '$':' ', pattern->rep.number); } +#endif #endif thiz->stats.n_found++; return 1; diff --git a/src/lib/third_party/src/roaring.c b/src/lib/third_party/src/roaring.c index f8ee417dab7..621e0dba830 100644 --- a/src/lib/third_party/src/roaring.c +++ b/src/lib/third_party/src/roaring.c @@ -1912,6 +1912,7 @@ int array_container_to_uint32_array(void *vout, const array_container_t *cont, /* Compute the number of runs */ int32_t array_container_number_of_runs(const array_container_t *ac); +#ifdef NDPI_ENABLE_DEBUG_MESSAGES /* * Print this container using printf (useful for debugging). */ @@ -1923,6 +1924,7 @@ void array_container_printf(const array_container_t *v); */ void array_container_printf_as_uint32_array(const array_container_t *v, uint32_t base); +#endif /** * Return the serialized size in bytes of a container having cardinality "card". @@ -2631,6 +2633,7 @@ int bitset_container_to_uint32_array(uint32_t *out, const bitset_container_t *bc, uint32_t base); +#ifdef NDPI_ENABLE_DEBUG_MESSAGES /* * Print this container using printf (useful for debugging). */ @@ -2642,6 +2645,7 @@ void bitset_container_printf(const bitset_container_t *v); */ void bitset_container_printf_as_uint32_array(const bitset_container_t *v, uint32_t base); +#endif /** * Return the serialized size in bytes of a container. @@ -3154,6 +3158,7 @@ void run_container_xor(const run_container_t *src_1, int run_container_to_uint32_array(void *vout, const run_container_t *cont, uint32_t base); +#ifdef NDPI_ENABLE_DEBUG_MESSAGES /* * Print this container using printf (useful for debugging). */ @@ -3165,6 +3170,7 @@ void run_container_printf(const run_container_t *v); */ void run_container_printf_as_uint32_array(const run_container_t *v, uint32_t base); +#endif /** * Return the serialized size in bytes of a container having "num_runs" runs. @@ -4290,6 +4296,11 @@ int run_run_container_ixor( #include #include +#include "ndpi_config.h" + +#define NDPI_REPLACE_FPRINTF +#include "../../ndpi_replace_printf.h" + #ifdef __cplusplus extern "C" { namespace roaring { namespace internal { @@ -4696,6 +4707,7 @@ static inline int32_t container_size_in_bytes( return 0; // unreached } +#ifdef NDPI_ENABLE_DEBUG_MESSAGES /** * print the container (useful for debugging), requires a typecode */ @@ -4707,6 +4719,7 @@ void container_printf(const container_t *container, uint8_t typecode); */ void container_printf_as_uint32_array(const container_t *container, uint8_t typecode, uint32_t base); +#endif /** * Checks whether a container is not empty, requires a typecode @@ -7786,7 +7799,7 @@ static void binarySearch2(const uint16_t *array, int32_t n, uint16_t target1, * and binarySearch2. This approach can be slightly superior to a conventional * galloping search in some instances. */ -int32_t intersect_skewed_uint16(const uint16_t *small, size_t size_s, +int32_t intersect_skewed_uint16(const uint16_t *_small, size_t size_s, const uint16_t *large, size_t size_l, uint16_t *buffer) { size_t pos = 0, idx_l = 0, idx_s = 0; @@ -7796,10 +7809,10 @@ int32_t intersect_skewed_uint16(const uint16_t *small, size_t size_s, } int32_t index1 = 0, index2 = 0, index3 = 0, index4 = 0; while ((idx_s + 4 <= size_s) && (idx_l < size_l)) { - uint16_t target1 = small[idx_s]; - uint16_t target2 = small[idx_s + 1]; - uint16_t target3 = small[idx_s + 2]; - uint16_t target4 = small[idx_s + 3]; + uint16_t target1 = _small[idx_s]; + uint16_t target2 = _small[idx_s + 1]; + uint16_t target3 = _small[idx_s + 2]; + uint16_t target4 = _small[idx_s + 3]; binarySearch4(large + idx_l, (int32_t)(size_l - idx_l), target1, target2, target3, target4, &index1, &index2, &index3, &index4); if ((index1 + idx_l < size_l) && (large[idx_l + index1] == target1)) { @@ -7818,8 +7831,8 @@ int32_t intersect_skewed_uint16(const uint16_t *small, size_t size_s, idx_l += index4; } if ((idx_s + 2 <= size_s) && (idx_l < size_l)) { - uint16_t target1 = small[idx_s]; - uint16_t target2 = small[idx_s + 1]; + uint16_t target1 = _small[idx_s]; + uint16_t target2 = _small[idx_s + 1]; binarySearch2(large + idx_l, (int32_t)(size_l - idx_l), target1, target2, &index1, &index2); if ((index1 + idx_l < size_l) && (large[idx_l + index1] == target1)) { @@ -7832,7 +7845,7 @@ int32_t intersect_skewed_uint16(const uint16_t *small, size_t size_s, idx_l += index2; } if ((idx_s < size_s) && (idx_l < size_l)) { - uint16_t val_s = small[idx_s]; + uint16_t val_s = _small[idx_s]; int32_t index = binarySearch(large + idx_l, (int32_t)(size_l - idx_l), val_s); if (index >= 0) buffer[pos++] = val_s; @@ -7843,7 +7856,7 @@ int32_t intersect_skewed_uint16(const uint16_t *small, size_t size_s, // TODO: this could be accelerated, possibly, by using binarySearch4 as above. -int32_t intersect_skewed_uint16_cardinality(const uint16_t *small, +int32_t intersect_skewed_uint16_cardinality(const uint16_t *_small, size_t size_s, const uint16_t *large, size_t size_l) { @@ -7853,7 +7866,7 @@ int32_t intersect_skewed_uint16_cardinality(const uint16_t *small, return 0; } - uint16_t val_l = large[idx_l], val_s = small[idx_s]; + uint16_t val_l = large[idx_l], val_s = _small[idx_s]; while (true) { if (val_l < val_s) { @@ -7863,12 +7876,12 @@ int32_t intersect_skewed_uint16_cardinality(const uint16_t *small, } else if (val_s < val_l) { idx_s++; if (idx_s == size_s) break; - val_s = small[idx_s]; + val_s = _small[idx_s]; } else { pos++; idx_s++; if (idx_s == size_s) break; - val_s = small[idx_s]; + val_s = _small[idx_s]; idx_l = advanceUntil(large, (int32_t)idx_l, (int32_t)size_l, val_s); if (idx_l == size_l) break; val_l = large[idx_l]; @@ -7878,7 +7891,7 @@ int32_t intersect_skewed_uint16_cardinality(const uint16_t *small, return (int32_t)pos; } -bool intersect_skewed_uint16_nonempty(const uint16_t *small, size_t size_s, +bool intersect_skewed_uint16_nonempty(const uint16_t *_small, size_t size_s, const uint16_t *large, size_t size_l) { size_t idx_l = 0, idx_s = 0; @@ -7886,7 +7899,7 @@ bool intersect_skewed_uint16_nonempty(const uint16_t *small, size_t size_s, return false; } - uint16_t val_l = large[idx_l], val_s = small[idx_s]; + uint16_t val_l = large[idx_l], val_s = _small[idx_s]; while (true) { if (val_l < val_s) { @@ -7896,7 +7909,7 @@ bool intersect_skewed_uint16_nonempty(const uint16_t *small, size_t size_s, } else if (val_s < val_l) { idx_s++; if (idx_s == size_s) break; - val_s = small[idx_s]; + val_s = _small[idx_s]; } else { return true; } @@ -10423,6 +10436,7 @@ int array_container_to_uint32_array(void *vout, const array_container_t *cont, return outpos; } +#ifdef NDPI_ENABLE_DEBUG_MESSAGES void array_container_printf(const array_container_t *v) { int i; if (v->cardinality == 0) { @@ -10449,6 +10463,7 @@ void array_container_printf_as_uint32_array(const array_container_t *v, printf(",%u", v->array[i] + base); } } +#endif /* Compute the number of runs */ int32_t array_container_number_of_runs(const array_container_t *ac) { @@ -11243,6 +11258,7 @@ int bitset_container_to_uint32_array( #endif } +#ifdef NDPI_ENABLE_DEBUG_MESSAGES /* * Print this container using printf (useful for debugging). */ @@ -11292,6 +11308,7 @@ void bitset_container_printf_as_uint32_array(const bitset_container_t * v, uint3 base += 64; } } +#endif // TODO: use the fast lower bound, also @@ -11561,6 +11578,11 @@ void container_free(container_t *c, uint8_t type) { } } +#ifdef NDPI_ENABLE_DEBUG_MESSAGES +void run_container_printf(const run_container_t *cont); +void run_container_printf_as_uint32_array(const run_container_t *cont, + uint32_t base); + void container_printf(const container_t *c, uint8_t type) { c = container_unwrap_shared(c, &type); switch (type) { @@ -11600,6 +11622,7 @@ void container_printf_as_uint32_array( __builtin_unreachable(); } } +#endif extern inline bool container_nonzero_cardinality( const container_t *c, uint8_t typecode); @@ -14901,6 +14924,7 @@ int run_container_to_uint32_array(void *vout, const run_container_t *cont, return outpos; } +#ifdef NDPI_ENABLE_DEBUG_MESSAGES /* * Print this container using printf (useful for debugging). */ @@ -14931,6 +14955,7 @@ void run_container_printf_as_uint32_array(const run_container_t *cont, uint32_t j;for ( j = 0; j <= le; ++j) printf(",%u", run_start + j); } } +#endif int32_t run_container_write(const run_container_t *container, char *buf) { uint16_t cast_16 = container->n_runs; @@ -15561,6 +15586,7 @@ void roaring_bitmap_remove_range_closed(roaring_bitmap_t *r, uint32_t min, uint3 extern inline void roaring_bitmap_add_range(roaring_bitmap_t *r, uint64_t min, uint64_t max); extern inline void roaring_bitmap_remove_range(roaring_bitmap_t *r, uint64_t min, uint64_t max); +#ifdef NDPI_ENABLE_DEBUG_MESSAGES void roaring_bitmap_printf(const roaring_bitmap_t *r) { const roaring_array_t *ra = &r->high_low_container; @@ -15596,6 +15622,7 @@ void roaring_bitmap_printf_describe(const roaring_bitmap_t *r) { } printf("}"); } +#endif typedef struct min_max_sum_s { uint32_t min; diff --git a/tests/dga/dga_evaluate.c b/tests/dga/dga_evaluate.c index 98cc6a2b1e9..3abe08ac236 100644 --- a/tests/dga/dga_evaluate.c +++ b/tests/dga/dga_evaluate.c @@ -41,6 +41,28 @@ void help() { extern int ndpi_verbose_dga_detection; +static void ndpi_debug_printf(unsigned int proto, + struct ndpi_detection_module_struct * ndpi_struct, + ndpi_log_level_t log_level, + ndpi_log_facility_t log_facility, + const char * file_name, + const char * func_name, + unsigned int line_number, + const char * format, + ...) +{ + va_list vl; + char buf[128]; + + if (log_facility != NDPI_FACILITY_DGA) + return; + + va_start(vl, format); + vsnprintf(buf, NDPI_ARRAY_LENGTH(buf), format, vl); + printf("%s", buf); + va_end(vl); +} + int main(int argc, char **argv) { FILE *fd; char buffer[512]; @@ -73,6 +95,8 @@ int main(int argc, char **argv) { assert(ndpi_str != NULL); NDPI_BITMASK_SET_ALL(all); ndpi_set_protocol_detection_bitmask2(ndpi_str, &all); + set_ndpi_debug_function(ndpi_str, ndpi_debug_printf); + ndpi_set_log_level(ndpi_str, NDPI_LOG_TRACE); ndpi_finalize_initialization(ndpi_str); assert(ndpi_str != NULL); diff --git a/utils/check_symbols.sh b/utils/check_symbols.sh index 5ab064c184d..4648f0e6dd2 100755 --- a/utils/check_symbols.sh +++ b/utils/check_symbols.sh @@ -19,7 +19,7 @@ for line in `nm -P -u "${NDPI_LIB}"`; do fi #printf '%s\n' "${line}" - FOUND_SYMBOL="$(printf '%s' "${line}" | grep '^\(malloc\|calloc\|realloc\|free\)$' || true)" + FOUND_SYMBOL="$(printf '%s' "${line}" | grep '^\(malloc\|calloc\|realloc\|free\|printf\|fprintf\)$' || true)" if [ ! -z "${FOUND_SYMBOL}" ]; then SKIP=0 @@ -39,6 +39,16 @@ for line in `nm -P -u "${NDPI_LIB}"`; do 'free') SKIP=1 ;; esac ;; + '[ndpi_main.o]') + case "${FOUND_SYMBOL}" in + 'printf'|'fprintf') SKIP=1 ;; + esac + ;; + '[ahocorasick.o]'|'[ndpi_main.o]'|'[ndpi_serializer.o]') + case "${FOUND_SYMBOL}" in + 'fprintf') SKIP=1 ;; + esac + ;; esac if [ ${SKIP} -eq 0 ]; then @@ -50,6 +60,7 @@ done printf 'Unwanted symbols found: %s\n' "${FAIL_COUNT}" if [ ${FAIL_COUNT} -gt 0 ]; then - printf '%s\n' 'Please make sure to use only ndpi_malloc/ndpi_calloc/ndpi_realloc/ndpi_free wrapper instead of malloc/calloc/realloc/free' + printf '%s\n' 'malloc: Please make sure to use only ndpi_malloc/ndpi_calloc/ndpi_realloc/ndpi_free wrapper instead of malloc/calloc/realloc/free' + printf '%s\n' 'printf: Do not print anything to stdout/stderr.' fi exit ${FAIL_COUNT} diff --git a/windows/nDPI.vcxproj b/windows/nDPI.vcxproj index 91cb8cadc74..c7593b5bf43 100644 --- a/windows/nDPI.vcxproj +++ b/windows/nDPI.vcxproj @@ -63,7 +63,7 @@ Disabled - $(ProjectDir)src\;$(ProjectDir)..\src\lib\protocols\;$(ProjectDir)..\src\include\;$(ProjectDir)..\;$(ProjectDir)..\src\lib\third_party\include\;%(AdditionalIncludeDirectories) + $(ProjectDir)src\;$(ProjectDir)src\lib\;$(ProjectDir)..\src\lib\protocols\;$(ProjectDir)..\src\include\;$(ProjectDir)..\;$(ProjectDir)..\src\lib\third_party\include\;%(AdditionalIncludeDirectories) NDPI_LIB_COMPILATION;WIN32;_WIN64;_DEBUG;_WINDOWS;_CRT_SECURE_NO_WARNINGS;_WINSOCK_DEPRECATED_NO_WARNINGS;%(PreprocessorDefinitions) Default MultiThreadedDebugDLL @@ -91,7 +91,7 @@ Disabled - $(ProjectDir)src\;$(ProjectDir)..\src\lib\protocols\;$(ProjectDir)..\src\include\;$(ProjectDir)..\;$(ProjectDir)..\src\lib\third_party\include\;$(ProjectDir)..\windows\WpdPack\Include\;%(AdditionalIncludeDirectories) + $(ProjectDir)src\;$(ProjectDir)src\lib\;$(ProjectDir)..\src\lib\protocols\;$(ProjectDir)..\src\include\;$(ProjectDir)..\;$(ProjectDir)..\src\lib\third_party\include\;$(ProjectDir)..\windows\WpdPack\Include\;%(AdditionalIncludeDirectories) PTW32_STATIC_LIB;STATIC_GETOPT;NDPI_LIB_COMPILATION;HAVE_STRUCT_TIMESPEC;WIN32;_WIN64;_DEBUG;_WINDOWS;_CRT_SECURE_NO_WARNINGS;_WINSOCK_DEPRECATED_NO_WARNINGS;%(PreprocessorDefinitions) Default MultiThreadedDebugDLL @@ -343,6 +343,7 @@ + diff --git a/windows/src/ndpi_define.h b/windows/src/ndpi_define.h index 5a47f925408..a973276d0b4 100644 --- a/windows/src/ndpi_define.h +++ b/windows/src/ndpi_define.h @@ -183,29 +183,33 @@ #endif #define NDPI_LOG_ERR(mod, args...) \ - if(mod && mod->ndpi_log_level >= NDPI_LOG_ERROR) { \ - if(mod != NULL && mod->ndpi_debug_printf != NULL) \ - (*(mod->ndpi_debug_printf))(NDPI_CURRENT_PROTO, mod, NDPI_LOG_ERROR , __FILE__, __FUNCTION__, __LINE__, args); \ + if(mod != NULL && mod->ndpi_log_level >= NDPI_LOG_ERROR) { \ + if(mod->ndpi_debug_printf != NULL) \ + (*(mod->ndpi_debug_printf))(NDPI_CURRENT_PROTO, mod, NDPI_LOG_ERROR , NDPI_FACILITY_CORE , __FILE__, __FUNCTION__, __LINE__, args); \ } #define NDPI_LOG_INFO(mod, args...) \ - if(mod && mod->ndpi_log_level >= NDPI_LOG_TRACE) { \ - if(mod != NULL && mod->ndpi_debug_printf != NULL) \ - (*(mod->ndpi_debug_printf))(NDPI_CURRENT_PROTO, mod, NDPI_LOG_TRACE , __FILE__, __FUNCTION__, __LINE__, args); \ + if(mod != NULL && mod->ndpi_log_level >= NDPI_LOG_TRACE) { \ + if(mod->ndpi_debug_printf != NULL) \ + (*(mod->ndpi_debug_printf))(NDPI_CURRENT_PROTO, mod, NDPI_LOG_TRACE , NDPI_FACILITY_CORE , __FILE__, __FUNCTION__, __LINE__, args); \ } #define NDPI_LOG_DBG(mod, args...) \ - if(mod && mod->ndpi_log_level >= NDPI_LOG_DEBUG) { \ - if(mod != NULL && mod->ndpi_debug_printf != NULL) \ - (*(mod->ndpi_debug_printf))(NDPI_CURRENT_PROTO, mod, NDPI_LOG_DEBUG , __FILE__, __FUNCTION__, __LINE__, args); \ + if(mod != NULL && mod->ndpi_log_level >= NDPI_LOG_DEBUG) { \ + if(mod->ndpi_debug_printf != NULL) \ + (*(mod->ndpi_debug_printf))(NDPI_CURRENT_PROTO, mod, NDPI_LOG_DEBUG , NDPI_FACILITY_CORE , __FILE__, __FUNCTION__, __LINE__, args); \ } #define NDPI_LOG_DBG2(mod, args...) \ - if(mod && mod->ndpi_log_level >= NDPI_LOG_DEBUG_EXTRA) { \ - if(mod != NULL && mod->ndpi_debug_printf != NULL) \ - (*(mod->ndpi_debug_printf))(NDPI_CURRENT_PROTO, mod, NDPI_LOG_DEBUG_EXTRA , __FILE__, __FUNCTION__, __LINE__, args); \ + if(mod != NULL && mod->ndpi_log_level >= NDPI_LOG_DEBUG_EXTRA) { \ + if(mod->ndpi_debug_printf != NULL) \ + (*(mod->ndpi_debug_printf))(NDPI_CURRENT_PROTO, mod, NDPI_LOG_DEBUG_EXTRA , NDPI_FACILITY_CORE , __FILE__, __FUNCTION__, __LINE__, args); \ } + #define NDPI_LOG_DGA(mod, args...) \ + if(ndpi_verbose_dga_detection && mod != NULL && mod->ndpi_debug_printf != NULL) \ + (*(mod->ndpi_debug_printf))(NDPI_CURRENT_PROTO, mod, NDPI_LOG_DEBUG_EXTRA , NDPI_FACILITY_DGA , __FILE__, __FUNCTION__, __LINE__, args); + #else /* not defined NDPI_ENABLE_DEBUG_MESSAGES */ # ifdef WIN32 # define NDPI_LOG(...) {} @@ -213,12 +217,14 @@ # define NDPI_LOG_INFO(...) {} # define NDPI_LOG_DBG(...) {} # define NDPI_LOG_DBG2(...) {} +# define NDPI_LOG_DGA(...) {} # else # define NDPI_LOG(proto, mod, log_level, args...) { /* printf(args); */ } # define NDPI_LOG_ERR(mod, args...) { printf(args); } # define NDPI_LOG_INFO(mod, args...) { /* printf(args); */ } # define NDPI_LOG_DBG(mod, args...) { /* printf(args); */ } # define NDPI_LOG_DBG2(mod, args...) { /* printf(args); */ } +# define NDPI_LOG_DGA(mod, args...) { /* printf(args); */ } # endif #endif /* NDPI_ENABLE_DEBUG_MESSAGES */