<html>
  <head>
    <meta content="text/html; charset=ISO-8859-1"
      http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    Hello,<br>
    <br>
    the problem with the BYE is that the R-URI is the ip address of
    kamailio, resulting in match for strict routing rather than loose
    routing (both cases are handled by loose_route() function).<br>
    <br>
    My guess of what happens is that 41.221.230.60 detects the invite as
    coming from behind nat and does something like fix_nated_contact().
    Not being the first proxy in the path of the caller, should not do
    any contact mangling, but rely only on Recor-Route headers for
    routing.<br>
    <br>
    If you cannot control 41.221.230.60 or ask for a change there, the
    solution is to use htable in your config to store the contact uri
    from invite and replace it in bye before loose_route().<br>
    <br>
    I wanted to add such logic in default config for kamailio as well
    (not mangle contact if not first proxy), but forgot about it, I'll
    do it soon. There is a new function is_first_hop() in devel version,
    for older version the solution is to store the number of
    record-route  headers for request and compare with the number of
    them in response.<br>
    <br>
    Cheers,<br>
    Daniel<br>
    <br>
    <div class="moz-cite-prefix">On 8/20/13 6:00 PM, Steve Davies wrote:<br>
    </div>
    <blockquote
cite="mid:CABFTEGVbd6D+TOwmT526Uo9grrszVSaUg13w7RQrVRzTdPbuXg@mail.gmail.com"
      type="cite">
      <div dir="ltr">Hi,
        <div><br>
        </div>
        <div>I'm having a problem with routing of BYEs in my multi homed
          Kamailio.</div>
        <div><br>
        </div>
        <div>My setup is a phone on 172.16.230.1, talking to Kamailio on
          172.16.230.128.</div>
        <div>
          On the "outside" Kamailio uses 10.64.5.16 and its talking to
          41.221.230.60</div>
        <div><br>
        </div>
        <div>I'm using the stock Kamailio 4.0.3 kamailio.cfg, with:</div>
        <div>  WITH_NAT defined</div>
        <div>  mhomed=1</div>
        <div>  Little change in NATMANAGE to do the rtpproxy_manage with
          ie or ei as appropriate, coming from my previous post and the
          response from Alex.</div>
        <div><br>
        </div>
        <div>Here's the invite from the phone:</div>
        <div><br>
        </div>
        <blockquote style="margin:0px 0px 0px
          40px;border:none;padding:0px">
          <div>
            <div>U <a moz-do-not-send="true"
                href="http://172.16.230.1:3694">172.16.230.1:3694</a>
              -> <a moz-do-not-send="true"
                href="http://172.16.230.128:5060">172.16.230.128:5060</a></div>
          </div>
          <div>
            <div>INVITE <a moz-do-not-send="true"
                href="mailto:sip%3A7171001@vc2.connection-telecom.com">sip:7171001@vc2.connection-telecom.com</a>;transport=udp
              SIP/2.0.</div>
          </div>
          <div>
            <div>Via: SIP/2.0/UDP
172.16.230.1:3694;branch=z9hG4bK-d8754z-6a91626ae4c3f625-1---d8754z-;rport.</div>
          </div>
          <div>
            <div>Max-Forwards: 70.</div>
          </div>
          <div>
            <div>Contact:
              <a class="moz-txt-link-rfc2396E" href="sip:2686959@172.16.230.1:3694;transport=udp"><sip:2686959@172.16.230.1:3694;transport=udp></a>.</div>
          </div>
          <div>
            <div>To: <<a moz-do-not-send="true"
                href="mailto:sip%3A7171001@vc2.connection-telecom.com">sip:7171001@vc2.connection-telecom.com</a>>.</div>
          </div>
          <div>
            <div>From: "vc2 2686959"<<a moz-do-not-send="true"
                href="mailto:sip%3A2686959@vc2.connection-telecom.com">sip:2686959@vc2.connection-telecom.com</a>>;tag=014e3010.</div>
          </div>
          <div>
            <div>Call-ID: ZDQ4YThjNzEzOTBhOTE5NGViNTFhM2Q5MTY2ZmY1ZDc.</div>
          </div>
          <div>
            <div>CSeq: 2 INVITE.</div>
          </div>
          <div>
            <div>Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER,
              NOTIFY, MESSAGE, SUBSCRIBE, INFO.</div>
          </div>
          <div>
            <div>Content-Type: application/sdp.</div>
          </div>
          <div>
            <div>Proxy-Authorization: ...some stuff...</div>
          </div>
          <div>
            <div>Supported: replaces.</div>
          </div>
          <div>
            <div>User-Agent: Bria 3 release 3.5.3 stamp 70600.</div>
          </div>
          <div>
            <div>Content-Length: 256.</div>
          </div>
          <div>
            <div>.</div>
          </div>
          <div>
            <div>v=0.</div>
          </div>
          <div>
            <div>o=- 1377005946728952 1 IN IP4 172.16.230.1.</div>
          </div>
          <div>
            <div>s=Bria 3 release 3.5.3 stamp 70600.</div>
          </div>
          <div>
            <div>c=IN IP4 172.16.230.1.</div>
          </div>
          <div>
            <div>t=0 0.</div>
          </div>
          <div>
            <div>m=audio 52448 RTP/AVP 8 18 101.</div>
          </div>
          <div>
            <div>a=rtpmap:18 G729/8000.</div>
          </div>
          <div>
            <div>a=fmtp:18 annexb=yes.</div>
          </div>
          <div>
            <div>a=rtpmap:101 telephone-event/8000.</div>
          </div>
          <div>
            <div>a=fmtp:101 0-15.</div>
          </div>
          <div>
            <div>a=sendrecv.</div>
          </div>
        </blockquote>
        <div><br>
        </div>
        <div>Kamailio forwards with double-Record-Route with both of its
          addresses.  I believe this is per SIP OUTBOUND RFC:</div>
        <div><br>
        </div>
        <blockquote style="margin:0px 0px 0px
          40px;border:none;padding:0px">
          <div>
            <div>U <a moz-do-not-send="true"
                href="http://10.64.5.16:5060">10.64.5.16:5060</a> ->
              <a moz-do-not-send="true" href="http://41.221.230.60:5060">41.221.230.60:5060</a></div>
          </div>
          <div>
            <div>INVITE <a moz-do-not-send="true"
                href="mailto:sip%3A7171001@vc2.connection-telecom.com">sip:7171001@vc2.connection-telecom.com</a>;transport=udp
              SIP/2.0.</div>
          </div>
          <div>
            <div>Record-Route:
              <a class="moz-txt-link-rfc2396E" href="sip:10.64.5.16;r2=on;lr=on;ftag=014e3010;nat=yes"><sip:10.64.5.16;r2=on;lr=on;ftag=014e3010;nat=yes></a>.</div>
          </div>
          <div>
            <div>Record-Route:
              <a class="moz-txt-link-rfc2396E" href="sip:172.16.230.128;r2=on;lr=on;ftag=014e3010;nat=yes"><sip:172.16.230.128;r2=on;lr=on;ftag=014e3010;nat=yes></a>.</div>
          </div>
          <div>
            <div>Via: SIP/2.0/UDP
              10.64.5.16;branch=z9hG4bKe355.e526ca52.0.</div>
          </div>
          <div>
            <div>Via: SIP/2.0/UDP
172.16.230.1:3694;branch=z9hG4bK-d8754z-6a91626ae4c3f625-1---d8754z-;rport=3694.</div>
          </div>
          <div>
            <div>Max-Forwards: 16.</div>
          </div>
          <div>
            <div>Contact:
              <a class="moz-txt-link-rfc2396E" href="sip:2686959@172.16.230.1:3694;transport=udp"><sip:2686959@172.16.230.1:3694;transport=udp></a>.</div>
          </div>
          <div>
            <div>To: <<a moz-do-not-send="true"
                href="mailto:sip%3A7171001@vc2.connection-telecom.com">sip:7171001@vc2.connection-telecom.com</a>>.</div>
          </div>
          <div>
            <div>From: "vc2 2686959"<<a moz-do-not-send="true"
                href="mailto:sip%3A2686959@vc2.connection-telecom.com">sip:2686959@vc2.connection-telecom.com</a>>;tag=014e3010.</div>
          </div>
          <div>
            <div>Call-ID: ZDQ4YThjNzEzOTBhOTE5NGViNTFhM2Q5MTY2ZmY1ZDc.</div>
          </div>
          <div>
            <div>CSeq: 2 INVITE.</div>
          </div>
          <div>
            <div>Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER,
              NOTIFY, MESSAGE, SUBSCRIBE, INFO.</div>
          </div>
          <div>
            <div>Content-Type: application/sdp.</div>
          </div>
          <div>
            <div>Proxy-Authorization: ...some stuff...</div>
          </div>
          <div>
            <div>Supported: replaces.</div>
          </div>
          <div>
            <div>User-Agent: Bria 3 release 3.5.3 stamp 70600.</div>
          </div>
          <div>
            <div>Content-Length: 270.</div>
          </div>
          <div>
            <div>P-hint: outbound.</div>
          </div>
          <div>
            <div>.</div>
          </div>
          <div>
            <div>v=0.</div>
          </div>
          <div>
            <div>o=- 1377005946728952 1 IN IP4 10.64.5.16.</div>
          </div>
          <div>
            <div>s=Bria 3 release 3.5.3 stamp 70600.</div>
          </div>
          <div>
            <div>c=IN IP4 10.64.5.16.</div>
          </div>
          <div>
            <div>t=0 0.</div>
          </div>
          <div>
            <div>
              m=audio 59194 RTP/AVP 8 18 101.</div>
          </div>
          <div>
            <div>a=rtpmap:18 G729/8000.</div>
          </div>
          <div>
            <div>a=fmtp:18 annexb=yes.</div>
          </div>
          <div>
            <div>a=rtpmap:101 telephone-event/8000.</div>
          </div>
          <div>
            <div>a=fmtp:101 0-15.</div>
          </div>
          <div>
            <div>a=sendrecv.</div>
          </div>
          <div>
            <div>a=nortpproxy:yes.</div>
          </div>
        </blockquote>
        <div><br>
        </div>
        <div>So that behaviour seems OK.  The call does get correctly
          established and rtpproxy is correctly setup and audio passes
          in both directions.</div>
        <div><br>
        </div>
        <div><br>
        </div>
        <div>But when the BYE is sent (from the outside), though, things
          go wrong:</div>
        <div><br>
        </div>
        <div>Here's what arrives from upstream.  Route: has the two
          entries per the RR that was sent.</div>
        <div><br>
        </div>
        <blockquote style="margin:0px 0px 0px
          40px;border:none;padding:0px">
          <div>
            <div>U <a moz-do-not-send="true"
                href="http://41.221.230.60:5060">41.221.230.60:5060</a>
              -> <a moz-do-not-send="true"
                href="http://10.64.5.16:5060">10.64.5.16:5060</a></div>
          </div>
          <div>
            <div>BYE <a class="moz-txt-link-freetext" href="sip:2686959@10.64.5.16:5060;transport=udp">sip:2686959@10.64.5.16:5060;transport=udp</a> SIP/2.0.</div>
          </div>
          <div>
            <div>Record-Route:
              <a class="moz-txt-link-rfc2396E" href="sip:41.221.230.60;lr=on;ftag=as70703d1c"><sip:41.221.230.60;lr=on;ftag=as70703d1c></a>.</div>
          </div>
          <div>
            <div>Via: SIP/2.0/UDP
              41.221.230.60;branch=z9hG4bKbd37.4108b6b2.0.</div>
          </div>
          <div>
            <div>Via: SIP/2.0/UDP
41.221.230.60:5070;received=41.221.230.60;branch=z9hG4bK4e6b38bf;rport=5070.</div>
          </div>
          <div>
            <div>Route:
<a class="moz-txt-link-rfc2396E" href="sip:10.64.5.16;r2=on;lr=on;ftag=014e3010;nat=yes"><sip:10.64.5.16;r2=on;lr=on;ftag=014e3010;nat=yes></a>,<a class="moz-txt-link-rfc2396E" href="sip:172.16.230.128;r2=on;lr=on;ftag=014e3010;nat=yes"><sip:172.16.230.128;r2=on;lr=on;ftag=014e3010;nat=yes></a>.</div>
          </div>
          <div>
            <div>Max-Forwards: 69.</div>
          </div>
          <div>
            <div>From: <<a moz-do-not-send="true"
                href="mailto:sip%3A7171001@vc2.connection-telecom.com">sip:7171001@vc2.connection-telecom.com</a>>;tag=as70703d1c.</div>
          </div>
          <div>
            <div>To: "vc2 2686959"<<a moz-do-not-send="true"
                href="mailto:sip%3A2686959@vc2.connection-telecom.com">sip:2686959@vc2.connection-telecom.com</a>>;tag=014e3010.</div>
          </div>
          <div>
            <div>Call-ID: ZDQ4YThjNzEzOTBhOTE5NGViNTFhM2Q5MTY2ZmY1ZDc.</div>
          </div>
          <div>
            <div>CSeq: 102 BYE.</div>
          </div>
          <div>
            <div>User-Agent: Enswitch.</div>
          </div>
          <div>
            <div>X-Asterisk-HangupCause: Normal Clearing.</div>
          </div>
          <div>
            <div>X-Asterisk-HangupCauseCode: 16.</div>
          </div>
          <div>
            <div>Content-Length: 0.</div>
          </div>
          <div>
            <div>X-Enswitch-RURI:
              <a class="moz-txt-link-freetext" href="sip:2686959@10.64.5.16:5060;transport=udp">sip:2686959@10.64.5.16:5060;transport=udp</a>.</div>
          </div>
          <div>
            <div>X-Enswitch-Source: <a moz-do-not-send="true"
                href="http://41.221.230.60:5070">41.221.230.60:5070</a>.</div>
          </div>
          <div>
            <div>.</div>
          </div>
          <div><br>
          </div>
          <div><br>
          </div>
        </blockquote>
        So Kamailio peels off the first route and then sends the BYE
        actually to itself.  With an oddly formed blank Route: header.
        <div><br>
        </div>
        <div>
          <div>Tracing through the kamailio.cfg the BYE is processed in
            WITHINDLG - loose_route() succeeds</div>
          <div><br>
          </div>
          <div>It logs that 172.16.230.128 "is loose router".</div>
          <div><br>
          </div>
          <blockquote style="margin:0px 0px 0px
            40px;border:none;padding:0px">
            <div>
              <div><br>
              </div>
            </div>
            <div>
              <div>U <a moz-do-not-send="true"
                  href="http://10.64.5.16:5060">10.64.5.16:5060</a>
                -> <a moz-do-not-send="true"
                  href="http://172.16.230.128:5060">172.16.230.128:5060</a></div>
            </div>
            <div>
              <div>BYE
                <a class="moz-txt-link-freetext" href="sip:172.16.230.128;r2=on;lr=on;ftag=014e3010;nat=yes">sip:172.16.230.128;r2=on;lr=on;ftag=014e3010;nat=yes</a>
                SIP/2.0.</div>
            </div>
            <div>
              <div>Record-Route:
                <a class="moz-txt-link-rfc2396E" href="sip:41.221.230.60;lr=on;ftag=as70703d1c"><sip:41.221.230.60;lr=on;ftag=as70703d1c></a>.</div>
            </div>
            <div>
              <div>Via: SIP/2.0/UDP
                10.64.5.16;branch=z9hG4bKbd37.25d16bf3.0.</div>
            </div>
            <div>
              <div>Via: SIP/2.0/UDP
                41.221.230.60;rport=5060;branch=z9hG4bKbd37.4108b6b2.0.</div>
            </div>
            <div>
              <div>Via: SIP/2.0/UDP
41.221.230.60:5070;received=41.221.230.60;branch=z9hG4bK4e6b38bf;rport=5070.</div>
            </div>
            <div>
              <div>Route: .</div>
            </div>
            <div>
              <div>Max-Forwards: 16.</div>
            </div>
            <div>
              <div>From: <<a moz-do-not-send="true"
                  href="mailto:sip%3A7171001@vc2.connection-telecom.com">sip:7171001@vc2.connection-telecom.com</a>>;tag=as70703d1c.</div>
            </div>
            <div>
              <div>To: "vc2 2686959"<<a moz-do-not-send="true"
                  href="mailto:sip%3A2686959@vc2.connection-telecom.com">sip:2686959@vc2.connection-telecom.com</a>>;tag=014e3010.</div>
            </div>
            <div>
              <div>Call-ID: ZDQ4YThjNzEzOTBhOTE5NGViNTFhM2Q5MTY2ZmY1ZDc.</div>
            </div>
            <div>
              <div>CSeq: 102 BYE.</div>
            </div>
            <div>
              <div>User-Agent: Enswitch.</div>
            </div>
            <div>
              <div>X-Asterisk-HangupCause: Normal Clearing.</div>
            </div>
            <div>
              <div>X-Asterisk-HangupCauseCode: 16.</div>
            </div>
            <div>
              <div>Content-Length: 0.</div>
            </div>
            <div>
              <div>X-Enswitch-RURI:
                <a class="moz-txt-link-freetext" href="sip:2686959@10.64.5.16:5060;transport=udp">sip:2686959@10.64.5.16:5060;transport=udp</a>.</div>
            </div>
            <div>
              <div>X-Enswitch-Source: <a moz-do-not-send="true"
                  href="http://41.221.230.60:5070">41.221.230.60:5070</a>.</div>
            </div>
            <div>
              <div>.</div>
            </div>
            <div>
              <div><br>
              </div>
            </div>
          </blockquote>
          <div><br>
          </div>
          <div>When Kamailio receives the BYE from itself it sends a 404
            Not here.  Which is forwarded back upstream.  This 404 Not
            here is generated in WITHINDLG too; looks like loose_route()
            fails (which makes sense since there is nothing in the Route
            header), and in that case WINTHINDLG only has code for
            dealing with SUBSCRIBE and ACK.<br>
          </div>
          <div><br>
          </div>
          <blockquote style="margin:0px 0px 0px
            40px;border:none;padding:0px">
            <div>U <a moz-do-not-send="true"
                href="http://172.16.230.128:5060">172.16.230.128:5060</a>
              -> <a moz-do-not-send="true"
                href="http://10.64.5.16:5060">10.64.5.16:5060</a><br>
            </div>
            <div>
              <div>SIP/2.0 404 Not here.</div>
            </div>
            <div>
              <div>Via: SIP/2.0/UDP
                10.64.5.16;branch=z9hG4bKbd37.25d16bf3.0;rport=5060.</div>
            </div>
            <div>
              <div>Via: SIP/2.0/UDP
                41.221.230.60;rport=5060;branch=z9hG4bKbd37.4108b6b2.0.</div>
            </div>
            <div>
              <div>Via: SIP/2.0/UDP
41.221.230.60:5070;received=41.221.230.60;branch=z9hG4bK4e6b38bf;rport=5070.</div>
            </div>
            <div>
              <div>From: <<a moz-do-not-send="true"
                  href="mailto:sip%3A7171001@vc2.connection-telecom.com">sip:7171001@vc2.connection-telecom.com</a>>;tag=as70703d1c.</div>
            </div>
            <div>
              <div>To: "vc2 2686959"<<a moz-do-not-send="true"
                  href="mailto:sip%3A2686959@vc2.connection-telecom.com">sip:2686959@vc2.connection-telecom.com</a>>;tag=014e3010.</div>
            </div>
            <div>
              <div>Call-ID: ZDQ4YThjNzEzOTBhOTE5NGViNTFhM2Q5MTY2ZmY1ZDc.</div>
            </div>
            <div>
              <div>CSeq: 102 BYE.</div>
            </div>
            <div>
              <div>Server: kamailio (4.0.3 (i386/linux)).</div>
            </div>
            <div>
              <div>Content-Length: 0.</div>
            </div>
            <div>
              <div>.</div>
            </div>
            <div>
              <div><br>
              </div>
            </div>
            <div>
              <div><br>
              </div>
            </div>
            <div>
              <div>U <a moz-do-not-send="true"
                  href="http://10.64.5.16:5060">10.64.5.16:5060</a>
                -> <a moz-do-not-send="true"
                  href="http://41.221.230.60:5060">41.221.230.60:5060</a></div>
            </div>
            <div>
              <div>SIP/2.0 404 Not here.</div>
            </div>
            <div>
              <div>Via: SIP/2.0/UDP
                41.221.230.60;rport=5060;branch=z9hG4bKbd37.4108b6b2.0.</div>
            </div>
            <div>
              <div>Via: SIP/2.0/UDP
41.221.230.60:5070;received=41.221.230.60;branch=z9hG4bK4e6b38bf;rport=5070.</div>
            </div>
            <div>
              <div>From: <<a moz-do-not-send="true"
                  href="mailto:sip%3A7171001@vc2.connection-telecom.com">sip:7171001@vc2.connection-telecom.com</a>>;tag=as70703d1c.</div>
            </div>
            <div>
              <div>To: "vc2 2686959"<<a moz-do-not-send="true"
                  href="mailto:sip%3A2686959@vc2.connection-telecom.com">sip:2686959@vc2.connection-telecom.com</a>>;tag=014e3010.</div>
            </div>
            <div>
              <div>Call-ID: ZDQ4YThjNzEzOTBhOTE5NGViNTFhM2Q5MTY2ZmY1ZDc.</div>
            </div>
            <div>
              <div>CSeq: 102 BYE.</div>
            </div>
            <div>
              <div>Server: kamailio (4.0.3 (i386/linux)).</div>
            </div>
            <div>
              <div>Content-Length: 0.</div>
            </div>
            <div>
              <div>.</div>
            </div>
          </blockquote>
          <div><br>
          </div>
          <div><br>
          </div>
          <div>I tried with enable_double_rr as 0 and that did send only
            one Record-Route with the relayed INVITE, but the record
            route uses the inside address of the proxy and so we never
            even receive the BYE from the upstream system in that case.</div>
          <div><br>
          </div>
          <div>I'm kinda lost about where this is going wrong - so
            pointers would be welcome!</div>
          <div><br>
          </div>
          <div>Thanks,</div>
          <div>Steve</div>
          <div><br>
          </div>
          <div><br>
          </div>
          <div><br>
          </div>
          <div><br>
          </div>
        </div>
      </div>
      <br>
      <fieldset class="mimeAttachmentHeader"></fieldset>
      <br>
      <pre wrap="">_______________________________________________
SIP Express Router (SER) and Kamailio (OpenSER) - sr-users mailing list
<a class="moz-txt-link-abbreviated" href="mailto:sr-users@lists.sip-router.org">sr-users@lists.sip-router.org</a>
<a class="moz-txt-link-freetext" href="http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-users">http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-users</a>
</pre>
    </blockquote>
    <br>
    <pre class="moz-signature" cols="72">-- 
Daniel-Constantin Mierla - <a class="moz-txt-link-freetext" href="http://www.asipto.com">http://www.asipto.com</a>
<a class="moz-txt-link-freetext" href="http://twitter.com/#!/miconda">http://twitter.com/#!/miconda</a> - <a class="moz-txt-link-freetext" href="http://www.linkedin.com/in/miconda">http://www.linkedin.com/in/miconda</a>
</pre>
  </body>
</html>