Asterisk - The Open Source Telephony Project  18.5.0
Data Structures | Macros | Functions | Variables
config_transport.c File Reference
#include "asterisk.h"
#include <math.h>
#include <pjsip.h>
#include <pjlib.h>
#include "asterisk/res_pjsip.h"
#include "asterisk/res_pjsip_cli.h"
#include "asterisk/logger.h"
#include "asterisk/astobj2.h"
#include "asterisk/sorcery.h"
#include "asterisk/acl.h"
#include "asterisk/utils.h"
#include "include/res_pjsip_private.h"
#include "asterisk/http_websocket.h"
Include dependency graph for config_transport.c:

Go to the source code of this file.

Data Structures

struct  internal_state
 

Macros

#define BIND_DELAY_US   100000
 
#define BIND_TRIES   3
 
#define DEFAULT_STATE_BUCKETS   53
 Default number of state container buckets. More...
 
#define MAX_POINTER_STRING   33
 

Functions

static void __init_temp_state_store (void)
 
int ast_sip_destroy_sorcery_transport (void)
 
struct ast_sip_transport_stateast_sip_get_transport_state (const char *transport_id)
 Retrieve transport state. More...
 
struct ao2_containerast_sip_get_transport_states (void)
 Retrieves all transport states. More...
 
int ast_sip_initialize_sorcery_transport (void)
 Initialize sorcery with transport support. More...
 
void ast_sip_message_apply_transport (const char *transport_name, pjsip_tx_data *tdata)
 Apply the configuration for a transport to an outgoing message. More...
 
struct ast_sip_service_route_vector * ast_sip_service_route_vector_alloc (void)
 Allocate a vector of service routes. More...
 
void ast_sip_service_route_vector_destroy (struct ast_sip_service_route_vector *service_routes)
 Destroy a vector of service routes. More...
 
int ast_sip_transport_state_set_preferred_identity (const char *transport_name, const char *identity)
 Sets the P-Preferred-Identity on a child transport. More...
 
int ast_sip_transport_state_set_service_routes (const char *transport_name, struct ast_sip_service_route_vector *service_routes)
 Sets the service routes on a child transport. More...
 
int ast_sip_transport_state_set_transport (const char *transport_name, pjsip_transport *transport)
 Sets the PJSIP transport on a child transport. More...
 
static int ca_list_file_to_str (const void *obj, const intptr_t *args, char **buf)
 
static int ca_list_path_to_str (const void *obj, const intptr_t *args, char **buf)
 
static int cert_file_to_str (const void *obj, const intptr_t *args, char **buf)
 
static struct ao2_containercli_get_container (const char *regex)
 
static int cli_iterate (void *container, ao2_callback_fn callback, void *args)
 
static int cli_print_body (void *obj, void *arg, int flags)
 
static int cli_print_header (void *obj, void *arg, int flags)
 
static void * cli_retrieve_by_id (const char *id)
 
static void copy_state_to_transport (struct ast_sip_transport *transport)
 
static int destroy_sip_transport_state (void *data)
 
static struct internal_statefind_internal_state_by_transport (const struct ast_sip_transport *transport)
 
static struct ast_sip_transport_statefind_or_create_temporary_state (struct ast_sip_transport *transport)
 
static struct ast_sip_transport_statefind_state_by_transport (const struct ast_sip_transport *transport)
 
static struct ast_sip_transport_statefind_temporary_state (struct ast_sip_transport *transport)
 
static int format_ami_endpoint_transport (const struct ast_sip_endpoint *endpoint, struct ast_sip_ami *ami)
 
static int has_state_changed (struct ast_sip_transport_state *a, struct ast_sip_transport_state *b)
 
static struct internal_stateinternal_state_alloc (struct ast_sip_transport *transport)
 
static int internal_state_cmp (void *obj, void *arg, int flags)
 comparator function for state objects More...
 
static void internal_state_destroy (void *obj)
 Destructor for ast_sip_transport state information. More...
 
static int internal_state_hash (const void *obj, const int flags)
 hashing function for state objects More...
 
static int localnet_to_str (const void *obj, const intptr_t *args, char **buf)
 
static int localnet_to_vl (const void *obj, struct ast_variable **fields)
 
static void localnet_to_vl_append (struct ast_variable **head, struct ast_ha *ha)
 
static int populate_transport_states (void *obj, void *arg, int flags)
 
static int privkey_file_to_str (const void *obj, const intptr_t *args, char **buf)
 
static int remove_temporary_state (void)
 
static int require_client_cert_to_str (const void *obj, const intptr_t *args, char **buf)
 
static void set_qos (struct ast_sip_transport *transport, pj_qos_params *qos)
 
static void * sip_transport_alloc (const char *name)
 Allocator for transport. More...
 
static void sip_transport_destroy (void *obj)
 Destructor for transport. More...
 
static void sip_transport_state_destroy (void *obj)
 Destructor for ast_sip_transport state information. More...
 
static int sip_transport_to_ami (const struct ast_sip_transport *transport, struct ast_str **buf)
 
static void states_cleanup (void *states)
 
static void temp_state_store_cleanup (void *data)
 
static int tls_method_to_str (const void *obj, const intptr_t *args, char **buf)
 
static int tos_to_str (const void *obj, const intptr_t *args, char **buf)
 
static int transport_apply (const struct ast_sorcery *sorcery, void *obj)
 Apply handler for transports. More...
 
static int transport_bind_handler (const struct aco_option *opt, struct ast_variable *var, void *obj)
 Custom handler for turning a string bind into a pj_sockaddr. More...
 
static int transport_bind_to_str (const void *obj, const intptr_t *args, char **buf)
 
static int transport_localnet_handler (const struct aco_option *opt, struct ast_variable *var, void *obj)
 Helper function which turns a cipher name into an identifier. More...
 
static int transport_protocol_handler (const struct aco_option *opt, struct ast_variable *var, void *obj)
 Custom handler for turning a string protocol into an enum. More...
 
static int transport_protocol_to_str (const void *obj, const intptr_t *args, char **buf)
 
static int transport_state_cmp (void *obj, void *arg, int flags)
 comparator function for state objects More...
 
static int transport_state_hash (const void *obj, const int flags)
 hashing function for state objects More...
 
static int transport_state_init (const struct aco_option *opt, struct ast_variable *var, void *obj)
 Custom handler for type just makes sure the state is created. More...
 
static int transport_tls_bool_handler (const struct aco_option *opt, struct ast_variable *var, void *obj)
 Custom handler for TLS boolean settings. More...
 
static int transport_tls_file_handler (const struct aco_option *opt, struct ast_variable *var, void *obj)
 Custom handler for TLS method setting. More...
 
static int transport_tls_method_handler (const struct aco_option *opt, struct ast_variable *var, void *obj)
 Custom handler for TLS method setting. More...
 
static int transport_tos_handler (const struct aco_option *opt, struct ast_variable *var, void *obj)
 Custom handler for TOS setting. More...
 
static int verify_client_to_str (const void *obj, const intptr_t *args, char **buf)
 
static int verify_server_to_str (const void *obj, const intptr_t *args, char **buf)
 

Variables

static struct ast_cli_entry cli_commands []
 
static struct ast_sip_cli_formatter_entrycli_formatter
 
struct ast_sip_endpoint_formatter endpoint_transport_formatter
 
static struct ast_threadstorage temp_state_store = { .once = PTHREAD_ONCE_INIT , .key_init = __init_temp_state_store , .custom_init = NULL , }
 
static const char * tls_method_map []
 
static struct ao2_containertransport_states
 
static const char * transport_types []
 

Macro Definition Documentation

◆ BIND_DELAY_US

#define BIND_DELAY_US   100000

Referenced by transport_apply().

◆ BIND_TRIES

#define BIND_TRIES   3

Referenced by transport_apply().

◆ DEFAULT_STATE_BUCKETS

#define DEFAULT_STATE_BUCKETS   53

Default number of state container buckets.

Definition at line 39 of file config_transport.c.

Referenced by ast_sip_get_transport_states(), and ast_sip_initialize_sorcery_transport().

◆ MAX_POINTER_STRING

#define MAX_POINTER_STRING   33

Definition at line 36 of file config_transport.c.

Function Documentation

◆ __init_temp_state_store()

static void __init_temp_state_store ( void  )
static

Definition at line 60 of file config_transport.c.

64 {

◆ ast_sip_destroy_sorcery_transport()

int ast_sip_destroy_sorcery_transport ( void  )

Definition at line 1692 of file config_transport.c.

References ao2_ref, ARRAY_LEN, ast_cli_unregister_multiple(), ast_sip_unregister_cli_formatter(), ast_sip_unregister_endpoint_formatter(), and NULL.

Referenced by ast_res_pjsip_destroy_configuration().

1693 {
1696 
1698 
1701 
1702  return 0;
1703 }
#define ARRAY_LEN(a)
Definition: isdn_lib.c:42
int ast_cli_unregister_multiple(struct ast_cli_entry *e, int len)
Unregister multiple commands.
Definition: clicompat.c:30
static struct ao2_container * transport_states
void ast_sip_unregister_endpoint_formatter(struct ast_sip_endpoint_formatter *obj)
Unregister an endpoint formatter.
Definition: res_pjsip.c:3685
#define NULL
Definition: resample.c:96
#define ao2_ref(o, delta)
Definition: astobj2.h:464
int ast_sip_unregister_cli_formatter(struct ast_sip_cli_formatter_entry *formatter)
Unregisters a CLI formatter.
Definition: pjsip_cli.c:326
struct ast_sip_endpoint_formatter endpoint_transport_formatter
static struct ast_sip_cli_formatter_entry * cli_formatter
static struct ast_cli_entry cli_commands[]

◆ ast_sip_get_transport_state()

struct ast_sip_transport_state* ast_sip_get_transport_state ( const char *  transport_id)

Retrieve transport state.

Since
13.7.1
Parameters
transport_id
Returns
transport_state
Note
ao2_cleanup(...) or ao2_ref(..., -1) must be called on the returned object

Definition at line 1564 of file config_transport.c.

References ao2_bump, ao2_find, ao2_lock, ao2_ref, ao2_unlock, ast_sip_transport_state::flow, NULL, OBJ_SEARCH_KEY, internal_state::state, and ast_sip_transport_state::transport.

Referenced by ast_sip_message_apply_transport(), ast_sip_set_tpselector_from_transport(), ast_sip_transport_state_set_preferred_identity(), ast_sip_transport_state_set_service_routes(), ast_sip_transport_state_set_transport(), change_outgoing_sdp_stream_media_address(), create_rtp(), and session_outgoing_nat_hook().

1565 {
1566  struct internal_state *state = NULL;
1567  struct ast_sip_transport_state *trans_state;
1568 
1569  if (!transport_states) {
1570  return NULL;
1571  }
1572 
1573  state = ao2_find(transport_states, transport_id, OBJ_SEARCH_KEY);
1574  if (!state) {
1575  return NULL;
1576  }
1577 
1578  trans_state = ao2_bump(state->state);
1579  ao2_ref(state, -1);
1580 
1581  /* If this is a child transport see if the transport is actually dead */
1582  if (trans_state->flow) {
1583  ao2_lock(trans_state);
1584  if (trans_state->transport && trans_state->transport->is_shutdown == PJ_TRUE) {
1585  pjsip_transport_dec_ref(trans_state->transport);
1586  trans_state->transport = NULL;
1587  }
1588  ao2_unlock(trans_state);
1589  }
1590 
1591  return trans_state;
1592 }
The arg parameter is a search key, but is not an object.
Definition: astobj2.h:1105
struct ast_sip_transport_state * state
Transport state information.
static struct ao2_container * transport_states
#define ao2_unlock(a)
Definition: astobj2.h:730
#define NULL
Definition: resample.c:96
#define ao2_bump(obj)
Definition: astobj2.h:491
Structure for SIP transport information.
Definition: res_pjsip.h:87
struct pjsip_transport * transport
Transport itself.
Definition: res_pjsip.h:89
#define ao2_ref(o, delta)
Definition: astobj2.h:464
#define ao2_lock(a)
Definition: astobj2.h:718
#define ao2_find(container, arg, flags)
Definition: astobj2.h:1756

◆ ast_sip_get_transport_states()

struct ao2_container* ast_sip_get_transport_states ( void  )

Retrieves all transport states.

Since
13.7.1
Returns
ao2_container
Note
ao2_cleanup(...) or ao2_ref(..., -1) must be called on the returned object

Definition at line 1604 of file config_transport.c.

References AO2_ALLOC_OPT_LOCK_MUTEX, ao2_callback, ao2_container_alloc_hash, DEFAULT_STATE_BUCKETS, NULL, OBJ_MULTIPLE, OBJ_NODATA, populate_transport_states(), transport_state_cmp(), and transport_state_hash().

Referenced by anonymous_identify(), find_endpoint(), get_udp_transport(), get_write_timeout(), and process_nat().

1605 {
1608 
1609  if (!states) {
1610  return NULL;
1611  }
1612 
1614  return states;
1615 }
static int transport_state_cmp(void *obj, void *arg, int flags)
comparator function for state objects
#define ao2_callback(c, flags, cb_fn, arg)
Definition: astobj2.h:1716
static struct ao2_container * transport_states
#define NULL
Definition: resample.c:96
static int transport_state_hash(const void *obj, const int flags)
hashing function for state objects
#define DEFAULT_STATE_BUCKETS
Default number of state container buckets.
static int populate_transport_states(void *obj, void *arg, int flags)
#define ao2_container_alloc_hash(ao2_options, container_options, n_buckets, hash_fn, sort_fn, cmp_fn)
Definition: astobj2.h:1310
Generic container type.

◆ ast_sip_initialize_sorcery_transport()

int ast_sip_initialize_sorcery_transport ( void  )

Initialize sorcery with transport support.

Definition at line 1618 of file config_transport.c.

References ao2_alloc, AO2_ALLOC_OPT_LOCK_MUTEX, ao2_cleanup, ao2_container_alloc_hash, ARRAY_LEN, ast_cli_register_multiple, AST_DEFAULT_WEBSOCKET_WRITE_TIMEOUT_STR, ast_log, AST_RETRIEVE_FLAG_ALL, AST_RETRIEVE_FLAG_MULTIPLE, ast_sip_get_sorcery(), ast_sip_register_cli_formatter(), ast_sip_register_endpoint_formatter(), ast_sorcery_apply_default, ast_sorcery_object_field_register, ast_sorcery_object_field_register_custom, ast_sorcery_object_get_id(), ast_sorcery_object_register, ast_sorcery_retrieve_by_fields(), ca_list_file_to_str(), ca_list_path_to_str(), cert_file_to_str(), cli_get_container(), cli_iterate(), cli_print_body(), cli_print_header(), cli_retrieve_by_id(), cos, DEFAULT_STATE_BUCKETS, FLDSET, ast_sip_cli_formatter_entry::get_container, ast_sip_cli_formatter_entry::get_id, internal_state_cmp(), internal_state_hash(), ast_sip_cli_formatter_entry::iterate, localnet_to_str(), localnet_to_vl(), LOG_ERROR, ast_sip_cli_formatter_entry::name, NULL, OPT_BOOL_T, OPT_INT_T, OPT_STRINGFIELD_T, OPT_UINT_T, PARSE_IN_RANGE, password, ast_sip_cli_formatter_entry::print_body, ast_sip_cli_formatter_entry::print_header, privkey_file_to_str(), require_client_cert_to_str(), ast_sip_cli_formatter_entry::retrieve_by_id, sip_transport_alloc(), sorcery, STRFLDSET, tls_method_to_str(), tos_to_str(), transport_apply(), transport_bind_handler(), transport_bind_to_str(), transport_localnet_handler(), transport_protocol_handler(), transport_protocol_to_str(), transport_state_init(), transport_tls_bool_handler(), transport_tls_file_handler(), transport_tls_method_handler(), transport_tos_handler(), verify_client_to_str(), and verify_server_to_str().

Referenced by ast_res_pjsip_initialize_configuration().

1619 {
1621  struct ao2_container *transports = NULL;
1622 
1623  /* Create outbound registration states container. */
1626  if (!transport_states) {
1627  ast_log(LOG_ERROR, "Unable to allocate transport states container\n");
1628  return -1;
1629  }
1630 
1631  ast_sorcery_apply_default(sorcery, "transport", "config", "pjsip.conf,criteria=type=transport");
1632 
1634  return -1;
1635  }
1636 
1637  /* Normally type is a OPT_NOOP_T but we're using it to make sure that state is created */
1638  ast_sorcery_object_field_register_custom(sorcery, "transport", "type", "", transport_state_init, NULL, NULL, 0, 0);
1641  ast_sorcery_object_field_register(sorcery, "transport", "async_operations", "1", OPT_UINT_T, 0, FLDSET(struct ast_sip_transport, async_operations));
1642 
1643  ast_sorcery_object_field_register_custom(sorcery, "transport", "ca_list_file", "", transport_tls_file_handler, ca_list_file_to_str, NULL, 0, 0);
1644  ast_sorcery_object_field_register_custom(sorcery, "transport", "ca_list_path", "", transport_tls_file_handler, ca_list_path_to_str, NULL, 0, 0);
1645  ast_sorcery_object_field_register_custom(sorcery, "transport", "cert_file", "", transport_tls_file_handler, cert_file_to_str, NULL, 0, 0);
1646  ast_sorcery_object_field_register_custom(sorcery, "transport", "priv_key_file", "", transport_tls_file_handler, privkey_file_to_str, NULL, 0, 0);
1647 
1648  ast_sorcery_object_field_register(sorcery, "transport", "password", "", OPT_STRINGFIELD_T, 0, STRFLDSET(struct ast_sip_transport, password));
1649  ast_sorcery_object_field_register(sorcery, "transport", "external_signaling_address", "", OPT_STRINGFIELD_T, 0, STRFLDSET(struct ast_sip_transport, external_signaling_address));
1650  ast_sorcery_object_field_register(sorcery, "transport", "external_signaling_port", "0", OPT_UINT_T, PARSE_IN_RANGE, FLDSET(struct ast_sip_transport, external_signaling_port), 0, 65535);
1651  ast_sorcery_object_field_register(sorcery, "transport", "external_media_address", "", OPT_STRINGFIELD_T, 0, STRFLDSET(struct ast_sip_transport, external_media_address));
1652  ast_sorcery_object_field_register(sorcery, "transport", "domain", "", OPT_STRINGFIELD_T, 0, STRFLDSET(struct ast_sip_transport, domain));
1653  ast_sorcery_object_field_register_custom(sorcery, "transport", "verify_server", "", transport_tls_bool_handler, verify_server_to_str, NULL, 0, 0);
1654  ast_sorcery_object_field_register_custom(sorcery, "transport", "verify_client", "", transport_tls_bool_handler, verify_client_to_str, NULL, 0, 0);
1655  ast_sorcery_object_field_register_custom(sorcery, "transport", "require_client_cert", "", transport_tls_bool_handler, require_client_cert_to_str, NULL, 0, 0);
1657 #if defined(PJ_HAS_SSL_SOCK) && PJ_HAS_SSL_SOCK != 0
1658  ast_sorcery_object_field_register_custom(sorcery, "transport", "cipher", "", transport_tls_cipher_handler, transport_tls_cipher_to_str, NULL, 0, 0);
1659 #endif
1661  ast_sorcery_object_field_register_custom(sorcery, "transport", "tos", "0", transport_tos_handler, tos_to_str, NULL, 0, 0);
1662  ast_sorcery_object_field_register(sorcery, "transport", "cos", "0", OPT_UINT_T, 0, FLDSET(struct ast_sip_transport, cos));
1663  ast_sorcery_object_field_register(sorcery, "transport", "websocket_write_timeout", AST_DEFAULT_WEBSOCKET_WRITE_TIMEOUT_STR, OPT_INT_T, PARSE_IN_RANGE, FLDSET(struct ast_sip_transport, write_timeout), 1, INT_MAX);
1664  ast_sorcery_object_field_register(sorcery, "transport", "allow_reload", "no", OPT_BOOL_T, 1, FLDSET(struct ast_sip_transport, allow_reload));
1665  ast_sorcery_object_field_register(sorcery, "transport", "symmetric_transport", "no", OPT_BOOL_T, 1, FLDSET(struct ast_sip_transport, symmetric_transport));
1666 
1668 
1670  if (!cli_formatter) {
1671  ast_log(LOG_ERROR, "Unable to allocate memory for cli formatter\n");
1672  return -1;
1673  }
1674  cli_formatter->name = "transport";
1681 
1684 
1685  /* trigger load of transports from realtime by trying to revrieve them all */
1687  ao2_cleanup(transports);
1688 
1689  return 0;
1690 }
struct ao2_container *(* get_container)(const char *regex)
Definition: res_pjsip_cli.h:64
unsigned int cos
Definition: chan_iax2.c:352
#define ARRAY_LEN(a)
Definition: isdn_lib.c:42
static int transport_localnet_handler(const struct aco_option *opt, struct ast_variable *var, void *obj)
Helper function which turns a cipher name into an identifier.
Definition: res_pjsip_cli.h:52
static int transport_bind_to_str(const void *obj, const intptr_t *args, char **buf)
static int transport_bind_handler(const struct aco_option *opt, struct ast_variable *var, void *obj)
Custom handler for turning a string bind into a pj_sockaddr.
static int transport_tls_method_handler(const struct aco_option *opt, struct ast_variable *var, void *obj)
Custom handler for TLS method setting.
static int transport_state_init(const struct aco_option *opt, struct ast_variable *var, void *obj)
Custom handler for type just makes sure the state is created.
static int cli_print_header(void *obj, void *arg, int flags)
static struct ao2_container * transport_states
Perform no matching, return all objects.
Definition: sorcery.h:123
static int cert_file_to_str(const void *obj, const intptr_t *args, char **buf)
Full structure for sorcery.
Definition: sorcery.c:230
int(* iterate)(void *container, ao2_callback_fn callback, void *args)
Definition: res_pjsip_cli.h:66
#define ast_cli_register_multiple(e, len)
Register multiple commands.
Definition: cli.h:265
Return all matching objects.
Definition: sorcery.h:120
static int localnet_to_vl(const void *obj, struct ast_variable **fields)
#define NULL
Definition: resample.c:96
Domain data structure.
Definition: sip.h:888
static struct ast_str * password
Definition: cdr_mysql.c:77
static int verify_client_to_str(const void *obj, const intptr_t *args, char **buf)
static int transport_apply(const struct ast_sorcery *sorcery, void *obj)
Apply handler for transports.
int ast_sip_register_cli_formatter(struct ast_sip_cli_formatter_entry *formatter)
Registers a CLI formatter.
Definition: pjsip_cli.c:310
static int internal_state_hash(const void *obj, const int flags)
hashing function for state objects
#define DEFAULT_STATE_BUCKETS
Default number of state container buckets.
void ast_sip_register_endpoint_formatter(struct ast_sip_endpoint_formatter *obj)
Register an endpoint formatter.
Definition: res_pjsip.c:3679
#define ast_log
Definition: astobj2.c:42
#define ast_sorcery_object_field_register_custom(sorcery, type, name, default_val, config_handler, sorcery_handler, multiple_handler, flags,...)
Register a field within an object with custom handlers.
Definition: sorcery.h:1005
#define FLDSET(type,...)
Convert a struct and list of fields to an argument list of field offsets.
static int require_client_cert_to_str(const void *obj, const intptr_t *args, char **buf)
Type for default option handler for unsigned integers.
static int tls_method_to_str(const void *obj, const intptr_t *args, char **buf)
static int transport_tls_bool_handler(const struct aco_option *opt, struct ast_variable *var, void *obj)
Custom handler for TLS boolean settings.
static void * cli_retrieve_by_id(const char *id)
static void * sip_transport_alloc(const char *name)
Allocator for transport.
const char * ast_sorcery_object_get_id(const void *object)
Get the unique identifier of a sorcery object.
Definition: sorcery.c:2312
void *(* retrieve_by_id)(const char *id)
Definition: res_pjsip_cli.h:68
#define ast_sorcery_object_register(sorcery, type, alloc, transform, apply)
Register an object type.
Definition: sorcery.h:838
static int ca_list_path_to_str(const void *obj, const intptr_t *args, char **buf)
static int verify_server_to_str(const void *obj, const intptr_t *args, char **buf)
static int cli_iterate(void *container, ao2_callback_fn callback, void *args)
#define LOG_ERROR
Definition: logger.h:285
#define ao2_container_alloc_hash(ao2_options, container_options, n_buckets, hash_fn, sort_fn, cmp_fn)
Definition: astobj2.h:1310
Type for default option handler for bools (ast_true/ast_false)
Transport to bind to.
Definition: res_pjsip.h:171
struct ast_sip_endpoint_formatter endpoint_transport_formatter
#define ast_sorcery_apply_default(sorcery, type, name, data)
Definition: sorcery.h:477
static int transport_tos_handler(const struct aco_option *opt, struct ast_variable *var, void *obj)
Custom handler for TOS setting.
static int internal_state_cmp(void *obj, void *arg, int flags)
comparator function for state objects
#define ao2_alloc(data_size, destructor_fn)
Definition: astobj2.h:411
static struct ao2_container * cli_get_container(const char *regex)
static int localnet_to_str(const void *obj, const intptr_t *args, char **buf)
static int transport_protocol_handler(const struct aco_option *opt, struct ast_variable *var, void *obj)
Custom handler for turning a string protocol into an enum.
#define STRFLDSET(type,...)
Convert a struct and a list of stringfield fields to an argument list of field offsets.
const char *(* get_id)(const void *obj)
Definition: res_pjsip_cli.h:70
static int transport_tls_file_handler(const struct aco_option *opt, struct ast_variable *var, void *obj)
Custom handler for TLS method setting.
void * ast_sorcery_retrieve_by_fields(const struct ast_sorcery *sorcery, const char *type, unsigned int flags, struct ast_variable *fields)
Retrieve an object or multiple objects using specific fields.
Definition: sorcery.c:1897
#define ast_sorcery_object_field_register(sorcery, type, name, default_val, opt_type, flags,...)
Register a field within an object.
Definition: sorcery.h:955
static int ca_list_file_to_str(const void *obj, const intptr_t *args, char **buf)
static struct ast_sip_cli_formatter_entry * cli_formatter
static struct ast_sorcery * sorcery
struct ast_sorcery * ast_sip_get_sorcery(void)
Get a pointer to the SIP sorcery structure.
#define ao2_cleanup(obj)
Definition: astobj2.h:1958
#define AST_DEFAULT_WEBSOCKET_WRITE_TIMEOUT_STR
Default websocket write timeout, in ms (as a string)
Type for default option handler for stringfields.
static int tos_to_str(const void *obj, const intptr_t *args, char **buf)
ao2_callback_fn * print_header
Definition: res_pjsip_cli.h:60
static int privkey_file_to_str(const void *obj, const intptr_t *args, char **buf)
Generic container type.
static int transport_protocol_to_str(const void *obj, const intptr_t *args, char **buf)
static int cli_print_body(void *obj, void *arg, int flags)
Type for default option handler for signed integers.
ao2_callback_fn * print_body
Definition: res_pjsip_cli.h:62
const char * name
Definition: res_pjsip_cli.h:58
static struct ast_cli_entry cli_commands[]

◆ ast_sip_message_apply_transport()

void ast_sip_message_apply_transport ( const char *  transport_name,
pjsip_tx_data *  tdata 
)

Apply the configuration for a transport to an outgoing message.

Since
17.0.0
Parameters
transport_nameThe name of the transport to apply configuration from
tdataThe SIP message

Definition at line 301 of file config_transport.c.

References ao2_lock, ao2_ref, ao2_unlock, ast_sip_add_header(), ast_sip_get_transport_state(), ast_strlen_zero, AST_VECTOR_GET, AST_VECTOR_SIZE, ast_sip_transport_state::flow, ast_sip_transport_state::preferred_identity, and ast_sip_transport_state::service_routes.

Referenced by ast_sip_send_out_of_dialog_request(), handle_outgoing_request(), handle_outgoing_response(), and supplement_outgoing_response().

302 {
303  struct ast_sip_transport_state *transport_state;
304 
305  if (ast_strlen_zero(transport_name)) {
306  return;
307  }
308 
309  /* We only currently care about requests that are of the INVITE, CANCEL, or OPTIONS
310  * type but in the future we could support other messages.
311  */
312  if (tdata->msg->type != PJSIP_REQUEST_MSG ||
313  (pjsip_method_cmp(&tdata->msg->line.req.method, &pjsip_invite_method) &&
314  pjsip_method_cmp(&tdata->msg->line.req.method, &pjsip_cancel_method) &&
315  pjsip_method_cmp(&tdata->msg->line.req.method, &pjsip_options_method))) {
316  return;
317  }
318 
319  transport_state = ast_sip_get_transport_state(transport_name);
320  if (!transport_state) {
321  return;
322  }
323 
324  if (!transport_state->flow) {
325  ao2_ref(transport_state, -1);
326  return;
327  }
328 
329  ao2_lock(transport_state);
330 
331  /* If a Preferred Identity has been set then add it to the request */
332  if (transport_state->preferred_identity) {
333  ast_sip_add_header(tdata, "P-Preferred-Identity", transport_state->preferred_identity);
334  }
335 
336  /* If Service Routes have been set then add them to the request */
337  if (transport_state->service_routes) {
338  int idx;
339 
340  for (idx = 0; idx < AST_VECTOR_SIZE(transport_state->service_routes); ++idx) {
341  char *service_route = AST_VECTOR_GET(transport_state->service_routes, idx);
342 
343  ast_sip_add_header(tdata, "Route", service_route);
344  }
345  }
346 
347  ao2_unlock(transport_state);
348 
349  ao2_ref(transport_state, -1);
350 }
struct ast_sip_transport_state * ast_sip_get_transport_state(const char *transport_id)
Retrieve transport state.
#define ao2_unlock(a)
Definition: astobj2.h:730
int ast_sip_add_header(pjsip_tx_data *tdata, const char *name, const char *value)
Add a header to an outbound SIP message.
Definition: res_pjsip.c:5063
#define ast_strlen_zero(foo)
Definition: strings.h:52
Structure for SIP transport information.
Definition: res_pjsip.h:87
#define ao2_ref(o, delta)
Definition: astobj2.h:464
#define ao2_lock(a)
Definition: astobj2.h:718
#define AST_VECTOR_GET(vec, idx)
Get an element from a vector.
Definition: vector.h:682
struct ast_sip_service_route_vector * service_routes
Definition: res_pjsip.h:159
#define AST_VECTOR_SIZE(vec)
Get the number of elements in a vector.
Definition: vector.h:611

◆ ast_sip_service_route_vector_alloc()

struct ast_sip_service_route_vector* ast_sip_service_route_vector_alloc ( void  )

Allocate a vector of service routes.

Since
17.0.0
Return values
non-NULLsuccess
NULLfailure

Definition at line 352 of file config_transport.c.

References ast_calloc, AST_VECTOR_INIT, and NULL.

Referenced by save_response_fields_to_transport().

353 {
354  struct ast_sip_service_route_vector *service_routes;
355 
356  service_routes = ast_calloc(1, sizeof(*service_routes));
357  if (!service_routes) {
358  return NULL;
359  }
360 
361  AST_VECTOR_INIT(service_routes, 0);
362 
363  return service_routes;
364 }
#define NULL
Definition: resample.c:96
#define AST_VECTOR_INIT(vec, size)
Initialize a vector.
Definition: vector.h:113
#define ast_calloc(num, len)
A wrapper for calloc()
Definition: astmm.h:204

◆ ast_sip_service_route_vector_destroy()

void ast_sip_service_route_vector_destroy ( struct ast_sip_service_route_vector *  service_routes)

Destroy a vector of service routes.

Since
17.0.0
Parameters
service_routesA vector of service routes

Definition at line 366 of file config_transport.c.

References ast_free, and AST_VECTOR_CALLBACK_VOID.

Referenced by ast_sip_transport_state_set_service_routes(), and save_response_fields_to_transport().

367 {
368  if (!service_routes) {
369  return;
370  }
371 
372  AST_VECTOR_CALLBACK_VOID(service_routes, ast_free);
373  ast_free(service_routes);
374 }
#define ast_free(a)
Definition: astmm.h:182
#define AST_VECTOR_CALLBACK_VOID(vec, callback,...)
Execute a callback on every element in a vector disregarding callback return.
Definition: vector.h:865

◆ ast_sip_transport_state_set_preferred_identity()

int ast_sip_transport_state_set_preferred_identity ( const char *  transport_name,
const char *  identity 
)

Sets the P-Preferred-Identity on a child transport.

Since
17.0.0
Parameters
transport_nameThe name of the transport to be set on
identityThe P-Preferred-Identity to use on requests on this transport
Return values
0success
-1failure

Definition at line 242 of file config_transport.c.

References ao2_lock, ao2_ref, ao2_unlock, ast_free, ast_sip_get_transport_state(), ast_strdup, ast_strlen_zero, ast_sip_transport_state::flow, and ast_sip_transport_state::preferred_identity.

Referenced by save_response_fields_to_transport().

243 {
244  struct ast_sip_transport_state *transport_state;
245 
246  if (ast_strlen_zero(transport_name)) {
247  return 0;
248  }
249 
250  transport_state = ast_sip_get_transport_state(transport_name);
251  if (!transport_state) {
252  return -1;
253  }
254 
255  if (!transport_state->flow) {
256  ao2_ref(transport_state, -1);
257  return 0;
258  }
259 
260  ao2_lock(transport_state);
261  ast_free(transport_state->preferred_identity);
262  transport_state->preferred_identity = ast_strdup(identity);
263  ao2_unlock(transport_state);
264 
265  ao2_ref(transport_state, -1);
266 
267  return 0;
268 }
struct ast_sip_transport_state * ast_sip_get_transport_state(const char *transport_id)
Retrieve transport state.
#define ao2_unlock(a)
Definition: astobj2.h:730
#define ast_strdup(str)
A wrapper for strdup()
Definition: astmm.h:243
#define ast_strlen_zero(foo)
Definition: strings.h:52
Structure for SIP transport information.
Definition: res_pjsip.h:87
#define ao2_ref(o, delta)
Definition: astobj2.h:464
#define ao2_lock(a)
Definition: astobj2.h:718
#define ast_free(a)
Definition: astmm.h:182

◆ ast_sip_transport_state_set_service_routes()

int ast_sip_transport_state_set_service_routes ( const char *  transport_name,
struct ast_sip_service_route_vector *  service_routes 
)

Sets the service routes on a child transport.

Since
17.0.0
Parameters
transport_nameThe name of the transport to be set on
service_routesA vector of service routes
Return values
0success
-1failure
Note
This assumes ownership of the service routes in both success and failure scenarios

Definition at line 270 of file config_transport.c.

References ao2_lock, ao2_ref, ao2_unlock, ast_sip_get_transport_state(), ast_sip_service_route_vector_destroy(), ast_strlen_zero, ast_sip_transport_state::flow, and ast_sip_transport_state::service_routes.

Referenced by save_response_fields_to_transport().

271 {
272  struct ast_sip_transport_state *transport_state;
273 
274  if (ast_strlen_zero(transport_name)) {
276  return 0;
277  }
278 
279  transport_state = ast_sip_get_transport_state(transport_name);
280  if (!transport_state) {
282  return -1;
283  }
284 
285  if (!transport_state->flow) {
286  ao2_ref(transport_state, -1);
288  return 0;
289  }
290 
291  ao2_lock(transport_state);
293  transport_state->service_routes = service_routes;
294  ao2_unlock(transport_state);
295 
296  ao2_ref(transport_state, -1);
297 
298  return 0;
299 }
struct ast_sip_transport_state * ast_sip_get_transport_state(const char *transport_id)
Retrieve transport state.
void ast_sip_service_route_vector_destroy(struct ast_sip_service_route_vector *service_routes)
Destroy a vector of service routes.
#define ao2_unlock(a)
Definition: astobj2.h:730
#define ast_strlen_zero(foo)
Definition: strings.h:52
Structure for SIP transport information.
Definition: res_pjsip.h:87
#define ao2_ref(o, delta)
Definition: astobj2.h:464
#define ao2_lock(a)
Definition: astobj2.h:718
struct ast_sip_service_route_vector * service_routes
Definition: res_pjsip.h:159

◆ ast_sip_transport_state_set_transport()

int ast_sip_transport_state_set_transport ( const char *  transport_name,
pjsip_transport *  transport 
)

Sets the PJSIP transport on a child transport.

Since
17.0.0
Parameters
transport_nameThe name of the transport to be updated
transportThe PJSIP transport
Return values
0success
-1failure

Definition at line 206 of file config_transport.c.

References ao2_lock, ao2_ref, ao2_unlock, ast_sip_get_transport_state(), ast_strlen_zero, ast_sip_transport_state::flow, internal_state::transport, and ast_sip_transport_state::transport.

Referenced by save_response_fields_to_transport().

207 {
208  struct ast_sip_transport_state *transport_state;
209 
210  /* To make it easier on callers we allow an empty transport name */
211  if (ast_strlen_zero(transport_name)) {
212  return 0;
213  }
214 
215  transport_state = ast_sip_get_transport_state(transport_name);
216  if (!transport_state) {
217  return -1;
218  }
219 
220  if (!transport_state->flow) {
221  ao2_ref(transport_state, -1);
222  return 0;
223  }
224 
225  ao2_lock(transport_state);
226  if (transport_state->transport != transport) {
227  if (transport_state->transport) {
228  pjsip_transport_dec_ref(transport_state->transport);
229  }
230  transport_state->transport = transport;
231  if (transport_state->transport) {
232  pjsip_transport_add_ref(transport_state->transport);
233  }
234  }
235  ao2_unlock(transport_state);
236 
237  ao2_ref(transport_state, -1);
238 
239  return 0;
240 }
struct ast_sip_transport_state * ast_sip_get_transport_state(const char *transport_id)
Retrieve transport state.
#define ao2_unlock(a)
Definition: astobj2.h:730
#define ast_strlen_zero(foo)
Definition: strings.h:52
Structure for SIP transport information.
Definition: res_pjsip.h:87
struct pjsip_transport * transport
Transport itself.
Definition: res_pjsip.h:89
#define ao2_ref(o, delta)
Definition: astobj2.h:464
#define ao2_lock(a)
Definition: astobj2.h:718

◆ ca_list_file_to_str()

static int ca_list_file_to_str ( const void *  obj,
const intptr_t *  args,
char **  buf 
)
static

Definition at line 922 of file config_transport.c.

References ast_strdup, ast_sip_transport::ca_list_file, and internal_state::transport.

Referenced by ast_sip_initialize_sorcery_transport().

923 {
924  const struct ast_sip_transport *transport = obj;
925 
926  *buf = ast_strdup(transport->ca_list_file);
927 
928  return 0;
929 }
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
#define ast_strdup(str)
A wrapper for strdup()
Definition: astmm.h:243
Transport to bind to.
Definition: res_pjsip.h:171
const ast_string_field ca_list_file
Definition: res_pjsip.h:191

◆ ca_list_path_to_str()

static int ca_list_path_to_str ( const void *  obj,
const intptr_t *  args,
char **  buf 
)
static

Definition at line 931 of file config_transport.c.

References ast_strdup, ast_sip_transport::ca_list_path, and internal_state::transport.

Referenced by ast_sip_initialize_sorcery_transport().

932 {
933  const struct ast_sip_transport *transport = obj;
934 
935  *buf = ast_strdup(transport->ca_list_path);
936 
937  return 0;
938 }
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
#define ast_strdup(str)
A wrapper for strdup()
Definition: astmm.h:243
const ast_string_field ca_list_path
Definition: res_pjsip.h:191
Transport to bind to.
Definition: res_pjsip.h:171

◆ cert_file_to_str()

static int cert_file_to_str ( const void *  obj,
const intptr_t *  args,
char **  buf 
)
static

Definition at line 940 of file config_transport.c.

References ast_strdup, ast_sip_transport::cert_file, and internal_state::transport.

Referenced by ast_sip_initialize_sorcery_transport().

941 {
942  const struct ast_sip_transport *transport = obj;
943 
944  *buf = ast_strdup(transport->cert_file);
945 
946  return 0;
947 }
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
#define ast_strdup(str)
A wrapper for strdup()
Definition: astmm.h:243
Transport to bind to.
Definition: res_pjsip.h:171
const ast_string_field cert_file
Definition: res_pjsip.h:191

◆ cli_get_container()

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

Definition at line 1454 of file config_transport.c.

References AO2_ALLOC_OPT_LOCK_NOLOCK, ao2_cleanup, ao2_container_alloc_list, ao2_container_dup(), ao2_ref, ast_sip_get_sorcery(), ast_sorcery_object_id_compare(), ast_sorcery_object_id_sort(), ast_sorcery_retrieve_by_regex(), container, NULL, and RAII_VAR.

Referenced by ast_sip_initialize_sorcery_transport().

1455 {
1457  struct ao2_container *s_container;
1458 
1460  regex);
1461  if (!container) {
1462  return NULL;
1463  }
1464 
1467  if (!s_container) {
1468  return NULL;
1469  }
1470 
1471  if (ao2_container_dup(s_container, container, 0)) {
1472  ao2_ref(s_container, -1);
1473  return NULL;
1474  }
1475 
1476  return s_container;
1477 }
#define ao2_container_alloc_list(ao2_options, container_options, sort_fn, cmp_fn)
Definition: astobj2.h:1335
int ast_sorcery_object_id_compare(void *obj, void *arg, int flags)
ao2 object comparator based on sorcery id.
Definition: sorcery.c:2459
#define NULL
Definition: resample.c:96
struct ao2_container * ast_sorcery_retrieve_by_regex(const struct ast_sorcery *sorcery, const char *type, const char *regex)
Retrieve multiple objects using a regular expression on their id.
Definition: sorcery.c:1949
#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:911
#define ao2_ref(o, delta)
Definition: astobj2.h:464
int ast_sorcery_object_id_sort(const void *obj, const void *arg, int flags)
ao2 object sorter based on sorcery id.
Definition: sorcery.c:2435
struct ao2_container * container
Definition: res_fax.c:502
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.
static int regex(struct ast_channel *chan, const char *cmd, char *parse, char *buf, size_t len)
Definition: func_strings.c:948
struct ast_sorcery * ast_sip_get_sorcery(void)
Get a pointer to the SIP sorcery structure.
#define ao2_cleanup(obj)
Definition: astobj2.h:1958
Generic container type.

◆ cli_iterate()

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

Definition at line 1479 of file config_transport.c.

References ast_sip_get_sorcery(), ast_sorcery_retrieve_by_id(), container, internal_state::transport, and ast_sip_endpoint::transport.

Referenced by ast_sip_initialize_sorcery_transport().

1480 {
1481  const struct ast_sip_endpoint *endpoint = container;
1483  "transport", endpoint->transport);
1484 
1485  if (!transport) {
1486  return -1;
1487  }
1488 
1489  return callback(transport, args, 0);
1490 }
const ast_string_field transport
Definition: res_pjsip.h:817
const char * args
void * ast_sorcery_retrieve_by_id(const struct ast_sorcery *sorcery, const char *type, const char *id)
Retrieve an object using its unique identifier.
Definition: sorcery.c:1853
struct ao2_container * container
Definition: res_fax.c:502
An entity with which Asterisk communicates.
Definition: res_pjsip.h:812
Transport to bind to.
Definition: res_pjsip.h:171
struct ast_sorcery * ast_sip_get_sorcery(void)
Get a pointer to the SIP sorcery structure.

◆ cli_print_body()

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

Definition at line 1512 of file config_transport.c.

References ao2_cleanup, ARRAY_IN_BOUNDS, ast_assert, ast_sip_cli_print_sorcery_objectset(), ast_sorcery_object_get_id(), ast_str_append(), CLI_INDENT_TO_SPACES, context, ast_sip_transport::cos, find_state_by_transport(), ast_sip_transport_state::host, ast_sip_cli_context::indent_level, NULL, ast_sip_cli_context::output_buffer, RAII_VAR, ast_sip_cli_context::show_details, ast_sip_cli_context::show_details_only_level_0, ast_sip_transport::tos, internal_state::transport, transport_types, and ast_sip_transport::type.

Referenced by ast_sip_initialize_sorcery_transport().

1513 {
1514  struct ast_sip_transport *transport = obj;
1515  struct ast_sip_cli_context *context = arg;
1516  char hoststr[PJ_INET6_ADDRSTRLEN];
1518 
1519  if (!state) {
1520  return -1;
1521  }
1522 
1523  ast_assert(context->output_buffer != NULL);
1524 
1525  pj_sockaddr_print(&state->host, hoststr, sizeof(hoststr), 3);
1526 
1527  ast_str_append(&context->output_buffer, 0, "%*s: %-21s %6s %5u %5u %s\n",
1528  CLI_INDENT_TO_SPACES(context->indent_level), "Transport",
1529  ast_sorcery_object_get_id(transport),
1530  ARRAY_IN_BOUNDS(transport->type, transport_types) ? transport_types[transport->type] : "Unknown",
1531  transport->cos, transport->tos, hoststr);
1532 
1533  if (context->show_details
1534  || (context->show_details_only_level_0 && context->indent_level == 0)) {
1535  ast_str_append(&context->output_buffer, 0, "\n");
1536  ast_sip_cli_print_sorcery_objectset(transport, context, 0);
1537  }
1538 
1539  return 0;
1540 }
struct ast_str * output_buffer
Definition: res_pjsip_cli.h:36
#define ARRAY_IN_BOUNDS(v, a)
Checks to see if value is within the bounds of the given array.
Definition: utils.h:658
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:1091
#define ast_assert(a)
Definition: utils.h:695
#define NULL
Definition: resample.c:96
unsigned int cos
Definition: res_pjsip.h:243
enum ast_transport type
Definition: res_pjsip.h:193
static struct ast_sip_transport_state * find_state_by_transport(const struct ast_sip_transport *transport)
static const char * transport_types[]
Structure for SIP transport information.
Definition: res_pjsip.h:87
#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:911
#define CLI_INDENT_TO_SPACES(x)
Definition: res_pjsip_cli.h:29
const char * ast_sorcery_object_get_id(const void *object)
Get the unique identifier of a sorcery object.
Definition: sorcery.c:2312
Transport to bind to.
Definition: res_pjsip.h:171
#define ao2_cleanup(obj)
Definition: astobj2.h:1958
unsigned int tos
Definition: res_pjsip.h:241
static char context[AST_MAX_CONTEXT]
Definition: chan_alsa.c:116
int ast_sip_cli_print_sorcery_objectset(void *obj, void *arg, int flags)
Prints a sorcery object&#39;s ast_variable list.
Definition: pjsip_cli.c:36
unsigned show_details_only_level_0
Definition: res_pjsip_cli.h:46

◆ cli_print_header()

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

Definition at line 1497 of file config_transport.c.

References ast_assert, ast_str_append(), CLI_HEADER_FILLER, CLI_INDENT_TO_SPACES, CLI_MAX_WIDTH, context, ast_sip_cli_context::indent_level, NULL, and ast_sip_cli_context::output_buffer.

Referenced by ast_sip_initialize_sorcery_transport().

1498 {
1499  struct ast_sip_cli_context *context = arg;
1500  int indent = CLI_INDENT_TO_SPACES(context->indent_level);
1501  int filler = CLI_MAX_WIDTH - indent - 61;
1502 
1503  ast_assert(context->output_buffer != NULL);
1504 
1505  ast_str_append(&context->output_buffer, 0,
1506  "%*s: <TransportId........> <Type> <cos> <tos> <BindAddress%*.*s>\n",
1507  indent, "Transport", filler, filler, CLI_HEADER_FILLER);
1508 
1509  return 0;
1510 }
struct ast_str * output_buffer
Definition: res_pjsip_cli.h:36
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:1091
#define ast_assert(a)
Definition: utils.h:695
#define NULL
Definition: resample.c:96
#define CLI_INDENT_TO_SPACES(x)
Definition: res_pjsip_cli.h:29
#define CLI_MAX_WIDTH
Definition: res_pjsip_cli.h:26
#define CLI_HEADER_FILLER
Definition: res_pjsip_cli.h:24
static char context[AST_MAX_CONTEXT]
Definition: chan_alsa.c:116

◆ cli_retrieve_by_id()

static void* cli_retrieve_by_id ( const char *  id)
static

Definition at line 1492 of file config_transport.c.

References ast_sip_get_sorcery(), and ast_sorcery_retrieve_by_id().

Referenced by ast_sip_initialize_sorcery_transport().

1493 {
1494  return ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(), "transport", id);
1495 }
void * ast_sorcery_retrieve_by_id(const struct ast_sorcery *sorcery, const char *type, const char *id)
Retrieve an object using its unique identifier.
Definition: sorcery.c:1853
struct ast_sorcery * ast_sip_get_sorcery(void)
Get a pointer to the SIP sorcery structure.

◆ copy_state_to_transport()

static void copy_state_to_transport ( struct ast_sip_transport transport)
static

Definition at line 568 of file config_transport.c.

References ast_assert, ast_sip_transport_state::ciphers, ast_sip_transport::ciphers, ast_sip_transport::external_address, ast_sip_transport::external_address_refresher, ast_sip_transport_state::external_signaling_address, ast_sip_transport::external_signaling_address, ast_sip_transport_state::external_signaling_address_refresher, ast_sip_transport_state::host, ast_sip_transport::host, ast_sip_transport_state::localnet, ast_sip_transport::localnet, ast_sip_transport::state, ast_sip_transport_state::tls, and ast_sip_transport::tls.

Referenced by transport_apply().

569 {
570  ast_assert(transport && transport->state);
571 
572  memcpy(&transport->host, &transport->state->host, sizeof(transport->host));
573  memcpy(&transport->tls, &transport->state->tls, sizeof(transport->tls));
574  memcpy(&transport->ciphers, &transport->state->ciphers, sizeof(transport->ciphers));
575  transport->localnet = transport->state->localnet;
577  memcpy(&transport->external_address, &transport->state->external_signaling_address, sizeof(transport->external_signaling_address));
578 }
struct ast_ha * localnet
Definition: res_pjsip.h:124
struct ast_dnsmgr_entry * external_address_refresher
Definition: res_pjsip.h:227
struct ast_ha * localnet
Definition: res_pjsip.h:221
#define ast_assert(a)
Definition: utils.h:695
pj_sockaddr host
Definition: res_pjsip.h:199
struct ast_sip_transport_state * state
Definition: res_pjsip.h:239
struct ast_sockaddr external_address
Definition: res_pjsip.h:233
pjsip_tls_setting tls
Definition: res_pjsip.h:111
const ast_string_field external_signaling_address
Definition: res_pjsip.h:191
struct ast_sockaddr external_signaling_address
Definition: res_pjsip.h:134
pj_ssl_cipher ciphers[SIP_TLS_MAX_CIPHERS]
Definition: res_pjsip.h:215
pjsip_tls_setting tls
Definition: res_pjsip.h:209
struct ast_dnsmgr_entry * external_signaling_address_refresher
Definition: res_pjsip.h:129
pj_ssl_cipher ciphers[SIP_TLS_MAX_CIPHERS]
Definition: res_pjsip.h:116

◆ destroy_sip_transport_state()

static int destroy_sip_transport_state ( void *  data)
static

Definition at line 415 of file config_transport.c.

References ast_dnsmgr_release(), ast_free, ast_free_ha(), ast_sip_transport_state::external_media_address_refresher, ast_sip_transport_state::external_signaling_address_refresher, ast_sip_transport_state::id, ast_sip_transport_state::localnet, and ast_sip_transport_state::transport.

Referenced by sip_transport_state_destroy().

416 {
417  struct ast_sip_transport_state *transport_state = data;
418 
419  ast_free(transport_state->id);
420  ast_free_ha(transport_state->localnet);
421 
422  if (transport_state->external_signaling_address_refresher) {
424  }
425  if (transport_state->external_media_address_refresher) {
427  }
428  if (transport_state->transport) {
429  pjsip_transport_shutdown(transport_state->transport);
430  }
431 
432  return 0;
433 }
struct ast_ha * localnet
Definition: res_pjsip.h:124
Structure for SIP transport information.
Definition: res_pjsip.h:87
void ast_dnsmgr_release(struct ast_dnsmgr_entry *entry)
Free a DNS manager entry.
Definition: dnsmgr.c:136
struct pjsip_transport * transport
Transport itself.
Definition: res_pjsip.h:89
#define ast_free(a)
Definition: astmm.h:182
void ast_free_ha(struct ast_ha *ha)
Free a list of HAs.
Definition: acl.c:222
struct ast_dnsmgr_entry * external_media_address_refresher
Definition: res_pjsip.h:139
struct ast_dnsmgr_entry * external_signaling_address_refresher
Definition: res_pjsip.h:129

◆ find_internal_state_by_transport()

static struct internal_state* find_internal_state_by_transport ( const struct ast_sip_transport transport)
static

Definition at line 453 of file config_transport.c.

References ao2_find, ast_sorcery_object_get_id(), OBJ_NOLOCK, and OBJ_SEARCH_KEY.

Referenced by find_state_by_transport(), and transport_apply().

454 {
455  const char *key = ast_sorcery_object_get_id(transport);
456 
458 }
The arg parameter is a search key, but is not an object.
Definition: astobj2.h:1105
static struct ao2_container * transport_states
Assume that the ao2_container is already locked.
Definition: astobj2.h:1067
const char * ast_sorcery_object_get_id(const void *object)
Get the unique identifier of a sorcery object.
Definition: sorcery.c:2312
#define ao2_find(container, arg, flags)
Definition: astobj2.h:1756

◆ find_or_create_temporary_state()

static struct ast_sip_transport_state* find_or_create_temporary_state ( struct ast_sip_transport transport)
static

Definition at line 534 of file config_transport.c.

References ao2_alloc, ao2_ref, ast_sorcery_object_get_id(), ast_strdup, ast_threadstorage_get(), ast_sip_transport_state::ciphers, find_temporary_state(), ast_sip_transport_state::id, NULL, sip_transport_state_destroy(), internal_state::state, temp_state_store, ast_sip_transport_state::tls, ast_sip_transport_state::type, and ast_sip_transport::type.

Referenced by tls_method_to_str(), transport_bind_handler(), transport_localnet_handler(), transport_protocol_handler(), transport_state_init(), transport_tls_bool_handler(), transport_tls_file_handler(), and transport_tls_method_handler().

535 {
537  struct ast_sip_transport_state *new_state;
538 
539  if ((new_state = find_temporary_state(transport))) {
540  return new_state;
541  }
542 
543  state = ast_threadstorage_get(&temp_state_store, sizeof(state));
544  if (!state || *state) {
545  return NULL;
546  }
547 
548  new_state = ao2_alloc(sizeof(**state), sip_transport_state_destroy);
549  if (!new_state) {
550  return NULL;
551  }
552  new_state->id = ast_strdup(ast_sorcery_object_get_id(transport));
553  new_state->type = transport->type;
554 
555  pjsip_tls_setting_default(&new_state->tls);
556 #ifdef HAVE_PJSIP_TLS_TRANSPORT_PROTO
557  /* proto must be forced to 0 to enable all protocols otherwise only TLS will work */
558  new_state->tls.proto = 0;
559 #endif
560  new_state->tls.ciphers = new_state->ciphers;
561 
562  ao2_ref(new_state, +1);
563  *state = new_state;
564 
565  return new_state;
566 }
enum ast_transport type
Definition: res_pjsip.h:101
enum sip_cc_notify_state state
Definition: chan_sip.c:959
void * ast_threadstorage_get(struct ast_threadstorage *ts, size_t init_size)
Retrieve thread storage.
#define ast_strdup(str)
A wrapper for strdup()
Definition: astmm.h:243
#define NULL
Definition: resample.c:96
enum ast_transport type
Definition: res_pjsip.h:193
Structure for SIP transport information.
Definition: res_pjsip.h:87
pjsip_tls_setting tls
Definition: res_pjsip.h:111
#define ao2_ref(o, delta)
Definition: astobj2.h:464
const char * ast_sorcery_object_get_id(const void *object)
Get the unique identifier of a sorcery object.
Definition: sorcery.c:2312
static struct ast_threadstorage temp_state_store
#define ao2_alloc(data_size, destructor_fn)
Definition: astobj2.h:411
static struct ast_sip_transport_state * find_temporary_state(struct ast_sip_transport *transport)
pj_ssl_cipher ciphers[SIP_TLS_MAX_CIPHERS]
Definition: res_pjsip.h:116
static void sip_transport_state_destroy(void *obj)
Destructor for ast_sip_transport state information.

◆ find_state_by_transport()

static struct ast_sip_transport_state* find_state_by_transport ( const struct ast_sip_transport transport)
static

Definition at line 460 of file config_transport.c.

References ao2_bump, ao2_ref, find_internal_state_by_transport(), NULL, and internal_state::state.

Referenced by cli_print_body(), localnet_to_str(), localnet_to_vl(), require_client_cert_to_str(), tls_method_to_str(), transport_bind_to_str(), verify_client_to_str(), and verify_server_to_str().

461 {
462  struct internal_state *state;
463  struct ast_sip_transport_state *trans_state;
464 
465  state = find_internal_state_by_transport(transport);
466  if (!state) {
467  return NULL;
468  }
469  trans_state = ao2_bump(state->state);
470  ao2_ref(state, -1);
471 
472  return trans_state;
473 }
enum sip_cc_notify_state state
Definition: chan_sip.c:959
struct ast_sip_transport_state * state
Transport state information.
static struct internal_state * find_internal_state_by_transport(const struct ast_sip_transport *transport)
#define NULL
Definition: resample.c:96
#define ao2_bump(obj)
Definition: astobj2.h:491
Structure for SIP transport information.
Definition: res_pjsip.h:87
#define ao2_ref(o, delta)
Definition: astobj2.h:464

◆ find_temporary_state()

static struct ast_sip_transport_state* find_temporary_state ( struct ast_sip_transport transport)
static

Definition at line 489 of file config_transport.c.

References ao2_ref, ast_threadstorage_get(), NULL, internal_state::state, and temp_state_store.

Referenced by find_or_create_temporary_state(), and internal_state_alloc().

490 {
492 
493  state = ast_threadstorage_get(&temp_state_store, sizeof(state));
494  if (state && *state) {
495  ao2_ref(*state, +1);
496  return *state;
497  }
498 
499  return NULL;
500 }
enum sip_cc_notify_state state
Definition: chan_sip.c:959
void * ast_threadstorage_get(struct ast_threadstorage *ts, size_t init_size)
Retrieve thread storage.
#define NULL
Definition: resample.c:96
Structure for SIP transport information.
Definition: res_pjsip.h:87
#define ao2_ref(o, delta)
Definition: astobj2.h:464
static struct ast_threadstorage temp_state_store

◆ format_ami_endpoint_transport()

static int format_ami_endpoint_transport ( const struct ast_sip_endpoint endpoint,
struct ast_sip_ami ami 
)
static

Definition at line 168 of file config_transport.c.

References ao2_cleanup, ast_free, ast_sip_create_ami_event(), ast_sip_get_sorcery(), ast_sorcery_object_get_id(), ast_sorcery_retrieve_by_id(), ast_str_append(), ast_str_buffer(), ast_strlen_zero, astman_append(), astman_send_error_va(), buf, ast_sip_ami::count, ast_sip_ami::m, NULL, RAII_VAR, ast_sip_ami::s, sip_transport_to_ami(), internal_state::transport, and ast_sip_endpoint::transport.

170 {
171  RAII_VAR(struct ast_str *, buf, NULL, ast_free);
173 
174  if (ast_strlen_zero(endpoint->transport)) {
175  return 0;
176  }
177 
178  buf = ast_sip_create_ami_event("TransportDetail", ami);
179  if (!buf) {
180  return -1;
181  }
182 
184  endpoint->transport);
185  if (!transport) {
186  astman_send_error_va(ami->s, ami->m, "Unable to retrieve "
187  "transport %s\n", endpoint->transport);
188  return -1;
189  }
190 
192 
193  ast_str_append(&buf, 0, "EndpointName: %s\r\n",
194  ast_sorcery_object_get_id(endpoint));
195 
196  astman_append(ami->s, "%s\r\n", ast_str_buffer(buf));
197  ami->count++;
198 
199  return 0;
200 }
void astman_append(struct mansession *s, const char *fmt,...)
Definition: manager.c:3080
const ast_string_field transport
Definition: res_pjsip.h:817
const struct message * m
Definition: res_pjsip.h:2741
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition: strings.h:714
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:1091
static int sip_transport_to_ami(const struct ast_sip_transport *transport, struct ast_str **buf)
#define NULL
Definition: resample.c:96
void astman_send_error_va(struct mansession *s, const struct message *m, const char *fmt,...)
Send error in manager transaction (with va_args support)
Definition: manager.c:3164
#define ast_strlen_zero(foo)
Definition: strings.h:52
void * ast_sorcery_retrieve_by_id(const struct ast_sorcery *sorcery, const char *type, const char *id)
Retrieve an object using its unique identifier.
Definition: sorcery.c:1853
#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:911
struct pjsip_transport * transport
Transport itself.
Definition: res_pjsip.h:89
const char * ast_sorcery_object_get_id(const void *object)
Get the unique identifier of a sorcery object.
Definition: sorcery.c:2312
struct mansession * s
Definition: res_pjsip.h:2739
The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field ...
Definition: strings.h:584
Transport to bind to.
Definition: res_pjsip.h:171
#define ast_free(a)
Definition: astmm.h:182
struct ast_str * ast_sip_create_ami_event(const char *event, struct ast_sip_ami *ami)
Creates a string to store AMI event data in.
struct ast_sorcery * ast_sip_get_sorcery(void)
Get a pointer to the SIP sorcery structure.
#define ao2_cleanup(obj)
Definition: astobj2.h:1958

◆ has_state_changed()

static int has_state_changed ( struct ast_sip_transport_state a,
struct ast_sip_transport_state b 
)
static

Definition at line 580 of file config_transport.c.

References ast_ha::addr, ast_sockaddr_cmp(), ast_sip_transport_state::ciphers, ast_sip_transport_state::external_media_address, ast_sip_transport_state::external_signaling_address, HAVE_PJSIP_TLS_TRANSPORT_PROTO, ast_sip_transport_state::host, ast_sip_transport_state::localnet, ast_ha::netmask, ast_sip_transport_state::tls, and ast_sip_transport_state::type.

Referenced by transport_apply().

581 {
582  if (a->type != b->type) {
583  return -1;
584  }
585 
586  if (pj_sockaddr_cmp(&a->host, &b->host)) {
587  return -1;
588  }
589 
590  if ((a->localnet || b->localnet)
591  && ((!a->localnet != !b->localnet)
594  {
595  return -1;
596  }
597 
599  return -1;
600  }
601 
603  return -1;
604  }
605 
606  if (a->tls.method != b->tls.method
607  || a->tls.ciphers_num != b->tls.ciphers_num
609  || a->tls.proto != b->tls.proto
610 #endif
611  || a->tls.verify_client != b->tls.verify_client
612  || a->tls.verify_server != b->tls.verify_server
613  || a->tls.require_client_cert != b->tls.require_client_cert) {
614  return -1;
615  }
616 
617  if (memcmp(a->ciphers, b->ciphers, sizeof(pj_ssl_cipher) * fmax(a->tls.ciphers_num, b->tls.ciphers_num))) {
618  return -1;
619  }
620 
621  return 0;
622 }
enum ast_transport type
Definition: res_pjsip.h:101
struct ast_ha * localnet
Definition: res_pjsip.h:124
struct ast_sockaddr addr
Definition: acl.h:53
int ast_sockaddr_cmp(const struct ast_sockaddr *a, const struct ast_sockaddr *b)
Compares two ast_sockaddr structures.
Definition: netsock2.c:388
struct ast_sockaddr external_media_address
Definition: res_pjsip.h:144
struct ast_sockaddr netmask
Definition: acl.h:54
pjsip_tls_setting tls
Definition: res_pjsip.h:111
#define HAVE_PJSIP_TLS_TRANSPORT_PROTO
Definition: autoconfig.h:672
struct ast_sockaddr external_signaling_address
Definition: res_pjsip.h:134
pj_ssl_cipher ciphers[SIP_TLS_MAX_CIPHERS]
Definition: res_pjsip.h:116

◆ internal_state_alloc()

static struct internal_state* internal_state_alloc ( struct ast_sip_transport transport)
static

Definition at line 502 of file config_transport.c.

References ao2_alloc, ao2_bump, ao2_cleanup, ast_sorcery_object_get_id(), ast_strdup, find_temporary_state(), internal_state::id, internal_state_destroy(), NULL, remove_temporary_state(), internal_state::state, ast_sip_transport::state, and internal_state::transport.

Referenced by transport_apply().

503 {
505 
506  internal_state = ao2_alloc(sizeof(*internal_state), internal_state_destroy);
507  if (!internal_state) {
508  return NULL;
509  }
510 
511  internal_state->id = ast_strdup(ast_sorcery_object_get_id(transport));
512  if (!internal_state->id) {
513  ao2_cleanup(internal_state);
514  return NULL;
515  }
516 
517  /* We're transferring the reference from find_temporary_state */
518  internal_state->state = find_temporary_state(transport);
519  if (!internal_state->state) {
520  ao2_cleanup(internal_state);
521  return NULL;
522  }
523  internal_state->transport = ao2_bump(transport);
524  internal_state->transport->state = internal_state->state;
526 
527  return internal_state;
528 }
struct ast_sip_transport_state * state
Transport state information.
#define ast_strdup(str)
A wrapper for strdup()
Definition: astmm.h:243
#define NULL
Definition: resample.c:96
struct ast_sip_transport_state * state
Definition: res_pjsip.h:239
#define ao2_bump(obj)
Definition: astobj2.h:491
const char * ast_sorcery_object_get_id(const void *object)
Get the unique identifier of a sorcery object.
Definition: sorcery.c:2312
static void internal_state_destroy(void *obj)
Destructor for ast_sip_transport state information.
#define ao2_alloc(data_size, destructor_fn)
Definition: astobj2.h:411
static int remove_temporary_state(void)
#define ao2_cleanup(obj)
Definition: astobj2.h:1958
static struct ast_sip_transport_state * find_temporary_state(struct ast_sip_transport *transport)
struct ast_sip_transport * transport
Transport configuration object.

◆ internal_state_cmp()

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

comparator function for state objects

Definition at line 84 of file config_transport.c.

References ast_assert, CMP_MATCH, internal_state::id, OBJ_SEARCH_KEY, OBJ_SEARCH_MASK, OBJ_SEARCH_OBJECT, and OBJ_SEARCH_PARTIAL_KEY.

Referenced by ast_sip_initialize_sorcery_transport().

85 {
86  const struct internal_state *object_left = obj;
87  const struct internal_state *object_right = arg;
88  const char *right_key = arg;
89  int cmp;
90 
91  switch (flags & OBJ_SEARCH_MASK) {
92  case OBJ_SEARCH_OBJECT:
93  right_key = object_right->id;
94  /* Fall through */
95  case OBJ_SEARCH_KEY:
96  cmp = strcmp(object_left->id, right_key);
97  break;
99  /* Not supported by container. */
100  ast_assert(0);
101  return 0;
102  default:
103  cmp = 0;
104  break;
105  }
106  if (cmp) {
107  return 0;
108  }
109  return CMP_MATCH;
110 }
The arg parameter is a search key, but is not an object.
Definition: astobj2.h:1105
#define ast_assert(a)
Definition: utils.h:695
The arg parameter is a partial search key similar to OBJ_SEARCH_KEY.
Definition: astobj2.h:1120
The arg parameter is an object of the same type.
Definition: astobj2.h:1091
Search option field mask.
Definition: astobj2.h:1076

◆ internal_state_destroy()

static void internal_state_destroy ( void *  obj)
static

Destructor for ast_sip_transport state information.

Definition at line 444 of file config_transport.c.

References ao2_cleanup, ast_free, internal_state::id, internal_state::state, and internal_state::transport.

Referenced by internal_state_alloc().

445 {
446  struct internal_state *state = obj;
447 
448  ast_free(state->id);
449  ao2_cleanup(state->transport);
450  ao2_cleanup(state->state);
451 }
struct ast_sip_transport_state * state
Transport state information.
#define ast_free(a)
Definition: astmm.h:182
#define ao2_cleanup(obj)
Definition: astobj2.h:1958
struct ast_sip_transport * transport
Transport configuration object.

◆ internal_state_hash()

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

hashing function for state objects

Definition at line 63 of file config_transport.c.

References ast_assert, ast_str_hash(), OBJ_SEARCH_KEY, OBJ_SEARCH_MASK, and OBJ_SEARCH_OBJECT.

Referenced by ast_sip_initialize_sorcery_transport().

64 {
65  const struct internal_state *object;
66  const char *key;
67 
68  switch (flags & OBJ_SEARCH_MASK) {
69  case OBJ_SEARCH_KEY:
70  key = obj;
71  break;
72  case OBJ_SEARCH_OBJECT:
73  object = obj;
74  key = object->id;
75  break;
76  default:
77  ast_assert(0);
78  return 0;
79  }
80  return ast_str_hash(key);
81 }
The arg parameter is a search key, but is not an object.
Definition: astobj2.h:1105
#define ast_assert(a)
Definition: utils.h:695
The arg parameter is an object of the same type.
Definition: astobj2.h:1091
Search option field mask.
Definition: astobj2.h:1076
static force_inline int attribute_pure ast_str_hash(const char *str)
Compute a hash value on a string.
Definition: strings.h:1206

◆ localnet_to_str()

static int localnet_to_str ( const void *  obj,
const intptr_t *  args,
char **  buf 
)
static

Definition at line 1403 of file config_transport.c.

References ao2_cleanup, ast_free, ast_ha_join(), ast_str_buffer(), ast_str_create, ast_strdup, find_state_by_transport(), ast_sip_transport_state::localnet, MAX_OBJECT_FIELD, RAII_VAR, str, and internal_state::transport.

Referenced by ast_sip_initialize_sorcery_transport().

1404 {
1406  const struct ast_sip_transport *transport = obj;
1408 
1409  if (!state) {
1410  return -1;
1411  }
1412 
1413  ast_ha_join(state->localnet, &str);
1415  return 0;
1416 }
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition: strings.h:714
#define ast_strdup(str)
A wrapper for strdup()
Definition: astmm.h:243
const char * str
Definition: app_jack.c:147
void ast_ha_join(const struct ast_ha *ha, struct ast_str **buf)
Convert HAs to a comma separated string value.
Definition: acl.c:723
static struct ast_sip_transport_state * find_state_by_transport(const struct ast_sip_transport *transport)
Structure for SIP transport information.
Definition: res_pjsip.h:87
#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:911
#define MAX_OBJECT_FIELD
Maximum length of an object field name.
Definition: sorcery.h:110
The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field ...
Definition: strings.h:584
Transport to bind to.
Definition: res_pjsip.h:171
#define ast_free(a)
Definition: astmm.h:182
#define ao2_cleanup(obj)
Definition: astobj2.h:1958
#define ast_str_create(init_len)
Create a malloc&#39;ed dynamic length string.
Definition: strings.h:620

◆ localnet_to_vl()

static int localnet_to_vl ( const void *  obj,
struct ast_variable **  fields 
)
static

Definition at line 1381 of file config_transport.c.

References ao2_cleanup, find_state_by_transport(), ast_sip_transport_state::localnet, localnet_to_vl_append(), ast_ha::next, NULL, RAII_VAR, and internal_state::transport.

Referenced by ast_sip_initialize_sorcery_transport().

1382 {
1383  const struct ast_sip_transport *transport = obj;
1384  struct ast_variable *head = NULL;
1385  struct ast_ha *ha;
1387 
1388  if (!state) {
1389  return -1;
1390  }
1391 
1392  for (ha = state->localnet; ha; ha = ha->next) {
1393  localnet_to_vl_append(&head, ha);
1394  }
1395 
1396  if (head) {
1397  *fields = head;
1398  }
1399 
1400  return 0;
1401 }
struct ast_ha * next
Definition: acl.h:56
Structure for variables, used for configurations and for channel variables.
#define NULL
Definition: resample.c:96
internal representation of ACL entries In principle user applications would have no need for this...
Definition: acl.h:51
static struct ast_sip_transport_state * find_state_by_transport(const struct ast_sip_transport *transport)
Structure for SIP transport information.
Definition: res_pjsip.h:87
#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:911
static void localnet_to_vl_append(struct ast_variable **head, struct ast_ha *ha)
Transport to bind to.
Definition: res_pjsip.h:171
#define ao2_cleanup(obj)
Definition: astobj2.h:1958

◆ localnet_to_vl_append()

static void localnet_to_vl_append ( struct ast_variable **  head,
struct ast_ha ha 
)
static

Definition at line 1371 of file config_transport.c.

References ast_ha::addr, AST_SENSE_ALLOW, ast_sockaddr_stringify_addr(), ast_strdupa, ast_variable_list_append, ast_variable_new, MAX_OBJECT_FIELD, ast_ha::netmask, ast_ha::sense, and str.

Referenced by localnet_to_vl().

1372 {
1373  char str[MAX_OBJECT_FIELD];
1374  const char *addr = ast_strdupa(ast_sockaddr_stringify_addr(&ha->addr));
1375  snprintf(str, MAX_OBJECT_FIELD, "%s%s/%s", ha->sense == AST_SENSE_ALLOW ? "!" : "",
1376  addr, ast_sockaddr_stringify_addr(&ha->netmask));
1377 
1378  ast_variable_list_append(head, ast_variable_new("local_net", str, ""));
1379 }
static char * ast_sockaddr_stringify_addr(const struct ast_sockaddr *addr)
Wrapper around ast_sockaddr_stringify_fmt() to return an address only.
Definition: netsock2.h:290
struct ast_sockaddr addr
Definition: acl.h:53
enum ast_acl_sense sense
Definition: acl.h:55
const char * str
Definition: app_jack.c:147
struct ast_sockaddr netmask
Definition: acl.h:54
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: astmm.h:300
#define ast_variable_new(name, value, filename)
#define MAX_OBJECT_FIELD
Maximum length of an object field name.
Definition: sorcery.h:110
#define ast_variable_list_append(head, new_var)

◆ populate_transport_states()

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

Definition at line 1594 of file config_transport.c.

References ao2_link, CMP_MATCH, container, and internal_state::state.

Referenced by ast_sip_get_transport_states().

1595 {
1596  struct internal_state *state = obj;
1597  struct ao2_container *container = arg;
1598 
1599  ao2_link(container, state->state);
1600 
1601  return CMP_MATCH;
1602 }
struct ast_sip_transport_state * state
Transport state information.
struct ao2_container * container
Definition: res_fax.c:502
Generic container type.
#define ao2_link(container, obj)
Definition: astobj2.h:1549

◆ privkey_file_to_str()

static int privkey_file_to_str ( const void *  obj,
const intptr_t *  args,
char **  buf 
)
static

Definition at line 949 of file config_transport.c.

References ast_strdup, ast_sip_transport::privkey_file, and internal_state::transport.

Referenced by ast_sip_initialize_sorcery_transport().

950 {
951  const struct ast_sip_transport *transport = obj;
952 
953  *buf = ast_strdup(transport->privkey_file);
954 
955  return 0;
956 }
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
#define ast_strdup(str)
A wrapper for strdup()
Definition: astmm.h:243
Transport to bind to.
Definition: res_pjsip.h:171
const ast_string_field privkey_file
Definition: res_pjsip.h:191

◆ remove_temporary_state()

static int remove_temporary_state ( void  )
static

Definition at line 475 of file config_transport.c.

References ao2_cleanup, ast_threadstorage_get(), NULL, internal_state::state, and temp_state_store.

Referenced by internal_state_alloc().

476 {
478 
479  state = ast_threadstorage_get(&temp_state_store, sizeof(state));
480  if (!state) {
481  return -1;
482  }
483 
484  ao2_cleanup(*state);
485  *state = NULL;
486  return 0;
487 }
enum sip_cc_notify_state state
Definition: chan_sip.c:959
void * ast_threadstorage_get(struct ast_threadstorage *ts, size_t init_size)
Retrieve thread storage.
#define NULL
Definition: resample.c:96
Structure for SIP transport information.
Definition: res_pjsip.h:87
static struct ast_threadstorage temp_state_store
#define ao2_cleanup(obj)
Definition: astobj2.h:1958

◆ require_client_cert_to_str()

static int require_client_cert_to_str ( const void *  obj,
const intptr_t *  args,
char **  buf 
)
static

Definition at line 1100 of file config_transport.c.

References ao2_cleanup, ast_strdup, AST_YESNO, find_state_by_transport(), RAII_VAR, and internal_state::transport.

Referenced by ast_sip_initialize_sorcery_transport().

1101 {
1102  const struct ast_sip_transport *transport = obj;
1104 
1105  if (!state) {
1106  return -1;
1107  }
1108 
1109  *buf = ast_strdup(AST_YESNO(state->tls.require_client_cert));
1110 
1111  return 0;
1112 }
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
#define ast_strdup(str)
A wrapper for strdup()
Definition: astmm.h:243
static struct ast_sip_transport_state * find_state_by_transport(const struct ast_sip_transport *transport)
Structure for SIP transport information.
Definition: res_pjsip.h:87
#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:911
Transport to bind to.
Definition: res_pjsip.h:171
#define AST_YESNO(x)
return Yes or No depending on the argument.
Definition: strings.h:139
#define ao2_cleanup(obj)
Definition: astobj2.h:1958

◆ set_qos()

static void set_qos ( struct ast_sip_transport transport,
pj_qos_params *  qos 
)
static

Definition at line 376 of file config_transport.c.

References ast_sip_transport::cos, and ast_sip_transport::tos.

Referenced by transport_apply().

377 {
378  int tos_as_dscp = transport->tos >> 2;
379 
380  if (transport->tos) {
381  qos->flags |= PJ_QOS_PARAM_HAS_DSCP;
382  qos->dscp_val = tos_as_dscp;
383  }
384  if (transport->cos) {
385  qos->flags |= PJ_QOS_PARAM_HAS_SO_PRIO;
386  qos->so_prio = transport->cos;
387  }
388 }
static struct @111 qos
unsigned int cos
Definition: res_pjsip.h:243
unsigned int tos
Definition: res_pjsip.h:241

◆ sip_transport_alloc()

static void* sip_transport_alloc ( const char *  name)
static

Allocator for transport.

Definition at line 399 of file config_transport.c.

References ao2_cleanup, ast_sorcery_generic_alloc(), ast_string_field_init, NULL, sip_transport_destroy(), and internal_state::transport.

Referenced by ast_sip_initialize_sorcery_transport().

400 {
401  struct ast_sip_transport *transport = ast_sorcery_generic_alloc(sizeof(*transport), sip_transport_destroy);
402 
403  if (!transport) {
404  return NULL;
405  }
406 
407  if (ast_string_field_init(transport, 256)) {
408  ao2_cleanup(transport);
409  return NULL;
410  }
411 
412  return transport;
413 }
static void sip_transport_destroy(void *obj)
Destructor for transport.
#define NULL
Definition: resample.c:96
#define ast_string_field_init(x, size)
Initialize a field pool and fields.
Definition: stringfields.h:353
Transport to bind to.
Definition: res_pjsip.h:171
#define ao2_cleanup(obj)
Definition: astobj2.h:1958
void * ast_sorcery_generic_alloc(size_t size, ao2_destructor_fn destructor)
Allocate a generic sorcery capable object.
Definition: sorcery.c:1728

◆ sip_transport_destroy()

static void sip_transport_destroy ( void *  obj)
static

Destructor for transport.

Definition at line 391 of file config_transport.c.

References ast_string_field_free_memory, and internal_state::transport.

Referenced by sip_transport_alloc().

392 {
393  struct ast_sip_transport *transport = obj;
394 
395  ast_string_field_free_memory(transport);
396 }
Transport to bind to.
Definition: res_pjsip.h:171
#define ast_string_field_free_memory(x)
free all memory - to be called before destroying the object
Definition: stringfields.h:368

◆ sip_transport_state_destroy()

static void sip_transport_state_destroy ( void *  obj)
static

Destructor for ast_sip_transport state information.

Definition at line 436 of file config_transport.c.

References ast_sip_push_task_wait_servant(), destroy_sip_transport_state(), and NULL.

Referenced by find_or_create_temporary_state().

437 {
438  struct ast_sip_transport_state *state = obj;
439 
441 }
#define NULL
Definition: resample.c:96
int ast_sip_push_task_wait_servant(struct ast_taskprocessor *serializer, int(*sip_task)(void *), void *task_data)
Push a task to SIP servants and wait for it to complete.
Definition: res_pjsip.c:5204
Structure for SIP transport information.
Definition: res_pjsip.h:87
static int destroy_sip_transport_state(void *data)

◆ sip_transport_to_ami()

static int sip_transport_to_ami ( const struct ast_sip_transport transport,
struct ast_str **  buf 
)
static

Definition at line 162 of file config_transport.c.

References ast_sip_sorcery_object_to_ami().

Referenced by format_ami_endpoint_transport().

164 {
165  return ast_sip_sorcery_object_to_ami(transport, buf);
166 }
int ast_sip_sorcery_object_to_ami(const void *obj, struct ast_str **buf)
Converts a sorcery object to a string of object properties.

◆ states_cleanup()

static void states_cleanup ( void *  states)
static

Definition at line 624 of file config_transport.c.

References ao2_unlock.

Referenced by transport_apply().

625 {
626  if (states) {
627  ao2_unlock(states);
628  }
629 }
#define ao2_unlock(a)
Definition: astobj2.h:730

◆ temp_state_store_cleanup()

static void temp_state_store_cleanup ( void *  data)
static

Definition at line 52 of file config_transport.c.

References ao2_cleanup, and ast_free.

53 {
54  struct ast_sip_transport_state **temp_state = data;
55 
56  ao2_cleanup(*temp_state);
57  ast_free(data);
58 }
Structure for SIP transport information.
Definition: res_pjsip.h:87
#define ast_free(a)
Definition: astmm.h:182
#define ao2_cleanup(obj)
Definition: astobj2.h:1958

◆ tls_method_to_str()

static int tls_method_to_str ( const void *  obj,
const intptr_t *  args,
char **  buf 
)
static

Definition at line 1161 of file config_transport.c.

References a, ao2_cleanup, args, ARRAY_IN_BOUNDS, ARRAY_LEN, ast_cli(), ast_free, ast_log, ast_str_append(), ast_str_buffer(), ast_str_create, ast_strdup, ast_strdupa, ast_strip(), ast_strlen_zero, buf, ast_sip_transport_state::ciphers, ast_sip_transport::ciphers, CLI_GENERATE, CLI_INIT, CLI_SUCCESS, ast_cli_entry::command, ast_cli_args::fd, find_or_create_temporary_state(), find_state_by_transport(), LOG_ERROR, name, NULL, parse(), RAII_VAR, S_OR, str, strsep(), ast_sip_transport_state::tls, tls_method_map, internal_state::transport, ast_cli_entry::usage, ast_variable::value, and var.

Referenced by ast_sip_initialize_sorcery_transport().

1162 {
1163  const struct ast_sip_transport *transport = obj;
1165 
1166  if (!state) {
1167  return -1;
1168  }
1169 
1170  if (ARRAY_IN_BOUNDS(state->tls.method, tls_method_map)) {
1171  *buf = ast_strdup(tls_method_map[state->tls.method]);
1172  }
1173 
1174  return 0;
1175 }
#define ARRAY_IN_BOUNDS(v, a)
Checks to see if value is within the bounds of the given array.
Definition: utils.h:658
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
#define ast_strdup(str)
A wrapper for strdup()
Definition: astmm.h:243
static struct ast_sip_transport_state * find_state_by_transport(const struct ast_sip_transport *transport)
Structure for SIP transport information.
Definition: res_pjsip.h:87
#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:911
static const char * tls_method_map[]
Transport to bind to.
Definition: res_pjsip.h:171
#define ao2_cleanup(obj)
Definition: astobj2.h:1958

◆ tos_to_str()

static int tos_to_str ( const void *  obj,
const intptr_t *  args,
char **  buf 
)
static

Definition at line 1444 of file config_transport.c.

References ast_asprintf, ast_sip_transport::tos, and internal_state::transport.

Referenced by ast_sip_initialize_sorcery_transport().

1445 {
1446  const struct ast_sip_transport *transport = obj;
1447 
1448  if (ast_asprintf(buf, "%u", transport->tos) == -1) {
1449  return -1;
1450  }
1451  return 0;
1452 }
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
#define ast_asprintf(ret, fmt,...)
A wrapper for asprintf()
Definition: astmm.h:269
Transport to bind to.
Definition: res_pjsip.h:171
unsigned int tos
Definition: res_pjsip.h:241

◆ transport_apply()

static int transport_apply ( const struct ast_sorcery sorcery,
void *  obj 
)
static

Apply handler for transports.

Definition at line 632 of file config_transport.c.

References ast_sip_transport::allow_reload, ao2_cleanup, ao2_link_flags, ao2_replace, ao2_unlink_flags, ao2_wrlock, ast_compare_versions(), ast_debug, ast_dnsmgr_lookup(), ast_log, ast_sip_get_pjsip_endpoint(), AST_SIP_X_AST_TXP, AST_SIP_X_AST_TXP_LEN, ast_sorcery_diff(), ast_sorcery_object_get_id(), ast_strlen_zero, AST_TRANSPORT_TCP, AST_TRANSPORT_TLS, AST_TRANSPORT_UDP, AST_TRANSPORT_WS, AST_TRANSPORT_WSS, ast_variables_destroy(), ast_sip_transport::async_operations, BIND_DELAY_US, BIND_TRIES, ast_sip_transport::ca_list_file, ast_sip_transport::ca_list_path, ast_sip_transport::cert_file, copy_state_to_transport(), ast_sip_transport::cos, ast_sip_transport::external_media_address, ast_sip_transport::external_signaling_address, find_internal_state_by_transport(), ast_sip_transport::flow, has_state_changed(), internal_state_alloc(), LOG_ERROR, LOG_WARNING, NULL, OBJ_NOLOCK, ast_sip_transport::password, ast_sip_transport::privkey_file, RAII_VAR, set_qos(), ast_sip_transport::state, states_cleanup(), ast_sip_transport_state::tls, ast_sip_transport::tos, internal_state::transport, and ast_sip_transport::type.

Referenced by ast_sip_initialize_sorcery_transport().

633 {
634  struct ast_sip_transport *transport = obj;
635  const char *transport_id = ast_sorcery_object_get_id(obj);
637  RAII_VAR(struct internal_state *, temp_state, NULL, ao2_cleanup);
638  RAII_VAR(struct internal_state *, perm_state, NULL, ao2_cleanup);
639  RAII_VAR(struct ast_variable *, changes, NULL, ast_variables_destroy);
640  pj_status_t res = -1;
641  int i;
642 #define BIND_TRIES 3
643 #define BIND_DELAY_US 100000
644 
645  if (!states) {
646  return -1;
647  }
648 
649  /*
650  * transport_apply gets called for EVERY retrieval of a transport when using realtime.
651  * We need to prevent multiple threads from trying to mess with underlying transports
652  * at the same time. The container is the only thing we have to lock on.
653  */
654  ao2_wrlock(states);
655 
656  temp_state = internal_state_alloc(transport);
657  if (!temp_state) {
658  ast_log(LOG_ERROR, "Transport '%s' failed to allocate memory\n", transport_id);
659  return -1;
660  }
661 
662  perm_state = find_internal_state_by_transport(transport);
663  if (perm_state) {
664  ast_sorcery_diff(sorcery, perm_state->transport, transport, &changes);
665  if (!changes && !has_state_changed(perm_state->state, temp_state->state)) {
666  /* In case someone is using the deprecated fields, reset them */
667  transport->state = perm_state->state;
668  copy_state_to_transport(transport);
669  ao2_replace(perm_state->transport, transport);
670  return 0;
671  }
672 
673  /* If we aren't allowed to reload then we copy values that can't be changed from perm_state */
674  if (!transport->allow_reload) {
675  memcpy(&temp_state->state->host, &perm_state->state->host, sizeof(temp_state->state->host));
676  memcpy(&temp_state->state->tls, &perm_state->state->tls, sizeof(temp_state->state->tls));
677  memcpy(&temp_state->state->ciphers, &perm_state->state->ciphers, sizeof(temp_state->state->ciphers));
678  }
679  }
680 
681  if (!transport->flow && (!perm_state || transport->allow_reload)) {
682  if (temp_state->state->host.addr.sa_family != PJ_AF_INET && temp_state->state->host.addr.sa_family != PJ_AF_INET6) {
683  ast_log(LOG_ERROR, "Transport '%s' could not be started as binding not specified\n", transport_id);
684  return -1;
685  }
686 
687  /* Set default port if not present */
688  if (!pj_sockaddr_get_port(&temp_state->state->host)) {
689  pj_sockaddr_set_port(&temp_state->state->host, (transport->type == AST_TRANSPORT_TLS) ? 5061 : 5060);
690  }
691  }
692 
693  /* Now that we know what address family we can set up a dnsmgr refresh for the external addresses if present */
694  if (!ast_strlen_zero(transport->external_signaling_address)) {
695  if (temp_state->state->host.addr.sa_family == pj_AF_INET()) {
696  temp_state->state->external_signaling_address.ss.ss_family = AF_INET;
697  } else if (temp_state->state->host.addr.sa_family == pj_AF_INET6()) {
698  temp_state->state->external_signaling_address.ss.ss_family = AF_INET6;
699  } else {
700  ast_log(LOG_ERROR, "Unknown address family for transport '%s', could not get external signaling address\n",
701  transport_id);
702  return -1;
703  }
704 
705  if (ast_dnsmgr_lookup(transport->external_signaling_address, &temp_state->state->external_signaling_address, &temp_state->state->external_signaling_address_refresher, NULL) < 0) {
706  ast_log(LOG_ERROR, "Could not create dnsmgr for external signaling address on '%s'\n", transport_id);
707  return -1;
708  }
709  }
710 
711  if (!ast_strlen_zero(transport->external_media_address)) {
712  if (temp_state->state->host.addr.sa_family == pj_AF_INET()) {
713  temp_state->state->external_media_address.ss.ss_family = AF_INET;
714  } else if (temp_state->state->host.addr.sa_family == pj_AF_INET6()) {
715  temp_state->state->external_media_address.ss.ss_family = AF_INET6;
716  } else {
717  ast_log(LOG_ERROR, "Unknown address family for transport '%s', could not get external media address\n",
718  transport_id);
719  return -1;
720  }
721 
722  if (ast_dnsmgr_lookup(transport->external_media_address, &temp_state->state->external_media_address, &temp_state->state->external_media_address_refresher, NULL) < 0) {
723  ast_log(LOG_ERROR, "Could not create dnsmgr for external media address on '%s'\n", transport_id);
724  return -1;
725  }
726  }
727 
728  if (transport->flow) {
729  pj_str_t address;
730 
731  ast_debug(1, "Ignoring any bind configuration on transport '%s' as it is a child of another\n",
732  transport_id);
733  pj_sockaddr_parse(pj_AF_UNSPEC(), 0, pj_cstr(&address, "0.0.0.0"), &temp_state->state->host);
734 
735  temp_state->state->flow = 1;
736  res = PJ_SUCCESS;
737  } else if (!transport->allow_reload && perm_state) {
738  /* We inherit the transport from perm state, untouched */
739  ast_log(LOG_WARNING, "Transport '%s' is not fully reloadable, not reloading: protocol, bind, TLS, TCP, ToS, or CoS options.\n", transport_id);
740  temp_state->state->transport = perm_state->state->transport;
741  perm_state->state->transport = NULL;
742  temp_state->state->factory = perm_state->state->factory;
743  perm_state->state->factory = NULL;
744  res = PJ_SUCCESS;
745  } else if (transport->type == AST_TRANSPORT_UDP) {
746 
747  for (i = 0; i < BIND_TRIES && res != PJ_SUCCESS; i++) {
748  if (perm_state && perm_state->state && perm_state->state->transport) {
749  pjsip_udp_transport_pause(perm_state->state->transport,
750  PJSIP_UDP_TRANSPORT_DESTROY_SOCKET);
751  usleep(BIND_DELAY_US);
752  }
753 
754  if (temp_state->state->host.addr.sa_family == pj_AF_INET()) {
755  res = pjsip_udp_transport_start(ast_sip_get_pjsip_endpoint(),
756  &temp_state->state->host.ipv4, NULL, transport->async_operations,
757  &temp_state->state->transport);
758  } else if (temp_state->state->host.addr.sa_family == pj_AF_INET6()) {
759  res = pjsip_udp_transport_start6(ast_sip_get_pjsip_endpoint(),
760  &temp_state->state->host.ipv6, NULL, transport->async_operations,
761  &temp_state->state->transport);
762  }
763  }
764 
765  if (res == PJ_SUCCESS) {
766  temp_state->state->transport->info = pj_pool_alloc(temp_state->state->transport->pool,
767  (AST_SIP_X_AST_TXP_LEN + strlen(transport_id) + 2));
768 
769  sprintf(temp_state->state->transport->info, "%s:%s", AST_SIP_X_AST_TXP, transport_id);
770 
771  if (transport->tos || transport->cos) {
772  pj_sock_t sock;
773  pj_qos_params qos_params;
774  sock = pjsip_udp_transport_get_socket(temp_state->state->transport);
775  pj_sock_get_qos_params(sock, &qos_params);
776  set_qos(transport, &qos_params);
777  pj_sock_set_qos_params(sock, &qos_params);
778  }
779  }
780  } else if (transport->type == AST_TRANSPORT_TCP) {
781  pjsip_tcp_transport_cfg cfg;
782  static int option = 1;
783 
784  pjsip_tcp_transport_cfg_default(&cfg, temp_state->state->host.addr.sa_family);
785  cfg.bind_addr = temp_state->state->host;
786  cfg.async_cnt = transport->async_operations;
787  set_qos(transport, &cfg.qos_params);
788  /* sockopt_params.options is copied to each newly connected socket */
789  cfg.sockopt_params.options[0].level = pj_SOL_TCP();
790  cfg.sockopt_params.options[0].optname = pj_TCP_NODELAY();
791  cfg.sockopt_params.options[0].optval = &option;
792  cfg.sockopt_params.options[0].optlen = sizeof(option);
793  cfg.sockopt_params.cnt = 1;
794 
795  for (i = 0; i < BIND_TRIES && res != PJ_SUCCESS; i++) {
796  if (perm_state && perm_state->state && perm_state->state->factory
797  && perm_state->state->factory->destroy) {
798  perm_state->state->factory->destroy(perm_state->state->factory);
799  usleep(BIND_DELAY_US);
800  }
801 
802  res = pjsip_tcp_transport_start3(ast_sip_get_pjsip_endpoint(), &cfg,
803  &temp_state->state->factory);
804  }
805  } else if (transport->type == AST_TRANSPORT_TLS) {
806 #if defined(PJ_HAS_SSL_SOCK) && PJ_HAS_SSL_SOCK != 0
807  static int option = 1;
808 
809  if (transport->async_operations > 1 && ast_compare_versions(pj_get_version(), "2.5.0") < 0) {
810  ast_log(LOG_ERROR, "Transport: %s: When protocol=tls and pjproject version < 2.5.0, async_operations can't be > 1\n",
812  return -1;
813  }
814 
815  temp_state->state->tls.password = pj_str((char*)transport->password);
816  set_qos(transport, &temp_state->state->tls.qos_params);
817 
818  /* sockopt_params.options is copied to each newly connected socket */
819  temp_state->state->tls.sockopt_params.options[0].level = pj_SOL_TCP();
820  temp_state->state->tls.sockopt_params.options[0].optname = pj_TCP_NODELAY();
821  temp_state->state->tls.sockopt_params.options[0].optval = &option;
822  temp_state->state->tls.sockopt_params.options[0].optlen = sizeof(option);
823  temp_state->state->tls.sockopt_params.cnt = 1;
824 
825  for (i = 0; i < BIND_TRIES && res != PJ_SUCCESS; i++) {
826  if (perm_state && perm_state->state && perm_state->state->factory
827  && perm_state->state->factory->destroy) {
828  perm_state->state->factory->destroy(perm_state->state->factory);
829  usleep(BIND_DELAY_US);
830  }
831 
832  res = pjsip_tls_transport_start2(ast_sip_get_pjsip_endpoint(), &temp_state->state->tls,
833  &temp_state->state->host, NULL, transport->async_operations,
834  &temp_state->state->factory);
835  }
836 #else
837  ast_log(LOG_ERROR, "Transport: %s: PJSIP has not been compiled with TLS transport support, ensure OpenSSL development packages are installed\n",
839  return -1;
840 #endif
841  } else if ((transport->type == AST_TRANSPORT_WS) || (transport->type == AST_TRANSPORT_WSS)) {
842  if (transport->cos || transport->tos) {
843  ast_log(LOG_WARNING, "TOS and COS values ignored for websocket transport\n");
844  } else if (!ast_strlen_zero(transport->ca_list_file) || !ast_strlen_zero(transport->ca_list_path) ||
845  !ast_strlen_zero(transport->cert_file) || !ast_strlen_zero(transport->privkey_file)) {
846  ast_log(LOG_WARNING, "TLS certificate values ignored for websocket transport as they are configured in http.conf\n");
847  }
848  res = PJ_SUCCESS;
849  }
850 
851  if (res != PJ_SUCCESS) {
852  char msg[PJ_ERR_MSG_SIZE];
853 
854  pj_strerror(res, msg, sizeof(msg));
855  ast_log(LOG_ERROR, "Transport '%s' could not be started: %s\n", ast_sorcery_object_get_id(obj), msg);
856  return -1;
857  }
858 
859  copy_state_to_transport(transport);
860  if (perm_state) {
861  ao2_unlink_flags(states, perm_state, OBJ_NOLOCK);
862  }
863  ao2_link_flags(states, temp_state, OBJ_NOLOCK);
864 
865  return 0;
866 }
void ast_variables_destroy(struct ast_variable *var)
Free variable list.
Definition: extconf.c:1263
char * address
Definition: f2c.h:59
#define LOG_WARNING
Definition: logger.h:274
const ast_string_field external_media_address
Definition: res_pjsip.h:191
static int has_state_changed(struct ast_sip_transport_state *a, struct ast_sip_transport_state *b)
Structure for variables, used for configurations and for channel variables.
static struct ao2_container * transport_states
Assume that the ao2_container is already locked.
Definition: astobj2.h:1067
int ast_sorcery_diff(const struct ast_sorcery *sorcery, const void *original, const void *modified, struct ast_variable **changes)
Create a changeset of two objects.
Definition: sorcery.c:1805
static struct internal_state * find_internal_state_by_transport(const struct ast_sip_transport *transport)
#define ao2_link_flags(container, obj, flags)
Definition: astobj2.h:1572
#define NULL
Definition: resample.c:96
unsigned int cos
Definition: res_pjsip.h:243
struct ast_sip_transport_state * state
Definition: res_pjsip.h:239
#define ao2_wrlock(a)
Definition: astobj2.h:720
static void set_qos(struct ast_sip_transport *transport, pj_qos_params *qos)
enum ast_transport type
Definition: res_pjsip.h:193
#define ast_strlen_zero(foo)
Definition: strings.h:52
const ast_string_field password
Definition: res_pjsip.h:191
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:452
#define ast_log
Definition: astobj2.c:42
const ast_string_field ca_list_path
Definition: res_pjsip.h:191
static void states_cleanup(void *states)
#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:911
pjsip_tls_setting tls
Definition: res_pjsip.h:111
const char * ast_sorcery_object_get_id(const void *object)
Get the unique identifier of a sorcery object.
Definition: sorcery.c:2312
static void copy_state_to_transport(struct ast_sip_transport *transport)
static struct internal_state * internal_state_alloc(struct ast_sip_transport *transport)
#define AST_SIP_X_AST_TXP_LEN
Definition: res_pjsip.h:910
#define LOG_ERROR
Definition: logger.h:285
const ast_string_field external_signaling_address
Definition: res_pjsip.h:191
Transport to bind to.
Definition: res_pjsip.h:171
unsigned int async_operations
Definition: res_pjsip.h:201
const ast_string_field ca_list_file
Definition: res_pjsip.h:191
const ast_string_field privkey_file
Definition: res_pjsip.h:191
pjsip_endpoint * ast_sip_get_pjsip_endpoint(void)
Get a pointer to the PJSIP endpoint.
Definition: res_pjsip.c:3718
#define ao2_replace(dst, src)
Definition: astobj2.h:517
#define ao2_cleanup(obj)
Definition: astobj2.h:1958
int ast_dnsmgr_lookup(const char *name, struct ast_sockaddr *result, struct ast_dnsmgr_entry **dnsmgr, const char *service)
Allocate and initialize a DNS manager entry.
Definition: dnsmgr.c:191
#define AST_SIP_X_AST_TXP
Definition: res_pjsip.h:909
#define ao2_unlink_flags(container, obj, flags)
Definition: astobj2.h:1622
unsigned int tos
Definition: res_pjsip.h:241
#define BIND_DELAY_US
int ast_compare_versions(const char *version1, const char *version2)
Compare 2 major.minor.patch.extra version strings.
Definition: main/utils.c:2872
Generic container type.
#define BIND_TRIES
const ast_string_field cert_file
Definition: res_pjsip.h:191

◆ transport_bind_handler()

static int transport_bind_handler ( const struct aco_option opt,
struct ast_variable var,
void *  obj 
)
static

Custom handler for turning a string bind into a pj_sockaddr.

Definition at line 1014 of file config_transport.c.

References ao2_cleanup, buf, find_or_create_temporary_state(), RAII_VAR, internal_state::transport, and ast_variable::value.

Referenced by ast_sip_initialize_sorcery_transport().

1015 {
1016  struct ast_sip_transport *transport = obj;
1017  pj_str_t buf;
1018  int rc;
1020 
1021  if (!state) {
1022  return -1;
1023  }
1024 
1025  rc = pj_sockaddr_parse(pj_AF_UNSPEC(), 0, pj_cstr(&buf, var->value), &state->host);
1026 
1027  return rc != PJ_SUCCESS ? -1 : 0;
1028 }
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
static struct ast_sip_transport_state * find_or_create_temporary_state(struct ast_sip_transport *transport)
Structure for SIP transport information.
Definition: res_pjsip.h:87
#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:911
Transport to bind to.
Definition: res_pjsip.h:171
#define ao2_cleanup(obj)
Definition: astobj2.h:1958

◆ transport_bind_to_str()

static int transport_bind_to_str ( const void *  obj,
const intptr_t *  args,
char **  buf 
)
static

Definition at line 1030 of file config_transport.c.

References ao2_cleanup, ast_calloc, find_state_by_transport(), MAX_OBJECT_FIELD, RAII_VAR, and internal_state::transport.

Referenced by ast_sip_initialize_sorcery_transport().

1031 {
1032  const struct ast_sip_transport *transport = obj;
1034 
1035  if (!state) {
1036  return -1;
1037  }
1038 
1039  if (!(*buf = ast_calloc(MAX_OBJECT_FIELD, sizeof(char)))) {
1040  return -1;
1041  }
1042 
1043  /* include port as well as brackets if IPv6 */
1044  pj_sockaddr_print(&state->host, *buf, MAX_OBJECT_FIELD, 1 | 2);
1045 
1046  return 0;
1047 }
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
static struct ast_sip_transport_state * find_state_by_transport(const struct ast_sip_transport *transport)
Structure for SIP transport information.
Definition: res_pjsip.h:87
#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:911
#define MAX_OBJECT_FIELD
Maximum length of an object field name.
Definition: sorcery.h:110
Transport to bind to.
Definition: res_pjsip.h:171
#define ast_calloc(num, len)
A wrapper for calloc()
Definition: astmm.h:204
#define ao2_cleanup(obj)
Definition: astobj2.h:1958

◆ transport_localnet_handler()

static int transport_localnet_handler ( const struct aco_option opt,
struct ast_variable var,
void *  obj 
)
static

Helper function which turns a cipher name into an identifier.

Custom handler for TLS cipher setting

Custom handler for localnet setting

Definition at line 1346 of file config_transport.c.

References ao2_cleanup, ast_append_ha(), ast_free_ha(), ast_strlen_zero, error(), find_or_create_temporary_state(), ast_sip_transport_state::localnet, NULL, RAII_VAR, internal_state::transport, and ast_variable::value.

Referenced by ast_sip_initialize_sorcery_transport().

1347 {
1348  struct ast_sip_transport *transport = obj;
1349  int error = 0;
1351 
1352  if (!state) {
1353  return -1;
1354  }
1355 
1356  if (ast_strlen_zero(var->value)) {
1357  ast_free_ha(state->localnet);
1358  state->localnet = NULL;
1359  return 0;
1360  }
1361 
1362  /* We use only the ast_apply_ha() which defaults to ALLOW
1363  * ("permit"), so we add DENY rules. */
1364  if (!(state->localnet = ast_append_ha("deny", var->value, state->localnet, &error))) {
1365  return -1;
1366  }
1367 
1368  return error;
1369 }
#define NULL
Definition: resample.c:96
#define ast_strlen_zero(foo)
Definition: strings.h:52
static struct ast_sip_transport_state * find_or_create_temporary_state(struct ast_sip_transport *transport)
Structure for SIP transport information.
Definition: res_pjsip.h:87
#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:911
Transport to bind to.
Definition: res_pjsip.h:171
void ast_free_ha(struct ast_ha *ha)
Free a list of HAs.
Definition: acl.c:222
#define ao2_cleanup(obj)
Definition: astobj2.h:1958
struct ast_ha * ast_append_ha(const char *sense, const char *stuff, struct ast_ha *path, int *error)
Add a new rule to a list of HAs.
Definition: acl.c:713
int error(const char *format,...)
Definition: utils/frame.c:999

◆ transport_protocol_handler()

static int transport_protocol_handler ( const struct aco_option opt,
struct ast_variable var,
void *  obj 
)
static

Custom handler for turning a string protocol into an enum.

Definition at line 959 of file config_transport.c.

References ao2_cleanup, AST_TRANSPORT_TCP, AST_TRANSPORT_TLS, AST_TRANSPORT_UDP, AST_TRANSPORT_WS, AST_TRANSPORT_WSS, find_or_create_temporary_state(), ast_sip_transport::flow, RAII_VAR, internal_state::transport, ast_sip_transport::type, and ast_variable::value.

Referenced by ast_sip_initialize_sorcery_transport().

960 {
961  struct ast_sip_transport *transport = obj;
963 
964  if (!state) {
965  return -1;
966  }
967 
968  if (!strcasecmp(var->value, "flow")) {
969  transport->flow = 1;
970  } else {
971  if (!strcasecmp(var->value, "udp")) {
972  transport->type = AST_TRANSPORT_UDP;
973  } else if (!strcasecmp(var->value, "tcp")) {
974  transport->type = AST_TRANSPORT_TCP;
975  } else if (!strcasecmp(var->value, "tls")) {
976  transport->type = AST_TRANSPORT_TLS;
977  } else if (!strcasecmp(var->value, "ws")) {
978  transport->type = AST_TRANSPORT_WS;
979  } else if (!strcasecmp(var->value, "wss")) {
980  transport->type = AST_TRANSPORT_WSS;
981  } else {
982  return -1;
983  }
984  transport->flow = 0;
985  }
986 
987  state->type = transport->type;
988 
989  return 0;
990 }
enum ast_transport type
Definition: res_pjsip.h:193
static struct ast_sip_transport_state * find_or_create_temporary_state(struct ast_sip_transport *transport)
Structure for SIP transport information.
Definition: res_pjsip.h:87
#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:911
Transport to bind to.
Definition: res_pjsip.h:171
#define ao2_cleanup(obj)
Definition: astobj2.h:1958

◆ transport_protocol_to_str()

static int transport_protocol_to_str ( const void *  obj,
const intptr_t *  args,
char **  buf 
)
static

Definition at line 1000 of file config_transport.c.

References ARRAY_IN_BOUNDS, ast_strdup, ast_sip_transport::flow, internal_state::transport, transport_types, and ast_sip_transport::type.

Referenced by ast_sip_initialize_sorcery_transport().

1001 {
1002  const struct ast_sip_transport *transport = obj;
1003 
1004  if (transport->flow) {
1005  *buf = ast_strdup("flow");
1006  } else if (ARRAY_IN_BOUNDS(transport->type, transport_types)) {
1007  *buf = ast_strdup(transport_types[transport->type]);
1008  }
1009 
1010  return 0;
1011 }
#define ARRAY_IN_BOUNDS(v, a)
Checks to see if value is within the bounds of the given array.
Definition: utils.h:658
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
#define ast_strdup(str)
A wrapper for strdup()
Definition: astmm.h:243
enum ast_transport type
Definition: res_pjsip.h:193
static const char * transport_types[]
Transport to bind to.
Definition: res_pjsip.h:171

◆ transport_state_cmp()

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

comparator function for state objects

Definition at line 134 of file config_transport.c.

References ast_assert, CMP_MATCH, ast_sip_transport_state::id, OBJ_SEARCH_KEY, OBJ_SEARCH_MASK, OBJ_SEARCH_OBJECT, and OBJ_SEARCH_PARTIAL_KEY.

Referenced by ast_sip_get_transport_states().

135 {
136  const struct ast_sip_transport_state *object_left = obj;
137  const struct ast_sip_transport_state *object_right = arg;
138  const char *right_key = arg;
139  int cmp;
140 
141  switch (flags & OBJ_SEARCH_MASK) {
142  case OBJ_SEARCH_OBJECT:
143  right_key = object_right->id;
144  /* Fall through */
145  case OBJ_SEARCH_KEY:
146  cmp = strcmp(object_left->id, right_key);
147  break;
149  /* Not supported by container. */
150  ast_assert(0);
151  return 0;
152  default:
153  cmp = 0;
154  break;
155  }
156  if (cmp) {
157  return 0;
158  }
159  return CMP_MATCH;
160 }
The arg parameter is a search key, but is not an object.
Definition: astobj2.h:1105
#define ast_assert(a)
Definition: utils.h:695
The arg parameter is a partial search key similar to OBJ_SEARCH_KEY.
Definition: astobj2.h:1120
Structure for SIP transport information.
Definition: res_pjsip.h:87
The arg parameter is an object of the same type.
Definition: astobj2.h:1091
Search option field mask.
Definition: astobj2.h:1076

◆ transport_state_hash()

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

hashing function for state objects

Definition at line 113 of file config_transport.c.

References ast_assert, ast_str_hash(), OBJ_SEARCH_KEY, OBJ_SEARCH_MASK, and OBJ_SEARCH_OBJECT.

Referenced by ast_sip_get_transport_states().

114 {
115  const struct ast_sip_transport_state *object;
116  const char *key;
117 
118  switch (flags & OBJ_SEARCH_MASK) {
119  case OBJ_SEARCH_KEY:
120  key = obj;
121  break;
122  case OBJ_SEARCH_OBJECT:
123  object = obj;
124  key = object->id;
125  break;
126  default:
127  ast_assert(0);
128  return 0;
129  }
130  return ast_str_hash(key);
131 }
The arg parameter is a search key, but is not an object.
Definition: astobj2.h:1105
#define ast_assert(a)
Definition: utils.h:695
Structure for SIP transport information.
Definition: res_pjsip.h:87
The arg parameter is an object of the same type.
Definition: astobj2.h:1091
Search option field mask.
Definition: astobj2.h:1076
static force_inline int attribute_pure ast_str_hash(const char *str)
Compute a hash value on a string.
Definition: strings.h:1206

◆ transport_state_init()

static int transport_state_init ( const struct aco_option opt,
struct ast_variable var,
void *  obj 
)
static

Custom handler for type just makes sure the state is created.

Definition at line 869 of file config_transport.c.

References ao2_cleanup, find_or_create_temporary_state(), and internal_state::transport.

Referenced by ast_sip_initialize_sorcery_transport().

870 {
871  struct ast_sip_transport *transport = obj;
873 
874  ao2_cleanup(state);
875 
876  return 0;
877 }
static struct ast_sip_transport_state * find_or_create_temporary_state(struct ast_sip_transport *transport)
Structure for SIP transport information.
Definition: res_pjsip.h:87
Transport to bind to.
Definition: res_pjsip.h:171
#define ao2_cleanup(obj)
Definition: astobj2.h:1958

◆ transport_tls_bool_handler()

static int transport_tls_bool_handler ( const struct aco_option opt,
struct ast_variable var,
void *  obj 
)
static

Custom handler for TLS boolean settings.

Definition at line 1050 of file config_transport.c.

References ao2_cleanup, ast_true(), find_or_create_temporary_state(), ast_variable::name, RAII_VAR, internal_state::transport, and ast_variable::value.

Referenced by ast_sip_initialize_sorcery_transport().

1051 {
1052  struct ast_sip_transport *transport = obj;
1054 
1055  if (!state) {
1056  return -1;
1057  }
1058 
1059  if (!strcasecmp(var->name, "verify_server")) {
1060  state->tls.verify_server = ast_true(var->value) ? PJ_TRUE : PJ_FALSE;
1061  } else if (!strcasecmp(var->name, "verify_client")) {
1062  state->tls.verify_client = ast_true(var->value) ? PJ_TRUE : PJ_FALSE;
1063  } else if (!strcasecmp(var->name, "require_client_cert")) {
1064  state->tls.require_client_cert = ast_true(var->value) ? PJ_TRUE : PJ_FALSE;
1065  } else {
1066  return -1;
1067  }
1068 
1069  return 0;
1070 }
static struct ast_sip_transport_state * find_or_create_temporary_state(struct ast_sip_transport *transport)
Structure for SIP transport information.
Definition: res_pjsip.h:87
#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:911
int attribute_pure ast_true(const char *val)
Make sure something is true. Determine if a string containing a boolean value is "true". This function checks to see whether a string passed to it is an indication of an "true" value. It checks to see if the string is "yes", "true", "y", "t", "on" or "1".
Definition: main/utils.c:1951
Transport to bind to.
Definition: res_pjsip.h:171
#define ao2_cleanup(obj)
Definition: astobj2.h:1958

◆ transport_tls_file_handler()

static int transport_tls_file_handler ( const struct aco_option opt,
struct ast_variable var,
void *  obj 
)
static

Custom handler for TLS method setting.

Definition at line 880 of file config_transport.c.

References ao2_cleanup, ast_file_is_readable(), ast_log, ast_sorcery_object_get_id(), ast_string_field_set, ast_strlen_zero, ast_sip_transport::ca_list_file, ast_sip_transport::ca_list_path, ast_sip_transport::cert_file, find_or_create_temporary_state(), LOG_ERROR, LOG_WARNING, ast_variable::name, ast_sip_transport::privkey_file, RAII_VAR, internal_state::transport, and ast_variable::value.

Referenced by ast_sip_initialize_sorcery_transport().

881 {
882  struct ast_sip_transport *transport = obj;
884 
885  if (!state) {
886  return -1;
887  }
888 
889  if (ast_strlen_zero(var->value)) {
890  /* Ignore empty options */
891  return 0;
892  }
893 
894  if (!ast_file_is_readable(var->value)) {
895  ast_log(LOG_ERROR, "Transport: %s: %s %s is either missing or not readable\n",
896  ast_sorcery_object_get_id(obj), var->name, var->value);
897  return -1;
898  }
899 
900  if (!strcasecmp(var->name, "ca_list_file")) {
901  state->tls.ca_list_file = pj_str((char*)var->value);
902  ast_string_field_set(transport, ca_list_file, var->value);
903  } else if (!strcasecmp(var->name, "ca_list_path")) {
904 #ifdef HAVE_PJ_SSL_CERT_LOAD_FROM_FILES2
905  state->tls.ca_list_path = pj_str((char*)var->value);
906  ast_string_field_set(transport, ca_list_path, var->value);
907 #else
908  ast_log(LOG_WARNING, "Asterisk has been built against a version of pjproject that does not "
909  "support the 'ca_list_path' option. Please upgrade to version 2.4 or later.\n");
910 #endif
911  } else if (!strcasecmp(var->name, "cert_file")) {
912  state->tls.cert_file = pj_str((char*)var->value);
913  ast_string_field_set(transport, cert_file, var->value);
914  } else if (!strcasecmp(var->name, "priv_key_file")) {
915  state->tls.privkey_file = pj_str((char*)var->value);
916  ast_string_field_set(transport, privkey_file, var->value);
917  }
918 
919  return 0;
920 }
#define LOG_WARNING
Definition: logger.h:274
int ast_file_is_readable(const char *filename)
Test that a file exists and is readable by the effective user.
Definition: main/utils.c:2855
#define ast_strlen_zero(foo)
Definition: strings.h:52
static struct ast_sip_transport_state * find_or_create_temporary_state(struct ast_sip_transport *transport)
#define ast_log
Definition: astobj2.c:42
const ast_string_field ca_list_path
Definition: res_pjsip.h:191
Structure for SIP transport information.
Definition: res_pjsip.h:87
#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:911
const char * ast_sorcery_object_get_id(const void *object)
Get the unique identifier of a sorcery object.
Definition: sorcery.c:2312
#define LOG_ERROR
Definition: logger.h:285
Transport to bind to.
Definition: res_pjsip.h:171
const ast_string_field ca_list_file
Definition: res_pjsip.h:191
const ast_string_field privkey_file
Definition: res_pjsip.h:191
#define ao2_cleanup(obj)
Definition: astobj2.h:1958
const ast_string_field cert_file
Definition: res_pjsip.h:191
#define ast_string_field_set(x, field, data)
Set a field to a simple string value.
Definition: stringfields.h:514

◆ transport_tls_method_handler()

static int transport_tls_method_handler ( const struct aco_option opt,
struct ast_variable var,
void *  obj 
)
static

Custom handler for TLS method setting.

Definition at line 1115 of file config_transport.c.

References ao2_cleanup, ast_strlen_zero, find_or_create_temporary_state(), RAII_VAR, internal_state::transport, and ast_variable::value.

Referenced by ast_sip_initialize_sorcery_transport().

1116 {
1117  struct ast_sip_transport *transport = obj;
1119 
1120  if (!state) {
1121  return -1;
1122  }
1123 
1124  if (ast_strlen_zero(var->value) || !strcasecmp(var->value, "default")) {
1125  state->tls.method = PJSIP_SSL_DEFAULT_METHOD;
1126  } else if (!strcasecmp(var->value, "unspecified")) {
1127  state->tls.method = PJSIP_SSL_UNSPECIFIED_METHOD;
1128  } else if (!strcasecmp(var->value, "tlsv1")) {
1129  state->tls.method = PJSIP_TLSV1_METHOD;
1130 #ifdef HAVE_PJSIP_TLS_TRANSPORT_PROTO
1131  } else if (!strcasecmp(var->value, "tlsv1_1")) {
1132  state->tls.method = PJSIP_TLSV1_1_METHOD;
1133  } else if (!strcasecmp(var->value, "tlsv1_2")) {
1134  state->tls.method = PJSIP_TLSV1_2_METHOD;
1135 #endif
1136  } else if (!strcasecmp(var->value, "sslv2")) {
1137  state->tls.method = PJSIP_SSLV2_METHOD;
1138  } else if (!strcasecmp(var->value, "sslv3")) {
1139  state->tls.method = PJSIP_SSLV3_METHOD;
1140  } else if (!strcasecmp(var->value, "sslv23")) {
1141  state->tls.method = PJSIP_SSLV23_METHOD;
1142  } else {
1143  return -1;
1144  }
1145 
1146  return 0;
1147 }
#define ast_strlen_zero(foo)
Definition: strings.h:52
static struct ast_sip_transport_state * find_or_create_temporary_state(struct ast_sip_transport *transport)
Structure for SIP transport information.
Definition: res_pjsip.h:87
#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:911
Transport to bind to.
Definition: res_pjsip.h:171
#define ao2_cleanup(obj)
Definition: astobj2.h:1958

◆ transport_tos_handler()

static int transport_tos_handler ( const struct aco_option opt,
struct ast_variable var,
void *  obj 
)
static

Custom handler for TOS setting.

Definition at line 1419 of file config_transport.c.

References ast_log, ast_sorcery_object_get_id(), ast_str2tos(), LOG_ERROR, LOG_WARNING, ast_sip_transport::tos, internal_state::transport, value, and ast_variable::value.

Referenced by ast_sip_initialize_sorcery_transport().

1420 {
1421  struct ast_sip_transport *transport = obj;
1422  unsigned int value;
1423 
1424  if (ast_str2tos(var->value, &value)) {
1425  ast_log(LOG_ERROR, "Error configuring transport '%s' - Could not "
1426  "interpret 'tos' value '%s'\n",
1427  ast_sorcery_object_get_id(transport), var->value);
1428  return -1;
1429  }
1430 
1431  if (value % 4) {
1432  value = value >> 2;
1433  value = value << 2;
1435  "transport '%s' - 'tos' value '%s' uses bits that are "
1436  "discarded when converted to DSCP. Using equivalent %u instead.\n",
1437  ast_sorcery_object_get_id(transport), var->value, value);
1438  }
1439 
1440  transport->tos = value;
1441  return 0;
1442 }
#define LOG_WARNING
Definition: logger.h:274
int ast_str2tos(const char *value, unsigned int *tos)
Convert a string to the appropriate TOS value.
Definition: acl.c:967
int value
Definition: syslog.c:37
#define ast_log
Definition: astobj2.c:42
const char * ast_sorcery_object_get_id(const void *object)
Get the unique identifier of a sorcery object.
Definition: sorcery.c:2312
#define LOG_ERROR
Definition: logger.h:285
Transport to bind to.
Definition: res_pjsip.h:171
unsigned int tos
Definition: res_pjsip.h:241

◆ verify_client_to_str()

static int verify_client_to_str ( const void *  obj,
const intptr_t *  args,
char **  buf 
)
static

Definition at line 1086 of file config_transport.c.

References ao2_cleanup, ast_strdup, AST_YESNO, find_state_by_transport(), RAII_VAR, and internal_state::transport.

Referenced by ast_sip_initialize_sorcery_transport().

1087 {
1088  const struct ast_sip_transport *transport = obj;
1090 
1091  if (!state) {
1092  return -1;
1093  }
1094 
1095  *buf = ast_strdup(AST_YESNO(state->tls.verify_client));
1096 
1097  return 0;
1098 }
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
#define ast_strdup(str)
A wrapper for strdup()
Definition: astmm.h:243
static struct ast_sip_transport_state * find_state_by_transport(const struct ast_sip_transport *transport)
Structure for SIP transport information.
Definition: res_pjsip.h:87
#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:911
Transport to bind to.
Definition: res_pjsip.h:171
#define AST_YESNO(x)
return Yes or No depending on the argument.
Definition: strings.h:139
#define ao2_cleanup(obj)
Definition: astobj2.h:1958

◆ verify_server_to_str()

static int verify_server_to_str ( const void *  obj,
const intptr_t *  args,
char **  buf 
)
static

Definition at line 1072 of file config_transport.c.

References ao2_cleanup, ast_strdup, AST_YESNO, find_state_by_transport(), RAII_VAR, and internal_state::transport.

Referenced by ast_sip_initialize_sorcery_transport().

1073 {
1074  const struct ast_sip_transport *transport = obj;
1076 
1077  if (!state) {
1078  return -1;
1079  }
1080 
1081  *buf = ast_strdup(AST_YESNO(state->tls.verify_server));
1082 
1083  return 0;
1084 }
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
#define ast_strdup(str)
A wrapper for strdup()
Definition: astmm.h:243
static struct ast_sip_transport_state * find_state_by_transport(const struct ast_sip_transport *transport)
Structure for SIP transport information.
Definition: res_pjsip.h:87
#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:911
Transport to bind to.
Definition: res_pjsip.h:171
#define AST_YESNO(x)
return Yes or No depending on the argument.
Definition: strings.h:139
#define ao2_cleanup(obj)
Definition: astobj2.h:1958

Variable Documentation

◆ cli_commands

struct ast_cli_entry cli_commands[]
static

Definition at line 1542 of file config_transport.c.

◆ cli_formatter

struct ast_sip_cli_formatter_entry* cli_formatter
static

Definition at line 1562 of file config_transport.c.

◆ endpoint_transport_formatter

struct ast_sip_endpoint_formatter endpoint_transport_formatter
Initial value:
= {
}
static int format_ami_endpoint_transport(const struct ast_sip_endpoint *endpoint, struct ast_sip_ami *ami)

Definition at line 202 of file config_transport.c.

◆ temp_state_store

struct ast_threadstorage temp_state_store = { .once = PTHREAD_ONCE_INIT , .key_init = __init_temp_state_store , .custom_init = NULL , }
static

◆ tls_method_map

const char* tls_method_map[]
static

Definition at line 1149 of file config_transport.c.

Referenced by tls_method_to_str().

◆ transport_states

struct ao2_container* transport_states
static

◆ transport_types

const char* transport_types[]
static

Definition at line 992 of file config_transport.c.

Referenced by cli_print_body(), and transport_protocol_to_str().