Asterisk - The Open Source Telephony Project GIT-master-80b953f
Loading...
Searching...
No Matches
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.
 
#define MAX_POINTER_STRING   33
 

Functions

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.
 
struct ao2_containerast_sip_get_transport_states (void)
 Retrieves all transport states.
 
int ast_sip_initialize_sorcery_transport (void)
 Initialize sorcery with transport support.
 
void ast_sip_message_apply_transport (const char *transport_name, pjsip_tx_data *tdata)
 Apply the configuration for a transport to an outgoing message.
 
struct ast_sip_service_route_vectorast_sip_service_route_vector_alloc (void)
 Allocate a vector of service routes.
 
void ast_sip_service_route_vector_destroy (struct ast_sip_service_route_vector *service_routes)
 Destroy a vector of service routes.
 
int ast_sip_transport_state_set_preferred_identity (const char *transport_name, const char *identity)
 Sets the P-Preferred-Identity on a child transport.
 
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.
 
int ast_sip_transport_state_set_transport (const char *transport_name, pjsip_transport *transport)
 Sets the PJSIP transport on a child transport.
 
 AST_THREADSTORAGE_CUSTOM_SCOPE (temp_state_store, NULL, temp_state_store_cleanup, static)
 
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
 
static void internal_state_destroy (void *obj)
 Destructor for ast_sip_transport state information.
 
static int internal_state_hash (const void *obj, const int flags)
 hashing function for state objects
 
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.
 
static void sip_transport_destroy (void *obj)
 Destructor for transport.
 
static void sip_transport_state_destroy (void *obj)
 Destructor for ast_sip_transport state information.
 
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.
 
static int transport_bind_handler (const struct aco_option *opt, struct ast_variable *var, void *obj)
 Custom handler for turning a string bind into a pj_sockaddr.
 
static int transport_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.
 
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.
 
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
 
static int transport_state_hash (const void *obj, const int flags)
 hashing function for state objects
 
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 transport_tls_bool_handler (const struct aco_option *opt, struct ast_variable *var, void *obj)
 Custom handler for TLS boolean settings.
 
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_tls_method_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 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 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 53 of file config_transport.c.

◆ MAX_POINTER_STRING

#define MAX_POINTER_STRING   33

Definition at line 50 of file config_transport.c.

Function Documentation

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

1291{
1293
1294 if (!state) {
1295 return -1;
1296 }
1297
1298 *buf = ast_strdup(AST_YESNO(state->allow_wildcard_certs));
1299 ao2_ref(state, -1);
1300
1301 return 0;
1302}
#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:117

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

1906{
1909
1911
1914
1915 return 0;
1916}
void ast_cli_unregister_multiple(void)
Definition ael_main.c:408
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:481
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:706

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

1773{
1774 struct internal_state *state = NULL;
1775 struct ast_sip_transport_state *trans_state;
1776
1777 if (!transport_states) {
1778 return NULL;
1779 }
1780
1782 if (!state) {
1783 return NULL;
1784 }
1785
1786 trans_state = ao2_bump(state->state);
1787 ao2_ref(state, -1);
1788
1789 /* If this is a child transport see if the transport is actually dead */
1790 if (trans_state->flow) {
1791 ao2_lock(trans_state);
1792 if (trans_state->transport && trans_state->transport->is_shutdown == PJ_TRUE) {
1793 pjsip_transport_dec_ref(trans_state->transport);
1794 trans_state->transport = NULL;
1795 }
1796 ao2_unlock(trans_state);
1797 }
1798
1799 return trans_state;
1800}
#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:119

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(), 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 1812 of file config_transport.c.

1813{
1816
1817 if (!states) {
1818 return NULL;
1819 }
1820
1822 return states;
1823}
@ 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 1826 of file config_transport.c.

1827{
1829 struct ao2_container *transports = NULL;
1830
1831 /* Create outbound registration states container. */
1834 if (!transport_states) {
1835 ast_log(LOG_ERROR, "Unable to allocate transport states container\n");
1836 return -1;
1837 }
1838
1839 ast_sorcery_apply_default(sorcery, "transport", "config", "pjsip.conf,criteria=type=transport");
1840
1842 return -1;
1843 }
1844
1845 /* Normally type is a OPT_NOOP_T but we're using it to make sure that state is created */
1849 ast_sorcery_object_field_register(sorcery, "transport", "async_operations", "1", OPT_UINT_T, 0, FLDSET(struct ast_sip_transport, async_operations));
1850
1855
1856 ast_sorcery_object_field_register(sorcery, "transport", "password", "", OPT_STRINGFIELD_T, 0, STRFLDSET(struct ast_sip_transport, password));
1857 ast_sorcery_object_field_register(sorcery, "transport", "external_signaling_address", "", OPT_STRINGFIELD_T, 0, STRFLDSET(struct ast_sip_transport, external_signaling_address));
1858 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);
1859 ast_sorcery_object_field_register(sorcery, "transport", "external_media_address", "", OPT_STRINGFIELD_T, 0, STRFLDSET(struct ast_sip_transport, external_media_address));
1860 ast_sorcery_object_field_register(sorcery, "transport", "domain", "", OPT_STRINGFIELD_T, 0, STRFLDSET(struct ast_sip_transport, domain));
1866 ast_sorcery_object_field_register(sorcery, "transport", "tcp_keepalive_enable", "no", OPT_BOOL_T, 1, FLDSET(struct ast_sip_transport, tcp_keepalive_enable));
1867 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));
1868 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));
1869 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));
1870#if defined(PJ_HAS_SSL_SOCK) && PJ_HAS_SSL_SOCK != 0
1871 ast_sorcery_object_field_register_custom(sorcery, "transport", "cipher", "", transport_tls_cipher_handler, transport_tls_cipher_to_str, NULL, 0, 0);
1872#endif
1875 ast_sorcery_object_field_register(sorcery, "transport", "cos", "0", OPT_UINT_T, 0, FLDSET(struct ast_sip_transport, cos));
1876 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);
1877 ast_sorcery_object_field_register(sorcery, "transport", "allow_reload", "no", OPT_BOOL_T, 1, FLDSET(struct ast_sip_transport, allow_reload));
1878 ast_sorcery_object_field_register(sorcery, "transport", "symmetric_transport", "no", OPT_BOOL_T, 1, FLDSET(struct ast_sip_transport, symmetric_transport));
1879
1881
1883 if (!cli_formatter) {
1884 ast_log(LOG_ERROR, "Unable to allocate memory for cli formatter\n");
1885 return -1;
1886 }
1887 cli_formatter->name = "transport";
1894
1897
1898 /* trigger load of transports from realtime by trying to revrieve them all */
1900 ao2_cleanup(transports);
1901
1902 return 0;
1903}
#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:380
static struct ast_sorcery * sorcery
#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:475
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
const char * ast_sorcery_object_get_id(const void *object)
Get the unique identifier of a sorcery object.
Definition sorcery.c:2381
@ 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:1961
CLI Formatter Registry Entry.
int(* iterate)(void *container, ao2_callback_fn callback, void *args)
ao2_callback_fn * print_header
void *(* retrieve_by_id)(const char *id)
const char *(* get_id)(const void *obj)
const char * name
ao2_callback_fn * print_body
struct ao2_container *(* get_container)(const char *regex)
Transport to bind to.
Definition res_pjsip.h:219
Full structure for sorcery.
Definition sorcery.c:231

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

316{
317 struct ast_sip_transport_state *transport_state;
318
319 if (ast_strlen_zero(transport_name)) {
320 return;
321 }
322
323 /* We only currently care about requests that are of the INVITE, CANCEL, or OPTIONS
324 * type but in the future we could support other messages.
325 */
326 if (tdata->msg->type != PJSIP_REQUEST_MSG ||
327 (pjsip_method_cmp(&tdata->msg->line.req.method, &pjsip_invite_method) &&
328 pjsip_method_cmp(&tdata->msg->line.req.method, &pjsip_cancel_method) &&
329 pjsip_method_cmp(&tdata->msg->line.req.method, &pjsip_options_method))) {
330 return;
331 }
332
333 transport_state = ast_sip_get_transport_state(transport_name);
334 if (!transport_state) {
335 return;
336 }
337
338 if (!transport_state->flow) {
339 ao2_ref(transport_state, -1);
340 return;
341 }
342
343 ao2_lock(transport_state);
344
345 /* If a Preferred Identity has been set then add it to the request */
346 if (transport_state->preferred_identity) {
347 ast_sip_add_header(tdata, "P-Preferred-Identity", transport_state->preferred_identity);
348 }
349
350 /* If Service Routes have been set then add them to the request */
351 if (transport_state->service_routes) {
352 int idx;
353
354 for (idx = 0; idx < AST_VECTOR_SIZE(transport_state->service_routes); ++idx) {
355 char *service_route = AST_VECTOR_GET(transport_state->service_routes, idx);
356
357 ast_sip_add_header(tdata, "Route", service_route);
358 }
359 }
360
361 ao2_unlock(transport_state);
362
363 ao2_ref(transport_state, -1);
364}
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:2002
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:189
#define AST_VECTOR_SIZE(vec)
Get the number of elements in a vector.
Definition vector.h:620
#define AST_VECTOR_GET(vec, idx)
Get an element from a vector.
Definition vector.h:691

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

367{
368 struct ast_sip_service_route_vector *service_routes;
369
370 service_routes = ast_calloc(1, sizeof(*service_routes));
371 if (!service_routes) {
372 return NULL;
373 }
374
375 AST_VECTOR_INIT(service_routes, 0);
376
377 return service_routes;
378}
#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:124

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

381{
382 if (!service_routes) {
383 return;
384 }
385
386 AST_VECTOR_CALLBACK_VOID(service_routes, ast_free);
387 ast_free(service_routes);
388}
#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:873

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

257{
258 struct ast_sip_transport_state *transport_state;
259
260 if (ast_strlen_zero(transport_name)) {
261 return 0;
262 }
263
264 transport_state = ast_sip_get_transport_state(transport_name);
265 if (!transport_state) {
266 return -1;
267 }
268
269 if (!transport_state->flow) {
270 ao2_ref(transport_state, -1);
271 return 0;
272 }
273
274 ao2_lock(transport_state);
275 ast_free(transport_state->preferred_identity);
276 transport_state->preferred_identity = ast_strdup(identity);
277 ao2_unlock(transport_state);
278
279 ao2_ref(transport_state, -1);
280
281 return 0;
282}

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

285{
286 struct ast_sip_transport_state *transport_state;
287
288 if (ast_strlen_zero(transport_name)) {
290 return 0;
291 }
292
293 transport_state = ast_sip_get_transport_state(transport_name);
294 if (!transport_state) {
296 return -1;
297 }
298
299 if (!transport_state->flow) {
300 ao2_ref(transport_state, -1);
302 return 0;
303 }
304
305 ao2_lock(transport_state);
307 transport_state->service_routes = service_routes;
308 ao2_unlock(transport_state);
309
310 ao2_ref(transport_state, -1);
311
312 return 0;
313}
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 220 of file config_transport.c.

221{
222 struct ast_sip_transport_state *transport_state;
223
224 /* To make it easier on callers we allow an empty transport name */
225 if (ast_strlen_zero(transport_name)) {
226 return 0;
227 }
228
229 transport_state = ast_sip_get_transport_state(transport_name);
230 if (!transport_state) {
231 return -1;
232 }
233
234 if (!transport_state->flow) {
235 ao2_ref(transport_state, -1);
236 return 0;
237 }
238
239 ao2_lock(transport_state);
240 if (transport_state->transport != transport) {
241 if (transport_state->transport) {
242 pjsip_transport_dec_ref(transport_state->transport);
243 }
244 transport_state->transport = transport;
245 if (transport_state->transport) {
246 pjsip_transport_add_ref(transport_state->transport);
247 }
248 }
249 ao2_unlock(transport_state);
250
251 ao2_ref(transport_state, -1);
252
253 return 0;
254}

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

◆ AST_THREADSTORAGE_CUSTOM_SCOPE()

AST_THREADSTORAGE_CUSTOM_SCOPE ( temp_state_store  ,
NULL  ,
temp_state_store_cleanup  ,
static   
)

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

1093{
1094 const struct ast_sip_transport *transport = obj;
1095
1096 *buf = ast_strdup(transport->ca_list_file);
1097
1098 return 0;
1099}
const ast_string_field ca_list_file
Definition res_pjsip.h:239

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

1102{
1103 const struct ast_sip_transport *transport = obj;
1104
1105 *buf = ast_strdup(transport->ca_list_path);
1106
1107 return 0;
1108}
const ast_string_field ca_list_path
Definition res_pjsip.h:239

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

1111{
1112 const struct ast_sip_transport *transport = obj;
1113
1114 *buf = ast_strdup(transport->cert_file);
1115
1116 return 0;
1117}
const ast_string_field cert_file
Definition res_pjsip.h:239

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

1663{
1665 struct ao2_container *s_container;
1666
1668 regex);
1669 if (!container) {
1670 return NULL;
1671 }
1672
1675 if (!s_container) {
1676 return NULL;
1677 }
1678
1679 if (ao2_container_dup(s_container, container, 0)) {
1680 ao2_ref(s_container, -1);
1681 return NULL;
1682 }
1683
1684 return s_container;
1685}
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:603
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:2018
int ast_sorcery_object_id_compare(void *obj, void *arg, int flags)
ao2 object comparator based on sorcery id.
Definition sorcery.c:2528
int ast_sorcery_object_id_sort(const void *obj, const void *arg, int flags)
ao2 object sorter based on sorcery id.
Definition sorcery.c:2504
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
Definition utils.h:981

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

1688{
1689 const struct ast_sip_endpoint *endpoint = container;
1691 "transport", endpoint->transport);
1692
1693 if (!transport) {
1694 return -1;
1695 }
1696
1697 return callback(transport, args, 0);
1698}
static struct ast_channel * callback(struct ast_channelstorage_instance *driver, ao2_callback_data_fn *cb_fn, void *arg, void *data, int ao2_flags, int rdlock)
static struct @521 args
void * ast_sorcery_retrieve_by_id(const struct ast_sorcery *sorcery, const char *type, const char *id)
Retrieve an object using its unique identifier.
Definition sorcery.c:1917
An entity with which Asterisk communicates.
Definition res_pjsip.h:1061
const ast_string_field transport
Definition res_pjsip.h:1090

References args, ast_sip_get_sorcery(), ast_sorcery_retrieve_by_id(), callback(), 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 1720 of file config_transport.c.

1721{
1722 struct ast_sip_transport *transport = obj;
1723 struct ast_sip_cli_context *context = arg;
1724 char hoststr[PJ_INET6_ADDRSTRLEN];
1726
1727 if (!state) {
1728 return -1;
1729 }
1730
1731 ast_assert(context->output_buffer != NULL);
1732
1733 pj_sockaddr_print(&state->host, hoststr, sizeof(hoststr), 3);
1734
1735 ast_str_append(&context->output_buffer, 0, "%*s: %-21s %6s %5u %5u %s\n",
1736 CLI_INDENT_TO_SPACES(context->indent_level), "Transport",
1737 ast_sorcery_object_get_id(transport),
1738 ARRAY_IN_BOUNDS(transport->type, transport_types) ? transport_types[transport->type] : "Unknown",
1739 transport->cos, transport->tos, hoststr);
1740
1741 if (context->show_details
1742 || (context->show_details_only_level_0 && context->indent_level == 0)) {
1743 ast_str_append(&context->output_buffer, 0, "\n");
1744 ast_sip_cli_print_sorcery_objectset(transport, context, 0);
1745 }
1746
1747 return 0;
1748}
unsigned int tos
Definition chan_iax2.c:379
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)
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.
enum ast_transport type
Definition res_pjsip.h:241
#define ast_assert(a)
Definition utils.h:779
#define ARRAY_IN_BOUNDS(v, a)
Checks to see if value is within the bounds of the given array.
Definition utils.h:727

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

