Asterisk - The Open Source Telephony Project GIT-master-70eff7f
Loading...
Searching...
No Matches
Data Structures | Macros | Functions | Variables
pjsip_distributor.c File Reference
#include "asterisk.h"
#include <pjsip.h>
#include "asterisk/res_pjsip.h"
#include "asterisk/acl.h"
#include "include/res_pjsip_private.h"
#include "asterisk/taskprocessor.h"
#include "asterisk/taskpool.h"
#include "asterisk/res_pjsip_cli.h"
Include dependency graph for pjsip_distributor.c:

Go to the source code of this file.

Data Structures

struct  distributor_dialog_data
 
struct  unidentified_request
 

Macros

#define DEFAULT_SUSPECTS_BUCKETS   53
 
#define DIALOG_ASSOCIATIONS_BUCKETS   251
 
#define DISTRIBUTOR_POOL_SIZE   31
 

Functions

static struct ast_sip_authalloc_artificial_auth (char *default_realm, char *default_algos_uac, char *default_algos_uas)
 
static AO2_GLOBAL_OBJ_STATIC (artificial_auth)
 
static void apply_acls (pjsip_rx_data *rdata)
 
static int apply_endpoint_acl (pjsip_rx_data *rdata, struct ast_sip_endpoint *endpoint)
 
static int apply_endpoint_contact_acl (pjsip_rx_data *rdata, struct ast_sip_endpoint *endpoint)
 
struct ast_sip_endpointast_pjsip_rdata_get_endpoint (pjsip_rx_data *rdata)
 Get the looked-up endpoint on an out-of dialog request or response.
 
void ast_sip_destroy_distributor (void)
 
struct ast_sip_endpointast_sip_dialog_get_endpoint (pjsip_dialog *dlg)
 Get the endpoint associated with this dialog.
 
void ast_sip_dialog_set_endpoint (pjsip_dialog *dlg, struct ast_sip_endpoint *endpoint)
 Set an endpoint on a SIP dialog so in-dialog requests do not undergo endpoint lookup.
 
void ast_sip_dialog_set_serializer (pjsip_dialog *dlg, struct ast_taskprocessor *serializer)
 Set a serializer on a SIP dialog so requests and responses are automatically serialized.
 
struct ast_sip_authast_sip_get_artificial_auth (void)
 Retrieves a reference to the artificial auth.
 
struct ast_sip_endpointast_sip_get_artificial_endpoint (void)
 Retrieves a reference to the artificial endpoint.
 
struct ast_taskprocessorast_sip_get_distributor_serializer (pjsip_rx_data *rdata)
 Determine the distributor serializer for the SIP message.
 
struct ast_taskprocessorast_sip_get_distributor_serializer_dialog (pjsip_dialog *dlg)
 Determine the distributor serializer for the SIP dialog.
 
struct ast_taskprocessorast_sip_get_distributor_serializer_hash (int hash)
 Determine the distributor serializer for a given hash.
 
int ast_sip_initialize_distributor (void)
 
static pj_bool_t authenticate (pjsip_rx_data *rdata)
 
static int buf_hash (const char *pos, size_t len)
 
static int buf_hash_add (const char *pos, size_t len, int hash)
 
static void check_endpoint (pjsip_rx_data *rdata, struct unidentified_request *unid, const char *name)
 
static int clean_task (const void *data)
 
static struct ao2_containercli_unid_get_container (const char *regex)
 
static const char * cli_unid_get_id (const void *obj)
 
static int cli_unid_iterate (void *container, ao2_callback_fn callback, void *args)
 
static int cli_unid_print_body (void *obj, void *arg, int flags)
 
static int cli_unid_print_header (void *obj, void *arg, int flags)
 
static void * cli_unid_retrieve_by_id (const char *id)
 
static int create_artificial_auth (void)
 
static int create_artificial_endpoint (void)
 
static int dialog_associations_cmp (void *obj, void *arg, int flags)
 
static int dialog_associations_hash (const void *obj, int flags)
 
static int distribute (void *data)
 
static pj_bool_t distributor (pjsip_rx_data *rdata)
 
static int distributor_pool_setup (void)
 
static void distributor_pool_shutdown (void)
 
static pj_bool_t endpoint_lookup (pjsip_rx_data *rdata)
 
static int expire_requests (void *object, void *arg, int flags)
 
static int extract_contact_addr (pjsip_contact_hdr *contact, struct ast_sockaddr **addrs)
 
static pjsip_dialog * find_dialog (pjsip_rx_data *rdata)
 
static struct ast_taskprocessorfind_request_serializer (pjsip_rx_data *rdata)
 
static void global_loaded (const char *object_type)
 
static void log_failed_request (pjsip_rx_data *rdata, char *msg, unsigned int count, unsigned int period)
 
static int pjstr_hash (pj_str_t *str)
 
static int pjstr_hash_add (pj_str_t *str, int hash)
 
static int prune_task (const void *data)
 
static pj_status_t record_serializer (pjsip_tx_data *tdata)
 
static int suspects_compare (void *obj, void *arg, int flags)
 
static int suspects_hash (const void *obj, int flags)
 
static int suspects_sort (const void *obj, const void *arg, int flags)
 

Variables

static struct ast_sip_endpointartificial_endpoint = NULL
 
static pjsip_module auth_mod
 
static struct ast_cli_entry cli_commands []
 
static struct ao2_containerdialog_associations
 
static pjsip_module distributor_mod
 
static struct ast_taskprocessordistributor_pool [DISTRIBUTOR_POOL_SIZE]
 
static pjsip_module endpoint_mod
 
static struct ast_sorcery_observer global_observer
 Observer which is used to update our interval and default_realm when the global setting changes.
 
static enum ast_sip_taskprocessor_overload_trigger overload_trigger
 
struct ast_sched_contextprune_context
 
struct ast_sip_cli_formatter_entryunid_formatter
 
static unsigned int unidentified_count
 
static unsigned int unidentified_period
 
static unsigned int unidentified_prune_interval
 
static struct ao2_containerunidentified_requests
 
static int using_auth_username
 

Macro Definition Documentation

◆ DEFAULT_SUSPECTS_BUCKETS

#define DEFAULT_SUSPECTS_BUCKETS   53

Definition at line 44 of file pjsip_distributor.c.

◆ DIALOG_ASSOCIATIONS_BUCKETS

#define DIALOG_ASSOCIATIONS_BUCKETS   251

Definition at line 159 of file pjsip_distributor.c.

◆ DISTRIBUTOR_POOL_SIZE

#define DISTRIBUTOR_POOL_SIZE   31

Number of serializers in pool if one not otherwise known. (Best if prime number)

Definition at line 60 of file pjsip_distributor.c.

Function Documentation

◆ alloc_artificial_auth()

static struct ast_sip_auth * alloc_artificial_auth ( char *  default_realm,
char *  default_algos_uac,
char *  default_algos_uas 
)
static

Definition at line 625 of file pjsip_distributor.c.

627{
628 struct ast_sip_auth *fake_auth;
629
631 "artificial");
632 if (!fake_auth) {
633 return NULL;
634 }
635
637 ast_string_field_set(fake_auth, auth_user, "");
638 ast_string_field_set(fake_auth, auth_pass, "");
639
641 &fake_auth->supported_algorithms_uac, "UAC", default_algos_uac);
642
644 &fake_auth->supported_algorithms_uas, "UAS", default_algos_uas);
645
647
648 return fake_auth;
649}
int ast_sip_auth_digest_algorithms_vector_init(const char *id, struct pjsip_auth_algorithm_type_vector *algorithms, const char *agent_type, const char *value)
Populate a vector of algorithm types from a string.
@ AST_SIP_AUTH_TYPE_ARTIFICIAL
Definition res_pjsip.h:587
#define SIP_SORCERY_AUTH_TYPE
Definition res_pjsip.h:599
struct ast_sorcery * ast_sip_get_sorcery(void)
Get a pointer to the SIP sorcery structure.
static char default_realm[AST_SIP_AUTH_MAX_REALM_LENGTH+1]
#define NULL
Definition resample.c:96
void * ast_sorcery_alloc(const struct ast_sorcery *sorcery, const char *type, const char *id)
Allocate an object.
Definition sorcery.c:1808
#define ast_string_field_set(x, field, data)
Set a field to a simple string value.
struct pjsip_auth_algorithm_type_vector supported_algorithms_uac
Definition res_pjsip.h:689
const ast_string_field realm
Definition res_pjsip.h:683
const ast_string_field auth_user
Definition res_pjsip.h:683
struct pjsip_auth_algorithm_type_vector supported_algorithms_uas
Definition res_pjsip.h:691
const ast_string_field auth_pass
Definition res_pjsip.h:683
enum ast_sip_auth_type type
Definition res_pjsip.h:687

References ast_sip_auth_digest_algorithms_vector_init(), AST_SIP_AUTH_TYPE_ARTIFICIAL, ast_sip_get_sorcery(), ast_sorcery_alloc(), ast_string_field_set, ast_sip_auth::auth_pass, ast_sip_auth::auth_user, default_realm, NULL, ast_sip_auth::realm, SIP_SORCERY_AUTH_TYPE, ast_sip_auth::supported_algorithms_uac, ast_sip_auth::supported_algorithms_uas, and ast_sip_auth::type.

Referenced by create_artificial_auth().

◆ AO2_GLOBAL_OBJ_STATIC()

static AO2_GLOBAL_OBJ_STATIC ( artificial_auth  )
static

◆ apply_acls()

static void apply_acls ( pjsip_rx_data *  rdata)
static

Definition at line 747 of file pjsip_distributor.c.

748{
749 struct ast_sip_endpoint *endpoint;
750
751 /* Is the endpoint allowed with the source or contact address? */
752 endpoint = rdata->endpt_info.mod_data[endpoint_mod.id];
753 if (endpoint != artificial_endpoint
754 && (apply_endpoint_acl(rdata, endpoint)
755 || apply_endpoint_contact_acl(rdata, endpoint))) {
756 ast_debug(1, "Endpoint '%s' not allowed by ACL\n",
757 ast_sorcery_object_get_id(endpoint));
758
759 /* Replace the rdata endpoint with the artificial endpoint. */
760 ao2_replace(rdata->endpt_info.mod_data[endpoint_mod.id], artificial_endpoint);
761 }
762}
#define ao2_replace(dst, src)
Replace one object reference with another cleaning up the original.
Definition astobj2.h:501
#define ast_debug(level,...)
Log a DEBUG message.
static int apply_endpoint_acl(pjsip_rx_data *rdata, struct ast_sip_endpoint *endpoint)
static pjsip_module endpoint_mod
static struct ast_sip_endpoint * artificial_endpoint
static int apply_endpoint_contact_acl(pjsip_rx_data *rdata, struct ast_sip_endpoint *endpoint)
const char * ast_sorcery_object_get_id(const void *object)
Get the unique identifier of a sorcery object.
Definition sorcery.c:2381
An entity with which Asterisk communicates.
Definition res_pjsip.h:1067

References ao2_replace, apply_endpoint_acl(), apply_endpoint_contact_acl(), artificial_endpoint, ast_debug, ast_sorcery_object_get_id(), and endpoint_mod.

Referenced by endpoint_lookup().

◆ apply_endpoint_acl()

static int apply_endpoint_acl ( pjsip_rx_data *  rdata,
struct ast_sip_endpoint endpoint 
)
static

Definition at line 852 of file pjsip_distributor.c.

853{
854 struct ast_sockaddr addr;
855
856 if (ast_acl_list_is_empty(endpoint->acl)) {
857 return 0;
858 }
859
860 memset(&addr, 0, sizeof(addr));
861 ast_sockaddr_parse(&addr, rdata->pkt_info.src_name, PARSE_PORT_FORBID);
862 ast_sockaddr_set_port(&addr, rdata->pkt_info.src_port);
863
864 if (ast_apply_acl(endpoint->acl, &addr, "SIP ACL: ") != AST_SENSE_ALLOW) {
865 log_failed_request(rdata, "Not match Endpoint ACL", 0, 0);
866 ast_sip_report_failed_acl(endpoint, rdata, "not_match_endpoint_acl");
867 return 1;
868 }
869 return 0;
870}
enum ast_acl_sense ast_apply_acl(struct ast_acl_list *acl_list, const struct ast_sockaddr *addr, const char *purpose)
Apply a set of rules to a given IP address.
Definition acl.c:799
@ AST_SENSE_ALLOW
Definition acl.h:38
int ast_acl_list_is_empty(struct ast_acl_list *acl_list)
Determines if an ACL is empty or if it contains entries.
Definition acl.c:540
int ast_sockaddr_parse(struct ast_sockaddr *addr, const char *str, int flags)
Parse an IPv4 or IPv6 address string.
Definition netsock2.c:230
#define ast_sockaddr_set_port(addr, port)
Sets the port number of a socket address.
Definition netsock2.h:532
static void log_failed_request(pjsip_rx_data *rdata, char *msg, unsigned int count, unsigned int period)
void ast_sip_report_failed_acl(struct ast_sip_endpoint *endpoint, pjsip_rx_data *rdata, const char *name)
Send a security event notification for when an ACL check fails.
struct ast_acl_list * acl
Definition res_pjsip.h:1142
Socket address structure.
Definition netsock2.h:97

References ast_sip_endpoint::acl, ast_acl_list_is_empty(), ast_apply_acl(), AST_SENSE_ALLOW, ast_sip_report_failed_acl(), ast_sockaddr_parse(), ast_sockaddr_set_port, log_failed_request(), and PARSE_PORT_FORBID.

Referenced by apply_acls().

◆ apply_endpoint_contact_acl()

static int apply_endpoint_contact_acl ( pjsip_rx_data *  rdata,
struct ast_sip_endpoint endpoint 
)
static

Definition at line 891 of file pjsip_distributor.c.

892{
893 int num_contact_addrs;
894 int forbidden = 0;
895 struct ast_sockaddr *contact_addrs;
896 int i;
897 pjsip_contact_hdr *contact = (pjsip_contact_hdr *)&rdata->msg_info.msg->hdr;
898
899 if (ast_acl_list_is_empty(endpoint->contact_acl)) {
900 return 0;
901 }
902
903 while ((contact = pjsip_msg_find_hdr(rdata->msg_info.msg, PJSIP_H_CONTACT, contact->next))) {
904 num_contact_addrs = extract_contact_addr(contact, &contact_addrs);
905 if (num_contact_addrs <= 0) {
906 continue;
907 }
908 for (i = 0; i < num_contact_addrs; ++i) {
909 if (ast_apply_acl(endpoint->contact_acl, &contact_addrs[i], "SIP Contact ACL: ") != AST_SENSE_ALLOW) {
910 log_failed_request(rdata, "Not match Endpoint Contact ACL", 0, 0);
911 ast_sip_report_failed_acl(endpoint, rdata, "not_match_endpoint_contact_acl");
912 forbidden = 1;
913 break;
914 }
915 }
916 ast_free(contact_addrs);
917 if (forbidden) {
918 /* No use checking other contacts if we already have failed ACL check */
919 break;
920 }
921 }
922
923 return forbidden;
924}
#define ast_free(a)
Definition astmm.h:180
static int extract_contact_addr(pjsip_contact_hdr *contact, struct ast_sockaddr **addrs)
struct ast_acl_list * contact_acl
Definition res_pjsip.h:1144

References ast_acl_list_is_empty(), ast_apply_acl(), ast_free, AST_SENSE_ALLOW, ast_sip_report_failed_acl(), ast_sip_endpoint::contact_acl, extract_contact_addr(), and log_failed_request().

Referenced by apply_acls().

◆ ast_pjsip_rdata_get_endpoint()

struct ast_sip_endpoint * ast_pjsip_rdata_get_endpoint ( pjsip_rx_data *  rdata)

Get the looked-up endpoint on an out-of dialog request or response.

The function may ONLY be called on out-of-dialog requests or responses. For in-dialog requests and responses, it is required that the user of the dialog has the looked-up endpoint stored locally.

This function should never return NULL if the message is out-of-dialog. It will always return NULL if the message is in-dialog.

This function will increase the reference count of the returned endpoint by one. Release your reference using the ao2_ref function when finished.

Parameters
rdataOut-of-dialog request or response
Returns
The looked up endpoint

Definition at line 1015 of file pjsip_distributor.c.

1016{
1017 struct ast_sip_endpoint *endpoint = rdata->endpt_info.mod_data[endpoint_mod.id];
1018 if (endpoint) {
1019 ao2_ref(endpoint, +1);
1020 }
1021 return endpoint;
1022}
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
Definition astobj2.h:459

References ao2_ref, and endpoint_mod.

Referenced by authenticate(), handle_new_invite_request(), maintenance_on_rx_request(), nat_on_rx_message(), options_on_rx_request(), pubsub_on_rx_mwi_notify_request(), pubsub_on_rx_publish_request(), pubsub_on_rx_refresh(), pubsub_on_rx_subscribe_request(), registrar_on_rx_request(), rx_data_to_ast_msg(), send_options_response(), send_response(), and supplement_on_rx_request().

◆ ast_sip_destroy_distributor()

void ast_sip_destroy_distributor ( void  )

Definition at line 1365 of file pjsip_distributor.c.

1366{
1369
1373
1374 ao2_global_obj_release(artificial_auth);
1376
1378
1379 if (prune_context) {
1381 }
1382
1384
1387}
void ast_cli_unregister_multiple(void)
Definition ael_main.c:408
#define ao2_cleanup(obj)
Definition astobj2.h:1934
#define ao2_global_obj_release(holder)
Release the ao2 object held in the global holder.
Definition astobj2.h:859
static struct ast_sorcery_observer global_observer
Observer which is used to update our interval and default_realm when the global setting changes.
static pjsip_module distributor_mod
static void distributor_pool_shutdown(void)
static struct ao2_container * unidentified_requests
static struct ast_cli_entry cli_commands[]
static pjsip_module auth_mod
struct ast_sched_context * prune_context
struct ast_sip_cli_formatter_entry * unid_formatter
static struct ao2_container * dialog_associations
void ast_sip_unregister_service(pjsip_module *module)
Definition res_pjsip.c:127
int ast_sip_unregister_cli_formatter(struct ast_sip_cli_formatter_entry *formatter)
Unregisters a CLI formatter.
Definition pjsip_cli.c:326
void ast_sched_context_destroy(struct ast_sched_context *c)
destroys a schedule context
Definition sched.c:271
void ast_sorcery_observer_remove(const struct ast_sorcery *sorcery, const char *type, const struct ast_sorcery_observer *callbacks)
Remove an observer from a specific object type.
Definition sorcery.c:2487
#define ARRAY_LEN(a)
Definition utils.h:706

References ao2_cleanup, ao2_global_obj_release, ARRAY_LEN, artificial_endpoint, ast_cli_unregister_multiple(), ast_sched_context_destroy(), ast_sip_get_sorcery(), ast_sip_unregister_cli_formatter(), ast_sip_unregister_service(), ast_sorcery_observer_remove(), auth_mod, cli_commands, dialog_associations, distributor_mod, distributor_pool_shutdown(), endpoint_mod, global_observer, prune_context, unid_formatter, and unidentified_requests.

Referenced by ast_sip_initialize_distributor(), and unload_pjsip().

◆ ast_sip_get_artificial_auth()

struct ast_sip_auth * ast_sip_get_artificial_auth ( void  )

Retrieves a reference to the artificial auth.

Return values
Theartificial auth

Definition at line 677 of file pjsip_distributor.c.

678{
679 return ao2_global_obj_ref(artificial_auth);
680}
#define ao2_global_obj_ref(holder)
Get a reference to the object stored in the global holder.
Definition astobj2.h:918

References ao2_global_obj_ref.

Referenced by digest_check_auth().

◆ ast_sip_get_artificial_endpoint()

struct ast_sip_endpoint * ast_sip_get_artificial_endpoint ( void  )

Retrieves a reference to the artificial endpoint.

Return values
Theartificial endpoint

Definition at line 700 of file pjsip_distributor.c.

701{
703 return artificial_endpoint;
704}

References ao2_ref, and artificial_endpoint.

Referenced by digest_check_auth(), digest_requires_authentication(), endpoint_lookup(), and get_account_id().

◆ ast_sip_initialize_distributor()

int ast_sip_initialize_distributor ( void  )

Definition at line 1291 of file pjsip_distributor.c.

1292{
1295 if (!unidentified_requests) {
1296 return -1;
1297 }
1298
1302 if (!dialog_associations) {
1304 return -1;
1305 }
1306
1307 if (distributor_pool_setup()) {
1309 return -1;
1310 }
1311
1313 if (!prune_context) {
1315 return -1;
1316 }
1317
1320 return -1;
1321 }
1322
1325
1328 return -1;
1329 }
1330
1333 return -1;
1334 }
1337 return -1;
1338 }
1341 return -1;
1342 }
1343
1346 if (!unid_formatter) {
1348 ast_log(LOG_ERROR, "Unable to allocate memory for unid_formatter\n");
1349 return -1;
1350 }
1351 unid_formatter->name = "unidentified_request";
1359
1361
1362 return 0;
1363}
#define ast_log
Definition astobj2.c:42
@ AO2_ALLOC_OPT_LOCK_NOLOCK
Definition astobj2.h:367
@ AO2_ALLOC_OPT_LOCK_RWLOCK
Definition astobj2.h:365
#define ao2_alloc_options(data_size, destructor_fn, options)
Definition astobj2.h:404
#define ao2_container_alloc_hash(ao2_options, container_options, n_buckets, hash_fn, sort_fn, cmp_fn)
Allocate and initialize a hash container with the desired number of buckets.
Definition astobj2.h:1303
#define ast_cli_register_multiple(e, len)
Register multiple commands.
Definition cli.h:265
#define LOG_ERROR
static int dialog_associations_hash(const void *obj, int flags)
static int cli_unid_iterate(void *container, ao2_callback_fn callback, void *args)
static int cli_unid_print_header(void *obj, void *arg, int flags)
#define DIALOG_ASSOCIATIONS_BUCKETS
static struct ao2_container * cli_unid_get_container(const char *regex)
static int cli_unid_print_body(void *obj, void *arg, int flags)
static int suspects_hash(const void *obj, int flags)
static void * cli_unid_retrieve_by_id(const char *id)
static int suspects_compare(void *obj, void *arg, int flags)
static int create_artificial_endpoint(void)
static int dialog_associations_cmp(void *obj, void *arg, int flags)
void ast_sip_destroy_distributor(void)
static int create_artificial_auth(void)
static const char * cli_unid_get_id(const void *obj)
static int distributor_pool_setup(void)
#define DEFAULT_SUSPECTS_BUCKETS
int ast_sip_register_service(pjsip_module *module)
Register a SIP service in Asterisk.
Definition res_pjsip.c:111
int ast_sip_register_cli_formatter(struct ast_sip_cli_formatter_entry *formatter)
Registers a CLI formatter.
Definition pjsip_cli.c:310
int ast_sched_start_thread(struct ast_sched_context *con)
Start a thread for processing scheduler entries.
Definition sched.c:197
struct ast_sched_context * ast_sched_context_create(void)
Create a scheduler context.
Definition sched.c:238
int ast_sorcery_observer_add(const struct ast_sorcery *sorcery, const char *type, const struct ast_sorcery_observer *callbacks)
Add an observer to a specific object type.
Definition sorcery.c:2455
void ast_sorcery_reload_object(const struct ast_sorcery *sorcery, const char *type)
Inform any wizards of a specific object type to reload persistent objects.
Definition sorcery.c:1506
CLI Formatter Registry Entry.
int(* iterate)(void *container, ao2_callback_fn callback, void *args)
ao2_callback_fn * print_header
void *(* retrieve_by_id)(const char *id)
const char *(* get_id)(const void *obj)
const char * name
ao2_callback_fn * print_body
struct ao2_container *(* get_container)(const char *regex)

References AO2_ALLOC_OPT_LOCK_NOLOCK, AO2_ALLOC_OPT_LOCK_RWLOCK, ao2_alloc_options, ao2_container_alloc_hash, ARRAY_LEN, ast_cli_register_multiple, ast_log, ast_sched_context_create(), ast_sched_start_thread(), ast_sip_destroy_distributor(), ast_sip_get_sorcery(), ast_sip_register_cli_formatter(), ast_sip_register_service(), ast_sorcery_observer_add(), ast_sorcery_reload_object(), auth_mod, cli_commands, cli_unid_get_container(), cli_unid_get_id(), cli_unid_iterate(), cli_unid_print_body(), cli_unid_print_header(), cli_unid_retrieve_by_id(), create_artificial_auth(), create_artificial_endpoint(), DEFAULT_SUSPECTS_BUCKETS, dialog_associations, DIALOG_ASSOCIATIONS_BUCKETS, dialog_associations_cmp(), dialog_associations_hash(), distributor_mod, distributor_pool_setup(), endpoint_mod, ast_sip_cli_formatter_entry::get_container, ast_sip_cli_formatter_entry::get_id, global_observer, ast_sip_cli_formatter_entry::iterate, LOG_ERROR, ast_sip_cli_formatter_entry::name, NULL, ast_sip_cli_formatter_entry::print_body, ast_sip_cli_formatter_entry::print_header, prune_context, ast_sip_cli_formatter_entry::retrieve_by_id, suspects_compare(), suspects_hash(), unid_formatter, and unidentified_requests.

Referenced by load_module().

◆ authenticate()

static pj_bool_t authenticate ( pjsip_rx_data *  rdata)
static

Definition at line 926 of file pjsip_distributor.c.

927{
929 int is_ack = rdata->msg_info.msg->line.req.method.id == PJSIP_ACK_METHOD;
930
931 ast_assert(endpoint != NULL);
932
933 if (is_ack) {
934 return PJ_FALSE;
935 }
936
937 if (ast_sip_requires_authentication(endpoint, rdata)) {
938 pjsip_tx_data *tdata;
939 struct unidentified_request *unid;
940
941 pjsip_endpt_create_response(ast_sip_get_pjsip_endpoint(), rdata, 401, NULL, &tdata);
942 switch (ast_sip_check_authentication(endpoint, rdata, tdata)) {
944 /* Send the 401 we created for them */
945 ast_sip_report_auth_challenge_sent(endpoint, rdata, tdata);
946 if (pjsip_endpt_send_response2(ast_sip_get_pjsip_endpoint(), rdata, tdata, NULL, NULL) != PJ_SUCCESS) {
947 pjsip_tx_data_dec_ref(tdata);
948 }
949 return PJ_TRUE;
951 /* See note in endpoint_lookup about not holding an unnecessary write lock */
952 unid = ao2_find(unidentified_requests, rdata->pkt_info.src_name, OBJ_SEARCH_KEY);
953 if (unid) {
955 ao2_ref(unid, -1);
956 }
957 ast_sip_report_auth_success(endpoint, rdata);
958 break;
960 log_failed_request(rdata, "Failed to authenticate", 0, 0);
962 if (pjsip_endpt_send_response2(ast_sip_get_pjsip_endpoint(), rdata, tdata, NULL, NULL) != PJ_SUCCESS) {
963 pjsip_tx_data_dec_ref(tdata);
964 }
965 return PJ_TRUE;
967 log_failed_request(rdata, "Error to authenticate", 0, 0);
969 pjsip_tx_data_dec_ref(tdata);
970 pjsip_endpt_respond_stateless(ast_sip_get_pjsip_endpoint(), rdata, 500, NULL, NULL, NULL);
971 return PJ_TRUE;
972 }
973 pjsip_tx_data_dec_ref(tdata);
974 } else if (endpoint == artificial_endpoint) {
975 /* Uh. Oh. The artificial endpoint couldn't challenge so block the request. */
976 pjsip_endpt_respond_stateless(ast_sip_get_pjsip_endpoint(), rdata, 500, NULL, NULL, NULL);
977 return PJ_TRUE;
978 }
979
980 return PJ_FALSE;
981}
#define ao2_unlink(container, obj)
Remove an object from a container.
Definition astobj2.h:1578
#define ao2_find(container, arg, flags)
Definition astobj2.h:1736
@ OBJ_SEARCH_KEY
The arg parameter is a search key, but is not an object.
Definition astobj2.h:1101
struct ast_sip_endpoint * ast_pjsip_rdata_get_endpoint(pjsip_rx_data *rdata)
Get the looked-up endpoint on an out-of dialog request or response.
int ast_sip_requires_authentication(struct ast_sip_endpoint *endpoint, pjsip_rx_data *rdata)
Determine if an incoming request requires authentication.
Definition res_pjsip.c:157
void ast_sip_report_auth_success(struct ast_sip_endpoint *endpoint, pjsip_rx_data *rdata)
Send a security event notification for when authentication succeeds.
void ast_sip_report_auth_challenge_sent(struct ast_sip_endpoint *endpoint, pjsip_rx_data *rdata, pjsip_tx_data *tdata)
Send a security event notification for when an authentication challenge is sent.
enum ast_sip_check_auth_result ast_sip_check_authentication(struct ast_sip_endpoint *endpoint, pjsip_rx_data *rdata, pjsip_tx_data *tdata)
Method to determine authentication status of an incoming request.
Definition res_pjsip.c:173
pjsip_endpoint * ast_sip_get_pjsip_endpoint(void)
Get a pointer to the PJSIP endpoint.
Definition res_pjsip.c:518
void ast_sip_report_auth_failed_challenge_response(struct ast_sip_endpoint *endpoint, pjsip_rx_data *rdata)
Send a security event notification for when a challenge response has failed.
@ AST_SIP_AUTHENTICATION_CHALLENGE
Definition res_pjsip.h:1341
@ AST_SIP_AUTHENTICATION_ERROR
Definition res_pjsip.h:1347
@ AST_SIP_AUTHENTICATION_SUCCESS
Definition res_pjsip.h:1343
@ AST_SIP_AUTHENTICATION_FAILED
Definition res_pjsip.h:1345
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
Definition utils.h:981
#define ast_assert(a)
Definition utils.h:779

References ao2_cleanup, ao2_find, ao2_ref, ao2_unlink, artificial_endpoint, ast_assert, ast_pjsip_rdata_get_endpoint(), AST_SIP_AUTHENTICATION_CHALLENGE, AST_SIP_AUTHENTICATION_ERROR, AST_SIP_AUTHENTICATION_FAILED, AST_SIP_AUTHENTICATION_SUCCESS, ast_sip_check_authentication(), ast_sip_get_pjsip_endpoint(), ast_sip_report_auth_challenge_sent(), ast_sip_report_auth_failed_challenge_response(), ast_sip_report_auth_success(), ast_sip_requires_authentication(), log_failed_request(), NULL, OBJ_SEARCH_KEY, RAII_VAR, and unidentified_requests.

◆ buf_hash()

static int buf_hash ( const char *  pos,
size_t  len 
)
static

Definition at line 207 of file pjsip_distributor.c.

208{
209 return buf_hash_add(pos, len, 5381);
210}
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
static int buf_hash_add(const char *pos, size_t len, int hash)

References buf_hash_add(), and len().

Referenced by dialog_associations_hash().

◆ buf_hash_add()

static int buf_hash_add ( const char *  pos,
size_t  len,
int  hash 
)
static

Definition at line 181 of file pjsip_distributor.c.

182{
183 while (len--) {
184 hash = hash * 33 ^ *pos++;
185 }
186
187 return hash;
188}

References len().

Referenced by buf_hash(), and pjstr_hash_add().

◆ check_endpoint()

static void check_endpoint ( pjsip_rx_data *  rdata,
struct unidentified_request unid,
const char *  name 
)
static

Definition at line 729 of file pjsip_distributor.c.

731{
732 int64_t ms = ast_tvdiff_ms(ast_tvnow(), unid->first_seen);
733
734 ao2_wrlock(unid);
735 unid->count++;
736
737 if (ms < (unidentified_period * 1000) && unid->count >= unidentified_count) {
738 log_failed_request(rdata, "No matching endpoint found", unid->count, ms);
740 }
741 ao2_unlock(unid);
742}
#define ao2_wrlock(a)
Definition astobj2.h:719
#define ao2_unlock(a)
Definition astobj2.h:729
static const char name[]
Definition format_mp3.c:68
static unsigned int unidentified_period
static unsigned int unidentified_count
void ast_sip_report_invalid_endpoint(const char *name, pjsip_rx_data *rdata)
Send a security event notification for when an invalid endpoint is requested.
struct timeval first_seen
int64_t ast_tvdiff_ms(struct timeval end, struct timeval start)
Computes the difference (in milliseconds) between two struct timeval instances.
Definition time.h:107
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().
Definition time.h:159

References ao2_unlock, ao2_wrlock, ast_sip_report_invalid_endpoint(), ast_tvdiff_ms(), ast_tvnow(), unidentified_request::count, unidentified_request::first_seen, log_failed_request(), name, unidentified_count, and unidentified_period.

Referenced by endpoint_lookup().

◆ clean_task()

static int clean_task ( const void *  data)
static

Definition at line 1206 of file pjsip_distributor.c.

1207{
1208 return 0;
1209}

Referenced by global_loaded().

◆ cli_unid_get_container()

static struct ao2_container * cli_unid_get_container ( const char *  regex)
static

Definition at line 1097 of file pjsip_distributor.c.

1098{
1099 struct ao2_container *s_container;
1100
1103 if (!s_container) {
1104 return NULL;
1105 }
1106
1107 if (ao2_container_dup(s_container, unidentified_requests, 0)) {
1108 ao2_ref(s_container, -1);
1109 return NULL;
1110 }
1111
1112 return s_container;
1113}
int ao2_container_dup(struct ao2_container *dest, struct ao2_container *src, enum search_flags flags)
Copy all object references in the src container into the dest container.
#define ao2_container_alloc_list(ao2_options, container_options, sort_fn, cmp_fn)
Allocate and initialize a list container.
Definition astobj2.h:1327
static int suspects_sort(const void *obj, const void *arg, int flags)
Generic container type.

References AO2_ALLOC_OPT_LOCK_NOLOCK, ao2_container_alloc_list, ao2_container_dup(), ao2_ref, NULL, suspects_compare(), suspects_sort(), and unidentified_requests.

Referenced by ast_sip_initialize_distributor().

◆ cli_unid_get_id()

static const char * cli_unid_get_id ( const void *  obj)
static

Definition at line 1127 of file pjsip_distributor.c.

1128{
1129 const struct unidentified_request *unid = obj;
1130
1131 return unid->src_name;
1132}

References unidentified_request::src_name.

Referenced by ast_sip_initialize_distributor().

◆ cli_unid_iterate()

static int cli_unid_iterate ( void *  container,
ao2_callback_fn  callback,
void *  args 
)
static

Definition at line 1115 of file pjsip_distributor.c.

1116{
1118
1119 return 0;
1120}
#define ao2_callback(c, flags, cb_fn, arg)
ao2_callback() is a generic function that applies cb_fn() to all objects in a container,...
Definition astobj2.h:1693
static struct ast_channel * callback(struct ast_channelstorage_instance *driver, ao2_callback_data_fn *cb_fn, void *arg, void *data, int ao2_flags, int rdlock)
struct ao2_container * container
Definition res_fax.c:603
static struct @522 args

References ao2_callback, args, callback(), and container.

Referenced by ast_sip_initialize_distributor().

◆ cli_unid_print_body()

static int cli_unid_print_body ( void *  obj,
void *  arg,
int  flags 
)
static

Definition at line 1151 of file pjsip_distributor.c.

1152{
1153 struct unidentified_request *unid = obj;
1154 struct ast_sip_cli_context *context = arg;
1155 int indent;
1156 int flexwidth;
1157 int64_t ms = ast_tvdiff_ms(ast_tvnow(), unid->first_seen);
1158
1159 ast_assert(context->output_buffer != NULL);
1160
1161 indent = CLI_INDENT_TO_SPACES(context->indent_level);
1162 flexwidth = CLI_LAST_TABSTOP - 4;
1163
1164 ast_str_append(&context->output_buffer, 0, "%*s: %-*.*s %7d %10.3f\n",
1165 indent,
1166 "Request",
1167 flexwidth, flexwidth,
1168 unid->src_name, unid->count, ms / 1000.0);
1169
1170 return 0;
1171}
#define CLI_LAST_TABSTOP
#define CLI_INDENT_TO_SPACES(x)
int ast_str_append(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Append to a thread local dynamic string.
Definition strings.h:1139
CLI Formatter Context passed to all formatters.

References ast_assert, ast_str_append(), ast_tvdiff_ms(), ast_tvnow(), CLI_INDENT_TO_SPACES, CLI_LAST_TABSTOP, unidentified_request::count, unidentified_request::first_seen, NULL, and unidentified_request::src_name.

Referenced by ast_sip_initialize_distributor().

◆ cli_unid_print_header()

static int cli_unid_print_header ( void *  obj,
void *  arg,
int  flags 
)
static

Definition at line 1134 of file pjsip_distributor.c.

1135{
1136 struct ast_sip_cli_context *context = arg;
1137 RAII_VAR(struct ast_sip_cli_formatter_entry *, formatter_entry, NULL, ao2_cleanup);
1138
1139 int indent = CLI_INDENT_TO_SPACES(context->indent_level);
1140 int filler = CLI_LAST_TABSTOP - indent - 7;
1141
1142 ast_assert(context->output_buffer != NULL);
1143
1144 ast_str_append(&context->output_buffer, 0,
1145 "%*s: <IP Address%*.*s> <Count> <Age(sec)>\n",
1146 indent, "Request", filler, filler, CLI_HEADER_FILLER);
1147
1148 return 0;
1149}
#define CLI_HEADER_FILLER

References ao2_cleanup, ast_assert, ast_str_append(), CLI_HEADER_FILLER, CLI_INDENT_TO_SPACES, CLI_LAST_TABSTOP, NULL, and RAII_VAR.

Referenced by ast_sip_initialize_distributor().

◆ cli_unid_retrieve_by_id()

static void * cli_unid_retrieve_by_id ( const char *  id)
static

Definition at line 1122 of file pjsip_distributor.c.

1123{
1125}

References ao2_find, OBJ_SEARCH_KEY, and unidentified_requests.

Referenced by ast_sip_initialize_distributor().

◆ create_artificial_auth()

static int create_artificial_auth ( void  )
static

Definition at line 653 of file pjsip_distributor.c.

654{
656 struct ast_sip_auth *fake_auth;
657 char default_algos_uac[AST_SIP_AUTH_MAX_SUPPORTED_ALGORITHMS_LENGTH + 1];
658 char default_algos_uas[AST_SIP_AUTH_MAX_SUPPORTED_ALGORITHMS_LENGTH + 1];
659
662 sizeof(default_algos_uac));
664 sizeof(default_algos_uas));
665
666 fake_auth = alloc_artificial_auth(default_realm, default_algos_uac,
667 default_algos_uas);
668 if (!fake_auth) {
669 ast_log(LOG_ERROR, "Unable to create artificial auth\n");
670 return -1;
671 }
672 ao2_global_obj_replace_unref(artificial_auth, fake_auth);
673 ao2_cleanup(fake_auth);
674 return 0;
675}
#define ao2_global_obj_replace_unref(holder, obj)
Replace an ao2 object in the global holder, throwing away any old object.
Definition astobj2.h:901
static struct ast_sip_auth * alloc_artificial_auth(char *default_realm, char *default_algos_uac, char *default_algos_uas)
void ast_sip_get_default_realm(char *realm, size_t size)
Retrieve the global default realm.
#define AST_SIP_AUTH_MAX_REALM_LENGTH
Definition res_pjsip.h:74
#define AST_SIP_AUTH_MAX_SUPPORTED_ALGORITHMS_LENGTH
Definition res_pjsip.h:75
void ast_sip_get_default_auth_algorithms_uac(char *default_auth_algorithms_uac, size_t size)
Retrieve the global auth algorithms for UAC.
void ast_sip_get_default_auth_algorithms_uas(char *default_auth_algorithms_uas, size_t size)
Retrieve the global auth algorithms for UAS.

References alloc_artificial_auth(), ao2_cleanup, ao2_global_obj_replace_unref, ast_log, AST_SIP_AUTH_MAX_REALM_LENGTH, AST_SIP_AUTH_MAX_SUPPORTED_ALGORITHMS_LENGTH, ast_sip_get_default_auth_algorithms_uac(), ast_sip_get_default_auth_algorithms_uas(), ast_sip_get_default_realm(), default_realm, and LOG_ERROR.

Referenced by ast_sip_initialize_distributor(), and global_loaded().

◆ create_artificial_endpoint()

static int create_artificial_endpoint ( void  )
static

Definition at line 684 of file pjsip_distributor.c.

685{
687 if (!artificial_endpoint) {
688 return -1;
689 }
690
692 /* Pushing a bogus value into the vector will ensure that
693 * the proper size of the vector is returned. This value is
694 * not actually used anywhere
695 */
697 return 0;
698}
#define ast_strdup(str)
A wrapper for strdup()
Definition astmm.h:241
struct ast_sip_auth_vector inbound_auths
Definition res_pjsip.h:1112
#define AST_VECTOR_INIT(vec, size)
Initialize a vector.
Definition vector.h:124
#define AST_VECTOR_APPEND(vec, elem)
Append an element to a vector, growing the vector if needed.
Definition vector.h:267

References artificial_endpoint, ast_sip_get_sorcery(), ast_sorcery_alloc(), ast_strdup, AST_VECTOR_APPEND, AST_VECTOR_INIT, ast_sip_endpoint::inbound_auths, and NULL.

Referenced by ast_sip_initialize_distributor().

◆ dialog_associations_cmp()

static int dialog_associations_cmp ( void *  obj,
void *  arg,
int  flags 
)
static

Definition at line 236 of file pjsip_distributor.c.

237{
238 const struct distributor_dialog_data *object_left = obj;
239 const struct distributor_dialog_data *object_right = arg;
240 const pjsip_dialog *right_key = arg;
241 int cmp = 0;
242
243 switch (flags & OBJ_SEARCH_MASK) {
245 right_key = object_right->dlg;
246 /* Fall through */
247 case OBJ_SEARCH_KEY:
248 if (object_left->dlg == right_key) {
249 cmp = CMP_MATCH;
250 }
251 break;
253 /* There is no such thing for this container. */
254 ast_assert(0);
255 break;
256 default:
257 cmp = 0;
258 break;
259 }
260 return cmp;
261}
@ CMP_MATCH
Definition astobj2.h:1027
@ OBJ_SEARCH_PARTIAL_KEY
The arg parameter is a partial search key similar to OBJ_SEARCH_KEY.
Definition astobj2.h:1116
@ OBJ_SEARCH_OBJECT
The arg parameter is an object of the same type.
Definition astobj2.h:1087
@ OBJ_SEARCH_MASK
Search option field mask.
Definition astobj2.h:1072

References ast_assert, CMP_MATCH, distributor_dialog_data::dlg, OBJ_SEARCH_KEY, OBJ_SEARCH_MASK, OBJ_SEARCH_OBJECT, and OBJ_SEARCH_PARTIAL_KEY.

Referenced by ast_sip_initialize_distributor().

◆ dialog_associations_hash()

static int dialog_associations_hash ( const void *  obj,
int  flags 
)
static

Definition at line 212 of file pjsip_distributor.c.

213{
214 const struct distributor_dialog_data *object;
215 union {
216 const pjsip_dialog *dlg;
217 const char buf[sizeof(pjsip_dialog *)];
218 } key;
219
220 switch (flags & OBJ_SEARCH_MASK) {
221 case OBJ_SEARCH_KEY:
222 key.dlg = obj;
223 break;
225 object = obj;
226 key.dlg = object->dlg;
227 break;
228 default:
229 /* Hash can only work on something with a full key. */
230 ast_assert(0);
231 return 0;
232 }
233 return ast_str_hash_restrict(buf_hash(key.buf, sizeof(key.buf)));
234}
char buf[BUFSIZE]
Definition eagi_proxy.c:66
static int buf_hash(const char *pos, size_t len)
static force_inline int attribute_pure ast_str_hash_restrict(unsigned int hash)
Restrict hash value range.
Definition strings.h:1246

References ast_assert, ast_str_hash_restrict(), buf, buf_hash(), distributor_dialog_data::dlg, OBJ_SEARCH_KEY, OBJ_SEARCH_MASK, and OBJ_SEARCH_OBJECT.

Referenced by ast_sip_initialize_distributor().

◆ distribute()

static int distribute ( void *  data)
static

Definition at line 989 of file pjsip_distributor.c.

990{
991 static pjsip_process_rdata_param param = {
992 .start_mod = &distributor_mod,
993 .idx_after_start = 1,
994 };
995 pj_bool_t handled = PJ_FALSE;
996 pjsip_rx_data *rdata = data;
997 int is_request = rdata->msg_info.msg->type == PJSIP_REQUEST_MSG;
998 int is_ack = is_request ? rdata->msg_info.msg->line.req.method.id == PJSIP_ACK_METHOD : 0;
999 struct ast_sip_endpoint *endpoint;
1000
1001 pjsip_endpt_process_rx_data(ast_sip_get_pjsip_endpoint(), rdata, &param, &handled);
1002 if (!handled && is_request && !is_ack) {
1003 pjsip_endpt_respond_stateless(ast_sip_get_pjsip_endpoint(), rdata, 501, NULL, NULL, NULL);
1004 }
1005
1006 /* The endpoint_mod stores an endpoint reference in the mod_data of rdata. This
1007 * is the only appropriate spot to actually decrement the reference.
1008 */
1009 endpoint = rdata->endpt_info.mod_data[endpoint_mod.id];
1010 ao2_cleanup(endpoint);
1011 pjsip_rx_data_free_cloned(rdata);
1012 return 0;
1013}

References ao2_cleanup, ast_sip_get_pjsip_endpoint(), distributor_mod, endpoint_mod, and NULL.

Referenced by distributor().

◆ distributor()

static pj_bool_t distributor ( pjsip_rx_data *  rdata)
static

Definition at line 516 of file pjsip_distributor.c.

517{
518 pjsip_dialog *dlg;
519 struct distributor_dialog_data *dist = NULL;
521 pjsip_rx_data *clone;
522
523 if (!ast_fully_booted) {
524 /*
525 * Ignore everything until we are fully booted. Let the
526 * peer retransmit messages until we are ready.
527 */
528 return PJ_TRUE;
529 }
530
531 dlg = find_dialog(rdata);
532 if (dlg) {
533 ast_debug(3, "Searching for serializer associated with dialog %s for %s\n",
534 dlg->obj_name, pjsip_rx_data_get_info(rdata));
536 if (dist) {
537 ao2_lock(dist);
539 ao2_unlock(dist);
540 if (serializer) {
541 ast_debug(3, "Found serializer %s associated with dialog %s\n",
542 ast_taskprocessor_name(serializer), dlg->obj_name);
543 }
544 }
545 }
546
547 if (serializer) {
548 /* We have a serializer so we know where to send the message. */
549 } else if (rdata->msg_info.msg->type == PJSIP_RESPONSE_MSG) {
550 ast_debug(3, "No dialog serializer for %s. Using request transaction as basis.\n",
551 pjsip_rx_data_get_info(rdata));
553 if (!serializer) {
554 /*
555 * Pick a serializer for the unmatched response.
556 * We couldn't determine what serializer originally
557 * sent the request or the serializer is gone.
558 */
560 }
561 } else if (!pjsip_method_cmp(&rdata->msg_info.msg->line.req.method, &pjsip_cancel_method)
562 || !pjsip_method_cmp(&rdata->msg_info.msg->line.req.method, &pjsip_bye_method)) {
563 /* We have a BYE or CANCEL request without a serializer. */
564 pjsip_endpt_respond_stateless(ast_sip_get_pjsip_endpoint(), rdata,
565 PJSIP_SC_CALL_TSX_DOES_NOT_EXIST, NULL, NULL, NULL);
566 ao2_cleanup(dist);
567 return PJ_TRUE;
568 } else {
573 /*
574 * When taskprocessors get backed up, there is a good chance that
575 * we are being overloaded and need to defer adding new work to
576 * the system. To defer the work we will ignore the request and
577 * rely on the peer's transport layer to retransmit the message.
578 * We usually work off the overload within a few seconds.
579 * If transport is non-UDP we send a 503 response instead.
580 */
581 switch (rdata->tp_info.transport->key.type) {
582 case PJSIP_TRANSPORT_UDP6:
583 case PJSIP_TRANSPORT_UDP:
584 ast_debug(3, "Taskprocessor overload alert: Ignoring '%s'.\n",
585 pjsip_rx_data_get_info(rdata));
586 break;
587 default:
588 ast_debug(3, "Taskprocessor overload on non-udp transport. Received:'%s'. "
589 "Responding with a 503.\n", pjsip_rx_data_get_info(rdata));
590 pjsip_endpt_respond_stateless(ast_sip_get_pjsip_endpoint(), rdata,
591 PJSIP_SC_SERVICE_UNAVAILABLE, NULL, NULL, NULL);
592 break;
593 }
594 ao2_cleanup(dist);
595 return PJ_TRUE;
596 }
597
598 /* Pick a serializer for the out-of-dialog request. */
600 }
601
602 if (pjsip_rx_data_clone(rdata, 0, &clone) != PJ_SUCCESS) {
604 ao2_cleanup(dist);
605 return PJ_TRUE;
606 }
607
608 if (dist) {
609 ao2_lock(dist);
610 clone->endpt_info.mod_data[endpoint_mod.id] = ao2_bump(dist->endpoint);
611 ao2_unlock(dist);
612 ao2_cleanup(dist);
613 }
614
616 ao2_cleanup(clone->endpt_info.mod_data[endpoint_mod.id]);
617 pjsip_rx_data_free_cloned(clone);
618 }
619
621
622 return PJ_TRUE;
623}
#define ao2_lock(a)
Definition astobj2.h:717
#define ao2_bump(obj)
Bump refcount on an AO2 object by one, returning the object.
Definition astobj2.h:480
struct ast_taskprocessor * ast_sip_get_distributor_serializer(pjsip_rx_data *rdata)
Determine the distributor serializer for the SIP message.
#define ast_sip_push_task(serializer, sip_task, task_data)
Definition res_pjsip.h:2126
#define ast_fully_booted
Definition options.h:127
static int distribute(void *data)
static enum ast_sip_taskprocessor_overload_trigger overload_trigger
static pjsip_dialog * find_dialog(pjsip_rx_data *rdata)
static struct ast_taskprocessor * find_request_serializer(pjsip_rx_data *rdata)
@ TASKPROCESSOR_OVERLOAD_TRIGGER_GLOBAL
@ TASKPROCESSOR_OVERLOAD_TRIGGER_PJSIP_ONLY
A ast_taskprocessor structure is a singleton by name.
struct ast_sip_endpoint * endpoint
struct ast_taskprocessor * serializer
void * ast_taskprocessor_unreference(struct ast_taskprocessor *tps)
Unreference the specified taskprocessor and its reference count will decrement.
unsigned int ast_taskprocessor_alert_get(void)
Get the current taskprocessor high water alert count.
unsigned int ast_taskprocessor_get_subsystem_alert(const char *subsystem)
Get the current taskprocessor high water alert count by subsystem.
const char * ast_taskprocessor_name(struct ast_taskprocessor *tps)
Return the name of the taskprocessor singleton.

References ao2_bump, ao2_cleanup, ao2_find, ao2_lock, ao2_unlock, ast_debug, ast_fully_booted, ast_sip_get_distributor_serializer(), ast_sip_get_pjsip_endpoint(), ast_sip_push_task, ast_taskprocessor_alert_get(), ast_taskprocessor_get_subsystem_alert(), ast_taskprocessor_name(), ast_taskprocessor_unreference(), dialog_associations, distribute(), distributor_dialog_data::endpoint, endpoint_mod, find_dialog(), find_request_serializer(), NULL, OBJ_SEARCH_KEY, overload_trigger, distributor_dialog_data::serializer, TASKPROCESSOR_OVERLOAD_TRIGGER_GLOBAL, and TASKPROCESSOR_OVERLOAD_TRIGGER_PJSIP_ONLY.

◆ distributor_pool_setup()

static int distributor_pool_setup ( void  )
static

Definition at line 1274 of file pjsip_distributor.c.

1275{
1276 char tps_name[AST_TASKPROCESSOR_MAX_NAME + 1];
1277 int idx;
1278
1279 for (idx = 0; idx < ARRAY_LEN(distributor_pool); ++idx) {
1280 /* Create name with seq number appended. */
1281 ast_taskprocessor_build_name(tps_name, sizeof(tps_name), "pjsip/distributor");
1282
1284 if (!distributor_pool[idx]) {
1285 return -1;
1286 }
1287 }
1288 return 0;
1289}
struct ast_taskprocessor * ast_sip_create_serializer(const char *name)
Create a new serializer for SIP tasks.
Definition res_pjsip.c:2092
static struct ast_taskprocessor * distributor_pool[DISTRIBUTOR_POOL_SIZE]
void ast_taskprocessor_build_name(char *buf, unsigned int size, const char *format,...)
Build a taskprocessor name with a sequence number on the end.
#define AST_TASKPROCESSOR_MAX_NAME
Suggested maximum taskprocessor name length (less null terminator).

References ARRAY_LEN, ast_sip_create_serializer(), ast_taskprocessor_build_name(), AST_TASKPROCESSOR_MAX_NAME, and distributor_pool.

Referenced by ast_sip_initialize_distributor().

◆ distributor_pool_shutdown()

static void distributor_pool_shutdown ( void  )
static

Definition at line 1256 of file pjsip_distributor.c.

1257{
1258 int idx;
1259
1260 for (idx = 0; idx < ARRAY_LEN(distributor_pool); ++idx) {
1262 distributor_pool[idx] = NULL;
1263 }
1264}

References ARRAY_LEN, ast_taskprocessor_unreference(), distributor_pool, and NULL.

Referenced by ast_sip_destroy_distributor().

◆ endpoint_lookup()

static pj_bool_t endpoint_lookup ( pjsip_rx_data *  rdata)
static

Definition at line 764 of file pjsip_distributor.c.

