kamailio.cfg 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629
  1. #!KAMAILIO
  2. #
  3. # This config file implements the basic I-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. system.shutdownmode = 0 desc "System shutdown mode"
  16. system.service = "Interrogating-CSCF" desc "Function of this server"
  17. include_file "icscf.cfg"
  18. ####### Defined Values #########
  19. # *** Value defines - IDs used later in config
  20. # - flags
  21. # FLT_ - per transaction (message) flags
  22. # FLB_ - per branch flags
  23. #!define FLT_CAPTURE 1
  24. #!ifdef WITH_XMLRPC
  25. listen=tcp:127.0.0.1:4060
  26. #!endif
  27. ####### Global Parameters #########
  28. #!ifdef WITH_DEBUG
  29. debug=5
  30. log_stderror=yes
  31. sip_warning=yes
  32. #!else
  33. debug=2
  34. log_stderror=no
  35. sip_warning=no
  36. #!endif
  37. user_agent_header="User-Agent: Kamailio I-CSCF"
  38. server_header="Server: Kamailio I-CSCF"
  39. /* comment the next line to enable the auto discovery of local aliases
  40. based on reverse DNS on IPs (default on) */
  41. auto_aliases=no
  42. # Do SRV-Loadbalancing:
  43. dns_srv_lb=yes
  44. # Always: Also try IPv6:
  45. dns_try_ipv6=yes
  46. # Query NAPTR-Records as well:
  47. dns_try_naptr=no
  48. #!ifdef WITH_XMLRPC
  49. #!ifndef WITH_TCP
  50. #!define WITH_TCP
  51. #!endif
  52. #!ifndef TCP_PROCESSES
  53. # Number of TCP Processes
  54. #!define TCP_PROCESSES 3
  55. #!endif
  56. #!endif
  57. #!ifdef WITH_TCP
  58. # life time of TCP connection when there is no traffic
  59. # - a bit higher than registration expires to cope with UA behind NAT
  60. tcp_connection_lifetime=3615
  61. #!ifdef TCP_PROCESSES
  62. tcp_children=TCP_PROCESSES
  63. #!endif
  64. #!else
  65. disable_tcp=yes
  66. #!endif
  67. check_via=no # (cmd. line: -v)
  68. dns=no # (cmd. line: -r)
  69. rev_dns=no # (cmd. line: -R)
  70. children=64
  71. # ------------------ module loading ----------------------------------
  72. mpath="/usr/lib64/kamailio/modules_k/:/usr/lib64/kamailio/modules/:/usr/lib/kamailio/modules_k/:/usr/lib/kamailio/modules/"
  73. # (we try both the lib64 and the lib directory)
  74. loadmodule "tm"
  75. loadmodule "sl"
  76. loadmodule "rr"
  77. loadmodule "pv"
  78. loadmodule "textops"
  79. loadmodule "maxfwd"
  80. loadmodule "sanity"
  81. loadmodule "siputils"
  82. loadmodule "kex"
  83. loadmodule "tmx"
  84. loadmodule "pike"
  85. loadmodule "corex"
  86. # Control interfaces:
  87. loadmodule "ctl"
  88. loadmodule "cfg_rpc"
  89. loadmodule "mi_rpc"
  90. loadmodule "mi_fifo"
  91. #!ifdef WITH_XMLRPC
  92. loadmodule "xmlrpc"
  93. #!endif
  94. # Load the according DB-Module:
  95. loadmodule "db_mysql"
  96. #!ifdef DB_URL2
  97. loadmodule "db_cluster"
  98. #!endif
  99. loadmodule "cdp.so"
  100. loadmodule "cdp_avp.so"
  101. loadmodule "xlog.so"
  102. loadmodule "ims_icscf.so"
  103. #!ifdef CAPTURE_NODE
  104. loadmodule "siptrace.so"
  105. #!endif
  106. #!ifdef WITH_DEBUG
  107. loadmodule "debugger.so"
  108. #!endif
  109. #!ifdef WITH_TLS
  110. loadmodule "tls.so"
  111. #!endif
  112. #!ifdef PEERING
  113. loadmodule "enum"
  114. #!endif
  115. # ----------------- setting module-specific parameters ---------------
  116. #!ifdef DB_URL2
  117. # ----- db_cluster params -----
  118. modparam("db_cluster", "connection", DB_URL)
  119. modparam("db_cluster", "connection", DB_URL2)
  120. modparam("db_cluster", "cluster", "cluster1=>con1=2s2s;con2=1s1s")
  121. #!endif
  122. # ----- mi_fifo params -----
  123. modparam("mi_fifo", "fifo_name", "/tmp/kamailio_fifo")
  124. modparam("mi_fifo", "fifo_mode", 0666)
  125. modparam("mi_fifo", "fifo_user", "kamailio")
  126. modparam("mi_fifo", "fifo_group", "kamailio")
  127. # -- rr params --
  128. # add value to ;lr param to make some broken UAs happy
  129. modparam("rr", "enable_full_lr", 1)
  130. # -- cdp params --
  131. modparam("cdp","config_file","/etc/kamailio_icscf/icscf.xml")
  132. # ----- icscf params -----
  133. # Comment the following line to enable realm routing
  134. #!ifdef CXDX_FORCED_PEER
  135. modparam("ims_icscf", "cxdx_forced_peer", CXDX_FORCED_PEER)
  136. #!endif
  137. modparam("ims_icscf","cxdx_dest_realm", NETWORKNAME)
  138. # DB-URL, where information about S-CSCF-Server can be found:
  139. #!ifdef DB_URL2
  140. modparam("ims_icscf", "db_url", "cluster://cluster1")
  141. #!else
  142. modparam("ims_icscf", "db_url", DB_URL)
  143. #!endif
  144. #!ifdef PEERING
  145. # Route which is executed, in case HSS returned "User-Unknown" on LIR request
  146. modparam("ims_icscf","route_lir_user_unknown", "lir_term_user_unknown")
  147. #!endif
  148. #!ifdef FALLBACK_AUTH
  149. # Route which is executed, in case HSS returned "User-Unknown" on UAR request
  150. modparam("ims_icscf","route_uar_user_unknown", "uar_term_user_unknown")
  151. #!endif
  152. #!ifdef WITH_TLS
  153. # ----- tls params -----
  154. modparam("tls", "config", "/etc/kamailio/tls.cfg")
  155. #!endif
  156. #!ifdef WITH_XMLRPC
  157. # ----- xmlrpc params -----
  158. modparam("xmlrpc", "route", "XMLRPC");
  159. modparam("xmlrpc", "url_match", "^/RPC")
  160. #!endif
  161. # ----- ctl params -----
  162. modparam("ctl", "binrpc", "unix:/var/run/kamailio_icscf/kamailio_ctl")
  163. #!ifdef WITH_DEBUG
  164. # ----- debugger params -----
  165. modparam("debugger", "cfgtrace", 1)
  166. #!endif
  167. #!ifdef CAPTURE_NODE
  168. # Destination, where to send the traffic
  169. modparam("siptrace", "duplicate_uri", CAPTURE_NODE)
  170. # Trace all traffic
  171. modparam("siptrace", "trace_on", 1)
  172. modparam("siptrace", "trace_to_database", 0)
  173. modparam("siptrace", "trace_flag", FLT_CAPTURE)
  174. modparam("siptrace", "hep_mode_on", 1)
  175. #!endif
  176. #!ifdef PEERING
  177. # ----- enum params -----
  178. modparam("enum", "domain_suffix", ENUM_SUFFIX)
  179. #!endif
  180. # ----- tm params -----
  181. # auto-discard branches from previous serial forking leg
  182. modparam("tm", "failure_reply_mode", 3)
  183. # default retransmission timeout: 10sec
  184. modparam("tm", "fr_timer", 10000)
  185. # default invite retransmission timeout after 1xx: 120sec
  186. modparam("tm", "fr_inv_timer", 120000)
  187. #!ifdef WITH_DEBUG
  188. loadmodule "debugger.so"
  189. modparam("debugger", "mod_hash_size", 5)
  190. modparam("debugger", "mod_level_mode", 1)
  191. modparam("debugger", "mod_level", "cdp=3")
  192. modparam("debugger", "mod_level", "ims_icscf=3")
  193. #!endif
  194. # ------------------------- request routing logic -------------------
  195. # main routing logic
  196. route{
  197. #!ifdef WITH_DEBUG
  198. xlog("I-CSCF >>>>>>>>>>>>>>>>>>>> $rm $ru ($fu => $tu ($si:$sp) to $tu, $ci)\n");
  199. #!endif
  200. if !($rU =~ "\+.*") {
  201. prefix("+");
  202. }
  203. # per request initial checks
  204. route(REQINIT);
  205. if (is_method("REGISTER")) {
  206. route(register);
  207. }
  208. if (is_method("INVITE|SUBSCRIBE|MESSAGE|INFO|PUBLISH|CANCEL")) {
  209. route(initial_request);
  210. } else {
  211. # Shouldn't get here unless missconfigured (add more methods as initial) or
  212. # somebody is routing unknown messages
  213. append_to_reply("Allow: INVITE,SUBSCRIBE,MESSAGE,INFO,PUBLISH,CANCEL\r\n");
  214. send_reply("406","Initial Request Method not allowed at the I-CSCF");
  215. break;
  216. }
  217. }
  218. ######################################################################
  219. # Helper routes (Basic-Checks, NAT-Handling/RTP-Control, XML-RPC)
  220. ######################################################################
  221. # Per SIP request initial checks
  222. route[REQINIT] {
  223. $var(used) = 1 - ($stat(free_size) / $stat(total_size));
  224. xlog("L_DBG", "Mem: Total $stat(total_size), Free $stat(free_size) [$var(used)% used]\n");
  225. if ($var(used) > 95) {
  226. send_reply("503", "Server overloaded");
  227. exit;
  228. }
  229. # Trace this message
  230. #!ifdef CAPTURE_NODE
  231. sip_trace();
  232. setflag(FLT_CAPTURE);
  233. #!endif
  234. if (!mf_process_maxfwd_header("10")) {
  235. sl_send_reply("483","Too Many Hops");
  236. exit;
  237. }
  238. if(!sanity_check("1511", "7")) {
  239. xlog("Malformed SIP message from $si:$sp\n");
  240. exit;
  241. }
  242. # Check for shutdown mode:
  243. if (!has_totag() && ($sel(cfg_get.system.shutdownmode) > 0)) {
  244. send_reply("503", "Server shutting down");
  245. exit;
  246. }
  247. # Reply to OPTIONS:
  248. if (is_method("OPTIONS") && (uri==myself)) {
  249. options_reply();
  250. exit;
  251. }
  252. # Ignore Re-Transmits:
  253. if (t_lookup_request()) {
  254. exit;
  255. }
  256. if (is_method("INVITE|REGISTER")) {
  257. send_reply("100", "Trying");
  258. }
  259. }
  260. ######################################################################
  261. # XMLRPC routing
  262. ######################################################################
  263. #!ifdef WITH_XMLRPC
  264. route[XMLRPC] {
  265. if ((method=="POST" || method=="GET")
  266. #!ifdef XMLRPC_WHITELIST_1
  267. && ((src_ip == XMLRPC_WHITELIST_1)
  268. #!ifdef XMLRPC_WHITELIST_2
  269. || (src_ip == XMLRPC_WHITELIST_2)
  270. #!endif
  271. #!ifdef XMLRPC_WHITELIST_3
  272. || (src_ip == XMLRPC_WHITELIST_3)
  273. #!endif
  274. )
  275. #!endif
  276. ) {
  277. # close connection only for xmlrpclib user agents (there is a bug in
  278. # xmlrpclib: it waits for EOF before interpreting the response).
  279. if ($hdr(User-Agent) =~ "xmlrpclib")
  280. set_reply_close();
  281. set_reply_no_connect();
  282. dispatch_rpc();
  283. exit;
  284. }
  285. send_reply("403", "Forbidden");
  286. exit;
  287. }
  288. #!endif
  289. ######################################################################
  290. # Handling of REGISTER requests
  291. ######################################################################
  292. route[register]
  293. {
  294. t_set_fr(5000, 5000);
  295. #first check if we have an S-CSCF list
  296. if (I_scscf_select("0")) {
  297. #there is an S-CSCF list - no need to do a UAR
  298. t_on_reply("register_reply");
  299. t_on_failure("register_failure");
  300. if (!t_relay()) {
  301. send_reply("500","Error forwarding towards S-CSCF");
  302. }
  303. } else {
  304. #no S-CSCF list therefore must do UAR
  305. #free this from the failed I_scscf_select call
  306. I_scscf_drop();
  307. # Do an asynchronous UAR:
  308. #0=REG/DEREG; 1=REG+Capabilities
  309. if (!I_perform_user_authorization_request("REG_UAR_REPLY","0")) {
  310. send_reply("500", "Error in Request");
  311. }
  312. }
  313. exit;
  314. }
  315. route[REG_UAR_REPLY]
  316. {
  317. #xlog("$$avp(s:uaa_return_code) = $avp(s:uaa_return_code)\n");
  318. #this is async so to know status we have to check the reply avp
  319. switch ($avp(s:uaa_return_code)){
  320. case 1: #success
  321. if (I_scscf_select("0")){
  322. t_on_failure("register_failure");
  323. t_on_reply("register_reply");
  324. #now relay to appropriate SCSCF
  325. if (!t_relay()) {
  326. t_reply("500", "Error forwarding to SCSCF");
  327. }
  328. } else {#select failed
  329. I_scscf_drop();
  330. t_reply("500", "Server error on SCSCF Select (UAR)");
  331. }
  332. break;
  333. case -1: #failure
  334. xlog("L_ERR", "UAR failure - error response sent from module\n");
  335. break;
  336. case -2: #error
  337. xlog("L_ERR", "UAR error - sending error response now\n");
  338. t_reply("500", "UAR failed");
  339. break;
  340. default:
  341. xlog("L_ERR", "Unknown return code from UAR, value is [$avp(s:uaa_return_code)]\n");
  342. t_reply("500", "Unknown response code from UAR");
  343. break;
  344. }
  345. }
  346. ######################################################################
  347. # Replies to REGISTER requests,
  348. ######################################################################
  349. onreply_route[register_reply]
  350. {
  351. xlog("L_DBG", "Enter register reply block");
  352. if (!t_check_status("(408)|(480)")){
  353. if (!t_check_status("(401)")){
  354. xlog("L_DBG", "dropping scscf list on register failure");
  355. I_scscf_drop();
  356. } else {
  357. xlog("L_DBG", "This is a 401 - keep scscf list to do optimisation");
  358. }
  359. }
  360. break;
  361. }
  362. ######################################################################
  363. # Failed REGISTERs
  364. ######################################################################
  365. failure_route[register_failure]
  366. {
  367. if (t_branch_timeout() || t_check_status("([5-6][0-9][0-9])")){
  368. if (I_scscf_select("1")) {
  369. t_on_reply("register_reply");
  370. t_on_failure("register_failure");
  371. if (!t_relay()) {
  372. t_reply("500","Error forwarding towards next S-CSCF");
  373. break;
  374. }
  375. break;
  376. } else {
  377. t_reply("500", "Server error on UAR select next S-CSCF");
  378. break;
  379. }
  380. } else {
  381. if (!t_check_status("(401)")){
  382. xlog("L_DBG", "dropping scscf list on register failure");
  383. I_scscf_drop();
  384. } else {
  385. xlog("L_DBG", "This is a 401 - keep scscf list to do optimisation");
  386. }
  387. break;
  388. }
  389. }
  390. ######################################################################
  391. # Initial requests
  392. ######################################################################
  393. route[initial_request]
  394. {
  395. xlog("$$ru => $ru\n");
  396. I_perform_location_information_request("LIR_REPLY", "0");
  397. }
  398. route[LIR_REPLY] {
  399. if ($avp(lia_return_code) == 1) {
  400. if (I_scscf_select("0")) {
  401. xlog("L_DBG", "ru = $ru, du = $du\n");
  402. t_on_reply("initial_request_reply");
  403. t_on_failure("initial_request_failure");
  404. if (!t_relay()) {
  405. t_reply("500","Error forwarding towards S-CSCF");
  406. break;
  407. }
  408. break;
  409. } else {
  410. xlog("L_DBG", "dropping scscf list on initial request");
  411. I_scscf_drop();
  412. t_reply("500", "Server error on LIR select S-CSCF");
  413. break;
  414. }
  415. } else {
  416. t_reply("500", "Server error on LIR");
  417. break;
  418. }
  419. break;
  420. }
  421. ######################################################################
  422. # Replies to initial requests
  423. ######################################################################
  424. onreply_route[initial_request_reply]
  425. {
  426. xlog("L_DBG", "Enter initial request request block");
  427. if (!t_check_status("(408)")){
  428. xlog("L_DBG", "dropping scscf list on initial request reply");
  429. I_scscf_drop();
  430. }
  431. break;
  432. }
  433. ######################################################################
  434. # Failed initial requests
  435. ######################################################################
  436. failure_route[initial_request_failure]
  437. {
  438. xlog("L_DBG", "Enter initial request failure block");
  439. if (t_check_status("(408)")){
  440. xlog("L_DBG", "Got a failure for initial request");
  441. if (I_scscf_select("1")) {
  442. t_on_reply("initial_request_reply");
  443. t_on_failure("initial_request_failure");
  444. if (!t_relay()) {
  445. t_reply("500","Error forwarding towards next S-CSCF");
  446. break;
  447. }
  448. break;
  449. } else {
  450. t_reply("500", "Server error on LIR select next S-CSCF");
  451. break;
  452. }
  453. } else {
  454. xlog("L_DBG", "dropping scscf list on initial request failure");
  455. I_scscf_drop();
  456. }
  457. break;
  458. }
  459. #!ifdef PEERING
  460. ######################################################################
  461. # HSS returned "User-Unknown" on LIR request
  462. ######################################################################
  463. route[lir_term_user_unknown]
  464. {
  465. if (uri =~ "tel:.*") {
  466. # Let's check, if the number can be found in ENUM:
  467. if(!enum_query()) {
  468. # ENUM failed, send it to the PSTN-Gateway:
  469. route(PSTN);
  470. break;
  471. }
  472. # ENUM resolved to another domain
  473. if ($rd != NETWORKNAME) {
  474. t_on_reply("initial_request_reply");
  475. t_on_failure("initial_request_failure");
  476. if (!t_relay()) {
  477. t_reply("500","Error forwarding to external domain");
  478. exit;
  479. };
  480. exit;
  481. } else {
  482. t_reply("604","Does not exist anywhere - HSS User Unknown");
  483. exit;
  484. };
  485. } else {
  486. # we received a request for our domain (non-tel), but HSS said "User Unknown"
  487. if ($rd != NETWORKNAME) {
  488. t_reply("604","Does not exist anywhere - HSS User Unknown");
  489. exit;
  490. } else {
  491. # try to forward non-tel request to other domain
  492. t_on_reply("Initial_Request_reply");
  493. t_on_failure("Initial_Request_failure");
  494. if (!t_relay()) {
  495. t_reply("500","Error forwarding to external domain");
  496. exit;
  497. };
  498. exit;
  499. };
  500. };
  501. }
  502. }
  503. ######################################################################
  504. # Send calls to the PSTN-Gateways:
  505. ######################################################################
  506. route[PSTN]
  507. {
  508. t_on_failure("PSTN_failure");
  509. # Relay the request towards the PSTN-Gateway:
  510. if (!ds_select_dst("1", "4")) {
  511. send_reply("503", "Service not available");
  512. exit;
  513. }
  514. # Relay the request:
  515. if (!t_relay()) {
  516. send_reply("503", "Service not available");
  517. exit;
  518. };
  519. exit;
  520. }
  521. ######################################################################
  522. # manage failure routing cases, perform failover
  523. ######################################################################
  524. failure_route[PSTN_failure] {
  525. # Choose another gateway, in case we
  526. # - get a local generated "408"
  527. # - receive a 5xx or 6xx reply from the proxy.
  528. if (t_branch_timeout() || t_check_status("[5-6]..")) {
  529. if (ds_next_dst()) {
  530. # Do Failover in case problems:
  531. t_on_failure("PSTN_failure");
  532. # Relay the request:
  533. if (!t_relay()) {
  534. send_reply("503", "Service not available");
  535. exit;
  536. };
  537. } else {
  538. # Add a header, to indicate the phone should try again in 30 seconds.
  539. append_hf("Retry-After: 30\r\n");
  540. send_reply("503", "Service not available");
  541. }
  542. exit;
  543. }
  544. }
  545. #!endif
  546. #!ifdef FALLBACK_AUTH
  547. ######################################################################
  548. # HSS returned "User-Unknown" on UAR request,
  549. # try to send it to any S-CSCF for authentication
  550. ######################################################################
  551. route[uar_term_user_unknown]
  552. {
  553. $rd = "scscf."+NETWORKNAME;
  554. t_on_reply("register_reply");
  555. t_on_failure("register_failure");
  556. if (!t_relay()) {
  557. t_reply("500","Error forwarding towards S-CSCF");
  558. break;
  559. }
  560. break;
  561. }
  562. #!endif