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:
+42
-52
@@ -22,10 +22,14 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "ndpi_protocol_ids.h"
|
||||
|
||||
#ifdef NDPI_PROTOCOL_UNENCRYPTED_JABBER
|
||||
|
||||
#define NDPI_CURRENT_PROTO NDPI_PROTOCOL_UNENCRYPTED_JABBER
|
||||
|
||||
#include "ndpi_api.h"
|
||||
|
||||
#ifdef NDPI_PROTOCOL_UNENCRYPTED_JABBER
|
||||
struct jabber_string {
|
||||
char *string;
|
||||
u_int ndpi_protocol;
|
||||
@@ -70,51 +74,47 @@ void ndpi_search_jabber_tcp(struct ndpi_detection_module_struct *ndpi_struct, st
|
||||
|
||||
u_int16_t x;
|
||||
|
||||
NDPI_LOG(NDPI_PROTOCOL_UNENCRYPTED_JABBER, ndpi_struct, NDPI_LOG_TRACE, "JABBER detection....\n");
|
||||
NDPI_LOG_DBG(ndpi_struct, "search JABBER\n");
|
||||
|
||||
/* search for jabber file transfer */
|
||||
/* this part is working asymmetrically */
|
||||
if (packet->tcp != NULL && packet->tcp->syn != 0 && packet->payload_packet_len == 0) {
|
||||
NDPI_LOG(NDPI_PROTOCOL_UNENCRYPTED_JABBER, ndpi_struct, NDPI_LOG_DEBUG, "check jabber syn\n");
|
||||
NDPI_LOG_DBG2(ndpi_struct, "check jabber syn\n");
|
||||
if (src != NULL && src->jabber_file_transfer_port[0] != 0) {
|
||||
NDPI_LOG(NDPI_PROTOCOL_UNENCRYPTED_JABBER, ndpi_struct, NDPI_LOG_DEBUG,
|
||||
"src jabber ft port set, ports are: %u, %u\n", ntohs(src->jabber_file_transfer_port[0]),
|
||||
ntohs(src->jabber_file_transfer_port[1]));
|
||||
NDPI_LOG_DBG2(ndpi_struct, "src jabber ft port set, ports are: %u, %u\n",
|
||||
ntohs(src->jabber_file_transfer_port[0]),
|
||||
ntohs(src->jabber_file_transfer_port[1]));
|
||||
if (((u_int32_t)
|
||||
(packet->tick_timestamp - src->jabber_stun_or_ft_ts)) >= ndpi_struct->jabber_file_transfer_timeout) {
|
||||
NDPI_LOG(NDPI_PROTOCOL_UNENCRYPTED_JABBER, ndpi_struct,
|
||||
NDPI_LOG_DEBUG, "JABBER src stun timeout %u %u\n", src->jabber_stun_or_ft_ts,
|
||||
packet->tick_timestamp);
|
||||
NDPI_LOG_DBG2(ndpi_struct, "JABBER src stun timeout %u %u\n",
|
||||
src->jabber_stun_or_ft_ts, packet->tick_timestamp);
|
||||
src->jabber_file_transfer_port[0] = 0;
|
||||
src->jabber_file_transfer_port[1] = 0;
|
||||
} else if (src->jabber_file_transfer_port[0] == packet->tcp->dest
|
||||
|| src->jabber_file_transfer_port[0] == packet->tcp->source
|
||||
|| src->jabber_file_transfer_port[1] == packet->tcp->dest
|
||||
|| src->jabber_file_transfer_port[1] == packet->tcp->source) {
|
||||
NDPI_LOG(NDPI_PROTOCOL_UNENCRYPTED_JABBER, ndpi_struct, NDPI_LOG_DEBUG,
|
||||
"found jabber file transfer.\n");
|
||||
NDPI_LOG_INFO(ndpi_struct, "found jabber file transfer\n");
|
||||
|
||||
ndpi_int_jabber_add_connection(ndpi_struct, flow,
|
||||
NDPI_PROTOCOL_UNENCRYPTED_JABBER);
|
||||
}
|
||||
}
|
||||
if (dst != NULL && dst->jabber_file_transfer_port[0] != 0) {
|
||||
NDPI_LOG(NDPI_PROTOCOL_UNENCRYPTED_JABBER, ndpi_struct, NDPI_LOG_DEBUG,
|
||||
"dst jabber ft port set, ports are: %u, %u\n", ntohs(dst->jabber_file_transfer_port[0]),
|
||||
ntohs(dst->jabber_file_transfer_port[1]));
|
||||
NDPI_LOG_DBG2(ndpi_struct, "dst jabber ft port set, ports are: %u, %u\n",
|
||||
ntohs(dst->jabber_file_transfer_port[0]),
|
||||
ntohs(dst->jabber_file_transfer_port[1]));
|
||||
if (((u_int32_t)
|
||||
(packet->tick_timestamp - dst->jabber_stun_or_ft_ts)) >= ndpi_struct->jabber_file_transfer_timeout) {
|
||||
NDPI_LOG(NDPI_PROTOCOL_UNENCRYPTED_JABBER, ndpi_struct,
|
||||
NDPI_LOG_DEBUG, "JABBER dst stun timeout %u %u\n", dst->jabber_stun_or_ft_ts,
|
||||
packet->tick_timestamp);
|
||||
NDPI_LOG_DBG2(ndpi_struct, "JABBER dst stun timeout %u %u\n",
|
||||
dst->jabber_stun_or_ft_ts, packet->tick_timestamp);
|
||||
dst->jabber_file_transfer_port[0] = 0;
|
||||
dst->jabber_file_transfer_port[1] = 0;
|
||||
} else if (dst->jabber_file_transfer_port[0] == packet->tcp->dest
|
||||
|| dst->jabber_file_transfer_port[0] == packet->tcp->source
|
||||
|| dst->jabber_file_transfer_port[1] == packet->tcp->dest
|
||||
|| dst->jabber_file_transfer_port[1] == packet->tcp->source) {
|
||||
NDPI_LOG(NDPI_PROTOCOL_UNENCRYPTED_JABBER, ndpi_struct, NDPI_LOG_DEBUG,
|
||||
"found jabber file transfer.\n");
|
||||
NDPI_LOG_INFO(ndpi_struct, "found jabber file transfer\n");
|
||||
|
||||
ndpi_int_jabber_add_connection(ndpi_struct, flow,
|
||||
NDPI_PROTOCOL_UNENCRYPTED_JABBER);
|
||||
@@ -135,17 +135,17 @@ void ndpi_search_jabber_tcp(struct ndpi_detection_module_struct *ndpi_struct, st
|
||||
/* check for google jabber voip connections ... */
|
||||
/* need big packet */
|
||||
if (packet->payload_packet_len < 100) {
|
||||
NDPI_LOG(NDPI_PROTOCOL_UNENCRYPTED_JABBER, ndpi_struct, NDPI_LOG_DEBUG, "packet too small, return.\n");
|
||||
NDPI_LOG_DBG2(ndpi_struct, "packet too small, return\n");
|
||||
return;
|
||||
}
|
||||
/* need message to or type for file-transfer */
|
||||
if (memcmp(packet->payload, "<iq from=\"", 8) == 0 || memcmp(packet->payload, "<iq from=\'", 8) == 0) {
|
||||
NDPI_LOG(NDPI_PROTOCOL_UNENCRYPTED_JABBER, ndpi_struct, NDPI_LOG_DEBUG, "JABBER <iq from=\".\n");
|
||||
NDPI_LOG_DBG2(ndpi_struct, "JABBER <iq from=\"\n");
|
||||
lastlen = packet->payload_packet_len - 11;
|
||||
for (x = 10; x < lastlen; x++) {
|
||||
if (packet->payload[x] == 'p') {
|
||||
if (memcmp(&packet->payload[x], "port=", 5) == 0) {
|
||||
NDPI_LOG(NDPI_PROTOCOL_UNENCRYPTED_JABBER, ndpi_struct, NDPI_LOG_DEBUG, "port=\n");
|
||||
NDPI_LOG_DBG2(ndpi_struct, "port=\n");
|
||||
if (src != NULL) {
|
||||
src->jabber_stun_or_ft_ts = packet->tick_timestamp;
|
||||
}
|
||||
@@ -155,30 +155,25 @@ void ndpi_search_jabber_tcp(struct ndpi_detection_module_struct *ndpi_struct, st
|
||||
}
|
||||
x += 6;
|
||||
j_port = ntohs_ndpi_bytestream_to_number(&packet->payload[x], packet->payload_packet_len, &x);
|
||||
NDPI_LOG(NDPI_PROTOCOL_UNENCRYPTED_JABBER, ndpi_struct,
|
||||
NDPI_LOG_DEBUG, "JABBER port : %u\n", ntohs(j_port));
|
||||
NDPI_LOG_DBG2(ndpi_struct, "JABBER port : %u\n", ntohs(j_port));
|
||||
if (src != NULL) {
|
||||
if (src->jabber_file_transfer_port[0] == 0 || src->jabber_file_transfer_port[0] == j_port) {
|
||||
NDPI_LOG(NDPI_PROTOCOL_UNENCRYPTED_JABBER, ndpi_struct,
|
||||
NDPI_LOG_DEBUG, "src->jabber_file_transfer_port[0] = j_port = %u;\n",
|
||||
NDPI_LOG_DBG2(ndpi_struct, "src->jabber_file_transfer_port[0] = j_port = %u;\n",
|
||||
ntohs(j_port));
|
||||
src->jabber_file_transfer_port[0] = j_port;
|
||||
} else {
|
||||
NDPI_LOG(NDPI_PROTOCOL_UNENCRYPTED_JABBER, ndpi_struct,
|
||||
NDPI_LOG_DEBUG, "src->jabber_file_transfer_port[1] = j_port = %u;\n",
|
||||
NDPI_LOG_DBG2(ndpi_struct, "src->jabber_file_transfer_port[1] = j_port = %u;\n",
|
||||
ntohs(j_port));
|
||||
src->jabber_file_transfer_port[1] = j_port;
|
||||
}
|
||||
}
|
||||
if (dst != NULL) {
|
||||
if (dst->jabber_file_transfer_port[0] == 0 || dst->jabber_file_transfer_port[0] == j_port) {
|
||||
NDPI_LOG(NDPI_PROTOCOL_UNENCRYPTED_JABBER, ndpi_struct,
|
||||
NDPI_LOG_DEBUG, "dst->jabber_file_transfer_port[0] = j_port = %u;\n",
|
||||
NDPI_LOG_DBG2(ndpi_struct, "dst->jabber_file_transfer_port[0] = j_port = %u;\n",
|
||||
ntohs(j_port));
|
||||
dst->jabber_file_transfer_port[0] = j_port;
|
||||
} else {
|
||||
NDPI_LOG(NDPI_PROTOCOL_UNENCRYPTED_JABBER, ndpi_struct,
|
||||
NDPI_LOG_DEBUG, "dst->jabber_file_transfer_port[1] = j_port = %u;\n",
|
||||
NDPI_LOG_DBG2(ndpi_struct, "dst->jabber_file_transfer_port[1] = j_port = %u;\n",
|
||||
ntohs(j_port));
|
||||
dst->jabber_file_transfer_port[1] = j_port;
|
||||
}
|
||||
@@ -191,7 +186,7 @@ void ndpi_search_jabber_tcp(struct ndpi_detection_module_struct *ndpi_struct, st
|
||||
|
||||
} else if (memcmp(packet->payload, "<iq to=\"", 8) == 0 || memcmp(packet->payload, "<iq to=\'", 8) == 0
|
||||
|| memcmp(packet->payload, "<iq type=", 9) == 0) {
|
||||
NDPI_LOG(NDPI_PROTOCOL_UNENCRYPTED_JABBER, ndpi_struct, NDPI_LOG_DEBUG, "JABBER <iq to=\"/type=\"\n");
|
||||
NDPI_LOG_DBG2(ndpi_struct, "JABBER <iq to=\"/type=\"\n");
|
||||
lastlen = packet->payload_packet_len - 21;
|
||||
for (x = 8; x < lastlen; x++) {
|
||||
/* invalid character */
|
||||
@@ -199,7 +194,7 @@ void ndpi_search_jabber_tcp(struct ndpi_detection_module_struct *ndpi_struct, st
|
||||
return;
|
||||
}
|
||||
if (packet->payload[x] == '@') {
|
||||
NDPI_LOG(NDPI_PROTOCOL_UNENCRYPTED_JABBER, ndpi_struct, NDPI_LOG_DEBUG, "JABBER @\n");
|
||||
NDPI_LOG_DBG2(ndpi_struct, "JABBER @\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -211,7 +206,7 @@ void ndpi_search_jabber_tcp(struct ndpi_detection_module_struct *ndpi_struct, st
|
||||
for (; x < lastlen; x++) {
|
||||
if (packet->payload[x] == 'p') {
|
||||
if (memcmp(&packet->payload[x], "port=", 5) == 0) {
|
||||
NDPI_LOG(NDPI_PROTOCOL_UNENCRYPTED_JABBER, ndpi_struct, NDPI_LOG_DEBUG, "port=\n");
|
||||
NDPI_LOG_DBG2(ndpi_struct, "port=\n");
|
||||
if (src != NULL) {
|
||||
src->jabber_stun_or_ft_ts = packet->tick_timestamp;
|
||||
}
|
||||
@@ -222,8 +217,7 @@ void ndpi_search_jabber_tcp(struct ndpi_detection_module_struct *ndpi_struct, st
|
||||
|
||||
x += 6;
|
||||
j_port = ntohs_ndpi_bytestream_to_number(&packet->payload[x], packet->payload_packet_len, &x);
|
||||
NDPI_LOG(NDPI_PROTOCOL_UNENCRYPTED_JABBER, ndpi_struct,
|
||||
NDPI_LOG_DEBUG, "JABBER port : %u\n", ntohs(j_port));
|
||||
NDPI_LOG_DBG2(ndpi_struct, "JABBER port : %u\n", ntohs(j_port));
|
||||
|
||||
if (src != NULL && src->jabber_voice_stun_used_ports < JABBER_MAX_STUN_PORTS - 1) {
|
||||
if (packet->payload[5] == 'o') {
|
||||
@@ -232,13 +226,12 @@ void ndpi_search_jabber_tcp(struct ndpi_detection_module_struct *ndpi_struct, st
|
||||
} else {
|
||||
if (src->jabber_file_transfer_port[0] == 0
|
||||
|| src->jabber_file_transfer_port[0] == j_port) {
|
||||
NDPI_LOG(NDPI_PROTOCOL_UNENCRYPTED_JABBER, ndpi_struct, NDPI_LOG_DEBUG,
|
||||
"src->jabber_file_transfer_port[0] = j_port = %u;\n", ntohs(j_port));
|
||||
NDPI_LOG_DBG2(ndpi_struct, "src->jabber_file_transfer_port[0] = j_port = %u;\n",
|
||||
ntohs(j_port));
|
||||
src->jabber_file_transfer_port[0] = j_port;
|
||||
} else {
|
||||
NDPI_LOG(NDPI_PROTOCOL_UNENCRYPTED_JABBER, ndpi_struct,
|
||||
NDPI_LOG_DEBUG, "src->jabber_file_transfer_port[1] = j_port = %u;\n",
|
||||
ntohs(j_port));
|
||||
NDPI_LOG_DBG2(ndpi_struct, "src->jabber_file_transfer_port[1] = j_port = %u;\n",
|
||||
ntohs(j_port));
|
||||
src->jabber_file_transfer_port[1] = j_port;
|
||||
}
|
||||
}
|
||||
@@ -251,13 +244,12 @@ void ndpi_search_jabber_tcp(struct ndpi_detection_module_struct *ndpi_struct, st
|
||||
} else {
|
||||
if (dst->jabber_file_transfer_port[0] == 0
|
||||
|| dst->jabber_file_transfer_port[0] == j_port) {
|
||||
NDPI_LOG(NDPI_PROTOCOL_UNENCRYPTED_JABBER, ndpi_struct, NDPI_LOG_DEBUG,
|
||||
"dst->jabber_file_transfer_port[0] = j_port = %u;\n", ntohs(j_port));
|
||||
NDPI_LOG_DBG2(ndpi_struct, "dst->jabber_file_transfer_port[0] = j_port = %u;\n",
|
||||
ntohs(j_port));
|
||||
dst->jabber_file_transfer_port[0] = j_port;
|
||||
} else {
|
||||
NDPI_LOG(NDPI_PROTOCOL_UNENCRYPTED_JABBER, ndpi_struct,
|
||||
NDPI_LOG_DEBUG, "dst->jabber_file_transfer_port[1] = j_port = %u;\n",
|
||||
ntohs(j_port));
|
||||
NDPI_LOG_DBG2(ndpi_struct, "dst->jabber_file_transfer_port[1] = j_port = %u;\n",
|
||||
ntohs(j_port));
|
||||
dst->jabber_file_transfer_port[1] = j_port;
|
||||
}
|
||||
}
|
||||
@@ -291,16 +283,14 @@ void ndpi_search_jabber_tcp(struct ndpi_detection_module_struct *ndpi_struct, st
|
||||
}
|
||||
|
||||
if (flow->packet_counter < 3) {
|
||||
NDPI_LOG(NDPI_PROTOCOL_UNENCRYPTED_JABBER, ndpi_struct,
|
||||
NDPI_LOG_DEBUG, "packet_counter: %u\n", flow->packet_counter);
|
||||
NDPI_LOG_DBG2(ndpi_struct, "packet_counter: %u\n", flow->packet_counter);
|
||||
return;
|
||||
}
|
||||
|
||||
NDPI_LOG(NDPI_PROTOCOL_UNENCRYPTED_JABBER, ndpi_struct, NDPI_LOG_TRACE, "JABBER Excluded.\n");
|
||||
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_UNENCRYPTED_JABBER);
|
||||
NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
|
||||
|
||||
#ifdef NDPI_PROTOCOL_TRUPHONE
|
||||
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_TRUPHONE);
|
||||
ndpi_exclude_protocol(ndpi_struct, flow, NDPI_PROTOCOL_TRUPHONE,__FILE__,__FUNCTION__,__LINE__);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user