Commit Graph

8727 Commits

Author SHA1 Message Date
Joshua Colp cd3a2a478f Merge "core: Improve MALLOC_DEBUG for frames." 2019-12-02 06:45:24 -06:00
Ben Ford 4a1cadeadb chan_sip.c: Prevent address change on unauthenticated SIP request.
If the name of a peer is known and a SIP request is sent using that
peer's name, the address of the peer will change even if the request
fails the authentication challenge. This means that an endpoint can
be altered and even rendered unusuable, even if it was in a working
state previously. This can only occur when the nat option is set to the
default, or auto_force_rport.

This change checks the result of authentication first to ensure it is
successful before setting the address and the nat option.

ASTERISK-28589 #close

Change-Id: I581c5ed1da60ca89f590bd70872de2b660de02df
2019-11-21 09:46:51 -06:00
Frederic LE FOLL a68299f508 chan_dahdi: PRI span status may stay "Down, Active" after a short alarm
Upon a short PRI disconnection, libpri may maintain Q.921 layer 'up' and
may thus not send PRI_EVENT_DCHAN_DOWN / PRI_EVENT_DCHAN_UP events.
If pri_event_alarm() clears DCHAN_UP status bit upon alarm detection
and no Q.921 reconnection sequence occurs, chan_dahdi will keep
seeing span status "Down" at the end of alarm.

This patch modifies pri_event_alarm() in order to keep DCHAN_UP bit
unchanged. libpri will send a PRI_EVENT_DCHAN_DOWN event if it detects
a disconnection of Q.921 layer and this will clear DCHAN_UP if required.

ASTERISK-28615

Change-Id: Ibe27df4971fd4c82cc6850020bce4a8b2692c996
2019-11-19 02:20:39 -05:00
Kevin Harwell bdd785d31c various files - fix some alerts raised by lgtm code analysis
This patch fixes several issues reported by the lgtm code analysis tool:

https://lgtm.com/projects/g/asterisk/asterisk

Not all reported issues were addressed in this patch. This patch mostly fixes
confirmed reported errors, potential problematic code points, and a few other
"low hanging" warnings or recommendations found in core supported modules.
These include, but are not limited to the following:

* innapropriate stack allocation in loops
* buffer overflows
* variable declaration "hiding" another variable declaration
* comparisons results that are always the same
* ambiguously signed bit-field members
* missing header guards

Change-Id: Id4a881686605d26c94ab5409bc70fcc21efacc25
2019-11-18 08:30:45 -06:00
Corey Farrell 8a1f30af04
core: Improve MALLOC_DEBUG for frames.
* Pass caller information to frame allocation functions.
* Disable caching as it interfers with MALLOC_DEBUG reporting.
* Stop using ast_calloc_cache.

Change-Id: Id343cd80a3db941d2daefde2a060750fea8cd260
2019-11-08 10:20:13 -05:00
Salah Ahmed ddb0091da5 Crash during "pjsip show channelstats" execution
During execution "pjsip show channelstats" cli command by an
external module asterisk crashed. It seems this is a separate
thread running to fetch and print rtp stats. The crash happened on
the ao2_lock method, just before it going to read the rtp stats on
a rtp instance. According to gdb backtrace log, it seems the
session media was already cleaned up at that moment.

ASTERISK-28578

Change-Id: I3e05980dd4694577be6d39be2c21a5736bae3c6f
2019-10-18 04:32:04 -05:00
lvl c03f50c1c8 chan_pjsip: Prevent segfault when running PlayDTMF on hungup channel
ASTERISK-28086 #close

Change-Id: Ib3baadc89b9f0477a6f25a63861433812368c5ea
2019-10-08 02:31:32 -05:00
Torrey Searle b43cdc7f1e channel/chan_pjsip: add dialplan function for music on hold
Add a new dialplan function PJSIP_MOH_PASSTHROUGH that allows
the on-hold behavior to be controlled on a per-call basis

ASTERISK-28542 #close

Change-Id: Iebe905b2ad6dbaa87ab330267147180b05a3c3a8
2019-10-01 02:06:45 -05:00
Friendly Automation 2205e25073 Merge "core: Add H.265/HEVC passthrough support" 2019-09-18 16:50:23 -05:00
Friendly Automation 0630dc3e49 Merge "chan_pjsip: Relock correct channel during "fax" redirect." 2019-09-18 07:44:27 -05:00
Florian Floimair c18983207d core: Add H.265/HEVC passthrough support
This change adds H.265/HEVC as a known codec and creates a cached
"h265" media format for use.

Note that RFC 7798 section 7.2 also describes additional SDP
parameters. Handling of these is not yet supported.

ASTERISK-28512

Change-Id: I26d262cc4110b4f7e99348a3ddc53bad0d2cd1f2
2019-09-17 13:42:26 +02:00
Guido Falsi 4072e219f7 chan_dahdi: Fix build with clang/llvm
On FreeBSD using the clang/llvm compiler build fails to build due
to the switch statement argument being a non integer type expression.
Switch to an if/else if/else construct to sidestep the issue.

ASTERISK-28536 #close

Change-Id: Idf4a82cc1e94580a2d017fe9e351c226f23e20c8
2019-09-17 05:38:59 -05:00
Joshua Colp c358da472e chan_pjsip: Relock correct channel during "fax" redirect.
When fax detection occurs on an outbound PJSIP channel the
redirect operation will result in a masquerade occurring and
the underlying channel on the session changing. The code
incorrectly relocked the new channel instead of the old
channel when returning. This resulted in the new channel
being locked indefinitely. The code now always acts on the
expected channel.

ASTERISK-28538

Change-Id: I2b2e60d07e74383ae7e90d752c036c4b02d6b3a3
2019-09-16 08:42:39 -05:00
Sean Bright 32ce6e9a06 channels: Allow updating variable value
When modifying an already defined variable in some channel drivers they
add a new variable with the same name to the list, but that value is
never used, only the first one found.

Introduce ast_variable_list_replace() and use it where appropriate.

ASTERISK-23756 #close
Patches:
  setvar-multiplie.patch submitted by Michael Goryainov

Change-Id: Ie1897a96c82b8945e752733612ee963686f32839
2019-09-12 16:00:07 -05:00
Friendly Automation bf63dcab6c Merge "chan_dahdi: set CHANNEL(hangupsource) when a PRI channel hangs up" 2019-09-11 07:13:30 -05:00
Joshua Colp a009dd1c1c Merge "chan_sip: Update links referenced in deprecation notice" 2019-09-11 07:12:48 -05:00
Frederic LE FOLL 41b67f150e chan_dahdi: set CHANNEL(hangupsource) when a PRI channel hangs up
When the remote ISDN party ends an ISDN call on a PRI link
(DISCONNECT), CHANNEL(hangupsource) information is not available.

chan_dahdi already contains an ast_set_hangupsource() in
__dahdi_exception() function but it seems that ISDN message processing
does not use this part of code.

Two other channel modules associate ast_queue_hangup() and
ast_set_hangupsource() functions calls:
- chan_pjsip in chan_pjsip_session_end() function,
- chan_sip in sip_queue_hangup_cause() function.
chan_iax2 separates them, in iax2_queue_hangup()/iax2_destroy() and
set_hangup_source_and_cause().

Thus, I propose to add ast_set_hangupsource() beside
ast_queue_hangup() in sig_pri_queue_hangup(), like chan_pjsip and
chan_sip already do.

ASTERISK-28525

Change-Id: I0f588a4bcf15ccd0648fd69830d1b801c3f21b7c
2019-09-10 10:59:26 -05:00
George Joseph 5fb9b23105 chan_sip: Update links referenced in deprecation notice
The links in the deprecation notice were the shortened
variety but it makes better sense to show the unshortened
links as they're more descriptive.

I.E.
wiki.asterisk.org/wiki/display/AST/Migrating+from+chan_sip+to+res_pjsip
rather than
wiki.asterisk.org/wiki/x/tAHOAQ

Change-Id: If2da5d5243e2d4a6f193b15691d23e7e5a7c57a9
2019-09-10 07:35:35 -05:00
Igor Goncharovsky 3863ab9af9 chan_unistim: Fix clang warning: variable sized type not at end of a struct
On reading information about initial client packet unistim use dirty
implementation of destination ip address retrieval. This fix uses
CMSG_*(..) to get ip address and make clang compile without warning.

ASTERISK-25592 #close
Reported-by: Alexander Traud

Change-Id: Ic1fd34c2c2bcc951da65bf62e3f7a8adff8351b1
2019-09-03 23:00:09 -05:00
George Joseph d3cfab159c Merge "chan_unistim: Fix code, causing all incoming DTMF sent back to asterisk" 2019-09-03 05:32:21 -05:00
Igor Goncharovsky 1d06a1efb3 chan_unistim: Fix code, causing all incoming DTMF sent back to asterisk
Current implementation of ast_channel_tech send_digit_begin hook uses
same function for tone playback as key press handler. This cause every
incoming dtmf send back to asterisk. In case of two unistim phones
connected to each other, it'll cause indefinite DTMF loop. Fix add
separate function for dtmf tone phone play.

Change-Id: I5795db468df552f0c89c7576b6b3858b26c4eab4
2019-08-27 02:53:21 -05:00
Igor Goncharovsky 649003821e chan_unistim: Fix RTP port byte order for big-endian arch
This patch fixes one-way oudio that users expirienced on
big-endian architechtires. RTP port number bytes was stored
in improper order and phone sent RTP to wrong RTP port.

Reported-by: Andrey Ionov
Change-Id: I9a9ca7f26e31a67bbbceff12923baa10dfb8a3be
2019-08-26 04:49:42 -05:00
George Joseph 19045db392 chan_rtp: Accept hostname as well as ip address as destination
The UnicastRTP channel driver provided by chan_rtp now accepts
"<hostname>:<port>" as an alternative to "<ip_address>:<port>"
in the destination. The first AAAA (preferred) or A record resolved
will be used as the destination. The lookup is synchronous so beware
of possible dialplan delays if you specify a hostname.

Change-Id: Ie6f95b983a8792bf0dacc64c7953a41032dba677
2019-08-22 07:39:50 -05:00
Kevin Harwell 3656c42cb0 various modules: json integer overflow
There were still a few places in the code that could overflow when "packing"
a json object with a value outside the base type integer's range. For instance:

unsigned int value = INT_MAX + 1
ast_json_pack("{s: i}", value);

would result in a negative number being "packed". In those situations this patch
alters those values to a ast_json_int_t, which widens the value up to a long or
long long.

ASTERISK-28480

Change-Id: Ied530780d83e6f1772adba0e28d8938ef30c49a1
2019-08-01 15:31:48 -06:00
Friendly Automation 7646f4196b Merge "openr2(6/6): Set hangup cause" 2019-07-23 19:32:57 -05:00
George Joseph 96a2ce1a0d Merge "openr2(5/6): added cli command -- mfcr2 destroy link <index>" 2019-07-23 18:43:00 -05:00
George Joseph 64b6d0fc28 Merge "openr2(4/6): added new cli command -- mfcr2 show links" 2019-07-23 17:28:59 -05:00
Friendly Automation d24d94beba Merge "openr2(3/6): Convert r2links to standard Asterisk AST_LIST*" 2019-07-23 15:26:30 -05:00
George Joseph 8c3ed46829 Merge "openr2(2/6): Stop polling channels when DAHDI returns -ENODEV (e.g: plug-out)" 2019-07-23 14:26:00 -05:00
George Joseph 497308b5d9 Merge "openr2(1/6): bugfix in configuration saving" 2019-07-23 13:02:42 -05:00
George Joseph 799c4cf494 Merge "chan_pjsip: Transmit REFER waits for the REFER result setting TRANSFERSTATUS" 2019-07-23 09:18:42 -05:00
Leonid Fainshtein 098797628e openr2(6/6): Set hangup cause
Change-Id: I94dc38920e6e77cc73062648f62fdd613d0d1452
Signed-off-by: Oron Peled <oron.peled@xorcom.com>
2019-07-22 21:11:12 +03:00
Tzafrir Cohen f67094503d openr2(5/6): added cli command -- mfcr2 destroy link <index>
Change-Id: I452d6a853bcd8c6e194455b19e5e017713e9c0fe
Signed-off-by: Oron Peled <oron.peled@xorcom.com>
2019-07-22 21:11:12 +03:00
Tzafrir Cohen 64bf3e3e82 openr2(4/6): added new cli command -- mfcr2 show links
* This command show the MFC/R2 links

Change-Id: I213822e1b7ef9c05bd89a2ba62df8e0856ce9f84
Signed-off-by: Oron Peled <oron.peled@xorcom.com>
2019-07-22 21:11:12 +03:00
Tzafrir Cohen f61adf2cf5 openr2(3/6): Convert r2links to standard Asterisk AST_LIST*
Change-Id: Ibcb2401515a58782a1488c0b9efbed201c3f3a17
Signed-off-by: Oron Peled <oron.peled@xorcom.com>
2019-07-22 21:11:12 +03:00
Tzafrir Cohen 97d2549bb1 openr2(2/6): Stop polling channels when DAHDI returns -ENODEV (e.g: plug-out)
Otherwise, OpenR2 threads go crazy and consume almost all CPU resources

Change-Id: I10a41f617613fe7399c5bdced5c64a2751173f28
Signed-off-by: Oron Peled <oron.peled@xorcom.com>
2019-07-22 21:11:12 +03:00
Tzafrir Cohen 2f0a8e12f9 openr2(1/6): bugfix in configuration saving
Details:
  - The memcpy() call copied part of "dahdi_conf" and not "dahdi_conf.mfcr2"
  - As a result, the memcmp() in dahdi_r2_get_link() always fails
  - This cause dahdi_r2_get_link() to create new link for every channel
    (instead of a new link for every ~30 channels)
  - With the fix, far less links are generated -- so we use far less threads

Change-Id: I7259dd6272f5e46e8a6c7f5bf3e8c2ec01b8c132
Signed-off-by: Oron Peled <oron.peled@xorcom.com>
2019-07-22 21:11:12 +03:00
Kevin Harwell 857ee76f4b Merge "MWI: Update modules that subscribe to MWI to use new API calls" 2019-07-12 09:19:18 -05:00
Francesco Castellano 8438d19b81 chan_sip: Handle invalid SDP answer to T.38 re-invite
The chan_sip module performs a T.38 re-invite using a single media
stream of udptl, and expects the SDP answer to be the same.

If an SDP answer is received instead that contains an additional
media stream with no joint codec a crash will occur as the code
assumes that at least one joint codec will exist in this
scenario.

This change removes this assumption.

ASTERISK-28465

Change-Id: I8b02845b53344c6babe867a3f0a5231045c7ac87
2019-07-11 11:16:37 -05:00
Kevin Harwell 9637e1dfdc MWI: Update modules that subscribe to MWI to use new API calls
The MWI core recently got some new API calls that make tracking MWI state
lifetime more reliable. This patch updates those modules that subscribe to
specific MWI topics to use the new API. Specifically, these modules now
subscribe to both MWI topics and MWI state.

ASTERISK-28442

Change-Id: I32bef880b647246823dbccdf44a98d384fcabfbd
2019-07-08 18:12:49 -05:00
Chris-Savinovich 0e669712e2 chan_dahdi.c: crash in chan_dahdi
Fixes a crash in chan_dahdi occurring on 32-bit systems. A previous
patch introduced a variable of type unassigned long long which is 64-bits.
Casting it as 'ast_json_int_t' along with JSON type 'I' makes it work
with 32-bit systems.

ASTERISK-28457

Change-Id: I9cef6b5f2d826fc5c93f2f6a1c997c4e3e6c93fe
2019-07-01 16:06:34 -06:00
Dan Cropp e52fbae00f chan_pjsip: Transmit REFER waits for the REFER result setting TRANSFERSTATUS
Previously, when a Transfer (REFER) was performed, chan_pjsip would set
the TRANSFERSTATUS to SUCCESS when the REFER was queued up.  This did not
reflect a successful/unsuccessful transfer the way chan_sip did.
Added a callback module to process the refer subscription information.

Now depends on res_pjsip_pubsub so call transfer progress can be monitored
and reported

ASTERISK-26968 #close
Reported-by: Dan Cropp

Change-Id: If6c27c757c66f71e8b75e3fe49da53ebe62395dc
2019-06-25 09:54:41 -05:00
George Joseph 13e89d372b sig_pri: Address gcc9 issues
A few more format truncation issues addressed.

Change-Id: I047f373169caaca0eec4889d3c0e5e10f130017a
2019-06-24 07:31:11 -06:00
George Joseph 92d4ec2906 chan_dahdi: Address gcc9 issues
Fixed format-truncation issues in chan_dahdi.c and
sig_analog.c.  Since they're related to fields provided
by dahdi-tools we can't change the buffer sizes so we're just
checking the return from snprintf and printing an errior if we
overflow.

Change-Id: Idc1f3c1565b88a7d145332a0196074b5832864e5
2019-06-17 12:58:48 -06:00
agupta d2f7b22640 chan_pjsip.c: Check for channel and session to not be NULL in hangup
We have seen some rare case of segmentation fault in hangup function
and we could notice that channel pointer was NULL.  Debug log shows
that there is a 200 OK answer and SIP timeout at the same time.  It
looks that while the SIP session was being destroyed due to timeout
call hangup due to answer event lead to race condition and channel
is being destroyed from two different places.  The check ensures we
check it not to be NULL before freeing it.

ASTERISK-25371

Change-Id: I19f6566830640625e08f7b87bfe15758ad33a778
2019-06-10 06:41:06 -06:00
George Joseph 216cc44e8e Merge "pjsip: replace 180 by 183 if SDP negotiation has completed" 2019-06-03 09:36:43 -05:00
Guido Falsi db535439f2 chan_dahdi: add missing include.
After some definitions have been moved to asterisk/mwi.h the files
channels/chan_dahdi.h channels/sig_pri.c are missing this new
include.

ASTERISK-28427 #close

Change-Id: Ia8cc595eeda653324643f40dcd9799d4c3f0ac91
2019-05-23 08:50:11 -06:00
Alexei Gradinari 466a17964f pjsip: replace 180 by 183 if SDP negotiation has completed
The caller endpoint hears dead silence if a callee replies 180 (without SDP)
and the caller already received 183 (with SDP).
It happens because Asterisk sends 180 (WITH SDP) to the caller,
there are not incoming RTP packets from the callee
and Asterisk does not generate inband ringing,
so there are not any outgoing RTP packets to the caller.

This patch replaces 180 by 183 if SDP negotiation has completed,
as if the caller endpoint is configured with "inband_progress=yes".

In this case Asterisk will generate inband ringing untill Asterisk receive
incoming RTP packets from the callee.

ASTERISK-27994 #close

Change-Id: I7450b751083ec30d68d6abffe922215a15ae5a73
2019-05-16 08:47:45 -06:00
George Joseph c5c953c1f1 Fixes for GCC 9
Various fixes for issues caught by gcc 9.  Mostly snprintf
trying to copy to a buffer potentially too small.

ASTERISK-28412

Change-Id: I9e85a60f3c81d46df16cfdd1c329ce63432cf32e
2019-05-10 10:22:55 -06:00
Kevin Harwell ff0d0ac23a mwi core: Move core MWI functionality into its own files
There is enough MWI functionality to warrant it having its own 'c' and header
files. This patch moves all current core MWI data structures, and functions
into the following files:

main/mwi.h
main/mwi.c

Note, code was simply moved, and not modified. However, this patch is also in
preparation for core MWI changes, and additions to come.

Change-Id: I9dde8bfae1e7ec254fa63166e090f77e4d3097e0
2019-04-23 17:40:15 -05:00
Salah Ahmed 5009d6d97a chan_pjsip: DTMF Mode auto_info fallback lead to both inband and info
When the dtmf_mode on an endpoint is configured as "auto_info"
Asterisk will produce an inband DTMF tone alongside an INFO
message when sending DTMF.

ASTERISK-28371

Change-Id: I1380b82f006e110a1b83fbb50c9873edd13a5d9a
2019-04-05 09:43:15 -06:00
Ben Ford dd1cc7791c build: Fix compiler warnings/errors.
The compiler complained about a couple of variables that weren't
initialized but were being used. Initializing them to NULL resolves the
warnings/errors.

ASTERISK-28362 #close

Change-Id: I6243afc5459b416edff6bbf571b0489f6b852e4b
2019-04-03 09:36:51 -06:00
Alexei Gradinari f236377ce9 pjsip: restrict function PJSIP_PARSE_URI to parse only SIP/SIPS URIs
The next usage of PJSIP_PARSE_URI will crash asterisk
${PJSIP_PARSE_URI(tel:+1234567890,host)}
or
${PJSIP_PARSE_URI(192.168.1.1:5060,host)}

The function pjsip_parse_uri successfully parses then, but returns
struct pjsip_other_uri *.

This patch restricts parsing only SIP/SIPS URIs.

Change-Id: I16f255c2b86a80a67e9f9604b94b129a381dd25e
2019-03-27 10:07:47 -06:00
Sean Bright 1499640da9 chan_sip: Ensure 'qualifygap' isn't negative
Passing negative intervals to the scheduler rips a hole in the
space-time continuum.

ASTERISK-25792 #close
Reported by: Paul Sandys

Change-Id: Ie706f21cee05f76ffb6f7d89e9c867930ee7bcd7
2019-03-25 13:32:47 -06:00
Kevin Harwell 8f5a6ed52d Merge "chan_dahdi: Add logical group at DAHDIChannel event and CHANNEL function" 2019-03-13 10:55:20 -05:00
cirillor 0d6d51b175 chan_dahdi: Add logical group at DAHDIChannel event and CHANNEL function
Add logical group at DAHDIChannel event
and create "dahdi_group" at CHANNEL function.

ASTERISK-28317

Change-Id: Ic1f834cd53982a9707a9748395ee746d6575086a
2019-03-11 06:32:24 -06:00
Torrey Searle 4661c08549 chan_pjsip: add a flag to ignore 183 responses if no SDP present
chan_sip will always ignore 183 responses that do not contain SDP
however, chan_pjsip will currently always translate it into a
183 with SDP.  This new flag allows chan_pjsip to have the same
behavior as chan_sip.

ASTERISK-28322 #close

Change-Id: If81cfaa17c11b6ac703e3d71696f259d86c6be4a
2019-03-08 14:16:30 -05:00
Sean Bright 2473b791b9 Replace calls to strtok() with strtok_r()
strtok() uses a static buffer, making it not thread safe.

Also add a #define to cause a compile failure if strtok is used.

Change-Id: Icce265153e1e65adafa8849334438ab6d190e541
2019-03-07 16:44:50 -06:00
sungtae kim fb651756c7 chan_pjsip: Changed to continued after invalid media for pjsip show channelstats
Currently, the pjsip show channelstats cli does not show channel's
stats after hits the invalid channel info. This makes hard to use
this cli. Changed to keep iterate after hits the invalid channel
info.

ASTERISK-28292

Change-Id: I3efdff1c9e1b1efd3c971fb82ae77aa133a6f43c
2019-02-15 00:12:23 +01:00
Giuseppe Sucameli 0bde3751a0 chan_sip: Fix leak using contact ACL
Free old peer's contactacl before overwrite it within build_peer.

ASTERISK-28194

Change-Id: Ie580db6494e50cee0e2a44b38e568e34116ff54c
2018-12-05 17:17:57 -05:00
Joshua Colp 50ac85cb40 stasis: Segment channel snapshot to reduce creation cost.
When a channel snapshot was created it used to be done
from scratch, copying all data (many strings). This incurs
a cost when doing so.

