# Main SIP request routing logic
# - processing of any incoming SIP request starts with this route
# - note: this is the same as route { ... }
request_route {
# NAT detection
route(NATDETECT);
### only initial requests (no To tag)
t_check_trans();
# record routing for dialog forming requests (in case they are routed)
# - remove preloaded route headers
remove_hf("Route");
if (is_method("INVITE"))
record_route_preset("195.235.93.8:5070;transport=TCP");
if (is_method("INVITE|SUBSCRIBE"))
record_route();
# account only INVITEs
if (is_method("INVITE"))
{
setflag(FLT_ACC); # do accounting
}
#ggb: TCP connection reuse
if (proto != UDP) {
add_contact_alias();
}
# dispatch requests to foreign domains
route(SIPOUT);
### requests for my local domains
if ($rU==$null)
{
# request with no Username in RURI
sl_send_reply("484","Address Incomplete");
exit;
}
route(MCU);
route(RELAY);
}
route[RELAY] {
# enable additional event routes for forwarded requests
# - serial forking, RTP relaying handling, a.s.o.
if (is_method("INVITE|SUBSCRIBE")) {
t_on_branch("MANAGE_BRANCH");
t_on_reply("MANAGE_REPLY");
}
if (is_method("INVITE")) {
t_on_failure("MANAGE_FAILURE");
}
if (!t_relay()) {
sl_reply_error();
}
exit;
}
# Caller NAT detection route
route[NATDETECT] {
#!ifdef WITH_NAT
force_rport();
if (nat_uac_test("19")) {
if (is_method("REGISTER")) {
xlog("fix_nated_register");
fix_nated_register();
} else {
xlog("fix_nated_contact");
fix_nated_contact();
}
setflag(FLT_NATS);
}
#!endif
return;
}
# RTPProxy control
route[NATMANAGE] {
#!ifdef WITH_NAT
if (is_request()) {
if(has_totag()) {
if(check_route_param("nat=yes")) {
setbflag(FLB_NATB);
}
}
}
if (!(isflagset(FLT_NATS) || isbflagset(FLB_NATB)))
return;
rtpproxy_manage("", "195.235.93.8");
if (is_request()) {
if (!has_totag()) {
add_rr_param(";nat=yes");
}
}
if (is_reply()) {
if(isbflagset(FLB_NATB)) {
fix_nated_contact();
}
}
#!endif
return;
}
# Routing to foreign domains
route[SIPOUT] {
if (!uri==myself)
{
append_hf("P-hint: outbound\r\n");
route(RELAY);
}
}
# manage outgoing branches
branch_route[MANAGE_BRANCH] {
xdbg("new branch [$T_branch_idx] to $ru\n");
route(NATMANAGE);
}
# manage incoming replies
onreply_route[MANAGE_REPLY] {
xdbg("incoming reply\n");
#ggb: TCP connection reuse
add_contact_alias();
if(status=~"[12][0-9][0-9]")
route(NATMANAGE);
}
onreply_route[CHANGE_SDP] {
xlog("CHANGE_SDP");
if(t_check_status("(200)|(183)"))
{
if(has_body("application/sdp"))
{
if(search("IN IP4 10.95.94.142"))
{
xlog("search IN IP4 .142");
fix_nated_sdp("2", "195.235.93.8");
}
}
}
}
# manage failure routing cases
failure_route[MANAGE_FAILURE] {
route(NATMANAGE);
if (t_is_canceled()) {
exit;
}
#!ifdef WITH_BLOCK3XX
# block call redirect based on 3xx replies.
if (t_check_status("3[0-9][0-9]")) {
t_reply("404","Not found");
exit;
}
#!endif
}
route [MCU]{
if (uri=~"^sip:[7,8][0-9]+@"){
xlog("Forward to MCU");
rewritehost("10.95.94.142");
rewriteport("5070");
rtpproxy_manage();
t_relay();
t_on_reply("CHANGE_SDP");
xlog("after forward to MCU");
exit;
}
}