Asterisk - The Open Source Telephony Project GIT-master-7921072
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 1269 of file config_transport.c.

1270{
1272
1273 if (!state) {
1274 return -1;
1275 }
1276
1277 *buf = ast_strdup(AST_YESNO(state->allow_wildcard_certs));
1278 ao2_ref(state, -1);
1279
1280 return 0;
1281}
#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 1877 of file config_transport.c.

1878{
1881
1883
1886
1887 return 0;
1888}
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 1744 of file config_transport.c.

1745{
1746 struct internal_state *state = NULL;
1747 struct ast_sip_transport_state *trans_state;
1748
1749 if (!transport_states) {
1750 return NULL;
1751 }
1752
1754 if (!state) {
1755 return NULL;
1756 }
1757
1758 trans_state = ao2_bump(state->state);
1759 ao2_ref(state, -1);
1760
1761 /* If this is a child transport see if the transport is actually dead */
1762 if (trans_state->flow) {
1763 ao2_lock(trans_state);
1764 if (trans_state->transport && trans_state->transport->is_shutdown == PJ_TRUE) {
1765 pjsip_transport_dec_ref(trans_state->transport);
1766 trans_state->transport = NULL;
1767 }
1768 ao2_unlock(trans_state);
1769 }
1770
1771 return trans_state;
1772}
#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 1784 of file config_transport.c.

1785{
1788
1789 if (!states) {
1790 return NULL;
1791 }
1792
1794 return states;
1795}
@ 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 1798 of file config_transport.c.

1799{
1801 struct ao2_container *transports = NULL;
1802
1803 /* Create outbound registration states container. */
1806 if (!transport_states) {
1807 ast_log(LOG_ERROR, "Unable to allocate transport states container\n");
1808 return -1;
1809 }
1810
1811 ast_sorcery_apply_default(sorcery, "transport", "config", "pjsip.conf,criteria=type=transport");
1812
1814 return -1;
1815 }
1816
1817 /* Normally type is a OPT_NOOP_T but we're using it to make sure that state is created */
1821 ast_sorcery_object_field_register(sorcery, "transport", "async_operations", "1", OPT_UINT_T, 0, FLDSET(struct ast_sip_transport, async_operations));
1822
1827
1828 ast_sorcery_object_field_register(sorcery, "transport", "password", "", OPT_STRINGFIELD_T, 0, STRFLDSET(struct ast_sip_transport, password));
1829 ast_sorcery_object_field_register(sorcery, "transport", "external_signaling_address", "", OPT_STRINGFIELD_T, 0, STRFLDSET(struct ast_sip_transport, external_signaling_address));
1830 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);
1831 ast_sorcery_object_field_register(sorcery, "transport", "external_media_address", "", OPT_STRINGFIELD_T, 0, STRFLDSET(struct ast_sip_transport, external_media_address));
1832 ast_sorcery_object_field_register(sorcery, "transport", "domain", "", OPT_STRINGFIELD_T, 0, STRFLDSET(struct ast_sip_transport, domain));
1838 ast_sorcery_object_field_register(sorcery, "transport", "tcp_keepalive_enable", "no", OPT_BOOL_T, 0, FLDSET(struct ast_sip_transport, tcp_keepalive_enable));
1839 ast_sorcery_object_field_register(sorcery, "transport", "tcp_keepalive_idle_time", "30", OPT_INT_T, 0, FLDSET(struct ast_sip_transport, tcp_keepalive_idle_time));
1840 ast_sorcery_object_field_register(sorcery, "transport", "tcp_keepalive_interval_time", "1", OPT_INT_T, 0, FLDSET(struct ast_sip_transport, tcp_keepalive_interval_time));
1841 ast_sorcery_object_field_register(sorcery, "transport", "tcp_keepalive_probe_count", "5", OPT_INT_T, 0, FLDSET(struct ast_sip_transport, tcp_keepalive_probe_count));
1842#if defined(PJ_HAS_SSL_SOCK) && PJ_HAS_SSL_SOCK != 0
1843 ast_sorcery_object_field_register_custom(sorcery, "transport", "cipher", "", transport_tls_cipher_handler, transport_tls_cipher_to_str, NULL, 0, 0);
1844#endif
1847 ast_sorcery_object_field_register(sorcery, "transport", "cos", "0", OPT_UINT_T, 0, FLDSET(struct ast_sip_transport, cos));
1848 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);
1849 ast_sorcery_object_field_register(sorcery, "transport", "allow_reload", "no", OPT_BOOL_T, 1, FLDSET(struct ast_sip_transport, allow_reload));
1850 ast_sorcery_object_field_register(sorcery, "transport", "symmetric_transport", "no", OPT_BOOL_T, 1, FLDSET(struct ast_sip_transport, symmetric_transport));
1851
1853
1855 if (!cli_formatter) {
1856 ast_log(LOG_ERROR, "Unable to allocate memory for cli formatter\n");
1857 return -1;
1858 }
1859 cli_formatter->name = "transport";
1866
1869
1870 /* trigger load of transports from realtime by trying to revrieve them all */
1872 ao2_cleanup(transports);
1873
1874 return 0;
1875}
#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:356
#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 1075 of file config_transport.c.

1076{
1077 const struct ast_sip_transport *transport = obj;
1078
1079 *buf = ast_strdup(transport->ca_list_file);
1080
1081 return 0;
1082}
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 1084 of file config_transport.c.

1085{
1086 const struct ast_sip_transport *transport = obj;
1087
1088 *buf = ast_strdup(transport->ca_list_path);
1089
1090 return 0;
1091}
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 1093 of file config_transport.c.

1094{
1095 const struct ast_sip_transport *transport = obj;
1096
1097 *buf = ast_strdup(transport->cert_file);
1098
1099 return 0;
1100}
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 1634 of file config_transport.c.

1635{
1637 struct ao2_container *s_container;
1638
1640 regex);
1641 if (!container) {
1642 return NULL;
1643 }
1644
1647 if (!s_container) {
1648 return NULL;
1649 }
1650
1651 if (ao2_container_dup(s_container, container, 0)) {
1652 ao2_ref(s_container, -1);
1653 return NULL;
1654 }
1655
1656 return s_container;
1657}
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 1659 of file config_transport.c.

1660{
1661 const struct ast_sip_endpoint *endpoint = container;
1663 "transport", endpoint->transport);
1664
1665 if (!transport) {
1666 return -1;
1667 }
1668
1669 return callback(transport, args, 0);
1670}
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:963
const ast_string_field transport
Definition: res_pjsip.h:992
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 1692 of file config_transport.c.

1693{
1694 struct ast_sip_transport *transport = obj;
1695 struct ast_sip_cli_context *context = arg;
1696 char hoststr[PJ_INET6_ADDRSTRLEN];
1698
1699 if (!state) {
1700 return -1;
1701 }
1702
1703 ast_assert(context->output_buffer != NULL);
1704
1705 pj_sockaddr_print(&state->host, hoststr, sizeof(hoststr), 3);
1706
1707 ast_str_append(&context->output_buffer, 0, "%*s: %-21s %6s %5u %5u %s\n",
1708 CLI_INDENT_TO_SPACES(context->indent_level), "Transport",
1709 ast_sorcery_object_get_id(transport),
1710 ARRAY_IN_BOUNDS(transport->type, transport_types) ? transport_types[transport->type] : "Unknown",
1711 transport->cos, transport->tos, hoststr);
1712
1713 if (context->show_details
1714 || (context->show_details_only_level_0 && context->indent_level == 0)) {
1715 ast_str_append(&context->output_buffer, 0, "\n");
1717 }
1718
1719 return 0;
1720}
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 1677 of file config_transport.c.

1678{
1679 struct ast_sip_cli_context *context = arg;
1680 int indent = CLI_INDENT_TO_SPACES(context->indent_level);
1681 int filler = CLI_MAX_WIDTH - indent - 61;
1682
1683 ast_assert(context->output_buffer != NULL);
1684
1685 ast_str_append(&context->output_buffer, 0,
1686 "%*s: <TransportId........> <Type> <cos> <tos> <BindAddress%*.*s>\n",
1687 indent, "Transport", filler, filler, CLI_HEADER_FILLER);
1688
1689 return 0;
1690}
#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 1672 of file config_transport.c.

1673{
1674 return ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(), "transport", id);
1675}

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:3386
void astman_append(struct mansession *s, const char *fmt,...)
Definition: manager.c:3302
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:3049
const struct message * m
Definition: res_pjsip.h:3051
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 1583 of file config_transport.c.

1584{
1586 const struct ast_sip_transport *transport = obj;
1588
1589 if (!state) {
1590 return -1;
1591 }
1592
1593 ast_ha_join(state->localnet, &str);
1595 return 0;
1596}
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 1561 of file config_transport.c.

1562{
1563 const struct ast_sip_transport *transport = obj;
1564 struct ast_variable *head = NULL;
1565 struct ast_ha *ha;
1567
1568 if (!state) {
1569 return -1;
1570 }
1571
1572 for (ha = state->localnet; ha; ha = ha->next) {
1573 localnet_to_vl_append(&head, ha);
1574 }
1575
1576 if (head) {
1577 *fields = head;
1578 }
1579
1580 return 0;
1581}
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 1551 of file config_transport.c.

1552{
1553 char str[MAX_OBJECT_FIELD];
1554 const char *addr = ast_strdupa(ast_sockaddr_stringify_addr(&ha->addr));
1555 snprintf(str, MAX_OBJECT_FIELD, "%s%s/%s", ha->sense == AST_SENSE_ALLOW ? "!" : "",
1557
1558 ast_variable_list_append(head, ast_variable_new("local_net", str, ""));
1559}
@ 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 1774 of file config_transport.c.

1775{
1776 struct internal_state *state = obj;
1777 struct ao2_container *container = arg;
1778
1779 ao2_link(container, state->state);
1780
1781 return CMP_MATCH;
1782}
#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 1102 of file config_transport.c.

1103{
1104 const struct ast_sip_transport *transport = obj;
1105
1106 *buf = ast_strdup(transport->privkey_file);
1107
1108 return 0;
1109}
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 1255 of file config_transport.c.

1256{
1257 const struct ast_sip_transport *transport = obj;
1259
1260 if (!state) {
1261 return -1;
1262 }
1263
1264 *buf = ast_strdup(AST_YESNO(state->tls.require_client_cert));
1265
1266 return 0;
1267}

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

1342{
1343 const struct ast_sip_transport *transport = obj;
1345
1346 if (!state) {
1347 return -1;
1348 }
1349
1350 if (ARRAY_IN_BOUNDS(state->tls.method, tls_method_map)) {
1351 *buf = ast_strdup(tls_method_map[state->tls.method]);
1352 }
1353
1354 return 0;
1355}
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 1624 of file config_transport.c.

1625{
1626 const struct ast_sip_transport *transport = obj;
1627
1628 if (ast_asprintf(buf, "%u", transport->tos) == -1) {
1629 return -1;
1630 }
1631 return 0;
1632}
#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 int sockopt_count = 0;
832
833 pjsip_tcp_transport_cfg_default(&cfg, temp_state->state->host.addr.sa_family);
834 cfg.bind_addr = temp_state->state->host;
835 cfg.async_cnt = transport->async_operations;
836 set_qos(transport, &cfg.qos_params);
837
838 /* sockopt_params.options is copied to each newly connected socket */
839 cfg.sockopt_params.options[sockopt_count].level = pj_SOL_TCP();
840 cfg.sockopt_params.options[sockopt_count].optname = pj_TCP_NODELAY();
841 cfg.sockopt_params.options[sockopt_count].optval = &option;
842 cfg.sockopt_params.options[sockopt_count].optlen = sizeof(option);
843 sockopt_count++;
844
845 if (transport->tcp_keepalive_enable) {
846#if defined(PJ_MAX_SOCKOPT_PARAMS) && PJ_MAX_SOCKOPT_PARAMS >= 5
847 ast_log(LOG_DEBUG, "TCP Keepalive enabled for transport '%s'. Idle Time: %d, Interval: %d, Count: %d\n",
849
850 cfg.sockopt_params.options[sockopt_count].level = pj_SOL_SOCKET();
851 cfg.sockopt_params.options[sockopt_count].optname = SO_KEEPALIVE;
852 cfg.sockopt_params.options[sockopt_count].optval = &option;
853 cfg.sockopt_params.options[sockopt_count].optlen = sizeof(option);
854 sockopt_count++;
855
856 cfg.sockopt_params.options[sockopt_count].level = pj_SOL_TCP();
857 cfg.sockopt_params.options[sockopt_count].optname = TCP_KEEPIDLE;
858 cfg.sockopt_params.options[sockopt_count].optval = &transport->tcp_keepalive_idle_time;
859 cfg.sockopt_params.options[sockopt_count].optlen = sizeof(transport->tcp_keepalive_idle_time);
860 sockopt_count++;
861
862 cfg.sockopt_params.options[sockopt_count].level = pj_SOL_TCP();
863 cfg.sockopt_params.options[sockopt_count].optname = TCP_KEEPINTVL;
864 cfg.sockopt_params.options[sockopt_count].optval = &transport->tcp_keepalive_interval_time;
865 cfg.sockopt_params.options[sockopt_count].optlen = sizeof(transport->tcp_keepalive_interval_time);
866 sockopt_count++;
867
868 cfg.sockopt_params.options[sockopt_count].level = pj_SOL_TCP();
869 cfg.sockopt_params.options[sockopt_count].optname = TCP_KEEPCNT;
870 cfg.sockopt_params.options[sockopt_count].optval = &transport->tcp_keepalive_probe_count;
871 cfg.sockopt_params.options[sockopt_count].optlen = sizeof(transport->tcp_keepalive_probe_count);
872 sockopt_count++;
873#else
874 ast_log(LOG_WARNING, "TCP keepalive settings for '%s' not set due to PJSIP built without support for setting all options. Consider using bundled PJSIP.\n",
876#endif
877 }
878
879 cfg.sockopt_params.cnt = sockopt_count;
880
881 for (i = 0; i < BIND_TRIES && res != PJ_SUCCESS; i++) {
882 if (perm_state && perm_state->state && perm_state->state->factory
883 && perm_state->state->factory->destroy) {
884 perm_state->state->factory->destroy(perm_state->state->factory);
885 usleep(BIND_DELAY_US);
886 }
887
888 res = pjsip_tcp_transport_start3(ast_sip_get_pjsip_endpoint(), &cfg,
889 &temp_state->state->factory);
890 }
891 } else if (transport->type == AST_TRANSPORT_TLS) {
892#if defined(PJ_HAS_SSL_SOCK) && PJ_HAS_SSL_SOCK != 0
893 static int option = 1;
894 int sockopt_count = 0;
895
896 if (transport->async_operations > 1 && ast_compare_versions(pj_get_version(), "2.5.0") < 0) {
897 ast_log(LOG_ERROR, "Transport: %s: When protocol=tls and pjproject version < 2.5.0, async_operations can't be > 1\n",
899 return -1;
900 }
901
902 temp_state->state->tls.password = pj_str((char*)transport->password);
903 set_qos(transport, &temp_state->state->tls.qos_params);
904
905 /* sockopt_params.options is copied to each newly connected socket */
906 temp_state->state->tls.sockopt_params.options[sockopt_count].level = pj_SOL_TCP();
907 temp_state->state->tls.sockopt_params.options[sockopt_count].optname = pj_TCP_NODELAY();
908 temp_state->state->tls.sockopt_params.options[sockopt_count].optval = &option;
909 temp_state->state->tls.sockopt_params.options[sockopt_count].optlen = sizeof(option);
910 sockopt_count++;
911
912 if (transport->tcp_keepalive_enable) {
913#if defined(PJ_MAX_SOCKOPT_PARAMS) && PJ_MAX_SOCKOPT_PARAMS >= 5
914 ast_log(LOG_DEBUG, "TCP Keepalive enabled for transport '%s'. Idle Time: %d, Interval: %d, Count: %d\n",
916
917 temp_state->state->tls.sockopt_params.options[sockopt_count].level = pj_SOL_SOCKET();
918 temp_state->state->tls.sockopt_params.options[sockopt_count].optname = SO_KEEPALIVE;
919 temp_state->state->tls.sockopt_params.options[sockopt_count].optval = &option;
920 temp_state->state->tls.sockopt_params.options[sockopt_count].optlen = sizeof(option);
921 sockopt_count++;
922
923 temp_state->state->tls.sockopt_params.options[sockopt_count].level = pj_SOL_TCP();
924 temp_state->state->tls.sockopt_params.options[sockopt_count].optname = TCP_KEEPIDLE;
925 temp_state->state->tls.sockopt_params.options[sockopt_count].optval = &transport->tcp_keepalive_idle_time;
926 temp_state->state->tls.sockopt_params.options[sockopt_count].optlen = sizeof(transport->tcp_keepalive_idle_time);
927 sockopt_count++;
928
929 temp_state->state->tls.sockopt_params.options[sockopt_count].level = pj_SOL_TCP();
930 temp_state->state->tls.sockopt_params.options[sockopt_count].optname = TCP_KEEPINTVL;
931 temp_state->state->tls.sockopt_params.options[sockopt_count].optval = &transport->tcp_keepalive_interval_time;
932 temp_state->state->tls.sockopt_params.options[sockopt_count].optlen = sizeof(transport->tcp_keepalive_interval_time);
933 sockopt_count++;
934
935 temp_state->state->tls.sockopt_params.options[sockopt_count].level = pj_SOL_TCP();
936 temp_state->state->tls.sockopt_params.options[sockopt_count].optname = TCP_KEEPCNT;
937 temp_state->state->tls.sockopt_params.options[sockopt_count].optval = &transport->tcp_keepalive_probe_count;
938 temp_state->state->tls.sockopt_params.options[sockopt_count].optlen = sizeof(transport->tcp_keepalive_probe_count);
939 sockopt_count++;
940#else
941 ast_log(LOG_WARNING, "TCP keepalive settings for '%s' not set due to PJSIP built without support for setting all options. Consider using bundled PJSIP.\n",
943#endif
944 }
945
946 temp_state->state->tls.sockopt_params.cnt = sockopt_count;
947
948 for (i = 0; i < BIND_TRIES && res != PJ_SUCCESS; i++) {
949 if (perm_state && perm_state->state && perm_state->state->factory
950 && perm_state->state->factory->destroy) {
951 perm_state->state->factory->destroy(perm_state->state->factory);
952 usleep(BIND_DELAY_US);
953 }
954
955 res = pjsip_tls_transport_start2(ast_sip_get_pjsip_endpoint(), &temp_state->state->tls,
956 &temp_state->state->host, NULL, transport->async_operations,
957 &temp_state->state->factory);
958 }
959
960 if (res == PJ_SUCCESS) {
961 /*
962 * PJSIP uses 100 bytes to store information, and during a restart will repopulate
963 * the field so ensure there is sufficient space - even though we'll revert it after.
964 */
965 temp_state->state->factory->info = pj_pool_alloc(
966 temp_state->state->factory->pool, (MAX(MAX_OBJECT_FIELD, 100) + 1));
967 /*
968 * Store transport id on the factory instance so it can be used
969 * later to look up the transport state.
970 */
971 sprintf(temp_state->state->factory->info, "%s", transport_id);
972 }
973#else
974 ast_log(LOG_ERROR, "Transport: %s: PJSIP has not been compiled with TLS transport support, ensure OpenSSL development packages are installed\n",
976 return -1;
977#endif
978 } else if ((transport->type == AST_TRANSPORT_WS) || (transport->type == AST_TRANSPORT_WSS)) {
979 if (transport->cos || transport->tos) {
980 ast_log(LOG_WARNING, "TOS and COS values ignored for websocket transport\n");
981 } else if (!ast_strlen_zero(transport->ca_list_file) || !ast_strlen_zero(transport->ca_list_path) ||
982 !ast_strlen_zero(transport->cert_file) || !ast_strlen_zero(transport->privkey_file)) {
983 ast_log(LOG_WARNING, "TLS certificate values ignored for websocket transport as they are configured in http.conf\n");
984 }
985 res = PJ_SUCCESS;
986 }
987
988 if (res != PJ_SUCCESS) {
989 char msg[PJ_ERR_MSG_SIZE];
990
991 pj_strerror(res, msg, sizeof(msg));
992 ast_log(LOG_ERROR, "Transport '%s' could not be started: %s\n", ast_sorcery_object_get_id(obj), msg);
993 return -1;
994 }
995
996 copy_state_to_transport(transport);
997 if (perm_state) {
998 ao2_unlink_flags(states, perm_state, OBJ_NOLOCK);
999 }
1000 ao2_link_flags(states, temp_state, OBJ_NOLOCK);
1001
1002 return 0;
1003}
#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_DEBUG
#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:1078
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:1079
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
int tcp_keepalive_probe_count
Definition: res_pjsip.h:309
unsigned int async_operations
Definition: res_pjsip.h:251
int tcp_keepalive_enable
Definition: res_pjsip.h:303
const ast_string_field external_media_address
Definition: res_pjsip.h:241
int tcp_keepalive_interval_time
Definition: res_pjsip.h:307
int tcp_keepalive_idle_time
Definition: res_pjsip.h:305
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_DEBUG, 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::tcp_keepalive_enable, ast_sip_transport::tcp_keepalive_idle_time, ast_sip_transport::tcp_keepalive_interval_time, ast_sip_transport::tcp_keepalive_probe_count, 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 1167 of file config_transport.c.

1168{
1169 struct ast_sip_transport *transport = obj;
1170 pj_str_t buf;
1171 int rc;
1173
1174 if (!state) {
1175 return -1;
1176 }
1177
1178 rc = pj_sockaddr_parse(pj_AF_UNSPEC(), 0, pj_cstr(&buf, var->value), &state->host);
1179
1180 return rc != PJ_SUCCESS ? -1 : 0;
1181}
#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 1183 of file config_transport.c.

1184{
1185 const struct ast_sip_transport *transport = obj;
1187
1188 if (!state) {
1189 return -1;
1190 }
1191
1192 if (!(*buf = ast_calloc(MAX_OBJECT_FIELD, sizeof(char)))) {
1193 return -1;
1194 }
1195
1196 /* include port as well as brackets if IPv6 */
1197 pj_sockaddr_print(&state->host, *buf, MAX_OBJECT_FIELD, 1 | 2);
1198
1199 return 0;
1200}

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

1527{
1528 struct ast_sip_transport *transport = obj;
1529 int error = 0;
1531
1532 if (!state) {
1533 return -1;
1534 }
1535
1536 if (ast_strlen_zero(var->value)) {
1537 ast_free_ha(state->localnet);
1538 state->localnet = NULL;
1539 return 0;
1540 }
1541
1542 /* We use only the ast_apply_ha() which defaults to ALLOW
1543 * ("permit"), so we add DENY rules. */
1544 if (!(state->localnet = ast_append_ha("deny", var->value, state->localnet, &error))) {
1545 return -1;
1546 }
1547
1548 return error;
1549}
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 1112 of file config_transport.c.

1113{
1114 struct ast_sip_transport *transport = obj;
1116
1117 if (!state) {
1118 return -1;
1119 }
1120
1121 if (!strcasecmp(var->value, "flow")) {
1122 transport->flow = 1;
1123 } else {
1124 if (!strcasecmp(var->value, "udp")) {
1125 transport->type = AST_TRANSPORT_UDP;
1126 } else if (!strcasecmp(var->value, "tcp")) {
1127 transport->type = AST_TRANSPORT_TCP;
1128 } else if (!strcasecmp(var->value, "tls")) {
1129 transport->type = AST_TRANSPORT_TLS;
1130 } else if (!strcasecmp(var->value, "ws")) {
1131 transport->type = AST_TRANSPORT_WS;
1132 } else if (!strcasecmp(var->value, "wss")) {
1133 transport->type = AST_TRANSPORT_WSS;
1134 } else {
1135 return -1;
1136 }
1137 transport->flow = 0;
1138 }
1139
1140 state->type = transport->type;
1141
1142 return 0;
1143}

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

1154{
1155 const struct ast_sip_transport *transport = obj;
1156
1157 if (transport->flow) {
1158 *buf = ast_strdup("flow");
1159 } else if (ARRAY_IN_BOUNDS(transport->type, transport_types)) {
1160 *buf = ast_strdup(transport_types[transport->type]);
1161 }
1162
1163 return 0;
1164}

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

1007{
1008 struct ast_sip_transport *transport = obj;
1010
1012
1013 return 0;
1014}

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

1204{
1205 struct ast_sip_transport *transport = obj;
1207
1208 if (!state) {
1209 return -1;
1210 }
1211
1212 if (!strcasecmp(var->name, "verify_server")) {
1213 state->verify_server = ast_true(var->value);
1214 } else if (!strcasecmp(var->name, "verify_client")) {
1215 state->tls.verify_client = ast_true(var->value) ? PJ_TRUE : PJ_FALSE;
1216 } else if (!strcasecmp(var->name, "require_client_cert")) {
1217 state->tls.require_client_cert = ast_true(var->value) ? PJ_TRUE : PJ_FALSE;
1218 } else if (!strcasecmp(var->name, "allow_wildcard_certs")) {
1219 state->allow_wildcard_certs = ast_true(var->value);
1220 } else {
1221 return -1;
1222 }
1223
1224 return 0;
1225}
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 1017 of file config_transport.c.

1018{
1019 struct ast_sip_transport *transport = obj;
1021
1022 if (!state) {
1023 return -1;
1024 }
1025
1026 if (ast_strlen_zero(var->value)) {
1027 /* Ignore empty options */
1028 return 0;
1029 }
1030
1031 if (!ast_file_is_readable(var->value)) {
1032 ast_log(LOG_ERROR, "Transport: %s: %s %s is either missing or not readable\n",
1033 ast_sorcery_object_get_id(obj), var->name, var->value);
1034 return -1;
1035 }
1036
1037 if (!strcasecmp(var->name, "ca_list_file")) {
1038 state->tls.ca_list_file = pj_str((char*)var->value);
1039 ast_string_field_set(transport, ca_list_file, var->value);
1040 } else if (!strcasecmp(var->name, "ca_list_path")) {
1041#ifdef HAVE_PJ_SSL_CERT_LOAD_FROM_FILES2
1042 state->tls.ca_list_path = pj_str((char *)var->value);
1043 ast_string_field_set(transport, ca_list_path, var->value);
1044#else
1045 ast_log(LOG_WARNING, "Asterisk has been built against a version of pjproject that does not "
1046 "support the 'ca_list_path' option. Please upgrade to version 2.4 or later.\n");
1047#endif
1048 } else if (!strcasecmp(var->name, "cert_file")) {
1049 state->tls.cert_file = pj_str((char *)var->value);
1050 ast_string_field_set(transport, cert_file, var->value);
1051#ifdef HAVE_PJSIP_TLS_TRANSPORT_RESTART
1052 if (stat(var->value, &state->cert_file_stat)) {
1053 ast_log(LOG_ERROR, "Failed to stat certificate file '%s' for transport '%s' due to '%s'\n",
1054 var->value, ast_sorcery_object_get_id(obj), strerror(errno));
1055 return -1;
1056 }
1058#endif
1059 } else if (!strcasecmp(var->name, "priv_key_file")) {
1060 state->tls.privkey_file = pj_str((char *)var->value);
1061 ast_string_field_set(transport, privkey_file, var->value);
1062#ifdef HAVE_PJSIP_TLS_TRANSPORT_RESTART
1063 if (stat(var->value, &state->privkey_file_stat)) {
1064 ast_log(LOG_ERROR, "Failed to stat private key file '%s' for transport '%s' due to '%s'\n",
1065 var->value, ast_sorcery_object_get_id(obj), strerror(errno));
1066 return -1;
1067 }
1069#endif
1070 }
1071
1072 return 0;
1073}
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 1284 of file config_transport.c.

1285{
1286 struct ast_sip_transport *transport = obj;
1288
1289 if (!state) {
1290 return -1;
1291 }
1292
1293 if (ast_strlen_zero(var->value) || !strcasecmp(var->value, "default")) {
1294 state->tls.method = PJSIP_SSL_DEFAULT_METHOD;
1295 } else if (!strcasecmp(var->value, "unspecified")) {
1296 state->tls.method = PJSIP_SSL_UNSPECIFIED_METHOD;
1297 } else if (!strcasecmp(var->value, "tlsv1")) {
1298 state->tls.method = PJSIP_TLSV1_METHOD;
1299#ifdef HAVE_PJSIP_TLS_1_1
1300 } else if (!strcasecmp(var->value, "tlsv1_1")) {
1301 state->tls.method = PJSIP_TLSV1_1_METHOD;
1302#endif
1303#ifdef HAVE_PJSIP_TLS_1_2
1304 } else if (!strcasecmp(var->value, "tlsv1_2")) {
1305 state->tls.method = PJSIP_TLSV1_2_METHOD;
1306#endif
1307#ifdef HAVE_PJSIP_TLS_1_3
1308 } else if (!strcasecmp(var->value, "tlsv1_3")) {
1309 state->tls.method = PJSIP_TLSV1_3_METHOD;
1310#endif
1311 } else if (!strcasecmp(var->value, "sslv2")) {
1312 state->tls.method = PJSIP_SSLV2_METHOD;
1313 } else if (!strcasecmp(var->value, "sslv3")) {
1314 state->tls.method = PJSIP_SSLV3_METHOD;
1315 } else if (!strcasecmp(var->value, "sslv23")) {
1316 state->tls.method = PJSIP_SSLV23_METHOD;
1317 } else {
1318 return -1;
1319 }
1320
1321 return 0;
1322}

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

1600{
1601 struct ast_sip_transport *transport = obj;
1602 unsigned int value;
1603
1604 if (ast_str2tos(var->value, &value)) {
1605 ast_log(LOG_ERROR, "Error configuring transport '%s' - Could not "
1606 "interpret 'tos' value '%s'\n",
1607 ast_sorcery_object_get_id(transport), var->value);
1608 return -1;
1609 }
1610
1611 if (value % 4) {
1612 value = value >> 2;
1613 value = value << 2;
1615 "transport '%s' - 'tos' value '%s' uses bits that are "
1616 "discarded when converted to DSCP. Using equivalent %u instead.\n",
1617 ast_sorcery_object_get_id(transport), var->value, value);
1618 }
1619
1620 transport->tos = value;
1621 return 0;
1622}
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 1241 of file config_transport.c.

1242{
1243 const struct ast_sip_transport *transport = obj;
1245
1246 if (!state) {
1247 return -1;
1248 }
1249
1250 *buf = ast_strdup(AST_YESNO(state->tls.verify_client));
1251
1252 return 0;
1253}

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

1228{
1229 const struct ast_sip_transport *transport = obj;
1231
1232 if (!state) {
1233 return -1;
1234 }
1235
1236 *buf = ast_strdup(AST_YESNO(state->verify_server));
1237
1238 return 0;
1239}

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 1324 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 1145 of file config_transport.c.

Referenced by cli_print_body(), and transport_protocol_to_str().