1706{
1707 struct ast_sip_cli_context *context = arg;
1708 int indent = CLI_INDENT_TO_SPACES(context->indent_level);
1709 int filler = CLI_MAX_WIDTH - indent - 61;
1710
1711 ast_assert(context->output_buffer != NULL);
1712
1713 ast_str_append(&context->output_buffer, 0,
1714 "%*s: <TransportId........> <Type> <cos> <tos> <BindAddress%*.*s>\n",
1715 indent, "Transport", filler, filler, CLI_HEADER_FILLER);
1716
1717 return 0;
1718}
#define CLI_HEADER_FILLER
#define CLI_MAX_WIDTH

References ast_assert, ast_str_append(), CLI_HEADER_FILLER, CLI_INDENT_TO_SPACES, CLI_MAX_WIDTH, 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 1700 of file config_transport.c.

1701{
1702 return ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(), "transport", id);
1703}

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

583{
584 ast_assert(transport && transport->state);
585
586 memcpy(&transport->host, &transport->state->host, sizeof(transport->host));
587 memcpy(&transport->tls, &transport->state->tls, sizeof(transport->tls));
588 memcpy(&transport->ciphers, &transport->state->ciphers, sizeof(transport->ciphers));
589 transport->localnet = transport->state->localnet;
591 memcpy(&transport->external_address, &transport->state->external_signaling_address, sizeof(transport->external_signaling_address));
592}
pjsip_tls_setting tls
Definition res_pjsip.h:141
struct ast_ha * localnet
Definition res_pjsip.h:154
struct ast_dnsmgr_entry * external_signaling_address_refresher
Definition res_pjsip.h:159
pj_ssl_cipher ciphers[SIP_TLS_MAX_CIPHERS]
Definition res_pjsip.h:146
struct ast_sockaddr external_signaling_address
Definition res_pjsip.h:164
pjsip_tls_setting tls
Definition res_pjsip.h:257
struct ast_sockaddr external_address
Definition res_pjsip.h:281
const ast_string_field external_signaling_address
Definition res_pjsip.h:239
struct ast_sip_transport_state * state
Definition res_pjsip.h:287
struct ast_ha * localnet
Definition res_pjsip.h:269
pj_sockaddr host
Definition res_pjsip.h:247
pj_ssl_cipher ciphers[SIP_TLS_MAX_CIPHERS]
Definition res_pjsip.h:263
struct ast_dnsmgr_entry * external_address_refresher
Definition res_pjsip.h:275

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

430{
431 struct ast_sip_transport_state *transport_state = data;
432
433 ast_free(transport_state->id);
434 ast_free_ha(transport_state->localnet);
435
436 if (transport_state->external_signaling_address_refresher) {
438 }
439 if (transport_state->external_media_address_refresher) {
441 }
442 if (transport_state->transport) {
443 pjsip_transport_shutdown(transport_state->transport);
444 }
445
446 return 0;
447}
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:169

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

468{
469 const char *key = ast_sorcery_object_get_id(transport);
470
472}
@ 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 548 of file config_transport.c.

549{
551 struct ast_sip_transport_state *new_state;
552
553 if ((new_state = find_temporary_state(transport))) {
554 return new_state;
555 }
556
557 state = ast_threadstorage_get(&temp_state_store, sizeof(state));
558 if (!state || *state) {
559 return NULL;
560 }
561
562 new_state = ao2_alloc(sizeof(**state), sip_transport_state_destroy);
563 if (!new_state) {
564 return NULL;
565 }
567 new_state->type = transport->type;
568
569 pjsip_tls_setting_default(&new_state->tls);
570#ifdef HAVE_PJSIP_TLS_TRANSPORT_PROTO
571 /* proto must be forced to 0 to enable all protocols otherwise only TLS will work */
572 new_state->tls.proto = 0;
573#endif
574 new_state->tls.ciphers = new_state->ciphers;
575
576 ao2_ref(new_state, +1);
577 *state = new_state;
578
579 return new_state;
580}
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.
enum ast_transport type
Definition res_pjsip.h:131
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(), 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 474 of file config_transport.c.

475{
476 struct internal_state *state;
477 struct ast_sip_transport_state *trans_state;
478
480 if (!state) {
481 return NULL;
482 }
483 trans_state = ao2_bump(state->state);
484 ao2_ref(state, -1);
485
486 return trans_state;
487}
static struct internal_state * find_internal_state_by_transport(const struct ast_sip_transport *transport)
struct ast_sip_transport_state * state
Transport state information.

References ao2_bump, ao2_ref, find_internal_state_by_transport(), NULL, internal_state::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 503 of file config_transport.c.

504{
506
507 state = ast_threadstorage_get(&temp_state_store, sizeof(state));
508 if (state && *state) {
509 ao2_ref(*state, +1);
510 return *state;
511 }
512
513 return NULL;
514}

References ao2_ref, ast_threadstorage_get(), and NULL.

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

184{
185 RAII_VAR(struct ast_str *, buf, NULL, ast_free);
186 RAII_VAR(struct ast_sip_transport *, transport, NULL, ao2_cleanup);
187
188 if (ast_strlen_zero(endpoint->transport)) {
189 return 0;
190 }
191
192 buf = ast_sip_create_ami_event("TransportDetail", ami);
193 if (!buf) {
194 return -1;
195 }
196
197 transport = ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(), "transport",
198 endpoint->transport);
199 if (!transport) {
200 astman_send_error_va(ami->s, ami->m, "Unable to retrieve "
201 "transport %s\n", endpoint->transport);
202 return -1;
203 }
204
205 sip_transport_to_ami(transport, &buf);
206
207 ast_str_append(&buf, 0, "EndpointName: %s\r\n",
208 ast_sorcery_object_get_id(endpoint));
209
210 astman_append(ami->s, "%s\r\n", ast_str_buffer(buf));
211 ami->count++;
212
213 return 0;
214}
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:1993
void astman_append(struct mansession *s, const char *fmt,...)
Definition manager.c:1909
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 *attribute_pure 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:3227
const struct message * m
Definition res_pjsip.h:3229
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 610 of file config_transport.c.

611{
612 if (a->type != b->type) {
613 return -1;
614 }
615
616 if (pj_sockaddr_cmp(&a->host, &b->host)) {
617 return -1;
618 }
619
620 if ((a->localnet || b->localnet)
621 && ((!a->localnet != !b->localnet)
622 || ast_sockaddr_cmp(&a->localnet->addr, &b->localnet->addr)
623 || ast_sockaddr_cmp(&a->localnet->netmask, &b->localnet->netmask)))
624 {
625 return -1;
626 }
627
628 if (ast_sockaddr_cmp(&a->external_signaling_address, &b->external_signaling_address)) {
629 return -1;
630 }
631
632 if (ast_sockaddr_cmp(&a->external_media_address, &b->external_media_address)) {
633 return -1;
634 }
635
636 if (a->tls.method != b->tls.method
637 || a->tls.ciphers_num != b->tls.ciphers_num
638#ifdef HAVE_PJSIP_TLS_TRANSPORT_PROTO
639 || a->tls.proto != b->tls.proto
640#endif
641 || a->tls.verify_client != b->tls.verify_client
642 || a->tls.verify_server != b->tls.verify_server
643 || a->tls.require_client_cert != b->tls.require_client_cert) {
644 return -1;
645 }
646
647 if (memcmp(a->ciphers, b->ciphers, sizeof(pj_ssl_cipher) * fmax(a->tls.ciphers_num, b->tls.ciphers_num))) {
648 return -1;
649 }
650
651#ifdef HAVE_PJSIP_TLS_TRANSPORT_RESTART
652 if (file_stat_cmp(&a->cert_file_stat, &b->cert_file_stat) || file_stat_cmp(&a->privkey_file_stat, &b->privkey_file_stat)) {
653 return -1;
654 }
655#endif
656
657 return 0;
658}
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 516 of file config_transport.c.

517{
519
521 if (!internal_state) {
522 return NULL;
523 }
524
526 if (!internal_state->id) {
528 return NULL;
529 }
530
531 /* We're transferring the reference from find_temporary_state */
533 if (!internal_state->state) {
535 return NULL;
536 }
540
541 return internal_state;
542}
static int remove_temporary_state(void)
static void internal_state_destroy(void *obj)
Destructor for ast_sip_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 98 of file config_transport.c.

99{
100 const struct internal_state *object_left = obj;
101 const struct internal_state *object_right = arg;
102 const char *right_key = arg;
103 int cmp;
104
105 switch (flags & OBJ_SEARCH_MASK) {
107 right_key = object_right->id;
108 /* Fall through */
109 case OBJ_SEARCH_KEY:
110 cmp = strcmp(object_left->id, right_key);
111 break;
113 /* Not supported by container. */
114 ast_assert(0);
115 return 0;
116 default:
117 cmp = 0;
118 break;
119 }
120 if (cmp) {
121 return 0;
122 }
123 return CMP_MATCH;
124}
@ 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 458 of file config_transport.c.

459{
460 struct internal_state *state = obj;
461
462 ast_free(state->id);
463 ao2_cleanup(state->transport);
464 ao2_cleanup(state->state);
465}

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

78{
79 const struct internal_state *object;
80 const char *key;
81
82 switch (flags & OBJ_SEARCH_MASK) {
83 case OBJ_SEARCH_KEY:
84 key = obj;
85 break;
87 object = obj;
88 key = object->id;
89 break;
90 default:
91 ast_assert(0);
92 return 0;
93 }
94 return ast_str_hash(key);
95}
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(), internal_state::id, 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 1610 of file config_transport.c.

1611{
1613 const struct ast_sip_transport *transport = obj;
1615
1616 if (!state) {
1617 return -1;
1618 }
1619
1620 ast_ha_join(state->localnet, &str);
1622 return 0;
1623}
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:150
#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 1588 of file config_transport.c.

1589{
1590 const struct ast_sip_transport *transport = obj;
1591 struct ast_variable *head = NULL;
1592 struct ast_ha *ha;
1594
1595 if (!state) {
1596 return -1;
1597 }
1598
1599 for (ha = state->localnet; ha; ha = ha->next) {
1600 localnet_to_vl_append(&head, ha);
1601 }
1602
1603 if (head) {
1604 *fields = head;
1605 }
1606
1607 return 0;
1608}
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 1578 of file config_transport.c.

1579{
1580 char str[MAX_OBJECT_FIELD];
1581 const char *addr = ast_strdupa(ast_sockaddr_stringify_addr(&ha->addr));
1582 snprintf(str, MAX_OBJECT_FIELD, "%s%s/%s", ha->sense == AST_SENSE_ALLOW ? "!" : "",
1583 addr, ast_sockaddr_stringify_addr(&ha->netmask));
1584
1585 ast_variable_list_append(head, ast_variable_new("local_net", str, ""));
1586}
@ 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
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 1802 of file config_transport.c.

1803{
1804 struct internal_state *state = obj;
1805 struct ao2_container *container = arg;
1806
1807 ao2_link(container, state->state);
1808
1809 return CMP_MATCH;
1810}
#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 1119 of file config_transport.c.

1120{
1121 const struct ast_sip_transport *transport = obj;
1122
1123 *buf = ast_strdup(transport->privkey_file);
1124
1125 return 0;
1126}
const ast_string_field privkey_file
Definition res_pjsip.h:239

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

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

1277{
1278 const struct ast_sip_transport *transport = obj;
1280
1281 if (!state) {
1282 return -1;
1283 }
1284
1285 *buf = ast_strdup(AST_YESNO(state->tls.require_client_cert));
1286
1287 return 0;
1288}

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

391{
392 int tos_as_dscp = transport->tos >> 2;
393
394 if (transport->tos) {
395 qos->flags |= PJ_QOS_PARAM_HAS_DSCP;
396 qos->dscp_val = tos_as_dscp;
397 }
398 if (transport->cos) {
399 qos->flags |= PJ_QOS_PARAM_HAS_SO_PRIO;
400 qos->so_prio = transport->cos;
401 }
402}
static struct @118 qos
unsigned int tos
Definition res_pjsip.h:289
unsigned int cos
Definition res_pjsip.h:291

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

414{
415 struct ast_sip_transport *transport = ast_sorcery_generic_alloc(sizeof(*transport), sip_transport_destroy);
416
417 if (!transport) {
418 return NULL;
419 }
420
421 if (ast_string_field_init(transport, 256)) {
422 ao2_cleanup(transport);
423 return NULL;
424 }
425
426 return transport;
427}
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:1792
#define ast_string_field_init(x, size)
Initialize a field pool and fields.

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

406{
407 struct ast_sip_transport *transport = obj;
408
410}
#define ast_string_field_free_memory(x)
free all memory - to be called before destroying the object

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

451{
452 struct ast_sip_transport_state *state = obj;
453
455}
static int destroy_sip_transport_state(void *data)
#define ast_sip_push_task_wait_servant(serializer, sip_task, task_data)
Definition res_pjsip.h:2133

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

178{
179 return ast_sip_sorcery_object_to_ami(transport, buf);
180}
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 660 of file config_transport.c.

661{
662 if (states) {
663 ao2_unlock(states);
664 }
665}

References ao2_unlock.

Referenced by transport_apply().

◆ temp_state_store_cleanup()

static void temp_state_store_cleanup ( void *  data)
static

Definition at line 66 of file config_transport.c.

67{
68 struct ast_sip_transport_state **temp_state = data;
69
70 ao2_cleanup(*temp_state);
71 ast_free(data);
72}

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

1364{
1365 const struct ast_sip_transport *transport = obj;
1367
1368 if (!state) {
1369 return -1;
1370 }
1371
1372 if (ARRAY_IN_BOUNDS(state->tls.method, tls_method_map)) {
1373 *buf = ast_strdup(tls_method_map[state->tls.method]);
1374 }
1375
1376 return 0;
1377}
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 1652 of file config_transport.c.

1653{
1654 const struct ast_sip_transport *transport = obj;
1655
1656 if (ast_asprintf(buf, "%u", transport->tos) == -1) {
1657 return -1;
1658 }
1659 return 0;
1660}
#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 668 of file config_transport.c.

669{
670 struct ast_sip_transport *transport = obj;
671 const char *transport_id = ast_sorcery_object_get_id(obj);
673 RAII_VAR(struct internal_state *, temp_state, NULL, ao2_cleanup);
674 RAII_VAR(struct internal_state *, perm_state, NULL, ao2_cleanup);
675 RAII_VAR(struct ast_variable *, changes, NULL, ast_variables_destroy);
676 pj_status_t res = -1;
677 int i;
678#define BIND_TRIES 3
679#define BIND_DELAY_US 100000
680
681 if (!states) {
682 return -1;
683 }
684
685 /*
686 * transport_apply gets called for EVERY retrieval of a transport when using realtime.
687 * We need to prevent multiple threads from trying to mess with underlying transports
688 * at the same time. The container is the only thing we have to lock on.
689 */
690 ao2_wrlock(states);
691
692 temp_state = internal_state_alloc(transport);
693 if (!temp_state) {
694 ast_log(LOG_ERROR, "Transport '%s' failed to allocate memory\n", transport_id);
695 return -1;
696 }
697
698 if (transport->async_operations != 1) {
699 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",
700 transport_id, transport->async_operations);
701 transport->async_operations = 1;
702 }
703
704 perm_state = find_internal_state_by_transport(transport);
705 if (perm_state) {
706 ast_sorcery_diff(sorcery, perm_state->transport, transport, &changes);
707 if (!changes && !has_state_changed(perm_state->state, temp_state->state)) {
708 /* In case someone is using the deprecated fields, reset them */
709 transport->state = perm_state->state;
710 copy_state_to_transport(transport);
711 ao2_replace(perm_state->transport, transport);
712 return 0;
713 }
714
715 /* If we aren't allowed to reload then we copy values that can't be changed from perm_state */
716 if (!transport->allow_reload) {
717 memcpy(&temp_state->state->host, &perm_state->state->host, sizeof(temp_state->state->host));
718 memcpy(&temp_state->state->tls, &perm_state->state->tls, sizeof(temp_state->state->tls));
719 memcpy(&temp_state->state->ciphers, &perm_state->state->ciphers, sizeof(temp_state->state->ciphers));
720 }
721 }
722
723 if (!transport->flow && (!perm_state || transport->allow_reload)) {
724 if (temp_state->state->host.addr.sa_family != PJ_AF_INET && temp_state->state->host.addr.sa_family != PJ_AF_INET6) {
725 ast_log(LOG_ERROR, "Transport '%s' could not be started as binding not specified\n", transport_id);
726 return -1;
727 }
728
729 /* Set default port if not present */
730 if (!pj_sockaddr_get_port(&temp_state->state->host)) {
731 pj_sockaddr_set_port(&temp_state->state->host, (transport->type == AST_TRANSPORT_TLS) ? 5061 : 5060);
732 }
733 }
734
735 /* Now that we know what address family we can set up a dnsmgr refresh for the external addresses if present */
737 if (temp_state->state->host.addr.sa_family == pj_AF_INET()) {
738 temp_state->state->external_signaling_address.ss.ss_family = AF_INET;
739 } else if (temp_state->state->host.addr.sa_family == pj_AF_INET6()) {
740 temp_state->state->external_signaling_address.ss.ss_family = AF_INET6;
741 } else {
742 ast_log(LOG_ERROR, "Unknown address family for transport '%s', could not get external signaling address\n",
743 transport_id);
744 return -1;
745 }
746
747 if (ast_dnsmgr_lookup(transport->external_signaling_address, &temp_state->state->external_signaling_address, &temp_state->state->external_signaling_address_refresher, NULL) < 0) {
748 ast_log(LOG_ERROR, "Could not create dnsmgr for external signaling address on '%s'\n", transport_id);
749 return -1;
750 }
751 }
752
753 if (!ast_strlen_zero(transport->external_media_address)) {
754 if (temp_state->state->host.addr.sa_family == pj_AF_INET()) {
755 temp_state->state->external_media_address.ss.ss_family = AF_INET;
756 } else if (temp_state->state->host.addr.sa_family == pj_AF_INET6()) {
757 temp_state->state->external_media_address.ss.ss_family = AF_INET6;
758 } else {
759 ast_log(LOG_ERROR, "Unknown address family for transport '%s', could not get external media address\n",
760 transport_id);
761 return -1;
762 }
763
764 if (ast_dnsmgr_lookup(transport->external_media_address, &temp_state->state->external_media_address, &temp_state->state->external_media_address_refresher, NULL) < 0) {
765 ast_log(LOG_ERROR, "Could not create dnsmgr for external media address on '%s'\n", transport_id);
766 return -1;
767 }
768 }
769
770 if (transport->flow) {
771 pj_str_t address;
772
773 ast_debug(1, "Ignoring any bind configuration on transport '%s' as it is a child of another\n",
774 transport_id);
775 pj_sockaddr_parse(pj_AF_UNSPEC(), 0, pj_cstr(&address, "0.0.0.0"), &temp_state->state->host);
776
777 temp_state->state->flow = 1;
778 res = PJ_SUCCESS;
779 } else if (!transport->allow_reload && perm_state) {
780 /* We inherit the transport from perm state, untouched */
781#ifdef HAVE_PJSIP_TLS_TRANSPORT_RESTART
782 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);
783 /* If this is a TLS transport and the certificate or private key has changed, then restart the transport so it uses the new one */
784 if (transport->type == AST_TRANSPORT_TLS) {
785 if (strcmp(perm_state->transport->cert_file, temp_state->transport->cert_file) ||
786 strcmp(perm_state->transport->privkey_file, temp_state->transport->privkey_file)) {
787 ast_log(LOG_ERROR, "Unable to restart TLS transport '%s' as certificate or private key filename has changed\n",
788 transport_id);
789 } else if (file_stat_cmp(&perm_state->state->cert_file_stat, &temp_state->state->cert_file_stat) ||
790 file_stat_cmp(&perm_state->state->privkey_file_stat, &temp_state->state->privkey_file_stat)) {
791 if (pjsip_tls_transport_restart(perm_state->state->factory, &perm_state->state->host, NULL) != PJ_SUCCESS) {
792 ast_log(LOG_ERROR, "Failed to restart TLS transport '%s'\n", transport_id);
793 } else {
794 sprintf(perm_state->state->factory->info, "%s", transport_id);
795 }
796 }
797 }
798#else
799 ast_log(LOG_NOTICE, "Transport '%s' is not fully reloadable, not reloading: protocol, bind, TLS, TCP, ToS, or CoS options.\n", transport_id);
800#endif
801 temp_state->state->transport = perm_state->state->transport;
802 perm_state->state->transport = NULL;
803 temp_state->state->factory = perm_state->state->factory;
804 perm_state->state->factory = NULL;
805
806 res = PJ_SUCCESS;
807 } else if (transport->type == AST_TRANSPORT_UDP) {
808
809 for (i = 0; i < BIND_TRIES && res != PJ_SUCCESS; i++) {
810 if (perm_state && perm_state->state && perm_state->state->transport) {
811 pjsip_udp_transport_pause(perm_state->state->transport,
812 PJSIP_UDP_TRANSPORT_DESTROY_SOCKET);
813 usleep(BIND_DELAY_US);
814 }
815
816 if (temp_state->state->host.addr.sa_family == pj_AF_INET()) {
817 res = pjsip_udp_transport_start(ast_sip_get_pjsip_endpoint(),
818 &temp_state->state->host.ipv4, NULL, transport->async_operations,
819 &temp_state->state->transport);
820 } else if (temp_state->state->host.addr.sa_family == pj_AF_INET6()) {
821 res = pjsip_udp_transport_start6(ast_sip_get_pjsip_endpoint(),
822 &temp_state->state->host.ipv6, NULL, transport->async_operations,
823 &temp_state->state->transport);
824 }
825 }
826
827 if (res == PJ_SUCCESS) {
828 temp_state->state->transport->info = pj_pool_alloc(temp_state->state->transport->pool,
829 (AST_SIP_X_AST_TXP_LEN + strlen(transport_id) + 2));
830
831 sprintf(temp_state->state->transport->info, "%s:%s", AST_SIP_X_AST_TXP, transport_id);
832
833 if (transport->tos || transport->cos) {
834 pj_sock_t sock;
835 pj_qos_params qos_params;
836 sock = pjsip_udp_transport_get_socket(temp_state->state->transport);
837 pj_sock_get_qos_params(sock, &qos_params);
838 set_qos(transport, &qos_params);
839 pj_sock_set_qos_params(sock, &qos_params);
840 }
841 }
842 } else if (transport->type == AST_TRANSPORT_TCP) {
843 pjsip_tcp_transport_cfg cfg;
844 static int option = 1;
845 int sockopt_count = 0;
846
847 pjsip_tcp_transport_cfg_default(&cfg, temp_state->state->host.addr.sa_family);
848 cfg.bind_addr = temp_state->state->host;
849 cfg.async_cnt = transport->async_operations;
850 set_qos(transport, &cfg.qos_params);
851
852 /* sockopt_params.options is copied to each newly connected socket */
853 cfg.sockopt_params.options[sockopt_count].level = pj_SOL_TCP();
854 cfg.sockopt_params.options[sockopt_count].optname = pj_TCP_NODELAY();
855 cfg.sockopt_params.options[sockopt_count].optval = &option;
856 cfg.sockopt_params.options[sockopt_count].optlen = sizeof(option);
857 sockopt_count++;
858
859 if (transport->tcp_keepalive_enable) {
860#if defined(PJ_MAX_SOCKOPT_PARAMS) && PJ_MAX_SOCKOPT_PARAMS >= 5
861 ast_log(LOG_DEBUG, "TCP Keepalive enabled for transport '%s'. Idle Time: %d, Interval: %d, Count: %d\n",
863
864 cfg.sockopt_params.options[sockopt_count].level = pj_SOL_SOCKET();
865 cfg.sockopt_params.options[sockopt_count].optname = SO_KEEPALIVE;
866 cfg.sockopt_params.options[sockopt_count].optval = &option;
867 cfg.sockopt_params.options[sockopt_count].optlen = sizeof(option);
868 sockopt_count++;
869
870 cfg.sockopt_params.options[sockopt_count].level = pj_SOL_TCP();
871 cfg.sockopt_params.options[sockopt_count].optname = TCP_KEEPIDLE;
872 cfg.sockopt_params.options[sockopt_count].optval = &transport->tcp_keepalive_idle_time;
873 cfg.sockopt_params.options[sockopt_count].optlen = sizeof(transport->tcp_keepalive_idle_time);
874 sockopt_count++;
875
876 cfg.sockopt_params.options[sockopt_count].level = pj_SOL_TCP();
877 cfg.sockopt_params.options[sockopt_count].optname = TCP_KEEPINTVL;
878 cfg.sockopt_params.options[sockopt_count].optval = &transport->tcp_keepalive_interval_time;
879 cfg.sockopt_params.options[sockopt_count].optlen = sizeof(transport->tcp_keepalive_interval_time);
880 sockopt_count++;
881
882 cfg.sockopt_params.options[sockopt_count].level = pj_SOL_TCP();
883 cfg.sockopt_params.options[sockopt_count].optname = TCP_KEEPCNT;
884 cfg.sockopt_params.options[sockopt_count].optval = &transport->tcp_keepalive_probe_count;
885 cfg.sockopt_params.options[sockopt_count].optlen = sizeof(transport->tcp_keepalive_probe_count);
886 sockopt_count++;
887#else
888 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",
890#endif
891 }
892
893 cfg.sockopt_params.cnt = sockopt_count;
894
895 for (i = 0; i < BIND_TRIES && res != PJ_SUCCESS; i++) {
896 if (perm_state && perm_state->state && perm_state->state->factory
897 && perm_state->state->factory->destroy) {
898 perm_state->state->factory->destroy(perm_state->state->factory);
899 usleep(BIND_DELAY_US);
900 }
901
902 res = pjsip_tcp_transport_start3(ast_sip_get_pjsip_endpoint(), &cfg,
903 &temp_state->state->factory);
904 }
905 } else if (transport->type == AST_TRANSPORT_TLS) {
906#if defined(PJ_HAS_SSL_SOCK) && PJ_HAS_SSL_SOCK != 0
907 static int option = 1;
908 int sockopt_count = 0;
909
910 if (transport->async_operations > 1 && ast_compare_versions(pj_get_version(), "2.5.0") < 0) {
911 ast_log(LOG_ERROR, "Transport: %s: When protocol=tls and pjproject version < 2.5.0, async_operations can't be > 1\n",
913 return -1;
914 }
915
916 temp_state->state->tls.password = pj_str((char*)transport->password);
917 set_qos(transport, &temp_state->state->tls.qos_params);
918
919 /* sockopt_params.options is copied to each newly connected socket */
920 temp_state->state->tls.sockopt_params.options[sockopt_count].level = pj_SOL_TCP();
921 temp_state->state->tls.sockopt_params.options[sockopt_count].optname = pj_TCP_NODELAY();
922 temp_state->state->tls.sockopt_params.options[sockopt_count].optval = &option;
923 temp_state->state->tls.sockopt_params.options[sockopt_count].optlen = sizeof(option);
924 sockopt_count++;
925
926 if (transport->tcp_keepalive_enable) {
927#if defined(PJ_MAX_SOCKOPT_PARAMS) && PJ_MAX_SOCKOPT_PARAMS >= 5
928 ast_log(LOG_DEBUG, "TCP Keepalive enabled for transport '%s'. Idle Time: %d, Interval: %d, Count: %d\n",
930
931 temp_state->state->tls.sockopt_params.options[sockopt_count].level = pj_SOL_SOCKET();
932 temp_state->state->tls.sockopt_params.options[sockopt_count].optname = SO_KEEPALIVE;
933 temp_state->state->tls.sockopt_params.options[sockopt_count].optval = &option;
934 temp_state->state->tls.sockopt_params.options[sockopt_count].optlen = sizeof(option);
935 sockopt_count++;
936
937 temp_state->state->tls.sockopt_params.options[sockopt_count].level = pj_SOL_TCP();
938 temp_state->state->tls.sockopt_params.options[sockopt_count].optname = TCP_KEEPIDLE;
939 temp_state->state->tls.sockopt_params.options[sockopt_count].optval = &transport->tcp_keepalive_idle_time;
940 temp_state->state->tls.sockopt_params.options[sockopt_count].optlen = sizeof(transport->tcp_keepalive_idle_time);
941 sockopt_count++;
942
943 temp_state->state->tls.sockopt_params.options[sockopt_count].level = pj_SOL_TCP();
944 temp_state->state->tls.sockopt_params.options[sockopt_count].optname = TCP_KEEPINTVL;
945 temp_state->state->tls.sockopt_params.options[sockopt_count].optval = &transport->tcp_keepalive_interval_time;
946 temp_state->state->tls.sockopt_params.options[sockopt_count].optlen = sizeof(transport->tcp_keepalive_interval_time);
947 sockopt_count++;
948
949 temp_state->state->tls.sockopt_params.options[sockopt_count].level = pj_SOL_TCP();
950 temp_state->state->tls.sockopt_params.options[sockopt_count].optname = TCP_KEEPCNT;
951 temp_state->state->tls.sockopt_params.options[sockopt_count].optval = &transport->tcp_keepalive_probe_count;
952 temp_state->state->tls.sockopt_params.options[sockopt_count].optlen = sizeof(transport->tcp_keepalive_probe_count);
953 sockopt_count++;
954#else
955 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",
957#endif
958 }
959
960 temp_state->state->tls.sockopt_params.cnt = sockopt_count;
961
962 for (i = 0; i < BIND_TRIES && res != PJ_SUCCESS; i++) {
963 if (perm_state && perm_state->state && perm_state->state->factory
964 && perm_state->state->factory->destroy) {
965 perm_state->state->factory->destroy(perm_state->state->factory);
966 usleep(BIND_DELAY_US);
967 }
968
969 res = pjsip_tls_transport_start2(ast_sip_get_pjsip_endpoint(), &temp_state->state->tls,
970 &temp_state->state->host, NULL, transport->async_operations,
971 &temp_state->state->factory);
972 }
973
974 if (res == PJ_SUCCESS) {
975 /*
976 * PJSIP uses 100 bytes to store information, and during a restart will repopulate
977 * the field so ensure there is sufficient space - even though we'll revert it after.
978 */
979 temp_state->state->factory->info = pj_pool_alloc(
980 temp_state->state->factory->pool, (MAX(MAX_OBJECT_FIELD, 100) + 1));
981 /*
982 * Store transport id on the factory instance so it can be used
983 * later to look up the transport state.
984 */
985 sprintf(temp_state->state->factory->info, "%s", transport_id);
986 }
987#else
988 ast_log(LOG_ERROR, "Transport: %s: PJSIP has not been compiled with TLS transport support, ensure OpenSSL development packages are installed\n",
990 return -1;
991#endif
992 } else if ((transport->type == AST_TRANSPORT_WS) || (transport->type == AST_TRANSPORT_WSS)) {
993 if (transport->cos || transport->tos) {
994 ast_log(LOG_WARNING, "TOS and COS values ignored for websocket transport\n");
995 } else if (!ast_strlen_zero(transport->ca_list_file) || !ast_strlen_zero(transport->ca_list_path) ||
996 !ast_strlen_zero(transport->cert_file) || !ast_strlen_zero(transport->privkey_file)) {
997 ast_log(LOG_WARNING, "TLS certificate values ignored for websocket transport as they are configured in http.conf\n");
998 }
999 res = PJ_SUCCESS;
1000 }
1001
1002 if (res != PJ_SUCCESS) {
1003 char msg[PJ_ERR_MSG_SIZE];
1004
1005 pj_strerror(res, msg, sizeof(msg));
1006 ast_log(LOG_ERROR, "Transport '%s' could not be started: %s\n", ast_sorcery_object_get_id(obj), msg);
1007 return -1;
1008 }
1009
1010 copy_state_to_transport(transport);
1011 if (perm_state) {
1012 ao2_unlink_flags(states, perm_state, OBJ_NOLOCK);
1013 }
1014 ao2_link_flags(states, temp_state, OBJ_NOLOCK);
1015
1016 return 0;
1017}
#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:1260
#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:1182
pjsip_endpoint * ast_sip_get_pjsip_endpoint(void)
Get a pointer to the PJSIP endpoint.
Definition res_pjsip.c:514
#define AST_SIP_X_AST_TXP_LEN
Definition res_pjsip.h:1183
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:1869
const ast_string_field password
Definition res_pjsip.h:239
int tcp_keepalive_probe_count
Definition res_pjsip.h:307
unsigned int async_operations
Definition res_pjsip.h:249
const ast_string_field external_media_address
Definition res_pjsip.h:239
int tcp_keepalive_interval_time
Definition res_pjsip.h:305
int tcp_keepalive_idle_time
Definition res_pjsip.h:303
int ast_compare_versions(const char *version1, const char *version2)
Compare 2 major.minor.patch.extra version strings.
Definition utils.c:3158
#define MAX(a, b)
Definition utils.h:254

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

1186{
1187 struct ast_sip_transport *transport = obj;
1188 pj_str_t buf;
1189 int rc;
1191
1192 if (!state) {
1193 return -1;
1194 }
1195
1196 rc = pj_sockaddr_parse(pj_AF_UNSPEC(), 0, pj_cstr(&buf, var->value), &state->host);
1197 if (rc != PJ_SUCCESS) {
1199 }
1200 return rc != PJ_SUCCESS ? -1 : 0;
1201}
#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, remove_temporary_state(), 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 1203 of file config_transport.c.

1204{
1205 const struct ast_sip_transport *transport = obj;
1207
1208 if (!state) {
1209 return -1;
1210 }
1211
1212 if (!(*buf = ast_calloc(MAX_OBJECT_FIELD, sizeof(char)))) {
1213 return -1;
1214 }
1215
1216 /* include port as well as brackets if IPv6 */
1217 pj_sockaddr_print(&state->host, *buf, MAX_OBJECT_FIELD, 1 | 2);
1218
1219 return 0;
1220}

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

1553{
1554 struct ast_sip_transport *transport = obj;
1555 int error = 0;
1557
1558 if (!state) {
1559 return -1;
1560 }
1561
1562 if (ast_strlen_zero(var->value)) {
1563 ast_free_ha(state->localnet);
1564 state->localnet = NULL;
1565 return 0;
1566 }
1567
1568 /* We use only the ast_apply_ha() which defaults to ALLOW
1569 * ("permit"), so we add DENY rules. */
1570 if (!(state->localnet = ast_append_ha("deny", var->value, state->localnet, &error))) {
1572 return -1;
1573 }
1574
1575 return error;
1576}
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,...)

References ao2_cleanup, ast_append_ha(), ast_free_ha(), ast_strlen_zero(), error(), find_or_create_temporary_state(), NULL, RAII_VAR, remove_temporary_state(), 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 1129 of file config_transport.c.

1130{
1131 struct ast_sip_transport *transport = obj;
1133
1134 if (!state) {
1135 return -1;
1136 }
1137
1138 if (!strcasecmp(var->value, "flow")) {
1139 transport->flow = 1;
1140 } else {
1141 if (!strcasecmp(var->value, "udp")) {
1142 transport->type = AST_TRANSPORT_UDP;
1143 } else if (!strcasecmp(var->value, "tcp")) {
1144 transport->type = AST_TRANSPORT_TCP;
1145 } else if (!strcasecmp(var->value, "tls")) {
1146 transport->type = AST_TRANSPORT_TLS;
1147 } else if (!strcasecmp(var->value, "ws")) {
1148 transport->type = AST_TRANSPORT_WS;
1149 } else if (!strcasecmp(var->value, "wss")) {
1150 transport->type = AST_TRANSPORT_WSS;
1151 } else {
1153 return -1;
1154 }
1155 transport->flow = 0;
1156 }
1157
1158 state->type = transport->type;
1159
1160 return 0;
1161}

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, remove_temporary_state(), 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 1171 of file config_transport.c.

1172{
1173 const struct ast_sip_transport *transport = obj;
1174
1175 if (transport->flow) {
1176 *buf = ast_strdup("flow");
1177 } else if (ARRAY_IN_BOUNDS(transport->type, transport_types)) {
1178 *buf = ast_strdup(transport_types[transport->type]);
1179 }
1180
1181 return 0;
1182}

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

149{
150 const struct ast_sip_transport_state *object_left = obj;
151 const struct ast_sip_transport_state *object_right = arg;
152 const char *right_key = arg;
153 int cmp;
154
155 switch (flags & OBJ_SEARCH_MASK) {
157 right_key = object_right->id;
158 /* Fall through */
159 case OBJ_SEARCH_KEY:
160 cmp = strcmp(object_left->id, right_key);
161 break;
163 /* Not supported by container. */
164 ast_assert(0);
165 return 0;
166 default:
167 cmp = 0;
168 break;
169 }
170 if (cmp) {
171 return 0;
172 }
173 return CMP_MATCH;
174}

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

128{
129 const struct ast_sip_transport_state *object;
130 const char *key;
131
132 switch (flags & OBJ_SEARCH_MASK) {
133 case OBJ_SEARCH_KEY:
134 key = obj;
135 break;
137 object = obj;
138 key = object->id;
139 break;
140 default:
141 ast_assert(0);
142 return 0;
143 }
144 return ast_str_hash(key);
145}

References ast_assert, ast_str_hash(), ast_sip_transport_state::id, 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 1020 of file config_transport.c.

1021{
1022 struct ast_sip_transport *transport = obj;
1024
1026
1027 return 0;
1028}

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

1224{
1225 struct ast_sip_transport *transport = obj;
1227
1228 if (!state) {
1229 return -1;
1230 }
1231
1232 if (!strcasecmp(var->name, "verify_server")) {
1233 state->verify_server = ast_true(var->value);
1234 } else if (!strcasecmp(var->name, "verify_client")) {
1235 state->tls.verify_client = ast_true(var->value) ? PJ_TRUE : PJ_FALSE;
1236 } else if (!strcasecmp(var->name, "require_client_cert")) {
1237 state->tls.require_client_cert = ast_true(var->value) ? PJ_TRUE : PJ_FALSE;
1238 } else if (!strcasecmp(var->name, "allow_wildcard_certs")) {
1239 state->allow_wildcard_certs = ast_true(var->value);
1240 } else {
1242 return -1;
1243 }
1244
1245 return 0;
1246}
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:2233

References ao2_cleanup, ast_true(), find_or_create_temporary_state(), RAII_VAR, remove_temporary_state(), 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 1031 of file config_transport.c.

1032{
1033 struct ast_sip_transport *transport = obj;
1035
1036 if (!state) {
1037 return -1;
1038 }
1039
1040 if (ast_strlen_zero(var->value)) {
1041 /* Ignore empty options */
1042 return 0;
1043 }
1044
1045 if (!ast_file_is_readable(var->value)) {
1046 ast_log(LOG_ERROR, "Transport: %s: %s %s is either missing or not readable\n",
1047 ast_sorcery_object_get_id(obj), var->name, var->value);
1049 return -1;
1050 }
1051
1052 if (!strcasecmp(var->name, "ca_list_file")) {
1053 state->tls.ca_list_file = pj_str((char*)var->value);
1054 ast_string_field_set(transport, ca_list_file, var->value);
1055 } else if (!strcasecmp(var->name, "ca_list_path")) {
1056#ifdef HAVE_PJ_SSL_CERT_LOAD_FROM_FILES2
1057 state->tls.ca_list_path = pj_str((char *)var->value);
1058 ast_string_field_set(transport, ca_list_path, var->value);
1059#else
1060 ast_log(LOG_WARNING, "Asterisk has been built against a version of pjproject that does not "
1061 "support the 'ca_list_path' option. Please upgrade to version 2.4 or later.\n");
1062#endif
1063 } else if (!strcasecmp(var->name, "cert_file")) {
1064 state->tls.cert_file = pj_str((char *)var->value);
1065 ast_string_field_set(transport, cert_file, var->value);
1066#ifdef HAVE_PJSIP_TLS_TRANSPORT_RESTART
1067 if (stat(var->value, &state->cert_file_stat)) {
1068 ast_log(LOG_ERROR, "Failed to stat certificate file '%s' for transport '%s' due to '%s'\n",
1069 var->value, ast_sorcery_object_get_id(obj), strerror(errno));
1071 return -1;
1072 }
1074#endif
1075 } else if (!strcasecmp(var->name, "priv_key_file")) {
1076 state->tls.privkey_file = pj_str((char *)var->value);
1077 ast_string_field_set(transport, privkey_file, var->value);
1078#ifdef HAVE_PJSIP_TLS_TRANSPORT_RESTART
1079 if (stat(var->value, &state->privkey_file_stat)) {
1080 ast_log(LOG_ERROR, "Failed to stat private key file '%s' for transport '%s' due to '%s'\n",
1081 var->value, ast_sorcery_object_get_id(obj), strerror(errno));
1083 return -1;
1084 }
1086#endif
1087 }
1088
1089 return 0;
1090}
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:2448
#define ast_string_field_set(x, field, data)
Set a field to a simple string value.
int ast_file_is_readable(const char *filename)
Test that a file exists and is readable by the effective user.
Definition utils.c:3141

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, remove_temporary_state(), 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 1305 of file config_transport.c.

1306{
1307 struct ast_sip_transport *transport = obj;
1309
1310 if (!state) {
1311 return -1;
1312 }
1313
1314 if (ast_strlen_zero(var->value) || !strcasecmp(var->value, "default")) {
1315 state->tls.method = PJSIP_SSL_DEFAULT_METHOD;
1316 } else if (!strcasecmp(var->value, "unspecified")) {
1317 state->tls.method = PJSIP_SSL_UNSPECIFIED_METHOD;
1318 } else if (!strcasecmp(var->value, "tlsv1")) {
1319 state->tls.method = PJSIP_TLSV1_METHOD;
1320#ifdef HAVE_PJSIP_TLS_1_1
1321 } else if (!strcasecmp(var->value, "tlsv1_1")) {
1322 state->tls.method = PJSIP_TLSV1_1_METHOD;
1323#endif
1324#ifdef HAVE_PJSIP_TLS_1_2
1325 } else if (!strcasecmp(var->value, "tlsv1_2")) {
1326 state->tls.method = PJSIP_TLSV1_2_METHOD;
1327#endif
1328#ifdef HAVE_PJSIP_TLS_1_3
1329 } else if (!strcasecmp(var->value, "tlsv1_3")) {
1330 state->tls.method = PJSIP_TLSV1_3_METHOD;
1331#endif
1332 } else if (!strcasecmp(var->value, "sslv2")) {
1333 state->tls.method = PJSIP_SSLV2_METHOD;
1334 } else if (!strcasecmp(var->value, "sslv3")) {
1335 state->tls.method = PJSIP_SSLV3_METHOD;
1336 } else if (!strcasecmp(var->value, "sslv23")) {
1337 state->tls.method = PJSIP_SSLV23_METHOD;
1338 } else {
1340 return -1;
1341 }
1342
1343 return 0;
1344}

References ao2_cleanup, ast_strlen_zero(), find_or_create_temporary_state(), RAII_VAR, remove_temporary_state(), 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 1626 of file config_transport.c.

1627{
1628 struct ast_sip_transport *transport = obj;
1629 unsigned int value;
1630
1631 if (ast_str2tos(var->value, &value)) {
1632 ast_log(LOG_ERROR, "Error configuring transport '%s' - Could not "
1633 "interpret 'tos' value '%s'\n",
1634 ast_sorcery_object_get_id(transport), var->value);
1636 return -1;
1637 }
1638
1639 if (value % 4) {
1640 value = value >> 2;
1641 value = value << 2;
1643 "transport '%s' - 'tos' value '%s' uses bits that are "
1644 "discarded when converted to DSCP. Using equivalent %u instead.\n",
1645 ast_sorcery_object_get_id(transport), var->value, value);
1646 }
1647
1648 transport->tos = value;
1649 return 0;
1650}
int ast_str2tos(const char *value, unsigned int *tos)
Convert a string to the appropriate TOS value.
Definition acl.c:983
int value
Definition syslog.c:37

References ast_log, ast_sorcery_object_get_id(), ast_str2tos(), LOG_ERROR, LOG_WARNING, remove_temporary_state(), 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 1262 of file config_transport.c.

1263{
1264 const struct ast_sip_transport *transport = obj;
1266
1267 if (!state) {
1268 return -1;
1269 }
1270
1271 *buf = ast_strdup(AST_YESNO(state->tls.verify_client));
1272
1273 return 0;
1274}

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

1249{
1250 const struct ast_sip_transport *transport = obj;
1252
1253 if (!state) {
1254 return -1;
1255 }
1256
1257 *buf = ast_strdup(AST_YESNO(state->verify_server));
1258
1259 return 0;
1260}

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

Definition at line 1750 of file config_transport.c.

1750 {
1751#if defined(PJ_HAS_SSL_SOCK) && PJ_HAS_SSL_SOCK != 0
1752 AST_CLI_DEFINE(handle_pjsip_list_ciphers, "List available OpenSSL cipher names"),
1753#endif
1754 AST_CLI_DEFINE(ast_sip_cli_traverse_objects, "List PJSIP Transports",
1755 .command = "pjsip list transports",
1756 .usage = "Usage: pjsip list transports [ like <pattern> ]\n"
1757 " List the configured PJSIP Transports\n"
1758 " Optional regular expression pattern is used to filter the list.\n"),
1759 AST_CLI_DEFINE(ast_sip_cli_traverse_objects, "Show PJSIP Transports",
1760 .command = "pjsip show transports",
1761 .usage = "Usage: pjsip show transports [ like <pattern> ]\n"
1762 " Show the configured PJSIP Transport\n"
1763 " Optional regular expression pattern is used to filter the list.\n"),
1764 AST_CLI_DEFINE(ast_sip_cli_traverse_objects, "Show PJSIP Transport",
1765 .command = "pjsip show transport",
1766 .usage = "Usage: pjsip show transport <id>\n"
1767 " Show the configured PJSIP Transport\n"),
1768};
#define AST_CLI_DEFINE(fn, txt,...)
Definition cli.h:197
char * ast_sip_cli_traverse_objects(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
Definition pjsip_cli.c:109
char * usage
Definition utils/frame.c:37

Referenced by ast_sip_destroy_sorcery_transport(), and ast_sip_initialize_sorcery_transport().

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

216 {
218};

Referenced by ast_sip_destroy_sorcery_transport(), and ast_sip_initialize_sorcery_transport().

◆ tls_method_map

const char* tls_method_map[]
static

Definition at line 1346 of file config_transport.c.

1346 {
1347 [PJSIP_SSL_UNSPECIFIED_METHOD] = "unspecified",
1348 [PJSIP_TLSV1_METHOD] = "tlsv1",
1349#ifdef HAVE_PJSIP_TLS_1_1
1350 [PJSIP_TLSV1_1_METHOD] = "tlsv1_1",
1351#endif
1352#ifdef HAVE_PJSIP_TLS_1_2
1353 [PJSIP_TLSV1_2_METHOD] = "tlsv1_2",
1354#endif
1355#ifdef HAVE_PJSIP_TLS_1_3
1356 [PJSIP_TLSV1_3_METHOD] = "tlsv1_3",
1357#endif
1358 [PJSIP_SSLV2_METHOD] = "sslv2",
1359 [PJSIP_SSLV3_METHOD] = "sslv3",
1360 [PJSIP_SSLV23_METHOD] = "sslv23",
1361};

Referenced by tls_method_to_str().

◆ transport_states

struct ao2_container* transport_states
static

◆ transport_types

const char* transport_types[]
static

Definition at line 1163 of file config_transport.c.

1163 {
1164 [AST_TRANSPORT_UDP] = "udp",
1165 [AST_TRANSPORT_TCP] = "tcp",
1166 [AST_TRANSPORT_TLS] = "tls",
1167 [AST_TRANSPORT_WS] = "ws",
1168 [AST_TRANSPORT_WSS] = "wss"
1169};

Referenced by cli_print_body(), and transport_protocol_to_str().