2018-06-15 22:47:47 +02:00
|
|
|
/* rtp_stream_id.c
|
|
|
|
* RTP stream id functions for Wireshark
|
|
|
|
*
|
|
|
|
* Copyright 2003, Alcatel Business Systems
|
|
|
|
* By Lars Ruoff <lars.ruoff@gmx.net>
|
|
|
|
*
|
|
|
|
* Wireshark - Network traffic analyzer
|
|
|
|
* By Gerald Combs <gerald@wireshark.org>
|
|
|
|
* Copyright 1998 Gerald Combs
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "file.h"
|
|
|
|
|
|
|
|
#include "ui/rtp_stream_id.h"
|
|
|
|
#include "epan/dissectors/packet-rtp.h"
|
|
|
|
|
|
|
|
/****************************************************************************/
|
|
|
|
/* rtpstream id functions */
|
|
|
|
/****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************/
|
|
|
|
/* deep copy of id */
|
|
|
|
void rtpstream_id_copy(const rtpstream_id_t *src, rtpstream_id_t *dest)
|
|
|
|
{
|
|
|
|
copy_address(&(dest->src_addr), &(src->src_addr));
|
|
|
|
dest->src_port=src->src_port;
|
|
|
|
copy_address(&(dest->dst_addr), &(src->dst_addr));
|
|
|
|
dest->dst_port=src->dst_port;
|
|
|
|
dest->ssrc=src->ssrc;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************/
|
|
|
|
/* deep copy of id from packet_info */
|
2024-03-29 18:08:09 -07:00
|
|
|
void rtpstream_id_copy_pinfo(const packet_info *pinfo, rtpstream_id_t *dest, bool swap_src_dst)
|
2018-06-15 22:47:47 +02:00
|
|
|
{
|
|
|
|
if (!swap_src_dst)
|
|
|
|
{
|
|
|
|
copy_address(&(dest->src_addr), &(pinfo->src));
|
|
|
|
dest->src_port=pinfo->srcport;
|
|
|
|
copy_address(&(dest->dst_addr), &(pinfo->dst));
|
|
|
|
dest->dst_port=pinfo->destport;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
copy_address(&(dest->src_addr), &(pinfo->dst));
|
|
|
|
dest->src_port=pinfo->destport;
|
|
|
|
copy_address(&(dest->dst_addr), &(pinfo->src));
|
|
|
|
dest->dst_port=pinfo->srcport;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-28 18:28:39 -05:00
|
|
|
/****************************************************************************/
|
|
|
|
/* shallow copy from packet_info to id */
|
2024-03-29 18:08:09 -07:00
|
|
|
void rtpstream_id_copy_pinfo_shallow(const packet_info *pinfo, rtpstream_id_t *dest, bool swap_src_dst)
|
2023-02-28 18:28:39 -05:00
|
|
|
{
|
|
|
|
if (!swap_src_dst)
|
|
|
|
{
|
|
|
|
copy_address_shallow(&(dest->src_addr), &(pinfo->src));
|
|
|
|
dest->src_port=pinfo->srcport;
|
|
|
|
copy_address_shallow(&(dest->dst_addr), &(pinfo->dst));
|
|
|
|
dest->dst_port=pinfo->destport;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
copy_address_shallow(&(dest->src_addr), &(pinfo->dst));
|
|
|
|
dest->src_port=pinfo->destport;
|
|
|
|
copy_address_shallow(&(dest->dst_addr), &(pinfo->src));
|
|
|
|
dest->dst_port=pinfo->srcport;
|
|
|
|
}
|
|
|
|
}
|
2018-06-15 22:47:47 +02:00
|
|
|
/****************************************************************************/
|
|
|
|
/* free memory allocated for id */
|
|
|
|
void rtpstream_id_free(rtpstream_id_t *id)
|
|
|
|
{
|
|
|
|
free_address(&(id->src_addr));
|
|
|
|
free_address(&(id->dst_addr));
|
|
|
|
memset(id, 0, sizeof(*id));
|
|
|
|
}
|
|
|
|
|
2021-04-13 16:38:13 +02:00
|
|
|
/****************************************************************************/
|
|
|
|
/* convert rtpstream_id_t to hash */
|
2024-03-29 18:08:09 -07:00
|
|
|
unsigned rtpstream_id_to_hash(const rtpstream_id_t *id)
|
2021-04-13 16:38:13 +02:00
|
|
|
{
|
2024-03-29 18:08:09 -07:00
|
|
|
unsigned hash = 0;
|
2021-04-13 16:38:13 +02:00
|
|
|
|
|
|
|
if (!id) { return 0; }
|
|
|
|
/* XOR of: */
|
|
|
|
/* SRC PORT | DST_PORT */
|
|
|
|
/* SSRC */
|
|
|
|
/* SRC ADDR */
|
|
|
|
/* DST ADDR */
|
|
|
|
hash ^= id->src_port | id->dst_port << 16;
|
|
|
|
hash ^= id->ssrc;
|
2021-04-15 10:39:19 -07:00
|
|
|
hash = add_address_to_hash(hash, &id->src_addr);
|
|
|
|
hash = add_address_to_hash(hash, &id->dst_addr);
|
2021-04-13 16:38:13 +02:00
|
|
|
|
|
|
|
return hash;
|
|
|
|
}
|
|
|
|
|
2018-06-15 22:47:47 +02:00
|
|
|
/****************************************************************************/
|
|
|
|
/* compare two ids by flags */
|
2024-03-29 18:08:09 -07:00
|
|
|
bool rtpstream_id_equal(const rtpstream_id_t *id1, const rtpstream_id_t *id2, unsigned flags)
|
2018-06-15 22:47:47 +02:00
|
|
|
{
|
|
|
|
if (addresses_equal(&(id1->src_addr), &(id2->src_addr))
|
|
|
|
&& id1->src_port == id2->src_port
|
|
|
|
&& addresses_equal(&(id1->dst_addr), &(id2->dst_addr))
|
|
|
|
&& id1->dst_port == id2->dst_port)
|
|
|
|
{
|
2024-03-29 18:08:09 -07:00
|
|
|
bool equal = true;
|
2018-06-15 22:47:47 +02:00
|
|
|
|
|
|
|
if ((flags & RTPSTREAM_ID_EQUAL_SSRC)
|
|
|
|
&& id1->ssrc != id2->ssrc)
|
|
|
|
{
|
2024-03-29 18:08:09 -07:00
|
|
|
equal = false;
|
2018-06-15 22:47:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return equal;
|
|
|
|
}
|
|
|
|
|
2024-03-29 18:08:09 -07:00
|
|
|
return false;
|
2018-06-15 22:47:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************/
|
RTP: Improve selection of streams for RTP Analysis/Player
If we are only trying to find RTP streams that match the current
packet, there's no reason to retap all other packets after
dissecting the current packet. This speeds up selection in that
case.
It is possible for an RTP session to contain multiple SSRCs
(such as with SDP negotiating BUNDLE (RFC 9143) as in WebRTC,
also see RFC 8872 for a general disscussion.)
The existing mechanism for searching for matching RTP streams for
the currently selected packet does not deal well with this.
findRtpStreams adds one copy of the forward stream (however, with the
same SSRC each time) for each stream bundled together on the session.
It also adds one copy for each stream in the reverse direction, only
using the first encountered SSRC.
When processed later, that means that only one reverse direction RTP
stream is added, which might not be the desired pair of the forward
stream (e.g., audio and video are bundled in each direction.)
Worse, if and when the RTP stream IDs are freed, a double-free can occur
and crash.
Don't add an RTP stream more than once.
Change the behavior when the Ctrl key is selected to adding all
RTP streams that share the addresses and ports (in either direction)
regardless of SSRC. Adding everything in the bundle makes more sense,
especially since there's no good way to determine which of the
bundled reverse RTP streams are paired with the selected packet's
RTP stream.
Also try to handle the unusual case of more than one stream in
the current packet (could happen with unusual tunneling.)
2023-07-01 07:51:16 -04:00
|
|
|
/* compare an rtpstream id address and ports with pinfo */
|
2024-03-29 18:08:09 -07:00
|
|
|
bool rtpstream_id_equal_pinfo(const rtpstream_id_t *id, const packet_info *pinfo, bool swap_src_dst)
|
RTP: Improve selection of streams for RTP Analysis/Player
If we are only trying to find RTP streams that match the current
packet, there's no reason to retap all other packets after
dissecting the current packet. This speeds up selection in that
case.
It is possible for an RTP session to contain multiple SSRCs
(such as with SDP negotiating BUNDLE (RFC 9143) as in WebRTC,
also see RFC 8872 for a general disscussion.)
The existing mechanism for searching for matching RTP streams for
the currently selected packet does not deal well with this.
findRtpStreams adds one copy of the forward stream (however, with the
same SSRC each time) for each stream bundled together on the session.
It also adds one copy for each stream in the reverse direction, only
using the first encountered SSRC.
When processed later, that means that only one reverse direction RTP
stream is added, which might not be the desired pair of the forward
stream (e.g., audio and video are bundled in each direction.)
Worse, if and when the RTP stream IDs are freed, a double-free can occur
and crash.
Don't add an RTP stream more than once.
Change the behavior when the Ctrl key is selected to adding all
RTP streams that share the addresses and ports (in either direction)
regardless of SSRC. Adding everything in the bundle makes more sense,
especially since there's no good way to determine which of the
bundled reverse RTP streams are paired with the selected packet's
RTP stream.
Also try to handle the unusual case of more than one stream in
the current packet (could happen with unusual tunneling.)
2023-07-01 07:51:16 -04:00
|
|
|
{
|
|
|
|
if (!swap_src_dst) {
|
|
|
|
if (addresses_equal(&(id->src_addr), &(pinfo->src))
|
|
|
|
&& id->src_port == pinfo->srcport
|
|
|
|
&& addresses_equal(&(id->dst_addr), &(pinfo->dst))
|
|
|
|
&& id->dst_port == pinfo->destport)
|
|
|
|
{
|
2024-03-29 18:08:09 -07:00
|
|
|
return true;
|
RTP: Improve selection of streams for RTP Analysis/Player
If we are only trying to find RTP streams that match the current
packet, there's no reason to retap all other packets after
dissecting the current packet. This speeds up selection in that
case.
It is possible for an RTP session to contain multiple SSRCs
(such as with SDP negotiating BUNDLE (RFC 9143) as in WebRTC,
also see RFC 8872 for a general disscussion.)
The existing mechanism for searching for matching RTP streams for
the currently selected packet does not deal well with this.
findRtpStreams adds one copy of the forward stream (however, with the
same SSRC each time) for each stream bundled together on the session.
It also adds one copy for each stream in the reverse direction, only
using the first encountered SSRC.
When processed later, that means that only one reverse direction RTP
stream is added, which might not be the desired pair of the forward
stream (e.g., audio and video are bundled in each direction.)
Worse, if and when the RTP stream IDs are freed, a double-free can occur
and crash.
Don't add an RTP stream more than once.
Change the behavior when the Ctrl key is selected to adding all
RTP streams that share the addresses and ports (in either direction)
regardless of SSRC. Adding everything in the bundle makes more sense,
especially since there's no good way to determine which of the
bundled reverse RTP streams are paired with the selected packet's
RTP stream.
Also try to handle the unusual case of more than one stream in
the current packet (could happen with unusual tunneling.)
2023-07-01 07:51:16 -04:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (addresses_equal(&(id->src_addr), &(pinfo->dst))
|
|
|
|
&& id->src_port == pinfo->destport
|
|
|
|
&& addresses_equal(&(id->dst_addr), &(pinfo->src))
|
|
|
|
&& id->dst_port == pinfo->srcport)
|
|
|
|
{
|
2024-03-29 18:08:09 -07:00
|
|
|
return true;
|
RTP: Improve selection of streams for RTP Analysis/Player
If we are only trying to find RTP streams that match the current
packet, there's no reason to retap all other packets after
dissecting the current packet. This speeds up selection in that
case.
It is possible for an RTP session to contain multiple SSRCs
(such as with SDP negotiating BUNDLE (RFC 9143) as in WebRTC,
also see RFC 8872 for a general disscussion.)
The existing mechanism for searching for matching RTP streams for
the currently selected packet does not deal well with this.
findRtpStreams adds one copy of the forward stream (however, with the
same SSRC each time) for each stream bundled together on the session.
It also adds one copy for each stream in the reverse direction, only
using the first encountered SSRC.
When processed later, that means that only one reverse direction RTP
stream is added, which might not be the desired pair of the forward
stream (e.g., audio and video are bundled in each direction.)
Worse, if and when the RTP stream IDs are freed, a double-free can occur
and crash.
Don't add an RTP stream more than once.
Change the behavior when the Ctrl key is selected to adding all
RTP streams that share the addresses and ports (in either direction)
regardless of SSRC. Adding everything in the bundle makes more sense,
especially since there's no good way to determine which of the
bundled reverse RTP streams are paired with the selected packet's
RTP stream.
Also try to handle the unusual case of more than one stream in
the current packet (could happen with unusual tunneling.)
2023-07-01 07:51:16 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-29 18:08:09 -07:00
|
|
|
return false;
|
RTP: Improve selection of streams for RTP Analysis/Player
If we are only trying to find RTP streams that match the current
packet, there's no reason to retap all other packets after
dissecting the current packet. This speeds up selection in that
case.
It is possible for an RTP session to contain multiple SSRCs
(such as with SDP negotiating BUNDLE (RFC 9143) as in WebRTC,
also see RFC 8872 for a general disscussion.)
The existing mechanism for searching for matching RTP streams for
the currently selected packet does not deal well with this.
findRtpStreams adds one copy of the forward stream (however, with the
same SSRC each time) for each stream bundled together on the session.
It also adds one copy for each stream in the reverse direction, only
using the first encountered SSRC.
When processed later, that means that only one reverse direction RTP
stream is added, which might not be the desired pair of the forward
stream (e.g., audio and video are bundled in each direction.)
Worse, if and when the RTP stream IDs are freed, a double-free can occur
and crash.
Don't add an RTP stream more than once.
Change the behavior when the Ctrl key is selected to adding all
RTP streams that share the addresses and ports (in either direction)
regardless of SSRC. Adding everything in the bundle makes more sense,
especially since there's no good way to determine which of the
bundled reverse RTP streams are paired with the selected packet's
RTP stream.
Also try to handle the unusual case of more than one stream in
the current packet (could happen with unusual tunneling.)
2023-07-01 07:51:16 -04:00
|
|
|
}
|
|
|
|
/****************************************************************************/
|
2018-06-15 22:47:47 +02:00
|
|
|
/* compare two ids, one in pinfo */
|
2024-03-29 18:08:09 -07:00
|
|
|
bool rtpstream_id_equal_pinfo_rtp_info(const rtpstream_id_t *id, const packet_info *pinfo, const struct _rtp_info *rtp_info)
|
2018-06-15 22:47:47 +02:00
|
|
|
{
|
|
|
|
if (addresses_equal(&(id->src_addr), &(pinfo->src))
|
|
|
|
&& id->src_port == pinfo->srcport
|
|
|
|
&& addresses_equal(&(id->dst_addr), &(pinfo->dst))
|
|
|
|
&& id->dst_port == pinfo->destport
|
|
|
|
&& id->ssrc == rtp_info->info_sync_src)
|
|
|
|
{
|
2024-03-29 18:08:09 -07:00
|
|
|
return true;
|
2018-06-15 22:47:47 +02:00
|
|
|
}
|
|
|
|
|
2024-03-29 18:08:09 -07:00
|
|
|
return false;
|
2018-06-15 22:47:47 +02:00
|
|
|
}
|
|
|
|
|
2021-04-13 16:38:13 +02:00
|
|
|
/****************************************************************************/
|
|
|
|
/* convert packet_info and _rtp_info to hash */
|
2024-03-29 18:08:09 -07:00
|
|
|
unsigned pinfo_rtp_info_to_hash(const packet_info *pinfo, const struct _rtp_info *rtp_info)
|
2021-04-13 16:38:13 +02:00
|
|
|
{
|
2024-03-29 18:08:09 -07:00
|
|
|
unsigned hash = 0;
|
2021-04-13 16:38:13 +02:00
|
|
|
|
|
|
|
if (!pinfo || !rtp_info) { return 0; }
|
|
|
|
/* XOR of: */
|
|
|
|
/* SRC PORT | DST_PORT */
|
|
|
|
/* SSRC */
|
|
|
|
/* SRC ADDR */
|
|
|
|
/* DST ADDR */
|
|
|
|
hash ^= pinfo->srcport | pinfo->destport << 16;
|
|
|
|
hash ^= rtp_info->info_sync_src;
|
2021-04-15 10:39:19 -07:00
|
|
|
hash = add_address_to_hash(hash, &pinfo->src);
|
|
|
|
hash = add_address_to_hash(hash, &pinfo->dst);
|
2021-04-13 16:38:13 +02:00
|
|
|
|
|
|
|
return hash;
|
|
|
|
}
|