<h4>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>doc/</code> subfolder, the README file is autogenerated)</li>
</ul>
<h4>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>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox"> New feature (non-breaking change which adds new functionality)</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox"> Breaking change (fix or feature that would change existing functionality)</li>
</ul>
<h4>Checklist:</h4>

<ul class="contains-task-list">
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox"> 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>Description</h4>

<p>It has been noticed, that after a list of contributions into lcr:</p>
<ul>
<li><a class="commit-link" data-hovercard-type="commit" data-hovercard-url="https://github.com/kamailio/kamailio/commit/14e6fc80b3d2389567c73c4a2196bf8e6d92d8d2/hovercard" href="https://github.com/kamailio/kamailio/commit/14e6fc80b3d2389567c73c4a2196bf8e6d92d8d2"><tt>14e6fc8</tt></a></li>
<li><a class="commit-link" data-hovercard-type="commit" data-hovercard-url="https://github.com/kamailio/kamailio/commit/d8583d6ce1748c1ac8494616fced507b01dd4375/hovercard" href="https://github.com/kamailio/kamailio/commit/d8583d6ce1748c1ac8494616fced507b01dd4375"><tt>d8583d6</tt></a></li>
<li><a class="commit-link" data-hovercard-type="commit" data-hovercard-url="https://github.com/kamailio/kamailio/commit/470fd5b8bedca56efcc5e6aa0225089fe3857ac9/hovercard" href="https://github.com/kamailio/kamailio/commit/470fd5b8bedca56efcc5e6aa0225089fe3857ac9"><tt>470fd5b</tt></a></li>
<li><a class="commit-link" data-hovercard-type="commit" data-hovercard-url="https://github.com/kamailio/kamailio/commit/aa8d3ed4fe20efbd22db3b0b01a655789afa8818/hovercard" href="https://github.com/kamailio/kamailio/commit/aa8d3ed4fe20efbd22db3b0b01a655789afa8818"><tt>aa8d3ed</tt></a></li>
</ul>
<p>the gateways matching when a search is being done based on<br>
the IP address and the src_port (through the array of GWs <strong>with the same IP</strong>)<br>
works, but not fully correct.</p>
<p>It is only related to the usage with the third parameter 'src_port',<br>
when calling from_gw() and from_any_gw(), and, only when the search<br>
is done through the gateways array, which have <strong>the same IP address</strong><br>
,but different ports (let's say one has 30 GWs with the same IP in the lcr_gw).<br>
If gateways have different IPs, the issue is not catchable.</p>
<p>The problem is in the algorithm used for matching based on<br>
two objects (ip_addr and src_port) - the binary search.<br>
It's not fully suitable for a search based on two (or more) objects.</p>
<p>The binary works completely fine, when only one object is used for searching,<br>
but works not fully correct when the search is based on a comparison<br>
of two (or more) objects. A division happening based on the value of<br>
the first object, gives a chance that the second object will never<br>
be found in the current half being looked up.</p>
<p>This commit concerns switching to a full cycling through the array of<br>
gateways of the same lcr_id, and gives a proper work of the do_from_gw().</p>
<p>The slight drawback of the new method is that we have to do a cycling<br>
through the whole array of GWs <strong>of the same lcr_id</strong>, but on the other hand<br>
it is much more efficient than trying to build up a matching using binary search<br>
based on two objects (ip_addr and src_port) being used for comparison.</p>
<p>If we had to build this using bsearch() as well, then we would have to:</p>
<ul>
<li>first prepare a sorted array of the gateways with the same IP (sorted in terms of ports)<br>
,which already means with have to go through the whole GWs array to catch all needed GWs ;</li>
<li>do a bsearch() based on src_port only (using previously prepared sorted array) ;<br>
Which looks similar <strong>to the full cycling</strong> in terms of CPU resource consumption.</li>
</ul>

<hr>

<h4>You can view, comment on, or merge this pull request online at:</h4>
<p>  <a href='https://github.com/kamailio/kamailio/pull/2876'>https://github.com/kamailio/kamailio/pull/2876</a></p>

<h4>Commit Summary</h4>
<ul>
  <li><a href="https://github.com/kamailio/kamailio/pull/2876/commits/7f02e89622d6e9294906bebb8ceda76b25072ba4">lcr: improve the search for GW when both IP address and src_port are used</a></li>
</ul>

<h4>File Changes</h4>
<ul>
  <li>
    <strong>M</strong>
    <a href="https://github.com/kamailio/kamailio/pull/2876/files#diff-a18bc91c82f4a29893e81dd0340f613964cad87bd5b6c98e6ae76b5a501433bd">src/modules/lcr/lcr_mod.c</a>
    (39)
  </li>
</ul>

<h4>Patch Links:</h4>
<ul>
  <li><a href='https://github.com/kamailio/kamailio/pull/2876.patch'>https://github.com/kamailio/kamailio/pull/2876.patch</a></li>
  <li><a href='https://github.com/kamailio/kamailio/pull/2876.diff'>https://github.com/kamailio/kamailio/pull/2876.diff</a></li>
</ul>

<p style="font-size:small;-webkit-text-size-adjust:none;color:#666;">—<br />You are receiving this because you are subscribed to this thread.<br />Reply to this email directly, <a href="https://github.com/kamailio/kamailio/pull/2876">view it on GitHub</a>, or <a href="https://github.com/notifications/unsubscribe-auth/ABO7UZIB66ZZ625NF26ATL3UF37WXANCNFSM5FTZBDBQ">unsubscribe</a>.<br />Triage notifications on the go with GitHub Mobile for <a href="https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675">iOS</a> or <a href="https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub">Android</a>.
<img src="https://github.com/notifications/beacon/ABO7UZJINX3PDK7VVNITHD3UF37WXA5CNFSM5FTZBDB2YY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4PG56LWA.gif" height="1" width="1" alt="" /></p>
<script type="application/ld+json">[
{
"@context": "http://schema.org",
"@type": "EmailMessage",
"potentialAction": {
"@type": "ViewAction",
"target": "https://github.com/kamailio/kamailio/pull/2876",
"url": "https://github.com/kamailio/kamailio/pull/2876",
"name": "View Pull Request"
},
"description": "View this Pull Request on GitHub",
"publisher": {
"@type": "Organization",
"name": "GitHub",
"url": "https://github.com"
}
}
]</script>