Advertisement
Guest User

Untitled

a guest
Feb 4th, 2014
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 17.46 KB | None | 0 0
  1.  
  2.  
  3. ####### Defined Values #########
  4.  
  5. # - flags
  6. # FLT_ - per transaction (message) flags
  7. # FLB_ - per branch flags
  8. #!define FLT_ACC 1
  9. #!define FLT_ACCMISSED 2
  10. #!define FLT_ACCFAILED 3
  11. #!define FLT_NATS 5
  12.  
  13. #!define FLB_NATB 6
  14. #!define FLB_NATSIPPING 7
  15.  
  16. ####### Global Parameters #########
  17.  
  18. ### LOG Levels: 3=DBG, 2=INFO, 1=NOTICE, 0=WARN, -1=ERR
  19. debug=3
  20. log_stderror=no
  21.  
  22. memdbg=5
  23. memlog=5
  24.  
  25. log_facility=LOG_LOCAL0
  26.  
  27. fork=yes
  28. children=8
  29.  
  30. /* uncomment the next line to disable TCP (default on) */
  31. disable_tcp=yes
  32.  
  33. /* uncomment the next line to disable the auto discovery of local aliases
  34. based on reverse DNS on IPs (default on) */
  35. auto_aliases=no
  36.  
  37. /* add local domain aliases */
  38. #alias=50.0.0.1
  39.  
  40. /* uncomment and configure the following line if you want Kamailio to
  41. bind on a specific interface/port/proto (default bind on all available) */
  42.  
  43. #listen=udp:50.0.0.1:5060 advertise 194.190.8.171:5060
  44. #listen=udp:194.190.8.171:5060 advertise 50.0.0.1:5060
  45.  
  46. listen=udp:194.190.8.171
  47. listen=udp:50.0.0.1
  48.  
  49. dns=no
  50. rev_dns=no
  51. check_via=yes
  52.  
  53. /* port to listen to
  54. * - can be specified more than once if needed to listen on many ports */
  55. port=5060
  56.  
  57. mhomed=1
  58.  
  59. # life time of TCP connection when there is no traffic
  60. # - a bit higher than registration expires to cope with UA behind NAT
  61. tcp_connection_lifetime=300
  62.  
  63. ####### Custom Parameters #########
  64.  
  65. asterisk.bindip = "50.0.0.10" desc "Asterisk IP Address"
  66. asterisk.bindport = "5060" desc "Asterisk Port"
  67. kamailio.bindip = "50.0.0.1" desc "Kamailio IP Address"
  68. kamailio.bindport = "5060" desc "Kamailio Port"
  69.  
  70. ####### Modules Section ########
  71.  
  72. # set paths to location of modules (to sources or installation folders)
  73. mpath="/usr/lib64/kamailio/modules/"
  74.  
  75.  
  76.  
  77. loadmodule "mi_fifo.so"
  78. loadmodule "kex.so"
  79. loadmodule "tm.so"
  80. loadmodule "tmx.so"
  81. loadmodule "sl.so"
  82. loadmodule "rr.so"
  83. loadmodule "pv.so"
  84. loadmodule "maxfwd.so"
  85. loadmodule "usrloc.so"
  86. loadmodule "registrar.so"
  87. loadmodule "textops.so"
  88. loadmodule "siputils.so"
  89. loadmodule "xlog.so"
  90. loadmodule "sanity.so"
  91. loadmodule "ctl.so"
  92. loadmodule "cfg_rpc.so"
  93. loadmodule "mi_rpc.so"
  94. loadmodule "acc.so"
  95.  
  96. loadmodule "nathelper.so"
  97. loadmodule "rtpproxy.so"
  98.  
  99. loadmodule "dialog.so"
  100.  
  101. modparam("dialog", "enable_stats", 1)
  102. modparam("dialog", "dlg_flag", 4)
  103.  
  104.  
  105. #loadmodule "path.so"
  106.  
  107. # -- path params --
  108. #modparam("path", "use_received", 1)
  109.  
  110. #loadmodule "topoh.so"
  111. #modparam("topoh", "mask_key", "balalayka")
  112. #modparam("topoh", "mask_ip", "50.0.0.1")
  113.  
  114. # ----------------- setting module-specific parameters ---------------
  115.  
  116.  
  117. # ----- mi_fifo params -----
  118. modparam("mi_fifo", "fifo_name", "/tmp/kamailio_fifo")
  119.  
  120.  
  121. # ----- tm params -----
  122. # auto-discard branches from previous serial forking leg
  123. modparam("tm", "failure_reply_mode", 3)
  124. # default retransmission timeout: 30sec
  125. modparam("tm", "fr_timer", 30000)
  126. # default invite retransmission timeout after 1xx: 120sec
  127. modparam("tm", "fr_inv_timer", 120000)
  128. modparam("tm", "reparse_on_dns_failover", 0)
  129.  
  130.  
  131. # ----- rr params -----
  132. # add value to ;lr param to cope with most of the UAs
  133. modparam("rr", "enable_full_lr", 1)
  134. # do not append from tag to the RR (no need for this script)
  135. modparam("rr", "append_fromtag", 1)
  136.  
  137.  
  138. # ----- acc params -----
  139. /* what special events should be accounted ? */
  140. modparam("acc", "early_media", 0)
  141. modparam("acc", "report_ack", 0)
  142. modparam("acc", "report_cancels", 0)
  143. /* by default ww do not adjust the direct of the sequential requests.
  144. if you enable this parameter, be sure the enable "append_fromtag"
  145. in "rr" module */
  146. modparam("acc", "detect_direction", 0)
  147. /* account triggers (flags) */
  148. modparam("acc", "log_flag", FLT_ACC)
  149. modparam("acc", "log_missed_flag", FLT_ACCMISSED)
  150. modparam("acc", "log_extra",
  151. "src_user=$fU;src_domain=$fd;src_ip=$si;"
  152. "dst_ouser=$tU;dst_user=$rU;dst_domain=$rd")
  153. modparam("acc", "failed_transaction_flag", FLT_ACCFAILED)
  154.  
  155.  
  156.  
  157. # ----- rtpproxy params -----
  158. modparam("rtpproxy", "rtpproxy_sock", "udp:127.0.0.1:7722")
  159.  
  160. # ----- nathelper params -----
  161. modparam("nathelper", "natping_interval", 30)
  162. modparam("nathelper", "ping_nated_only", 1)
  163. modparam("nathelper", "sipping_bflag", FLB_NATSIPPING)
  164. modparam("nathelper", "sipping_from", "sip:pinger@194.190.8.171")
  165.  
  166. # params needed for NAT traversal in other modules
  167. modparam("nathelper|registrar", "received_avp", "$avp(RECEIVED)")
  168. modparam("usrloc", "nat_bflag", FLB_NATB)
  169.  
  170.  
  171. ####################################################################################################
  172. #################### in the end of the route u meet UCHIBUCHI. just ignore him. ####################
  173. ####################################################################################################
  174.  
  175.  
  176. # Main SIP request routing logic
  177. # - processing of any incoming SIP request starts with this route
  178. # - note: this is the same as route { ... }
  179. route {
  180.  
  181. # per request initial checks
  182. route(REQINIT);
  183.  
  184. # NAT detection
  185. route(NATDETECT);
  186.  
  187. # CANCEL processing
  188. if (is_method("CANCEL"))
  189. {
  190. if (t_check_trans()) {
  191. route(RELAY);
  192. }
  193. exit;
  194. }
  195.  
  196. # handle requests within SIP dialogs
  197. route(WITHINDLG);
  198.  
  199. ### only initial requests (no To tag)
  200.  
  201. t_check_trans();
  202.  
  203. # record routing for dialog forming requests (in case they are routed)
  204. # - remove preloaded route headers
  205. remove_hf("Route");
  206. if (is_method("INVITE|SUBSCRIBE"))
  207. record_route();
  208.  
  209. # account only INVITEs
  210. if (is_method("INVITE"))
  211. {
  212. setflag(FLT_ACC); # do accounting
  213. }
  214.  
  215. # dispatch requests to foreign domains
  216. route(SIPOUT);
  217.  
  218. ### requests for my local domains
  219.  
  220. # handle presence related requests
  221. route(PRESENCE);
  222.  
  223. # handle registrations
  224. route(REGISTRAR);
  225.  
  226. if ($rU==$null)
  227. {
  228. # request with no Username in RURI
  229. sl_send_reply("484","Address Incomplete");
  230. exit;
  231. }
  232.  
  233. # dispatch destinations to PSTN
  234. route(PSTN);
  235.  
  236. # user location service
  237. route(LOCATION);
  238. }
  239.  
  240.  
  241. ####################################################################################################
  242. #################### in the end of the route u meet UCHIBUCHI. just ignore him. ####################
  243. ####################################################################################################
  244.  
  245.  
  246. # Per SIP request initial checks
  247. route[REQINIT] {
  248. if (!mf_process_maxfwd_header("10")) {
  249. sl_send_reply("483","Too Many Hops");
  250. xlog("483 Too Many Hops to $du\n");
  251. exit;
  252. }
  253.  
  254. if(!sanity_check("1511", "7"))
  255. {
  256. xlog("Malformed SIP message from $si:$sp\n");
  257. exit;
  258. }
  259. }
  260.  
  261.  
  262. ####################################################################################################
  263. #################### in the end of the route u meet UCHIBUCHI. just ignore him. ####################
  264. ####################################################################################################
  265.  
  266.  
  267. # Caller NAT detection route
  268. route[NATDETECT] {
  269. force_rport();
  270. xlog("L_NOTICE","--------------------- FORCE RPORT --------------------------------------\n");
  271. if (nat_uac_test("19")) {
  272. if (is_method("REGISTER")) {
  273. # forward("50.0.0.10");
  274. # xlog("L_NOTICE","--------------------- NATDETECT REGISTER FWD --------------------------------------\n");
  275. xlog("L_NOTICE","--------------------- BEFORE fix_nated_register TO_URI: $dlg(to_uri) FROM_URI: $dlg(from_uri) --------------------------------------\n");
  276. fix_nated_register();
  277. xlog("L_NOTICE","--------------------- fix_nated_register TO_URI: $dlg(to_uri) FROM_URI: $dlg(from_uri) --------------------------------------\n");
  278. } else {
  279. if(is_first_hop())
  280. xlog("L_NOTICE","--------------------- BEFORE set_contact_alias $dlg(to_contact) --------------------------------------\n");
  281. set_contact_alias();
  282. xlog("L_NOTICE","--------------------- set_contact_alias $dlg(to_contact) --------------------------------------\n");
  283. }
  284. xlog("L_NOTICE","--------------------- BEFORE setflag(FLT_NATS) flags: $mf --------------------------------------\n");
  285. setflag(FLT_NATS);
  286. xlog("L_NOTICE","--------------------- setflag(FLT_NATS) flags: $mf --------------------------------------\n");
  287. }
  288. return;
  289. }
  290.  
  291.  
  292. ####################################################################################################
  293. #################### in the end of the route u meet UCHIBUCHI. just ignore him. ####################
  294. ####################################################################################################
  295.  
  296.  
  297. # Handle requests within SIP dialogs
  298. route[WITHINDLG] {
  299. if (has_totag()) {
  300. xlog("L_NOTICE","--------------------- chech to tag: $tt $dlg(to_tag) --------------------------------------\n");
  301. # sequential request withing a dialog should
  302. # take the path determined by record-routing
  303. if (loose_route()) {
  304. route(DLGURI);
  305. if (is_method("BYE")) {
  306. setflag(FLT_ACC); # do accounting ...
  307. xlog("L_NOTICE","--------------------- FLT_ACC setflag check: $tt --------------------------------------\n");
  308. setflag(FLT_ACCFAILED); # ... even if the transaction fails
  309. xlog("L_NOTICE","--------------------- FLT_ACCFAILED setflag check: $tt --------------------------------------\n");
  310. }
  311. else if ( is_method("ACK") ) {
  312. # ACK is forwarded statelessy
  313. route(NATMANAGE);
  314. }
  315. else if ( is_method("NOTIFY") ) {
  316. # Add Record-Route for in-dialog NOTIFY as per RFC 6665.
  317. xlog("L_NOTICE","--------------------- BEFORE rr TO_RS: $dlg(to_rs) FROM_RS: $dlg(from_rs) --------------------------------------\n");
  318. record_route();
  319. xlog("L_NOTICE","--------------------- rr TO_RS: $dlg(to_rs) FROM_RS: $dlg(from_rs) --------------------------------------\n");
  320. }
  321. route(RELAY);
  322. } else {
  323. if (is_method("SUBSCRIBE") && uri == myself) {
  324. # in-dialog subscribe requests
  325. route(PRESENCE);
  326. exit;
  327. }
  328. if ( is_method("ACK") ) {
  329. if ( t_check_trans() ) {
  330. # no loose-route, but stateful ACK;
  331. # must be an ACK after a 487
  332. # or e.g. 404 from upstream server
  333. route(RELAY);
  334. exit;
  335. } else {
  336. # ACK without matching transaction ... ignore and discard
  337. exit;
  338. }
  339. }
  340. sl_send_reply("404","Not here");
  341. }
  342. exit;
  343. }
  344. }
  345.  
  346.  
  347. ####################################################################################################
  348. #################### in the end of the route u meet UCHIBUCHI. just ignore him. ####################
  349. ####################################################################################################
  350.  
  351.  
  352. # Routing to foreign domains
  353. route[SIPOUT] {
  354. if (!uri==myself)
  355. {
  356. append_hf("P-hint: outbound\r\n");
  357. route(RELAY);
  358. }
  359. }
  360.  
  361.  
  362. ####################################################################################################
  363. #################### in the end of the route u meet UCHIBUCHI. just ignore him. ####################
  364. ####################################################################################################
  365.  
  366. # Presence server route
  367. route[PRESENCE] {
  368. if(!is_method("PUBLISH|SUBSCRIBE"))
  369. return;
  370.  
  371. if(is_method("SUBSCRIBE") && $hdr(Event)=="message-summary") {
  372. forward("50.0.0.10");
  373. xlog("L_NOTICE","--------------------- PRESENSE FWD --------------------------------------\n");
  374. # route(TOVOICEMAIL);
  375. # returns here if no voicemail server is configured
  376. # sl_send_reply("404", "No voicemail service");
  377. exit;
  378. }
  379.  
  380. # if presence enabled, this part will not be executed
  381. if (is_method("PUBLISH") || $rU==$null)
  382. {
  383. sl_send_reply("404", "Not here");
  384. exit;
  385. }
  386. return;
  387. }
  388.  
  389.  
  390. ####################################################################################################
  391. #################### in the end of the route u meet UCHIBUCHI. just ignore him. ####################
  392. ####################################################################################################
  393.  
  394.  
  395. # Handle SIP registrations
  396. route[REGISTRAR] {
  397. if (is_method("REGISTER"))
  398. {
  399. forward("50.0.0.10");
  400. xlog("L_NOTICE","--------------------- REGISTER FWD --------------------------------------\n");
  401.  
  402. if(isflagset(FLT_NATS))
  403. {
  404. # setbflag(FLB_NATB);
  405. # # uncomment next line to do SIP NAT pinging
  406. # xlog("L_NOTICE","--------------------- BEFORE NATSIPPING setflag check: $tt --------------------------------------\n");
  407. setbflag(FLB_NATSIPPING);
  408. xlog("L_NOTICE","--------------------- NATSIPPING setflag check: $tt --------------------------------------\n");
  409. }
  410. if (!save("location"))
  411. sl_reply_error();
  412.  
  413. exit;
  414. }
  415. }
  416.  
  417. #route[REGISTRAR] {
  418. # if (is_method("REGISTER"))
  419. # {
  420. # forward("50.0.0.10");
  421. # save("sip:50.0.0.10","0x02");
  422. # t_relay_to_udp("50.0.0.10", "5060");
  423. # exit;
  424. # }
  425. #}
  426.  
  427.  
  428. ####################################################################################################
  429. #################### in the end of the route u meet UCHIBUCHI. just ignore him. ####################
  430. ####################################################################################################
  431.  
  432.  
  433. # PSTN GW routing
  434. route[PSTN] {
  435. return;
  436. }
  437.  
  438.  
  439. ####################################################################################################
  440. #################### in the end of the route u meet UCHIBUCHI. just ignore him. ####################
  441. ####################################################################################################
  442.  
  443.  
  444. # USER location service
  445. route[LOCATION] {
  446.  
  447. $avp(oexten) = $rU;
  448. if (!lookup("location")) {
  449. $var(rc) = $rc;
  450. route(TOVOICEMAIL);
  451. t_newtran();
  452. switch ($var(rc)) {
  453. case -1:
  454. case -3:
  455. send_reply("404", "Not Found");
  456. exit;
  457. case -2:
  458. send_reply("405", "Method Not Allowed");
  459. exit;
  460. }
  461. }
  462.  
  463. # when routing via usrloc, log the missed calls also
  464. if (is_method("INVITE"))
  465. {
  466. xlog("L_NOTICE","--------------------- NEED TO REMOVE setflag check: $tt -------------------------------------\n");
  467. setflag(FLT_ACCMISSED);
  468. xlog("L_NOTICE","--------------------- NEED TO REMOVE setflag check: $tt --------------------------------------\n");
  469. forward("50.0.0.10");
  470. xlog("L_NOTICE","--------------------- INVITE FWD --------------------------------------\n");
  471. }
  472.  
  473. route(RELAY);
  474. exit;
  475. }
  476.  
  477.  
  478.  
  479. ####################################################################################################
  480. #################### in the end of the route u meet UCHIBUCHI. just ignore him. ####################
  481. ####################################################################################################
  482.  
  483.  
  484. route[RELAY] {
  485.  
  486. # enable additional event routes for forwarded requests
  487. # - serial forking, RTP relaying handling, a.s.o.
  488. if (is_method("INVITE|BYE|SUBSCRIBE|UPDATE")) {
  489. if(!t_is_set("branch_route")) t_on_branch("MANAGE_BRANCH");
  490. }
  491. if (is_method("INVITE|SUBSCRIBE|UPDATE")) {
  492. if(!t_is_set("onreply_route")) t_on_reply("MANAGE_REPLY");
  493. }
  494. if (is_method("INVITE")) {
  495. if(!t_is_set("failure_route")) t_on_failure("MANAGE_FAILURE");
  496. }
  497.  
  498. if (!t_relay()) {
  499. sl_reply_error();
  500. }
  501. exit;
  502. }
  503.  
  504. # manage outgoing branches
  505. branch_route[MANAGE_BRANCH] {
  506. xdbg("new branch [$T_branch_idx] to $ru\n");
  507. xlog("L_NOTICE","new branch [$T_branch_idx] to $ru\n");
  508. route(NATMANAGE);
  509. }
  510.  
  511. # manage incoming replies
  512. onreply_route[MANAGE_REPLY] {
  513. xdbg("incoming reply\n");
  514. xlog("L_NOTICE","incoming reply\n");
  515. if(status=~"[12][0-9][0-9]")
  516. route(NATMANAGE);
  517. }
  518.  
  519. # manage failure routing cases
  520. failure_route[MANAGE_FAILURE] {
  521. route(NATMANAGE);
  522. if (t_is_canceled()) {
  523. exit;
  524. }
  525.  
  526. }
  527.  
  528.  
  529. ####################################################################################################
  530. #################### in the end of the route u meet UCHIBUCHI. just ignore him. ####################
  531. ####################################################################################################
  532.  
  533.  
  534. # route to voicemail server
  535. route[TOVOICEMAIL] {
  536. return;
  537. }
  538.  
  539.  
  540. ####################################################################################################
  541. #################### in the end of the route u meet UCHIBUCHI. just ignore him. ####################
  542. ####################################################################################################
  543.  
  544.  
  545. # URI update for dialog requests
  546. route[DLGURI] {
  547. if(!isdsturiset()) {
  548. xlog("L_NOTICE","--------------------- BEFORE HANDLE RURI ALIAS TO_URI: $dlg(to_uri) FROM_URI: $dlg(from_uri) --------------------------------------\n");
  549. handle_ruri_alias();
  550. xlog("L_NOTICE","--------------------- HANDLE RURI ALIAS TO_URI: $dlg(to_uri) FROM_URI: $dlg(from_uri) --------------------------------------\n");
  551. }
  552. return;
  553. }
  554.  
  555.  
  556. ####################################################################################################
  557. #################### in the end of the route u meet UCHIBUCHI. just ignore him. ####################
  558. ####################################################################################################
  559.  
  560.  
  561. # RTPProxy control
  562. route[NATMANAGE] {
  563. if (is_request()) {
  564. if(has_totag()) {
  565. if(check_route_param("nat=yes")) {
  566. setbflag(FLB_NATB);
  567. }
  568. }
  569. }
  570. if (!(isflagset(FLT_NATS) || isbflagset(FLB_NATB)))
  571. return;
  572.  
  573. rtpproxy_manage();
  574.  
  575. if (is_request()) {
  576. if (!has_totag()) {
  577. if(t_is_branch_route()) {
  578. add_rr_param(";nat=yes");
  579. }
  580. }
  581. }
  582. if (is_reply()) {
  583. if(isbflagset(FLB_NATB)) {
  584. if(is_first_hop())
  585. set_contact_alias();
  586. }
  587. }
  588. return;
  589. }
  590.  
  591.  
  592. ####################################################################################################
  593. #################### in the end of the route u meet UCHIBUCHI. just ignore him. ####################
  594. ####################################################################################################
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement