Commit Graph

28799 Commits

Author SHA1 Message Date
Sean Bright
1b50df78d0 cleanup: Fix fread() and fwrite() error handling
Cleaned up some of the incorrect uses of fread() and fwrite(), mostly in
the format modules. Neither of these functions will ever return a value
less than 0, which we were checking for in some cases.

I've introduced a fair amount of duplication in the format modules, but
I plan to change how format modules work internally in a subsequent
patch set, so this is simply a stop-gap.

Change-Id: I8ca1cd47c20b2c0b72088bd13b9046f6977aa872
2017-04-25 16:24:37 -05:00
George Joseph
f7ca69809a Merge "res_pjsip_session.c: Restructure ast_sip_session_alloc()" into 13 2017-04-25 15:38:25 -05:00
Sean Bright
cea3742c54 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 12:46:27 -04:00
George Joseph
dac4442cdd Merge "pbx: Use same thread if AST_OUTGOING_WAIT_COMPLETE specified" into 13 2017-04-21 15:48:15 -05:00
Richard Mudgett
80fd7fd908 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:06:45 -05:00
George Joseph
5860ad3ee8 Merge "rtp_engine/res_rtp_asterisk: Fix RTP struct reentrancy crashes." into 13 2017-04-21 13:11:07 -05:00
George Joseph
eb479ee6c7 Merge "build: Update config.guess and config.sub" into 13 2017-04-20 13:34:26 -05:00
George Joseph
98bb64f88a Merge "res_stun_monitor: Don't fail to load if DNS resolution fails" into 13 2017-04-20 07:19:19 -05:00
George Joseph
12affa7b6e Merge "make ari-stubs so doc periodic jobs can run" into 13 2017-04-20 07:18:26 -05:00
Sean Bright
98e38daf82 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 17:42:40 -04:00
Richard Mudgett
f856cfbb51 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 10:46:41 -05:00
Sean Bright
dafcd97a77 build: Update config.guess and config.sub
Change-Id: Id078a1df07a771808775e1053cdfe1d99c8fb172
2017-04-19 09:39:00 -04:00
Joshua Colp
f9de4b5de9 Merge "format_wav: Read 16khz wav samples properly" into 13 2017-04-19 08:38:41 -05:00
Joshua Colp
69bebd8f1a Merge "format_ogg_vorbis: Clear ogg/vorbis data structures on close" into 13 2017-04-19 08:37:56 -05:00
Joshua Colp
441a75daea Merge "Revert "bridging: Ensure successful T.38 negotation"" into 13 2017-04-19 08:37:04 -05:00
Sean Bright
9bbfa6fda1 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 15:50:43 -04:00
George Joseph
4ccaffe644 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: Ibd4bc649556615ff714d44534c45b6c2f6aa449d
2017-04-16 18:54:52 -06:00
Sean Bright
90c630aaa1 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:14:48 -05:00
Richard Mudgett
9084c85cb1 Revert "bridging: Ensure successful T.38 negotation"
This reverts commit 3e7c396a51.

Change-Id: I61d49d563babff788bb557345729b200d116bd88
2017-04-14 17:31:45 -05:00
Sean Bright
357d1fbdcc 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 17:50:56 -04:00
Sean Bright
ac15ebc379 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 15:43:12 -04:00
Joshua Colp
5e2a8ef94a Merge "modules: change module LOAD_FAILUREs to LOAD_DECLINES" into 13 2017-04-13 05:45:46 -05:00
zuul
a22de46a06 Merge "strings.h: Avoid overflows in the string hash functions" into 13 2017-04-12 18:10:01 -05:00
Joshua Colp
ec051345f2 Merge "bridging: Ensure successful T.38 negotation" into 13 2017-04-12 17:38:55 -05:00
George Joseph
f882ca2572 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 16:46:22 -05:00
zuul
2e9f186c17 Merge "res_rtp_asterisk.c: Add stun_blacklist option" into 13 2017-04-12 09:01:50 -05:00
Joshua Colp
fdc63152c3 Merge changes from topics 'ASTERISK-26890', 'ASTERISK-26851' into 13
* changes:
  stun.c: Fix ast_stun_request() erratic timeout.
  sorcery.c: Speed up ast_sorcery_retrieve_by_id()
  res_pjsip: Fix pointer use after unref.
  res_pjsip_sdp_rtp.c: Don't use deprecated transport struct member.
2017-04-12 04:55:12 -05:00
Richard Mudgett
cd80af508e 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 13:03:57 -05:00
Richard Mudgett
f8219a2e12 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 13:03:57 -05:00
Richard Mudgett
19b82a8644 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 13:03:57 -05:00
Richard Mudgett
aecf19e7d2 res_pjsip: Fix pointer use after unref.
Change-Id: I4b6e1b0070563eeaee223cb58326f1b962ed5bc1
2017-04-11 13:03:57 -05:00
Richard Mudgett
304f652cda 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 13:03:57 -05:00
Richard Mudgett
bb8cd2add7 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:53 -05:00
Torrey Searle
d8967ff2c0 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-10 15:01:06 -05:00
Walter Doekes
bbbd262ec0 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 10:05:03 +02:00
zuul
e8514129a6 Merge "pjproject_bundled: Crash on pj_ssl_get_info() while ioqueue_on_read_complete()." into 13 2017-04-07 15:55:40 -05:00
zuul
b82f58d2bf Merge "pjsip: Add Alembic for PUBLISH support." into 13 2017-04-07 14:50:03 -05:00
zuul
293f9d39b7 Merge "samples: Canonicalize app names in extensions.conf.sample." into 13 2017-04-07 08:50:06 -05:00
Joshua Colp
b3f4a6365e 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 13:38:14 +00:00
Alexander Traud
e0e5a337fd 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 08:09:11 -05:00
Joshua Colp
09ec2dbbf3 Merge "chan_sip: Session Timers required but refused wrongly." into 13 2017-04-06 11:01:16 -05:00
Joshua Colp
0b00df55fc Merge "pjproject_bundled: Add 3 upstream patches" into 13 2017-04-06 10:49:16 -05:00
Torrey Searle
3e7c396a51 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-06 16:23:51 +02:00
Joshua Colp
4b504544f6 Merge "sample_config: Add samples for pubsub to pjsip.conf.sample" into 13 2017-04-06 08:29:43 -05:00
Joshua Colp
1a35801994 Merge "Unused realtime MOH classes not purged on 'moh reload'" into 13 2017-04-06 04:31:33 -05:00
Joshua Colp
f80b7f7014 Merge "res_pjsip_session: Allow BYE to be sent on disconnected session." into 13 2017-04-05 17:50:28 -05:00
George Joseph
4e6e069491 pjproject_bundled: Add 3 upstream patches
0035-r5572-svn-backport-dialog-transaction-deadlock.patch
0036-r5573-svn-backport-ua-pjsua-transaction-deadlock.patch
0037-r5576-svn-backport-session-timer-crash.patch

Also removed the progress bar from wget download to stdout.

ASTERISK-26905 #close
Reported-by: Ross Beer

Change-Id: I268fb3cf71a3bb24283ff0d24bd8b03239d81256
2017-04-05 16:16:42 -06:00
George Joseph
d2a33cdedc sample_config: Add samples for pubsub to pjsip.conf.sample
Added:
 * outbound-publish
 * resource_list
 * inbound-publication
 * asterisk-publication

Change-Id: I65043a896c35483f30a92d30b5b118359af7ba5a
2017-04-05 13:50:40 -06:00
Walter Doekes
ab9d2fc86d samples: Canonicalize app names in extensions.conf.sample.
This takes care of warnings by ossobv/asterisklint.

Change-Id: Ia79aea64de89531362e993e34230c2044a70aa93
2017-04-05 16:10:42 +02:00
Richard Mudgett
6906765381 res_pjsip_sdp_rtp.c: Don't alter global addr variable.
* create_rtp(): Fix unexpected alteration of global address_rtp if a
transport is bound to an address.

* create_rtp(): Fix use of uninitialized memory if the endpoint RTP media
address is invalid or the transport has an invalid address.

ASTERISK-26851

Change-Id: Icde42e65164a88913cb5c2601b285eebcff397b7
2017-04-04 10:26:11 -05:00