xadhoom created an issue (kamailio/kamailio#4301)
<!-- 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:
* https://lists.kamailio.org/mailman3/postorius/lists/sr-users.lists.kamailio....
If you have questions about developing extensions to Kamailio or its existing C code, ask on sr-dev mailing list:
* https://lists.kamailio.org/mailman3/postorius/lists/sr-dev.lists.kamailio.or...
Please try to fill this template as much as possible for any issue. It helps the developers to troubleshoot the issue.
Note that an issue report may be closed automatically after about 2 months if there is no interest from developers or community users on pursuing it, being considered expired. In such case, it can be reopened by writing a comment that includes the token `/notexpired`. About two weeks before considered expired, the issue is marked with the label `stale`, trying to notify the submitter and everyone else that might be interested in it. To remove the label `stale`, write a comment that includes the token `/notstale`. Also, any comment postpone the `expire` timeline, being considered that there is interest in pursuing 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
When topos receives an in-dialog REFER, it correctly unmask everywhing as expected, but not the Refer-To header, which breaks transfers.
### 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). -->
For example, this is the refer from a client:
``` REFER sip:atpsh-685d3cd2-69-2@172.23.42.1;transport=tcp SIP/2.0 Via: SIP/2.0/TCP 172.23.42.1:23045;rport;branch=z9hG4bKlaklhcax Max-Forwards: 70 To: sip:3338063766@example.voismart.com;tag=Brcm20gBS5eZe From: "Joe" sip:1001@example.voismart.com;tag=xbdlk Call-ID: kpjiixyvombnlkw@fedora.fritz.box CSeq: 340 REFER Contact: sip:1001@172.23.42.1:23045;transport=tcp Refer-To: sip:atpsh-685d3cd2-69-4@172.23.42.1;transport=tcp?Replaces=lmhzfrkbucirwbc%40fedora.fritz.box%3bto-tag%3dXDQD403r30jeS%3bfrom-tag%3dtwbnd Referred-By: "Joe" sip:1001@example.voismart.com User-Agent: Twinkle/1.10.3 Content-Length: 0
```
And this is what exits from topos proxy: ``` REFER sip:3338063766@172.23.42.211:5060;transport=udp SIP/2.0 Via: SIP/2.0/TCP 172.23.42.250;branch=z9hG4bK89f.32493a6f0ee894aad0bf66f581e5053a.0;i=3 Max-Forwards: 69 To: sip:3338063766@example.voismart.com;tag=Brcm20gBS5eZe From: "Joe" sip:1001@example.voismart.com;tag=xbdlk Call-ID: kpjiixyvombnlkw@fedora.fritz.box CSeq: 340 REFER Refer-To: sip:atpsh-685d3cd2-69-4@172.23.42.1;transport=tcp?Replaces=lmhzfrkbucirwbc%40fedora.fritz.box%3bto-tag%3dXDQD403r30jeS%3bfrom-tag%3dtwbnd Referred-By: "Joe" sip:1001@example.voismart.com User-Agent: Twinkle/1.10.3 Content-Length: 0 Route: sip:172.23.42.3;transport=tcp;r2=on;lr=on;ftag=xbdlk;did=c84.2b02 Route: sip:172.23.42.3;r2=on;lr=on;ftag=xbdlk;did=c84.2b02 Contact: sip:btpsh-685d3cd2-69-2@172.23.42.250 ```
### Possible Solutions
Will try to find a solution, I see that in `tps_msg.c` `parse_refer_to.h` is included so perhaps there was some idea about it, but since I'm not an expert in kamailio internals may need some time.
### Additional Information v6.0.x and master
xadhoom left a comment (kamailio/kamailio#4301)
I see that topoh actually does that, so maybe is just needed to port that part. Will try.
miconda left a comment (kamailio/kamailio#4301)
Can you provide a pcap file for such case, from the beginning of first call involved, till the end of all calls?
xadhoom left a comment (kamailio/kamailio#4301)
Attached.
The network scheme is the following:
client -> edge proxy (with topos) -> "worker" proxy -> freeswitch
Even the b2bua says "202 Accepted", it fails since the refer-to header points to nowhere (another call is placed by FS which then fails).
[topos_refer_to.pcap.gz](https://github.com/user-attachments/files/21032411/topos_refer_to.pcap.gz)
xadhoom left a comment (kamailio/kamailio#4301)
In the end, since to properly un-topos it needs some step and my C knowledge is not that good, I was able to do it from the script.
For example: ``` route[MANGLE_REFER] { if (!has_totag()) return;
if (!is_method("REFER")) return;
if ($rt ne "") { $var(hdrs) = $(rt{uri.headers}); $var(hdrs) = $(var(hdrs){s.urldecode.param}); $var(uri-user) = $(rt{uri.user});
if ($(var(hdrs){param.in,Replaces,&}) == 0) { xlog("L_DBG", "Detected blind transfer to $rt skipping mangling \n"); return; }
$var(replaces) = $(var(hdrs){param.value,Replaces,&}); $var(from-tag) = $(var(replaces){param.value,from-tag}); $var(to-tag) = $(var(replaces){param.value,to-tag}); $var(call-id) = $(var(replaces){s.select,0,;});
xlog("L_DBG", "Got Refer-To: $rt \n"); xlog("L_DBG", "Got Refer-To headers $var(hdrs) \n"); xlog("L_DBG", "Got Refer-To replaces $var(replaces) \n"); xlog("L_DBG", "Got Refer-To uri user $var(uri-user) \n"); xlog("L_DBG", "Got Refer-To call-id $var(call-id) \n"); xlog("L_DBG", "Got Refer-To from tag $var(from-tag) \n"); xlog("L_DBG", "Got Refer-To to tag $var(to-tag) \n");
$var(query) = $_s(SELECT b_contact FROM topos_d WHERE a_callid = '$var(call-id)' AND a_uuid = '$var(uri-user)'); sql_xquery("conn1", "$var(query)", "topos_rset"); switch ($rc) { case 1: xlog("L_DBG", "B-Contact for refer is $xavp(topos_rset=>b_contact)\n"); break; case -1: xlog("L_ERR", "Error in topos lookup of refer target contact \n"); return; break; default: xlog("L_ERR", "Unhandled result $rc in lookup of refer target contact \n"); return; }
remove_hf("Refer-To");
$var(params) = $_s($var(call-id);to-tag=$var(to-tag);from-tag=$var(from-tag)); $var(params_enc) = $(var(params){s.urlencode.param}); $var(new_replaces) = $_s(Replaces=$var(params_enc));
xlog("L_DBG", "Replacing refer target contact with $var(new_replaces) \n");
append_hf("Refer-To: <$xavp(topos_rset=>b_contact)?$var(new_replaces)>\r\n"); } else { xlog("L_ERR", "Uh? Refer without Refer-To \n");
return; } } ```
and then (for example) in call it from the route WITHIN_DIALOG just before the loose_route relay.
This won't work if call-id is masked, but in my setup I'm not using call-id masking.