[sr-dev] [kamailio/kamailio] dispatcher: fix alog13 gateway selections (PR #3232)

Julien Chavanton notifications at github.com
Tue Sep 6 16:49:15 CEST 2022


<!-- Kamailio Pull Request Template -->

<!--
IMPORTANT:
  - for detailed contributing guidelines, read:
    https://github.com/kamailio/kamailio/blob/master/.github/CONTRIBUTING.md
  - pull requests must be done to master branch, unless they are backports
    of fixes from master branch to a stable branch
  - backports to stable branches must be done with 'git cherry-pick -x ...'
  - code is contributed under BSD for core and main components (tm, sl, auth, tls)
  - code is contributed GPLv2 or a compatible license for the other components
  - GPL code is contributed with OpenSSL licensing exception
-->

#### Pre-Submission Checklist
<!-- Go over all points below, and after creating the PR, tick all the checkboxes that apply -->
<!-- All points should be verified, otherwise, read the CONTRIBUTING guidelines from above-->
<!-- If you're unsure about any of these, don't hesitate to ask on sr-dev mailing list -->
- [x] Commit message has the format required by CONTRIBUTING guide
- [x] Commits are split per component (core, individual modules, libs, utils, ...)
- [x] Each component has a single commit (if not, squash them into one commit)
- [x] No commits to README files for modules (changes must be done to docbook files
in `doc/` subfolder, the README file is autogenerated)

#### Type Of Change
- [x] Small bug fix (non-breaking change which fixes an issue)

#### Checklist:
<!-- Go over all points below, and after creating the PR, tick the checkboxes that apply -->
- [x] PR should be backported to stable branches
- [x] Tested changes locally
- [ ] Related to issue #XXXX (replace XXXX with an open issue number)

#### Description
<!-- Describe your changes in detail -->

I found how the indexes could get mixed up between the call to ds_sorted_by_priority() and ds_manage_routes_fill_reordered_xavp() resulting in invalid gateway list selection. 


```
// TEST logs
I made some tests with 3 and 6 gateways, disabling one and then two.

Some test data :

INSERT INTO dispatcher VALUES(1,1,'sip:[192.168.0.1:5060](http://192.168.0.1:5060/)',0,12,'','');
INSERT INTO dispatcher VALUES(2,1,'sip:[192.168.0.2:5060](http://192.168.0.2:5060/)',0,12,'','');
INSERT INTO dispatcher VALUES(3,1,'sip:[192.168.0.3:5060](http://192.168.0.3:5060/)',0,12,'','');
INSERT INTO dispatcher VALUES(4,1,'sip:[192.168.0.4:5060](http://192.168.0.4:5060/)',0,12,'','');
INSERT INTO dispatcher VALUES(5,1,'sip:[192.168.0.5:5060](http://192.168.0.5:5060/)',0,12,'','');
INSERT INTO dispatcher VALUES(6,1,'sip:[192.168.0.6:5060](http://192.168.0.6:5060/)',0,12,'','');

Then disabling 2 gateways :

dispatcher.set_state i 1 sip:[192.168.0.1:5060](http://192.168.0.1:5060/)
dispatcher.set_state i 1 sip:[192.168.0.3:5060](http://192.168.0.3:5060/)


// ----------------- Routing Logic -----------------
//
route {
        xinfo("[MAIN][$rm][$ci]from[$fU]to[$tU]ruri[$ru]Rp[$Rp]Ri[$Ri]\n");
        if (!ds_select_dst("1","13", "-1")) {
                xinfo("[MAIN] no gateway available !\n");
        }                                                                                                                                                                                     
        while (defined $xavp(_dsdst_)) {
                xinfo("[MAIN] URI : $xavp(_dsdst_=>uri) \n");
                pv_unset("$xavp(_dsdst_)");
        }
        return;
}

// Logs showing the gateways returned.

 0(398491) DEBUG: dispatcher [dispatch.c:2263]: ds_manage_route_algo13(): [active][0]idx[1]uri[sip:[192.168.0.5:5060](http://192.168.0.5:5060/)]priority[12-0=12]latency[0ms]flag[0]
 0(398491) DEBUG: dispatcher [dispatch.c:2263]: ds_manage_route_algo13(): [active][1]idx[2]uri[sip:192.168.0.4:5060]priority[12-0=12]latency[0ms]flag[0]
 0(398491) DEBUG: dispatcher [dispatch.c:2270]: ds_manage_route_algo13(): [inactive][2]idx[-1]uri[sip:192.168.0.3:5060]priority[12]latency[0ms]flag[1]
 0(398491) DEBUG: dispatcher [dispatch.c:2263]: ds_manage_route_algo13(): [active][3]idx[4]uri[sip:192.168.0.2:5060]priority[12-0=12]latency[0ms]flag[0]
 0(398491) DEBUG: dispatcher [dispatch.c:2270]: ds_manage_route_algo13(): [inactive][4]idx[-1]uri[sip:192.168.0.1:5060]priority[12]latency[0ms]flag[1]
 0(398491) DEBUG: dispatcher [dispatch.c:2263]: ds_manage_route_algo13(): [active][5]idx[0]uri[sip:192.168.0.6:5060]priority[12-0=12]latency[0ms]flag[0]

 0(398491) DEBUG: dispatcher [dispatch.c:2128]: ds_manage_routes_fill_reordered_xavp(): [4|sip:192.168.0.3:5060|idx:-1]skipped 1 || 1
 0(398491) DEBUG: dispatcher [dispatch.c:2128]: ds_manage_routes_fill_reordered_xavp(): [5|sip:192.168.0.1:5060|idx:-1]skipped 1 || 1
 0(398491) DEBUG: dispatcher [dispatch.c:2300]: ds_manage_route_algo13(): priority[12]gateway_selected[1]next_index[2]
 0(398491) DEBUG: dispatcher [dispatch.c:2465]: ds_manage_routes(): using alg [13] hash [1]
 0(398491) DEBUG: dispatcher [dispatch.c:2512]: ds_manage_routes(): selected [13-1-0/1] <sip:[192.168.0.5:5060](http://192.168.0.5:5060/)>
 0(398491) DEBUG: dispatcher [dispatch.c:2107]: ds_select_dst_limit(): selected target destinations: 4
 0(398491) INFO: <script>: [MAIN][sip:[192.168.0.5:5060](http://192.168.0.5:5060/)]
 0(398491) INFO: <script>: [MAIN] URI : sip:192.168.0.5:5060
 0(398491) INFO: <script>: [MAIN] URI : sip:[192.168.0.4:5060](http://192.168.0.4:5060/)
 0(398491) INFO: <script>: [MAIN] URI : sip:[192.168.0.2:5060](http://192.168.0.2:5060/)
 0(398491) INFO: <script>: [MAIN] URI : sip:[192.168.0.6:5060](http://192.168.0.6:5060/)
 ```

You can view, comment on, or merge this pull request online at:

  https://github.com/kamailio/kamailio/pull/3232

-- Commit Summary --

  * dispatcher: fix alog13 gateway selections

-- File Changes --

    M src/modules/dispatcher/dispatch.c (32)

-- Patch Links --

https://github.com/kamailio/kamailio/pull/3232.patch
https://github.com/kamailio/kamailio/pull/3232.diff

-- 
Reply to this email directly or view it on GitHub:
https://github.com/kamailio/kamailio/pull/3232
You are receiving this because you are subscribed to this thread.

Message ID: <kamailio/kamailio/pull/3232 at github.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.kamailio.org/pipermail/sr-dev/attachments/20220906/79ef2a47/attachment.htm>


More information about the sr-dev mailing list