Advertisement
Guest User

kamailio.cfg

a guest
Oct 19th, 2011
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.95 KB | None | 0 0
  1. ####### Defined Values #########
  2.  
  3. # - flags
  4. # FLT_ - per transaction (message) flags
  5. # FLB_ - per branch flags
  6. #!define FLT_ACC 1
  7. #!define FLT_ACCMISSED 2
  8. #!define FLT_ACCFAILED 3
  9. #!define FLT_NATS 5
  10.  
  11. #!define FLB_NATB 6
  12. #!define FLB_NATSIPPING 7
  13.  
  14. ####### Global Parameters #########
  15.  
  16. debug=2
  17. log_stderror=no
  18.  
  19. memdbg=5
  20. memlog=5
  21.  
  22. log_facility=LOG_LOCAL0
  23.  
  24. fork=yes
  25. children=4
  26.  
  27. /* port to listen to
  28. * - can be specified more than once if needed to listen on many ports */
  29. port=5060
  30.  
  31. # life time of TCP connection when there is no traffic
  32. # - a bit higher than registration expires to cope with UA behind NAT
  33. tcp_connection_lifetime=3605
  34.  
  35. ####### Modules Section ########
  36.  
  37. # set paths to location of modules (to sources or installation folders)
  38. mpath="/usr/local/lib64/kamailio/modules_k/:/usr/local/lib64/kamailio/modules/"
  39.  
  40. loadmodule "mi_fifo.so"
  41. loadmodule "kex.so"
  42. loadmodule "tm.so"
  43. loadmodule "tmx.so"
  44. loadmodule "sl.so"
  45. loadmodule "rr.so"
  46. loadmodule "pv.so"
  47. loadmodule "maxfwd.so"
  48. loadmodule "usrloc.so"
  49. loadmodule "registrar.so"
  50. loadmodule "textops.so"
  51. loadmodule "siputils.so"
  52. loadmodule "xlog.so"
  53. loadmodule "sanity.so"
  54. loadmodule "ctl.so"
  55. loadmodule "cfg_rpc.so"
  56. loadmodule "mi_rpc.so"
  57. loadmodule "acc.so"
  58. loadmodule "nathelper.so"
  59. loadmodule "rtpproxy.so"
  60. loadmodule "dispatcher.so"
  61.  
  62. # ----------------- setting module-specific parameters ---------------
  63.  
  64. # ----- mi_fifo params -----
  65. modparam("mi_fifo", "fifo_name", "/tmp/kamailio_fifo")
  66.  
  67. # ----- tm params -----
  68. # auto-discard branches from previous serial forking leg
  69. modparam("tm", "failure_reply_mode", 3)
  70. # default retransmission timeout: 30sec
  71. modparam("tm", "fr_timer", 30000)
  72. # default invite retransmission timeout after 1xx: 120sec
  73. modparam("tm", "fr_inv_timer", 120000)
  74.  
  75. # ----- rtpproxy params -----
  76. # rtpproxy -u rtpproxy:rtpproxy -l _your_public_ip_ -s udp:localhost:7722
  77. modparam("rtpproxy", "rtpproxy_sock", "udp:127.0.0.1:7722")
  78.  
  79. # ----- nathelper params -----
  80. modparam("nathelper", "natping_interval", 30)
  81. modparam("nathelper", "ping_nated_only", 1)
  82. modparam("nathelper", "sipping_bflag", FLB_NATSIPPING)
  83. modparam("nathelper", "sipping_from", "sip:pinger@kamailio.org")
  84.  
  85. # params needed for NAT traversal in other modules
  86. modparam("nathelper|registrar", "received_avp", "$avp(RECEIVED)")
  87. modparam("usrloc", "nat_bflag", FLB_NATB)
  88.  
  89. # -- dispatcher params -----
  90. modparam("dispatcher", "list_file", "/usr/local/etc/kamailio/dispatcher.list")
  91. modparam("dispatcher", "flags", 2)
  92. modparam("dispatcher", "dst_avp", "$avp(AVP_DST)")
  93. modparam("dispatcher", "grp_avp", "$avp(AVP_GRP)")
  94. modparam("dispatcher", "cnt_avp", "$avp(AVP_CNT)")
  95.  
  96. ####### Routing Logic ########
  97.  
  98. # Main SIP request routing logic
  99. # - processing of any incoming SIP request starts with this route
  100. # - note: this is the same as route { ... }
  101. request_route {
  102.  
  103. # per request initial checks
  104. route(REQINIT);
  105.  
  106. # NAT detection
  107. route(NATDETECT);
  108.  
  109. # handle requests within SIP dialogs
  110. route(WITHINDLG);
  111.  
  112. # select from first dst group by round-robin
  113. if (!ds_select_dst("1", "4"))
  114. {
  115. sl_send_reply("500", "No destination available");
  116. exit;
  117. }
  118.  
  119. t_on_failure("RTF_DISPATCH");
  120.  
  121. route(RELAY);
  122. }
  123.  
  124.  
  125. route[RELAY] {
  126.  
  127. # enable additional event routes for forwarded requests
  128. # - serial forking, RTP relaying handling, a.s.o.
  129. if (is_method("INVITE|SUBSCRIBE")) {
  130. t_on_branch("MANAGE_BRANCH");
  131. t_on_reply("MANAGE_REPLY");
  132. }
  133. if (is_method("INVITE")) {
  134. t_on_failure("MANAGE_FAILURE");
  135. }
  136.  
  137. if (!t_relay()) {
  138. sl_reply_error();
  139. }
  140. exit;
  141. }
  142.  
  143. # Per SIP request initial checks
  144. route[REQINIT] {
  145. if (!mf_process_maxfwd_header("10")) {
  146. sl_send_reply("483","Too Many Hops");
  147. exit;
  148. }
  149.  
  150. if(!sanity_check("1511", "7"))
  151. {
  152. xlog("Malformed SIP message from $si:$sp\n");
  153. exit;
  154. }
  155. }
  156.  
  157. # Handle requests within SIP dialogs
  158. route[WITHINDLG] {
  159. if (has_totag()) {
  160. # sequential request withing a dialog should
  161. # take the path determined by record-routing
  162. if (loose_route()) {
  163. if (is_method("BYE")) {
  164. setflag(FLT_ACC); # do accounting ...
  165. setflag(FLT_ACCFAILED); # ... even if the transaction fails
  166. }
  167. if ( is_method("ACK") ) {
  168. # ACK is forwarded statelessy
  169. route(NATMANAGE);
  170. }
  171. route(RELAY);
  172. } else {
  173. if ( is_method("ACK") ) {
  174. if ( t_check_trans() ) {
  175. # no loose-route, but stateful ACK;
  176. # must be an ACK after a 487
  177. # or e.g. 404 from upstream server
  178. t_relay();
  179. exit;
  180. } else {
  181. # ACK without matching transaction ... ignore and discard
  182. exit;
  183. }
  184. }
  185. sl_send_reply("404","Not here");
  186. }
  187. exit;
  188. }
  189. }
  190.  
  191. # Caller NAT detection route
  192. route[NATDETECT] {
  193. force_rport();
  194. if (nat_uac_test("19")) {
  195. if (is_method("REGISTER")) {
  196. fix_nated_register();
  197. } else {
  198. fix_nated_contact();
  199. }
  200. setflag(FLT_NATS);
  201. }
  202. return;
  203. }
  204.  
  205. # RTPProxy control
  206. route[NATMANAGE] {
  207. if (is_request()) {
  208. if(has_totag()) {
  209. if(check_route_param("nat=yes")) {
  210. setbflag(FLB_NATB);
  211. }
  212. }
  213. }
  214. if (!(isflagset(FLT_NATS) || isbflagset(FLB_NATB)))
  215. return;
  216.  
  217. rtpproxy_manage();
  218.  
  219. if (is_request()) {
  220. if (!has_totag()) {
  221. add_rr_param(";nat=yes");
  222. }
  223. }
  224. if (is_reply()) {
  225. if(isbflagset(FLB_NATB)) {
  226. fix_nated_contact();
  227. }
  228. }
  229. return;
  230. }
  231.  
  232. # manage outgoing branches
  233. branch_route[MANAGE_BRANCH] {
  234. xdbg("new branch [$T_branch_idx] to $ru\n");
  235. route(NATMANAGE);
  236. }
  237.  
  238. # manage incoming replies
  239. onreply_route[MANAGE_REPLY] {
  240. xdbg("incoming reply\n");
  241. if(status=~"[12][0-9][0-9]")
  242. route(NATMANAGE);
  243. }
  244.  
  245. # manage failure routing cases
  246. failure_route[MANAGE_FAILURE] {
  247. route(NATMANAGE);
  248.  
  249. if (t_is_canceled()) {
  250. exit;
  251. }
  252. }
  253.  
  254. # dispatcher failure routing block
  255. failure_route[RTF_DISPATCH] {
  256. if (t_is_canceled()) {
  257. exit;
  258. }
  259. # select next destination only for local timeout
  260. if (t_branch_timeout() && !t_branch_replied())
  261. {
  262. if(ds_next_dst())
  263. {
  264. t_on_failure("RTF_DISPATCH");
  265. t_relay();
  266. exit;
  267. }
  268. }
  269. }
  270.  
  271.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement