<html>
 <body>
  <div style="font-family: Verdana, Arial, Helvetica, Sans-Serif;">
   <table bgcolor="#f9f3c9" width="100%" cellpadding="8" style="border: 1px #c9c399 solid;">
    <tr>
     <td>
      This is an automatically generated e-mail. To reply, visit:
      <a href="https://reviewboard.asterisk.org/r/1977/">https://reviewboard.asterisk.org/r/1977/</a>
     </td>
    </tr>
   </table>
   <br />









<div>




<table width="100%" border="0" bgcolor="white" style="border: 1px solid #C0C0C0; border-collapse: collapse; margin: 2px padding: 2px;">
 <thead>
  <tr>
   <th colspan="4" bgcolor="#F0F0F0" style="border-bottom: 1px solid #C0C0C0; font-size: 9pt; padding: 4px 8px; text-align: left;">
    <a href="https://reviewboard.asterisk.org/r/1977/diff/1/?file=28599#file28599line25254" style="color: black; font-weight: bold; text-decoration: underline;">/branches/1.8/channels/chan_sip.c</a>
    <span style="font-weight: normal;">

     (Diff revision 1)

    </span>
   </th>
  </tr>
 </thead>

 <tbody style="background-color: #e4d9cb; padding: 4px 8px; text-align: center;">
  <tr>

   <td colspan="4"><pre style="font-size: 8pt; line-height: 140%; margin: 0; ">static int handle_incoming(struct sip_pvt *p, struct sip_request *req, struct ast_sockaddr *addr, int *recount, int *nounlock)</pre></td>

  </tr>
 </tbody>



 
 




 <tbody>

  <tr>
    <th bgcolor="#e9eaa8" style="border-right: 1px solid #C0C0C0;" align="right"><font size="2">25254</font></th>
    <td bgcolor="#fdfebc" width="50%"><pre style="font-size: 8pt; line-height: 140%; margin: 0; ">                                <span class="kt">char</span> <span class="o">*</span><span class="n">tag</span> <span class="o">=</span> <span class="n">strstr</span><span class="p">(</span><span class="n">to_header</span><span class="p">,</span> <span class="s">&quot;;tag=&quot;</span><span class="p">);</span></pre></td>
    <th bgcolor="#e9eaa8" style="border-left: 1px solid #C0C0C0; border-right: 1px solid #C0C0C0;" align="right"><font size="2">25254</font></th>
    <td bgcolor="#fdfebc" width="50%"><pre style="font-size: 8pt; line-height: 140%; margin: 0; ">                                <span class="k">const</span> <span class="kt">char</span> <span class="o">*</span><span class="n">to_header</span> <span class="o">=</span> <span class="n">get_header</span><span class="p">(</span><span class="n">req</span><span class="p">,</span> <span class="s">&quot;To&quot;</span><span class="p">);</span></pre></td>
  </tr>

  <tr>
    <th bgcolor="#e9eaa8" style="border-right: 1px solid #C0C0C0;" align="right"><font size="2">25255</font></th>
    <td bgcolor="#fdfebc" width="50%"><pre style="font-size: 8pt; line-height: 140%; margin: 0; ">                                <span class="o">*</span><span class="n">tag</span> <span class="o">=</span> <span class="sc">&#39;\0&#39;</span><span class="p">;</span></pre></td>
    <th bgcolor="#e9eaa8" style="border-left: 1px solid #C0C0C0; border-right: 1px solid #C0C0C0;" align="right"><font size="2">25255</font></th>
    <td bgcolor="#fdfebc" width="50%"><pre style="font-size: 8pt; line-height: 140%; margin: 0; ">                                <span class="kt">char</span> <span class="o">*</span><span class="n">totag</span> <span class="o">=</span> <span class="n">strstr</span><span class="p">(</span><span class="n">to_header</span><span class="p">,</span> <span class="s">&quot;;tag=&quot;</span><span class="p">);</span></pre></td>
  </tr>

 </tbody>



 
 



 <tbody>

  <tr>
    <th bgcolor="#b1ebb0" style="border-right: 1px solid #C0C0C0;" align="right"><font size="2"></font></th>
    <td bgcolor="#c5ffc4" width="50%"><pre style="font-size: 8pt; line-height: 140%; margin: 0; "></pre></td>
    <th bgcolor="#b1ebb0" style="border-left: 1px solid #C0C0C0; border-right: 1px solid #C0C0C0;" align="right"><font size="2">25256</font></th>
    <td bgcolor="#c5ffc4" width="50%"><pre style="font-size: 8pt; line-height: 140%; margin: 0; ">                                <span class="n">totag</span> <span class="o">+=</span> <span class="mi">5</span><span class="p">;</span> <span class="cm">/* &quot;;tag=&quot; */</span></pre></td>
  </tr>

  <tr>
    <th bgcolor="#b1ebb0" style="border-right: 1px solid #C0C0C0;" align="right"><font size="2"></font></th>
    <td bgcolor="#c5ffc4" width="50%"><pre style="font-size: 8pt; line-height: 140%; margin: 0; "></pre></td>
    <th bgcolor="#b1ebb0" style="border-left: 1px solid #C0C0C0; border-right: 1px solid #C0C0C0;" align="right"><font size="2">25257</font></th>
    <td bgcolor="#c5ffc4" width="50%"><pre style="font-size: 8pt; line-height: 140%; margin: 0; ">                                <span class="n">ast_string_field_set</span><span class="p">(</span><span class="n">p</span><span class="p">,</span> <span class="n">tag</span><span class="p">,</span> <span class="n">totag</span><span class="p">);</span></pre></td>
  </tr>

 </tbody>

</table>

<pre style="margin-left: 2em; white-space: pre-wrap; white-space: -moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap; word-wrap: break-word;">You should use gettag() here.

(And preferably all other strcasestr.*&quot;tag=&quot; should be replaced with a to be created hastag() that checks &quot;;tag=&quot; instead of &quot;tag=&quot;.)</pre>
</div>
<br />



 <pre style="white-space: pre-wrap; white-space: -moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap; word-wrap: break-word;">Otherwise it looks good, although I haven&#39;t tested it.</pre>

<p>- wdoekes</p>


<br />
<p>On June 7th, 2012, 9:38 a.m., Mark Michelson wrote:</p>






<table bgcolor="#fefadf" width="100%" cellspacing="0" cellpadding="8" style="background-image: url('https://reviewboard.asterisk.org/media/rb/images/review_request_box_top_bg.png'); background-position: left top; background-repeat: repeat-x; border: 1px black solid;">
 <tr>
  <td>

<div>Review request for Asterisk Developers.</div>
<div>By Mark Michelson.</div>


<p style="color: grey;"><i>Updated June 7, 2012, 9:38 a.m.</i></p>




<h1 style="color: #575012; font-size: 10pt; margin-top: 1.5em;">Description </h1>
<table width="100%" bgcolor="#ffffff" cellspacing="0" cellpadding="10" style="border: 1px solid #b8b5a0">
 <tr>
  <td>
   <pre style="margin: 0; padding: 0; white-space: pre-wrap; white-space: -moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap; word-wrap: break-word;">When Asterisk receives what it believes to be a dialog-starting INVITE with a to-tag, Asterisk will reply with a 481. There was an issue where Asterisk would not recognize the incoming ACK of the 481 because Asterisk&#39;s internally generated to-tag did not match the actual to-tag used in the transaction. My initial fix for this was to make Asterisk send its generated to-tag in the 481 to essentially &quot;change&quot; the to-tag of the transaction. This way, the UA would respond with an ACK with a matching to-tag and all would be happy.

Unfortunately, it was pointed out to me that just because Asterisk thinks that an INVITE is out-of-dialog doesn&#39;t make it so. For instance, Asterisk could crash with a SIP dialog up, be restarted, and then receive a reinvite for that dialog. The new Asterisk instance would have no knowledge of the dialog, so it would think the INVITE was out-of-dialog with an illegitimate to-tag. In this case, the sender of the reinvite would not recognize the 481 as being in-dialog and would thus continue retransmitting the reinvite until the transaction timed out.

The new approach here is to update Asterisk&#39;s local tag to be the to-tag present in the INVITE in the case that Asterisk will be transmitting a 481 response. Taking this approach meant having to change the local tag to be a string field instead of a static buffer and rewriting the make_our_tag() method.</pre>
  </td>
 </tr>
</table>


<h1 style="color: #575012; font-size: 10pt; margin-top: 1.5em;">Testing </h1>
<table width="100%" bgcolor="#ffffff" cellspacing="0" cellpadding="10" style="border: 1px solid #b8b5a0">
 <tr>
  <td>
   <pre style="margin: 0; padding: 0; white-space: pre-wrap; white-space: -moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap; word-wrap: break-word;">I have tested using Walter Doekes&#39;s 481 test. The 481 that Asterisk sends has the same to-tag as the INVITE, and Asterisk properly recognizes the inbound ACK.</pre>
  </td>
 </tr>
</table>



<div style="margin-top: 1.5em;">
 <b style="color: #575012; font-size: 10pt; margin-top: 1.5em;">Bugs: </b>


 <a href="https://issues.asterisk.org/jira/browse/ASTERISK-19892">ASTERISK-19892</a>


</div>


<h1 style="color: #575012; font-size: 10pt; margin-top: 1.5em;">Diffs</b> </h1>
<ul style="margin-left: 3em; padding-left: 0;">

 <li>/branches/1.8/channels/chan_sip.c <span style="color: grey">(368625)</span></li>

 <li>/branches/1.8/channels/sip/include/sip.h <span style="color: grey">(368624)</span></li>

</ul>

<p><a href="https://reviewboard.asterisk.org/r/1977/diff/" style="margin-left: 3em;">View Diff</a></p>




  </td>
 </tr>
</table>








  </div>
 </body>
</html>