<!--
Kamailio Project uses GitHub Issues only for bugs in the code or feature 
requests. Please use this template only for bug reports.

If you have questions about using Kamailio or related to its configuration 
file, ask on sr-users mailing list:

  * http://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users

If you have questions about developing extensions to Kamailio or its existing C 
code, ask on sr-dev mailing list:

  * http://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-dev

Please try to fill this template as much as possible for any issue. It helps 
the developers to troubleshoot the issue.

If there is no content to be filled in a section, the entire section can be 
removed.

You can delete the comments from the template sections when filling.

You can delete next line and everything above before submitting (it is a 
comment).
-->

### Description
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.

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.
<!--
Explain what you did, what you expected to happen, and what actually happened.
-->

### Troubleshooting
#### SIP Traffic

<!--
If the issue is exposed by processing specific SIP messages, grab them with 
ngrep or save in a pcap file, then add them next, or attach to issue, or 
provide a link to download them (e.g., to a pastebin site).
-->


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

INVITE sip:[email protected]: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:[email protected]>;tag=as77e25748
To: <sip:[email protected]>
Contact: <sip:[email protected]:5060>
Call-ID: [email protected]
CSeq: 102 INVITE
Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, SUBSCRIBE, NOTIFY, INFO, 
PUBLISH, MESSAGE
Supported: replaces, timer
X-CID: [email protected]
Remote-Party-ID: "sbcpub-stage-test-01" 
<sip:[email protected]>;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
```
2) OPTIONS is routed to "received" value of first Route header when doing 
keepalives using the usrloc module:
```
2020/08/18 19:58:02.450949 172.30.154.189:5060 -> 2.2.2.2:5064

OPTIONS sip:[email protected]: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:[email protected]>;tag=uloc-5f3be864-5d75-2-8617a458-5f3c089a-6e141-1.1
To: <sip:[email protected]>
Call-ID: ksrulka-1.1
CSeq: 80 OPTIONS
Content-Length: 0
```

#### usrloc entries

The location entries for the examples above are as follows:
```
        AoR: voip-test-user-04
        Contacts: {
                Contact: {
                        Address: sip:[email protected]: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:[email protected]:5064
                        Expires: 88
                        Q: -1.000000
                        Call-ID: [email protected]
                        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
                }
        }
```

### Possible Solutions
There are two ways I can thing of to mitigate this:
* 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.
* 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()

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...
<!--
If you found a solution or workaround for the issue, describe it. Ideally, 
provide a pull request with a fix.
-->

### Additional Information

  * **Kamailio Version** - output of `kamailio -v`

```
version: kamailio 5.4.0 (x86_64/linux)
```
built with this patch: 
https://github.com/kamailio/kamailio/commit/19128f2121d8b859a6a546dfdf2c0855b9bd9502


* **Operating System**:

<!--
Details about the operating system, the type: Linux (e.g.,: Debian 8.4, Ubuntu 
16.04, CentOS 7.1, ...), MacOS, xBSD, Solaris, ...;
Kernel details (output of `uname -a`)
-->

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


-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/kamailio/kamailio/issues/2447
_______________________________________________
Kamailio (SER) - Development Mailing List
[email protected]
https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-dev

Reply via email to