123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280 |
- #!KAMAILIO
- #
- # Kamailio (OpenSER) SIP Server v5.2 - default configuration script
- # - web: https://www.kamailio.org
- # - git: https://github.com/kamailio/kamailio
- #
- # Direct your questions about this file to: <[email protected]>
- #
- # Refer to the Core CookBook at https://www.kamailio.org/wiki/
- # for an explanation of possible statements, functions and parameters.
- #
- ####### Defined Values #########
- #!define MULTIDOMAIN 0
- # - flags
- # FLT_ - per transaction (message) flags
- # FLB_ - per branch flags
- #!define FLT_ACC 1
- #!define FLT_ACCMISSED 2
- #!define FLT_ACCFAILED 3
- #!define FLT_NATS 5
- #!define FLB_NATB 6
- #!define FLB_NATSIPPING 7
- ####### Global Parameters #########
- ### LOG Levels: 3=DBG, 2=INFO, 1=NOTICE, 0=WARN, -1=ERR
- debug=2
- log_stderror=no
- memdbg=5
- memlog=5
- log_facility=LOG_LOCAL0
- log_prefix="{$mt $hdr(CSeq) $ci} "
- /* number of SIP routing processes */
- children=2
- /* uncomment the next line to disable TCP (default on) */
- # disable_tcp=yes
- /* uncomment the next line to disable the auto discovery of local aliases
- * based on reverse DNS on IPs (default on) */
- # auto_aliases=no
- /* add local domain aliases */
- # alias="sip.mydomain.com"
- /* listen addresses */
- # listen=udp:127.0.0.1:5060
- ####### Custom Parameters #########
- /* These parameters can be modified runtime via RPC interface
- * - see the documentation of 'cfg_rpc' module.
- *
- * Format: group.id = value 'desc' description
- * Access: $sel(cfg_get.group.id) or @cfg_get.group.id */
- ####### Modules Section ########
- /* set paths to location of modules */
- loadmodule "jsonrpcs.so"
- loadmodule "kex.so"
- loadmodule "corex.so"
- loadmodule "tm.so"
- loadmodule "tmx.so"
- loadmodule "sl.so"
- loadmodule "rr.so"
- loadmodule "pv.so"
- loadmodule "maxfwd.so"
- loadmodule "textops.so"
- loadmodule "siputils.so"
- loadmodule "xlog.so"
- loadmodule "sanity.so"
- loadmodule "ctl.so"
- loadmodule "cfg_rpc.so"
- loadmodule "acc.so"
- loadmodule "counters.so"
- # ----------------- setting module-specific parameters ---------------
- # ----- jsonrpcs params -----
- modparam("jsonrpcs", "pretty_format", 1)
- /* set the path to RPC fifo control file */
- # modparam("jsonrpcs", "fifo_name", "/var/run/kamailio/kamailio_rpc.fifo")
- /* set the path to RPC unix socket control file */
- # modparam("jsonrpcs", "dgram_socket", "/var/run/kamailio/kamailio_rpc.sock")
- # ----- ctl params -----
- /* set the path to RPC unix socket control file */
- # modparam("ctl", "binrpc", "unix:/var/run/kamailio/kamailio_ctl")
- # ----- tm params -----
- # auto-discard branches from previous serial forking leg
- modparam("tm", "failure_reply_mode", 3)
- # default retransmission timeout: 30sec
- modparam("tm", "fr_timer", 30000)
- # default invite retransmission timeout after 1xx: 120sec
- modparam("tm", "fr_inv_timer", 120000)
- # ----- rr params -----
- # set next param to 1 to add value to ;lr param (helps with some UAs)
- modparam("rr", "enable_full_lr", 0)
- # do not append from tag to the RR (no need for this script)
- modparam("rr", "append_fromtag", 0)
- # ----- acc params -----
- /* what special events should be accounted ? */
- modparam("acc", "early_media", 0)
- modparam("acc", "report_ack", 0)
- modparam("acc", "report_cancels", 0)
- /* by default ww do not adjust the direct of the sequential requests.
- * if you enable this parameter, be sure the enable "append_fromtag"
- * in "rr" module */
- modparam("acc", "detect_direction", 0)
- /* account triggers (flags) */
- modparam("acc", "log_flag", FLT_ACC)
- modparam("acc", "log_missed_flag", FLT_ACCMISSED)
- modparam("acc", "log_extra",
- "src_user=$fU;src_domain=$fd;src_ip=$si;"
- "dst_ouser=$tU;dst_user=$rU;dst_domain=$rd")
- modparam("acc", "failed_transaction_flag", FLT_ACCFAILED)
- ####### Routing Logic ########
- /* 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();
- }
- # account only INVITEs
- if (is_method("INVITE")) {
- setflag(FLT_ACC); # do accounting
- }
- if ($rU==$null) {
- # request with no Username in RURI
- sl_send_reply("484","Address Incomplete");
- exit;
- }
- # update $du to set the destination address for proxying
- $du = "sip:" + $rd + ":9";
- 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");
- }
- if (!t_relay()) {
- sl_reply_error();
- }
- 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 withing a dialog should
- # take the path determined by record-routing
- if (loose_route()) {
- if (is_method("BYE")) {
- setflag(FLT_ACC); # do accounting ...
- setflag(FLT_ACCFAILED); # ... even if the transaction fails
- } 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] {
- xdbg("incoming reply\n");
- }
- # Manage failure routing cases
- failure_route[MANAGE_FAILURE] {
- if (t_is_canceled()) exit;
- }
|