# Load required modules loadmodule "tm.so" loadmodule "sl.so" loadmodule "rr.so" loadmodule "maxfwd.so" loadmodule "textops.so" loadmodule "rtpengine.so" loadmodule "dispatcher.so" loadmodule "nathelper.so" loadmodule "ctl" loadmodule "pv" loadmodule "db_mysql.so" loadmodule "uac.so" loadmodule "xlog.so" loadmodule "tmx" loadmodule "siputils" loadmodule "sanity" loadmodule "acc" # Global parameters cfgengine "native" fork=yes children=4 log_facility=LOG_LOCAL0 # RTPProxy settings modparam("rtpengine", "rtpengine_sock", "udp:127.0.0.1:2223") # Dispatcher settings modparam("dispatcher", "list_file", "/etc/kamailio/dispatcher.list") # KAMCTL config modparam("ctl", "binrpc", "/var/run/kamailio/kamailio_ctl") # UAC settings modparam("uac","reg_contact_addr", "10.0.5.7:5060") modparam("uac","reg_db_url", "mysql://kamailio:kamailiow@localhost/kamailio") modparam("uac","auth_username_avp","$avp(auser)") modparam("uac","auth_password_avp","$avp(apass)") modparam("uac","auth_realm_avp","$avp(arealm)") # TM settings modparam("tm", "auto_inv_100_reason", "Trying") /* 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); # 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(); } if ($rU==$null) { # request with no Username in RURI 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; } # Wrapper for relaying requests route[RELAY] { # enable additional event routes for forwarded requests # - serial forking, RTP relaying handling, a.s.o. if (is_method("INVITE|BYE|SUBSCRIBE|UPDATE")) { if(!t_is_set("branch_route")) t_on_branch("MANAGE_BRANCH"); } if (is_method("INVITE|SUBSCRIBE|UPDATE")) { if(!t_is_set("onreply_route")) t_on_reply("MANAGE_REPLY"); } if (is_method("INVITE")) { if(!t_is_set("failure_route")) t_on_failure("MANAGE_FAILURE"); } t_on_failure("TRUNKAUTH"); t_relay(); exit; } # TRUNK AUTH ROUTE failure_route[TRUNKAUTH] { xlog("trunk auth"); if (t_is_canceled()) { exit; } xlog("Checking status code"); if(t_check_status("401|407")) { xlog("status code is valid auth challenge"); $avp(auser) = "kam"; $avp(apass) = "kam"; uac_auth(); xlog("after uac_auth"); t_relay(); exit; } } # Per SIP request initial checks 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; } if (!mf_process_maxfwd_header("10")) { sl_send_reply("483", "Too Many Hops"); exit; } if(is_method("OPTIONS") && uri==myself && $rU==$null) { sl_send_reply("200", "Keepalive"); exit; } if(!sanity_check("1511", "7")) { xlog("Malformed SIP message from $si:$sp\n"); exit; } } # Handle requests within SIP dialogs route[WITHINDLG] { if (!has_totag()) return; # sequential request within a dialog should # take the path determined by record-routing if (loose_route()) { if (is_method("BYE")) { rtpengine_delete(); route(RELAY); exit; } else if ( is_method("NOTIFY") ) { # Add Record-Route for in-dialog NOTIFY as per RFC 6665. record_route(); } route(RELAY); exit; } if ( is_method("ACK") ) { if ( t_check_trans() ) { # no loose-route, but stateful ACK; # must be an ACK after a 487 # or e.g. 404 from upstream server route(RELAY); exit; } else { # ACK without matching transaction ... ignore and discard exit; } } sl_send_reply("404", "Not here"); exit; } # Manage outgoing branches branch_route[MANAGE_BRANCH] { xdbg("new branch [$T_branch_idx] to $ru\n"); } # Manage incoming replies onreply_route[MANAGE_REPLY] { if (is_method("INVITE")) { # Force RTP relay on reply rtpengine_manage("force-relay"); xdbg("incoming reply\n"); } } # Manage failure routing cases failure_route[MANAGE_FAILURE] { if (t_is_canceled()) exit; }