Commit Graph

71 Commits

Author SHA1 Message Date
Philip Prindeville 287a1a9126 time: add support for time64 libcs
Treat time_t's as entirely unique and use the POSIX API's for
converting to/from strings.

Lastly, a 64-bit integer formats as 20 digits at most in base10.
Don't need to have any 100 byte buffers to hold that.

ASTERISK-29674 #close

Signed-off-by: Philip Prindeville <philipp@redfish-solutions.com>
Change-Id: Id7b25bdca8f92e34229f6454f6c3e500f2cd6f56
2022-03-24 12:00:58 -05:00
Alexander Traud 463f6c83e8 res_pjsip: Fix for Doxygen.
ASTERISK-29747

Change-Id: Ic7a1e9453f805a6264fe86c96b7d18b87b376084
2021-11-18 12:14:54 -06:00
Joseph Nadiv 47cb177baf res_pjsip_registrar: Remove unavailable contacts if exceeds max_contacts
The behavior of max_contacts and remove_existing are connected.  If
remove_existing is enabled, the soonest expiring contacts are removed.
This may occur when there is an unavailable contact.  Similarly,
when remove_existing is not enabled, registrations from good
endpoints are rejected in favor of retaining unavailable contacts.

This commit adds a new AOR option remove_unavailable, and the effect
of this setting will depend on remove_existing.  If remove_existing
is set to no, we will still remove unavailable contacts when they
exceed max_contacts, if there are any. If remove_existing is set to
yes, we will prioritize the removal of unavailable contacts before
those that are expiring soonest.

ASTERISK-29525

Change-Id: Ia2711b08f2b4d1177411b1be23e970d7fdff5784
2021-09-24 11:47:22 -05:00
Ben Ford 12e8600849 STIR/SHAKEN: Add Date header, dest->tn, and URL checking.
STIR/SHAKEN requires a Date header alongside the Identity header, so
that has been added. Still on the outgoing side, we were missing the
dest->tn section of the JSON payload, so that has been added as well.
Moving to the incoming side, URL checking has been added to the public
cert URL to ensure that it starts with http.

https://wiki.asterisk.org/wiki/display/AST/OpenSIPit+2021

Change-Id: Idee5b1b5e45bc3b483b3070e46ce322dca5b3f1c
2021-05-26 12:45:54 -05:00
Joshua C. Colp 6f67f24afd res_pjsip_registrar: Include source IP and port in log messages.
When registering it can be useful to see the source IP address and
port in cases where multiple devices are using the same endpoint
or when anonymous is in use.

ASTERISK-29325

Change-Id: Ie178a6f55f53f8473035854c411bc3d056e0a2e0
2021-03-05 08:14:20 -06:00
Joshua C. Colp 921b1a02c4 res_pjsip_registrar: Don't specify an expiration for static contacts.
Statically configured contacts on an AOR don't have an expiration
time so when adding them to the resulting 200 OK if an endpoint
registers ensure they are marked as such.

ASTERISK-28995

Change-Id: I9f0e45eb2ccdedc9a0df5358634a19ccab0ad596
2020-07-28 09:48:19 -05:00
Kevin Harwell 415b55af5a pjproject: Upgrade bundled version to pjproject 2.10
This patch makes the usual necessary changes when upgrading to a new
version pjproject. For instance, version number bump, patches removed
from third-party, new *.md5 file added, etc..

This patch also includes a change to the Asterisk pjproject Makefile to
explicitly create the 'source/pjsip-apps/lib' directory. This directory
is no longer there by default so needs to be added so the Asterisk
malloc debug can be built.

This patch also includes some minor changes to Asterisk that were a result
of the upgrade. Specifically, there was a backward incompatibility change
made in 2.10 that modified the "expires header" variable field from a
signed to an unsigned value. This potentially effects comparison. Namely,
those check for a value less than zero. This patch modified a few locations
in the Asterisk code that may have been affected.

Lastly, this patch adds a new macro PJSIP_MINVERSION that can be used to
check a minimum version of pjproject at compile time.

ASTERISK-28899 #close

Change-Id: Iec8821c6cbbc08c369d0e3cd2f14e691b41d0c81
2020-06-16 08:07:17 -05:00
Kevin Harwell 3d1bf3c537 Compiler fixes for gcc 10
This patch fixes a few compile warnings/errors that now occur when using gcc
10+.

Also, the Makefile.rules check to turn off partial inlining in gcc versions
greater or equal to 8.2.1 had a bug where it only it only checked against
versions with at least 3 numbers (ex: 8.2.1 vs 10). This patch now ensures
any version above the specified version is correctly compared.

Change-Id: I54718496eb0c3ce5bd6d427cd279a29e8d2825f9
2020-06-10 09:33:28 -05:00
Sean Bright b1be06df8d res_pjsip_registrar.c: Prevent potential double free if AOR is not found
The simple fix here is simply to NULL out username and password after we call
ast_free on them. Unfortunately, I noticed that we weren't checking for
allocation failures for username and password, and adding those checks made
things noisy and cumbersome.

So instead we partially rollback the recent LGTM patch, and move the alloca
calls into find_aor_name().

ASTERISK-28641 #close
Reported by: Ross Beer

Change-Id: Ic9d01624e717a020be0b0aee31f0814e7f1ffbe2
2019-12-04 16:19:23 -06:00
Sean Bright 0183e2bc67 res_pjsip_registrar.c: Prevent possible buffer overflow with domain aliases
We're appropriately sizing the id_domain_alias buffer, but then copying the data
into the id_domain one. We were then using the uninitialized id_domain_alias
buffer we just allocated.

This is ASTERISK~28641 adjacent, but significant enough to warrant its own
patch.

Change-Id: I81c38724d18deab8c6573153e2b99dbb6e2f33d9
2019-12-04 16:15:26 -06:00
Sean Bright a5fa0d662e res_pjsip_registrar: Fix uninitlized variable warning
Fixes: error: ‘domain_name’ may be used uninitialized in this function

Found with gcc (Ubuntu 9.2.1-9ubuntu2) 9.2.1 20191008

Change-Id: I44413b49ea1205aa25538142161deb73883c79e8
2019-11-19 10:33:02 -05:00
Kevin Harwell bdd785d31c various files - fix some alerts raised by lgtm code analysis
This patch fixes several issues reported by the lgtm code analysis tool:

https://lgtm.com/projects/g/asterisk/asterisk

Not all reported issues were addressed in this patch. This patch mostly fixes
confirmed reported errors, potential problematic code points, and a few other
"low hanging" warnings or recommendations found in core supported modules.
These include, but are not limited to the following:

* innapropriate stack allocation in loops
* buffer overflows
* variable declaration "hiding" another variable declaration
* comparisons results that are always the same
* ambiguously signed bit-field members
* missing header guards

Change-Id: Id4a881686605d26c94ab5409bc70fcc21efacc25
2019-11-18 08:30:45 -06:00
Sean Bright 982a5025b3 res_pjsip_registrar: Validate Contact URI before adding to responses
If a permanent contact URI associated with an AOR is invalid, we add a
Contact header to REGISTER responses with a NULL URI, causing a crash.

ASTERISK-28463 #close

Change-Id: Id2b643e58b975bc560aab1c111e6669d54db9102
2019-09-25 06:21:18 -05:00
George Joseph ef92c69fa8 res_pjsip: Check return from pjsip_parse_uri calls
Updated ast_sip_create_rdata_with_contact and registrar_find_contact
to check the return from pjsip_parse_uri before attempting to
use the uri returned.

ASTERISK-28402
Reported-by: Ross Beer

Change-Id: I9810b3b163c45ed5a56ec743586e5ce107f13ba7
2019-05-02 12:32:40 -06:00
Kevin Harwell 930a7fe910 res_pjsip_registrar: blocked threads on reliable transport shutdown take 3
When a contact was removed by the registrar it did not always check to see if
the circumstances involved a monitored reliable transport. For instance, if the
'remove_existing' option was set to 'true' then when existing contacts were
removed due to 'max_contacts' being reached, those existing contacts being
removed did not unregister the transport monitor.

Also, it was possible to add more than one monitor on a reliable transport for
a given aor and contact.

This patch makes it so all contact removals done by the registrar also remove
any associated transport monitors if necessary. It also makes it so duplicate
monitors cannot be added for a given transport.

ASTERISK-28213

Change-Id: I94b06f9026ed177d6adfd538317c784a42c1b17a
2019-02-27 17:02:43 -06:00
Kevin Harwell 61a8f79a29 res_pjsip_registrar: lock transport monitor when setting 'removing' flag
A previous patch attempt to mitigate blocked threads on transport shutdown for
a given contact. It was thought that a second lock could be avoided by checking
the 'removing' flag on the transport monitor twice (once before and once after
the normal named aor locking). However as with usual threading issues if the
timing was right the original problem still occured.

This patch adds locking around the first 'removing' flag check and set, thus
nullifying the secondary check, so it was removed.

ASTERISK-28213

Change-Id: Iaa8e36e5311789549b76d8de42dfcea96013b2ed
2019-02-07 14:28:41 -06:00
Kevin Harwell b82d2856b4 res_pjsip_registrar: mitigate blocked threads on reliable transport shutdown
When a reliable transport is shutdown it's possible for the pjsip registrar
resource shutdown handler to get called multiple times. If this happens and one
of the threads is taking "too long" (slow database call for instance) then the
others get blocked waiting to delete.

Since it only takes one to delete the contact then the other threads should be
able to continue on if one of the threads is currently "deleting". This patch
makes it so now when a thread enters the shutdown handler it checks to see if a
thread is currently already "deleting". If so, then the thread does not attempt
to get the lock, and instead continues on thus avoiding the blockage.

ASTERISK-28213 #close

Change-Id: I7563ca596312b1dff4f3ab41483e89fe2862328a
2019-01-22 13:16:42 -06:00
Joshua Colp cbf082ed53 res_pjsip_registrar: Improve performance on inbound handling.
This change removes a sorcery lookup for retrieving all
contacts at the end of the registration process by keeping
track of the contacts that are added/updated/deleted.

This ensures at the end of the process the container of
contacts we have is the current state.

Pool usage has also been reduced by allocating one for
usage throughout the handling of a REGISTER and resetting
it to a clean state. This ensures that in most cases
we allocate once and just reuse it.

ASTERISK-28001

Change-Id: I1a78b2d46f9a2045dbbff1a3fd6dba84b612b3cb
2018-08-03 04:09:15 -05:00
Richard Mudgett 97cc67b12f res_pjsip: Fix deadlock on reliable transport shutdown.
A deadlock can happen when the PJSIP monitor thread is shutting down a
connection oriented transport (TCP/TLS) used by a subscription at the same
time as another thread tries to send something for that subscription.  The
deadlock is between the pjsip monitor thread attempting to get the dialog
lock and another thread sending something for that dialog when it tries to
get the transport manager lock.

* res_pjsip_pubsub.c: Avoid the deadlock by pushing the subscription
removal to the subscription serializer.

* res_pjsip_registrar.c: Pushed off incoming registration contact removals
to a default serializer as a precaution.  Removing the contacts involves
sorcery access which in this case will involve database access.  Depending
upon the setup, the database may not be on the same machine and could take
awhile.  We don't want to hold up the pjsip monitor thread with
potentially long access times.

ASTERISK-27706

Change-Id: I56b647aea565f24dba33e9e5ebeed4cd3f31f8c4
2018-03-29 16:22:25 -06:00
George Joseph b148453708 Merge "res_pjsip_pubsub: Prune subs with reliable transports at startup" 2018-02-01 11:26:49 -06:00
Richard Mudgett 6c5e3226ec res_pjsip_registrar.c: Fix compiler error.
Need to include signal.h to define pthread_kill() and SIGURG.

Change-Id: I10ae3aa4bf8e7386ac29ade78c0f2caed8e674fa
2018-01-31 11:02:47 -06:00
George Joseph 2b9aa6b5bb res_pjsip_pubsub: Prune subs with reliable transports at startup
In an earlier release, inbound registrations on a reliable transport
were pruned on Asterisk restart since the TCP connection would have
been torn down and become unusable when Asterisk stopped.  This same
process is now also applied to inbound subscriptions.

Also fixed issues in res_pjsip_registrar where it wasn't handling the
monitoring correctly when multiple registrations came in over the same
transport.

To accomplish this, the pjsip_transport_event feature needed to
be refactored to allow multiple monitors (multiple subcriptions or
registrations from the same endpoint) to exist on the same transport.
Since this changed the API, any external modules that may have used the
transport monitor feature (highly unlikey) will need to be changed.

ASTERISK-27612
Reported by: Ross Beer

Change-Id: Iee87cf4eb9b7b2b93d5739a72af52d6ca8fbbe36
2018-01-30 09:29:51 -06:00
George Joseph 81db0aca0f res_pjsip_registrar_expire: Refactor into res_pjsip_register
res_pjsip_registrar_expire remains as an empty module for now.

