aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLuca Deri <lucaderi@users.noreply.github.com>2020-07-07 14:43:32 +0200
committerGitHub <noreply@github.com>2020-07-07 14:43:32 +0200
commitdb707e0829d29f7aed6d2a5848706600ca8ff971 (patch)
tree18028e1c8eba670d61304ae13a49835bc48ce139 /src
parent540326f3ffcc3126a1db3811464046ac7e061157 (diff)
parent030f3f3d48184133a6647108c156787fb3f39b58 (diff)
Merge pull request #932 from IvanNardi/log
Log
Diffstat (limited to 'src')
-rw-r--r--src/include/ndpi_api.h.in1
-rw-r--r--src/include/ndpi_define.h.in4
-rw-r--r--src/lib/ndpi_main.c18
-rw-r--r--src/lib/protocols/dnp3.c3
-rw-r--r--src/lib/protocols/http.c14
-rw-r--r--src/lib/protocols/iec60870-5-104.c3
-rw-r--r--src/lib/protocols/mining.c2
-rw-r--r--src/lib/protocols/modbus.c3
-rw-r--r--src/lib/protocols/mqtt.c6
-rw-r--r--src/lib/protocols/nats.c3
-rw-r--r--src/lib/protocols/s7comm.c2
-rw-r--r--src/lib/protocols/smb.c2
12 files changed, 42 insertions, 19 deletions
diff --git a/src/include/ndpi_api.h.in b/src/include/ndpi_api.h.in
index ed94c5bf3..865ddc8dd 100644
--- a/src/include/ndpi_api.h.in
+++ b/src/include/ndpi_api.h.in
@@ -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_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);
/* LRU cache */
struct ndpi_lru_cache* ndpi_lru_cache_init(u_int32_t num_entries);
diff --git a/src/include/ndpi_define.h.in b/src/include/ndpi_define.h.in
index 13989a60e..5add2e1c8 100644
--- a/src/include/ndpi_define.h.in
+++ b/src/include/ndpi_define.h.in
@@ -179,6 +179,8 @@
#define NDPI_JABBER_FT_TIMEOUT 5
#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
#define NDPI_LOG(proto, m, log_level, args...) \
{ \
@@ -196,7 +198,7 @@
*/
#ifndef NDPI_CURRENT_PROTO
- #define NDPI_CURRENT_PROTO NDPI_PROTO_UNKNOWN
+ #define NDPI_CURRENT_PROTO NDPI_PROTOCOL_UNKNOWN
#endif
#define NDPI_LOG_ERR(mod, args...) \
diff --git a/src/lib/ndpi_main.c b/src/lib/ndpi_main.c
index 7715f0460..199c34a5b 100644
--- a/src/lib/ndpi_main.c
+++ b/src/lib/ndpi_main.c
@@ -1953,9 +1953,10 @@ struct ndpi_detection_module_struct *ndpi_init_detection_module(ndpi_init_prefs
int i;
if(ndpi_str == NULL) {
-#ifdef NDPI_ENABLE_DEBUG_MESSAGES
- NDPI_LOG_ERR(ndpi_str, "ndpi_init_detection_module initial malloc failed for ndpi_str\n");
-#endif /* NDPI_ENABLE_DEBUG_MESSAGES */
+ /* Logging this error is a bit tricky. At this point, we can't use NDPI_LOG*
+ functions yet, we don't have a custom log function and, as a library,
+ we shouldn't use stdout/stderr. Since this error is quite unlikely,
+ simply avoid any logs at all */
return(NULL);
}
@@ -1963,6 +1964,7 @@ struct ndpi_detection_module_struct *ndpi_init_detection_module(ndpi_init_prefs
#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_New_Patricia(32 /* IPv4 */)) != NULL)
@@ -2008,8 +2010,10 @@ struct ndpi_detection_module_struct *ndpi_init_detection_module(ndpi_init_prefs
ndpi_str->custom_categories.ipAddresses = ndpi_New_Patricia(32 /* IPv4 */);
ndpi_str->custom_categories.ipAddresses_shadow = ndpi_New_Patricia(32 /* IPv4 */);
- if((ndpi_str->custom_categories.ipAddresses == NULL) || (ndpi_str->custom_categories.ipAddresses_shadow == NULL))
+ if((ndpi_str->custom_categories.ipAddresses == NULL) || (ndpi_str->custom_categories.ipAddresses_shadow == NULL)) {
+ NDPI_LOG_ERR(ndpi_str, "[NDPI] Error allocating Patricia trees\n");
return(NULL);
+ }
ndpi_init_protocol_defaults(ndpi_str);
@@ -6286,6 +6290,12 @@ 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
+ ndpi_str->debug_bitmask = debug_bitmask;
+#endif
+}
+
void ndpi_set_log_level(struct ndpi_detection_module_struct *ndpi_str, u_int l){
ndpi_str->ndpi_log_level = l;
}
diff --git a/src/lib/protocols/dnp3.c b/src/lib/protocols/dnp3.c
index 7d0c17f70..805f8f335 100644
--- a/src/lib/protocols/dnp3.c
+++ b/src/lib/protocols/dnp3.c
@@ -6,9 +6,8 @@
*/
#include "ndpi_protocol_ids.h"
-#include "ndpi_api.h"
-
#define NDPI_CURRENT_PROTO NDPI_PROTOCOL_DNP3
+#include "ndpi_api.h"
void ndpi_search_dnp3_tcp(struct ndpi_detection_module_struct *ndpi_struct,
struct ndpi_flow_struct *flow) {
diff --git a/src/lib/protocols/http.c b/src/lib/protocols/http.c
index 9ac26785c..8f74d22ad 100644
--- a/src/lib/protocols/http.c
+++ b/src/lib/protocols/http.c
@@ -558,6 +558,14 @@ static void check_http_payload(struct ndpi_detection_module_struct *ndpi_struct,
/* ************************************************************* */
+#ifdef NDPI_ENABLE_DEBUG_MESSAGES
+static uint8_t non_ctrl(uint8_t c) {
+ return c < 32 ? '.':c;
+}
+#endif
+
+/* ************************************************************* */
+
/**
* Functions to check whether the packet begins with a valid http request
* @param ndpi_struct
@@ -589,8 +597,10 @@ static u_int16_t http_request_url_offset(struct ndpi_detection_module_struct *nd
int i;
NDPI_LOG_DBG2(ndpi_struct, "====>>>> HTTP: %c%c%c%c [len: %u]\n",
- non_ctrl(packet->payload[0]), non_ctrl(packet->payload[1]),
- non_ctrl(packet->payload[2]), non_ctrl(packet->payload[3]),
+ packet->payload_packet_len > 0 ? non_ctrl(packet->payload[0]) : '.',
+ packet->payload_packet_len > 1 ? non_ctrl(packet->payload[1]) : '.',
+ packet->payload_packet_len > 2 ? non_ctrl(packet->payload[2]) : '.',
+ packet->payload_packet_len > 3 ? non_ctrl(packet->payload[3]) : '.',
packet->payload_packet_len);
/* Check first char */
diff --git a/src/lib/protocols/iec60870-5-104.c b/src/lib/protocols/iec60870-5-104.c
index 040a1842a..e5e5325bf 100644
--- a/src/lib/protocols/iec60870-5-104.c
+++ b/src/lib/protocols/iec60870-5-104.c
@@ -25,9 +25,8 @@
*/
#include "ndpi_protocol_ids.h"
-#include "ndpi_api.h"
-
#define NDPI_CURRENT_PROTO NDPI_PROTOCOL_IEC60870
+#include "ndpi_api.h"
void ndpi_search_iec60870_tcp(struct ndpi_detection_module_struct *ndpi_struct,
struct ndpi_flow_struct *flow) {
diff --git a/src/lib/protocols/mining.c b/src/lib/protocols/mining.c
index 78ed9ff29..1f86987fb 100644
--- a/src/lib/protocols/mining.c
+++ b/src/lib/protocols/mining.c
@@ -21,7 +21,7 @@
*
*/
#include "ndpi_protocol_ids.h"
-
+#define NDPI_CURRENT_PROTO NDPI_PROTOCOL_MINING
#include "ndpi_api.h"
/* ************************************************************************** */
diff --git a/src/lib/protocols/modbus.c b/src/lib/protocols/modbus.c
index 2a6dd2a49..c98c71298 100644
--- a/src/lib/protocols/modbus.c
+++ b/src/lib/protocols/modbus.c
@@ -24,9 +24,8 @@
#include "ndpi_protocol_ids.h"
-#include "ndpi_api.h"
-
#define NDPI_CURRENT_PROTO NDPI_PROTOCOL_MODBUS
+#include "ndpi_api.h"
void ndpi_search_modbus_tcp(struct ndpi_detection_module_struct *ndpi_struct,
struct ndpi_flow_struct *flow) {
diff --git a/src/lib/protocols/mqtt.c b/src/lib/protocols/mqtt.c
index 45669c03a..bf8538604 100644
--- a/src/lib/protocols/mqtt.c
+++ b/src/lib/protocols/mqtt.c
@@ -79,7 +79,11 @@ void ndpi_search_mqtt (struct ndpi_detection_module_struct *ndpi_struct,
}
NDPI_LOG_DBG2(ndpi_struct, "====>>>> Mqtt header: %4x%4x%4x%4x [len: %u]\n",
- packet->payload[0], packet->payload[1], packet->payload[2], packet->payload[3], packet->payload_packet_len);
+ packet->payload_packet_len > 0 ? packet->payload[0] : '.',
+ 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);
if (packet->payload_packet_len < 2) {
NDPI_LOG_DBG(ndpi_struct, "Excluding Mqtt .. mandatory header not found!\n");
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_MQTT);
diff --git a/src/lib/protocols/nats.c b/src/lib/protocols/nats.c
index 300cc838d..da99a36de 100644
--- a/src/lib/protocols/nats.c
+++ b/src/lib/protocols/nats.c
@@ -20,9 +20,8 @@
*/
#include "ndpi_protocol_ids.h"
-#include "ndpi_api.h"
-
#define NDPI_CURRENT_PROTO NDPI_PROTOCOL_NATS
+#include "ndpi_api.h"
static const char* commands[] =
{
diff --git a/src/lib/protocols/s7comm.c b/src/lib/protocols/s7comm.c
index 7d2b92642..ec32c106e 100644
--- a/src/lib/protocols/s7comm.c
+++ b/src/lib/protocols/s7comm.c
@@ -21,8 +21,8 @@
*
*/
#include "ndpi_protocol_ids.h"
-#include "ndpi_api.h"
#define NDPI_CURRENT_PROTO NDPI_PROTOCOL_S7COMM
+#include "ndpi_api.h"
void ndpi_search_s7comm_tcp(struct ndpi_detection_module_struct *ndpi_struct,
struct ndpi_flow_struct *flow) {
diff --git a/src/lib/protocols/smb.c b/src/lib/protocols/smb.c
index b50f59346..a70072853 100644
--- a/src/lib/protocols/smb.c
+++ b/src/lib/protocols/smb.c
@@ -21,7 +21,7 @@
*
*/
#include "ndpi_protocol_ids.h"
-
+#define NDPI_CURRENT_PROTO NDPI_PROTOCOL_SMBV23
#include "ndpi_api.h"