Commit Graph

5838 Commits

Author SHA1 Message Date
Joshua Colp 57bbba7d43 Merge "res_stasis: Plug reference leak on stolen channels" 2017-06-19 16:49:39 -05:00
Corey Farrell 70d2ccb9da Core: Add support for systemd socket activation.
This change adds support for socket activation of certain SOCK_STREAM
listeners in Asterisk:
* AMI / AMI over TLS
* CLI
* HTTP / HTTPS

Example systemd units are provided.  This support extends to any socket
which is initialized using ast_tcptls_server_start, so any unknown
modules using this function will support socket activation.

Asterisk continues to function as normal if socket activation is not
enabled or if systemd development headers are not available during
build.

ASTERISK-27063 #close

Change-Id: Id814ee6a892f4b80d018365c8ad8d89063474f4d
2017-06-19 13:33:48 -04:00
George Joseph 3f5bf287a2 Merge "SDP: Add get/set option calls for RTP sched context per type." 2017-06-19 09:27:43 -05:00
George Joseph 854a6de819 res_stasis: Plug reference leak on stolen channels
When a stasis channel is stolen by another app, the control
structure is unreffed but never unlinked from the app_controls
container.  This causes the channel reference to leak.

Added OBJ_UNLINK to the callback in channel_stolen_cb.

Also added some additional channel lifecycle debug messages to
channel.c.

ASTERISK-27059 #close
Repoorted-by: George Joseph

Change-Id: Ib820936cd49453f20156971785e7f4f182c56e14
2017-06-16 15:08:45 -05:00
Frederic LE FOLL 0ad95bc8a0 Core/PBX: Deadlock between dialplan execution and application unregistration.
Not easy to reproduce, but we have noticed deadlocks when unloading a module
while dialplan is handling a request.

The deadlock is between :
1) Dialplan execution: pbx_extension_helper() first taking conlock,
then pbx_findapp() [when called] asking for lock on apps list.
2) Application unregistration: ast_unregister_application() first taking lock
on apps list, then unreference_cached_app() [when called] asking for conlock.

As a protection, I suggest to modify ast_unregister_application(), so that it
anticipates the need of conlock, before taking the lock on apps list.
The side effect is a longer unavailability of conlock when unregistering an
application.

ASTERISK-27041

Change-Id: I0db0f1eb320da6a5758cce3a47d765be1face8e2
2017-06-16 13:26:22 -05:00
Joshua Colp 0405185357 Merge "SDP: Search for the ice-lite attribute in the right place." 2017-06-16 12:00:38 -05:00
Jenkins2 d81293a5dd Merge changes from topic 'sdp_api_adjustments'
* changes:
  SDP: Set the remote c= line in RTP instance.
  SDP: Add t= line in sdp_create_from_state()
  stream: Ignore declined streams for some topology calls.
2017-06-16 11:51:41 -05:00
Jenkins2 2f684eb6a5 Merge "stream: Add ast_stream_topology_del_stream() and unit test." 2017-06-16 11:50:32 -05:00
Joshua Colp 41bd01c861 Merge "channel: Fix reference counting in ast_channel_suppress." 2017-06-15 16:24:55 -05:00
Richard Mudgett e563a1920e SDP: Add get/set option calls for RTP sched context per type.
Change-Id: I82dc75c63c48904e9e5a49e2205dcc06e88487e4
2017-06-15 09:42:15 -05:00
Richard Mudgett 716abaf33d SDP: Search for the ice-lite attribute in the right place.
* Pulled finding the rtcp-mux attribute flag out of the ICE candidate for
loop.  Also ordered the RTCP ICE candidate skip test to fail earlier.

Change-Id: I8905d9c68563027a46cd3ae14dbcc27e9c814809
2017-06-15 09:42:15 -05:00
Richard Mudgett a95584d079 SDP: Set the remote c= line in RTP instance.
Change-Id: I23b646392082deab65bedeb19b12dcbcb9216d0c
2017-06-15 09:42:15 -05:00
Richard Mudgett 06265b8c8a stream: Add ast_stream_topology_del_stream() and unit test.
Change-Id: If07e3c716a2e3ff85ae905c17572ea6ec3cdc1f9
2017-06-15 09:42:15 -05:00
Richard Mudgett 0fdb99c268 SDP: Add t= line in sdp_create_from_state()
Change-Id: I4060391328a893101ed87d0d9bacbbab4fd8b141
2017-06-15 09:42:15 -05:00
Richard Mudgett 4797a8bb81 stream: Ignore declined streams for some topology calls.
* Made ast_format_cap_from_stream_topology() not include any formats from
declined streams.

* Made ast_stream_topology_get_first_stream_by_type() ignore declined
streams to return the first active stream of the type.

* Updated unit tests to check these changes have the expected effect.

Change-Id: Iabbc6a3e8edf263a25fd3056c3c614407c7897df
2017-06-15 09:42:15 -05:00
Joshua Colp bd16c3c524 channel: Fix reference counting in ast_channel_suppress.
The ast_channel_suppress function wrongly decremented the
reference count of the underlying structure used to keep
track of what should be suppressed on a channel if the
function was called multiple times on the same channel.

This change cleans up the reference counting a bit so
this no longer occurs.

ASTERISK-27016

Change-Id: I2eed4077cb4916e6626f9f120b63b963acc5c136
2017-06-15 07:36:59 -05:00
Joshua Colp d6386a8f0c bridge: Add a deferred queue.
This change adds a deferred queue to bridging. If a bridge
technology determines that a frame can not be written and
should be deferred it can indicate back to bridging to do so.
Bridging will then requeue any deferred frames upon a new
channel joining the bridge.

This change has been leveraged for T.38 request negotiate
control frames. Without the deferred queue there is a race
condition between the bridge receiving the T.38 request
negotiate and the second channel joining and being in the
bridge. If the channel is not yet in the bridge then the T.38
negotiation fails.

A unit test has also been added that confirms that a T.38
request negotiate control frame is deferred when no other
channel is in the bridge and that it is requeued when a new
channel joins the bridge.

ASTERISK-26923

Change-Id: Ie05b08523f399eae579130f4a5f562a344d2e415
2017-06-13 17:06:15 -05:00
Jenkins2 5d3420a2de Merge "BuildSystem: Add patches to allow building with recent LibreSSL" 2017-06-13 05:47:10 -05:00
Guido Falsi d27168d36f BuildSystem: Add patches to allow building with recent LibreSSL
Add some #if defined checks which allow building against LibreSSL.
These patchess come from OpenBSD ports:
https://cvsweb.openbsd.org/cgi-bin/cvsweb/ports/telephony/asterisk/patches/

ASTERISK-27043 #close
Reported by: OpenBSD ports

Change-Id: I2f6c08a5840b85ad4d2b75370b947ddde7a9a572
2017-06-09 15:34:34 +02:00
Guido Falsi 7b668297f3 BuildSystem: Fix build on FreeBSD due to missing crypt.h
FreeBSD does not include a crypt.h include file. Definitions for
crypt() and crypt_r() are in unistd.h

ASTERISK-27042 #close

Change-Id: Ib307ee5e384870c6af50efa89fb73722dd0c3a7e
2017-06-08 10:42:54 -05:00
Jenkins2 29f87a5530 Merge "channel: ast_write frame wrongly freed after call to audiohooks" 2017-06-07 08:07:10 -05:00
Jenkins2 452e6315bb Merge "format: Reintroduce smoother flags" 2017-06-06 08:59:37 -05:00
Joshua Colp 1a24543124 Merge "Confbridge: Add "sfu" video mode to bridge profile options." 2017-06-06 07:05:13 -05:00
Jenkins2 bb2f6234da Merge "Add primitive SFU support to bridge_softmix." 2017-06-06 06:57:24 -05:00
Kevin Harwell d8802a6a0f channel: ast_write frame wrongly freed after call to audiohooks
ASTERISK-26419 introduced a bug when calling ast_audiohook_write_list in
ast_write. It would free the frame given to ast_write if the frame returned
by ast_audiohook_write_list was different than the given one. The frame give
to ast_write should never be freed within that function. It is the caller's
resposibility to free the frame after writing (or when it its done with it).
By freeing it within ast_write this of course led to some memory corruption
problems.

This patch makes it so the frame given to ast_write is no longer freed within
the function. The frame returned by ast_audiohook_write_list is now subsequently
used in ast_write and is freed later. It is freed either after translate if the
frame returned by translate is different, or near the end of ast_write prior to
function exit.

ASTERISK-26973 #close

Change-Id: Ic9085ba5f555eeed12f6e565a638c3649695988b
2017-06-05 11:27:32 -05:00
Sean Bright 001f4ddda4 pbx_builtin: Properly handle hangup during Background
Before this patch, when a user hung up during a Background, we would
stuff 0xff into a char and attempt a dialplan lookup of it. This caused
problems for some realtime engines which interpreted the value as the
beginning of an invalid UTF-8 sequence.

ASTERISK-19291 #close
Reported by: Andrew Nowrot

Change-Id: I8ca6da93252d61c76ebdb46a4aa65e73ca985358
2017-05-31 12:25:54 -05:00
Joshua Colp f6eeaaafd5 channel / app_meetme: Fix parentheses.
ASTERISK-27025

Change-Id: Id736b0aa4ec6b6b0f04663d64fa8d151f81fdbed
2017-05-31 09:00:09 -05:00
Sean Bright 5c27fe2187 format: Reintroduce smoother flags
In review 4843 (ASTERISK-24858), we added a hack that forced a smoother
creation when sending signed linear so that the byte order was adjusted
during transmission. This was needed because smoother flags were lost
during the new format work that was done in Asterisk 13.

Rather than rolling that same hack into res_rtp_multicast, re-introduce
smoother flags so that formats can dictate their own options.

Change-Id: I77b835fba0e539c6ce50014a984766f63cab2c16
2017-05-30 15:10:20 -05:00
Mark Michelson 39d14834f8 Confbridge: Add "sfu" video mode to bridge profile options.
A previous commit added plumbing to bridge_softmix to allow for an SFU
experience with Asterisk. This commit adds an option to app_confbridge
that allows for a confbridge to actually make use of the SFU video mode.

SFU mode is implemented in a "set it and forget it" kind of way. That
is, when the bridge is created, if SFU mode is enabled, then the video
mode gets set to SFU and cannot be changed. Future improvements may
allow for a hybrid experience (e.g. forward multiple video streams,
specifically those of the most recent talkers), but for this addition,
no such capability is present.

Change-Id: I87bbcb63dec6dbbb42488f894871b86f112b2020
2017-05-30 10:24:20 -05:00
Mark Michelson 2da869408a Add primitive SFU support to bridge_softmix.
This sets up the "plumbing" in bridge_softmix to
be able to accommodate Asterisk asking as an SFU
(selective forwarding unit) for conferences.

The way this works is that whenever a channel enters or leaves a
conference, all participants in the bridge get sent a stream topology
change request. The topologies consist of the channels' original
topology, along with video destination streams corresponding to each
participants' source video streams. So for instance, if Alice, Bob, and
Carol are in the conference, and each supplies one video stream, then
the topologies for each would look like so:

Alice:
Audio,
Source video(Alice),
Destination Video(Bob),
Destination video (Carol)

Bob:
Audio,
Source video(Bob)
Destination Video(Alice),
Destination video (Carol)

Carol:
Audio,
Source video(Carol)
Destination Video(Alice),
Destination video (Bob)

This way, video that arrives from a source video stream can then be
copied out to the destination video streams on the other participants'
channels.

Once the bridge gets told that a topology on a channel has changed, the
bridge constructs a map in order to get the video frames routed to the
proper destination streams. This is done using the bridge channel's
stream_map.

This change is bare-bones with regards to SFU support. Some key features
are missing at this point:

* Stream limits. This commit makes no effort to limit the number of
  streams on a specific channel. This means that if there were 50 video
  callers in a conference, bridge_softmix will happily send out topology
  change requests to every channel in the bridge, requesting 50+
  streams.

* Configuration. The plumbing has been added to bridge_softmix, but
  there has been nothing added as of yet to app_confbridge to enable SFU
  video mode.

* Testing. Some functions included here have unit tests.
  However, the functionality as a whole has only been verified by
  hand-tracing the code.

* Selectivenss. For a "selective" forwarding unit, this does not
  currently have any means of being selective.

* Features. Presumably, someone might wish to only receive video from
  specific sources. There are no external-facing functions at the moment
  that allow for users to select who they receive video from.

* Efficiency. The current scheme treats all video streams as being
  unidirectional. We could be re-using a source video stream as a
  desetnation, too. But to simplify things on this first round, I did it
  this way.

Change-Id: I7c44a829cc63acf8b596a337b2dc3c13898a6c4d
2017-05-30 10:24:01 -05:00
Joshua Colp 9c4f63263c manager: Clear the flag on the other channel.
During the channel flag audit an incorrect change was
done. The flag should be cleared on the second channel.

ASTERISK-26469

Change-Id: I770c5a389550a2fb5a6ade942fccbb2e1d9199c8
2017-05-26 11:43:12 -05:00
Jenkins2 56b6a71548 Merge "asterisk: Audit locking of channel when manipulating flags." 2017-05-26 09:25:51 -05:00
George Joseph 08edd54c1b unittests: Add a unit test that causes a SEGV and...
...that can only be run by explicitly calling it with
'test execute category /DO_NOT_RUN/ name RAISE_SEGV'

This allows us to more easily test CI and debugging tools that
should do certain things when asterisk coredumps.

To allow this a new member was added to the ast_test_info
structure named 'explicit_only'.  If set by a test, the test
will be skipped during a 'test execute all' or
'test execute category ...'.

Change-Id: Ia3a11856aae4887df9a02b6b081cc777b36eb6ed
2017-05-24 15:58:18 -05:00
Kevin Harwell 51375686f7 core/conversions: Added string to unsigned integer and long conversions
Added functions that convert a string to an unsigned integer or unsigned long.
A couple of unit test were also created to test the routines. The reasons for
adding these conversion utilities (and hopefully eventually more) are as
follows:

  * Conversion routines are functionally contained with consistent and
    better error checking
  * The function names offer a better description of what is happening
  * It encourages code reuse for easier bug fixing at a single source
  * It's simpler to use
  * It's unit testable

For instance, currently in a lot of places when converting to an integer or
similar the "sscanf" function is used. When using "sscanf" it may not be
immediately clear what's happening as it lacks semantic naming. Limited error
checking is usually done as well. For example, most of the time a check is done
to make sure the value converted, but does not check for overflows or negative
valued conversions when converting unsigned numbers.

Why use/wrap "strtoul" and not "sscanf" then? Primarily, it lacks some of the
built in error handling that "strtoul" has. For instance "strtoul" contains
overflow checks. Less so, but can still factor as reasons, "sscanf" is slightly
more complex in its use. And maybe a bit controversial, but it may be ("big if")
potentially slower than "strtoul" in some cases.

Change-Id: If7eaca4a48f8c7b89cc8b5a1f4bed2852fca82bb
2017-05-17 17:41:11 -05:00
Joshua Colp 5a7af00e80 asterisk: Audit locking of channel when manipulating flags.
When manipulating flags on a channel the channel has to be
locked to guarantee that nothing else is also manipulating
the flags. This change introduces locking where necessary to
guarantee this. It also adds helper functions that manipulate
channel flags and lock to reduce repeated code.

ASTERISK-26789

Change-Id: I489280662dba0f4c50981bfc5b5a7073fef2db10
2017-05-16 14:25:23 +00:00
George Joseph ce4d8dac91 Merge changes from topic 'sdp_api_adjustments'
* changes:
  SDP: Make process possible multiple fmtp attributes per rtpmap.
  SDP: Explicitly stop a RTP instance before destoying it.
  SDP: Rework merge_capabilities().
  SDP: Update ast_get_topology_from_sdp() to keep RTP map.
2017-05-12 12:29:39 -05:00
George Joseph 28d4e6be9b Merge "SDP: Remove sdp_state.remote_capabilities" 2017-05-12 12:29:15 -05:00
Jenkins2 f09e079294 Merge "SDP: Add interface_address to specify our address to use." 2017-05-12 11:49:58 -05:00
Jenkins2 542dd7d795 Merge "logger: Added logger_queue_limit to the configuration options." 2017-05-11 12:03:07 -05:00
Jenkins2 8b15719a11 Merge "tcptls: Improve error messages for TLS connections." 2017-05-11 10:46:15 -05:00
Richard Mudgett b8659be9b0 SDP: Make process possible multiple fmtp attributes per rtpmap.
Change-Id: Ie7511008d82b59590e0eb520a21b5e1da4bd7349
2017-05-09 12:57:57 -05:00
Richard Mudgett c2906dfa05 SDP: Remove sdp_state.remote_capabilities
The sdp_state.remote_capabilities was only used inside merge_sdps() and
subsequent calls to merge_sdps() by re-INVITE's would leak them.

Change-Id: I0ceb7838ea044cc913e8ad4a255c39c9740ae0ce
2017-05-09 12:57:57 -05:00
Richard Mudgett 16785c0908 SDP: Add interface_address to specify our address to use.
When we optionally set the interface_address we are forcing the media to
go out a specific interface address.  This allows us to optionally have
the media go out the interface that SIP signalling came in on or if we are
configured to have the media always go out a specific address.

Change-Id: I160d9fac322a075bd2557b430632544178196189
2017-05-09 12:57:57 -05:00
Richard Mudgett 367042bd3e SDP: Explicitly stop a RTP instance before destoying it.
* Made sdp_add_m_from_rtp_stream() and sdp_add_m_from_udptl_stream()
handle generating disabled/declined streams.

* Added /main/sdp/sdp_merge_asymmetric unit test.  It currently does not
check the offerer side negotiated SDP because that isn't the purpose of
this patch and there is much to be done to handle declined/dummy streams.

* Added T.38 image streams to the /main/sdp/sdp_merge_symmetric and
/main/sdp/sdp_merge_crisscross unit tests.

Change-Id: Ib4dcb3ca4f9a9133b376f4e3302f9a1f963f2b31
2017-05-09 12:57:57 -05:00
Richard Mudgett be5809fac8 SDP: Rework merge_capabilities().
* Tried to give better variable names.
* Made our SDP answer use the offer's RTP payload types as the SDP RFC
says we SHOULD.
* Updating the local topology now takes the stream format caps.  We are
likely preparing to send an offer.

Change-Id: I34d3be8e3036402a8575ffcae3eebc5ce348d7c0
2017-05-09 12:57:57 -05:00
Richard Mudgett ae7689f093 SDP: Update ast_get_topology_from_sdp() to keep RTP map.
* Add failure exits to ast_get_topology_from_sdp().

Change-Id: I4cc85c1ede8d712766ed20f544dbcef04c8c1049
2017-05-09 12:57:57 -05:00
Joshua Colp cbbd119c21 tcptls: Improve error messages for TLS connections.
This change uses the functions provided by OpenSSL to query
and better construct error messages for situations where
the connection encounters a problem.

ASTERISK-26606

Change-Id: I7ae40ce88c0dc4e185c4df1ceb3a6ccc198f075b
2017-05-09 16:12:04 +00:00
Joshua Elson 10a4439ac9 Prevent Undefined Capath Crash
It is possible to initialize a valid config without a capath
or cafile definition. This will cause a crash on a reload.

This fix ensures capath is always allocated.

ASTERISK-26983 #close

Change-Id: I63ff715d9d9023427543a5b8a4ba7b0d82533c12
2017-05-09 09:22:00 -05:00
Joshua Colp c62b5721b3 Merge "stream: ast_stream_clone() cannot copy the opaque user data." 2017-05-08 17:25:22 -05:00
George Joseph 201346fb7d logger: Added logger_queue_limit to the configuration options.
All log messages go to a queue serviced by a single thread
which does all the IO.  This setting controls how big that
queue can get (and therefore how much memory is allocated)
before new messages are discarded. The default is 1000.
Should something go bezerk and log tons of messages in a tight
loop, this will prevent memory escalation.

When the limit is reached, a WARNING is logged to that effect
and messages are discarded until the queue is empty again.  At
that time another WARNING will be logged with the count of
discarded messages.  There's no "low water mark" for this queue
because the logger thread empties the entire queue and processes it
in 1 batch before going back and waiting on the queue again.
Implementing a low water mark would mean additional locking as
the thread processes each message and it's not worth it.

A "test" was added to test_logger.c but since the outcome is
non-deterministic, it's really just a cli command, not a unit
test.

Change-Id: Ib4520c95e1ca5325dbf584c7989ce391649836d1
2017-05-08 16:49:13 -05:00
Joshua Colp d96f755682 Merge "netsock2.c: Made get/set addr port avoid potential uninitialized memory." 2017-05-08 08:44:22 -05:00
Joshua Colp 552e6d81ef Merge "bridge: Fix returning to dialplan when executing Bridge() from AMI." 2017-05-08 07:33:07 -05:00
Richard Mudgett 56c5c51076 stream: ast_stream_clone() cannot copy the opaque user data.
ast_stream_clone() cannot copy the opaque user data stored on a stream.
We don't know how to clone the data so it isn't copied into the clone.

Change-Id: Ia51321bf38ecbfdcc53787ca77ea5fd2cabdf367
2017-05-05 18:49:19 -05:00
Richard Mudgett 924628812b netsock2.c: Made get/set addr port avoid potential uninitialized memory.
Change-Id: I532052bd7cd95a4b3565485fc01e2a1ea07ee647
2017-05-05 18:49:19 -05:00
George Joseph 0001834157 app_confbridge: Fix reference to cfg in menu_template_handler
menu_template_handler wasn't properly accounting for the fact that
it might be called both during a load/reload (which isn't really
valid but not prevented) and by a dialplan function.  In both cases
it was attempting to use the "pending" config which wasn't valid in
the latter case.  aco_process_config is also partly to blame because
it wasn't properly cleaning "pending" up when a reload was done and
no changes were made.  Both of these contributed to a crash if
CONFBRIDGE(menu,template) was called in a dialplan after a reload.

* aco_process_config now sets info->internal->pending to NULL
  after it unrefs it although this isn't strictly necessary in the
  context of this fix.
* menu_template_handler now uses the "current" config and silently
  ignores any attempt to be called as a result of someone uses the
  "template" parameter in the conf file.

Luckily there's no other place in the codebase where
aco_pending_config is used outside of aco_process_config.

ASTERISK-25506 #close
Reported-by: Frederic LE FOLL

Change-Id: Ib349a17d3d088f092480b19addd7122fcaac21a7
2017-05-04 20:13:55 -05:00
Jenkins2 a20db27c56 Merge "SDP: Replace SDP telephone_event option with dtmf option" 2017-05-04 19:17:06 -05:00
Joshua Colp c90d81ef51 bridge: Fix returning to dialplan when executing Bridge() from AMI.
When using the Bridge AMI action on the same channel multiple times
it was possible for the channel to return to the wrong location in
the dialplan if the other party hung up. This happened because the
priority of the channel was not preserved across each action
invocation and it would fail to move on to the next priority in
other cases.

This change makes it so that the priority of a channel is preserved
when taking control of it from another thread and it is incremented
as appropriate such that the priority reflects where the channel
should next be executed in the dialplan, not where it may or may not
currently be.

The Bridge AMI action was also changed to ensure that it too
starts the channels at the next location in the dialplan.

ASTERISK-24529

Change-Id: I52406669cf64208aef7252a65b63ade31fbf7a5a
2017-05-04 16:40:04 -05:00
Kevin Harwell 7b0e3b92fd bridge_simple: Added support for streams
This patch is the first cut at adding stream support to the bridging framework.
Changes were made to the framework that allows mapping of stream topologies to
a bridge's supported media types.

The first channel to enter a bridge initially defines the media types for a
bridge (i.e. a one to one mapping is created between the bridge and the first
channel). Subsequently added channels merge their media types into the bridge's
adding to it when necessary. This allows channels with different sized
topologies to map correctly to each other according to media type. The bridge
drops any frame that does not have a matching index into a given write stream.

For now though, bridge_simple will align its two channels according to size or
first to join. Once both channels join the bridge the one with the most streams
will indicate to the other channel to update its streams to be the same as that
of the other. If both channels have the same number of streams then the first
channel to join is chosen as the stream base.

A topology change source was also added to a channel when a stream toplogy
change request is made. This allows subsystems to know whether or not they
initiated a change request. Thus avoiding potential recursive situations.

ASTERISK-26966 #close

Change-Id: I1eb5987921dd80c3cdcf52accc136393ca2d4163
2017-05-03 16:36:22 -05:00
Richard Mudgett cd272da7a8 SDP: Replace SDP telephone_event option with dtmf option
The telephone_event option was used as a flag and a bit mapped value in
different places when it is a boolean.  It is also inadequate to configure
the DTMF operation of the RTP instance created for the stream.

Change-Id: Ib1addeaf0ce86f07039f2f979cab29405dc5239b
2017-05-02 10:59:53 -05:00
Joshua Colp 1d6429b269 Merge "SDP: Make SDP translation to/from internal representation more const." 2017-05-02 05:19:59 -05:00
Joshua Colp 090c6b702e Merge "stream: Make ast_stream_topology_create_from_format_cap() allow NULL cap." 2017-05-02 05:19:12 -05:00
Jenkins2 9af53d3563 Merge "SDP: Make ast_sdp_state_set_remote_sdp() return error." 2017-05-01 17:01:20 -05:00
Jenkins2 74134a03bc Merge "SDP: Misc cleanups (Mostly memory leaks)" 2017-05-01 14:19:34 -05:00
Jenkins2 94b97e0835 Merge "SDP API: Add SSRC-level attributes" 2017-05-01 14:16:55 -05:00
Richard Mudgett ede90e4aa5 SDP: Make SDP translation to/from internal representation more const.
Change-Id: I473a174b869728604b37c60853896b0c458bc504
2017-04-27 19:08:05 -05:00
Richard Mudgett 5c1851cbc0 stream: Make ast_stream_topology_create_from_format_cap() allow NULL cap.
Change-Id: Ie29760c49c25d7022ba2124698283181a0dd5d08
2017-04-27 19:08:05 -05:00
Richard Mudgett d71c6e3bfd SDP: Make ast_sdp_state_set_remote_sdp() return error.
Change-Id: I7707c9d872c476d897ff459008652b35142a35e1
2017-04-27 19:08:05 -05:00
Richard Mudgett 176123e76c SDP: Misc cleanups (Mostly memory leaks)
Change-Id: I74431b385da333f2c5f5a6d7c55e70b69a4f05d2
2017-04-27 19:08:05 -05:00
Jenkins2 528e238447 Merge "channel: Add ability to request an outgoing channel with stream topology." 2017-04-27 17:53:53 -05:00
Jenkins2 16089ae1c9 Merge "frame: Better handle interpolated frames." 2017-04-27 17:29:02 -05:00
Mark Michelson d6535c0080 SDP API: Add SSRC-level attributes
RFC 5576 defines how SSRC-level attributes may be added to SDP media
descriptions. In general, this is useful for grouping related SSRCes,
indicating SSRC-level format attributes, and resolving collisions in RTP
SSRC values. These attributes are used widely by browsers during WebRTC
communications, including attributes defined by documents outside of RFC
5576.

This commit introduces the addition of SSRC-level attributes into SDPs
generated by Asterisk. Since Asterisk does not tend to use multiple
SSRCs on a media stream, the initial support is minimal. Asterisk
includes an SSRC-level CNAME attribute if configured to do so. This at
least gives browsers (and possibly others) the ability to resolve SSRC
collisions at offer-answer time.

In order to facilitate this, the RTP engine API has been enhanced to be
able to retrieve the SSRC and CNAME on a given RTP instance.

res_rtp_asterisk currently does not provide meaningful CNAME values in
its RTCP SDES items, and therefore it currently will always return an
empty string as the CNAME value. A task in the near future will result
in res_rtp_asterisk generating more meaningful CNAMEs.

Change-Id: I29e7f23e7db77524f82a3b6e8531b1195ff57789
2017-04-27 15:03:51 -05:00
Joshua Colp 2b22c3c84b channel: Add ability to request an outgoing channel with stream topology.
This change extends the ast_request functionality by adding another
function and callback to create an outgoing channel with a requested
stream topology. Fallback is provided by either converting the
requested stream topology into a format capabilities structure if
the channel driver does not support streams or by converting the
requested format capabilities into a stream topology if the channel
driver does support streams.

The Dial application has also been updated to request an outgoing
channel with the stream topology of the calling channel.

ASTERISK-26959

Change-Id: Ifa9037a672ac21d42dd7125aa09816dc879a70e6
2017-04-27 10:39:46 +00:00
Joshua Colp 78eb08e7ba Merge "sdp: Add support for T.38" 2017-04-27 05:38:14 -05:00
Joshua Colp ed69471f94 Merge "SDP: Ensure SDPs "merge" properly." 2017-04-27 05:38:07 -05:00
Joshua Colp 985a5fd7aa frame: Better handle interpolated frames.
Interpolated frames are frames which contain a number of
samples but have no actual data. Audiohooks did not
handle this case when translating an incoming frame into
signed linear. It assumed that a frame would always contain
media when it may not. If this occurs audiohooks will now
immediately return and not act on the frame.

As well for users of ast_trans_frameout the function has
been changed to be a bit more sane and ensure that the data
pointer on a frame is set to NULL if no data is actually
on the frame. This allows the various spots in Asterisk that
check for an interpolated frame based on the presence of a
data pointer to work as expected.

ASTERISK-26926

Change-Id: I7fa22f631fa28d540722ed789ce28e84c7f8662b
2017-04-26 11:34:59 -05:00
Jenkins2 e478d2eb94 Merge "res_pjsip_sdp_rtp: No rtpmap for static RTP payload IDs in SDP." 2017-04-26 10:44:00 -05:00
Joshua Colp 19a79ae12c sdp: Add support for T.38
This change adds a T.38 format which can be used in a stream
topology to specify that a UDPTL stream needs to be created.
The SDP API has been changed to understand T.38 and create
the UDPTL session, add the attributes, and parse the attributes.

This change does not change the boundary of the T.38 state
machine. It is still up to the channel driver to implement and
act on it (such as queueing control frames or reacting to them).

ASTERISK-26949

Change-Id: If28956762ccb8ead562ac6c03d162d3d6014f2c7
2017-04-25 13:03:33 -05:00
Mark Michelson 32b3e36c68 SDP: Ensure SDPs "merge" properly.
The gist of this work ensures that when a remote SDP is received, it is
merged properly with the local capabilities. The remote SDP is converted
into a stream topology. That topology is then merged with the current
local topology on the SDP state. That new merged topology is then used
to create an SDP. Finally, adjustments are made to RTP instances based
on knowledge gained from the remote SDP.

There are also a battery of tests in this commit that ensure that some
basic SDP merges work as expected.

While this may not sound like a big change, it has the property that it
caused lots of ancillary changes.

* The remote SDP is no longer stored on the SDP state. Biggest reason:
  there's no need for it. The remote SDP is used at the time it is being
  set and nowhere else.

* Some new SDP APIs were added in order to find attributes and convert
  generic SDP attributes into rtpmap structures.

* Writing tests made me realize that retrieving a value from an SDP
  options structure, the SDP options needs to be made const.

* The SDP state machine was essentially gutted by a previous commit.
  Initially, I attempted to reinstate it, but I found that as it had
  been defined, it was not all that useful. What was more useful was
  knowing the role we play in SDP negotiation, so the SDP state machine
  has been transformed into an indicator of role.

* Rather than storing separate local and joint stream state
  capabilities, it makes more sense to keep track of current stream
  state and update it as things change.

Change-Id: I5938c2be3c6f0a003aa88a39a59e0880f8b2df3d
2017-04-25 13:03:33 -05:00
Sean Bright 59203c51cc core: Use eventfd for alert pipes on Linux when possible
The primary win of switching to eventfd when possible is that it only
uses a single file descriptor while pipe() will use two. This means for
each bridge channel we're reducing the number of required file
descriptors by 1, and - if you're using timerfd - we also now have 1
less file descriptor per Asterisk channel.

The API is not ideal (passing int arrays), but this is the cleanest
approach I could come up with to maintain API/ABI.

I've also removed what I believe to be an erroneous code block that
checked the non-blocking flag on the pipe ends for each read. If the
file descriptor is 'losing' its non-blocking mode, it is because of a
bug somewhere else in our code.

In my testing I haven't seen any measurable difference in performance.

Change-Id: Iff0fb1573e7f7a187d5211ddc60aa8f3da3edb1d
2017-04-24 11:50:09 -05:00
George Joseph dc6654d969 Merge "pbx: Use same thread if AST_OUTGOING_WAIT_COMPLETE specified" 2017-04-21 15:47:36 -05:00
Sean Bright c47b3e74d2 pbx: Use same thread if AST_OUTGOING_WAIT_COMPLETE specified
Both ast_pbx_outgoing_app() and ast_pbx_outgoing_exten() cause the core
to spawn a new thread to perform the dial. When AST_OUTGOING_WAIT_COMPLETE
is passed to these functions, the calling thread will be blocked until
the newly created channel has been hung up.

After this patch, we run the dial on the current thread rather than
spawning a new one. The only in-tree code that passes
AST_OUTGOING_WAIT_COMPLETE is pbx_spool, so you should see reduced
thread usage if you are using .call files.

Change-Id: I512735d243f0a9da2bcc128f7a96dece71f2d913
2017-04-19 16:43:55 -05:00
Richard Mudgett d165079cbc rtp_engine/res_rtp_asterisk: Fix RTP struct reentrancy crashes.
The struct ast_rtp_instance has historically been indirectly protected
from reentrancy issues by the channel lock because early channel drivers
held the lock for really long times.  Holding the channel lock for such a
long time has caused many deadlock problems in the past.  Along comes
chan_pjsip/res_pjsip which doesn't necessarily hold the channel lock
because sometimes there may not be an associated channel created yet or
the channel pointer isn't available.

In the case of ASTERISK-26835 a pjsip serializer thread was processing a
message's SDP body while another thread was reading a RTP packet from the
socket.  Both threads wound up changing the rtp->rtcp->local_addr_str
string and interfering with each other.  The classic reentrancy problem
resulted in a crash.

In the case of ASTERISK-26853 a pjsip serializer thread was processing a
message's SDP body while another thread was reading a RTP packet from the
socket.  Both threads wound up processing ICE candidates in PJPROJECT and
interfering with each other.  The classic reentrancy problem resulted in a
crash.

* rtp_engine.c: Make the ast_rtp_instance_xxx() calls lock the RTP
instance struct.

* rtp_engine.c: Make ICE and DTLS wrapper functions to lock the RTP
instance struct for the API call.

* res_rtp_asterisk.c: Lock the RTP instance to prevent a reentrancy
problem with rtp->rtcp->local_addr_str in the scheduler thread running
ast_rtcp_write().

* res_rtp_asterisk.c: Avoid deadlock when local RTP bridging in
bridge_p2p_rtp_write() because there are two RTP instance structs
involved.

* res_rtp_asterisk.c: Avoid deadlock when trying to stop scheduler
callbacks.  We cannot hold the instance lock when trying to stop a
scheduler callback.

* res_rtp_asterisk.c: Remove the lock in struct dtls_details and use the
struct ast_rtp_instance ao2 object lock instead.  The lock was used to
synchronize two threads to prevent a race condition between starting and
stopping a timeout timer.  The race condition is no longer present between
dtls_perform_handshake() and __rtp_recvfrom() because the instance lock
prevents these functions from overlapping each other with regards to the
timeout timer.

* res_rtp_asterisk.c: Remove the lock in struct ast_rtp and use the struct
ast_rtp_instance ao2 object lock instead.  The lock was used to
synchronize two threads using a condition signal to know when TURN
negotiations complete.

* res_rtp_asterisk.c: Avoid deadlock when trying to stop the TURN
ioqueue_worker_thread().  We cannot hold the instance lock when trying to
create or shut down the worker thread without a risk of deadlock.

This patch exposed a race condition between a PJSIP serializer thread
setting up an ICE session in ice_create() and another thread reading RTP
packets.

* res_rtp_asterisk.c:ice_create(): Set the new rtp->ice pointer after we
have re-locked the RTP instance to prevent the other thread from trying to
process ICE packets on an incomplete ICE session setup.

A similar race condition is between a PJSIP serializer thread resetting up
an ICE session in ice_create() and the timer_worker_thread() processing
the completion of the previous ICE session.

* res_rtp_asterisk.c:ast_rtp_on_ice_complete(): Protect against an
uninitialized/null remote_address after calling
update_address_with_ice_candidate().

* res_rtp_asterisk.c: Eliminate the chance of ice_reset_session()
destroying and setting the rtp->ice pointer to NULL while other threads
are using it by adding an ao2 wrapper around the PJPROJECT ice pointer.
Now when we have to unlock the RTP instance object to call a PJPROJECT ICE
function we will hold a ref to the wrapper.  Also added some rtp->ice NULL
checks after we relock the RTP instance and have to do something with the
ICE structure.

ASTERISK-26835 #close
ASTERISK-26853 #close

Change-Id: I780b39ec935dcefcce880d50c1a7261744f1d1b4
2017-04-19 13:40:57 -05:00
Alexander Traud 72c5f3b0ba res_pjsip_sdp_rtp: No rtpmap for static RTP payload IDs in SDP.
This saves around 100 bytes when G.711, G.722, G.729, and GSM are advertised in
SDP. This reduces the chance to hit the MTU bearer of 1300 bytes for SIP over
UDP, if many codecs are allowed in Asterisk. This new feature is enabled
together with the optional feature compact_headers=yes via the file pjsip.conf.

ASTERISK-26932 #close

Change-Id: Iaa556ab4c8325cd34c334387ab2847fab07b1689
2017-04-13 11:05:25 +02:00
George Joseph 747beb1ed1 modules: change module LOAD_FAILUREs to LOAD_DECLINES
In all non-pbx modules, AST_MODULE_LOAD_FAILURE has been changed
to AST_MODULE_LOAD_DECLINE.  This prevents asterisk from exiting
if a module can't be loaded.  If the user wishes to retain the
FAILURE behavior for a specific module, they can use the "require"
or "preload-require" keyword in modules.conf.

A new API was added to logger: ast_is_logger_initialized().  This
allows asterisk.c/check_init() to print to the error log once the
logger subsystem is ready instead of just to stdout.  If something
does fail before the logger is initialized, we now print to stderr
instead of stdout.

Change-Id: I5f4b50623d9b5a6cb7c5624a8c5c1274c13b2b25
2017-04-12 15:57:21 -06:00
Joshua Colp c5536eaee9 Merge "stun.c: Fix ast_stun_request() erratic timeout." 2017-04-12 04:54:33 -05:00
zuul 3c32680a8a Merge "sorcery.c: Speed up ast_sorcery_retrieve_by_id()" 2017-04-11 20:12:55 -05:00
Richard Mudgett 7c37365f03 stun.c: Fix ast_stun_request() erratic timeout.
If ast_stun_request() receives packets other than a STUN response then we
could conceivably never exit if we continue to receive packets with less
than three seconds between them.

* Fix poll timeout to keep track of the time when we sent the STUN
request.  We will now send a STUN request every three seconds regardless
of how many other packets we receive while waiting for a response until we
have completed three STUN request transmission cycles.

Change-Id: Ib606cb08585e06eb50877f67b8d3bd385a85c266
2017-04-11 12:58:35 -05:00
Richard Mudgett 8d323c74fa sorcery.c: Speed up ast_sorcery_retrieve_by_id()
Return early if ast_sorcery_retrieve_by_id() is not passed an id to find.
Also eliminated the RAII_VAR() usage in the function.

Change-Id: I871dbe162a301b5ced8b4393cec27180c7c6b218
2017-04-11 12:58:35 -05:00
Richard Mudgett d76bc0565c tcptls.c: Cleanup TCP/TLS listener thread on abnormal exit.
Temporarily running out of file descriptors should not terminate the
listener thread.  Otherwise, when there becomes more file descriptors
available, nothing is listening.

* Added EMFILE exception to abnormal thread exit.

* Added an abnormal TCP/TLS listener exit error message.

* Closed the TCP/TLS listener socket on abnormal exit so Asterisk does not
appear dead if something tries to connect to the socket.

ASTERISK-26903 #close

Change-Id: I10f2f784065136277f271159f0925927194581b5
2017-04-11 11:13:39 -05:00
Corey Farrell 380973cc47 CDR: Protect from data overflow in ast_cdr_setuserfield.
ast_cdr_setuserfield wrote to a fixed length field using strcpy. This could
result in a buffer overrun when called from chan_sip or func_cdr. This patch
adds a maximum bytes written to the field by using ast_copy_string instead.

ASTERISK-26897 #close
patches:
  0001-CDR-Protect-from-data-overflow-in-ast_cdr_setuserfie.patch submitted
    by Corey Farrell (license #5909)

Change-Id: Ib23ca77e9b9e2803a450e1206af45df2d2fdf65c
2017-04-04 10:14:26 +00:00
Mark Michelson cf4dd32bef Merge "sdp: Add support for setting connection address and clean up state." 2017-04-03 09:32:08 -05:00
Walter Doekes a7d94f504f build: Fix deb build issues with fakeroot
If DESTDIR is set, don't call ldconfig. Assume that DESTDIR is used to
create a binary archive. The ldconfig call should be delegated to the
archive postinst script. This fixes the case where fakeroot wraps 'make
install' causing $EUID to be 0 even though it doesn't have permission to
call ldconfig.

The previous logic in configure.ac to detect and correct libdir
has been removed as it was not completely accurate.  CentOS 64-bit
users should again specifiy --libdir=/usr/lib64 when configuring
to prevent install to /usr/lib.

Updated Makefile:check-old-libdir to check for orphans in
lib64 when installing to lib as well as orphans in lib when installing
to lib64.

Updated Makefile and main/Makefile uninstall targets to remove the
orphans using the new logic.

ASTERISK-26705

Change-Id: I51739d4a03e60bff38be719b8d2ead0007afdd51
2017-03-30 17:10:32 -05:00
Joshua Colp f3290d6b66 sdp: Add support for setting connection address and clean up state.
This change cleans up state management for media streams by moving
RTP instances into their own session structure and adding additional
details that are not relevant to the core (such as connection address).
These can live either in the local capabilities or joint capabilities.

The ability to set explicit connection address information for
the purposes of direct media and NAT has also been added at the
global and stream specific level.

ASTERISK-26900

Change-Id: If7e5307239a9534420732de11c451a2705b6b681
2017-03-30 18:26:10 +00:00
Sean Bright 5c1ea3ebbd astobj2: Prevent potential deadlocks with ao2_global_obj_release
The ao2_global_obj_release() function holds an exclusive lock on the
global object while it is being dereferenced. Any destructors that
run during this time that call ao2_global_obj_ref() will deadlock
because a read lock is required.

Instead, we make the global object inaccessible inside of the write
lock and only dereference it once we have released the lock. This
allows the affected destructors to fail gracefully.

While this doesn't completely solve the referenced issue (the error
message about not being able to create an IQ continues to be shown)
it does solve the backtrace spew that accompanied it.

ASTERISK-21009 #close
Reported by: Marcello Ceschia

Change-Id: Idf40ae136b5070dba22cb576ea8414fbc9939385
2017-03-30 13:59:11 -04:00
George Joseph 88a4c93e4c Merge "core: Remove embedded module support" 2017-03-29 14:40:36 -05:00
zuul 7c2f4601f2 Merge "channel: Remove old epoll support and fixed max number of file descriptors." 2017-03-29 12:45:47 -05:00
Joshua Colp 5d938045d4 channel: Remove old epoll support and fixed max number of file descriptors.
This change removes the old epoll support which has not been used or
maintained in quite some time.

The fixed number of file descriptors on a channel has also been removed.
File descriptors are now contained in a growable vector. This can be
used like before by specifying a specific position to store a file
descriptor at or using a new API call, ast_channel_fd_add, which adds
a file descriptor to the channel and returns its position.

Tests have been added which cover the growing behavior of the vector
and the new API call.

ASTERISK-26885

Change-Id: I1a754b506c009b83dfdeeb08c2d2815db30ef928
2017-03-27 19:54:44 +00:00
Sean Bright cf6a6226ab core: Remove embedded module support
This has not worked for some time and is no longer actively maintained.

Change-Id: I5110b0db69c152761b58fa025cb0a53b0e544d99
2017-03-27 10:36:08 -04:00
Joshua Colp 772afa59dc Merge "cdr: Allow setting of user field from 'h' extension" 2017-03-24 18:02:12 -05:00
zuul 90634cc184 Merge "rtp_engine: allocate RTP dynamic payloads per session" 2017-03-24 16:22:55 -05:00
Joshua Colp 59df60efb9 Merge "audiohook.c: Lost RTP packets lead to out-of-sync MixMonitor." 2017-03-24 07:25:07 -05:00
Kevin Harwell 9b103e7bea rtp_engine: allocate RTP dynamic payloads per session
Dynamic payload types were statically defined in Asterisk. This unfortunately
limited the number of dynamic payloads that could be registered. With this patch
dynamic payload type numbers are now assigned dynamically and per RTP instance.
However, in order to limit any issues where some clients expect the old
statically defined value this patch makes it so the value Asterisk used to pre-
designate is used for the dynamic assignment if available.

An option, "rtp_use_dynamic", has also been added (can be set in asterisk.conf)
that turns the new dynamic behavior on or off. When off it reverts back to using
statically defined payload values. This option defaults to "yes" in Asterisk 15.

ASTERISK-26515 #close
patches:
  ASTERISK-26515.diff submitted by jcolp (license 5000

Change-Id: I7653465c5ebeaf968f1a1cc8f3f4f5c4321da7fc
2017-03-22 15:43:33 -05:00
zuul 06c9966608 Merge "res_pjsip_messaging: Check URI type before dereferencing" 2017-03-22 12:36:43 -05:00
Sebastian Gutierrez bb2936f3e4 cdr: Allow setting of user field from 'h' extension
The CDR code previously did not allow the user field to be set
from the 'h' extension in the dialplan. This change removes that
limitation and allows it to be set.

ASTERISK-26818

Change-Id: I0fed8a79b5e408bac4e30542b8f33a61c5ed9aa6
2017-03-22 07:49:51 -06:00
zuul 9f64980e60 Merge "autochan/mixmonitor/chanspy: Fix unsafe channel locking and references." 2017-03-21 21:51:49 -05:00
Sean Bright 6b4b87787c res_pjsip_messaging: Check URI type before dereferencing
We aren't validating that the URI we just parsed is a SIP/SIPS one before
trying to access the user, host, and port members of a possibly uninitialized
structure.

Also update the MessageSend documentation to indicate what 'from' formats are
accepted.

ASTERISK-26484 #close
Reported by: Vinod Dharashive

Change-Id: I476b5cc5f18a7713d0ee945374f2a1c164857d30
2017-03-21 08:45:37 -06:00
Aaron An 25016a74f8 audiohook.c: Lost RTP packets lead to out-of-sync MixMonitor.
Fixed a bug in function "ast_audiohook_write_frame" that checked the
variable other_factory_samples and only flushed the factories, so they
would be in sync, when other_factory_samples > 0. When there is not any
rtp incoming the variable other_factory_samples will be 0, and although
the result of "our_factory_ms - other_factory_ms" may be very large,
this led to the record file not syncing.

ASTERISK-26875 #close
Reported-by: Aaron An
Tested-by: Aaron An

Change-Id: Ia4d890fb8fc1636a7188502bab35f555685aea22
2017-03-20 13:01:52 -06:00
Sean Bright fc71c18a9b thread safety: Don't use getprotobyname()
POSIX does not require getprotobyname() to be thread safe and some
implementations use static memory which causes issues when multiple
threads are used.

Further, our usage of it today is just to ultimately get IPPROTO_TCP
for calls to setsockopt(). So instead we just use IPPROTO_TCP directly.

Change-Id: I2e14e58674808f7ce99b2f5e900d0f90d0d8da48
2017-03-20 08:55:05 -04:00
Joshua Colp 76e64f5589 Merge "RFC sdp: Initial SDP creation" 2017-03-16 14:45:20 -05:00
zuul 3f30ce1272 Merge "pbx.c: Fix crash from malformed exten pattern." 2017-03-15 19:14:08 -05:00
Richard Mudgett c87e7dd9ec autochan/mixmonitor/chanspy: Fix unsafe channel locking and references.
Dereferencing struct ast_autochan.chan without first calling
ast_autochan_channel_lock() is unsafe because the pointer could change at
any time due to a masquerade.  Unfortunately, ast_autochan_channel_lock()
itself uses struct ast_autochan.chan unsafely and can result in a deadlock
if the original channel happens to get destroyed after a masquerade in
addition to the pointer getting changed.

The problem is more likely to happen with v11 and earlier because
masquerades are used to optimize out local channels on those versions.
However, it could still happen on newer versions if the channel is
executing a dialplan application when the channel is transferred or
redirected.  In this situation a masquerade still must be used.

* Added a lock to struct ast_autochan to safely be able to use
ast_autochan.chan while trying to get the channel lock in
ast_autochan_channel_lock().  The locking order is the channel lock then
the autochan lock.  Locking in the other direction requires deadlock
avoidance.

* Fix unsafe ast_autochan.chan usages in app_mixmonitor.c.

* Fix unsafe ast_autochan.chan usages in app_chanspy.c.

* app_chanspy.c: Removed unused autochan parameter from next_channel().

ASTERISK-26867

Change-Id: Id29dd22bc0f369b44e23ca423d2f3657187cc592
2017-03-15 17:18:55 -06:00
zuul 3fe1d8afba Merge "core: Add stream topology changing primitives with tests." 2017-03-15 17:23:30 -05:00
Richard Mudgett f997090877 pbx.c: Fix crash from malformed exten pattern.
Forgetting to indicate an exten is a pattern can cause a crash if the
"pattern" has a character set range.  e.g., "9999[3-5]" The crash is due
to a buffer overwrite because the '-' exten eye-candy wasn't removed as
expected and overran the allocated space.

The buffer overwrite is fixed two ways in this patch.

1) Fix ext_strncpy() to distinguish between pattern and non-pattern
extens.  Now '-' characters are removed when they are eye-candy and not
when they are part of a pattern character set.  Since the function is
private to pbx.c, the return value now returns the number of bytes written
to the destination buffer instead of the strlen() of the final buffer so
the callers that care don't need to add one.

2) Fix callers to ext_strncpy() to supply the correct available buffer
size of the destination buffer.

ASTERISK-26668

Change-Id: I555d97411140e47e0522684062d174fbe32aa84a
2017-03-14 17:09:53 -06:00
George Joseph 8470c2bdea RFC sdp: Initial SDP creation
* Added additional fields to ast_sdp_options.
* Re-organized ast_sdp.
* Updated field names to correspond to RFC4566 terminology.
* Created allocs/frees for SDP children.
* Created getters/setters for SDP children where appropriate.
* Added ast_sdp_create_from_state.
* Refactored res_sdp_translator_pjmedia for changes.

Change-Id: Iefbd877af7f5a4d3c74deead1bff8802661b0d48
2017-03-14 12:26:32 -06:00
Matt Jordan b03b72717f main/stasis_cache: Demote the ERROR message when removing a nonexistent item
This patch demotes the ERROR message that is displayed when a
nonexistent item is removed from the Stasis cache. The genesis of this
demotion is due to chan_sip's realtime peers and their interaction with
Asterisk's core ast_endpoint code, but ostensibly it could happen from
other channel drivers as well.

Since Mark Michelson already did an excellent job of explaining on this
issue, it is quoted here for posterity:

"Internally, when a realtime peer is retrieved, Asterisk creates an
ast_endpoint structure. When that peer is destroyed, the ast_endpoint is
destroyed as well. Part of the destruction of the ast_endpoint involves
clearing the Stasis cache of all information about that endpoint. The
problem here is that the act of creating the ast_endpoint is not enough
to actually put any information in the Stasis cache. Instead, something
has to happen, such as a state change, in order for the Stasis cache to
have any information about that endpoint. When a device registers,
chan_sip creates an ast_endpoint structure, processes the REGISTER, and
then destroys the ast_endpoint. When the ast_endpoint is destroyed,
there is nothing to destroy in the Stasis cache, so an error message is
emitted. When you use rtcachefriends, ast_endpoint structures persist
for the lifetime of the module and so you do not see this error
message."

ASTERISK-25237 #close

Change-Id: I53cebc6b4a897a1ab9564182b75c177780feff70
2017-03-14 08:40:54 -06:00
Sean Bright 35cfd2c0cc media_cache: Prefer ast_file_is_readable() over access()
Change-Id: Icc0dc6e61b2e68d5cdcb74b016b2726a388c7def
2017-03-08 17:26:41 -06:00
Joshua Colp 3ed05badb9 core: Add stream topology changing primitives with tests.
This change adds a few things to facilitate stream topology changing:

1. Control frame types have been added for use by the channel driver
to notify the application that the channel wants to change the stream
topology or that a stream topology change has been accepted. They are
also used by the indicate interface to the channel that the application
uses to indicate it wants to do the same.

2. Legacy behavior has been adopted in ast_read() such that if a
channel requests a stream topology change it is denied automatically
and the current stream topology is preserved if the application is
not capable of handling streams.

Tests have also been written which confirm the multistream and
non-multistream behavior.

ASTERISK-26839

Change-Id: Ia68ef22bca8e8457265ca4f0f9de600cbcc10bc9
2017-03-07 12:08:51 +00:00
Daniel Journo 272259a2c6 Saynumber is trying to get "and" from "digits/" subfolder
* say.c Changed 'digits/and' to 'vm-and' for en_GB

ASTERISK-26598 #close

Change-Id: If1b713e5daea6f952b339f139178d292a6c4fcfe
2017-03-06 15:59:49 -06:00
Richard Mudgett c9296b23d1 core: Cleanup ast_get_hint() usage.
* manager.c:manager_state_cb() Fix potential use of uninitialized hint[]
if a hint does not exist for the requested extension.  Ran into this when
developing a testsuite test.  The AMI event ExtensionStatus came out with
the hint header value containing garbage.  The AMI event PresenceStatus
also had the same issue.

* manager.c:action_extensionstate() no need to completely initialize the
hint[].  Only initialize the first element.

* pbx.c:ast_add_hint() Remove unnecessary assignment.

* chan_sip.c: Eliminate an unneeded hint[] local variable.  We only care
about the return value of ast_get_hint() there.

Change-Id: Ia9a8786f01f93f1f917200f0a50bead0319af97b
2017-03-02 21:46:51 -06:00
Joshua Colp fb11f038a3 Merge "stream: Unit tests for stream read and tweaks framework" 2017-03-01 14:58:45 -06:00
George Joseph 0560c32375 stream: Unit tests for stream read and tweaks framework
* Removed the AST_CHAN_TP_MULTISTREAM tech property.  We now rely
  on read_stream being set to indicate a multi stream channel.
* Added ast_channel_is_multistream convenience function.
* Fixed issue where stream and default_stream weren't being set on
  a frame retrieved from the queue.
* Now testing for NULL being returned from the driver's read or
  read_stream callback.
* Fixed issue where the dropnondefault code was crashing on a
  NULL f.
* Now enforcing that if either read_stream or write_stream are
  set when ast_channel_tech_set is called that BOTH are set.
* Added the unit tests.

ASTERISK-26816

Change-Id: If7792b20d782e71e823dabd3124572cf0a4caab2
2017-03-01 07:30:49 -07:00
Mark Michelson 9c55a71798 SDP: Add initial SDP state machine.
This introduces and documents the various states in the state machine.
This also introduces API functions that induce state changes, and places
TODO comments telling what needs to be done in addition to what is
already there. Those TODOs will be replaced with real code in upcoming
changes.

Change-Id: I871c0eb480b4c84d83e91ac5628e7a673e8b89ed
2017-03-01 12:12:46 +00:00
Joshua Colp 26bf1846e2 Merge "media_cache: Mark cache entry stale if cache file is removed" 2017-03-01 04:47:59 -06:00
Sean Bright 60e9e4fcc0 media_cache: Mark cache entry stale if cache file is removed
In the event that a cache file is removed out from under us, we should
treat the cache entry as stale and force a refresh.

ASTERISK-26774 #close
Reported by: Igor Gamayunov

Change-Id: I3b1bd0c999d59d18664ef73a29823bc5b431dc52
2017-02-28 16:09:54 -06:00
George Joseph 4692a32ed7 build: Warn if asterisk is installed in both 32 and 64 bit sys dirs
... and clean them both up on uninstall.

We've fixed the issue where 'make install' was installing to
/usr/lib on 64-bit systems that use /usr/lib64.  Now we need
to clean up the remnants in /usr/lib.

* 'make install' now prints a warning if DESTDIR/ASTLIBDIR
  contains 'lib64' and libasterisk* shared libraries or modules
  are also found in DESTDIR/ASTLIBDIR with 'lib64' transformed
  to 'lib'.

* 'make uninstall' ALWAYS cleans up both DESTDIR/ASTLIBDIR and
  DESTDIR/ASTLIBDIR with 'lib64' transformed to 'lib'.

ASTERISK-26705

Change-Id: I6edddeb3c07a51e7c7ba7cac3c05e4bf3ec3f01f
2017-02-27 12:57:18 -06:00
George Joseph df22d297a6 Merge "channel: Add ast_read_stream function for reading frames from all streams." 2017-02-27 08:51:26 -06:00
Joshua Colp 6ac33bfe3e Merge "Binaural synthesis (confbridge): Adds binaural synthesis to bridge_softmix." 2017-02-24 12:49:00 -06:00
zuul f943ead12e Merge "build: Execute ldconfig to build cache. (take two)" 2017-02-24 12:12:13 -06:00
zuul 461577b23b Merge "channel: Add support for writing to a specific stream." 2017-02-24 11:16:13 -06:00
Joshua Colp c07c6714f2 channel: Add ast_read_stream function for reading frames from all streams.
This change introduces an ast_read_stream function and callback in
the channel technology which allows reading frames from all streams
and not just the default streams.

The stream number has also been added to frames. This is to allow the
case where frames are queued onto the channel instead of being read
directly from the driver.

This change does impose a restriction on reading though: a chain of
frames can only contain frames from the same stream.

ASTERISK-26816

