kamailio-minimal-proxy.cfg 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. #!KAMAILIO
  2. #
  3. # Kamailio (OpenSER) SIP Server v5.2 - default configuration script
  4. # - web: https://www.kamailio.org
  5. # - git: https://github.com/kamailio/kamailio
  6. #
  7. # Direct your questions about this file to: <[email protected]>
  8. #
  9. # Refer to the Core CookBook at https://www.kamailio.org/wiki/
  10. # for an explanation of possible statements, functions and parameters.
  11. #
  12. ####### Defined Values #########
  13. #!define MULTIDOMAIN 0
  14. # - flags
  15. # FLT_ - per transaction (message) flags
  16. # FLB_ - per branch flags
  17. #!define FLT_ACC 1
  18. #!define FLT_ACCMISSED 2
  19. #!define FLT_ACCFAILED 3
  20. #!define FLT_NATS 5
  21. #!define FLB_NATB 6
  22. #!define FLB_NATSIPPING 7
  23. ####### Global Parameters #########
  24. ### LOG Levels: 3=DBG, 2=INFO, 1=NOTICE, 0=WARN, -1=ERR
  25. debug=2
  26. log_stderror=no
  27. memdbg=5
  28. memlog=5
  29. log_facility=LOG_LOCAL0
  30. log_prefix="{$mt $hdr(CSeq) $ci} "
  31. /* number of SIP routing processes */
  32. children=2
  33. /* uncomment the next line to disable TCP (default on) */
  34. # disable_tcp=yes
  35. /* uncomment the next line to disable the auto discovery of local aliases
  36. * based on reverse DNS on IPs (default on) */
  37. # auto_aliases=no
  38. /* add local domain aliases */
  39. # alias="sip.mydomain.com"
  40. /* listen addresses */
  41. # listen=udp:127.0.0.1:5060
  42. ####### Custom Parameters #########
  43. /* These parameters can be modified runtime via RPC interface
  44. * - see the documentation of 'cfg_rpc' module.
  45. *
  46. * Format: group.id = value 'desc' description
  47. * Access: $sel(cfg_get.group.id) or @cfg_get.group.id */
  48. ####### Modules Section ########
  49. /* set paths to location of modules */
  50. loadmodule "jsonrpcs.so"
  51. loadmodule "kex.so"
  52. loadmodule "corex.so"
  53. loadmodule "tm.so"
  54. loadmodule "tmx.so"
  55. loadmodule "sl.so"
  56. loadmodule "rr.so"
  57. loadmodule "pv.so"
  58. loadmodule "maxfwd.so"
  59. loadmodule "textops.so"
  60. loadmodule "siputils.so"
  61. loadmodule "xlog.so"
  62. loadmodule "sanity.so"
  63. loadmodule "ctl.so"
  64. loadmodule "cfg_rpc.so"
  65. loadmodule "acc.so"
  66. loadmodule "counters.so"
  67. # ----------------- setting module-specific parameters ---------------
  68. # ----- jsonrpcs params -----
  69. modparam("jsonrpcs", "pretty_format", 1)
  70. /* set the path to RPC fifo control file */
  71. # modparam("jsonrpcs", "fifo_name", "/var/run/kamailio/kamailio_rpc.fifo")
  72. /* set the path to RPC unix socket control file */
  73. # modparam("jsonrpcs", "dgram_socket", "/var/run/kamailio/kamailio_rpc.sock")
  74. # ----- ctl params -----
  75. /* set the path to RPC unix socket control file */
  76. # modparam("ctl", "binrpc", "unix:/var/run/kamailio/kamailio_ctl")
  77. # ----- tm params -----
  78. # auto-discard branches from previous serial forking leg
  79. modparam("tm", "failure_reply_mode", 3)
  80. # default retransmission timeout: 30sec
  81. modparam("tm", "fr_timer", 30000)
  82. # default invite retransmission timeout after 1xx: 120sec
  83. modparam("tm", "fr_inv_timer", 120000)
  84. # ----- rr params -----
  85. # set next param to 1 to add value to ;lr param (helps with some UAs)
  86. modparam("rr", "enable_full_lr", 0)
  87. # do not append from tag to the RR (no need for this script)
  88. modparam("rr", "append_fromtag", 0)
  89. # ----- acc params -----
  90. /* what special events should be accounted ? */
  91. modparam("acc", "early_media", 0)
  92. modparam("acc", "report_ack", 0)
  93. modparam("acc", "report_cancels", 0)
  94. /* by default ww do not adjust the direct of the sequential requests.
  95. * if you enable this parameter, be sure the enable "append_fromtag"
  96. * in "rr" module */
  97. modparam("acc", "detect_direction", 0)
  98. /* account triggers (flags) */
  99. modparam("acc", "log_flag", FLT_ACC)
  100. modparam("acc", "log_missed_flag", FLT_ACCMISSED)
  101. modparam("acc", "log_extra",
  102. "src_user=$fU;src_domain=$fd;src_ip=$si;"
  103. "dst_ouser=$tU;dst_user=$rU;dst_domain=$rd")
  104. modparam("acc", "failed_transaction_flag", FLT_ACCFAILED)
  105. ####### Routing Logic ########
  106. /* Main SIP request routing logic
  107. * - processing of any incoming SIP request starts with this route
  108. * - note: this is the same as route { ... } */
  109. request_route {
  110. # per request initial checks
  111. route(REQINIT);
  112. # CANCEL processing
  113. if (is_method("CANCEL")) {
  114. if (t_check_trans()) {
  115. route(RELAY);
  116. }
  117. exit;
  118. }
  119. # handle retransmissions
  120. if (!is_method("ACK")) {
  121. if(t_precheck_trans()) {
  122. t_check_trans();
  123. exit;
  124. }
  125. t_check_trans();
  126. }
  127. # handle requests within SIP dialogs
  128. route(WITHINDLG);
  129. ### only initial requests (no To tag)
  130. # record routing for dialog forming requests (in case they are routed)
  131. # - remove preloaded route headers
  132. remove_hf("Route");
  133. if (is_method("INVITE|SUBSCRIBE")) {
  134. record_route();
  135. }
  136. # account only INVITEs
  137. if (is_method("INVITE")) {
  138. setflag(FLT_ACC); # do accounting
  139. }
  140. if ($rU==$null) {
  141. # request with no Username in RURI
  142. sl_send_reply("484","Address Incomplete");
  143. exit;
  144. }
  145. # update $du to set the destination address for proxying
  146. $du = "sip:" + $rd + ":9";
  147. route(RELAY);
  148. exit;
  149. }
  150. # Wrapper for relaying requests
  151. route[RELAY] {
  152. # enable additional event routes for forwarded requests
  153. # - serial forking, RTP relaying handling, a.s.o.
  154. if (is_method("INVITE|BYE|SUBSCRIBE|UPDATE")) {
  155. if(!t_is_set("branch_route")) t_on_branch("MANAGE_BRANCH");
  156. }
  157. if (is_method("INVITE|SUBSCRIBE|UPDATE")) {
  158. if(!t_is_set("onreply_route")) t_on_reply("MANAGE_REPLY");
  159. }
  160. if (is_method("INVITE")) {
  161. if(!t_is_set("failure_route")) t_on_failure("MANAGE_FAILURE");
  162. }
  163. if (!t_relay()) {
  164. sl_reply_error();
  165. }
  166. exit;
  167. }
  168. # Per SIP request initial checks
  169. route[REQINIT] {
  170. if($ua =~ "friendly-scanner|sipcli|VaxSIPUserAgent") {
  171. # silent drop for scanners - uncomment next line if want to reply
  172. # sl_send_reply("200", "OK");
  173. exit;
  174. }
  175. if (!mf_process_maxfwd_header("10")) {
  176. sl_send_reply("483","Too Many Hops");
  177. exit;
  178. }
  179. if(is_method("OPTIONS") && uri==myself && $rU==$null) {
  180. sl_send_reply("200","Keepalive");
  181. exit;
  182. }
  183. if(!sanity_check("1511", "7")) {
  184. xlog("Malformed SIP message from $si:$sp\n");
  185. exit;
  186. }
  187. }
  188. # Handle requests within SIP dialogs
  189. route[WITHINDLG] {
  190. if (!has_totag()) return;
  191. # sequential request withing a dialog should
  192. # take the path determined by record-routing
  193. if (loose_route()) {
  194. if (is_method("BYE")) {
  195. setflag(FLT_ACC); # do accounting ...
  196. setflag(FLT_ACCFAILED); # ... even if the transaction fails
  197. } else if ( is_method("NOTIFY") ) {
  198. # Add Record-Route for in-dialog NOTIFY as per RFC 6665.
  199. record_route();
  200. }
  201. route(RELAY);
  202. exit;
  203. }
  204. if ( is_method("ACK") ) {
  205. if ( t_check_trans() ) {
  206. # no loose-route, but stateful ACK;
  207. # must be an ACK after a 487
  208. # or e.g. 404 from upstream server
  209. route(RELAY);
  210. exit;
  211. } else {
  212. # ACK without matching transaction ... ignore and discard
  213. exit;
  214. }
  215. }
  216. sl_send_reply("404","Not here");
  217. exit;
  218. }
  219. # Manage outgoing branches
  220. branch_route[MANAGE_BRANCH] {
  221. xdbg("new branch [$T_branch_idx] to $ru\n");
  222. }
  223. # Manage incoming replies
  224. onreply_route[MANAGE_REPLY] {
  225. xdbg("incoming reply\n");
  226. }
  227. # Manage failure routing cases
  228. failure_route[MANAGE_FAILURE] {
  229. if (t_is_canceled()) exit;
  230. }