<h4 dir="auto">Pre-Submission Checklist</h4>
<ul class="contains-task-list">
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> Commit message has the format required by CONTRIBUTING guide</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> Commits are split per component (core, individual modules, libs, utils, ...)</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> Each component has a single commit (if not, squash them into one commit)</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> No commits to README files for modules (changes must be done to docbook files<br>
in <code class="notranslate">doc/</code> subfolder, the README file is autogenerated)</li>
</ul>
<h4 dir="auto">Type Of Change</h4>
<ul class="contains-task-list">
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> Small bug fix (non-breaking change which fixes an issue)</li>
</ul>
<h4 dir="auto">Checklist:</h4>
<ul class="contains-task-list">
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> PR should be backported to stable branches</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> Tested changes locally</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox"> Related to issue #XXXX (replace XXXX with an open issue number)</li>
</ul>
<h4 dir="auto">Description</h4>
<p dir="auto">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.</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="// 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/)"><pre class="notranslate notranslate"><code>// 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/)
</code></pre></div>
<hr>
<h4>You can view, comment on, or merge this pull request online at:</h4>
<p> <a href='https://github.com/kamailio/kamailio/pull/3232'>https://github.com/kamailio/kamailio/pull/3232</a></p>
<h4>Commit Summary</h4>
<ul>
<li><a href="https://github.com/kamailio/kamailio/pull/3232/commits/f62dcc6aa3c171760c3076119dc64e5bb4d51947" class="commit-link">f62dcc6</a> dispatcher: fix alog13 gateway selections</li>
</ul>
<h4 style="display: inline-block">File Changes </h4> <p style="display: inline-block">(<a href="https://github.com/kamailio/kamailio/pull/3232/files">1 file</a>)</p>
<ul>
<li>
<strong>M</strong>
<a href="https://github.com/kamailio/kamailio/pull/3232/files#diff-174a89f2c0a1f9644e11bba127bd562eb1944206d6f4575b37c4e7f23579bc21">src/modules/dispatcher/dispatch.c</a>
(32)
</li>
</ul>
<h4>Patch Links:</h4>
<ul>
<li><a href='https://github.com/kamailio/kamailio/pull/3232.patch'>https://github.com/kamailio/kamailio/pull/3232.patch</a></li>
<li><a href='https://github.com/kamailio/kamailio/pull/3232.diff'>https://github.com/kamailio/kamailio/pull/3232.diff</a></li>
</ul>
<p style="font-size:small;-webkit-text-size-adjust:none;color:#666;">—<br />Reply to this email directly, <a href="https://github.com/kamailio/kamailio/pull/3232">view it on GitHub</a>, or <a href="https://github.com/notifications/unsubscribe-auth/ABO7UZPXUSJVMD3TH37USQTV45KWXANCNFSM6AAAAAAQF466BA">unsubscribe</a>.<br />You are receiving this because you are subscribed to this thread.<img src="https://github.com/notifications/beacon/ABO7UZPERQJRLLUFSTA2ETTV45KWXA5CNFSM6AAAAAAQF466BCWGG33NNVSW45C7OR4XAZNFJFZXG5LFVJRW63LNMVXHIX3JMTHFCQ7X7A.gif" height="1" width="1" alt="" /><span style="color: transparent; font-size: 0; display: none; visibility: hidden; overflow: hidden; opacity: 0; width: 0; height: 0; max-width: 0; max-height: 0; mso-hide: all">Message ID: <span><kamailio/kamailio/pull/3232</span><span>@</span><span>github</span><span>.</span><span>com></span></span></p>
<script type="application/ld+json">[
{
"@context": "http://schema.org",
"@type": "EmailMessage",
"potentialAction": {
"@type": "ViewAction",
"target": "https://github.com/kamailio/kamailio/pull/3232",
"url": "https://github.com/kamailio/kamailio/pull/3232",
"name": "View Pull Request"
},
"description": "View this Pull Request on GitHub",
"publisher": {
"@type": "Organization",
"name": "GitHub",
"url": "https://github.com"
}
}
]</script>