Commit Graph

26915 Commits

Author SHA1 Message Date
Mark Michelson 58edd2dddc Merge "chan_dahdi.c: Lock private struct for ast_write()." 2015-08-12 13:37:33 -05:00
Mark Michelson 318b97fd1e Merge "chan_dahdi.c: Flush the DAHDI write buffer after starting DTMF." 2015-08-12 13:37:14 -05:00
Joshua Colp 1aa722b3ce Merge "chan_sip: Fix negotiation of iLBC 30." 2015-08-12 13:36:08 -05:00
Mark Michelson cf45868984 Merge "res_pjsip.c: Fix crash from corrupt saved SUBSCRIBE message." 2015-08-12 13:08:02 -05:00
Matt Jordan a87e2dd254 res/res_format_attr_silk: Expose format attributes to other modules
This patch adds the .get callback to the format attribute module, such
that the Asterisk core or other third party modules can query for the
negotiated format attributes.

Change-Id: Ia24f55cf9b661d651ce89b4f4b023d921380f19c
2015-08-11 18:24:29 -05:00
Richard Mudgett 87c92d2aee chan_dahdi.c: Flush the DAHDI write buffer after starting DTMF.
Pressing DTMF digits on a phone to go out on a DAHDI channel can result in
the digit not being recognized or even heard by the peer.

Phone -> Asterisk -> DAHDI/channel

Turns out the DAHDI behavior with DTMF generation (and any other generated
tones) is exposed by the "buffers=" setting in chan_dahdi.conf.  When
Asterisk requests to start sending DTMF then DAHDI waits until its write
buffer is empty before generating any samples for the DTMF tones.  When
Asterisk subsequently requests DAHDI to stop sending DTMF then DAHDI
immediately stops generating the DTMF samples.  As a result, the more
samples there are in the DAHDI write buffer the shorter the time DTMF
actually gets sent on the wire.  If there are more samples in the write
buffer than the time DTMF is supposed to be sent then no DTMF gets sent on
the wire.  With the "buffers=12,half" setting and each buffer representing
20 ms of samples then the DAHDI write buffer is going to contain around
120 ms of samples.  For DTMF to be recognized by the peer the actual sent
DTMF duration needs to be a minimum of 40 ms.  Therefore, the intended
duration needs to be a minimum of 160 ms for the peer to receive the
minimum DTMF digit duration to recognize it.

A simple and effective solution to work around the DAHDI behavior is for
Asterisk to flush the DAHDI write buffer when sending DTMF so the full
duration of DTMF is actually sent on the wire.  When someone is going to
send DTMF they are not likely to be talking before sending the tones so
the flushed write samples are expected to just contain silence.

* Made dahdi_digit_begin() flush the DAHDI write buffer after requesting
to send a DTMF digit.

ASTERISK-25315 #close
Reported by John Hardin

Change-Id: Ib56262c708cb7858082156bfc70ebd0a220efa6a
2015-08-11 16:58:32 -05:00
Richard Mudgett b9b957d4e9 chan_dahdi.c: Lock private struct for ast_write().
There is a window of opportunity for DTMF to not go out if an audio frame
is in the process of being written to DAHDI while another thread starts
sending DTMF.  The thread sending the audio frame could be past the
currently dialing check before being preempted by another thread starting
a DTMF generation request.  When the thread sending the audio frame
resumes it will then cause DAHDI to stop the DTMF tone generation.  The
result is no DTMF goes out.

* Made dahdi_write() lock the private struct before writing to the DAHDI
file descriptor.

ASTERISK-25315
Reported by John Hardin

Change-Id: Ib4e0264cf63305ed5da701188447668e72ec9abb
2015-08-11 16:58:11 -05:00
Richard Mudgett f3f5b45d57 res_pjsip.c: Fix crash from corrupt saved SUBSCRIBE message.
If the saved SUBSCRIBE message is not parseable for whatever reason then
Asterisk could crash when libpjsip tries to parse the message and adds an
error message to the parse error list.

* Made ast_sip_create_rdata() initialize the parse error rdata list.  The
list is checked after parsing to see that it remains empty for the
function to return successful.

ASTERISK-25306
Reported by Mark Michelson

Change-Id: Ie0677f69f707503b1a37df18723bd59418085256
2015-08-11 16:57:36 -05:00
Alexander Traud 991d4da1eb chan_sip: Fix negotiation of iLBC 30.
iLBC 20 was advertised in a SIP/SDP negotiation. However, only iLBC 30 is
supported. Removes "a=fmtp:x mode=y" from SDP. Because of RFC 3952 section 5,
only iLBC 30 is negotiated now.

ASTERISK-25309 #close

Change-Id: I92d724600a183eec3114da0ac607b994b1a793da
2015-08-11 14:49:01 +02:00
Matt Jordan e188192ad1 main/format: Add an API call for retrieving format attributes
Some codecs that may be a third party library to Asterisk need to have
knowledge of the format attributes that were negotiated. Unfortunately,
when the great format migration of Asterisk 13 occurred, that ability
was lost.

This patch adds an API call, ast_format_attribute_get, to the core
format API, along with updates to the unit test to check the new API
call. A new callback is also now available for format attribute modules,
such that they can provide the format attribute values they manage.

Note that the API returns a void *. This is done as the format attribute
modules themselves may store format attributes in any particular manner
they like. Care should be taken by consumers of the API to check the
return value before casting and dereferencing. Consumers will obviously
need to have a priori knowledge of the type of the format attribute as
well.

Change-Id: Ieec76883dfb46ecd7aff3dc81a52c81f4dc1b9e3
2015-08-10 12:47:56 -05:00
Joshua Colp feffafbd55 Merge "Replace htobe64 with htonll" 2015-08-10 11:39:11 -05:00
Joshua Colp ff36b5482b Merge "Replaces clock_gettime() with ast_tsnow()" 2015-08-10 11:27:12 -05:00
Matt Jordan 35fe8f74fe Merge "rtp_engine.c: Fix performance issue with several channel drivers that use RTP." 2015-08-08 08:07:13 -05:00
David M. Lee d5f0c27122 Replace htobe64 with htonll
We don't have a compatability function to fill in a missing htobe64; but
we already have one for the identical htonll.

Change-Id: Ic0a95db1c5b0041e14e6b127432fb533b97e4cac
2015-08-07 23:40:56 -05:00
David M. Lee 40caf0ad9b Replaces clock_gettime() with ast_tsnow()
clock_gettime() is, unfortunately, not portable. But I did like that
over our usual `ts.tv_nsec = tv.tv_usec * 1000` copy/paste code we
usually do when we want a timespec and all we have is ast_tvnow().

This patch adds ast_tsnow(), which mimics ast_tvnow(), but returns a
timespec. If clock_gettime() is available, it will use that. Otherwise
ast_tsnow() falls back to using ast_tvnow().

Change-Id: Ibb1ee67ccf4826b9b76d5a5eb62e90b29b6c456e
2015-08-07 19:35:13 -05:00
Scott Emidy 12e6f5ac01 ARI: Retrieve existing log channels
An http request can be sent to get the existing Asterisk logs.

The command "curl -v -u user:pass -X GET 'http://localhost:8088
/ari/asterisk/logging'" can be run in the terminal to access the
newly implemented functionality.

* Retrieve all existing log channels

ASTERISK-25252

Change-Id: I7bb08b93e3b938c991f3f56cc5d188654768a808
2015-08-07 14:57:45 -05:00
Scott Emidy b91ca7ba49 ARI: Creating log channels
An http request can be sent to create a log channel
in Asterisk.

The command "curl -v -u user:pass -X POST
'http://localhost:088/ari/asterisk/logging/mylog?
configuration=notice,warning'" can be run in the terminal
to access the newly implemented functionality for ARI.

* Ability to create log channels using ARI

ASTERISK-25252

Change-Id: I9a20e5c75716dfbb6b62fd3474faf55be20bd782
2015-08-07 11:18:13 -05:00
Joshua Colp ecd4cde521 Merge "ARI: Deleting log channels" 2015-08-07 10:41:12 -05:00
Joshua Colp 1b89cbb3b0 Merge "res_pjsip: Ensure sanitized XML is NULL terminated." 2015-08-07 10:23:49 -05:00
Joshua Colp 12d7c8a740 Merge "res_pjsip_pubsub: More accurately persist packet." 2015-08-07 05:17:13 -05:00
Joshua Colp 58effbc3f6 Merge "res_rtp_asterisk.c: Fix off-nominal crash potential." 2015-08-07 05:18:06 -05:00
Scott Emidy f19c4930c2 ARI: Deleting log channels
An http request can be sent to delete a log channel
in Asterisk.

The command "curl -v -u user:pass -X DELETE 'http://localhost:8088
/ari/asterisk/logging/mylog'" can be run in the terminal
to access the newly implemented functionally for ARI.

* Able to delete log channels using ARI

ASTERISK-25252

