<p>George Joseph <strong>merged</strong> this change.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/11649">View Change</a></p><div style="white-space:pre-wrap">Approvals:
  Kevin Harwell: Looks good to me, but someone else must approve; Verified
  George Joseph: Looks good to me, approved; Approved for Submit

</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">main/udptl.c: correctly handle udptl sequence wrap around<br><br>incorrect handling of UDPTL squence number wrap arounds causes<br>loss of packets every time the wrap around occurs<br><br>ASTERISK-28483 #close<br><br>Change-Id: I33caeb2bf13c574a1ebb81714b58907091d64234<br>---<br>M main/udptl.c<br>1 file changed, 18 insertions(+), 0 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/main/udptl.c b/main/udptl.c</span><br><span>index 99a9c74..555ae69 100644</span><br><span>--- a/main/udptl.c</span><br><span>+++ b/main/udptl.c</span><br><span>@@ -405,6 +405,24 @@</span><br><span>  seq_no = (buf[0] << 8) | buf[1];</span><br><span>       ptr += 2;</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+ /* UDPTL sequence numbers are 16 bit so after 0xFFFF comes</span><br><span style="color: hsl(120, 100%, 40%);">+       0 which breaks all packet recovery logic.  To fix this</span><br><span style="color: hsl(120, 100%, 40%);">+        if we see that next expected packet (rx_seq_no) is close</span><br><span style="color: hsl(120, 100%, 40%);">+      to or beyond the wrap around limit & the received packet</span><br><span style="color: hsl(120, 100%, 40%);">+          is still near zero, then we 'unwrap' the received seqno</span><br><span style="color: hsl(120, 100%, 40%);">+       so it has the value it would have had.  After a 16</span><br><span style="color: hsl(120, 100%, 40%);">+    packet grace period (there shouldn't be  more than</span><br><span style="color: hsl(120, 100%, 40%);">+        that many recovery packets) we wrap the expected</span><br><span style="color: hsl(120, 100%, 40%);">+      sequence number around and things can return back</span><br><span style="color: hsl(120, 100%, 40%);">+     to normal */</span><br><span style="color: hsl(120, 100%, 40%);">+       if (seq_no < 0x000F && s->rx_seq_no > 0xFFF0) {</span><br><span style="color: hsl(120, 100%, 40%);">+              /* received seq_no has wrapped adjust it */</span><br><span style="color: hsl(120, 100%, 40%);">+           seq_no += 0x10000;</span><br><span style="color: hsl(120, 100%, 40%);">+    } else {</span><br><span style="color: hsl(120, 100%, 40%);">+              /* otherwise make sure expected rx_seq_no is properly wrapped */</span><br><span style="color: hsl(120, 100%, 40%);">+              s->rx_seq_no &= 0xFFFF;</span><br><span style="color: hsl(120, 100%, 40%);">+        }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span>  /* Break out the primary packet */</span><br><span>   if ((stat1 = decode_open_type(buf, len, &ptr, &ifp, &ifp_len)) != 0)</span><br><span>             return -1;</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/11649">change 11649</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.asterisk.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.asterisk.org/c/asterisk/+/11649"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 17.0 </div>
<div style="display:none"> Gerrit-Change-Id: I33caeb2bf13c574a1ebb81714b58907091d64234 </div>
<div style="display:none"> Gerrit-Change-Number: 11649 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Torrey Searle <tsearle@gmail.com> </div>
<div style="display:none"> Gerrit-Reviewer: Friendly Automation </div>
<div style="display:none"> Gerrit-Reviewer: George Joseph <gjoseph@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Kevin Harwell <kharwell@digium.com> </div>
<div style="display:none"> Gerrit-MessageType: merged </div>