Advertisement
Guest User

Untitled

a guest
Feb 3rd, 2014
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.44 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. # Enable debugging only when kamailio is mading boo-boo
  17. ### LOG Levels: 3=DBG, 2=INFO, 1=NOTICE, 0=WARN, -1=ERR
  18. debug=3
  19. log_stderror=no
  20.  
  21. memdbg=5
  22. memlog=5
  23.  
  24. log_facility=LOG_LOCAL0
  25.  
  26. fork=yes
  27. children=8
  28.  
  29. /* uncomment the next line to disable TCP (default on) */
  30. disable_tcp=yes
  31.  
  32. /* uncomment the next line to disable the auto discovery of local aliases
  33. based on reverse DNS on IPs (default on) */
  34. auto_aliases=no
  35.  
  36. /* add local domain aliases */
  37. #alias="kamaz.ikatele.com"
  38.  
  39. /* uncomment and configure the following line if you want Kamailio to
  40. bind on a specific interface/port/proto (default bind on all available) */
  41.  
  42. #listen=udp:50.0.0.1:5060 advertise 194.190.8.171:5060
  43. #listen=udp:194.190.8.171:5060 advertise 50.0.0.1:5060
  44.  
  45. listen=udp:194.190.8.171
  46. listen=udp:50.0.0.1
  47.  
  48. dns=no
  49. rev_dns=no
  50. check_via=yes
  51.  
  52. /* port to listen to
  53. * - can be specified more than once if needed to listen on many ports */
  54. port=5060
  55.  
  56. mhomed=1
  57.  
  58. ####### Modules Section ########
  59.  
  60. # set paths to location of modules (to sources or installation folders)
  61. mpath="/usr/lib64/kamailio/modules/"
  62.  
  63.  
  64. loadmodule "mi_fifo.so"
  65. loadmodule "kex.so"
  66. loadmodule "tm.so"
  67. loadmodule "tmx.so"
  68. loadmodule "sl.so"
  69. loadmodule "rr.so"
  70. loadmodule "pv.so"
  71. loadmodule "maxfwd.so"
  72. loadmodule "usrloc.so"
  73. loadmodule "registrar.so"
  74. loadmodule "textops.so"
  75. loadmodule "siputils.so"
  76. loadmodule "xlog.so"
  77. loadmodule "sanity.so"
  78. loadmodule "ctl.so"
  79. loadmodule "cfg_rpc.so"
  80. loadmodule "mi_rpc.so"
  81. loadmodule "acc.so"
  82.  
  83.  
  84. loadmodule "nathelper.so"
  85. loadmodule "rtpproxy.so"
  86.  
  87. #loadmodule "topoh.so"
  88. #modparam("topoh", "mask_key", "balalayka")
  89. #modparam("topoh", "mask_ip", "50.0.0.1")
  90.  
  91. # ----------------- setting module-specific parameters ---------------
  92.  
  93.  
  94. # ----- mi_fifo params -----
  95. modparam("mi_fifo", "fifo_name", "/tmp/kamailio_fifo")
  96.  
  97.  
  98. # ----- tm params -----
  99. # auto-discard branches from previous serial forking leg
  100. modparam("tm", "failure_reply_mode", 3)
  101. # default retransmission timeout: 30sec
  102. modparam("tm", "fr_timer", 3000)
  103. # default invite retransmission timeout after 1xx: 120sec
  104. modparam("tm", "fr_inv_timer", 12000)
  105.  
  106.  
  107. # ----- rr params -----
  108. # add value to ;lr param to cope with most of the UAs
  109. modparam("rr", "enable_full_lr", 1)
  110. # do not append from tag to the RR (no need for this script)
  111. modparam("rr", "append_fromtag", 1)
  112.  
  113.  
  114.  
  115. # ----- rtpproxy params -----
  116. modparam("rtpproxy", "rtpproxy_sock", "udp:127.0.0.1:7722")
  117.  
  118. # ----- nathelper params -----
  119. modparam("nathelper", "natping_interval", 30)
  120. modparam("nathelper", "ping_nated_only", 1)
  121. modparam("nathelper", "sipping_bflag", FLB_NATSIPPING)
  122. modparam("nathelper", "sipping_from", "sip:pinger@194.190.8.171")
  123.  
  124. # params needed for NAT traversal in other modules
  125. modparam("nathelper", "received_avp", "$avp(RECEIVED)")
  126. modparam("usrloc", "nat_bflag", FLB_NATB)
  127.  
  128.  
  129.  
  130. ####### Routing Logic ########
  131.  
  132.  
  133. # Main SIP request routing logic
  134. # - processing of any incoming SIP request starts with this route
  135. # - note: this is the same as route { ... }
  136.  
  137. route {
  138.  
  139. # per request initial checks
  140. route(REQINIT);
  141.  
  142. # NAT detection
  143. xlog("L_NOTICE","$rm from $fu (IP:$si:$sp) Main Route before ---NAT---\n");
  144.  
  145. route(NATDETECT);
  146.  
  147. xlog("L_NOTICE","$rm from $fu (IP:$si:$sp) in Route[NATDETECT] fix_nat-register\n");
  148.  
  149. # CANCEL processing
  150. if (is_method("CANCEL"))
  151. {
  152. if (t_check_trans()) {
  153. route(RELAY);
  154. }
  155. exit;
  156. }
  157.  
  158. # handle requests within SIP dialogs
  159. route(WITHINDLG);
  160.  
  161. ### only initial requests (no To tag)
  162.  
  163. t_check_trans();
  164.  
  165. # record routing for dialog forming requests (in case they are routed)
  166. # - remove preloaded route headers
  167. remove_hf("Route");
  168. if (is_method("INVITE|SUBSCRIBE"))
  169. record_route();
  170.  
  171. # account only INVITEs
  172. if (is_method("INVITE"))
  173. {
  174. setflag(FLT_ACC); # do accounting
  175. }
  176.  
  177. # dispatch requests to foreign domains
  178. route(SIPOUT);
  179.  
  180. # handle registrations
  181. route(REGISTRAR);
  182.  
  183. if ($rU==$null)
  184. {
  185. # request with no Username in RURI
  186. sl_send_reply("484","Address Incomplete");
  187. exit;
  188. }
  189.  
  190. route(RELAY);
  191.  
  192. }
  193.  
  194. # Per SIP request initial checks
  195. route[REQINIT] {
  196. if (!mf_process_maxfwd_header("20")) {
  197. xlog("L_NOTICE","$rm from $fu (IP:$si:$sp) in MAX FDW HEADERS ALARMO\n");
  198.  
  199. sl_send_reply("483","Too Many Hops");
  200. exit;
  201. }
  202.  
  203. if(!sanity_check("1511", "7"))
  204. {
  205. xlog("Malformed SIP message from $si:$sp\n");
  206. exit;
  207. }
  208. }
  209.  
  210.  
  211. # Caller NAT detection route
  212. route[NATDETECT] {
  213. force_rport();
  214. if (nat_uac_test("19")) {
  215. if (is_method("REGISTER")) {
  216. fix_nated_register();
  217. } else {
  218. if(is_first_hop())
  219. set_contact_alias();
  220. }
  221. setflag(FLT_NATS);
  222.  
  223. }
  224. return;
  225. }
  226.  
  227. # Handle requests within SIP dialogs
  228. route[WITHINDLG] {
  229. if (has_totag()) {
  230. # sequential request withing a dialog should
  231. # take the path determined by record-routing
  232. if (loose_route()) {
  233. route(DLGURI);
  234. if (is_method("BYE")) {
  235. setflag(FLT_ACC); # do accounting ...
  236. setflag(FLT_ACCFAILED); # ... even if the transaction fails
  237. }
  238. else if ( is_method("ACK") ) {
  239. # ACK is forwarded statelessy
  240. route(NATMANAGE);
  241. }
  242. else if ( is_method("NOTIFY") ) {
  243. # Add Record-Route for in-dialog NOTIFY as per RFC 6665.
  244. record_route();
  245. }
  246. route(RELAY);
  247. } else {
  248. if ( is_method("ACK") ) {
  249. if ( t_check_trans() ) {
  250. # no loose-route, but stateful ACK;
  251. # must be an ACK after a 487
  252. # or e.g. 404 from upstream server
  253. route(RELAY);
  254. exit;
  255. } else {
  256. xlog("L_NOTICE","ACK without matching transaction ... ignore and discard\n");
  257. # ACK without matching transaction ... ignore and discard
  258. exit;
  259. }
  260. }
  261. sl_send_reply("404","Not here");
  262. }
  263. exit;
  264. }
  265. }
  266.  
  267.  
  268. # Routing to foreign domains
  269. route[SIPOUT] {
  270. if (!uri==myself)
  271. {
  272. append_hf("P-hint: outbound\r\n");
  273. route(RELAY);
  274. }
  275. }
  276. # Handle SIP registrations
  277. route[REGISTRAR] {
  278. if (is_method("REGISTER"))
  279. {
  280. # if(isflagset(FLT_NATS))
  281. # {
  282. # setbflag(FLB_NATB);
  283. # # uncomment next line to do SIP NAT pinging
  284. # xlog("L_NOTICE","--------------------- SIP NAT PINGING --------------------------------------\n");
  285. # setbflag(FLB_NATSIPPING);
  286. # }
  287. # if (!save("location"))
  288. # sl_reply_error();
  289. # xlog("L_NOTICE","--------------------- SL REPLY ERROR --------------------------------------\n");
  290.  
  291. if( t_check_trans() )
  292. {
  293. xlog("L_NOTICE","Transaction already exist, forwarding\n");
  294. }
  295. else
  296. {
  297. xlog("L_NOTICE","New transaction upcoming, creating\n");
  298.  
  299. # forward("50.0.0.10");
  300. # save("sip:50.0.0.10","0x02");
  301. t_relay_to_udp("50.0.0.10", "5060");
  302. exit;
  303. }
  304. exit;
  305. }
  306. }
  307.  
  308.  
  309.  
  310. route[RELAY] {
  311. # enable additional event routes for forwarded requests
  312. # - serial forking, RTP relaying handling, a.s.o.
  313. xlog("L_NOTICE","Default routing block raised!\n");
  314. if (is_method("INVITE|BYE|SUBSCRIBE|UPDATE")) {
  315. if(!t_is_set("branch_route")) t_on_branch("MANAGE_BRANCH");
  316. }
  317. if (is_method("INVITE|SUBSCRIBE|UPDATE")) {
  318. if(!t_is_set("onreply_route")) t_on_reply("MANAGE_REPLY");
  319. }
  320. if (is_method("INVITE")) {
  321. if(!t_is_set("failure_route")) t_on_failure("MANAGE_FAILURE");
  322. }
  323.  
  324. if (!t_relay()) {
  325. sl_reply_error();
  326. }
  327. exit;
  328. }
  329.  
  330.  
  331. # RTPProxy control
  332. route[NATMANAGE] {
  333. if (is_request()) {
  334. if(has_totag()) {
  335. if(check_route_param("nat=yes")) {
  336. xlog("L_NOTICE","------------------------------------ SETBFLAG ----------------------------\n");
  337. setbflag(FLB_NATB);
  338. }
  339. }
  340. }
  341. if (!(isflagset(FLT_NATS) || isbflagset(FLB_NATB)))
  342. return;
  343.  
  344. rtpproxy_manage();
  345.  
  346. if (is_request()) {
  347. if (!has_totag()) {
  348. if(t_is_branch_route()) {
  349. xlog("L_NOTICE","------------------------------------ ADD RR PARAM NAT YES ----------------------------\n");
  350. add_rr_param(";nat=yes");
  351. }
  352. }
  353. }
  354. if (is_reply()) {
  355. if(isbflagset(FLB_NATB)) {
  356. if(is_first_hop())
  357. xlog("L_NOTICE","------------------------------------ IS FIRST HOP SRT CONACT ALIAS ----------------------------\n");
  358. set_contact_alias();
  359. }
  360.  
  361. xlog("L_NOTICE","$rm from $fu (IP:$si:$sp) in route[NATMANAGE] RTPproxy with EI Flags\n");
  362.  
  363. }
  364. return;
  365. }
  366.  
  367. # URI update for dialog requests
  368. route[DLGURI] {
  369. if(!isdsturiset()) {
  370. handle_ruri_alias();
  371.  
  372. xlog("L_NOTICE","$rm from $fu (IP:$si:$sp) in route[DLGURI] RTPproxy with EI Flags\n");
  373.  
  374. }
  375. return;
  376. }
  377.  
  378. # manage outgoing branches
  379. branch_route[MANAGE_BRANCH] {
  380. xlog("L_NOTICE","$rm from $fu (IP:$si:$sp) in MANAGE_BRANCH\n");
  381. xdbg("new branch [$T_branch_idx] to $ru\n");
  382. route(NATMANAGE);
  383. }
  384.  
  385. # manage incoming replies
  386. onreply_route[MANAGE_REPLY] {
  387. xlog("L_NOTICE","$rm from $fu (IP:$si:$sp) in MANAGE_REPLY\n");
  388. xdbg("incoming reply\n");
  389. if(status=~"[12][0-9][0-9]")
  390. route(NATMANAGE);
  391. }
  392.  
  393. # manage failure routing cases
  394. failure_route[MANAGE_FAILURE] {
  395. xlog("L_NOTICE","$rm from $fu (IP:$si:$sp) in MANAGE_FAILURE\n");
  396. route(NATMANAGE);
  397.  
  398. if (t_is_canceled()) {
  399. exit;
  400. }
  401. }
  402.  
  403.  
  404. route[DEBUG] {
  405. if (method==("PUBLISH|SUBSCRIBE|REGISTER|OPTIONS")) {
  406. return;
  407. }
  408. xlog("[$mi] Received SIP Message (method: $rm) ($ml bytes) to $Ri:$Rp from $si:$sp:\n$mb\n");
  409. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement