Browse Source

MT#55283 add media PUBLIC flag

A simple mechanism to track whether a given media endpoint has been
advertised to the public. If it hasn't, then any media received on it is
considered suspicious, and source addresses are ignored for learning
purposes.

Change-Id: I76a08e3f442f263dad192ff496a5d734a9349d26
pull/1964/head
Richard Fuchs 6 months ago
parent
commit
a2c9d5c7a1
7 changed files with 107 additions and 48 deletions
  1. +1
    -0
      daemon/call.c
  2. +4
    -0
      daemon/media_socket.c
  3. +2
    -0
      daemon/sdp.c
  4. +1
    -0
      include/call.h
  5. +51
    -0
      t/auto-daemon-tests-heuristic.pl
  6. +23
    -23
      t/auto-daemon-tests-redis-json.pl
  7. +25
    -25
      t/auto-daemon-tests-redis.pl

+ 1
- 0
daemon/call.c View File

@ -867,6 +867,7 @@ static struct endpoint_map *__get_endpoint_map(struct call_media *media, unsigne
return NULL;
__C_DBG("allocating stream_fds for %u ports", num_ports);
MEDIA_CLEAR(media, PUBLIC);
struct socket_intf_list *il;
while ((il = t_queue_pop_head(&intf_sockets))) {


+ 4
- 0
daemon/media_socket.c View File

@ -2427,6 +2427,10 @@ static bool media_packet_address_check(struct packet_handler_ctx *phc)
phc->mp.stream->endpoint.port);
goto out;
}
if (!MEDIA_ISSET(phc->mp.media, PUBLIC)) {
__C_DBG("media not answered");
goto out;
}
// GH #697 - apparent Asterisk bug where it sends stray RTCP to the RTP port.
// work around this by detecting this situation and ignoring the packet for


+ 2
- 0
daemon/sdp.c View File

@ -3253,6 +3253,8 @@ int sdp_create(str *out, struct call_monologue *monologue, sdp_ng_flags *flags)
if (!sdp_out_add_media(s, media, port))
goto err;
MEDIA_SET(media, PUBLIC);
/* print media level attributes */
print_sdp_media_section(s, media, &sdp_address, copy_media, source_media,
rtp_ps, rtp_ps_link, flags);


+ 1
- 0
include/call.h View File

@ -215,6 +215,7 @@ enum {
#define MEDIA_FLAG_REAL_SENDONLY (1LL << 35)
#define MEDIA_FLAG_SELECT_PT (1LL << 36)
#define MEDIA_FLAG_RECRYPT (1LL << 37)
#define MEDIA_FLAG_PUBLIC (1LL << 38)
/* struct call_monologue */
#define ML_FLAG_REC_FORWARDING (1LL << 16)


+ 51
- 0
t/auto-daemon-tests-heuristic.pl View File

@ -580,5 +580,56 @@ rcv_no($sock_e);
($sock_a, $sock_b, $sock_c) = new_call(
[qw(198.51.100.1 2188)], # caller
[qw(198.51.100.3 2190)], # callee - from SDP
[qw(198.51.100.3 2210)], # hijack
);
($port_a) = offer('offer only', { flags => ['strict source'] }, <<SDP);
v=0
o=- 1545997027 1 IN IP4 198.51.100.1
s=tester
t=0 0
m=audio 2188 RTP/AVP 0 8
c=IN IP4 198.51.100.1
a=sendrecv
----------------------------------
v=0
o=- 1545997027 1 IN IP4 198.51.100.1
s=tester
t=0 0
m=audio PORT RTP/AVP 0 8
c=IN IP4 203.0.113.1
a=rtpmap:0 PCMU/8000
a=rtpmap:8 PCMA/8000
a=sendrecv
a=rtcp:PORT
SDP
# callee send
snd($sock_b, $port_a, rtp(0, 2000, 4000, 0x1234, "\x00" x 160));
($port_b) = rcv($sock_a, -1, rtpm(0, 2000, 4000, 0x1234, "\x00" x 160));
rcv_no($sock_b);
rcv_no($sock_c);
# hijack send
snd($sock_c, $port_b, rtp(0, 1001, 3160, 0x1234, "\x00" x 160));
rcv_no($sock_a);
rcv_no($sock_b);
rcv_no($sock_c);
# callee send, forward, hijack ignored
snd($sock_b, $port_a, rtp(0, 2001, 4160, 0x1234, "\x00" x 160));
rcv($sock_a, $port_b, rtpm(0, 2001, 4160, 0x1234, "\x00" x 160));
rcv_no($sock_b);
rcv_no($sock_c);
rcv_no($sock_a);
rcv_no($sock_b);
rcv_no($sock_c);
#done_testing;NGCP::Rtpengine::AutoTest::terminate('f00');exit;
done_testing();

+ 23
- 23
t/auto-daemon-tests-redis-json.pl View File

@ -148,7 +148,7 @@ $json_exp = {
'format_str' => '0 8',
'index' => '1',
'logical_intf' => 'foo',
'media_flags' => '2228236',
'media_flags' => '274880135180',
'protocol' => 'RTP/AVP',
'ptime' => '0',
'tag' => '1',
@ -404,7 +404,7 @@ $json_exp = {
'format_str' => '8',
'index' => '1',
'logical_intf' => 'foo',
'media_flags' => '2293772',
'media_flags' => '274880200716',
'protocol' => 'RTP/AVP',
'ptime' => '0',
'tag' => '1',
@ -415,7 +415,7 @@ $json_exp = {
'format_str' => '8',
'index' => '1',
'logical_intf' => 'foo',
'media_flags' => '65548',
'media_flags' => '274877972492',
'protocol' => 'RTP/AVP',
'ptime' => '0',
'tag' => '0',
@ -665,7 +665,7 @@ $json_exp = {
'format_str' => '0 8',
'index' => '1',
'logical_intf' => 'foo',
'media_flags' => '2228236',
'media_flags' => '274880135180',
'protocol' => 'RTP/AVP',
'ptime' => '0',
'tag' => '1',
@ -922,7 +922,7 @@ $json_exp = {
'format_str' => '0 8',
'index' => '1',
'logical_intf' => 'foo',
'media_flags' => '2293772',
'media_flags' => '274880200716',
'protocol' => 'RTP/AVP',
'ptime' => '0',
'tag' => '1',
@ -933,7 +933,7 @@ $json_exp = {
'format_str' => '0 8',
'index' => '1',
'logical_intf' => 'foo',
'media_flags' => '65548',
'media_flags' => '274877972492',
'protocol' => 'RTP/AVP',
'ptime' => '0',
'tag' => '0',
@ -1211,7 +1211,7 @@ $json_exp = {
'format_str' => '0 8',
'index' => '1',
'logical_intf' => 'foo',
'media_flags' => '2293772',
'media_flags' => '274880200716',
'protocol' => 'RTP/AVP',
'ptime' => '0',
'tag' => '1',
@ -1222,7 +1222,7 @@ $json_exp = {
'format_str' => '0 8',
'index' => '1',
'logical_intf' => 'foo',
'media_flags' => '65548',
'media_flags' => '274877972492',
'protocol' => 'RTP/AVP',
'ptime' => '0',
'tag' => '0',
@ -1233,7 +1233,7 @@ $json_exp = {
'format_str' => '0 8',
'index' => '1',
'logical_intf' => 'foo',
'media_flags' => '2097156',
'media_flags' => '274880004100',
'protocol' => 'RTP/AVP',
'ptime' => '0',
'tag' => '2',
@ -1244,7 +1244,7 @@ $json_exp = {
'format_str' => '0 8',
'index' => '2',
'logical_intf' => 'foo',
'media_flags' => '2097156',
'media_flags' => '274880004100',
'protocol' => 'RTP/AVP',
'ptime' => '0',
'tag' => '2',
@ -1566,12 +1566,12 @@ a=rtcp:PORT
SDP
$json_exp->{'media-1'}{media_flags} = '2293772';
$json_exp->{'media-0'}{media_flags} = '65548';
$json_exp->{'media-1'}{media_flags} = '274880200716';
$json_exp->{'media-0'}{media_flags} = '274877972492';
$json_exp->{'media-2'}{format_str} = '8';
$json_exp->{'media-2'}{media_flags} = '2162692';
$json_exp->{'media-2'}{media_flags} = '274880069636';
$json_exp->{'media-3'}{format_str} = '8';
$json_exp->{'media-3'}{media_flags} = '2162692';
$json_exp->{'media-3'}{media_flags} = '274880069636';
$json_exp->{'payload_types-2'}[0] = '8/PCMA/8000//0/20//';
$#{$json_exp->{'payload_types-2'}} = 0;
$json_exp->{'payload_types-3'}[0] = '8/PCMA/8000//0/20//';
@ -1653,7 +1653,7 @@ $json_exp = {
'format_str' => '0 8 9',
'index' => '1',
'logical_intf' => 'foo',
'media_flags' => '65544',
'media_flags' => '274877972488',
'protocol' => 'RTP/AVP',
'ptime' => '0',
'tag' => '0',
@ -1810,7 +1810,7 @@ $json_exp = {
'format_str' => '0 8 9',
'index' => '1',
'logical_intf' => 'foo',
'media_flags' => '65544',
'media_flags' => '274877972488',
'protocol' => 'RTP/AVP',
'ptime' => '0',
'tag' => '0',
@ -1821,7 +1821,7 @@ $json_exp = {
'format_str' => '0 8 9',
'index' => '1',
'logical_intf' => 'foo',
'media_flags' => '2097156',
'media_flags' => '274880004100',
'protocol' => 'RTP/AVP',
'ptime' => '0',
'tag' => '1',
@ -2047,7 +2047,7 @@ $json_exp = {
'format_str' => '0 8 9',
'index' => '1',
'logical_intf' => 'foo',
'media_flags' => '65544',
'media_flags' => '274877972488',
'protocol' => 'RTP/AVP',
'ptime' => '0',
'tag' => '0',
@ -2058,7 +2058,7 @@ $json_exp = {
'format_str' => '0',
'index' => '1',
'logical_intf' => 'foo',
'media_flags' => '2162692',
'media_flags' => '274880069636',
'protocol' => 'RTP/AVP',
'ptime' => '0',
'tag' => '1',
@ -2298,7 +2298,7 @@ $json_exp = {
'format_str' => '0 8 9',
'index' => '1',
'logical_intf' => 'foo',
'media_flags' => '65544',
'media_flags' => '274877972488',
'protocol' => 'RTP/AVP',
'ptime' => '0',
'tag' => '0',
@ -2309,7 +2309,7 @@ $json_exp = {
'format_str' => '0',
'index' => '1',
'logical_intf' => 'foo',
'media_flags' => '2162692',
'media_flags' => '274880069636',
'protocol' => 'RTP/AVP',
'ptime' => '0',
'tag' => '1',
@ -2320,7 +2320,7 @@ $json_exp = {
'format_str' => '0 8 9',
'index' => '1',
'logical_intf' => 'foo',
'media_flags' => '2097156',
'media_flags' => '274880004100',
'protocol' => 'RTP/AVP',
'ptime' => '0',
'tag' => '2',
@ -2565,7 +2565,7 @@ a=rtcp:PORT
SDP
$json_exp->{'media-2'}{format_str} = '0';
$json_exp->{'media-2'}{media_flags} = '2162692';
$json_exp->{'media-2'}{media_flags} = '274880069636';
$json_exp->{'stream-1'}{ps_flags} = '1179649';
$json_exp->{'stream-4'}{advertised_endpoint} = '198.51.100.14:6046';
$json_exp->{'stream-4'}{endpoint} = '198.51.100.14:6046';


+ 25
- 25
t/auto-daemon-tests-redis.pl View File

@ -147,7 +147,7 @@ $json_exp = {
'format_str' => '0 8',
'index' => '1',
'logical_intf' => 'foo',
'media_flags' => '2228236',
'media_flags' => '274880135180',
'protocol' => 'RTP/AVP',
'ptime' => '0',
'tag' => '1',
@ -405,7 +405,7 @@ $json_exp = {
'format_str' => '8',
'index' => '1',
'logical_intf' => 'foo',
'media_flags' => '2293772',
'media_flags' => '274880200716',
'protocol' => 'RTP/AVP',
'ptime' => '0',
'tag' => '1',
@ -416,7 +416,7 @@ $json_exp = {
'format_str' => '8',
'index' => '1',
'logical_intf' => 'foo',
'media_flags' => '65548',
'media_flags' => '274877972492',
'protocol' => 'RTP/AVP',
'ptime' => '0',
'tag' => '0',
@ -666,7 +666,7 @@ $json_exp = {
'format_str' => '8',
'index' => '1',
'logical_intf' => 'foo',
'media_flags' => '2293772',
'media_flags' => '274880200716',
'protocol' => 'RTP/AVP',
'ptime' => '0',
'tag' => '1',
@ -677,7 +677,7 @@ $json_exp = {
'format_str' => '8',
'index' => '1',
'logical_intf' => 'foo',
'media_flags' => '65548',
'media_flags' => '274877972492',
'protocol' => 'RTP/AVP',
'ptime' => '0',
'tag' => '0',
@ -927,7 +927,7 @@ $json_exp = {
'format_str' => '0 8',
'index' => '1',
'logical_intf' => 'foo',
'media_flags' => '2228236',
'media_flags' => '274880135180',
'protocol' => 'RTP/AVP',
'ptime' => '0',
'tag' => '1',
@ -1184,7 +1184,7 @@ $json_exp = {
'format_str' => '0 8',
'index' => '1',
'logical_intf' => 'foo',
'media_flags' => '2293772',
'media_flags' => '274880200716',
'protocol' => 'RTP/AVP',
'ptime' => '0',
'tag' => '1',
@ -1195,7 +1195,7 @@ $json_exp = {
'format_str' => '0 8',
'index' => '1',
'logical_intf' => 'foo',
'media_flags' => '65548',
'media_flags' => '274877972492',
'protocol' => 'RTP/AVP',
'ptime' => '0',
'tag' => '0',
@ -1473,7 +1473,7 @@ $json_exp = {
'format_str' => '0 8',
'index' => '1',
'logical_intf' => 'foo',
'media_flags' => '2293772',
'media_flags' => '274880200716',
'protocol' => 'RTP/AVP',
'ptime' => '0',
'tag' => '1',
@ -1484,7 +1484,7 @@ $json_exp = {
'format_str' => '0 8',
'index' => '1',
'logical_intf' => 'foo',
'media_flags' => '65548',
'media_flags' => '274877972492',
'protocol' => 'RTP/AVP',
'ptime' => '0',
'tag' => '0',
@ -1495,7 +1495,7 @@ $json_exp = {
'format_str' => '0 8',
'index' => '1',
'logical_intf' => 'foo',
'media_flags' => '2097156',
'media_flags' => '274880004100',
'protocol' => 'RTP/AVP',
'ptime' => '0',
'tag' => '2',
@ -1506,7 +1506,7 @@ $json_exp = {
'format_str' => '0 8',
'index' => '2',
'logical_intf' => 'foo',
'media_flags' => '2097156',
'media_flags' => '274880004100',
'protocol' => 'RTP/AVP',
'ptime' => '0',
'tag' => '2',
@ -1828,12 +1828,12 @@ a=rtcp:PORT
SDP
$json_exp->{'media-1'}{media_flags} = '2293772';
$json_exp->{'media-0'}{media_flags} = '65548';
$json_exp->{'media-1'}{media_flags} = '274880200716';
$json_exp->{'media-0'}{media_flags} = '274877972492';
$json_exp->{'media-2'}{format_str} = '8';
$json_exp->{'media-2'}{media_flags} = '2162692';
$json_exp->{'media-2'}{media_flags} = '274880069636';
$json_exp->{'media-3'}{format_str} = '8';
$json_exp->{'media-3'}{media_flags} = '2162692';
$json_exp->{'media-3'}{media_flags} = '274880069636';
$json_exp->{'payload_types-2'}[0] = '8/PCMA/8000//0/20//';
$#{$json_exp->{'payload_types-2'}} = 0;
$json_exp->{'payload_types-3'}[0] = '8/PCMA/8000//0/20//';
@ -1914,7 +1914,7 @@ $json_exp = {
'format_str' => '0 8 9',
'index' => '1',
'logical_intf' => 'foo',
'media_flags' => '65544',
'media_flags' => '274877972488',
'protocol' => 'RTP/AVP',
'ptime' => '0',
'tag' => '0',
@ -2071,7 +2071,7 @@ $json_exp = {
'format_str' => '0 8 9',
'index' => '1',
'logical_intf' => 'foo',
'media_flags' => '65544',
'media_flags' => '274877972488',
'protocol' => 'RTP/AVP',
'ptime' => '0',
'tag' => '0',
@ -2082,7 +2082,7 @@ $json_exp = {
'format_str' => '0 8 9',
'index' => '1',
'logical_intf' => 'foo',
'media_flags' => '2097156',
'media_flags' => '274880004100',
'protocol' => 'RTP/AVP',
'ptime' => '0',
'tag' => '1',
@ -2308,7 +2308,7 @@ $json_exp = {
'format_str' => '0 8 9',
'index' => '1',
'logical_intf' => 'foo',
'media_flags' => '65544',
'media_flags' => '274877972488',
'protocol' => 'RTP/AVP',
'ptime' => '0',
'tag' => '0',
@ -2319,7 +2319,7 @@ $json_exp = {
'format_str' => '0',
'index' => '1',
'logical_intf' => 'foo',
'media_flags' => '2162692',
'media_flags' => '274880069636',
'protocol' => 'RTP/AVP',
'ptime' => '0',
'tag' => '1',
@ -2559,7 +2559,7 @@ $json_exp = {
'format_str' => '0 8 9',
'index' => '1',
'logical_intf' => 'foo',
'media_flags' => '65544',
'media_flags' => '274877972488',
'protocol' => 'RTP/AVP',
'ptime' => '0',
'tag' => '0',
@ -2570,7 +2570,7 @@ $json_exp = {
'format_str' => '0',
'index' => '1',
'logical_intf' => 'foo',
'media_flags' => '2162692',
'media_flags' => '274880069636',
'protocol' => 'RTP/AVP',
'ptime' => '0',
'tag' => '1',
@ -2581,7 +2581,7 @@ $json_exp = {
'format_str' => '0 8 9',
'index' => '1',
'logical_intf' => 'foo',
'media_flags' => '2097156',
'media_flags' => '274880004100',
'protocol' => 'RTP/AVP',
'ptime' => '0',
'tag' => '2',
@ -2826,7 +2826,7 @@ a=rtcp:PORT
SDP
$json_exp->{'media-2'}{format_str} = '0';
$json_exp->{'media-2'}{media_flags} = '2162692';
$json_exp->{'media-2'}{media_flags} = '274880069636';
$json_exp->{'stream-1'}{ps_flags} = '1179649';
$json_exp->{'stream-4'}{advertised_endpoint} = '198.51.100.14:6046';
$json_exp->{'stream-4'}{endpoint} = '198.51.100.14:6046';


Loading…
Cancel
Save