Change-Id: Ib93698938bae548d2199cb542f3692d1a171239f
2018-01-29 12:49:53 -07:00
Corey Farrell 527cf5a570 Remove redundant module checks and references.
This removes references that are no longer needed due to automatic
references created by module dependencies.

In addition this removes most calls to ast_module_check as they were
checking modules which are listed as dependencies.

Change-Id: I332a6e8383d4c72c8e89d988a184ab8320c4872e
2018-01-24 13:37:29 -05:00
Corey Farrell 9cfdb81e91 loader: Add dependency fields to module structures.
* Declare 'requires' and 'enhances' text fields on module info structure.
* Rename 'nonoptreq' to 'optional_modules'.
* Update doxygen comments.

Still need to investigate dependencies among modules I cannot compile.

Change-Id: I3ad9547a0a6442409ff4e352a6d897bef2cc04bf
2018-01-15 13:25:51 -05:00
Richard Mudgett 0cfc3cbf02 res_pjsip_registrar.c: Fix AOR and pjproject group deadlock.
One of the patches for ASTERISK_27147 introduced a deadlock regression.
When the connection oriented transport shut down, the code attempted to
remove the associated contact.  However, that same transport had just
requested a registration that we hadn't responded to yet.  Depending
upon timing we could deadlock.

* Made send the REGISTER response after we completed processing the
request contacts and released the AOR lock to avoid the deadlock.

ASTERISK-27391

Change-Id: I89a90f87cb7a02facbafb44c75d8845f93417364
2017-11-07 13:01:25 -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
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 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
Mark Michelson 46147a8f30 Revert "Update qualifies when AOR configuration changes."
This reverts commit 6492e91392.

The change in question was intended to prevent the need to reload in
order to update qualifies on contacts when an AOR changes. However, this
ended up causing a deadlock instead.

Change-Id: I1a835c90a5bb65b6dc3a1e94cddc12a4afc3d71e
2017-02-08 11:54:39 -06:00
Mark Michelson bbed75c3ba Update qualifies when AOR configuration changes.
Prior to this change, qualifies would only update in the following
cases:
* A reload of res_pjsip.so was issued.
* A dynamic contact was re-registered after its AOR's qualify_frequency
  had been changed
This does not work well if you are using realtime for your AORs. You can
update your database to have a new qualify_frequency, but the permanent
contacts on that AOR will not have their qualifies updated. And the
dynamic contacts on that AOR will not have their qualifies updated until
the next registration, which could be a long time.

This change seeks to fix this problem by making it so that whenever AOR
configuration is applied, the contacts pertaining to that AOR have their
qualifies updated.

Additions from this patch:
* AOR sorcery objects now have an apply handler that calls into a newly
  added function in the OPTIONS code. This causes all contacts
  associated with that AOR to re-schedule qualifies.
* When it is time to qualify a contact, the OPTIONS code checks to see
  if the AOR can still be retrieved. If not, then qualification is
  canceled on the contact.

Alterations from this patch:
* The registrar code no longer updates contact's qualify_frequence and
  qualify_timeout. There is no point to this since those values already
  get updated when the AOR changes.
* Reloading res_pjsip.so no longer calls the OPTIONS initialization
  function. Reloading res_pjsip.so results in re-loading AORs, which
  results in re-scheduling qualifies.

Change-Id: I2e7c3316da28f389c45954f24c4e9389abac1121
2017-02-01 14:21:04 -06:00
George Joseph 79b09b5f18 res_pjsip_registrar: AMI Add RegistrationInboundContactStatuses command
The PJSIPShowRegistrationsInbound AMI command was just dumping out
all AORs which was pretty useless and resource heavy since it had
to get all endpoints, then all aors for each endpoint, then all
contacts for each aor.

PJSIPShowRegistrationInboundContactStatuses sends ContactStatusDetail
events which meets the intended purpose of the other command and has
significantly less overhead.  Also, some additional fields that were
added to Contact since the original creation of the ContactStatusDetail
event have been added to the end of the event.

For compatibility purposes, PJSIPShowRegistrationsInbound is left
intact.

ASTERISK-26644 #close

Change-Id: I326f12c9ecb52bf37ba03f0748749de4da01490a
2016-12-07 18:11:28 -06:00
Richard Mudgett ba362822f3 res_pjsip: Add ignore_uri_user_options option.
This implements the chan_sip legacy_useroption_parsing option but with a
better name.

* Made the caller-id number and redirecting number strings obtained from
incoming SIP URI user fields always truncated at the first semicolon.
People don't care about anything after the semicolon showing up on their
displays even though the RFC allows the semicolon.

ASTERISK-26316 #close
Reported by: Kevin Harwell

Change-Id: Ib42b0e940dd34d84c7b14bc2e90d1ba392624f62
2016-09-09 17:13:02 -05:00
zuul 7437467d94 Merge "res_pjsip_registrar.c: Reduce stack usage in find_aor_name()." 2016-09-06 22:47:50 -05:00
Richard Mudgett 68c7694abb res_pjsip_registrar.c: Reduce stack usage in find_aor_name().
Change-Id: I8aebad1fdcf303bd115b59a4b57fbbd5b2267f09
2016-09-02 13:24:29 -05:00
Corey Farrell e875e1c12a sorcery: Create function ast_sorcery_lockable_alloc.
Create an alternative to ast_sorcery_generic_alloc which uses astobj2
shared locking. Use this new method for the 'struct ast_sip_aor' allocator.

Change-Id: I3f62f2ada64b622571950278fbb6ad57395b5d6f
2016-09-02 09:26:25 -04:00
Richard Mudgett 5ba6357be2 res_pjsip: Make aor named lock a mutex.
The named aor lock was always being locked for writes so a rwlock adds no
benefit and may be slower because rwlocks are biased toward read locking.

Change-Id: I8c5c2c780eb30ce5441832257beeb3506fd12b28
2016-08-11 11:58:38 -05:00
Richard Mudgett 04ec9c745e res_pjsip_registrar.c: Eliminate rx REGISTER request race condition.
This patch fixes a race condition processing received REGISTER requests
and their retransmissions caused by REGISTER requests being processed by
two threads.  The "sip_transaction Unable to register REGISTER transaction
(key exists)" message is a notable symptom of this issue.

This issue was more likely to happen before the pjsip/distributor
serializers were created.  Instead of steps one and two below placing the
REGISTER messages into the same pjsip/distributor they were placed in
random pjsip/default serializers.

1) REGISTER requests come in and get placed on the pjsip/distributor
serializer.

2) Before the first request is processed a retransmission comes in and is
placed on the same pjsip/distributor serializer.

3) The first request goes up the pjsip stack and is then shunted off to
the pjsip/aor/<aor> serializer.

4) Before the first request is completed processing in the pjsip/aor/<aor>
serializer, the second request goes up the pjsip stack and is also shunted
off to the pjsip/aor/<aor> serializer.

5) The first request completes processing and sends out its response.

6) The second request completes processing and tries to send out its
response but pjlib complains that the REGISTER transaction key already
exists.

7) Sadness ensues.

* The race is eliminated by removing the pjsip/aor/<aor> serializer and
continuing the processing in the pjsip/distributor serializer.  Now any
retransmissions queued in the pjsip/distributor serializer will be
processed after the first message is completely processed.

ASTERISK-26088 #close
Reported by:  Richard Mudgett

Change-Id: I842d714346088bf717ea27437f1dd85bff0bab5a
2016-06-09 10:32:07 -05:00
Alexei Gradinari 31f17abe44 res_pjsip: add "via_addr", "via_port", "call_id" to contact
As res_pjsip_nat rewrites contact's address, only the last Via header
can contain the source address of registered endpoint.
Also Call-Id header may contain the source address of registered
endpoint.

Added "via_addr", "via_port", "call_id" to contact.
Added new fields ViaAddress, CallID to AMI event ContactStatus.

ASTERISK-26011

Change-Id: I36bcc0bf422b3e0623680152d80486aeafe4c576
2016-05-26 16:18:11 -05:00
Alexei Gradinari 322c3b4262 res_pjsip: module load priority
The res_pjsip_authenticator_digest, res_pjsip_endpoint_identifier_*
and res_pjsip_registrar modules should load ASAP
to avoid "No matching endpoint found" for legitimate endpoint.

ASTERISK-25994

Change-Id: Iac95d95ad031e0be104189d29e923a2ad7c24a1b
2016-05-06 12:56:07 -04:00
Alexei Gradinari 2b1edee772 pjsip: Added "reg_server" to contacts.
If the Asterisk system name is set in asterisk.conf, it will be stored
into the "reg_server" field in the ps_contacts table to facilitate
multi-server setups.

ASTERISK-25931

Change-Id: Ia8f6bd2267809c78753b52bcf21835b9b59f4cb8
2016-05-02 10:01:40 -03:00
George Joseph 4ebf9a938d res_pjsip: Add ability to identify by Authorization username
A feature of chan_sip that service providers relied upon was the ability to
identify by the Authorization username.  This is most often used when customers
have a PBX that needs to register rather than identify by IP address.  From my
own experiance, this is pretty common with small businesses who otherwise
don't need a static IP.

In this scenario, a register from the customer's PBX may succeed because From
will usually contain the PBXs account id but an INVITE will contain the caller
id.  With nothing recognizable in From, the service provider's Asterisk can
never match to an endpoint and the INVITE just stays unauthorized.

The fixes:

A new value "auth_username" has been added to endpoint/identify_by that
will use the username and digest fields in the Authorization header
instead of username and domain in the the From header to match an endpoint,
or the To header to match an aor.  This code as added to
res_pjsip_endpoint_identifier_user rather than creating a new module.

Although identify_by was always a comma-separated list, there was only
1 choice so order wasn't preserved.  So to keep the order, a vector was added
to the end of ast_sip_endpoint.  This is only used by res_pjsip_registrar
to find the aor.  The res_pjsip_endpoint_identifier_* modules are called in
globals/endpoint_identifier_order.

Along the way, the logic in res_pjsip_registrar was corrected to match
most-specific to least-specific as res_pjsip_endpoint_identifier_user does.

The order is:

username@domain
username@domain_alias
username

Auth by username does present 1 problem however, the first INVITE won't have
an Authorization header so the distributor, not finding a match on anything,
sends a securty_alert.  It still sends a 401 with a challenge so the next
INVITE will have the Authorization header and presumably succeed.  As a result
though, that first security alert is actually a false alarm.

To address this, a new feature has been added to pjsip_distributor that keeps
track of unidentified requests and only sends the security alert if a
configurable number of unidentified requests come from the same IP in a
configurable amout of time.  Those configuration options have been added to
the global config object.  This feature is only used when auth_username
is enabled.

Finally, default_realm was added to the globals object to replace the hard
coded "asterisk" used when an endpoint is not yet identified.

The testsuite tests all pass but new tests are forthcoming for this new
feature.

ASTERISK-25835 #close
Reported-by: Ross Beer

Change-Id: I30ba62d208e6f63439600916fcd1c08a365ed69d
2016-04-27 16:33:51 -05:00
Mark Michelson b8b60135ec res_pjsip_registrar: Fix bad memory-ness with user_agent.
Recent changes to the PJSIP registrar resulted in tests failing due to
missing AOR_CONTACT_ADDED test events. The reason for this was that the
user_agent string had junk values in it, resulting in being unable to
generate the event.

I'm going to be honest here, I have no idea why this was happening. Here
are the steps needed for the user_agent variable to get messed up:
* REGISTER is received
* First contact in the REGISTER results in a contact being removed
* Second contact in the REGISTER results in a contact being added
* The contact, AOR, expiration, and user agent all have to be passed as
  format parameters to the creation of a string. Any subset of those
  parameters would not be enough to cause the problem.

Looking into what was happening, the thing that struck me as odd was
that the user_agent variable was meant to be set to the value of the
User-Agent SIP header in the incoming REGISTER. However, when removing a
contact, the user_agent variable would be set (via ast_strdupa inside a
loop) to the stored contact's user_agent. This means that the
user_agent's value would be incorrect when attempting to process further
contacts in the incoming REGISTER.

The fix here is to use a different variable for the stored user agent
when removing a contact. Correcting the behavior to be correct also
means the memory usage is less weird, and the issue no longer occurs.

ASTERISK-25929 #close
Reported by Joshua Colp

Change-Id: I7cd24c86a38dec69ebcc94150614bc25f46b8c08
2016-04-19 08:22:23 -05:00
Mark Michelson 7b8b6e2e4f AST-2016-004: Fix crash on REGISTER with long URI.
Due to some ignored return values, Asterisk could crash if processing an
incoming REGISTER whose contact URI was above a certain length.

ASTERISK-25707 #close
Reported by George Joseph

Patches:
    0001-res_pjsip-Validate-that-URIs-don-t-exceed-pjproject-.patch

AST-2016-004

Change-Id: I3ea7cee16f29c8088794de3085ca7523c1c4833d
2016-04-14 07:23:54 -05:00
George Joseph a621dd5e96 res_pjsip contact: Lock expiration/addition of contacts
Contact expiration can occur in several places:  res_pjsip_registrar,
res_pjsip_registrar_expire, and automatically when anyone calls
ast_sip_location_retrieve_aor_contact.  At the same time, res_pjsip_registrar
may also be attempting to renew or add a contact.  Since none of this was locked
it was possible for one thread to be renewing a contact and another thread to
expire it immediately because it was working off of stale data.  This was the
casue of intermittent registration/inbound/nominal/multiple_contacts test
failures.

Now, the new named lock functionality is used to lock the aor during contact
expire and add operations and res_pjsip_registrar_expire now checks the
expiration with the lock held before deleting the contact.

ASTERISK-25885 #close
Reported-by: Josh Colp

Change-Id: I83d413c46a47796f3ab052ca3b349f21cca47059
2016-04-11 13:00:27 -05:00
George Joseph d2eb65f71e res_pjsip: Strip spaces from items parsed from comma-separated lists
Configurations like "aors = a, b, c" were either ignoring everything after "a"
or trying to look up " b".  Same for mailboxes,  ciphers, contacts and a few
others.

To fix, all the strsep(&copy, ",") calls have been wrapped in ast_strip.  To
facilitate this, ast_strip, ast_skip_blanks and ast_skip_nonblanks were
updated to handle null pointers.

In some cases, an ast_strlen_zero() test was added to skip consecutive commas.

There was also an attempt to ast_free an ast_strdupa'd string in
ast_sip_for_each_aor which was causing a SEGV.  I removed it.

Although this issue was reported for realtime, the issue was in the res_pjsip
modules so all config mechanisms were affected.

ASTERISK-25829 #close
Reported-by: Mateusz Kowalski

Change-Id: I0b22a2cf22a7c1c50d4ecacbfa540155bec0e7a2
2016-03-07 13:16:41 -06:00
Richard Mudgett 0bca2a5c26 res_pjsip: Create human friendly serializer names.
PJSIP name formats:
pjsip/aor/<aor>-<seq> -- registrar thread pool serializer
pjsip/default-<seq> -- default thread pool serializer
pjsip/messaging -- messaging thread pool serializer
pjsip/outreg/<registration>-<seq> -- outbound registration thread pool
serializer
pjsip/pubsub/<endpoint>-<seq> -- pubsub thread pool serializer
pjsip/refer/<endpoint>-<seq> -- REFER thread pool serializer
pjsip/session/<endpoint>-<seq> -- session thread pool serializer
pjsip/websocket-<seq> -- websocket thread pool serializer

Change-Id: Iff9df8da3ddae1132cb2ef65f64df0c465c5e084
2016-01-08 22:11:45 -06:00
Joshua Colp 7846f73432 res_pjsip_mwi: Set up unsolicited MWI upon registration.
The res_pjsip_mwi previously required a reload to set up the proper
subscriptions to allow unsolicited MWI to work. This change
makes it so the act of registering will also cause this to occur.
This is particularly useful if realtime is involved as no reload
needs to occur within Asterisk to cause the MWI information
to get sent.

ASTERISK-25180 #close

Change-Id: Id847b47de4b8b3ab8858455ccc2f07b0f915f252
2015-06-23 08:15:05 -05:00
Rodrigo Ramírez Norambuena eec010829a AST_MODULE_INFO: Format corrections to the usages of AST_MODULE_INFO macro.
Change-Id: Icf88f9f861c6b2a16e5f626ff25795218a6f2723
2015-05-13 16:34:23 -05:00
Mark Michelson 0b62e41654 Add stateful PJSIP response API call, and use it for out-of-dialog responses.
Asterisk had an issue where retransmissions of MESSAGE requests resulted in
Asterisk processing the retransmission as if it were a new MESSAGE request.

This patch fixes the issue by creating a transaction in PJSIP on the incoming
request. This way, if a retransmission arrives, the PJSIP transaction layer
will resend the response and Asterisk will not ever see the retransmission.

ASTERISK-24920 #close
Reported by Mark Michelson

Review: https://reviewboard.asterisk.org/r/4532/
........

Merged revisions 433619 from http://svn.asterisk.org/svn/asterisk/branches/13


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@433620 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2015-03-27 20:46:55 +00:00