Advertisement
Guest User

Untitled

a guest
Jun 13th, 2011
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 22.91 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. #!define WITH_TLS
  90. #!define WITH_MYSQL
  91. #!define WITH_AUTH
  92. #!define WITH_USRLOCDB
  93. #!define WITH_ALIASDB
  94. # ---- ##### -!define WITH_TLS
  95. #!define WITH_NAT
  96. #!define WITH_ACCDB
  97. # *** Value defines - IDs used later in config
  98. #!ifdef WITH_MYSQL
  99. # - database URL - used to connect to database server by modules such
  100. # as: auth_db, acc, usrloc, a.s.o.
  101. #!define DBURL "mysql://username:password@DB_IP/kamailio"
  102. #!endif
  103. #!ifdef WITH_MULTIDOMAIN
  104. # - the value for 'use_domain' parameters
  105. #!define MULTIDOMAIN 1
  106. #!else
  107. #!define MULTIDOMAIN 0
  108. #!endif
  109.  
  110. # - flags
  111. # FLT_ - per transaction (message) flags
  112. # FLB_ - per branch flags
  113. #!define FLT_ACC 1
  114. #!define FLT_ACCMISSED 2
  115. #!define FLT_ACCFAILED 3
  116. #!define FLT_NATS 5
  117.  
  118. #!define FLB_NATB 6
  119. #!define FLB_NATSIPPING 7
  120.  
  121. ####### Global Parameters #########
  122. #!define WITH_DEBUG
  123. #!ifdef WITH_DEBUG
  124. debug=2
  125. log_stderror=no
  126. #!else
  127. debug=7
  128. log_stderror=no
  129. #!endif
  130.  
  131. memdbg=5
  132. memlog=5
  133.  
  134. log_facility=LOG_LOCAL6
  135.  
  136. fork=yes
  137. children=4
  138.  
  139. /* uncomment the next line to disable TCP (default on) */
  140. #disable_tcp=yes
  141.  
  142. /* uncomment the next line to disable the auto discovery of local aliases
  143. based on reverse DNS on IPs (default on) */
  144. #auto_aliases=no
  145.  
  146. /* add local domain aliases */
  147. alias=tlsata.domain.com
  148.  
  149. /* uncomment and configure the following line if you want Kamailio to
  150. bind on a specific interface/port/proto (default bind on all available) */
  151. listen=udp:X.X.X.X:5060
  152. listen=udp:X.X.X.X:5061
  153. listen=udp:X.X.X.X:443
  154. #listen=udp:X.X.X.X:123
  155. listen=tcp:X.X.X.X
  156. listen=tcp:X.X.X.X:80
  157. listen=tcp:X.X.X.X:444
  158. listen=tls:X.X.X.X
  159. listen=tls:X.X.X.X:5061
  160. listen=tls:X.X.X.X:8080
  161. /* port to listen to
  162. * - can be specified more than once if needed to listen on many ports */
  163. port=5060
  164.  
  165. #!ifdef WITH_TLS
  166. enable_tls=yes
  167. #!endif
  168.  
  169. ####### Custom Parameters #########
  170.  
  171. # These parameters can be modified runtime via RPC interface
  172. # - see the documentation of 'cfg_rpc' module.
  173. #
  174. # Format: group.id = value 'desc' description
  175. # Access: $sel(cfg_get.group.id) or @cfg_get.group.id
  176. #
  177.  
  178. #!ifdef WITH_PSTN
  179. # PSTN GW Routing
  180. #
  181. # - pstn.gw_ip: valid IP or hostname as string value, example:
  182. # pstn.gw_ip = "10.0.0.101" desc "My PSTN GW Address"
  183. #
  184. # - by default is empty to avoid misrouting
  185. pstn.gw_ip = "" desc "PSTN GW Address"
  186. #!endif
  187.  
  188.  
  189. ####### Modules Section ########
  190.  
  191. # set paths to location of modules
  192. #!ifdef LOCAL_TEST_RUN
  193. mpath="modules_k:modules"
  194. #!else
  195. mpath="/usr/local/lib/kamailio/modules_k/:/usr/local/lib/kamailio/modules/"
  196. #!endif
  197.  
  198. #!ifdef WITH_MYSQL
  199. loadmodule "db_mysql.so"
  200. #!endif
  201.  
  202. loadmodule "exec.so"
  203. loadmodule "group.so"
  204. loadmodule "speeddial.so"
  205. loadmodule "carrierroute.so"
  206.  
  207.  
  208. loadmodule "mi_fifo.so"
  209. loadmodule "kex.so"
  210. loadmodule "tm.so"
  211. loadmodule "tmx.so"
  212. loadmodule "sl.so"
  213. loadmodule "rr.so"
  214. loadmodule "pv.so"
  215. loadmodule "maxfwd.so"
  216. loadmodule "usrloc.so"
  217. loadmodule "registrar.so"
  218. loadmodule "textops.so"
  219. loadmodule "siputils.so"
  220. loadmodule "xlog.so"
  221. loadmodule "sanity.so"
  222. loadmodule "ctl.so"
  223. loadmodule "mi_rpc.so"
  224. loadmodule "acc.so"
  225.  
  226. #!ifdef WITH_AUTH
  227. loadmodule "auth.so"
  228. loadmodule "auth_db.so"
  229. #!ifdef WITH_IPAUTH
  230. loadmodule "permissions.so"
  231. #!endif
  232. #!endif
  233.  
  234. #!ifdef WITH_ALIASDB
  235. loadmodule "alias_db.so"
  236. #!endif
  237.  
  238. #!ifdef WITH_MULTIDOMAIN
  239. loadmodule "domain.so"
  240. #!endif
  241.  
  242. #!ifdef WITH_PRESENCE
  243. loadmodule "presence.so"
  244. loadmodule "presence_xml.so"
  245. #!endif
  246.  
  247. #!ifdef WITH_NAT
  248. loadmodule "nathelper.so"
  249. loadmodule "rtpproxy.so"
  250. #!endif
  251.  
  252. #!ifdef WITH_TLS
  253. loadmodule "tls.so"
  254. #!endif
  255.  
  256. #!ifdef WITH_ANTIFLOOD
  257. loadmodule "htable.so"
  258. loadmodule "pike.so"
  259. #!endif
  260.  
  261. #!ifdef WITH_XMLRPC
  262. loadmodule "xmlrpc.so"
  263. #!endif
  264.  
  265. # ----------------- setting module-specific parameters ---------------
  266.  
  267.  
  268. # ----- mi_fifo params -----
  269. modparam("mi_fifo", "fifo_name", "/tmp/kamailio_fifo")
  270.  
  271.  
  272. # ----- tm params -----
  273. # auto-discard branches from previous serial forking leg
  274. modparam("tm", "failure_reply_mode", 3)
  275. # default retransmission timeout: 30sec
  276. modparam("tm", "fr_timer", 30000)
  277. # default invite retransmission timeout after 1xx: 120sec
  278. modparam("tm", "fr_inv_timer", 120000)
  279.  
  280.  
  281. # ----- rr params -----
  282. # add value to ;lr param to cope with most of the UAs
  283. modparam("rr", "enable_full_lr", 1)
  284. # do not append from tag to the RR (no need for this script)
  285. modparam("rr", "append_fromtag", 0)
  286.  
  287.  
  288. # ----- registrar params -----
  289. modparam("registrar", "method_filtering", 1)
  290. /* uncomment the next line to disable parallel forking via location */
  291. # modparam("registrar", "append_branches", 0)
  292. /* uncomment the next line not to allow more than 10 contacts per AOR */
  293. #modparam("registrar", "max_contacts", 10)
  294.  
  295.  
  296. # ----- acc params -----
  297. /* what special events should be accounted ? */
  298. modparam("acc", "early_media", 0)
  299. modparam("acc", "report_ack", 0)
  300. modparam("acc", "report_cancels", 0)
  301. /* by default ww do not adjust the direct of the sequential requests.
  302. if you enable this parameter, be sure the enable "append_fromtag"
  303. in "rr" module */
  304. modparam("acc", "detect_direction", 0)
  305. /* account triggers (flags) */
  306. modparam("acc", "log_flag", FLT_ACC)
  307. modparam("acc", "log_missed_flag", FLT_ACCMISSED)
  308. modparam("acc", "log_extra",
  309. "src_user=$fU;src_domain=$fd;dst_ouser=$tU;dst_user=$rU;dst_domain=$rd")
  310. modparam("acc", "failed_transaction_flag", FLT_ACCFAILED)
  311. /* enhanced DB accounting */
  312. #!ifdef WITH_ACCDB
  313. modparam("acc", "db_flag", FLT_ACC)
  314. modparam("acc", "db_missed_flag", FLT_ACCMISSED)
  315. modparam("acc", "db_url", DBURL)
  316. modparam("acc", "db_extra",
  317. "src_user=$fU;src_domain=$fd;dst_ouser=$tU;dst_user=$rU;dst_domain=$rd")
  318. #!endif
  319.  
  320.  
  321. # ----- usrloc params -----
  322. /* enable DB persistency for location entries */
  323. #!ifdef WITH_USRLOCDB
  324. modparam("usrloc", "timer_interval", 1)
  325. modparam("usrloc", "db_url", DBURL)
  326. modparam("usrloc", "db_mode", 2)
  327. modparam("usrloc", "use_domain", MULTIDOMAIN)
  328. #!endif
  329.  
  330.  
  331. # ----- auth_db params -----
  332. #!ifdef WITH_AUTH
  333. modparam("auth_db", "db_url", DBURL)
  334. modparam("auth_db", "calculate_ha1", yes)
  335. modparam("auth_db", "password_column", "password")
  336. modparam("auth_db", "load_credentials", "")
  337. modparam("auth_db", "use_domain", MULTIDOMAIN)
  338.  
  339. #######Carrier Route
  340. # ----------------- setting module-specific parameters ---------------
  341. modparam("carrierroute", "db_url", DBURL)
  342. modparam("carrierroute", "config_source", "db")
  343. modparam("carrierroute", "use_domain", 0)
  344. #modparam("carrierroute", "carrierroute_table", "carrierroute")
  345.  
  346. #######group module
  347. modparam("group","db_url", DBURL)
  348.  
  349. #######group module
  350. modparam("speeddial", "db_url", DBURL)
  351.  
  352.  
  353. # ----- permissions params -----
  354. #!ifdef WITH_IPAUTH
  355. modparam("permissions", "db_url", DBURL)
  356. modparam("permissions", "db_mode", 1)
  357. #!endif
  358.  
  359. #!endif
  360.  
  361.  
  362. # ----- alias_db params -----
  363. #!ifdef WITH_ALIASDB
  364. modparam("alias_db", "db_url", DBURL)
  365. modparam("alias_db", "use_domain", MULTIDOMAIN)
  366. #!endif
  367.  
  368.  
  369. # ----- domain params -----
  370. #!ifdef WITH_MULTIDOMAIN
  371. modparam("domain", "db_url", DBURL)
  372. # use caching
  373. modparam("domain", "db_mode", 1)
  374. # register callback to match myself condition with domains list
  375. modparam("domain", "register_myself", 1)
  376. #!endif
  377.  
  378.  
  379. #!ifdef WITH_PRESENCE
  380. # ----- presence params -----
  381. modparam("presence", "db_url", DBURL)
  382.  
  383. # ----- presence_xml params -----
  384. modparam("presence_xml", "db_url", DBURL)
  385. modparam("presence_xml", "force_active", 1)
  386. #!endif
  387.  
  388.  
  389. #!ifdef WITH_NAT
  390. # ----- rtpproxy params -----
  391. modparam("rtpproxy", "rtpproxy_sock", "udp:RTP_PROXY_IP:7890")
  392.  
  393. # ----- nathelper params -----
  394. modparam("nathelper", "natping_interval", 30)
  395. modparam("nathelper", "ping_nated_only", 1)
  396. modparam("nathelper", "sipping_bflag", FLB_NATSIPPING)
  397. modparam("nathelper", "sipping_from", "sip:pinger@RTP_PROXY_IP")
  398.  
  399. # params needed for NAT traversal in other modules
  400. modparam("nathelper|registrar", "received_avp", "$avp(RECEIVED)")
  401. modparam("usrloc", "nat_bflag", FLB_NATB)
  402. #!endif
  403.  
  404.  
  405. #!ifdef WITH_TLS
  406. # ----- tls params -----
  407. tcp_connection_lifetime=3610
  408. #modparam("tls", "tls_method", "TLSv1")
  409. #modparam("tls", "certificate", "/home/folder/temp/certs/tlsata.domain.com/cert.pem")
  410. #modparam("tls", "private_key", "/home/folder/temp/certs/tlsata.domain.com/key.pem")
  411. #modparam("tls", "ca_list", "//home/folder/temp/certs/demoCA/cert.pem")
  412. #modparam("tls", "verify_certificate", 1)
  413. #modparam("tls", "require_certificate", 1)
  414. modparam("tls", "config", "/usr/local/etc/kamailio/tls.cfg")
  415. #!endif
  416.  
  417.  
  418. #!ifdef WITH_ANTIFLOOD
  419. # ----- pike params -----
  420. modparam("pike", "sampling_time_unit", 2)
  421. modparam("pike", "reqs_density_per_unit", 16)
  422. modparam("pike", "remove_latency", 4)
  423.  
  424. # ----- htable params -----
  425. # ip ban htable with autoexpire after 5 minutes
  426. modparam("htable", "htable", "ipban=>size=8;autoexpire=300;")
  427. #!endif
  428.  
  429. #!ifdef WITH_XMLRPC
  430. # ----- xmlrpc params -----
  431. modparam("xmlrpc", "route", "XMLRPC");
  432. modparam("xmlrpc", "url_match", "^/RPC")
  433. #!endif
  434.  
  435. ####### Routing Logic ########
  436.  
  437.  
  438. # Main SIP request routing logic
  439. # - processing of any incoming SIP request starts with this route
  440. route {
  441.  
  442. # per request initial checks
  443. route(REQINIT);
  444.  
  445. # NAT detection
  446. route(NAT);
  447.  
  448. # handle requests within SIP dialogs
  449. route(WITHINDLG);
  450.  
  451. ### only initial requests (no To tag)
  452.  
  453. # CANCEL processing
  454. if (is_method("CANCEL"))
  455. {
  456. if (t_check_trans())
  457. t_relay();
  458. exit;
  459. }
  460.  
  461. t_check_trans();
  462.  
  463. # authentication
  464. route(AUTH);
  465.  
  466. # record routing for dialog forming requests (in case they are routed)
  467. # - remove preloaded route headers
  468. remove_hf("Route");
  469. if (is_method("INVITE|SUBSCRIBE"))
  470. record_route();
  471.  
  472. # account only INVITEs
  473. if (is_method("INVITE"))
  474. {
  475. setflag(FLT_ACC); # do accounting
  476. }
  477.  
  478. # dispatch requests to foreign domains
  479. route(SIPOUT);
  480.  
  481. ### requests for my local domains
  482.  
  483. # handle presence related requests
  484. route(PRESENCE);
  485.  
  486. # handle registrations
  487. route(REGISTRAR);
  488.  
  489. if ($rU==$null)
  490. {
  491. # request with no Username in RURI
  492. sl_send_reply("484","Address Incomplete");
  493. exit;
  494. }
  495.  
  496. # dispatch destinations to PSTN
  497. route(PSTN);
  498.  
  499.  
  500. if($rU=~"^111" || $rU=~"^011.*" || $rU=~"^00.*" || $rU=~"^[+].*" )
  501. {
  502.  
  503. if(!cr_route("default", "ata.domain.com", "$rU", "$rU", "call_id")){
  504. sl_send_reply("403", "Not allowed");
  505. } else {
  506.  
  507. setbflag(6); # force rtpproxy by considering the destination
  508. route(1);
  509. }
  510. exit;
  511. }
  512. else
  513. {
  514. xlog("L_ERR","NOT_CARRIERROUTE_time_dbg:method=$rm;time=$Ts;callid=$ci - before cr\n");
  515. route(LOCATION);
  516.  
  517. route(RELAY);
  518. }
  519. }
  520.  
  521.  
  522.  
  523. ############# THIS IS THE GENERIC RELAY ROUTE THAT MUST BE USED ALL THE TIME FOR RELAY
  524. route[1]
  525. {
  526. if (subst_uri('/(sip:.*);nat=yes/\1/')){
  527. setbflag(6);
  528. };
  529.  
  530.  
  531. # apply any NAT changes?
  532. if(isflagset(5)||isbflagset(6)) {
  533. route(4);
  534. }
  535.  
  536.  
  537. #xlog("L_ERR","sending out $rm / $ci | $ru , $du\n");
  538. xlog("L_ERR","time_dbg:method=$rm;time=$Ts;callid=$ci - before t_relay\n");
  539. if (!t_relay()) {
  540. sl_reply_error();
  541. };
  542. exit;
  543. }
  544.  
  545. route[4]
  546. {
  547.  
  548.  
  549. if (is_method("BYE|CANCEL")) {
  550. unforce_rtp_proxy();
  551. } else if (is_method("INVITE")){
  552. if (nat_uac_test("8")) {
  553. force_rtp_proxy();
  554. } else {
  555. force_rtp_proxy();
  556. }
  557. t_on_failure("1");
  558. t_on_reply("1");
  559.  
  560.  
  561. #route(RELAY);
  562. };
  563.  
  564.  
  565. if (isflagset(5))
  566. search_append('Contact:.*sip:[^>[:cntrl:]]*', ';nat=yes');
  567. }
  568.  
  569.  
  570.  
  571.  
  572.  
  573.  
  574.  
  575.  
  576. route[CARRIERROUTE]
  577. {
  578. #!ifdef WITH_NAT
  579. if (check_route_param("nat=yes")) {
  580. setbflag(FLB_NATB);
  581. }
  582. if (isflagset(FLT_NATS) || isbflagset(FLB_NATB)) {
  583. if (is_method("BYE")) {
  584. unforce_rtp_proxy();
  585. } else if (is_method("INVITE")){
  586. force_rtp_proxy();
  587. rewritehost("Y.Y.Y.Y");
  588. }
  589. if (!has_totag()) add_rr_param(";nat=yes");
  590. }
  591. #!endif
  592.  
  593. /* example how to enable some additional event routes */
  594. if (is_method("INVITE")) {
  595. # when routing via usrloc, log the missed calls also
  596. # setflag(FLT_ACCMISSED);
  597.  
  598. #t_on_branch("BRANCH_ONE");
  599. t_on_reply("REPLY_ONE");
  600. t_on_failure("FAIL_ONE");
  601. # t_relay();
  602. }
  603.  
  604. if (!t_relay()) {
  605. sl_reply_error();
  606. }
  607. exit;
  608. # return;
  609.  
  610. }
  611.  
  612.  
  613. route[RELAY] {
  614. #!ifdef WITH_NAT
  615. if (check_route_param("nat=yes")) {
  616. setbflag(FLB_NATB);
  617. }
  618. if (isflagset(FLT_NATS) || isbflagset(FLB_NATB)) {
  619. route(RTPPROXY);
  620. }
  621. #!endif
  622.  
  623. /* example how to enable some additional event routes */
  624. if (is_method("INVITE")) {
  625. #t_on_branch("BRANCH_ONE");
  626. t_on_reply("REPLY_ONE");
  627. t_on_failure("FAIL_ONE");
  628. }
  629.  
  630. if (!t_relay()) {
  631. sl_reply_error();
  632. }
  633. exit;
  634. }
  635.  
  636. # Per SIP request initial checks
  637. route[REQINIT] {
  638. #!ifdef WITH_ANTIFLOOD
  639. # flood dection from same IP and traffic ban for a while
  640. # be sure you exclude checking trusted peers, such as pstn gateways
  641. # - local host excluded (e.g., loop to self)
  642. if(src_ip!=myself)
  643. {
  644. if($sht(ipban=>$si)!=$null)
  645. {
  646. # ip is already blocked
  647. xdbg("request from blocked IP - $rm from $fu (IP:$si:$sp)\n");
  648. exit;
  649. }
  650. if (!pike_check_req())
  651. {
  652. xlog("L_ALERT","ALERT: pike blocking $rm from $fu (IP:$si:$sp)\n");
  653. $sht(ipban=>$si) = 1;
  654. exit;
  655. }
  656. }
  657. #!endif
  658.  
  659. if (!mf_process_maxfwd_header("10")) {
  660. sl_send_reply("483","Too Many Hops");
  661. exit;
  662. }
  663.  
  664. if(!sanity_check("1511", "7"))
  665. {
  666. xlog("Malformed SIP message from $si:$sp\n");
  667. exit;
  668. }
  669. }
  670.  
  671. # Handle requests within SIP dialogs
  672. route[WITHINDLG] {
  673. if (has_totag()) {
  674. # sequential request withing a dialog should
  675. # take the path determined by record-routing
  676. if (loose_route()) {
  677. if (is_method("BYE")) {
  678. setflag(FLT_ACC); # do accounting ...
  679. setflag(FLT_ACCFAILED); # ... even if the transaction fails
  680. }
  681. route(RELAY);
  682. } else {
  683. if (is_method("SUBSCRIBE") && uri == myself) {
  684. # in-dialog subscribe requests
  685. route(PRESENCE);
  686. exit;
  687. }
  688. if ( is_method("ACK") ) {
  689. if ( t_check_trans() ) {
  690. # no loose-route, but stateful ACK;
  691. # must be an ACK after a 487
  692. # or e.g. 404 from upstream server
  693. t_relay();
  694. exit;
  695. } else {
  696. # ACK without matching transaction ... ignore and discard
  697. exit;
  698. }
  699. }
  700. sl_send_reply("404","Not here");
  701. }
  702. exit;
  703. }
  704. }
  705.  
  706. # Handle SIP registrations
  707. route[REGISTRAR] {
  708. if (is_method("REGISTER"))
  709. {
  710. if(isflagset(FLT_NATS))
  711. {
  712. setbflag(FLB_NATB);
  713. # uncomment next line to do SIP NAT pinging
  714. ## setbflag(FLB_NATSIPPING);
  715. }
  716. if (!save("location"))
  717. sl_reply_error();
  718.  
  719. exit;
  720. }
  721. }
  722.  
  723. # USER location service
  724. route[LOCATION] {
  725.  
  726. #!ifdef WITH_ALIASDB
  727. # search in DB-based aliases
  728. alias_db_lookup("dbaliases");
  729. #!endif
  730.  
  731. if (!lookup("location")) {
  732. switch ($rc) {
  733. case -1:
  734. case -3:
  735. t_newtran();
  736. t_reply("404", "Not Found");
  737. exit;
  738. case -2:
  739. sl_send_reply("405", "Method Not Allowed");
  740. exit;
  741. }
  742. }
  743.  
  744. # when routing via usrloc, log the missed calls also
  745. if (is_method("INVITE"))
  746. {
  747. setflag(FLT_ACCMISSED);
  748. }
  749. }
  750.  
  751. # Presence server route
  752. route[PRESENCE] {
  753. if(!is_method("PUBLISH|SUBSCRIBE"))
  754. return;
  755.  
  756. #!ifdef WITH_PRESENCE
  757. if (!t_newtran())
  758. {
  759. sl_reply_error();
  760. exit;
  761. };
  762.  
  763. if(is_method("PUBLISH"))
  764. {
  765. handle_publish();
  766. t_release();
  767. }
  768. else
  769. if( is_method("SUBSCRIBE"))
  770. {
  771. handle_subscribe();
  772. t_release();
  773. }
  774. exit;
  775. #!endif
  776.  
  777. # if presence enabled, this part will not be executed
  778. if (is_method("PUBLISH") || $rU==$null)
  779. {
  780. sl_send_reply("404", "Not here");
  781. exit;
  782. }
  783. return;
  784. }
  785. ############# THIS IS THE GENERIC RELAY ROUTE THAT MUST BE USED ALL THE TIME FOR RELAY
  786.  
  787.  
  788. # Authentication route
  789. route[AUTH] {
  790. #!ifdef WITH_AUTH
  791. if (is_method("REGISTER"))
  792. {
  793. if (is_user_in("From", "blocked")) {
  794. sl_send_reply("403", "Unauthorized, account is disabled");
  795. exit();
  796. }
  797. # authenticate the REGISTER requests (uncomment to enable auth)
  798. if (!www_authorize("$fd", "subscriber"))
  799. {
  800. www_challenge("$fd", "0");
  801. exit;
  802. }
  803. save("location");
  804.  
  805. if ($au!=$tU)
  806. {
  807. sl_send_reply("403","Forbidden auth ID");
  808. exit;
  809. }
  810. } else {
  811.  
  812. #!ifdef WITH_IPAUTH
  813. if(allow_source_address())
  814. {
  815. # source IP allowed
  816. return;
  817. }
  818. #!endif
  819.  
  820. # authenticate if from local subscriber
  821. # if (from_uri==myself)
  822. # {
  823. # if (!proxy_authorize("$fd", "subscriber")) {
  824. # proxy_challenge("$fd", "0");
  825. xlog("L_ERR","proxy_$fd:method=$rm;time=$Ts;callid=$ci - before cr\n");
  826. # exit;
  827. # }
  828. # if (is_method("PUBLISH"))
  829. # {
  830. # if ($au!=$tU) {
  831. # sl_send_reply("403","Forbidden auth ID");
  832. # exit;
  833. # }
  834. # } else {
  835. # if ($au!=$fU) {
  836. # sl_send_reply("403","Forbidden auth ID");
  837. # exit;
  838. # }
  839. # }
  840. #
  841. # consume_credentials();
  842. # # caller authenticated
  843. # } else {
  844. # # caller is not local subscriber, then check if it calls
  845. # # a local destination, otherwise deny, not an open relay here
  846. # if (!uri==myself)
  847. # {
  848. # sl_send_reply("403","Not relaying");
  849. # exit;
  850. # }
  851. # }
  852. }
  853. #!endif
  854. return;
  855. }
  856.  
  857. # Caller NAT detection route
  858. route[NAT] {
  859. #!ifdef WITH_NAT
  860. force_rport();
  861. if (nat_uac_test("19")) {
  862. if (method=="REGISTER") {
  863. fix_nated_register();
  864. } else {
  865. fix_nated_contact();
  866. }
  867. setflag(FLT_NATS);
  868. }
  869. #!endif
  870. return;
  871. }
  872.  
  873. # RTPProxy control
  874. route[RTPPROXY] {
  875. #!ifdef WITH_NAT
  876. if (is_method("BYE")) {
  877. unforce_rtp_proxy();
  878. } else if (is_method("INVITE")){
  879. force_rtp_proxy();
  880. }
  881. if (!has_totag()) add_rr_param(";nat=yes");
  882. #!endif
  883. return;
  884. }
  885.  
  886. # Routing to foreign domains
  887. route[SIPOUT] {
  888. if (!uri==myself)
  889. {
  890. append_hf("P-hint: outbound\r\n");
  891. route(RELAY);
  892. }
  893. }
  894.  
  895. # PSTN GW routing
  896. route[PSTN] {
  897. #!ifdef WITH_PSTN
  898. # check if PSTN GW IP is defined
  899. if (strempty($sel(cfg_get.pstn.gw_ip))) {
  900. xlog("SCRIPT: PSTN rotuing enabled but pstn.gw_ip not defined\n");
  901. return;
  902. }
  903.  
  904. # route to PSTN dialed numbers starting with '+' or '00'
  905. # (international format)
  906. # - update the condition to match your dialing rules for PSTN routing
  907. if(!($rU=~"^(\+|00)[1-9][0-9]{3,20}$"))
  908. return;
  909.  
  910. # only local users allowed to call
  911. if(from_uri!=myself) {
  912. sl_send_reply("403", "Not Allowed");
  913. exit;
  914. }
  915.  
  916. $ru = "sip:" + $rU + "@" + $sel(cfg_get.pstn.gw_ip);
  917.  
  918. route(RELAY);
  919. exit;
  920. #!endif
  921.  
  922. return;
  923. }
  924.  
  925. # XMLRPC routing
  926. #!ifdef WITH_XMLRPC
  927. route[XMLRPC]
  928. {
  929. # allow XMLRPC from localhost
  930. if ((method=="POST" || method=="GET")
  931. && (src_ip==127.0.0.1)) {
  932. # close connection only for xmlrpclib user agents (there is a bug in
  933. # xmlrpclib: it waits for EOF before interpreting the response).
  934. if ($hdr(User-Agent) =~ "xmlrpclib")
  935. set_reply_close();
  936. set_reply_no_connect();
  937. dispatch_rpc();
  938. exit;
  939. }
  940. send_reply("403", "Forbidden");
  941. exit;
  942. }
  943. #!endif
  944.  
  945. # Sample branch router
  946. branch_route[BRANCH_ONE] {
  947. xdbg("new branch at $ru\n");
  948. }
  949.  
  950. # Sample onreply route
  951. onreply_route[REPLY_ONE] {
  952. xdbg("incoming reply\n");
  953. #!ifdef WITH_NAT
  954. if ((isflagset(FLT_NATS) || isbflagset(FLB_NATB))
  955. && status=~"(183)|(2[0-9][0-9])") {
  956. force_rtp_proxy();
  957. }
  958. if (isbflagset("6")) {
  959. fix_nated_contact();
  960. }
  961. #!endif
  962. }
  963.  
  964.  
  965.  
  966.  
  967.  
  968.  
  969.  
  970.  
  971.  
  972. # Sample failure route
  973. failure_route[FAIL_ONE] {
  974. #!ifdef WITH_NAT
  975. if (is_method("INVITE")
  976. && (isbflagset(FLB_NATB) || isflagset(FLT_NATS))) {
  977. unforce_rtp_proxy();
  978. }
  979. #!endif
  980.  
  981. if (t_is_canceled()) {
  982. exit;
  983. }
  984.  
  985. # uncomment the following lines if you want to block client
  986. # redirect based on 3xx replies.
  987. ##if (t_check_status("3[0-9][0-9]")) {
  988. ##t_reply("404","Not found");
  989. ## exit;
  990. ##}
  991.  
  992. # uncomment the following lines if you want to redirect the failed
  993. # calls to a different new destination
  994. ##if (t_check_status("486|408")) {
  995. ## sethostport("192.168.2.100:5060");
  996. ## append_branch();
  997. ## # do not set the missed call flag again
  998. ## t_relay();
  999. ##}
  1000. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement