Asterisk - The Open Source Telephony Project GIT-master-2de1a68
config_transport.c
Go to the documentation of this file.
1/*
2 * Asterisk -- An open source telephony toolkit.
3 *
4 * Copyright (C) 2013, Digium, Inc.
5 *
6 * Joshua Colp <jcolp@digium.com>
7 *
8 * See http://www.asterisk.org for more information about
9 * the Asterisk project. Please do not directly contact
10 * any of the maintainers of this project for assistance;
11 * the project provides a web site, mailing lists and IRC
12 * channels for your use.
13 *
14 * This program is free software, distributed under the terms of
15 * the GNU General Public License Version 2. See the LICENSE file
16 * at the top of the source tree.
17 */
18
19#include "asterisk.h"
20
21#include <math.h>
22#include <pjsip.h>
23#include <pjlib.h>
24
25#include "asterisk/res_pjsip.h"
27#include "asterisk/logger.h"
28#include "asterisk/astobj2.h"
29#include "asterisk/sorcery.h"
30#include "asterisk/acl.h"
31#include "asterisk/utils.h"
33/* We're only using a #define from http_websocket.h, no OPTIONAL_API symbols are used. */
35
36#define MAX_POINTER_STRING 33
37
38/*! \brief Default number of state container buckets */
39#define DEFAULT_STATE_BUCKETS 53
41
43 char *id;
44 /*! Set if there was a change detected */
46 /*! \brief Transport configuration object */
48 /*! \brief Transport state information */
50};
51
52static void temp_state_store_cleanup(void *data)
53{
54 struct ast_sip_transport_state **temp_state = data;
55
56 ao2_cleanup(*temp_state);
57 ast_free(data);
58}
59
61
62/*! \brief hashing function for state objects */
63static int internal_state_hash(const void *obj, const int flags)
64{
65 const struct internal_state *object;
66 const char *key;
67
68 switch (flags & OBJ_SEARCH_MASK) {
69 case OBJ_SEARCH_KEY:
70 key = obj;
71 break;
73 object = obj;
74 key = object->id;
75 break;
76 default:
77 ast_assert(0);
78 return 0;
79 }
80 return ast_str_hash(key);
81}
82
83/*! \brief comparator function for state objects */
84static int internal_state_cmp(void *obj, void *arg, int flags)
85{
86 const struct internal_state *object_left = obj;
87 const struct internal_state *object_right = arg;
88 const char *right_key = arg;
89 int cmp;
90
91 switch (flags & OBJ_SEARCH_MASK) {
93 right_key = object_right->id;
94 /* Fall through */
95 case OBJ_SEARCH_KEY:
96 cmp = strcmp(object_left->id, right_key);
97 break;
99 /* Not supported by container. */
100 ast_assert(0);
101 return 0;
102 default:
103 cmp = 0;
104 break;
105 }
106 if (cmp) {
107 return 0;
108 }
109 return CMP_MATCH;
110}
111
112/*! \brief hashing function for state objects */
113static int transport_state_hash(const void *obj, const int flags)
114{
115 const struct ast_sip_transport_state *object;
116 const char *key;
117
118 switch (flags & OBJ_SEARCH_MASK) {
119 case OBJ_SEARCH_KEY:
120 key = obj;
121 break;
123 object = obj;
124 key = object->id;
125 break;
126 default:
127 ast_assert(0);
128 return 0;
129 }
130 return ast_str_hash(key);
131}
132
133/*! \brief comparator function for state objects */
134static int transport_state_cmp(void *obj, void *arg, int flags)
135{
136 const struct ast_sip_transport_state *object_left = obj;
137 const struct ast_sip_transport_state *object_right = arg;
138 const char *right_key = arg;
139 int cmp;
140
141 switch (flags & OBJ_SEARCH_MASK) {
143 right_key = object_right->id;
144 /* Fall through */
145 case OBJ_SEARCH_KEY:
146 cmp = strcmp(object_left->id, right_key);
147 break;
149 /* Not supported by container. */
150 ast_assert(0);
151 return 0;
152 default:
153 cmp = 0;
154 break;
155 }
156 if (cmp) {
157 return 0;
158 }
159 return CMP_MATCH;
160}
161
163 struct ast_str **buf)
164{
166}
167
168static int format_ami_endpoint_transport(const struct ast_sip_endpoint *endpoint,
169 struct ast_sip_ami *ami)
170{
171 RAII_VAR(struct ast_str *, buf, NULL, ast_free);
173
174 if (ast_strlen_zero(endpoint->transport)) {
175 return 0;
176 }
177
178 buf = ast_sip_create_ami_event("TransportDetail", ami);
179 if (!buf) {
180 return -1;
181 }
182
184 endpoint->transport);
185 if (!transport) {
186 astman_send_error_va(ami->s, ami->m, "Unable to retrieve "
187 "transport %s\n", endpoint->transport);
188 return -1;
189 }
190
192
193 ast_str_append(&buf, 0, "EndpointName: %s\r\n",
194 ast_sorcery_object_get_id(endpoint));
195
196 astman_append(ami->s, "%s\r\n", ast_str_buffer(buf));
197 ami->count++;
198
199 return 0;
200}
201
204};
205
206int ast_sip_transport_state_set_transport(const char *transport_name, pjsip_transport *transport)
207{
208 struct ast_sip_transport_state *transport_state;
209
210 /* To make it easier on callers we allow an empty transport name */
211 if (ast_strlen_zero(transport_name)) {
212 return 0;
213 }
214
215 transport_state = ast_sip_get_transport_state(transport_name);
216 if (!transport_state) {
217 return -1;
218 }
219
220 if (!transport_state->flow) {
221 ao2_ref(transport_state, -1);
222 return 0;
223 }
224
225 ao2_lock(transport_state);
226 if (transport_state->transport != transport) {
227 if (transport_state->transport) {
228 pjsip_transport_dec_ref(transport_state->transport);
229 }
230 transport_state->transport = transport;
231 if (transport_state->transport) {
232 pjsip_transport_add_ref(transport_state->transport);
233 }
234 }
235 ao2_unlock(transport_state);
236
237 ao2_ref(transport_state, -1);
238
239 return 0;
240}
241
242int ast_sip_transport_state_set_preferred_identity(const char *transport_name, const char *identity)
243{
244 struct ast_sip_transport_state *transport_state;
245
246 if (ast_strlen_zero(transport_name)) {
247 return 0;
248 }
249
250 transport_state = ast_sip_get_transport_state(transport_name);
251 if (!transport_state) {
252 return -1;
253 }
254
255 if (!transport_state->flow) {
256 ao2_ref(transport_state, -1);
257 return 0;
258 }
259
260 ao2_lock(transport_state);
261 ast_free(transport_state->preferred_identity);
262 transport_state->preferred_identity = ast_strdup(identity);
263 ao2_unlock(transport_state);
264
265 ao2_ref(transport_state, -1);
266
267 return 0;
268}
269
271{
272 struct ast_sip_transport_state *transport_state;
273
274 if (ast_strlen_zero(transport_name)) {
276 return 0;
277 }
278
279 transport_state = ast_sip_get_transport_state(transport_name);
280 if (!transport_state) {
282 return -1;
283 }
284
285 if (!transport_state->flow) {
286 ao2_ref(transport_state, -1);
288 return 0;
289 }
290
291 ao2_lock(transport_state);
293 transport_state->service_routes = service_routes;
294 ao2_unlock(transport_state);
295
296 ao2_ref(transport_state, -1);
297
298 return 0;
299}
300
301void ast_sip_message_apply_transport(const char *transport_name, pjsip_tx_data *tdata)
302{
303 struct ast_sip_transport_state *transport_state;
304
305 if (ast_strlen_zero(transport_name)) {
306 return;
307 }
308
309 /* We only currently care about requests that are of the INVITE, CANCEL, or OPTIONS
310 * type but in the future we could support other messages.
311 */
312 if (tdata->msg->type != PJSIP_REQUEST_MSG ||
313 (pjsip_method_cmp(&tdata->msg->line.req.method, &pjsip_invite_method) &&
314 pjsip_method_cmp(&tdata->msg->line.req.method, &pjsip_cancel_method) &&
315 pjsip_method_cmp(&tdata->msg->line.req.method, &pjsip_options_method))) {
316 return;
317 }
318
319 transport_state = ast_sip_get_transport_state(transport_name);
320 if (!transport_state) {
321 return;
322 }
323
324 if (!transport_state->flow) {
325 ao2_ref(transport_state, -1);
326 return;
327 }
328
329 ao2_lock(transport_state);
330
331 /* If a Preferred Identity has been set then add it to the request */
332 if (transport_state->preferred_identity) {
333 ast_sip_add_header(tdata, "P-Preferred-Identity", transport_state->preferred_identity);
334 }
335
336 /* If Service Routes have been set then add them to the request */
337 if (transport_state->service_routes) {
338 int idx;
339
340 for (idx = 0; idx < AST_VECTOR_SIZE(transport_state->service_routes); ++idx) {
341 char *service_route = AST_VECTOR_GET(transport_state->service_routes, idx);
342
343 ast_sip_add_header(tdata, "Route", service_route);
344 }
345 }
346
347 ao2_unlock(transport_state);
348
349 ao2_ref(transport_state, -1);
350}
351
353{
354 struct ast_sip_service_route_vector *service_routes;
355
356 service_routes = ast_calloc(1, sizeof(*service_routes));
357 if (!service_routes) {
358 return NULL;
359 }
360
361 AST_VECTOR_INIT(service_routes, 0);
362
363 return service_routes;
364}
365
367{
368 if (!service_routes) {
369 return;
370 }
371
372 AST_VECTOR_CALLBACK_VOID(service_routes, ast_free);
373 ast_free(service_routes);
374}
375
376static void set_qos(struct ast_sip_transport *transport, pj_qos_params *qos)
377{
378 int tos_as_dscp = transport->tos >> 2;
379
380 if (transport->tos) {
381 qos->flags |= PJ_QOS_PARAM_HAS_DSCP;
382 qos->dscp_val = tos_as_dscp;
383 }
384 if (transport->cos) {
385 qos->flags |= PJ_QOS_PARAM_HAS_SO_PRIO;
386 qos->so_prio = transport->cos;
387 }
388}
389
390/*! \brief Destructor for transport */
391static void sip_transport_destroy(void *obj)
392{
393 struct ast_sip_transport *transport = obj;
394
396}
397
398/*! \brief Allocator for transport */
399static void *sip_transport_alloc(const char *name)
400{
401 struct ast_sip_transport *transport = ast_sorcery_generic_alloc(sizeof(*transport), sip_transport_destroy);
402
403 if (!transport) {
404 return NULL;
405 }
406
407 if (ast_string_field_init(transport, 256)) {
408 ao2_cleanup(transport);
409 return NULL;
410 }
411
412 return transport;
413}
414
415static int destroy_sip_transport_state(void *data)
416{
417 struct ast_sip_transport_state *transport_state = data;
418
419 ast_free(transport_state->id);
420 ast_free_ha(transport_state->localnet);
421
422 if (transport_state->external_signaling_address_refresher) {
424 }
425 if (transport_state->external_media_address_refresher) {
427 }
428 if (transport_state->transport) {
429 pjsip_transport_shutdown(transport_state->transport);
430 }
431
432 return 0;
433}
434
435/*! \brief Destructor for ast_sip_transport state information */
436static void sip_transport_state_destroy(void *obj)
437{
438 struct ast_sip_transport_state *state = obj;
439
441}
442
443/*! \brief Destructor for ast_sip_transport state information */
444static void internal_state_destroy(void *obj)
445{
446 struct internal_state *state = obj;
447
448 ast_free(state->id);
449 ao2_cleanup(state->transport);
450 ao2_cleanup(state->state);
451}
452
454{
455 const char *key = ast_sorcery_object_get_id(transport);
456
458}
459
461{
462 struct internal_state *state;
463 struct ast_sip_transport_state *trans_state;
464
466 if (!state) {
467 return NULL;
468 }
469 trans_state = ao2_bump(state->state);
470 ao2_ref(state, -1);
471
472 return trans_state;
473}
474
476{
478
480 if (!state) {
481 return -1;
482 }
483
485 *state = NULL;
486 return 0;
487}
488
490{
492
494 if (state && *state) {
495 ao2_ref(*state, +1);
496 return *state;
497 }
498
499 return NULL;
500}
501
503{
505
507 if (!internal_state) {
508 return NULL;
509 }
510
512 if (!internal_state->id) {
514 return NULL;
515 }
516
517 /* We're transferring the reference from find_temporary_state */
519 if (!internal_state->state) {
521 return NULL;
522 }
526
527 return internal_state;
528}
529
530/*!
531 * \internal
532 * \brief Should only be called by the individual field handlers
533 */
535{
537 struct ast_sip_transport_state *new_state;
538
539 if ((new_state = find_temporary_state(transport))) {
540 return new_state;
541 }
542
544 if (!state || *state) {
545 return NULL;
546 }
547
548 new_state = ao2_alloc(sizeof(**state), sip_transport_state_destroy);
549 if (!new_state) {
550 return NULL;
551 }
553 new_state->type = transport->type;
554
555 pjsip_tls_setting_default(&new_state->tls);
556#ifdef HAVE_PJSIP_TLS_TRANSPORT_PROTO
557 /* proto must be forced to 0 to enable all protocols otherwise only TLS will work */
558 new_state->tls.proto = 0;
559#endif
560 new_state->tls.ciphers = new_state->ciphers;
561
562 ao2_ref(new_state, +1);
563 *state = new_state;
564
565 return new_state;
566}
567
569{
570 ast_assert(transport && transport->state);
571
572 memcpy(&transport->host, &transport->state->host, sizeof(transport->host));
573 memcpy(&transport->tls, &transport->state->tls, sizeof(transport->tls));
574 memcpy(&transport->ciphers, &transport->state->ciphers, sizeof(transport->ciphers));
575 transport->localnet = transport->state->localnet;
576 transport->external_address_refresher = transport->state->external_signaling_address_refresher;
577 memcpy(&transport->external_address, &transport->state->external_signaling_address, sizeof(transport->external_signaling_address));
578}
579
580#ifdef HAVE_PJSIP_TLS_TRANSPORT_RESTART
581static int file_stat_cmp(const struct stat *old_stat, const struct stat *new_stat)
582{
583 return old_stat->st_size != new_stat->st_size
584 || old_stat->st_mtime != new_stat->st_mtime
585#if defined(HAVE_STRUCT_STAT_ST_MTIM)
586 || old_stat->st_mtim.tv_nsec != new_stat->st_mtim.tv_nsec
587#elif defined(HAVE_STRUCT_STAT_ST_MTIMENSEC)
588 || old_stat->st_mtimensec != new_stat->st_mtimensec
589#elif defined(HAVE_STRUCT_STAT_ST_MTIMESPEC)
590 || old_stat->st_mtimespec.tv_nsec != new_stat->st_mtimespec.tv_nsec
591#endif
592 ;
593}
594#endif
595
597{
598 if (a->type != b->type) {
599 return -1;
600 }
601
602 if (pj_sockaddr_cmp(&a->host, &b->host)) {
603 return -1;
604 }
605
606 if ((a->localnet || b->localnet)
607 && ((!a->localnet != !b->localnet)
608 || ast_sockaddr_cmp(&a->localnet->addr, &b->localnet->addr)
609 || ast_sockaddr_cmp(&a->localnet->netmask, &b->localnet->netmask)))
610 {
611 return -1;
612 }
613
614 if (ast_sockaddr_cmp(&a->external_signaling_address, &b->external_signaling_address)) {
615 return -1;
616 }
617
618 if (ast_sockaddr_cmp(&a->external_media_address, &b->external_media_address)) {
619 return -1;
620 }
621
622 if (a->tls.method != b->tls.method
623 || a->tls.ciphers_num != b->tls.ciphers_num
624#ifdef HAVE_PJSIP_TLS_TRANSPORT_PROTO
625 || a->tls.proto != b->tls.proto
626#endif
627 || a->tls.verify_client != b->tls.verify_client
628 || a->tls.verify_server != b->tls.verify_server
629 || a->tls.require_client_cert != b->tls.require_client_cert) {
630 return -1;
631 }
632
633 if (memcmp(a->ciphers, b->ciphers, sizeof(pj_ssl_cipher) * fmax(a->tls.ciphers_num, b->tls.ciphers_num))) {
634 return -1;
635 }
636
637#ifdef HAVE_PJSIP_TLS_TRANSPORT_RESTART
638 if (file_stat_cmp(&a->cert_file_stat, &b->cert_file_stat) || file_stat_cmp(&a->privkey_file_stat, &b->privkey_file_stat)) {
639 return -1;
640 }
641#endif
642
643 return 0;
644}
645
646static void states_cleanup(void *states)
647{
648 if (states) {
649 ao2_unlock(states);
650 }
651}
652
653/*! \brief Apply handler for transports */
654static int transport_apply(const struct ast_sorcery *sorcery, void *obj)
655{
656 struct ast_sip_transport *transport = obj;
657 const char *transport_id = ast_sorcery_object_get_id(obj);
659 RAII_VAR(struct internal_state *, temp_state, NULL, ao2_cleanup);
660 RAII_VAR(struct internal_state *, perm_state, NULL, ao2_cleanup);
661 RAII_VAR(struct ast_variable *, changes, NULL, ast_variables_destroy);
662 pj_status_t res = -1;
663 int i;
664#define BIND_TRIES 3
665#define BIND_DELAY_US 100000
666
667 if (!states) {
668 return -1;
669 }
670
671 /*
672 * transport_apply gets called for EVERY retrieval of a transport when using realtime.
673 * We need to prevent multiple threads from trying to mess with underlying transports
674 * at the same time. The container is the only thing we have to lock on.
675 */
676 ao2_wrlock(states);
677
678 temp_state = internal_state_alloc(transport);
679 if (!temp_state) {
680 ast_log(LOG_ERROR, "Transport '%s' failed to allocate memory\n", transport_id);
681 return -1;
682 }
683
684 if (transport->async_operations != 1) {
685 ast_log(LOG_WARNING, "The async_operations setting on transport '%s' has been set to '%d'. The setting can no longer be set and is always 1.\n",
686 transport_id, transport->async_operations);
687 transport->async_operations = 1;
688 }
689
690 perm_state = find_internal_state_by_transport(transport);
691 if (perm_state) {
692 ast_sorcery_diff(sorcery, perm_state->transport, transport, &changes);
693 if (!changes && !has_state_changed(perm_state->state, temp_state->state)) {
694 /* In case someone is using the deprecated fields, reset them */
695 transport->state = perm_state->state;
696 copy_state_to_transport(transport);
697 ao2_replace(perm_state->transport, transport);
698 return 0;
699 }
700
701 /* If we aren't allowed to reload then we copy values that can't be changed from perm_state */
702 if (!transport->allow_reload) {
703 memcpy(&temp_state->state->host, &perm_state->state->host, sizeof(temp_state->state->host));
704 memcpy(&temp_state->state->tls, &perm_state->state->tls, sizeof(temp_state->state->tls));
705 memcpy(&temp_state->state->ciphers, &perm_state->state->ciphers, sizeof(temp_state->state->ciphers));
706 }
707 }
708
709 if (!transport->flow && (!perm_state || transport->allow_reload)) {
710 if (temp_state->state->host.addr.sa_family != PJ_AF_INET && temp_state->state->host.addr.sa_family != PJ_AF_INET6) {
711 ast_log(LOG_ERROR, "Transport '%s' could not be started as binding not specified\n", transport_id);
712 return -1;
713 }
714
715 /* Set default port if not present */
716 if (!pj_sockaddr_get_port(&temp_state->state->host)) {
717 pj_sockaddr_set_port(&temp_state->state->host, (transport->type == AST_TRANSPORT_TLS) ? 5061 : 5060);
718 }
719 }
720
721 /* Now that we know what address family we can set up a dnsmgr refresh for the external addresses if present */
723 if (temp_state->state->host.addr.sa_family == pj_AF_INET()) {
724 temp_state->state->external_signaling_address.ss.ss_family = AF_INET;
725 } else if (temp_state->state->host.addr.sa_family == pj_AF_INET6()) {
726 temp_state->state->external_signaling_address.ss.ss_family = AF_INET6;
727 } else {
728 ast_log(LOG_ERROR, "Unknown address family for transport '%s', could not get external signaling address\n",
729 transport_id);
730 return -1;
731 }
732
733 if (ast_dnsmgr_lookup(transport->external_signaling_address, &temp_state->state->external_signaling_address, &temp_state->state->external_signaling_address_refresher, NULL) < 0) {
734 ast_log(LOG_ERROR, "Could not create dnsmgr for external signaling address on '%s'\n", transport_id);
735 return -1;
736 }
737 }
738
739 if (!ast_strlen_zero(transport->external_media_address)) {
740 if (temp_state->state->host.addr.sa_family == pj_AF_INET()) {
741 temp_state->state->external_media_address.ss.ss_family = AF_INET;
742 } else if (temp_state->state->host.addr.sa_family == pj_AF_INET6()) {
743 temp_state->state->external_media_address.ss.ss_family = AF_INET6;
744 } else {
745 ast_log(LOG_ERROR, "Unknown address family for transport '%s', could not get external media address\n",
746 transport_id);
747 return -1;
748 }
749
750 if (ast_dnsmgr_lookup(transport->external_media_address, &temp_state->state->external_media_address, &temp_state->state->external_media_address_refresher, NULL) < 0) {
751 ast_log(LOG_ERROR, "Could not create dnsmgr for external media address on '%s'\n", transport_id);
752 return -1;
753 }
754 }
755
756 if (transport->flow) {
757 pj_str_t address;
758
759 ast_debug(1, "Ignoring any bind configuration on transport '%s' as it is a child of another\n",
760 transport_id);
761 pj_sockaddr_parse(pj_AF_UNSPEC(), 0, pj_cstr(&address, "0.0.0.0"), &temp_state->state->host);
762
763 temp_state->state->flow = 1;
764 res = PJ_SUCCESS;
765 } else if (!transport->allow_reload && perm_state) {
766 /* We inherit the transport from perm state, untouched */
767#ifdef HAVE_PJSIP_TLS_TRANSPORT_RESTART
768 ast_log(LOG_NOTICE, "Transport '%s' is not fully reloadable, not reloading: protocol, bind, TLS (everything but certificate and private key if filename is unchanged), TCP, ToS, or CoS options.\n", transport_id);
769 /* If this is a TLS transport and the certificate or private key has changed, then restart the transport so it uses the new one */
770 if (transport->type == AST_TRANSPORT_TLS) {
771 if (strcmp(perm_state->transport->cert_file, temp_state->transport->cert_file) ||
772 strcmp(perm_state->transport->privkey_file, temp_state->transport->privkey_file)) {
773 ast_log(LOG_ERROR, "Unable to restart TLS transport '%s' as certificate or private key filename has changed\n",
774 transport_id);
775 } else if (file_stat_cmp(&perm_state->state->cert_file_stat, &temp_state->state->cert_file_stat) ||
776 file_stat_cmp(&perm_state->state->privkey_file_stat, &temp_state->state->privkey_file_stat)) {
777 if (pjsip_tls_transport_restart(perm_state->state->factory, &perm_state->state->host, NULL) != PJ_SUCCESS) {
778 ast_log(LOG_ERROR, "Failed to restart TLS transport '%s'\n", transport_id);
779 } else {
780 sprintf(perm_state->state->factory->info, "%s", transport_id);
781 }
782 }
783 }
784#else
785 ast_log(LOG_NOTICE, "Transport '%s' is not fully reloadable, not reloading: protocol, bind, TLS, TCP, ToS, or CoS options.\n", transport_id);
786#endif
787 temp_state->state->transport = perm_state->state->transport;
788 perm_state->state->transport = NULL;
789 temp_state->state->factory = perm_state->state->factory;
790 perm_state->state->factory = NULL;
791
792 res = PJ_SUCCESS;
793 } else if (transport->type == AST_TRANSPORT_UDP) {
794
795 for (i = 0; i < BIND_TRIES && res != PJ_SUCCESS; i++) {
796 if (perm_state && perm_state->state && perm_state->state->transport) {
797 pjsip_udp_transport_pause(perm_state->state->transport,
798 PJSIP_UDP_TRANSPORT_DESTROY_SOCKET);
799 usleep(BIND_DELAY_US);
800 }
801
802 if (temp_state->state->host.addr.sa_family == pj_AF_INET()) {
803 res = pjsip_udp_transport_start(ast_sip_get_pjsip_endpoint(),
804 &temp_state->state->host.ipv4, NULL, transport->async_operations,
805 &temp_state->state->transport);
806 } else if (temp_state->state->host.addr.sa_family == pj_AF_INET6()) {
807 res = pjsip_udp_transport_start6(ast_sip_get_pjsip_endpoint(),
808 &temp_state->state->host.ipv6, NULL, transport->async_operations,
809 &temp_state->state->transport);
810 }
811 }
812
813 if (res == PJ_SUCCESS) {
814 temp_state->state->transport->info = pj_pool_alloc(temp_state->state->transport->pool,
815 (AST_SIP_X_AST_TXP_LEN + strlen(transport_id) + 2));
816
817 sprintf(temp_state->state->transport->info, "%s:%s", AST_SIP_X_AST_TXP, transport_id);
818
819 if (transport->tos || transport->cos) {
820 pj_sock_t sock;
821 pj_qos_params qos_params;
822 sock = pjsip_udp_transport_get_socket(temp_state->state->transport);
823 pj_sock_get_qos_params(sock, &qos_params);
824 set_qos(transport, &qos_params);
825 pj_sock_set_qos_params(sock, &qos_params);
826 }
827 }
828 } else if (transport->type == AST_TRANSPORT_TCP) {
829 pjsip_tcp_transport_cfg cfg;
830 static int option = 1;
831
832 pjsip_tcp_transport_cfg_default(&cfg, temp_state->state->host.addr.sa_family);
833 cfg.bind_addr = temp_state->state->host;
834 cfg.async_cnt = transport->async_operations;
835 set_qos(transport, &cfg.qos_params);
836 /* sockopt_params.options is copied to each newly connected socket */
837 cfg.sockopt_params.options[0].level = pj_SOL_TCP();
838 cfg.sockopt_params.options[0].optname = pj_TCP_NODELAY();
839 cfg.sockopt_params.options[0].optval = &option;
840 cfg.sockopt_params.options[0].optlen = sizeof(option);
841 cfg.sockopt_params.cnt = 1;
842
843 for (i = 0; i < BIND_TRIES && res != PJ_SUCCESS; i++) {
844 if (perm_state && perm_state->state && perm_state->state->factory
845 && perm_state->state->factory->destroy) {
846 perm_state->state->factory->destroy(perm_state->state->factory);
847 usleep(BIND_DELAY_US);
848 }
849
850 res = pjsip_tcp_transport_start3(ast_sip_get_pjsip_endpoint(), &cfg,
851 &temp_state->state->factory);
852 }
853 } else if (transport->type == AST_TRANSPORT_TLS) {
854#if defined(PJ_HAS_SSL_SOCK) && PJ_HAS_SSL_SOCK != 0
855 static int option = 1;
856
857 if (transport->async_operations > 1 && ast_compare_versions(pj_get_version(), "2.5.0") < 0) {
858 ast_log(LOG_ERROR, "Transport: %s: When protocol=tls and pjproject version < 2.5.0, async_operations can't be > 1\n",
860 return -1;
861 }
862
863 temp_state->state->tls.password = pj_str((char*)transport->password);
864 set_qos(transport, &temp_state->state->tls.qos_params);
865
866 /* sockopt_params.options is copied to each newly connected socket */
867 temp_state->state->tls.sockopt_params.options[0].level = pj_SOL_TCP();
868 temp_state->state->tls.sockopt_params.options[0].optname = pj_TCP_NODELAY();
869 temp_state->state->tls.sockopt_params.options[0].optval = &option;
870 temp_state->state->tls.sockopt_params.options[0].optlen = sizeof(option);
871 temp_state->state->tls.sockopt_params.cnt = 1;
872
873 for (i = 0; i < BIND_TRIES && res != PJ_SUCCESS; i++) {
874 if (perm_state && perm_state->state && perm_state->state->factory
875 && perm_state->state->factory->destroy) {
876 perm_state->state->factory->destroy(perm_state->state->factory);
877 usleep(BIND_DELAY_US);
878 }
879
880 res = pjsip_tls_transport_start2(ast_sip_get_pjsip_endpoint(), &temp_state->state->tls,
881 &temp_state->state->host, NULL, transport->async_operations,
882 &temp_state->state->factory);
883 }
884
885 if (res == PJ_SUCCESS) {
886 /*
887 * PJSIP uses 100 bytes to store information, and during a restart will repopulate
888 * the field so ensure there is sufficient space - even though we'll revert it after.
889 */
890 temp_state->state->factory->info = pj_pool_alloc(
891 temp_state->state->factory->pool, (MAX(MAX_OBJECT_FIELD, 100) + 1));
892 /*
893 * Store transport id on the factory instance so it can be used
894 * later to look up the transport state.
895 */
896 sprintf(temp_state->state->factory->info, "%s", transport_id);
897 }
898#else
899 ast_log(LOG_ERROR, "Transport: %s: PJSIP has not been compiled with TLS transport support, ensure OpenSSL development packages are installed\n",
901 return -1;
902#endif
903 } else if ((transport->type == AST_TRANSPORT_WS) || (transport->type == AST_TRANSPORT_WSS)) {
904 if (transport->cos || transport->tos) {
905 ast_log(LOG_WARNING, "TOS and COS values ignored for websocket transport\n");
906 } else if (!ast_strlen_zero(transport->ca_list_file) || !ast_strlen_zero(transport->ca_list_path) ||
907 !ast_strlen_zero(transport->cert_file) || !ast_strlen_zero(transport->privkey_file)) {
908 ast_log(LOG_WARNING, "TLS certificate values ignored for websocket transport as they are configured in http.conf\n");
909 }
910 res = PJ_SUCCESS;
911 }
912
913 if (res != PJ_SUCCESS) {
914 char msg[PJ_ERR_MSG_SIZE];
915
916 pj_strerror(res, msg, sizeof(msg));
917 ast_log(LOG_ERROR, "Transport '%s' could not be started: %s\n", ast_sorcery_object_get_id(obj), msg);
918 return -1;
919 }
920
921 copy_state_to_transport(transport);
922 if (perm_state) {
923 ao2_unlink_flags(states, perm_state, OBJ_NOLOCK);
924 }
925 ao2_link_flags(states, temp_state, OBJ_NOLOCK);
926
927 return 0;
928}
929
930/*! \brief Custom handler for type just makes sure the state is created */
931static int transport_state_init(const struct aco_option *opt, struct ast_variable *var, void *obj)
932{
933 struct ast_sip_transport *transport = obj;
935
937
938 return 0;
939}
940
941/*! \brief Custom handler for TLS method setting */
942static int transport_tls_file_handler(const struct aco_option *opt, struct ast_variable *var, void *obj)
943{
944 struct ast_sip_transport *transport = obj;
946
947 if (!state) {
948 return -1;
949 }
950
951 if (ast_strlen_zero(var->value)) {
952 /* Ignore empty options */
953 return 0;
954 }
955
956 if (!ast_file_is_readable(var->value)) {
957 ast_log(LOG_ERROR, "Transport: %s: %s %s is either missing or not readable\n",
958 ast_sorcery_object_get_id(obj), var->name, var->value);
959 return -1;
960 }
961
962 if (!strcasecmp(var->name, "ca_list_file")) {
963 state->tls.ca_list_file = pj_str((char*)var->value);
964 ast_string_field_set(transport, ca_list_file, var->value);
965 } else if (!strcasecmp(var->name, "ca_list_path")) {
966#ifdef HAVE_PJ_SSL_CERT_LOAD_FROM_FILES2
967 state->tls.ca_list_path = pj_str((char *)var->value);
968 ast_string_field_set(transport, ca_list_path, var->value);
969#else
970 ast_log(LOG_WARNING, "Asterisk has been built against a version of pjproject that does not "
971 "support the 'ca_list_path' option. Please upgrade to version 2.4 or later.\n");
972#endif
973 } else if (!strcasecmp(var->name, "cert_file")) {
974 state->tls.cert_file = pj_str((char *)var->value);
975 ast_string_field_set(transport, cert_file, var->value);
976#ifdef HAVE_PJSIP_TLS_TRANSPORT_RESTART
977 if (stat(var->value, &state->cert_file_stat)) {
978 ast_log(LOG_ERROR, "Failed to stat certificate file '%s' for transport '%s' due to '%s'\n",
979 var->value, ast_sorcery_object_get_id(obj), strerror(errno));
980 return -1;
981 }
983#endif
984 } else if (!strcasecmp(var->name, "priv_key_file")) {
985 state->tls.privkey_file = pj_str((char *)var->value);
986 ast_string_field_set(transport, privkey_file, var->value);
987#ifdef HAVE_PJSIP_TLS_TRANSPORT_RESTART
988 if (stat(var->value, &state->privkey_file_stat)) {
989 ast_log(LOG_ERROR, "Failed to stat private key file '%s' for transport '%s' due to '%s'\n",
990 var->value, ast_sorcery_object_get_id(obj), strerror(errno));
991 return -1;
992 }
994#endif
995 }
996
997 return 0;
998}
999
1000static int ca_list_file_to_str(const void *obj, const intptr_t *args, char **buf)
1001{
1002 const struct ast_sip_transport *transport = obj;
1003
1004 *buf = ast_strdup(transport->ca_list_file);
1005
1006 return 0;
1007}
1008
1009static int ca_list_path_to_str(const void *obj, const intptr_t *args, char **buf)
1010{
1011 const struct ast_sip_transport *transport = obj;
1012
1013 *buf = ast_strdup(transport->ca_list_path);
1014
1015 return 0;
1016}
1017
1018static int cert_file_to_str(const void *obj, const intptr_t *args, char **buf)
1019{
1020 const struct ast_sip_transport *transport = obj;
1021
1022 *buf = ast_strdup(transport->cert_file);
1023
1024 return 0;
1025}
1026
1027static int privkey_file_to_str(const void *obj, const intptr_t *args, char **buf)
1028{
1029 const struct ast_sip_transport *transport = obj;
1030
1031 *buf = ast_strdup(transport->privkey_file);
1032
1033 return 0;
1034}
1035
1036/*! \brief Custom handler for turning a string protocol into an enum */
1037static int transport_protocol_handler(const struct aco_option *opt, struct ast_variable *var, void *obj)
1038{
1039 struct ast_sip_transport *transport = obj;
1041
1042 if (!state) {
1043 return -1;
1044 }
1045
1046 if (!strcasecmp(var->value, "flow")) {
1047 transport->flow = 1;
1048 } else {
1049 if (!strcasecmp(var->value, "udp")) {
1050 transport->type = AST_TRANSPORT_UDP;
1051 } else if (!strcasecmp(var->value, "tcp")) {
1052 transport->type = AST_TRANSPORT_TCP;
1053 } else if (!strcasecmp(var->value, "tls")) {
1054 transport->type = AST_TRANSPORT_TLS;
1055 } else if (!strcasecmp(var->value, "ws")) {
1056 transport->type = AST_TRANSPORT_WS;
1057 } else if (!strcasecmp(var->value, "wss")) {
1058 transport->type = AST_TRANSPORT_WSS;
1059 } else {
1060 return -1;
1061 }
1062 transport->flow = 0;
1063 }
1064
1065 state->type = transport->type;
1066
1067 return 0;
1068}
1069
1070static const char *transport_types[] = {
1071 [AST_TRANSPORT_UDP] = "udp",
1072 [AST_TRANSPORT_TCP] = "tcp",
1073 [AST_TRANSPORT_TLS] = "tls",
1074 [AST_TRANSPORT_WS] = "ws",
1075 [AST_TRANSPORT_WSS] = "wss"
1076};
1077
1078static int transport_protocol_to_str(const void *obj, const intptr_t *args, char **buf)
1079{
1080 const struct ast_sip_transport *transport = obj;
1081
1082 if (transport->flow) {
1083 *buf = ast_strdup("flow");
1084 } else if (ARRAY_IN_BOUNDS(transport->type, transport_types)) {
1085 *buf = ast_strdup(transport_types[transport->type]);
1086 }
1087
1088 return 0;
1089}
1090
1091/*! \brief Custom handler for turning a string bind into a pj_sockaddr */
1092static int transport_bind_handler(const struct aco_option *opt, struct ast_variable *var, void *obj)
1093{
1094 struct ast_sip_transport *transport = obj;
1095 pj_str_t buf;
1096 int rc;
1098
1099 if (!state) {
1100 return -1;
1101 }
1102
1103 rc = pj_sockaddr_parse(pj_AF_UNSPEC(), 0, pj_cstr(&buf, var->value), &state->host);
1104
1105 return rc != PJ_SUCCESS ? -1 : 0;
1106}
1107
1108static int transport_bind_to_str(const void *obj, const intptr_t *args, char **buf)
1109{
1110 const struct ast_sip_transport *transport = obj;
1112
1113 if (!state) {
1114 return -1;
1115 }
1116
1117 if (!(*buf = ast_calloc(MAX_OBJECT_FIELD, sizeof(char)))) {
1118 return -1;
1119 }
1120
1121 /* include port as well as brackets if IPv6 */
1122 pj_sockaddr_print(&state->host, *buf, MAX_OBJECT_FIELD, 1 | 2);
1123
1124 return 0;
1125}
1126
1127/*! \brief Custom handler for TLS boolean settings */
1128static int transport_tls_bool_handler(const struct aco_option *opt, struct ast_variable *var, void *obj)
1129{
1130 struct ast_sip_transport *transport = obj;
1132
1133 if (!state) {
1134 return -1;
1135 }
1136
1137 if (!strcasecmp(var->name, "verify_server")) {
1138 state->verify_server = ast_true(var->value);
1139 } else if (!strcasecmp(var->name, "verify_client")) {
1140 state->tls.verify_client = ast_true(var->value) ? PJ_TRUE : PJ_FALSE;
1141 } else if (!strcasecmp(var->name, "require_client_cert")) {
1142 state->tls.require_client_cert = ast_true(var->value) ? PJ_TRUE : PJ_FALSE;
1143 } else if (!strcasecmp(var->name, "allow_wildcard_certs")) {
1144 state->allow_wildcard_certs = ast_true(var->value);
1145 } else {
1146 return -1;
1147 }
1148
1149 return 0;
1150}
1151
1152static int verify_server_to_str(const void *obj, const intptr_t *args, char **buf)
1153{
1154 const struct ast_sip_transport *transport = obj;
1156
1157 if (!state) {
1158 return -1;
1159 }
1160
1161 *buf = ast_strdup(AST_YESNO(state->verify_server));
1162
1163 return 0;
1164}
1165
1166static int verify_client_to_str(const void *obj, const intptr_t *args, char **buf)
1167{
1168 const struct ast_sip_transport *transport = obj;
1170
1171 if (!state) {
1172 return -1;
1173 }
1174
1175 *buf = ast_strdup(AST_YESNO(state->tls.verify_client));
1176
1177 return 0;
1178}
1179
1180static int require_client_cert_to_str(const void *obj, const intptr_t *args, char **buf)
1181{
1182 const struct ast_sip_transport *transport = obj;
1184
1185 if (!state) {
1186 return -1;
1187 }
1188
1189 *buf = ast_strdup(AST_YESNO(state->tls.require_client_cert));
1190
1191 return 0;
1192}
1193
1194static int allow_wildcard_certs_to_str(const void *obj, const intptr_t *args, char **buf)
1195{
1197
1198 if (!state) {
1199 return -1;
1200 }
1201
1202 *buf = ast_strdup(AST_YESNO(state->allow_wildcard_certs));
1203 ao2_ref(state, -1);
1204
1205 return 0;
1206}
1207
1208/*! \brief Custom handler for TLS method setting */
1209static int transport_tls_method_handler(const struct aco_option *opt, struct ast_variable *var, void *obj)
1210{
1211 struct ast_sip_transport *transport = obj;
1213
1214 if (!state) {
1215 return -1;
1216 }
1217
1218 if (ast_strlen_zero(var->value) || !strcasecmp(var->value, "default")) {
1219 state->tls.method = PJSIP_SSL_DEFAULT_METHOD;
1220 } else if (!strcasecmp(var->value, "unspecified")) {
1221 state->tls.method = PJSIP_SSL_UNSPECIFIED_METHOD;
1222 } else if (!strcasecmp(var->value, "tlsv1")) {
1223 state->tls.method = PJSIP_TLSV1_METHOD;
1224#ifdef HAVE_PJSIP_TLS_1_1
1225 } else if (!strcasecmp(var->value, "tlsv1_1")) {
1226 state->tls.method = PJSIP_TLSV1_1_METHOD;
1227#endif
1228#ifdef HAVE_PJSIP_TLS_1_2
1229 } else if (!strcasecmp(var->value, "tlsv1_2")) {
1230 state->tls.method = PJSIP_TLSV1_2_METHOD;
1231#endif
1232#ifdef HAVE_PJSIP_TLS_1_3
1233 } else if (!strcasecmp(var->value, "tlsv1_3")) {
1234 state->tls.method = PJSIP_TLSV1_3_METHOD;
1235#endif
1236 } else if (!strcasecmp(var->value, "sslv2")) {
1237 state->tls.method = PJSIP_SSLV2_METHOD;
1238 } else if (!strcasecmp(var->value, "sslv3")) {
1239 state->tls.method = PJSIP_SSLV3_METHOD;
1240 } else if (!strcasecmp(var->value, "sslv23")) {
1241 state->tls.method = PJSIP_SSLV23_METHOD;
1242 } else {
1243 return -1;
1244 }
1245
1246 return 0;
1247}
1248
1249static const char *tls_method_map[] = {
1250 [PJSIP_SSL_UNSPECIFIED_METHOD] = "unspecified",
1251 [PJSIP_TLSV1_METHOD] = "tlsv1",
1252#ifdef HAVE_PJSIP_TLS_1_1
1253 [PJSIP_TLSV1_1_METHOD] = "tlsv1_1",
1254#endif
1255#ifdef HAVE_PJSIP_TLS_1_2
1256 [PJSIP_TLSV1_2_METHOD] = "tlsv1_2",
1257#endif
1258#ifdef HAVE_PJSIP_TLS_1_3
1259 [PJSIP_TLSV1_3_METHOD] = "tlsv1_3",
1260#endif
1261 [PJSIP_SSLV2_METHOD] = "sslv2",
1262 [PJSIP_SSLV3_METHOD] = "sslv3",
1263 [PJSIP_SSLV23_METHOD] = "sslv23",
1264};
1265
1266static int tls_method_to_str(const void *obj, const intptr_t *args, char **buf)
1267{
1268 const struct ast_sip_transport *transport = obj;
1270
1271 if (!state) {
1272 return -1;
1273 }
1274
1275 if (ARRAY_IN_BOUNDS(state->tls.method, tls_method_map)) {
1276 *buf = ast_strdup(tls_method_map[state->tls.method]);
1277 }
1278
1279 return 0;
1280}
1281
1282#if defined(PJ_HAS_SSL_SOCK) && PJ_HAS_SSL_SOCK != 0
1283/*! \brief Helper function which turns a cipher name into an identifier */
1284static pj_ssl_cipher cipher_name_to_id(const char *name)
1285{
1286 pj_ssl_cipher ciphers[PJ_SSL_SOCK_MAX_CIPHERS];
1287 unsigned int cipher_num = PJ_ARRAY_SIZE(ciphers);
1288 unsigned int pos;
1289
1290 if (pj_ssl_cipher_get_availables(ciphers, &cipher_num)) {
1291 return 0;
1292 }
1293
1294 for (pos = 0; pos < cipher_num; ++pos) {
1295 const char *pos_name = pj_ssl_cipher_name(ciphers[pos]);
1296 if (pos_name && !strcmp(pos_name, name)) {
1297 return ciphers[pos];
1298 }
1299 }
1300
1301 return 0;
1302}
1303#endif
1304
1305#if defined(PJ_HAS_SSL_SOCK) && PJ_HAS_SSL_SOCK != 0
1306/*!
1307 * \internal
1308 * \brief Add a new cipher to the transport's cipher list array.
1309 *
1310 * \param state Which transport to add the cipher to.
1311 * \param name Cipher identifier name.
1312 *
1313 * \retval 0 on success.
1314 * \retval -1 on error.
1315 */
1316static int transport_cipher_add(struct ast_sip_transport_state *state, const char *name)
1317{
1318 pj_ssl_cipher cipher;
1319 int idx;
1320
1321 cipher = cipher_name_to_id(name);
1322 if (!cipher) {
1323 /* TODO: Check this over/tweak - it's taken from pjsua for now */
1324 if (!strnicmp(name, "0x", 2)) {
1325 pj_str_t cipher_st = pj_str((char *) name + 2);
1326 cipher = pj_strtoul2(&cipher_st, NULL, 16);
1327 } else {
1328 cipher = atoi(name);
1329 }
1330 }
1331
1332 if (pj_ssl_cipher_is_supported(cipher)) {
1333 for (idx = state->tls.ciphers_num; idx--;) {
1334 if (state->ciphers[idx] == cipher) {
1335 /* The cipher is already in the list. */
1336 return 0;
1337 }
1338 }
1339 state->ciphers[state->tls.ciphers_num++] = cipher;
1340 return 0;
1341 } else {
1342 ast_log(LOG_ERROR, "Cipher '%s' is unsupported\n", name);
1343 return -1;
1344 }
1345}
1346#endif
1347
1348#if defined(PJ_HAS_SSL_SOCK) && PJ_HAS_SSL_SOCK != 0
1349/*! \brief Custom handler for TLS cipher setting */
1350static int transport_tls_cipher_handler(const struct aco_option *opt, struct ast_variable *var, void *obj)
1351{
1352 struct ast_sip_transport *transport = obj;
1353 char *parse;
1354 char *name;
1355 int res = 0;
1357
1358 if (!state) {
1359 return -1;
1360 }
1361
1362 parse = ast_strdupa(S_OR(var->value, ""));
1363 while ((name = ast_strip(strsep(&parse, ",")))) {
1364 if (ast_strlen_zero(name)) {
1365 continue;
1366 }
1367 if (ARRAY_LEN(state->ciphers) <= state->tls.ciphers_num) {
1368 ast_log(LOG_ERROR, "Too many ciphers specified (maximum allowed is %d)\n", SIP_TLS_MAX_CIPHERS);
1369 res = -1;
1370 break;
1371 }
1372 res |= transport_cipher_add(state, name);
1373 }
1374 return res ? -1 : 0;
1375}
1376#endif
1377
1378#if defined(PJ_HAS_SSL_SOCK) && PJ_HAS_SSL_SOCK != 0
1379static void cipher_to_str(char **buf, const pj_ssl_cipher *ciphers, unsigned int cipher_num)
1380{
1381 struct ast_str *str;
1382 unsigned int idx;
1383
1384 str = ast_str_create(128);
1385 if (!str) {
1386 *buf = NULL;
1387 return;
1388 }
1389
1390 for (idx = 0; idx < cipher_num; ++idx) {
1391 ast_str_append(&str, 0, "%s", pj_ssl_cipher_name(ciphers[idx]));
1392 if (idx < cipher_num - 1) {
1393 ast_str_append(&str, 0, ", ");
1394 }
1395 }
1396
1398 ast_free(str);
1399}
1400#endif
1401
1402#if defined(PJ_HAS_SSL_SOCK) && PJ_HAS_SSL_SOCK != 0
1403static int transport_tls_cipher_to_str(const void *obj, const intptr_t *args, char **buf)
1404{
1405 const struct ast_sip_transport *transport = obj;
1407
1408 if (!state) {
1409 return -1;
1410 }
1411
1412 cipher_to_str(buf, state->ciphers, state->tls.ciphers_num);
1413 return *buf ? 0 : -1;
1414}
1415#endif
1416
1417#if defined(PJ_HAS_SSL_SOCK) && PJ_HAS_SSL_SOCK != 0
1418static char *handle_pjsip_list_ciphers(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
1419{
1420 pj_ssl_cipher ciphers[PJ_SSL_SOCK_MAX_CIPHERS];
1421 unsigned int cipher_num = PJ_ARRAY_SIZE(ciphers);
1422 char *buf;
1423
1424 switch (cmd) {
1425 case CLI_INIT:
1426 e->command = "pjsip list ciphers";
1427 e->usage = "Usage: pjsip list ciphers\n"
1428 " List available OpenSSL cipher names.\n";
1429 return NULL;
1430 case CLI_GENERATE:
1431 return NULL;
1432 }
1433
1434 if (pj_ssl_cipher_get_availables(ciphers, &cipher_num) || !cipher_num) {
1435 buf = NULL;
1436 } else {
1437 cipher_to_str(&buf, ciphers, cipher_num);
1438 }
1439
1440 if (!ast_strlen_zero(buf)) {
1441 ast_cli(a->fd, "Available ciphers: '%s'\n", buf);
1442 } else {
1443 ast_cli(a->fd, "No available ciphers\n");
1444 }
1445 ast_free(buf);
1446 return CLI_SUCCESS;
1447}
1448#endif
1449
1450/*! \brief Custom handler for localnet setting */
1451static int transport_localnet_handler(const struct aco_option *opt, struct ast_variable *var, void *obj)
1452{
1453 struct ast_sip_transport *transport = obj;
1454 int error = 0;
1456
1457 if (!state) {
1458 return -1;
1459 }
1460
1461 if (ast_strlen_zero(var->value)) {
1462 ast_free_ha(state->localnet);
1463 state->localnet = NULL;
1464 return 0;
1465 }
1466
1467 /* We use only the ast_apply_ha() which defaults to ALLOW
1468 * ("permit"), so we add DENY rules. */
1469 if (!(state->localnet = ast_append_ha("deny", var->value, state->localnet, &error))) {
1470 return -1;
1471 }
1472
1473 return error;
1474}
1475
1476static void localnet_to_vl_append(struct ast_variable **head, struct ast_ha *ha)
1477{
1478 char str[MAX_OBJECT_FIELD];
1479 const char *addr = ast_strdupa(ast_sockaddr_stringify_addr(&ha->addr));
1480 snprintf(str, MAX_OBJECT_FIELD, "%s%s/%s", ha->sense == AST_SENSE_ALLOW ? "!" : "",
1482
1483 ast_variable_list_append(head, ast_variable_new("local_net", str, ""));
1484}
1485
1486static int localnet_to_vl(const void *obj, struct ast_variable **fields)
1487{
1488 const struct ast_sip_transport *transport = obj;
1489 struct ast_variable *head = NULL;
1490 struct ast_ha *ha;
1492
1493 if (!state) {
1494 return -1;
1495 }
1496
1497 for (ha = state->localnet; ha; ha = ha->next) {
1498 localnet_to_vl_append(&head, ha);
1499 }
1500
1501 if (head) {
1502 *fields = head;
1503 }
1504
1505 return 0;
1506}
1507
1508static int localnet_to_str(const void *obj, const intptr_t *args, char **buf)
1509{
1511 const struct ast_sip_transport *transport = obj;
1513
1514 if (!state) {
1515 return -1;
1516 }
1517
1518 ast_ha_join(state->localnet, &str);
1520 return 0;
1521}
1522
1523/*! \brief Custom handler for TOS setting */
1524static int transport_tos_handler(const struct aco_option *opt, struct ast_variable *var, void *obj)
1525{
1526 struct ast_sip_transport *transport = obj;
1527 unsigned int value;
1528
1529 if (ast_str2tos(var->value, &value)) {
1530 ast_log(LOG_ERROR, "Error configuring transport '%s' - Could not "
1531 "interpret 'tos' value '%s'\n",
1532 ast_sorcery_object_get_id(transport), var->value);
1533 return -1;
1534 }
1535
1536 if (value % 4) {
1537 value = value >> 2;
1538 value = value << 2;
1540 "transport '%s' - 'tos' value '%s' uses bits that are "
1541 "discarded when converted to DSCP. Using equivalent %u instead.\n",
1542 ast_sorcery_object_get_id(transport), var->value, value);
1543 }
1544
1545 transport->tos = value;
1546 return 0;
1547}
1548
1549static int tos_to_str(const void *obj, const intptr_t *args, char **buf)
1550{
1551 const struct ast_sip_transport *transport = obj;
1552
1553 if (ast_asprintf(buf, "%u", transport->tos) == -1) {
1554 return -1;
1555 }
1556 return 0;
1557}
1558
1559static struct ao2_container *cli_get_container(const char *regex)
1560{
1562 struct ao2_container *s_container;
1563
1565 regex);
1566 if (!container) {
1567 return NULL;
1568 }
1569
1572 if (!s_container) {
1573 return NULL;
1574 }
1575
1576 if (ao2_container_dup(s_container, container, 0)) {
1577 ao2_ref(s_container, -1);
1578 return NULL;
1579 }
1580
1581 return s_container;
1582}
1583
1584static int cli_iterate(void *container, ao2_callback_fn callback, void *args)
1585{
1586 const struct ast_sip_endpoint *endpoint = container;
1588 "transport", endpoint->transport);
1589
1590 if (!transport) {
1591 return -1;
1592 }
1593
1594 return callback(transport, args, 0);
1595}
1596
1597static void *cli_retrieve_by_id(const char *id)
1598{
1599 return ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(), "transport", id);
1600}
1601
1602static int cli_print_header(void *obj, void *arg, int flags)
1603{
1604 struct ast_sip_cli_context *context = arg;
1605 int indent = CLI_INDENT_TO_SPACES(context->indent_level);
1606 int filler = CLI_MAX_WIDTH - indent - 61;
1607
1608 ast_assert(context->output_buffer != NULL);
1609
1610 ast_str_append(&context->output_buffer, 0,
1611 "%*s: <TransportId........> <Type> <cos> <tos> <BindAddress%*.*s>\n",
1612 indent, "Transport", filler, filler, CLI_HEADER_FILLER);
1613
1614 return 0;
1615}
1616
1617static int cli_print_body(void *obj, void *arg, int flags)
1618{
1619 struct ast_sip_transport *transport = obj;
1620 struct ast_sip_cli_context *context = arg;
1621 char hoststr[PJ_INET6_ADDRSTRLEN];
1623
1624 if (!state) {
1625 return -1;
1626 }
1627
1628 ast_assert(context->output_buffer != NULL);
1629
1630 pj_sockaddr_print(&state->host, hoststr, sizeof(hoststr), 3);
1631
1632 ast_str_append(&context->output_buffer, 0, "%*s: %-21s %6s %5u %5u %s\n",
1633 CLI_INDENT_TO_SPACES(context->indent_level), "Transport",
1634 ast_sorcery_object_get_id(transport),
1635 ARRAY_IN_BOUNDS(transport->type, transport_types) ? transport_types[transport->type] : "Unknown",
1636 transport->cos, transport->tos, hoststr);
1637
1638 if (context->show_details
1639 || (context->show_details_only_level_0 && context->indent_level == 0)) {
1640 ast_str_append(&context->output_buffer, 0, "\n");
1642 }
1643
1644 return 0;
1645}
1646
1647static struct ast_cli_entry cli_commands[] = {
1648#if defined(PJ_HAS_SSL_SOCK) && PJ_HAS_SSL_SOCK != 0
1649 AST_CLI_DEFINE(handle_pjsip_list_ciphers, "List available OpenSSL cipher names"),
1650#endif
1651 AST_CLI_DEFINE(ast_sip_cli_traverse_objects, "List PJSIP Transports",
1652 .command = "pjsip list transports",
1653 .usage = "Usage: pjsip list transports [ like <pattern> ]\n"
1654 " List the configured PJSIP Transports\n"
1655 " Optional regular expression pattern is used to filter the list.\n"),
1656 AST_CLI_DEFINE(ast_sip_cli_traverse_objects, "Show PJSIP Transports",
1657 .command = "pjsip show transports",
1658 .usage = "Usage: pjsip show transports [ like <pattern> ]\n"
1659 " Show the configured PJSIP Transport\n"
1660 " Optional regular expression pattern is used to filter the list.\n"),
1661 AST_CLI_DEFINE(ast_sip_cli_traverse_objects, "Show PJSIP Transport",
1662 .command = "pjsip show transport",
1663 .usage = "Usage: pjsip show transport <id>\n"
1664 " Show the configured PJSIP Transport\n"),
1665};
1666
1668
1670{
1671 struct internal_state *state = NULL;
1672 struct ast_sip_transport_state *trans_state;
1673
1674 if (!transport_states) {
1675 return NULL;
1676 }
1677
1679 if (!state) {
1680 return NULL;
1681 }
1682
1683 trans_state = ao2_bump(state->state);
1684 ao2_ref(state, -1);
1685
1686 /* If this is a child transport see if the transport is actually dead */
1687 if (trans_state->flow) {
1688 ao2_lock(trans_state);
1689 if (trans_state->transport && trans_state->transport->is_shutdown == PJ_TRUE) {
1690 pjsip_transport_dec_ref(trans_state->transport);
1691 trans_state->transport = NULL;
1692 }
1693 ao2_unlock(trans_state);
1694 }
1695
1696 return trans_state;
1697}
1698
1699static int populate_transport_states(void *obj, void *arg, int flags)
1700{
1701 struct internal_state *state = obj;
1702 struct ao2_container *container = arg;
1703
1704 ao2_link(container, state->state);
1705
1706 return CMP_MATCH;
1707}
1708
1710{
1713
1714 if (!states) {
1715 return NULL;
1716 }
1717
1719 return states;
1720}
1721
1722/*! \brief Initialize sorcery with transport support */
1724{
1726 struct ao2_container *transports = NULL;
1727
1728 /* Create outbound registration states container. */
1731 if (!transport_states) {
1732 ast_log(LOG_ERROR, "Unable to allocate transport states container\n");
1733 return -1;
1734 }
1735
1736 ast_sorcery_apply_default(sorcery, "transport", "config", "pjsip.conf,criteria=type=transport");
1737
1739 return -1;
1740 }
1741
1742 /* Normally type is a OPT_NOOP_T but we're using it to make sure that state is created */
1746 ast_sorcery_object_field_register(sorcery, "transport", "async_operations", "1", OPT_UINT_T, 0, FLDSET(struct ast_sip_transport, async_operations));
1747
1752
1753 ast_sorcery_object_field_register(sorcery, "transport", "password", "", OPT_STRINGFIELD_T, 0, STRFLDSET(struct ast_sip_transport, password));
1754 ast_sorcery_object_field_register(sorcery, "transport", "external_signaling_address", "", OPT_STRINGFIELD_T, 0, STRFLDSET(struct ast_sip_transport, external_signaling_address));
1755 ast_sorcery_object_field_register(sorcery, "transport", "external_signaling_port", "0", OPT_UINT_T, PARSE_IN_RANGE, FLDSET(struct ast_sip_transport, external_signaling_port), 0, 65535);
1756 ast_sorcery_object_field_register(sorcery, "transport", "external_media_address", "", OPT_STRINGFIELD_T, 0, STRFLDSET(struct ast_sip_transport, external_media_address));
1757 ast_sorcery_object_field_register(sorcery, "transport", "domain", "", OPT_STRINGFIELD_T, 0, STRFLDSET(struct ast_sip_transport, domain));
1763#if defined(PJ_HAS_SSL_SOCK) && PJ_HAS_SSL_SOCK != 0
1764 ast_sorcery_object_field_register_custom(sorcery, "transport", "cipher", "", transport_tls_cipher_handler, transport_tls_cipher_to_str, NULL, 0, 0);
1765#endif
1768 ast_sorcery_object_field_register(sorcery, "transport", "cos", "0", OPT_UINT_T, 0, FLDSET(struct ast_sip_transport, cos));
1769 ast_sorcery_object_field_register(sorcery, "transport", "websocket_write_timeout", AST_DEFAULT_WEBSOCKET_WRITE_TIMEOUT_STR, OPT_INT_T, PARSE_IN_RANGE, FLDSET(struct ast_sip_transport, write_timeout), 1, INT_MAX);
1770 ast_sorcery_object_field_register(sorcery, "transport", "allow_reload", "no", OPT_BOOL_T, 1, FLDSET(struct ast_sip_transport, allow_reload));
1771 ast_sorcery_object_field_register(sorcery, "transport", "symmetric_transport", "no", OPT_BOOL_T, 1, FLDSET(struct ast_sip_transport, symmetric_transport));
1772
1774
1776 if (!cli_formatter) {
1777 ast_log(LOG_ERROR, "Unable to allocate memory for cli formatter\n");
1778 return -1;
1779 }
1780 cli_formatter->name = "transport";
1787
1790
1791 /* trigger load of transports from realtime by trying to revrieve them all */
1793 ao2_cleanup(transports);
1794
1795 return 0;
1796}
1797
1799{
1802
1804
1807
1808 return 0;
1809}
Access Control of various sorts.
void ast_free_ha(struct ast_ha *ha)
Free a list of HAs.
Definition: acl.c:222
int ast_str2tos(const char *value, unsigned int *tos)
Convert a string to the appropriate TOS value.
Definition: acl.c:966
@ AST_SENSE_ALLOW
Definition: acl.h:38
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
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
const char * str
Definition: app_jack.c:147
#define var
Definition: ast_expr2f.c:605
Asterisk main include file. File version handling, generic pbx functions.
#define ast_free(a)
Definition: astmm.h:180
#define ast_strdup(str)
A wrapper for strdup()
Definition: astmm.h:241
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: astmm.h:298
#define ast_asprintf(ret, fmt,...)
A wrapper for asprintf()
Definition: astmm.h:267
#define ast_calloc(num, len)
A wrapper for calloc()
Definition: astmm.h:202
#define ast_log
Definition: astobj2.c:42
int ao2_container_dup(struct ao2_container *dest, struct ao2_container *src, enum search_flags flags)
Copy all object references in the src container into the dest container.
#define ao2_link(container, obj)
Add an object to a container.
Definition: astobj2.h:1532
@ CMP_MATCH
Definition: astobj2.h:1027
@ AO2_ALLOC_OPT_LOCK_NOLOCK
Definition: astobj2.h:367
@ AO2_ALLOC_OPT_LOCK_MUTEX
Definition: astobj2.h:363
#define ao2_wrlock(a)
Definition: astobj2.h:719
#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
#define ao2_cleanup(obj)
Definition: astobj2.h:1934
#define ao2_unlink_flags(container, obj, flags)
Remove an object from a container.
Definition: astobj2.h:1600
int() ao2_callback_fn(void *obj, void *arg, int flags)
Type of a generic callback function.
Definition: astobj2.h:1226
#define ao2_link_flags(container, obj, flags)
Add an object to a container.
Definition: astobj2.h:1554
#define ao2_find(container, arg, flags)
Definition: astobj2.h:1736
#define ao2_unlock(a)
Definition: astobj2.h:729
#define ao2_replace(dst, src)
Replace one object reference with another cleaning up the original.
Definition: astobj2.h:501
#define ao2_lock(a)
Definition: astobj2.h:717
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
Definition: astobj2.h:459
#define ao2_bump(obj)
Bump refcount on an AO2 object by one, returning the object.
Definition: astobj2.h:480
@ 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_NOLOCK
Assume that the ao2_container is already locked.
Definition: astobj2.h:1063
@ OBJ_NODATA
Definition: astobj2.h:1044
@ OBJ_SEARCH_MASK
Search option field mask.
Definition: astobj2.h:1072
@ OBJ_MULTIPLE
Definition: astobj2.h:1049
@ OBJ_SEARCH_KEY
The arg parameter is a search key, but is not an object.
Definition: astobj2.h:1101
#define ao2_container_alloc_list(ao2_options, container_options, sort_fn, cmp_fn)
Allocate and initialize a list container.
Definition: astobj2.h:1327
#define ao2_alloc(data_size, destructor_fn)
Definition: astobj2.h:409
#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
enum cc_state state
Definition: ccss.c:393
static struct @116 qos
unsigned int cos
Definition: chan_iax2.c:359
#define CLI_SUCCESS
Definition: cli.h:44
int ast_cli_unregister_multiple(struct ast_cli_entry *e, int len)
Unregister multiple commands.
Definition: clicompat.c:30
#define AST_CLI_DEFINE(fn, txt,...)
Definition: cli.h:197
void ast_cli(int fd, const char *fmt,...)
Definition: clicompat.c:6
@ CLI_INIT
Definition: cli.h:152
@ CLI_GENERATE
Definition: cli.h:153
#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 struct ast_sip_transport_state * find_temporary_state(struct ast_sip_transport *transport)
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.
#define BIND_TRIES
int ast_sip_initialize_sorcery_transport(void)
Initialize sorcery with transport support.
static struct ast_cli_entry cli_commands[]
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.
int ast_sip_transport_state_set_transport(const char *transport_name, pjsip_transport *transport)
Sets the PJSIP transport on a child transport.
static int format_ami_endpoint_transport(const struct ast_sip_endpoint *endpoint, struct ast_sip_ami *ami)
static int transport_state_hash(const void *obj, const int flags)
hashing function for state objects
static int cli_print_header(void *obj, void *arg, int flags)
struct ao2_container * ast_sip_get_transport_states(void)
Retrieves all transport states.
static int destroy_sip_transport_state(void *data)
static int transport_state_cmp(void *obj, void *arg, int flags)
comparator function for state objects
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 void sip_transport_state_destroy(void *obj)
Destructor for ast_sip_transport state information.
static int transport_protocol_to_str(const void *obj, const intptr_t *args, char **buf)
static void sip_transport_destroy(void *obj)
Destructor for transport.
#define DEFAULT_STATE_BUCKETS
Default number of state container buckets.
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 void localnet_to_vl_append(struct ast_variable **head, struct ast_ha *ha)
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.
void ast_sip_message_apply_transport(const char *transport_name, pjsip_tx_data *tdata)
Apply the configuration for a transport to an outgoing message.
static int transport_bind_to_str(const void *obj, const intptr_t *args, char **buf)
static struct ast_sip_transport_state * find_state_by_transport(const struct ast_sip_transport *transport)
static struct ast_sip_transport_state * find_or_create_temporary_state(struct ast_sip_transport *transport)
static int internal_state_cmp(void *obj, void *arg, int flags)
comparator function for state objects
void ast_sip_service_route_vector_destroy(struct ast_sip_service_route_vector *service_routes)
Destroy a vector of service routes.
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 sip_transport_to_ami(const struct ast_sip_transport *transport, struct ast_str **buf)
static int cli_iterate(void *container, ao2_callback_fn callback, void *args)
static void copy_state_to_transport(struct ast_sip_transport *transport)
static struct internal_state * internal_state_alloc(struct ast_sip_transport *transport)
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 struct internal_state * find_internal_state_by_transport(const struct ast_sip_transport *transport)
static int populate_transport_states(void *obj, void *arg, int flags)
static void temp_state_store_cleanup(void *data)
static void set_qos(struct ast_sip_transport *transport, pj_qos_params *qos)
struct ast_sip_service_route_vector * ast_sip_service_route_vector_alloc(void)
Allocate a vector of service routes.
static int tos_to_str(const void *obj, const intptr_t *args, char **buf)
static struct ao2_container * cli_get_container(const char *regex)
#define BIND_DELAY_US
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)
struct ast_sip_transport_state * ast_sip_get_transport_state(const char *transport_id)
Retrieve transport state.
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.
int ast_sip_destroy_sorcery_transport(void)
static const char * transport_types[]
struct ast_sip_endpoint_formatter endpoint_transport_formatter
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 struct ast_threadstorage temp_state_store
static struct ast_sip_cli_formatter_entry * cli_formatter
static void * sip_transport_alloc(const char *name)
Allocator for transport.
static int remove_temporary_state(void)
static void internal_state_destroy(void *obj)
Destructor for ast_sip_transport state information.
static int ca_list_path_to_str(const void *obj, const intptr_t *args, char **buf)
int ast_sip_transport_state_set_preferred_identity(const char *transport_name, const char *identity)
Sets the P-Preferred-Identity on a child transport.
static const char * tls_method_map[]
static int has_state_changed(struct ast_sip_transport_state *a, struct ast_sip_transport_state *b)
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.
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.
static struct ao2_container * transport_states
static void states_cleanup(void *states)
void ast_dnsmgr_release(struct ast_dnsmgr_entry *entry)
Free a DNS manager entry.
Definition: dnsmgr.c:136
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 buf[BUFSIZE]
Definition: eagi_proxy.c:66
char * address
Definition: f2c.h:59
static const char name[]
Definition: format_mp3.c:68
static int regex(struct ast_channel *chan, const char *cmd, char *parse, char *buf, size_t len)
void astman_send_error_va(struct mansession *s, const struct message *m, const char *fmt,...)
Send error in manager transaction (with va_args support)
Definition: manager.c:3359
void astman_append(struct mansession *s, const char *fmt,...)
Definition: manager.c:3275
int ast_sip_push_task_wait_servant(struct ast_taskprocessor *serializer, int(*sip_task)(void *), void *task_data)
Push a task to SIP servants and wait for it to complete.
Definition: res_pjsip.c:2165
Support for WebSocket connections within the Asterisk HTTP server and client WebSocket connections to...
#define AST_DEFAULT_WEBSOCKET_WRITE_TIMEOUT_STR
Default websocket write timeout, in ms (as a string)
char * strsep(char **str, const char *delims)
#define ast_variable_new(name, value, filename)
#define ast_variable_list_append(head, new_var)
void ast_variables_destroy(struct ast_variable *var)
Free variable list.
Definition: extconf.c:1262
Support for logging to various files, console and syslog Configuration in file logger....
#define ast_debug(level,...)
Log a DEBUG message.
#define LOG_ERROR
#define LOG_NOTICE
#define LOG_WARNING
int errno
@ 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
int ast_sockaddr_cmp(const struct ast_sockaddr *a, const struct ast_sockaddr *b)
Compares two ast_sockaddr structures.
Definition: netsock2.c:388
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 ao2_container * container
Definition: res_fax.c:501
#define AST_SIP_X_AST_TXP
Definition: res_pjsip.h:1066
pjsip_endpoint * ast_sip_get_pjsip_endpoint(void)
Get a pointer to the PJSIP endpoint.
Definition: res_pjsip.c:520
#define SIP_TLS_MAX_CIPHERS
Maximum number of ciphers supported for a TLS transport.
Definition: res_pjsip.h:107
void ast_sip_register_endpoint_formatter(struct ast_sip_endpoint_formatter *obj)
Register an endpoint formatter.
Definition: res_pjsip.c:481
void ast_sip_unregister_endpoint_formatter(struct ast_sip_endpoint_formatter *obj)
Unregister an endpoint formatter.
Definition: res_pjsip.c:487
int ast_sip_sorcery_object_to_ami(const void *obj, struct ast_str **buf)
Converts a sorcery object to a string of object properties.
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.
int ast_sip_add_header(pjsip_tx_data *tdata, const char *name, const char *value)
Add a header to an outbound SIP message.
Definition: res_pjsip.c:2008
struct ast_sorcery * ast_sip_get_sorcery(void)
Get a pointer to the SIP sorcery structure.
#define AST_SIP_X_AST_TXP_LEN
Definition: res_pjsip.h:1067
int ast_sip_unregister_cli_formatter(struct ast_sip_cli_formatter_entry *formatter)
Unregisters a CLI formatter.
Definition: pjsip_cli.c:326
#define CLI_HEADER_FILLER
Definition: res_pjsip_cli.h:24
#define CLI_MAX_WIDTH
Definition: res_pjsip_cli.h:26
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
char * ast_sip_cli_traverse_objects(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
Definition: pjsip_cli.c:109
#define CLI_INDENT_TO_SPACES(x)
Definition: res_pjsip_cli.h:29
int ast_sip_register_cli_formatter(struct ast_sip_cli_formatter_entry *formatter)
Registers a CLI formatter.
Definition: pjsip_cli.c:310
static struct ast_sorcery * sorcery
#define NULL
Definition: resample.c:96
Sorcery Data Access Layer API.
const char * ast_sorcery_object_get_id(const void *object)
Get the unique identifier of a sorcery object.
Definition: sorcery.c:2312
@ AST_RETRIEVE_FLAG_MULTIPLE
Return all matching objects.
Definition: sorcery.h:120
@ AST_RETRIEVE_FLAG_ALL
Perform no matching, return all objects.
Definition: sorcery.h:123
void ast_sorcery_object_set_has_dynamic_contents(const void *object)
Set the dynamic contents flag on a sorcery object.
Definition: sorcery.c:2379
int ast_sorcery_diff(const struct ast_sorcery *sorcery, const void *original, const void *modified, struct ast_variable **changes)
Create a changeset of two objects.
Definition: sorcery.c:1805
void * ast_sorcery_retrieve_by_id(const struct ast_sorcery *sorcery, const char *type, const char *id)
Retrieve an object using its unique identifier.
Definition: sorcery.c:1853
#define ast_sorcery_object_register(sorcery, type, alloc, transform, apply)
Register an object type.
Definition: sorcery.h:837
struct ao2_container * ast_sorcery_retrieve_by_regex(const struct ast_sorcery *sorcery, const char *type, const char *regex)
Retrieve multiple objects using a regular expression on their id.
Definition: sorcery.c:1949
#define 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
void * ast_sorcery_generic_alloc(size_t size, ao2_destructor_fn destructor)
Allocate a generic sorcery capable object.
Definition: sorcery.c:1728
int ast_sorcery_object_id_compare(void *obj, void *arg, int flags)
ao2 object comparator based on sorcery id.
Definition: sorcery.c:2459
#define ast_sorcery_object_field_register(sorcery, type, name, default_val, opt_type, flags,...)
Register a field within an object.
Definition: sorcery.h:955
int ast_sorcery_object_id_sort(const void *obj, const void *arg, int flags)
ao2 object sorter based on sorcery id.
Definition: sorcery.c:2435
#define MAX_OBJECT_FIELD
Maximum length of an object field name.
Definition: sorcery.h:110
#define ast_sorcery_apply_default(sorcery, type, name, data)
Definition: sorcery.h:476
void * ast_sorcery_retrieve_by_fields(const struct ast_sorcery *sorcery, const char *type, unsigned int flags, struct ast_variable *fields)
Retrieve an object or multiple objects using specific fields.
Definition: sorcery.c:1897
#define ast_string_field_set(x, field, data)
Set a field to a simple string value.
Definition: stringfields.h:521
#define ast_string_field_init(x, size)
Initialize a field pool and fields.
Definition: stringfields.h:359
#define ast_string_field_free_memory(x)
free all memory - to be called before destroying the object
Definition: stringfields.h:374
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
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition: strings.h:761
#define S_OR(a, b)
returns the equivalent of logic or for strings: first one if not empty, otherwise second one.
Definition: strings.h:80
static force_inline int attribute_pure ast_str_hash(const char *str)
Compute a hash value on a string.
Definition: strings.h:1259
int attribute_pure ast_true(const char *val)
Make sure something is true. Determine if a string containing a boolean value is "true"....
Definition: utils.c:2199
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:65
#define ast_str_create(init_len)
Create a malloc'ed dynamic length string.
Definition: strings.h:659
#define AST_YESNO(x)
return Yes or No depending on the argument.
Definition: strings.h:143
char * ast_strip(char *s)
Strip leading/trailing whitespace from a string.
Definition: strings.h:223
Generic container type.
descriptor for a cli entry.
Definition: cli.h:171
char * command
Definition: cli.h:186
const char * usage
Definition: cli.h:177
internal representation of ACL entries In principle user applications would have no need for this,...
Definition: acl.h:51
struct ast_sockaddr addr
Definition: acl.h:53
struct ast_sockaddr netmask
Definition: acl.h:54
struct ast_ha * next
Definition: acl.h:56
enum ast_acl_sense sense
Definition: acl.h:55
AMI variable container.
Definition: res_pjsip.h:3035
struct mansession * s
Definition: res_pjsip.h:3037
const struct message * m
Definition: res_pjsip.h:3039
CLI Formatter Context passed to all formatters.
Definition: res_pjsip_cli.h:34
CLI Formatter Registry Entry.
Definition: res_pjsip_cli.h:52
int(* iterate)(void *container, ao2_callback_fn callback, void *args)
Definition: res_pjsip_cli.h:66
ao2_callback_fn * print_header
Definition: res_pjsip_cli.h:60
void *(* retrieve_by_id)(const char *id)
Definition: res_pjsip_cli.h:68
const char *(* get_id)(const void *obj)
Definition: res_pjsip_cli.h:70
const char * name
Definition: res_pjsip_cli.h:58
ao2_callback_fn * print_body
Definition: res_pjsip_cli.h:62
struct ao2_container *(* get_container)(const char *regex)
Definition: res_pjsip_cli.h:64
An entity responsible formatting endpoint information.
Definition: res_pjsip.h:3061
int(* format_ami)(const struct ast_sip_endpoint *endpoint, struct ast_sip_ami *ami)
Callback used to format endpoint information over AMI.
Definition: res_pjsip.h:3065
An entity with which Asterisk communicates.
Definition: res_pjsip.h:951
const ast_string_field transport
Definition: res_pjsip.h:980
Structure for SIP transport information.
Definition: res_pjsip.h:119
pjsip_tls_setting tls
Definition: res_pjsip.h:143
struct ast_dnsmgr_entry * external_media_address_refresher
Definition: res_pjsip.h:171
enum ast_transport type
Definition: res_pjsip.h:133
struct ast_sip_service_route_vector * service_routes
Definition: res_pjsip.h:191
struct pjsip_transport * transport
Transport itself.
Definition: res_pjsip.h:121
struct ast_ha * localnet
Definition: res_pjsip.h:156
struct ast_dnsmgr_entry * external_signaling_address_refresher
Definition: res_pjsip.h:161
pj_ssl_cipher ciphers[SIP_TLS_MAX_CIPHERS]
Definition: res_pjsip.h:148
Transport to bind to.
Definition: res_pjsip.h:221
unsigned int tos
Definition: res_pjsip.h:291
const ast_string_field privkey_file
Definition: res_pjsip.h:241
const ast_string_field ca_list_path
Definition: res_pjsip.h:241
enum ast_transport type
Definition: res_pjsip.h:243
const ast_string_field cert_file
Definition: res_pjsip.h:241
const ast_string_field password
Definition: res_pjsip.h:241
const ast_string_field external_signaling_address
Definition: res_pjsip.h:241
const ast_string_field ca_list_file
Definition: res_pjsip.h:241
struct ast_sip_transport_state * state
Definition: res_pjsip.h:289
unsigned int async_operations
Definition: res_pjsip.h:251
pj_ssl_cipher ciphers[SIP_TLS_MAX_CIPHERS]
Definition: res_pjsip.h:265
const ast_string_field external_media_address
Definition: res_pjsip.h:241
unsigned int cos
Definition: res_pjsip.h:293
Full structure for sorcery.
Definition: sorcery.c:230
Support for dynamic strings.
Definition: strings.h:623
Structure for variables, used for configurations and for channel variables.
struct ast_sip_transport_state * state
Transport state information.
struct ast_sip_transport * transport
Transport configuration object.
int value
Definition: syslog.c:37
const char * args
static struct test_val b
static struct test_val a
#define AST_THREADSTORAGE_CUSTOM(a, b, c)
Define a thread storage variable, with custom initialization and cleanup.
void * ast_threadstorage_get(struct ast_threadstorage *ts, size_t init_size)
Retrieve thread storage.
int error(const char *format,...)
Definition: utils/frame.c:999
char * usage
Definition: utils/frame.c:37
Utility functions.
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
Definition: utils.h:941
#define ast_assert(a)
Definition: utils.h:739
int ast_file_is_readable(const char *filename)
Test that a file exists and is readable by the effective user.
Definition: utils.c:3107
int ast_compare_versions(const char *version1, const char *version2)
Compare 2 major.minor.patch.extra version strings.
Definition: utils.c:3124
#define ARRAY_IN_BOUNDS(v, a)
Checks to see if value is within the bounds of the given array.
Definition: utils.h:687
#define ARRAY_LEN(a)
Definition: utils.h:666
#define MAX(a, b)
Definition: utils.h:233
#define AST_VECTOR_SIZE(vec)
Get the number of elements in a vector.
Definition: vector.h:609
#define AST_VECTOR_INIT(vec, size)
Initialize a vector.
Definition: vector.h:113
#define AST_VECTOR_CALLBACK_VOID(vec, callback,...)
Execute a callback on every element in a vector disregarding callback return.
Definition: vector.h:862
#define AST_VECTOR_GET(vec, idx)
Get an element from a vector.
Definition: vector.h:680