<p>I see a strange behaviour using the route_to_carrier and use_next_gw function:</p>

<p>If I use a sip client whichs adds :5060 to the ruri and I receive a 503 Service unavailable from the first gateway, then the ruri sent to the next gateway (using the use_next_gw() function) is mixed up. The first prefix is still there preceded by the prefix from the next gateway with the original number four digets short.</p>

<p>Let me explain:</p>

<p>The way it works ok (note, no :5060)</p>

<p>INVITE sip:<a href="mailto:31206655443@mysipserver.org">31206655443@mysipserver.org</a> SIP/2.0 -&gt; INVITE sip:123431206655443@10.20.30.40 SIP/2.0<br>
                                               &lt;- 503 Service unavailable<br>
                                               -&gt; INVITE sip:876531206655443@20.30.40.50 SIP/2.0</p>

<p>The problem i see (note, :5060)</p>

<p>INVITE sip:<a href="mailto:31206655443@mysipserver.org">31206655443@mysipserver.org</a> SIP/2.0 -&gt; INVITE sip:123431206655443@10.20.30.40 SIP/2.0<br>
                                               &lt;- 503 Service unavailable<br>
                                               -&gt; INVITE sip:876512343120665@20.30.40.50 SIP/2.0</p>

<p>So I notice the first prefix is still there: 8765 1234 3120665<br>
I can reproduce this by using a 3CX soft client (then it goes wrong).</p>

<p>Here below the output of 'opensipsctl dr show'</p>

<p>dr gateways<br>
+----+------+------+---------------+-------+------------+-------+------------+-------+--------+-------------+<br>
| id | gwid | type | address       | strip | pri_prefix | attrs | probe_mode | state | socket | description |<br>
+----+------+------+---------------+-------+------------+-------+------------+-------+--------+-------------+<br>
|  1 | 1    |    1 | 10.20.30.40   |     0 | 1234       | NULL  |          0 |     0 | NULL   | Gateway A   |<br>
|  2 | 2    |    2 | 20.30.40.50   |     0 | 8765       | NULL  |          0 |     0 | NULL   | Gateway B   |<br>
+----+------+------+---------------+-------+------------+-------+------------+-------+--------+-------------+<br>
dr groups<br>
+----+----------+--------+---------+-------------+<br>
| id | username | domain | groupid | description |<br>
+----+----------+--------+---------+-------------+<br>
|  1 | .*       | .*     |       1 | Inbound     |<br>
|  2 | .*       | .*     |       2 | Outbound    |<br>
+----+----------+--------+---------+-------------+<br>
dr carriers<br>
+----+-----------+--------+-------+-------+-------+---------------------------+<br>
| id | carrierid | gwlist | flags | state | attrs | description               |<br>
+----+-----------+--------+-------+-------+-------+---------------------------+<br>
|  1 | 1         | 1,2    |     0 |     0 | NULL  | Carrier A                 |<br>
|  2 | 2         | 2,1    |     0 |     0 | NULL  | Carrier B                 |<br>
+----+-----------+--------+-------+-------+-------+---------------------------+<br>
dr rules<br>
+--------+---------+------------+---------+----------+---------+--------+-------+-------------+<br>
| ruleid | groupid | prefix     | timerec | priority | routeid | gwlist | attrs | description |<br>
+--------+---------+------------+---------+----------+---------+--------+-------+-------------+<br>
|      1 | 1       | 4165555555 |         |        0 | NULL    | 1      | NULL  | Inbound     |<br>
|      2 | 2       | 4165555555 |         |        0 | NULL    | 1      | NULL  | Outbound    |<br>
+--------+---------+------------+---------+----------+---------+--------+-------+-------------+</p>

<p>I tested a quick 'fix' which works:</p>

<p>$ru = "sip:" + $rU + "@" + $rd;</p>

<pre><code>    if(route_to_carrier("$avp(droute)"))
    { 
</code></pre>

<p style="font-size:small;-webkit-text-size-adjust:none;color:#666;">&mdash;<br>Reply to this email directly or <a href="https://github.com/OpenSIPS/opensips/issues/425">view it on GitHub</a>.<img alt="" height="1" src="https://github.com/notifications/beacon/AFOciT7HswWfvHLypHCRorCsnnNockL-ks5nzZ97gaJpZM4DrqEv.gif" width="1" /></p>
<div itemscope itemtype="http://schema.org/EmailMessage">
  <div itemprop="action" itemscope itemtype="http://schema.org/ViewAction">
    <link itemprop="url" href="https://github.com/OpenSIPS/opensips/issues/425"></link>
    <meta itemprop="name" content="View Issue"></meta>
  </div>
  <meta itemprop="description" content="View this Issue on GitHub"></meta>
</div>