diff options
author | Nardi Ivan <nardi.ivan@gmail.com> | 2024-01-10 11:19:44 +0100 |
---|---|---|
committer | Ivan Nardi <12729895+IvanNardi@users.noreply.github.com> | 2024-01-18 10:21:24 +0100 |
commit | 6c85f10cd5a29346522ad647a38066f0cc44e5a7 (patch) | |
tree | 062db3a48785916f4532ca712ad0ea41698f952c /src | |
parent | c704be1a20d169bea1c55a720421742f09f4aa88 (diff) |
config: move debug/log configuration to the new API
Diffstat (limited to 'src')
-rw-r--r-- | src/include/ndpi_api.h | 2 | ||||
-rw-r--r-- | src/include/ndpi_define.h.in | 10 | ||||
-rw-r--r-- | src/include/ndpi_private.h | 6 | ||||
-rw-r--r-- | src/lib/ndpi_main.c | 22 |
4 files changed, 14 insertions, 26 deletions
diff --git a/src/include/ndpi_api.h b/src/include/ndpi_api.h index df31e30b1..818228aac 100644 --- a/src/include/ndpi_api.h +++ b/src/include/ndpi_api.h @@ -1052,8 +1052,6 @@ extern "C" { u_int ndpi_get_ndpi_num_supported_protocols(struct ndpi_detection_module_struct *ndpi_mod); u_int ndpi_get_ndpi_num_custom_protocols(struct ndpi_detection_module_struct *ndpi_mod); u_int ndpi_get_ndpi_detection_module_size(void); - void ndpi_set_log_level(struct ndpi_detection_module_struct *ndpi_mod, u_int l); - void ndpi_set_debug_bitmask(struct ndpi_detection_module_struct *ndpi_mod, NDPI_PROTOCOL_BITMASK debug_bitmask); /* Simple helper to get current time, in sec */ u_int32_t ndpi_get_current_time(struct ndpi_flow_struct *flow); diff --git a/src/include/ndpi_define.h.in b/src/include/ndpi_define.h.in index 3ec09ebdd..7a818195d 100644 --- a/src/include/ndpi_define.h.in +++ b/src/include/ndpi_define.h.in @@ -166,7 +166,7 @@ #define NDPI_LOG(proto, m, log_level, args...) \ { \ struct ndpi_detection_module_struct *mod = (struct ndpi_detection_module_struct*) m; \ - if(mod && mod->ndpi_log_level >= log_level) { \ + if(mod && mod->cfg.log_level >= log_level) { \ if(mod != NULL && mod->ndpi_debug_printf != NULL) \ (*(mod->ndpi_debug_printf))(proto, mod, log_level, __FILE__, __FUNCTION__, __LINE__, args); \ } \ @@ -185,25 +185,25 @@ #endif #define NDPI_LOG_ERR(mod, args...) \ - if(mod && mod->ndpi_log_level >= NDPI_LOG_ERROR) { \ + if(mod && mod->cfg.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); \ } #define NDPI_LOG_INFO(mod, args...) \ - if(mod && mod->ndpi_log_level >= NDPI_LOG_TRACE) { \ + if(mod && mod->cfg.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); \ } #define NDPI_LOG_DBG(mod, args...) \ - if(mod && mod->ndpi_log_level >= NDPI_LOG_DEBUG) { \ + if(mod && mod->cfg.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); \ } #define NDPI_LOG_DBG2(mod, args...) \ - if(mod && mod->ndpi_log_level >= NDPI_LOG_DEBUG_EXTRA) { \ + if(mod && mod->cfg.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); \ } diff --git a/src/include/ndpi_private.h b/src/include/ndpi_private.h index 0de05c817..282deba2d 100644 --- a/src/include/ndpi_private.h +++ b/src/include/ndpi_private.h @@ -170,6 +170,8 @@ struct ndpi_detection_module_config_struct { char filename_config[CFG_MAX_LEN]; + int log_level; + /* LRU caches */ int ookla_cache_num_entries; @@ -212,6 +214,7 @@ struct ndpi_detection_module_config_struct { int ookla_aggressiveness; + NDPI_PROTOCOL_BITMASK debug_bitmask; NDPI_PROTOCOL_BITMASK ip_list_bitmask; int flow_risk_lists_enabled; @@ -245,14 +248,11 @@ struct ndpi_detection_module_struct { default_ports_tree_node_t *tcpRoot, *udpRoot; - ndpi_log_level_t ndpi_log_level; /* default error */ - #ifdef NDPI_ENABLE_DEBUG_MESSAGES /* debug callback, only set when debug is used */ ndpi_debug_function_ptr ndpi_debug_printf; const char *ndpi_debug_print_file; const char *ndpi_debug_print_function; - NDPI_PROTOCOL_BITMASK debug_bitmask; #endif /* misc parameters */ diff --git a/src/lib/ndpi_main.c b/src/lib/ndpi_main.c index 8e0c8b278..b22b6c68e 100644 --- a/src/lib/ndpi_main.c +++ b/src/lib/ndpi_main.c @@ -475,7 +475,7 @@ void ndpi_exclude_protocol(struct ndpi_detection_module_struct *ndpi_str, struct u_int16_t protocol_id, const char *_file, const char *_func, int _line) { 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) { + if(ndpi_str && ndpi_str->cfg.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_get_proto_name(ndpi_str, protocol_id)); } @@ -2914,7 +2914,7 @@ void ndpi_debug_printf(unsigned int proto, struct ndpi_detection_module_struct * #define MAX_STR_LEN 250 char str[MAX_STR_LEN]; if(ndpi_str != NULL && log_level > NDPI_LOG_ERROR && proto > 0 && proto < NDPI_MAX_SUPPORTED_PROTOCOLS && - !NDPI_ISSET(&ndpi_str->debug_bitmask, proto)) + !NDPI_ISSET(&ndpi_str->cfg.debug_bitmask, proto)) return; va_start(args, format); ndpi_vsnprintf(str, sizeof(str) - 1, format, args); @@ -3099,7 +3099,6 @@ struct ndpi_detection_module_struct *ndpi_init_detection_module(void) { #ifdef NDPI_ENABLE_DEBUG_MESSAGES set_ndpi_debug_function(ndpi_str, (ndpi_debug_function_ptr) ndpi_debug_printf); - NDPI_BITMASK_RESET(ndpi_str->debug_bitmask); #endif /* NDPI_ENABLE_DEBUG_MESSAGES */ if((ndpi_str->protocols_ptree = ndpi_patricia_new(32 /* IPv4 */)) == NULL || @@ -9786,18 +9785,6 @@ u_int ndpi_get_ndpi_detection_module_size() { return(sizeof(struct ndpi_detection_module_struct)); } -void ndpi_set_debug_bitmask(struct ndpi_detection_module_struct *ndpi_str, NDPI_PROTOCOL_BITMASK debug_bitmask) { -#ifdef NDPI_ENABLE_DEBUG_MESSAGES - if(ndpi_str) - ndpi_str->debug_bitmask = debug_bitmask; -#endif -} - -void ndpi_set_log_level(struct ndpi_detection_module_struct *ndpi_str, u_int l){ - if(ndpi_str) - ndpi_str->ndpi_log_level = l; -} - /* ******************************************************************** */ u_int32_t ndpi_get_current_time(struct ndpi_flow_struct *flow) @@ -10797,7 +10784,8 @@ static const struct cfg_param { { "ookla", "aggressiveness", "0x01", "0", "1", CFG_PARAM_INT, __OFF(ookla_aggressiveness) }, - { "$PROTO_NAME_OR_ID", "ip_list.load", "1", NULL, NULL, CFG_PARAM_PROTOCOL_ENABLE_DISABLE, __OFF(ip_list_bitmask)}, + { "$PROTO_NAME_OR_ID", "log.enable", "0", NULL, NULL, CFG_PARAM_PROTOCOL_ENABLE_DISABLE, __OFF(debug_bitmask) }, + { "$PROTO_NAME_OR_ID", "ip_list.load", "1", NULL, NULL, CFG_PARAM_PROTOCOL_ENABLE_DISABLE, __OFF(ip_list_bitmask) }, /* Global parameters */ @@ -10816,6 +10804,8 @@ static const struct cfg_param { { NULL, "filename.config", NULL, NULL, NULL, CFG_PARAM_FILENAME_CONFIG, __OFF(filename_config) }, + { NULL, "log.level", "0", "0", "3", CFG_PARAM_INT, __OFF(log_level) }, + /* LRU caches */ { NULL, "lru.ookla.size", "1024", "0", "16777215", CFG_PARAM_INT, __OFF(ookla_cache_num_entries)}, |