| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
#include "asterisk.h" |
| 20 |
|
| 21 |
#include <math.h> |
| 22 |
#include <pjsip.h> |
| 23 |
#include <pjlib.h> |
| 24 |
|
| 25 |
|
| 26 |
#ifdef __APPLE__ |
| 27 |
#include <netinet/tcp.h> |
| 28 |
#ifndef TCP_KEEPIDLE |
| 29 |
#define TCP_KEEPIDLE TCP_KEEPALIVE |
| 30 |
#endif |
| 31 |
#ifndef TCP_KEEPINTVL |
| 32 |
#define TCP_KEEPINTVL 0x101 |
| 33 |
#endif |
| 34 |
#ifndef TCP_KEEPCNT |
| 35 |
#define TCP_KEEPCNT 0x102 |
| 36 |
#endif |
| 37 |
#endif |
| 38 |
|
| 39 |
#include "asterisk/res_pjsip.h" |
| 40 |
#include "asterisk/res_pjsip_cli.h" |
| 41 |
#include "asterisk/logger.h" |
| 42 |
#include "asterisk/astobj2.h" |
| 43 |
#include "asterisk/sorcery.h" |
| 44 |
#include "asterisk/acl.h" |
| 45 |
#include "asterisk/utils.h" |
| 46 |
#include "include/res_pjsip_private.h" |
| 47 |
|
| 48 |
#include "asterisk/http_websocket.h" |
| 49 |
|
| 50 |
#define MAX_POINTER_STRING 33 |
| 51 |
|
| 52 |
|
| 53 |
#define DEFAULT_STATE_BUCKETS 53 |
| 54 |
static struct ao2_container *transport_states; |
| 55 |
|
| 56 |
struct internal_state { |
| 57 |
char *id; |
| 58 |
|
| 59 |
int change_detected; |
| 60 |
|
| 61 |
struct ast_sip_transport *transport; |
| 62 |
|
| 63 |
struct ast_sip_transport_state *state; |
| 64 |
}; |
| 65 |
|
| 66 |
static void temp_state_store_cleanup(void *data) |
| 67 |
{ |
| 68 |
struct ast_sip_transport_state **temp_state = data; |
| 69 |
|
| 70 |
ao2_cleanup(*temp_state); |
| 71 |
ast_free(data); |
| 72 |
} |
| 73 |
|
| 74 |
AST_THREADSTORAGE_CUSTOM(temp_state_store, NULL, temp_state_store_cleanup); |
| 75 |
|
| 76 |
|
| 77 |
static int internal_state_hash(const void *obj, const int flags) |
| 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; |
| 86 |
case OBJ_SEARCH_OBJECT: |
| 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 |
} |
| 96 |
|
| 97 |
|
| 98 |
static int internal_state_cmp(void *obj, void *arg, int flags) |
| 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) { |
| 106 |
case OBJ_SEARCH_OBJECT: |
| 107 |
right_key = object_right->id; |
| 108 |
|
| 109 |
case OBJ_SEARCH_KEY: |
| 110 |
cmp = strcmp(object_left->id, right_key); |
| 111 |
break; |
| 112 |
case OBJ_SEARCH_PARTIAL_KEY: |
| 113 |
|
| 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 |
} |
| 125 |
|
| 126 |
|
| 127 |
static int transport_state_hash(const void *obj, const int flags) |
| 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; |
| 136 |
case OBJ_SEARCH_OBJECT: |
| 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 |
} |
| 146 |
|
| 147 |
|
| 148 |
static int transport_state_cmp(void *obj, void *arg, int flags) |
| 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) { |
| 156 |
case OBJ_SEARCH_OBJECT: |
| 157 |
right_key = object_right->id; |
| 158 |
|
| 159 |
case OBJ_SEARCH_KEY: |
| 160 |
cmp = strcmp(object_left->id, right_key); |
| 161 |
break; |
| 162 |
case OBJ_SEARCH_PARTIAL_KEY: |
| 163 |
|
| 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 |
} |
| 175 |
|
| 176 |
static int sip_transport_to_ami(const struct ast_sip_transport *transport, |
| 177 |
struct ast_str **buf) |
| 178 |
{ |
| 179 |
return ast_sip_sorcery_object_to_ami(transport, buf); |
| 180 |
} |
| 181 |
|
| 182 |
static int format_ami_endpoint_transport(const struct ast_sip_endpoint *endpoint, |
| 183 |
struct ast_sip_ami *ami) |
| 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 |
} |
| 215 |
|
| 216 |
struct ast_sip_endpoint_formatter endpoint_transport_formatter = { |
| 217 |
.format_ami = format_ami_endpoint_transport |
| 218 |
}; |
| 219 |
|
| 220 |
int ast_sip_transport_state_set_transport(const char *transport_name, pjsip_transport *transport) |
| 221 |
{ |
| 222 |
struct ast_sip_transport_state *transport_state; |
| 223 |
|
| 224 |
|
| 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 |
} |
| 255 |
|
| 256 |
int ast_sip_transport_state_set_preferred_identity(const char *transport_name, const char *identity) |
| 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 |
} |
| 283 |
|
| 284 |
int ast_sip_transport_state_set_service_routes(const char *transport_name, struct ast_sip_service_route_vector *service_routes) |
| 285 |
{ |
| 286 |
struct ast_sip_transport_state *transport_state; |
| 287 |
|
| 288 |
if (ast_strlen_zero(transport_name)) { |
| 289 |
ast_sip_service_route_vector_destroy(service_routes); |
| 290 |
return 0; |
| 291 |
} |
| 292 |
|
| 293 |
transport_state = ast_sip_get_transport_state(transport_name); |
| 294 |
if (!transport_state) { |
| 295 |
ast_sip_service_route_vector_destroy(service_routes); |
| 296 |
return -1; |
| 297 |
} |
| 298 |
|
| 299 |
if (!transport_state->flow) { |
| 300 |
ao2_ref(transport_state, -1); |
| 301 |
ast_sip_service_route_vector_destroy(service_routes); |
| 302 |
return 0; |
| 303 |
} |
| 304 |
|
| 305 |
ao2_lock(transport_state); |
| 306 |
ast_sip_service_route_vector_destroy(transport_state->service_routes); |
| 307 |
transport_state->service_routes = service_routes; |
| 308 |
ao2_unlock(transport_state); |
| 309 |
|
| 310 |
ao2_ref(transport_state, -1); |
| 311 |
|
| 312 |
return 0; |
| 313 |
} |
| 314 |
|
| 315 |
void ast_sip_message_apply_transport(const char *transport_name, pjsip_tx_data *tdata) |
| 316 |
{ |
| 317 |
struct ast_sip_transport_state *transport_state; |
| 318 |
|
| 319 |
if (ast_strlen_zero(transport_name)) { |
| 320 |
return; |
| 321 |
} |
| 322 |
|
| 323 |
|
| 324 |
|
| 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 |
|
| 346 |
if (transport_state->preferred_identity) { |
| 347 |
ast_sip_add_header(tdata, "P-Preferred-Identity", transport_state->preferred_identity); |
| 348 |
} |
| 349 |
|
| 350 |
|
| 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 |
} |
| 365 |
|
| 366 |
struct ast_sip_service_route_vector *ast_sip_service_route_vector_alloc(void) |
| 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 |
} |
| 379 |
|
| 380 |
void ast_sip_service_route_vector_destroy(struct ast_sip_service_route_vector *service_routes) |
| 381 |
{ |
| 382 |
if (!service_routes) { |
| 383 |
return; |
| 384 |
} |
| 385 |
|
| 386 |
AST_VECTOR_CALLBACK_VOID(service_routes, ast_free); |
| 387 |
ast_free(service_routes); |
| 388 |
} |
| 389 |
|
| 390 |
static void set_qos(struct ast_sip_transport *transport, pj_qos_params *qos) |
| 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 |
} |
| 403 |
|
| 404 |
|
| 405 |
static void sip_transport_destroy(void *obj) |
| 406 |
{ |
| 407 |
struct ast_sip_transport *transport = obj; |
| 408 |
|
| 409 |
ast_string_field_free_memory(transport); |
| 410 |
} |
| 411 |
|
| 412 |
|
| 413 |
static void *sip_transport_alloc(const char *name) |
| 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 |
} |
| 428 |
|
| 429 |
static int destroy_sip_transport_state(void *data) |
| 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) { |
| 437 |
ast_dnsmgr_release(transport_state->external_signaling_address_refresher); |
| 438 |
} |
| 439 |
if (transport_state->external_media_address_refresher) { |
| 440 |
ast_dnsmgr_release(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 |
} |
| 448 |
|
| 449 |
|
| 450 |
static void sip_transport_state_destroy(void *obj) |
| 451 |
{ |
| 452 |
struct ast_sip_transport_state *state = obj; |
| 453 |
|
| 454 |
ast_sip_push_task_wait_servant(NULL, destroy_sip_transport_state, state); |
| 455 |
} |
| 456 |
|
| 457 |
|
| 458 |
static void internal_state_destroy(void *obj) |
| 459 |
{ |
| 460 |
struct internal_state *state = obj; |
| 461 |
|
| 462 |
ast_free(state->id); |
| 463 |
ao2_cleanup(state->transport); |
| 464 |
ao2_cleanup(state->state); |
| 465 |
} |
| 466 |
|
| 467 |
static struct internal_state *find_internal_state_by_transport(const struct ast_sip_transport *transport) |
| 468 |
{ |
| 469 |
const char *key = ast_sorcery_object_get_id(transport); |
| 470 |
|
| 471 |
return ao2_find(transport_states, key, OBJ_SEARCH_KEY | OBJ_NOLOCK); |
| 472 |
} |
| 473 |
|
| 474 |
static struct ast_sip_transport_state *find_state_by_transport(const struct ast_sip_transport *transport) |
| 475 |
{ |
| 476 |
struct internal_state *state; |
| 477 |
struct ast_sip_transport_state *trans_state; |
| 478 |
|
| 479 |
state = find_internal_state_by_transport(transport); |
| 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 |
} |
| 488 |
|
| 489 |
static int remove_temporary_state(void) |
| 490 |
{ |
| 491 |
struct ast_sip_transport_state **state; |
| 492 |
|
| 493 |
state = ast_threadstorage_get(&temp_state_store, sizeof(state)); |
| 494 |
if (!state) { |
| 495 |
return -1; |
| 496 |
} |
| 497 |
|
| 498 |
ao2_cleanup(*state); |
| 499 |
*state = NULL; |
| 500 |
return 0; |
| 501 |
} |
| 502 |
|
| 503 |
static struct ast_sip_transport_state *find_temporary_state(struct ast_sip_transport *transport) |
| 504 |
{ |
| 505 |
struct ast_sip_transport_state **state; |
| 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 |
} |
| 515 |
|
| 516 |
static struct internal_state *internal_state_alloc(struct ast_sip_transport *transport) |
| 517 |
{ |
| 518 |
struct internal_state *internal_state; |
| 519 |
|
| 520 |
internal_state = ao2_alloc(sizeof(*internal_state), internal_state_destroy); |
| 521 |
if (!internal_state) { |
| 522 |
return NULL; |
| 523 |
} |
| 524 |
|
| 525 |
internal_state->id = ast_strdup(ast_sorcery_object_get_id(transport)); |
| 526 |
if (!internal_state->id) { |
| 527 |
ao2_cleanup(internal_state); |
| 528 |
return NULL; |
| 529 |
} |
| 530 |
|
| 531 |
|
| 532 |
internal_state->state = find_temporary_state(transport); |
| 533 |
if (!internal_state->state) { |
| 534 |
ao2_cleanup(internal_state); |
| 535 |
return NULL; |
| 536 |
} |
| 537 |
internal_state->transport = ao2_bump(transport); |
| 538 |
internal_state->transport->state = internal_state->state; |
| 539 |
remove_temporary_state(); |
| 540 |
|
| 541 |
return internal_state; |
| 542 |
} |
| 543 |
|
| 544 |
|
| 545 |
|
| 546 |
|
| 547 |
|
| 548 |
static struct ast_sip_transport_state *find_or_create_temporary_state(struct ast_sip_transport *transport) |
| 549 |
{ |
| 550 |
struct ast_sip_transport_state **state; |
| 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 |
} |
| 566 |
new_state->id = ast_strdup(ast_sorcery_object_get_id(transport)); |
| 567 |
new_state->type = transport->type; |
| 568 |
|
| 569 |
pjsip_tls_setting_default(&new_state->tls); |
| 570 |
#ifdef HAVE_PJSIP_TLS_TRANSPORT_PROTO |
| 571 |
|
| 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 |
} |
| 581 |
|
| 582 |
static void copy_state_to_transport(struct ast_sip_transport *transport) |
| 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; |
| 590 |
transport->external_address_refresher = transport->state->external_signaling_address_refresher; |
| 591 |
memcpy(&transport->external_address, &transport->state->external_signaling_address, sizeof(transport->external_signaling_address)); |
| 592 |
} |
| 593 |
|
| 594 |
#ifdef HAVE_PJSIP_TLS_TRANSPORT_RESTART |
| 595 |
static int file_stat_cmp(const struct stat *old_stat, const struct stat *new_stat) |
| 596 |
{ |
| 597 |
return old_stat->st_size != new_stat->st_size |
| 598 |
|| old_stat->st_mtime != new_stat->st_mtime |
| 599 |
#if defined(HAVE_STRUCT_STAT_ST_MTIM) |
| 600 |
|| old_stat->st_mtim.tv_nsec != new_stat->st_mtim.tv_nsec |
| 601 |
#elif defined(HAVE_STRUCT_STAT_ST_MTIMENSEC) |
| 602 |
|| old_stat->st_mtimensec != new_stat->st_mtimensec |
| 603 |
#elif defined(HAVE_STRUCT_STAT_ST_MTIMESPEC) |
| 604 |
|| old_stat->st_mtimespec.tv_nsec != new_stat->st_mtimespec.tv_nsec |
| 605 |
#endif |
| 606 |
; |
| 607 |
} |
| 608 |
#endif |
| 609 |
|
| 610 |
static int has_state_changed(struct ast_sip_transport_state *a, struct ast_sip_transport_state *b) |
| 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 |
} |
| 659 |
|
| 660 |
static void states_cleanup(void *states) |
| 661 |
{ |
| 662 |
if (states) { |
| 663 |
ao2_unlock(states); |
| 664 |
} |
| 665 |
} |
| 666 |
|
| 667 |
|
| 668 |
static int transport_apply(const struct ast_sorcery *sorcery, void *obj) |
| 669 |
{ |
| 670 |
struct ast_sip_transport *transport = obj; |
| 671 |
const char *transport_id = ast_sorcery_object_get_id(obj); |
| 672 |
RAII_VAR(struct ao2_container *, states, transport_states, states_cleanup); |
| 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 |
|
| 687 |
|
| 688 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 736 |
if (!ast_strlen_zero(transport->external_signaling_address)) { |
| 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 |
|
| 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 |
|
| 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 |
|
| 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", |
| 862 |
ast_sorcery_object_get_id(obj), transport->tcp_keepalive_idle_time, transport->tcp_keepalive_interval_time, transport->tcp_keepalive_probe_count); |
| 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", |
| 889 |
ast_sorcery_object_get_id(obj)); |
| 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", |
| 912 |
ast_sorcery_object_get_id(obj)); |
| 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 |
|
| 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", |
| 929 |
ast_sorcery_object_get_id(obj), transport->tcp_keepalive_idle_time, transport->tcp_keepalive_interval_time, transport->tcp_keepalive_probe_count); |
| 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", |
| 956 |
ast_sorcery_object_get_id(obj)); |
| 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 |
|
| 977 |
|
| 978 |
|
| 979 |
temp_state->state->factory->info = pj_pool_alloc( |
| 980 |
temp_state->state->factory->pool, (MAX(MAX_OBJECT_FIELD, 100) + 1)); |
| 981 |
|
| 982 |
|
| 983 |
|
| 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", |
| 989 |
ast_sorcery_object_get_id(obj)); |
| 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 |
} |
| 1018 |
|
| 1019 |
|
| 1020 |
static int transport_state_init(const struct aco_option *opt, struct ast_variable *var, void *obj) |
| 1021 |
{ |
| 1022 |
struct ast_sip_transport *transport = obj; |
| 1023 |
struct ast_sip_transport_state *state = find_or_create_temporary_state(transport); |
| 1024 |
|
| 1025 |
ao2_cleanup(state); |
| 1026 |
|
| 1027 |
return 0; |
| 1028 |
} |
| 1029 |
|
| 1030 |
|
| 1031 |
static int transport_tls_file_handler(const struct aco_option *opt, struct ast_variable *var, void *obj) |
| 1032 |
{ |
| 1033 |
struct ast_sip_transport *transport = obj; |
| 1034 |
RAII_VAR(struct ast_sip_transport_state *, state, find_or_create_temporary_state(transport), ao2_cleanup); |
| 1035 |
|
| 1036 |
if (!state) { |
| 1037 |
return -1; |
| 1038 |
} |
| 1039 |
|
| 1040 |
if (ast_strlen_zero(var->value)) { |
| 1041 |
|
| 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); |
| 1048 |
remove_temporary_state(); |
| 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)); |
| 1070 |
remove_temporary_state(); |
| 1071 |
return -1; |
| 1072 |
} |
| 1073 |
ast_sorcery_object_set_has_dynamic_contents(transport); |
| 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)); |
| 1082 |
remove_temporary_state(); |
| 1083 |
return -1; |
| 1084 |
} |
| 1085 |
ast_sorcery_object_set_has_dynamic_contents(transport); |
| 1086 |
#endif |
| 1087 |
} |
| 1088 |
|
| 1089 |
return 0; |
| 1090 |
} |
| 1091 |
|
| 1092 |
static int ca_list_file_to_str(const void *obj, const intptr_t *args, char **buf) |
| 1093 |
{ |
| 1094 |
const struct ast_sip_transport *transport = obj; |
| 1095 |
|
| 1096 |
*buf = ast_strdup(transport->ca_list_file); |
| 1097 |
|
| 1098 |
return 0; |
| 1099 |
} |
| 1100 |
|
| 1101 |
static int ca_list_path_to_str(const void *obj, const intptr_t *args, char **buf) |
| 1102 |
{ |
| 1103 |
const struct ast_sip_transport *transport = obj; |
| 1104 |
|
| 1105 |
*buf = ast_strdup(transport->ca_list_path); |
| 1106 |
|
| 1107 |
return 0; |
| 1108 |
} |
| 1109 |
|
| 1110 |
static int cert_file_to_str(const void *obj, const intptr_t *args, char **buf) |
| 1111 |
{ |
| 1112 |
const struct ast_sip_transport *transport = obj; |
| 1113 |
|
| 1114 |
*buf = ast_strdup(transport->cert_file); |
| 1115 |
|
| 1116 |
return 0; |
| 1117 |
} |
| 1118 |
|
| 1119 |
static int privkey_file_to_str(const void *obj, const intptr_t *args, char **buf) |
| 1120 |
{ |
| 1121 |
const struct ast_sip_transport *transport = obj; |
| 1122 |
|
| 1123 |
*buf = ast_strdup(transport->privkey_file); |
| 1124 |
|
| 1125 |
return 0; |
| 1126 |
} |
| 1127 |
|
| 1128 |
|
| 1129 |
static int transport_protocol_handler(const struct aco_option *opt, struct ast_variable *var, void *obj) |
| 1130 |
{ |
| 1131 |
struct ast_sip_transport *transport = obj; |
| 1132 |
RAII_VAR(struct ast_sip_transport_state *, state, find_or_create_temporary_state(transport), ao2_cleanup); |
| 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 { |
| 1152 |
remove_temporary_state(); |
| 1153 |
return -1; |
| 1154 |
} |
| 1155 |
transport->flow = 0; |
| 1156 |
} |
| 1157 |
|
| 1158 |
state->type = transport->type; |
| 1159 |
|
| 1160 |
return 0; |
| 1161 |
} |
| 1162 |
|
| 1163 |
static const char *transport_types[] = { |
| 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 |
}; |
| 1170 |
|
| 1171 |
static int transport_protocol_to_str(const void *obj, const intptr_t *args, char **buf) |
| 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 |
} |
| 1183 |
|
| 1184 |
|
| 1185 |
static int transport_bind_handler(const struct aco_option *opt, struct ast_variable *var, void *obj) |
| 1186 |
{ |
| 1187 |
struct ast_sip_transport *transport = obj; |
| 1188 |
pj_str_t buf; |
| 1189 |
int rc; |
| 1190 |
RAII_VAR(struct ast_sip_transport_state *, state, find_or_create_temporary_state(transport), ao2_cleanup); |
| 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) { |
| 1198 |
remove_temporary_state(); |
| 1199 |
} |
| 1200 |
return rc != PJ_SUCCESS ? -1 : 0; |
| 1201 |
} |
| 1202 |
|
| 1203 |
static int transport_bind_to_str(const void *obj, const intptr_t *args, char **buf) |
| 1204 |
{ |
| 1205 |
const struct ast_sip_transport *transport = obj; |
| 1206 |
RAII_VAR(struct ast_sip_transport_state *, state, find_state_by_transport(transport), ao2_cleanup); |
| 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 |
|
| 1217 |
pj_sockaddr_print(&state->host, *buf, MAX_OBJECT_FIELD, 1 | 2); |
| 1218 |
|
| 1219 |
return 0; |
| 1220 |
} |
| 1221 |
|
| 1222 |
|
| 1223 |
static int transport_tls_bool_handler(const struct aco_option *opt, struct ast_variable *var, void *obj) |
| 1224 |
{ |
| 1225 |
struct ast_sip_transport *transport = obj; |
| 1226 |
RAII_VAR(struct ast_sip_transport_state *, state, find_or_create_temporary_state(transport), ao2_cleanup); |
| 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 { |
| 1241 |
remove_temporary_state(); |
| 1242 |
return -1; |
| 1243 |
} |
| 1244 |
|
| 1245 |
return 0; |
| 1246 |
} |
| 1247 |
|
| 1248 |
static int verify_server_to_str(const void *obj, const intptr_t *args, char **buf) |
| 1249 |
{ |
| 1250 |
const struct ast_sip_transport *transport = obj; |
| 1251 |
RAII_VAR(struct ast_sip_transport_state *, state, find_state_by_transport(transport), ao2_cleanup); |
| 1252 |
|
| 1253 |
if (!state) { |
| 1254 |
return -1; |
| 1255 |
} |
| 1256 |
|
| 1257 |
*buf = ast_strdup(AST_YESNO(state->verify_server)); |
| 1258 |
|
| 1259 |
return 0; |
| 1260 |
} |
| 1261 |
|
| 1262 |
static int verify_client_to_str(const void *obj, const intptr_t *args, char **buf) |
| 1263 |
{ |
| 1264 |
const struct ast_sip_transport *transport = obj; |
| 1265 |
RAII_VAR(struct ast_sip_transport_state *, state, find_state_by_transport(transport), ao2_cleanup); |
| 1266 |
|
| 1267 |
if (!state) { |
| 1268 |
return -1; |
| 1269 |
} |
| 1270 |
|
| 1271 |
*buf = ast_strdup(AST_YESNO(state->tls.verify_client)); |
| 1272 |
|
| 1273 |
return 0; |
| 1274 |
} |
| 1275 |
|
| 1276 |
static int require_client_cert_to_str(const void *obj, const intptr_t *args, char **buf) |
| 1277 |
{ |
| 1278 |
const struct ast_sip_transport *transport = obj; |
| 1279 |
RAII_VAR(struct ast_sip_transport_state *, state, find_state_by_transport(transport), ao2_cleanup); |
| 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 |
} |
| 1289 |
|
| 1290 |
static int allow_wildcard_certs_to_str(const void *obj, const intptr_t *args, char **buf) |
| 1291 |
{ |
| 1292 |
struct ast_sip_transport_state *state = find_state_by_transport(obj); |
| 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 |
} |
| 1303 |
|
| 1304 |
|
| 1305 |
static int transport_tls_method_handler(const struct aco_option *opt, struct ast_variable *var, void *obj) |
| 1306 |
{ |
| 1307 |
struct ast_sip_transport *transport = obj; |
| 1308 |
RAII_VAR(struct ast_sip_transport_state *, state, find_or_create_temporary_state(transport), ao2_cleanup); |
| 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 { |
| 1339 |
remove_temporary_state(); |
| 1340 |
return -1; |
| 1341 |
} |
| 1342 |
|
| 1343 |
return 0; |
| 1344 |
} |
| 1345 |
|
| 1346 |
static const char *tls_method_map[] = { |
| 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 |
}; |
| 1362 |
|
| 1363 |
static int tls_method_to_str(const void *obj, const intptr_t *args, char **buf) |
| 1364 |
{ |
| 1365 |
const struct ast_sip_transport *transport = obj; |
| 1366 |
RAII_VAR(struct ast_sip_transport_state *, state, find_state_by_transport(transport), ao2_cleanup); |
| 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 |
} |
| 1378 |
|
| 1379 |
#if defined(PJ_HAS_SSL_SOCK) && PJ_HAS_SSL_SOCK != 0 |
| 1380 |
|
| 1381 |
static pj_ssl_cipher cipher_name_to_id(const char *name) |
| 1382 |
{ |
| 1383 |
pj_ssl_cipher ciphers[PJ_SSL_SOCK_MAX_CIPHERS]; |
| 1384 |
unsigned int cipher_num = PJ_ARRAY_SIZE(ciphers); |
| 1385 |
unsigned int pos; |
| 1386 |
|
| 1387 |
if (pj_ssl_cipher_get_availables(ciphers, &cipher_num)) { |
| 1388 |
return 0; |
| 1389 |
} |
| 1390 |
|
| 1391 |
for (pos = 0; pos < cipher_num; ++pos) { |
| 1392 |
const char *pos_name = pj_ssl_cipher_name(ciphers[pos]); |
| 1393 |
if (pos_name && !strcmp(pos_name, name)) { |
| 1394 |
return ciphers[pos]; |
| 1395 |
} |
| 1396 |
} |
| 1397 |
|
| 1398 |
return 0; |
| 1399 |
} |
| 1400 |
#endif |
| 1401 |
|
| 1402 |
#if defined(PJ_HAS_SSL_SOCK) && PJ_HAS_SSL_SOCK != 0 |
| 1403 |
|
| 1404 |
|
| 1405 |
|
| 1406 |
|
| 1407 |
|
| 1408 |
|
| 1409 |
|
| 1410 |
|
| 1411 |
|
| 1412 |
|
| 1413 |
static int transport_cipher_add(struct ast_sip_transport_state *state, const char *name) |
| 1414 |
{ |
| 1415 |
pj_ssl_cipher cipher; |
| 1416 |
int idx; |
| 1417 |
|
| 1418 |
cipher = cipher_name_to_id(name); |
| 1419 |
if (!cipher) { |
| 1420 |
|
| 1421 |
if (!strnicmp(name, "0x", 2)) { |
| 1422 |
pj_str_t cipher_st = pj_str((char *) name + 2); |
| 1423 |
cipher = pj_strtoul2(&cipher_st, NULL, 16); |
| 1424 |
} else { |
| 1425 |
cipher = atoi(name); |
| 1426 |
} |
| 1427 |
} |
| 1428 |
|
| 1429 |
if (pj_ssl_cipher_is_supported(cipher)) { |
| 1430 |
for (idx = state->tls.ciphers_num; idx--;) { |
| 1431 |
if (state->ciphers[idx] == cipher) { |
| 1432 |
|
| 1433 |
return 0; |
| 1434 |
} |
| 1435 |
} |
| 1436 |
state->ciphers[state->tls.ciphers_num++] = cipher; |
| 1437 |
return 0; |
| 1438 |
} else { |
| 1439 |
ast_log(LOG_ERROR, "Cipher '%s' is unsupported\n", name); |
| 1440 |
return -1; |
| 1441 |
} |
| 1442 |
} |
| 1443 |
#endif |
| 1444 |
|
| 1445 |
#if defined(PJ_HAS_SSL_SOCK) && PJ_HAS_SSL_SOCK != 0 |
| 1446 |
|
| 1447 |
static int transport_tls_cipher_handler(const struct aco_option *opt, struct ast_variable *var, void *obj) |
| 1448 |
{ |
| 1449 |
struct ast_sip_transport *transport = obj; |
| 1450 |
char *parse; |
| 1451 |
char *name; |
| 1452 |
int res = 0; |
| 1453 |
RAII_VAR(struct ast_sip_transport_state *, state, find_or_create_temporary_state(transport), ao2_cleanup); |
| 1454 |
|
| 1455 |
if (!state) { |
| 1456 |
return -1; |
| 1457 |
} |
| 1458 |
|
| 1459 |
parse = ast_strdupa(S_OR(var->value, "")); |
| 1460 |
while ((name = ast_strip(strsep(&parse, ",")))) { |
| 1461 |
if (ast_strlen_zero(name)) { |
| 1462 |
continue; |
| 1463 |
} |
| 1464 |
if (ARRAY_LEN(state->ciphers) <= state->tls.ciphers_num) { |
| 1465 |
ast_log(LOG_ERROR, "Too many ciphers specified (maximum allowed is %d)\n", SIP_TLS_MAX_CIPHERS); |
| 1466 |
res = -1; |
| 1467 |
break; |
| 1468 |
} |
| 1469 |
res |= transport_cipher_add(state, name); |
| 1470 |
} |
| 1471 |
|
| 1472 |
if (res) { |
| 1473 |
remove_temporary_state(); |
| 1474 |
} |
| 1475 |
return res ? -1 : 0; |
| 1476 |
} |
| 1477 |
#endif |
| 1478 |
|
| 1479 |
#if defined(PJ_HAS_SSL_SOCK) && PJ_HAS_SSL_SOCK != 0 |
| 1480 |
static void cipher_to_str(char **buf, const pj_ssl_cipher *ciphers, unsigned int cipher_num) |
| 1481 |
{ |
| 1482 |
struct ast_str *str; |
| 1483 |
unsigned int idx; |
| 1484 |
|
| 1485 |
str = ast_str_create(128); |
| 1486 |
if (!str) { |
| 1487 |
*buf = NULL; |
| 1488 |
return; |
| 1489 |
} |
| 1490 |
|
| 1491 |
for (idx = 0; idx < cipher_num; ++idx) { |
| 1492 |
ast_str_append(&str, 0, "%s", pj_ssl_cipher_name(ciphers[idx])); |
| 1493 |
if (idx < cipher_num - 1) { |
| 1494 |
ast_str_append(&str, 0, ", "); |
| 1495 |
} |
| 1496 |
} |
| 1497 |
|
| 1498 |
*buf = ast_strdup(ast_str_buffer(str)); |
| 1499 |
ast_free(str); |
| 1500 |
} |
| 1501 |
#endif |
| 1502 |
|
| 1503 |
#if defined(PJ_HAS_SSL_SOCK) && PJ_HAS_SSL_SOCK != 0 |
| 1504 |
static int transport_tls_cipher_to_str(const void *obj, const intptr_t *args, char **buf) |
| 1505 |
{ |
| 1506 |
const struct ast_sip_transport *transport = obj; |
| 1507 |
RAII_VAR(struct ast_sip_transport_state *, state, find_state_by_transport(transport), ao2_cleanup); |
| 1508 |
|
| 1509 |
if (!state) { |
| 1510 |
return -1; |
| 1511 |
} |
| 1512 |
|
| 1513 |
cipher_to_str(buf, state->ciphers, state->tls.ciphers_num); |
| 1514 |
return *buf ? 0 : -1; |
| 1515 |
} |
| 1516 |
#endif |
| 1517 |
|
| 1518 |
#if defined(PJ_HAS_SSL_SOCK) && PJ_HAS_SSL_SOCK != 0 |
| 1519 |
static char *handle_pjsip_list_ciphers(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| 1520 |
{ |
| 1521 |
pj_ssl_cipher ciphers[PJ_SSL_SOCK_MAX_CIPHERS]; |
| 1522 |
unsigned int cipher_num = PJ_ARRAY_SIZE(ciphers); |
| 1523 |
char *buf; |
| 1524 |
|
| 1525 |
switch (cmd) { |
| 1526 |
case CLI_INIT: |
| 1527 |
e->command = "pjsip list ciphers"; |
| 1528 |
e->usage = "Usage: pjsip list ciphers\n" |
| 1529 |
" List available OpenSSL cipher names.\n"; |
| 1530 |
return NULL; |
| 1531 |
case CLI_GENERATE: |
| 1532 |
return NULL; |
| 1533 |
} |
| 1534 |
|
| 1535 |
if (pj_ssl_cipher_get_availables(ciphers, &cipher_num) || !cipher_num) { |
| 1536 |
buf = NULL; |
| 1537 |
} else { |
| 1538 |
cipher_to_str(&buf, ciphers, cipher_num); |
| 1539 |
} |
| 1540 |
|
| 1541 |
if (!ast_strlen_zero(buf)) { |
| 1542 |
ast_cli(a->fd, "Available ciphers: '%s'\n", buf); |
| 1543 |
} else { |
| 1544 |
ast_cli(a->fd, "No available ciphers\n"); |
| 1545 |
} |
| 1546 |
ast_free(buf); |
| 1547 |
return CLI_SUCCESS; |
| 1548 |
} |
| 1549 |
#endif |
| 1550 |
|
| 1551 |
|
| 1552 |
static int transport_localnet_handler(const struct aco_option *opt, struct ast_variable *var, void *obj) |
| 1553 |
{ |
| 1554 |
struct ast_sip_transport *transport = obj; |
| 1555 |
int error = 0; |
| 1556 |
RAII_VAR(struct ast_sip_transport_state *, state, find_or_create_temporary_state(transport), ao2_cleanup); |
| 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 |
|
| 1569 |
|
| 1570 |
if (!(state->localnet = ast_append_ha("deny", var->value, state->localnet, &error))) { |
| 1571 |
remove_temporary_state(); |
| 1572 |
return -1; |
| 1573 |
} |
| 1574 |
|
| 1575 |
return error; |
| 1576 |
} |
| 1577 |
|
| 1578 |
static void localnet_to_vl_append(struct ast_variable **head, struct ast_ha *ha) |
| 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 |
} |
| 1587 |
|
| 1588 |
static int localnet_to_vl(const void *obj, struct ast_variable **fields) |
| 1589 |
{ |
| 1590 |
const struct ast_sip_transport *transport = obj; |
| 1591 |
struct ast_variable *head = NULL; |
| 1592 |
struct ast_ha *ha; |
| 1593 |
RAII_VAR(struct ast_sip_transport_state *, state, find_state_by_transport(transport), ao2_cleanup); |
| 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 |
} |
| 1609 |
|
| 1610 |
static int localnet_to_str(const void *obj, const intptr_t *args, char **buf) |
| 1611 |
{ |
| 1612 |
RAII_VAR(struct ast_str *, str, ast_str_create(MAX_OBJECT_FIELD), ast_free); |
| 1613 |
const struct ast_sip_transport *transport = obj; |
| 1614 |
RAII_VAR(struct ast_sip_transport_state *, state, find_state_by_transport(transport), ao2_cleanup); |
| 1615 |
|
| 1616 |
if (!state) { |
| 1617 |
return -1; |
| 1618 |
} |
| 1619 |
|
| 1620 |
ast_ha_join(state->localnet, &str); |
| 1621 |
*buf = ast_strdup(ast_str_buffer(str)); |
| 1622 |
return 0; |
| 1623 |
} |
| 1624 |
|
| 1625 |
|
| 1626 |
static int transport_tos_handler(const struct aco_option *opt, struct ast_variable *var, void *obj) |
| 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); |
| 1635 |
remove_temporary_state(); |
| 1636 |
return -1; |
| 1637 |
} |
| 1638 |
|
| 1639 |
if (value % 4) { |
| 1640 |
value = value >> 2; |
| 1641 |
value = value << 2; |
| 1642 |
ast_log(LOG_WARNING, |
| 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 |
} |
| 1651 |
|
| 1652 |
static int tos_to_str(const void *obj, const intptr_t *args, char **buf) |
| 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 |
} |
| 1661 |
|
| 1662 |
static struct ao2_container *cli_get_container(const char *regex) |
| 1663 |
{ |
| 1664 |
RAII_VAR(struct ao2_container *, container, NULL, ao2_cleanup); |
| 1665 |
struct ao2_container *s_container; |
| 1666 |
|
| 1667 |
container = ast_sorcery_retrieve_by_regex(ast_sip_get_sorcery(), "transport", |
| 1668 |
regex); |
| 1669 |
if (!container) { |
| 1670 |
return NULL; |
| 1671 |
} |
| 1672 |
|
| 1673 |
s_container = ao2_container_alloc_list(AO2_ALLOC_OPT_LOCK_NOLOCK, 0, |
| 1674 |
ast_sorcery_object_id_sort, ast_sorcery_object_id_compare); |
| 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 |
} |
| 1686 |
|
| 1687 |
static int cli_iterate(void *container, ao2_callback_fn callback, void *args) |
| 1688 |
{ |
| 1689 |
const struct ast_sip_endpoint *endpoint = container; |
| 1690 |
struct ast_sip_transport *transport = ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(), |
| 1691 |
"transport", endpoint->transport); |
| 1692 |
|
| 1693 |
if (!transport) { |
| 1694 |
return -1; |
| 1695 |
} |
| 1696 |
|
| 1697 |
return callback(transport, args, 0); |
| 1698 |
} |
| 1699 |
|
| 1700 |
static void *cli_retrieve_by_id(const char *id) |
| 1701 |
{ |
| 1702 |
return ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(), "transport", id); |
| 1703 |
} |
| 1704 |
|
| 1705 |
static int cli_print_header(void *obj, void *arg, int flags) |
| 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 |
} |
| 1719 |
|
| 1720 |
static int cli_print_body(void *obj, void *arg, int flags) |
| 1721 |
{ |
| 1722 |
struct ast_sip_transport *transport = obj; |
| 1723 |
struct ast_sip_cli_context *context = arg; |
| 1724 |
char hoststr[PJ_INET6_ADDRSTRLEN]; |
| 1725 |
RAII_VAR(struct ast_sip_transport_state *, state, find_state_by_transport(transport), ao2_cleanup); |
| 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 |
} |
| 1749 |
|
| 1750 |
static struct ast_cli_entry cli_commands[] = { |
| 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 |
}; |
| 1769 |
|
| 1770 |
static struct ast_sip_cli_formatter_entry *cli_formatter; |
| 1771 |
|
| 1772 |
struct ast_sip_transport_state *ast_sip_get_transport_state(const char *transport_id) |
| 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 |
|
| 1781 |
state = ao2_find(transport_states, transport_id, OBJ_SEARCH_KEY); |
| 1782 |
if (!state) { |
| 1783 |
return NULL; |
| 1784 |
} |
| 1785 |
|
| 1786 |
trans_state = ao2_bump(state->state); |
| 1787 |
ao2_ref(state, -1); |
| 1788 |
|
| 1789 |
|
| 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 |
} |
| 1801 |
|
| 1802 |
static int populate_transport_states(void *obj, void *arg, int flags) |
| 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 |
} |
| 1811 |
|
| 1812 |
struct ao2_container *ast_sip_get_transport_states(void) |
| 1813 |
{ |
| 1814 |
struct ao2_container *states = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_MUTEX, 0, |
| 1815 |
DEFAULT_STATE_BUCKETS, transport_state_hash, NULL, transport_state_cmp); |
| 1816 |
|
| 1817 |
if (!states) { |
| 1818 |
return NULL; |
| 1819 |
} |
| 1820 |
|
| 1821 |
ao2_callback(transport_states, OBJ_NODATA | OBJ_MULTIPLE, populate_transport_states, states); |
| 1822 |
return states; |
| 1823 |
} |
| 1824 |
|
| 1825 |
|
| 1826 |
int ast_sip_initialize_sorcery_transport(void) |
| 1827 |
{ |
| 1828 |
struct ast_sorcery *sorcery = ast_sip_get_sorcery(); |
| 1829 |
struct ao2_container *transports = NULL; |
| 1830 |
|
| 1831 |
|
| 1832 |
transport_states = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_MUTEX, 0, |
| 1833 |
DEFAULT_STATE_BUCKETS, internal_state_hash, NULL, internal_state_cmp); |
| 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 |
|
| 1841 |
if (ast_sorcery_object_register(sorcery, "transport", sip_transport_alloc, NULL, transport_apply)) { |
| 1842 |
return -1; |
| 1843 |
} |
| 1844 |
|
| 1845 |
|
| 1846 |
ast_sorcery_object_field_register_custom(sorcery, "transport", "type", "", transport_state_init, NULL, NULL, 0, 0); |
| 1847 |
ast_sorcery_object_field_register_custom(sorcery, "transport", "protocol", "udp", transport_protocol_handler, transport_protocol_to_str, NULL, 0, 0); |
| 1848 |
ast_sorcery_object_field_register_custom(sorcery, "transport", "bind", "", transport_bind_handler, transport_bind_to_str, NULL, 0, 0); |
| 1849 |
ast_sorcery_object_field_register(sorcery, "transport", "async_operations", "1", OPT_UINT_T, 0, FLDSET(struct ast_sip_transport, async_operations)); |
| 1850 |
|
| 1851 |
ast_sorcery_object_field_register_custom(sorcery, "transport", "ca_list_file", "", transport_tls_file_handler, ca_list_file_to_str, NULL, 0, 0); |
| 1852 |
ast_sorcery_object_field_register_custom(sorcery, "transport", "ca_list_path", "", transport_tls_file_handler, ca_list_path_to_str, NULL, 0, 0); |
| 1853 |
ast_sorcery_object_field_register_custom(sorcery, "transport", "cert_file", "", transport_tls_file_handler, cert_file_to_str, NULL, 0, 0); |
| 1854 |
ast_sorcery_object_field_register_custom(sorcery, "transport", "priv_key_file", "", transport_tls_file_handler, privkey_file_to_str, NULL, 0, 0); |
| 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)); |
| 1861 |
ast_sorcery_object_field_register_custom(sorcery, "transport", "verify_server", "", transport_tls_bool_handler, verify_server_to_str, NULL, 0, 0); |
| 1862 |
ast_sorcery_object_field_register_custom(sorcery, "transport", "verify_client", "", transport_tls_bool_handler, verify_client_to_str, NULL, 0, 0); |
| 1863 |
ast_sorcery_object_field_register_custom(sorcery, "transport", "require_client_cert", "", transport_tls_bool_handler, require_client_cert_to_str, NULL, 0, 0); |
| 1864 |
ast_sorcery_object_field_register_custom(sorcery, "transport", "allow_wildcard_certs", "", transport_tls_bool_handler, allow_wildcard_certs_to_str, NULL, 0, 0); |
| 1865 |
ast_sorcery_object_field_register_custom(sorcery, "transport", "method", "", transport_tls_method_handler, tls_method_to_str, NULL, 0, 0); |
| 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 |
| 1873 |
ast_sorcery_object_field_register_custom(sorcery, "transport", "local_net", "", transport_localnet_handler, localnet_to_str, localnet_to_vl, 0, 0); |
| 1874 |
ast_sorcery_object_field_register_custom(sorcery, "transport", "tos", "0", transport_tos_handler, tos_to_str, NULL, 0, 0); |
| 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 |
|
| 1880 |
ast_sip_register_endpoint_formatter(&endpoint_transport_formatter); |
| 1881 |
|
| 1882 |
cli_formatter = ao2_alloc(sizeof(struct ast_sip_cli_formatter_entry), NULL); |
| 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"; |
| 1888 |
cli_formatter->print_header = cli_print_header; |
| 1889 |
cli_formatter->print_body = cli_print_body; |
| 1890 |
cli_formatter->get_container = cli_get_container; |
| 1891 |
cli_formatter->iterate = cli_iterate; |
| 1892 |
cli_formatter->get_id = ast_sorcery_object_get_id; |
| 1893 |
cli_formatter->retrieve_by_id = cli_retrieve_by_id; |
| 1894 |
|
| 1895 |
ast_sip_register_cli_formatter(cli_formatter); |
| 1896 |
ast_cli_register_multiple(cli_commands, ARRAY_LEN(cli_commands)); |
| 1897 |
|
| 1898 |
|
| 1899 |
transports = ast_sorcery_retrieve_by_fields(sorcery, "transport", AST_RETRIEVE_FLAG_ALL | AST_RETRIEVE_FLAG_MULTIPLE, NULL); |
| 1900 |
ao2_cleanup(transports); |
| 1901 |
|
| 1902 |
return 0; |
| 1903 |
} |
| 1904 |
|
| 1905 |
int ast_sip_destroy_sorcery_transport(void) |
| 1906 |
{ |
| 1907 |
ast_cli_unregister_multiple(cli_commands, ARRAY_LEN(cli_commands)); |
| 1908 |
ast_sip_unregister_cli_formatter(cli_formatter); |
| 1909 |
|
| 1910 |
ast_sip_unregister_endpoint_formatter(&endpoint_transport_formatter); |
| 1911 |
|
| 1912 |
ao2_ref(transport_states, -1); |
| 1913 |
transport_states = NULL; |
| 1914 |
|
| 1915 |
return 0; |
| 1916 |
} |