aboutsummaryrefslogtreecommitdiff
path: root/src/lib/protocols/gnutella.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/protocols/gnutella.c')
-rw-r--r--src/lib/protocols/gnutella.c86
1 files changed, 36 insertions, 50 deletions
diff --git a/src/lib/protocols/gnutella.c b/src/lib/protocols/gnutella.c
index 1ead0570b..295cfaecd 100644
--- a/src/lib/protocols/gnutella.c
+++ b/src/lib/protocols/gnutella.c
@@ -22,12 +22,14 @@
*
*/
+#include "ndpi_protocol_ids.h"
-/* include files */
+#ifdef NDPI_PROTOCOL_GNUTELLA
-#include "ndpi_protocols.h"
+#define NDPI_CURRENT_PROTO NDPI_PROTOCOL_GNUTELLA
+
+#include "ndpi_api.h"
-#ifdef NDPI_PROTOCOL_GNUTELLA
static void ndpi_int_gnutella_add_connection(struct ndpi_detection_module_struct *ndpi_struct,
struct ndpi_flow_struct *flow/* , */
@@ -38,22 +40,21 @@ static void ndpi_int_gnutella_add_connection(struct ndpi_detection_module_struct
struct ndpi_id_struct *dst = flow->dst;
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_GNUTELLA, NDPI_PROTOCOL_UNKNOWN);
+ NDPI_LOG_INFO(ndpi_struct, "found GNUTELLA\n");
if (src != NULL) {
src->gnutella_ts = packet->tick_timestamp;
if (packet->udp != NULL) {
if (!src->detected_gnutella_udp_port1) {
src->detected_gnutella_udp_port1 = (packet->udp->source);
- NDPI_LOG(NDPI_PROTOCOL_GNUTELLA, ndpi_struct,
- NDPI_LOG_DEBUG, "GNUTELLA UDP PORT1 DETECTED as %u\n",
- src->detected_gnutella_udp_port1);
+ NDPI_LOG_DBG2(ndpi_struct,
+ "GNUTELLA UDP PORT1 DETECTED as %u\n", src->detected_gnutella_udp_port1);
} else if ((ntohs(packet->udp->source) != src->detected_gnutella_udp_port1)
&& !src->detected_gnutella_udp_port2) {
src->detected_gnutella_udp_port2 = (packet->udp->source);
- NDPI_LOG(NDPI_PROTOCOL_GNUTELLA, ndpi_struct,
- NDPI_LOG_DEBUG, "GNUTELLA UDP PORT2 DETECTED as %u\n",
- src->detected_gnutella_udp_port2);
+ NDPI_LOG_DBG2(ndpi_struct,
+ "GNUTELLA UDP PORT2 DETECTED as %u\n", src->detected_gnutella_udp_port2);
}
}
@@ -71,16 +72,17 @@ void ndpi_search_gnutella(struct ndpi_detection_module_struct *ndpi_struct, stru
struct ndpi_id_struct *dst = flow->dst;
u_int16_t c;
+
+ NDPI_LOG_DBG(ndpi_struct, "search GNUTELLA\n");
+
if (packet->detected_protocol_stack[0] == NDPI_PROTOCOL_GNUTELLA) {
if (src != NULL && ((u_int32_t)
(packet->tick_timestamp - src->gnutella_ts) < ndpi_struct->gnutella_timeout)) {
- NDPI_LOG(NDPI_PROTOCOL_GNUTELLA, ndpi_struct,
- NDPI_LOG_DEBUG, "gnutella : save src connection packet detected\n");
+ NDPI_LOG_DBG2(ndpi_struct, "save src connection packet detected\n");
src->gnutella_ts = packet->tick_timestamp;
} else if (dst != NULL && ((u_int32_t)
(packet->tick_timestamp - dst->gnutella_ts) < ndpi_struct->gnutella_timeout)) {
- NDPI_LOG(NDPI_PROTOCOL_GNUTELLA, ndpi_struct,
- NDPI_LOG_DEBUG, "gnutella : save dst connection packet detected\n");
+ NDPI_LOG_DBG2(ndpi_struct, "save dst connection packet detected\n");
dst->gnutella_ts = packet->tick_timestamp;
}
if (src != NULL && (packet->tick_timestamp - src->gnutella_ts) > ndpi_struct->gnutella_timeout) {
@@ -102,13 +104,11 @@ void ndpi_search_gnutella(struct ndpi_detection_module_struct *ndpi_struct, stru
if (packet->tcp != NULL) {
/* this case works asymmetrically */
if (packet->payload_packet_len > 10 && memcmp(packet->payload, "GNUTELLA/", 9) == 0) {
- NDPI_LOG(NDPI_PROTOCOL_GNUTELLA, ndpi_struct, NDPI_LOG_TRACE, "GNUTELLA DETECTED\n");
ndpi_int_gnutella_add_connection(ndpi_struct, flow);
return;
}
/* this case works asymmetrically */
if (packet->payload_packet_len > 17 && memcmp(packet->payload, "GNUTELLA CONNECT/", 17) == 0) {
- NDPI_LOG(NDPI_PROTOCOL_GNUTELLA, ndpi_struct, NDPI_LOG_TRACE, "GNUTELLA DETECTED\n");
ndpi_int_gnutella_add_connection(ndpi_struct, flow);
return;
}
@@ -123,7 +123,6 @@ void ndpi_search_gnutella(struct ndpi_detection_module_struct *ndpi_struct, stru
|| (packet->line[c].len > 7 && memcmp(packet->line[c].ptr, "X-Queue:", 8) == 0)
|| (packet->line[c].len > 36 && memcmp(packet->line[c].ptr,
"Content-Type: application/x-gnutella-", 37) == 0)) {
- NDPI_LOG(NDPI_PROTOCOL_GNUTELLA, ndpi_struct, NDPI_LOG_DEBUG, "DETECTED GNUTELLA GET.\n");
ndpi_int_gnutella_add_connection(ndpi_struct, flow);
return;
}
@@ -135,7 +134,6 @@ void ndpi_search_gnutella(struct ndpi_detection_module_struct *ndpi_struct, stru
&& memcmp(packet->user_agent_line.ptr, "BearShare Lite ", 15) == 0)
|| (packet->accept_line.ptr != NULL && packet->accept_line.len > 24
&& memcmp(packet->accept_line.ptr, "application n/x-gnutella", 24) == 0)) {
- NDPI_LOG(NDPI_PROTOCOL_GNUTELLA, ndpi_struct, NDPI_LOG_DEBUG, "DETECTED GNUTELLA GET.\n");
ndpi_int_gnutella_add_connection(ndpi_struct, flow);
}
@@ -151,8 +149,7 @@ void ndpi_search_gnutella(struct ndpi_detection_module_struct *ndpi_struct, stru
}
if (c < (packet->payload_packet_len - 9) && memcmp(&packet->payload[c], "urn:sha1:", 9) == 0) {
- NDPI_LOG(NDPI_PROTOCOL_GNUTELLA, ndpi_struct, NDPI_LOG_TRACE,
- "detected GET /get/ or GET /uri-res/.\n");
+ NDPI_LOG_DBG2(ndpi_struct, "detected GET /get/ or GET /uri-res/\n");
ndpi_int_gnutella_add_connection(ndpi_struct, flow);
}
@@ -161,14 +158,14 @@ void ndpi_search_gnutella(struct ndpi_detection_module_struct *ndpi_struct, stru
/* answer to this packet is HTTP/1.1 ..... Content-Type: application/x-gnutella-packets,
* it is searched in the upper paragraph. */
if (packet->payload_packet_len > 30 && memcmp(packet->payload, "HEAD /gnutella/push-proxy?", 26) == 0) {
- NDPI_LOG(NDPI_PROTOCOL_GNUTELLA, ndpi_struct, NDPI_LOG_TRACE, "detected HEAD /gnutella/push-proxy?\n");
+ NDPI_LOG_DBG2(ndpi_struct, "detected HEAD /gnutella/push-proxy?\n");
ndpi_int_gnutella_add_connection(ndpi_struct, flow);
return;
}
/* haven't found any trace with this pattern */
if (packet->payload_packet_len == 46
&& memcmp(packet->payload, "\x50\x55\x53\x48\x20\x67\x75\x69\x64\x3a", 10) == 0) {
- NDPI_LOG(NDPI_PROTOCOL_GNUTELLA, ndpi_struct, NDPI_LOG_TRACE,
+ NDPI_LOG_DBG2(ndpi_struct,
"detected \x50\x55\x53\x48\x20\x67\x75\x69\x64\x3a\n");
ndpi_int_gnutella_add_connection(ndpi_struct, flow);
return;
@@ -189,8 +186,7 @@ void ndpi_search_gnutella(struct ndpi_detection_module_struct *ndpi_struct, stru
44) == 0) || (end - c > 10 && memcmp(&packet->payload[c], "\r\nX-Queue:", 10) == 0)
|| (end - c > 13 && memcmp(&packet->payload[c], "\r\nX-Features:", 13) == 0)) {
- NDPI_LOG(NDPI_PROTOCOL_GNUTELLA,
- ndpi_struct, NDPI_LOG_TRACE, "FOXY :: GNUTELLA GET 2 DETECTED\n");
+ NDPI_LOG_DBG2(ndpi_struct, "FOXY :: GNUTELLA GET 2 DETECTED\n");
ndpi_int_gnutella_add_connection(ndpi_struct, flow);
return;
}
@@ -202,7 +198,7 @@ void ndpi_search_gnutella(struct ndpi_detection_module_struct *ndpi_struct, stru
if (packet->payload_packet_len > 1 && packet->payload[packet->payload_packet_len - 1] == 0x0a
&& packet->payload[packet->payload_packet_len - 2] == 0x0a) {
if (packet->payload_packet_len > 3 && memcmp(packet->payload, "GIV", 3) == 0) {
- NDPI_LOG(NDPI_PROTOCOL_GNUTELLA, ndpi_struct, NDPI_LOG_TRACE, "MORPHEUS GIV DETECTED\n");
+ NDPI_LOG_DBG2(ndpi_struct, "MORPHEUS GIV DETECTED\n");
/* Not Excluding the flow now.. We shall Check the next Packet too for Gnutella Patterns */
return;
}
@@ -211,21 +207,21 @@ void ndpi_search_gnutella(struct ndpi_detection_module_struct *ndpi_struct, stru
if (packet->payload_packet_len == 46 && get_u_int32_t(packet->payload, 0) == htonl(0x802c0103) &&
get_u_int32_t(packet->payload, 4) == htonl(0x01000300) && get_u_int32_t(packet->payload, 8) == htonl(0x00002000) &&
get_u_int16_t(packet->payload, 12) == htons(0x0034)) {
- NDPI_LOG(NDPI_PROTOCOL_GNUTELLA, ndpi_struct, NDPI_LOG_TRACE, "detected gnutella len == 46.\n");
+ NDPI_LOG_DBG2(ndpi_struct, "detected gnutella len == 46\n");
ndpi_int_gnutella_add_connection(ndpi_struct, flow);
return;
}
if (packet->payload_packet_len == 49 &&
memcmp(packet->payload, "\x80\x2f\x01\x03\x01\x00\x06\x00\x00\x00\x20\x00\x00\x34\x00\x00\xff\x4d\x6c",
19) == 0) {
- NDPI_LOG(NDPI_PROTOCOL_GNUTELLA, ndpi_struct, NDPI_LOG_TRACE, "detected gnutella len == 49.\n");
+ NDPI_LOG_DBG2(ndpi_struct, "detected gnutella len == 49\n");
ndpi_int_gnutella_add_connection(ndpi_struct, flow);
return;
}
if (packet->payload_packet_len == 89 && memcmp(&packet->payload[43], "\x20\x4d\x6c", 3) == 0 &&
memcmp(packet->payload, "\x16\x03\x01\x00\x54\x01\x00\x00\x50\x03\x01\x4d\x6c", 13) == 0 &&
memcmp(&packet->payload[76], "\x00\x02\x00\x34\x01\x00\x00\x05", 8) == 0) {
- NDPI_LOG(NDPI_PROTOCOL_GNUTELLA, ndpi_struct, NDPI_LOG_TRACE,
+ NDPI_LOG_DBG2(ndpi_struct,
"detected gnutella asymmetrically len == 388.\n");
ndpi_int_gnutella_add_connection(ndpi_struct, flow);
return;
@@ -235,7 +231,7 @@ void ndpi_search_gnutella(struct ndpi_detection_module_struct *ndpi_struct, stru
&& get_u_int16_t(packet->payload, 8) == htons(0x4903)
&& get_u_int16_t(packet->payload, 76) == htons(0x0002)
&& get_u_int32_t(packet->payload, 78) == htonl(0x00340100)) {
- NDPI_LOG(NDPI_PROTOCOL_GNUTELLA, ndpi_struct, NDPI_LOG_TRACE, "detected len == 82.\n");
+ NDPI_LOG_DBG2(ndpi_struct, "detected len == 82\n");
ndpi_int_gnutella_add_connection(ndpi_struct, flow);
return;
}
@@ -244,7 +240,7 @@ void ndpi_search_gnutella(struct ndpi_detection_module_struct *ndpi_struct, stru
if (src != NULL && (packet->udp->source == src->detected_gnutella_udp_port1 ||
packet->udp->source == src->detected_gnutella_udp_port2) &&
(packet->tick_timestamp - src->gnutella_ts) < ndpi_struct->gnutella_timeout) {
- NDPI_LOG(NDPI_PROTOCOL_GNUTELLA, ndpi_struct, NDPI_LOG_DEBUG, "port based detection\n\n");
+ NDPI_LOG_DBG2(ndpi_struct, "port based detection\n\n");
ndpi_int_gnutella_add_connection(ndpi_struct, flow);
}
/* observations:
@@ -257,8 +253,7 @@ void ndpi_search_gnutella(struct ndpi_detection_module_struct *ndpi_struct, stru
&& packet->payload[16] == 0x41 && packet->payload[17] == 0x01
&& packet->payload[18] == 0x00 && packet->payload[19] == 0x00
&& packet->payload[20] == 0x00 && packet->payload[21] == 0x00 && packet->payload[22] == 0x00) {
- NDPI_LOG(NDPI_PROTOCOL_GNUTELLA, ndpi_struct, NDPI_LOG_DEBUG,
- "detected gnutella udp, len = 23.\n");
+ NDPI_LOG_DBG2(ndpi_struct, "detected gnutella udp, len = 23\n");
ndpi_int_gnutella_add_connection(ndpi_struct, flow);
return;
@@ -267,29 +262,25 @@ void ndpi_search_gnutella(struct ndpi_detection_module_struct *ndpi_struct, stru
&& packet->payload[26] == 0x50 && packet->payload[27] == 0x40
&& packet->payload[28] == 0x83 && packet->payload[29] == 0x53
&& packet->payload[30] == 0x43 && packet->payload[31] == 0x50 && packet->payload[32] == 0x41) {
- NDPI_LOG(NDPI_PROTOCOL_GNUTELLA, ndpi_struct, NDPI_LOG_DEBUG,
- "detected gnutella udp, len = 35.\n");
+ NDPI_LOG_DBG2(ndpi_struct, "detected gnutella udp, len = 35\n");
ndpi_int_gnutella_add_connection(ndpi_struct, flow);
return;
}
if (packet->payload_packet_len == 32
&& (memcmp(&packet->payload[16], "\x31\x01\x00\x09\x00\x00\x00\x4c\x49\x4d\x45", 11) == 0)) {
- NDPI_LOG(NDPI_PROTOCOL_GNUTELLA, ndpi_struct, NDPI_LOG_DEBUG,
- "detected gnutella udp, len = 32.\n");
+ NDPI_LOG_DBG2(ndpi_struct, "detected gnutella udp, len = 32\n");
ndpi_int_gnutella_add_connection(ndpi_struct, flow);
return;
}
if (packet->payload_packet_len == 34 && (memcmp(&packet->payload[25], "SCP@", 4) == 0)
&& (memcmp(&packet->payload[30], "DNA@", 4) == 0)) {
- NDPI_LOG(NDPI_PROTOCOL_GNUTELLA, ndpi_struct, NDPI_LOG_DEBUG,
- "detected gnutella udp, len = 34.\n");
+ NDPI_LOG_DBG2(ndpi_struct, "detected gnutella udp, len = 34\n");
ndpi_int_gnutella_add_connection(ndpi_struct, flow);
return;
}
if ((packet->payload_packet_len == 73 || packet->payload_packet_len == 96)
&& memcmp(&packet->payload[32], "urn:sha1:", 9) == 0) {
- NDPI_LOG(NDPI_PROTOCOL_GNUTELLA, ndpi_struct, NDPI_LOG_DEBUG,
- "detected gnutella udp, len = 73,96.\n");
+ NDPI_LOG_DBG2(ndpi_struct, "detected gnutella udp, len = 73,96\n");
ndpi_int_gnutella_add_connection(ndpi_struct, flow);
return;
}
@@ -308,8 +299,7 @@ void ndpi_search_gnutella(struct ndpi_detection_module_struct *ndpi_struct, stru
&& (memcmp(&packet->payload[6], "\x01\x01\x5c\x1b\x50\x55\x53\x48\x48\x10", 10) == 0))
|| (packet->payload_packet_len > 200 && packet->payload_packet_len < 300 && packet->payload[3] == 0x03)
|| (packet->payload_packet_len > 300 && (packet->payload[3] == 0x01 || packet->payload[3] == 0x03))) {
- NDPI_LOG(NDPI_PROTOCOL_GNUTELLA, ndpi_struct, NDPI_LOG_DEBUG,
- "detected gnutella udp, GND.\n");
+ NDPI_LOG_DBG2(ndpi_struct, "detected gnutella udp, GND\n");
ndpi_int_gnutella_add_connection(ndpi_struct, flow);
return;
}
@@ -317,15 +307,13 @@ void ndpi_search_gnutella(struct ndpi_detection_module_struct *ndpi_struct, stru
if ((packet->payload_packet_len == 32)
&& memcmp(&packet->payload[16], "\x31\x01\x00\x09\x00\x00\x00", 7) == 0) {
- NDPI_LOG(NDPI_PROTOCOL_GNUTELLA, ndpi_struct, NDPI_LOG_DEBUG,
- "detected gnutella udp, len = 32 ii.\n");
+ NDPI_LOG_DBG2(ndpi_struct, "detected gnutella udp, len = 32 ii\n");
ndpi_int_gnutella_add_connection(ndpi_struct, flow);
return;
}
if ((packet->payload_packet_len == 23)
&& memcmp(&packet->payload[16], "\x00\x01\x00\x00\x00\x00\x00", 7) == 0) {
- NDPI_LOG(NDPI_PROTOCOL_GNUTELLA, ndpi_struct, NDPI_LOG_DEBUG,
- "detected gnutella udp, len = 23 ii.\n");
+ NDPI_LOG_DBG2(ndpi_struct, "detected gnutella udp, len = 23 ii\n");
ndpi_int_gnutella_add_connection(ndpi_struct, flow);
return;
}
@@ -350,8 +338,7 @@ void ndpi_search_gnutella(struct ndpi_detection_module_struct *ndpi_struct, stru
&& flow->l4.tcp.gnutella_msg_id[1] == packet->payload[2]
&& flow->l4.tcp.gnutella_msg_id[2] == packet->payload[4]
&& NDPI_SRC_OR_DST_HAS_PROTOCOL(src, dst, NDPI_PROTOCOL_GNUTELLA)) {
- NDPI_LOG(NDPI_PROTOCOL_GNUTELLA, ndpi_struct,
- NDPI_LOG_TRACE, "GNUTELLA DETECTED due to message ID match (NEONet protocol)\n");
+ NDPI_LOG_DBG2(ndpi_struct, "GNUTELLA DETECTED due to message ID match (NEONet protocol)\n");
ndpi_int_gnutella_add_connection(ndpi_struct, flow);
return;
}
@@ -361,15 +348,14 @@ void ndpi_search_gnutella(struct ndpi_detection_module_struct *ndpi_struct, stru
&& flow->l4.tcp.gnutella_msg_id[1] == packet->payload[2]
&& flow->l4.tcp.gnutella_msg_id[2] == packet->payload[4]
&& NDPI_SRC_OR_DST_HAS_PROTOCOL(src, dst, NDPI_PROTOCOL_GNUTELLA)) {
- NDPI_LOG(NDPI_PROTOCOL_GNUTELLA, ndpi_struct,
- NDPI_LOG_TRACE, "GNUTELLA DETECTED due to message ID match (NEONet protocol)\n");
+ NDPI_LOG_DBG2(ndpi_struct, "GNUTELLA DETECTED due to message ID match (NEONet protocol)\n");
ndpi_int_gnutella_add_connection(ndpi_struct, flow);
return;
}
}
}
- NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_GNUTELLA);
+ NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
}