<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:#0563C1;
        text-decoration:underline;}
span.EmailStyle18
        {mso-style-type:personal-reply;
        font-family:"Calibri",sans-serif;
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style>
</head>
<body lang="EN-US" link="#0563C1" vlink="#954F72">
<div class="WordSection1">
<p class="MsoNormal">You don’t have to call t_reply from failure_route. The default action of failure_route is already to relay the response back upstream [1], unless you created a new branch. Simply call append_to_reply and then exit. It is the t_reply call
 that is confusing things.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">[1] - <a href="https://www.opensips.org/Documentation/Script-Routes-2-4#toc3">
https://www.opensips.org/Documentation/Script-Routes-2-4#toc3</a><o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><span style="color:black">Ben Newlin </span><o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal"><b><span style="font-size:12.0pt;color:black">From: </span></b><span style="font-size:12.0pt;color:black">Users <users-bounces@lists.opensips.org> on behalf of Yury Kirsanov <y.kirsanov@gmail.com><br>
<b>Reply-To: </b>OpenSIPS users mailling list <users@lists.opensips.org><br>
<b>Date: </b>Thursday, March 26, 2020 at 4:15 AM<br>
<b>To: </b>OpenSIPS users mailling list <users@lists.opensips.org><br>
<b>Subject: </b>[OpenSIPS-Users] Issue with 'To' tag and t_reply<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">Hi, <o:p></o:p></p>
<div>
<p class="MsoNormal">I'm using an OpenSIPS as a proxy between two servers. First one is sending SIP INVITE to OpenSIPS, then OpenSIPS forwards request to second server. I'm creating a dialog on initial INVITE. Second server then replies with SIP 183 Session
 Progress, plays back a message and then responds with 4XX code, for example SIP 404 Not Found (indicating that number dialed is disconnected). In OpenSIPS I'm receiving that reply and in failure_route I'd like to change that code to a bit different SIP 404,
 so I'm using following code:<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">append_to_reply("Reason: Q.850;cause=1");<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">t_reply("404","Not Found");<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">exit;<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">But in this case I can see that OpenSIPS generates additional branch (??? not sure here) with different "To" tag and pushes it out and then forwards original reply SIP packet even though I have an exit statement in my failure_route. I tried
 to do sl_send_reply and behavior is pretty much the same. Can someone let me know what I may be doing wrong? I need correct "To" tag to be used (based on 183 Session Progress message from server B and passed to server A previously) and second 404 shouldn't
 be forwarded out.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">Here's an example of a call with my explanations<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">Initial invite from server A, no 'to tag' as expected:<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">INVITE sip:XXXXXXXXX@B.B.B.B SIP/2.0<br>
Max-Forwards: 67<br>
To: "XXXXXXXXX" <sip:XXXXXXXXX@B.B.B.B><br>
Call-ID: 469A5568-E092-4038-B1B8-13AC9B9571CA<br>
Via: SIP/2.0/UDP A.A.A.A:5060;rport;branch=z9hG4bK773616538<br>
From: "YYYYYYYYY" <sip:YYYYYYYYY@A.A.A.A>;tag=117583367<br>
CSeq: 1741310 INVITE<br>
User-Agent: User Agent<br>
Contact: <sip:YYYYYYYYY@A.A.A.A:5060><br>
Allow: ACK, INVITE, BYE, CANCEL, REGISTER, REFER, OPTIONS, INFO, SUBSCRIBE, NOTIFY<br>
Date: Thu, 26 Mar 2020 07:54:55 GMT<br>
Content-Type: application/sdp<br>
Content-Length: 250<br>
<br>
v=0<br>
o=dcom 1585209295 1585209295 IN IP4 A.A.A.A<br>
s=SIP Call<br>
c=IN IP4 A.A.A.A<br>
t=0 0<br>
m=audio 15340 RTP/AVP 8 0 18 101<br>
a=rtpmap:8 PCMA/8000<br>
a=rtpmap:0 PCMU/8000<br>
a=rtpmap:18 G729/8000<br>
a=fmtp:18 annexb=no<br>
a=rtpmap:101 telephone-event/8000<br>
<br>
Response from OpenSIPS:<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><br>
SIP/2.0 100 Giving a try<br>
To: "XXXXXXXXX" <sip:XXXXXXXXX@B.B.B.B><br>
Call-ID: 469A5568-E092-4038-B1B8-13AC9B9571CA<br>
Via: SIP/2.0/UDP A.A.A.A:5060;received=A.A.A.A;rport=5060;branch=z9hG4bK773616538<br>
From: "YYYYYYYYY" <sip:YYYYYYYYY@A.A.A.A>;tag=117583367<br>
CSeq: 1741310 INVITE<br>
Server: Server Signature<br>
Content-Length: 0<br>
<br>
OpenSIPS has forwarded packet to Server B and Server B responded with 183 and assigned a 'To' tag:<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><br>
SIP/2.0 183 Session Progress<br>
Via: SIP/2.0/UDP A.A.A.A:5060;received=A.A.A.A;rport=5060;branch=z9hG4bK773616538<br>
Call-ID: 469A5568-E092-4038-B1B8-13AC9B9571CA<br>
From: "YYYYYYYYY" <sip:YYYYYYYYY@A.A.A.A>;tag=117583367<br>
To: "XXXXXXXXX" <sip:XXXXXXXXX@B.B.B.B>;<b><span style="font-size:13.5pt;color:red">tag=0b49dc32-2c4b-413e-a349-c781a23d53b9</span></b><br>
CSeq: 1741310 INVITE<br>
Server: PBX<br>
Contact: <sip:B.B.B.B;did=d0a.99678f73><br>
Allow: OPTIONS, REGISTER, SUBSCRIBE, NOTIFY, PUBLISH, INVITE, ACK, BYE, CANCEL, UPDATE, PRACK, REFER<br>
Content-Type: application/sdp<br>
Content-Length: 354<br>
<br>
v=0<br>
o=- 1585209295 1585209297 IN IP4 B.B.B.B<br>
s=Asterisk<br>
c=IN IP4 B.B.B.B<br>
t=0 0<br>
a=rtpengine:673f999268ae<br>
m=audio 32386 RTP/AVP 0 8 18 101<br>
a=maxptime:150<br>
a=rtpmap:0 PCMU/8000<br>
a=rtpmap:8 PCMA/8000<br>
a=rtpmap:18 G729/8000<br>
a=rtpmap:101 telephone-event/8000<br>
a=fmtp:18 annexb=no<br>
a=fmtp:101 0-16<br>
a=sendrecv<br>
a=rtcp:32387<br>
a=ptime:20<br>
<br>
Server B responds with SIP 404 after playing back message that number is disconnected and I'm trying to reply to server A with custom Reason message. To_tag is completely different from the To tag that has been passed to server A after initial 183!!!<br>
<br>
SIP/2.0 404 Not Found<br>
To: "XXXXXXXXX" <sip:XXXXXXXXX@B.B.B.B>;<b><span style="font-size:13.5pt;color:blue">tag=a976.21514595b467be41a9b712a6b0b621d9</span></b><br>
Call-ID: 469A5568-E092-4038-B1B8-13AC9B9571CA<br>
Via: SIP/2.0/UDP A.A.A.A:5060;received=A.A.A.A;rport=5060;branch=z9hG4bK773616538<br>
From: "YYYYYYYYY" <sip:YYYYYYYYY@A.A.A.A>;tag=117583367<br>
CSeq: 1741310 INVITE<br>
Reason: Q.850;cause=1;text="Number is disconnected"<br>
Server: Server Signature<br>
Content-Length: 0<br>
<br>
Of course, server A just ignores this message as it can't match 'To' tag to its transaction. Now, for some reason, OpenSIPS forwards original reply from Server B to Server A with the same 'To' tag as in 183 Session Progress:<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">SIP/2.0 404 Not Found<br>
Via: SIP/2.0/UDP A.A.A.A:5060;received=A.A.A.A;rport=5060;branch=z9hG4bK773616538<br>
Call-ID: 469A5568-E092-4038-B1B8-13AC9B9571CA<br>
From: "YYYYYYYYY" <sip:YYYYYYYYY@A.A.A.A>;tag=117583367<br>
To: "XXXXXXXXX" <sip:XXXXXXXXX@B.B.B.B>;<b><span style="font-size:13.5pt;color:red">tag=0b49dc32-2c4b-413e-a349-c781a23d53b9</span></b><br>
CSeq: 1741310 INVITE<br>
Server: PBX<br>
Allow: OPTIONS, REGISTER, SUBSCRIBE, NOTIFY, PUBLISH, INVITE, ACK, BYE, CANCEL, UPDATE, PRACK, REFER<br>
Reason: Q.850;cause=1<br>
Content-Length:  0<br>
<br>
And at this point Server A can match this reply and responds with an ACK:<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><br>
ACK sip:XXXXXXXXX@B.B.B.B SIP/2.0<br>
Via: SIP/2.0/UDP A.A.A.A:5060;rport;branch=z9hG4bK773616538<br>
From: "YYYYYYYYY" <sip:YYYYYYYYY@A.A.A.A>;tag=117583367<br>
To: "XXXXXXXXX" <sip:XXXXXXXXX@B.B.B.B>;<b><span style="font-size:13.5pt;color:red">tag=0b49dc32-2c4b-413e-a349-c781a23d53b9</span></b><br>
Call-ID: 469A5568-E092-4038-B1B8-13AC9B9571CA<br>
CSeq: 1741310 ACK<br>
Max-Forwards: 67<br>
Contact: <sip:YYYYYYYYY@A.A.A.A:5060><br>
User-Agent: User Agent<br>
Content-Length: 0<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">I think that t_reply is creating a new transaction instead of using existing one, but I'm not sure why and how to fix this?<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">Thanks!<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">Best regards,<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">Yury.<o:p></o:p></p>
</div>
</div>
</div>
</body>
</html>