Change-Id: Id6eeb54ebcc511595f0418d586ff55914bc3aae6
2015-08-06 17:43:49 -05:00
Mark Michelson 382334cc06 res_pjsip_pubsub: More accurately persist packet.
The pjsip_rx_data structure has a pkt_info.packet field on it that is
the packet that was read from the transport. For datagram transports,
the packet read from the transport will correspond to the SIP message
that arrived. For streamed transports, however, it is possible to read
multiple SIP messages in one packet.

In a recent case, Asterisk crashed on a system where TCP was being used.
This is because at some point, a read from the TCP socket resulted in a
200 OK response as well as an incoming SUBSCRIBE request being stored in
rdata->pkt_info.packet. When the SUBSCRIBE was processed, the
combination 200 OK and SUBSCRIBE was saved in persistent storage. Later,
a restart of Asterisk resulted in the crash because the persistent
subscription recreation code ended up building the 200 OK response
instead of a SUBSCRIBE request, and we attempted to access
request-specific data.

The fix here is to use the pjsip_msg_print() function in order to
persist SUBSCRIBE requests. This way, rather than using the raw socket
data, we use the parsed SIP message that PJSIP has given us. If we
receive multiple SIP messages from a single read, we will be sure only
to save off the relevant SIP message. There also is a safeguard put in
place to make sure that if we do end up reconstructing a SIP response,
it will not cause a crash.

ASTERISK-25306 #close
Reported by Mark Michelson

Change-Id: I4bf16f7b76a2541d10b55de82bcd14c6e542afb2
2015-08-06 13:15:59 -05:00
Joshua Colp ca84a4b235 Merge "rtp_engine.c: Must protect mime_types_len with mime_types_lock." 2015-08-06 12:25:08 -05:00
Joshua Colp 7ebca6795b Merge "res_pjsip_sdp_rtp.c: Fixup some whitespace." 2015-08-06 11:53:20 -05:00
Joshua Colp 4b6c657a82 res_pjsip: Ensure sanitized XML is NULL terminated.
The ast_sip_sanitize_xml function is used to sanitize
a string for placement into XML. This is done by examining
an input string and then appending values to an output
buffer. The function used by its implementation, strncat,
has specific behavior that was not taken into account.
If the size of the input string exceeded the available
output buffer size it was possible for the sanitization
function to write past the output buffer itself causing
a crash. The crash would either occur because it was
writing into memory it shouldn't be or because the resulting
string was not NULL terminated.

This change keeps count of how much remaining space is
available in the output buffer for text and only allows
strncat to use that amount.

Since this was exposed by the res_pjsip_pidf_digium_body_supplement
module attempting to send a large message the maximum allowed
message size has also been increased in it.

A unit test has also been added which confirms that the
ast_sip_sanitize_xml function is providing NULL terminated
output even when the input length exceeds the output
buffer size.

ASTERISK-25304 #close

Change-Id: I743dd9809d3e13d722df1b0509dfe34621398302
2015-08-06 05:20:47 -05:00
Joshua Colp 3d4db97253 Merge "res_pjsip_sdp_rtp.c: Fix processing wrong SDP media list." 2015-08-06 04:52:49 -05:00
Joshua Colp 8a48c9e6cb Merge "res_http_websocket: Debug write lengths." 2015-08-06 04:52:10 -05:00
Joshua Colp 7351d33a1f res_rtp_asterisk: Don't leak temporary key when enabling PFS.
A change recently went in which enabled perfect forward secrecy for
DTLS in res_rtp_asterisk. This was accomplished two different ways
depending on the availability of a feature in OpenSSL. The fallback
method created a temporary instance of a key but did not free it.
This change fixes that.

ASTERISK-25265

Change-Id: Iadc031b67a91410bbefb17ffb4218d615d051396
2015-08-05 10:25:53 -05:00
Mark Michelson c63316eec1 res_http_websocket: Debug write lengths.
Commit 39cc28f6ea attempted to fix a
test failure observed on 32 bit test agents by ensuring that a cast from
a 32 bit unsigned integer to a 64 bit unsigned integer was happening in
a predictable place. As it turns out, this did not cause test runs to
succeed.

This commit adds several redundant debug messages that print the payload
lengths of websocket frames. The idea here is that this commit will not
cause tests to succeed for the faulty test agent, but we might deduce
where the fault lies more easily this way by observing at what point the
expected value (537) changes to some ungangly huge number.

If you are wondering why something like this is being committed to the
branch, keep in mind that in commit
39cc28f6ea I noted that the observed test
failures only happen when automated tests are run. Attempts to run the
tests by hand manually on the test agent result in the tests passing.

Change-Id: I14a65c19d8af40dadcdbd52348de3b0016e1ae8d
2015-08-04 10:19:36 -05:00
Matt Jordan 3ba6099a9e Merge "res_http_websocket: Avoid passing strlen() to ast_websocket_write()." 2015-08-03 11:52:01 -05:00
Matt Jordan 8672f0bbbd Merge "res/res_rtp_asterisk: Add ECDH support" 2015-08-03 11:49:43 -05:00
Mark Michelson 35a98161df res_http_websocket: Avoid passing strlen() to ast_websocket_write().
We have seen a rash of test failures on a 32-bit build agent. Commit
48698a5e21 solved an obvious problem where
we were not encoding a 64-bit value correctly over the wire. This
commit, however, did not solve the test failures.

In the failing tests, ARI is attempting to send a 537 byte text frame
over a websocket. When sending a frame this small, 16 bits are all that
is required in order to encode the payload length on the websocket
frame. However, ast_websocket_write() thinks that the payload length is
greater than 65535 and therefore writes out a 64 bit payload length.
Inspecting this payload length, the lower 32 bits are exactly what we
would expect it to be, 537 in hex. The upper 32 bits, are junk values
that are not expected to be there.

In the failure, we are passing the result of strlen() to a function that
expects a uint64_t parameter to be passed in. strlen() returns a size_t,
which on this 32-bit machine is 32 bits wide. Normally, passing a 32-bit
unsigned value to somewhere where a 64-bit unsigned value is expected
would cause no problems. In fact, in manual runs of failing tests, this
works just fine. However, ast_websocket_write() uses the Asterisk
optional API, which means that rather than a simple function call, there
are a series of macros that are used for its declaration and
implementation. These macros may be causing some sort of error to occur
when converting from a 32 bit quantity to a 64 bit quantity.

This commit changes the logic by making existing ast_websocket_write()
calls use ast_websocket_write_string() instead. Within
ast_websocket_write_string(), the 64-bit converted strlen is saved in a
local variable, and that variable is passed to ast_websocket_write()
instead.

Note that this commit message is full of speculation rather than
certainty. This is because the observed test failures, while always
present in automated test runs, never occur when tests are manually
attempted on the same test agent. The idea behind this commit is to fix
a theoretical issue by performing changes that should, at the least,
cause no harm. If it turns out that this change does not fix the failing
tests, then this commit should be reverted.

Change-Id: I4458dd87d785ca322b89c152b223a540a3d23e67
2015-08-03 11:23:29 -05:00
Joshua Colp 8eef7392c4 Merge topic 'misc_rtp_tweaks'
* changes:
  rtp_engine.h: No sense allowing payload types larger than RFC allows.
  rtp_engine.c: Minor tweaks.
  rtp_engine.h: Misc comment fixes.
2015-08-03 08:46:21 -05:00
Joshua Colp 4cf21fed27 Merge "chan_sip.c: Tweak glue->update_peer() parameter nil value." 2015-08-03 08:43:21 -05:00
Mark Michelson b002e09214 Merge "ARI: Channels added to Stasis application during WebSocket creation ..." 2015-07-31 11:58:30 -05:00
Mark Michelson 92ddda68aa Merge "ARI: Rotate log channels." 2015-07-31 11:58:12 -05:00
Joshua Colp 94f7427b17 Merge "res_pjsip_session.c: Fix crashes seen when call cancelled." 2015-07-31 11:54:42 -05:00
Benjamin Ford 1f02d20da4 ARI: Rotate log channels.
An http request can be sent to rotate a specified log channel.
If the channel does not exist, an error response will be
returned.

The command "curl -v -u user:pass -X PUT 'http://localhost:8088
/ari/asterisk/logging/logChannelName/rotate'" can be run in the
terminal to access this new functionality.

* Added the ability to rotate log files through ARI

ASTERISK-25252

Change-Id: Iaefa21cbbc1b29effb33004ee3d89c977e76ab01
2015-07-31 11:46:08 -05:00
Joshua Colp d61ea4bcc2 Merge "dns_core: Allow zero-length DNS responses." 2015-07-31 11:42:42 -05:00
Ashley Sanders fe804b09b3 ARI: Channels added to Stasis application during WebSocket creation ...
Prior to ASTERISK-24988, the WebSocket handshake was resolved before Stasis
applications were registered. This was done such that the WebSocket would be
ready when an application is registered. However, by creating the WebSocket
first, the client had the ability to make requests for the Stasis application
it thought had been created with the initial handshake request. The inevitable
conclusion of this scenario was the cart being put before the horse.

ASTERISK-24988 resolved half of the problem by ensuring that the applications
were created and registered with Stasis prior to completing the handshake
with the client. While this meant that Stasis was ready when the client
received the green-light from Asterisk, it also meant that the WebSocket was
not yet ready for Stasis to dispatch messages.

This patch introduces a message queuing mechanism for delaying messages from
Stasis applications while the WebSocket is being constructed. When the ARI
event processor receives the message from the WebSocket that it is being
created, the event processor instantiates an event session which contains a
message queue. It then tries to create and register the requested applications
with Stasis. Messages that are dispatched from Stasis between this point and
the point at which the event processor is notified the WebSocket is ready, are
stashed in the queue. Once the WebSocket has been built, the queue's messages
are dispatched in the order in which they were originally received and the
queue is concurrently cleared.

ASTERISK-25181 #close
Reported By: Matt Jordan

Change-Id: Iafef7b85a2e0bf78c114db4c87ffc3d16d671a17
2015-07-31 11:28:10 -05:00
Mark Michelson 86034227ca dns_core: Allow zero-length DNS responses.
A testsuite test recently failed due to a crash that occurred in the DNS
core. The problem was that the test could not resolve an address, did
not set a result on the DNS query, and then indicated the query was
completed. The DNS core does not handle the case of a query with no
result gracefully, and so there is a crash.

This changeset makes the DNS system resolver set a result with a
zero-length answer in the case that a DNS resolution failure occurs
early. The DNS core now also will accept such a response without
treating it as invalid input. A unit test was updated to no longer treat
setting a zero-length response as off-nominal.

Change-Id: Ie56641e22debdaa61459e1c9a042e23b78affbf6
2015-07-31 09:44:20 -05:00
Richard Mudgett f49bef08a2 rtp_engine.c: Fix performance issue with several channel drivers that use RTP.
ast_rtp_codecs_get_payload() gets called once or twice for every received
RTP frame so it would be nice to not allocate an ao2 object to then have
it destroyed shortly thereafter.  The ao2 object gets allocated only if
the payload type is not set by the channel driver as a negotiated value.
The issue affects chan_skinny, chan_unistim, chan_rtp, and chan_ooh323.

* Made static_RTP_PT[] an array of ao2 objects that
ast_rtp_codecs_get_payload() can return instead of an array of structs
that must be copied into a created ao2 object.

ASTERISK-25296 #close
Reported by: Richard Mudgett

Change-Id: Icb6de5cd90bfae07d44403a1352963db9109dac0
2015-07-30 17:11:58 -05:00
Richard Mudgett 33a465249b res_rtp_asterisk.c: Fix off-nominal crash potential.
ASTERISK-25296
Reported by: Richard Mudgett

Change-Id: I08549fb7c3ab40a559f41a3940f3732a4059b55b
2015-07-30 17:11:58 -05:00
Richard Mudgett 5f925d48b7 rtp_engine.c: Must protect mime_types_len with mime_types_lock.
Change-Id: I44220dd369cc151ebf5281d5119d84bb9e54d54e
2015-07-30 17:11:58 -05:00
Richard Mudgett ba7dd38470 res_pjsip_sdp_rtp.c: Fixup some whitespace.
Change-Id: Ib4eb7ef7dcaf93ddc26538f0a498aaf110d7a973
2015-07-30 17:11:58 -05:00
Richard Mudgett 3751bf0971 res_pjsip_sdp_rtp.c: Fix processing wrong SDP media list.
Change-Id: I7c076826c2d3c6ae8c923ca73b7a71980cca11f2
2015-07-30 17:11:58 -05:00
Richard Mudgett e2d5d4db35 rtp_engine.h: No sense allowing payload types larger than RFC allows.
* Tweaked add_static_payload() to not use magic numbers.

Change-Id: I1719ff0f6d3ce537a91572501eae5bcd912a420b
2015-07-30 17:11:58 -05:00
Richard Mudgett bc1eae55cb rtp_engine.c: Minor tweaks.
* Fix off nominial ref leak of new_type in
ast_rtp_codecs_payloads_set_m_type().

* No need to lock static_RTP_PT_lock in
ast_rtp_codecs_payloads_set_m_type() and
ast_rtp_codecs_payloads_set_rtpmap_type_rate() before the payload type
parameter sanity check.

* No need to create ast_rtp_payload_type ao2 objects with a lock since the
lock is not used.

Change-Id: I64dd1bb4dfabdc7e981e3f61448beac9bb7504d4
2015-07-30 17:11:58 -05:00
Richard Mudgett d122c1e50b chan_sip.c: Tweak glue->update_peer() parameter nil value.
Change glue->update_peer() parameter from 0 to NULL to better indicate it
is a pointer.

Change-Id: I8ff2e5087f0e19f6998e3488a712a2470cc823bd
2015-07-30 17:11:57 -05:00