the way i do it:
i do ds_select and use a specific relay setting a specific FAILURE from the
R server
# Send the call over to one of the R servers, which are in the
1000 setid (dispatcher)
if (ds_select_dst("DEFAULT_R_SETID", "4", "2"))
{ # round-robin
route(RELAY_TO_R);
}
then
route[RELAY_TO_R]
{
t_on_failure("FAILURE_FROM_R");
t_on_branch("2");
...
then:
# This will get triggered when R server replies with a 302
failure_route[FAILURE_FROM_R] {
if (t_is_canceled()) {
exit;
}
# detect failure and redirect to next available GW
if (t_check_status("(408)|([56][0-9][0-9])")) {
if (ds_next_dst()) {
xlog("L_ERR", "[$ci][$rm]: Server did not respond, trying next
R server\n");
t_on_failure("FAILURE_FROM_R"); # use other R servers in
failover
t_relay();
exit;
}
xlog("L_ERR", "[$ci][$rm]: All R gateways failed to respond,
continuing routing without Identity header\n");
route(INVITE);
}
# detect redirect, store the header and send to "invite" as normally
if (t_check_status("302")) {
$var(rspb) = $T_rpl($mb);
$var(id_hdr) = $(var(rspb){line.sw,Identity:});
if ($(var(id_hdr){s.len}) >10) {
$avp(identity_header) = $(var(id_hdr){s.substr,10,0}{s.trim});
} else {
xlog("L_ERR", "[$ci][$rm]: R replied, but did not get the
Identity header, sending the call forward without it\n");
}
while (ds_next_dst()) { # since we're using dispatcher again, we
want a fresh start
xlog("L_DBG", "clearing dispatcher stack from R
_dsdst_.uri=$xavp(_dsdst_=>uri)");
}
route(INVITE);
}
}
Regards,
David Villasmil
email: david.villasmil.work(a)gmail.com
phone: +34669448337
On Sun, Jun 9, 2024 at 8:16 PM Rob Green via sr-users <
sr-users(a)lists.kamailio.org> wrote:
For posterity and to help other people since this doesnt appear to be
common request, this is what i did to get it working. Basically, i
switched to using uac_redirect.so module, save the headers returned from
the 300 reply, and then send new invite with those headers using
get_redirects().
# Manage incoming replies in transaction context
onreply_route[MANAGE_REPLY] {
xdbg("DBG: incoming reply\n");
if(status=~"[12][0-9][0-9]") {
route(NATMANAGE);
}
if (t_check_status("3[0-9][0-9]")) {
xlog("L_INFO", "DBG: got 3xx redirect");
# grab the header from the 300 redirect and save it to add to
invite
$shv(identity) = $hdr(Identity);
xlog("L_INFO","DBG: manage_reply: redirect identity:
[$shv(identity)]");
}
return;
}
# Manage failure routing cases
failure_route[MANAGE_FAILURE] {
route(NATMANAGE);
if (t_is_canceled()) exit;
if (t_check_status("3[0-9][0-9]")) {
xlog("L_INFO", "DBG: following 3xx redirect");
xlog("L_INFO","DBG: manage_failure: redirect identity:
[$shv(identity)]");
# add the saved header onto the new invite(s) being sent out
append_hf("Identity: $shv(identity)\r\n");
get_redirects("*:1");
route(RELAY);
exit;
}
return;
}
Rob Green
Chief Information Officer (CIO)
[image: NUWAVE Communications] <https://www.nuwave.com/>
Tel: 1-352-218-1490
Cell: 1-407-620-0932
Email: rob.green(a)nuwave.com
Web:
www.nuwave.com
[image: LinkedIn] <https://www.linkedin.com/company/1613876/admin/>
[image: Twitter] <https://twitter.com/nuwavecomm>
[image: Facebook] <https://www.facebook.com/nuwavecommunications>
[image: Explore iPILOT, Communications in Minutes, not Months.]
<http://ipilot.io/>
This communication is the Property of NUWAVE Communications and may
contain confidential or privileged information. Unauthorized use of this
communication is strictly prohibited and may be unlawful. If you have
received this communication in Error, Please immediately notify the sender
by reply e-mail and destroy all copies of the communication and any
attachments.
------------------------------
*From:* Rob Green via sr-users <sr-users(a)lists.kamailio.org>
*Sent:* Friday, June 7, 2024 7:47 PM
*To:* sr-users(a)lists.kamailio.org <sr-users(a)lists.kamailio.org>
*Cc:* Rob Green <rob.green(a)nuwave.com>
*Subject:* [SR-Users] handling 300 redirect requests
sr-users(a)lists.kamailio.org appears similar to someone who previously
sent you email, but may not be that person. Learn why this could be a risk
<https://aka.ms/LearnAboutSenderIdentification>
I am trying to proxy a request from server A to server C with me being
server B. i send the invite from A to B, then i need to send to server R
which returns back to me a 300 redirect, which i then need to take the
answer from the Contsct and then proxy the original invite from A to C.
server A can not handle 3xx responses and must be proxied. I havent been
able to find any examples where the 300 is intercepted and a new invite to
the target is sent. i have the following code but it results in no new
INVITE and the original session is hung until it is canceled. Any idea
what i may be doing wrong? In the example below i am just hardcoding the
uri for the new invite instead of getting from the Contact as a debug
exercise. I am using Kamailio 5.7.3
route[HANDLEREDIRECT] {
xlog("L_INFO", "DBG: HANDLEREDIRECT");
msg_apply_changes();
$var(test) = $hdr(Contact);
xlog("L_INFO","DBG: redirect headers [$var(test)]: from=[$fu]
from_user=[$fU], to=[$tu] to_user=[$tU]");
# send to gateway
$var(new_uri) = "sip:" + $tU + "@" + "gateway";
if ($var(new_uri) != "") {
xlog("DBG: Redirecting to: $var(new_uri)\n");
$ru = $var(new_uri);
$tu = $ru;
record_route();
route(RELAY);
exit;
# i have also tried using
#t_newtran();
# and
#t_relay();
} else {
xlog("DBG: No contact header found in 300 response\n");
}
}
# Manage outgoing branches
branch_route[MANAGE_BRANCH] {
xdbg("DBG: new branch [$T_branch_idx] to $ru\n");
xlog("L_INFO", "DBG: manage branch");
route(NATMANAGE);
return;
}
onreply_route[MANAGE_REPLY] {
xdbg("DBG: incoming reply\n");
xlog("L_INFO", "DBG: manage reply");
if (t_check_status("3[0-9][0-9]")) {
xlog("L_INFO", "DBG: got 3xx redirect");
route(HANDLEREDIRECT);
drop;
}
return;
}
I also tried using uac_redirect module, but it stalls the incoming invite
also, and i cant figure out how to modify the uri from the contact before
sending (to add params)
# Manage failure routing cases
failure_route[MANAGE_FAILURE] {
route(NATMANAGE);
if (t_is_canceled()) exit;
if (t_check_status("3[0-9][0-9]")) {
xlog("L_INFO", "DBG: following 3xx redirect");
get_redirects("3:1");
t_relay();
exit;
}
}
Rob Green
Chief Information Officer (CIO)
[image: NUWAVE Communications] <https://www.nuwave.com/>
Tel: 1-352-218-1490
Cell: 1-407-620-0932
Email: rob.green(a)nuwave.com
Web:
www.nuwave.com
[image: LinkedIn] <https://www.linkedin.com/company/1613876/admin/>
[image: Twitter] <https://twitter.com/nuwavecomm>
[image: Facebook] <https://www.facebook.com/nuwavecommunications>
[image: Explore iPILOT, Communications in Minutes, not Months.]
<http://ipilot.io/>
This communication is the Property of NUWAVE Communications and may
contain confidential or privileged information. Unauthorized use of this
communication is strictly prohibited and may be unlawful. If you have
received this communication in Error, Please immediately notify the sender
by reply e-mail and destroy all copies of the communication and any
attachments.
__________________________________________________________
Kamailio - Users Mailing List - Non Commercial Discussions
To unsubscribe send an email to sr-users-leave(a)lists.kamailio.org
Important: keep the mailing list in the recipients, do not reply only to
the sender!
Edit mailing list options or unsubscribe: