RTP: fix detection over TCP (#2462)
RFC4571 is not the only way to wrap RTP messages in TCP streams.
For example, when RTP is encapsulated over TURN flows (i.e. via DATA
attribute) there is no additional framing.
See also 6127e0490
This commit is contained in:
@@ -648,7 +648,8 @@ const uint8_t *get_crypto_data(struct ndpi_detection_module_struct *ndpi_struct,
|
||||
|
||||
/* RTP */
|
||||
int is_valid_rtp_payload_type(uint8_t type);
|
||||
int is_rtp_or_rtcp(struct ndpi_detection_module_struct *ndpi_struct, u_int16_t *seq);
|
||||
int is_rtp_or_rtcp(struct ndpi_detection_module_struct *ndpi_struct,
|
||||
const u_int8_t *payload, u_int16_t payload_len, u_int16_t *seq);
|
||||
u_int8_t rtp_get_stream_type(u_int8_t payloadType, ndpi_multimedia_flow_type *s_type);
|
||||
|
||||
/* Bittorrent */
|
||||
|
||||
@@ -83,7 +83,7 @@ static void ndpi_search_line(struct ndpi_detection_module_struct *ndpi_struct,
|
||||
/* It might be a RTP/RTCP packet. Ignore it and keep looking for the
|
||||
LINE packet numbers */
|
||||
/* Basic RTP detection */
|
||||
rc = is_rtp_or_rtcp(ndpi_struct, NULL);
|
||||
rc = is_rtp_or_rtcp(ndpi_struct, packet->payload, packet->payload_packet_len, NULL);
|
||||
if(rc == IS_RTCP || rc == IS_RTP) {
|
||||
if(flow->packet_counter < 10) {
|
||||
NDPI_LOG_DBG(ndpi_struct, "Probably RTP; keep looking for LINE\n");
|
||||
|
||||
+5
-10
@@ -83,23 +83,16 @@ static int is_valid_rtcp_payload_type(uint8_t type) {
|
||||
return (type >= 192 && type <= 213);
|
||||
}
|
||||
|
||||
int is_rtp_or_rtcp(struct ndpi_detection_module_struct *ndpi_struct, u_int16_t *seq)
|
||||
int is_rtp_or_rtcp(struct ndpi_detection_module_struct *ndpi_struct,
|
||||
const u_int8_t *payload, u_int16_t payload_len, u_int16_t *seq)
|
||||
{
|
||||
struct ndpi_packet_struct *packet = &ndpi_struct->packet;
|
||||
u_int8_t csrc_count, ext_header;
|
||||
u_int16_t ext_len;
|
||||
u_int32_t min_len;
|
||||
const u_int8_t *payload = packet->payload;
|
||||
u_int16_t payload_len = packet->payload_packet_len;
|
||||
|
||||
if(payload_len < 2)
|
||||
return NO_RTP_RTCP;
|
||||
|
||||
if(packet->tcp != NULL) {
|
||||
payload_len -= 2;
|
||||
payload += 2; /* Skip the length field */
|
||||
}
|
||||
|
||||
if((payload[0] & 0xC0) != 0x80) { /* Version 2 */
|
||||
NDPI_LOG_DBG(ndpi_struct, "Not version 2\n");
|
||||
return NO_RTP_RTCP;
|
||||
@@ -149,10 +142,12 @@ static void ndpi_rtp_search(struct ndpi_detection_module_struct *ndpi_struct,
|
||||
u_int8_t is_rtp;
|
||||
struct ndpi_packet_struct *packet = &ndpi_struct->packet;
|
||||
const u_int8_t *payload = packet->payload;
|
||||
u_int16_t payload_len = packet->payload_packet_len;
|
||||
u_int16_t seq;
|
||||
|
||||
if(packet->tcp != NULL) {
|
||||
payload += 2; /* Skip the length field */
|
||||
payload_len -= 2;
|
||||
}
|
||||
NDPI_LOG_DBG(ndpi_struct, "search RTP (stage %d/%d)\n", flow->rtp_stage, flow->rtcp_stage);
|
||||
|
||||
@@ -169,7 +164,7 @@ static void ndpi_rtp_search(struct ndpi_detection_module_struct *ndpi_struct,
|
||||
return;
|
||||
}
|
||||
|
||||
is_rtp = is_rtp_or_rtcp(ndpi_struct, &seq);
|
||||
is_rtp = is_rtp_or_rtcp(ndpi_struct, payload, payload_len, &seq);
|
||||
|
||||
if(is_rtp == IS_RTP) {
|
||||
if(flow->rtp_stage == 2) {
|
||||
|
||||
@@ -796,7 +796,7 @@ static int stun_search_again(struct ndpi_detection_module_struct *ndpi_struct,
|
||||
NDPI_LOG_DBG(ndpi_struct, "QUIC range. Unexpected\n");
|
||||
} else if(first_byte <= 191) {
|
||||
|
||||
rtp_rtcp = is_rtp_or_rtcp(ndpi_struct, NULL);
|
||||
rtp_rtcp = is_rtp_or_rtcp(ndpi_struct, packet->payload, packet->payload_packet_len, NULL);
|
||||
if(rtp_rtcp == IS_RTP) {
|
||||
NDPI_LOG_DBG(ndpi_struct, "RTP (dir %d)\n", packet->packet_direction);
|
||||
NDPI_LOG_INFO(ndpi_struct, "Found RTP over STUN\n");
|
||||
|
||||
Reference in New Issue
Block a user