Commit Graph

29326 Commits

Author SHA1 Message Date
George Joseph 8df729517e Merge "res_pjsip_session.c: Restructure ast_sip_session_alloc()" 2017-04-25 15:37:15 -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
George Joseph cebfe85aff Merge "rtp_engine/res_rtp_asterisk: Fix RTP struct reentrancy crashes." 2017-04-21 15:46:21 -05:00
Richard Mudgett 835c209445 res_pjsip_session.c: Restructure ast_sip_session_alloc()
* Restructure ast_sip_session_alloc() to need less cleanup on off nominal
error paths.

* Made ast_sip_session_alloc() and ast_sip_session_create_outgoing() avoid
unnecessary ref manipulation to return a session.  This is faster than
calling a function.  That function may do logging of the ref changes with
REF_DEBUG enabled.

Change-Id: I2a0affc4be51013d3f0485782c96b8fee3ddb00a
2017-04-21 14:14:08 -05:00
George Joseph d373ebc428 Merge "build: Update config.guess and config.sub" 2017-04-20 13:34:45 -05:00
George Joseph dd239e9f91 Merge "res_stun_monitor: Don't fail to load if DNS resolution fails" 2017-04-20 07:19:46 -05:00
George Joseph b18bfb7672 Merge "make ari-stubs so doc periodic jobs can run" 2017-04-20 07:17:28 -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
Sean Bright b8b3380944 build: Update config.guess and config.sub
Change-Id: Id078a1df07a771808775e1053cdfe1d99c8fb172
2017-04-19 08:39:46 -05:00
Joshua Colp b84abac144 Merge "format_wav: Read 16khz wav samples properly" 2017-04-19 08:38:59 -05:00
Joshua Colp e756a9e063 Merge "format_ogg_vorbis: Clear ogg/vorbis data structures on close" 2017-04-19 08:38:16 -05:00
Joshua Colp b0c72da6fc Merge "Revert "bridging: Ensure successful T.38 negotation"" 2017-04-19 08:37:17 -05:00
Sean Bright 6c0ab9afa7 format_wav: Read 16khz wav samples properly
When opening a PCM wave file for reading, we aren't tracking the
frequency of the opened file, so we treat 16khz files as 8khz and do
half reads.

This patch also cleans up some of the data types and an unnecessarily
complex `if` expression.

ASTERISK-26613 #close
Reported by: Vitaly K

Change-Id: I05f8b263058dc573ea8ffe0c62e7964506e11815
2017-04-17 14:51:11 -05:00
George Joseph b55d21ad91 make ari-stubs so doc periodic jobs can run
The periodic doc job does a make ari-stubs and checks that
there are no changes before generating the docs.  Since I changed
the mustache template (and the generated code directly) recently
and forgot to regenerate the stubs, the doc job thinks they're out
of date.

Change-Id: I94b97035311eccf52b0101b8590223265a7881d4
2017-04-16 18:59:54 -06:00
Sean Bright 4fb9f5d60e format_ogg_vorbis: Clear ogg/vorbis data structures on close
On filestream close, we need to clear out the ogg & vorbis data
structures to prevent a memory leak.

ASTERISK-26169 #close
Reported by: Ivan Myalkin

Change-Id: Iee94c5a5d5bdafbf8b181c5c064d15d90ace8274
2017-04-15 12:15:57 -05:00
Richard Mudgett a3e623dd70 Revert "bridging: Ensure successful T.38 negotation"
This reverts commit 7819f95791.

Change-Id: Ib91a7e6c9856f5f41329e42f40ba2394fee861a4
2017-04-14 17:32:22 -05:00
Sean Bright f6600f2c2e res_stun_monitor: Don't fail to load if DNS resolution fails
res_stun_monitor will fail to load if DNS resolution of the STUN server
fails. Instead, we continue without the STUN server being resolved and
we will re-attempt the resolution on the STUN refresh interval.

ASTERISK-21856 #close
Reported by: Jeremy Kister

Change-Id: I6334c54a1cc798f8a836b4b47948e0bb4ef59254
2017-04-14 16:55:03 -05:00
Sean Bright be71be7ed2 format_pcm: Track actual header size of .au files
Sun's Au file format has a minimum data offset 24 bytes, but this
offset is encoded in each .au file. Instead of assuming the minimum,
read the actual value and store it for later use.

ASTERISK-20984 #close
Reported by: Roman S.
Patches:
	asterisk-1.8.20.0-au-clicks-2.diff (license #6474) patch
	uploaded by Roman S.

Change-Id: I524022fb19ff2fd5af2cc2d669d27a780ab2057c
2017-04-14 14:43:35 -05:00
George Joseph 2e6075c51f modules: change module LOAD_FAILUREs to LOAD_DECLINES (master)
Change-Id: Iac40ecb20e10513d67bf0eaf61807f306067b258
2017-04-13 07:46:02 -06:00
Joshua Colp 49535c17fc Merge "modules: change module LOAD_FAILUREs to LOAD_DECLINES (14)" 2017-04-13 07:06:51 -05:00
zuul e803eafb65 Merge "modules: change module LOAD_FAILUREs to LOAD_DECLINES" 2017-04-13 07:03:42 -05:00
Joshua Colp f4ed700ca2 Merge "strings.h: Avoid overflows in the string hash functions" 2017-04-12 19:46:06 -05:00
George Joseph 6db0939b96 modules: change module LOAD_FAILUREs to LOAD_DECLINES (14)
Change-Id: If99e3b4fc2d7e86fc3e61182aa6c835b407ed49e
2017-04-12 15:57:39 -06: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
zuul 60fd01f7f4 Merge "bridging: Ensure successful T.38 negotation" 2017-04-12 11:22:19 -05:00
zuul 1d15e95440 Merge "res_rtp_asterisk.c: Add stun_blacklist option" 2017-04-12 09:55:42 -05:00
Torrey Searle 7819f95791 bridging: Ensure successful T.38 negotation
When a T.38 happens immediatly after call establishment, the control
frame can be lost because the other leg is not yet in the bridge.

This patch detects this case an makes sure T.38 negotation happens
when the 2nd leg is being made compatible with the negotating
first leg

ASTERISK-26923 #close

Change-Id: If334125ee61ed63550d242fc9efe7987e37e1d94
2017-04-12 07:57:22 -05: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
zuul ecde4f1593 Merge "res_pjsip: Fix pointer use after unref." 2017-04-11 20:12:53 -05:00
zuul a0220877fa Merge "res_pjsip_sdp_rtp.c: Don't use deprecated transport struct member." 2017-04-11 20:12:50 -05:00
Torrey Searle 7901225261 strings.h: Avoid overflows in the string hash functions
On 2's compliment machines abs(INT_MIN) behavior is undefined and
results in a negative value still being returnd.  This results in
negative hash codes that can result in crashes.

ASTERISK-26528 #close

Change-Id: Idff550145ca2133792a61a2e212b4a3e82c6517b
2017-04-11 13:34:28 -05:00
Richard Mudgett 7312cbe803 res_rtp_asterisk.c: Add stun_blacklist option
Added the stun_blacklist option to rtp.conf.  Some multihomed servers have
IP interfaces that cannot reach the STUN server specified by stunaddr.
Blacklist those interface subnets from trying to send a STUN packet to
find the external IP address.  Attempting to send the STUN packet
needlessly delays processing incoming and outgoing SIP INVITEs because we
will wait for a response that can never come until we give up on the
response.  Multiple subnets may be listed.

ASTERISK-26890 #close

Change-Id: I3ff4f729e787f00c3e6e670fe6435acce38be342
2017-04-11 12:58:35 -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 5b4e2ec267 res_pjsip: Fix pointer use after unref.
Change-Id: I4b6e1b0070563eeaee223cb58326f1b962ed5bc1
2017-04-11 12:58:35 -05:00
Richard Mudgett 6f793ac149 res_pjsip_sdp_rtp.c: Don't use deprecated transport struct member.
* create_rtp(): Eliminate use of deprecated transport struct member.  That
member and several others in the transport structure were deprecated
because of an infinite loop created when using realtime configuration.
See 2451d4e455

ASTERISK-26851

Change-Id: I0533aa13c9ce3c6cc394e0fd2b5bf1cd1b2ef3bc
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
Walter Doekes 2b8dbc9e00 samples: Undo removal of include from canonicalize-app-names commit.
This include was accidentally removed in changeset
Ia79aea64de89531362e993e34230c2044a70aa93. My bad.

Change-Id: I1d716c7f9590b4e97909fb8bca1f2ed9bd0e4082
2017-04-08 03:16:26 -05:00
Joshua Colp 62386dd1df Merge "pjproject_bundled: Crash on pj_ssl_get_info() while ioqueue_on_read_complete()." 2017-04-07 17:33:12 -05:00
zuul 6ac1c686ca Merge "pjsip: Add Alembic for PUBLISH support." 2017-04-07 15:26:01 -05:00
Joshua Colp a1a2e16f67 Merge "samples: Canonicalize app names in extensions.conf.sample." 2017-04-07 14:49:12 -05:00
Joshua Colp 0e7d29501d Merge "core: Improve/simplify handling of required headers." 2017-04-07 14:48:36 -05:00
Joshua Colp 270b485f04 pjsip: Add Alembic for PUBLISH support.
This change adds database tables for the PUBLISH support so it
can be configured using realtime. A minor fix to the
res_pjsip_publish_asterisk module was done so that it read the
sorcery configuration from the correct section. Finally the
sample configuration files have been updated.

ASTERISK-26928

Change-Id: I81991ae5c75af98d247f7eacd1c0b0a763675952
2017-04-07 08:44:49 -05:00
Alexander Traud 7a46cd7433 pjproject_bundled: Crash on pj_ssl_get_info() while ioqueue_on_read_complete().
When the Asterisk channel driver res_pjsip offers SIP-over-TLS, sometimes, not
reproducible, Asterisk crashed in pj_ssl_sock_get_info() because a NULL pointer
was read. This change avoids this crash.

ASTERISK-26927 #close

Change-Id: I24a6011b44d1426d159742ff4421cf806a52938b
2017-04-07 15:06:11 +02:00
Walter Doekes e6ae3651b8 samples: Canonicalize app names in extensions.conf.sample.
This takes care of warnings by ossobv/asterisklint.

Change-Id: Ia79aea64de89531362e993e34230c2044a70aa93
2017-04-06 15:57:17 -05:00
Joshua Colp 33f29240da Merge "pjproject_bundled: Add 3 upstream patches" 2017-04-06 12:23:47 -05:00
Joshua Colp b12eeddb35 Merge "chan_sip: Session Timers required but refused wrongly." 2017-04-06 11:39:41 -05:00