Solved invalid detection on tests. Needs further work to detect one of the flows.
Please enter the commit message for your changes. Lines starting
This commit is contained in:
+20
-17
@@ -45,7 +45,6 @@ enum MQTT_PACKET_TYPES {
|
|||||||
DISCONNECT = 14
|
DISCONNECT = 14
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Entry point when protocol is identified.
|
* Entry point when protocol is identified.
|
||||||
*/
|
*/
|
||||||
@@ -93,34 +92,34 @@ void ndpi_search_mqtt (struct ndpi_detection_module_struct *ndpi_struct,
|
|||||||
u_int8_t flags = (u_int8_t) (packet->payload[0] & 0x0F);
|
u_int8_t flags = (u_int8_t) (packet->payload[0] & 0x0F);
|
||||||
NDPI_LOG(NDPI_PROTOCOL_MQTT, ndpi_struct, NDPI_LOG_DEBUG,"====>>>> Mqtt flags type: [%d]\n",flags);
|
NDPI_LOG(NDPI_PROTOCOL_MQTT, ndpi_struct, NDPI_LOG_DEBUG,"====>>>> Mqtt flags type: [%d]\n",flags);
|
||||||
// first stage verification
|
// first stage verification
|
||||||
if ((pt == CONNECT) || (pt == CONNACK) || (pt == PUBACK) || (pt == PUBREC) ||
|
if (((pt == CONNECT) || (pt == CONNACK) || (pt == PUBACK) || (pt == PUBREC) ||
|
||||||
(pt == PUBCOMP) || (pt == SUBACK) || (pt == UNSUBACK) || (pt == PINGREQ) ||
|
(pt == PUBCOMP) || (pt == SUBACK) || (pt == UNSUBACK) || (pt == PINGREQ) ||
|
||||||
(pt == PINGRESP) || (pt == DISCONNECT)) {
|
(pt == PINGRESP) || (pt == DISCONNECT)) && (flags > 0)) {
|
||||||
if (flags > 0) {
|
|
||||||
NDPI_LOG(NDPI_PROTOCOL_MQTT, ndpi_struct, NDPI_LOG_DEBUG, "Excluding Mqtt invalid Packet-Flag combination flag!=0\n");
|
NDPI_LOG(NDPI_PROTOCOL_MQTT, ndpi_struct, NDPI_LOG_DEBUG, "Excluding Mqtt invalid Packet-Flag combination flag!=0\n");
|
||||||
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_MQTT);
|
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_MQTT);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if (((pt == PUBREL) || (pt == SUBSCRIBE) || (pt == UNSUBSCRIBE)) && (flags != 2)) {
|
if (((pt == PUBREL) || (pt == SUBSCRIBE) || (pt == UNSUBSCRIBE)) && (flags != 2)) {
|
||||||
NDPI_LOG(NDPI_PROTOCOL_MQTT, ndpi_struct, NDPI_LOG_DEBUG, "Excluding Mqtt invalid Packet-Flag combination flag!=2\n");
|
NDPI_LOG(NDPI_PROTOCOL_MQTT, ndpi_struct, NDPI_LOG_DEBUG, "Excluding Mqtt invalid Packet-Flag combination flag!=2\n");
|
||||||
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_MQTT);
|
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_MQTT);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
NDPI_LOG(NDPI_PROTOCOL_MQTT, ndpi_struct, NDPI_LOG_DEBUG,"====>>>> Passed first stage of identification\n");
|
NDPI_LOG(NDPI_PROTOCOL_MQTT, ndpi_struct, NDPI_LOG_DEBUG,"====>>>> Passed first stage of identification\n");
|
||||||
// second stage verification (no payload)
|
// second stage verification (no payload, just variable headers)
|
||||||
if (((pt == CONNACK) || (pt == PUBACK) || (pt == PUBREL) ||
|
if ((pt == CONNACK) || (pt == PUBACK) || (pt == PUBREL) ||
|
||||||
(pt == PUBREC) || (pt == PUBCOMP) || (pt == UNSUBACK)) && (packet->payload_packet_len > 4)){
|
(pt == PUBREC) || (pt == PUBCOMP) || (pt == UNSUBACK)) {
|
||||||
|
if (packet->payload_packet_len != 4) { // these packets are always 4 bytes long
|
||||||
NDPI_LOG(NDPI_PROTOCOL_MQTT, ndpi_struct, NDPI_LOG_DEBUG, "Excluding Mqtt invalid Packet-Length < 4 \n");
|
NDPI_LOG(NDPI_PROTOCOL_MQTT, ndpi_struct, NDPI_LOG_DEBUG, "Excluding Mqtt invalid Packet-Length < 4 \n");
|
||||||
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_MQTT);
|
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_MQTT);
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
NDPI_LOG(NDPI_PROTOCOL_MQTT, ndpi_struct, NDPI_LOG_DEBUG, "Mqtt found \n");
|
NDPI_LOG(NDPI_PROTOCOL_MQTT, ndpi_struct, NDPI_LOG_DEBUG, "Mqtt found CONNACK/PUBACK/PUBREL/PUBREC/PUBCOMP/UNSUBACK\n");
|
||||||
ndpi_int_mqtt_add_connection(ndpi_struct,flow);
|
ndpi_int_mqtt_add_connection(ndpi_struct,flow);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (((pt == PINGREQ) || (pt == PINGRESP) || (pt == DISCONNECT)) && (packet->payload_packet_len > 2))
|
}
|
||||||
{
|
if ((pt == PINGREQ) || (pt == PINGRESP) || (pt == DISCONNECT)) {
|
||||||
|
if (packet->payload_packet_len != 2) { // these packets are always 2 bytes long
|
||||||
NDPI_LOG(NDPI_PROTOCOL_MQTT, ndpi_struct, NDPI_LOG_DEBUG, "Excluding Mqtt invalid Packet-Length <2 \n");
|
NDPI_LOG(NDPI_PROTOCOL_MQTT, ndpi_struct, NDPI_LOG_DEBUG, "Excluding Mqtt invalid Packet-Length <2 \n");
|
||||||
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_MQTT);
|
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_MQTT);
|
||||||
return;
|
return;
|
||||||
@@ -129,6 +128,7 @@ void ndpi_search_mqtt (struct ndpi_detection_module_struct *ndpi_struct,
|
|||||||
ndpi_int_mqtt_add_connection(ndpi_struct,flow);
|
ndpi_int_mqtt_add_connection(ndpi_struct,flow);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
NDPI_LOG(NDPI_PROTOCOL_MQTT, ndpi_struct, NDPI_LOG_DEBUG,"====>>>> Passed second stage of identification\n");
|
NDPI_LOG(NDPI_PROTOCOL_MQTT, ndpi_struct, NDPI_LOG_DEBUG,"====>>>> Passed second stage of identification\n");
|
||||||
// third stage verification (payload)
|
// third stage verification (payload)
|
||||||
if ((pt == CONNECT) && (memcmp(&(packet->payload[4]),"MQTT",4) == 0) ) {
|
if ((pt == CONNECT) && (memcmp(&(packet->payload[4]),"MQTT",4) == 0) ) {
|
||||||
@@ -160,9 +160,9 @@ void ndpi_search_mqtt (struct ndpi_detection_module_struct *ndpi_struct,
|
|||||||
NDPI_LOG(NDPI_PROTOCOL_MQTT, ndpi_struct, NDPI_LOG_DEBUG, "Mqtt found PUBLISH\n");
|
NDPI_LOG(NDPI_PROTOCOL_MQTT, ndpi_struct, NDPI_LOG_DEBUG, "Mqtt found PUBLISH\n");
|
||||||
ndpi_int_mqtt_add_connection(ndpi_struct,flow);
|
ndpi_int_mqtt_add_connection(ndpi_struct,flow);
|
||||||
return;
|
return;
|
||||||
|
|
||||||
}
|
}
|
||||||
if ((pt == SUBSCRIBE) && (packet->payload_packet_len < 8)){ // at least one topic+filter is required in the payload
|
if (pt == SUBSCRIBE) {
|
||||||
|
if (packet->payload_packet_len < 8) { // at least one topic+filter is required in the payload
|
||||||
NDPI_LOG(NDPI_PROTOCOL_MQTT, ndpi_struct, NDPI_LOG_DEBUG, "Excluding Mqtt invalid SUBSCRIBE\n");
|
NDPI_LOG(NDPI_PROTOCOL_MQTT, ndpi_struct, NDPI_LOG_DEBUG, "Excluding Mqtt invalid SUBSCRIBE\n");
|
||||||
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_MQTT);
|
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_MQTT);
|
||||||
return;
|
return;
|
||||||
@@ -171,8 +171,9 @@ void ndpi_search_mqtt (struct ndpi_detection_module_struct *ndpi_struct,
|
|||||||
ndpi_int_mqtt_add_connection(ndpi_struct,flow);
|
ndpi_int_mqtt_add_connection(ndpi_struct,flow);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if ((pt == SUBACK ) && (packet->payload_packet_len <5 )){ // must have at least a response code
|
if (pt == SUBACK ) {
|
||||||
|
if (packet->payload_packet_len <5 ) { // must have at least a response code
|
||||||
NDPI_LOG(NDPI_PROTOCOL_MQTT, ndpi_struct, NDPI_LOG_DEBUG, "Excluding Mqtt invalid SUBACK\n");
|
NDPI_LOG(NDPI_PROTOCOL_MQTT, ndpi_struct, NDPI_LOG_DEBUG, "Excluding Mqtt invalid SUBACK\n");
|
||||||
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_MQTT);
|
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_MQTT);
|
||||||
return;
|
return;
|
||||||
@@ -181,8 +182,9 @@ void ndpi_search_mqtt (struct ndpi_detection_module_struct *ndpi_struct,
|
|||||||
ndpi_int_mqtt_add_connection(ndpi_struct,flow);
|
ndpi_int_mqtt_add_connection(ndpi_struct,flow);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if ((pt == UNSUBSCRIBE) && (packet->payload_packet_len < 7)) { // at least a topic
|
if (pt == UNSUBSCRIBE) {
|
||||||
|
if (packet->payload_packet_len < 7) { // at least a topic
|
||||||
NDPI_LOG(NDPI_PROTOCOL_MQTT, ndpi_struct, NDPI_LOG_DEBUG, "Excluding Mqtt invalid UNSUBSCRIBE\n");
|
NDPI_LOG(NDPI_PROTOCOL_MQTT, ndpi_struct, NDPI_LOG_DEBUG, "Excluding Mqtt invalid UNSUBSCRIBE\n");
|
||||||
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_MQTT);
|
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_MQTT);
|
||||||
return;
|
return;
|
||||||
@@ -191,6 +193,7 @@ void ndpi_search_mqtt (struct ndpi_detection_module_struct *ndpi_struct,
|
|||||||
ndpi_int_mqtt_add_connection(ndpi_struct,flow);
|
ndpi_int_mqtt_add_connection(ndpi_struct,flow);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
NDPI_LOG(NDPI_PROTOCOL_MQTT, ndpi_struct, NDPI_LOG_DEBUG,"====>>>> Passed third stage of identification");
|
NDPI_LOG(NDPI_PROTOCOL_MQTT, ndpi_struct, NDPI_LOG_DEBUG,"====>>>> Passed third stage of identification");
|
||||||
NDPI_LOG(NDPI_PROTOCOL_MQTT, ndpi_struct, NDPI_LOG_DEBUG, "Reached the end excluding Mqtt ...\n");
|
NDPI_LOG(NDPI_PROTOCOL_MQTT, ndpi_struct, NDPI_LOG_DEBUG, "Reached the end excluding Mqtt ...\n");
|
||||||
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_MQTT);
|
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_MQTT);
|
||||||
|
|||||||
Reference in New Issue
Block a user