Fix compilation with --enable-debug-messages flag
NDPI_LOG* macros dereference ndpi_detection_module_struct object which is private to ndpi library (via NDPI_LIB_COMPILATION define). So we can't use them outside the library itself, i.e. in ndpiReader code Therefore, in files in example/, convert all (rare) uses of NDPI_LOG* macros to a new very simple macro, private to ndpiReader program. If necessary, such macro may be improved. According to a comment in ndpi_define.h, each dissector must define its own NDPI_CURRENT_PROTO macro before including ndpi_api.h file
This commit is contained in:
+11
-16
@@ -419,13 +419,13 @@ struct ndpi_workflow* ndpi_workflow_init(const struct ndpi_workflow_prefs * pref
|
|||||||
module = ndpi_init_detection_module(ndpi_no_prefs);
|
module = ndpi_init_detection_module(ndpi_no_prefs);
|
||||||
|
|
||||||
if(module == NULL) {
|
if(module == NULL) {
|
||||||
NDPI_LOG(0, NULL, NDPI_LOG_ERROR, "global structure initialization failed\n");
|
LOG(NDPI_LOG_ERROR, "global structure initialization failed\n");
|
||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
workflow = ndpi_calloc(1, sizeof(struct ndpi_workflow));
|
workflow = ndpi_calloc(1, sizeof(struct ndpi_workflow));
|
||||||
if(workflow == NULL) {
|
if(workflow == NULL) {
|
||||||
NDPI_LOG(0, NULL, NDPI_LOG_ERROR, "global structure initialization failed\n");
|
LOG(NDPI_LOG_ERROR, "global structure initialization failed\n");
|
||||||
ndpi_free(module);
|
ndpi_free(module);
|
||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
@@ -441,13 +441,8 @@ struct ndpi_workflow* ndpi_workflow_init(const struct ndpi_workflow_prefs * pref
|
|||||||
exit(-1);
|
exit(-1);
|
||||||
_debug_protocols_ok = 1;
|
_debug_protocols_ok = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef NDPI_ENABLE_DEBUG_MESSAGES
|
|
||||||
NDPI_BITMASK_RESET(module->debug_bitmask);
|
|
||||||
|
|
||||||
if(_debug_protocols_ok)
|
if(_debug_protocols_ok)
|
||||||
module->debug_bitmask = debug_bitmask;
|
ndpi_set_debug_bitmask(module, debug_bitmask);
|
||||||
#endif
|
|
||||||
|
|
||||||
workflow->ndpi_flows_root = ndpi_calloc(workflow->prefs.num_roots, sizeof(void *));
|
workflow->ndpi_flows_root = ndpi_calloc(workflow->prefs.num_roots, sizeof(void *));
|
||||||
|
|
||||||
@@ -811,7 +806,7 @@ static struct ndpi_flow_info *get_ndpi_flow_info(struct ndpi_workflow * workflow
|
|||||||
|
|
||||||
if(ret == NULL) {
|
if(ret == NULL) {
|
||||||
if(workflow->stats.ndpi_flow_count == workflow->prefs.max_ndpi_flows) {
|
if(workflow->stats.ndpi_flow_count == workflow->prefs.max_ndpi_flows) {
|
||||||
NDPI_LOG(0, workflow->ndpi_struct, NDPI_LOG_ERROR,
|
LOG(NDPI_LOG_ERROR,
|
||||||
"maximum flow count (%u) has been exceeded\n",
|
"maximum flow count (%u) has been exceeded\n",
|
||||||
workflow->prefs.max_ndpi_flows);
|
workflow->prefs.max_ndpi_flows);
|
||||||
exit(-1);
|
exit(-1);
|
||||||
@@ -819,7 +814,7 @@ static struct ndpi_flow_info *get_ndpi_flow_info(struct ndpi_workflow * workflow
|
|||||||
struct ndpi_flow_info *newflow = (struct ndpi_flow_info*)malloc(sizeof(struct ndpi_flow_info));
|
struct ndpi_flow_info *newflow = (struct ndpi_flow_info*)malloc(sizeof(struct ndpi_flow_info));
|
||||||
|
|
||||||
if(newflow == NULL) {
|
if(newflow == NULL) {
|
||||||
NDPI_LOG(0, workflow->ndpi_struct, NDPI_LOG_ERROR, "[NDPI] %s(1): not enough memory\n", __FUNCTION__);
|
LOG(NDPI_LOG_ERROR, "[NDPI] %s(1): not enough memory\n", __FUNCTION__);
|
||||||
return(NULL);
|
return(NULL);
|
||||||
} else
|
} else
|
||||||
workflow->num_allocated_flows++;
|
workflow->num_allocated_flows++;
|
||||||
@@ -856,7 +851,7 @@ static struct ndpi_flow_info *get_ndpi_flow_info(struct ndpi_workflow * workflow
|
|||||||
}
|
}
|
||||||
|
|
||||||
if((newflow->ndpi_flow = ndpi_flow_malloc(SIZEOF_FLOW_STRUCT)) == NULL) {
|
if((newflow->ndpi_flow = ndpi_flow_malloc(SIZEOF_FLOW_STRUCT)) == NULL) {
|
||||||
NDPI_LOG(0, workflow->ndpi_struct, NDPI_LOG_ERROR, "[NDPI] %s(2): not enough memory\n", __FUNCTION__);
|
LOG(NDPI_LOG_ERROR, "[NDPI] %s(2): not enough memory\n", __FUNCTION__);
|
||||||
#ifdef DIRECTION_BINS
|
#ifdef DIRECTION_BINS
|
||||||
ndpi_free_bin(&newflow->payload_len_bin_src2dst), ndpi_free_bin(&newflow->payload_len_bin_dst2src);
|
ndpi_free_bin(&newflow->payload_len_bin_src2dst), ndpi_free_bin(&newflow->payload_len_bin_dst2src);
|
||||||
#else
|
#else
|
||||||
@@ -868,7 +863,7 @@ static struct ndpi_flow_info *get_ndpi_flow_info(struct ndpi_workflow * workflow
|
|||||||
memset(newflow->ndpi_flow, 0, SIZEOF_FLOW_STRUCT);
|
memset(newflow->ndpi_flow, 0, SIZEOF_FLOW_STRUCT);
|
||||||
|
|
||||||
if((newflow->src_id = ndpi_malloc(SIZEOF_ID_STRUCT)) == NULL) {
|
if((newflow->src_id = ndpi_malloc(SIZEOF_ID_STRUCT)) == NULL) {
|
||||||
NDPI_LOG(0, workflow->ndpi_struct, NDPI_LOG_ERROR, "[NDPI] %s(3): not enough memory\n", __FUNCTION__);
|
LOG(NDPI_LOG_ERROR, "[NDPI] %s(3): not enough memory\n", __FUNCTION__);
|
||||||
#ifdef DIRECTION_BINS
|
#ifdef DIRECTION_BINS
|
||||||
ndpi_free_bin(&newflow->payload_len_bin_src2dst), ndpi_free_bin(&newflow->payload_len_bin_dst2src);
|
ndpi_free_bin(&newflow->payload_len_bin_src2dst), ndpi_free_bin(&newflow->payload_len_bin_dst2src);
|
||||||
#else
|
#else
|
||||||
@@ -880,7 +875,7 @@ static struct ndpi_flow_info *get_ndpi_flow_info(struct ndpi_workflow * workflow
|
|||||||
memset(newflow->src_id, 0, SIZEOF_ID_STRUCT);
|
memset(newflow->src_id, 0, SIZEOF_ID_STRUCT);
|
||||||
|
|
||||||
if((newflow->dst_id = ndpi_malloc(SIZEOF_ID_STRUCT)) == NULL) {
|
if((newflow->dst_id = ndpi_malloc(SIZEOF_ID_STRUCT)) == NULL) {
|
||||||
NDPI_LOG(0, workflow->ndpi_struct, NDPI_LOG_ERROR, "[NDPI] %s(4): not enough memory\n", __FUNCTION__);
|
LOG(NDPI_LOG_ERROR, "[NDPI] %s(4): not enough memory\n", __FUNCTION__);
|
||||||
#ifdef DIRECTION_BINS
|
#ifdef DIRECTION_BINS
|
||||||
ndpi_free_bin(&newflow->payload_len_bin_src2dst), ndpi_free_bin(&newflow->payload_len_bin_dst2src);
|
ndpi_free_bin(&newflow->payload_len_bin_src2dst), ndpi_free_bin(&newflow->payload_len_bin_dst2src);
|
||||||
#else
|
#else
|
||||||
@@ -1754,7 +1749,7 @@ struct ndpi_proto ndpi_workflow_process_packet(struct ndpi_workflow * workflow,
|
|||||||
|
|
||||||
if(cap_warning_used == 0) {
|
if(cap_warning_used == 0) {
|
||||||
if(!workflow->prefs.quiet_mode)
|
if(!workflow->prefs.quiet_mode)
|
||||||
NDPI_LOG(0, workflow->ndpi_struct, NDPI_LOG_DEBUG,
|
LOG(NDPI_LOG_DEBUG,
|
||||||
"\n\nWARNING: packet capture size is smaller than packet size, DETECTION MIGHT NOT WORK CORRECTLY\n\n");
|
"\n\nWARNING: packet capture size is smaller than packet size, DETECTION MIGHT NOT WORK CORRECTLY\n\n");
|
||||||
cap_warning_used = 1;
|
cap_warning_used = 1;
|
||||||
}
|
}
|
||||||
@@ -1777,7 +1772,7 @@ struct ndpi_proto ndpi_workflow_process_packet(struct ndpi_workflow * workflow,
|
|||||||
|
|
||||||
if(ipv4_frags_warning_used == 0) {
|
if(ipv4_frags_warning_used == 0) {
|
||||||
if(!workflow->prefs.quiet_mode)
|
if(!workflow->prefs.quiet_mode)
|
||||||
NDPI_LOG(0, workflow->ndpi_struct, NDPI_LOG_DEBUG, "\n\nWARNING: IPv4 fragments are not handled by this demo (nDPI supports them)\n");
|
LOG(NDPI_LOG_DEBUG, "\n\nWARNING: IPv4 fragments are not handled by this demo (nDPI supports them)\n");
|
||||||
ipv4_frags_warning_used = 1;
|
ipv4_frags_warning_used = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1811,7 +1806,7 @@ struct ndpi_proto ndpi_workflow_process_packet(struct ndpi_workflow * workflow,
|
|||||||
v4_warning:
|
v4_warning:
|
||||||
if(ipv4_warning_used == 0) {
|
if(ipv4_warning_used == 0) {
|
||||||
if(!workflow->prefs.quiet_mode)
|
if(!workflow->prefs.quiet_mode)
|
||||||
NDPI_LOG(0, workflow->ndpi_struct, NDPI_LOG_DEBUG,
|
LOG(NDPI_LOG_DEBUG,
|
||||||
"\n\nWARNING: only IPv4/IPv6 packets are supported in this demo (nDPI supports both IPv4 and IPv6), all other packets will be discarded\n\n");
|
"\n\nWARNING: only IPv4/IPv6 packets are supported in this demo (nDPI supports both IPv4 and IPv6), all other packets will be discarded\n\n");
|
||||||
ipv4_warning_used = 1;
|
ipv4_warning_used = 1;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -336,4 +336,15 @@ float ndpi_flow_get_byte_count_entropy(const uint32_t byte_count[256], unsigned
|
|||||||
|
|
||||||
extern int nDPI_LogLevel;
|
extern int nDPI_LogLevel;
|
||||||
|
|
||||||
|
/* TODO: conditional compilation? */
|
||||||
|
#if 1
|
||||||
|
#define LOG(log_level, args...) \
|
||||||
|
{ \
|
||||||
|
if(log_level <= nDPI_LogLevel) \
|
||||||
|
printf(args); \
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
#define LOG(...) {}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -844,6 +844,7 @@ extern "C" {
|
|||||||
u_int ndpi_get_ndpi_num_custom_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);
|
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_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);
|
||||||
|
|
||||||
/* LRU cache */
|
/* LRU cache */
|
||||||
struct ndpi_lru_cache* ndpi_lru_cache_init(u_int32_t num_entries);
|
struct ndpi_lru_cache* ndpi_lru_cache_init(u_int32_t num_entries);
|
||||||
|
|||||||
@@ -179,6 +179,8 @@
|
|||||||
#define NDPI_JABBER_FT_TIMEOUT 5
|
#define NDPI_JABBER_FT_TIMEOUT 5
|
||||||
#define NDPI_SOULSEEK_CONNECTION_IP_TICK_TIMEOUT 600
|
#define NDPI_SOULSEEK_CONNECTION_IP_TICK_TIMEOUT 600
|
||||||
|
|
||||||
|
#include "ndpi_config.h" /* To have access to NDPI_ENABLE_DEBUG_MESSAGES */
|
||||||
|
|
||||||
#ifdef NDPI_ENABLE_DEBUG_MESSAGES
|
#ifdef NDPI_ENABLE_DEBUG_MESSAGES
|
||||||
#define NDPI_LOG(proto, m, log_level, args...) \
|
#define NDPI_LOG(proto, m, log_level, args...) \
|
||||||
{ \
|
{ \
|
||||||
@@ -196,7 +198,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef NDPI_CURRENT_PROTO
|
#ifndef NDPI_CURRENT_PROTO
|
||||||
#define NDPI_CURRENT_PROTO NDPI_PROTO_UNKNOWN
|
#define NDPI_CURRENT_PROTO NDPI_PROTOCOL_UNKNOWN
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define NDPI_LOG_ERR(mod, args...) \
|
#define NDPI_LOG_ERR(mod, args...) \
|
||||||
|
|||||||
+9
-1
@@ -1954,7 +1954,8 @@ struct ndpi_detection_module_struct *ndpi_init_detection_module(ndpi_init_prefs
|
|||||||
|
|
||||||
if(ndpi_str == NULL) {
|
if(ndpi_str == NULL) {
|
||||||
#ifdef NDPI_ENABLE_DEBUG_MESSAGES
|
#ifdef NDPI_ENABLE_DEBUG_MESSAGES
|
||||||
NDPI_LOG_ERR(ndpi_str, "ndpi_init_detection_module initial malloc failed for ndpi_str\n");
|
/* We can't use NDPI_LOG* functions yet! */
|
||||||
|
fprintf(stderr, "ndpi_init_detection_module initial malloc failed for ndpi_str\n");
|
||||||
#endif /* NDPI_ENABLE_DEBUG_MESSAGES */
|
#endif /* NDPI_ENABLE_DEBUG_MESSAGES */
|
||||||
return(NULL);
|
return(NULL);
|
||||||
}
|
}
|
||||||
@@ -1963,6 +1964,7 @@ struct ndpi_detection_module_struct *ndpi_init_detection_module(ndpi_init_prefs
|
|||||||
|
|
||||||
#ifdef NDPI_ENABLE_DEBUG_MESSAGES
|
#ifdef NDPI_ENABLE_DEBUG_MESSAGES
|
||||||
set_ndpi_debug_function(ndpi_str, (ndpi_debug_function_ptr) ndpi_debug_printf);
|
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 */
|
#endif /* NDPI_ENABLE_DEBUG_MESSAGES */
|
||||||
|
|
||||||
if((ndpi_str->protocols_ptree = ndpi_New_Patricia(32 /* IPv4 */)) != NULL)
|
if((ndpi_str->protocols_ptree = ndpi_New_Patricia(32 /* IPv4 */)) != NULL)
|
||||||
@@ -6247,6 +6249,12 @@ u_int ndpi_get_ndpi_detection_module_size() {
|
|||||||
return(sizeof(struct ndpi_detection_module_struct));
|
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
|
||||||
|
ndpi_str->debug_bitmask = debug_bitmask;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
void ndpi_set_log_level(struct ndpi_detection_module_struct *ndpi_str, u_int l){
|
void ndpi_set_log_level(struct ndpi_detection_module_struct *ndpi_str, u_int l){
|
||||||
ndpi_str->ndpi_log_level = l;
|
ndpi_str->ndpi_log_level = l;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,9 +6,8 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "ndpi_protocol_ids.h"
|
#include "ndpi_protocol_ids.h"
|
||||||
#include "ndpi_api.h"
|
|
||||||
|
|
||||||
#define NDPI_CURRENT_PROTO NDPI_PROTOCOL_DNP3
|
#define NDPI_CURRENT_PROTO NDPI_PROTOCOL_DNP3
|
||||||
|
#include "ndpi_api.h"
|
||||||
|
|
||||||
void ndpi_search_dnp3_tcp(struct ndpi_detection_module_struct *ndpi_struct,
|
void ndpi_search_dnp3_tcp(struct ndpi_detection_module_struct *ndpi_struct,
|
||||||
struct ndpi_flow_struct *flow) {
|
struct ndpi_flow_struct *flow) {
|
||||||
|
|||||||
@@ -589,8 +589,10 @@ static u_int16_t http_request_url_offset(struct ndpi_detection_module_struct *nd
|
|||||||
int i;
|
int i;
|
||||||
|
|
||||||
NDPI_LOG_DBG2(ndpi_struct, "====>>>> HTTP: %c%c%c%c [len: %u]\n",
|
NDPI_LOG_DBG2(ndpi_struct, "====>>>> HTTP: %c%c%c%c [len: %u]\n",
|
||||||
non_ctrl(packet->payload[0]), non_ctrl(packet->payload[1]),
|
packet->payload_packet_len > 0 ? packet->payload[0] : '.',
|
||||||
non_ctrl(packet->payload[2]), non_ctrl(packet->payload[3]),
|
packet->payload_packet_len > 1 ? packet->payload[1] : '.',
|
||||||
|
packet->payload_packet_len > 2 ? packet->payload[2] : '.',
|
||||||
|
packet->payload_packet_len > 3 ? packet->payload[3] : '.',
|
||||||
packet->payload_packet_len);
|
packet->payload_packet_len);
|
||||||
|
|
||||||
/* Check first char */
|
/* Check first char */
|
||||||
|
|||||||
@@ -25,9 +25,8 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "ndpi_protocol_ids.h"
|
#include "ndpi_protocol_ids.h"
|
||||||
#include "ndpi_api.h"
|
|
||||||
|
|
||||||
#define NDPI_CURRENT_PROTO NDPI_PROTOCOL_IEC60870
|
#define NDPI_CURRENT_PROTO NDPI_PROTOCOL_IEC60870
|
||||||
|
#include "ndpi_api.h"
|
||||||
|
|
||||||
void ndpi_search_iec60870_tcp(struct ndpi_detection_module_struct *ndpi_struct,
|
void ndpi_search_iec60870_tcp(struct ndpi_detection_module_struct *ndpi_struct,
|
||||||
struct ndpi_flow_struct *flow) {
|
struct ndpi_flow_struct *flow) {
|
||||||
|
|||||||
@@ -21,7 +21,7 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
#include "ndpi_protocol_ids.h"
|
#include "ndpi_protocol_ids.h"
|
||||||
|
#define NDPI_CURRENT_PROTO NDPI_PROTOCOL_MINING
|
||||||
#include "ndpi_api.h"
|
#include "ndpi_api.h"
|
||||||
|
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|||||||
@@ -24,9 +24,8 @@
|
|||||||
|
|
||||||
|
|
||||||
#include "ndpi_protocol_ids.h"
|
#include "ndpi_protocol_ids.h"
|
||||||
#include "ndpi_api.h"
|
|
||||||
|
|
||||||
#define NDPI_CURRENT_PROTO NDPI_PROTOCOL_MODBUS
|
#define NDPI_CURRENT_PROTO NDPI_PROTOCOL_MODBUS
|
||||||
|
#include "ndpi_api.h"
|
||||||
|
|
||||||
void ndpi_search_modbus_tcp(struct ndpi_detection_module_struct *ndpi_struct,
|
void ndpi_search_modbus_tcp(struct ndpi_detection_module_struct *ndpi_struct,
|
||||||
struct ndpi_flow_struct *flow) {
|
struct ndpi_flow_struct *flow) {
|
||||||
|
|||||||
@@ -20,9 +20,8 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "ndpi_protocol_ids.h"
|
#include "ndpi_protocol_ids.h"
|
||||||
#include "ndpi_api.h"
|
|
||||||
|
|
||||||
#define NDPI_CURRENT_PROTO NDPI_PROTOCOL_NATS
|
#define NDPI_CURRENT_PROTO NDPI_PROTOCOL_NATS
|
||||||
|
#include "ndpi_api.h"
|
||||||
|
|
||||||
static const char* commands[] =
|
static const char* commands[] =
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -21,8 +21,8 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
#include "ndpi_protocol_ids.h"
|
#include "ndpi_protocol_ids.h"
|
||||||
#include "ndpi_api.h"
|
|
||||||
#define NDPI_CURRENT_PROTO NDPI_PROTOCOL_S7COMM
|
#define NDPI_CURRENT_PROTO NDPI_PROTOCOL_S7COMM
|
||||||
|
#include "ndpi_api.h"
|
||||||
|
|
||||||
void ndpi_search_s7comm_tcp(struct ndpi_detection_module_struct *ndpi_struct,
|
void ndpi_search_s7comm_tcp(struct ndpi_detection_module_struct *ndpi_struct,
|
||||||
struct ndpi_flow_struct *flow) {
|
struct ndpi_flow_struct *flow) {
|
||||||
|
|||||||
@@ -21,7 +21,7 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
#include "ndpi_protocol_ids.h"
|
#include "ndpi_protocol_ids.h"
|
||||||
|
#define NDPI_CURRENT_PROTO NDPI_PROTOCOL_SMBV23
|
||||||
#include "ndpi_api.h"
|
#include "ndpi_api.h"
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user