MCPcopy Create free account
hub / github.com/OpenSIPS/opensips / lb_route

Function lb_route

modules/load_balancer/lb_data.c:450–920  ·  view source on GitHub ↗

Performce the LB logic. It may return: * 0 - success * -1 - generic error * -2 - no capacity (destinations may exist) * -3 - no destination at all * -4 - bad resources */

Source from the content-addressed store, hash-verified

448 * -4 - bad resources
449 */
450int lb_route(struct sip_msg *req, int group, struct lb_res_str_list *rl,
451 unsigned int flags, struct lb_data *data, int reuse, str *attrs)
452{
453 /* resources for previous iteration */
454 static struct lb_resource **res_prev = NULL;
455 static unsigned int res_prev_size = 0;
456 /* resources for new iteration */
457 static struct lb_resource **res_new = NULL;
458 static unsigned int res_new_size = 0;
459 /* probed destinations bitmap */
460 static unsigned int *dst_bitmap = NULL;
461 static unsigned int bitmap_size = 0;
462 /* selected destinations buffer */
463 static struct lb_dst **dsts = NULL;
464 static unsigned int dsts_size = 0;
465
466 /* control vars */
467 struct lb_resource **res_cur;
468 int res_prev_n, res_new_n, res_cur_n;
469 struct lb_dst **dsts_cur;
470 struct lb_dst *last_dst, *dst;
471 unsigned int dsts_size_cur, dsts_size_max;
472 unsigned int *dst_bitmap_cur;
473 unsigned int bitmap_size_cur;
474 struct dlg_cell *dlg;
475
476 /* AVP related vars */
477 struct usr_avp *group_avp;
478 struct usr_avp *flags_avp;
479 struct usr_avp *mask_avp;
480 struct usr_avp *id_avp;
481 struct usr_avp *res_avp;
482 int_str group_val;
483 int_str flags_val;
484 int_str mask_val;
485 int_str id_val;
486 int_str res_val;
487
488 /* iterators, e.t.c. */
489 struct lb_dst *it_d;
490 struct lb_resource *it_r;
491 int load, it_l;
492 int i, j, cond, cnt_aval_dst;
493
494
495 /* init control vars state */
496 res_cur = NULL;
497 res_cur_n = res_prev_n = res_new_n = 0;
498 last_dst = dst = NULL;
499 dst_bitmap_cur = NULL;
500
501 /* search and fill new resources references if we should not reuse
502 previous iteration data */
503 if( !reuse ) {
504 res_new_n = rl->n;
505 /* adjust size of statically allocated buffer */
506 if( res_new_n > res_new_size ) {
507 res_new = (struct lb_resource **)pkg_realloc

Callers 2

do_lb_startFunction · 0.85
do_lb_nextFunction · 0.85

Calls 12

search_resource_strFunction · 0.85
search_first_avpFunction · 0.85
destroy_avpFunction · 0.85
search_next_avpFunction · 0.85
get_resource_by_nameFunction · 0.85
lock_getFunction · 0.85
get_dst_loadFunction · 0.85
lock_releaseFunction · 0.85
add_avpFunction · 0.85
destroy_avpsFunction · 0.85
add_avp_lastFunction · 0.85
set_dst_uriFunction · 0.85

Tested by

no test coverage detected