[SR-Users] Re: Is there any way to modify the Refer-To header username?
Hi Henning, Thanks a lot for the suggestion, it helped me to fix my issue. I used the replace function and it worked perfectly for my use-case! 4.7. replace(re, txt) Replaces the first occurrence of re with txt. Meaning of the parameters is as follows: * re - Regular expression. * txt - String. This function can be used from REQUEST_ROUTE, ONREPLY_ROUTE, FAILURE_ROUTE, BRANCH_ROUTE. Example 1.7. replace usage ... replace("server", "Kamailio SIP Proxy"); ... Regards, Shah Hussain From: Henning Westerholt Sent: Thursday, May 9, 2024 5:36 PM To: Kamailio (SER) - Users Mailing List Cc: Shah Hussain Khattak Subject: RE: Is there any way to modify the Refer-To header username? Hello, there are other functions in textops module, e.g. subst(..) that can be used to do replacements. Have a look to this module for more details and examples. The approach of deleting and adding it new works as well, of course. Cheers, Henning -- Henning Westerholt – https://skalatan.de/blog/ Kamailio services – https://gilawa.com<https://gilawa.com/> From: Shah Hussain Khattak via sr-users Sent: Donnerstag, 9. Mai 2024 08:16 To: Kamailio (SER) - Users Mailing List Cc: Shah Hussain Khattak Subject: [SR-Users] Is there any way to modify the Refer-To header username? Hello Experts, I wanted to check, is there any way to modify the username part of the Refer-To header in Kamailio? For example, I am getting the following header: REFER-TO: > the username part is missing. Can I add a username inside it? For example, change it to REFER-TO: > REFER-TO: > I could not find any solution in the mailing list, the only way was to remove the header and then re-add it. Thank you! Regards, Shah Hussain __ Kamailio - Users Mailing List - Non Commercial Discussions To unsubscribe send an email to sr-users-le...@lists.kamailio.org Important: keep the mailing list in the recipients, do not reply only to the sender! Edit mailing list options or unsubscribe:
[SR-Users] Is there any way to modify the Refer-To header username?
Hello Experts, I wanted to check, is there any way to modify the username part of the Refer-To header in Kamailio? For example, I am getting the following header: REFER-TO: the username part is missing. Can I add a username inside it? For example, change it to REFER-TO: REFER-TO: I could not find any solution in the mailing list, the only way was to remove the header and then re-add it. Thank you! Regards, Shah Hussain __ Kamailio - Users Mailing List - Non Commercial Discussions To unsubscribe send an email to sr-users-le...@lists.kamailio.org Important: keep the mailing list in the recipients, do not reply only to the sender! Edit mailing list options or unsubscribe:
[SR-Users] Re: Need guidance on Teams interop with Kamailio
Hi, Thanks for the response. I managed to fix this by just adding a check in my route block based on incoming BYE message and simply relayed it: if (is_method("BYE") && $ua=~"FreeSwitch BOX/v1\\.0") { t_relay(); exit; } This fixed my issue. Some other minor tweaks that I applied: For blind and attended call transfers from MS Teams, I had to disable REFER support towards MS Teams, then you will be able to perform any kind of transfer from the Teams client. Teams require SBC FQDN in the CONTACT header of the INVITE and 200 OK message. To address the ringback tone issue for inbound calls, I converted the 183 response with SDP into a 180 response without SDP and relayed it towards my PSTN route. After all, configuring Kamailio with MS Teams was a good learning experience; it works like a charm and opens door to many interesting interop scenarios. Regards, Shah Hussain From: Kjartan S via sr-users Sent: Friday, March 15, 2024 4:23 PM To: sr-users@lists.kamailio.org Cc: Kjartan S Subject: [SR-Users] Re: Need guidance on Teams interop with Kamailio Your Kamailio is using the RURI for routing the BYE and not RR header. My tip is to xlog your Kamailio config in order to see if the subsequent BYE request will run the loose_route function inside your route[WITHINDLG]. if (loose_route()) { if (is_method("BYE")) { xlog("L_INFO","Running loose route for subsequent BYE request from $si : $sp \n"); } I also recommend not to remove any record route headers when engaging with MS Teams - so do not remove any RR header and make sure your FreePBX include record route header originally received from Teams. Regarding the call disconnect: Might be that the corresponding ACK or the 200 OK (depending on Teams being UAC/UAS`) is not handled from MS Teams side. Again, make sure not to replace to much of the headers received from Teams apart from what is mentioned in the MS Teams Kamailio guide. __ Kamailio - Users Mailing List - Non Commercial Discussions To unsubscribe send an email to sr-users-le...@lists.kamailio.org Important: keep the mailing list in the recipients, do not reply only to the sender! Edit mailing list options or unsubscribe: __ Kamailio - Users Mailing List - Non Commercial Discussions To unsubscribe send an email to sr-users-le...@lists.kamailio.org Important: keep the mailing list in the recipients, do not reply only to the sender! Edit mailing list options or unsubscribe:
[SR-Users] Need guidance on Teams interop with Kamailio
Hello Experts, I'm not an expert in Kamailio, but thanks to some excellent online resources, I managed to set up a basic interconnection between Teams and Kamailio. So far, outbound calls, as well as blind and attended call transfers, are working smoothly. However, I'm facing a challenge with call disconnection for outbound calls. Specifically, when an outbound call is made and the called party hangs up, the BYE message isn't being relayed properly towards the Teams side. In my routing configurations, I remove the Record-Route header received from Teams and add a new Record-Route header with Kamailio's IP before forwarding it to my IP PBX (FreeSwitch). For the BYE message to be processed correctly, Microsoft Teams requires the original contact in the Request URI (RURI) and the Route header to match the initial Record-Route included in the INVITE. Currently, my BYE message appears as follows: BYE sip:api-du-a-auea.pstnhub.microsoft.com:443;x-i=5e96d703-b1e7-449c-aebf-a87bfa628176;x-c=f61b674bc597513ab8d888dbe7c560fb/d/8/9a6c508a9cbd44ebb892b62c33ba9b67 SIP/2.0 Via: SIP/2.0/UDP x.x.x.x:5060;branch=z9hG4bKeab5.b657e3455b6d11ed6975c69882632a27.0 Via: SIP/2.0/UDP x.x.x.x;received=x.x.x.x;rport=5060;branch=z9hG4bKK3HKQBUvX42ya Max-Forwards: 69 From: ;tag=j5gptBSXXrXDc To: "XYZ Pty Ltd" ;tag=3a5f0c9e32bc4eb1bffed29dc954118f Call-ID: f61b674bc597513ab8d888dbe7c560fb CSeq: 80555743 BYE User-Agent: Unknown/v1.0 Allow: INVITE, ACK, BYE, CANCEL, OPTIONS, MESSAGE, INFO, UPDATE, REGISTER, REFER, NOTIFY Supported: timer, path, replaces Reason: MVTSLocal;cause=10;text="BYE received" Content-Length: 0 Kamailio conducts a lookup for api-du-a-auea.pstnhub.microsoft.com but ends up sending the BYE message to an incorrect IP. Below is a snippet of my routing block configurations: ### Routing Logic /* Main SIP request routing logic * - processing of any incoming SIP request starts with this route * - note: this is the same as route { ... } */ request_route { # per request initial checks route(REQINIT); #check who is the sender route(INITCHECK); # CANCEL processing if (is_method("CANCEL")) { if (t_check_trans()) { route(RELAY); } exit; } # handle retransmissions if (!is_method("ACK")) { if(t_precheck_trans()) { t_check_trans(); exit; } t_check_trans(); } # handle requests within SIP dialogs route(WITHINDLG); ### only initial requests (no To tag) # record routing for dialog forming requests (in case they are routed) # - remove preloaded route headers remove_hf("Route"); if (is_method("INVITE|SUBSCRIBE")) { record_route(); } # account only INVITEs if (is_method("INVITE")) { setflag(FLT_ACC); # do accounting } if ($rU==$null) { # request with no Username in RURI sl_send_reply("484","Address Incomplete"); exit; } # update $du to set the destination address for proxying #$du = "sip:" + $rd + ":9"; route(RELAY); exit; } route[INITCHECK] { if(from_uri =~ ".*microsoft.com") { setflag(FROM_TEAMS); $du = "sip:" + "MY_PBX_IP" + ":" + "5060"; //added by SHK remove_hf("Record-Route"); // Remove existing Record-Route header append_hf("Record-Route: \r\n"); route(HANDLE_RTP_FROM_TEAMS); } if(from_uri =~ ".*" + "MY_PBX_IP") { setflag(FROM_PBX); $du="sip:sip.pstnhub.microsoft.com;transport=tls"; route(HANDLE_RTP_FROM_PBX); } } #Manage RTP & transcoding comming from Teams to PBX route[HANDLE_RTP_FROM_TEAMS] { t_on_reply("PBX_REPLY_TO_TEAMS"); if (has_body("application/sdp")) { rtpengine_manage("RTP codec-mask=all codec-transcode=PCMA replace-origin replace-session-connection ICE=remove media-address=HOST_IP"); // record_route(); t_relay_to_udp("MY_PBX_IP","5060"); } else { rtpengine_manage(); } } #Manage RTP & transcoding comming from PBX to Teams route[HANDLE_RTP_FROM_PBX] { t_on_reply("TEAMS_REPLY_TO_PBX"); if (has_body("application/sdp")) { rtpengine_manage("SRTP codec-mask=all ICE=force codec-transcode=PCMA replace-origin replace-session-connection media-address=ADVERTISE_IP"); $rd = "sip.pstnhub.microsoft.com"; $td = "kamsbc.xyzdomain.com"; $fd = "kamsbc.xyzdomain.com"; // record_route(); #Set
[SR-Users] Iterating Through Multiple IP Peers for DID Call Termination in Kamailio
Hello Team, I hope you're all doing well. I'm reaching out to request your insights on the following scenario. Overview: I have successfully configured Kamailio to authenticate IP addresses, primarily for PBXs and customers unable to register. With this setup, I can flawlessly receive incoming traffic and forward it to our internal FreeSwitch servers. Current issue: Now, I'm focusing on managing traffic in the opposite direction—specifically for DIDs. I have a DID table set up in Kamailio that associates DID numbers with their respective IP peers. Upon receiving a call, a database lookup is performed to find the destination number, after which the call is terminated at the customer's IP. I'm facing difficulty in handling situations where a customer has multiple IP peers (for redundancy). My aim is to try each of these IPs sequentially when terminating a specific DID call towards them. The current logic I'm employing for the INVITE lookup looks like this: # Database lookup for INVITEs if (is_method("INVITE")) { sql_query("didrouting_db", "SELECT route_to FROM did_routing WHERE did_number='$rU'", "result"); if ($dbr(result=>rows) > 0) { $var(route_to) = $dbr(result=>[0,0]); xlog("L_INFO", "Routing DID $rU to $var(route_to)\n"); $du = "sip:" + $var(route_to) + ":5060"; } else { $du = "sip:" + FS_IP + ":5060"; } } The above logic works fine for a single IP. I intend to use a comma-separated list of IPs in my route_to column (for example 192.168.1.2,192.168.1.3, ...) and then iterate through these IPs one by one. I'm having trouble coming up with a workable logic or loop to achieve this. Would you be able to offer any guidance or suggestions? Please also recommend if there is a better approach available to handle this scenario. Thank you in advance for your valuable input. Regards, Shah Hussain __ Kamailio - Users Mailing List - Non Commercial Discussions To unsubscribe send an email to sr-users-le...@lists.kamailio.org Important: keep the mailing list in the recipients, do not reply only to the sender! Edit mailing list options or unsubscribe:
[SR-Users] Re: Modifying SDP as drop-in replacement for overloaded Asterisk box - looking for help/paid consulting fast
Hmm, try to use: subst_hf() then: 3.15. subst_hf(hf, subexp, flags) Perl-like substitutions in the body of a header field. Meaning of the parameters is as follows: * hf - header field name. * subexp - substitution expression in the same format as of the 'subst' function parameter. * flags - control flags - it has to be one of: a - all headers matching the name; f - only first header matching the name; l - only the last header matching the name. This function can be used from REQUEST_ROUTE, ONREPLY_ROUTE, FAILURE_ROUTE, BRANCH_ROUTE. Example 1.15. search_body usage ... if ( subst_hf("From", "/:test@/:best@/", "a") ) { /**/ }; ... For example, from one google search: subst_hf("Contact", "/(.*)?<(sip):(.*)@(.*)//", "a"); Sent from my iPhone On 22 Sep 2023, at 9:25 pm, Markus wrote: textops.so was already loaded. Now added textopsx.so too but the error remains the same. Is $cU a pseudo-variable that should be available within Kamailio by default? I can't find it here: https://www.kamailio.org/wiki/cookbooks/5.5.x/pseudovariables Is it maybe $ct or something else? :) "$ct - Contact header $ct - reference to body of contact header" Thanks again, Markus Am 22.09.2023 um 13:15 schrieb Shah Hussain Khattak: I should have mentioned, please load the following modules: loadmodule "textops.so" loadmodule "textopsx.so" then restart Kamailio. *From:* Markus *Sent:* Friday, September 22, 2023 5:58 PM *To:* sr-users@lists.kamailio.org *Cc:* Shah Hussain Khattak *Subject:* Re: [SR-Users] Modifying SDP as drop-in replacement for overloaded Asterisk box - looking for help/paid consulting fast Wow, cool, thanks! I added this snippet in the request_route { part, I hope that's correct. When I try to start Kamailio I get: kamailio: Not starting : invalid configuration file! kamailio: 0(2371) ERROR: [pvapi.c:828]: pv_parse_spec2(): error searching pvar "cU" kamailio: 0(2371) ERROR: [pvapi.c:1032]: pv_parse_spec2(): wrong char [U/85] in [$cU] at [2 (0)] kamailio: 0(2371) : [cfg.y:3368]: yyerror_at(): parse error in config file //etc/kamailio/kamailio.cfg, line 530, column 34-36: Can't get from cache: $cU Somehow it doesn't know what $cU is? It looks like this now: ... # authentication route(AUTH); $ru = "sip:" + $rU + "@3.3.3.3"; $tu = "sip:" + $tU + "@3.3.3.3"; $fu = "sip:" + $fU + "@2.2.2.2"; $var(contact_username) = $cU; # Remove existing Contact header remove_hf("Contact"); # Insert new Contact header using the stored username insert_hf("Contact: \r\n"); # record routing for dialog forming requests (in case they are routed) # - remove preloaded route headers remove_hf("Route"); if (is_method("INVITE|SUBSCRIBE")) record_route(); ... (formatting changed for E-Mail compatibility) Thanks again, Markus Am 22.09.2023 um 10:04 schrieb Shah Hussain Khattak: You can start with the following: # Change URI(s) $ru = "sip:" + $rU + "@3.3.3.3"; $tu = "sip:" + $tU + "@3.3.3.3"; $fu = "sip:" + $fU + "@2.2.2.2"; $var(contact_username) = $cU; # Remove existing Contact header remove_hf("Contact"); # Insert new Contact header using the stored username insert_hf("Contact: \r\n"); OR # Insert new Contact header using the stored username insert_hf("Contact: \r\n"); and then add the remaining modifications if needed as per your upstream carrier requirements. Regards, Shah Hussain *From:* Markus *Sent:* Friday, September 22, 2023 8:58 AM *To:* sr-users@lists.kamailio.org *Subject:* [SR-Users] Modifying SDP as drop-in replacement for overloaded Asterisk box - looking for help/paid consulting fast Hi list, I'm trying to use Kamailio 4.4.4 with rtpengine in a self-inflicted emergency situation (didn't monitor traffic growth properly and now encountering packet loss during peak times) as a drop-in replacement for an overloaded Asterisk box in a call-termination-to-upstream-carrier scenario. My test scenario is to make a call from a SIP softphone to Asterisk IP 1.1.1.1 -> Kamailio/rtpengine IP 2.2.2.2 -> Upstream carrier 3.3.3.3 sngrep on Kamailio box 2.2.2.2 - the following SDP will not work - carrier is rejecting it. Carrier is authenticating our calls based on our IP address 2.2.2.2, no username/pass involved. 2023/09/22 02:06:49.216136 2.2.2.2:5060 -> 3.3.3.3:5060 INVITE sip:+32@2.2.2.2;user=phone SIP/2.0 Record-Route: Via: SIP/2.0/UDP 2.2.2.2;branch=z9hG4bKd9c3.d6fa3abe5d52b827e2054de5573028e0.0 Via: SIP/2.0/UDP 1.1.1.1:5060;branch=z9hG4bK473270e8 Max-Forwards: 69 From: "61x" ;tag=as3d75aadd To: Contact: Call-ID: 3f31e1622a72b6d17f24e42362f4f1d0@1.1.1.1:5060 CSeq: 102 INVITE User-Agent: Asterisk PBX 20.0.0 Date: Fri, 22 Sep 2023 00:06:50 GMT Session-Expires: 1800 Min-SE: 90 Allow: INVITE, ACK, CANCEL, OPTIONS, BYE,
[SR-Users] Re: Modifying SDP as drop-in replacement for overloaded Asterisk box - looking for help/paid consulting fast
I should have mentioned, please load the following modules: loadmodule "textops.so" loadmodule "textopsx.so" then restart Kamailio. From: Markus Sent: Friday, September 22, 2023 5:58 PM To: sr-users@lists.kamailio.org Cc: Shah Hussain Khattak Subject: Re: [SR-Users] Modifying SDP as drop-in replacement for overloaded Asterisk box - looking for help/paid consulting fast Wow, cool, thanks! I added this snippet in the request_route { part, I hope that's correct. When I try to start Kamailio I get: kamailio: Not starting : invalid configuration file! kamailio: 0(2371) ERROR: [pvapi.c:828]: pv_parse_spec2(): error searching pvar "cU" kamailio: 0(2371) ERROR: [pvapi.c:1032]: pv_parse_spec2(): wrong char [U/85] in [$cU] at [2 (0)] kamailio: 0(2371) : [cfg.y:3368]: yyerror_at(): parse error in config file //etc/kamailio/kamailio.cfg, line 530, column 34-36: Can't get from cache: $cU Somehow it doesn't know what $cU is? It looks like this now: ... # authentication route(AUTH); $ru = "sip:" + $rU + "@3.3.3.3"; $tu = "sip:" + $tU + "@3.3.3.3"; $fu = "sip:" + $fU + "@2.2.2.2"; $var(contact_username) = $cU; # Remove existing Contact header remove_hf("Contact"); # Insert new Contact header using the stored username insert_hf("Contact: \r\n"); # record routing for dialog forming requests (in case they are routed) # - remove preloaded route headers remove_hf("Route"); if (is_method("INVITE|SUBSCRIBE")) record_route(); ... (formatting changed for E-Mail compatibility) Thanks again, Markus Am 22.09.2023 um 10:04 schrieb Shah Hussain Khattak: > You can start with the following: > > > # Change URI(s) > $ru = "sip:" + $rU + "@3.3.3.3"; > $tu = "sip:" + $tU + "@3.3.3.3"; > $fu = "sip:" + $fU + "@2.2.2.2"; > > $var(contact_username) = $cU; > > # Remove existing Contact header > remove_hf("Contact"); > > # Insert new Contact header using the stored username > insert_hf("Contact: > \r\n"); > OR > # Insert new Contact header using the stored username > insert_hf("Contact: \r\n"); > > and then add the remaining modifications if needed as per your upstream > carrier requirements. > > > Regards, > Shah Hussain > > *From:* Markus > *Sent:* Friday, September 22, 2023 8:58 AM > *To:* sr-users@lists.kamailio.org > *Subject:* [SR-Users] Modifying SDP as drop-in replacement for > overloaded Asterisk box - looking for help/paid consulting fast > Hi list, > > I'm trying to use Kamailio 4.4.4 with rtpengine in a self-inflicted > emergency situation (didn't monitor traffic growth properly and now > encountering packet loss during peak times) as a drop-in replacement for > an overloaded Asterisk box in a call-termination-to-upstream-carrier > scenario. > > My test scenario is to make a call from a SIP softphone to Asterisk IP > 1.1.1.1 -> Kamailio/rtpengine IP 2.2.2.2 -> Upstream carrier 3.3.3.3 > > sngrep on Kamailio box 2.2.2.2 - the following SDP will not work - > carrier is rejecting it. Carrier is authenticating our calls based on > our IP address 2.2.2.2, no username/pass involved. > > 2023/09/22 02:06:49.216136 2.2.2.2:5060 -> 3.3.3.3:5060 > INVITE sip:+32@2.2.2.2;user=phone SIP/2.0 > Record-Route: > Via: SIP/2.0/UDP > 2.2.2.2;branch=z9hG4bKd9c3.d6fa3abe5d52b827e2054de5573028e0.0 > Via: SIP/2.0/UDP 1.1.1.1:5060;branch=z9hG4bK473270e8 > Max-Forwards: 69 > From: "61x" ;tag=as3d75aadd > To: > Contact: > Call-ID: 3f31e1622a72b6d17f24e42362f4f1d0@1.1.1.1:5060 > CSeq: 102 INVITE > User-Agent: Asterisk PBX 20.0.0 > Date: Fri, 22 Sep 2023 00:06:50 GMT > Session-Expires: 1800 > Min-SE: 90 > Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, SUBSCRIBE, NOTIFY, > INFO, PUBLISH, MESSAGE > Supported: replaces, timer > P-Asserted-Identity: > Content-Type: application/sdp > Content-Length: 314 > X-SIP: 1.1.1.1 > > v=0 > o=root 1093000903 1093000903 IN IP4 1.1.1.1 > s=Asterisk PBX 20.0.0 > c=IN IP4 2.2.2.2 > t=0 0 > m=audio 25742 RTP/AVP 8 9 0 101 > a=maxptime:150 > a=rtpmap:8 PCMA/8000 > a=rtpmap:9 G722/8000 > a=rtpmap:0 PCMU/8000 > a=rtpmap:101 telephone-event/8000 > a=fmtp:101 0-16 > a=sendrecv > a=rtcp:25743 > a=ptime:20 > > I'm comparing this rejected INVITE to a successful INVITE sent by the > original Asterisk box at IP 2.2.2.2 (now Kamailio box) to the carrier > without Kamailio in the path, and these are the differences I noticed, > and probably the things I have to mimick with Kamailio in order to make > it work: > > INVITE sip:+32x@2.2.2.2;user=phone SIP/2.0 > should be > INVITE sip:+32x@3.3.3.3;user=phone SIP/2.0 > > To: > should be > To: > > From: "61x" ;tag=as3d75aadd > should be > From: "61x" ;tag=as3d75aadd > > Contact: > should be > Contact: > > Call-ID: 3f31e1622a72b6d17f24e42362f4f1d0@1.1.1.1:5060 > should be > Call-ID: