# Working version 1.0 by Matija Turk # 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.so" loadmodule "dialog.so" loadmodule "db_flatstore.so" # Global parameters cfgengine "native" fork=yes children=4 log_facility=LOG_LOCAL0 log_prefix="{$mt $hdr(CSeq) $ci} " # RTPProxy settings modparam("rtpengine", "rtpengine_sock", "udp:127.0.0.1:2223") # Dispatcher settings modparam("dispatcher", "db_url", "mysql://kamy:kamy@localhost/kamailio") modparam("dispatcher", "ds_ping_interval", 3) modparam("dispatcher", "ds_ping_method", "OPTIONS") modparam("dispatcher", "ds_probing_threshold", 2) modparam("dispatcher", "ds_inactive_threshold", 3) modparam("dispatcher", "ds_ping_latency_stats", 1) modparam("dispatcher", "ds_ping_reply_codes", "class=2;code=404;code=401") 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 modparam("uac","reg_contact_addr", "10.0.5.6:5060") modparam("uac","reg_db_url", "mysql://kamy:kamy@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") # CDR STUFF #!define DLG_FLAG 4 #!define FLT_ACC 5 #!define FLT_ACCMISSED 6 #!define FLT_ACCFAILED 7 modparam("dialog", "dlg_flag", DLG_FLAG) # ACC # -- cdr accounting to database modparam("acc", "db_url", "mysql://kamy:kamy@localhost/kamailio") modparam("acc", "cdrs_table", "acc_cdrs") modparam("acc", "cdr_enable", 1) modparam("acc", "cdr_skip", "nocdr") modparam("acc", "cdr_extra_nullable", 1) modparam("acc", "cdr_log_enable", 1) modparam("acc", "cdr_on_failed", 1) modparam("acc", "cdr_expired_dlg_enable", 1) modparam("acc", "cdr_start_on_confirmed", 1) modparam("acc", "cdr_facility", "LOG_LOCAL2") modparam("acc", "cdr_extra","src_user=$fU;src_domain=$fd;src_ip=$si;dst_user=$rU;dst_ouser=$tU;dst_domain=$rd;callid=$dlg(callid);dst_ip=$Ri;direction=$avp(direction)") # DIALOG modparam("dialog", "dlg_flag", DLG_FLAG) modparam("dialog", "dlg_match_mode", 1) modparam("dialog", "enable_stats", 1) /* Main SIP request routing logic * - processing of any incoming SIP request starts with this route * - note: this is the same as route { ... } */ request_route { dlg_manage(); # Variables $avp(customerpbxip)="10.0.5.4"; $avp(sip1)="10.0.5.7"; $avp(sip2)="10.0.5.5"; # 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; } 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"); setflag(DLG_FLAG); setflag(FLT_ACC); # do accounting setflag(FLT_ACCFAILED); # even if the transaction fails } # 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==$avp(sip1) || $siz==$avp(sip2)) { $du = "sip:" + $avp(customerpbxip); $avp(direction)="inbound"; } else { $avp(direction)="outbound"; # Change To header ds_select_dst("1","9"); if (is_method("INVITE")) { uac_replace_to("sip:" + $rU + "@" + $nh(d) + ":" + $nh(p)); } } # If auth is required perform it t_on_failure("TRUNKAUTH"); # Relay t_relay(); exit; } # TRUNK AUTH ROUTE failure_route[TRUNKAUTH] { if (t_is_canceled()) { exit; } if(t_check_status("401|407")) { $avp(auser) = "kam"; $avp(apass) = "kam"; 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 exit; } if (!mf_process_maxfwd_header("10")) { sl_send_reply("483", "Too Many Hops"); exit; } if(is_method("OPTIONS") && uri==myself && $rU==$null) { route(RELAY); 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("replace-origin force-relay"); xdbg("incoming reply\n"); } } # Manage failure routing cases failure_route[MANAGE_FAILURE] { if (t_is_canceled()) exit; }