Refactoring the debugging output.

levels of debug output:
 0 - ERROR: Only for errors.
 1 - TRACE: Start of each packets and if found protocol.
 2 - DEBUG: Start of searching each protocol and excluding protocols.
 3 - DEBUG_EXTRA: For all other messages.

Added field ndpi_struct->debug_logging for enable debug output of each protocols.

Simple macros for debugging output are added:
NDPI_LOG_ERR(), NDPI_LOG_INFO(), NDPI_LOG_DBG(), NDPI_LOG_DBG2(),
NDPI_EXCLUDE_PROTO()
This commit is contained in:
Vitaly Lavrov
2017-10-26 20:41:22 +03:00
parent 4f72b954da
commit 2787c2390c
153 changed files with 2680 additions and 2492 deletions
+10 -11
View File
@@ -18,10 +18,14 @@
*
*/
#include "ndpi_protocol_ids.h"
#ifdef NDPI_PROTOCOL_NETFLOW
#define NDPI_CURRENT_PROTO NDPI_PROTOCOL_NETFLOW
#include "ndpi_api.h"
#ifdef NDPI_PROTOCOL_NETFLOW
#ifdef WIN32
extern int gettimeofday(struct timeval * tp, struct timezone * tzp);
@@ -95,7 +99,7 @@ struct flow_ver7_rec {
u_int32_t router_sc; /* Router which is shortcut by switch */
};
static void ndpi_check_netflow(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow)
void ndpi_search_netflow(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow)
{
struct ndpi_packet_struct *packet = &flow->packet;
// const u_int8_t *packet_payload = packet->payload;
@@ -103,6 +107,8 @@ static void ndpi_check_netflow(struct ndpi_detection_module_struct *ndpi_struct,
time_t now;
struct timeval now_tv;
NDPI_LOG_DBG(ndpi_struct, "search netflow\n");
if((packet->udp != NULL) && (payload_len >= 24)) {
u_int16_t version = (packet->payload[0] << 8) + packet->payload[1], uptime_offset;
u_int32_t when, *_when;
@@ -132,7 +138,7 @@ static void ndpi_check_netflow(struct ndpi_detection_module_struct *ndpi_struct,
}
if((expected_len > 0) && (expected_len != payload_len)) {
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_NETFLOW);
NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
return;
}
@@ -159,20 +165,13 @@ static void ndpi_check_netflow(struct ndpi_detection_module_struct *ndpi_struct,
if(((version == 1) && (when == 0))
|| ((when >= 946684800 /* 1/1/2000 */) && (when <= now))) {
NDPI_LOG(NDPI_PROTOCOL_NETFLOW, ndpi_struct, NDPI_LOG_DEBUG, "Found netflow.\n");
NDPI_LOG_INFO(ndpi_struct, "found netflow\n");
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_NETFLOW, NDPI_PROTOCOL_UNKNOWN);
return;
}
}
}
void ndpi_search_netflow(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow)
{
NDPI_LOG(NDPI_PROTOCOL_NETFLOW, ndpi_struct, NDPI_LOG_DEBUG, "netflow detection...\n");
ndpi_check_netflow(ndpi_struct, flow);
}
void init_netflow_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask)
{
ndpi_set_bitmask_protocol_detection("NetFlow", ndpi_struct, detection_bitmask, *id,