765{
766 struct ast_sip_endpoint *endpoint;
767 struct unidentified_request *unid;
768 int is_ack = rdata->msg_info.msg->line.req.method.id == PJSIP_ACK_METHOD;
769
770 endpoint = rdata->endpt_info.mod_data[endpoint_mod.id];
771 if (endpoint) {
772 /*
773 * ao2_find with OBJ_UNLINK always write locks the container before even searching
774 * for the object. Since the majority case is that the object won't be found, do
775 * the find without OBJ_UNLINK to prevent the unnecessary write lock, then unlink
776 * if needed.
777 */
778 unid = ao2_find(unidentified_requests, rdata->pkt_info.src_name, OBJ_SEARCH_KEY);
779 if (unid) {
781 ao2_ref(unid, -1);
782 }
783 apply_acls(rdata);
784 return PJ_FALSE;
785 }
786
787 endpoint = ast_sip_identify_endpoint(rdata);
788 if (endpoint) {
789 unid = ao2_find(unidentified_requests, rdata->pkt_info.src_name, OBJ_SEARCH_KEY);
790 if (unid) {
792 ao2_ref(unid, -1);
793 }
794 }
795
796 if (!endpoint) {
797 /* always use an artificial endpoint - per discussion no reason
798 to have "alwaysauthreject" as an option. It is felt using it
799 was a bug fix and it is not needed since we are not worried about
800 breaking old stuff and we really don't want to enable the discovery
801 of SIP accounts */
803 }
804
805 /* endpoint ref held by mod_data[] */
806 rdata->endpt_info.mod_data[endpoint_mod.id] = endpoint;
807
808 if (endpoint == artificial_endpoint && !is_ack) {
809 char name[AST_UUID_STR_LEN] = "";
810 pjsip_uri *from = rdata->msg_info.from->uri;
811
812 if (ast_sip_is_allowed_uri(from)) {
814 }
815
816 unid = ao2_find(unidentified_requests, rdata->pkt_info.src_name, OBJ_SEARCH_KEY);
817 if (unid) {
818 check_endpoint(rdata, unid, name);
819 ao2_ref(unid, -1);
820 } else if (using_auth_username) {
822 /* Checking again with the write lock held allows us to eliminate the DUPS_REPLACE and sort_fn */
823 unid = ao2_find(unidentified_requests, rdata->pkt_info.src_name,
825 if (unid) {
826 check_endpoint(rdata, unid, name);
827 } else {
828 unid = ao2_alloc_options(sizeof(*unid) + strlen(rdata->pkt_info.src_name) + 1,
830 if (!unid) {
832 pjsip_endpt_respond_stateless(ast_sip_get_pjsip_endpoint(), rdata, 500, NULL, NULL, NULL);
833 return PJ_TRUE;
834 }
835 strcpy(unid->src_name, rdata->pkt_info.src_name); /* Safe */
836 unid->first_seen = ast_tvnow();
837 unid->count = 1;
839 }
840 ao2_ref(unid, -1);
842 } else {
843 log_failed_request(rdata, "No matching endpoint found", 0, 0);
845 }
846 }
847
848 apply_acls(rdata);
849 return PJ_FALSE;
850}
#define ao2_link_flags(container, obj, flags)
Add an object to a container.
Definition astobj2.h:1554
@ OBJ_NOLOCK
Assume that the ao2_container is already locked.
Definition astobj2.h:1063
struct ast_sip_endpoint * ast_sip_get_artificial_endpoint(void)
Retrieves a reference to the artificial endpoint.
static void check_endpoint(pjsip_rx_data *rdata, struct unidentified_request *unid, const char *name)
static void apply_acls(pjsip_rx_data *rdata)
static int using_auth_username
const pj_str_t * ast_sip_pjsip_uri_get_username(pjsip_uri *uri)
Get the user portion of the pjsip_uri.
Definition res_pjsip.c:3452
int ast_sip_is_allowed_uri(pjsip_uri *uri)
Check whether a pjsip_uri is allowed or not.
Definition res_pjsip.c:3447
void ast_copy_pj_str(char *dest, const pj_str_t *src, size_t size)
Copy a pj_str_t into a standard character buffer.
Definition res_pjsip.c:2176
struct ast_sip_endpoint * ast_sip_identify_endpoint(pjsip_rx_data *rdata)
Determine the endpoint that has sent a SIP message.
Definition res_pjsip.c:324
#define AST_UUID_STR_LEN
Definition uuid.h:27

References AO2_ALLOC_OPT_LOCK_RWLOCK, ao2_alloc_options, ao2_find, ao2_link_flags, ao2_ref, ao2_unlink, ao2_unlock, ao2_wrlock, apply_acls(), artificial_endpoint, ast_copy_pj_str(), ast_sip_get_artificial_endpoint(), ast_sip_get_pjsip_endpoint(), ast_sip_identify_endpoint(), ast_sip_is_allowed_uri(), ast_sip_pjsip_uri_get_username(), ast_sip_report_invalid_endpoint(), ast_tvnow(), AST_UUID_STR_LEN, check_endpoint(), unidentified_request::count, endpoint_mod, unidentified_request::first_seen, log_failed_request(), name, NULL, OBJ_NOLOCK, OBJ_SEARCH_KEY, unidentified_request::src_name, unidentified_requests, and using_auth_username.

◆ expire_requests()

static int expire_requests ( void *  object,
void *  arg,
int  flags 
)
static

Definition at line 1182 of file pjsip_distributor.c.

1183{
1184 struct unidentified_request *unid = object;
1185 int *maxage = arg;
1186 int64_t ms = ast_tvdiff_ms(ast_tvnow(), unid->first_seen);
1187
1188 if (ms > (*maxage) * 2 * 1000) {
1189 return CMP_MATCH;
1190 }
1191
1192 return 0;
1193}

References ast_tvdiff_ms(), ast_tvnow(), CMP_MATCH, and unidentified_request::first_seen.

Referenced by prune_task().

◆ extract_contact_addr()

static int extract_contact_addr ( pjsip_contact_hdr *  contact,
struct ast_sockaddr **  addrs 
)
static

Definition at line 872 of file pjsip_distributor.c.

873{
874 pjsip_sip_uri *sip_uri;
875 char host[256];
876
877 if (!contact || contact->star) {
878 *addrs = NULL;
879 return 0;
880 }
881
882 if (!PJSIP_URI_SCHEME_IS_SIP(contact->uri) && !PJSIP_URI_SCHEME_IS_SIPS(contact->uri)) {
883 *addrs = NULL;
884 return 0;
885 }
886 sip_uri = pjsip_uri_get_uri(contact->uri);
887 ast_copy_pj_str(host, &sip_uri->host, sizeof(host));
889}
int ast_sockaddr_resolve(struct ast_sockaddr **addrs, const char *str, int flags, int family)
Parses a string with an IPv4 or IPv6 address and place results into an array.
Definition netsock2.c:280
@ AST_AF_UNSPEC
Definition netsock2.h:54

References AST_AF_UNSPEC, ast_copy_pj_str(), ast_sockaddr_resolve(), NULL, and PARSE_PORT_FORBID.

Referenced by apply_endpoint_contact_acl().

◆ find_dialog()

static pjsip_dialog * find_dialog ( pjsip_rx_data *  rdata)
static

Definition at line 336 of file pjsip_distributor.c.

337{
338 pj_str_t tsx_key;
339 pjsip_transaction *tsx;
340 pjsip_dialog *dlg;
341 pj_str_t *local_tag;
342 pj_str_t *remote_tag;
343
344 if (!rdata->msg_info.msg) {
345 return NULL;
346 }
347
348 if (rdata->msg_info.msg->type == PJSIP_REQUEST_MSG) {
349 local_tag = &rdata->msg_info.to->tag;
350 remote_tag = &rdata->msg_info.from->tag;
351 } else {
352 local_tag = &rdata->msg_info.from->tag;
353 remote_tag = &rdata->msg_info.to->tag;
354 }
355
356 /* We can only call the convenient method for
357 * 1) responses
358 * 2) non-CANCEL requests
359 * 3) CANCEL requests with a to-tag
360 */
361 if (rdata->msg_info.msg->type == PJSIP_RESPONSE_MSG ||
362 pjsip_method_cmp(&rdata->msg_info.msg->line.req.method, &pjsip_cancel_method) ||
363 rdata->msg_info.to->tag.slen != 0) {
364 dlg = pjsip_ua_find_dialog(&rdata->msg_info.cid->id, local_tag,
365 remote_tag, PJ_FALSE);
366 if (dlg) {
367 return dlg;
368 }
369 }
370
371 /*
372 * There may still be a matching dialog if this is
373 * 1) an incoming CANCEL request without a to-tag
374 * 2) an incoming response to a dialog-creating request.
375 */
376 if (rdata->msg_info.msg->type == PJSIP_REQUEST_MSG) {
377 /* CANCEL requests will need to match the INVITE we initially received. Any
378 * other request type will either have been matched already or is not in
379 * dialog
380 */
381 pjsip_tsx_create_key(rdata->tp_info.pool, &tsx_key, PJSIP_ROLE_UAS,
382 pjsip_get_invite_method(), rdata);
383 } else {
384 pjsip_tsx_create_key(rdata->tp_info.pool, &tsx_key, PJSIP_ROLE_UAC,
385 &rdata->msg_info.cseq->method, rdata);
386 }
387
388 tsx = pjsip_tsx_layer_find_tsx(&tsx_key, PJ_TRUE);
389 if (!tsx) {
390 ast_debug(3, "Could not find matching transaction for %s\n",
391 pjsip_rx_data_get_info(rdata));
392 return NULL;
393 }
394
395 dlg = pjsip_tsx_get_dlg(tsx);
396
397#ifdef HAVE_PJ_TRANSACTION_GRP_LOCK
398 pj_grp_lock_release(tsx->grp_lock);
399#else
400 pj_mutex_unlock(tsx->mutex);
401#endif
402
403 return dlg;
404}

References ast_debug, and NULL.

Referenced by distributor().

◆ find_request_serializer()

static struct ast_taskprocessor * find_request_serializer ( pjsip_rx_data *  rdata)
static

Definition at line 109 of file pjsip_distributor.c.

110{
112 pj_str_t tsx_key;
113 pjsip_transaction *tsx;
114
115 pjsip_tsx_create_key(rdata->tp_info.pool, &tsx_key, PJSIP_ROLE_UAC,
116 &rdata->msg_info.cseq->method, rdata);
117
118 tsx = pjsip_tsx_layer_find_tsx(&tsx_key, PJ_TRUE);
119 if (!tsx) {
120 ast_debug(1, "Could not find transaction for %s.\n",
121 pjsip_rx_data_get_info(rdata));
122 return NULL;
123 }
124 ast_debug(3, "Found transaction %s for %s.\n",
125 tsx->obj_name, pjsip_rx_data_get_info(rdata));
126
127 if (tsx->last_tx) {
128 const char *serializer_name;
129
130 serializer_name = tsx->last_tx->mod_data[distributor_mod.id];
131 if (!ast_strlen_zero(serializer_name)) {
133 if (serializer) {
134 ast_debug(3, "Found serializer %s on transaction %s\n",
135 serializer_name, tsx->obj_name);
136 }
137 }
138 }
139
140#ifdef HAVE_PJ_TRANSACTION_GRP_LOCK
141 pj_grp_lock_release(tsx->grp_lock);
142#else
143 pj_mutex_unlock(tsx->mutex);
144#endif
145
146 return serializer;
147}
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition strings.h:65
struct ast_taskprocessor * ast_taskprocessor_get(const char *name, enum ast_tps_options create)
Get a reference to a taskprocessor with the specified name and create the taskprocessor if necessary.
@ TPS_REF_IF_EXISTS
return a reference to a taskprocessor ONLY if it already exists

References ast_debug, ast_strlen_zero(), ast_taskprocessor_get(), distributor_mod, NULL, and TPS_REF_IF_EXISTS.

Referenced by distributor().

◆ global_loaded()

static void global_loaded ( const char *  object_type)
static

Definition at line 1211 of file pjsip_distributor.c.

1212{
1213 char *identifier_order;
1214
1215 /* Update using_auth_username */
1216 identifier_order = ast_sip_get_endpoint_identifier_order();
1217 if (identifier_order) {
1218 char *identify_method;
1219 char *io_copy = ast_strdupa(identifier_order);
1220 int new_using = 0;
1221
1222 ast_free(identifier_order);
1223 while ((identify_method = ast_strip(strsep(&io_copy, ",")))) {
1224 if (!strcmp(identify_method, "auth_username")) {
1225 new_using = 1;
1226 break;
1227 }
1228 }
1229 using_auth_username = new_using;
1230 }
1231
1233
1235
1237
1238 /* Clean out the old task, if any */
1240 /* Have to do something with the return value to shut up the stupid compiler. */
1242 return;
1243 }
1244}
char * strsep(char **str, const char *delims)
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition astmm.h:298
enum ast_sip_taskprocessor_overload_trigger ast_sip_get_taskprocessor_overload_trigger(void)
static int prune_task(const void *data)
static unsigned int unidentified_prune_interval
static int clean_task(const void *data)
char * ast_sip_get_endpoint_identifier_order(void)
Retrieve the global endpoint_identifier_order setting.
void ast_sip_get_unidentified_request_thresholds(unsigned int *count, unsigned int *period, unsigned int *prune_interval)
Retrieve the unidentified request security event thresholds.
void ast_sched_clean_by_callback(struct ast_sched_context *con, ast_sched_cb match, ast_sched_cb cleanup_cb)
Clean all scheduled events with matching callback.
Definition sched.c:409
int ast_sched_add_variable(struct ast_sched_context *con, int when, ast_sched_cb callback, const void *data, int variable) attribute_warn_unused_result
Adds a scheduled event with rescheduling support.
Definition sched.c:526
char * ast_strip(char *s)
Strip leading/trailing whitespace from a string.
Definition strings.h:223

References ast_free, ast_sched_add_variable(), ast_sched_clean_by_callback(), ast_sip_get_endpoint_identifier_order(), ast_sip_get_taskprocessor_overload_trigger(), ast_sip_get_unidentified_request_thresholds(), ast_strdupa, ast_strip(), clean_task(), create_artificial_auth(), NULL, overload_trigger, prune_context, prune_task(), strsep(), unidentified_count, unidentified_period, unidentified_prune_interval, and using_auth_username.

◆ log_failed_request()

static void log_failed_request ( pjsip_rx_data *  rdata,
char *  msg,
unsigned int  count,
unsigned int  period 
)
static

Definition at line 706 of file pjsip_distributor.c.

707{
708 char from_buf[PJSIP_MAX_URL_SIZE];
709 char callid_buf[PJSIP_MAX_URL_SIZE];
710 char method_buf[PJSIP_MAX_URL_SIZE];
711 char src_addr_buf[AST_SOCKADDR_BUFLEN];
712 pjsip_uri_print(PJSIP_URI_IN_FROMTO_HDR, rdata->msg_info.from->uri, from_buf, PJSIP_MAX_URL_SIZE);
713 ast_copy_pj_str(callid_buf, &rdata->msg_info.cid->id, PJSIP_MAX_URL_SIZE);
714 ast_copy_pj_str(method_buf, &rdata->msg_info.msg->line.req.method.name, PJSIP_MAX_URL_SIZE);
715 if (count) {
716 ast_log(LOG_NOTICE, "Request '%s' from '%s' failed for '%s' (callid: %s) - %s"
717 " after %u tries in %.3f ms\n",
718 method_buf, from_buf,
719 pj_sockaddr_print(&rdata->pkt_info.src_addr, src_addr_buf, sizeof(src_addr_buf), 3),
720 callid_buf, msg, count, period / 1000.0);
721 } else {
722 ast_log(LOG_NOTICE, "Request '%s' from '%s' failed for '%s' (callid: %s) - %s\n",
723 method_buf, from_buf,
724 pj_sockaddr_print(&rdata->pkt_info.src_addr, src_addr_buf, sizeof(src_addr_buf), 3),
725 callid_buf, msg);
726 }
727}
#define LOG_NOTICE
#define AST_SOCKADDR_BUFLEN
Definition netsock2.h:46

References ast_copy_pj_str(), ast_log, AST_SOCKADDR_BUFLEN, and LOG_NOTICE.

Referenced by apply_endpoint_acl(), apply_endpoint_contact_acl(), authenticate(), check_endpoint(), and endpoint_lookup().

◆ pjstr_hash()

static int pjstr_hash ( pj_str_t *  str)
static

Definition at line 440 of file pjsip_distributor.c.

441{
442 return pjstr_hash_add(str, 5381);
443}
const char * str
Definition app_jack.c:150
static int pjstr_hash_add(pj_str_t *str, int hash)

References pjstr_hash_add(), and str.

Referenced by ast_sip_get_distributor_serializer(), and ast_sip_get_distributor_serializer_dialog().

◆ pjstr_hash_add()

static int pjstr_hash_add ( pj_str_t *  str,
int  hash 
)
static

Definition at line 423 of file pjsip_distributor.c.

424{
425 return buf_hash_add(pj_strbuf(str), pj_strlen(str), hash);
426}

References buf_hash_add(), and str.

Referenced by ast_sip_get_distributor_serializer(), ast_sip_get_distributor_serializer_dialog(), and pjstr_hash().

◆ prune_task()

static int prune_task ( const void *  data)
static

◆ record_serializer()

static pj_status_t record_serializer ( pjsip_tx_data *  tdata)
static

Definition at line 74 of file pjsip_distributor.c.

75{
77
79 if (serializer) {
80 const char *name;
81
84 && (!tdata->mod_data[distributor_mod.id]
85 || strcmp(tdata->mod_data[distributor_mod.id], name))) {
86 char *tdata_name;
87
88 /* The serializer in use changed. */
89 tdata_name = pj_pool_alloc(tdata->pool, strlen(name) + 1);
90 strcpy(tdata_name, name);/* Safe */
91
92 tdata->mod_data[distributor_mod.id] = tdata_name;
93 }
94 }
95
96 return PJ_SUCCESS;
97}
struct ast_taskprocessor * ast_taskpool_serializer_get_current(void)
Get the taskpool serializer currently associated with this thread.
Definition taskpool.c:842

References ast_strlen_zero(), ast_taskpool_serializer_get_current(), ast_taskprocessor_name(), distributor_mod, and name.

◆ suspects_compare()

static int suspects_compare ( void *  obj,
void *  arg,
int  flags 
)
static

Definition at line 1048 of file pjsip_distributor.c.

1049{
1050 const struct unidentified_request *object_left = obj;
1051 const struct unidentified_request *object_right = arg;
1052 const char *right_key = arg;
1053 int cmp = 0;
1054
1055 switch (flags & OBJ_SEARCH_MASK) {
1056 case OBJ_SEARCH_OBJECT:
1057 right_key = object_right->src_name;
1058 /* Fall through */
1059 case OBJ_SEARCH_KEY:
1060 if (strcmp(object_left->src_name, right_key) == 0) {
1061 cmp = CMP_MATCH;
1062 }
1063 break;
1065 if (strncmp(object_left->src_name, right_key, strlen(right_key)) == 0) {
1066 cmp = CMP_MATCH;
1067 }
1068 break;
1069 default:
1070 cmp = 0;
1071 break;
1072 }
1073 return cmp;
1074}

References CMP_MATCH, OBJ_SEARCH_KEY, OBJ_SEARCH_MASK, OBJ_SEARCH_OBJECT, OBJ_SEARCH_PARTIAL_KEY, and unidentified_request::src_name.

Referenced by ast_sip_initialize_distributor(), and cli_unid_get_container().

◆ suspects_hash()

static int suspects_hash ( const void *  obj,
int  flags 
)
static

Definition at line 1076 of file pjsip_distributor.c.

1077{
1078 const struct unidentified_request *object;
1079 const char *key;
1080
1081 switch (flags & OBJ_SEARCH_MASK) {
1082 case OBJ_SEARCH_KEY:
1083 key = obj;
1084 break;
1085 case OBJ_SEARCH_OBJECT:
1086 object = obj;
1087 key = object->src_name;
1088 break;
1089 default:
1090 /* Hash can only work on something with a full key. */
1091 ast_assert(0);
1092 return 0;
1093 }
1094 return ast_str_hash(key);
1095}
static force_inline int attribute_pure ast_str_hash(const char *str)
Compute a hash value on a string.
Definition strings.h:1259

References ast_assert, ast_str_hash(), OBJ_SEARCH_KEY, OBJ_SEARCH_MASK, OBJ_SEARCH_OBJECT, and unidentified_request::src_name.

Referenced by ast_sip_initialize_distributor().

◆ suspects_sort()

static int suspects_sort ( const void *  obj,
const void *  arg,
int  flags 
)
static

Definition at line 1024 of file pjsip_distributor.c.

1025{
1026 const struct unidentified_request *object_left = obj;
1027 const struct unidentified_request *object_right = arg;
1028 const char *right_key = arg;
1029 int cmp;
1030
1031 switch (flags & OBJ_SEARCH_MASK) {
1032 case OBJ_SEARCH_OBJECT:
1033 right_key = object_right->src_name;
1034 /* Fall through */
1035 case OBJ_SEARCH_KEY:
1036 cmp = strcmp(object_left->src_name, right_key);
1037 break;
1039 cmp = strncmp(object_left->src_name, right_key, strlen(right_key));
1040 break;
1041 default:
1042 cmp = 0;
1043 break;
1044 }
1045 return cmp;
1046}

References OBJ_SEARCH_KEY, OBJ_SEARCH_MASK, OBJ_SEARCH_OBJECT, OBJ_SEARCH_PARTIAL_KEY, and unidentified_request::src_name.

Referenced by cli_unid_get_container().

Variable Documentation

◆ artificial_endpoint

struct ast_sip_endpoint* artificial_endpoint = NULL
static

◆ auth_mod

pjsip_module auth_mod
static
Initial value:
= {
.name = {"Request Authenticator", 21},
.priority = PJSIP_MOD_PRIORITY_APPLICATION - 2,
.on_rx_request = authenticate,
}
static pj_bool_t authenticate(pjsip_rx_data *rdata)

Definition at line 983 of file pjsip_distributor.c.

983 {
984 .name = {"Request Authenticator", 21},
985 .priority = PJSIP_MOD_PRIORITY_APPLICATION - 2,
986 .on_rx_request = authenticate,
987};

Referenced by ast_sip_destroy_distributor(), and ast_sip_initialize_distributor().

◆ cli_commands

struct ast_cli_entry cli_commands[]
static

Definition at line 1173 of file pjsip_distributor.c.

1173 {
1174 AST_CLI_DEFINE(ast_sip_cli_traverse_objects, "Show PJSIP Unidentified Requests",
1175 .command = "pjsip show unidentified_requests",
1176 .usage = "Usage: pjsip show unidentified_requests\n"
1177 " Show the PJSIP Unidentified Requests\n"),
1178};
#define AST_CLI_DEFINE(fn, txt,...)
Definition cli.h:197
char * ast_sip_cli_traverse_objects(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
Definition pjsip_cli.c:109
char * usage
Definition utils/frame.c:37

Referenced by ast_sip_destroy_distributor(), and ast_sip_initialize_distributor().

◆ dialog_associations

struct ao2_container* dialog_associations
static

◆ distributor_mod

pjsip_module distributor_mod
static

Definition at line 34 of file pjsip_distributor.c.

34 {
35 .name = {"Request Distributor", 19},
36 .priority = PJSIP_MOD_PRIORITY_TSX_LAYER - 6,
37 .on_tx_request = record_serializer,
38 .on_rx_request = distributor,
39 .on_rx_response = distributor,
40};
static pj_status_t record_serializer(pjsip_tx_data *tdata)
static pj_bool_t distributor(pjsip_rx_data *rdata)

Referenced by ast_sip_destroy_distributor(), ast_sip_initialize_distributor(), distribute(), find_request_serializer(), and record_serializer().

◆ distributor_pool

struct ast_taskprocessor* distributor_pool[DISTRIBUTOR_POOL_SIZE]
static

◆ endpoint_mod

pjsip_module endpoint_mod
static
Initial value:
= {
.name = {"Endpoint Identifier", 19},
.priority = PJSIP_MOD_PRIORITY_TSX_LAYER - 3,
.on_rx_request = endpoint_lookup,
}
static pj_bool_t endpoint_lookup(pjsip_rx_data *rdata)

Definition at line 510 of file pjsip_distributor.c.

510 {
511 .name = {"Endpoint Identifier", 19},
512 .priority = PJSIP_MOD_PRIORITY_TSX_LAYER - 3,
513 .on_rx_request = endpoint_lookup,
514};

Referenced by apply_acls(), ast_pjsip_rdata_get_endpoint(), ast_sip_destroy_distributor(), ast_sip_initialize_distributor(), distribute(), distributor(), and endpoint_lookup().

◆ global_observer

struct ast_sorcery_observer global_observer
static
Initial value:
= {
.loaded = global_loaded,
}
static void global_loaded(const char *object_type)

Observer which is used to update our interval and default_realm when the global setting changes.

Definition at line 1247 of file pjsip_distributor.c.

1247 {
1248 .loaded = global_loaded,
1249};

Referenced by ast_sip_destroy_distributor(), and ast_sip_initialize_distributor().

◆ overload_trigger

enum ast_sip_taskprocessor_overload_trigger overload_trigger
static

Definition at line 51 of file pjsip_distributor.c.

Referenced by distributor(), and global_loaded().

◆ prune_context

struct ast_sched_context* prune_context

◆ unid_formatter

struct ast_sip_cli_formatter_entry* unid_formatter

◆ unidentified_count

unsigned int unidentified_count
static

Definition at line 47 of file pjsip_distributor.c.

Referenced by check_endpoint(), global_loaded(), and prune_task().

◆ unidentified_period

unsigned int unidentified_period
static

Definition at line 48 of file pjsip_distributor.c.

Referenced by check_endpoint(), global_loaded(), and prune_task().

◆ unidentified_prune_interval

unsigned int unidentified_prune_interval
static

Definition at line 49 of file pjsip_distributor.c.

Referenced by global_loaded(), and prune_task().

◆ unidentified_requests

struct ao2_container* unidentified_requests
static

◆ using_auth_username

int using_auth_username
static

Definition at line 50 of file pjsip_distributor.c.

Referenced by endpoint_lookup(), and global_loaded().