<!-- Kamailio Project uses GitHub Issues only for bugs in the code or feature requests.
If you have questions about using Kamailio or related to its configuration file, ask on sr-users mailing list:
* http://lists.sip-router.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.sip-router.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 you submit a feature request (or enhancement), you can delete the text of the template and only add the description of what you would like to be added.
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
<!-- Explain what you did, what you expected to happen, and what actually happened. -->
### Troubleshooting
#### Reproduction
we have an issue with our Kamailio.
This configuration is multi-homed, we have two network interfaces, one on a private network and on the public Internet. Kamailio is configured to listen on port 5060 and 5066 on both interfaces. We register two users Alice and Bob on the public Internet using port 5066. Both users are behind a NAT and we capture the SIP exchange on the proxy server.
We have set the parameter mhomed=1

The ACK packet gets relayed with the wrong source port. Then the NAT rejects the packet and the call cannot be established.
Also, if we set mhomed=0 it works BUT we are not sure that multi homed is handled correctly.
the issue seems to be located in the RR module and the loose_route() function. In the after_loose() function in loose.c, the function set_force_socket() is called only if a DOUBLE route is mentioned in the route set of the ACK message
But when both users are using 5066 as proxy port, we get only ONE route for the proxy in the route set (and to us it is OK). In this case, we get a trace:
"No next URI found"
and the code exits. Later in the message processing, when t_relay() is called, the forward_request() selects the first socket defined in our configuration instead.
At this point, we can't presume what socket we be select. We believe that it is a software bug and that after_loose() should force the send_socket even though we have only one route in the route set
#### Debugging Data
<!-- If you got a core dump, use gdb to extract troubleshooting data - full backtrace, local variables and the list of the code at the issue location.
gdb /path/to/kamailio /path/to/corefile bt full info locals list
If you are familiar with gdb, feel free to attach more of what you consider to be relevant. -->
``` (paste your debugging data here) ```
#### Log Messages
<!-- Check the syslog file and if there are relevant log messages printed by Kamailio, add them next, or attach to issue, or provide a link to download them (e.g., to a pastebin site). -->
``` (paste your log messages here) ```
#### 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). -->
``` (paste your sip traffic here) ```
### Possible Solutions Adding the process of set_force_socket in case we have one route and only.
L.808 if (res > 0) { /* No next route found */ LM_DBG("No next URI found\n");
if (!use_ob) { if ((si = grep_sock_info( &puri.host, puri.port_no?puri.port_no:proto_default_port(puri.proto), puri.proto)) != 0) { set_force_socket(_m, si); } else if ((si = grep_sock_info( &puri.host, puri.port_no, puri.proto)) != 0) { set_force_socket(_m, si); } else { if (enable_socket_mismatch_warning) { LM_WARN("no socket found to match second RR (%.*s)\n", rt->nameaddr.uri.len, ZSW(rt->nameaddr.uri.s)); if(!is_myself(&puri)) { LM_WARN("second RR uri is not myself (%.*s)\n", rt->nameaddr.uri.len, ZSW(rt->nameaddr.uri.s)); } } } }
status = (preloaded ? NOT_RR_DRIVEN : RR_DRIVEN); goto done; }
### Additional Information
* **Kamailio Version** - output of `kamailio -v`
``` (paste your output here) ```
* **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`) -->
``` (paste your output here) ```
I pushed a commit to rr module adding a new parameter that allows enforcing send socket even on a single Route header - see 93739c0b8674a09f8364eac6f28bcc91b167843a .
Testing and providing feedback will be appreciated.
Anyhow, for older versions you can force the socket from config, after loose_route, do something like:
``` $fs = $pr + ":" + $(route_uri{uri.host}) + ":" + $(route_uri{uri.port}); ```
Closed #1428.
Closing after the commit and remarks in the previous comment.
Thank you for your time! One of our engineer is currently testing it. If we have any issue or comments ,we will come back to you.
Hi Daniel,
I reviewed the code and unfortunately, it does not cover the case when
- enable_double_rr=1 - both UA are using the same IP and the same port and there is only one route inserted by record_route()
To handle this case, see the patch I suggest below. Alternatively, we could set enable_double_rr=2 I guess. What is your opinion ?
[loose.diff.txt](https://github.com/kamailio/kamailio/files/1716237/loose.diff.txt)
Did you just review the code or you also tested it?
It covers the cases when enable_double_rr is 1 (or different than 0) and there is no second Route header. Because if there is a second route, then the socket is forced later to the outgoing socket.
No I did not test it. I will.
OK, let's see the results, because it should work for single Route header, that was the purpose of the patch.
Ok, I tested and it is working but I would kindly need an explanation
1- the setup : - kamailio 5.1 with three listen (on port 5060, 5063, 5066) - 2 UAs using UDP on port 5063 - added a log in the script
``` route[WITHINDLG] { if (!has_totag()) return;
# sequential request withing a dialog should # take the path determined by record-routing if (loose_route()) { route(DLGURI); if (is_method("BYE")) { setflag(FLT_ACC); # do accounting ... setflag(FLT_ACCFAILED); # ... even if the transaction fails } else if ( is_method("ACK") ) { # ACK is forwarded statelessly xlog("forced socket $fs\n"); route(NATMANAGE); } else if ( is_method("NOTIFY") ) { # Add Record-Route for in-dialog NOTIFY as per RFC 6665. record_route(); } route(RELAY);
```
2- parameter for rr module
``` modparam("rr", "enable_full_lr", 0) modparam("rr", "enable_double_rr", 1)
```
3- result - on K master, ACK gets forwarded **properly** using source port 5036 with the following traces
``` Feb 14 17:13:50 mcudev3 /usr/local/sbin/kamailio[21394]: {1 5765 ACK ffb8d7ca-efae-79ef-6035-dd1043352c55} DEBUG: rr [loose.c:812]: after_loose(): Topmost route URI: 'sip:172.21.100.108:5063;lr' is me
Feb 14 17:13:50 mcudev3 /usr/local/sbin/kamailio[21394]: {1 5765 ACK ffb8d7ca-efae-79ef-6035-dd1043352c55} DEBUG: <core> [core/parser/msg_parser.c:89]: get_hdr_field(): found end of header
Feb 14 17:13:50 mcudev3 /usr/local/sbin/kamailio[21394]: {1 5765 ACK ffb8d7ca-efae-79ef-6035-dd1043352c55} DEBUG: rr [loose.c:181]: find_next_route(): No next Route HF found Feb 14 17:13:50 mcudev3 /usr/local/sbin/kamailio[21394]: {1 5765 ACK ffb8d7ca-efae-79ef-6035-dd1043352c55} DEBUG: rr [loose.c:842]: after_loose(): No next URI found Feb 14 17:13:50 mcudev3 /usr/local/sbin/kamailio[21394]: {1 5765 ACK ffb8d7ca-efae-79ef-6035-dd1043352c55} ERROR: <script>: forced socket <null>` ```
If I inspect the packet I see a single route without transport information. And yet the correct source port is selected ! Can you tell us how kamailio guess the source port to use in that case.
These traces demonstrate that in the loose_route() function, send_socket is NOT forced. And yet this is working. Can you tell me HOW kamailio knows that
Daniel, in fact it is not working. See previous comment.
Have you set `force_send_socket` parameter of `rr` module to `1`? I don't see it in your comment that shows `rr` params in config.
Oups ....
Just tested both with TCP and UDP. Its working fine. Thank you very much!