diff options
author | Ivan Nardi <12729895+IvanNardi@users.noreply.github.com> | 2024-05-29 18:31:10 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-05-29 18:31:10 +0200 |
commit | 81e42b748e46666158596cc22224b0ec11d85be0 (patch) | |
tree | 8deb2ebecddd9556607dbee28c5de51d0c4c74c7 /src | |
parent | 6127e04900d14682f524cca5b5720b2fb9f0e283 (diff) |
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
Diffstat (limited to 'src')
-rw-r--r-- | src/include/ndpi_private.h | 3 | ||||
-rw-r--r-- | src/lib/protocols/line.c | 2 | ||||
-rw-r--r-- | src/lib/protocols/rtp.c | 15 | ||||
-rw-r--r-- | src/lib/protocols/stun.c | 2 |
4 files changed, 9 insertions, 13 deletions
diff --git a/src/include/ndpi_private.h b/src/include/ndpi_private.h index 4ecb7c1b8..341d01900 100644 --- a/src/include/ndpi_private.h +++ b/src/include/ndpi_private.h @@ -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 */ diff --git a/src/lib/protocols/line.c b/src/lib/protocols/line.c index da28e613b..933693ed9 100644 --- a/src/lib/protocols/line.c +++ b/src/lib/protocols/line.c @@ -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"); diff --git a/src/lib/protocols/rtp.c b/src/lib/protocols/rtp.c index b543e8b99..d8c09be3a 100644 --- a/src/lib/protocols/rtp.c +++ b/src/lib/protocols/rtp.c @@ -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) { diff --git a/src/lib/protocols/stun.c b/src/lib/protocols/stun.c index aca6540fc..877379abc 100644 --- a/src/lib/protocols/stun.c +++ b/src/lib/protocols/stun.c @@ -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"); |