12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223 |
- #!KAMAILIO
- #
- # This config file implements the basic P-CSCF functionality
- # - web: http://www.kamailio.org
- # - git: http://sip-router.org
- #
- # Refer to the Core CookBook at http://www.kamailio.org/dokuwiki/doku.php
- # for an explanation of possible statements, functions and parameters.
- #
- # Direct your questions about this file to: <[email protected]>.
- #
- # For more information about the various parameters, functions and statements
- # try http://sip-router.org/wiki/ .
- #
- ####### Defined Values #########
- # *** Value defines - IDs used later in config
- # - flags
- # FLT_ - per transaction (message) flags
- # FLB_ - per branch flags
- #!define FLT_CAPTURE 1
- #!define FLT_DIALOG 2
- #!define DLG_TIMEOUT_AVP "i:1"
- #!define RR_CUSTOM_USER_AVP "i:2"
- #!define DISPATCHER_DST_AVP "i:3"
- #!define DISPATCHER_GRP_AVP "i:4"
- #!define DISPATCHER_CNT_AVP "i:5"
- #!define DISPATCHER_SOCK_AVP "i:6"
- ####### Global Parameters #########
- include_file "scscf.cfg"
- #!ifdef WITH_DEBUG
- debug=5
- log_stderror=no
- sip_warning=yes
- #!else
- debug=2
- log_stderror=no
- sip_warning=no
- #!endif
- #!ifdef WITH_XMLRPC
- listen=tcp:127.0.0.1:6060
- #!endif
- alias=HOSTNAME
- user_agent_header="User-Agent: Kamailio S-CSCF"
- server_header="Server: Kamailio S-CSCF"
- /* comment the next line to enable the auto discovery of local aliases
- based on reverse DNS on IPs (default on) */
- auto_aliases=no
- check_via=no # (cmd. line: -v)
- dns=no # (cmd. line: -r)
- rev_dns=no # (cmd. line: -R)
- # Do SRV-Loadbalancing:
- dns_srv_lb=yes
- # Always: Also try IPv6:
- dns_try_ipv6=yes
- # Always prefer IPv6:
- dns_cache_flags=6
- # DNS-Based failover
- use_dns_failover = on
- # Query NAPTR-Records as well:
- dns_try_naptr=no
- #!ifdef WITH_XMLRPC
- #!ifndef WITH_TCP
- #!define WITH_TCP
- #!endif
- #!ifndef TCP_PROCESSES
- # Number of TCP Processes
- #!define TCP_PROCESSES 3
- #!endif
- #!endif
- #!ifdef WITH_TCP
- # life time of TCP connection when there is no traffic
- # - a bit higher than registration expires to cope with UA behind NAT
- tcp_connection_lifetime=3615
- #!ifdef TCP_PROCESSES
- tcp_children=TCP_PROCESSES
- #!endif
- #!else
- disable_tcp=yes
- #!endif
- children=12
- system.shutdownmode = 0 desc "System shutdown mode"
- system.service = "Serving-CSCF" desc "Function of this server"
- # ------------------ module loading ----------------------------------
- mpath="/usr/lib64/kamailio/modules_k/:/usr/lib64/kamailio/modules/:/usr/lib/kamailio/modules_k/:/usr/lib/kamailio/modules/"
- # (we try both the lib64 and the lib directory)
- loadmodule "tm.so"
- loadmodule "pv.so"
- loadmodule "sl.so"
- loadmodule "rr.so"
- loadmodule "ims_dialog.so"
- loadmodule "textops.so"
- loadmodule "textopsx.so"
- loadmodule "maxfwd.so"
- loadmodule "xlog.so"
- loadmodule "sanity.so"
- loadmodule "siputils.so"
- loadmodule "kex.so"
- loadmodule "tmx.so"
- loadmodule "pike.so"
- #!ifdef DB_URL
- loadmodule "presence"
- #!endif
- #!ifdef DB_URL
- loadmodule "db_mysql"
- #!ifdef DB_URL2
- loadmodule "db_cluster"
- #!endif
- #!endif
- loadmodule "dispatcher"
- loadmodule "enum"
- loadmodule "uac"
- # Control interfaces:
- loadmodule "ctl"
- loadmodule "cfg_rpc"
- #!ifdef WITH_XMLRPC
- loadmodule "xmlrpc"
- #!endif
- loadmodule "cdp.so"
- loadmodule "cdp_avp.so"
- loadmodule "ims_usrloc_scscf.so"
- loadmodule "ims_registrar_scscf.so"
- loadmodule "ims_auth.so"
- loadmodule "ims_isc.so"
- #!ifdef WITH_RO
- loadmodule "ims_charging.so"
- #!endif
- #!ifdef CAPTURE_NODE
- loadmodule "siptrace.so"
- #!endif
- ##!ifdef WITH_DEBUG
- loadmodule "debugger.so"
- modparam("debugger", "mod_hash_size", 5)
- modparam("debugger", "mod_level_mode", 1)
- #modparam("debugger", "mod_level", "ims_usrloc_scscf=3")
- #modparam("debugger", "mod_level", "ims_registrar_scscf=3")
- modparam("debugger", "mod_level", "ims_auth=3")
- #modparam("debugger", "mod_level", "ims_isc=3")
- modparam("debugger", "mod_level", "ims_dialog=3")
- #modparam("debugger", "mod_level", "ims_charging=3")
- ##!endif
- # ----------------- setting module-specific parameters ---------------
- #!ifdef DB_URL2
- # ----- db_cluster params -----
- modparam("db_cluster", "connection", DB_URL)
- modparam("db_cluster", "connection", DB_URL2)
- modparam("db_cluster", "cluster", "cluster1=>con1=2s2s;con2=1s1s")
- #!endif
- # ----- presence params -----
- #!ifdef DB_URL
- #!ifdef DB_URL2
- modparam("presence", "db_url", "cluster://cluster1")
- #!else
- modparam("presence", "db_url", DB_URL)
- #!endif
- #modparam("presence", "fallback2db", 1)
- modparam("presence", "db_update_period", 20)
- #!endif
- loadmodule "jsonrpcs.so"
- # ----- 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 -----
- modparam("ctl", "binrpc", "unix:/var/run/kamailio_scscf/kamailio_ctl")
- # ----- tm params -----
- # auto-discard branches from previous serial forking leg
- modparam("tm", "failure_reply_mode", 3)
- # default retransmission timeout: 10sec
- modparam("tm", "fr_timer", 10000)
- # default invite retransmission timeout after 1xx: 120sec
- modparam("tm", "fr_inv_timer", 120000)
- # Don't reply automatically with "100 Trying"
- modparam("tm", "auto_inv_100", 0)
- # ----- rr params -----
- # add value to ;lr param to cope with most of the UAs
- modparam("rr", "enable_full_lr", 1)
- # append from tag to the RR
- modparam("rr", "append_fromtag", 1)
- # add a Username to RR-Header
- modparam("rr", "add_username", 1)
- # Take User from a custom AVP
- modparam("rr", "custom_user_avp", "$avp(RR_CUSTOM_USER_AVP)")
- # -- usrloc params --
- modparam("ims_usrloc_scscf", "enable_debug_file", 0)
- modparam("ims_usrloc_scscf", "matching_mode", 0)
- modparam("ims_registrar_scscf", "max_contacts", 3);
- modparam("ims_usrloc_scscf", "maxcontact_behaviour", 2) #overwrite
- #!ifdef DB_URL
- #!ifdef DB_URL2
- modparam("ims_usrloc_scscf", "db_url", "cluster://cluster1")
- #!else
- modparam("ims_usrloc_scscf", "db_url", DB_URL)
- #!endif
- modparam("ims_usrloc_scscf", "db_mode", 1)
- #!endif
- modparam("ims_registrar_scscf", "subscription_default_expires", 654800)
- modparam("ims_registrar_scscf", "subscription_min_expires", 3700)
- modparam("ims_registrar_scscf", "subscription_max_expires", 605800)
- # -- CDP params --
- modparam("cdp","config_file","/etc/kamailio_scscf/scscf.xml")
- # -- ims_dialog params --
- modparam("ims_dialog", "dlg_flag", FLT_DIALOG)
- modparam("ims_dialog", "timeout_avp", "$avp(DLG_TIMEOUT_AVP)")
- modparam("ims_dialog", "detect_spirals", 1)
- modparam("ims_dialog", "profiles_no_value", "orig ; term")
- modparam("ims_dialog", "db_mode", 0)
- #!ifdef WITH_XMLRPC
- # ----- xmlrpc params -----
- modparam("xmlrpc", "route", "XMLRPC");
- modparam("xmlrpc", "url_match", "^/RPC")
- #!endif
- #!ifdef WITH_DEBUG
- # ----- debugger params -----
- modparam("debugger", "cfgtrace", 1)
- #!endif
- #!ifdef CAPTURE_NODE
- # Destination, where to send the traffic
- modparam("siptrace", "duplicate_uri", CAPTURE_NODE)
- # Trace all traffic
- modparam("siptrace", "trace_on", 1)
- modparam("siptrace", "trace_to_database", 0)
- modparam("siptrace", "trace_flag", FLT_CAPTURE)
- modparam("siptrace", "hep_mode_on", 1)
- #!endif
- # -- ims_auth params --
- modparam("ims_auth", "name", URI)
- modparam("ims_auth", "registration_default_algorithm", REG_AUTH_DEFAULT_ALG)
- #!ifdef CXDX_FORCED_PEER
- modparam("ims_auth", "cxdx_forced_peer", CXDX_FORCED_PEER)
- #!endif
- modparam("ims_auth", "cxdx_dest_realm", NETWORKNAME)
- modparam("ims_auth", "av_check_only_impu", 1)
- #modparam("ims_auth", "auth_data_timeout", 5)
- modparam("ims_auth","auth_used_vector_timeout", 300)
- # -- ims_registrar_scscf params --
- #!ifdef WITH_DEBUG
- modparam("ims_registrar_scscf", "default_expires", 60)
- modparam("ims_registrar_scscf", "min_expires", 60)
- modparam("ims_registrar_scscf", "max_expires", 60)
- #!else
- modparam("ims_registrar_scscf", "default_expires", 604800)
- modparam("ims_registrar_scscf", "min_expires", 60)
- modparam("ims_registrar_scscf", "max_expires", 604800)
- #!endif
- modparam("ims_registrar_scscf", "use_path", 1)
- modparam("ims_registrar_scscf", "support_wildcardPSI",1)
- modparam("ims_registrar_scscf", "user_data_xsd","/etc/kamailio_scscf/CxDataType_Rel7.xsd")
- modparam("ims_registrar_scscf", "scscf_name", URI)
- modparam("ims_registrar_scscf", "scscf_name", URI)
- modparam("ims_registrar_scscf", "cxdx_dest_realm", NETWORKNAME)
- #!ifdef WITH_MULTIDOMAIN
- # ----- domain params -----
- #!ifdef DB_URL
- #!ifdef DB_URL2
- modparam("domain", "db_url", "cluster://cluster1")
- #!else
- modparam("domain", "db_url", DB_URL)
- #!endif
- modparam("domain", "db_mode", 1)
- #!endif
- # register callback to match myself condition with domains list
- modparam("domain", "register_myself", 1)
- #!endif
- # ----- ims_isc params -----
- modparam("ims_isc", "my_uri", HOSTNAME)
- modparam("ims_isc", "add_p_served_user", 1)
- #!ifdef WITH_RO
- # ----- ims_diameter_ro params -----
- #!ifdef DB_URL
- #!ifdef DB_URL2
- #modparam("ims_charging", "db_url", "cluster://cluster1")
- #!else
- #modparam("ims_charging", "db_url", DB_URL)
- #!endif
- #modparam("ims_charging", "db_mode", 1)
- #!endif
- modparam("ims_charging", "origin_host", HOSTNAME);
- modparam("ims_charging", "origin_realm", NETWORKNAME);
- #!ifdef RO_FORCED_PEER
- modparam("ims_charging", "ro_forced_peer", RO_FORCED_PEER);
- #!endif
- modparam("ims_charging", "destination_host", RO_DESTINATION);
- modparam("ims_charging", "destination_realm", NETWORKNAME);
- modparam("ims_charging","service_context_id_root", RO_ROOT);
- modparam("ims_charging","service_context_id_ext", RO_EXT);
- modparam("ims_charging","service_context_id_mnc", RO_MNC);
- modparam("ims_charging","service_context_id_mcc", RO_MCC);
- modparam("ims_charging","service_context_id_release", RO_RELEASE);
- modparam("ims_charging","interim_update_credits",30);
- modparam("ims_charging","timer_buffer",5);
- #!endif
- # ----- enum params -----
- modparam("enum", "domain_suffix", ENUM_SUFFIX)
- # ----- sanity params -----
- modparam("sanity", "autodrop", 0)
- # ----------------- Settings for Dispatcher ---------------
- modparam("dispatcher", "list_file", "/etc/kamailio_scscf/dispatcher.list")
- # Dispatcher: Enable Failover-Support
- modparam("dispatcher", "flags", 2)
- # Dispatcher: Overwrite Destination address, if required.
- modparam("dispatcher", "force_dst", 1)
- # AVP's required for Fail-Over-Support:
- modparam("dispatcher", "dst_avp", "$avp(DISPATCHER_DST_AVP)")
- modparam("dispatcher", "grp_avp", "$avp(DISPATCHER_GRP_AVP)")
- modparam("dispatcher", "cnt_avp", "$avp(DISPATCHER_CNT_AVP)")
- modparam("dispatcher", "sock_avp", "$avp(DISPATCHER_SOCK_AVP)")
- # Try to recover disabled destinations every 15 seconds.
- modparam("dispatcher", "ds_ping_interval", 15)
- # Actively query the gateways:
- modparam("dispatcher", "ds_probing_mode", 1)
- modparam("dispatcher", "ds_ping_reply_codes", "class=2;code=404;code=480")
- ####### Routing Logic ########
- # Main SIP request routing logic
- # - processing of any incoming SIP request starts with this route
- route {
- ##!ifdef WITH_DEBUG
- xlog("$rm ($fu ($si:$sp) to $tu, $ci)\n");
- ##!endif
- # per request initial checks
- route(REQINIT);
- # Handle Registrations:
- if (is_method("REGISTER")) {
- route(REGISTER);
- exit;
- }
- # we need to support subscription to reg event
- if (is_method("SUBSCRIBE") && search("^(Event|o)([ \t]*):([ \t]*)reg")) {
- route(SUBSCRIBE);
- break;
- }
- if (is_method("PUBLISH") && search("^(Event|o)([ \t]*):([ \t]*)reg")) {
- route(PUBLISH);
- break;
- }
-
- #Set DLG flag to track dialogs using dialog2
- if (!is_method("REGISTER|SUBSCRIBE"))
- setflag(FLT_DIALOG);
- # Evaluate Route-Header and set $route_uri
- loose_route();
- if (is_method("CANCEL|ACK")) {
- t_relay();
- exit;
- }
- if (($route_uri =~ "sip:orig@.*") || isc_from_as("orig")) {
- xlog("Orig");
- # we need something like this to assign SCSCF to unregistered user for services
- # support for AS origination on behalf of unregistered useri
- # can use the registrar is_registered methods - must see if we need to check orig or term?
- # Originating
- route(orig);
- break;
- } else {
- isc_from_as("term");
- if ($retcode == -2) {
- # Treat as originating, since it was retargeted:
- route(orig);
- break;
- }
- if ((is_in_profile("orig") || has_totag()) && ($route_uri =~ "sip:mo@"+".*")) {
- route(orig_subsequent);
- break;
- }
- if ((is_in_profile("term") || has_totag()) && ($route_uri =~ "sip:mt@"+".*")) {
- route(term_subsequent);
- break;
- }
- # Terminating
- if (uri == myself || uri =~ "tel:.*") {
- if (!term_impu_registered("location")) {
- xlog("L_DBG", "We need to do an UNREG server SAR assignemnt");
- assign_server_unreg("UNREG_SAR_REPLY", "location", "term");
- exit;
- }
- } else {
- sl_send_reply("403","Forbidden - Domain not served");
- exit();
- }
- route(term);
- break;
- }
- }
- route[UNREG_SAR_REPLY]
- {
- xlog("L_DBG","saa_return code is $avp(s:saa_return_code)\n");
- switch ($avp(s:saa_return_code)){
- case 1: #success
- xlog("L_DBG", "SAR success - will route message\n");
- route(term);
- break;
- case -1: #failure
- xlog("L_ERR", "SAR failure - error response sent from module\n");
- break;
- case -2: #error
- xlog("L_ERR", "SAR error - error response sent from module\n");
- break;
- default:
- xlog("L_ERR", "Unknown return code from SAR, value is [$avp(s:saa_return_code)]\n");
- break;
- }
- exit;
- }
- ######################################################################
- # Helper routes (Basic-Checks, NAT-Handling/RTP-Control, XML-RPC)
- ######################################################################
- # Per SIP request initial checks
- route[REQINIT] {
- $var(used) = 1 - ($stat(free_size) / $stat(total_size));
- xlog("L_DBG", "Mem: Total $stat(total_size), Free $stat(free_size) [$var(used)% used]\n");
- if ($var(used) > 95) {
- send_reply("503", "Server overloaded");
- exit;
- }
- # Trace this message
- #!ifdef CAPTURE_NODE
- sip_trace();
- setflag(FLT_CAPTURE);
- #!endif
- if (!mf_process_maxfwd_header("10")) {
- sl_send_reply("483","Too Many Hops");
- exit;
- }
- if(!sanity_check("1511", "7")) {
- xlog("Malformed SIP message from $si:$sp\n");
- exit;
- }
- # Check for shutdown mode:
- if (!has_totag() && ($sel(cfg_get.system.shutdownmode) > 0)) {
- send_reply("503", "Server shutting down");
- exit;
- }
- # Reply to OPTIONS:
- if (is_method("OPTIONS") && (uri==myself)) {
- options_reply();
- exit;
- }
-
- # Ignore Re-Transmits:
- if (t_lookup_request()) {
- exit;
- }
- if (is_method("INVITE")) {
- send_reply("100", "Trying");
- }
- }
- ######################################################################
- # Publish route
- ######################################################################
- route[PUBLISH]
- {
- if (!t_newtran()) {
- #absorb retransmissions
- sl_reply("500","Could not create transaction");
- exit;
- }
- if (can_publish_reg("location")) {
- $var(ret)= publish_reg("location");
- switch ($var(ret)){
- case 1: #success
- xlog("L_DBG", "Publish reg successful");
- break;
- case -1: #failure
- xlog("L_ERR", "Publish reg failure - sending 500 Error now\n");
- t_reply("500","Server Error publishing subscription");
- break;
- default:
- xlog("L_ERR", "Unknown return code from publish reg event alue is [$var(ret)]\n");
- break;
- }
- } else {
- t_reply("403","Forbidden to PUBLISH");
- exit;
- }
- }
- ######################################################################
- # Subscribe route
- ######################################################################
- route[SUBSCRIBE]
- {
- if (!t_newtran()) {
- #absorb retransmissions
- sl_reply("500","Could not create transaction");
- exit;
- }
- if (!has_totag()) {
- xlog("L_DBG", "This is an initial SUBSCRIBE\n");
- if (!term_impu_registered("location")) {
- xlog("L_DBG", "We need to do an UNREG server SAR assignment\n");
- assign_server_unreg("SUBSCRIBE_UNREG_SAR_REPLY", "location", "term");
- exit;
- }
- if (!can_subscribe_to_reg("location")){
- t_reply("403","Forbidden to SUBSCRIBE");
- exit;
- }
- }else{
- xlog("L_DBG", "This is a subsequent SUBSCRIBE\n");
- }
- $var(ret)= subscribe_to_reg("location");
- switch ($var(ret)){
- case 1: #success
- xlog("L_DBG", "Subscribe to reg successful");
- break;
- case -1: #failure
- xlog("L_ERR", "Subscribe to reg failure - sending 500 Error now\n");
- t_reply("500","Server Error saving subscription");
- break;
- case -2: #error
- xlog("L_ERR", "Subscribe to reg error sending notify - 200 OK so subscription already sent\n");
- break;
- default:
- xlog("L_ERR", "Unknown return code from subscribe to reg event alue is [$var(ret)]\n");
- break;
- }
- }
- route[SUBSCRIBE_UNREG_SAR_REPLY]
- {
-
- xlog("L_DBG","saa_return code is $avp(s:saa_return_code)\n");
- switch ($avp(s:saa_return_code)){
- case 1: #success
- xlog("L_DBG", "SAR success - will process subscribe\n");
- if (can_subscribe_to_reg("location")){
- $var(ret)= subscribe_to_reg("location");
- switch ($var(ret)){
- case 1: #success
- xlog("L_DBG", "Subscribe to reg successful");
- break;
- case -1: #failure
- xlog("L_ERR", "Subscribe to reg failure - sending 500 Error now\n");
- t_reply("500","Server Error saving subscription");
- break;
- case -2: #error
- xlog("L_ERR", "Subscribe to reg error sending notify - 200 OK so subscription already sent\n");
- break;
- default:
- xlog("L_ERR", "Unknown return code from subscribe to reg event alue is [$var(ret)]\n");
- break;
- }
- }else{
- t_reply("403","Forbidden to SUBSCRIBE");
- exit;
- }
- break;
- case -1: #failure
- xlog("L_ERR", "SAR failure - Sending 403 Forbidden\n");
- t_reply("403","Forbidden to SUBSCRIBE");
- break;
- case -2: #error
- xlog("L_ERR", "SAR error - Sending 403 Forbidden\n");
- t_reply("403","Forbidden to SUBSCRIBE");
- break;
- default:
- xlog("L_ERR", "Unknown return code from SAR, value is [$avp(s:saa_return_code)] - sending 403 Forbidden\n");
- t_reply("403","Forbidden to SUBSCRIBE");
- break;
- }
- exit;
- }
- ######################################################################
- # XMLRPC routing
- ######################################################################
- #!ifdef WITH_XMLRPC
- route[XMLRPC] {
- if ((method=="POST" || method=="GET")
- #!ifdef XMLRPC_WHITELIST_1
- && ((src_ip == XMLRPC_WHITELIST_1)
- #!ifdef XMLRPC_WHITELIST_2
- || (src_ip == XMLRPC_WHITELIST_2)
- #!endif
- #!ifdef XMLRPC_WHITELIST_3
- || (src_ip == XMLRPC_WHITELIST_3)
- #!endif
- )
- #!endif
- ) {
- # close connection only for xmlrpclib user agents (there is a bug in
- # xmlrpclib: it waits for EOF before interpreting the response).
- if ($hdr(User-Agent) =~ "xmlrpclib")
- set_reply_close();
- set_reply_no_connect();
- dispatch_rpc();
- exit;
- }
- send_reply("403", "Forbidden");
- exit;
- }
- #!endif
- ######################################################################
- # Route for handling Registrations:
- ######################################################################
- route[REGISTER] {
- xlog("ALGORITHM IS [$aa] and User-Agent is [$ua]\n");
- $var(alg) = $aa;
- if ($aa == $null) {
- $var(alg) = "MD5"; #force to MD5 for zoiper.... non-ims
- }
- #!ifdef WITH_AUTH
- if (!ims_www_authenticate("$td")) {
- #!else
- if (($var(alg) == "MD5") && (!ims_www_authenticate("$td"))) {
- #!endif
- if ($? == -2) {
- send_reply("403", "Authentication Failed");
- exit;
- } else if ($? == -3) {
- send_reply("400", "Bad Request");
- exit;
- } else if ($? == -9) {
- xlog("L_DBG", "Authentication re-sync requested\n");
- ims_www_resync_auth("REG_RESYNC_REPLY", "$td");
- exit;
- } else {
- #user has not been authenticated. Lets send a challenge via 401 Unauthorized
- xlog("L_DBG","About to challenge! auth_ims\n");
- ims_www_challenge("REG_MAR_REPLY", "$td", "$var(alg)");
- exit;
- }
- } else {
- xlog("L_DBG", "Auth succeeded\n");
- # We need to check if this user is registered or not
- if (!impu_registered("location")) {
- xlog("L_ERR", "Not REGISTERED\n");
- save("PRE_REG_SAR_REPLY","location");
- exit;
- } else {
- isc_match_filter_reg("1","location");
- save("REG_SAR_REPLY","location");
- exit;
- }
- }
- }
- route[REG_MAR_REPLY]
- {
- #this is async so to know status we have to check the reply avp
- xlog("L_DBG","maa_return code is $avp(s:maa_return_code)\n");
- switch ($avp(s:maa_return_code)){
- case 1: #success
- xlog("L_DBG", "MAR success - 401/407 response sent from module\n");
- break;
- case -1: #failure
- xlog("L_ERR", "MAR failure - error response sent from module\n");
- break;
- case -2: #error
- xlog("L_ERR", "MAR error - sending error response now\n");
- send_reply("500", "MAR failed");
- break;
- default:
- xlog("L_ERR", "Unknown return code from MAR, value is [$avp(s:maa_return_code)]\n");
- send_reply("500", "Unknown response code from MAR");
- break;
- }
- exit;
- }
- route[PRE_REG_SAR_REPLY]
- {
- xlog("L_DBG","saa_return code is $avp(s:saa_return_code)\n");
- #this is async so to know status we have to check the reply avp
- xlog("L_DBG","saa_return code (for scscf_save on register) is $avp(s:saa_return_code)\n");
- switch ($avp(s:saa_return_code)){
- case 1: #success
- xlog("L_DBG", "SAR success - 200 response sent from module\n");
- isc_match_filter_reg("0","location");
- exit;
- case -1: #failure
- xlog("L_ERR", "SAR failure - error response sent from module\n");
- break;
- case -2: #error
- xlog("L_ERR", "SAR error - error response sent from module\n");
- break;
- default:
- xlog("L_ERR", "Unknown return code from SAR, value is [$avp(s:saa_return_code)]\n");
- break;
- }
- exit;
- }
- route[REG_SAR_REPLY]
- {
- xlog("L_DBG","saa_return code is $avp(s:saa_return_code)\n");
- #this is async so to know status we have to check the reply avp
- xlog("L_DBG","saa_return code (for scscf_save on register) is $avp(s:saa_return_code)\n");
- switch ($avp(s:saa_return_code)){
- case 1: #success
- xlog("L_DBG", "SAR success - 200 response sent from module\n");
- exit;
- case -1: #failure
- xlog("L_ERR", "SAR failure - error response sent from module\n");
- break;
- case -2: #error
- xlog("L_ERR", "SAR error - error response sent from module\n");
- break;
- default:
- xlog("L_ERR", "Unknown return code from SAR, value is [$avp(s:saa_return_code)]\n");
- break;
- }
- exit;
- }
- route[REG_RESYNC_REPLY]
- {
- ims_www_challenge("REG_MAR_REPLY", "$td");
- }
- ######################################################################
- # Apply privacy, if requested
- ######################################################################
- route[apply_privacy]
- {
- if (is_present_hf("Privacy") && ($hdr(Privacy)=="id")) {
- remove_hf("P-Asserted-Identity");
- }
- }
- ######################################################################
- # Originating, Intial Requests
- ######################################################################
- route[orig]
- {
- xlog("L_DBG","Enter orig route\n");
- set_dlg_profile("orig");
- # we MAYBE need something like this to check if a user is barred
- # if (S_originating_barred()){
- # sl_send_reply("403","Forbidden - Originating Public Identity barred");
- # exit;
- # }
- if (is_method("INVITE|SUBSCRIBE")) {
- $avp(RR_CUSTOM_USER_AVP)="mo";
- record_route();
- }
-
- # Start new transaction:
- t_newtran();
- # check if dialog saved as fwded to AS
- if (isc_match_filter("orig", "location")) {
- t_on_failure("isc_orig_failure");
- xlog("Orig - msg was fwded to AS\n");
- exit;
- }
- if (!isc_from_as("orig")) {
- remove_hf("P-Asserted-Identity");
- append_hf("P-Asserted-Identity: <sip:$fU@$fd>\r\n");
- }
- #!ifdef WITH_RO
- # before we allow call - lets check credit
- if (is_method("INVITE")) {
- xlog("L_DBG","Sending initial CCR Request for call\n");
- $var(cc_ret) = Ro_CCR("CHARGING_CCR_ORIG_REPLY", "orig", 30, "0", "0");
- if ($var(cc_ret) < 0) {
- xlog("L_ERR","CCR Request failure\n");
- sl_send_reply("402","Payment required");
- exit;
- }
- xlog("L_DBG","CCR Request success\n");
- exit;
- }
- #!endif
- route(FINAL_ORIG);
- }
- route[FINAL_ORIG]
- {
- # Check for PSTN destinations:
- if (is_method("INVITE")) {
- route(PSTN_handling);
- }
- t_on_reply("orig_reply");
- t_relay();
- }
- route[CHARGING_CCR_ORIG_REPLY]
- {
- xlog("L_DBG","cca_return code is $avp(s:cca_return_code)\n");
- switch ($avp(s:cca_return_code)){
- case 1: #success
- xlog("L_DBG", "CCR success - will route message\n");
- route(FINAL_ORIG);
- break;
- case -1: #failure
- xlog("L_ERR", "CCR failure - error response sent from module\n");
- switch ($avp(s:cca_result_code)){
- case 5030:
- send_reply("403", "Charging User not found");
- break;
- case 5031:
- send_reply("403", "Rating failed");
- break;
- case 4010:
- send_reply("402", "Payment required - Unsufficient funds");
- break;
- case 5006:
- send_reply("486", "Line limit exceeded");
- break;
- default:
- send_reply("402","Payment required ($avp(s:cca_result_code))");
- break;
- }
- case -2: #error
- xlog("L_ERR", "CCR error - error response sent from module\n");
- send_reply("500", "Charging Error");
- break;
- default:
- xlog("L_ERR", "Unknown return code from CCR: [$avp(s:cca_return_code)] \n");
- send_reply("500", "Charging Error");
- break;
- }
- exit;
- }
- ######################################################################
- # Replies to the Initial Requests
- ######################################################################
- onreply_route[orig_reply]
- {
- xlog("L_DBG","Orig reply\n");
- route(apply_privacy);
- break;
- }
- ######################################################################
- # Originating, subsequent requests
- ######################################################################
- route[orig_subsequent]
- {
- xlog("L_DBG","Orig_Subsequent\n");
-
- if (!is_method("ACK")) {
- t_on_reply("orig_subsequent_reply");
- }
- t_relay();
- }
- ######################################################################
- # Replies for originating, subsequent requests
- ######################################################################
- onreply_route[orig_subsequent_reply]
- {
- xlog("L_DBG","Orig_Subsequent_reply\n");
- route(apply_privacy);
- break;
- }
- ######################################################################
- # Failure-Route for Requests to an AS
- ######################################################################
- failure_route[isc_orig_failure]
- {
- xlog("L_DBG","ISC_Orig_failure\n");
- if (t_check_status("(408)|(5..)")){
- t_on_failure("isc_orig_failure");
- if (isc_match_filter("orig","location")){
- xlog("L_DBG","ISC_Orig_failure - msg was fwded to AS\n");
- exit;
- }
- if (isc_from_as("origfail")) {
- remove_hf("P-Asserted-Identity");
- append_hf("P-Asserted-Identity: <sip:$fU@$fd>\r\n");
- }
- t_on_reply("orig_reply");
- t_relay();
- }
- }
- ######################################################################
- # Terminating requests
- ######################################################################
- route[term]
- {
- xlog("L_DBG","Term\n");
- set_dlg_profile("term");
- #we need something like this to check if a user is barred
- # if (S_terminating_barred()){
- # sl_send_reply("404","Not Found - Terminating user barred");
- # exit;
- # }
- if (is_method("INVITE|SUBSCRIBE")) {
- $avp(RR_CUSTOM_USER_AVP)="mt";
- $avp(i:20)="mt";
- record_route();
- }
- # check if dialog saved as fwded to AS
- if (isc_match_filter("term","location")){
- t_on_failure("isc_term_failure");
- xlog("L_DBG","Term - msg was fwded to AS\n");
- exit;
- }
- #!ifdef WITH_RO_TERM
- # before we allow call - lets check credit
- if (is_method("INVITE")) {
- xlog("L_DBG","Sending initial CCR Request for call\n");
- $var(cc_ret) = Ro_CCR("CHARGING_CCR_TERM_REPLY", "term", 30, "0", "0");
- if ($var(cc_ret) < 0) {
- xlog("L_ERR","CCR Request failure\n");
- sl_send_reply("402","Payment required");
- exit;
- }
- xlog("L_DBG","CCR Request success\n");
- exit;
- }
- #!endif
- route(FINAL_TERM);
- }
- route[FINAL_TERM] {
- if (lookup("location")) {
- if (uri==myself) {
- if (!t_newtran()) {
- sl_reply_error();
- exit;
- }
- t_reply("404","Not Found - destination user not found on this S-CSCF");
- exit;
- }
- } else {
- # User not registered? Reply with 404.
- if (!t_newtran()) {
- sl_reply_error();
- exit;
- }
- t_reply("404","Not Found - destination user not found on this S-CSCF");
- exit;
- }
- route(apply_privacy);
- t_relay();
- }
- route[CHARGING_CCR_TERM_REPLY]
- {
- xlog("L_DBG","cca_return code is $avp(s:cca_return_code)\n");
- switch ($avp(s:cca_return_code)){
- case 1: #success
- xlog("L_DBG", "CCR success - will route message\n");
- route(FINAL_TERM);
- break;
- case -1: #failure
- xlog("L_ERR", "CCR failure - error response sent from module\n");
- switch ($avp(s:cca_result_code)){
- case 5030:
- send_reply("403", "Charging User not found");
- break;
- case 5031:
- send_reply("403", "Rating failed");
- break;
- case 4010:
- send_reply("402", "Payment required - Unsufficient funds");
- break;
- case 5006:
- send_reply("486", "Line limit exceeded");
- break;
- default:
- send_reply("402","Payment required ($avp(s:cca_result_code))");
- break;
- }
- case -2: #error
- xlog("L_ERR", "CCR error - error response sent from module\n");
- send_reply("500", "Charging Error");
- break;
- default:
- xlog("L_ERR", "Unknown return code from CCR: [$avp(s:cca_return_code)] \n");
- send_reply("500", "Charging Error");
- break;
- }
- exit;
- }
- ######################################################################
- # Failure Route for Terminating requests
- ######################################################################
- failure_route[isc_term_failure]
- {
- xlog("L_DBG","ISC_term_failure\n");
- if (t_check_status("(408)|(5..)")){
- t_on_failure("isc_term_failure");
- if (isc_match_filter("term","location")){
- xlog("L_DBG","Term - msg was fwded to AS\n");
- exit;
- }
- if (lookup("location")) {
- if (uri==myself) {
- t_reply("404","Not Found - destination user not found on this S-CSCF");
- exit;
- }
- } else {
- t_reply("404","Not Found - destination user not found on this S-CSCF");
- exit;
- }
- t_relay();
- }
- }
- ######################################################################
- # Terminating, subsequent requests
- ######################################################################
- route[term_subsequent]
- {
- xlog("L_DBG","term_subsequent\n");
- route(apply_privacy);
- t_relay();
- }
- ######################################################################
- # Check for PSTN destinations:
- ######################################################################
- route[PSTN_handling]
- {
- # First, we translate "tel:"-URI's to SIP-URI's:
- # $ru: tel:+(34)-999-888-777
- # $fu: sip:[email protected]
- # becomes $ru: sip:[email protected];user=phone
- if (!tel2sip("$ru", "$fd", "$ru"))
- xlog("L_WARN","Failed to convert $ru to a sip:-URI - M=$rm R=$ru F=$fu T=$tu IP=$si:$sp ID=$ci\n\n");
- if ($rU =~ "\+[0-9]+") {
- # Now let's check, if the number can be found in ENUM:
- if(!enum_query()) {
- # ENUM failed, send it to the PSTN-Gateway:
- route(PSTN);
- break;
- }
- }
- }
- ######################################################################
- # Send calls to the PSTN-Gateways:
- ######################################################################
- route[PSTN]
- {
- $var(has_trf) = 0;
- if (is_present_hf("Feature-Caps")) {
- xlog("Feature-Caps: $hdr(Feature-Caps) => $(hdr(Feature-Caps){param.value,+g.3gpp.trf}{nameaddr.uri}{uri.host})\n");
- if ($(hdr(Feature-Caps){param.value,+g.3gpp.trf}) != $null) {
- $rd = $(hdr(Feature-Caps){param.value,+g.3gpp.trf}{nameaddr.uri}{uri.host});
- if (!strempty($(ou{uri.params}))) {
- $ru = $ru+";"+$(ou{uri.params});
- }
- t_on_failure("TRF_failure");
- if (t_relay_to("0x02")) {
- $var(has_trf) = 1;
- } else {
- xlog("Relay to $du failed.\n");
- $du = $null;
- }
- }
- }
- if ($var(has_trf) == 0) {
- if (!ds_select_domain("1", "4")) {
- xlog("L_WARN","No PSTN-Gateways available - M=$rm R=$ru F=$fu T=$tu IP=$si:$sp ID=$ci\n\n");
- send_reply("503", "Service not available");
- exit;
- }
- if (!strempty($(ou{uri.params}))) {
- $ru = $ru+";"+$(ou{uri.params});
- }
- t_relay();
- }
- # Relay the request:
- t_on_failure("PSTN_failure");
- exit;
- }
- ######################################################################
- # manage failure routing cases, perform failover
- ######################################################################
- failure_route[TRF_failure] {
- xlog("TRF_failure\n");
- # Choose another gateway, in case we
- # - get a local generated "408"
- # - receive a 5xx or 6xx reply from the proxy.
- if (t_branch_timeout() || t_check_status("[5-6]..")) {
- $du = $null;
- if (!ds_select_domain("1", "4")) {
- xlog("L_WARN","No PSTN-Gateways available - M=$rm R=$ru F=$fu T=$tu IP=$si:$sp ID=$ci\n\n");
- send_reply("503", "Service not available");
- exit;
- }
- if (!strempty($(ou{uri.params}))) {
- $ru = $ru+";"+$(ou{uri.params});
- }
- # Relay the request:
- t_on_failure("PSTN_failure");
- t_relay();
- exit;
- }
- }
- ######################################################################
- # manage failure routing cases, perform failover
- ######################################################################
- failure_route[PSTN_failure] {
- # Choose another gateway, in case we
- # - get a local generated "408"
- # - receive a 5xx or 6xx reply from the proxy.
- if (t_branch_timeout() || t_check_status("[5-6]..")) {
- if (ds_next_domain()) {
- if (!strempty($(ou{uri.params}))) {
- $ru = $ru+";"+$(ou{uri.params});
- }
- # Do Failover in case problems:
- t_on_failure("PSTN_failure");
- t_relay();
- } else {
- # Add a header, to indicate the phone should try again in 30 seconds.
- append_hf("Retry-After: 30\r\n");
- send_reply("503", "Service not available");
- }
- exit;
- }
- }
|