Advertisement
Guest User

kamailio.cfg

a guest
Sep 29th, 2011
233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 19.81 KB | None | 0 0
  1. #!KAMAILIO
  2. #
  3. # Kamailio (OpenSER) SIP Server v3.1 - default configuration script
  4. # - web: http://www.kamailio.org
  5. # - git: http://sip-router.org
  6. #
  7. # Direct your questions about this file to: <sr-users@lists.sip-router.org>
  8. #
  9. # Refer to the Core CookBook at http://www.kamailio.org/dokuwiki/doku.php
  10. # for an explanation of possible statements, functions and parameters.
  11. #
  12. # Several features can be enabled using '#!define WITH_FEATURE' directives:
  13. #
  14. # *** To run in debug mode:
  15. # - define WITH_DEBUG
  16. #
  17. # *** To enable mysql:
  18. # - define WITH_MYSQL
  19. #
  20. # *** To enable authentication execute:
  21. # - enable mysql
  22. # - define WITH_AUTH
  23. # - add users using 'kamctl'
  24. #
  25. # *** To enable IP authentication execute:
  26. # - enable mysql
  27. # - enable authentication
  28. # - define WITH_IPAUTH
  29. # - add IP addresses with group id '1' to 'address' table
  30. #
  31. # *** To enable persistent user location execute:
  32. # - enable mysql
  33. # - define WITH_USRLOCDB
  34. #
  35. # *** To enable presence server execute:
  36. # - enable mysql
  37. # - define WITH_PRESENCE
  38. #
  39. # *** To enable nat traversal execute:
  40. # - define WITH_NAT
  41. # - install RTPProxy: http://www.rtpproxy.org
  42. # - start RTPProxy:
  43. # rtpproxy -l _your_public_ip_ -s udp:localhost:7722
  44. #
  45. # *** To enable PSTN gateway routing execute:
  46. # - define WITH_PSTN
  47. # - set the value of pstn.gw_ip
  48. # - check route[PSTN] for regexp routing condition
  49. #
  50. # *** To enable database aliases lookup execute:
  51. # - enable mysql
  52. # - define WITH_ALIASDB
  53. #
  54. # *** To enable multi-domain support execute:
  55. # - enable mysql
  56. # - define WITH_MULTIDOMAIN
  57. #
  58. # *** To enable TLS support execute:
  59. # - adjust CFGDIR/tls.cfg as needed
  60. # - define WITH_TLS
  61. #
  62. # *** To enable XMLRPC support execute:
  63. # - define WITH_XMLRPC
  64. # - adjust route[XMLRPC] for access policy
  65. #
  66. # *** To enable anti-flood detection execute:
  67. # - adjust pike and htable=>ipban settings as needed (default is
  68. # block if more than 16 requests in 2 seconds and ban for 300 seconds)
  69. # - define WITH_ANTIFLOOD
  70. #
  71. # *** To enhance accounting execute:
  72. # - enable mysql
  73. # - define WITH_ACCDB
  74. # - add following columns to database
  75. #!ifdef ACCDB_COMMENT
  76. ALTER TABLE acc ADD COLUMN src_user VARCHAR(64) NOT NULL DEFAULT '';
  77. ALTER TABLE acc ADD COLUMN src_domain VARCHAR(128) NOT NULL DEFAULT '';
  78. ALTER TABLE acc ADD COLUMN dst_ouser VARCHAR(64) NOT NULL DEFAULT '';
  79. ALTER TABLE acc ADD COLUMN dst_user VARCHAR(64) NOT NULL DEFAULT '';
  80. ALTER TABLE acc ADD COLUMN dst_domain VARCHAR(128) NOT NULL DEFAULT '';
  81. ALTER TABLE missed_calls ADD COLUMN src_user VARCHAR(64) NOT NULL DEFAULT '';
  82. ALTER TABLE missed_calls ADD COLUMN src_domain VARCHAR(128) NOT NULL DEFAULT '';
  83. ALTER TABLE missed_calls ADD COLUMN dst_ouser VARCHAR(64) NOT NULL DEFAULT '';
  84. ALTER TABLE missed_calls ADD COLUMN dst_user VARCHAR(64) NOT NULL DEFAULT '';
  85. ALTER TABLE missed_calls ADD COLUMN dst_domain VARCHAR(128) NOT NULL DEFAULT '';
  86. #!endif
  87.  
  88. ####### Defined Values #########
  89.  
  90. # *** Value defines - IDs used later in config
  91. #!ifdef WITH_MYSQL
  92. # - database URL - used to connect to database server by modules such
  93. # as: auth_db, acc, usrloc, a.s.o.
  94. #!define DBURL "mysql://openser:openserrw@localhost/openser"
  95. #!endif
  96. #!ifdef WITH_MULTIDOMAIN
  97. # - the value for 'use_domain' parameters
  98. #!define MULTIDOMAIN 1
  99. #!else
  100. #!define MULTIDOMAIN 0
  101. #!endif
  102.  
  103. # - flags
  104. # FLT_ - per transaction (message) flags
  105. # FLB_ - per branch flags
  106. #!define FLT_ACC 1
  107. #!define FLT_ACCMISSED 2
  108. #!define FLT_ACCFAILED 3
  109. #!define FLT_NATS 5
  110.  
  111. #!define FLB_NATB 6
  112. #!define FLB_NATSIPPING 7
  113.  
  114. ####### Global Parameters #########
  115.  
  116. #!ifdef WITH_DEBUG
  117. debug=4
  118. log_stderror=yes
  119. #!else
  120. debug=2
  121. log_stderror=no
  122. #!endif
  123.  
  124. memdbg=5
  125. memlog=5
  126.  
  127. log_facility=LOG_LOCAL0
  128.  
  129. fork=yes
  130. children=4
  131.  
  132. /* uncomment the next line to disable TCP (default on) */
  133. #disable_tcp=yes
  134.  
  135. /* uncomment the next line to disable the auto discovery of local aliases
  136. based on reverse DNS on IPs (default on) */
  137. #auto_aliases=no
  138.  
  139. /* add local domain aliases */
  140. #alias="sip.mydomain.com"
  141.  
  142. /* uncomment and configure the following line if you want Kamailio to
  143. bind on a specific interface/port/proto (default bind on all available) */
  144. #listen=udp:10.0.0.10:5060
  145.  
  146. /* port to listen to
  147. * - can be specified more than once if needed to listen on many ports */
  148. port=5060
  149.  
  150. #!ifdef WITH_TLS
  151. enable_tls=yes
  152. #!endif
  153.  
  154. ####### Custom Parameters #########
  155.  
  156. # These parameters can be modified runtime via RPC interface
  157. # - see the documentation of 'cfg_rpc' module.
  158. #
  159. # Format: group.id = value 'desc' description
  160. # Access: $sel(cfg_get.group.id) or @cfg_get.group.id
  161. #
  162.  
  163. #!ifdef WITH_PSTN
  164. # PSTN GW Routing
  165. #
  166. # - pstn.gw_ip: valid IP or hostname as string value, example:
  167. # pstn.gw_ip = "10.0.0.101" desc "My PSTN GW Address"
  168. #
  169. # - by default is empty to avoid misrouting
  170. pstn.gw_ip = "" desc "PSTN GW Address"
  171. #!endif
  172.  
  173.  
  174. ####### Modules Section ########
  175.  
  176. # set paths to location of modules
  177. #!ifdef LOCAL_TEST_RUN
  178. mpath="modules_k:modules"
  179. #!else
  180. mpath="/usr/local/kamailio/lib64/kamailio/modules_k/:/usr/local/kamailio/lib64/kamailio/modules/"
  181. #!endif
  182.  
  183. #!ifdef WITH_MYSQL
  184. loadmodule "db_mysql.so"
  185. #!endif
  186.  
  187. loadmodule "mi_fifo.so"
  188. loadmodule "kex.so"
  189. loadmodule "tm.so"
  190. loadmodule "tmx.so"
  191. loadmodule "sl.so"
  192. loadmodule "rr.so"
  193. loadmodule "pv.so"
  194. loadmodule "maxfwd.so"
  195. loadmodule "usrloc.so"
  196. loadmodule "registrar.so"
  197. loadmodule "textops.so"
  198. loadmodule "siputils.so"
  199. loadmodule "xlog.so"
  200. loadmodule "sanity.so"
  201. loadmodule "ctl.so"
  202. loadmodule "mi_rpc.so"
  203. loadmodule "acc.so"
  204.  
  205. #!ifdef WITH_AUTH
  206. loadmodule "auth.so"
  207. loadmodule "auth_db.so"
  208. #!ifdef WITH_IPAUTH
  209. loadmodule "permissions.so"
  210. #!endif
  211. #!endif
  212.  
  213. #!ifdef WITH_ALIASDB
  214. loadmodule "alias_db.so"
  215. #!endif
  216.  
  217. #!ifdef WITH_MULTIDOMAIN
  218. loadmodule "domain.so"
  219. #!endif
  220.  
  221. #!ifdef WITH_PRESENCE
  222. loadmodule "presence.so"
  223. loadmodule "presence_xml.so"
  224. #!endif
  225.  
  226. #!ifdef WITH_NAT
  227. loadmodule "nathelper.so"
  228. loadmodule "rtpproxy.so"
  229. #!endif
  230.  
  231. #!ifdef WITH_TLS
  232. loadmodule "tls.so"
  233. #!endif
  234.  
  235. #!ifdef WITH_ANTIFLOOD
  236. loadmodule "htable.so"
  237. loadmodule "pike.so"
  238. #!endif
  239.  
  240. #!ifdef WITH_XMLRPC
  241. loadmodule "xmlrpc.so"
  242. #!endif
  243.  
  244. loadmodule "dispatcher.so"
  245.  
  246. # ----------------- setting module-specific parameters ---------------
  247.  
  248.  
  249. # ----- mi_fifo params -----
  250. modparam("mi_fifo", "fifo_name", "/tmp/kamailio_fifo")
  251.  
  252.  
  253. # ----- tm params -----
  254. # auto-discard branches from previous serial forking leg
  255. modparam("tm", "failure_reply_mode", 3)
  256. # default retransmission timeout: 30sec
  257. modparam("tm", "fr_timer", 30000)
  258. # default invite retransmission timeout after 1xx: 120sec
  259. modparam("tm", "fr_inv_timer", 120000)
  260.  
  261.  
  262. # ----- rr params -----
  263. # add value to ;lr param to cope with most of the UAs
  264. modparam("rr", "enable_full_lr", 1)
  265. # do not append from tag to the RR (no need for this script)
  266. modparam("rr", "append_fromtag", 0)
  267.  
  268.  
  269. # ----- registrar params -----
  270. modparam("registrar", "method_filtering", 1)
  271. /* uncomment the next line to disable parallel forking via location */
  272. # modparam("registrar", "append_branches", 0)
  273. /* uncomment the next line not to allow more than 10 contacts per AOR */
  274. #modparam("registrar", "max_contacts", 10)
  275.  
  276.  
  277. # ----- acc params -----
  278. /* what special events should be accounted ? */
  279. modparam("acc", "early_media", 0)
  280. modparam("acc", "report_ack", 0)
  281. modparam("acc", "report_cancels", 0)
  282. /* by default ww do not adjust the direct of the sequential requests.
  283. if you enable this parameter, be sure the enable "append_fromtag"
  284. in "rr" module */
  285. modparam("acc", "detect_direction", 0)
  286. /* account triggers (flags) */
  287. modparam("acc", "log_flag", FLT_ACC)
  288. modparam("acc", "log_missed_flag", FLT_ACCMISSED)
  289. modparam("acc", "log_extra",
  290. "src_user=$fU;src_domain=$fd;dst_ouser=$tU;dst_user=$rU;dst_domain=$rd")
  291. modparam("acc", "failed_transaction_flag", FLT_ACCFAILED)
  292. /* enhanced DB accounting */
  293. #!ifdef WITH_ACCDB
  294. modparam("acc", "db_flag", FLT_ACC)
  295. modparam("acc", "db_missed_flag", FLT_ACCMISSED)
  296. modparam("acc", "db_url", DBURL)
  297. modparam("acc", "db_extra",
  298. "src_user=$fU;src_domain=$fd;dst_ouser=$tU;dst_user=$rU;dst_domain=$rd")
  299. #!endif
  300.  
  301.  
  302. # ----- usrloc params -----
  303. /* enable DB persistency for location entries */
  304. #!ifdef WITH_USRLOCDB
  305. modparam("usrloc", "db_url", DBURL)
  306. modparam("usrloc", "db_mode", 2)
  307. modparam("usrloc", "use_domain", MULTIDOMAIN)
  308. #!endif
  309.  
  310.  
  311. # ----- auth_db params -----
  312. #!ifdef WITH_AUTH
  313. modparam("auth_db", "db_url", DBURL)
  314. modparam("auth_db", "calculate_ha1", yes)
  315. modparam("auth_db", "password_column", "password")
  316. modparam("auth_db", "load_credentials", "")
  317. modparam("auth_db", "use_domain", MULTIDOMAIN)
  318.  
  319. # ----- permissions params -----
  320. #!ifdef WITH_IPAUTH
  321. modparam("permissions", "db_url", DBURL)
  322. modparam("permissions", "db_mode", 1)
  323. #!endif
  324.  
  325. #!endif
  326.  
  327.  
  328. # ----- alias_db params -----
  329. #!ifdef WITH_ALIASDB
  330. modparam("alias_db", "db_url", DBURL)
  331. modparam("alias_db", "use_domain", MULTIDOMAIN)
  332. #!endif
  333.  
  334.  
  335. # ----- domain params -----
  336. #!ifdef WITH_MULTIDOMAIN
  337. modparam("domain", "db_url", DBURL)
  338. # use caching
  339. modparam("domain", "db_mode", 1)
  340. # register callback to match myself condition with domains list
  341. modparam("domain", "register_myself", 1)
  342. #!endif
  343.  
  344.  
  345. #!ifdef WITH_PRESENCE
  346. # ----- presence params -----
  347. modparam("presence", "db_url", DBURL)
  348.  
  349. # ----- presence_xml params -----
  350. modparam("presence_xml", "db_url", DBURL)
  351. modparam("presence_xml", "force_active", 1)
  352. #!endif
  353.  
  354.  
  355. #!ifdef WITH_NAT
  356. # ----- rtpproxy params -----
  357. modparam("rtpproxy", "rtpproxy_sock", "udp:127.0.0.1:7722")
  358.  
  359. # ----- nathelper params -----
  360. modparam("nathelper", "natping_interval", 30)
  361. modparam("nathelper", "ping_nated_only", 1)
  362. modparam("nathelper", "sipping_bflag", FLB_NATSIPPING)
  363. modparam("nathelper", "sipping_from", "sip:pinger@kamailio.org")
  364.  
  365. # params needed for NAT traversal in other modules
  366. modparam("nathelper|registrar", "received_avp", "$avp(RECEIVED)")
  367. modparam("usrloc", "nat_bflag", FLB_NATB)
  368. #!endif
  369.  
  370.  
  371. #!ifdef WITH_TLS
  372. # ----- tls params -----
  373. modparam("tls", "config", "/usr/local/kamailio/etc/kamailio/tls.cfg")
  374. #!endif
  375.  
  376. #!ifdef WITH_ANTIFLOOD
  377. # ----- pike params -----
  378. modparam("pike", "sampling_time_unit", 2)
  379. modparam("pike", "reqs_density_per_unit", 16)
  380. modparam("pike", "remove_latency", 4)
  381.  
  382. # ----- htable params -----
  383. # ip ban htable with autoexpire after 5 minutes
  384. modparam("htable", "htable", "ipban=>size=8;autoexpire=300;")
  385. #!endif
  386.  
  387. #!ifdef WITH_XMLRPC
  388. # ----- xmlrpc params -----
  389. modparam("xmlrpc", "route", "XMLRPC");
  390. modparam("xmlrpc", "url_match", "^/RPC")
  391. #!endif
  392.  
  393. modparam("dispatcher", "list_file", "/usr/local/kamailio/etc/kamailio/dispatcher.list")
  394. modparam("dispatcher", "flags", 2)
  395. modparam("dispatcher", "dst_avp", "$avp(AVP_DST)")
  396. modparam("dispatcher", "grp_avp", "$avp(AVP_GRP)")
  397. modparam("dispatcher", "cnt_avp", "$avp(AVP_CNT)")
  398.  
  399. ####### Routing Logic ########
  400.  
  401.  
  402. # Main SIP request routing logic
  403. # - processing of any incoming SIP request starts with this route
  404. route {
  405.  
  406. # select from first dst group by round-robin
  407. if(!ds_select_dst("1", "4"))
  408. {
  409. sl_send_reply("500", "No destination available");
  410. exit;
  411. }
  412.  
  413. t_on_failure("RTF_DISPATCH");
  414. if(!t_relay())
  415. {
  416. sl_reply_error();
  417. exit;
  418. }
  419.  
  420. # per request initial checks
  421. route(REQINIT);
  422.  
  423. # NAT detection
  424. route(NAT);
  425.  
  426. # handle requests within SIP dialogs
  427. route(WITHINDLG);
  428.  
  429. ### only initial requests (no To tag)
  430.  
  431. # CANCEL processing
  432. if (is_method("CANCEL"))
  433. {
  434. if (t_check_trans())
  435. t_relay();
  436. exit;
  437. }
  438.  
  439. t_check_trans();
  440.  
  441. # authentication
  442. route(AUTH);
  443.  
  444. # record routing for dialog forming requests (in case they are routed)
  445. # - remove preloaded route headers
  446. remove_hf("Route");
  447. if (is_method("INVITE|SUBSCRIBE"))
  448. record_route();
  449.  
  450. # account only INVITEs
  451. if (is_method("INVITE"))
  452. {
  453. setflag(FLT_ACC); # do accounting
  454. }
  455.  
  456. # dispatch requests to foreign domains
  457. route(SIPOUT);
  458.  
  459. ### requests for my local domains
  460.  
  461. # handle presence related requests
  462. route(PRESENCE);
  463.  
  464. # handle registrations
  465. route(REGISTRAR);
  466.  
  467. if ($rU==$null)
  468. {
  469. # request with no Username in RURI
  470. sl_send_reply("484","Address Incomplete");
  471. exit;
  472. }
  473.  
  474. # dispatch destinations to PSTN
  475. route(PSTN);
  476.  
  477. # user location service
  478. route(LOCATION);
  479.  
  480. route(RELAY);
  481. }
  482.  
  483.  
  484. route[RELAY] {
  485. #!ifdef WITH_NAT
  486. if (check_route_param("nat=yes")) {
  487. setbflag(FLB_NATB);
  488. }
  489. if (isflagset(FLT_NATS) || isbflagset(FLB_NATB)) {
  490. route(RTPPROXY);
  491. }
  492. #!endif
  493.  
  494. /* example how to enable some additional event routes */
  495. if (is_method("INVITE")) {
  496. #t_on_branch("BRANCH_ONE");
  497. t_on_reply("REPLY_ONE");
  498. t_on_failure("FAIL_ONE");
  499. }
  500.  
  501. if (!t_relay()) {
  502. sl_reply_error();
  503. }
  504. exit;
  505. }
  506.  
  507. # Per SIP request initial checks
  508. route[REQINIT] {
  509. #!ifdef WITH_ANTIFLOOD
  510. # flood dection from same IP and traffic ban for a while
  511. # be sure you exclude checking trusted peers, such as pstn gateways
  512. # - local host excluded (e.g., loop to self)
  513. if(src_ip!=myself)
  514. {
  515. if($sht(ipban=>$si)!=$null)
  516. {
  517. # ip is already blocked
  518. xdbg("request from blocked IP - $rm from $fu (IP:$si:$sp)\n");
  519. exit;
  520. }
  521. if (!pike_check_req())
  522. {
  523. xlog("L_ALERT","ALERT: pike blocking $rm from $fu (IP:$si:$sp)\n");
  524. $sht(ipban=>$si) = 1;
  525. exit;
  526. }
  527. }
  528. #!endif
  529.  
  530. if (!mf_process_maxfwd_header("10")) {
  531. sl_send_reply("483","Too Many Hops");
  532. exit;
  533. }
  534.  
  535. if(!sanity_check("1511", "7"))
  536. {
  537. xlog("Malformed SIP message from $si:$sp\n");
  538. exit;
  539. }
  540. }
  541.  
  542. # Handle requests within SIP dialogs
  543. route[WITHINDLG] {
  544. if (has_totag()) {
  545. # sequential request withing a dialog should
  546. # take the path determined by record-routing
  547. if (loose_route()) {
  548. if (is_method("BYE")) {
  549. setflag(FLT_ACC); # do accounting ...
  550. setflag(FLT_ACCFAILED); # ... even if the transaction fails
  551. }
  552. route(RELAY);
  553. } else {
  554. if (is_method("SUBSCRIBE") && uri == myself) {
  555. # in-dialog subscribe requests
  556. route(PRESENCE);
  557. exit;
  558. }
  559. if ( is_method("ACK") ) {
  560. if ( t_check_trans() ) {
  561. # no loose-route, but stateful ACK;
  562. # must be an ACK after a 487
  563. # or e.g. 404 from upstream server
  564. t_relay();
  565. exit;
  566. } else {
  567. # ACK without matching transaction ... ignore and discard
  568. exit;
  569. }
  570. }
  571. sl_send_reply("404","Not here");
  572. }
  573. exit;
  574. }
  575. }
  576.  
  577. # Handle SIP registrations
  578. route[REGISTRAR] {
  579. if (is_method("REGISTER"))
  580. {
  581. if(isflagset(FLT_NATS))
  582. {
  583. setbflag(FLB_NATB);
  584. # uncomment next line to do SIP NAT pinging
  585. ## setbflag(FLB_NATSIPPING);
  586. }
  587. if (!save("location"))
  588. sl_reply_error();
  589.  
  590. exit;
  591. }
  592. }
  593.  
  594. # USER location service
  595. route[LOCATION] {
  596.  
  597. #!ifdef WITH_ALIASDB
  598. # search in DB-based aliases
  599. alias_db_lookup("dbaliases");
  600. #!endif
  601.  
  602. if (!lookup("location")) {
  603. switch ($rc) {
  604. case -1:
  605. case -3:
  606. t_newtran();
  607. t_reply("404", "Not Found");
  608. exit;
  609. case -2:
  610. sl_send_reply("405", "Method Not Allowed");
  611. exit;
  612. }
  613. }
  614.  
  615. # when routing via usrloc, log the missed calls also
  616. if (is_method("INVITE"))
  617. {
  618. setflag(FLT_ACCMISSED);
  619. }
  620. }
  621.  
  622. # Presence server route
  623. route[PRESENCE] {
  624. if(!is_method("PUBLISH|SUBSCRIBE"))
  625. return;
  626.  
  627. #!ifdef WITH_PRESENCE
  628. if (!t_newtran())
  629. {
  630. sl_reply_error();
  631. exit;
  632. };
  633.  
  634. if(is_method("PUBLISH"))
  635. {
  636. handle_publish();
  637. t_release();
  638. }
  639. else
  640. if( is_method("SUBSCRIBE"))
  641. {
  642. handle_subscribe();
  643. t_release();
  644. }
  645. exit;
  646. #!endif
  647.  
  648. # if presence enabled, this part will not be executed
  649. if (is_method("PUBLISH") || $rU==$null)
  650. {
  651. sl_send_reply("404", "Not here");
  652. exit;
  653. }
  654. return;
  655. }
  656.  
  657. # Authentication route
  658. route[AUTH] {
  659. #!ifdef WITH_AUTH
  660. if (is_method("REGISTER"))
  661. {
  662. # authenticate the REGISTER requests (uncomment to enable auth)
  663. if (!www_authorize("$td", "subscriber"))
  664. {
  665. www_challenge("$td", "0");
  666. exit;
  667. }
  668.  
  669. if ($au!=$tU)
  670. {
  671. sl_send_reply("403","Forbidden auth ID");
  672. exit;
  673. }
  674. } else {
  675.  
  676. #!ifdef WITH_IPAUTH
  677. if(allow_source_address())
  678. {
  679. # source IP allowed
  680. return;
  681. }
  682. #!endif
  683.  
  684. # authenticate if from local subscriber
  685. if (from_uri==myself)
  686. {
  687. if (!proxy_authorize("$fd", "subscriber")) {
  688. proxy_challenge("$fd", "0");
  689. exit;
  690. }
  691. if (is_method("PUBLISH"))
  692. {
  693. if ($au!=$tU) {
  694. sl_send_reply("403","Forbidden auth ID");
  695. exit;
  696. }
  697. } else {
  698. if ($au!=$fU) {
  699. sl_send_reply("403","Forbidden auth ID");
  700. exit;
  701. }
  702. }
  703.  
  704. consume_credentials();
  705. # caller authenticated
  706. } else {
  707. # caller is not local subscriber, then check if it calls
  708. # a local destination, otherwise deny, not an open relay here
  709. if (!uri==myself)
  710. {
  711. sl_send_reply("403","Not relaying");
  712. exit;
  713. }
  714. }
  715. }
  716. #!endif
  717. return;
  718. }
  719.  
  720. # Caller NAT detection route
  721. route[NAT] {
  722. #!ifdef WITH_NAT
  723. force_rport();
  724. if (nat_uac_test("19")) {
  725. if (method=="REGISTER") {
  726. fix_nated_register();
  727. } else {
  728. fix_nated_contact();
  729. }
  730. setflag(FLT_NATS);
  731. }
  732. #!endif
  733. return;
  734. }
  735.  
  736. # RTPProxy control
  737. route[RTPPROXY] {
  738. #!ifdef WITH_NAT
  739. if (is_method("BYE")) {
  740. unforce_rtp_proxy();
  741. } else if (is_method("INVITE")){
  742. force_rtp_proxy();
  743. }
  744. if (!has_totag()) add_rr_param(";nat=yes");
  745. #!endif
  746. return;
  747. }
  748.  
  749. # Routing to foreign domains
  750. route[SIPOUT] {
  751. if (!uri==myself)
  752. {
  753. append_hf("P-hint: outbound\r\n");
  754. route(RELAY);
  755. }
  756. }
  757.  
  758. # PSTN GW routing
  759. route[PSTN] {
  760. #!ifdef WITH_PSTN
  761. # check if PSTN GW IP is defined
  762. if (strempty($sel(cfg_get.pstn.gw_ip))) {
  763. xlog("SCRIPT: PSTN rotuing enabled but pstn.gw_ip not defined\n");
  764. return;
  765. }
  766.  
  767. # route to PSTN dialed numbers starting with '+' or '00'
  768. # (international format)
  769. # - update the condition to match your dialing rules for PSTN routing
  770. if(!($rU=~"^(\+|00)[1-9][0-9]{3,20}$"))
  771. return;
  772.  
  773. # only local users allowed to call
  774. if(from_uri!=myself) {
  775. sl_send_reply("403", "Not Allowed");
  776. exit;
  777. }
  778.  
  779. $ru = "sip:" + $rU + "@" + $sel(cfg_get.pstn.gw_ip);
  780.  
  781. route(RELAY);
  782. exit;
  783. #!endif
  784.  
  785. return;
  786. }
  787.  
  788. # XMLRPC routing
  789. #!ifdef WITH_XMLRPC
  790. route[XMLRPC]
  791. {
  792. # allow XMLRPC from localhost
  793. if ((method=="POST" || method=="GET")
  794. && (src_ip==127.0.0.1)) {
  795. # close connection only for xmlrpclib user agents (there is a bug in
  796. # xmlrpclib: it waits for EOF before interpreting the response).
  797. if ($hdr(User-Agent) =~ "xmlrpclib")
  798. set_reply_close();
  799. set_reply_no_connect();
  800. dispatch_rpc();
  801. exit;
  802. }
  803. send_reply("403", "Forbidden");
  804. exit;
  805. }
  806. #!endif
  807.  
  808. # Sample branch router
  809. branch_route[BRANCH_ONE] {
  810. xdbg("new branch at $ru\n");
  811. }
  812.  
  813. # Sample onreply route
  814. onreply_route[REPLY_ONE] {
  815. xdbg("incoming reply\n");
  816. #!ifdef WITH_NAT
  817. if ((isflagset(FLT_NATS) || isbflagset(FLB_NATB))
  818. && status=~"(183)|(2[0-9][0-9])") {
  819. force_rtp_proxy();
  820. }
  821. if (isbflagset(FLB_NATB)) {
  822. fix_nated_contact();
  823. }
  824. #!endif
  825. }
  826.  
  827. # Sample failure route
  828. failure_route[FAIL_ONE] {
  829. #!ifdef WITH_NAT
  830. if (is_method("INVITE")
  831. && (isbflagset(FLB_NATB) || isflagset(FLT_NATS))) {
  832. unforce_rtp_proxy();
  833. }
  834. #!endif
  835.  
  836. if (t_is_canceled()) {
  837. exit;
  838. }
  839.  
  840. # uncomment the following lines if you want to block client
  841. # redirect based on 3xx replies.
  842. ##if (t_check_status("3[0-9][0-9]")) {
  843. ##t_reply("404","Not found");
  844. ## exit;
  845. ##}
  846.  
  847. # uncomment the following lines if you want to redirect the failed
  848. # calls to a different new destination
  849. ##if (t_check_status("486|408")) {
  850. ## sethostport("192.168.2.100:5060");
  851. ## append_branch();
  852. ## # do not set the missed call flag again
  853. ## t_relay();
  854. ##}
  855. }
  856.  
  857. # dispatcher failure routing block
  858. failure_route[RTF_DISPATCH] {
  859. if (t_is_canceled()) {
  860. exit;
  861. }
  862. # select next destination only for local timeout
  863. if (t_branch_timeout() && !t_branch_replied())
  864. {
  865. if(ds_next_dst())
  866. {
  867. t_on_failure("RTF_DISPATCH");
  868. t_relay();
  869. exit;
  870. }
  871. }
  872. }
  873.  
  874.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement