added new fb detection - remove old bittorrent functions - fix rx warning

This commit is contained in:
Campus
2016-05-24 23:28:43 +02:00
parent b05907f592
commit f8ecdc004f
6 changed files with 95 additions and 100 deletions
-4
View File
@@ -52,10 +52,6 @@ void ndpi_search_tcp_or_udp(struct ndpi_detection_module_struct *ndpi_struct, st
/* Applications and other protocols. */ /* Applications and other protocols. */
void ndpi_search_bittorrent(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow); void ndpi_search_bittorrent(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_bittorrent_init(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t size,u_int32_t timeout);
void ndpi_bittorrent_done(struct ndpi_detection_module_struct *ndpi_struct);
int ndpi_bittorrent_gc(struct hash_ip4p_table *ht,int key,time_t now);
void ndpi_search_edonkey(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow); void ndpi_search_edonkey(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_fasttrack_tcp(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow); void ndpi_search_fasttrack_tcp(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_gnutella(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow); void ndpi_search_gnutella(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
+2 -1
View File
@@ -7277,7 +7277,8 @@ ndpi_protocol_match host_match[] = {
{ ".facebook.com", "Facebook", NDPI_SERVICE_FACEBOOK, NDPI_PROTOCOL_FUN }, { ".facebook.com", "Facebook", NDPI_SERVICE_FACEBOOK, NDPI_PROTOCOL_FUN },
{ "fbstatic-a.akamaihd.net", "Facebook", NDPI_SERVICE_FACEBOOK, NDPI_PROTOCOL_FUN }, { "fbstatic-a.akamaihd.net", "Facebook", NDPI_SERVICE_FACEBOOK, NDPI_PROTOCOL_FUN },
{ ".fbcdn.net", "Facebook", NDPI_SERVICE_FACEBOOK, NDPI_PROTOCOL_FUN }, { ".fbcdn.net", "Facebook", NDPI_SERVICE_FACEBOOK, NDPI_PROTOCOL_FUN },
{ "fbcdn-", "Facebook", NDPI_SERVICE_FACEBOOK, NDPI_PROTOCOL_FUN }, /* fbcdn-video-a-akamaihd.net */ { "fbcdn-", "Facebook", NDPI_SERVICE_FACEBOOK, NDPI_PROTOCOL_FUN }, /* fbcdn-video-a-akamaihd.net */
{ ".facebook.net", "Facebook", NDPI_SERVICE_FACEBOOK, NDPI_PROTOCOL_FUN },
{ ".google.", "Google", NDPI_SERVICE_GOOGLE, NDPI_PROTOCOL_ACCEPTABLE }, { ".google.", "Google", NDPI_SERVICE_GOOGLE, NDPI_PROTOCOL_ACCEPTABLE },
{ ".gstatic.com", "Google", NDPI_SERVICE_GOOGLE, NDPI_PROTOCOL_ACCEPTABLE }, { ".gstatic.com", "Google", NDPI_SERVICE_GOOGLE, NDPI_PROTOCOL_ACCEPTABLE },
{ ".googlesyndication.com", "Google", NDPI_SERVICE_GOOGLE, NDPI_PROTOCOL_ACCEPTABLE }, { ".googlesyndication.com", "Google", NDPI_SERVICE_GOOGLE, NDPI_PROTOCOL_ACCEPTABLE },
+8 -8
View File
@@ -1523,18 +1523,18 @@ static void ndpi_init_protocol_defaults(struct ndpi_detection_module_struct *ndp
ndpi_build_default_ports(ports_a, 0, 0, 0, 0, 0), /* TCP */ ndpi_build_default_ports(ports_a, 0, 0, 0, 0, 0), /* TCP */
ndpi_build_default_ports(ports_b, 5683, 5684, 0, 0, 0)); /* UDP */ ndpi_build_default_ports(ports_b, 5683, 5684, 0, 0, 0)); /* UDP */
ndpi_set_proto_defaults(ndpi_mod,NDPI_PROTOCOL_ACCEPTABLE,NDPI_PROTOCOL_MQTT, ndpi_set_proto_defaults(ndpi_mod,NDPI_PROTOCOL_ACCEPTABLE,NDPI_PROTOCOL_MQTT,
no_master, no_master,
no_master, "MQTT", no_master, "MQTT",
ndpi_build_default_ports(ports_a, 1883, 8883, 0, 0, 0), /* TCP */ ndpi_build_default_ports(ports_a, 1883, 8883, 0, 0, 0), /* TCP */
ndpi_build_default_ports(ports_b, 0, 0, 0, 0, 0)); /* UDP */ ndpi_build_default_ports(ports_b, 0, 0, 0, 0, 0)); /* UDP */
ndpi_build_default_ports(ports_b, 0, 0, 0, 0, 0); ndpi_build_default_ports(ports_b, 0, 0, 0, 0, 0);
ports_b[0].port_low = 7000; ports_b[0].port_low = 7000;
ports_b[0].port_high = 7032; /* See https://www-01.ibm.com/support/docview.wss?uid=swg21044407 */ ports_b[0].port_high = 7032; /* See https://www-01.ibm.com/support/docview.wss?uid=swg21044407 */
ndpi_set_proto_defaults(ndpi_mod,NDPI_PROTOCOL_ACCEPTABLE,NDPI_PROTOCOL_RX, ndpi_set_proto_defaults(ndpi_mod,NDPI_PROTOCOL_ACCEPTABLE,NDPI_PROTOCOL_RX,
no_master, no_master,
no_master, "RX", no_master, "RX",
ndpi_build_default_ports(ports_a, 0, 0, 0, 0, 0), /* TCP */ ndpi_build_default_ports(ports_a, 0, 0, 0, 0, 0), /* TCP */
ports_b); /* UDP */ ports_b); /* UDP */
/* calling function for host and content matched protocols */ /* calling function for host and content matched protocols */
init_string_based_protocols(ndpi_mod); init_string_based_protocols(ndpi_mod);
-1
View File
@@ -18,7 +18,6 @@
* *
*/ */
#include "ndpi_api.h" #include "ndpi_api.h"
#ifdef NDPI_PROTOCOL_GTP #ifdef NDPI_PROTOCOL_GTP
+26 -36
View File
@@ -22,54 +22,44 @@
* *
*/ */
#include "ndpi_protocols.h" #include "ndpi_protocols.h"
#ifdef NDPI_PROTOCOL_NTP #ifdef NDPI_PROTOCOL_NTP
static void ndpi_int_ntp_add_connection(struct ndpi_detection_module_struct static void ndpi_int_ntp_add_connection(struct ndpi_detection_module_struct
*ndpi_struct, struct ndpi_flow_struct *flow) *ndpi_struct, struct ndpi_flow_struct *flow)
{ {
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_NTP, NDPI_PROTOCOL_UNKNOWN); ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_NTP, NDPI_PROTOCOL_UNKNOWN);
} }
/* detection also works asymmetrically */
void ndpi_search_ntp_udp(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow) void ndpi_search_ntp_udp(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow)
{ {
struct ndpi_packet_struct *packet = &flow->packet; struct ndpi_packet_struct *packet = &flow->packet;
// struct ndpi_id_struct *src=ndpi_struct->src; if (!(packet->udp->dest == htons(123) || packet->udp->source == htons(123)))
// struct ndpi_id_struct *dst=ndpi_struct->dst; goto exclude_ntp;
if (!(packet->udp->dest == htons(123) || packet->udp->source == htons(123))) NDPI_LOG(NDPI_PROTOCOL_NTP, ndpi_struct, NDPI_LOG_DEBUG, "NTP port detected\n");
goto exclude_ntp;
NDPI_LOG(NDPI_PROTOCOL_NTP, ndpi_struct, NDPI_LOG_DEBUG, "NTP length detected\n");
NDPI_LOG(NDPI_PROTOCOL_NTP, ndpi_struct, NDPI_LOG_DEBUG, "NTP port detected\n");
// It's not correct because packets could be bigger if ((((packet->payload[0] & 0x38) >> 3) <= 4)) {
//if (packet->payload_packet_len != 48) NDPI_LOG(NDPI_PROTOCOL_NTP, ndpi_struct, NDPI_LOG_DEBUG, "detected NTP.");
// goto exclude_ntp;
NDPI_LOG(NDPI_PROTOCOL_NTP, ndpi_struct, NDPI_LOG_DEBUG, "NTP length detected\n");
if ((((packet->payload[0] & 0x38) >> 3) <= 4)) {
NDPI_LOG(NDPI_PROTOCOL_NTP, ndpi_struct, NDPI_LOG_DEBUG, "detected NTP.");
// 38 in binary representation is 00111000 // 38 in binary representation is 00111000
flow->protos.ntp.version = (packet->payload[0] & 0x38) >> 3; flow->protos.ntp.version = (packet->payload[0] & 0x38) >> 3;
if (flow->protos.ntp.version == 2) { if (flow->protos.ntp.version == 2) {
flow->protos.ntp.request_code = packet->payload[3]; flow->protos.ntp.request_code = packet->payload[3];
} }
ndpi_int_ntp_add_connection(ndpi_struct, flow); ndpi_int_ntp_add_connection(ndpi_struct, flow);
return; return;
} }
exclude_ntp:
exclude_ntp:
NDPI_LOG(NDPI_PROTOCOL_NTP, ndpi_struct, NDPI_LOG_DEBUG, "NTP excluded.\n"); NDPI_LOG(NDPI_PROTOCOL_NTP, ndpi_struct, NDPI_LOG_DEBUG, "NTP excluded.\n");
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_NTP); NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_NTP);
} }
+59 -50
View File
@@ -106,6 +106,7 @@ void ndpi_check_rx(struct ndpi_detection_module_struct *ndpi_struct,
* Check the TYPE and FLAGS fields of an RX packet header. * Check the TYPE and FLAGS fields of an RX packet header.
* This check is necessary because we could detect an RX session already begun * This check is necessary because we could detect an RX session already begun
**/ **/
/* TYPE field */ /* TYPE field */
if((header->type < DATA) && (header->type > VERSION)) { if((header->type < DATA) && (header->type > VERSION)) {
NDPI_LOG(NDPI_PROTOCOL_RX, ndpi_struct, NDPI_LOG_DEBUG, "excluding RX\n"); NDPI_LOG(NDPI_PROTOCOL_RX, ndpi_struct, NDPI_LOG_DEBUG, "excluding RX\n");
@@ -119,50 +120,59 @@ void ndpi_check_rx(struct ndpi_detection_module_struct *ndpi_struct,
header->flags == PLUS_2 || header->flags == REQ_ACK || header->flags == PLUS_2 || header->flags == REQ_ACK ||
header->flags == MORE_1 || header->flags == CLIENT_INIT_1 || header->flags == MORE_1 || header->flags == CLIENT_INIT_1 ||
header->flags == CLIENT_INIT_2) { header->flags == CLIENT_INIT_2) {
/* TYPE and FLAGS combo */ /* TYPE and FLAGS combo */
if(header->type == DATA) { switch(header->type)
if(header->flags == LAST_PKT || header->flags == EMPTY || {
header->flags == PLUS_0 || header->flags == PLUS_1 || case DATA:
header->flags == PLUS_2 || header->flags == REQ_ACK || if(header->flags == LAST_PKT || header->flags == EMPTY ||
header->flags == MORE_1) header->flags == PLUS_0 || header->flags == PLUS_1 ||
found = 1; header->flags == PLUS_2 || header->flags == REQ_ACK ||
} header->flags == MORE_1)
else if(header->type == ACK) { goto security;
if(header->flags == CLIENT_INIT_1 || header->flags == CLIENT_INIT_2 || case ACK:
header->flags == EMPTY) if(header->flags == CLIENT_INIT_1 || header->flags == CLIENT_INIT_2 ||
found = 1; header->flags == EMPTY)
goto security;
} case CHALLENGE:
else if(header->type == CHALLENGE || header->type == RESPONSE) { if(header->flags == EMPTY || header->call_number == 0)
if(header->flags == EMPTY || header->call_number == 0) goto security;
found = 1; case RESPONSE:
if(header->flags == EMPTY || header->call_number == 0)
} goto security;
else if(header->type == ACKALL) { case ACKALL:
if(header->flags == EMPTY) if(header->flags == EMPTY)
found = 1; goto security;
} case BUSY:
else if(header->type == BUSY || header->type == ABORT || goto security;
header->type == DEBUG || header->type == PARAM_1 || case ABORT:
header->type == PARAM_2 || header->type == PARAM_3 || goto security;
header->type == VERSION) case DEBUG:
found = 1; goto security;
else { case PARAM_1:
NDPI_LOG(NDPI_PROTOCOL_RX, ndpi_struct, NDPI_LOG_DEBUG, "excluding RX\n"); goto security;
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_RX); case PARAM_2:
return; goto security;
} case PARAM_3:
} goto security;
else { case VERSION:
goto security;
default:
NDPI_LOG(NDPI_PROTOCOL_RX, ndpi_struct, NDPI_LOG_DEBUG, "excluding RX\n");
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_RX);
return;
} // switch
} else { // FLAG
NDPI_LOG(NDPI_PROTOCOL_RX, ndpi_struct, NDPI_LOG_DEBUG, "excluding RX\n"); NDPI_LOG(NDPI_PROTOCOL_RX, ndpi_struct, NDPI_LOG_DEBUG, "excluding RX\n");
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_RX); NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_RX);
return; return;
} }
security:
/* SECURITY field */ /* SECURITY field */
if(header->security != 0 && header->security != 1 && if(header->security != 0 && header->security != 1 &&
header->security != 2 && header->security != 3) { header->security != 2 && header->security != 3)
{
NDPI_LOG(NDPI_PROTOCOL_RX, ndpi_struct, NDPI_LOG_DEBUG, "excluding RX\n"); NDPI_LOG(NDPI_PROTOCOL_RX, ndpi_struct, NDPI_LOG_DEBUG, "excluding RX\n");
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_RX); NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_RX);
return; return;
@@ -171,12 +181,17 @@ void ndpi_check_rx(struct ndpi_detection_module_struct *ndpi_struct,
/* If we have already seen one packet in the other direction, then /* If we have already seen one packet in the other direction, then
the two must have matching connection numbers. Otherwise store the two must have matching connection numbers. Otherwise store
them. */ them. */
if (flow->packet_direction_counter[!packet->packet_direction] != 0) { if(flow->packet_direction_counter[!packet->packet_direction] != 0)
{
if (flow->l4.udp.rx_conn_epoch == header->conn_epoch && if (flow->l4.udp.rx_conn_epoch == header->conn_epoch &&
flow->l4.udp.rx_conn_id == header->conn_id) flow->l4.udp.rx_conn_id == header->conn_id)
found = 1; {
NDPI_LOG(NDPI_PROTOCOL_RX, ndpi_struct, NDPI_LOG_DEBUG, "found RX\n");
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_RX, NDPI_PROTOCOL_UNKNOWN);
}
/* https://www.central.org/frameless/numbers/rxservice.html. */ /* https://www.central.org/frameless/numbers/rxservice.html. */
else { else
{
NDPI_LOG(NDPI_PROTOCOL_RX, ndpi_struct, NDPI_LOG_DEBUG, "excluding RX\n"); NDPI_LOG(NDPI_PROTOCOL_RX, ndpi_struct, NDPI_LOG_DEBUG, "excluding RX\n");
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_RX); NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_RX);
return; return;
@@ -184,16 +199,10 @@ void ndpi_check_rx(struct ndpi_detection_module_struct *ndpi_struct,
} else { } else {
flow->l4.udp.rx_conn_epoch = header->conn_epoch; flow->l4.udp.rx_conn_epoch = header->conn_epoch;
flow->l4.udp.rx_conn_id = header->conn_id; flow->l4.udp.rx_conn_id = header->conn_id;
found = 1; {
} NDPI_LOG(NDPI_PROTOCOL_RX, ndpi_struct, NDPI_LOG_DEBUG, "found RX\n");
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_RX, NDPI_PROTOCOL_UNKNOWN);
if(found) { }
NDPI_LOG(NDPI_PROTOCOL_RX, ndpi_struct, NDPI_LOG_DEBUG, "found RX\n");
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_RX, NDPI_PROTOCOL_UNKNOWN);
}
else {
NDPI_LOG(NDPI_PROTOCOL_RX, ndpi_struct, NDPI_LOG_DEBUG, "excluding RX\n");
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_RX);
} }
} }