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
+15 -13
View File
@@ -22,11 +22,14 @@
*
*/
#include "ndpi_protocols.h"
#include "ndpi_protocol_ids.h"
#ifdef NDPI_PROTOCOL_SHOUTCAST
#define NDPI_CURRENT_PROTO NDPI_PROTOCOL_SHOUTCAST
#include "ndpi_api.h"
static void ndpi_int_shoutcast_add_connection(struct ndpi_detection_module_struct
*ndpi_struct, struct ndpi_flow_struct *flow)
{
@@ -39,13 +42,13 @@ void ndpi_search_shoutcast_tcp(struct ndpi_detection_module_struct
struct ndpi_packet_struct *packet = &flow->packet;
NDPI_LOG(NDPI_PROTOCOL_SHOUTCAST, ndpi_struct, NDPI_LOG_DEBUG, "search shoutcast.\n");
NDPI_LOG_DBG(ndpi_struct, "search shoutcast\n");
if (flow->packet_counter == 1) {
/* this case in paul_upload_oddcast_002.pcap */
if (packet->payload_packet_len >= 6
&& packet->payload_packet_len < 80 && memcmp(packet->payload, "123456", 6) == 0) {
NDPI_LOG(NDPI_PROTOCOL_SHOUTCAST, ndpi_struct, NDPI_LOG_DEBUG, "Shoutcast stage 1, \"123456\".\n");
NDPI_LOG_DBG2(ndpi_struct, "Shoutcast stage 1, \"123456\"\n");
return;
}
if (flow->packet_counter < 3
@@ -53,11 +56,11 @@ void ndpi_search_shoutcast_tcp(struct ndpi_detection_module_struct
&& packet->detected_protocol_stack[0] == NDPI_PROTOCOL_HTTP
#endif
) {
NDPI_LOG(NDPI_PROTOCOL_SHOUTCAST, ndpi_struct, NDPI_LOG_DEBUG,
NDPI_LOG_DBG2(ndpi_struct,
"http detected, need next packet for shoutcast detection.\n");
if (packet->payload_packet_len > 4
&& get_u_int32_t(packet->payload, packet->payload_packet_len - 4) != htonl(0x0d0a0d0a)) {
NDPI_LOG(NDPI_PROTOCOL_SHOUTCAST, ndpi_struct, NDPI_LOG_DEBUG, "segmented packet found.\n");
NDPI_LOG_DBG2(ndpi_struct, "segmented packet found\n");
flow->l4.tcp.shoutcast_stage = 1 + packet->packet_direction;
}
return;
@@ -70,7 +73,7 @@ void ndpi_search_shoutcast_tcp(struct ndpi_detection_module_struct
}
/* evtl. für asym detection noch User-Agent:Winamp dazunehmen. */
if (packet->payload_packet_len > 11 && memcmp(packet->payload, "ICY 200 OK\x0d\x0a", 12) == 0) {
NDPI_LOG(NDPI_PROTOCOL_SHOUTCAST, ndpi_struct, NDPI_LOG_DEBUG, "found shoutcast by ICY 200 OK.\n");
NDPI_LOG_INFO(ndpi_struct, "found shoutcast by ICY 200 OK\n");
ndpi_int_shoutcast_add_connection(ndpi_struct, flow);
return;
}
@@ -81,19 +84,19 @@ void ndpi_search_shoutcast_tcp(struct ndpi_detection_module_struct
if (flow->packet_counter == 2) {
if (packet->payload_packet_len == 2 && memcmp(packet->payload, "\x0d\x0a", 2) == 0) {
NDPI_LOG(NDPI_PROTOCOL_SHOUTCAST, ndpi_struct, NDPI_LOG_DEBUG, "Shoutcast stage 1 continuation.\n");
NDPI_LOG_DBG2(ndpi_struct, "Shoutcast stage 1 continuation\n");
return;
} else if (packet->payload_packet_len > 3 && memcmp(&packet->payload[0], "OK2", 3) == 0) {
NDPI_LOG(NDPI_PROTOCOL_SHOUTCAST, ndpi_struct, NDPI_LOG_DEBUG, "Shoutcast stage 2, OK2 found.\n");
NDPI_LOG_DBG2(ndpi_struct, "Shoutcast stage 2, OK2 found\n");
return;
} else
goto exclude_shoutcast;
} else if (flow->packet_counter == 3 || flow->packet_counter == 4) {
if (packet->payload_packet_len > 3 && memcmp(&packet->payload[0], "OK2", 3) == 0) {
NDPI_LOG(NDPI_PROTOCOL_SHOUTCAST, ndpi_struct, NDPI_LOG_DEBUG, "Shoutcast stage 2, OK2 found.\n");
NDPI_LOG_DBG2(ndpi_struct, "Shoutcast stage 2, OK2 found\n");
return;
} else if (packet->payload_packet_len > 4 && memcmp(&packet->payload[0], "icy-", 4) == 0) {
NDPI_LOG(NDPI_PROTOCOL_SHOUTCAST, ndpi_struct, NDPI_LOG_DEBUG, "Shoutcast detected.\n");
NDPI_LOG_INFO(ndpi_struct, "found Shoutcast\n");
ndpi_int_shoutcast_add_connection(ndpi_struct, flow);
return;
} else
@@ -101,8 +104,7 @@ void ndpi_search_shoutcast_tcp(struct ndpi_detection_module_struct
}
exclude_shoutcast:
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_SHOUTCAST);
NDPI_LOG(NDPI_PROTOCOL_SHOUTCAST, ndpi_struct, NDPI_LOG_DEBUG, "Shoutcast excluded.\n");
NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
}