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 */
| 448 | * -4 - bad resources |
| 449 | */ |
| 450 | int 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 |
no test coverage detected