<p>Harald Welte <strong>merged</strong> this change.</p><p><a href="https://gerrit.osmocom.org/9259">View Change</a></p><div style="white-space:pre-wrap">Approvals:
  Harald Welte: Looks good to me, approved
  Jenkins Builder: Verified

</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">protocol: Try whole port range on port allocation<br><br>The function allocate_port tryes at least 200 different ports when<br>a new port is allocated. Since after every allocation the port<br>number is incremented the allocation should be able to allocate<br>a port with the first attempt. However, the number 200 is an<br>arbitrary number and it will not cover the whole port range in<br>most cases.<br><br>- Make sure that in the worst case at each port in the range<br>  is tryed once, not only the next 200<br><br>Change-Id: Ic47f09869eaddd4aea817bb2517362883d65d029<br>Related: OS#2825<br>---<br>M src/libosmo-mgcp/mgcp_protocol.c<br>1 file changed, 8 insertions(+), 5 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/src/libosmo-mgcp/mgcp_protocol.c b/src/libosmo-mgcp/mgcp_protocol.c</span><br><span>index ea86672..c391fec 100644</span><br><span>--- a/src/libosmo-mgcp/mgcp_protocol.c</span><br><span>+++ b/src/libosmo-mgcp/mgcp_protocol.c</span><br><span>@@ -356,13 +356,15 @@</span><br><span> </span><br><span> /* Try to find a free port by attempting to bind on it. Also handle the</span><br><span>  * counter that points on the next free port. Since we have a pointer</span><br><span style="color: hsl(0, 100%, 40%);">- * to the next free port, binding should work on the first attempt,</span><br><span style="color: hsl(0, 100%, 40%);">- * nevertheless, try at least the next 200 ports before giving up */</span><br><span style="color: hsl(120, 100%, 40%);">+ * to the next free port, binding should in work on the first attempt in</span><br><span style="color: hsl(120, 100%, 40%);">+ * general. In case of failure the next port is tryed until the whole port</span><br><span style="color: hsl(120, 100%, 40%);">+ * range is tryed once. */</span><br><span> static int allocate_port(struct mgcp_endpoint *endp, struct mgcp_conn_rtp *conn)</span><br><span> {</span><br><span>      int i;</span><br><span>       struct mgcp_rtp_end *end;</span><br><span>    struct mgcp_port_range *range;</span><br><span style="color: hsl(120, 100%, 40%);">+        unsigned int tries;</span><br><span> </span><br><span>      OSMO_ASSERT(conn);</span><br><span>   end = &conn->end;</span><br><span>@@ -371,7 +373,8 @@</span><br><span>       range = &endp->cfg->net_ports;</span><br><span> </span><br><span>         /* attempt to find a port */</span><br><span style="color: hsl(0, 100%, 40%);">-    for (i = 0; i < 200; ++i) {</span><br><span style="color: hsl(120, 100%, 40%);">+        tries = (range->range_end - range->range_start) / 2;</span><br><span style="color: hsl(120, 100%, 40%);">+    for (i = 0; i < tries; ++i) {</span><br><span>             int rc;</span><br><span> </span><br><span>          if (range->last_port >= range->range_end)</span><br><span>@@ -387,8 +390,8 @@</span><br><span>     }</span><br><span> </span><br><span>        LOGP(DLMGCP, LOGL_ERROR,</span><br><span style="color: hsl(0, 100%, 40%);">-             "Allocating a RTP/RTCP port failed 200 times 0x%x.\n",</span><br><span style="color: hsl(0, 100%, 40%);">-        ENDPOINT_NUMBER(endp));</span><br><span style="color: hsl(120, 100%, 40%);">+       "Allocating a RTP/RTCP port failed %u times 0x%x.\n",</span><br><span style="color: hsl(120, 100%, 40%);">+       tries, ENDPOINT_NUMBER(endp));</span><br><span>  return -1;</span><br><span> }</span><br><span> </span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.osmocom.org/9259">change 9259</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.osmocom.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.osmocom.org/9259"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: osmo-mgw </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-MessageType: merged </div>
<div style="display:none"> Gerrit-Change-Id: Ic47f09869eaddd4aea817bb2517362883d65d029 </div>
<div style="display:none"> Gerrit-Change-Number: 9259 </div>
<div style="display:none"> Gerrit-PatchSet: 3 </div>
<div style="display:none"> Gerrit-Owner: dexter <pmaier@sysmocom.de> </div>
<div style="display:none"> Gerrit-Reviewer: Harald Welte <laforge@gnumonks.org> </div>
<div style="display:none"> Gerrit-Reviewer: Jenkins Builder </div>