Asterisk - The Open Source Telephony Project GIT-master-2de1a68
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)
 
static int allow_wildcard_certs_to_str (const void *obj, const intptr_t *args, char **buf)
 
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_vectorast_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)
 Custom handler for localnet setting. 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

◆ BIND_TRIES

#define BIND_TRIES   3

◆ DEFAULT_STATE_BUCKETS

#define DEFAULT_STATE_BUCKETS   53

Default number of state container buckets.

Definition at line 39 of file config_transport.c.

◆ 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{

◆ allow_wildcard_certs_to_str()

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

Definition at line 1194 of file config_transport.c.

1195{
1197
1198 if (!state) {
1199 return -1;
1200 }
1201
1202 *buf = ast_strdup(AST_YESNO(state->allow_wildcard_certs));
1203 ao2_ref(state, -1);
1204
1205 return 0;
1206}
#define ast_strdup(str)
A wrapper for strdup()
Definition: astmm.h:241
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
Definition: astobj2.h:459
static struct ast_sip_transport_state * find_state_by_transport(const struct ast_sip_transport *transport)
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
#define AST_YESNO(x)
return Yes or No depending on the argument.
Definition: strings.h:143
Structure for SIP transport information.
Definition: res_pjsip.h:119

References ao2_ref, ast_strdup, AST_YESNO, buf, and find_state_by_transport().

Referenced by ast_sip_initialize_sorcery_transport().

◆ ast_sip_destroy_sorcery_transport()

int ast_sip_destroy_sorcery_transport ( void  )

Definition at line 1798 of file config_transport.c.

1799{
1802
1804
1807
1808 return 0;
1809}
int ast_cli_unregister_multiple(struct ast_cli_entry *e, int len)
Unregister multiple commands.
Definition: clicompat.c:30
static struct ast_cli_entry cli_commands[]
struct ast_sip_endpoint_formatter endpoint_transport_formatter
static struct ast_sip_cli_formatter_entry * cli_formatter
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:487
int ast_sip_unregister_cli_formatter(struct ast_sip_cli_formatter_entry *formatter)
Unregisters a CLI formatter.
Definition: pjsip_cli.c:326
#define NULL
Definition: resample.c:96
#define ARRAY_LEN(a)
Definition: utils.h:666

References ao2_ref, ARRAY_LEN, ast_cli_unregister_multiple(), ast_sip_unregister_cli_formatter(), ast_sip_unregister_endpoint_formatter(), cli_commands, cli_formatter, endpoint_transport_formatter, NULL, and transport_states.

Referenced by ast_res_pjsip_destroy_configuration().

◆ 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
Return values
transport_state
Note
ao2_cleanup(...) or ao2_ref(..., -1) must be called on the returned object

Definition at line 1669 of file config_transport.c.

1670{
1671 struct internal_state *state = NULL;
1672 struct ast_sip_transport_state *trans_state;
1673
1674 if (!transport_states) {
1675 return NULL;
1676 }
1677
1679 if (!state) {
1680 return NULL;
1681 }
1682
1683 trans_state = ao2_bump(state->state);
1684 ao2_ref(state, -1);
1685
1686 /* If this is a child transport see if the transport is actually dead */
1687 if (trans_state->flow) {
1688 ao2_lock(trans_state);
1689 if (trans_state->transport && trans_state->transport->is_shutdown == PJ_TRUE) {
1690 pjsip_transport_dec_ref(trans_state->transport);
1691 trans_state->transport = NULL;
1692 }
1693 ao2_unlock(trans_state);
1694 }
1695
1696 return trans_state;
1697}
#define ao2_find(container, arg, flags)
Definition: astobj2.h:1736
#define ao2_unlock(a)
Definition: astobj2.h:729
#define ao2_lock(a)
Definition: astobj2.h:717
#define ao2_bump(obj)
Bump refcount on an AO2 object by one, returning the object.
Definition: astobj2.h:480
@ OBJ_SEARCH_KEY
The arg parameter is a search key, but is not an object.
Definition: astobj2.h:1101
struct pjsip_transport * transport
Transport itself.
Definition: res_pjsip.h:121

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

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(), session_outgoing_nat_hook(), t38_initialize_session(), and transport_tls_verify().

◆ ast_sip_get_transport_states()

struct ao2_container * ast_sip_get_transport_states ( void  )

Retrieves all transport states.

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

Definition at line 1709 of file config_transport.c.

1710{
1713
1714 if (!states) {
1715 return NULL;
1716 }
1717
1719 return states;
1720}
@ AO2_ALLOC_OPT_LOCK_MUTEX
Definition: astobj2.h:363
#define ao2_callback(c, flags, cb_fn, arg)
ao2_callback() is a generic function that applies cb_fn() to all objects in a container,...
Definition: astobj2.h:1693
@ OBJ_NODATA
Definition: astobj2.h:1044
@ OBJ_MULTIPLE
Definition: astobj2.h:1049
#define ao2_container_alloc_hash(ao2_options, container_options, n_buckets, hash_fn, sort_fn, cmp_fn)
Allocate and initialize a hash container with the desired number of buckets.
Definition: astobj2.h:1303
static int transport_state_hash(const void *obj, const int flags)
hashing function for state objects
static int transport_state_cmp(void *obj, void *arg, int flags)
comparator 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)
Generic container type.

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(), transport_state_hash(), and transport_states.

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

◆ ast_sip_initialize_sorcery_transport()

int ast_sip_initialize_sorcery_transport ( void  )

Initialize sorcery with transport support.

Definition at line 1723 of file config_transport.c.

1724{
1726 struct ao2_container *transports = NULL;
1727
1728 /* Create outbound registration states container. */
1731 if (!transport_states) {
1732 ast_log(LOG_ERROR, "Unable to allocate transport states container\n");
1733 return -1;
1734 }
1735
1736 ast_sorcery_apply_default(sorcery, "transport", "config", "pjsip.conf,criteria=type=transport");
1737
1739 return -1;
1740 }
1741
1742 /* Normally type is a OPT_NOOP_T but we're using it to make sure that state is created */
1746 ast_sorcery_object_field_register(sorcery, "transport", "async_operations", "1", OPT_UINT_T, 0, FLDSET(struct ast_sip_transport, async_operations));
1747
1752
1753 ast_sorcery_object_field_register(sorcery, "transport", "password", "", OPT_STRINGFIELD_T, 0, STRFLDSET(struct ast_sip_transport, password));
1754 ast_sorcery_object_field_register(sorcery, "transport", "external_signaling_address", "", OPT_STRINGFIELD_T, 0, STRFLDSET(struct ast_sip_transport, external_signaling_address));
1755 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);
1756 ast_sorcery_object_field_register(sorcery, "transport", "external_media_address", "", OPT_STRINGFIELD_T, 0, STRFLDSET(struct ast_sip_transport, external_media_address));
1757 ast_sorcery_object_field_register(sorcery, "transport", "domain", "", OPT_STRINGFIELD_T, 0, STRFLDSET(struct ast_sip_transport, domain));
1763#if defined(PJ_HAS_SSL_SOCK) && PJ_HAS_SSL_SOCK != 0
1764 ast_sorcery_object_field_register_custom(sorcery, "transport", "cipher", "", transport_tls_cipher_handler, transport_tls_cipher_to_str, NULL, 0, 0);
1765#endif
1768 ast_sorcery_object_field_register(sorcery, "transport", "cos", "0", OPT_UINT_T, 0, FLDSET(struct ast_sip_transport, cos));
1769 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);
1770 ast_sorcery_object_field_register(sorcery, "transport", "allow_reload", "no", OPT_BOOL_T, 1, FLDSET(struct ast_sip_transport, allow_reload));
1771 ast_sorcery_object_field_register(sorcery, "transport", "symmetric_transport", "no", OPT_BOOL_T, 1, FLDSET(struct ast_sip_transport, symmetric_transport));
1772
1774
1776 if (!cli_formatter) {
1777 ast_log(LOG_ERROR, "Unable to allocate memory for cli formatter\n");
1778 return -1;
1779 }
1780 cli_formatter->name = "transport";
1787
1790
1791 /* trigger load of transports from realtime by trying to revrieve them all */
1793 ao2_cleanup(transports);
1794
1795 return 0;
1796}
#define ast_log
Definition: astobj2.c:42
#define ao2_cleanup(obj)
Definition: astobj2.h:1934
#define ao2_alloc(data_size, destructor_fn)
Definition: astobj2.h:409
unsigned int cos
Definition: chan_iax2.c:359
#define ast_cli_register_multiple(e, len)
Register multiple commands.
Definition: cli.h:265
#define STRFLDSET(type,...)
Convert a struct and a list of stringfield fields to an argument list of field offsets.
#define FLDSET(type,...)
Convert a struct and list of fields to an argument list of field offsets.
@ OPT_UINT_T
Type for default option handler for unsigned integers.
@ OPT_BOOL_T
Type for default option handler for bools (ast_true/ast_false)
@ OPT_INT_T
Type for default option handler for signed integers.
@ OPT_STRINGFIELD_T
Type for default option handler for stringfields.
static int require_client_cert_to_str(const void *obj, const intptr_t *args, char **buf)
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 verify_server_to_str(const void *obj, const intptr_t *args, char **buf)
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 cli_print_header(void *obj, void *arg, int flags)
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 tls_method_to_str(const void *obj, const intptr_t *args, char **buf)
static int transport_protocol_to_str(const void *obj, const intptr_t *args, char **buf)
static int internal_state_hash(const void *obj, const int flags)
hashing function for state objects
static int verify_client_to_str(const void *obj, const intptr_t *args, char **buf)
static int allow_wildcard_certs_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 int transport_tls_bool_handler(const struct aco_option *opt, struct ast_variable *var, void *obj)
Custom handler for TLS boolean settings.
static int transport_bind_to_str(const void *obj, const intptr_t *args, char **buf)
static int internal_state_cmp(void *obj, void *arg, int flags)
comparator function for state objects
static int localnet_to_str(const void *obj, const intptr_t *args, char **buf)
static int privkey_file_to_str(const void *obj, const intptr_t *args, char **buf)
static int cli_iterate(void *container, ao2_callback_fn callback, void *args)
static int transport_localnet_handler(const struct aco_option *opt, struct ast_variable *var, void *obj)
Custom handler for localnet setting.
static void * cli_retrieve_by_id(const char *id)
static int tos_to_str(const void *obj, const intptr_t *args, char **buf)
static struct ao2_container * cli_get_container(const char *regex)
static int transport_apply(const struct ast_sorcery *sorcery, void *obj)
Apply handler for transports.
static int cli_print_body(void *obj, void *arg, int flags)
static int localnet_to_vl(const void *obj, struct ast_variable **fields)
static int transport_tls_file_handler(const struct aco_option *opt, struct ast_variable *var, void *obj)
Custom handler for TLS method setting.
static int transport_tos_handler(const struct aco_option *opt, struct ast_variable *var, void *obj)
Custom handler for TOS setting.
static int ca_list_file_to_str(const void *obj, const intptr_t *args, char **buf)
static void * sip_transport_alloc(const char *name)
Allocator for transport.
static int ca_list_path_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 AST_DEFAULT_WEBSOCKET_WRITE_TIMEOUT_STR
Default websocket write timeout, in ms (as a string)
#define LOG_ERROR
void ast_sip_register_endpoint_formatter(struct ast_sip_endpoint_formatter *obj)
Register an endpoint formatter.
Definition: res_pjsip.c:481
struct ast_sorcery * ast_sip_get_sorcery(void)
Get a pointer to the SIP sorcery structure.
int ast_sip_register_cli_formatter(struct ast_sip_cli_formatter_entry *formatter)
Registers a CLI formatter.
Definition: pjsip_cli.c:310
static struct ast_sorcery * sorcery
const char * ast_sorcery_object_get_id(const void *object)
Get the unique identifier of a sorcery object.
Definition: sorcery.c:2312
@ AST_RETRIEVE_FLAG_MULTIPLE
Return all matching objects.
Definition: sorcery.h:120
@ AST_RETRIEVE_FLAG_ALL
Perform no matching, return all objects.
Definition: sorcery.h:123
#define ast_sorcery_object_register(sorcery, type, alloc, transform, apply)
Register an object type.
Definition: sorcery.h:837
#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 ast_sorcery_object_field_register(sorcery, type, name, default_val, opt_type, flags,...)
Register a field within an object.
Definition: sorcery.h:955
#define ast_sorcery_apply_default(sorcery, type, name, data)
Definition: sorcery.h:476
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
CLI Formatter Registry Entry.
Definition: res_pjsip_cli.h:52
int(* iterate)(void *container, ao2_callback_fn callback, void *args)
Definition: res_pjsip_cli.h:66
ao2_callback_fn * print_header
Definition: res_pjsip_cli.h:60
void *(* retrieve_by_id)(const char *id)
Definition: res_pjsip_cli.h:68
const char *(* get_id)(const void *obj)
Definition: res_pjsip_cli.h:70
const char * name
Definition: res_pjsip_cli.h:58
ao2_callback_fn * print_body
Definition: res_pjsip_cli.h:62
struct ao2_container *(* get_container)(const char *regex)
Definition: res_pjsip_cli.h:64
Transport to bind to.
Definition: res_pjsip.h:221
Full structure for sorcery.
Definition: sorcery.c:230

References allow_wildcard_certs_to_str(), 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_commands, cli_formatter, cli_get_container(), cli_iterate(), cli_print_body(), cli_print_header(), cli_retrieve_by_id(), cos, DEFAULT_STATE_BUCKETS, endpoint_transport_formatter, 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, 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_states, 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().

◆ 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.

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.
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:2008
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:65
struct ast_sip_service_route_vector * service_routes
Definition: res_pjsip.h:191
#define AST_VECTOR_SIZE(vec)
Get the number of elements in a vector.
Definition: vector.h:609
#define AST_VECTOR_GET(vec, idx)
Get an element from a vector.
Definition: vector.h:680

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().

◆ 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.

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 ast_calloc(num, len)
A wrapper for calloc()
Definition: astmm.h:202
#define AST_VECTOR_INIT(vec, size)
Initialize a vector.
Definition: vector.h:113

References ast_calloc, AST_VECTOR_INIT, and NULL.

Referenced by save_response_fields_to_transport().

◆ 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.

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:180
#define AST_VECTOR_CALLBACK_VOID(vec, callback,...)
Execute a callback on every element in a vector disregarding callback return.
Definition: vector.h:862

References ast_free, and AST_VECTOR_CALLBACK_VOID.

Referenced by ast_sip_transport_state_set_service_routes(), and save_response_fields_to_transport().

◆ 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.

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}

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().

◆ 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.

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}
void ast_sip_service_route_vector_destroy(struct ast_sip_service_route_vector *service_routes)
Destroy a vector of service routes.

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().

◆ 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.

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}

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

Referenced by save_response_fields_to_transport().

◆ 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 1000 of file config_transport.c.

1001{
1002 const struct ast_sip_transport *transport = obj;
1003
1004 *buf = ast_strdup(transport->ca_list_file);
1005
1006 return 0;
1007}
const ast_string_field ca_list_file
Definition: res_pjsip.h:241

References ast_strdup, buf, and ast_sip_transport::ca_list_file.

Referenced by ast_sip_initialize_sorcery_transport().

◆ 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 1009 of file config_transport.c.

1010{
1011 const struct ast_sip_transport *transport = obj;
1012
1013 *buf = ast_strdup(transport->ca_list_path);
1014
1015 return 0;
1016}
const ast_string_field ca_list_path
Definition: res_pjsip.h:241

References ast_strdup, buf, and ast_sip_transport::ca_list_path.

Referenced by ast_sip_initialize_sorcery_transport().

◆ cert_file_to_str()

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

Definition at line 1018 of file config_transport.c.

1019{
1020 const struct ast_sip_transport *transport = obj;
1021
1022 *buf = ast_strdup(transport->cert_file);
1023
1024 return 0;
1025}
const ast_string_field cert_file
Definition: res_pjsip.h:241

References ast_strdup, buf, and ast_sip_transport::cert_file.

Referenced by ast_sip_initialize_sorcery_transport().

◆ cli_get_container()

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

Definition at line 1559 of file config_transport.c.

1560{
1562 struct ao2_container *s_container;
1563
1565 regex);
1566 if (!container) {
1567 return NULL;
1568 }
1569
1572 if (!s_container) {
1573 return NULL;
1574 }
1575
1576 if (ao2_container_dup(s_container, container, 0)) {
1577 ao2_ref(s_container, -1);
1578 return NULL;
1579 }
1580
1581 return s_container;
1582}
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.
@ AO2_ALLOC_OPT_LOCK_NOLOCK
Definition: astobj2.h:367
#define ao2_container_alloc_list(ao2_options, container_options, sort_fn, cmp_fn)
Allocate and initialize a list container.
Definition: astobj2.h:1327
static int regex(struct ast_channel *chan, const char *cmd, char *parse, char *buf, size_t len)
struct ao2_container * container
Definition: res_fax.c:501
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
int ast_sorcery_object_id_compare(void *obj, void *arg, int flags)
ao2 object comparator based on sorcery id.
Definition: sorcery.c:2459
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
#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:941

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, RAII_VAR, and regex().

Referenced by ast_sip_initialize_sorcery_transport().

◆ cli_iterate()

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

Definition at line 1584 of file config_transport.c.

1585{
1586 const struct ast_sip_endpoint *endpoint = container;
1588 "transport", endpoint->transport);
1589
1590 if (!transport) {
1591 return -1;
1592 }
1593
1594 return callback(transport, args, 0);
1595}
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
An entity with which Asterisk communicates.
Definition: res_pjsip.h:951
const ast_string_field transport
Definition: res_pjsip.h:980
const char * args

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

Referenced by ast_sip_initialize_sorcery_transport().

◆ cli_print_body()

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

Definition at line 1617 of file config_transport.c.

1618{
1619 struct ast_sip_transport *transport = obj;
1620 struct ast_sip_cli_context *context = arg;
1621 char hoststr[PJ_INET6_ADDRSTRLEN];
1623
1624 if (!state) {
1625 return -1;
1626 }
1627
1628 ast_assert(context->output_buffer != NULL);
1629
1630 pj_sockaddr_print(&state->host, hoststr, sizeof(hoststr), 3);
1631
1632 ast_str_append(&context->output_buffer, 0, "%*s: %-21s %6s %5u %5u %s\n",
1633 CLI_INDENT_TO_SPACES(context->indent_level), "Transport",
1634 ast_sorcery_object_get_id(transport),
1635 ARRAY_IN_BOUNDS(transport->type, transport_types) ? transport_types[transport->type] : "Unknown",
1636 transport->cos, transport->tos, hoststr);
1637
1638 if (context->show_details
1639 || (context->show_details_only_level_0 && context->indent_level == 0)) {
1640 ast_str_append(&context->output_buffer, 0, "\n");
1642 }
1643
1644 return 0;
1645}
static const char * transport_types[]
int ast_sip_cli_print_sorcery_objectset(void *obj, void *arg, int flags)
Prints a sorcery object's ast_variable list.
Definition: pjsip_cli.c:36
#define CLI_INDENT_TO_SPACES(x)
Definition: res_pjsip_cli.h:29
int ast_str_append(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Append to a thread local dynamic string.
Definition: strings.h:1139
CLI Formatter Context passed to all formatters.
Definition: res_pjsip_cli.h:34
unsigned int tos
Definition: res_pjsip.h:291
enum ast_transport type
Definition: res_pjsip.h:243
unsigned int cos
Definition: res_pjsip.h:293
#define ast_assert(a)
Definition: utils.h:739
#define ARRAY_IN_BOUNDS(v, a)
Checks to see if value is within the bounds of the given array.
Definition: utils.h:687

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, voicemailpwcheck::context, ast_sip_transport::cos, find_state_by_transport(), NULL, RAII_VAR, ast_sip_transport::tos, transport_types, and ast_sip_transport::type.

Referenced by ast_sip_initialize_sorcery_transport().

◆ cli_print_header()

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

Definition at line 1602 of file config_transport.c.

1603{
1604 struct ast_sip_cli_context *context = arg;
1605 int indent = CLI_INDENT_TO_SPACES(context->indent_level);
1606 int filler = CLI_MAX_WIDTH - indent - 61;
1607
1608 ast_assert(context->output_buffer != NULL);
1609
1610 ast_str_append(&context->output_buffer, 0,
1611 "%*s: <TransportId........> <Type> <cos> <tos> <BindAddress%*.*s>\n",
1612 indent, "Transport", filler, filler, CLI_HEADER_FILLER);
1613
1614 return 0;
1615}
#define CLI_HEADER_FILLER
Definition: res_pjsip_cli.h:24
#define CLI_MAX_WIDTH
Definition: res_pjsip_cli.h:26

References ast_assert, ast_str_append(), CLI_HEADER_FILLER, CLI_INDENT_TO_SPACES, CLI_MAX_WIDTH, voicemailpwcheck::context, and NULL.

Referenced by ast_sip_initialize_sorcery_transport().

◆ cli_retrieve_by_id()

static void * cli_retrieve_by_id ( const char *  id)
static

Definition at line 1597 of file config_transport.c.

1598{
1599 return ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(), "transport", id);
1600}

References ast_sip_get_sorcery(), and ast_sorcery_retrieve_by_id().

Referenced by ast_sip_initialize_sorcery_transport().

◆ 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.

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}
pjsip_tls_setting tls
Definition: res_pjsip.h:143
struct ast_ha * localnet
Definition: res_pjsip.h:156
struct ast_dnsmgr_entry * external_signaling_address_refresher
Definition: res_pjsip.h:161
pj_ssl_cipher ciphers[SIP_TLS_MAX_CIPHERS]
Definition: res_pjsip.h:148
struct ast_sockaddr external_signaling_address
Definition: res_pjsip.h:166
pjsip_tls_setting tls
Definition: res_pjsip.h:259
struct ast_sockaddr external_address
Definition: res_pjsip.h:283
const ast_string_field external_signaling_address
Definition: res_pjsip.h:241
struct ast_sip_transport_state * state
Definition: res_pjsip.h:289
struct ast_ha * localnet
Definition: res_pjsip.h:271
pj_sockaddr host
Definition: res_pjsip.h:249
pj_ssl_cipher ciphers[SIP_TLS_MAX_CIPHERS]
Definition: res_pjsip.h:265
struct ast_dnsmgr_entry * external_address_refresher
Definition: res_pjsip.h:277

References ast_assert, and ast_sip_transport_state::transport.

Referenced by transport_apply().

◆ destroy_sip_transport_state()

static int destroy_sip_transport_state ( void *  data)
static

Definition at line 415 of file config_transport.c.

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}
void ast_free_ha(struct ast_ha *ha)
Free a list of HAs.
Definition: acl.c:222
void ast_dnsmgr_release(struct ast_dnsmgr_entry *entry)
Free a DNS manager entry.
Definition: dnsmgr.c:136
struct ast_dnsmgr_entry * external_media_address_refresher
Definition: res_pjsip.h:171

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().

◆ 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.

454{
455 const char *key = ast_sorcery_object_get_id(transport);
456
458}
@ OBJ_NOLOCK
Assume that the ao2_container is already locked.
Definition: astobj2.h:1063

References ao2_find, ast_sorcery_object_get_id(), OBJ_NOLOCK, OBJ_SEARCH_KEY, internal_state::transport, and transport_states.

Referenced by find_state_by_transport(), and transport_apply().

◆ 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.

535{
537 struct ast_sip_transport_state *new_state;
538
539 if ((new_state = find_temporary_state(transport))) {
540 return new_state;
541 }
542
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 }
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 cc_state state
Definition: ccss.c:393
static struct ast_sip_transport_state * find_temporary_state(struct ast_sip_transport *transport)
static void sip_transport_state_destroy(void *obj)
Destructor for ast_sip_transport state information.
static struct ast_threadstorage temp_state_store
enum ast_transport type
Definition: res_pjsip.h:133
void * ast_threadstorage_get(struct ast_threadstorage *ts, size_t init_size)
Retrieve thread storage.

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(), state, temp_state_store, ast_sip_transport_state::tls, ast_sip_transport_state::transport, and ast_sip_transport_state::type.

Referenced by 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().

◆ 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.

461{
462 struct internal_state *state;
463 struct ast_sip_transport_state *trans_state;
464
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}
static struct internal_state * find_internal_state_by_transport(const struct ast_sip_transport *transport)

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

Referenced by allow_wildcard_certs_to_str(), 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().

◆ 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.

490{
492
494 if (state && *state) {
495 ao2_ref(*state, +1);
496 return *state;
497 }
498
499 return NULL;
500}

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

Referenced by find_or_create_temporary_state(), and internal_state_alloc().

◆ 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.

170{
171 RAII_VAR(struct ast_str *, buf, NULL, ast_free);
172 RAII_VAR(struct ast_sip_transport *, transport, NULL, ao2_cleanup);
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
183 transport = ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(), "transport",
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
191 sip_transport_to_ami(transport, &buf);
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}
static int sip_transport_to_ami(const struct ast_sip_transport *transport, struct ast_str **buf)
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:3359
void astman_append(struct mansession *s, const char *fmt,...)
Definition: manager.c:3275
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.
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition: strings.h:761
struct mansession * s
Definition: res_pjsip.h:3037
const struct message * m
Definition: res_pjsip.h:3039
Support for dynamic strings.
Definition: strings.h:623

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(), ast_sip_transport_state::transport, and ast_sip_endpoint::transport.

◆ has_state_changed()

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

Definition at line 596 of file config_transport.c.

597{
598 if (a->type != b->type) {
599 return -1;
600 }
601
602 if (pj_sockaddr_cmp(&a->host, &b->host)) {
603 return -1;
604 }
605
606 if ((a->localnet || b->localnet)
607 && ((!a->localnet != !b->localnet)
608 || ast_sockaddr_cmp(&a->localnet->addr, &b->localnet->addr)
609 || ast_sockaddr_cmp(&a->localnet->netmask, &b->localnet->netmask)))
610 {
611 return -1;
612 }
613
614 if (ast_sockaddr_cmp(&a->external_signaling_address, &b->external_signaling_address)) {
615 return -1;
616 }
617
618 if (ast_sockaddr_cmp(&a->external_media_address, &b->external_media_address)) {
619 return -1;
620 }
621
622 if (a->tls.method != b->tls.method
623 || a->tls.ciphers_num != b->tls.ciphers_num
624#ifdef HAVE_PJSIP_TLS_TRANSPORT_PROTO
625 || a->tls.proto != b->tls.proto
626#endif
627 || a->tls.verify_client != b->tls.verify_client
628 || a->tls.verify_server != b->tls.verify_server
629 || a->tls.require_client_cert != b->tls.require_client_cert) {
630 return -1;
631 }
632
633 if (memcmp(a->ciphers, b->ciphers, sizeof(pj_ssl_cipher) * fmax(a->tls.ciphers_num, b->tls.ciphers_num))) {
634 return -1;
635 }
636
637#ifdef HAVE_PJSIP_TLS_TRANSPORT_RESTART
638 if (file_stat_cmp(&a->cert_file_stat, &b->cert_file_stat) || file_stat_cmp(&a->privkey_file_stat, &b->privkey_file_stat)) {
639 return -1;
640 }
641#endif
642
643 return 0;
644}
int ast_sockaddr_cmp(const struct ast_sockaddr *a, const struct ast_sockaddr *b)
Compares two ast_sockaddr structures.
Definition: netsock2.c:388
static struct test_val b
static struct test_val a

References a, ast_sockaddr_cmp(), and b.

Referenced by transport_apply().

◆ 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.

503{
505
507 if (!internal_state) {
508 return NULL;
509 }
510
512 if (!internal_state->id) {
514 return NULL;
515 }
516
517 /* We're transferring the reference from find_temporary_state */
519 if (!internal_state->state) {
521 return NULL;
522 }
526
527 return internal_state;
528}
static int remove_temporary_state(void)
static void internal_state_destroy(void *obj)
Destructor for ast_sip_transport state information.
struct ast_sip_transport_state * state
Transport state information.
struct ast_sip_transport * transport
Transport configuration object.

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(), ast_sip_transport::state, internal_state::state, and internal_state::transport.

Referenced by transport_apply().

◆ 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.

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) {
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}
@ CMP_MATCH
Definition: astobj2.h:1027
@ OBJ_SEARCH_PARTIAL_KEY
The arg parameter is a partial search key similar to OBJ_SEARCH_KEY.
Definition: astobj2.h:1116
@ OBJ_SEARCH_OBJECT
The arg parameter is an object of the same type.
Definition: astobj2.h:1087
@ OBJ_SEARCH_MASK
Search option field mask.
Definition: astobj2.h:1072

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

Referenced by ast_sip_initialize_sorcery_transport().

◆ 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.

445{
446 struct internal_state *state = obj;
447
448 ast_free(state->id);
449 ao2_cleanup(state->transport);
450 ao2_cleanup(state->state);
451}

References ao2_cleanup, and ast_free.

Referenced by internal_state_alloc().

◆ 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.

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;
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}
static force_inline int attribute_pure ast_str_hash(const char *str)
Compute a hash value on a string.
Definition: strings.h:1259

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

Referenced by ast_sip_initialize_sorcery_transport().

◆ localnet_to_str()

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

Definition at line 1508 of file config_transport.c.

1509{
1511 const struct ast_sip_transport *transport = obj;
1513
1514 if (!state) {
1515 return -1;
1516 }
1517
1518 ast_ha_join(state->localnet, &str);
1520 return 0;
1521}
void ast_ha_join(const struct ast_ha *ha, struct ast_str **buf)
Convert HAs to a comma separated string value.
Definition: acl.c:722
const char * str
Definition: app_jack.c:147
#define MAX_OBJECT_FIELD
Maximum length of an object field name.
Definition: sorcery.h:110
#define ast_str_create(init_len)
Create a malloc'ed dynamic length string.
Definition: strings.h:659

References ao2_cleanup, ast_free, ast_ha_join(), ast_str_buffer(), ast_str_create, ast_strdup, buf, find_state_by_transport(), MAX_OBJECT_FIELD, RAII_VAR, and str.

Referenced by ast_sip_initialize_sorcery_transport().

◆ localnet_to_vl()

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

Definition at line 1486 of file config_transport.c.

1487{
1488 const struct ast_sip_transport *transport = obj;
1489 struct ast_variable *head = NULL;
1490 struct ast_ha *ha;
1492
1493 if (!state) {
1494 return -1;
1495 }
1496
1497 for (ha = state->localnet; ha; ha = ha->next) {
1498 localnet_to_vl_append(&head, ha);
1499 }
1500
1501 if (head) {
1502 *fields = head;
1503 }
1504
1505 return 0;
1506}
static void localnet_to_vl_append(struct ast_variable **head, struct ast_ha *ha)
internal representation of ACL entries In principle user applications would have no need for this,...
Definition: acl.h:51
struct ast_ha * next
Definition: acl.h:56
Structure for variables, used for configurations and for channel variables.

References ao2_cleanup, find_state_by_transport(), localnet_to_vl_append(), ast_ha::next, NULL, and RAII_VAR.

Referenced by ast_sip_initialize_sorcery_transport().

◆ localnet_to_vl_append()

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

Definition at line 1476 of file config_transport.c.

1477{
1478 char str[MAX_OBJECT_FIELD];
1479 const char *addr = ast_strdupa(ast_sockaddr_stringify_addr(&ha->addr));
1480 snprintf(str, MAX_OBJECT_FIELD, "%s%s/%s", ha->sense == AST_SENSE_ALLOW ? "!" : "",
1482
1483 ast_variable_list_append(head, ast_variable_new("local_net", str, ""));
1484}
@ AST_SENSE_ALLOW
Definition: acl.h:38
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: astmm.h:298
#define ast_variable_new(name, value, filename)
#define ast_variable_list_append(head, new_var)
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:286
struct ast_sockaddr addr
Definition: acl.h:53
struct ast_sockaddr netmask
Definition: acl.h:54
enum ast_acl_sense sense
Definition: acl.h:55

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().

◆ populate_transport_states()

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

Definition at line 1699 of file config_transport.c.

1700{
1701 struct internal_state *state = obj;
1702 struct ao2_container *container = arg;
1703
1704 ao2_link(container, state->state);
1705
1706 return CMP_MATCH;
1707}
#define ao2_link(container, obj)
Add an object to a container.
Definition: astobj2.h:1532

References ao2_link, CMP_MATCH, and container.

Referenced by ast_sip_get_transport_states().

◆ privkey_file_to_str()

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

Definition at line 1027 of file config_transport.c.

1028{
1029 const struct ast_sip_transport *transport = obj;
1030
1031 *buf = ast_strdup(transport->privkey_file);
1032
1033 return 0;
1034}
const ast_string_field privkey_file
Definition: res_pjsip.h:241

References ast_strdup, buf, and ast_sip_transport::privkey_file.

Referenced by ast_sip_initialize_sorcery_transport().

◆ remove_temporary_state()

static int remove_temporary_state ( void  )
static

Definition at line 475 of file config_transport.c.

476{
478
480 if (!state) {
481 return -1;
482 }
483
485 *state = NULL;
486 return 0;
487}

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

Referenced by internal_state_alloc().

◆ 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 1180 of file config_transport.c.

1181{
1182 const struct ast_sip_transport *transport = obj;
1184
1185 if (!state) {
1186 return -1;
1187 }
1188
1189 *buf = ast_strdup(AST_YESNO(state->tls.require_client_cert));
1190
1191 return 0;
1192}

References ao2_cleanup, ast_strdup, AST_YESNO, buf, find_state_by_transport(), and RAII_VAR.

Referenced by ast_sip_initialize_sorcery_transport().

◆ 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.

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 @116 qos

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

Referenced by transport_apply().

◆ sip_transport_alloc()

static void * sip_transport_alloc ( const char *  name)
static

Allocator for transport.

Definition at line 399 of file config_transport.c.

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.
void * ast_sorcery_generic_alloc(size_t size, ao2_destructor_fn destructor)
Allocate a generic sorcery capable object.
Definition: sorcery.c:1728
#define ast_string_field_init(x, size)
Initialize a field pool and fields.
Definition: stringfields.h:359

References ao2_cleanup, ast_sorcery_generic_alloc(), ast_string_field_init, NULL, and sip_transport_destroy().

Referenced by ast_sip_initialize_sorcery_transport().

◆ sip_transport_destroy()

static void sip_transport_destroy ( void *  obj)
static

Destructor for transport.

Definition at line 391 of file config_transport.c.

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

References ast_string_field_free_memory.

Referenced by sip_transport_alloc().

◆ 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.

437{
438 struct ast_sip_transport_state *state = obj;
439
441}
static int destroy_sip_transport_state(void *data)
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:2165

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

Referenced by find_or_create_temporary_state().

◆ 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.

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.

References ast_sip_sorcery_object_to_ami(), buf, and ast_sip_transport_state::transport.

Referenced by format_ami_endpoint_transport().

◆ states_cleanup()

static void states_cleanup ( void *  states)
static

Definition at line 646 of file config_transport.c.

647{
648 if (states) {
649 ao2_unlock(states);
650 }
651}

References ao2_unlock.

Referenced by transport_apply().

◆ temp_state_store_cleanup()

static void temp_state_store_cleanup ( void *  data)
static

Definition at line 52 of file config_transport.c.

53{
54 struct ast_sip_transport_state **temp_state = data;
55
56 ao2_cleanup(*temp_state);
57 ast_free(data);
58}

References ao2_cleanup, and ast_free.

◆ tls_method_to_str()

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

Definition at line 1266 of file config_transport.c.

1267{
1268 const struct ast_sip_transport *transport = obj;
1270
1271 if (!state) {
1272 return -1;
1273 }
1274
1275 if (ARRAY_IN_BOUNDS(state->tls.method, tls_method_map)) {
1276 *buf = ast_strdup(tls_method_map[state->tls.method]);
1277 }
1278
1279 return 0;
1280}
static const char * tls_method_map[]

References ao2_cleanup, ARRAY_IN_BOUNDS, ast_strdup, buf, find_state_by_transport(), RAII_VAR, and tls_method_map.

Referenced by ast_sip_initialize_sorcery_transport().

◆ tos_to_str()

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

Definition at line 1549 of file config_transport.c.

1550{
1551 const struct ast_sip_transport *transport = obj;
1552
1553 if (ast_asprintf(buf, "%u", transport->tos) == -1) {
1554 return -1;
1555 }
1556 return 0;
1557}
#define ast_asprintf(ret, fmt,...)
A wrapper for asprintf()
Definition: astmm.h:267

References ast_asprintf, buf, and ast_sip_transport::tos.

Referenced by ast_sip_initialize_sorcery_transport().

◆ transport_apply()

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

Apply handler for transports.

Definition at line 654 of file config_transport.c.

655{
656 struct ast_sip_transport *transport = obj;
657 const char *transport_id = ast_sorcery_object_get_id(obj);
659 RAII_VAR(struct internal_state *, temp_state, NULL, ao2_cleanup);
660 RAII_VAR(struct internal_state *, perm_state, NULL, ao2_cleanup);
661 RAII_VAR(struct ast_variable *, changes, NULL, ast_variables_destroy);
662 pj_status_t res = -1;
663 int i;
664#define BIND_TRIES 3
665#define BIND_DELAY_US 100000
666
667 if (!states) {
668 return -1;
669 }
670
671 /*
672 * transport_apply gets called for EVERY retrieval of a transport when using realtime.
673 * We need to prevent multiple threads from trying to mess with underlying transports
674 * at the same time. The container is the only thing we have to lock on.
675 */
676 ao2_wrlock(states);
677
678 temp_state = internal_state_alloc(transport);
679 if (!temp_state) {
680 ast_log(LOG_ERROR, "Transport '%s' failed to allocate memory\n", transport_id);
681 return -1;
682 }
683
684 if (transport->async_operations != 1) {
685 ast_log(LOG_WARNING, "The async_operations setting on transport '%s' has been set to '%d'. The setting can no longer be set and is always 1.\n",
686 transport_id, transport->async_operations);
687 transport->async_operations = 1;
688 }
689
690 perm_state = find_internal_state_by_transport(transport);
691 if (perm_state) {
692 ast_sorcery_diff(sorcery, perm_state->transport, transport, &changes);
693 if (!changes && !has_state_changed(perm_state->state, temp_state->state)) {
694 /* In case someone is using the deprecated fields, reset them */
695 transport->state = perm_state->state;
696 copy_state_to_transport(transport);
697 ao2_replace(perm_state->transport, transport);
698 return 0;
699 }
700
701 /* If we aren't allowed to reload then we copy values that can't be changed from perm_state */
702 if (!transport->allow_reload) {
703 memcpy(&temp_state->state->host, &perm_state->state->host, sizeof(temp_state->state->host));
704 memcpy(&temp_state->state->tls, &perm_state->state->tls, sizeof(temp_state->state->tls));
705 memcpy(&temp_state->state->ciphers, &perm_state->state->ciphers, sizeof(temp_state->state->ciphers));
706 }
707 }
708
709 if (!transport->flow && (!perm_state || transport->allow_reload)) {
710 if (temp_state->state->host.addr.sa_family != PJ_AF_INET && temp_state->state->host.addr.sa_family != PJ_AF_INET6) {
711 ast_log(LOG_ERROR, "Transport '%s' could not be started as binding not specified\n", transport_id);
712 return -1;
713 }
714
715 /* Set default port if not present */
716 if (!pj_sockaddr_get_port(&temp_state->state->host)) {
717 pj_sockaddr_set_port(&temp_state->state->host, (transport->type == AST_TRANSPORT_TLS) ? 5061 : 5060);
718 }
719 }
720
721 /* Now that we know what address family we can set up a dnsmgr refresh for the external addresses if present */
723 if (temp_state->state->host.addr.sa_family == pj_AF_INET()) {
724 temp_state->state->external_signaling_address.ss.ss_family = AF_INET;
725 } else if (temp_state->state->host.addr.sa_family == pj_AF_INET6()) {
726 temp_state->state->external_signaling_address.ss.ss_family = AF_INET6;
727 } else {
728 ast_log(LOG_ERROR, "Unknown address family for transport '%s', could not get external signaling address\n",
729 transport_id);
730 return -1;
731 }
732
733 if (ast_dnsmgr_lookup(transport->external_signaling_address, &temp_state->state->external_signaling_address, &temp_state->state->external_signaling_address_refresher, NULL) < 0) {
734 ast_log(LOG_ERROR, "Could not create dnsmgr for external signaling address on '%s'\n", transport_id);
735 return -1;
736 }
737 }
738
739 if (!ast_strlen_zero(transport->external_media_address)) {
740 if (temp_state->state->host.addr.sa_family == pj_AF_INET()) {
741 temp_state->state->external_media_address.ss.ss_family = AF_INET;
742 } else if (temp_state->state->host.addr.sa_family == pj_AF_INET6()) {
743 temp_state->state->external_media_address.ss.ss_family = AF_INET6;
744 } else {
745 ast_log(LOG_ERROR, "Unknown address family for transport '%s', could not get external media address\n",
746 transport_id);
747 return -1;
748 }
749
750 if (ast_dnsmgr_lookup(transport->external_media_address, &temp_state->state->external_media_address, &temp_state->state->external_media_address_refresher, NULL) < 0) {
751 ast_log(LOG_ERROR, "Could not create dnsmgr for external media address on '%s'\n", transport_id);
752 return -1;
753 }
754 }
755
756 if (transport->flow) {
757 pj_str_t address;
758
759 ast_debug(1, "Ignoring any bind configuration on transport '%s' as it is a child of another\n",
760 transport_id);
761 pj_sockaddr_parse(pj_AF_UNSPEC(), 0, pj_cstr(&address, "0.0.0.0"), &temp_state->state->host);
762
763 temp_state->state->flow = 1;
764 res = PJ_SUCCESS;
765 } else if (!transport->allow_reload && perm_state) {
766 /* We inherit the transport from perm state, untouched */
767#ifdef HAVE_PJSIP_TLS_TRANSPORT_RESTART
768 ast_log(LOG_NOTICE, "Transport '%s' is not fully reloadable, not reloading: protocol, bind, TLS (everything but certificate and private key if filename is unchanged), TCP, ToS, or CoS options.\n", transport_id);
769 /* If this is a TLS transport and the certificate or private key has changed, then restart the transport so it uses the new one */
770 if (transport->type == AST_TRANSPORT_TLS) {
771 if (strcmp(perm_state->transport->cert_file, temp_state->transport->cert_file) ||
772 strcmp(perm_state->transport->privkey_file, temp_state->transport->privkey_file)) {
773 ast_log(LOG_ERROR, "Unable to restart TLS transport '%s' as certificate or private key filename has changed\n",
774 transport_id);
775 } else if (file_stat_cmp(&perm_state->state->cert_file_stat, &temp_state->state->cert_file_stat) ||
776 file_stat_cmp(&perm_state->state->privkey_file_stat, &temp_state->state->privkey_file_stat)) {
777 if (pjsip_tls_transport_restart(perm_state->state->factory, &perm_state->state->host, NULL) != PJ_SUCCESS) {
778 ast_log(LOG_ERROR, "Failed to restart TLS transport '%s'\n", transport_id);
779 } else {
780 sprintf(perm_state->state->factory->info, "%s", transport_id);
781 }
782 }
783 }
784#else
785 ast_log(LOG_NOTICE, "Transport '%s' is not fully reloadable, not reloading: protocol, bind, TLS, TCP, ToS, or CoS options.\n", transport_id);
786#endif
787 temp_state->state->transport = perm_state->state->transport;
788 perm_state->state->transport = NULL;
789 temp_state->state->factory = perm_state->state->factory;
790 perm_state->state->factory = NULL;
791
792 res = PJ_SUCCESS;
793 } else if (transport->type == AST_TRANSPORT_UDP) {
794
795 for (i = 0; i < BIND_TRIES && res != PJ_SUCCESS; i++) {
796 if (perm_state && perm_state->state && perm_state->state->transport) {
797 pjsip_udp_transport_pause(perm_state->state->transport,
798 PJSIP_UDP_TRANSPORT_DESTROY_SOCKET);
799 usleep(BIND_DELAY_US);
800 }
801
802 if (temp_state->state->host.addr.sa_family == pj_AF_INET()) {
803 res = pjsip_udp_transport_start(ast_sip_get_pjsip_endpoint(),
804 &temp_state->state->host.ipv4, NULL, transport->async_operations,
805 &temp_state->state->transport);
806 } else if (temp_state->state->host.addr.sa_family == pj_AF_INET6()) {
807 res = pjsip_udp_transport_start6(ast_sip_get_pjsip_endpoint(),
808 &temp_state->state->host.ipv6, NULL, transport->async_operations,
809 &temp_state->state->transport);
810 }
811 }
812
813 if (res == PJ_SUCCESS) {
814 temp_state->state->transport->info = pj_pool_alloc(temp_state->state->transport->pool,
815 (AST_SIP_X_AST_TXP_LEN + strlen(transport_id) + 2));
816
817 sprintf(temp_state->state->transport->info, "%s:%s", AST_SIP_X_AST_TXP, transport_id);
818
819 if (transport->tos || transport->cos) {
820 pj_sock_t sock;
821 pj_qos_params qos_params;
822 sock = pjsip_udp_transport_get_socket(temp_state->state->transport);
823 pj_sock_get_qos_params(sock, &qos_params);
824 set_qos(transport, &qos_params);
825 pj_sock_set_qos_params(sock, &qos_params);
826 }
827 }
828 } else if (transport->type == AST_TRANSPORT_TCP) {
829 pjsip_tcp_transport_cfg cfg;
830 static int option = 1;
831
832 pjsip_tcp_transport_cfg_default(&cfg, temp_state->state->host.addr.sa_family);
833 cfg.bind_addr = temp_state->state->host;
834 cfg.async_cnt = transport->async_operations;
835 set_qos(transport, &cfg.qos_params);
836 /* sockopt_params.options is copied to each newly connected socket */
837 cfg.sockopt_params.options[0].level = pj_SOL_TCP();
838 cfg.sockopt_params.options[0].optname = pj_TCP_NODELAY();
839 cfg.sockopt_params.options[0].optval = &option;
840 cfg.sockopt_params.options[0].optlen = sizeof(option);
841 cfg.sockopt_params.cnt = 1;
842
843 for (i = 0; i < BIND_TRIES && res != PJ_SUCCESS; i++) {
844 if (perm_state && perm_state->state && perm_state->state->factory
845 && perm_state->state->factory->destroy) {
846 perm_state->state->factory->destroy(perm_state->state->factory);
847 usleep(BIND_DELAY_US);
848 }
849
850 res = pjsip_tcp_transport_start3(ast_sip_get_pjsip_endpoint(), &cfg,
851 &temp_state->state->factory);
852 }
853 } else if (transport->type == AST_TRANSPORT_TLS) {
854#if defined(PJ_HAS_SSL_SOCK) && PJ_HAS_SSL_SOCK != 0
855 static int option = 1;
856
857 if (transport->async_operations > 1 && ast_compare_versions(pj_get_version(), "2.5.0") < 0) {
858 ast_log(LOG_ERROR, "Transport: %s: When protocol=tls and pjproject version < 2.5.0, async_operations can't be > 1\n",
860 return -1;
861 }
862
863 temp_state->state->tls.password = pj_str((char*)transport->password);
864 set_qos(transport, &temp_state->state->tls.qos_params);
865
866 /* sockopt_params.options is copied to each newly connected socket */
867 temp_state->state->tls.sockopt_params.options[0].level = pj_SOL_TCP();
868 temp_state->state->tls.sockopt_params.options[0].optname = pj_TCP_NODELAY();
869 temp_state->state->tls.sockopt_params.options[0].optval = &option;
870 temp_state->state->tls.sockopt_params.options[0].optlen = sizeof(option);
871 temp_state->state->tls.sockopt_params.cnt = 1;
872
873 for (i = 0; i < BIND_TRIES && res != PJ_SUCCESS; i++) {
874 if (perm_state && perm_state->state && perm_state->state->factory
875 && perm_state->state->factory->destroy) {
876 perm_state->state->factory->destroy(perm_state->state->factory);
877 usleep(BIND_DELAY_US);
878 }
879
880 res = pjsip_tls_transport_start2(ast_sip_get_pjsip_endpoint(), &temp_state->state->tls,
881 &temp_state->state->host, NULL, transport->async_operations,
882 &temp_state->state->factory);
883 }
884
885 if (res == PJ_SUCCESS) {
886 /*
887 * PJSIP uses 100 bytes to store information, and during a restart will repopulate
888 * the field so ensure there is sufficient space - even though we'll revert it after.
889 */
890 temp_state->state->factory->info = pj_pool_alloc(
891 temp_state->state->factory->pool, (MAX(MAX_OBJECT_FIELD, 100) + 1));
892 /*
893 * Store transport id on the factory instance so it can be used
894 * later to look up the transport state.
895 */
896 sprintf(temp_state->state->factory->info, "%s", transport_id);
897 }
898#else
899 ast_log(LOG_ERROR, "Transport: %s: PJSIP has not been compiled with TLS transport support, ensure OpenSSL development packages are installed\n",
901 return -1;
902#endif
903 } else if ((transport->type == AST_TRANSPORT_WS) || (transport->type == AST_TRANSPORT_WSS)) {
904 if (transport->cos || transport->tos) {
905 ast_log(LOG_WARNING, "TOS and COS values ignored for websocket transport\n");
906 } else if (!ast_strlen_zero(transport->ca_list_file) || !ast_strlen_zero(transport->ca_list_path) ||
907 !ast_strlen_zero(transport->cert_file) || !ast_strlen_zero(transport->privkey_file)) {
908 ast_log(LOG_WARNING, "TLS certificate values ignored for websocket transport as they are configured in http.conf\n");
909 }
910 res = PJ_SUCCESS;
911 }
912
913 if (res != PJ_SUCCESS) {
914 char msg[PJ_ERR_MSG_SIZE];
915
916 pj_strerror(res, msg, sizeof(msg));
917 ast_log(LOG_ERROR, "Transport '%s' could not be started: %s\n", ast_sorcery_object_get_id(obj), msg);
918 return -1;
919 }
920
921 copy_state_to_transport(transport);
922 if (perm_state) {
923 ao2_unlink_flags(states, perm_state, OBJ_NOLOCK);
924 }
925 ao2_link_flags(states, temp_state, OBJ_NOLOCK);
926
927 return 0;
928}
#define ao2_wrlock(a)
Definition: astobj2.h:719
#define ao2_unlink_flags(container, obj, flags)
Remove an object from a container.
Definition: astobj2.h:1600
#define ao2_link_flags(container, obj, flags)
Add an object to a container.
Definition: astobj2.h:1554
#define ao2_replace(dst, src)
Replace one object reference with another cleaning up the original.
Definition: astobj2.h:501
#define BIND_TRIES
static void copy_state_to_transport(struct ast_sip_transport *transport)
static struct internal_state * internal_state_alloc(struct ast_sip_transport *transport)
static void set_qos(struct ast_sip_transport *transport, pj_qos_params *qos)
#define BIND_DELAY_US
static int has_state_changed(struct ast_sip_transport_state *a, struct ast_sip_transport_state *b)
static void states_cleanup(void *states)
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
char * address
Definition: f2c.h:59
void ast_variables_destroy(struct ast_variable *var)
Free variable list.
Definition: extconf.c:1262
#define ast_debug(level,...)
Log a DEBUG message.
#define LOG_NOTICE
#define LOG_WARNING
@ AST_TRANSPORT_WSS
Definition: netsock2.h:64
@ AST_TRANSPORT_WS
Definition: netsock2.h:63
@ AST_TRANSPORT_UDP
Definition: netsock2.h:60
@ AST_TRANSPORT_TLS
Definition: netsock2.h:62
@ AST_TRANSPORT_TCP
Definition: netsock2.h:61
#define AST_SIP_X_AST_TXP
Definition: res_pjsip.h:1066
pjsip_endpoint * ast_sip_get_pjsip_endpoint(void)
Get a pointer to the PJSIP endpoint.
Definition: res_pjsip.c:520
#define AST_SIP_X_AST_TXP_LEN
Definition: res_pjsip.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
const ast_string_field password
Definition: res_pjsip.h:241
unsigned int async_operations
Definition: res_pjsip.h:251
const ast_string_field external_media_address
Definition: res_pjsip.h:241
int ast_compare_versions(const char *version1, const char *version2)
Compare 2 major.minor.patch.extra version strings.
Definition: utils.c:3124
#define MAX(a, b)
Definition: utils.h:233

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_NOTICE, LOG_WARNING, MAX, MAX_OBJECT_FIELD, NULL, OBJ_NOLOCK, ast_sip_transport::password, ast_sip_transport::privkey_file, RAII_VAR, set_qos(), sorcery, ast_sip_transport::state, states_cleanup(), ast_sip_transport_state::tls, ast_sip_transport::tos, transport_states, and ast_sip_transport::type.

Referenced by ast_sip_initialize_sorcery_transport().

◆ 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 1092 of file config_transport.c.

1093{
1094 struct ast_sip_transport *transport = obj;
1095 pj_str_t buf;
1096 int rc;
1098
1099 if (!state) {
1100 return -1;
1101 }
1102
1103 rc = pj_sockaddr_parse(pj_AF_UNSPEC(), 0, pj_cstr(&buf, var->value), &state->host);
1104
1105 return rc != PJ_SUCCESS ? -1 : 0;
1106}
#define var
Definition: ast_expr2f.c:605
static struct ast_sip_transport_state * find_or_create_temporary_state(struct ast_sip_transport *transport)

References ao2_cleanup, buf, find_or_create_temporary_state(), RAII_VAR, and var.

Referenced by ast_sip_initialize_sorcery_transport().

◆ transport_bind_to_str()

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

Definition at line 1108 of file config_transport.c.

1109{
1110 const struct ast_sip_transport *transport = obj;
1112
1113 if (!state) {
1114 return -1;
1115 }
1116
1117 if (!(*buf = ast_calloc(MAX_OBJECT_FIELD, sizeof(char)))) {
1118 return -1;
1119 }
1120
1121 /* include port as well as brackets if IPv6 */
1122 pj_sockaddr_print(&state->host, *buf, MAX_OBJECT_FIELD, 1 | 2);
1123
1124 return 0;
1125}

References ao2_cleanup, ast_calloc, buf, find_state_by_transport(), MAX_OBJECT_FIELD, and RAII_VAR.

Referenced by ast_sip_initialize_sorcery_transport().

◆ transport_localnet_handler()

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

Custom handler for localnet setting.

Definition at line 1451 of file config_transport.c.

1452{
1453 struct ast_sip_transport *transport = obj;
1454 int error = 0;
1456
1457 if (!state) {
1458 return -1;
1459 }
1460
1461 if (ast_strlen_zero(var->value)) {
1462 ast_free_ha(state->localnet);
1463 state->localnet = NULL;
1464 return 0;
1465 }
1466
1467 /* We use only the ast_apply_ha() which defaults to ALLOW
1468 * ("permit"), so we add DENY rules. */
1469 if (!(state->localnet = ast_append_ha("deny", var->value, state->localnet, &error))) {
1470 return -1;
1471 }
1472
1473 return error;
1474}
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:712
int error(const char *format,...)
Definition: utils/frame.c:999

References ao2_cleanup, ast_append_ha(), ast_free_ha(), ast_strlen_zero(), error(), find_or_create_temporary_state(), NULL, RAII_VAR, and var.

Referenced by ast_sip_initialize_sorcery_transport().

◆ 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 1037 of file config_transport.c.

1038{
1039 struct ast_sip_transport *transport = obj;
1041
1042 if (!state) {
1043 return -1;
1044 }
1045
1046 if (!strcasecmp(var->value, "flow")) {
1047 transport->flow = 1;
1048 } else {
1049 if (!strcasecmp(var->value, "udp")) {
1050 transport->type = AST_TRANSPORT_UDP;
1051 } else if (!strcasecmp(var->value, "tcp")) {
1052 transport->type = AST_TRANSPORT_TCP;
1053 } else if (!strcasecmp(var->value, "tls")) {
1054 transport->type = AST_TRANSPORT_TLS;
1055 } else if (!strcasecmp(var->value, "ws")) {
1056 transport->type = AST_TRANSPORT_WS;
1057 } else if (!strcasecmp(var->value, "wss")) {
1058 transport->type = AST_TRANSPORT_WSS;
1059 } else {
1060 return -1;
1061 }
1062 transport->flow = 0;
1063 }
1064
1065 state->type = transport->type;
1066
1067 return 0;
1068}

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, ast_sip_transport::type, and var.

Referenced by ast_sip_initialize_sorcery_transport().

◆ transport_protocol_to_str()

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

Definition at line 1078 of file config_transport.c.

1079{
1080 const struct ast_sip_transport *transport = obj;
1081
1082 if (transport->flow) {
1083 *buf = ast_strdup("flow");
1084 } else if (ARRAY_IN_BOUNDS(transport->type, transport_types)) {
1085 *buf = ast_strdup(transport_types[transport->type]);
1086 }
1087
1088 return 0;
1089}

References ARRAY_IN_BOUNDS, ast_strdup, buf, ast_sip_transport::flow, transport_types, and ast_sip_transport::type.

Referenced by ast_sip_initialize_sorcery_transport().

◆ 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.

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) {
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}

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().

◆ 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.

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;
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}

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

Referenced by ast_sip_get_transport_states().

◆ 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 931 of file config_transport.c.

932{
933 struct ast_sip_transport *transport = obj;
935
937
938 return 0;
939}

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

Referenced by ast_sip_initialize_sorcery_transport().

◆ 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 1128 of file config_transport.c.

1129{
1130 struct ast_sip_transport *transport = obj;
1132
1133 if (!state) {
1134 return -1;
1135 }
1136
1137 if (!strcasecmp(var->name, "verify_server")) {
1138 state->verify_server = ast_true(var->value);
1139 } else if (!strcasecmp(var->name, "verify_client")) {
1140 state->tls.verify_client = ast_true(var->value) ? PJ_TRUE : PJ_FALSE;
1141 } else if (!strcasecmp(var->name, "require_client_cert")) {
1142 state->tls.require_client_cert = ast_true(var->value) ? PJ_TRUE : PJ_FALSE;
1143 } else if (!strcasecmp(var->name, "allow_wildcard_certs")) {
1144 state->allow_wildcard_certs = ast_true(var->value);
1145 } else {
1146 return -1;
1147 }
1148
1149 return 0;
1150}
int attribute_pure ast_true(const char *val)
Make sure something is true. Determine if a string containing a boolean value is "true"....
Definition: utils.c:2199

References ao2_cleanup, ast_true(), find_or_create_temporary_state(), RAII_VAR, and var.

Referenced by ast_sip_initialize_sorcery_transport().

◆ 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 942 of file config_transport.c.

943{
944 struct ast_sip_transport *transport = obj;
946
947 if (!state) {
948 return -1;
949 }
950
951 if (ast_strlen_zero(var->value)) {
952 /* Ignore empty options */
953 return 0;
954 }
955
956 if (!ast_file_is_readable(var->value)) {
957 ast_log(LOG_ERROR, "Transport: %s: %s %s is either missing or not readable\n",
958 ast_sorcery_object_get_id(obj), var->name, var->value);
959 return -1;
960 }
961
962 if (!strcasecmp(var->name, "ca_list_file")) {
963 state->tls.ca_list_file = pj_str((char*)var->value);
964 ast_string_field_set(transport, ca_list_file, var->value);
965 } else if (!strcasecmp(var->name, "ca_list_path")) {
966#ifdef HAVE_PJ_SSL_CERT_LOAD_FROM_FILES2
967 state->tls.ca_list_path = pj_str((char *)var->value);
968 ast_string_field_set(transport, ca_list_path, var->value);
969#else
970 ast_log(LOG_WARNING, "Asterisk has been built against a version of pjproject that does not "
971 "support the 'ca_list_path' option. Please upgrade to version 2.4 or later.\n");
972#endif
973 } else if (!strcasecmp(var->name, "cert_file")) {
974 state->tls.cert_file = pj_str((char *)var->value);
975 ast_string_field_set(transport, cert_file, var->value);
976#ifdef HAVE_PJSIP_TLS_TRANSPORT_RESTART
977 if (stat(var->value, &state->cert_file_stat)) {
978 ast_log(LOG_ERROR, "Failed to stat certificate file '%s' for transport '%s' due to '%s'\n",
979 var->value, ast_sorcery_object_get_id(obj), strerror(errno));
980 return -1;
981 }
983#endif
984 } else if (!strcasecmp(var->name, "priv_key_file")) {
985 state->tls.privkey_file = pj_str((char *)var->value);
986 ast_string_field_set(transport, privkey_file, var->value);
987#ifdef HAVE_PJSIP_TLS_TRANSPORT_RESTART
988 if (stat(var->value, &state->privkey_file_stat)) {
989 ast_log(LOG_ERROR, "Failed to stat private key file '%s' for transport '%s' due to '%s'\n",
990 var->value, ast_sorcery_object_get_id(obj), strerror(errno));
991 return -1;
992 }
994#endif
995 }
996
997 return 0;
998}
int errno
void ast_sorcery_object_set_has_dynamic_contents(const void *object)
Set the dynamic contents flag on a sorcery object.
Definition: sorcery.c:2379
#define ast_string_field_set(x, field, data)
Set a field to a simple string value.
Definition: stringfields.h:521
int ast_file_is_readable(const char *filename)
Test that a file exists and is readable by the effective user.
Definition: utils.c:3107

References ao2_cleanup, ast_file_is_readable(), ast_log, ast_sorcery_object_get_id(), ast_sorcery_object_set_has_dynamic_contents(), ast_string_field_set, ast_strlen_zero(), ast_sip_transport::ca_list_file, ast_sip_transport::ca_list_path, ast_sip_transport::cert_file, errno, find_or_create_temporary_state(), LOG_ERROR, LOG_WARNING, ast_sip_transport::privkey_file, RAII_VAR, and var.

Referenced by ast_sip_initialize_sorcery_transport().

◆ 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 1209 of file config_transport.c.

1210{
1211 struct ast_sip_transport *transport = obj;
1213
1214 if (!state) {
1215 return -1;
1216 }
1217
1218 if (ast_strlen_zero(var->value) || !strcasecmp(var->value, "default")) {
1219 state->tls.method = PJSIP_SSL_DEFAULT_METHOD;
1220 } else if (!strcasecmp(var->value, "unspecified")) {
1221 state->tls.method = PJSIP_SSL_UNSPECIFIED_METHOD;
1222 } else if (!strcasecmp(var->value, "tlsv1")) {
1223 state->tls.method = PJSIP_TLSV1_METHOD;
1224#ifdef HAVE_PJSIP_TLS_1_1
1225 } else if (!strcasecmp(var->value, "tlsv1_1")) {
1226 state->tls.method = PJSIP_TLSV1_1_METHOD;
1227#endif
1228#ifdef HAVE_PJSIP_TLS_1_2
1229 } else if (!strcasecmp(var->value, "tlsv1_2")) {
1230 state->tls.method = PJSIP_TLSV1_2_METHOD;
1231#endif
1232#ifdef HAVE_PJSIP_TLS_1_3
1233 } else if (!strcasecmp(var->value, "tlsv1_3")) {
1234 state->tls.method = PJSIP_TLSV1_3_METHOD;
1235#endif
1236 } else if (!strcasecmp(var->value, "sslv2")) {
1237 state->tls.method = PJSIP_SSLV2_METHOD;
1238 } else if (!strcasecmp(var->value, "sslv3")) {
1239 state->tls.method = PJSIP_SSLV3_METHOD;
1240 } else if (!strcasecmp(var->value, "sslv23")) {
1241 state->tls.method = PJSIP_SSLV23_METHOD;
1242 } else {
1243 return -1;
1244 }
1245
1246 return 0;
1247}

References ao2_cleanup, ast_strlen_zero(), find_or_create_temporary_state(), RAII_VAR, and var.

Referenced by ast_sip_initialize_sorcery_transport().

◆ 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 1524 of file config_transport.c.

1525{
1526 struct ast_sip_transport *transport = obj;
1527 unsigned int value;
1528
1529 if (ast_str2tos(var->value, &value)) {
1530 ast_log(LOG_ERROR, "Error configuring transport '%s' - Could not "
1531 "interpret 'tos' value '%s'\n",
1532 ast_sorcery_object_get_id(transport), var->value);
1533 return -1;
1534 }
1535
1536 if (value % 4) {
1537 value = value >> 2;
1538 value = value << 2;
1540 "transport '%s' - 'tos' value '%s' uses bits that are "
1541 "discarded when converted to DSCP. Using equivalent %u instead.\n",
1542 ast_sorcery_object_get_id(transport), var->value, value);
1543 }
1544
1545 transport->tos = value;
1546 return 0;
1547}
int ast_str2tos(const char *value, unsigned int *tos)
Convert a string to the appropriate TOS value.
Definition: acl.c:966
int value
Definition: syslog.c:37

References ast_log, ast_sorcery_object_get_id(), ast_str2tos(), LOG_ERROR, LOG_WARNING, ast_sip_transport::tos, value, and var.

Referenced by ast_sip_initialize_sorcery_transport().

◆ verify_client_to_str()

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

Definition at line 1166 of file config_transport.c.

1167{
1168 const struct ast_sip_transport *transport = obj;
1170
1171 if (!state) {
1172 return -1;
1173 }
1174
1175 *buf = ast_strdup(AST_YESNO(state->tls.verify_client));
1176
1177 return 0;
1178}

References ao2_cleanup, ast_strdup, AST_YESNO, buf, find_state_by_transport(), and RAII_VAR.

Referenced by ast_sip_initialize_sorcery_transport().

◆ verify_server_to_str()

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

Definition at line 1152 of file config_transport.c.

1153{
1154 const struct ast_sip_transport *transport = obj;
1156
1157 if (!state) {
1158 return -1;
1159 }
1160
1161 *buf = ast_strdup(AST_YESNO(state->verify_server));
1162
1163 return 0;
1164}

References ao2_cleanup, ast_strdup, AST_YESNO, buf, find_state_by_transport(), and RAII_VAR.

Referenced by ast_sip_initialize_sorcery_transport().

Variable Documentation

◆ cli_commands

struct ast_cli_entry cli_commands[]
static

◆ cli_formatter

struct ast_sip_cli_formatter_entry* cli_formatter
static

◆ 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.

Referenced by ast_sip_destroy_sorcery_transport(), and ast_sip_initialize_sorcery_transport().

◆ 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 1249 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 1070 of file config_transport.c.

Referenced by cli_print_body(), and transport_protocol_to_str().