This change segments the channel snapshot into different
components which can be reused if unchanged from the
previous snapshot creation, reducing the cost. In normal
cases this results in some pointers being copied with
reference count being bumped, some integers being set,
and a string or two copied. The other benefit is that it
is now possible to determine if a channel snapshot update
is redundant and thus stop it before a message is published
to stasis.

The specific segments in the channel snapshot were split up
based on whether they are changed together, how often they
are changed, and their general grouping. In practice only
1 (or 0) of the segments actually get changed in normal
operation.

Invalidation is done by setting a flag on the channel when
the segment source is changed, forcing creation of a new
segment when the channel snapshot is created.

ASTERISK-28119

Change-Id: I5d7ef3df963a88ac47bc187d73c5225c315f8423
2018-11-26 12:56:24 -06:00
Joshua Colp d0ccbb3377 stasis: Use an implementation specific channel snapshot cache.
Channels no longer use the Stasis cache for channel snapshots. Instead
they are stored in a hash table in stasis_channels which reduces the
number of Stasis messages created and allows better storage.

As a result the following APIs are no longer available since the stasis
cache is no longer used:
ast_channel_topic_cached()
ast_channel_topic_all_cached()

The ast_channel_cache_all() and ast_channel_cache_by_name() functions
now return an ao2_container of ast_channel_snapshots rather than
a container of stasis_messages therefore you can't (and don't need
to) call stasis_cache functions on it.

The ast_channel_topic_all() function now returns a normal topic not
a cached one so you can't use stasis cache functions on it either.

The ast_channel_snapshot_type() stasis message now has the
ast_channel_snapshot_update structure as it's data. It contains the
last snapshot and the new one.

ast_channel_snapshot_get_latest() still returns the latest snapshot.

The latest snapshot is now stored on the channel itself to eliminate
cache hits when Stasis messages that have the snapshot as a payload
are created.

ASTERISK-28102

Change-Id: I9334febff60a82d7c39703e49059fa3a68825786
2018-11-26 18:43:53 +00:00
Corey Farrell 021ce938ca
astobj2: Remove legacy ao2_container_alloc routine.
Replace usage of ao2_container_alloc with ao2_container_alloc_hash or
ao2_container_alloc_list.  Remove ao2_container_alloc macro.

Change-Id: I0907d78bc66efc775672df37c8faad00f2f6c088
2018-11-21 09:56:16 -05:00
Joshua Colp 614c8a60d7 Merge "stasis: Add internal filtering of messages." 2018-11-19 08:36:50 -06:00
Alexei Gradinari fa048183aa pjsip: New function PJSIP_PARSE_URI to parse URI and return part of URI
New dialplan function PJSIP_PARSE_URI added to parse an URI and return
a specified part of the URI.

This is useful when need to get part of the URI instead of cutting it
using a CUT function.

For example to get 'user' part of Remote URI
${PJSIP_PARSE_URI(${CHANNEL(pjsip,remote_uri)},user)}

ASTERISK-28144 #close

Change-Id: I5d828fb87f6803b6c1152bb7b44835f027bb9d5a
2018-11-18 15:27:48 -05:00
Joshua Colp 3077ad0c24 stasis: Add internal filtering of messages.
This change adds the ability for subscriptions to indicate
which message types they are interested in accepting. By
doing so the filtering is done before being dispatched
to the subscriber, reducing the amount of work that has
to be done.

This is optional and if a subscriber does not add
message types they wish to accept and set the subscription
to selective filtering the previous behavior is preserved
and they receive all messages.

There is also the ability to explicitly force the reception
of all messages for cases such as AMI or ARI where a large
number of messages are expected that are then generically
converted into a different format.

ASTERISK-28103

Change-Id: I99bee23895baa0a117985d51683f7963b77aa190
2018-11-18 15:08:16 -05:00
Jasper Hafkenscheid 2cf5079205 chan_sip: Attempt ast_do_pickup in handle_invite_replaces
When a call pickup is performed using and invite with replaces header
the ast_do_pickup method is attempted and a PICKUP stasis message is sent.

ASTERISK-28081 #close
Reported-by: Luit van Drongelen

Change-Id: Ieb1442027a3ce6ae55faca47bc095e53972f947a
2018-11-02 10:21:52 -05:00
George Joseph 26810197c7 Merge "pjsip: new endpoint's options to control Connected Line updates" 2018-10-31 13:57:15 -05:00
Alexei Gradinari eee935983b pjsip: new endpoint's options to control Connected Line updates
This patch adds new options 'trust_connected_line' and 'send_connected_line'
to the endpoint.

The option 'trust_connected_line' is to control if connected line updates
are accepted from this endpoint.

The option 'send_connected_line' is to control if connected line updates
can be sent to this endpoint.

The default value is 'yes' for both options.

Change-Id: I16af967815efd904597ec2f033337e4333d097cd
2018-10-30 10:39:28 -05:00
Corey Farrell 90a11c4ae7
chan_sip deprecation.
This officially deprecates chan_sip in Asterisk 17+.  A warning is
printed upon startup or module load to tell users that they should
consider migrating.  chan_sip is still built by default but the default
modules.conf skips loading it at startup.

Very important to note we are not scheduling a time where chan_sip will
be removed.  The goal of this change is to accurately inform end users
of the current state of chan_sip and encourage movement to the fully
supported chan_pjsip.

Change-Id: Icebd8848f63feab94ef882d36b2e99d73155af93
2018-10-25 08:57:16 -04:00
Corey Farrell 687ab7aeee
astobj2: Eliminate legacy container allocation macros.
These macros have been documented as legacy for a long time but are
still used in new code because they exist.  Remove all references to:
* ao2_container_alloc_options
* ao2_t_container_alloc_options
* ao2_t_container_alloc

These macro's are also removed.  Only ao2_container_alloc remains due to
it's use in over 100 places.

Change-Id: I1a26258b5bf3deb081aaeed11a0baa175c933c7a
2018-10-19 17:33:05 -04:00
pk16208 6627c56b3d chan_sip: SipNotify on Chan_Sip vi AMI behave different to CLI
With tls and udp enabled asterisk generates a warning about sending
message via udp instead of tls.
sip notify command via cli works as expected and without warning.

asterisk has to set the connection information accordingly to connection
and not on presumption

ASTERISK-28057 #close

Change-Id: Ib43315aba1f2c14ba077b52d8c5b00be0006656e
2018-09-26 07:28:05 -05:00
hajekd 406be41f21 chan_sip.c: chan_sip unstable with TLS after asterisk start or reloads
Fixes random asterisk crash on start or reload with TLS phones.

ASTERISK-28034 #close
Reported-by: David Hajek

Change-Id: I2a859f97dc80c348e2fa56e918214ee29521c4ac
2018-09-20 09:00:55 -05:00
George Joseph 1ca54b18dd Merge "chan_sip: improved ip:port finding of peers for non-UDP transports." 2018-08-27 07:17:39 -05:00
Jaco Kroon 9680790531 chan_sip: improved ip:port finding of peers for non-UDP transports.
Also remove function peer_ipcmp_cb since it's not used (according to
rmudgett).

Prior to b2c4e8660a (ASTERISK_27457)
insecure=port was the defacto standard.  That commit also prevented
insecure=port from being applied for sip/tcp or sip/tls.

Into consideration there are three sets of behaviour:

1.  "previous" - before the above commit.
2.  "current" - post above commit, pre this one.
3.  "new" - post this commit.

The problem that the above commit tried to address was guests over TCP.
It succeeded in doing that but broke transport!=udp with host!=dynamic.

This commit attempts to restore sane behaviour with respect to
transport!=udp for host!=dynamic whilst still retaining the guest users
over tcp.

It should be noted that when looking for a peer, two passes are made, the
first pass doesn't have SIP_INSECURE_PORT set for the searched-for peer,
thus looking for full matches (IP + Port), the second pass sets
SIP_INSECURE_PORT, thus expecting matches on IP only where the matched
peer allows for that (in the author's opinion:  UDP with insecure=port,
or any TCP based, non-dynamic host).

In previous behaviour there was special handling for transport=tcp|tls
whereby a peer would match during the first pass if the utilized
transport was TCP|TLS (and the peer allowed that specific transport).

This behaviour was wrong, or dubious at best.  Consider two dynamic tcp
peers, both registering from the same IP (NAT), in this case either peer
could match for connections from an IP.  It's also this behaviour that
prevented SIP guests over tcp.

The above referenced commit removed this behaviour, but kept applying
the SIP_INSECURE_PORT only to WS|WSS|UDP.  Since WS and WSS is also TCP
based, the logic here should fall into the TCP category.

This patch updates things such that the previously non-explicit (TCP
behaviour) transport test gets performed explicitly (ie, matched peer
must allow for the used transport), as well as the indeterministic
source-port nature of the TCP protocol is taken into account.  The new
match algorithm now looks like:

1.  As per previous behaviour, IP address is matched first.

2.  Explicit filter with respect to transport protocol, previous
    behaviour was semi-implied in the test for TCP pure IP match - this now
    made explicit.

3.  During first pass (without SIP_INSECURE_PORT), always match on port.

4.  If doing UDP, match if matched against peer also has
    SIP_INSECURE_PORT, else don't match.

5.  Match if not a dynamic host (for non-UDP protocols)

6.  Don't match if this is WS|WSS, or we can't trust the Contact address
    (presumably due to NAT)

7.  Match (we have a valid Contact thus if the IP matches we have no
    choice, this will likely only apply to non-NAT).

To logic-test this we need a few different scenarios.  Towards this end,
I work with a set number of peers defined in sip.conf:

[peer1]
host=1.1.1.1
transport=tcp

[peer2]
host=1.1.1.1
transport=udp

[peer3]
host=1.1.1.1
port=5061
insecure=port
transport=udp

[peer4]
host=1.1.1.2
transport=udp,tcp

[peer5]
host=dynamic
transport=udp,tcp

Test cases for UDP:

1 - incoming UDP request from 1.1.1.1:
  - previous:
    - pass 1:
      * peer1 or peer2 if from port 5060 (indeterminate, depends on peer
        ordering)
      * peer3 if from port 5061
      * peer5 if registered from 1.1.1.1 and source port matches
    - pass 2:
      * peer3
  - current: as per previous.
  - new:
    - pass 1:
      * peer2 if from port 5060
      * peer3 if from port 5061
      * peer5 if registered from 1.1.1.1 and source port matches
    - pass 2:
      * peer3

2 - incoming UDP request from 1.1.1.2:
  - previous:
    - pass 1:
      * peer5 if registered from 1.1.1.2 and port matches
      * peer4 if source port is 5060
    - pass 2:
      * no match (guest)
  - current: as previous.
  - new as previous (with the variation that if peer5 didn't have udp as
          allowed transport it would not match peer5 whereas previous
          and current code could).

3 - incoming UDP request from anywhere else:
  - previous:
    - pass 1:
      * peer5 if registered from that address and source port matches.
    - pass 2:
      * peer5 if insecure=port is additionally set.
      * no match (guest)
  - current - as per previous
  - new - as per previous

Test cases for TCP based transports:

4 - incoming TCP request from 1.1.1.1
  - previous:
    - pass 1 (indeterministic, depends on ordering of peers in memory):
      * peer1; or
      * peer5 if peer5 registered from 1.1.1.1 (irrespective of source port); or
      * peer2 if the source port happens to be 5060; or
      * peer3 if the source port happens to be 5061.
    - pass 2: cannot happen since pass 1 will always find a peer.
  - current:
    - pass 1:
      * peer1 or peer2 if from source port 5060
      * peer3 if from source port 5060
      * peer5 if registered as 1.1.1.1 and source port matches
    - pass 2:
      * no match (guest)
  - new:
    - pass 1:
      * peer 1 if from port 5060
      * peer 5 if registered and source port matches
    - pass 2:
      * peer 1

5 - incoming TCP request from 1.1.1.2
  - previous (indeterminate, depends on ordering):
    - pass 1:
      * peer4; or
      * peer5 if peer5 registered from 1.1.1.2
    - pass 2: cannot happen since pass 1 will always find a peer.
  - current:
    - pass 1:
      * peer4 if source port is 5060
      * peer5 if peer5 registered as 1.1.1.2 and source port matches
    - pass 2:
      * no match (guest).
  - new:
    - pass 1:
      * peer4 if source port is 5060
      * peer5 if peer5 registered as 1.1.1.2 and source port matches
    - pass 2:
      * peer4

6 - incoming TCP request from anywhere else:
  - previous:
    - pass 1:
      * peer5 if registered from that address
    - pass 2: cannot happen since pass 1 will always find a peer.
  - current:
    - pass 1:
      * peer5 if registered from that address and port matches.
    - pass 2:
      * no match (guest)
  - new: as per current.

It should be noted the test cases don't make explicit mention of TLS, WS
or WSS.  WS and WSS previously followed UDP semantics, they will now
enforce source port matching.  TLS follow TCP semantics.

The previous commit specifically tried to address test-case 6, but broke
test-cases 4 and 5 in the process.

ASTERISK-27881 #close

Change-Id: I61a9804e4feba9c7224c481f7a10bf7eb7c7f2a2
2018-08-24 01:23:46 -05:00
Jenkins2 5241a53acd Merge "Build System: Improve ccache matching for different menuselect options." 2018-08-14 13:41:32 -05:00
Salah Ahmed a90177cd63 dialplan_functions: wrong srtp use status report of a dialplan function
If asterisk offer an endpoint with SRTP and that endpoint respond
with non srtp, in that case channel(rtp,secure,audio) reply wrong
status.

Why delete flag AST_SRTP_CRYPTO_OFFER_OK while check identical remote_key:
Currently this flag has being set redundantly. In either case identical
or different remote_key this flag has being set. So if we
don't set it while we receive identical remote_key or non SRTP SDP
response then we can take decision of srtp use by using that flag.

ASTERISK-27999

Change-Id: I29dc2843cf4e5ae2604301cb4ff258f1822dc2d7
2018-08-03 13:50:04 -05:00
Corey Farrell a10a3aff6a Build System: Improve ccache matching for different menuselect options.
Changing any Menuselect option in the `Compiler Flags` section causes a
full rebuild of the Asterisk source tree.  Every enabled option causes
a #define to be added to buildopts.h, thus breaking ccache caching for
every source file that includes "asterisk.h".  In most cases each option
only applies to one or two files.  Now we only define those options for
the specific sources which use them, this causes much better cache
matching when working with multiple builds.  For example testing code
with an without MALLOC_DEBUG will now use just over half the ccache
size, only main/astmm.o will have two builds cached instead of every
file.

Reorder main/Makefile so _ASTCFLAGS set on specific object files are all
together, sorted by filename.  Stop adding -DMALLOC_DEBUG to CFLAGS of
bundled pjproject, this define is no longer used by any header so only
serves to break cache.

The only code change is a slight adjustment to how main/astmm.c is
initialized.  Initialization functions always exist so main/asterisk.c
can call them unconditionally.  Additionally rename the astmm
initialization functions so they are not exported.

Change-Id: Ie2085237a964f6e1e6fff55ed046e2afff83c027
2018-08-01 12:01:15 -04:00
Joshua Colp 134e2f0ddc module: Remove deprecated modules and update support levels.
I have removed the STATIC_BUILD option immediately as it has not
been maintained in many years and is non-functional.

ASTERISK-27965

Change-Id: I64783d017b86dba9ee3c7bcfb97e59889a3f76d7
2018-07-18 18:15:53 +00:00
Alexander Traud 9704c424f5 chan_oss: Compile in Solaris 11.
M_READ existed already and was conflicting in name.

Change-Id: I02108e07ae7d2dc314fe1e6c706c17731095a3e4
2018-06-21 12:07:21 +02:00
Richard Mudgett a470bb9e27 channel: Fix some more unprotected channel flag setting.
Change-Id: I34c3b1201b1de539945bcfdcb264fff30332d48c
2018-06-18 09:55:59 -06:00
ktyerman e1908ea484 chan_iax2: better handling for timeout and EINTR
The iax2 module is not handling timeout and EINTR case properly. Mainly when
there is an interupt to the kernel thread. In case of ast_io_wait recieves a
signal, or timeout it can be an error or return 0 which eventually escapes the
thread loop, so that it cant recieve any data. This then causes the modules
receive queue to build up on the kernel and stop any communications via iax in
asterisk.

The proposed patch is for the iax module, so that timeout and EINTR does not
exit the thread.

ASTERISK-27705
Reported-by: Kirsty Tyerman

Change-Id: Ib4c32562f69335869adc1783608e940c3535fbfb
2018-06-13 16:47:02 -06:00
Jenkins2 076ff479ac Merge "crypto.h: Repair ./configure --with-ssl=PATH." 2018-06-12 09:53:15 -05:00
Alexander Traud 99aed78078 crypto.h: Repair ./configure --with-ssl=PATH.
ASTERISK-27908

Change-Id: Iac49d9f82faeb8a4611c6805906bd6d650b1b1d8
2018-06-08 13:01:53 +02:00
George Joseph 1725eaf8fb chan_pjsip: Register for "BEFORE_MEDIA" responses
chan_pjsip wasn't registering for "BEFORE_MEDIA" responses which meant
it was not updating HANGUPCAUSE for 4XX responses.  If the remote end
sent a "180 Ringing", then a "486 Busy", the hangup cause was left at
"180 Normal Clearing".

* Removed chan_pjsip_incoming_response from the original session
  supplement (which was handling only "AFTER MEDIA") and added it to a
  new session supplement which accepts both "BEFORE_MEDIA" and
  "AFTER_MEDIA".

* Also cleaned up some cleanup code in load module.

ASTERISK-27902

Change-Id: If9b860541887aca8ac2c9f2ed51ceb0550fb007a
2018-06-07 08:31:45 -06:00
Joshua Colp 25764691b0 Merge "netsock2: Add ast_sockaddr_resolve_first_af to netsock2 public API" 2018-05-23 12:10:13 -05:00
Matthew Fredrickson 9f9dce05b2 netsock2: Add ast_sockaddr_resolve_first_af to netsock2 public API
This function originally was used in chan_sip to enable some simplifying
assumptions and eventually was copy and pasted into res_pjsip_logger and
res_hep.  Since it's replicated in three places, it's probably best to
move it into the public netsock2 API for these modules to use.

Change-Id: Id52e23be885601c51d70259f62de1a5e59d38d04
2018-05-21 11:03:10 -05:00
Corey Farrell b5914d90ac Fix GCC 8 build issues.
This fixes build warnings found by GCC 8.  In some cases format
truncation is intentional so the warning is just suppressed.

ASTERISK-27824 #close

Change-Id: I724f146cbddba8b86619d4c4a9931ee877995c84
2018-05-11 09:48:58 -04:00
Tzafrir Cohen 6301531416 chan_dahdi: Configurable dialed digit timeouts
Analog phones dial overlap dialing and it is chan_dahdi's job to read the
numbers.  It has three timeout constants that this commit converts to
channel-level configuration options:

* firstdigit_timeout: Default time (ms) to detect first digit

* interdigit_timeout: Default time (ms) to detect following digits

* matchdigit_timeout: Default time (ms) to wait in case of ambiguous
match.  This happens when the dialed digits match a number in the current
context but are also the prefix of another number.

Change-Id: Ib728fa900a4f6ae56d1ed810aba61b6593fb7213
2018-05-03 10:34:12 -05:00
George Joseph 3bad41257b Merge "BuildSystem: Add DragonFly BSD." 2018-04-30 09:07:30 -05:00
Jenkins2 9c430569d4 Merge "bridge_softmix: Forward TEXT frames" 2018-04-27 10:06:30 -05:00
Alexander Traud efe40ff671 BuildSystem: Add DragonFly BSD.
ASTERISK-27820

Change-Id: I310896143e94d65da1c2be3bb448204a8b86d557
2018-04-20 12:50:03 +02:00
George Joseph 4fb7967c73 bridge_softmix: Forward TEXT frames
Core bridging and, more specifically, bridge_softmix have been
enhanced to relay received frames of type TEXT or TEXT_DATA to all
participants in a softmix bridge.  res_pjsip_messaging and
chan_pjsip have been enhanced to take advantage of this so when
res_pjsip_messaging receives an in-dialog MESSAGE message from a
user in a conference call, it's relayed to all other participants
in the call.

res_pjsip_messaging already queues TEXT frames to the channel when
it receives an in-dialog MESSAGE from an endpoint and chan_pjsip
will send an MESSAGE when it gets a TEXT frame.  On a normal
point-to-point call, the frames are forwarded between the two
correctly.  bridge_softmix was not though so messages weren't
getting forwarded to conference bridge participants.  Even if they
were, the bridging code had no way to tell the participants who
sent the message so it would look like it came from the bridge
itself.

* The TEXT frame type doesn't allow storage of any meta data, such
as sender, on the frame so a new TEXT_DATA frame type was added that
uses the new ast_msg_data structure as its payload.  A channel
driver can queue a frame of that type when it receives a message
from outside.  A channel driver can use it for sending messages
by implementing the new send_text_data channel tech callback and
setting the new AST_CHAN_TP_SEND_TEXT_DATA flag in its tech
properties.  If set, the bridging/channel core will use it instead
of the original send_text callback and it will get the ast_msg_data
structure. Channel drivers aren't required to implement this.  Even
if a TEXT_DATA enabled driver uses it for incoming messages, an
outgoing channel driver that doesn't will still have it's send_text
callback called with only the message text just as before.

* res_pjsip_messaging now creates a TEXT_DATA frame for incoming
in-dialog messages and sets the "from" to the display name in the
"From" header, or if that's empty, the caller id name from the
channel.  This allows the chat client user to set a friendly name
for the chat.

* bridge_softmix now forwards TEXT and TEXT_DATA frames to all
participants (except the sender).

* A new function "ast_sendtext_data" was added to channel which
takes an ast_msg_data structure and calls a channel's
send_text_data callback, or if that's not defined, the original
send_text callback.

* bridge_channel now calls ast_sendtext_data for TEXT_DATA frame
types and ast_sendtext for TEXT frame types.

* chan_pjsip now uses the "from" name in the ast_msg_data structure
(if it exists) to set the "From" header display name on outgoing text
messages.

Change-Id: Idacf5900bfd5f22ab8cd235aa56dfad090d18489
2018-04-17 10:30:23 -06:00
Alexander Traud 3d9345e3ae chan_vpb: Avoid GNU old-style field designator extension.
clang 6.0 warned about this. Beside that, this change removes the used variable
'desc'.

ASTERISK-27808

Change-Id: Ia26bdcc0a562c058151814511cfcf70ecafa595b
2018-04-17 12:41:40 +02:00
Richard Mudgett 237d341bbd res_pjsip.c: Split ast_sip_push_task_synchronous() to fit expectations.
ast_sip_push_task_synchronous() did not necessarily execute the passed in
task under the specified serializer.  If the current thread is any
registered pjsip thread then it would execute the task immediately instead
of under the specified serializer.  Reentrancy issues could result if the
task does not execute with the right serializer.

The original reason ast_sip_push_task_synchronous() checked to see if the
current thread was a registered pjsip thread was because of a deadlock
with masquerades and the channel technology's fixup callback
(ASTERISK_22936).  A subsequent masquerade deadlock fix (ASTERISK_24356)
involving call pickups avoided the original deadlock situation entirely.
The PJSIP channel technology's fixup callback no longer needed to call
ast_sip_push_task_synchronous().

However, there are a few places where this unexpected behavior is still
required to avoid deadlocks.  The pjsip monitor thread executes callbacks
that do calls to ast_sip_push_task_synchronous() that would deadlock if
the task were actually pushed to the specified serializer.  I ran into one
dealing with the pubsub subscriptions where an ao2 destructor called
ast_sip_push_task_synchronous().

* Split ast_sip_push_task_synchronous() into
ast_sip_push_task_wait_servant() and ast_sip_push_task_wait_serializer().
ast_sip_push_task_wait_servant() has the old behavior of
ast_sip_push_task_synchronous().  ast_sip_push_task_wait_serializer() has
the new behavior where the task is always executed by the specified
serializer or a picked serializer if one is not passed in.  Both functions
behave the same if the current thread is not a SIP servant.

* Redirected ast_sip_push_task_synchronous() to
ast_sip_push_task_wait_servant() to preserve API for released branches.

ASTERISK_26806

Change-Id: Id040fa42c0e5972f4c8deef380921461d213b9f3
2018-04-12 17:34:16 -05:00
Jenkins2 fabfe701bb Merge "res_pjsip_refer/chan_sip: Fix INVITE with replaces transfer to ConfBridge" 2018-04-11 07:11:16 -05:00
George Joseph 8af759c088 Merge "chan_sip.c: Fix INVITE with replaces channel ref leak." 2018-04-10 10:10:52 -05:00
Richard Mudgett 0c03eab962 res_pjsip_refer/chan_sip: Fix INVITE with replaces transfer to ConfBridge
There is a problem when an INVITE-with-Replaces transfer targets a channel
in a ConfBridge.  The transfer will unconditionally swap out the
ConfBridge channel.  Unfortunately, the ConfBridge state will not be aware
of this change.  Unexpected behavior will happen as a result since
ConfBridge channels currently can only be replaced by a masquerade and not
normal bridge channel moves.

* We just need to pretend that the channel isn't in a bridge (like other
transfer methods already do) so the transfer channel will masquerade into
the ConfBridge channel.

Change-Id: I209beb0e748fa4f4b92a576f36afa8f495ba4c82
2018-04-06 16:12:57 -06:00
Joshua Colp c7bd554094 pjsip / res_rtp_asterisk: Add support for sending REMB
This change allows chan_pjsip to be given an AST_FRAME_RTCP
containing REMB feedback and pass it to res_rtp_asterisk.
Once res_rtp_asterisk receives the frame a REMB RTCP feedback
packet is constructed with the appropriate contents and sent
to the remote endpoint.

ASTERISK-27776

Change-Id: Ic53f821c1560d8924907ad82c4d9c0bc322b38cd
2018-04-06 08:36:54 -06:00
Richard Mudgett d72a2966da chan_sip.c: Fix INVITE with replaces channel ref leak.
Given the below call scenario:
A -> Ast1 -> B
C <- Ast2 <- B

1) A calls B through Ast1
2) B calls C through Ast2
3) B transfers A to C

When party B transfers A to C, B sends a REFER to Ast1 causing Ast1 to
send an INVITE with replaces to Ast2.  Ast2 then leaks a channel ref of
the channel between Ast1 and Ast2.

Channel ref leaks are easily seen in the CLI "core show channels" output.
The leaked channels appear in the output but you can do nothing with them
and they never go away unless you restart Asterisk.

* Properly account for the channel refs when imparting a channel into a
bridge when handling an INVITE with replaces in handle_invite_replaces().
The ast_bridge_impart() function steals a channel ref but the code didn't
account for how many refs were held by the code at the time and which ref
was stolen.

* Eliminated RAII_VAR in handle_invite_replaces().

ASTERISK-27740

Change-Id: I7edbed774314b55acf0067b2762bfe984ecaa9a4
2018-04-05 17:34:41 -06:00
Joshua Colp e14b0e960d res_rtp_asterisk: Add support for raising additional RTCP messages.
This change extends the existing AST_FRAME_RTCP frame type to be
able to contain additional RTCP message types, such as feedback
messages. The payload type is contained in the subclass which allows
knowing what is in the frame itself.

The RTCP feedback message type is now handled and REMB[1] messages
are raised with their containing information.

This also fixes a bug where all feedback messages were triggering
video updates instead of just FIR and FUR.

Finally RTCP frames are now passed up through the Asterisk core to
what is handling the channel, mapped appropriately in the case of
bridging, and written to an outgoing stream. Since RTCP frames are
on a per-stream basis this is only done on multistream capable
channels.

[1] https://tools.ietf.org/html/draft-alvestrand-rmcat-remb-03

ASTERISK-27758
ASTERISK-26366

Change-Id: I680da0ad8d5059d5e9655d896fb9d92e9da8491e
2018-03-27 08:39:00 -06:00
Jenkins2 e45e8466f1 Merge "chan_sip: Peers with distinct source ports don't match, regardless of transport." 2018-03-21 09:42:54 -05:00
Jenkins2 beab57a576 Merge "BuildSystem: Enable Advanced Linux Sound Architecture (ALSA) in NetBSD." 2018-03-20 06:45:35 -05:00
Alexander Traud 00789174f6 BuildSystem: Enable Advanced Linux Sound Architecture (ALSA) in NetBSD.
In the script ./configure, AST_EXT_LIB_CHECK checks for external libraries. Some
libraries do not specify all their dependencies and require additional shared
libraries. In AST_EXT_LIB_CHECK, this is the fifth parameter. However, if a
library is specified there, it must exist on the platform, because ./configure
tries to compile/link/execute a small app using those statements. For example,
the library libdl.so is Linux specific and does not exist on BSD-like platforms.

Furthermore, no supported platform/version was found, which still (ever?)
requires those additional libraries. Therefore, they were simply removed.

Finally, this change adds the error code ESTRPIPE to the channel driver
chan_alsa for those platforms which lack it, again for example NetBSD.

ASTERISK-27720

Change-Id: I3b21f2135f6cbfac7590ccdc2df753257f426e0b
2018-03-16 16:04:26 +01:00
Corey Farrell 572a508ef2 loader: Convert reload_classes to built-in modules.
* acl (named_acl.c)
* cdr
* cel
* ccss
* dnsmgr
* dsp
* enum
* extconfig (config.c)
* features
* http
* indications
* logger
* manager
* plc
* sounds
* udptl

These modules are now loaded at appropriate time by the module loader.
Unlike loadable modules these use AST_MODULE_LOAD_FAILURE on error so
the module loader will abort startup on failure of these modules.

Some of these modules are still initialized or shutdown from outside the
module loader.  logger.c is initialized very early and shutdown very
late, manager.c is initialized by the module loader but is shutdown by
the Asterisk core (too much uses it without holding references).

Change-Id: I371a9a45064f20026c492623ea8062d02a1ab97f
2018-03-14 05:20:12 -04:00
Jenkins2 1485719531 Merge "Replace direct checks of option_debug with DEBUG_ATLEAST macro." 2018-03-12 10:44:46 -05:00
Corey Farrell c8a521b6c8 Replace direct checks of option_debug with DEBUG_ATLEAST macro.
Checking option_debug directly is incorrect as it ignores file/module
specific debug settings.  This system-wide change replaces nearly all
direct checks for option_debug with the DEBUG_ATLEAST macro.

Change-Id: Ic342d4799a945dbc40ac085ac142681094a4ebf0
2018-03-07 16:03:01 -06:00
Jean Aunis 75a35ee5e8 chan_sip: Fix improper RTP framing on outgoing calls
The "ptime" SDP parameter received in a SIP response was not honoured.
Moreover, in the abscence of this "ptime" parameter, locally configured
framing was lost during response processing.

This patch systematically stores the framing information in the
ast_rtp_codecs structure, taking it from the response or from the
configuration as appropriate.

ASTERISK-27674

Change-Id: I828a6a98d27a45a8afd07236a2bd0aa3cbd3fb2c
2018-03-07 01:34:54 -06:00
Jenkins2 24c72ea286 Merge "chan_unistim: NetBSD has an incompatible struct in_pktinfo." 2018-03-05 12:42:56 -06:00
Alexander Traud aabbb49e33 chan_unistim: NetBSD has an incompatible struct in_pktinfo.
ASTERISK-27714
Reported by: John Nemeth

Change-Id: I1b84a89315a5f61222123d21bf35c59224da8990
2018-03-03 16:06:13 +01:00
Joshua Colp 259c80675e chan_sip: Emit a second ringing event to ensure channel is found.
When constructing a dialog-info+xml NOTIFY message a ringing channel
is found if the state is ringing and further information is placed into
the message. Due to the migration to the Stasis message bus this did
not always work as expected.

This change raises a second ringing event in such a way to guarantee
that the event is received by chan_sip and another lookup is done to
find the ringing channel.

ASTERISK-24488

Change-Id: I547a458fc59721c918cb48be060cbfc3c88bcf9c
2018-02-20 10:42:58 -06:00
Richard Mudgett 8372138cce chan_sip.c: Fix crash processing CANCEL.
Check if initreq data string exists before using it when processing a
CANCEL request.

ASTERISK-27666

Change-Id: Id1d0f0fa4ec94e81b332b2973d93e5a14bb4cc97
2018-02-12 20:57:57 -06:00
Oron Peled 5b8fea93d1 chan_console: don't read and write at the same time
It seems that the ALSA backend of PortAudio doesn't know how to both
read and write at the same time by adding a per-device mutex.

FIXME: currently only a draft version. Need to either auto-detect
we work with the ALSA backend or add an extra configuration option
to use this mutex.

ASTERISK-27426 #close

Change-Id: I635eacee45f5413faa18f5a3b606af03b926dacb
2018-02-03 09:41:07 -05:00
Corey Farrell 527cf5a570 Remove redundant module checks and references.
This removes references that are no longer needed due to automatic
references created by module dependencies.

In addition this removes most calls to ast_module_check as they were
checking modules which are listed as dependencies.

Change-Id: I332a6e8383d4c72c8e89d988a184ab8320c4872e
2018-01-24 13:37:29 -05:00
Igor Goncharovsky 33d5ab3e69 chan_unistim: Fix hold function ability to lock/crash asterisk
This patch fix chan_unistim hold functions to correctly support
hold function in different states possible in case of multiple lines
established on the phone

ASTERISK-26596 #close

Change-Id: Ib1e04e482e7c8939607a42d7fddacc07e26e14d4
2018-01-18 00:12:41 -06:00
Corey Farrell 9cfdb81e91 loader: Add dependency fields to module structures.
* Declare 'requires' and 'enhances' text fields on module info structure.
* Rename 'nonoptreq' to 'optional_modules'.
* Update doxygen comments.

Still need to investigate dependencies among modules I cannot compile.

Change-Id: I3ad9547a0a6442409ff4e352a6d897bef2cc04bf
2018-01-15 13:25:51 -05:00
Joshua Colp 6d5f4768a4 chan_sip: Check that an iostream exists before accessing.
Before getting the file descriptor for an iostream check
that it is present.

ASTERISK-27534

Change-Id: Ie0aa1394007a37c30e337ea1176a6fb3a63bc99c
2018-01-11 13:05:05 -05:00
Sean Bright 15f8b9b8bf ice: Increase foundation buffer size
Per RFC 5245, the foundation specified with an ICE candidate can be up
to 32 characters but we are only allowing for 31.

ASTERISK-27498 #close
Reported by: Michele Prà

Change-Id: I05ce7a5952721a76a2b4c90366168022558dc7cf
2017-12-31 11:34:41 -05:00
Corey Farrell c2529a352c astobj.h: Remove from Asterisk core.
This is the old ASTOBJ macro's which are no longer used except by the
deprecated netsock.c.  Move it to the chan_iax2 include folder so it
does not get used elsewhere.

Change-Id: I7e4ae96678b36b9f41d3cae14b167f110eb5d349
2017-12-22 15:00:14 -05:00
Sean Bright fd0ca1c3f9 Remove as much trailing whitespace as possible.
Change-Id: I873c1c6d00f447269bd841494459efccdd2c19c0
2017-12-22 09:23:22 -05:00
Corey Farrell 1b80ffa495 Fix Common Typo's.
Fix instances of:
* Retreive
* Recieve
* other then
* different then
* Repeated words ("the the", "an an", "and and", etc).
* othterwise, teh

ASTERISK-24198 #close

Change-Id: I3809a9c113b92fd9d0d9f9bac98e9c66dc8b2d31
2017-12-20 12:40:01 -05:00
Jenkins2 968993a297 Merge "chan_sip: Fix memory leaks." 2017-12-19 19:42:13 -06:00
Jenkins2 262eda7801 Merge "Remove constant conditionals (dead-code)." 2017-12-19 19:17:25 -06:00
Corey Farrell 3c037ef972 chan_sip: Fix memory leaks.
In change_redirecting_information variables we use ast_strlen_zero to
see if a value should be saved.  In the case where the value is not NULL
but is a zero length string we leaked.

handle_response_subscribe leaked a reference to the ccss monitor
instance.

Change-Id: Ib11444de69c3d5b2360a88ba2feb54d2c2e9f05f
2017-12-19 14:47:26 -05:00
Corey Farrell b3e839debd Remove constant conditionals (dead-code).
Some variables are set and never changed, making them constant.  This
means that code in the 'false' block of the conditional is unreachable.

In chan_skinny and res_config_ldap I used preprocessor directive `#if 0`
as I'm unsure if the unreachable code could be enabled in the future.

Change-Id: I62e2aac353d739fb3c983cf768933120f5fba059
2017-12-19 09:42:19 -05:00
Oron Peled c02e256407 chan_console: Use correct parameter for 'set active'
chan_console supports multiple devices but the CLI only works on a
single device. 'console set active' selects this device.

Sadly that CLI picks the wrong command-line parameter and will only
work for a device called 'active'.

ASTERISK-27490 #close

Change-Id: I2f0e5fe63db19845bee862575b739360797dc73d
2017-12-19 14:12:57 +02:00
Jenkins2 11a1e07ad2 Merge "netsock: Remove from Asterisk core." 2017-12-18 17:40:22 -06:00
Joshua Colp 5224fd3ab4 Merge changes from topic 'faster-aco'
* changes:
  aco: Minimize use of regex.
  aco: Create ways to minimize use of regex.
2017-12-18 14:41:41 -06:00
Corey Farrell 064c74e4af netsock: Remove from Asterisk core.
This moves netsock.c / netsock.h to the chan_iax2 module.  netsock.h has
been marked deprecated since 13.0.0, chan_iax2 is the only remaining
user.

Change-Id: I28c6578043bac18de5ea608e136acec4f83d5dd3
2017-12-18 15:00:35 -05:00
Jenkins2 e79f0c0709 Merge "chan_pjsip.c: Improve ast_request() diagnostic msgs." 2017-12-18 09:37:19 -06:00
Richard Mudgett 4a461bcde4 chan_pjsip.c: Improve ast_request() diagnostic msgs.
Attempting to dial PJSIP/endpoint when the endpoint doesn't exist and
disable_multi_domain=no results in a misleading empty endpoint name
message.  The message should say the endpoint was not found.

* Added missing endpoint not found message.

* Added more information to the empty endpoint name msgs if available.

* Eliminated RAII_VAR in request().

Change-Id: I21da85ebd62dcc32115b2ffcb5157416ebae51e4
2017-12-15 19:59:50 -06:00
Corey Farrell 6f8b34f9c1 chan_sip: Add security event for calls to invalid extension.
Log a message to security events when an INVITE is received to an
invalid extension.

ASTERISK-25869 #close

Change-Id: I0da40cd7c2206c825c2f0d4e172275df331fcc8f
2017-12-15 12:43:38 -06:00
Corey Farrell bf2d35931d aco: Minimize use of regex.
Remove nearly all use of regex from ACO users.  Still remaining:
* app_confbridge has a legitamate use of option name regex.
* ast_sorcery_object_fields_register is implemented with regex, all
  callers use simple prefix based regex.  I haven't decided the best
  way to fix this in both 13/15 and master.

Change-Id: Ib5ed478218d8a661ace4d2eaaea98b59a897974b
2017-12-15 10:14:31 -05:00
Joshua Colp e411b7d112 Merge "chan_sip: 3PCC patch for AMI "SIPnotify"" 2017-12-14 06:14:16 -06:00
Joshua Colp c50905756b Merge "chan_pjsip/res_pjsip: Add CHANNEL(pjsip,request_uri)" 2017-12-13 11:21:15 -06:00
Jenkins2 58514c7442 Merge "chan_sip: Don't crash in Dial on invalid destination" 2017-12-13 07:14:13 -06:00
Yasuhiko Kamata cb249b2419 chan_sip: 3PCC patch for AMI "SIPnotify"
A patch for sending in-dialog SIP NOTIFY message
with "SIPnotify" AMI action.

ASTERISK-27461

Change-Id: I5797ded4752acd966db6b13971284db684cc5ab4
2017-12-13 13:42:35 +09:00
Sean Bright 0c9cc7e975 chan_sip: Don't send trailing \0 on keep alive packets
This is a partial fix for ASTERISK~25817 but does not address the
comments regarding RFC 5626.

Change-Id: I227e2d10c0035bbfa1c6e46ae2318fd1122d8420
2017-12-12 15:52:25 -06:00
Sean Bright 5039b5741c chan_sip: Don't crash in Dial on invalid destination
Stripping the DNID in a SIP dial string can result in attempting to call
the argument parsing macros on an empty string, causing a crash.

ASTERISK-26131 #close
Reported by: Dwayne Hubbard
Patches:
	dw-asterisk-master-dnid-crash.patch (license #6257) patch
	uploaded by Dwayne Hubbard

Change-Id: Ib84c1f740a9ec0539d582b09d847fc85ddca1c5e
2017-12-12 15:35:17 -06:00
Richard Mudgett 22810fc635 chan_pjsip/res_pjsip: Add CHANNEL(pjsip,request_uri)
This patch does three things associated with the initial incoming INVITE
request URI.

1) Add access to the full initial incoming INVITE request URI.

2) We were not setting DNID on incoming PJSIP channels.  The DNID is the
user portion of the initial incoming INVITE Request-URI.  The value is
accessed by reading CALLERID(dnid).

3) Fix CHANNEL(pjsip,target_uri) documentation.

* The initial incoming INVITE request URI is now available using
CHANNEL(pjsip,request_uri).

* Set the DNID on PJSIP channel creation so CALLERID(dnid) can return the
initial incoming INVITE request URI user portion.

* CHANNEL(pjsip,target_uri) now correctly documents that the target URI is
the contact URI.

* Refactored print_escaped_uri() out of channel_read_pjsip() to handle
pjsip_uri_print() error condition when the buffer is too small.

ASTERISK-27478

Change-Id: I512e60d1f162395c946451becb37af3333337b33
2017-12-12 13:46:42 -06:00
Sean Bright 2ffe52a116 utils: Add convenience function for setting fd flags
There are many places in the code base where we ignore the return value
of fcntl() when getting/setting file descriptior flags. This patch
introduces a convenience function that allows setting or clearing file
descriptor flags and will also log an error on failure for later
analysis.

Change-Id: I8b81901e1b1bd537ca632567cdb408931c6eded7
2017-12-08 13:28:04 -06:00
Richard Mudgett 8536a09b86 security-events: Fix SuccessfulAuth using_password declaration.
The SuccessfulAuth using_password field was declared as a pointer to a
uint32_t when the field was later read as a uint32_t value.  This resulted
in unnecessary casts and a non-portable field value reinterpret in
main/security_events.c:add_json_object().  i.e., It would work on a 32 bit
architecture but not on a 64 bit big endian architecture.

Change-Id: Ia08bc797613a62f07e5473425f9ccd8d77c80935
2017-12-04 17:21:27 -06:00
Alexander Traud b2c4e8660a chan_sip: Peers with distinct source ports don't match, regardless of transport.
Previously, peers connected via TCP (or TLS) were matched by ignoring their
source port. One cannot say anything when protocol:IP:port match, yes (see
<http://stackoverflow.com/q/3329641>). However, when the ports do not match, the
peers do not match as well.

This change allows two peers connected to an Asterisk server via TCP (or TLS)
behind a NAT (= same source IP address) to be differentiated via their port as
well.

ASTERISK-27457
Reported by: Stephane Chazelas

Change-Id: Id190428bf1d931f2dbfd4b293f53ff8f20d98efa
2017-12-04 12:54:05 +01:00
George Joseph 075faac2fd AST-2017-013: chan_skinny: Call pthread_detach when sess threads end
chan_skinny creates a new thread for each new session.  In trying
to be a good cleanup citizen, the threads are joinable and the
unload_module function does a pthread_cancel() and a pthread_join()
on any sessions that are active at that time.  This has an
unintended side effect though. Since you can call pthread_join on a
thread that's already terminated, pthreads keeps the thread's
storage around until you explicitly call pthread_join (or
pthread_detach()).   Since only the module_unload function was
calling pthread_join, and even then only on the ones active at the
tme, the storage for every thread/session ever created sticks
around until asterisk exits.

* A thread can detach itself so the session_destroy() function
  now calls pthread_detach() just before it frees the session
  memory allocation.  The module_unload function still takes care
  of the ones that are still active should the module be unloaded.

ASTERISK-27452
Reported by: Juan Sacco

Change-Id: I9af7268eba14bf76960566f891320f97b974e6dd
(cherry picked from commit 8f5dff543e)
2017-12-01 13:29:52 -06:00
Alexander Traud 491e2eba0d chan_sip: ICE contained square brackets around IPv6 addresses.
ASTERISK-27434

Change-Id: Iaeed89b4fa05d94c5f0ec2d3b7cd6e93d2d5a8f7
2017-11-21 10:52:10 +01:00
Richard Mudgett e793501084 chan_pjsip.c: Improve answer failure log messages.
* Balanced the session->inv_session refs on answer failure.

Change-Id: I33542d639d37e692cb46550b972a5fcfc3b804b8
2017-11-15 17:53:40 -05:00
Richard Mudgett 90bb0a3e10 core: Add cache_media_frames debugging option.
The media frame cache gets in the way of finding use after free errors of
media frames.  Tools like valgrind and MALLOC_DEBUG don't know when a
frame is released because it gets put into the cache instead of being
freed.

* Added the "cache_media_frames" option to asterisk.conf.  Disabling the
option helps track down media frame mismanagement when using valgrind or
MALLOC_DEBUG.  The cache gets in the way of determining if the frame is
used after free and who freed it.  NOTE: This option has no effect when
Asterisk is compiled with the LOW_MEMORY compile time option enabled
because the cache code does not exist.

To disable the media frame cache simply disable the cache_media_frames
option in asterisk.conf and restart Asterisk.

Sample asterisk.conf setting:
[options]
cache_media_frames=no

ASTERISK-27413

Change-Id: I0ab2ce0f4547cccf2eb214901835c2d951b78c00
2017-11-11 14:46:15 -05:00
Richard Mudgett 12010fc5c0 chan_pjsip.c: Fix uninitialized cause value on failure.
Change-Id: I3f9dd3c31bd582e54a30381500077de2319d8cc3
2017-11-09 08:42:34 -05:00
Joshua Colp 637b37fb98 Merge "dtls: Add support for ephemeral DTLS certificates." 2017-11-06 12:22:38 -06:00
Sean Bright 04d3785a79 dtls: Add support for ephemeral DTLS certificates.
This mimics the behavior of Chrome and Firefox and creates an ephemeral
X.509 certificate for each DTLS session.

Currently, the only supported key type is ECDSA because of its faster
generation time, but other key types can be added in the future as
necessary.

ASTERISK-27395

Change-Id: I5122e5f4b83c6320cc17407a187fcf491daf30b4
2017-11-06 08:11:48 -05:00
Corey Farrell 606ae3484a Add missing menuselect dependencies.
This adds menuselect dependencies for modules that use symbols of other
modules.

ASTERISK-27390

Change-Id: Ia2d2849f5b87a72af7324a82edc3f283eafb5385
2017-11-02 02:57:52 -04:00
Corey Farrell 6474de5f72 chan_sip: Fix SUBSCRIBE with missing "Expires" header.
When chan_sip receives a SUBSCRIBE request with no "Expires" header it
processes the request as an unsubscribe.  This is incorrect, per RFC3264
when the "Expires" header is missing a default expiry should be used.

ASTERISK-18140

Change-Id: Ibf6dcd4fdd07a32c2bc38be1dd557981f08188b5
2017-10-24 11:57:53 -04:00
Alexander Traud 840e08716b chan_sip: Crypto attribute not last but first on SDP media level.
This matches the behavior of the other SIP channel driver, chan_pjsip.

ASTERISK-27365

Change-Id: I8f23a51290a58b75816da2999ed1965441dfc5d6
2017-10-21 10:44:21 +02:00
Corey Farrell c9e19b31f5 chan_sip: Fix output of 'sip set debug off'.
When sip.conf contains 'sipdebug=yes' it is impossible to disable it
using CLI 'sip set debug off'.  This corrects the output of that CLI
command to instruct the user to turn sipdebug off in the configuration
file.

ASTERISK-23462 #close

Change-Id: I1cceade9caa9578e1b060feb832e3495ef5ad318
2017-10-18 13:04:29 -04:00
Guido Falsi c4f40b778a chan_dahdi: wrap include file which is not present on BSD systems in #ifdef
The sys/sysmacros.h include file does not exist in BSD systems and
is not required to build this module there.
Since an "#if defined(__NetBSD__) || defined(__FreeBSD__)" section
already exist I moved that include line inside it's #else branch.

ASTERISK-27343 #close

Change-Id: Ibfb64f4e9a0ce8b6eda7a7695cfe57916f175dc1
2017-10-14 14:36:07 +02:00
George Joseph ab4d36533c chan_vpb: Fix a gcc 7 out-of-bounds complaint
chan_vpb was trying to use sizeof(*p->play_dtmf), where
p->play_dtmf is defined as char[16], to get the length of the array
but since p->play_dtmf is an actual array, sizeof(*p->play_dtmf)
returns the size of the first array element, which is 1.  gcc7
validly complains because the context in which it's used could
cause an out-of-bounds condition.

Change-Id: If9c4bfdb6b02fa72d39e0c09bf88900663c000ba
2017-10-11 07:10:45 -05:00
Daniel Tryba 59b6e8467a res_pjsip_caller_id chan_sip: Comply to RFC 3323 values for privacy
Currently privacy requests are only granted if the Privacy header
value is exactly "id" (defined in RFC 3325). It ignores any other
possible value (or a combination there of). This patch reverses the
logic from testing for "id" to grant privacy, to testing for "none" and
granting privacy for any other value. "none" must not be used in
combination with any other value (RFC 3323 section 4.2).

ASTERISK-27284 #close

Change-Id: If438a21f31a962da32d7a33ff33bdeb1e776fe56
2017-10-05 07:53:03 -05:00
George Joseph 4275ca16a1 build: A few gcc 7 error fixes
Change-Id: I7b5300fbf1af7d88d47129db13ad6dbdc9b553ec
2017-09-25 07:32:14 -05:00
Joshua Colp f2985e3106 bridge: Change participant SFU streams when source streams change.
Some endpoints do not like a stream being reused for a new
media stream. The frame/jitterbuffer can rely on underlying
attributes of the media stream in order to order the packets.
When a new stream takes its place without any notice the
buffer can get confused and the media ends up getting dropped.

This change uses the SSRC change to determine that a new source
is reusing an existing stream and then bridge_softmix renegotiates
each participant such that they see a new media stream. This
causes the frame/jitterbuffer to start fresh and work as expected.

ASTERISK-27277

Change-Id: I30ccbdba16ca073d7f31e0e59ab778c153afae07
2017-09-21 12:20:02 -05:00
Jenkins2 b9da3d643c Merge "chan_sip: Expose read-only access to the full SIP INVITE Request-URI" 2017-09-21 11:11:15 -05:00
George Joseph b6aa728a58 chan_pjsip: Ignore AST_CONTROL_STREAM_TOPOLOGY_CHANGED for now
chan_pjsip_indicate was missing a case for the recently added
AST_CONTROL_STREAM_TOPOLOGY_CHANGED condition and was returning an
error and causing the call to be hung up instead of just ignoring
it.

ASTERISK-27260
Reported by: Daniel Heckl

Change-Id: I4fecbb00a0b8a853da85155065c1a6bddf235e80
2017-09-20 11:13:47 -05:00
David J. Pryke a5f1d58fe1 chan_sip: Expose read-only access to the full SIP INVITE Request-URI
Provide a way to get the contents of the the Request URI from the initial SIP
INVITE in dial plan function call. (In this case "${CHANNEL(ruri)}")

ASTERISK-27278
Reported by: David J. Pryke
Tested by: David J. Pryke

Change-Id: I1dd4d6988eed1b6c98a9701e0e833a15ef0dac3e
2017-09-19 12:24:33 -05:00
Sean Bright eec0396395 chan_rtp: Use μ-law by default instead of signed linear
Multicast/Unicast RTP do not use SDP so we need to use a format that
cleanly maps to one of the static RTP payload types. Without this
change, an Originate to a Multicast or Unicast channel without a format
specified would produce no audio on the receiving device.

ASTERISK-21399 #close
Reported by: Tzafrir Cohen

Change-Id: I97e332b566e85da04b0004b9b0daae746cfca0e3
2017-09-13 09:40:56 -05:00
Jenkins2 68b506caaa Merge "chan_sip: when getting sip pvt return failure if not found" 2017-09-08 10:24:08 -05:00
Scott Griepentrog 5553644284 chan_sip: when getting sip pvt return failure if not found
In handle_request_invite, when processing a pickup, a call
is made to get_sip_pvt_from_replaces to locate the pvt for
the subscription. The pvt is assumed to be valid when zero
is returned indicating no error, and is dereferenced which
can cause a crash if it was not found.

This change checks the not found case and returns -1 which
allows the calling code to fail appropriately.

ASTERISK-27217 #close
Reported-by: Bryan Walters

Change-Id: I6bee92b8b8b85fcac3fd66f8c00ab18bc1765612
2017-09-06 17:05:32 -04:00
Vitezslav Novy 67a2ca31f5 chan_sip: Do not change IP address in SDP origin line (o=) in SIP reINVITE
If directmedia=yes is configured, when call is answered, Asterisk sends reINVITE
to both parties to set up media path directly between the endpoints.
In this reINVITE msg SDP origin line (o=) contains IP address of endpoint
instead of IP of asterisk. This behavior violates RFC3264, sec 8:
"When issuing an offer that modifies the session,
the "o=" line of the new SDP MUST be identical to that in the
previous SDP, except that the version in the origin field MUST
increment by one from the previous SDP."
This patch assures IP address of Asterisk is always sent in
SDP origin line.

ASTERISK-17540
Reported by:  saghul

Change-Id: I533a047490c43dcff32eeca8378b2ba02345b64e
2017-09-06 10:08:06 -05:00
Ben Ford bfc29de3ea chan_pjsip: Suppress frame warnings.
When rtp_keepalive is on for a PJSIP endpoint dialing to another
Asterisk instance also using PJSIP, Asterisk will continue to print
warning messages about not being able to send frames of a certain
type. This suppresses that warning message.

Change-Id: I0332a05519d7bda9cacfa26d433909ff1909be67
2017-09-05 17:20:47 -05:00
Andre Nazario 71be8d5bbe chan_pjsip: Add tag info in CHANNEL function
Create local_tag and remote_tag in CHANNEL info to get tag from From and
To headers of a SIP dialog.

ASTERISK-27220

Change-Id: I59b16c4b928896fcbde02ad88f0e98922b15d524
2017-08-30 07:52:24 -05:00
Joshua Colp 9d0c3564ee Merge "res/res_pjsip_session: allow SDP answer to be regenerated" 2017-08-28 07:34:47 -05:00
Torrey Searle 33a648d4c6 res/res_pjsip_session: allow SDP answer to be regenerated
If an SDP answer hasn't been sent yet, it's legal to change it.
This is required for PJSIP_DTMF_MODE to work correctly, and can
also have use in the future for updating codecs too.

ASTERISK-27209 #close

Change-Id: Idbbfb7cb3f72fbd96c94d10d93540f69bd51e7a1
2017-08-25 14:27:24 +02:00
Richard Mudgett 850a3fd017 chan_pjsip.c: Fix topology refresh response code accuracy.
There are other 1xx and 2xx codes than 100 and 200 respectively.

Change-Id: I680db0997343256add1478714f5bf5b5569aee17
2017-08-22 11:33:25 -05:00
Torrey Searle a2dde59154 res_rtp_asterisk: Make P2P bridge Asymmetric codec aware
Introduce a new property to rtp-engine to make it aware of
the desire for assymetric codecs or not.  If asymmetric codecs
is not allowed, the bridge will compare read/write formats
and shut down the p2p bridge if needed

ASTERISK-26745 #close

Change-Id: I0d9c83e5356df81661e58d40a8db565833501a6f
2017-08-09 08:57:50 -05:00
kkm 4b58609c33 chan_sip: Access incoming REFER headers in dialplan
This adds a way to access information passed along with SIP headers in
a REFER message that initiates a transfer. Headers matching a dialplan
variable GET_TRANSFERRER_DATA in the transferrer channel are added to
a HASH object TRANSFER_DATA to be accessed with functions HASHKEY and HASH.

The variable GET_TRANSFERRER_DATA is interpreted to be a prefix for
headers that should be put into the hash. If not set, no headers are
included. If set to a string (perhaps 'X-' in a typical case), all headers
starting this string are added. Empty string matches all headers.

If there are multiple of the same header, only the latest occurrence in
the REFER message is available in the hash.

Obviously, the variable GET_TRANSFERRER_DATA must be inherited by the
referrer channel, and should be set with the '_' or '__' prefix.

I avoided a specific reference to SIP or REFER, as in my mind the mechanism
can be generalized to other channel techs.

ASTERISK-27162

Change-Id: I73d7a1e95981693bc59aa0d5093c074b555f708e
2017-08-07 11:17:39 +00:00
Joshua Colp 1f01106cfc Merge "chan_sip: Add dialplan function SIP_HEADERS" 2017-08-04 12:57:58 -05:00
Jenkins2 38c8080cdd Merge "Fix compile error for old versions of GCC." 2017-08-04 12:03:23 -05:00
Corey Farrell 7f8f3ca4dd Correct some leaks in unit tests.
* chan_sip: channel in test_sip_rtpqos_1.
* test_config: config hook, config info and global config holder.
* test_core_format: format in format_attribute_set_without_interface.
* test_stream: unneeded frame duplication.
* test_taskprocessor: task_data.

Change-Id: I94d364d195cf3b3b5de2bf3ad565343275c7ad31
2017-08-03 22:09:28 -04:00
kkm 4c0798e91d chan_sip: Add dialplan function SIP_HEADERS
Syntax: SIP_HEADERS([prefix])

If the argument is specified, only the headers matching the given prefix
are returned.

The function returns a comma-separated list of SIP header names from an
incoming INVITE message. Multiple headers with the same name are included
in the list only once. The returned list can be iterated over using the
functions POP() and SIP_HEADER().

For example, '${SIP_HEADERS(Co)}' might return the string
'Contact,Content-Length,Content-Type'.

Practical use is rather '${SIP_HEADERS(X-)}' to enumerate optional
extended headers sent by a peer.

ASTERISK-27163

Change-Id: I2076d3893d03a2f82429f393b5b46db6cf68a267
2017-08-02 19:19:29 -05:00
Corey Farrell 4b03eb5c38 Fix compile error for old versions of GCC.
Use -Wno-format-truncation only if supported by compiler.

ASTERISK-27171 #close

Change-Id: Iac0aed7a5bcaa16c21b7d62c4e4678d244c4ccb6
2017-08-02 18:10:57 -04:00
Corey Farrell 58d032112b Fix compiler warnings on Fedora 26 / GCC 7.
GCC 7 has added capability to produce warnings, this fixes most of those
warnings.  The specific warnings are disabled in a few places:

* app_voicemail.c: truncation of paths more than 4096 chars in many places.
* chan_mgcp.c: callid truncated to 80 chars.
* cdr.c: two userfields are combined to cdr copy, fix would break ABI.
* tcptls.c: ignore use of deprecated method SSLv3_client_method().

ASTERISK-27156 #close

Change-Id: I65f280e7d3cfad279d16f41823a4d6fddcbc4c88
2017-08-01 15:42:38 -06:00
Torrey Searle 65c560894d chan_pjsip: add a new function PJSIP_DTMF_MODE
This function is a replica of SIPDtmfMode, allowing the DTMF mode of a
PJSIP call to be modified on a per-call basis

ASTERISK-27085 #close

Change-Id: I20eef5da3e5d1d3e58b304416bc79683f87e7612
2017-08-01 15:41:53 -06:00
Joshua Colp a6eb9ee7d2 core: Add VP9 passthrough support.
This change adds VP9 as a known codec and creates a cached
"vp9" media format for use.

Change-Id: I025a93ed05cf96153d66f36db1839109cc24c5cc
2017-07-24 18:30:59 +00:00
Jenkins2 647f539e15 Merge "res_pjsip: Add "webrtc" configuration option" 2017-07-17 15:16:30 -05:00
Sergej Kasumovic d3f5b265c7 chan_iax2: On reload make sure to check for existing MWI subscription
On every reload of chan_iax2 module, MWI subscription was added, which
results in additional taskprocessors being accumulated over time.

This commit fixes it by making sure we check for existing subscription
first.

This was verified with 'core show taskprocessors' CLI command.

ASTERISK-27122 #close

Change-Id: Ie2ef528fd5ca01b933eeb88188cc10967899cfb9
2017-07-14 01:22:31 -05:00
Kevin Harwell 7da6ddda30 res_pjsip: Add "webrtc" configuration option
This patch creates a new configuration option called "webrtc". When enabled it
defaults and enables the following options that are needed in order for webrtc
to work in Asterisk:

  rtcp-mux, use_avpf, ice_support, and use_received_transport=enabled
  media_encryption=dtls
  dtls_verify=fingerprint
  dtls_setup=actpass

When "webrtc" is enabled, this patch also parses the "msid" media level
attribute from an SDP. It will also appropriately add it onto the outgoing
session when applicable.

Lastly, when "webrtc" is enabled h264 RTCP FIR feedback frames are now sent.

ASTERISK-27119 #close

Change-Id: I5ec02e07c5d5b9ad86a34fdf31bf2f9da9aac6fd
2017-07-13 18:19:35 -05:00
Jenkins2 0f45c979a3 Merge "res_rtp_asterisk / res_pjsip: Add support for BUNDLE." 2017-07-13 14:40:11 -05:00
Joshua Colp 065c3005ad res_rtp_asterisk / res_pjsip: Add support for BUNDLE.
BUNDLE is a specification used in WebRTC to allow multiple
streams to use the same underlying transport. This reduces
the number of ICE and DTLS negotiations that has to occur
to 1 normally.

This change implements this by adding support for it to
the RTP SDP module in PJSIP. BUNDLE can be turned on using
the "bundle" option and on an offer we will offer to
bundle streams together. On an answer we will accept any
bundle groups provided. Once accepted each stream is bundled
to another RTP instance for transport.

For the res_rtp_asterisk changes the ability to bundle
an RTP instance to another based on the SSRC received
from the remote side has been added. For outgoing traffic
if an RTP instance is bundled to another we will use the
other RTP instance for any transport related things. For
incoming traffic received from the transport instance we
look up the correct instance based on the SSRC and use it
for any non-transport related data.

ASTERISK-27118

Change-Id: I96c0920b9f9aca7382256484765a239017973c11
2017-07-13 14:47:50 +00:00
Jenkins2 d6c08cc559 Merge "core: Remove 'Data Retrieval API'" 2017-07-07 15:42:56 -05:00
Jenkins2 75022f6b11 Merge "chan_sip: Fix a typo for tlsbindaddr in autodomain (SIP Domain Support)." 2017-07-05 16:37:39 -05:00
Jenkins2 2ec388680b Merge "chan_sip: Only when different, add TCP|TLS in autodomain (SIP Domain Support)." 2017-07-05 16:29:45 -05:00
Jenkins2 d2b32cd009 Merge "chan_pjsip: Fix ability to send UPDATE on COLP" 2017-07-05 14:17:23 -05:00
Sean Bright 325eeced6a core: Remove 'Data Retrieval API'
This API was not actively maintained, was not added to new modules
(such as res_pjsip), and there exist better alternatives to acquire the
same information, such as the ARI.

Change-Id: I4b2185a83aeb74798b4ad43ff8f89f971096aa83
2017-07-05 11:25:58 -05:00
Alexander Traud 910c05455d chan_sip: Only when different, add TCP|TLS in autodomain (SIP Domain Support).
When sip.conf contained tcpenable=yes and autodomain=yes, the TCP domain was
added in any case, because of a local Boolean-negation error of the return value
of ast_sockaddr_cmp. After fixing this error for TCP and TLS, the TLS domain was
still always added with tlsenable=yes, because the domains were not compared
just on the address but also on the port – and TLS is always on a different port
than UDP/TCP.

ASTERISK-27106

Change-Id: I14fe9e319e238320b094016980445ef3a5b3337c
2017-07-03 17:59:43 +02:00
Alexander Traud 4398aa8fa4 chan_sip: Fix a typo for tlsbindaddr in autodomain (SIP Domain Support).
Because of a copy-and-paste error when the struct ast_sockaddr changed,
tlsbindaddr was not added, when sip.conf contained autodomain=yes; see
"show sip domains" on the command-line interface (CLI) of Asterisk.

ASTERISK-27106

Change-Id: I3d0957150017c223136968ef1266f275d0d6695e
2017-07-03 17:38:32 +02:00
George Joseph c0c99c7618 chan_pjsip: Fix ability to send UPDATE on COLP
When connected_line_method is "invite", we're supposed to determine
if the client can support UPDATE and if it can, send UPDATE instead
of INVITE to avoid the SDP renegotiation.  Not only was pjproject
not setting the PJSIP_INV_SUPPORT_UPDATE flag, we were testing
that invite_tsx wasn't NULL which isn't always the case.

* Updated chan_pjsip/update_connected_line_information to drop the
  requirement that invite_tsx isn't NULL.
* Submitted patch to pjproject sip_inv.c that sets the
  PJSIP_INV_SUPPORT_UPDATE flag correctly.
* Updated pjsip.conf.sample to clarify what happens when "invite"
  is specified.

ASTERISK-27095

Change-Id: Ic2381b3567b8052c616d96fbe79564c530e81560
2017-06-29 15:45:58 -05:00
Torrey Searle fb7247c57c res_pjsip: Add DTMF INFO Failback mode
The existing auto dtmf mode reverts to inband if 4733 fails to be
negotiated.  This patch adds a new mode auto_info which will
switch to INFO instead of inband if 4733 is not available.

ASTERISK-27066 #close

Change-Id: Id185b11e84afd9191a2f269e8443019047765e91
2017-06-29 07:57:01 -06:00
Mark Michelson 45df25a579 chan_pjsip: Add support for multiple streams of the same type.
The stream topology (list of streams and order) is now stored with the
configured PJSIP endpoints and used during the negotiation process.

Media negotiation state information has been changed to be stored
in a separate object. Two of these objects exist at any one time
on a session. The active media state information is what was previously
negotiated and the pending media state information is what the
media state will become if negotiation succeeds. Streams and other
state information is stored in this object using the index (or
position) of each individual stream for easy lookup.

The ability for a media type handler to specify a callback for
writing has been added as well as the ability to add file
descriptors with a callback which is invoked when data is available
to be read on them. This allows media logic to live outside of
the chan_pjsip module.

Direct media has been changed so that only the first audio and
video stream are directly connected. In the future once the RTP
engine glue API has been updated to know about streams each individual
stream can be directly connected as appropriate.

Media negotiation itself will currently answer all the provided streams
on an offer within configured limits and on an offer will use the
topology created as a result of the disallow/allow codec lines.

If a stream has been removed or declined we will now mark it as such
within the resulting SDP.

Applications can now also request that the stream topology change.
If we are told to do so we will limit any provided formats to the ones
configured on the endpoint and send a re-invite with the new topology.

Two new configuration options have also been added to PJSIP endpoints:

max_audio_streams: determines the maximum number of audio streams to
offer/accept from an endpoint. Defaults to 1.

max_video_streams: determines the maximum number of video streams to
offer/accept from an endpoint. Defaults to 1.

ASTERISK-27076

Change-Id: I8afd8dd2eb538806a39b887af0abd046266e14c7
2017-06-28 18:36:29 +00:00
Richard Mudgett 11ec2945c7 chan_pjsip: Fix PJSIP_MEDIA_OFFER dialplan function read.
The construction of the returned string assumed incorrectly that the
supplied buffer would always be initialized as an empty string.  If it is
not an empty string we could overrun the supplied buffer by the length of
the non-empty buffer string plus one.  It is also theoreticaly possible
for the supplied buffer to be overrun by a string terminator during a read
operation even if the supplied buffer is an empty string.

* Fix the assumption that the supplied buffer would already be an empty
string.  The buffer is not guaranteed to contain an empty string by all
possible callers.

* Fix string terminator buffer overrun potential.

Change-Id: If6a0806806527678c8554b1dcb34fd7808aa95c9
2017-06-15 12:35:53 -05:00
Jenkins2 abe1dd3039 Merge "pjsip: Extend 'asymmetric_rtp_codec' option to include us changing." 2017-06-13 09:17:10 -05:00
Joshua Colp 5b80496b42 chan_pjsip: Update device state when in early media.
The chan_pjsip module uses a calculation approach for
determining device state. This means that in situations
where we would expect device state to change we need to
tell the core to query. A scenario that was missed is
when early media was signaled.

This change adds the notification for the core to
query device state when we are told that early media
is being provided.

ASTERISK-27039

Change-Id: Iafebfd152894966344ff2e950a3cee9f59a3eb6f
2017-06-07 15:23:14 -05:00
Joshua Colp d3e951edf5 pjsip: Extend 'asymmetric_rtp_codec' option to include us changing.
PJSIP support in Asterisk differs from chan_sip in that it
allows media to be sent as-is without transcoding provided
the codecs were negotiated in the SDP. This is allowed
according to the RFC. Support for this differs quite a lot
though and some endpoints do not handle it well.

This change extends the 'asymmetric_rtp_codec' option to
also cover this case. When set to no (the default) the code
behaves as chan_sip does - the best codec is selected and
we will only ever send that, unless we change what we are
sending if the remote side changes. When set to yes we
will send media as-is without transcoding if the codec
has been negotiated in the SDP.

ASTERISK-26996

Change-Id: Ib1647f6902a0843e8c435946f831c2159e8d1d51
2017-06-07 13:34:58 +00:00