Change-Id: I5d7dc35e86694df91fd025126f6cfe0453aa38ce
2017-02-24 10:20:33 -06:00
George Joseph b0067bcf2c build: Execute ldconfig to build cache. (take two)
On some platforms a multiarch approach is used for libraries.
The build system does not take this into account and still
places libraries into the lib directory if no --libdir is
specified to configure. On initial startup this results in
libasteriskssl.so not being found, as it is not in the multiarch
lib directory.  To make matters worse, options were being passed
to ldconfig on both Linux and FreeBSD that actually prevented
the rebuild of the cache.

 * Fedora has a /usr/share/config.site that automatically tells
   autoconf to use /usr/lib64 but CentOS does not. This logic was
   copied to configure.ac and modified so systems like Ubuntu,
   which still use /usr/lib for 64-bit systems, aren't affected.

Now that we have them in the correct directory...

In order for the system loader to find libasteriskssl and
libasteriskpj, one of 3 things has to happen...

  - The linker cache must be rebuilt including the directory
    where the libasterisk* libraries were installed.  Only root
    can rebuild the cache.  This was busted.
  - We have to link the asterisk binary with an rpath pointing
    to the directrory where the libasterisk* libraries were
    installed.  This makes things very complicated and will happen
    over the collective dead bodies of everyone who's had to
    package a distribution with an rpath.
  - Finally, you can start asterisk with LD_LIBRARY_PATH set to the
    directrory where the libasterisk* libraries were installed.

There are no other options. So...

 * The invokation of ldconfig has been moved from main/Makefile
   to ASTTOPDIR/Makefile, the options have been removed, and
   DESTDIR/ASTLIBDIR appended.  If you aren't root, you will be
   warned after the "Asterisk Installation Compete" banner that
   you must re-run 'make install' as root, manually run
   'ldconfig DESTDIR/ASTLIBDIR' as root, or run asterisk with
   LD_LIBRARY_PATH.

ASTERISK-26705

Change-Id: I2a64b7c33a7d3e9bde20f47e3d3ab771977af982
2017-02-23 16:07:29 -06:00
Joshua Colp 6cc890b880 channel: Add support for writing to a specific stream.
This change adds an ast_write_stream function which allows
writing a frame to a specific media stream. It also moves
ast_write() to using this underneath by writing media
frames provided to it to the default streams of the channel.
Existing functionality (such as audiohooks, framehooks, etc)
are limited to being applied to the default stream only.

Unit tests have also been added which test the behavior of
both non-multistream and multistream channels to confirm that
the write() and write_stream() callbacks are invoked
appropriately.

ASTERISK-26793

Change-Id: I4df20d1b65bd4d787fce0b4b478e19d2dfea245c
2017-02-23 18:31:15 +00:00
frahaase 094c26aa68 Binaural synthesis (confbridge): Adds binaural synthesis to bridge_softmix.
Adds binaural synthesis to bridge_softmix (via convolution using libfftw3).
Binaural synthesis is conducted at 48kHz.
For a conference, only one spatial representation is rendered.
The default rendering is applied for mono-capable channels.

ASTERISK-26292

Change-Id: Iecdb381b6adc17c961049658678f6219adae1ddf
2017-02-23 10:34:58 -07:00
zuul 9ad1df71b3 Merge "Revert "build: Execute ldconfig to build cache."" 2017-02-22 13:56:48 -06:00
zuul 6c22d4b320 Merge "core: Show streams in "core show channel"." 2017-02-22 11:40:02 -06:00
Joshua Colp ced73d5b79 Revert "build: Execute ldconfig to build cache."
This reverts commit 28c8e4f58f.

Change-Id: Ie2e1aaf61fd49045994974a4581545ac8348fe4c
2017-02-22 11:12:54 -06:00
Joshua Colp 10302fa63f Merge "Add initial SDP state code." 2017-02-22 10:56:02 -06:00
Joshua Colp f58aefba5b core: Show streams in "core show channel".
The "core show channel" CLI command will now output the streams
present on the channel with their details.

ASTERISK-26811

Change-Id: I9c95b57aa09415005f0677a1949a0feb07e4987a
2017-02-22 14:32:23 +00:00
Mark Michelson a738772edd Add initial SDP state code.
This establishes the basic allocation/destruction of an SDP state
object, plus some of the simpler getter methods involved. Subsequent
tasks will deal with adding a state machine, creating SDPs from
capabilities and options, and merging SDPs into a joint SDP.

Change-Id: Ie3757ce186f04b65e9d1883f5aace53f24e53709
2017-02-21 15:14:34 -06:00
Joshua Colp 16b0bb39c1 Merge changes from topic 'sdp_state_beginnings'
* changes:
  Add SDP translator and PJMEDIA implementation.
  Add initial SDP options.
2017-02-21 13:37:03 -06:00
Joshua Colp 28c8e4f58f build: Execute ldconfig to build cache.
On some platforms a multiarch approach is used for libraries.
The build system does not take this into account and still
places libraries into the lib directory if no --libdir is
specified to configure. On initial startup this results in
libasteriskssl.so not being found, as it is not in the multiarch
lib directory.

This change does the minimally invasive thing and executes
ldconfig so that the libraries in the lib directory are found
and their location cached. By doing so Asterisk starts up fine.

If DESTDIR is specified, however, the old logic is executed as
the install process may not have permission to alter the ldconfig
cache.

ASTERISK-26705

Change-Id: If4eca46ac510c6fea5568256280ffdb3888d7bb4
2017-02-21 05:25:13 -06:00
zuul 8dde33d184 Merge "tcptls.c: Add some missing allocation failure checks." 2017-02-20 17:43:27 -06:00
zuul 496a7b0b4c Merge "Revert "build: Execute ldconfig to build cache."" 2017-02-20 14:09:27 -06:00
Joshua Colp 7739b0b3ae Revert "build: Execute ldconfig to build cache."
This reverts commit 8851c3e088.

Change-Id: I124380be5e3bd57da978428a2a93604336ccd0db
2017-02-20 11:19:55 -06:00
zuul c227745bc7 Merge "Remove extra ast_iostream_close() calls." 2017-02-17 17:41:06 -06:00
Richard Mudgett 0b427f9b59 tcptls.c: Add some missing allocation failure checks.
* Fix tcptls_session ref and fd leak in ast_tcptls_server_root().

Change-Id: I0ddf01cd3c10d3b6666d7bf68d4e206a37f4fbdb
2017-02-17 17:00:24 -06:00
Mark Michelson dbc3598014 Remove extra ast_iostream_close() calls.
When AMI encounters an error at the beginning of a session, it would
explicitly call ast_iostream_close() on its tcptls session's iostream.
It then would jump to a label where it would shut down the tcptls
session instance. The tcptls session instance would again attempt to
close the iostream.

Under normal circumstances, this might go by unnoticed. However, when
MALLOC_DEBUG is enabled, all fields on the iostream get set to
0xdeaddead when the iostream is freed. Thus a second call to
ast_iostream_close() after the iostream has been freed would reslt in an
attempt to call SSL_shutdown on 0xdeaddead, which would crash and burn
horribly.

The fix here is to not directly close the iostream from the dangerous
scenarios. The specific scenarios are:
* Exceeding the configured authlimit
* Failing to build a mansession on a new connection

Change-Id: I908f98d516afd5a263bd36b072221008a4731acd
2017-02-17 15:12:30 -06:00
Mark Michelson 5a130b2e17 Add SDP translator and PJMEDIA implementation.
This creates the following:
* Asterisk's internal representation of an SDP
* An API for translating SDPs from one format to another
* An implementation of a translator for PJMEDIA

Change-Id: Ie2ecd3cbebe76756577be9b133e84d2ee356d46b
2017-02-17 09:47:47 -06:00
Mark Michelson 8af6342555 Add initial SDP options.
This is step one of adding an SDP API: defining some
configurable settings for SDPs. This is based on options
that are currently supported in Asterisk.

Change-Id: I1ede91aafed403b12a9ccdfb91a88389baa7e5d7
2017-02-17 09:23:12 -06:00
Joshua Colp 8851c3e088 build: Execute ldconfig to build cache.
On some platforms a multiarch approach is used for libraries.
The build system does not take this into account and still
places libraries into the lib directory if no --libdir is
specified to configure. On initial startup this results in
libasteriskssl.so not being found, as it is not in the multiarch
lib directory.

This change does the minimally invasive thing and executes
ldconfig so that the libraries in the lib directory are found
and their location cached. By doing so Asterisk starts up fine.

ASTERISK-26705

Change-Id: I6d30b6427e9d5e69470e11327c7ff203fa7da519
2017-02-16 14:21:14 -06:00