Advertisement
Guest User

Untitled

a guest
Dec 26th, 2016
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.97 KB | None | 0 0
  1. #!KAMAILIO
  2. #
  3. # Kamailio (OpenSER) SIP Server v4.3 - 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/wiki/
  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 nat traversal execute:
  36. # - define WITH_NAT
  37. # - install RTPProxy: http://www.rtpproxy.org
  38. # - start RTPProxy:
  39. # rtpproxy -l _your_public_ip_ -s udp:localhost:7722
  40. # - option for NAT SIP OPTIONS keepalives: WITH_NATSIPPING
  41. #
  42. # *** To enable TLS support execute:
  43. # - adjust CFGDIR/tls.cfg as needed
  44. # - define WITH_TLS
  45. #
  46. # *** To enhance accounting execute:
  47. # - enable mysql
  48. # - define WITH_ACCDB
  49. # - add following columns to database
  50.  
  51.  
  52. #!define WITH_MYSQL
  53. #!define WITH_AUTH
  54. #!define WITH_USRLOCDB
  55. #!define WITH_DEBUG
  56.  
  57. #!ifdef ACCDB_COMMENT
  58. ALTER TABLE acc ADD COLUMN src_user VARCHAR(64) NOT NULL DEFAULT '';
  59. ALTER TABLE acc ADD COLUMN src_domain VARCHAR(128) NOT NULL DEFAULT '';
  60. ALTER TABLE acc ADD COLUMN src_ip varchar(64) NOT NULL default '';
  61. ALTER TABLE acc ADD COLUMN dst_ouser VARCHAR(64) NOT NULL DEFAULT '';
  62. ALTER TABLE acc ADD COLUMN dst_user VARCHAR(64) NOT NULL DEFAULT '';
  63. ALTER TABLE acc ADD COLUMN dst_domain VARCHAR(128) NOT NULL DEFAULT '';
  64. ALTER TABLE missed_calls ADD COLUMN src_user VARCHAR(64) NOT NULL DEFAULT '';
  65. ALTER TABLE missed_calls ADD COLUMN src_domain VARCHAR(128) NOT NULL DEFAULT '';
  66. ALTER TABLE missed_calls ADD COLUMN src_ip varchar(64) NOT NULL default '';
  67. ALTER TABLE missed_calls ADD COLUMN dst_ouser VARCHAR(64) NOT NULL DEFAULT '';
  68. ALTER TABLE missed_calls ADD COLUMN dst_user VARCHAR(64) NOT NULL DEFAULT '';
  69. ALTER TABLE missed_calls ADD COLUMN dst_domain VARCHAR(128) NOT NULL DEFAULT '';
  70. #!endif
  71.  
  72. ####### Include Local Config If Exists #########
  73. import_file "kamailio-local.cfg"
  74.  
  75. ####### Defined Values #########
  76.  
  77. # *** Value defines - IDs used later in config
  78. #!ifdef WITH_MYSQL
  79. # - database URL - used to connect to database server by modules such
  80. # as: auth_db, acc, usrloc, a.s.o.
  81. #!ifndef DBURL
  82. #!define DBURL "mysql://kamailio:kamailiorw@localhost/kamailio"
  83. #!endif
  84. #!endif
  85. #!define MULTIDOMAIN 0
  86.  
  87. # - flags
  88. # FLT_ - per transaction (message) flags
  89. # FLB_ - per branch flags
  90. #!define FLT_ACC 1
  91. #!define FLT_ACCMISSED 2
  92. #!define FLT_ACCFAILED 3
  93. #!define FLT_NATS 5
  94.  
  95. #!define FLB_NATB 6
  96. #!define FLB_NATSIPPING 7
  97.  
  98. ####### Global Parameters #########
  99.  
  100. ### LOG Levels: 3=DBG, 2=INFO, 1=NOTICE, 0=WARN, -1=ERR
  101. #!ifdef WITH_DEBUG
  102. debug=4
  103. log_stderror=yes
  104. #!else
  105. debug=2
  106. log_stderror=no
  107. #!endif
  108.  
  109. memdbg=5
  110. memlog=5
  111.  
  112. log_facility=LOG_LOCAL0
  113.  
  114. fork=yes
  115. children=4
  116. async_workers=4
  117.  
  118. /* uncomment the next line to disable TCP (default on) */
  119. disable_tcp=yes
  120.  
  121. /* uncomment the next line to disable the auto discovery of local aliases
  122. based on reverse DNS on IPs (default on) */
  123. auto_aliases=no
  124.  
  125.  
  126. /* uncomment and configure the following line if you want Kamailio to
  127. bind on a specific interface/port/proto (default bind on all available) */
  128. listen=udp:172.31.13.113:5060 advertise ec2-35-166-152-104.us-west-2.compute.amazonaws.com:5060
  129.  
  130.  
  131. # life time of TCP connection when there is no traffic
  132. # - a bit higher than registration expires to cope with UA behind NAT
  133. tcp_connection_lifetime=3605
  134.  
  135.  
  136. ####### Modules Section ########
  137.  
  138. # set paths to location of modules (to sources or installation folders)
  139. #!ifdef WITH_SRCPATH
  140. mpath="modules"
  141. #!else
  142. mpath="/usr/local/lib64/kamailio/modules/"
  143. #!endif
  144.  
  145. #!ifdef WITH_MYSQL
  146. loadmodule "db_mysql.so"
  147. #!endif
  148.  
  149. #loadmodule "tcpops.so"
  150. loadmodule "mi_fifo.so"
  151. loadmodule "kex.so"
  152. loadmodule "corex.so"
  153. loadmodule "tm.so"
  154. loadmodule "tmx.so"
  155. loadmodule "sl.so"
  156. loadmodule "rr.so"
  157. loadmodule "pv.so"
  158. loadmodule "maxfwd.so"
  159. loadmodule "usrloc.so"
  160. loadmodule "registrar.so"
  161. loadmodule "textops.so"
  162. loadmodule "siputils.so"
  163. loadmodule "xlog.so"
  164. loadmodule "sanity.so"
  165. loadmodule "ctl.so"
  166. loadmodule "cfg_rpc.so"
  167. loadmodule "mi_rpc.so"
  168. loadmodule "acc.so"
  169. loadmodule "json.so"
  170.  
  171.  
  172. #!ifdef WITH_AUTH
  173. loadmodule "auth.so"
  174. loadmodule "auth_db.so"
  175. #!ifdef WITH_IPAUTH
  176. loadmodule "permissions.so"
  177. #!endif
  178. #!endif
  179.  
  180. #!ifdef WITH_NAT
  181. loadmodule "nathelper.so"
  182. loadmodule "rtpproxy.so"
  183. #!endif
  184.  
  185.  
  186. #!ifdef WITH_DEBUG
  187. loadmodule "debugger.so"
  188. #!endif
  189.  
  190.  
  191.  
  192. #!ifdef WITH_PRESENCE
  193. loadmodule "presence.so"
  194. loadmodule "presence_xml.so"
  195. #!endif
  196.  
  197.  
  198.  
  199. # ----- mi_fifo params -----
  200. #modparam("mi_fifo", "fifo_name", "/var/run/kamailio/kamailio_fifo")
  201.  
  202. # ----- ctl params -----
  203. #modparam("ctl", "binrpc", "unix:/var/run/kamailio/kamailio_ctl")
  204.  
  205. # ----- tm params -----
  206. # auto-discard branches from previous serial forking leg
  207. modparam("tm", "failure_reply_mode", 3)
  208. # default retransmission timeout: 30sec
  209. modparam("tm", "fr_timer", 60000)
  210. # default invite retransmission timeout after 1xx: 120sec
  211. modparam("tm", "fr_inv_timer", 120000)
  212.  
  213.  
  214. # ----- rr params -----
  215. # add value to ;lr param to cope with most of the UAs
  216. modparam("rr", "enable_full_lr", 1)
  217. # do not append from tag to the RR (no need for this script)
  218. modparam("rr", "append_fromtag", 0)
  219.  
  220.  
  221. # ----- registrar params -----
  222. modparam("registrar", "method_filtering", 1)
  223. /* uncomment the next line to disable parallel forking via location */
  224. # modparam("registrar", "append_branches", 0)
  225. /* uncomment the next line not to allow more than 10 contacts per AOR */
  226. #modparam("registrar", "max_contacts", 10)
  227. # max value for expires of registrations
  228. modparam("registrar", "max_expires", 3600)
  229. # set it to 1 to enable GRUU
  230. modparam("registrar", "gruu_enabled", 0)
  231.  
  232.  
  233. # ----- acc params -----
  234. /* what special events should be accounted ? */
  235. modparam("acc", "early_media", 0)
  236. modparam("acc", "report_ack", 0)
  237. modparam("acc", "report_cancels", 0)
  238. /* by default ww do not adjust the direct of the sequential requests.
  239. if you enable this parameter, be sure the enable "append_fromtag"
  240. in "rr" module */
  241. modparam("acc", "detect_direction", 0)
  242. /* account triggers (flags) */
  243. modparam("acc", "log_flag", FLT_ACC)
  244. modparam("acc", "log_missed_flag", FLT_ACCMISSED)
  245. modparam("acc", "log_extra",
  246. "src_user=$fU;src_domain=$fd;src_ip=$si;"
  247. "dst_ouser=$tU;dst_user=$rU;dst_domain=$rd")
  248. modparam("acc", "failed_transaction_flag", FLT_ACCFAILED)
  249. /* enhanced DB accounting */
  250. #!ifdef WITH_ACCDB
  251. modparam("acc", "db_flag", FLT_ACC)
  252. modparam("acc", "db_missed_flag", FLT_ACCMISSED)
  253. modparam("acc", "db_url", DBURL)
  254. modparam("acc", "db_extra",
  255. "src_user=$fU;src_domain=$fd;src_ip=$si;"
  256. "dst_ouser=$tU;dst_user=$rU;dst_domain=$rd")
  257. #!endif
  258.  
  259.  
  260. # ----- usrloc params -----
  261. /* enable DB persistency for location entries */
  262. #!ifdef WITH_USRLOCDB
  263. modparam("usrloc", "db_url", DBURL)
  264. modparam("usrloc", "db_mode", 3)
  265. modparam("usrloc", "use_domain", MULTIDOMAIN)
  266. modparam("usrloc", "timer_interval", 5)
  267. #modparam("usrloc", "handle_lost_tcp", 1)
  268. #!endif
  269.  
  270.  
  271. # ----- auth_db params -----
  272. #!ifdef WITH_AUTH
  273. modparam("auth_db", "db_url", DBURL)
  274. modparam("auth_db", "calculate_ha1", 0)
  275. modparam("auth_db", "password_column", "ha1")
  276. modparam("auth_db", "load_credentials", "")
  277. modparam("auth_db", "use_domain", MULTIDOMAIN)
  278.  
  279. # ----- permissions params -----
  280. #!ifdef WITH_IPAUTH
  281. modparam("permissions", "db_url", DBURL)
  282. modparam("permissions", "db_mode", 1)
  283. #!endif
  284.  
  285. #!endif
  286.  
  287.  
  288. #!ifdef WITH_NAT
  289. # ----- rtpproxy params -----
  290. modparam("rtpproxy", "rtpproxy_sock", "udp:127.0.0.1:7722")
  291.  
  292. # ----- nathelper params -----
  293. modparam("nathelper", "natping_interval", 30)
  294. modparam("nathelper", "ping_nated_only", 1)
  295. modparam("nathelper", "sipping_bflag", FLB_NATSIPPING)
  296. modparam("nathelper", "sipping_from", "sip:pinger@kamailio.org")
  297.  
  298. # params needed for NAT traversal in other modules
  299. modparam("nathelper|registrar", "received_avp", "$avp(RECEIVED)")
  300. modparam("usrloc", "nat_bflag", FLB_NATB)
  301. #!endif
  302.  
  303.  
  304. #!ifdef WITH_DEBUG
  305. # ----- debugger params -----
  306. modparam("debugger", "cfgtrace", 1)
  307. #!endif
  308.  
  309.  
  310.  
  311. #!ifdef WITH_PRESENCE
  312. # ----- presence params -----
  313. modparam("presence", "db_url", DBURL)
  314.  
  315. # ----- presence_xml params -----
  316. modparam("presence_xml", "db_url", DBURL)
  317. modparam("presence_xml", "force_active", 1)
  318. #modparam("presence_xml", "integrated_xcap_server", 1)
  319. #!endif
  320.  
  321.  
  322. ####### Routing Logic ########
  323.  
  324.  
  325. # Main SIP request routing logic
  326. # - processing of any incoming SIP request starts with this route
  327. # - note: this is the same as route { ... }
  328. request_route {
  329.  
  330. # per request initial checks
  331. route(REQINIT);
  332.  
  333. # NAT detection
  334. route(NATDETECT);
  335.  
  336. # CANCEL processing
  337. if (is_method("CANCEL")) {
  338. if (t_check_trans()) {
  339. route(RELAY);
  340. }
  341. exit;
  342. }
  343.  
  344.  
  345.  
  346. # handle requests within SIP dialogs
  347. route(WITHINDLG);
  348.  
  349. ### only initial requests (no To tag)
  350.  
  351. # handle retransmissions
  352. if(t_precheck_trans()) {
  353. t_check_trans();
  354. exit;
  355. }
  356. t_check_trans();
  357.  
  358. # authentication
  359. route(AUTH);
  360.  
  361. # record routing for dialog forming requests (in case they are routed)
  362. # - remove preloaded route headers
  363. remove_hf("Route");
  364. if (is_method("INVITE|SUBSCRIBE")) record_route();
  365.  
  366. # account only INVITEs
  367. if (is_method("INVITE")) {
  368. setflag(FLT_ACC); # do accounting
  369. }
  370.  
  371.  
  372. ### requests for my local domains
  373.  
  374. # handle presence related requests
  375. route(PRESENCE);
  376.  
  377. # handle registrations
  378. route(REGISTRAR);
  379.  
  380. if ($rU==$null) {
  381. # request with no Username in RURI
  382. sl_send_reply("484","Address Incomplete");
  383. exit;
  384. }
  385.  
  386. # user location service
  387. route(LOCATION);
  388.  
  389. route(RELAY);
  390. }
  391.  
  392.  
  393. route[RELAY] {
  394.  
  395. # enable additional event routes for forwarded requests
  396. # - serial forking, RTP relaying handling, a.s.o.
  397. if (is_method("INVITE|BYE|SUBSCRIBE|UPDATE")) {
  398. if(!t_is_set("branch_route")) t_on_branch("MANAGE_BRANCH");
  399. }
  400. if (is_method("INVITE|SUBSCRIBE|UPDATE")) {
  401. if(!t_is_set("onreply_route")) t_on_reply("MANAGE_REPLY");
  402. }
  403. if (is_method("INVITE")) {
  404. if(!t_is_set("failure_route")) t_on_failure("MANAGE_FAILURE");
  405. }
  406.  
  407. if (!t_relay()) {
  408. sl_reply_error();
  409. }
  410. exit;
  411. }
  412.  
  413. # Per SIP request initial checks
  414. route[REQINIT] {
  415.  
  416. #!ifdef WITH_ANTIFLOOD
  417. # flood dection from same IP and traffic ban for a while
  418. # be sure you exclude checking trusted peers, such as pstn gateways
  419. # - local host excluded (e.g., loop to self)
  420. if(src_ip!=myself) {
  421. if($sht(ipban=>$si)!=$null) {
  422. # ip is already blocked
  423. xdbg("request from blocked IP - $rm from $fu (IP:$si:$sp)\n");
  424. exit;
  425. }
  426. if (!pike_check_req()) {
  427. xlog("L_ALERT","ALERT: pike blocking $rm from $fu (IP:$si:$sp)\n");
  428. $sht(ipban=>$si) = 1;
  429. exit;
  430. }
  431. }
  432. if($ua =~ "friendly-scanner") {
  433. sl_send_reply("200", "OK");
  434. exit;
  435. }
  436. #!endif
  437.  
  438. if (!mf_process_maxfwd_header("10")) {
  439. sl_send_reply("483","Too Many Hops");
  440. exit;
  441. }
  442.  
  443. if(is_method("OPTIONS") && uri==myself && $rU==$null) {
  444. sl_send_reply("200","Keepalive");
  445. exit;
  446. }
  447.  
  448. if(!sanity_check("1511", "7")) {
  449. xlog("Malformed SIP message from $si:$sp\n");
  450. exit;
  451. }
  452. }
  453.  
  454. # Handle requests within SIP dialogs
  455. route[WITHINDLG] {
  456. if (!has_totag()) return;
  457.  
  458. # sequential request withing a dialog should
  459. # take the path determined by record-routing
  460. if (loose_route()) {
  461. route(DLGURI);
  462. if (is_method("BYE")) {
  463. setflag(FLT_ACC); # do accounting ...
  464. setflag(FLT_ACCFAILED); # ... even if the transaction fails
  465. }
  466. else if ( is_method("ACK") ) {
  467. # ACK is forwarded statelessy
  468. route(NATMANAGE);
  469. }
  470. else if ( is_method("NOTIFY") ) {
  471. # Add Record-Route for in-dialog NOTIFY as per RFC 6665.
  472. record_route();
  473. }
  474. route(RELAY);
  475. exit;
  476. }
  477. else{
  478. if (is_method("SUBSCRIBE") && uri == myself) {
  479. # in-dialog subscribe requests
  480.  
  481. route(PRESENCE);
  482.  
  483. exit;
  484. }
  485. if ( is_method("ACK") ) {
  486. if ( t_check_trans() ) {
  487. # no loose-route, but stateful ACK;
  488. # must be an ACK after a 487
  489. # or e.g. 404 from upstream server
  490. route(RELAY);
  491. exit;
  492. } else {
  493. # ACK without matching transaction ... ignore and discard
  494. exit;
  495. }
  496. }
  497. }
  498.  
  499. sl_send_reply("404", "Not here");
  500. exit;
  501. }
  502.  
  503. # Handle SIP registrations
  504. route[REGISTRAR] {
  505. if (!is_method("REGISTER")) return;
  506. if(isflagset(FLT_NATS)) {
  507. setbflag(FLB_NATB);
  508.  
  509. #!ifdef WITH_NATSIPPING
  510. # do SIP NAT pinging
  511. setbflag(FLB_NATSIPPING);
  512. #!endif
  513. }
  514. if (!save("location")){
  515. sl_reply_error();
  516. }
  517.  
  518. exit;
  519. }
  520.  
  521. # User location service
  522. route[LOCATION] {
  523.  
  524.  
  525. if (!lookup("location")) {
  526. $var(rc) = $rc;
  527.  
  528. t_newtran();
  529. switch ($var(rc)) {
  530. case -1:
  531. case -3:
  532. send_reply("404", "Not Found");
  533. exit;
  534. case -2:
  535. send_reply("405", "Method Not Allowed");
  536. exit;
  537. }
  538. }
  539.  
  540. # when routing via usrloc, log the missed calls also
  541. if (is_method("INVITE")) {
  542. setflag(FLT_ACCMISSED);
  543. }
  544.  
  545. route(RELAY);
  546. exit;
  547. }
  548.  
  549.  
  550. # IP authorization and user uthentication
  551. route[AUTH] {
  552. #!ifdef WITH_AUTH
  553.  
  554. #!ifdef WITH_IPAUTH
  555. if((!is_method("REGISTER")) && allow_source_address()) {
  556. # source IP allowed
  557. return;
  558. }
  559. #!endif
  560.  
  561.  
  562. if (is_method("REGISTER") || from_uri==myself) {
  563. # authenticate requests
  564. if (!auth_check("$fd", "subscriber", "1")) {
  565. auth_challenge("$fd", "0");
  566. exit;
  567. }
  568. # user authenticated - remove auth header
  569. if(!is_method("REGISTER|PUBLISH")){
  570. consume_credentials();
  571. }
  572. }
  573.  
  574. #!endif
  575.  
  576. return;
  577. }
  578.  
  579. # Caller NAT detection
  580. route[NATDETECT] {
  581. #!ifdef WITH_NAT
  582. force_rport();
  583. if (nat_uac_test("19")) {
  584. if (is_method("REGISTER")) {
  585. fix_nated_register();
  586. } else {
  587. if(is_first_hop()){
  588. set_contact_alias();
  589. }
  590. }
  591. setflag(FLT_NATS);
  592. }
  593. #!endif
  594. return;
  595. }
  596.  
  597. # RTPProxy control
  598. route[NATMANAGE] {
  599. #!ifdef WITH_NAT
  600. if (is_request()) {
  601. if(has_totag()) {
  602. if(check_route_param("nat=yes")) {
  603. setbflag(FLB_NATB);
  604. }
  605. }
  606. }
  607.  
  608. if (!(isflagset(FLT_NATS) || isbflagset(FLB_NATB)))
  609. return;
  610.  
  611. rtpproxy_manage("co");
  612.  
  613. if (is_request()) {
  614. if (!has_totag()) {
  615. if(t_is_branch_route()) {
  616. add_rr_param(";nat=yes");
  617. }
  618. }
  619. }
  620.  
  621. if (is_reply()) {
  622. if(isbflagset(FLB_NATB)) {
  623. set_contact_alias();
  624. }
  625. }
  626. #!endif
  627.  
  628. return;
  629. }
  630.  
  631. # URI update for dialog requests
  632. route[DLGURI] {
  633. #!ifdef WITH_NAT
  634. if(!isdsturiset()) {
  635. handle_ruri_alias();
  636. }
  637. #!endif
  638.  
  639. return;
  640. }
  641.  
  642.  
  643. # Manage outgoing branches
  644. branch_route[MANAGE_BRANCH] {
  645. xdbg("new branch [$T_branch_idx] to $ru\n");
  646. route(NATMANAGE);
  647. }
  648.  
  649. # Manage incoming replies
  650. onreply_route[MANAGE_REPLY] {
  651. if(status=~"[12][0-9][0-9]")
  652. route(NATMANAGE);
  653. }
  654.  
  655. # Manage failure routing cases
  656. failure_route[MANAGE_FAILURE] {
  657. xlog('enter failure route\n');
  658.  
  659. if (t_branch_timeout()){
  660. xdbg("t_branch_timeout\n");
  661. }
  662.  
  663. if (t_is_expired()){
  664. xdbg("t_is_expired\n");
  665. }
  666.  
  667. route(NATMANAGE);
  668.  
  669. if (t_is_canceled()) {
  670. exit;
  671. }
  672.  
  673. }
  674.  
  675.  
  676.  
  677.  
  678. # Presence server route
  679. route[PRESENCE] {
  680. if(!is_method("PUBLISH|SUBSCRIBE")) return;
  681.  
  682. #!ifdef WITH_PRESENCE
  683. if (!t_newtran())
  684. {
  685. sl_reply_error();
  686. exit;
  687. }
  688.  
  689. if(is_method("PUBLISH"))
  690. {
  691. xlog("publish message");
  692. handle_publish();
  693. t_release();
  694. }
  695. else if( is_method("SUBSCRIBE"))
  696. {
  697. xlog("subscribe message");
  698. handle_subscribe();
  699. t_release();
  700. }
  701. exit;
  702. #!endif
  703.  
  704. # if presence enabled, this part will not be executed
  705. if (is_method("PUBLISH") || $rU==$null)
  706. {
  707. sl_send_reply("404", "Not here");
  708. exit;
  709. }
  710. return;
  711. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement