<p></p>

<h3>Description</h3>
<p>Consider the following setup: an edge proxy is configured with the path module, double rr is enabled (because the proxy is multihomed), add_path_received() is used to cope with NATted endpoints and the registrar is a separate kamailio instance residing on a private network. Contacts are saved successfully by the registrar, along with path information. INVITEs are first sent to the registrar which performs location lookup, and forwards the request based on the contact's Path. This part works as expected.</p>
<p>However, things seem to fail when using the new keepalive functionality of the usrloc module on the registrar. The OPTIONS request is forwarded to the "received" parameter of the first Route header instead of the URI of the first Route header.</p>

<h3>Troubleshooting</h3>
<h4>SIP Traffic</h4>

<p>EXAMPLES (check the first line printed by sngrep for L3/L4 info, public IPs have been censored):</p>
<ol>
<li>INVITE is routed to $route_uri, ignoring the "received" parameter when doing a loose_route():</li>
</ol>
<pre><code>2020/08/18 19:58:29.918672 172.30.154.189:5060 -> 172.28.155.1:5060

INVITE sip:voip-test-user-04@2.2.2.2:5060 SIP/2.0
Via: SIP/2.0/UDP 172.30.154.189;branch=z9hG4bKa788.302fa172e9b1851973593c7f20d3586d.0
Route: <sip:172.28.155.1;lr;received=sip:2.2.2.2:5060;r2=on>,<sip:3.3.3.3;lr;received=sip:2.2.2.2:5060;r2=on>
Via: SIP/2.0/UDP 172.30.152.3:5060;branch=z9hG4bK104f503d
Max-Forwards: 69
From: "sbcpub-stage-test-01" <sip:1234567890@sip.domain>;tag=as77e25748
To: <sip:voip-test-user-04@sip.domain>
Contact: <sip:1234567890@172.30.152.3:5060>
Call-ID: 53d1089c6bc695875816e25a49da8a29@sip.domain
CSeq: 102 INVITE
Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, SUBSCRIBE, NOTIFY, INFO, PUBLISH, MESSAGE
Supported: replaces, timer
X-CID: ac32e4ae-580e164d@172.17.173.14
Remote-Party-ID: "sbcpub-stage-test-01" <sip:1234567890@sip.domain>;party=calling;privacy=off;screen=no
Content-Type: application/sdp
Content-Length: 346
X-Called-Username: voip-test-user-04

v=0
o=root 18222507 18222507 IN IP4 172.30.152.3
c=IN IP4 172.30.152.3
t=0 0
m=audio 16106 RTP/AVP 9 8 0 18 101
a=rtpmap:9 G722/8000
a=rtpmap:8 PCMA/8000
a=rtpmap:0 PCMU/8000
a=rtpmap:18 G729/8000
a=fmtp:18 annexb=no
a=rtpmap:101 telephone-event/8000
a=fmtp:101 0-16
a=ptime:20
a=maxptime:150
a=sendrecv
</code></pre>
<ol start="2">
<li>OPTIONS is routed to "received" value of first Route header when doing keepalives using the usrloc module:</li>
</ol>
<pre><code>2020/08/18 19:58:02.450949 172.30.154.189:5060 -> 2.2.2.2:5064

OPTIONS sip:voip-test-user-05@172.17.173.36:5064 SIP/2.0
Via: SIP/2.0/UDP 172.30.154.189:5060;branch=z9hG4bKx.1.1.0
Route: <sip:172.30.155.1;lr;received=sip:2.2.2.2:5064;r2=on>,<sip:3.3.3.3:6050;lr;received=sip:2.2.2.2:5064;r2=on>
From: <sip:conn-revival@sip.domain>;tag=uloc-5f3be864-5d75-2-8617a458-5f3c089a-6e141-1.1
To: <sip:voip-test-user-05@sip.domain>
Call-ID: ksrulka-1.1
CSeq: 80 OPTIONS
Content-Length: 0
</code></pre>
<h4>usrloc entries</h4>
<p>The location entries for the examples above are as follows:</p>
<pre><code>        AoR: voip-test-user-04
        Contacts: {
                Contact: {
                        Address: sip:voip-test-user-04@2.2.2.2:5060
                        Expires: 47
                        Q: -1.000000
                        Call-ID: 34b4a487df71412e8e93a7a1c358d723
                        CSeq: 54
                        User-Agent: PolycomVVX-VVX_250-UA/6.3.0.14929
                        Received: sip:2.2.2.2:5060
                        Path: <sip:172.28.155.1;lr;received=sip:2.2.2.2:5060;r2=on>,<sip:3.3.3.3;lr;received=sip:2.2.2.2:5060;r2=on>
                        State: CS_DIRTY
                        Flags: 0
                        CFlags: 128
                        Socket: udp:172.30.154.189:5060
                        Methods: 8159
                        Ruid: uloc-5f3bf3b8-65c3-b7
                        Instance: [not set]
                        Reg-Id: 0
                        Server-Id: 0
                        Tcpconn-Id: -1
                        Keepalive: 0
                        Last-Keepalive: 1597771086
                        KA-Roundtrip: 0
                        Last-Modified: 1597771086
                }
        }
        AoR: voip-test-user-05
        Contacts: {
                Contact: {
                        Address: sip:voip-test-user-05@172.17.173.36:5064
                        Expires: 88
                        Q: -1.000000
                        Call-ID: 3279de38-f6ae2c18@172.17.173.36
                        CSeq: 17174
                        User-Agent: Cisco/SPA525G2-7.6.2e
                        Received: sip:2.2.2.2:5064
                        Path: <sip:172.30.155.1;lr;received=sip:2.2.2.2:5064;r2=on>,<sip:3.3.3.3:6050;lr;received=sip:2.2.2.2:5064;r2=on>
                        State: CS_DIRTY
                        Flags: 0
                        CFlags: 128
                        Socket: udp:172.30.154.189:5060
                        Methods: 6815
                        Ruid: uloc-5f3be864-5d75-2
                        Instance: [not set]
                        Reg-Id: 0
                        Server-Id: 0
                        Tcpconn-Id: -1
                        Keepalive: 0
                        Last-Keepalive: 1597771100
                        KA-Roundtrip: 0
                        Last-Modified: 1597771100
                }
        }
</code></pre>
<h3>Possible Solutions</h3>
<p>There are two ways I can thing of to mitigate this:</p>
<ul>
<li>Modify the path module so that the received parameter is only set for the first Path header, which corresponds to the interface the request was received on. I believe this is the preferred way to deal with this, as I don't see the point in adding ";received" to both path entries when performing double "r2" path injection.</li>
<li>Or, make usrloc keepalive behave the same way as loose_route(). It seems loose_route will only honour the ";received=" parameter in a Route header only if it's the last remaining one? I'm not sure this is how it works, but somehow I get the desired behaviour with loose_route()</li>
</ul>
<p>On a sidenote, usrloc locally generated OPTIONS do not seem to be handled by the local-request event route. Is this intentional? AFAICT it would require engaging the tm module which will add some overhead...</p>

<h3>Additional Information</h3>
<ul>
<li><strong>Kamailio Version</strong> - output of <code>kamailio -v</code></li>
</ul>
<pre><code>version: kamailio 5.4.0 (x86_64/linux)
</code></pre>
<p>built with this patch: <a class="commit-link" data-hovercard-type="commit" data-hovercard-url="https://github.com/kamailio/kamailio/commit/19128f2121d8b859a6a546dfdf2c0855b9bd9502/hovercard" href="https://github.com/kamailio/kamailio/commit/19128f2121d8b859a6a546dfdf2c0855b9bd9502"><tt>19128f2</tt></a></p>
<ul>
<li><strong>Operating System</strong>:</li>
</ul>

<pre><code>Linux sbcpub0-stage-lhe0-cn1 4.19.0-8-amd64 #1 SMP Debian 4.19.98-1 (2020-01-26) x86_64 GNU/Linux
</code></pre>

<p style="font-size:small;-webkit-text-size-adjust:none;color:#666;">—<br />You are receiving this because you are subscribed to this thread.<br />Reply to this email directly, <a href="https://github.com/kamailio/kamailio/issues/2447">view it on GitHub</a>, or <a href="https://github.com/notifications/unsubscribe-auth/ABO7UZMZD3MB2GCD27VLYMDSBK2UZANCNFSM4QD2D5NQ">unsubscribe</a>.<img src="https://github.com/notifications/beacon/ABO7UZI43MZOOML5UZ25WNDSBK2UZA5CNFSM4QD2D5N2YY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4KE2NY3A.gif" height="1" width="1" alt="" /></p>
<script type="application/ld+json">[
{
"@context": "http://schema.org",
"@type": "EmailMessage",
"potentialAction": {
"@type": "ViewAction",
"target": "https://github.com/kamailio/kamailio/issues/2447",
"url": "https://github.com/kamailio/kamailio/issues/2447",
"name": "View Issue"
},
"description": "View this Issue on GitHub",
"publisher": {
"@type": "Organization",
"name": "GitHub",
"url": "https://github.com"
}
}
]</script>