edge.cfg 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. #!KAMAILIO
  2. #
  3. # Edge proxy configuration
  4. #
  5. #!substdef "!REGISTRAR_IP!a.b.c.d!g"
  6. #!substdef "!REGISTRAR_PORT!5060!g"
  7. #!substdef "!FLOW_TIMER!20!g"
  8. ####### Global Parameters #########
  9. debug=2
  10. log_stderror=no
  11. log_facility=LOG_LOCAL0
  12. fork=yes
  13. children=4
  14. alias="example.com"
  15. mpath="/usr/lib64/kamailio/modules"
  16. tcp_connection_lifetime=30 # FLOW_TIMER + 10
  17. force_rport=yes
  18. ####### Modules Section ########
  19. loadmodule "tm.so"
  20. loadmodule "sl.so"
  21. loadmodule "outbound.so"
  22. loadmodule "rr.so"
  23. loadmodule "path.so"
  24. loadmodule "pv.so"
  25. loadmodule "maxfwd.so"
  26. loadmodule "xlog.so"
  27. loadmodule "sanity.so"
  28. loadmodule "ctl.so"
  29. loadmodule "mi_rpc.so"
  30. loadmodule "mi_fifo.so"
  31. loadmodule "textops.so"
  32. loadmodule "siputils.so"
  33. loadmodule "stun.so"
  34. # ----------------- setting module-specific parameters ---------------
  35. # ----- mi_fifo params -----
  36. modparam("mi_fifo", "fifo_name", "/tmp/kamailio_fifo")
  37. # ----- tm params -----
  38. modparam("tm", "failure_reply_mode", 3)
  39. # ----- rr params -----
  40. modparam("rr", "append_fromtag", 0)
  41. ####### Routing Logic ########
  42. request_route {
  43. route(REQINIT);
  44. if (is_method("CANCEL")) {
  45. if (t_check_trans()) {
  46. route(RELAY);
  47. }
  48. exit;
  49. }
  50. route(WITHINDLG);
  51. t_check_trans();
  52. if (is_method("REGISTER")) {
  53. remove_hf("Route");
  54. add_path();
  55. $du = "sip:REGISTRAR_IP:REGISTRAR_PORT";
  56. } else {
  57. if (is_method("INVITE|SUBSCRIBE"))
  58. record_route();
  59. if (@via[2] == "") {
  60. # From client so route to registrar...
  61. if ($rU == $null) {
  62. sl_send_reply("484", "Address Incomplete");
  63. exit;
  64. }
  65. remove_hf("Route");
  66. $du = "sip:REGISTRAR_IP:REGISTRAR_PORT";
  67. } else {
  68. # From registrar so route using "Route:" headers...
  69. if (!loose_route()) {
  70. switch($rc) {
  71. case -2:
  72. sl_send_reply("403", "Forbidden");
  73. exit;
  74. default:
  75. xlog("L_ERR", "in request_route\n");
  76. sl_reply_error();
  77. exit;
  78. }
  79. }
  80. t_on_failure("FAIL_OUTBOUND");
  81. }
  82. }
  83. route(RELAY);
  84. }
  85. route[RELAY] {
  86. if (!t_relay()) {
  87. sl_reply_error();
  88. }
  89. exit;
  90. }
  91. route[REQINIT] {
  92. if (!mf_process_maxfwd_header("10")) {
  93. sl_send_reply("483","Too Many Hops");
  94. exit;
  95. }
  96. if(!sanity_check("1511", "7"))
  97. {
  98. xlog("Malformed SIP message from $si:$sp\n");
  99. exit;
  100. }
  101. }
  102. route[WITHINDLG] {
  103. if (has_totag()) {
  104. if (!loose_route()) {
  105. switch($rc) {
  106. case -2:
  107. sl_send_reply("403", "Forbidden");
  108. exit;
  109. default:
  110. if (is_method("ACK")) {
  111. if ( t_check_trans() ) {
  112. route(RELAY);
  113. exit;
  114. } else {
  115. exit;
  116. }
  117. }
  118. sl_send_reply("404","Not Found");
  119. }
  120. } else {
  121. if (is_method("NOTIFY")) {
  122. record_route();
  123. }
  124. route(RELAY);
  125. }
  126. exit;
  127. }
  128. }
  129. onreply_route {
  130. if (!t_check_trans()) {
  131. drop;
  132. }
  133. if ($rm == "REGISTER" && $rs >= 200 && $rs <= 299) {
  134. remove_hf("Flow-Timer");
  135. if ($(hdr(Require)[*])=~"outbound")
  136. insert_hf("Flow-Timer: FLOW_TIMER\r\n", "Call-ID");
  137. }
  138. }
  139. failure_route[FAIL_OUTBOUND] {
  140. if (t_branch_timeout() || !t_branch_replied()) {
  141. send_reply("430", "Flow Failed");
  142. }
  143. }