kamailio.cfg 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230
  1. #!KAMAILIO
  2. #
  3. # This config file implements the basic P-CSCF functionality
  4. # - web: http://www.kamailio.org
  5. # - git: http://sip-router.org
  6. #
  7. # Refer to the Core CookBook at http://www.kamailio.org/dokuwiki/doku.php
  8. # for an explanation of possible statements, functions and parameters.
  9. #
  10. # Direct your questions about this file to: <[email protected]>.
  11. #
  12. # For more information about the various parameters, functions and statements
  13. # try http://sip-router.org/wiki/ .
  14. #
  15. ####### Defined Values #########
  16. # *** Value defines - IDs used later in config
  17. # - flags
  18. # FLT_ - per transaction (message) flags
  19. # FLB_ - per branch flags
  20. #!define FLT_CAPTURE 1
  21. #!define FLT_DIALOG 2
  22. #!define DLG_TIMEOUT_AVP "i:1"
  23. #!define RR_CUSTOM_USER_AVP "i:2"
  24. #!define DISPATCHER_DST_AVP "i:3"
  25. #!define DISPATCHER_GRP_AVP "i:4"
  26. #!define DISPATCHER_CNT_AVP "i:5"
  27. #!define DISPATCHER_SOCK_AVP "i:6"
  28. ####### Global Parameters #########
  29. include_file "scscf.cfg"
  30. #!ifdef WITH_DEBUG
  31. debug=5
  32. log_stderror=no
  33. sip_warning=yes
  34. #!else
  35. debug=2
  36. log_stderror=no
  37. sip_warning=no
  38. #!endif
  39. #!ifdef WITH_XMLRPC
  40. listen=tcp:127.0.0.1:6060
  41. #!endif
  42. alias=HOSTNAME
  43. user_agent_header="User-Agent: Kamailio S-CSCF"
  44. server_header="Server: Kamailio S-CSCF"
  45. /* comment the next line to enable the auto discovery of local aliases
  46. based on reverse DNS on IPs (default on) */
  47. auto_aliases=no
  48. check_via=no # (cmd. line: -v)
  49. dns=no # (cmd. line: -r)
  50. rev_dns=no # (cmd. line: -R)
  51. # Do SRV-Loadbalancing:
  52. dns_srv_lb=yes
  53. # Always: Also try IPv6:
  54. dns_try_ipv6=yes
  55. # Always prefer IPv6:
  56. dns_cache_flags=6
  57. # DNS-Based failover
  58. use_dns_failover = on
  59. # Query NAPTR-Records as well:
  60. dns_try_naptr=no
  61. #!ifdef WITH_XMLRPC
  62. #!ifndef WITH_TCP
  63. #!define WITH_TCP
  64. #!endif
  65. #!ifndef TCP_PROCESSES
  66. # Number of TCP Processes
  67. #!define TCP_PROCESSES 3
  68. #!endif
  69. #!endif
  70. #!ifdef WITH_TCP
  71. # life time of TCP connection when there is no traffic
  72. # - a bit higher than registration expires to cope with UA behind NAT
  73. tcp_connection_lifetime=3615
  74. #!ifdef TCP_PROCESSES
  75. tcp_children=TCP_PROCESSES
  76. #!endif
  77. #!else
  78. disable_tcp=yes
  79. #!endif
  80. children=12
  81. system.shutdownmode = 0 desc "System shutdown mode"
  82. system.service = "Serving-CSCF" desc "Function of this server"
  83. # ------------------ module loading ----------------------------------
  84. mpath="/usr/lib64/kamailio/modules_k/:/usr/lib64/kamailio/modules/:/usr/lib/kamailio/modules_k/:/usr/lib/kamailio/modules/"
  85. # (we try both the lib64 and the lib directory)
  86. loadmodule "tm.so"
  87. loadmodule "pv.so"
  88. loadmodule "sl.so"
  89. loadmodule "rr.so"
  90. loadmodule "ims_dialog.so"
  91. loadmodule "textops.so"
  92. loadmodule "textopsx.so"
  93. loadmodule "maxfwd.so"
  94. loadmodule "xlog.so"
  95. loadmodule "sanity.so"
  96. loadmodule "siputils.so"
  97. loadmodule "kex.so"
  98. loadmodule "tmx.so"
  99. loadmodule "pike.so"
  100. #!ifdef DB_URL
  101. loadmodule "presence"
  102. #!endif
  103. #!ifdef DB_URL
  104. loadmodule "db_mysql"
  105. #!ifdef DB_URL2
  106. loadmodule "db_cluster"
  107. #!endif
  108. #!endif
  109. loadmodule "dispatcher"
  110. loadmodule "enum"
  111. loadmodule "uac"
  112. # Control interfaces:
  113. loadmodule "ctl"
  114. loadmodule "cfg_rpc"
  115. loadmodule "mi_rpc"
  116. loadmodule "mi_fifo"
  117. #!ifdef WITH_XMLRPC
  118. loadmodule "xmlrpc"
  119. #!endif
  120. loadmodule "cdp.so"
  121. loadmodule "cdp_avp.so"
  122. loadmodule "ims_usrloc_scscf.so"
  123. loadmodule "ims_registrar_scscf.so"
  124. loadmodule "ims_auth.so"
  125. loadmodule "ims_isc.so"
  126. #!ifdef WITH_RO
  127. loadmodule "ims_charging.so"
  128. #!endif
  129. #!ifdef CAPTURE_NODE
  130. loadmodule "siptrace.so"
  131. #!endif
  132. ##!ifdef WITH_DEBUG
  133. loadmodule "debugger.so"
  134. modparam("debugger", "mod_hash_size", 5)
  135. modparam("debugger", "mod_level_mode", 1)
  136. #modparam("debugger", "mod_level", "ims_usrloc_scscf=3")
  137. #modparam("debugger", "mod_level", "ims_registrar_scscf=3")
  138. modparam("debugger", "mod_level", "ims_auth=3")
  139. #modparam("debugger", "mod_level", "ims_isc=3")
  140. modparam("debugger", "mod_level", "ims_dialog=3")
  141. #modparam("debugger", "mod_level", "ims_charging=3")
  142. ##!endif
  143. # ----------------- setting module-specific parameters ---------------
  144. #!ifdef DB_URL2
  145. # ----- db_cluster params -----
  146. modparam("db_cluster", "connection", DB_URL)
  147. modparam("db_cluster", "connection", DB_URL2)
  148. modparam("db_cluster", "cluster", "cluster1=>con1=2s2s;con2=1s1s")
  149. #!endif
  150. # ----- presence params -----
  151. #!ifdef DB_URL
  152. #!ifdef DB_URL2
  153. modparam("presence", "db_url", "cluster://cluster1")
  154. #!else
  155. modparam("presence", "db_url", DB_URL)
  156. #!endif
  157. #modparam("presence", "fallback2db", 1)
  158. modparam("presence", "db_update_period", 20)
  159. #!endif
  160. # ----- mi_fifo params -----
  161. modparam("mi_fifo", "fifo_name", "/tmp/kamailio_fifo")
  162. modparam("mi_fifo", "fifo_mode", 0666)
  163. modparam("mi_fifo", "fifo_user", "kamailio")
  164. modparam("mi_fifo", "fifo_group", "kamailio")
  165. # ----- mi_fifo params -----
  166. modparam("mi_fifo", "fifo_name", "/tmp/kamailio_fifo")
  167. modparam("mi_fifo", "fifo_mode", 0666)
  168. modparam("mi_fifo", "fifo_user", "kamailio")
  169. modparam("mi_fifo", "fifo_group", "kamailio")
  170. # ----- ctl params -----
  171. modparam("ctl", "binrpc", "unix:/var/run/kamailio_scscf/kamailio_ctl")
  172. # ----- tm params -----
  173. # auto-discard branches from previous serial forking leg
  174. modparam("tm", "failure_reply_mode", 3)
  175. # default retransmission timeout: 10sec
  176. modparam("tm", "fr_timer", 10000)
  177. # default invite retransmission timeout after 1xx: 120sec
  178. modparam("tm", "fr_inv_timer", 120000)
  179. # Don't reply automatically with "100 Trying"
  180. modparam("tm", "auto_inv_100", 0)
  181. # ----- rr params -----
  182. # add value to ;lr param to cope with most of the UAs
  183. modparam("rr", "enable_full_lr", 1)
  184. # append from tag to the RR
  185. modparam("rr", "append_fromtag", 1)
  186. # add a Username to RR-Header
  187. modparam("rr", "add_username", 1)
  188. # Take User from a custom AVP
  189. modparam("rr", "custom_user_avp", "$avp(RR_CUSTOM_USER_AVP)")
  190. # -- usrloc params --
  191. modparam("ims_usrloc_scscf", "enable_debug_file", 0)
  192. modparam("ims_usrloc_scscf", "matching_mode", 0)
  193. modparam("ims_registrar_scscf", "max_contacts", 3);
  194. modparam("ims_usrloc_scscf", "maxcontact_behaviour", 2) #overwrite
  195. #!ifdef DB_URL
  196. #!ifdef DB_URL2
  197. modparam("ims_usrloc_scscf", "db_url", "cluster://cluster1")
  198. #!else
  199. modparam("ims_usrloc_scscf", "db_url", DB_URL)
  200. #!endif
  201. modparam("ims_usrloc_scscf", "db_mode", 1)
  202. #!endif
  203. modparam("ims_registrar_scscf", "subscription_default_expires", 654800)
  204. modparam("ims_registrar_scscf", "subscription_min_expires", 3700)
  205. modparam("ims_registrar_scscf", "subscription_max_expires", 605800)
  206. # -- CDP params --
  207. modparam("cdp","config_file","/etc/kamailio_scscf/scscf.xml")
  208. # -- ims_dialog params --
  209. modparam("ims_dialog", "dlg_flag", FLT_DIALOG)
  210. modparam("ims_dialog", "timeout_avp", "$avp(DLG_TIMEOUT_AVP)")
  211. modparam("ims_dialog", "detect_spirals", 1)
  212. modparam("ims_dialog", "profiles_no_value", "orig ; term")
  213. modparam("ims_dialog", "db_mode", 0)
  214. #!ifdef WITH_XMLRPC
  215. # ----- xmlrpc params -----
  216. modparam("xmlrpc", "route", "XMLRPC");
  217. modparam("xmlrpc", "url_match", "^/RPC")
  218. #!endif
  219. #!ifdef WITH_DEBUG
  220. # ----- debugger params -----
  221. modparam("debugger", "cfgtrace", 1)
  222. #!endif
  223. #!ifdef CAPTURE_NODE
  224. # Destination, where to send the traffic
  225. modparam("siptrace", "duplicate_uri", CAPTURE_NODE)
  226. # Trace all traffic
  227. modparam("siptrace", "trace_on", 1)
  228. modparam("siptrace", "trace_to_database", 0)
  229. modparam("siptrace", "trace_flag", FLT_CAPTURE)
  230. modparam("siptrace", "hep_mode_on", 1)
  231. #!endif
  232. # -- ims_auth params --
  233. modparam("ims_auth", "name", URI)
  234. modparam("ims_auth", "registration_default_algorithm", REG_AUTH_DEFAULT_ALG)
  235. #!ifdef CXDX_FORCED_PEER
  236. modparam("ims_auth", "cxdx_forced_peer", CXDX_FORCED_PEER)
  237. #!endif
  238. modparam("ims_auth", "cxdx_dest_realm", NETWORKNAME)
  239. modparam("ims_auth", "av_check_only_impu", 1)
  240. #modparam("ims_auth", "auth_data_timeout", 5)
  241. modparam("ims_auth","auth_used_vector_timeout", 300)
  242. # -- ims_registrar_scscf params --
  243. #!ifdef WITH_DEBUG
  244. modparam("ims_registrar_scscf", "default_expires", 60)
  245. modparam("ims_registrar_scscf", "min_expires", 60)
  246. modparam("ims_registrar_scscf", "max_expires", 60)
  247. #!else
  248. modparam("ims_registrar_scscf", "default_expires", 604800)
  249. modparam("ims_registrar_scscf", "min_expires", 60)
  250. modparam("ims_registrar_scscf", "max_expires", 604800)
  251. #!endif
  252. modparam("ims_registrar_scscf", "use_path", 1)
  253. modparam("ims_registrar_scscf", "support_wildcardPSI",1)
  254. modparam("ims_registrar_scscf", "user_data_xsd","/etc/kamailio_scscf/CxDataType_Rel7.xsd")
  255. modparam("ims_registrar_scscf", "scscf_name", URI)
  256. modparam("ims_registrar_scscf", "scscf_name", URI)
  257. modparam("ims_registrar_scscf", "cxdx_dest_realm", NETWORKNAME)
  258. #!ifdef WITH_MULTIDOMAIN
  259. # ----- domain params -----
  260. #!ifdef DB_URL
  261. #!ifdef DB_URL2
  262. modparam("domain", "db_url", "cluster://cluster1")
  263. #!else
  264. modparam("domain", "db_url", DB_URL)
  265. #!endif
  266. modparam("domain", "db_mode", 1)
  267. #!endif
  268. # register callback to match myself condition with domains list
  269. modparam("domain", "register_myself", 1)
  270. #!endif
  271. # ----- ims_isc params -----
  272. modparam("ims_isc", "my_uri", HOSTNAME)
  273. modparam("ims_isc", "add_p_served_user", 1)
  274. #!ifdef WITH_RO
  275. # ----- ims_diameter_ro params -----
  276. #!ifdef DB_URL
  277. #!ifdef DB_URL2
  278. #modparam("ims_charging", "db_url", "cluster://cluster1")
  279. #!else
  280. #modparam("ims_charging", "db_url", DB_URL)
  281. #!endif
  282. #modparam("ims_charging", "db_mode", 1)
  283. #!endif
  284. modparam("ims_charging", "origin_host", HOSTNAME);
  285. modparam("ims_charging", "origin_realm", NETWORKNAME);
  286. #!ifdef RO_FORCED_PEER
  287. modparam("ims_charging", "ro_forced_peer", RO_FORCED_PEER);
  288. #!endif
  289. modparam("ims_charging", "destination_host", RO_DESTINATION);
  290. modparam("ims_charging", "destination_realm", NETWORKNAME);
  291. modparam("ims_charging","service_context_id_root", RO_ROOT);
  292. modparam("ims_charging","service_context_id_ext", RO_EXT);
  293. modparam("ims_charging","service_context_id_mnc", RO_MNC);
  294. modparam("ims_charging","service_context_id_mcc", RO_MCC);
  295. modparam("ims_charging","service_context_id_release", RO_RELEASE);
  296. modparam("ims_charging","interim_update_credits",30);
  297. modparam("ims_charging","timer_buffer",5);
  298. #!endif
  299. # ----- enum params -----
  300. modparam("enum", "domain_suffix", ENUM_SUFFIX)
  301. # ----- sanity params -----
  302. modparam("sanity", "autodrop", 0)
  303. # ----------------- Settings for Dispatcher ---------------
  304. modparam("dispatcher", "list_file", "/etc/kamailio_scscf/dispatcher.list")
  305. # Dispatcher: Enable Failover-Support
  306. modparam("dispatcher", "flags", 2)
  307. # Dispatcher: Overwrite Destination address, if required.
  308. modparam("dispatcher", "force_dst", 1)
  309. # AVP's required for Fail-Over-Support:
  310. modparam("dispatcher", "dst_avp", "$avp(DISPATCHER_DST_AVP)")
  311. modparam("dispatcher", "grp_avp", "$avp(DISPATCHER_GRP_AVP)")
  312. modparam("dispatcher", "cnt_avp", "$avp(DISPATCHER_CNT_AVP)")
  313. modparam("dispatcher", "sock_avp", "$avp(DISPATCHER_SOCK_AVP)")
  314. # Try to recover disabled destinations every 15 seconds.
  315. modparam("dispatcher", "ds_ping_interval", 15)
  316. # Actively query the gateways:
  317. modparam("dispatcher", "ds_probing_mode", 1)
  318. modparam("dispatcher", "ds_ping_reply_codes", "class=2;code=404;code=480")
  319. ####### Routing Logic ########
  320. # Main SIP request routing logic
  321. # - processing of any incoming SIP request starts with this route
  322. route {
  323. ##!ifdef WITH_DEBUG
  324. xlog("$rm ($fu ($si:$sp) to $tu, $ci)\n");
  325. ##!endif
  326. # per request initial checks
  327. route(REQINIT);
  328. # Handle Registrations:
  329. if (is_method("REGISTER")) {
  330. route(REGISTER);
  331. exit;
  332. }
  333. # we need to support subscription to reg event
  334. if (is_method("SUBSCRIBE") && search("^(Event|o)([ \t]*):([ \t]*)reg")) {
  335. route(SUBSCRIBE);
  336. break;
  337. }
  338. if (is_method("PUBLISH") && search("^(Event|o)([ \t]*):([ \t]*)reg")) {
  339. route(PUBLISH);
  340. break;
  341. }
  342. #Set DLG flag to track dialogs using dialog2
  343. if (!is_method("REGISTER|SUBSCRIBE"))
  344. setflag(FLT_DIALOG);
  345. # Evaluate Route-Header and set $route_uri
  346. loose_route();
  347. if (is_method("CANCEL|ACK")) {
  348. t_relay();
  349. exit;
  350. }
  351. if (($route_uri =~ "sip:orig@.*") || isc_from_as("orig")) {
  352. xlog("Orig");
  353. # we need something like this to assign SCSCF to unregistered user for services
  354. # support for AS origination on behalf of unregistered useri
  355. # can use the registrar is_registered methods - must see if we need to check orig or term?
  356. # Originating
  357. route(orig);
  358. break;
  359. } else {
  360. isc_from_as("term");
  361. if ($retcode == -2) {
  362. # Treat as originating, since it was retargeted:
  363. route(orig);
  364. break;
  365. }
  366. if ((is_in_profile("orig") || has_totag()) && ($route_uri =~ "sip:mo@"+".*")) {
  367. route(orig_subsequent);
  368. break;
  369. }
  370. if ((is_in_profile("term") || has_totag()) && ($route_uri =~ "sip:mt@"+".*")) {
  371. route(term_subsequent);
  372. break;
  373. }
  374. # Terminating
  375. if (uri == myself || uri =~ "tel:.*") {
  376. if (!term_impu_registered("location")) {
  377. xlog("L_DBG", "We need to do an UNREG server SAR assignemnt");
  378. assign_server_unreg("UNREG_SAR_REPLY", "location", "term");
  379. exit;
  380. }
  381. } else {
  382. sl_send_reply("403","Forbidden - Domain not served");
  383. exit();
  384. }
  385. route(term);
  386. break;
  387. }
  388. }
  389. route[UNREG_SAR_REPLY]
  390. {
  391. xlog("L_DBG","saa_return code is $avp(s:saa_return_code)\n");
  392. switch ($avp(s:saa_return_code)){
  393. case 1: #success
  394. xlog("L_DBG", "SAR success - will route message\n");
  395. route(term);
  396. break;
  397. case -1: #failure
  398. xlog("L_ERR", "SAR failure - error response sent from module\n");
  399. break;
  400. case -2: #error
  401. xlog("L_ERR", "SAR error - error response sent from module\n");
  402. break;
  403. default:
  404. xlog("L_ERR", "Unknown return code from SAR, value is [$avp(s:saa_return_code)]\n");
  405. break;
  406. }
  407. exit;
  408. }
  409. ######################################################################
  410. # Helper routes (Basic-Checks, NAT-Handling/RTP-Control, XML-RPC)
  411. ######################################################################
  412. # Per SIP request initial checks
  413. route[REQINIT] {
  414. $var(used) = 1 - ($stat(free_size) / $stat(total_size));
  415. xlog("L_DBG", "Mem: Total $stat(total_size), Free $stat(free_size) [$var(used)% used]\n");
  416. if ($var(used) > 95) {
  417. send_reply("503", "Server overloaded");
  418. exit;
  419. }
  420. # Trace this message
  421. #!ifdef CAPTURE_NODE
  422. sip_trace();
  423. setflag(FLT_CAPTURE);
  424. #!endif
  425. if (!mf_process_maxfwd_header("10")) {
  426. sl_send_reply("483","Too Many Hops");
  427. exit;
  428. }
  429. if(!sanity_check("1511", "7")) {
  430. xlog("Malformed SIP message from $si:$sp\n");
  431. exit;
  432. }
  433. # Check for shutdown mode:
  434. if (!has_totag() && ($sel(cfg_get.system.shutdownmode) > 0)) {
  435. send_reply("503", "Server shutting down");
  436. exit;
  437. }
  438. # Reply to OPTIONS:
  439. if (is_method("OPTIONS") && (uri==myself)) {
  440. options_reply();
  441. exit;
  442. }
  443. # Ignore Re-Transmits:
  444. if (t_lookup_request()) {
  445. exit;
  446. }
  447. if (is_method("INVITE")) {
  448. send_reply("100", "Trying");
  449. }
  450. }
  451. ######################################################################
  452. # Publish route
  453. ######################################################################
  454. route[PUBLISH]
  455. {
  456. if (!t_newtran()) {
  457. #absorb retransmissions
  458. sl_reply("500","Could not create transaction");
  459. exit;
  460. }
  461. if (can_publish_reg("location")) {
  462. $var(ret)= publish_reg("location");
  463. switch ($var(ret)){
  464. case 1: #success
  465. xlog("L_DBG", "Publish reg successful");
  466. break;
  467. case -1: #failure
  468. xlog("L_ERR", "Publish reg failure - sending 500 Error now\n");
  469. t_reply("500","Server Error publishing subscription");
  470. break;
  471. default:
  472. xlog("L_ERR", "Unknown return code from publish reg event alue is [$var(ret)]\n");
  473. break;
  474. }
  475. } else {
  476. t_reply("403","Forbidden to PUBLISH");
  477. exit;
  478. }
  479. }
  480. ######################################################################
  481. # Subscribe route
  482. ######################################################################
  483. route[SUBSCRIBE]
  484. {
  485. if (!t_newtran()) {
  486. #absorb retransmissions
  487. sl_reply("500","Could not create transaction");
  488. exit;
  489. }
  490. if (!has_totag()) {
  491. xlog("L_DBG", "This is an initial SUBSCRIBE\n");
  492. if (!term_impu_registered("location")) {
  493. xlog("L_DBG", "We need to do an UNREG server SAR assignment\n");
  494. assign_server_unreg("SUBSCRIBE_UNREG_SAR_REPLY", "location", "term");
  495. exit;
  496. }
  497. if (!can_subscribe_to_reg("location")){
  498. t_reply("403","Forbidden to SUBSCRIBE");
  499. exit;
  500. }
  501. }else{
  502. xlog("L_DBG", "This is a subsequent SUBSCRIBE\n");
  503. }
  504. $var(ret)= subscribe_to_reg("location");
  505. switch ($var(ret)){
  506. case 1: #success
  507. xlog("L_DBG", "Subscribe to reg successful");
  508. break;
  509. case -1: #failure
  510. xlog("L_ERR", "Subscribe to reg failure - sending 500 Error now\n");
  511. t_reply("500","Server Error saving subscription");
  512. break;
  513. case -2: #error
  514. xlog("L_ERR", "Subscribe to reg error sending notify - 200 OK so subscription already sent\n");
  515. break;
  516. default:
  517. xlog("L_ERR", "Unknown return code from subscribe to reg event alue is [$var(ret)]\n");
  518. break;
  519. }
  520. }
  521. route[SUBSCRIBE_UNREG_SAR_REPLY]
  522. {
  523. xlog("L_DBG","saa_return code is $avp(s:saa_return_code)\n");
  524. switch ($avp(s:saa_return_code)){
  525. case 1: #success
  526. xlog("L_DBG", "SAR success - will process subscribe\n");
  527. if (can_subscribe_to_reg("location")){
  528. $var(ret)= subscribe_to_reg("location");
  529. switch ($var(ret)){
  530. case 1: #success
  531. xlog("L_DBG", "Subscribe to reg successful");
  532. break;
  533. case -1: #failure
  534. xlog("L_ERR", "Subscribe to reg failure - sending 500 Error now\n");
  535. t_reply("500","Server Error saving subscription");
  536. break;
  537. case -2: #error
  538. xlog("L_ERR", "Subscribe to reg error sending notify - 200 OK so subscription already sent\n");
  539. break;
  540. default:
  541. xlog("L_ERR", "Unknown return code from subscribe to reg event alue is [$var(ret)]\n");
  542. break;
  543. }
  544. }else{
  545. t_reply("403","Forbidden to SUBSCRIBE");
  546. exit;
  547. }
  548. break;
  549. case -1: #failure
  550. xlog("L_ERR", "SAR failure - Sending 403 Forbidden\n");
  551. t_reply("403","Forbidden to SUBSCRIBE");
  552. break;
  553. case -2: #error
  554. xlog("L_ERR", "SAR error - Sending 403 Forbidden\n");
  555. t_reply("403","Forbidden to SUBSCRIBE");
  556. break;
  557. default:
  558. xlog("L_ERR", "Unknown return code from SAR, value is [$avp(s:saa_return_code)] - sending 403 Forbidden\n");
  559. t_reply("403","Forbidden to SUBSCRIBE");
  560. break;
  561. }
  562. exit;
  563. }
  564. ######################################################################
  565. # XMLRPC routing
  566. ######################################################################
  567. #!ifdef WITH_XMLRPC
  568. route[XMLRPC] {
  569. if ((method=="POST" || method=="GET")
  570. #!ifdef XMLRPC_WHITELIST_1
  571. && ((src_ip == XMLRPC_WHITELIST_1)
  572. #!ifdef XMLRPC_WHITELIST_2
  573. || (src_ip == XMLRPC_WHITELIST_2)
  574. #!endif
  575. #!ifdef XMLRPC_WHITELIST_3
  576. || (src_ip == XMLRPC_WHITELIST_3)
  577. #!endif
  578. )
  579. #!endif
  580. ) {
  581. # close connection only for xmlrpclib user agents (there is a bug in
  582. # xmlrpclib: it waits for EOF before interpreting the response).
  583. if ($hdr(User-Agent) =~ "xmlrpclib")
  584. set_reply_close();
  585. set_reply_no_connect();
  586. dispatch_rpc();
  587. exit;
  588. }
  589. send_reply("403", "Forbidden");
  590. exit;
  591. }
  592. #!endif
  593. ######################################################################
  594. # Route for handling Registrations:
  595. ######################################################################
  596. route[REGISTER] {
  597. xlog("ALGORITHM IS [$aa] and User-Agent is [$ua]\n");
  598. $var(alg) = $aa;
  599. if ($aa == $null) {
  600. $var(alg) = "MD5"; #force to MD5 for zoiper.... non-ims
  601. }
  602. #!ifdef WITH_AUTH
  603. if (!ims_www_authenticate("$td")) {
  604. #!else
  605. if (($var(alg) == "MD5") && (!ims_www_authenticate("$td"))) {
  606. #!endif
  607. if ($? == -2) {
  608. send_reply("403", "Authentication Failed");
  609. exit;
  610. } else if ($? == -3) {
  611. send_reply("400", "Bad Request");
  612. exit;
  613. } else if ($? == -9) {
  614. xlog("L_DBG", "Authentication re-sync requested\n");
  615. ims_www_resync_auth("REG_RESYNC_REPLY", "$td");
  616. exit;
  617. } else {
  618. #user has not been authenticated. Lets send a challenge via 401 Unauthorized
  619. xlog("L_DBG","About to challenge! auth_ims\n");
  620. ims_www_challenge("REG_MAR_REPLY", "$td", "$var(alg)");
  621. exit;
  622. }
  623. } else {
  624. xlog("L_DBG", "Auth succeeded\n");
  625. # We need to check if this user is registered or not
  626. if (!impu_registered("location")) {
  627. xlog("L_ERR", "Not REGISTERED\n");
  628. save("PRE_REG_SAR_REPLY","location");
  629. exit;
  630. } else {
  631. isc_match_filter_reg("1","location");
  632. save("REG_SAR_REPLY","location");
  633. exit;
  634. }
  635. }
  636. }
  637. route[REG_MAR_REPLY]
  638. {
  639. #this is async so to know status we have to check the reply avp
  640. xlog("L_DBG","maa_return code is $avp(s:maa_return_code)\n");
  641. switch ($avp(s:maa_return_code)){
  642. case 1: #success
  643. xlog("L_DBG", "MAR success - 401/407 response sent from module\n");
  644. break;
  645. case -1: #failure
  646. xlog("L_ERR", "MAR failure - error response sent from module\n");
  647. break;
  648. case -2: #error
  649. xlog("L_ERR", "MAR error - sending error response now\n");
  650. send_reply("500", "MAR failed");
  651. break;
  652. default:
  653. xlog("L_ERR", "Unknown return code from MAR, value is [$avp(s:maa_return_code)]\n");
  654. send_reply("500", "Unknown response code from MAR");
  655. break;
  656. }
  657. exit;
  658. }
  659. route[PRE_REG_SAR_REPLY]
  660. {
  661. xlog("L_DBG","saa_return code is $avp(s:saa_return_code)\n");
  662. #this is async so to know status we have to check the reply avp
  663. xlog("L_DBG","saa_return code (for scscf_save on register) is $avp(s:saa_return_code)\n");
  664. switch ($avp(s:saa_return_code)){
  665. case 1: #success
  666. xlog("L_DBG", "SAR success - 200 response sent from module\n");
  667. isc_match_filter_reg("0","location");
  668. exit;
  669. case -1: #failure
  670. xlog("L_ERR", "SAR failure - error response sent from module\n");
  671. break;
  672. case -2: #error
  673. xlog("L_ERR", "SAR error - error response sent from module\n");
  674. break;
  675. default:
  676. xlog("L_ERR", "Unknown return code from SAR, value is [$avp(s:saa_return_code)]\n");
  677. break;
  678. }
  679. exit;
  680. }
  681. route[REG_SAR_REPLY]
  682. {
  683. xlog("L_DBG","saa_return code is $avp(s:saa_return_code)\n");
  684. #this is async so to know status we have to check the reply avp
  685. xlog("L_DBG","saa_return code (for scscf_save on register) is $avp(s:saa_return_code)\n");
  686. switch ($avp(s:saa_return_code)){
  687. case 1: #success
  688. xlog("L_DBG", "SAR success - 200 response sent from module\n");
  689. exit;
  690. case -1: #failure
  691. xlog("L_ERR", "SAR failure - error response sent from module\n");
  692. break;
  693. case -2: #error
  694. xlog("L_ERR", "SAR error - error response sent from module\n");
  695. break;
  696. default:
  697. xlog("L_ERR", "Unknown return code from SAR, value is [$avp(s:saa_return_code)]\n");
  698. break;
  699. }
  700. exit;
  701. }
  702. route[REG_RESYNC_REPLY]
  703. {
  704. ims_www_challenge("REG_MAR_REPLY", "$td");
  705. }
  706. ######################################################################
  707. # Apply privacy, if requested
  708. ######################################################################
  709. route[apply_privacy]
  710. {
  711. if (is_present_hf("Privacy") && ($hdr(Privacy)=="id")) {
  712. remove_hf("P-Asserted-Identity");
  713. }
  714. }
  715. ######################################################################
  716. # Originating, Intial Requests
  717. ######################################################################
  718. route[orig]
  719. {
  720. xlog("L_DBG","Enter orig route\n");
  721. set_dlg_profile("orig");
  722. # we MAYBE need something like this to check if a user is barred
  723. # if (S_originating_barred()){
  724. # sl_send_reply("403","Forbidden - Originating Public Identity barred");
  725. # exit;
  726. # }
  727. if (is_method("INVITE|SUBSCRIBE")) {
  728. $avp(RR_CUSTOM_USER_AVP)="mo";
  729. record_route();
  730. }
  731. # Start new transaction:
  732. t_newtran();
  733. # check if dialog saved as fwded to AS
  734. if (isc_match_filter("orig", "location")) {
  735. t_on_failure("isc_orig_failure");
  736. xlog("Orig - msg was fwded to AS\n");
  737. exit;
  738. }
  739. if (!isc_from_as("orig")) {
  740. remove_hf("P-Asserted-Identity");
  741. append_hf("P-Asserted-Identity: <sip:$fU@$fd>\r\n");
  742. }
  743. #!ifdef WITH_RO
  744. # before we allow call - lets check credit
  745. if (is_method("INVITE")) {
  746. xlog("L_DBG","Sending initial CCR Request for call\n");
  747. $var(cc_ret) = Ro_CCR("CHARGING_CCR_ORIG_REPLY", "orig", 30, "0", "0");
  748. if ($var(cc_ret) < 0) {
  749. xlog("L_ERR","CCR Request failure\n");
  750. sl_send_reply("402","Payment required");
  751. exit;
  752. }
  753. xlog("L_DBG","CCR Request success\n");
  754. exit;
  755. }
  756. #!endif
  757. route(FINAL_ORIG);
  758. }
  759. route[FINAL_ORIG]
  760. {
  761. # Check for PSTN destinations:
  762. if (is_method("INVITE")) {
  763. route(PSTN_handling);
  764. }
  765. t_on_reply("orig_reply");
  766. t_relay();
  767. }
  768. route[CHARGING_CCR_ORIG_REPLY]
  769. {
  770. xlog("L_DBG","cca_return code is $avp(s:cca_return_code)\n");
  771. switch ($avp(s:cca_return_code)){
  772. case 1: #success
  773. xlog("L_DBG", "CCR success - will route message\n");
  774. route(FINAL_ORIG);
  775. break;
  776. case -1: #failure
  777. xlog("L_ERR", "CCR failure - error response sent from module\n");
  778. switch ($avp(s:cca_result_code)){
  779. case 5030:
  780. send_reply("403", "Charging User not found");
  781. break;
  782. case 5031:
  783. send_reply("403", "Rating failed");
  784. break;
  785. case 4010:
  786. send_reply("402", "Payment required - Unsufficient funds");
  787. break;
  788. case 5006:
  789. send_reply("486", "Line limit exceeded");
  790. break;
  791. default:
  792. send_reply("402","Payment required ($avp(s:cca_result_code))");
  793. break;
  794. }
  795. case -2: #error
  796. xlog("L_ERR", "CCR error - error response sent from module\n");
  797. send_reply("500", "Charging Error");
  798. break;
  799. default:
  800. xlog("L_ERR", "Unknown return code from CCR: [$avp(s:cca_return_code)] \n");
  801. send_reply("500", "Charging Error");
  802. break;
  803. }
  804. exit;
  805. }
  806. ######################################################################
  807. # Replies to the Initial Requests
  808. ######################################################################
  809. onreply_route[orig_reply]
  810. {
  811. xlog("L_DBG","Orig reply\n");
  812. route(apply_privacy);
  813. break;
  814. }
  815. ######################################################################
  816. # Originating, subsequent requests
  817. ######################################################################
  818. route[orig_subsequent]
  819. {
  820. xlog("L_DBG","Orig_Subsequent\n");
  821. if (!is_method("ACK")) {
  822. t_on_reply("orig_subsequent_reply");
  823. }
  824. t_relay();
  825. }
  826. ######################################################################
  827. # Replies for originating, subsequent requests
  828. ######################################################################
  829. onreply_route[orig_subsequent_reply]
  830. {
  831. xlog("L_DBG","Orig_Subsequent_reply\n");
  832. route(apply_privacy);
  833. break;
  834. }
  835. ######################################################################
  836. # Failure-Route for Requests to an AS
  837. ######################################################################
  838. failure_route[isc_orig_failure]
  839. {
  840. xlog("L_DBG","ISC_Orig_failure\n");
  841. if (t_check_status("(408)|(5..)")){
  842. t_on_failure("isc_orig_failure");
  843. if (isc_match_filter("orig","location")){
  844. xlog("L_DBG","ISC_Orig_failure - msg was fwded to AS\n");
  845. exit;
  846. }
  847. if (isc_from_as("origfail")) {
  848. remove_hf("P-Asserted-Identity");
  849. append_hf("P-Asserted-Identity: <sip:$fU@$fd>\r\n");
  850. }
  851. t_on_reply("orig_reply");
  852. t_relay();
  853. }
  854. }
  855. ######################################################################
  856. # Terminating requests
  857. ######################################################################
  858. route[term]
  859. {
  860. xlog("L_DBG","Term\n");
  861. set_dlg_profile("term");
  862. #we need something like this to check if a user is barred
  863. # if (S_terminating_barred()){
  864. # sl_send_reply("404","Not Found - Terminating user barred");
  865. # exit;
  866. # }
  867. if (is_method("INVITE|SUBSCRIBE")) {
  868. $avp(RR_CUSTOM_USER_AVP)="mt";
  869. $avp(i:20)="mt";
  870. record_route();
  871. }
  872. # check if dialog saved as fwded to AS
  873. if (isc_match_filter("term","location")){
  874. t_on_failure("isc_term_failure");
  875. xlog("L_DBG","Term - msg was fwded to AS\n");
  876. exit;
  877. }
  878. #!ifdef WITH_RO_TERM
  879. # before we allow call - lets check credit
  880. if (is_method("INVITE")) {
  881. xlog("L_DBG","Sending initial CCR Request for call\n");
  882. $var(cc_ret) = Ro_CCR("CHARGING_CCR_TERM_REPLY", "term", 30, "0", "0");
  883. if ($var(cc_ret) < 0) {
  884. xlog("L_ERR","CCR Request failure\n");
  885. sl_send_reply("402","Payment required");
  886. exit;
  887. }
  888. xlog("L_DBG","CCR Request success\n");
  889. exit;
  890. }
  891. #!endif
  892. route(FINAL_TERM);
  893. }
  894. route[FINAL_TERM] {
  895. if (lookup("location")) {
  896. if (uri==myself) {
  897. if (!t_newtran()) {
  898. sl_reply_error();
  899. exit;
  900. }
  901. t_reply("404","Not Found - destination user not found on this S-CSCF");
  902. exit;
  903. }
  904. } else {
  905. # User not registered? Reply with 404.
  906. if (!t_newtran()) {
  907. sl_reply_error();
  908. exit;
  909. }
  910. t_reply("404","Not Found - destination user not found on this S-CSCF");
  911. exit;
  912. }
  913. route(apply_privacy);
  914. t_relay();
  915. }
  916. route[CHARGING_CCR_TERM_REPLY]
  917. {
  918. xlog("L_DBG","cca_return code is $avp(s:cca_return_code)\n");
  919. switch ($avp(s:cca_return_code)){
  920. case 1: #success
  921. xlog("L_DBG", "CCR success - will route message\n");
  922. route(FINAL_TERM);
  923. break;
  924. case -1: #failure
  925. xlog("L_ERR", "CCR failure - error response sent from module\n");
  926. switch ($avp(s:cca_result_code)){
  927. case 5030:
  928. send_reply("403", "Charging User not found");
  929. break;
  930. case 5031:
  931. send_reply("403", "Rating failed");
  932. break;
  933. case 4010:
  934. send_reply("402", "Payment required - Unsufficient funds");
  935. break;
  936. case 5006:
  937. send_reply("486", "Line limit exceeded");
  938. break;
  939. default:
  940. send_reply("402","Payment required ($avp(s:cca_result_code))");
  941. break;
  942. }
  943. case -2: #error
  944. xlog("L_ERR", "CCR error - error response sent from module\n");
  945. send_reply("500", "Charging Error");
  946. break;
  947. default:
  948. xlog("L_ERR", "Unknown return code from CCR: [$avp(s:cca_return_code)] \n");
  949. send_reply("500", "Charging Error");
  950. break;
  951. }
  952. exit;
  953. }
  954. ######################################################################
  955. # Failure Route for Terminating requests
  956. ######################################################################
  957. failure_route[isc_term_failure]
  958. {
  959. xlog("L_DBG","ISC_term_failure\n");
  960. if (t_check_status("(408)|(5..)")){
  961. t_on_failure("isc_term_failure");
  962. if (isc_match_filter("term","location")){
  963. xlog("L_DBG","Term - msg was fwded to AS\n");
  964. exit;
  965. }
  966. if (lookup("location")) {
  967. if (uri==myself) {
  968. t_reply("404","Not Found - destination user not found on this S-CSCF");
  969. exit;
  970. }
  971. } else {
  972. t_reply("404","Not Found - destination user not found on this S-CSCF");
  973. exit;
  974. }
  975. t_relay();
  976. }
  977. }
  978. ######################################################################
  979. # Terminating, subsequent requests
  980. ######################################################################
  981. route[term_subsequent]
  982. {
  983. xlog("L_DBG","term_subsequent\n");
  984. route(apply_privacy);
  985. t_relay();
  986. }
  987. ######################################################################
  988. # Check for PSTN destinations:
  989. ######################################################################
  990. route[PSTN_handling]
  991. {
  992. # First, we translate "tel:"-URI's to SIP-URI's:
  993. # $ru: tel:+(34)-999-888-777
  994. # $fu: sip:[email protected]
  995. # becomes $ru: sip:[email protected];user=phone
  996. if (!tel2sip("$ru", "$fd", "$ru"))
  997. 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");
  998. if ($rU =~ "\+[0-9]+") {
  999. # Now let's check, if the number can be found in ENUM:
  1000. if(!enum_query()) {
  1001. # ENUM failed, send it to the PSTN-Gateway:
  1002. route(PSTN);
  1003. break;
  1004. }
  1005. }
  1006. }
  1007. ######################################################################
  1008. # Send calls to the PSTN-Gateways:
  1009. ######################################################################
  1010. route[PSTN]
  1011. {
  1012. $var(has_trf) = 0;
  1013. if (is_present_hf("Feature-Caps")) {
  1014. xlog("Feature-Caps: $hdr(Feature-Caps) => $(hdr(Feature-Caps){param.value,+g.3gpp.trf}{nameaddr.uri}{uri.host})\n");
  1015. if ($(hdr(Feature-Caps){param.value,+g.3gpp.trf}) != $null) {
  1016. $rd = $(hdr(Feature-Caps){param.value,+g.3gpp.trf}{nameaddr.uri}{uri.host});
  1017. if (!strempty($(ou{uri.params}))) {
  1018. $ru = $ru+";"+$(ou{uri.params});
  1019. }
  1020. t_on_failure("TRF_failure");
  1021. if (t_relay_to("0x02")) {
  1022. $var(has_trf) = 1;
  1023. } else {
  1024. xlog("Relay to $du failed.\n");
  1025. $du = $null;
  1026. }
  1027. }
  1028. }
  1029. if ($var(has_trf) == 0) {
  1030. if (!ds_select_domain("1", "4")) {
  1031. xlog("L_WARN","No PSTN-Gateways available - M=$rm R=$ru F=$fu T=$tu IP=$si:$sp ID=$ci\n\n");
  1032. send_reply("503", "Service not available");
  1033. exit;
  1034. }
  1035. if (!strempty($(ou{uri.params}))) {
  1036. $ru = $ru+";"+$(ou{uri.params});
  1037. }
  1038. t_relay();
  1039. }
  1040. # Relay the request:
  1041. t_on_failure("PSTN_failure");
  1042. exit;
  1043. }
  1044. ######################################################################
  1045. # manage failure routing cases, perform failover
  1046. ######################################################################
  1047. failure_route[TRF_failure] {
  1048. xlog("TRF_failure\n");
  1049. # Choose another gateway, in case we
  1050. # - get a local generated "408"
  1051. # - receive a 5xx or 6xx reply from the proxy.
  1052. if (t_branch_timeout() || t_check_status("[5-6]..")) {
  1053. $du = $null;
  1054. if (!ds_select_domain("1", "4")) {
  1055. xlog("L_WARN","No PSTN-Gateways available - M=$rm R=$ru F=$fu T=$tu IP=$si:$sp ID=$ci\n\n");
  1056. send_reply("503", "Service not available");
  1057. exit;
  1058. }
  1059. if (!strempty($(ou{uri.params}))) {
  1060. $ru = $ru+";"+$(ou{uri.params});
  1061. }
  1062. # Relay the request:
  1063. t_on_failure("PSTN_failure");
  1064. t_relay();
  1065. exit;
  1066. }
  1067. }
  1068. ######################################################################
  1069. # manage failure routing cases, perform failover
  1070. ######################################################################
  1071. failure_route[PSTN_failure] {
  1072. # Choose another gateway, in case we
  1073. # - get a local generated "408"
  1074. # - receive a 5xx or 6xx reply from the proxy.
  1075. if (t_branch_timeout() || t_check_status("[5-6]..")) {
  1076. if (ds_next_domain()) {
  1077. if (!strempty($(ou{uri.params}))) {
  1078. $ru = $ru+";"+$(ou{uri.params});
  1079. }
  1080. # Do Failover in case problems:
  1081. t_on_failure("PSTN_failure");
  1082. t_relay();
  1083. } else {
  1084. # Add a header, to indicate the phone should try again in 30 seconds.
  1085. append_hf("Retry-After: 30\r\n");
  1086. send_reply("503", "Service not available");
  1087. }
  1088. exit;
  1089. }
  1090. }