Advertisement
Guest User

Untitled

a guest
Oct 10th, 2012
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 19.72 KB | None | 0 0
  1. #!KAMAILIO
  2. #!define WITH_xHTTP
  3. #!define WITH_xHTTPRPC
  4. #!define WITH_EXEC
  5. #!define WITH_ANTIFLOOD
  6. #!define WITH_NAT
  7.  
  8. # Kamailio (OpenSER) SIP Server v3.3 - default configuration script
  9. # - web: http://www.kamailio.org
  10. # - git: http://sip-router.org
  11. #
  12. # Direct your questions about this file to: <sr-users@lists.sip-router.org>
  13. #
  14. # Refer to the Core CookBook at http://www.kamailio.org/dokuwiki/doku.php
  15. # for an explanation of possible statements, functions and parameters.ddress Incomplete
  16. #
  17. # Several features can be enabled using '#!define WITH_FEATURE' directives:
  18. #
  19. # *** To run in debug mode:
  20. # - define WITH_DEBUG
  21. #
  22. # *** To enable mysql:
  23. # - define WITH_MYSQL
  24. #
  25. # *** To enable authentication execute:
  26. # - enable mysql
  27. # - define WITH_AUTH
  28. # - add users using 'kamctl'
  29. #
  30. # *** To enable IP authentication execute:
  31. # - enable mysql
  32. # - enable authentication
  33. # - define WITH_IPAUTH
  34. # - add IP addresses with group id '1' to 'address' table
  35. #
  36. # *** To enable persistent user location execute:
  37. # - enable mysql
  38. # - define WITH_USRLOCDB
  39. #
  40. # *** To enable presence server execute:
  41. # - enable mysql
  42. # - define WITH_PRESENCE
  43. #
  44. # *** To enable nat traversal execute:
  45. # - define WITH_NAT
  46. # - install RTPProxy: http://www.rtpproxy.org
  47. # - start RTPProxy:
  48. # rtpproxy -l _your_public_ip_ -s udp:localhost:7722
  49. #
  50. # *** To enable PSTN gateway routing execute:
  51. # - define WITH_PSTN
  52. # - set the value of pstn.gw_ip
  53. # - check route[PSTN] for regexp routing condition
  54. #
  55. # *** To enable database aliases lookup execute:
  56. # - enable mysql
  57. # - define WITH_ALIASDB
  58. #
  59. # *** To enable speed dial lookup execute:
  60. # - enable mysql
  61. # - define WITH_SPEEDDIAL
  62. #
  63. # *** To enable multi-domain support execute:
  64. # - enable mysql
  65. # - define WITH_MULTIDOMAIN
  66. #
  67. # *** To enable TLS support execute:
  68. # - adjust CFGDIR/tls.cfg as needed
  69. # - define WITH_TLS
  70. #
  71. # *** To enable XMLRPC support execute:
  72. # - define WITH_XMLRPC
  73. # - adjust route[XMLRPC] for access policy
  74. #
  75. # *** To enable anti-flood detection execute:
  76. # - adjust pike and htable=>ipban settings as needed (default is
  77. # block if more than 16 requests in 2 seconds and ban for 300 seconds)
  78. # - define WITH_ANTIFLOOD
  79. #
  80. # *** To block 3XX redirect replies execute:
  81. # - define WITH_BLOCK3XX
  82. #
  83. # *** To enable VoiceMail routing execute:
  84. # - define WITH_VOICEMAIL
  85. # - set the value of voicemail.srv_ip
  86. # - adjust the value of voicemail.srv_port
  87. #
  88. # *** To enhance accounting execute:
  89. # - enable mysql
  90. # - define WITH_ACCDB
  91. # - add following columns to database
  92. #!ifdef ACCDB_COMMENT
  93. ALTER TABLE acc ADD COLUMN src_user VARCHAR(64) NOT NULL DEFAULT '';
  94. ALTER TABLE acc ADD COLUMN src_domain VARCHAR(128) NOT NULL DEFAULT '';
  95. ALTER TABLE acc ADD COLUMN src_ip varchar(64) NOT NULL default '';
  96. ALTER TABLE acc ADD COLUMN dst_ouser VARCHAR(64) NOT NULL DEFAULT '';
  97. ALTER TABLE acc ADD COLUMN dst_user VARCHAR(64) NOT NULL DEFAULT '';
  98. ALTER TABLE acc ADD COLUMN dst_domain VARCHAR(128) NOT NULL DEFAULT '';
  99. ALTER TABLE missed_calls ADD COLUMN src_user VARCHAR(64) NOT NULL DEFAULT '';
  100. ALTER TABLE missed_calls ADD COLUMN src_domain VARCHAR(128) NOT NULL DEFAULT '';
  101. ALTER TABLE missed_calls ADD COLUMN src_ip varchar(64) NOT NULL default '';
  102. ALTER TABLE missed_calls ADD COLUMN dst_ouser VARCHAR(64) NOT NULL DEFAULT '';
  103. ALTER TABLE missed_calls ADD COLUMN dst_user VARCHAR(64) NOT NULL DEFAULT '';
  104. ALTER TABLE missed_calls ADD COLUMN dst_domain VARCHAR(128) NOT NULL DEFAULT '';
  105. #!endif
  106.  
  107. ####### Defined Values #########
  108.  
  109. # *** Value defines - IDs used later in config
  110. #!ifdef WITH_MYSQL
  111. # - database URL - used to connect to database server by modules such
  112. # as: auth_db, acc, usrloc, a.s.o.
  113. #!define DBURL "mysql://kamailio:XXXXXXXXX@localhost/kamailio"
  114. #!endif
  115. #!ifdef WITH_MULTIDOMAIN
  116. # - the value for 'use_domain' parameters
  117. #!define MULTIDOMAIN 1
  118. #!else
  119. #!define MULTIDOMAIN 0
  120. #!endif
  121.  
  122. # - flags
  123. # FLT_ - per transaction (message) flags
  124. # FLB_ - per branch flags
  125. #!define FLT_ACC 1
  126. #!define FLT_ACCMISSED 2
  127. #!define FLT_ACCFAILED 3
  128. #!define FLT_NATS 5
  129.  
  130. #!define FLB_NATB 6
  131. #!define FLB_NATSIPPING 7
  132.  
  133. #!define FLT_DIALOG 4
  134.  
  135. ####### Global Parameters #########
  136.  
  137. #!ifdef WITH_DEBUG
  138. debug=4
  139. log_stderror=yes
  140. #!else
  141. debug=2
  142. log_stderror=no
  143. #!endif
  144.  
  145. memdbg=5
  146. memlog=5
  147.  
  148. log_facility=LOG_LOCAL6
  149.  
  150. fork=yes
  151. children=4
  152.  
  153. /* uncomment the next line to disable TCP (default on) */
  154. #disable_tcp=yes
  155.  
  156. /* uncomment the next line to disable the auto discovery of local aliases
  157. based on reverse DNS on IPs (default on) */
  158. #auto_aliases=no
  159.  
  160. /* add local domain aliases */
  161. #alias="sip.myd
  162. alias=IP_PUBLICA_ROUTER:5060
  163.  
  164. /* uncomment and configure the following line if you want Kamailio to
  165. bind on a specific interface/port/proto (default bind on all available) */
  166. listen=udp:IP_PUBLICA_ROUTER:5060
  167. listen=udp:IP_PRIVADA_KAMAILIO:5060
  168.  
  169.  
  170. #!ifdef WITH_xHTTP
  171. listen=tcp:127.0.0.1:80
  172. #!endif
  173. /* port to listen to
  174. * - can be specified more than once if needed to listen on many ports */
  175. port=5060
  176.  
  177. advertised_address="IP_PUBLICA_ROUTER"
  178.  
  179. #!ifdef WITH_TLS
  180. enable_tls=yes
  181. #!endif
  182.  
  183. # life time of TCP connection when there is no traffic
  184. # - a bit higher than registration expires to cope with UA behind NAT
  185. tcp_connection_lifetime=3605
  186.  
  187. #!ifdef WITH_xHTTP
  188. #xHTTP Module conf: the core must be configured to allow incoming requests without content length header
  189. tcp_accept_no_cl=yes
  190. #!endif
  191.  
  192. #Server Header Value for replies generated by Kamailio.
  193. #server_header="User-Agent: SBC "
  194.  
  195. server_signature=no
  196.  
  197. ####### Custom Parameters #########
  198.  
  199. # These parameters can be modified runtime via RPC interface
  200. # - see the documentation of 'cfg_rpc' module.
  201. #
  202. # Format: group.id = value 'desc' description
  203. # Access: $sel(cfg_get.group.id) or @cfg_get.group.id
  204. #
  205.  
  206. #!ifdef WITH_PSTN
  207. # PSTN GW Routing
  208. #
  209. # - pstn.gw_ip: valid IP or hostname as string value, example:
  210. # pstn.gw_ip = "10.0.0.101" desc "My PSTN GW Address"
  211. #
  212. # - by default is empty to avoid misrouting
  213. pstn.gw_ip = "" desc "PSTN GW Address"
  214. #!endif
  215.  
  216. #!ifdef WITH_VOICEMAIL
  217. # VoiceMail Routing on offline, busy or no answer
  218. #
  219. # - by default Voicemail server IP is empty to avoid misrouting
  220. voicemail.srv_ip = "" desc "VoiceMail IP Address"
  221. voicemail.srv_port = "5060" desc "VoiceMail Port"
  222. #!endif
  223.  
  224. kamailio.bindip = "IP_PUBLICA_ROUTER" desc "Kamailio IP Address"
  225. kamailio.bindport = "5060" desc "Kamailio Port"
  226.  
  227.  
  228. kamailiopublic.bindip = "IP_PUBLICA_ROUTER" desc "Kamailio Public IP Address"
  229. kamailiopublic.bindport = "5060" desc "Kamailio Public Port"
  230.  
  231.  
  232. ####### Modules Section ########
  233.  
  234. # set paths to location of modules (to sources or installation folders)
  235. #!ifdef WITH_SRCPATH
  236. mpath="modules_k:modules"
  237. #!else
  238. mpath="/usr/lib/kamailio/modules_k/:/usr/lib/kamailio/modules/"
  239. #!endif
  240.  
  241. #!ifdef WITH_MYSQL
  242. loadmodule "db_mysql.so"
  243. #!endif
  244.  
  245. #loadmodule "mi_fifo.so"
  246. loadmodule "kex.so"
  247. loadmodule "tm.so"
  248. loadmodule "tmx.so"
  249. loadmodule "sl.so"
  250. loadmodule "rr.so"
  251. loadmodule "pv.so"
  252. loadmodule "maxfwd.so"
  253. loadmodule "usrloc.so"
  254. loadmodule "registrar.so"
  255. loadmodule "textops.so"
  256. loadmodule "siputils.so"
  257. loadmodule "xlog.so"
  258. loadmodule "sanity.so"
  259. loadmodule "ctl.so"
  260. loadmodule "cfg_rpc.so"
  261. loadmodule "mi_rpc.so"
  262. loadmodule "acc.so"
  263. loadmodule "dispatcher.so"
  264.  
  265. #!ifdef WITH_AUTH
  266. loadmodule "auth.so"
  267. loadmodule "auth_db.so"
  268. #!ifdef WITH_IPAUTH
  269. loadmodule "permissions.so"
  270. #!endif
  271. #!endif
  272.  
  273. #!ifdef WITH_ALIASDB
  274. loadmodule "alias_db.so"
  275. #!endif
  276.  
  277. #!ifdef WITH_SPEEDDIAL
  278. loadmodule "speeddial.so"
  279. #!endif
  280.  
  281. #!ifdef WITH_MULTIDOMAIN
  282. loadmodule "domain.so"
  283. #!endif
  284.  
  285. #!ifdef WITH_PRESENCE
  286. loadmodule "presence.so"
  287. loadmodule "presence_xml.so"
  288. #!endif
  289.  
  290. #!ifdef WITH_NAT
  291. loadmodule "nathelper.so"
  292. loadmodule "rtpproxy.so"
  293. #!endif
  294.  
  295. #!ifdef WITH_TLS
  296. loadmodule "tls.so"
  297. #!endif
  298.  
  299. #!ifdef WITH_ANTIFLOOD
  300. loadmodule "htable.so"
  301. loadmodule "pike.so"
  302. #!endif
  303.  
  304. #!ifdef WITH_XMLRPC
  305. loadmodule "xmlrpc.so"
  306. #!endif
  307.  
  308. #!ifdef WITH_DEBUG
  309. loadmodule "debugger.so"
  310. #!endif
  311.  
  312. #!ifdef WITH_DIALOG
  313. loadmodule "dialog.so"
  314. #!endif
  315.  
  316. #!ifdef WITH_xHTTP
  317. loadmodule "xhttp.so"
  318. #!endif WITH_xHTTP
  319.  
  320. #!ifdef WITH_xHTTPRPC
  321. loadmodule "xhttp_rpc.so"
  322. #!endif WITH_xHTTPRPC
  323.  
  324. #!ifdef WITH_EXEC
  325. loadmodule "exec.so"
  326. #!endif WITH_EXEC
  327.  
  328. loadmodule "ipops.so"
  329.  
  330. # ----------------- setting module-specific parameters ---------------
  331.  
  332.  
  333. # ----- mi_fifo params -----
  334. #modparam("mi_fifo", "fifo_name", "/tmp/kamailio_fifo")
  335.  
  336.  
  337. # ----- tm params -----
  338. # auto-discard branches from previous serial forking leg
  339. modparam("tm", "failure_reply_mode", 3)
  340. # default retransmission timeout: 30sec
  341. modparam("tm", "fr_timer", 30000)
  342. # default invite retransmission timeout after 1xx: 120sec
  343. modparam("tm", "fr_inv_timer", 120000)
  344. # Reason text of the automatically send 100 to an INVITE
  345. modparam("tm", "auto_inv_100_reason", "Trying")
  346.  
  347.  
  348.  
  349. # ----- rr params -----
  350. # add value to ;lr param to cope with most of the UAs
  351. modparam("rr", "enable_full_lr", 1)
  352. # do not append from tag to the RR (no need for this script)
  353. modparam("rr", "append_fromtag", 0)
  354.  
  355.  
  356. # ----- registrar params -----
  357. modparam("registrar", "method_filtering", 1)
  358. /* uncomment the next line to disable parallel forking via location */
  359. # modparam("registrar", "append_branches", 0)
  360. /* uncomment the next line not to allow more than 10 contacts per AOR */
  361. #modparam("registrar", "max_contacts", 10)
  362. # max value for expires of registrations
  363. modparam("registrar", "max_expires", 3600)
  364. # set it to 1 to enable GRUU
  365. modparam("registrar", "gruu_enabled", 0)
  366.  
  367.  
  368. # ----- acc params -----
  369. /* what special events should be accounted ? */
  370. modparam("acc", "early_media", 0)
  371. modparam("acc", "report_ack", 0)
  372. modparam("acc", "report_cancels", 0)
  373. /* by default ww do not adjust the direct of the sequential requests.
  374. if you enable this parameter, be sure the enable "append_fromtag"
  375. in "rr" module */
  376. modparam("acc", "detect_direction", 0)
  377. /* account triggers (flags) */
  378. modparam("acc", "log_flag", FLT_ACC)
  379. modparam("acc", "log_missed_flag", FLT_ACCMISSED)
  380. modparam("acc", "log_extra",
  381. "src_user=$fU;src_domain=$fd;src_ip=$si;"
  382. "dst_ouser=$tU;dst_user=$rU;dst_domain=$rd")
  383. modparam("acc", "failed_transaction_flag", FLT_ACCFAILED)
  384. /* enhanced DB accounting */
  385. #!ifdef WITH_ACCDB
  386. modparam("acc", "db_flag", FLT_ACC)
  387. modparam("acc", "db_missed_flag", FLT_ACCMISSED)
  388. modparam("acc", "db_url", DBURL)
  389. modparam("acc", "db_extra",
  390. "src_user=$fU;src_domain=$fd;src_ip=$si;"
  391. "dst_ouser=$tU;dst_user=$rU;dst_domain=$rd")
  392. #!endif
  393.  
  394.  
  395. # ----- usrloc params -----
  396. /* enable DB persistency for location entries */
  397. #!ifdef WITH_USRLOCDB
  398. modparam("usrloc", "db_url", DBURL)
  399. modparam("usrloc", "db_mode", 2)
  400. modparam("usrloc", "use_domain", MULTIDOMAIN)
  401. #!endif
  402.  
  403.  
  404. # ----- auth_db params -----
  405. #!ifdef WITH_AUTH
  406. modparam("auth_db", "db_url", DBURL)
  407. modparam("auth_db", "calculate_ha1", yes)
  408. modparam("auth_db", "password_column", "password")
  409. modparam("auth_db", "load_credentials", "")
  410. modparam("auth_db", "use_domain", MULTIDOMAIN)
  411.  
  412. # ----- permissions params -----
  413. #!ifdef WITH_IPAUTH
  414. modparam("permissions", "db_url", DBURL)
  415. modparam("permissions", "db_mode", 1)
  416. #!endif
  417.  
  418. #!endif
  419.  
  420.  
  421. # ----- alias_db params -----
  422. #!ifdef WITH_ALIASDB
  423. modparam("alias_db", "db_url", DBURL)
  424. modparam("alias_db", "use_domain", MULTIDOMAIN)
  425. #!endif
  426.  
  427.  
  428. # ----- speedial params -----
  429. #!ifdef WITH_SPEEDDIAL
  430. modparam("speeddial", "db_url", DBURL)
  431. modparam("speeddial", "use_domain", MULTIDOMAIN)
  432. #!endif
  433.  
  434.  
  435. # ----- domain params -----
  436. #!ifdef WITH_MULTIDOMAIN
  437. modparam("domain", "db_url", DBURL)
  438. # use caching
  439. modparam("domain", "db_mode", 1)
  440. # register callback to match myself condition with domains list
  441. modparam("domain", "register_myself", 1)
  442. #!endif
  443.  
  444.  
  445. #!ifdef WITH_PRESENCE
  446. # ----- presence params -----
  447. modparam("presence", "db_url", DBURL)
  448.  
  449. # ----- presence_xml params -----
  450. modparam("presence_xml", "db_url", DBURL)
  451. modparam("presence_xml", "force_active", 1)
  452. #!endif
  453.  
  454.  
  455. #!ifdef WITH_NAT
  456. # ----- rtpproxy params -----
  457. #modparam("rtpproxy", "rtpproxy_sock", "udp:127.0.0.1:7722")
  458.  
  459. # ----- nathelper params -----
  460. modparam("nathelper", "natping_interval", 30)
  461. modparam("nathelper", "ping_nated_only", 1)
  462. modparam("nathelper", "sipping_bflag", FLB_NATSIPPING)
  463. modparam("nathelper", "sipping_from", "sip:pinger@kamailio.org")
  464.  
  465. # params needed for NAT traversal in other modules
  466. modparam("nathelper|registrar", "received_avp", "$avp(RECEIVED)")
  467. modparam("usrloc", "nat_bflag", FLB_NATB)
  468. #!endif
  469.  
  470.  
  471. #!ifdef WITH_TLS
  472. # ----- tls params -----
  473. modparam("tls", "config", "//etc/kamailio/tls.cfg")
  474. #!endif
  475.  
  476. #!ifdef WITH_ANTIFLOOD
  477. # ----- pike params -----
  478. modparam("pike", "sampling_time_unit", 2)
  479. modparam("pike", "reqs_density_per_unit", 16)
  480. modparam("pike", "remove_latency", 4)
  481.  
  482. # ----- htable params -----
  483. # ip ban htable with autoexpire after 5 minutes
  484. modparam("htable", "htable", "ipban=>size=12;autoexpire=15;")
  485. #!endif
  486.  
  487. #!ifdef WITH_XMLRPC
  488. # ----- xmlrpc params -----
  489. modparam("xmlrpc", "route", "XMLRPC");
  490. modparam("xmlrpc", "url_match", "^/RPC")
  491. #!endif
  492.  
  493. #!ifdef WITH_DEBUG
  494. # ----- debugger params -----
  495. modparam("debugger", "cfgtrace", 1)
  496. #!endif
  497.  
  498. #!ifdef WITH_DIALOG
  499. modparam("dialog", "enable_stats", 1)
  500. modparam("dialog", "hash_size", 4096)
  501. modparam("dialog", "rr_param", "did")
  502. modparam("dialog", "dlg_flag", FLT_DIALOG)
  503. modparam("dialog", "default_timeout", 21600)
  504. #modparam("dialog", "timeout_avp", "$avp(i:10)")
  505. modparam("dialog", "dlg_match_mode",2)
  506. modparam("dialog", "profiles_no_value", "global")
  507. modparam("dialog", "profiles_with_value", "user")
  508. #!ifdef WITH_MYSQL
  509. modparam("dialog", "db_url", DBURL)
  510. modparam("dialog", "db_mode", 1)
  511. #!endif
  512.  
  513. #Send bye packet when timetout expires
  514. #modparam("dialog", "send_bye", 1)
  515. #!endif
  516.  
  517.  
  518. #!ifdef WITH_xHTTP
  519. #modparam("xhttp", "url_match", "^/RPC|^/BYE")
  520. #!endif
  521.  
  522. #!ifdef WITH_xHTTPRPC
  523. modparam("xhttp_rpc", "xhttp_rpc_root", "RPC")
  524. #!endif WITH_xHTTPRPC
  525.  
  526. #!ifdef WITH_EXEC
  527. modparam("exec", "time_to_kill", 2)
  528. modparam("exec", "setvars", 0)
  529. #!endif WITH_EXEC
  530.  
  531. # ----- dispatcher params -----
  532. #modparam("dispatcher", "db_url",
  533. # "mysql://openser:openserro@localhost/openser")
  534. modparam("dispatcher", "list_file", "/etc/kamailio/dispatcher.list")
  535. #modparam("dispatcher", "table_name", "dispatcher")
  536. modparam("dispatcher", "flags", 2)
  537. modparam("dispatcher", "dst_avp", "$avp(AVP_DST)")
  538. #modparam("dispatcher", "dstid_avp", "$avp(AVP_DSTID)")
  539. modparam("dispatcher", "grp_avp", "$avp(AVP_GRP)")
  540. modparam("dispatcher", "cnt_avp", "$avp(AVP_CNT)")
  541.  
  542. ####### Routing Logic ########
  543.  
  544.  
  545. # Main SIP request routing logic
  546. # - processing of any incoming SIP request starts with this route
  547. # - note: this is the same as route { ... }
  548. request_route {
  549. #Log request
  550. xlog("L_NOTICE", "IP From: [$si]\n");
  551. xlog("L_NOTICE", "SIP request [$rm] [$ru] from uri: [$fu]\n");
  552. # per request initial checks
  553. route(REQINIT);
  554.  
  555. # handle requests within SIP dialogs
  556. route(WITHINDLG);
  557.  
  558. ### only initial requests (no To tag)
  559.  
  560. # CANCEL processing
  561. if (is_method("CANCEL"))
  562. {
  563. if (t_check_trans())
  564. t_relay();
  565. exit;
  566. }
  567.  
  568. t_check_trans();
  569.  
  570. # record routing for dialog forming requests (in case they are routed)
  571. # - remove preloaded route headers
  572. remove_hf("Route");
  573. if (is_method("INVITE|SUBSCRIBE"))
  574. #!ifdef WITH_NAT
  575. record_route_advertised_address("IP_PUBLICA_ROUTER:5060");
  576. #!else
  577. record_route();
  578. #!endif
  579.  
  580. # account only INVITEs
  581. if (is_method("INVITE"))
  582. {
  583. setflag(FLT_ACC); # do accounting
  584. }
  585.  
  586. if ($rU==$null)
  587. {
  588. # request with no Username in RURI
  589. sl_send_reply("484","Address Incomplete");
  590. exit;
  591. }
  592.  
  593. # dispatch destinations
  594. route(DISPATCH);
  595.  
  596. route(RELAY);
  597.  
  598. }
  599.  
  600. # Dispatch requests
  601. route[DISPATCH] {
  602. xlog("L_NOTICE","Dispatching Request.");
  603. # round robin dispatching on gateways group '1'
  604. if(!ds_select_dst("1", "4"))
  605. {
  606. xlog("L_DBG", "No destination");
  607. send_reply("404", "No destination");
  608. exit;
  609. }
  610. xlog("L_NOTICE", "Dispatch: going to <$ru> via <$du>\n");
  611. return;
  612. }
  613.  
  614.  
  615. route[RELAY] {
  616. xlog("L_NOTICE", "Relaying packet:[$rm] from uri: [$fu] to uri: [$tu] \n");
  617. # enable additional event routes for forwarded requests
  618. # - serial forking, RTP relaying handling, a.s.o.
  619. if (is_method("INVITE|SUBSCRIBE")) {
  620. #t_on_branch("MANAGE_BRANCH");
  621. t_on_reply("MANAGE_REPLY");
  622. }
  623. if (is_method("INVITE")) {
  624. t_on_failure("MANAGE_FAILURE");
  625. }
  626.  
  627. if (!t_relay()) {
  628. sl_reply_error();
  629. }
  630. exit;
  631. }
  632.  
  633. # Per SIP request initial checks
  634. route[REQINIT] {
  635. #!ifdef WITH_ANTIFLOOD
  636. # flood dection from same IP and traffic ban for a while
  637. # be sure you exclude checking trusted peers, such as pstn gateways
  638. # - local host excluded (e.g., loop to self)
  639. if(src_ip!=myself)
  640. {
  641. if($sht(ipban=>$si)!=$null)
  642. {
  643. # ip is already blocked
  644. xlog("L_NOTICE","request from blocked IP - $rm from $fu (IP:$si:$sp)\n");
  645. exit;
  646. }
  647. if (!pike_check_req())
  648. {
  649. xlog("L_ALERT","ALERT: pike blocking $rm from $fu (IP:$si:$sp)\n");
  650. $sht(ipban=>$si) = 1;
  651. exit;
  652. }
  653. }
  654. #!endif
  655.  
  656. if (!mf_process_maxfwd_header("10")) {
  657. xlog("L_NOTICE","483: Too Many Hops");
  658. sl_send_reply("483","Too Many Hops");
  659. exit;
  660. }
  661.  
  662. if(!sanity_check("1511", "7"))
  663. {
  664. xlog("Malformed SIP message from $si:$sp\n");
  665. exit;
  666. }
  667. if(!is_pure_ip($rd)) {
  668. xlog("L_NOTICE","Invalid IPV4 or IPV6 domain in SIP Request URI");
  669. sl_send_reply("403","Invalid IPV4 or IPV6 domain \n.");
  670. exit;
  671. }
  672. }
  673.  
  674. # Handle requests within SIP dialogs
  675. route[WITHINDLG] {
  676. if (has_totag()) {
  677. xlog("L_NOTICE","Request tagged packet: From tag: [$ft] To tag: [$tt]");
  678. # sequential request withing a dialog should
  679. # take the path determined by record-routing
  680. if (loose_route()) {
  681. if (is_method("BYE")) {
  682. setflag(FLT_ACC); # do accounting ...
  683. setflag(FLT_ACCMISSED); # ... even if the transaction fails
  684. }
  685. xlog("L_NOTICE","Within dialog, with loose route. ACK arrive. Relaying..");
  686. route(RELAY);
  687. } else {
  688. if ( is_method("ACK") ) {
  689. if ( t_check_trans() ) {
  690. # non loose-route, but stateful ACK;
  691. # must be ACK after a 487 or e.g. 404 from upstream server
  692. t_relay();
  693. exit;
  694. } else {
  695. # ACK without matching transaction ... ignore and discard.
  696. exit;
  697. }
  698. }
  699. sl_send_reply("404","Not here");
  700. }
  701. exit;
  702. }
  703. }
  704.  
  705.  
  706.  
  707. # RTPProxy control
  708. route[NATMANAGE] {
  709. #!ifdef WITH_NAT
  710. if (is_request()) {
  711. if(has_totag()) {
  712. if(check_route_param("nat=yes")) {
  713. setbflag(FLB_NATB);
  714. }
  715. }
  716. }
  717. if (!(isflagset(FLT_NATS) || isbflagset(FLB_NATB)))
  718. return;
  719.  
  720. rtpproxy_manage();
  721.  
  722. if (is_request()) {
  723. if (!has_totag()) {
  724. add_rr_param(";nat=yes");
  725. }
  726. }
  727. if (is_reply()) {
  728. if(isbflagset(FLB_NATB)) {
  729. fix_nated_contact();
  730. }
  731. }
  732. #!endif
  733. return;
  734. }
  735.  
  736. onreply_route[MANAGE_REPLY] {
  737. xlog("L_NOTICE", "IP From: [$si]\n");
  738. xlog("L_NOTICE", "Incoming Reply: with status [$rs] [$rr] of [$rm] request.\n");
  739. #Replace record route to set private IP. This packet will be sent to asterisk/freeswitch box
  740. #replace_all("Record-Route: <sip:"+$sel(cfg_get.kamailiopublic.bindip)+":"+$sel(cfg_get.kamailiopublic.bindport),"Record-Route: <sip:"+$sel(cfg_get.kamailio.bindip)+":"+$sel(cfg_get.kamailio.bindport));
  741. #if(remove_hf("Record-Route"))
  742. # {
  743. # User Agent header removed
  744. # insert_hf("Record-Route: <sip:IP_PRIVADA_KAMAILIO:5060;lr=on>");
  745. # }
  746. if(status=~"[12][0-9][0-9]")
  747. route(NATMANAGE);
  748. }
  749.  
  750. # manage failure routing cases
  751. failure_route[MANAGE_FAILURE] {
  752. xlog("L_NOTICE", "Failed route\n");
  753. route(NATMANAGE);
  754.  
  755. if (t_is_canceled()) {
  756. exit;
  757. }
  758.  
  759. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement