Commit Graph

4566 Commits

Author SHA1 Message Date
Corey Farrell 449ee66a11 res_pjsip_refer: Prevent unload except during shutdown.
Prevent unload of the module as certain pjsip initialization functions
cannot be reversed.

ASTERISK-24483

Change-Id: I94597ec8b8491f5af9c57bf66dbc3b078fe2d49d
2017-10-18 14:37:57 -04:00
Alexander Traud 95b45d1c46 res_srtp: Add support for libsrtp2 with AES-GCM.
Beside allowing AES-GCM again, this adds AES-192 again.

ASTERISK-27356

Change-Id: Ia97a435faf26300335d9552fa676b5d17e5f7233
2017-10-18 03:34:56 -05:00
Jenkins2 c5d9cce6f6 Merge "res_pjsip_session: Rewrite o= with external_media_address." 2017-10-17 06:34:42 -05:00
Jenkins2 3a2b132411 Merge "declare optional openssl dependencies in moduleinfo" 2017-10-16 09:19:56 -05:00
Alexander Traud 8f65d91dfd res_pjsip_session: Rewrite o= with external_media_address.
PJSIP allows a domain name as external_media_address. This allows chan_pjsip to
be used behind a NAT with changing IP addresses. The IP address of that domain
is resolved to the c= line already. This change sets also the o= line to that
domain.

ASTERISK-27341 #close

Change-Id: I690163b6e762042ec38b3995aa5c9bea909d8ec4
2017-10-14 12:57:03 +02:00
Daniel Tryba 6576e4320a res_pjsip_session: Prevent user=phone being added to anonimized URIs.
Move ast_sip_add_usereqphone to be called after anonymization of URIs,
to prevent the user_eq_phone adding "user=phone" to URIs containing a
username that is not a phonenumber (RFC3261 19.1.1). An extra call to
ast_sip_add_usereqphone on the saved version before anonymization is
added to add user=phone" to the PAI.

ASTERISK-27047 #close

Change-Id: Ie5644bc66341b86dc08b1f7442210de2e6acdec6
2017-10-12 11:06:09 -05:00
Daniel Tryba a56316423f res_pjsip: Prevent "user=phone" being added multiple times to header
ast_sip_add_usereqphone adds "user=phone" to the header every time is is
called without checking whether the param already exists. Preventing
this by searching to string representation of header for "user=phone".

ASTERISK-26988 #close

Change-Id: Ib84383b07254de357dc6a98d91fc1d2c2c3719e6
2017-10-11 15:36:28 -05:00
Seán C McCord e8bde6916a ari/bridge: Add mute, dtmf suppression controls
Add bridge_features structure to bridge creation.  Specifically, this
implements mute and DTMF suppression, but others should be able to be
easily added to the same structure.

ASTERISK-27322 #close
Reported by: Darren Sessions
Sponsored by: AVOXI

Change-Id: Id4002adfb65c9a8027ee9e1a5f477e0f01cf9d61
2017-10-11 08:23:05 -04:00
Jenkins2 1505c1bb09 Merge "res_pjsip_registrar.c: Update remove_existing AOR contact handling." 2017-10-11 06:49:54 -05:00
Jenkins2 6fc222a1d2 Merge "res_pjsip: Add REF_DEBUG info to module references." 2017-10-10 12:28:13 -05:00
Tzafrir Cohen b228f5c5e6 declare optional openssl dependencies in moduleinfo
Declare optional openssl dependencies in:
* res_rtp_asterisk.c
* tcptls.c

ASTERISK-27328 #close

Change-Id: I2636f1c05b8104b4fe6f36cce0ebd9a98b9c78ab
2017-10-10 15:42:46 +03:00
Corey Farrell fae09c6676 res_pjproject: Fix cleanup of buildopts vector.
ASTERISK-27306

Change-Id: I3bed0edf3f55b1d4adcbabb25ec14f11dc766c72
2017-10-09 23:51:03 -04:00
Jenkins2 89859f33b2 Merge "res_pjsip: Fix issues that prevented shutdown of modules." 2017-10-09 17:29:26 -05:00
Jenkins2 b877181cd9 Merge "res_pjsip_session: Fix format_cap leak." 2017-10-09 16:23:01 -05:00
Jenkins2 4914311150 Merge "res_pjsip: Fix leak of persistent endpoint references." 2017-10-09 15:24:49 -05:00
Richard Mudgett fb19799b62 res_pjsip_registrar.c: Update remove_existing AOR contact handling.
When "rewrite_contact" is enabled, the "max_contacts" count option can
block re-registrations because the source port from the endpoint can be
random.  When the re-registration is blocked, the endpoint may give up
re-registering and require manual intervention.

* The "remove_existing" option now allows a registration to succeed by
displacing any existing contacts that now exceed the "max_contacts" count.
Any removed contacts are the next to expire.  The behaviour change is
beneficial when "rewrite_contact" is enabled and "max_contacts" is greater
than one.  The removed contact is likely the old contact created by
"rewrite_contact" that the device is refreshing.

ASTERISK-27192

Change-Id: I64c107a10b70db1697d17136051ae6bf22b5314b
2017-10-09 12:52:30 -05:00
Jenkins2 13c1c72401 Merge "res_sdp_translator_pjmedia: Fix test unregistration." 2017-10-09 12:10:34 -05:00
hajekd a0a1f95abf res/res_ari.c Fix: Memory leaks in ARI when using Content-Type: application/json
ASTERISK-27305
Reported by: David Hajek
Tested by: David Hajek

Change-Id: Ife3e289062e6cf7d0e7d342dbf79ed96feff441e
2017-10-09 08:05:31 -05:00
Corey Farrell eb224fea5e res_pjsip_session: Fix format_cap leak.
ASTERISK-27306

Change-Id: I2c8d3fc148f9f53715c958314e1146f9611741f3
2017-10-07 17:29:30 -04:00
Corey Farrell a68a91f722 res_pjsip: Fix leak of persistent endpoint references.
Do not manually call sip_endpoint_apply_handler from load_all_endpoints.
This is not necessary and causes memory leaks.

Additionally reinitialize persistent->aors when we reuse a persistent
object with a new endpoint.

ASTERISK-27306

Change-Id: I59bbfc8da8a14d5f4af8c5bb1e71f8592ae823eb
2017-10-06 16:43:31 -04:00
Jenkins2 d4be387d41 Merge "res_pjsip: Fix leak of fake_auth references." 2017-10-06 14:16:56 -05:00
Corey Farrell b35ac9e566 res_pjsip: Fix leak of fake_auth references.
pjsip_distributor leaks references to fake_auth when the default realm
has not changed.

ASTERISK-27306

Change-Id: I3fcf103b3680ad2d1d4610dcd6738eeaebf4d202
2017-10-06 10:23:38 -04:00
Corey Farrell 0b6be1b2d4 res_sdp_translator_pjmedia: Fix test unregistration.
ASTERISK-27306

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

ASTERISK-27284 #close

Change-Id: If438a21f31a962da32d7a33ff33bdeb1e776fe56
2017-10-05 07:53:03 -05:00
Corey Farrell 65399a5eda res_pjsip: Add REF_DEBUG info to module references.
This provides better information to REF_DEBUG log for troubleshooting
when the system is unable to unload res_pjsip.so during shutdown due to
module references.

ASTERISK-27306

Change-Id: I63197ad33d1aebe60d12e0a6561718bdc54e4612
2017-10-04 12:00:47 -04:00
Corey Farrell 7d04544986 res_pjsip: Fix issues that prevented shutdown of modules.
res_pjsip and res_pjsip_session had circular references, preventing both
modules from shutting down.
* Move session supplement registration to res_pjsip.
* Use create internal functions for use by pjsip_message_filter.c.

ASTERISK-27306

Change-Id: Ifbd5c19ec848010111afeab2436f9699da06ba6b
2017-10-04 12:00:31 -04:00
krells 2301447a20 res_calendar_icalendar: Filter out occurrences superceded by another VEVENT
When we are loading the calendars, we call libical's
icalcomponent_foreach_recurrence method for each VEVENT component that
we have in our calendar.

That method has no knowledge concerning the existence of the other
VEVENT components and will feed our callback with all ocurrences
matching the requested time span.

The occurrences generated by icalcomponent_foreach_recurrence while
expanding a recurring VEVENT's RRULE and RDATE properties can be
superceded by an other VEVENT sharing the same UID.

I use an external iterator (in libical terminology) to avoid messing
with the internal ones from the calling function, and search for
VEVENTS which could supersede the current occurrence.

The event which can invalidate this occurence needs to have:

- the same UID as our recurrent component (comp)
- a RECURRENCE-ID property, which represents the start time of this
  occurrence

If one component is found, just clean and return.

ASTERISK-27296 #close
Reported by: Benoît Dereck-Tricot

Change-Id: I8587ae3eaa765af7cb21eda3b6bf84e8a1c87af8
2017-10-04 10:02:53 -05:00
Jenkins2 5307659e96 Merge "pjsip_message_filter: Fix regression causing bad contact address" 2017-09-28 13:36:29 -05:00
Joshua Colp 47d68401d7 Merge "res_stasis: Add 'video_sfu' as a requested bridge type." 2017-09-28 13:13:31 -05:00
Joshua Colp dd4c573e6d Merge "res_pjsip_session: outgoing call did not offer all configured codecs" 2017-09-28 12:24:11 -05:00
Joshua Colp a78ffe96a8 Merge "res_rtp_asterisk.c: Fix bridge_p2p_rtp_write() reentrancy potential." 2017-09-28 07:08:33 -05:00
Joshua Colp 4ea4364eef Merge "res_rtp_asterisk: Trim trailing byte off of SDES packet" 2017-09-28 06:45:28 -05:00
Joshua Colp f21408c866 res_stasis: Add 'video_sfu' as a requested bridge type.
This change adds 'video_sfu' as a requested bridge type when
creating a bridge. By specifying this a mixing type bridge is
created that exchanges video in an SFU fashion.

Change-Id: I2ada47cf5f3fc176518b647c0b4aa39d55339606
2017-09-28 05:34:15 -05:00
Richard Mudgett a6dc0527a2 res_pjsip_outbound_publish.c: Fix misplaced parenthesis.
The pjsip_publishc_init() call was referenced with a misplaced
parentheses.  As a result, outbound publication messages went out with an
expiration of 1 second.

ASTERISK-27298

Change-Id: I93622eabc8ee83e7a22e98c107f921284c605a08
2017-09-27 11:25:46 -05:00
George Joseph 61ea872233 pjsip_message_filter: Fix regression causing bad contact address
The "res_pjsip:  Filter out non SIP(S) requests" commit moved the
filtering of messages to pjproject's PJSIP_MOD_PRIORITY_TRANSPORT_LAYER
in order to filter out incoming bad uri schemes as early as possible.
Since the change affected outgoing messages as well and the TRANSPORT
layer is the last to be run on outgoing messages, we were overwriting
the setting of external_signaling_address (which is set earlier by
res_pjsip_nat) with an internal address.

* pjsip_message_filter now registers itself as a pjproject module
twice.  Once in the TSX layer for the outgoing messages (as it was
originally), then a second time in the TRANSPORT layer for the
incoming messages to catch the invalid uri schemes.

ASTERISK-27295
Reported by: Sean Bright

Change-Id: I2c90190c43370f8a9d1c4693a19fd65840689c8c
2017-09-26 11:47:02 -05:00
Richard Mudgett 9d65057cdf res_rtp_asterisk.c: Fix bridge_p2p_rtp_write() reentrancy potential.
The bridge_p2p_rtp_write() has potential reentrancy problems.

* Accessing the bridged RTP members must be done with the instance1 lock
held.  The DTMF and asymmetric codec checks must be split to be done with
the correct RTP instance struct locked.  i.e., They must be done when
working on the appropriate side of the point to point bridge.

* Forcing the RTP mark bit was referencing the wrong side of the point to
point bridge.  The set mark bit is used everywhere else to set the mark
bit when sending not receiving.

The patches for ASTERISK_26745 and ASTERISK_27158 did not take into
account that not everything carried by RTP uses a codec.  The telephony
DTMF events are not exchanged with a codec.  As a result when
RFC2833/RFC4733 sent digits you would crash if "core set debug 1" is
enabled, the DTMF digits would always get passed to the core even though
the local native RTP bridge is active, and the DTMF digits would go out
using the wrong SSRC id.

* Add protection for non-format payload types like DTMF when updating the
lastrxformat and lasttxformat.  Also protect against non-format payload
types when checking for asymmetric codecs.

ASTERISK-27292

Change-Id: I6344ab7de21e26f84503c4d1fca1a41579364186
2017-09-26 11:19:17 -05:00
Sean Bright c9e972a26a res_rtp_asterisk: Trim trailing byte off of SDES packet
This could have been fixed by subtracting 1 from the final value of
'len' but the way the packet was being constructed was confusing so I
took the opportunity to (I think) make it more clear.

We were sending 1 extra byte at the end of the SDES RTCP packet which
caused Chrome to complain (in its debug log):

    Too little data (1 byte) remaining in buffer to parse
    RTCP header (4 bytes).

We now send the correct number of bytes.

Change-Id: I9dcf087cdaf97da0374ae0acb7d379746a71e81b
2017-09-26 11:14:07 -05:00
Joshua Colp c8a8933558 Merge "webrtc: Allow 'webrtc' to be set on endpoints without dtls_ca_file" 2017-09-26 07:37:22 -05:00
Joshua Colp 87c4a72f16 Merge "res_pjsip_session: Reduce (and improve) SDP renegotiation." 2017-09-25 15:35:11 -05:00
Sean Bright 721947ebae webrtc: Allow 'webrtc' to be set on endpoints without dtls_ca_file
If using a legitimate certificate from a trusted certificate authority,
you don't need to provide CA file.

Change-Id: I8623973b4209b44889243716d7880274caed8a6d
2017-09-25 13:11:47 -05:00
Kevin Harwell b74cbadd05 res_pjsip_session: outgoing call did not offer all configured codecs
For some scenarios when an outgoing call was made only a subset of the
configured codecs were offered. If the codecs being offered happened to
not have a codec supported by the phone then the call would fail.

For instance Alice and Bob both are configured in Asterisk for g722 and ulaw(
allow=!all,g722,ulaw). Alice's endpoint however only supports g722 while Bob's
only supports ulaw. When Alice calls Bob, Alice negotiates g722 fine with
Asterisk. But when Asterisk sends the outgoing offer to Bob it only contains
g722 and not both g722 and ulaw, so the call ends.

This patch makes it so all the audio codecs configured on the endpoint always
get sent, and not just a subset. However priority is given to those codecs that
are compatible with the "other side".

ASTERISK-27259 #close

Change-Id: Iffabc373bd94cd1dc700925dcfe406e12918c696
2017-09-25 12:34:55 -05:00
Joshua Colp 360bd11c30 Merge "res_pjsip_session: Don't end session when receiving a 500 on a reinvite" 2017-09-25 12:23:53 -05:00
Joshua Colp 1b468b543d Merge "res_pjsip: Use ast_sip_is_content_type() where appropriate" 2017-09-25 07:28:41 -05:00
Joshua Colp 601e0c563f res_pjsip_session: Reduce (and improve) SDP renegotiation.
When pruning a request to change the topology of a channel be
more intelligent about the resulting topology that is actually
used for SDP renegotiation.

In a case where a stream has not already been negotiated we
don't need to renegotiate and offer a declined stream. This can
occur if something in Asterisk (such as ConfBridge) requests
to add video to a PJSIP channel that has no video codecs configured.
In this case since the stream did not already exist we can safely
remove the stream from the requested topology, resulting in no
renegotiation occurring.

In a case where a renegotiation is requested with a codec that is
not supported we can reuse the formats of the existing stream if
it exists to ensure that the stream continues to flow, instead of
removing it.

Change-Id: I636540798d55922377318fe619c510fb6ed125fb
2017-09-22 17:54:53 -05:00
Kevin Harwell 36690c26f8 res_pjsip_session: Don't end session when receiving a 500 on a reinvite
During a reinvite, if a remote endpoint error occurs and it returns a 500 the
session would end. This patch makes it so the session is not terminated, but
continues as it was.

The reason for this is because some endpoints may send non session terminating
"server errors" like a failed codec negotiation. So in this case instead of
ending the call it can hopefully continue. In the case of a real server error
the session is already "doomed", will be known soon enough and appropriately
ended by Asterisk later.

Change-Id: Ifeedae86b8cb44b92d52c79046522ec5f0aff1d5
2017-09-22 16:36:09 -05:00
Joshua Colp f91a905003 Merge "res_pjsip_session/BUNDLE: Handle no audio codecs on endpoint" 2017-09-22 15:35:29 -05:00
Joshua Colp feadd654af Merge "res_pjsip_session: Change some asserts to warning/debug messages" 2017-09-22 11:10:11 -05:00
Sean Bright ebd0a4bebf res_pjsip: Use ast_sip_is_content_type() where appropriate
Change-Id: If3ab0d73d79ac4623308bd48508af2bfd554937d
2017-09-22 10:05:23 -05:00
George Joseph 6c0e13da22 res_pjsip_session/BUNDLE: Handle no audio codecs on endpoint
When an INVITE came in with both audio and video streams but there
were no audio codecs defined for the endpoint, we weren't declining
the audio stream.  Since it's usually the first/transport stream,
when the video stream was processed and tried to use the transport,
it was empty and caused a crash.  We now decline the the stream if
there are no matching codecs so when the video stream is processed,
it's now the first/transport stream and processes normally.

Change-Id: Ic854eda54c95031e66b076ecfae3041d34daa692
2017-09-22 07:02:47 -05:00
Joshua Colp 63a3d17f0b Merge "res_rtp_asterisk.c: Fix bundled SSRC handling." 2017-09-22 06:42:30 -05:00
Joshua Colp 8b7aed0025 Merge "res_config_pgsql: Fix removed support to previous for versions PostgreSQL 9.1" 2017-09-22 05:42:43 -05:00
Joshua Colp f77a2367e7 Merge "bridge: Change participant SFU streams when source streams change." 2017-09-21 15:56:47 -05:00
Richard Mudgett 7c93982e9d res_rtp_asterisk.c: Fix bundled SSRC handling.
Assertions in the v15+ AST-2017-008 patches found that we were not
handling the case if the incoming SDP did not specify the required SSRC
attributes for bundled to work.

* Be strict on matching SSRC for bundled instances including the parent
instance.  If the SSRC doesn't match then discard the packet.  Bundled has
to tell us in the SDP signaling what SSRC to expect.  Otherwise, we will
not know how to find the bundled instance structure.

Change-Id: I152830bbff71c662408909042068fada39e617f9
2017-09-21 15:02:27 -05:00
Joshua Colp b9f7b03c0b Merge "AST-2017-008: Improve RTP and RTCP packet processing." 2017-09-21 14:48:17 -05:00
Jenkins2 f01cd0b409 Merge "res_config_pgsql: Add missing \n in debug log and update copyright year" 2017-09-21 13:06:18 -05:00
Joshua Colp 357a2f353b Merge "res_pjsip_session: Check for removed stream state." 2017-09-21 12:30:18 -05:00
Joshua Colp f2985e3106 bridge: Change participant SFU streams when source streams change.
Some endpoints do not like a stream being reused for a new
media stream. The frame/jitterbuffer can rely on underlying
attributes of the media stream in order to order the packets.
When a new stream takes its place without any notice the
buffer can get confused and the media ends up getting dropped.

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

ASTERISK-27277

Change-Id: I30ccbdba16ca073d7f31e0e59ab778c153afae07
2017-09-21 12:20:02 -05:00
Jenkins2 5ff46578aa Merge "res_srtp: lower log level of auth failures" 2017-09-21 12:07:57 -05:00
George Joseph 971548405b res_pjsip_session: Change some asserts to warning/debug messages
There was an issue reported where an SDP received on a 183 Session
Progress message caused a crash because the pending streams had
already been processed when the OK was received.  In that case the
pending topology was legitimately NULL.  There was an assert for an
incorrect number of streams in the topology but not one for
topology being NULL.  In any case, if you're not in dev-mode the
asserts don't do anything and since the scenario is legit, the
asserts weren't appropriate anyway.

* Changed several asserts to warning or debug messages and return
codes as appropriate.

ASTERISK-27264
Reported by: Daniel Heckl

Change-Id: I58daaa9d2938fa980857ab3ec41925ab5ff9c848
2017-09-21 10:40:24 -05:00
Rodrigo Ramírez Norambuena cad68137a7 res_config_pgsql: Fix removed support to previous for versions PostgreSQL 9.1
In PostgreSQL 9.1 the backslash are string literals and not the escape
of characters.

In previous issue ASTERISK_26057 was fixed the use of escape LIKE but the
support for old version of Postgresql than 9.1 was dropped. The sentence
before make was "ESCAPE '\'" but in version before than 9.1  need it to be
as follow "ESCAPE '\\'".

ASTERISK-27283

Change-Id: I96d9ee1ed7693ab17503cb36a9cd72847165f949
2017-09-21 06:52:41 -05:00
Ben Ford e666051d79 res_pjsip_session: Check for removed stream state.
When a sip session is refreshed, the stream topology is looped
through, checking each stream for compatible formats. This would
cause a crash if the stream state was AST_STREAM_STATE_REMOVED,
since the formats would never be set for this stream, causing
a NULL value to be returned from ast_stream_get_formats. This
commit adds a check for streams with removed states.

Also removed a stray semicolon.

Change-Id: Ic86f8b65a4a26a60885b28b8b1a0b22e1b471d42
2017-09-20 12:14:45 -05:00
Joshua Colp 8830cc0541 Merge "res_calendar: Plug memory leak and micro-optimization" 2017-09-20 09:44:53 -05:00
Alexander Traud 1e4c1cec7f res_srtp: lower log level of auth failures
Previously, sRTP authentication failures were reported on log level WARNING.
When such failures happen, each RT(C)P packet is affected, spamming the log.
Now, those failures are reported at log level VERBOSE 2. Furthermore, the
amount is further reduced (previously all two seconds, now all three seconds).
Additionally, the new log entry informs whether media (RTP) or statistics (RTCP)
are affected.

ASTERISK-16898 #close

Change-Id: I6c98d46b711f56e08655abeb01c951ab8e8d7fa0
2017-09-20 15:36:00 +02:00
George Joseph b748038230 res_pjsip_pubsub: Check for Content-Type header in rx_notify_request
pubsub_on_rx_notify_request wasn't checking for a null
Content-Type header before checking that it was
application/simple-message-summary.

ASTERISK-27279
Reported by: Ross Beer

Change-Id: Iec2a6c4d2e74af37ff779ecc9fd35644c5c4ea52
2017-09-19 13:52:17 -05:00
Rodrigo Ramírez Norambuena 56f0d5fc0f res_config_pgsql: Add missing \n in debug log and update copyright year
Change-Id: I4ba338ecbdecc6a814a902eddc4121c8ef3cda58
2017-09-19 08:34:28 -03:00
Sean Bright 55567ee1d8 res_calendar: Plug memory leak and micro-optimization
ast_variables_destroy is NULL safe, so there is no need to check its
argument before passing it.

ASTERISK-25524 #close
Reported by: Jesper

Change-Id: Ib0f8057642e9d471960f1a79fd42e5a3ce587d3b
2017-09-19 07:09:52 -04:00
Richard Mudgett 087f667ab1 AST-2017-008: Improve RTP and RTCP packet processing.
Validate RTCP packets before processing them.

* Validate that the received packet is of a minimum length and apply the
RFC3550 RTCP packet validation checks.

* Fixed potentially reading garbage beyond the received RTCP record data.

* Fixed rtp->themssrc only being set once when the remote could change
the SSRC.  We would effectively stop handling the RTCP statistic records.

* Fixed rtp->themssrc to not treat a zero value as special by adding
rtp->themssrc_valid to indicate if rtp->themssrc is available.

ASTERISK-27274

Make strict RTP learning more flexible.

Direct media can cause strict RTP to attempt to learn a remote address
again before it has had a chance to learn the remote address the first
time.  Because of the rapid relearn requests, strict RTP could latch onto
the first remote address and fail to latch onto the direct media remote
address.  As a result, you have one way audio until the call is placed on
and off hold.

The new algorithm learns remote addresses for a set time (1.5 seconds)
before locking the remote address.  In addition, we must see a configured
number of remote packets from the same address in a row before switching.

* Fixed strict RTP learning from always accepting the first new address
packet as the new stream.

* Fixed strict RTP to initialize the expected sequence number with the
last received sequence number instead of the last transmitted sequence
number.

* Fixed the predicted next sequence number calculation in
rtp_learning_rtp_seq_update() to handle overflow.

ASTERISK-27252

Change-Id: Ia2d3aa6e0f22906c25971e74f10027d96525f31c
2017-09-15 15:50:43 -05:00
Jenkins2 317b62c8b4 Merge "res_pjsip: Filter out non SIP(S) requests" 2017-09-15 15:37:04 -05:00
Joshua Colp e1837aca0c Merge "res_calendar: Various fixes" 2017-09-15 08:20:45 -05:00
George Joseph d178f497d2 res_pjsip: Filter out non SIP(S) requests
Incoming requests with non sip(s) URIs in the Request, To, From
or Contact URIs are now rejected with
PJSIP_SC_UNSUPPORTED_URI_SCHEME (416).  This is performed in
pjsip_message_filter (formerly pjsip_message_ip_updater) and is
done at pjproject's "TRANSPORT" layer before a request can even
reach the distributor.

URIs read by res_pjsip_outbound_publish from pjsip.conf are now
also checked for both length and sip(s) scheme.  Those URIs read
by outbound registration and aor were already being checked for
scheme but their error messages needed to be updated to include
scheme failure as well as length failure.

Change-Id: Ibb2f9f1d2dc7549da562af4cbd9156c44ffdd460
2017-09-14 14:18:42 -05:00
Sean Bright d8112cd98b res_calendar: Various fixes
* The way that we were looking at XML elements for CalDAV was extremely
  fragile, so use SAX2 for increased robustness.

* Don't complain about a 'channel' not be specified if autoreminder is
  not set. Assume that if 'channel' is not set, we don't want to be
  notified.

* Fix some truncated CLI output in 'calendar show calendar' and make the
  'Autoreminder' description a bit more clear

ASTERISK-24588 #close
Reported by: Stefan Gofferje

ASTERISK-25523 #close
Reported by: Jesper

Change-Id: I200d11afca6a47e7d97888f286977e2e69874b2c
2017-09-13 14:47:21 -05:00
George Joseph 446d48fd49 res_pjsip: Add handling for incoming unsolicited MWI NOTIFY
A new endpoint parameter "incoming_mwi_mailbox" allows Asterisk to
receive unsolicited MWI NOTIFY requests and make them available to
other modules via the stasis message bus.

res_pjsip_pubsub has a new handler "pubsub_on_rx_mwi_notify_request"
that parses a simple-message-summary body and, if
endpoint->incoming_mwi_account is set, calls ast_publish_mwi_state
with the voice-message counts from the message.

Change-Id: I08bae3d16e77af48fcccc2c936acce8fc0ef0f3c
2017-09-13 09:24:28 -05:00
Richard Mudgett 4889574ff5 res_rtp_asterisk.c: Add doxygen to RTCP payload types.
Change-Id: I3f20ce428777cc4ce9c13b2f808d29ff8c873998
2017-09-11 12:36:17 -05:00
Walter Doekes 680aba21ec res/res_pjsip: Fix localnet checks in pjsip, part 2.
In 45744fc53, I mistakenly broke SDP media address rewriting by
misinterpreting which address was checked in the localnet comparison.

Instead of checking the remote peer address to decide whether we need
media address rewriting, we check our local media address: if it's
local, then we rewrite. This feels awkward, but works and even made
directmedia work properly if you set local_net. (For the record: for
local peers, the SDP media rewrite code is not called, so the
comparison does no harm there.)

ASTERISK-27248 #close

Change-Id: I566be1c33f4d0a689567d451ed46bab9c3861d4f
2017-09-10 06:19:28 -05:00
Joshua Colp 973885df0d Merge "res_srtp: Add support for libsrtp2.1." 2017-09-08 05:40:04 -05:00
Jenkins2 bee342fdd2 Merge "res_pjsip_session: Preserve stream name during renegotiation." 2017-09-07 12:51:40 -05:00
Jenkins2 2f03e11b0e Merge "stasis/control.c: Fix set_interval_hook() ref leak." 2017-09-07 10:46:43 -05:00
Richard Mudgett 23571f31ac stasis/control.c: Fix set_interval_hook() ref leak.
Change-Id: Ia0edb7dc0dbbb879c079ff7000f1b722d86ce7dc
2017-09-06 13:40:12 -05:00
George Joseph 94091c7b96 stasis/control: Fix possible deadlock with swap channel
If an error occurs during a bridge impart it's possible that
the "bridge_after" callback might try to run before
control_swap_channel_in_bridge has been signalled to continue.
Since control_swap_channel_in_bridge is holding the control lock
and the callback needs it, a deadlock will occur.

* control_swap_channel_in_bridge now only holds the control
  lock while it's actually modifying the control structure and
  releases it while the bridge impart is running.
* bridge_after_cb is now tolerant of impart failures.

Change-Id: Ifd239aa93955b3eb475521f61e284fcb0da2c3b3
2017-09-06 13:00:49 -05:00
Jenkins2 23f22a3647 Merge "res/res_pjsip: Standardize/fix localnet checks across pjsip." 2017-09-06 10:17:06 -05:00
Jenkins2 4b606c25e3 Merge "res_pjsip_t38: Make t38_reinvite_response_cb tolerant of NULL channel" 2017-09-06 06:48:45 -05:00
Alexander Traud 2d395793b7 res_srtp: Add support for libsrtp2.1.
Asterisk is able to use libSRTP 2.0.x. However since libSRTP 2.1.x, the macro
SRTP_AES_ICM got renamed to SRTP_AES_ICM_128. Beside to still compile with
previous versions of libSRTP, this change allows libSRTP 2.1.x as well.

ASTERISK-27253 #close

Change-Id: I2e6eb3c3bc844fee8a624060a2eb6f182dc70315
2017-09-06 10:02:19 +02:00
Walter Doekes f856d9b42b res/res_pjsip: Standardize/fix localnet checks across pjsip.
In 2dee95cc (ASTERISK-27024) and 776ffd77 (ASTERISK-26879) there was
confusion about whether the transport_state->localnet ACL has ALLOW or
DENY semantics.

For the record: the localnet has DENY semantics, meaning that "not in
the list" means ALLOW, and the local nets are in the list.

Therefore, checks like this look wrong, but are right:

    /* See if where we are sending this request is local or not, and if
       not that we can get a Contact URI to modify */
    if (ast_apply_ha(transport_state->localnet, &addr) != AST_SENSE_ALLOW) {
        ast_debug(5, "Request is being sent to local address, "
                     "skipping NAT manipulation\n");

(In the list == localnet == DENY == skip NAT manipulation.)

And conversely, other checks that looked right, were wrong.

This change adds two macro's to reduce the confusion and uses those
instead:

    ast_sip_transport_is_nonlocal(transport_state, addr)
    ast_sip_transport_is_local(transport_state, addr)

ASTERISK-27248 #close

Change-Id: Ie7767519eb5a822c4848e531a53c0fd054fae934
2017-09-05 09:17:32 -05:00
Joshua Colp 68bcfccd52 res_pjsip_session: Preserve stream name during renegotiation.
Stream names within Asterisk can have meaning so when an externally
initiated renegotiation occurs we need to preserve the name of
the stream if it already exists.

Change-Id: I29f50d0cc7f3238287d6d647777e76e1bdf8c596
2017-09-05 08:41:08 -05:00
George Joseph 0ec95515f3 res_calendar*, res_smdi: Move to "extended" support
Change-Id: I31eee8be30c6b0fc3dadb31111dd47742da8892d
2017-09-05 07:51:56 -05:00
George Joseph 9b3f6d26bd res_pjsip_t38: Make t38_reinvite_response_cb tolerant of NULL channel
t38_reinvite_response_cb can get called by res_pjsip_session's
session_inv_on_tsx_state_changed in situations where session->channel
is NULL.  If it is, the ast_log warning segfaults because it tries
to get the channel name from a NULL channel.

* Check session->channel and print "unknown channel" when it's NULL.

ASTERISK-27236
Reported by: Ross Beer

Change-Id: I4326e288d36327f6c79ab52226d54905cdc87dc7
2017-09-05 05:57:59 -05:00
Joshua Colp be8639f81b Merge "res_rtp_asterisk: Allow remote SSRC to change on an RTP instance." 2017-08-31 16:50:50 -05:00
Joshua Colp 8cfff60cee Merge "res_rtp_asterisk: Only learn a new source in learn state." 2017-08-31 08:34:48 -05:00
Jenkins2 41ab281f1a Merge "pjsip_message_ip_updater: Fix issue handling "tel" URIs" 2017-08-31 08:30:17 -05:00
George Joseph f78f5278ff pjsip_message_ip_updater: Fix issue handling "tel" URIs
sanitize_tdata was assuming all URIs were SIP URIs so when a non
SIP uri was in the From, To or Contact headers, the unconditional
cast of a non-pjsip_sip_uri structure to pjsip_sip_uri caused
a segfault when trying to access uri->other_param.

* Added PJSIP_URI_SCHEME_IS_SIP(uri) || PJSIP_URI_SCHEME_IS_SIPS(uri)
  checks before attempting to cast or use the returned uri.

ASTERISK-27152
Reported-by: Ross Beer

Change-Id: Id380df790e6622c8058a96035f8b8f4aa0b8551f
2017-08-30 18:46:05 +00:00
Corey Farrell 1bf3dfffd7 AST-2017-006: Fix app_minivm application MinivmNotify command injection
An admin can configure app_minivm with an externnotify program to be run
when a voicemail is received.  The app_minivm application MinivmNotify
uses ast_safe_system() for this purpose which is vulnerable to command
injection since the Caller-ID name and number values given to externnotify
can come from an external untrusted source.

* Add ast_safe_execvp() function.  This gives modules the ability to run
external commands with greater safety compared to ast_safe_system().
Specifically when some parameters are filled by untrusted sources the new
function does not allow malicious input to break argument encoding.  This
may be of particular concern where CALLERID(name) or CALLERID(num) may be
used as a parameter to a script run by ast_safe_system() which could
potentially allow arbitrary command execution.

* Changed app_minivm.c:run_externnotify() to use the new ast_safe_execvp()
instead of ast_safe_system() to avoid command injection.

* Document code injection potential from untrusted data sources for other
shell commands that are under user control.

ASTERISK-27103

Change-Id: I7552472247a84cde24e1358aaf64af160107aef1
2017-08-30 18:43:38 +00:00
Joshua Colp 7f2a60fb38 res_rtp_asterisk: Only learn a new source in learn state.
This change moves the logic which learns a new source address
for RTP so it only occurs in the learning state. The learning
state is entered on initial allocation of RTP or if we are
told that the remote address for the media has changed. While
in the learning state if we continue to receive media from
the original source we restart the learning process. It is
only once we receive a sufficient number of RTP packets from
the new source that we will switch to it. Once this is done
the closed state is entered where all packets that do not
originate from the expected source are dropped.

The learning process has also been improved to take into
account the time between received packets so a flood of them
while in the learning state does not cause media to be switched.

Finally RTCP now drops packets which are not for the learned
SSRC if strict RTP is enabled.

ASTERISK-27013

Change-Id: I56a96e993700906355e79bc880ad9d4ad3ab129c
2017-08-30 18:39:26 +00:00
Joshua Colp 5ba82cedc6 res_rtp_asterisk: Allow remote SSRC to change on an RTP instance.
When SDP renegotiation occurs it is possible for an RTP
instance to be reused for a new stream, resulting in the remote
SSRC changing if it is part of a bundle group. This change
allows this and updates its mapping in the current bundle
group.

ASTERISK-27231

Change-Id: I6e3703974f236bc024c5dbe9bd43adae0c6fb490
2017-08-30 09:18:56 -05:00
Torrey Searle 33a648d4c6 res/res_pjsip_session: allow SDP answer to be regenerated
If an SDP answer hasn't been sent yet, it's legal to change it.
This is required for PJSIP_DTMF_MODE to work correctly, and can
also have use in the future for updating codecs too.

ASTERISK-27209 #close

Change-Id: Idbbfb7cb3f72fbd96c94d10d93540f69bd51e7a1
2017-08-25 14:27:24 +02:00
Sean Bright 7937d5b8b3 res_smdi: Clean up memory leak
Change-Id: I1e33290929e1aa7c5b9cb513f8254f2884974de8
2017-08-24 08:39:50 -05:00
Richard Mudgett f2c14f00b8 res_pjsip_session.c: Fix crash when declining an active stream.
If a previously active stream is declined we could crash because the
channel's thread is still using the stream while we are updating the
topology in the serializer thread.

* Defer removing any declined stream's handler until we have blocked the
channel's thread with the channel lock.

ASTERISK-27212

Change-Id: I50e1d3ef26f8e41948f4c411ee329aa3b960a420
2017-08-22 11:59:49 -05:00
Jenkins2 c86619bab8 Merge "res_xmpp: fix inverted return code check in OAuth" 2017-08-22 07:57:39 -05:00
Michael Kuron 83b81d1f8d res_xmpp: fix inverted return code check in OAuth
fetch_access_token calls func_curl via ast_func_read. The latter returns 0 upon
success and -1 if the function is not available.
This commit inverts the return code check so that an error is printed if the
module is not loaded and not if it is loaded.

ASTERISK-27207 #close

Change-Id: I9ef903f80702d1218e8701f65a4e5e918e6548fb
2017-08-22 00:36:07 -05:00
Sean Bright 667986d875 res_calendar_icalendar: Properly handle recurring events
When looking for recurring events, use the correct end time based on the
configured 'timeframe.'

ASTERISK-27174 #close
Reported by: Mark Thompson

Change-Id: Id90c3cfc79d561a5521d79be176683e225f2edef
2017-08-17 12:15:52 -05:00
Richard Mudgett 9e2b2a9837 res_pjsip: Fix prune_on_boot to remove only contacts for the host.
* Check that the contact's reg_server matches the host's name before
deleting any prune_on_boot contacts.  We don't want to delete reliable
transport contacts made with other servers if the ps_contacts database
table is shared with other servers.

Thanks to Ross Beer for pointing out that the original prune logic would
delete reliable transport contacts from other servers.

ASTERISK-27147

Change-Id: I8e439d0d1c266ffdfd7b73d1e5e466180a689bd0
2017-08-15 11:22:54 -05:00
Andrey Egorov 15fbcc74d8 res_xmpp: Google OAuth 2.0 protocol support for XMPP / Motif
Add ability to use tokens instead of passwords according to Google OAuth 2.0
protocol.

ASTERISK-27169
Reported by: Andrey Egorov
Tested by: Andrey Egorov

Change-Id: I07f7052a502457ab55010a4d3686653b60f4c8db
2017-08-15 06:09:52 -05:00
Richard Mudgett 1bec781cce res_pjsip_outbound_registration.c: Re-REGISTER on transport shutdown.
The fix for the issue is broken up into three parts.

This is part three which handles the client side of REGISTER requests.
The registered contact may no longer be valid on the server when the
transport used is reliable and the connection is broken.

* Re-REGISTER our contact if the reliable transport is broken after
registration completes.  We attempt to re-REGISTER immediately to minimize
the time we are unreachable.  Time may have already passed between the
connection being broken and the loss being detected.

* Reorder sip_outbound_registration_state_alloc() so the STATSD_GUAGE's
are still correct if an allocation failure happens.

ASTERISK-27147

Change-Id: I3668405b1ee75dfefb07c0d637826176f741ce83
2017-08-10 12:18:58 -05:00
Richard Mudgett 82f4ade959 res_pjsip: Remove ephemeral registered contacts on transport shutdown.
The fix for the issue is broken up into three parts.

This is part two which handles the server side of REGISTER requests when
rewrite_contact is enabled.  Any registered reliable transport contact
becomes invalid when the transport connection becomes disconnected.

* Monitor the rewrite_contact's reliable transport REGISTER contact for
shutdown.  If it is shutdown then the contact must be removed because it
is no longer valid.  Otherwise, when the client attempts to re-REGISTER it
may be blocked because the invalid contact is there.  Also if we try to
send a call to the endpoint using the invalid contact then the endpoint is
not likely to see the request.  The endpoint either won't be listening on
that port for new connections or a NAT/firewall will block it.

* Prune any rewrite_contact's registered reliable transport contacts on
boot.  The reliable transport no longer exists so the contact is invalid.

* Websockets always rewrite the REGISTER contact address and the transport
needs to be monitored for shutdown.

* Made the websocket transport set a unique name since that is what we use
as the ao2 container key.  Otherwise, we would not know which transport we
find when one of them shuts down.  The names are also used for PJPROJECT
debug logging.

* Made the websocket transport post the PJSIP_TP_STATE_CONNECTED state
event.  Now the global keep_alive_interval option, initially idle shutdown
timer, and the server REGISTER contact monitor can work on wetsocket
transports.

* Made the websocket transport set the PJSIP_TP_DIR_INCOMING direction.
Now initially idle websockets will automatically shutdown.

ASTERISK-27147

Change-Id: I397a5e7d18476830f7ffe1726adf9ee6c15964f4
2017-08-10 12:18:58 -05:00
Richard Mudgett 1dcb92bba8 res_pjsip: PJSIP Transport state monitor refactor.
The fix for the issue is broken up into three parts.

This is part one which refactors the transport state monitor code to allow
more modules to be able to monitor transports.

* Pull the management of PJPROJECT's transport state callback code from
res_pjsip_transport_management.c into res_pjsip.  Now other modules can
dynamically add and remove themselves from transport monitoring without
worrying about breaking PJPROJECT's callback chain.

* Add the ability for other modules to get a callback whenever a specific
transport is shutdown.

ASTERISK-27147

Change-Id: I7d9a31371eb1487c9b7050cf82a9af5180a57912
2017-08-10 12:18:58 -05:00
Richard Mudgett ee5edfb050 res_pjsip_transport_management.c: Rename some variables.
* Use monitored instead of the misleading keepalive name.

Change-Id: I9e5bcbb4ab2b82d49bcd0f06dfe85d15e0b552b6
2017-08-10 12:18:58 -05:00
Scott Griepentrog 4ed2733dde res_pjsip_messaging: IPv6 receive address needs brackets
When handling an incoming SIP MESSAGE, PJSIP
attaches the IP address that the message was
received from to the message in the variable
PJSIP_RECVADDR.  When the IP address is IPv6
the :PORT appended results in an unparseable
mess. By using an additional bit flag on the
pj_sockaddr_print call, the conventional use
of brackets around the address is achieved.

ASTERISK-27193 #close

Change-Id: I12342521f2ce87a5b6e4883d480a3fd957aa9fd9
2017-08-10 09:23:38 -05:00
Jenkins2 08d22bedcc Merge "res_rtp_asterisk: Make P2P bridge Asymmetric codec aware" 2017-08-09 15:39:34 -05:00
Torrey Searle d430f718f5 res_rtp_asterisk: enable rtcp & QOS stats on native bridge
Asterisk wasn't generating or forwarding RTCP packets when native
bridge was activated.  Also the stats weren't available via
CHANNEL(qos). Now the RTCP stats are always calculated.

ASTERISK-27158 #close

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

ASTERISK-26745 #close

Change-Id: I0d9c83e5356df81661e58d40a8db565833501a6f
2017-08-09 08:57:50 -05:00
Jenkins2 df4bcdda2a Merge "res_pjsip_session/_sdp_rtp: Handling of 'msid' is incorrect" 2017-08-09 08:15:24 -05:00
Joshua Colp 62092bc114 res_pjsip_session: Release media resources on session end quicker.
A change was made long ago where the session was kept around
until the underlying INVITE session had been destroyed. This
had the side effect of also keeping the underlying media resources
around for this time as well.

This change ensures that when we are told to terminate the
session we immediately release any media sessions associated
with it.

ASTERISK-27110

Change-Id: I643e431d5c3bf05cda220c1d39e824a505a29b82
2017-08-07 19:54:01 -05:00
Joshua Colp dcd846c321 Merge "res_pjsip_nat.c: Remove unnecessary CMP_STOP." 2017-08-07 08:31:50 -05:00
Jenkins2 e0aed61e96 Merge "Support GMIME 3.0" 2017-08-07 07:33:03 -05:00
Kevin Harwell 104a8047a5 res_pjsip_session/_sdp_rtp: Handling of 'msid' is incorrect
Currently, the handling of the msid attribute is not quite right. According to
the spec the msid's between the offer/answer are not dependent upon one another.
Meaning the same msid's given in an offer do not have to be returned in the
answer for a given stream. And they probably shouldn't be (copied/reused) since
this can potentially cause some browser side confusion.

This patch generates new msids when both an offer and answer are sent from
Asterisk. However, Asterisk does reuse the original msid it sent out for a
reinvite. Also audio+video streams are paired together by sharing the same
stream id, but a different track id.

ASTERISK-27179 #close

Change-Id: Ifaec06dc7e65ad841633a24ebec8c8a9302d6643
2017-08-04 17:15:40 -05:00
Jenkins2 2ba29df200 Merge "alembic/res_pjsip: Add "webrtc" configuration option" 2017-08-04 13:11:34 -05:00
Jenkins2 7af10de1ba Merge "res_pjsip_transport_websocket.c: Fix serializer ref leak." 2017-08-04 10:51:42 -05:00
Jenkins2 50d842b79a Merge "res_pjsip_outbound_registration.c: Misc fixes." 2017-08-04 10:00:56 -05:00
Richard Mudgett 842e1414d0 res_pjsip_transport_websocket.c: Fix serializer ref leak.
Change-Id: Ib5a19bfd597f63d9021baeb645fc11153b3afa57
2017-08-03 16:35:49 -05:00
Richard Mudgett 615b6a200a res_pjsip_outbound_registration.c: Misc fixes.
* Remove unnecessary CMP_STOP.

* In handle_client_registration() use DEBUG_ATLEAST() to only do work
needed for the debug log message when the debug log message is needed.

* In sip_outbound_registration_state_destroy() check state->registration
for NULL.

Change-Id: I656d0fa11dda0b00048103efb1558e67a426fd80
2017-08-03 16:26:52 -05:00
Richard Mudgett 564927c5ed res_pjsip_nat.c: Remove unnecessary CMP_STOP.
Change-Id: I6279b0d723bc3b75b8d65e81e02da9ea9bc0c3da
2017-08-03 16:24:22 -05:00
Richard Mudgett 5655cded78 res_pjsip_registrar.c: Remove unnecessary CMP_STOP.
Most uses of CMP_STOP are superfluous and are only respected when
OBJ_MULTIPLE is used to search the container.

Change-Id: I20571a202ec0aa1098bb2749eeba18de7ca110b8
2017-08-03 16:22:15 -05:00
Tzafrir Cohen 123c93a77c Support GMIME 3.0
Support building the Asterisk httpd with version 3.0 of gmime as
well as earlier versions of that library.

ASTERISK-27173

Change-Id: I7e13dd05a3083ccb0df2dabf83110223f6a9fa8f
2017-08-03 14:15:26 -04:00
Kevin Harwell 521b6fed12 alembic/res_pjsip: Add "webrtc" configuration option
When the "webrtc" option was added in res_pjsip it was not added to the alembic
scripts. This patch adds the option for alembic.

Also, changed the sorcery configuration type to an OPT_YESNO_T value instead of
an OPT_BOOL_T so if this field is ever written to a database it will write out
the correct value.

ASTERISK-27119 #close

Change-Id: I3e199f060aea25e193c439fc5cf96be4d3ed1c7b
2017-08-03 11:44:28 -05:00
Sean Bright 2be8d91c0f res_pjsip_pidf_eyebeam_body_supplement: Correct status presentation
This change fixes PIDF content generation when the underlying device
state is considered in use. Previously it was incorrectly marked
as closed meaning they were offline/unavailable. The code now
correctly marks them as open.

Additionally:

  * Generate an XML element for our activity instead of a using a text
    node.

  * Consider every extension state other than "unavailable" to be 'open'
    status.

  * Update the XML namespaces and structure to reflect those
    documented in RFC 4480

  * Use 'on-the-phone' (defined in RFC 4880) instead of 'busy' as the
    "in use" activity. This change results in eyeBeam using the
    appropriate icon for the watched user.

This was tested on eyeBeam 1.5.20.2 build 59030 on Windows.

ASTERISK-26659 #close
Reported by: Abraham Liebsch
patches:
  ASTERISK-26659.diff submitted by snuffy (license 5024)

Change-Id: I6e5ad450f91106029fb30517b8c0ea0c2058c810
2017-08-01 15:42:38 -06:00
Joshua Colp 2a4283f3e7 res_pjsip: Add support for dnsmgr to external_media_address.
The "external_media_address" option on transports is now
resolved using dnsmgr. This allows it to be automatically
refreshed regularly if refreshes are enabled in dnsmgr.
If the system is using a dynamic IP address a dynamic DNS
hostname can be provided to keep the IP address up to
date.

Change-Id: Ia54771720dff0105bde55d5bbb81a3ba437e05b2
2017-08-01 15:42:38 -06:00
Corey Farrell 58d032112b Fix compiler warnings on Fedora 26 / GCC 7.
GCC 7 has added capability to produce warnings, this fixes most of those
warnings.  The specific warnings are disabled in a few places:

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

ASTERISK-27156 #close

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

ASTERISK-27085 #close

Change-Id: I20eef5da3e5d1d3e58b304416bc79683f87e7612
2017-08-01 15:41:53 -06:00
Sean Bright b3914df10b res_rtp_asterisk: Fix mapping of pjsip's ICE roles to ours
Change-Id: Ia578ede1a55b21014581793992a429441903278b
2017-07-26 16:16:41 -05:00
Joshua Colp b610295b62 Merge "bridge_softmix / res_rtp_asterisk: Fix packet loss and renegotiation issues." 2017-07-26 08:31:13 -05:00
Joshua Colp 7ea6c66968 Merge "res_stasis_device_state: Unsubscribe should remove old subscriptions" 2017-07-26 08:27:31 -05:00
Joshua Colp 8412cc1e07 Merge "SDP: Rework SDP offer/answer model and update capabilities merges." 2017-07-26 08:20:35 -05:00
Sergej Kasumovic 4f4936fd72 res_stasis_device_state: Unsubscribe should remove old subscriptions
Case scenario with Applications ARI:

* Once you subscribe to deviceState with Applications REST API, it will be
added into subscription pool.

* When you unsubscribe it will remove from the device_state_subscription
hash table but not from the subscription pool.

* When you subscribe again, it will add it to pool again.

* Now you will have two subscriptions and you will receive same event
twice.

This fix should now remove deviceState subscription from pool and it
should fix unsubscribe on deviceState.

ASTERISK-27130 #close

Change-Id: I718b70d770a086e39b4ddba4f69a3c616d4476c4
2017-07-25 07:58:21 -05:00
Joshua Colp f43fc91911 Merge "core: Add digit filtering to ast_waitfordigit_full" 2017-07-19 13:09:56 -05:00
Joshua Colp 680c491a62 bridge_softmix / res_rtp_asterisk: Fix packet loss and renegotiation issues.
This change does a few things to improve packet loss and renegotiation:

1. On outgoing RTP streams we will now properly reflect out of order
packets and packet loss in the sequence number. This allows the
remote jitterbuffer to better reorder things.

2. Video updates can now be discarded for a period of time
after one has been sent to prevent flooding of clients.

3. For declined and removed streams we will now release any
media session resources associated with them. This was not
previously done and caused an issue where old state was being
used for a new stream.

4. RTP bundling was not actually removing bundled RTP instances
from the parent. This has been resolved by removing based on
the RTP instance itself and not the SSRC.

5. The code did not properly handle explicitly unbundling an
RTP instance from its parent. This now works as expected.

ASTERISK-27143

Change-Id: Ibd91362f0e4990b6129638e712bc8adf0899fd45
2017-07-19 13:23:26 +00:00
Jenkins2 647f539e15 Merge "res_pjsip: Add "webrtc" configuration option" 2017-07-17 15:16:30 -05:00
Jenkins2 29af7d5558 Merge "res_rtp_asterisk: Use RTP component for ICE if RTCP-MUX is in use." 2017-07-17 14:54:22 -05:00
Jenkins2 e34dfca8be Merge "res/res_stasis_snoop: generate silence when audiohook returns null" 2017-07-17 08:25:29 -05:00
Joshua Colp 942ee54b53 res_rtp_asterisk: Use RTP component for ICE if RTCP-MUX is in use.
This change makes it so that if an RTCP packet is being sent
the RTP ICE component is used for sending if RTCP-MUX is in use.

ASTERISK-27133

Change-Id: I6200f611ede709602ee9b89501720c29545ed68b
2017-07-16 17:26:00 +00:00
George Joseph a20703fd1b Merge "res/res_pjsip_t38 ensure t38 requests get rejected quickly" 2017-07-14 07:44:20 -05:00
Kevin Harwell 7da6ddda30 res_pjsip: Add "webrtc" configuration option
This patch creates a new configuration option called "webrtc". When enabled it
defaults and enables the following options that are needed in order for webrtc
to work in Asterisk:

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

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

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

ASTERISK-27119 #close

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

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

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

ASTERISK-27118

Change-Id: I96c0920b9f9aca7382256484765a239017973c11
2017-07-13 14:47:50 +00:00
Torrey Searle 8b535a406b res/res_stasis_snoop: generate silence when audiohook returns null
Currently when rtp is paused, no packets are written to the
recorded audio file, causing the silence to be skipped and recording
not properly time aligned.  The read handler as been adapted to
return a silence frame of the correct size.

ASTERISK-27128 #close

Change-Id: I2d7f60650457860b9c70907b14426756b058a844
2017-07-13 09:46:53 -05:00
Torrey Searle d42a9cc9dc res/res_pjsip_t38 ensure t38 requests get rejected quickly
arm the t38 webhook always, so we can correctly reject a
T38 negotiation request when t38 is disabled on a channel

Change-Id: Ib1ffe35aee145d4e0fe61dd012580be11aae079d
2017-07-13 15:02:20 +02:00
Corey Farrell 6b138046e7 core: Add digit filtering to ast_waitfordigit_full
This adds a parameter to ast_waitfordigit_full which can be used to only
stop waiting when certain expected digits are received.  Any unexpected
DTMF digits are simply ignored.

This also creates a new dialplan application WaitDigit.

ASTERISK-27129 #close

Change-Id: Id233935ea3d13e71c75a0861834c5936c3700ef9
2017-07-12 19:08:23 -04:00
Joshua Colp 8082f6cf7e Merge "res_rtp_asterisk: trigger source change control frame when dtls is established" 2017-07-12 06:13:25 -05:00
George Joseph b7a875778a res_musiconhold: Add kill_escalation_delay, kill_method to class
By default, when res_musiconhold reloads or unloads, it sends a HUP
signal to custom applications (and all descendants), waits 100ms,
then sends a TERM signal, waits 100ms, then finally sends a KILL
signal.  An application which is interacting with an external
device and/or spawns children of its own may not be able to exit
cleanly in the default times, expecially if sent a KILL signal, or
if it's children are getting signals directly from
res_musiconhoild.

* To allow extra time, the 'kill_escalation_delay'
  class option can be used to set the number of milliseconds
  res_musiconhold waits before escalating kill signals, with the
  default being the current 100ms.

* To control to whom the signals are sent, the "kill_method" class
  option can be set to "process_group" (the default, existing
  behavior), which sends signals to the application and its
  descendants directly, or "process" which sends signals only to the
  application itself.

Change-Id: Iff70a1a9405685a9021a68416830c0db5158603b
2017-07-11 14:43:41 -06:00
Jenkins2 3e7cfe3a92 Merge "res_pjsip: Fix crash with from_user containing invalid characters." 2017-07-11 07:08:39 -05:00
Jenkins2 f878ac2d07 Merge "res_rtp_asterisk.c: Fix TURN deadlock by using ICE session group lock." 2017-07-10 11:19:16 -05:00
Benjamin Keith Ford 8f72128e66 res_pjsip: Fix crash with from_user containing invalid characters.
If the from_user field contains certain characters (like @, {, ^, etc.),
PJSIP will return a null value for the URI when attempting to parse it.
This causes a crash when trying to dial out through a trunk that contains
these invalid characters in its from_user field.

This change checks the configuration and ensures that an endpoint will
not be created if the from_user contains an invalid character. It also
adds a null check to the PJSIP URI parsing as a backup.

ASTERISK-27036 #close
Reported by: Maxim Vasilev

Change-Id: I0396fdb5080604e0bdf1277464d5c8a85db913d0
2017-07-10 09:55:05 -05:00
Jenkins2 d6c08cc559 Merge "core: Remove 'Data Retrieval API'" 2017-07-07 15:42:56 -05:00
Richard Mudgett 9cd8a1df79 res_rtp_asterisk.c: Fix TURN deadlock by using ICE session group lock.
When a message is received on the TURN socket, the code processing the
message needs to call into the ICE/STUN session for further processing.
This code path locks the TURN group lock then the ICE/STUN group lock.  In
another thread an ICE/STUN timer can fire off to send a keep alive message
over the TURN socket.  In this code path, the ICE/STUN group lock is
obtained then the TURN group lock is obtained to send the packet.  A
classic deadlock case if the group locks are not the same.

* Made TURN get created using the ICE/STUN session's group lock.

NOTE: I was originally concerned that the ICE/STUN session can get
recreated by ice_reset_session() for an event like RTCP multiplexing
causing a change during SDP negotiation.  In this case the TURN group lock
would become different.  However, TURN is also recreated as part of the
ICE/STUN recreation in ice_create() when all known ICE candidates are
added to the new ICE session.  While the ICE/STUN and TURN sessions are
being recreated there is a period where the group locks could be
different.

ASTERISK-27023 #close
Patches:
    res_rtp_asterisk-turn-deadlock-fix.patch (license #6502)
        patch uploaded by Michael Walton (modified)

Change-Id: Ic870edb99ce4988a8c8eb6e678ca7f19da1432b9
2017-07-06 16:14:48 -05:00
George Joseph a10bc3e23f Merge "pjsip_distributor.c: Fix deadlock with TCP type transports." 2017-07-05 16:08:46 -05:00
Jenkins2 16f0fa52c0 Merge "pjsip_distributor.c: Fix unidentified_requests hash functions." 2017-07-05 15:32:40 -05:00
Jenkins2 d2b32cd009 Merge "chan_pjsip: Fix ability to send UPDATE on COLP" 2017-07-05 14:17:23 -05:00
Sean Bright 325eeced6a core: Remove 'Data Retrieval API'
This API was not actively maintained, was not added to new modules
(such as res_pjsip), and there exist better alternatives to acquire the
same information, such as the ARI.

Change-Id: I4b2185a83aeb74798b4ad43ff8f89f971096aa83
2017-07-05 11:25:58 -05:00
Richard Mudgett b485f6c59c pjsip_distributor.c: Fix deadlock with TCP type transports.
When a SIP message comes in on a transport, pjproject obtains the lock on
the transport and pulls the data out of the socket.  Unlike UDP, the TCP
transport does not allow concurrent access.  Without concurrency the
transport lock is not released when the transport's message complete
callback is called.  The processing continues and eventually Asterisk
starts processing the SIP message.  The first thing Asterisk tries to do
is determine the associated dialog of the message to determine the
associated serializer.  To get the associated serializer safely requires
us to get the dialog lock.

To send a request or response message for a dialog, pjproject obtains the
dialog lock and then obtains the transport lock.  Deadlock can result
because of the opposite order the locks are obtained.

* Fix the deadlock by obtaining the serializer associated with the dialog
another way that doesn't involve obtaining the dialog lock.  In this case,
we use an ao2 container to hold the associated endpoint and serializer.
The new locks are held a brief time and won't overlap other existing lock
times.

ASTERISK-27090 #close

Change-Id: I9ed63f4da9649e9db6ed4be29c360968917a89bd
2017-06-30 13:04:37 -05:00
Richard Mudgett 65a5ac0168 pjsip_distributor.c: Fix unidentified_requests hash functions.
The OBJ_SEARCH_xxx defines should not be used as if they were individual
bits.  They represent a multi-bit enumeration value field.

Change-Id: I32abc9a475396dab02402a7014357dd94284e17b
2017-06-30 12:01:21 -05:00
Jenkins2 e1c0e14fac Merge "res_pjsip: Add DTMF INFO Failback mode" 2017-06-30 11:57:00 -05:00
Joshua Colp 16e43ef701 Merge "res_rtp_asterisk: Fix issues with ICE renegotiation." 2017-06-30 11:47:42 -05:00
Kevin Harwell 7df7b8a90c res_rtp_asterisk: trigger source change control frame when dtls is established
There needed to be a way to notify handlers upstream that DTLS had been
established. This patch makes it so once DTLS has been estalished a source
change control frame is put into the read queue. Any handlers can then watch
for that frame and trigger off of it.

ASTERISK-27096 #close

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

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

ASTERISK-27095

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

ASTERISK-27066 #close

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

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

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

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

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

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

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

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

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

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

ASTERISK-27076

Change-Id: I8afd8dd2eb538806a39b887af0abd046266e14c7
2017-06-28 18:36:29 +00:00
Joshua Colp 642f8356ab res_rtp_asterisk: Fix issues with ICE renegotiation.
When re-inviting to add more streams it is possible for
the role of existing ICE sessions to be changed to the
incorrect value. This results in subsequent refreshes
within the sessions getting a role conflict and the ICE
session breaking down. This change only sets the role to
be the new value if an ICE renegotiation is actually
going to happen, otherwise the existing role is preserved.

As well if we encounter a situation where a unidirectional
ICE negotiation happens and the other side does not send us
candidates we will not store any information for sending
traffic, even though we know where they are reachable. This
change fixes this by using the source of the ICE traffic
itself as the target if no candidates are known and we
receive some ICE traffic.

ASTERISK-27088

Change-Id: I71228181e358917fcefc3100fad21b2fc02a59a9
2017-06-28 09:14:21 -05:00
Torrey Searle a48d3e4d31 res/res_pjsip_t38: fix incorrect increment of media_count
The T38 sdp callback incorrectly has a side effect of incrementing
the media_count.  This can lead to core dumps.

Change-Id: I7bb2f4987de4046ec52cfc34e5ea0662dae32af8
2017-06-27 11:46:23 -05:00
Jenkins2 d59b0efabd Merge "res_pjsip_mwi: update unsolicited MWI subscriptions on updating contact" 2017-06-22 16:01:52 -05:00
Richard Mudgett 975e271b01 res_pjsip_mwi.c: Eliminate RAII_VAR in contact delete observer
Change-Id: I0bc97c6608de1d1a4228826b3b3be43f162f05f3
2017-06-21 18:25:17 -05:00
Alexei Gradinari 34db4c3993 res_pjsip_mwi: update unsolicited MWI subscriptions on updating contact
Do not need to unsubscribe/subscribe on creating the ednpoint's contact.
The modified function create_mwi_subscriptions_for_endpoint adds
the subscription only if it does not exist.

The subscriptions aren't added for active contacts
which are retrieved on startup from realtime
if mwi_disable_initial_unsolicited=yes.
Because the mwi_contact_added is not called.
So the subscriptions also should be created on updating contact.

ASTERISK-26230 #close

Change-Id: I47e265af9296ca09aa42a316fdacac104148cee4
2017-06-21 18:24:31 -05:00
Jenkins2 db5e269365 Merge "res_corosync: Change thread stack size" 2017-06-20 18:18:19 -05:00
Richard Mudgett 3a18a09030 SDP: Rework SDP offer/answer model and update capabilities merges.
The SDP offer/answer model requires an answer to an offer before a new SDP
can be processed.  This allows our local SDP creation to be deferred until
we know that we need to create an offer or an answer SDP.  Once the local
SDP is created it won't change until the SDP negotiation is restarted.

An offer SDP in an initial SIP INVITE can receive more than one answer
SDP.  In this case, we need to merge each answer SDP with our original
offer capabilities to get the currently negotiated capabilities.  To
satisfy this requirement means that we cannot update our proposed
capabilities until the negotiations are restarted.

Local topology updates from ast_sdp_state_update_local_topology() are
merged together until the next offer SDP is created.  These accumulated
updates are then merged with the current negotiated capabilities to create
the new proposed capabilities that the offer SDP is built.

Local topology updates are merged in several passes to attempt to be smart
about how streams from the system are matched with the previously
negotiated stream slots.  To allow for T.38 support when merging, type
matching considers audio and image types to be equivalent.  First streams
are matched by stream name and type.  Then streams are matched by stream
type only.  Any remaining unmatched existing streams are declined.  Any
new active streams are either backfilled into pre-merge declined slots or
appended onto the end of the merged topology.  Any excess new streams
above the maximum supported number of streams are simply discarded.

Remote topology negotiation merges depend if the topology is an offer or
answer.  An offer remote topology negotiation dictates the stream slot
ordering and new streams can be added.  A remote offer can do anything to
the previously negotiated streams except reduce the number of stream
slots.  An answer remote topology negotiation is limited to what our offer
requested.  The answer can only decline streams, pick codecs from the
offered list, or indicate the remote's stream hold state.

I had originally kept the RTP instance if the remote offer SDP changed a
stream type between audio and video since they both use RTP.  However, I
later removed this support in favor of simply creating a new RTP instance
since the stream's purpose has to be changing anyway.  Any RTP packets
from the old stream type might cause mischief for the bridged peer.

* Added ast_sdp_state_restart_negotiations() to restart the SDP
offer/answer negotiations.  We will thus know to create a new local SDP
when it is time to create an offer or answer.

* Removed ast_sdp_state_reset().  Save the current topology before
starting T.38.  To recover from T.38 simply update the local topology to
the saved topology and restart the SDP negotiations to get the offer SDP
renegotiating the previous configuration.

* Allow initial topology for ast_sdp_state_alloc() to be NULL so an
initial remote offer SDP can dictate the streams we start with.  We can
always update the local topology later if it turns out we need to offer
SDP first because the remote chose to defer sending us a SDP.

* Made the ast_sdp_state_alloc() initial topology limit to max_streams,
limit to configured codecs, handle declined streams, and discard
unsupported types.

* Convert struct ast_sdp to ao2 object.  Needed to easily save off a
remote SDP to refer to later for various reasons such as generating
declined m= lines in the local SDP.

* Improve converting remote SDP streams to a topology including stream
state.  A stream state of AST_STREAM_STATE_REMOVED indicates the stream is
declined/dead.

* Improve merging streams to take into account the stream state.

* Added query for remote hold state.

* Added maximum streams allowed SDP config option.

* Added ability to create new streams as needed.  New streams are created
with configured default audio, video, or image codecs depending on stream
type.

* Added global locally_held state along with a per stream local hold
state.  Historically, Asterisk only has a global locally held state
because when the we put the remote on hold we do it for all active
streams.

* Added queries for a rejected offer and current SDP negotiation role.
The rejected query allows the using module to know how to respond to a
failed remote SDP set.  Should the using module respond with a 488 Not
Acceptable Here or 500 Internal Error to the offer SDP?

* Moved sdp_state_capabilities.connection_address to ast_sdp_state.  There
seems no reason to keep it in the sdp_state_capabilities struct since it
was only used by the ast_sdp_state.proposed_capabilities instance.

* Callbacks are now available to allow the using module some customization
of negotiated streams and to complete setting up streams for use.  See the
typedef doxygen for each callback for what is allowable and when they are
called.
    * Added topology answerer modify callback.
    * Added topology pre and post apply callbacks.
    * Added topology offerer modify callback.
    * Added topology offerer configure callback.

* Had to rework the unit tests because I changed how SDP topologies are
merged.  Replaced several unit tests with new negotiation tests.

Change-Id: If07fe6d79fbdce33968a9401d41d908385043a06
2017-06-20 18:15:52 -05:00
Joshua Colp 0ecf504de9 Merge "res_pjsip_mwi: unsubscribe unsolicited MWI on deleting endpoint last contact" 2017-06-20 05:47:46 -05:00
Joshua Colp 57bbba7d43 Merge "res_stasis: Plug reference leak on stolen channels" 2017-06-19 16:49:39 -05:00
Alexei Gradinari d7b6e06abb res_pjsip_mwi: unsubscribe unsolicited MWI on deleting endpoint last contact
If the endpoint's last contact is deleted unsolicited MWI has to be
unsubscribed.

ASTERISK-27051 #close

Change-Id: I33e174e0b9dba0998927d16d6d100fda5c7254e0
2017-06-16 17:54: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
Alexei Gradinari 7a46309d3d res_pjsip: New endpoint option "notify_early_inuse_ringing"
This option was added to control whether to notify dialog-info state
'early' or 'confirmed' on Ringing when already INUSE.
The value "yes" is useful for some SIP phones (Cisco SPA)
to be able to indicate and pick up ringing devices.

ASTERISK-26919 #close

Change-Id: Ie050bc30023543c7dfb4365c5be3ce58c738c711
2017-06-16 11:25:07 -05:00
Jan Friesse 9aeab4aced res_corosync: Change thread stack size
In Corosync 2.x libraries were changed to use LibQB IPC.
Sadly LibQB IPC doesn't support copy-free access to received buffer, so
Corosync libraries were rewritten to use stack as buffer. Mostly the
needed stack size is quite small, but for all *_dispatch functions, 1MiB
is needed.

Asterisk function ast_pthread_create_background set stack size for new
thread to much smaller AST_BACKGROUND_STACKSIZE (~500KiB).

This results in Asterisk crash when running with Corosync 2.x.

Patch solves this issue by creating it's own version of
ast_pthread_create_background which sets stack size to much higher value
(actually it's AST_BACKGROUND_STACKSIZE + 3MiB).

Another problem may appear when "corosync show members" netconsole
command is executed. It is also executed in thread and also has only
500KiB stack size. Sadly it calls corosync_cfg_get_node_addrs which
again needs at least 1MiB stack.

Solution is to use HAVE_COROSYNC_CFG_STATE_TRACK as a discriminator
between Corosync 1.x and 2.x. If 1.x is found, nothing changes. If 2.x
is found, NodeID is displayed instead of IP address.

ASTERISK-25370 #close
Reported by: mdu113

Change-Id: Id95b0d21ab6e708e7d74ad8786c587211676fa08
2017-06-16 07:53:22 -05:00
George Joseph 1ac0096512 res_ari: Add "module loaded" check to ari stubs
The recent change to make the use of LOAD_DECLINE more consistent
caused res_ari to unload itself before declining if the ari.conf
file wasn't found.  The ari stubs though still tried to use the
configuration resulting in segfaults.

This patch creates a new CHECK_ARI_MODULE_LOADED macro which tests
to see if res_ari is actually loaded and causes the stubs to also
decline if it isn't.  The macro was then added to the mustache
template's "load_module" function.

ASTERISK-27026 #close
Reported-by: Ronald Raikes

Change-Id: I263d56efa628ee3c411bdcd16d49af6260c6c91d
2017-06-15 19:34:03 -05:00
Jenkins2 2adc0aef19 Merge "res_pjsip_pubsub: Fix reference to released endpoint" 2017-06-15 15:24:25 -05:00
Jenkins2 2c3c862cee Merge "res_pjsip_refer/session: Calls dropped during transfer" 2017-06-15 08:12:43 -05:00
George Joseph 54a08a2e43 Merge "res_rtp_asterisk: Fix ssrc change for rtcp srtp" 2017-06-14 16:05:37 -05:00
Jenkins2 4681b9baef Merge "res_pjsip_session: Correct inverted test in session_outgoing_nat_hook" 2017-06-14 15:54:22 -05:00
Jenkins2 433e876317 Merge "res_pjsip_transport_websocket: Add NULL check in get_write_timeout" 2017-06-14 15:24:32 -05:00
George Joseph 65ed2ea311 res_pjsip_pubsub: Fix reference to released endpoint
destroy_subscription was attempting to get the id of the
subscription tree's endpoint after we'd already called ao2_cleanup
on it causing a segfault.

Moved the cleanup until after the debug statement and since
endpoint could also be NULL at this point, check for that as well.

ASTERISK-27057 #close
Reported-by: Ryan Smith

Change-Id: Ice0a7727f560cf204d870a774c6df71e159b1678
2017-06-14 11:16:54 -05:00
George Joseph ea3f8c6889 res_pjsip_session: Correct inverted test in session_outgoing_nat_hook
There was a typo introduced in commit 776ffd77 which was preventing
the transport's external media address from being used.

ASTERISK-27024 #close
Reported-by: Christopher van de Sande
patches:
	patch.diff submitted by Florian Floimair (license 6892)

Change-Id: I7ec617171eaa2d86d2680b00cf37d5088adafc27
2017-06-14 11:07:07 -05:00
George Joseph 88f18faf2a res_rtp_asterisk: Fix ssrc change for rtcp srtp
It looks like there was a copy/paste error in ast_rtp_change_source
where if there was a rtcp srtp instance, instead of updating its
ssrc we were updating the srtp instance ssrc twice.

ASTERISK-27022 #close
Reported-by: Michael Walton

Change-Id: Ic88f3aee7227b401c58745ac265ff92c19620095
2017-06-14 08:59:09 -05:00
Kevin Harwell 9e53c30610 res_pjsip_refer/session: Calls dropped during transfer
When doing an attended transfer it's possible for the transferer, after
receiving an accepted response from Asterisk, to send a BYE to Asterisk,
which can then be processed before Asterisk has time to start and/or
complete the transfer process. This of course causes the transfer to not
complete successfully, thus dropping the call.

This patch makes it so any BYEs received from the transferer, after the REFER,
that initiate a session end are deferred until the transfer is complete. This
allows the channel that would have otherwise been hung up by Asterisk to
remain available throughout the transfer process.

ASTERISK-27053 #close

Change-Id: I43586db79079457d92d71f1fd993be9a3b409d5a
2017-06-13 14:28:21 -05:00
Alexei Gradinari 42f738e052 res_pjsip_mwi: don't create mwi subscriptions if initial unsolicited disabled
If sending unsolicited mwi to all endpoints on startup is disabled
(mwi_disable_initial_unsolicited=yes) do not need to create subscriptions.
If there are many (thousands) realtime endpoints configured with unsolicited mwi
and Vociemail Storage configured as ODBC or IMAP there will be huge number of
DB/IMAP requests on startup.

ASTERISK-26230 #close

Change-Id: I50ae909639e3ee298b931a54def4b2b9e0fb86c5
2017-06-13 09:34:24 -05:00
Jørgen H 8d1f54b92e res_pjsip_transport_websocket: Add NULL check in get_write_timeout
Added check for NULL return value when calling
ast_sorcery_retrieve_by_id in function get_write_timeout

ASTERISK-27046

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

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

ASTERISK-26996

Change-Id: Ib1647f6902a0843e8c435946f831c2159e8d1d51
2017-06-07 13:34:58 +00:00
Joshua Colp 9f054955f2 Merge "res_pjsip: Add support for returning only reachable contacts and use it." 2017-06-07 08:33:53 -05:00
Sean Bright b3ca24d216 res_rtp_multicast: Use consistent timestamps when possible
When a frame destined for a MulticastRTP channel does not have timing
information (such as when an 'originate' is done), we generate the RTP
timestamps ourselves without regard to the number of samples we are
about to send.

Instead, use the same method as res_rtp_asterisk and 'predict' a
timestamp given the number of samples. If the difference between the
timestamp that we generate and the one we predict is within a specific
threshold, use the predicted timestamp so that we end up with timestamps
that are consistent with the number of samples we are actually sending.

Change-Id: I2bf0db3541b1573043330421cbb114ff0f22ec1f
2017-06-06 10:55:04 -05:00
Joshua Colp 861984eac0 res_pjsip: Add support for returning only reachable contacts and use it.
This introduces the ability for PJSIP code to specify filtering flags
when retrieving PJSIP contacts. The first flag for use causes the
query code to only retrieve contacts that are not unreachable. This
change has been leveraged by both the Dial() process and the
PJSIP_DIAL_CONTACTS dialplan function so they will now only attempt
calls to contacts which are not unreachable.

ASTERISK-26281

Change-Id: I8233b4faa21ba3db114f5a42e946e4b191446f6c
2017-06-06 09:46:39 -05:00
Jenkins2 452e6315bb Merge "format: Reintroduce smoother flags" 2017-06-06 08:59:37 -05:00
Joshua Colp 97abf6d475 Merge "res_srtp: Add support for libsrtp2" 2017-06-06 05:01:17 -05:00
Jenkins2 1dc1af4aa5 Merge "stasis_recording: Correct ast_asprintf error checking" 2017-06-01 11:06:16 -05:00
Jenkins2 48d047ad5a Merge "res_pjsip: New endpoint option "refer_blind_progress"" 2017-06-01 10:05:53 -05:00
Jenkins2 77f7c1b98f Merge "Sqlite3: make busy_timeout configurable." 2017-06-01 09:31:24 -05:00
Sean Bright 9dce4a947b stasis_recording: Correct ast_asprintf error checking
ASTERISK-27021 #close
Reported by: Tim Morgan

Change-Id: I0ac061f040093e806c3b1f4e2340864f3ce4dd75
2017-05-30 16:09:50 -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
Sean Bright 1f136fe885 res_srtp: Add support for libsrtp2
ASTERISK-25294 #close
Reported by: Tzafrir Cohen

ASTERISK-26976 #close
Reported by: Alex

Change-Id: I789b1c3d1ed31365bbd9339fa58ef36f48833c40
2017-05-26 12:15:42 -04:00
Jenkins2 56b6a71548 Merge "asterisk: Audit locking of channel when manipulating flags." 2017-05-26 09:25:51 -05:00
George Joseph 6bb3cedb1b Merge "res_agi: Prevent crash when SET VARIABLE called without arguments" 2017-05-26 07:12:16 -05:00
George Joseph 366b10a500 Merge "res_agi: Allow configuration of audio format of EAGI pipe" 2017-05-25 19:01:57 -05:00
Jenkins2 915acf1e5d Merge "res_agi: Fix malformed AGI usage response" 2017-05-25 15:23:18 -05:00
Martin Tomec 44c5a144ce Sqlite3: make busy_timeout configurable.
Enables runtime configuration of busy_timeout for sqlite databases.
Default timeout remains 1000ms.

ASTERISK-27014 #close

Change-Id: I8921a3aac3c335843be4cb17d2dd0a5c157a36da
2017-05-25 10:02:42 +02:00
Jenkins2 d6992daaef Merge "res_agi: Clarify 'RECORD FILE' documentation" 2017-05-24 18:09:33 -05:00
Jenkins2 cd0e6a2324 Merge "res_rtp_asterisk: rtcp mux using the wrong srtp unprotecting algorithm" 2017-05-24 11:25:58 -05:00
Sean Bright d847fe6585 res_agi: Allow configuration of audio format of EAGI pipe
This change allows the format of the EAGI audio pipe to be changed by
setting the dialplan variable 'EAGI_AUDIO_FORMAT' to the name of one of
the loaded formats.

ASTERISK-26124 #close

Change-Id: I7a10fad401ad2a21c68c2e7246fa357d5cee5bbd
2017-05-23 16:51:19 -04:00
Sean Bright e2e6baa8d8 res_agi: Clarify 'RECORD FILE' documentation
Documented the 'beep' option in both the parameters list and the command
description.

ASTERISK-23839 #close

Change-Id: I4970395c922dbdce3f7cf0f56d5b065ec9aa53ea
2017-05-23 13:35:26 -05:00
Sean Bright 3dcb3c88aa res_agi: Prevent crash when SET VARIABLE called without arguments
Explicitly check that the appropriate number of arguments were passed to
SET VARIABLE before attempting to reference them. Also initialize the
arguments array to zeroes before populating it.

ASTERISK-22432 #close

Change-Id: I5143607d80a2724f749c1674f3126b04ed32ea97
2017-05-23 13:08:44 -05:00
Sean Bright e490aa3176 res_agi: Fix malformed AGI usage response
If the generated XML documentation for a command does not end with a \n,
the postamble of the usage message does not appear on its own line.

ASTERISK-25662 #close

Change-Id: If190f1e9e37fe215fed95897d78d4a6e142b0020
2017-05-23 12:37:28 -05:00
Sean Bright 8ae0227cf3 res_format_attr_h26x: Trim blanks in fmtp attributes
Some devices separate format attributes with a semicolon followed by a
space, so trim blanks before trying to match them.

ASTERISK-27008 #close

Change-Id: Ia44cb2e4fef5c73dc541a29da79cb0e19c22d9cc
2017-05-23 10:57:57 -05:00
Joshua Colp dece2eb892 Merge "res_pjsip_session : fixed wrong From Header number On Re-invite" 2017-05-23 09:17:13 -05:00
Kevin Harwell 440ff38c08 res_rtp_asterisk: rtcp mux using the wrong srtp unprotecting algorithm
When using rtcp mux if an rtcp payload came in it would still use the srtp
unprotect algorithm instead of the srtp unprotect rtcp method. Since rtcp
data was being passed to the rtp unprotect method this would result in an
error.

This patch ensures that the correct unprotect method is chosen by making
sure the passed in rtcp flag is appropriately set when rtcp mux is enabled
and an rtcp payload is received.

ASTERISK-26979 #close

Change-Id: Ic5409f9d1a267f1d4785fc5aed867daaecca6241
2017-05-22 14:05:51 -05:00
Sean Bright 4141748e85 res_hep_rtcp: Add support level to module info
Change-Id: I5661478f9cf12d431f730e42be79323b62831e92
2017-05-18 16:36:21 -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
Richard Mudgett 30fbed65f1 res_pjsip_session.c: Process initial INVITE sooner. (key exists)
Retransmissions of an initial INVITE could be queued in the serializer
before we have processed the first INVITE message.  If the first INVITE
message doesn't get completely processed before the retransmissions are
seen then we could try to setup the same call from the retransmissions.  A
symptom of this is seeing a (key exists) message associated with an
INVITE.  An earlier change attempted to address this kind of problem by
calculating a distributor serializer to use for unassociated messages.
Part of that change also made incoming calls keep using that distributor
serializer.  (ASTERISK-26088) However, some leftover code was still
deferring the INVITE processing to the session's serializer even though we
were already in that serializer.  This not only is unnecessary but would
cause the same call resetup problem.

* Removed the code to defer processing the initial INVITE to the session's
serializer because we are already running in that serializer.

ASTERISK-26998 #close

Change-Id: I1e822d82dcc650e508bc2d40d545d5de4f3421f6
2017-05-15 15:12:26 -05:00
Alexei Gradinari 808f299808 res_pjsip: New endpoint option "refer_blind_progress"
This option was added to turn off notifying the progress details
on Blind Transfer. If this option is not set then the chan_pjsip
will send NOTIFY "200 OK" immediately after "202 Accepted".

Some SIP phones like Mitel/Aastra or Snom keep the line busy until
receive "200 OK".

ASTERISK-26333 #close

Change-Id: Id606fbff2e02e967c02138457badc399144720f2
2017-05-11 10:50:35 -05:00
Joshua Colp 3c36c29c81 res_hep_rtcp: Provide chan_sip Call-ID for RTCP messages.
This change adds the required logic to allow the SIP
Call-ID to be placed into the HEP RTCP traffic if the
chan_sip module is used. In cases where the option is
enabled but the channel is not either SIP or PJSIP then
the code will fallback to the channel name as done
previously.

Based on the change on Nir's branch at:
team/nirs/hep-chan-sip-support

ASTERISK-26427

Change-Id: I09ffa5f6e2fdfd99ee999650ba4e0a7aad6dc40d
2017-05-09 05:38:59 -05:00
Kevin Harwell 008e25def9 res_rtp_asterisk: Clearing the remote RTCP address causes RTCP failures
When a call gets put on hold RTP is temporarily stopped and Asterisk was
setting the remote RTCP address to NULL. Then when RTCP data was received
from the remote endpoint, Asterisk would be missing this information when
publishing the rtcp_message stasis event. Consequently, message subscribers
(in this case res_hep_rtcp) trying to parse the "from" field output the
following error:

"ast_sockaddr_split_hostport: Port missing in (null)"

This patch makes it so the remote RTCP address is no longer set to NULL when
stopping RTP. There was only one place that appeared to check if the remote
RTCP address was NULL as a way to tell if RTCP was running. This patch added
an additional check on the RTCP schedid for that case to make sure RTCP was
truly not running.

ASTERISK-26860 #close

Change-Id: I6be200fb20db647e48b5138ea4b81dfa7962974b
2017-05-03 12:29:22 -05:00
Jenkins2 dc948163ca Merge "res_pjsip_t38.c: Fix deadlock in T.38 framehook." 2017-05-02 09:22:24 -05:00
Joshua Colp d1944c1892 Merge "res_sdp_translator_pjmedia.c: Add TODO notes." 2017-05-02 05:20:03 -05:00
Joshua Colp 1d6429b269 Merge "SDP: Make SDP translation to/from internal representation more const." 2017-05-02 05:19:59 -05:00
Jenkins2 b67423c8a3 Merge "res_pjsip_outbound_authenticator_digest: Add context to log messages" 2017-05-01 15:08:21 -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 52e4f02b1a res_pjsip_t38.c: Fix deadlock in T.38 framehook.
A deadlock can happen between a channel lock and a pjsip session media
container lock.  One thread is processing a reINVITE's SDP and walking
through the session's media container when it waits for the channel lock
to put the determined format capabilities onto the channel.  The other
thread is writing a frame to the channel and processing the T.38 frame
hook.  The T.38 frame hook then waits for the pjsip session's media
container lock.  The two threads are now deadlocked.

* Made the T.38 frame hook release the channel lock before searching the
session's media container.  This fix has been done to several other
frame hooks to fix deadlocks.

ASTERISK-26974 #close

Change-Id: Ie984a76ce00bef6ec9aa239010e51e8dd74c8186
2017-04-29 18:15:32 -05:00
George Joseph 8170793be6 res_pjsip_outbound_authenticator_digest: Add context to log messages
There was no context info in this module's log messages so it was
impossible to toubleshoot.

Added endpoint or host to all messages and added the realms in the
challenge for the "No auth credentials for any realm" message.

Change-Id: Ifeed2786f35fbea7d141237ae15625e472acff9b
2017-04-28 11:04:57 -05:00
Richard Mudgett 48566b8c66 res_sdp_translator_pjmedia.c: Add TODO notes.
Change-Id: If27ca61f79accc882c3376d2e876d2b44aa1347b
2017-04-27 19:08:05 -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 176123e76c SDP: Misc cleanups (Mostly memory leaks)
Change-Id: I74431b385da333f2c5f5a6d7c55e70b69a4f05d2
2017-04-27 19:08:05 -05:00
Jenkins2 066659a383 Merge "res_pjsip_session: Add cleanup to ast_sip_session_terminate" 2017-04-27 17:14:48 -05:00
Jenkins2 175297fe34 Merge "res_pjsip/res_pjsip_callerid: NULL check on caller id name string" 2017-04-27 16:47:34 -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
George Joseph d6b2a58736 res_pjsip_session: Add cleanup to ast_sip_session_terminate
If you use ast_request to create a PJSIP channel but then hang it
up without causing a transaction to be sent, the session will
never be destroyed.  This is due ot the fact that it's pjproject
that triggers the session cleanup when the transaction ends.
app_chanisavail was doing this to get more granular channel state
and it's also possible for this to happen via ARI.

* ast_sip_session_terminate was modified to explicitly call the
  cleanup tasks and unreference session if the invite state is NULL
  AND invite_tsx is NULL (meaning we never sent a transaction).

* chan_pjsip/hangup was modified to bump session before it calls
  ast_sip_session_terminate to insure that session stays valid
  while it does its own cleanup.

* Added test events to session_destructor for a future testsuite
  test.

ASTERISK-26908 #close
Reported-by: Richard Mudgett

Change-Id: I52daf6f757184e5544c261f64f6fe9602c4680a9
2017-04-27 10:43:32 -05:00
Jenkins2 54e27cad3c Merge "res_rtp_asterisk.c: Fix crash in RTCP DTLS operation." 2017-04-27 10:05:16 -05:00
Kevin Harwell c6b757fa05 res_pjsip/res_pjsip_callerid: NULL check on caller id name string
It's possible for a name in a party id structure to be marked as valid, but the
name string itself be NULL (for instance this is possible to do by using the
dialplan CALLERID function). There were a couple of places where the name was
validated, but the string itself was not checked before passing it to functions
like 'strlen'. This of course caused a crashed.

This patch adds in a NULL check before attempting to pass it into a function
that is not NULL tolerant.

ASTERISK-25823 #close

Change-Id: Iaa6ffe9d92f598fe9e3c8ae373fadbe3dfbf1d4a
2017-04-26 15:32:11 -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
Yasin CANER 99dea9ba84 res_pjsip_session : fixed wrong From Header number On Re-invite
ASTERISK-26964 #close

Change-Id: I55a9caa7dc90e6c4c219cb09b5c2ec08af84a302
2017-04-26 17:29:52 +03:00
Jenkins2 5a987fc5e9 Merge "res_pjsip_session.c: Send 100 Trying out earlier to prevent retransmissions." 2017-04-25 17:04:47 -05:00
George Joseph a3a77890dc Merge "res_hep: Add additional config initialization and validation" 2017-04-25 16:39:04 -05:00
George Joseph 8df729517e Merge "res_pjsip_session.c: Restructure ast_sip_session_alloc()" 2017-04-25 15:37:15 -05:00
Sean Bright 0611f2ca17 res_hep: Add additional config initialization and validation
* Initialize hepv3_runtime_data.sockfd to -1 so that our ao2 destructor
  does not close fd 0

* Add logging output when the required option - capture_address - is not
  specified.

* Remove a no longer relevant #define and correct related documentation

* Pass appropriate flags to aco_option_register so that capture_address
  cannot be the empty string.

ASTERISK-26953 #close

Change-Id: Ief08441bc6596d6f1718fa810e54a5048124f076
2017-04-24 13:22:48 -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 f1d20c84a1 res_pjsip_session.c: Send 100 Trying out earlier to prevent retransmissions.
If ICE is enabled and a STUN server does not respond then we will block
until we give up on the STUN response.  This will take nine seconds.  In
the mean time the peer that sent the INVITE will send retransmissions.

* Restructure res_pjsip_session.c:new_invite() to send a 100 Trying out
earlier to prevent these retransmissions.

ASTERISK-26890

Change-Id: Ie3fc611e53a0eff6586ad55e4aacad81cf6319a8
2017-04-21 14:17:55 -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 dd239e9f91 Merge "res_stun_monitor: Don't fail to load if DNS resolution fails" 2017-04-20 07:19:46 -05:00
Richard Mudgett afad2ffd9f res_rtp_asterisk.c: Fix crash in RTCP DTLS operation.
Occasionally a crash happens when processing the RTCP DTLS timeout
handler.  The RTCP DTLS timeout timer could be left running if we have not
completed the DTLS handshake before we place the call on hold or we
attempt direct media.

* Made ast_rtp_prop_set() stop the RTCP DTLS timer when disabling RTCP.

* Made some sanity tweaks to ast_rtp_prop_set() when switching from
standard RTCP mode to RTCP multiplexed mode.

ASTERISK-26692 #close

Change-Id: If6c64c79129961acfa4b3d63a864e8f6b664acc0
2017-04-19 13:40:57 -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
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 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
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 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
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 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
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
zuul d2e6eb2afe Merge "Unused realtime MOH classes not purged on 'moh reload'" 2017-04-05 19:14:28 -05:00
zuul a385db5333 Merge "res_pjsip_session: Allow BYE to be sent on disconnected session." 2017-04-05 19:04:25 -05:00
Richard Mudgett f2ee8ac21e 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 13:38:07 -05:00
Daniel Journo 6c3ae397cb Unused realtime MOH classes not purged on 'moh reload'
Purge Realtime MOH classes on 'moh reload' even when musiconhold.conf
hasn't changed.

ASTERISK-25974 #close

Change-Id: I42c78ea76528473a656f204595956c9eedcf3246
2017-04-03 17:43:50 -05:00
Richard Mudgett a889621b14 res_pjsip: Fix transport ref leak.
We were leaking a transport ref in multihomed_on_rx_message() which
resulted in the FRACK about excessive ref counts.

ASTERISK-26916 #close

Change-Id: I7a96658a9614a060565bb9ad51cb1c9c11ee145f
2017-04-03 14:03:24 -05:00
Joshua Colp 48be02c5d8 res_pjsip_session: Allow BYE to be sent on disconnected session.
It is perfectly acceptable for a BYE to be sent on a disconnected
session. This occurs when we respond to a challenge to the BYE
for authentication credentials.

ASTERISK-26363

Change-Id: I6ef0ddece812fea6665a1dd2549ef44fb9d90045
2017-04-01 06:02:04 -05:00
zuul 7898aad02d Merge "res_pjsip_config_wizard: Add 2 new parameters to help with proxy config" 2017-03-30 17:02:38 -05:00
Joshua Colp 7581bb4f5f Merge "srtp: Allow zero as tag value for a sRTP Crypto Suite." 2017-03-29 17:49:55 -05:00
zuul 410a5ac0fa Merge "Add DTLS sanity check." 2017-03-29 16:11:12 -05:00
zuul 5a530171ca Merge "res_musiconhold: Don't chdir() when scanning MoH files" 2017-03-29 10:11:01 -05:00
Alexander Traud e76cc51d5e srtp: Allow zero as tag value for a sRTP Crypto Suite.
ASTERISK-25490 #close

Change-Id: I1c5fc0942c33c96d62b24203aad0f1e1a1a0131f
2017-03-29 15:04:05 +02:00
Joshua Colp f43cfb81d9 Merge "res_xmpp: Fix ref counting issue" 2017-03-29 06:57:49 -05:00
George Joseph 2fe52174de res_pjsip_config_wizard: Add 2 new parameters to help with proxy config
Two new parameters have been added to the pjsip config wizard.

 * Setting 'sends_line_with_registrations' to true will cause the wizard
   to skip the creation of an identify object to match incoming request
   to the endpoint and instead add the line and endpoint parameters to
   the outbound registration object.

 * Setting 'outbound_proxy' is a shortcut for adding individual
   endpoint/outbound_proxy, aor/outbound_proxy and
   registration/outbound_proxy parameters.

Change-Id: I678e5f80765734c056620528a6d40d82736ceeb0
(cherry picked from commit a827892ff7)
(cherry picked from commit 27344675be)
2017-03-28 15:51:21 -06:00
Joshua Colp d0ada2246e Merge "res_xmpp: Use incremental backoff when a read error occurs" 2017-03-28 16:46:52 -05:00
Richard Mudgett 3d8899bacf Add DTLS sanity check.
Change-Id: Ib32612cf6c7ce9213a11b9cba82f630f8cd3564b
2017-03-27 15:43:03 -06:00
Sean Bright d22c678999 res_musiconhold: Don't chdir() when scanning MoH files
There doesn't appear to be any reason that we are chdir'ing in
moh_scan_files, and in the event of an Asterisk crash, the core files
may not get written because we have changed into a read-only directory.

ASTERISK-23996 #close
Reported by: Walter Doekes

Change-Id: Iac806dce01b3335963fbd62d4b4da9a65c614354
2017-03-27 08:00:57 -06:00
Joshua Colp 3bdf876b04 Merge "res_pjsip_sdp_rtp: Set hangup cause for RTP timeouts" 2017-03-25 05:20:03 -05:00
Sean Bright d5a8799c4b res_xmpp: Use incremental backoff when a read error occurs
If a read error occurs, we immediately attempt a reconnect without any
delay. Instead, let's sleep and backoff up to 60 seconds before we try
again.

ASTERISK-24712 #close
Reported by: Matthias Urlichs

Change-Id: I6fe10ef4734837727437beab715e336777f13f48
2017-03-24 15:11:39 -06:00
zuul f27c1c7dc2 Merge "res_xmpp: Correct implementation of JABBER_STATUS & JabberStatus" 2017-03-24 12:25:07 -05:00
zuul 8982d0e007 Merge "res_xmpp: Include client name in connection related error messages" 2017-03-24 11:55:38 -05:00
Sean Bright d08c69a9e2 res_pjsip_sdp_rtp: Set hangup cause for RTP timeouts
chan_sip sets the hangup cause code to AST_CAUSE_REQUESTED_CHAN_UNAVAIL
(44) when a channel is hung up due to an RTP timeout. So do the same
when it happens with PJSIP for parity.

Change-Id: I3546ebbde6460c22a27c9da1bf321711b5961ab8
2017-03-24 10:31:39 -06:00
Joshua Colp 6666deb907 Merge "res_xmpp: Don't crash when trying to send a message without a connection" 2017-03-24 10:46:34 -05:00
zuul 1a626ffb89 Merge "res_xmpp: Correctly check return value of SSL_connect" 2017-03-24 09:13:06 -05:00
Sean Bright 98a88e9ffa res_xmpp: Correct implementation of JABBER_STATUS & JabberStatus
The documentation for JABBER_STATUS (and the deprecated JabberStatus
app) indicate that a return value of 7 indicates that the specified
buddy was not in the roster. It also indicates that you can specify a
"bare" JID (one without a resource). Unfortunately the actual behavior
does not match the documented behavior.

Assuming that our roster includes the buddy online and available
"valid@example.org/Valid" and does *not* include the buddy
"invalid@example.org", the JABBER_STATUS() function returns the
following before this patch:

+------------------------------+------------+--------------------------+
| Buddy                        | Status     | Result                   |
+------------------------------+------------+--------------------------+
| valid@example.org            |  Online    |  7 (Not in roster)       |
| valid@example.org/Valid      |  Online    |  1 (Online)              |
| valid@example.org/Invalid    |  N/A       |  7 (Not in roster)       |
| invalid@example.org          |  N/A       |  Error logged, no return |
| invalid@example.org/Valid    |  N/A       |  Error logged, no return |
+------------------------------+------------+--------------------------+

And after this patch:

+------------------------------+------------+--------------------------+
| Buddy                        | Status     | Result                   |
+------------------------------+------------+--------------------------+
| valid@example.org            |  Online    |  1 (Online)              |
| valid@example.org/Valid      |  Online    |  1 (Online)              |
| valid@example.org/Invalid    |  N/A       |  6 (Offline)             |
| invalid@example.org          |  N/A       |  7 (Not in roster)       |
| invalid@example.org/Valid    |  N/A       |  7 (Not in roster)       |
+------------------------------+------------+--------------------------+

This brings the behavior in line with the documentation.

ASTERISK-23510 #close
Reported by: Anthony Critelli

Change-Id: I9c3241035363ef4a6bdc21fabfd8ffcd9ec657bf
2017-03-23 09:45:49 -06:00
Sean Bright be94105d6d res_xmpp: Try to provide useful errors messages from OpenSSL
If any errors occur during the TLS connection setup, we currently dump a
fairly generic error message. So instead we try to pull in something
useful from OpenSSL to report instead.

ASTERISK-24712
Reported by: Matthias Urlichs

Change-Id: I288500991a9681f447d92913b11fedaf426087f4
2017-03-23 08:58:53 -06:00
Sean Bright ee81ee1f14 res_xmpp: Fix ref counting issue
The only remaining reference to the endpoint is in the endpoints
container, and because it is unlinked in ast_endpoint_shutdown, we don't
have to explicitly cleanup the endpoint ourselves.

Change-Id: I912a2692e52d3e2ed445b32d8ae3f9004bc2f2e8
2017-03-23 08:58:29 -06:00
Sean Bright 9493981419 res_xmpp: Correctly check return value of SSL_connect
SSL_connect returns non-zero for both success and some error conditions
so simply negating is inadequate.

Change-Id: Ifbf882896e598703b6c615407fa456d3199f95b1
2017-03-23 08:58:05 -06:00
Sean Bright 7657c279b5 res_xmpp: Don't crash when trying to send a message without a connection
If we never establish a connection to our Jabber server, iksemel never sets up
its internal transport pointer, so attempting to send a message dereferences a
NULL pointer and causes a crash.

ASTERISK-21855 #close
Reported by: Jeremy Kister

Change-Id: I204a568894e4a53ab929783ecc594a000f04d79c
2017-03-23 08:57:11 -06:00
Sean Bright 0136ec12a3 res_xmpp: Include client name in connection related error messages
ASTERISK-25622 #close
Reported by: Sean Darcy

Change-Id: I8472cb7bfb58d411a3cfbd482da98cae2d94d1e9
2017-03-23 08:56:47 -06:00
Joshua Colp c1ab8ca74c Merge "res_pjsip_session: Enable RFC3578 overlap dialing support." 2017-03-22 17:08:08 -05:00
zuul 06c9966608 Merge "res_pjsip_messaging: Check URI type before dereferencing" 2017-03-22 12:36:43 -05:00
Richard Begg 6b7697ed48 res_pjsip_session: Enable RFC3578 overlap dialing support.
Support for RFC3578 overlap dialling (i.e. 484 Response to partially matched
destinations) as currently provided by chan_sip is missing from res_pjsip.
This patch adds a new endpoint attribute (allow_overlap) [defaults to yes]
which when set to yes enables 484 responses to partial destination
matches rather than the current 404.

ASTERISK-26864

Change-Id: Iea444da3ee7c7d4f1fde1d01d138a3d7b0fe40f6
2017-03-22 11:26:48 +00:00
Sean Bright d4fcf196a2 res_hep: Capture actual transport type in use
Rather than hard-coding UDP, allow consumers of the HEP API to specify
which protocol is in use. Update the PJSIP provider to pass in the
current protocol type.

ASTERISK-26850 #close

Change-Id: I54bbb0a001cfe4c6a87ad4b6f2014af233349978
2017-03-21 13:40:29 -06: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
Joshua Colp f5603cb1ec Merge "res/res_pjsip_session: Only check localnet if it is defined" 2017-03-20 14:39:20 -05:00
Sean Bright 516e028b44 res_rtp_asterisk: Pass correct data length to ast_rtcp_interpret
We are currently passing in the capacity of the read buffer instead of the
number of bytes that we actually read off the wire.

Change-Id: I60465049727d955c7f9a5e529e6f2aaff04cda36
2017-03-19 12:29:38 -06:00
Joshua Colp 77582634d7 Merge "res_rtp_asterisk: Fix crash when RTCP is not present when DTLS is stopped." 2017-03-18 05:37:29 -05:00
Joshua Colp 0db211dc64 Merge "res_pjsip_asterisk.c: Fix compile error if libsrtp is not installed." 2017-03-18 05:36:34 -05:00
Joshua Colp 7f87cd7b4e Merge "res_pjsip_sdp_rtp.c: Fix cut-n-paste error" 2017-03-17 14:45:05 -05:00
Joshua Colp 15c72b3239 Merge "res_pjsip_sdp_rtp: RTP instance does not use same IP as explicit transport" 2017-03-17 11:47:36 -05:00
Richard Mudgett 82982a191c res_pjsip_asterisk.c: Fix compile error if libsrtp is not installed.
struct ast_rtcp does not define the dtls member if SRTP is not enabled.

ASTERISK-26732

Change-Id: Id15ea212e04490e012f2cf4a56818b4dd948875e
2017-03-16 15:44:24 -06:00
Joshua Colp 732367e806 Merge "res_pjsip: Symmetric transports" 2017-03-16 16:04:43 -05:00
Richard Mudgett 49b1f1ca16 res_pjsip_sdp_rtp.c: Fix cut-n-paste error
We were inadvertenly referencing the cos_video option to determine if we
should set the tos_audio and cos_audio value on the RTP instance.

Change-Id: Ia7964f486801d39dc6f5dae570baff079e1595b0
2017-03-16 14:49:24 -06:00
Matt Jordan e6dc28b78f res/res_pjsip_session: Only check localnet if it is defined
If local_net is not defined on a transport, transport_state->localnet
will be NULL. ast_apply_ha will, be default, return AST_SENSE_ALLOW in
this case, causing the external_media_address, if set, to be skipped.

This patch causes us to only check if we are sending within a network if
local_net is defined.

ASTERISK-26879 #close

Change-Id: Ib661c31a954cabc9c99f1f25c9c9a5c5b82cbbfb
2017-03-16 14:03:43 -06:00
Joshua Colp 76e64f5589 Merge "RFC sdp: Initial SDP creation" 2017-03-16 14:45:20 -05:00
Richard Begg 44568fc712 res_pjsip_sdp_rtp: RTP instance does not use same IP as explicit transport
Currently a wildcard address is used for the local RTP socket, which
will not always result in the same address as used by the SIP socket
(e.g. if explicit transport addresses are configured).
Use the transport's host address when binding new local RTP sockets if
available.

ASTERISK-26851

Change-Id: I098c29c9d1f79a4f970d72ba894874ac75954f1a
2017-03-16 13:14:58 -06:00
George Joseph 5013d8f5d3 res_pjsip: Symmetric transports
A new transport parameter 'symmetric_transport' has been added.

When a request from a dynamic contact comes in on a transport with
this option set to 'yes', the transport name will be saved and used
for subsequent outgoing requests like OPTIONS, NOTIFY and INVITE.
It's saved as a contact uri parameter named 'x-ast-txp' and will
display with the contact uri in CLI, AMI, and ARI output.  On the
outgoing request, if a transport wasn't explicitly set on the
endpoint AND the request URI is not a hostname, the saved transport
will be used and the 'x-ast-txp' parameter stripped from the
outgoing packet.

* config_transport was modified to accept and store the new parameter.

* config_transport/transport_apply was updated to store the transport
  name in the pjsip_transport->info field using the pjsip_transport->pool
  on UDP transports.

* A 'multihomed_on_rx_message' function was added to
  pjsip_message_ip_updater that, for incoming requests, retrieves the
  transport name from pjsip_transport->info and retrieves the transport.
  If transport->symmetric_transport is set, an 'x-ast-txp' uri parameter
  containing the transport name is added to the incoming Contact header.

* An 'ast_sip_get_transport_name' function was added to res_pjsip.
  It takes an ast_sip_endpoint and a pjsip_sip_uri and returns a
  transport name if endpoint->transport is set or if there's an
  'x-ast-txp' parameter on the uri and the uri host is an ipv4 or
  ipv6 address.  Otherwise it returns NULL.

* An 'ast_sip_dlg_set_transport' function was added to res_pjsip
  which takes an ast_sip_endpoint, a pjsip_dialog, and an optional
  pjsip_tpselector.  It calls ast_sip_get_transport_name() and if
  a non-NULL is returned, sets the selector and sets the transport
  on the dialog.  If a selector was passed in, it's updated.

* res_pjsip/ast_sip_create_dialog_uac and ast_sip_create_dialog_uas
  were modified to call ast_sip_dlg_set_transport() instead of their
  original logic.

* res_pjsip/create_out_of_dialog_request was modified to call
  ast_sip_get_transport_name() and pjsip_tx_data_set_transport()
  instead of its original logic.

* Existing transport logic was removed from endpt_send_request
  since that can only be called after a create_out_of_dialog_request.

* res_pjsip/ast_sip_create_rdata was converted to a wrapper around
  a new 'ast_sip_create_rdata_with_contact' function which allows
  a contact_uri to be specified in addition to the existing
  parameters.  (See below)

* res_pjsip_pubsub/internal_pjsip_evsub_send_request was eliminated
  since all it did was transport selection and that is now done in
  ast_sip_create_dialog_uac and ast_sip_create_dialog_uas.

* 'contact_uri' was added to subscription_persistence.  This was
  necessary because although the parsed rdata contact header has the
  x-ast-txp parameter added (if appropriate),
  subscription_persistence_update stores the raw packet which
  doesn't have it.  subscription_persistence_recreate was then
  updated to call ast_sip_create_rdata_with_contact with the
  persisted contact_uri so the recreated subscription has the
  correct transport info to send the NOTIFYs.

* res_pjsip_session/internal_pjsip_inv_send_msg was eliminated since
  all it did was transport selection and that is now done in
  ast_sip_create_dialog_uac.

* pjsip_message_ip_updater/multihomed_on_tx_message was updated
  to remove all traces of the x-ast-txp parameter from the
  outgoing headers.

NOTE:  This change does NOT modify the behavior of permanent
contacts specified on an aor.  To do so would require that the
permanent contact's contact uri be updated with the x-ast-txp
parameter and the aor sorcery object updated.  If we need to
persue this, we need to think about cloning permanent contacts into
the same store as the dynamic ones on an aor load so they can be
updated without disturbing the originally configured value.

You CAN add the x-ast-txp parameter to a permanent contact's uri
but it would be much simpler to just set endpoint->transport.

Change-Id: I4ee1f51473da32ca54b877cd158523efcef9655f
2017-03-16 09:49:07 -06:00
Joshua Colp 68749a9fa7 res_rtp_asterisk: Fix crash when RTCP is not present when DTLS is stopped.
This change removes an assumption that when DTLS is stopped
an RTCP session will be present on the RTP session. This is not
always the case.

ASTERISK-26732

Change-Id: Ib9f7c09ce0b005efe362dbcc8795202b18f94611
2017-03-16 09:47:37 -06:00
Joshua Colp 84f0871cba Merge "Add rtcp-mux support" 2017-03-16 10:46:01 -05:00
zuul 5fdd61b556 Merge "res/res_pjsip_refer: call xfer w/o extension" 2017-03-15 23:03:52 -05:00
Mark Michelson 10fa49e327 Add rtcp-mux support
This commit adds support for RFC 5761: Multiplexing RTP Data and Control
Packets on a Single Port. Specifically, it enables the feature when
using chan_pjsip.

A new option, "rtcp_mux" has been added to endpoint configuration in
pjsip.conf. If set, then Asterisk will attempt to use rtcp-mux with
whatever it communicates with. Asterisk follows the rules set forth in
RFC 5761 with regards to falling back to standard RTCP behavior if the
far end does not indicate support for rtcp-mux.

The lion's share of the changes in this commit are in
res_rtp_asterisk.c. This is because it was pretty much hard wired to
have an RTP and an RTCP transport. The strategy used here is that when
rtcp-mux is enabled, the current RTCP transport and its trappings (such
as DTLS SSL session) are freed, and the RTCP session instead just
mooches off the RTP session. This leads to a lot of specialized if
statements throughout.

ASTERISK-26732 #close
Reported by Dan Jenkins

Change-Id: If46a93ba1282418d2803e3fd7869374da8b77ab5
2017-03-15 16:34:13 -05:00
Torrey Searle dc4cdafd42 res/res_pjsip_refer: call xfer w/o extension
When transfering to a URI without an extension, ensure that the
s extension of the dialplan is entered

ASTERISK-26869 #close

Change-Id: I07403df66cf93f09e00a40ab5b41bfc6f72b1525
2017-03-15 10:29:16 -06:00
Joshua Colp 0b8a57af6d res_pjsip_endpoint_identifier_ip: Don't output error if no header_match.
This change ensures that if no header_match option is set on an
identify an error message is not output stating the option is set
to an invalid value.

ASTERISK-26863

Change-Id: I239bc6d2319dd3da24ba96a38d4d6e9b5526d62a
2017-03-15 13:52:15 +00:00
Matt Jordan 1475604eff res_pjsip_endpoint_identifier_ip: Add an option to match requests by header
This patch adds a new features to the endpoint identifier module,
'match_header'. When set, inbound requests are matched by a provided SIP
header: value pair. This option works in conjunction with the existing
'match' configuration option, such that if any 'match*' attribute
matches an inbound request, the request is associated with the specified
endpoint.

Since this module now identifies by more than just IP address,
appropriate renaming of the module and/or variables can be done in a
non-release branch.

ASTERISK-26863 #close

Change-Id: Icfc14835c962f92e35e67bbdb235cf0589de5453
(cherry picked from commit 30f52d79d7)
2017-03-15 07:51:35 -06:00
George Joseph 71cc3fd969 Merge "res_pjsip_endpoint_identifier_ip: Clean up a spaces/tabs issue" 2017-03-15 08:47:36 -05:00
zuul c152329932 Merge "res_pjsip_transport_websocket: Add support for IPv6." 2017-03-14 21:22:26 -05: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 2d7e68c075 res_pjsip_endpoint_identifier_ip: Clean up a spaces/tabs issue
Tabs > spaces. Always.

Change-Id: I899ff662361c7ab0327173bd7851a67b53dd65f1
2017-03-14 07:00:02 -06:00
Daniel Journo b14724adb3 res_musiconhold: moh general section is a class and issues warning
* res_musiconhold.c: Ensure the general section is not treated as
a moh class.

ASTERISK-26353 #close

Change-Id: Ia3dbd11ea2b43ab3e6c820a9827811dd24bea82d
2017-03-09 10:36:35 -06:00
Joshua Colp 4e3b0cedba res_pjsip_transport_websocket: Add support for IPv6.
This change adds a PJSIP patch (which has been contributed upstream)
to allow the registration of IPv6 transport types.

Using this the res_pjsip_transport_websocket module now registers
an IPv6 Websocket transport and uses it for the corresponding
traffic.

ASTERISK-26685

Change-Id: Id1f9126f995b31dc38db8fdb58afd289b4ad1647
2017-03-08 15:09:59 -06:00
Mark Michelson 5d0371d743 res_http_websocket: Fix faulty read logic.
When doing some WebRTC testing, I found that the websocket would
disconnect whenever I attempted to place a call into Asterisk. After
looking into it, I pinpointed the problem to be due to the iostreams
change being merged in.

Under certain circumstances, a call to ast_iostream_read() can return a
negative value. However, in this circumstance, the websocket code was
treating this negative return as if it were a partial read from the
websocket. The expected length would get adjusted by this negative
value, resulting in the expected length being too large.

This patch simply adds an if check to be sure that we are only updating
the expected length of a read when the return from a read is positive.

ASTERISK-26842 #close
Reported by Mark Michelson

Change-Id: Ib4423239828a013d27d7bc477d317d2f02db61ab
2017-03-07 13:38:17 -06:00
Joshua Colp e9b2360d17 Merge "res_pjsip WebRTC/websockets: Fix usage of WS vs WSS." 2017-03-01 17:24:43 -06:00
Jørgen H 7922f26cb0 res_pjsip WebRTC/websockets: Fix usage of WS vs WSS.
According to the RFC[1] WSS should only be used in the Via header
for secure Websockets.

* Use WSS in Via for secure transport.

* Only register one transport with the WS name because it would be
ambiguous.  Outgoing requests may try to find the transport by name and
pjproject only finds the first one registered.  This may mess up unsecure
websockets but the impact should be minimal.  Firefox and Chrome do not
support anything other than secure websockets anymore.

* Added and updated some debug messages concerning websockets.

* security_events.c: Relax case restriction when determining security
transport type.

* The res_pjsip_nat module has been updated to not touch the transport
on Websocket originating messages.

[1] https://tools.ietf.org/html/rfc7118

ASTERISK-26796 #close

Change-Id: Ie3a0fb1a41101a4c1e49d875a8aa87b189e7ab12
2017-03-01 09:53:18 -06:00
Sean Bright 1dacf317f3 res_config_pgsql: Make 'require' return consistent with other backends
res_config_pgsql should match the behavior of other realtime backend
drivers so that queue_log can disable adaptive logging.

ASTERISK-25628 #close
Reported by: Dmitry Wagin

Change-Id: Ic1fb1600c7ce10fdfb1bcdc43c5576b7e0014372
2017-03-01 07:27:50 -06:00
Joshua Colp 10d12b277c Merge "res_config_pgsql: Release table locks where appropriate" 2017-02-28 19:37:36 -06:00
Joshua Colp 063af910eb Merge "res_pjsip_outbound_registration: Subscribe to network change events" 2017-02-28 19:25:04 -06:00
Joshua Colp 5e5aff04ec Merge "res_pjsip_pubsub: Remove unneeded endpoint unref" 2017-02-28 17:32:25 -06:00
Joshua Colp 0986998f2f Merge "config: Improve documentation and behavior of outbound_proxy option." 2017-02-28 14:44:29 -06:00
Joshua Colp 9c714b03f9 Merge "res_pjsip: Fix crash when contact has no status" 2017-02-28 10:24:45 -06:00
Sean Bright e5b44c26b4 res_config_pgsql: Release table locks where appropriate
The find_table() functions NULL or a locked table pointer. We are
not consistently calling release_table() in failure paths.

Change-Id: I6f665b455799c84b036e5b34904b82b05eab9544
2017-02-28 09:44:09 -06:00
George Joseph fb68db87b1 res_pjsip_pubsub: Remove unneeded endpoint unref
When a subscription was being recreated and the endpoint wasn't
found, we were trying to unref the endpoint.  This was causing
FRACKs.  Removed the unref.

ASTERISK-26823 #close

Change-Id: If86d2aecff8fe853c7f38a1bfde721fcef3cd164
2017-02-27 20:09:36 -06:00
Jørgen H ee0a123f43 res_pjsip: Fix crash when contact has no status
This change fixes an assumption in res_pjsip that a contact will
always have a status. There is a race condition where this is
not true and would crash. The status will now be unknown when
this situation occurs.

ASTERISK-26623 #close

Change-Id: Id52d3ca4d788562d236da49990a319118f8d22b5
2017-02-27 15:16:57 -06:00
George Joseph 22242fef5d res_pjsip_outbound_registration: Subscribe to network change events
Outbound registration now subscribes to network change events
published by res_stun_monitor and refreshes all registrations
when an event happens.

The 'pjsip send (un)register' CLI commands were updated to accept
'*all' as an argument to operate on all registrations.

The 'PJSIP(Un)Register' AMI commands were also updated to
accept '*all'.

ASTERISK-26808 #close

Change-Id: Iad58a9e0aa5d340477fca200bf293187a6ca5a25
2017-02-27 15:10:48 -06:00
Joshua Colp 2046743938 config: Improve documentation and behavior of outbound_proxy option.
This change updates the documentation for the outbound_proxy option
to ensure it is consistently stated that a full SIP URI must be
provided for the option.

The res_pjsip_outbound_registration module has also been changed so
that the provided outbound_proxy value is checked to ensure it is a
URI and if not an error is output stating so.

ASTERISK-26782

Change-Id: I6c239a32274846fd44e65b44ad9bf6373479b593
2017-02-24 14:05:17 -06:00
Joshua Colp e4ba07f1a6 Merge "pjproject_bundled: Update for pjproject 2.6" 2017-02-24 12:49:07 -06:00
George Joseph a537dae6d0 pjproject_bundled: Update for pjproject 2.6
* Removed all 2.5.5 functional patches.
 * Updated usages of pj_release_pool to be "safe".
 * Updated configure options to disable webrtc.
 * Updated config_site.h to disable webrtc in pjmedia.
 * Added Richard Mudgett's recent resolver patches.

Change-Id: Ib400cc4dfca68b3d07ce14d314e829bfddc252c7
2017-02-23 16:23:53 -06:00
Sean Bright 0f4b349d37 res_config_pgsql: Fix thread safety problems
* A missing AST_LIST_UNLOCK() in find_table()

* The ESCAPE_STRING() macro uses pgsqlConn under the hood and we were
  not consistently locking before calling it.

* There were a handful of other places where pgsqlConn was accessed
  directly without appropriate locking.

Change-Id: Iea63f0728f76985a01e95b9912c3c5c6065836ed
2017-02-23 14:56:53 -06:00
Sean Bright e57961db84 res_config_ldap: Various code improvements
The initial motivation for this patch was to properly handle memory
allocation failures - we weren't checking the return values from the
various LDAP library allocation functions.

In the process, because update_ldap() and update2_ldap() were
substantially the same code, they've been consolidated.

Change-Id: Iebcfe404177cc6860ee5087976fe97812221b822
2017-02-22 17:37:52 -06:00
Joshua Colp 8f248f7a1c Merge "realtime: Centralize some common realtime backend code" 2017-02-22 05:53:50 -06:00
zuul 911252d7b5 Merge "res_pjsip_authenticator_digest.c: Fix sorcery's immutable contract violation." 2017-02-21 23:13:44 -06:00
zuul 1774f778f6 Merge "res_pjsip: Update artificial auth whenever default_realm changes." 2017-02-21 22:55:13 -06:00
zuul ac6e0fdcdb Merge "res_pjsip: Update authentication realm documentation." 2017-02-21 22:39:09 -06:00
zuul 26d1bd2490 Merge "pjsip_distributor.c: Update some debug messages to get transaction name." 2017-02-21 20:01:08 -06:00
zuul d90047fec3 Merge "res_config_ldap: Don't try to delete non-existent attributes" 2017-02-21 18:58:28 -06:00
zuul fa7803e697 Merge "res_config_ldap: Remove extraneous line numbers from log messages" 2017-02-21 18:58:27 -06:00
zuul 66e3edada9 Merge "res_config_ldap: Make memory allocation more consistent" 2017-02-21 18:58:26 -06:00
zuul da2ba22248 Merge "res_config_ldap: Fix configuration inheritance from _general" 2017-02-21 18:24:05 -06:00
zuul d5e25d8e3d Merge "res_config_ldap: Fix erroneous LDAP_MOD_REPLACE in LDAP modify" 2017-02-21 17:57:24 -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
Sean Bright 6e6c96d713 realtime: Centralize some common realtime backend code
All of the realtime backends create artificial ast_categorys to pass
back into the core as query results. These categories have no filename
or line number information associated with them and the backends differ
slightly on how they create them. So create a couple helper macros to
help make things more consistent.

Also updated the call sites to remove redundant error messages about
memory allocation failure.

Note that res_config_ldap sets the category filename to the 'table name'
but that is not read by anything in the core, so I've dropped it.

Change-Id: I3a1fd91e0c807dea1ce3b643b0a6fe5be9002897
2017-02-21 10:53:17 -06:00
zuul 144b09ab41 Merge "realtime: Fix LIKE escaping in SQL backends" 2017-02-21 06:26:30 -06:00