From 536d511de87d222448d30ab87e495b0e4363438f Mon Sep 17 00:00:00 2001 From: Matija Turk Date: Wed, 11 Sep 2024 12:57:34 +0200 Subject: [PATCH] optimized code calls word both ways and options - failover and logs needed - ALMOST DONE --- kamailio.cfg | 62 ++++++++++++++++++++++++---------------------------- 1 file changed, 29 insertions(+), 33 deletions(-) diff --git a/kamailio.cfg b/kamailio.cfg index a6e6fd9..6d98bc3 100644 --- a/kamailio.cfg +++ b/kamailio.cfg @@ -5,7 +5,7 @@ loadmodule "rr.so" loadmodule "maxfwd.so" loadmodule "textops.so" loadmodule "rtpengine.so" -loadmodule "dispatcher.so" +#loadmodule "dispatcher.so" loadmodule "nathelper.so" loadmodule "ctl" loadmodule "pv" @@ -25,14 +25,14 @@ log_facility=LOG_LOCAL0 # RTPProxy settings modparam("rtpengine", "rtpengine_sock", "udp:127.0.0.1:2223") # Dispatcher settings -modparam("dispatcher", "db_url", "mysql://kamailio:kamailiow@localhost/kamailio") -modparam("dispatcher", "ds_ping_interval", 10) -modparam("dispatcher", "ds_ping_method", "OPTIONS") -modparam("dispatcher", "ds_probing_threshold", 10) -modparam("dispatcher", "ds_inactive_threshold", 10) -modparam("dispatcher", "ds_ping_latency_stats", 1) -modparam("dispatcher", "ds_ping_from", "sip:kam@10.0.5.6") -modparam("dispatcher", "ds_probing_mode", 1) #Keeps pinging gateways when state is known (to detect change in state) +#modparam("dispatcher", "db_url", "mysql://kamailio:kamailiow@localhost/kamailio") +#modparam("dispatcher", "ds_ping_interval", 10) +#modparam("dispatcher", "ds_ping_method", "OPTIONS") +#modparam("dispatcher", "ds_probing_threshold", 10) +#modparam("dispatcher", "ds_inactive_threshold", 10) +#modparam("dispatcher", "ds_ping_latency_stats", 1) +#modparam("dispatcher", "ds_ping_from", "sip:kam@10.0.5.6") +#modparam("dispatcher", "ds_probing_mode", 1) #Keeps pinging gateways when state is known (to detect change in state) # KAMCTL config modparam("ctl", "binrpc", "/var/run/kamailio/kamailio_ctl") # UAC settings @@ -86,18 +86,6 @@ request_route { sl_send_reply("484", "Address Incomplete"); exit; } - # Force RTPENGINE - if (is_method("INVITE")) { - rtpengine_manage("replace-origin replace-session-connection force-relay"); - } - # update $du to set the destination address for proxying - if ($siz=="10.0.5.7") { - xlog("Incomming call from SIP provider"); - $du = "sip:" + "10.0.5.4"; - } else { - xlog("Incomming call from Customer PBX"); - $du = "sip:" + "10.0.5.7"; - } route(RELAY); exit; } @@ -116,7 +104,26 @@ route[RELAY] { if (is_method("INVITE")) { if(!t_is_set("failure_route")) t_on_failure("MANAGE_FAILURE"); } + # Force RTPENGINE + if (is_method("INVITE")) { + rtpengine_manage("replace-origin replace-session-connection force-relay"); + } + + # update $du to set the destination address for proxying based on caller IP + if ($siz=="10.0.5.7") { + xlog("Incomming call from SIP provider"); + $du = "sip:" + "10.0.5.4"; + } else { + xlog("Incomming call from Customer PBX"); + $du = "sip:" + "10.0.5.7"; + } + if ($siz=="10.0.5.5") { + xlog("Incomming call from SIP provider2"); + $du = "sip:" + "10.0.5.4"; + } + # If auth is required perform it t_on_failure("TRUNKAUTH"); + # Relay t_relay(); exit; } @@ -143,7 +150,6 @@ failure_route[TRUNKAUTH] { route[REQINIT] { if($ua =~ "friendly-scanner|sipcli|VaxSIPUserAgent") { # silent drop for scanners - uncomment next line if want to reply - # sl_send_reply("200", "OK"); exit; } @@ -153,17 +159,7 @@ route[REQINIT] { } if(is_method("OPTIONS") && uri==myself && $rU==$null) { -# sl_send_reply("200", "Keepalive"); - # update $du to set the destination address for proxying - if ($siz=="10.0.5.7") { - xlog("Incomming call from SIP provider"); - $du = "sip:" + "10.0.5.4"; - } else { - xlog("Incomming call from Customer PBX"); - $du = "sip:" + "10.0.5.7"; - } - t_on_failure("TRUNKAUTH"); - t_relay(); + route(RELAY); exit; }