Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ####### Defined Values #########
- # - 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 #########
- # Enable debugging only when kamailio is mading boo-boo
- ### LOG Levels: 3=DBG, 2=INFO, 1=NOTICE, 0=WARN, -1=ERR
- debug=3
- log_stderror=no
- memdbg=5
- memlog=5
- log_facility=LOG_LOCAL0
- fork=yes
- children=8
- /* 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="kamaz.ikatele.com"
- /* uncomment and configure the following line if you want Kamailio to
- bind on a specific interface/port/proto (default bind on all available) */
- #listen=udp:50.0.0.1:5060 advertise 194.190.8.171:5060
- #listen=udp:194.190.8.171:5060 advertise 50.0.0.1:5060
- listen=udp:194.190.8.171
- listen=udp:50.0.0.1
- dns=no
- rev_dns=no
- check_via=yes
- /* port to listen to
- * - can be specified more than once if needed to listen on many ports */
- port=5060
- mhomed=1
- ####### Modules Section ########
- # set paths to location of modules (to sources or installation folders)
- mpath="/usr/lib64/kamailio/modules/"
- loadmodule "mi_fifo.so"
- loadmodule "kex.so"
- loadmodule "tm.so"
- loadmodule "tmx.so"
- loadmodule "sl.so"
- loadmodule "rr.so"
- loadmodule "pv.so"
- loadmodule "maxfwd.so"
- loadmodule "usrloc.so"
- loadmodule "registrar.so"
- loadmodule "textops.so"
- loadmodule "siputils.so"
- loadmodule "xlog.so"
- loadmodule "sanity.so"
- loadmodule "ctl.so"
- loadmodule "cfg_rpc.so"
- loadmodule "mi_rpc.so"
- loadmodule "acc.so"
- loadmodule "nathelper.so"
- loadmodule "rtpproxy.so"
- #loadmodule "topoh.so"
- #modparam("topoh", "mask_key", "balalayka")
- #modparam("topoh", "mask_ip", "50.0.0.1")
- # ----------------- setting module-specific parameters ---------------
- # ----- mi_fifo params -----
- modparam("mi_fifo", "fifo_name", "/tmp/kamailio_fifo")
- # ----- tm params -----
- # auto-discard branches from previous serial forking leg
- modparam("tm", "failure_reply_mode", 3)
- # default retransmission timeout: 30sec
- modparam("tm", "fr_timer", 3000)
- # default invite retransmission timeout after 1xx: 120sec
- modparam("tm", "fr_inv_timer", 12000)
- # ----- rr params -----
- # add value to ;lr param to cope with most of the UAs
- modparam("rr", "enable_full_lr", 1)
- # do not append from tag to the RR (no need for this script)
- modparam("rr", "append_fromtag", 1)
- # ----- rtpproxy params -----
- modparam("rtpproxy", "rtpproxy_sock", "udp:127.0.0.1:7722")
- # ----- nathelper params -----
- modparam("nathelper", "natping_interval", 30)
- modparam("nathelper", "ping_nated_only", 1)
- modparam("nathelper", "sipping_bflag", FLB_NATSIPPING)
- modparam("nathelper", "sipping_from", "sip:pinger@194.190.8.171")
- # params needed for NAT traversal in other modules
- modparam("nathelper", "received_avp", "$avp(RECEIVED)")
- modparam("usrloc", "nat_bflag", FLB_NATB)
- ####### Routing Logic ########
- # Main SIP request routing logic
- # - processing of any incoming SIP request starts with this route
- # - note: this is the same as route { ... }
- route {
- # per request initial checks
- route(REQINIT);
- # NAT detection
- xlog("L_NOTICE","$rm from $fu (IP:$si:$sp) Main Route before ---NAT---\n");
- route(NATDETECT);
- xlog("L_NOTICE","$rm from $fu (IP:$si:$sp) in Route[NATDETECT] fix_nat-register\n");
- # CANCEL processing
- if (is_method("CANCEL"))
- {
- if (t_check_trans()) {
- route(RELAY);
- }
- exit;
- }
- # handle requests within SIP dialogs
- route(WITHINDLG);
- ### 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|SUBSCRIBE"))
- record_route();
- # account only INVITEs
- if (is_method("INVITE"))
- {
- setflag(FLT_ACC); # do accounting
- }
- # dispatch requests to foreign domains
- route(SIPOUT);
- # handle registrations
- route(REGISTRAR);
- if ($rU==$null)
- {
- # request with no Username in RURI
- sl_send_reply("484","Address Incomplete");
- exit;
- }
- route(RELAY);
- }
- # Per SIP request initial checks
- route[REQINIT] {
- if (!mf_process_maxfwd_header("20")) {
- xlog("L_NOTICE","$rm from $fu (IP:$si:$sp) in MAX FDW HEADERS ALARMO\n");
- sl_send_reply("483","Too Many Hops");
- exit;
- }
- if(!sanity_check("1511", "7"))
- {
- xlog("Malformed SIP message from $si:$sp\n");
- exit;
- }
- }
- # Caller NAT detection route
- route[NATDETECT] {
- force_rport();
- if (nat_uac_test("19")) {
- if (is_method("REGISTER")) {
- fix_nated_register();
- } else {
- if(is_first_hop())
- set_contact_alias();
- }
- setflag(FLT_NATS);
- }
- return;
- }
- # Handle requests within SIP dialogs
- route[WITHINDLG] {
- if (has_totag()) {
- # sequential request withing a dialog should
- # take the path determined by record-routing
- if (loose_route()) {
- route(DLGURI);
- if (is_method("BYE")) {
- setflag(FLT_ACC); # do accounting ...
- setflag(FLT_ACCFAILED); # ... even if the transaction fails
- }
- else if ( is_method("ACK") ) {
- # ACK is forwarded statelessy
- route(NATMANAGE);
- }
- else if ( is_method("NOTIFY") ) {
- # Add Record-Route for in-dialog NOTIFY as per RFC 6665.
- record_route();
- }
- route(RELAY);
- } else {
- 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 {
- xlog("L_NOTICE","ACK without matching transaction ... ignore and discard\n");
- # ACK without matching transaction ... ignore and discard
- exit;
- }
- }
- sl_send_reply("404","Not here");
- }
- exit;
- }
- }
- # Routing to foreign domains
- route[SIPOUT] {
- if (!uri==myself)
- {
- append_hf("P-hint: outbound\r\n");
- route(RELAY);
- }
- }
- # Handle SIP registrations
- route[REGISTRAR] {
- if (is_method("REGISTER"))
- {
- # if(isflagset(FLT_NATS))
- # {
- # setbflag(FLB_NATB);
- # # uncomment next line to do SIP NAT pinging
- # xlog("L_NOTICE","--------------------- SIP NAT PINGING --------------------------------------\n");
- # setbflag(FLB_NATSIPPING);
- # }
- # if (!save("location"))
- # sl_reply_error();
- # xlog("L_NOTICE","--------------------- SL REPLY ERROR --------------------------------------\n");
- if( t_check_trans() )
- {
- xlog("L_NOTICE","Transaction already exist, forwarding\n");
- }
- else
- {
- xlog("L_NOTICE","New transaction upcoming, creating\n");
- # forward("50.0.0.10");
- # save("sip:50.0.0.10","0x02");
- t_relay_to_udp("50.0.0.10", "5060");
- exit;
- }
- exit;
- }
- }
- route[RELAY] {
- # enable additional event routes for forwarded requests
- # - serial forking, RTP relaying handling, a.s.o.
- xlog("L_NOTICE","Default routing block raised!\n");
- 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;
- }
- # RTPProxy control
- route[NATMANAGE] {
- if (is_request()) {
- if(has_totag()) {
- if(check_route_param("nat=yes")) {
- xlog("L_NOTICE","------------------------------------ SETBFLAG ----------------------------\n");
- setbflag(FLB_NATB);
- }
- }
- }
- if (!(isflagset(FLT_NATS) || isbflagset(FLB_NATB)))
- return;
- rtpproxy_manage();
- if (is_request()) {
- if (!has_totag()) {
- if(t_is_branch_route()) {
- xlog("L_NOTICE","------------------------------------ ADD RR PARAM NAT YES ----------------------------\n");
- add_rr_param(";nat=yes");
- }
- }
- }
- if (is_reply()) {
- if(isbflagset(FLB_NATB)) {
- if(is_first_hop())
- xlog("L_NOTICE","------------------------------------ IS FIRST HOP SRT CONACT ALIAS ----------------------------\n");
- set_contact_alias();
- }
- xlog("L_NOTICE","$rm from $fu (IP:$si:$sp) in route[NATMANAGE] RTPproxy with EI Flags\n");
- }
- return;
- }
- # URI update for dialog requests
- route[DLGURI] {
- if(!isdsturiset()) {
- handle_ruri_alias();
- xlog("L_NOTICE","$rm from $fu (IP:$si:$sp) in route[DLGURI] RTPproxy with EI Flags\n");
- }
- return;
- }
- # manage outgoing branches
- branch_route[MANAGE_BRANCH] {
- xlog("L_NOTICE","$rm from $fu (IP:$si:$sp) in MANAGE_BRANCH\n");
- xdbg("new branch [$T_branch_idx] to $ru\n");
- route(NATMANAGE);
- }
- # manage incoming replies
- onreply_route[MANAGE_REPLY] {
- xlog("L_NOTICE","$rm from $fu (IP:$si:$sp) in MANAGE_REPLY\n");
- xdbg("incoming reply\n");
- if(status=~"[12][0-9][0-9]")
- route(NATMANAGE);
- }
- # manage failure routing cases
- failure_route[MANAGE_FAILURE] {
- xlog("L_NOTICE","$rm from $fu (IP:$si:$sp) in MANAGE_FAILURE\n");
- route(NATMANAGE);
- if (t_is_canceled()) {
- exit;
- }
- }
- route[DEBUG] {
- if (method==("PUBLISH|SUBSCRIBE|REGISTER|OPTIONS")) {
- return;
- }
- xlog("[$mi] Received SIP Message (method: $rm) ($ml bytes) to $Ri:$Rp from $si:$sp:\n$mb\n");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement