| 457 | } |
| 458 | |
| 459 | static enum clusterer_send_ret |
| 460 | clusterer_bcast_msg(bin_packet_t *packet, int dst_cid, |
| 461 | enum cl_node_match_op match_op, int check_cap) |
| 462 | { |
| 463 | node_info_t *node; |
| 464 | int rc, sent = 0, down = 1, matched_once = 0; |
| 465 | cluster_info_t *dst_cl; |
| 466 | int ev_actions_required = 0; |
| 467 | str capability; |
| 468 | |
| 469 | if (!cl_list_lock) { |
| 470 | LM_ERR("cluster shutdown - cannot send new messages!\n"); |
| 471 | return CLUSTERER_CURR_DISABLED; |
| 472 | } |
| 473 | |
| 474 | lock_start_read(cl_list_lock); |
| 475 | |
| 476 | dst_cl = get_cluster_by_id(dst_cid); |
| 477 | if (!dst_cl) { |
| 478 | LM_ERR("Unknown cluster, id [%d]\n", dst_cid); |
| 479 | lock_stop_read(cl_list_lock); |
| 480 | return CLUSTERER_SEND_ERR; |
| 481 | } |
| 482 | |
| 483 | lock_get(dst_cl->current_node->lock); |
| 484 | if (!(dst_cl->current_node->flags & NODE_STATE_ENABLED)) { |
| 485 | lock_release(dst_cl->current_node->lock); |
| 486 | lock_stop_read(cl_list_lock); |
| 487 | return CLUSTERER_CURR_DISABLED; |
| 488 | } |
| 489 | lock_release(dst_cl->current_node->lock); |
| 490 | |
| 491 | if (check_cap) { |
| 492 | bin_get_capability(packet, &capability); |
| 493 | rc = get_capability_status(dst_cl, &capability); |
| 494 | if (rc == -1) { |
| 495 | lock_stop_read(cl_list_lock); |
| 496 | return CLUSTERER_SEND_ERR; |
| 497 | } else if (rc == CAP_DISABLED) { |
| 498 | lock_stop_read(cl_list_lock); |
| 499 | LM_DBG("capability [%.*s] disabled, skip message sending\n", |
| 500 | capability.len, capability.s); |
| 501 | return CLUSTERER_SEND_SUCCESS; |
| 502 | } |
| 503 | } |
| 504 | |
| 505 | for (node = dst_cl->node_list; node; node = node->next) { |
| 506 | if (!match_node(dst_cl->current_node, node, match_op)) |
| 507 | continue; |
| 508 | |
| 509 | lock_get(node->lock); |
| 510 | if (!(node->flags & NODE_STATE_ENABLED)) { |
| 511 | lock_release(node->lock); |
| 512 | LM_DBG("node disabled, skip message sending\n"); |
| 513 | continue; |
| 514 | } |
| 515 | lock_release(node->lock); |
| 516 |
no test coverage detected