Advertisement
load-net

blog.ipcalls24.com/htable-in-kamailio

Apr 5th, 2023 (edited)
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 20.66 KB | None | 0 0
  1. #!KAMAILIO
  2. #
  3. # Kamailio (OpenSER) SIP Server v5.4 - default configuration script
  4. # - web: https://www.kamailio.org
  5. # - git: https://github.com/kamailio/kamailio
  6. #
  7. # Direct your questions about this file to: <sr-users@lists.kamailio.org>
  8. #
  9. # Refer to the Core CookBook at https://www.kamailio.org/wiki/
  10. # for an explanation of possible statements, functions and parameters.
  11. #
  12. # Note: the comments can be:
  13. # - lines starting with #, but not the pre-processor directives,
  14. # which start with #!, like #!define, #!ifdef, #!endif, #!else, #!trydef,
  15. # #!subst, #!substdef, ...
  16. # - lines starting with //
  17. # - blocks enclosed in between /* */
  18. # Note: the config performs symmetric SIP signaling
  19. # - it sends the reply to the source address of the request
  20. # - remove the use of force_rport() for asymmetric SIP signaling
  21. #
  22. # Several features can be enabled using '#!define WITH_FEATURE' directives:
  23. #
  24. # *** To run in debug mode:
  25. #!define WITH_DEBUG
  26. # - debug level increased to 3, logs still sent to syslog
  27. # - debugger module loaded with cfgtrace endabled
  28. #
  29. # *** To enable mysql:
  30. # - define WITH_MYSQL
  31. #
  32. # *** To enable authentication execute:
  33. # - enable mysql
  34. #!define WITH_AUTH
  35. # - add users using 'kamctl' or 'kamcli'
  36. #
  37. # *** To enable IP authentication execute:
  38. # - enable mysql
  39. # - enable authentication
  40. #!define WITH_IPAUTH
  41. # - add IP addresses with group id '1' to 'address' table
  42. #
  43. # *** To enable persistent user location execute:
  44. # - enable mysql
  45. #!define WITH_USRLOCDB
  46. #
  47. # *** To enable presence server execute:
  48. # - enable mysql
  49. # - define WITH_PRESENCE
  50. # - if modified headers or body in config must be used by presence handling:
  51. # - define WITH_MSGREBUILD
  52. #
  53. # *** To enable nat traversal execute:
  54. #!define WITH_NAT
  55. # - option for NAT SIP OPTIONS keepalives: WITH_NATSIPPING
  56. # - install RTPProxy: http://www.rtpproxy.org
  57. # - start RTPProxy:
  58. # rtpproxy -l _your_public_ip_ -s udp:localhost:7722
  59. #
  60. # *** To use RTPEngine (instead of RTPProxy) for nat traversal execute:
  61. #!define WITH_RTPENGINE
  62. # - install RTPEngine: https://github.com/sipwise/rtpengine
  63. # - start RTPEngine:
  64. # rtpengine --listen-ng=127.0.0.1:2223 ...
  65. #
  66. # *** To enable PSTN gateway routing execute:
  67. # - define WITH_PSTN
  68. # - set the value of pstn.gw_ip
  69. # - check route[PSTN] for regexp routing condition
  70. #
  71. # *** To enable database aliases lookup execute:
  72. # - enable mysql
  73. # - define WITH_ALIASDB
  74. #
  75. # *** To enable speed dial lookup execute:
  76. # - enable mysql
  77. # - define WITH_SPEEDDIAL
  78. #
  79. # *** To enable multi-domain support execute:
  80. # - enable mysql
  81. # - define WITH_MULTIDOMAIN
  82. #
  83. # *** To enable TLS support execute:
  84. # - adjust CFGDIR/tls.cfg as needed
  85. # - define WITH_TLS
  86. #
  87. # *** To enable JSONRPC over HTTP(S) support execute:
  88. # - define WITH_JSONRPC
  89. # - adjust event_route[xhttp:request] for access policy
  90. #
  91. # *** To enable anti-flood detection execute:
  92. # - adjust pike and htable=>ipban settings as needed (default is
  93. # block if more than 16 requests in 2 seconds and ban for 300 seconds)
  94. # - define WITH_ANTIFLOOD
  95. #
  96. # *** To block 3XX redirect replies execute:
  97. # - define WITH_BLOCK3XX
  98. #
  99. # *** To block 401 and 407 authentication replies execute:
  100. # - define WITH_BLOCK401407
  101. #
  102. # *** To enable VoiceMail routing execute:
  103. # - define WITH_VOICEMAIL
  104. # - set the value of voicemail.srv_ip
  105. # - adjust the value of voicemail.srv_port
  106. #
  107. # *** To enhance accounting execute:
  108. # - enable mysql
  109. # - define WITH_ACCDB
  110. # - add following columns to database
  111. #!ifdef ACCDB_COMMENT
  112. ALTER TABLE acc ADD COLUMN src_user VARCHAR(64) NOT NULL DEFAULT '';
  113. ALTER TABLE acc ADD COLUMN src_domain VARCHAR(128) NOT NULL DEFAULT '';
  114. ALTER TABLE acc ADD COLUMN src_ip varchar(64) NOT NULL default '';
  115. ALTER TABLE acc ADD COLUMN dst_ouser VARCHAR(64) NOT NULL DEFAULT '';
  116. ALTER TABLE acc ADD COLUMN dst_user VARCHAR(64) NOT NULL DEFAULT '';
  117. ALTER TABLE acc ADD COLUMN dst_domain VARCHAR(128) NOT NULL DEFAULT '';
  118. ALTER TABLE missed_calls ADD COLUMN src_user VARCHAR(64) NOT NULL DEFAULT '';
  119. ALTER TABLE missed_calls ADD COLUMN src_domain VARCHAR(128) NOT NULL DEFAULT '';
  120. ALTER TABLE missed_calls ADD COLUMN src_ip varchar(64) NOT NULL default '';
  121. ALTER TABLE missed_calls ADD COLUMN dst_ouser VARCHAR(64) NOT NULL DEFAULT '';
  122. ALTER TABLE missed_calls ADD COLUMN dst_user VARCHAR(64) NOT NULL DEFAULT '';
  123. ALTER TABLE missed_calls ADD COLUMN dst_domain VARCHAR(128) NOT NULL DEFAULT '';
  124. #!endif
  125.  
  126. ####### Include Local Config If Exists #########
  127. import_file "kamailio-local.cfg"
  128.  
  129. ####### Defined Values #########
  130.  
  131. # *** Value defines - IDs used later in config
  132. #!ifdef WITH_DEBUG
  133. #!define DBGLEVEL 3
  134. #!else
  135. #!define DBGLEVEL 2
  136. #!endif
  137.  
  138. #!ifdef WITH_MYSQL
  139. # - database URL - used to connect to database server by modules such
  140. # as: auth_db, acc, usrloc, a.s.o.
  141. #!trydef DBURL "mysql://kamailio:kamailiorw@localhost/kamailio"
  142. #!endif
  143.  
  144. #!ifdef WITH_MULTIDOMAIN
  145. # - the value for 'use_domain' parameters
  146. #!define MULTIDOMAIN 1
  147. #!else
  148. #!define MULTIDOMAIN 0
  149. #!endif
  150.  
  151. # - flags
  152. # FLT_ - per transaction (message) flags
  153. # FLB_ - per branch flags
  154. #!define FLT_ACC 1
  155. #!define FLT_ACCMISSED 2
  156. #!define FLT_ACCFAILED 3
  157. #!define FLT_NATS 5
  158.  
  159. #!define FLB_NATB 6
  160. #!define FLB_NATSIPPING 7
  161.  
  162. ####### Global Parameters #########
  163.  
  164. /* LOG Levels: 3=DBG, 2=INFO, 1=NOTICE, 0=WARN, -1=ERR, ... */
  165. debug=DBGLEVEL
  166.  
  167. /* set to 'yes' to print log messages to terminal or use '-E' cli option */
  168. log_stderror=no
  169.  
  170. memdbg=5
  171. memlog=5
  172.  
  173. log_facility=LOG_LOCAL0
  174. log_prefix="{$mt $hdr(CSeq) $ci} "
  175.  
  176. /* number of SIP routing processes for each UDP socket
  177. * - value inherited by tcp_children and sctp_children when not set explicitely */
  178. children=8
  179.  
  180. /* uncomment the next line to disable TCP (default on) */
  181. disable_tcp=yes
  182.  
  183. /* number of SIP routing processes for all TCP/TLS sockets */
  184. # tcp_children=8
  185.  
  186. /* uncomment the next line to disable the auto discovery of local aliases
  187. * based on reverse DNS on IPs (default on) */
  188. # auto_aliases=no
  189.  
  190. /* add local domain aliases - it can be set many times */
  191. alias="pdl.sytes.net"
  192.  
  193. /* listen sockets - if none set, Kamailio binds to all local IP addresses
  194. * - basic prototype (full prototype can be found in Wiki - Core Cookbook):
  195. * listen=[proto]:[localip]:[lport] advertise [publicip]:[pport]
  196. * - it can be set many times to add more sockets to listen to */
  197.  
  198. listen=udp:10.20.7.103:5060
  199. #listen=udp:0.0.0.0:5060
  200. mhomed=1
  201.  
  202. /* life time of TCP connection when there is no traffic
  203. * - a bit higher than registration expires to cope with UA behind NAT */
  204. tcp_connection_lifetime=3605
  205.  
  206. /* upper limit for TCP connections (it includes the TLS connections) */
  207. tcp_max_connections=2048
  208.  
  209. #!ifdef WITH_JSONRPC
  210. tcp_accept_no_cl=yes
  211. #!endif
  212.  
  213. #!ifdef WITH_TLS
  214. #enable_tls=yes
  215.  
  216. /* upper limit for TLS connections */
  217. tls_max_connections=2048
  218. #!endif
  219.  
  220. /* set it to yes to enable sctp and load sctp.so module */
  221. enable_sctp=no
  222.  
  223. ####### Custom Parameters #########
  224.  
  225. /* These parameters can be modified runtime via RPC interface
  226. * - see the documentation of 'cfg_rpc' module.
  227. *
  228. * Format: group.id = value 'desc' description
  229. * Access: $sel(cfg_get.group.id) or @cfg_get.group.id */
  230.  
  231. #!ifdef WITH_PSTN
  232. /* PSTN GW Routing
  233. *
  234. * - pstn.gw_ip: valid IP or hostname as string value, example:
  235. * pstn.gw_ip = "10.0.0.101" desc "My PSTN GW Address"
  236. *
  237. * - by default is empty to avoid misrouting */
  238. pstn.gw_ip = "" desc "PSTN GW Address"
  239. pstn.gw_port = "" desc "PSTN GW Port"
  240. #!endif
  241.  
  242. #!ifdef WITH_VOICEMAIL
  243. /* VoiceMail Routing on offline, busy or no answer
  244. *
  245. * - by default Voicemail server IP is empty to avoid misrouting */
  246. voicemail.srv_ip = "" desc "VoiceMail IP Address"
  247. voicemail.srv_port = "5060" desc "VoiceMail Port"
  248. #!endif
  249.  
  250. ####### Modules Section ########
  251.  
  252. /* set paths to location of modules */
  253. # mpath="/usr/lib/x86_64-linux-gnu/kamailio/modules/"
  254.  
  255. #!ifdef WITH_MYSQL
  256. #loadmodule "db_mysql.so"
  257. #!endif
  258.  
  259. #!ifdef WITH_JSONRPC
  260. loadmodule "xhttp.so"
  261. #!endif
  262. loadmodule "jsonrpcs.so"
  263. loadmodule "kex.so"
  264. loadmodule "corex.so"
  265. loadmodule "tm.so"
  266. loadmodule "tmx.so"
  267. loadmodule "sl.so"
  268. loadmodule "rr.so"
  269. loadmodule "pv.so"
  270. loadmodule "maxfwd.so"
  271. loadmodule "usrloc.so"
  272. loadmodule "registrar.so"
  273. loadmodule "textops.so"
  274. loadmodule "textopsx.so"
  275. loadmodule "siputils.so"
  276. loadmodule "xlog.so"
  277. loadmodule "sanity.so"
  278. loadmodule "ctl.so"
  279. loadmodule "cfg_rpc.so"
  280. loadmodule "acc.so"
  281. loadmodule "counters.so"
  282. loadmodule "db_postgres.so"
  283. loadmodule "dialog.so"
  284. loadmodule "uac.so"
  285. loadmodule "htable.so"
  286.  
  287. #!define DBURL "postgres://kamailio:kamailiorw@10.20.7.123:5432/kamailio"
  288.  
  289. #!ifdef WITH_AUTH
  290. loadmodule "auth.so"
  291. loadmodule "auth_db.so"
  292. #!ifdef WITH_IPAUTH
  293. loadmodule "permissions.so"
  294. #!endif
  295. #!endif
  296.  
  297. #!ifdef WITH_ALIASDB
  298. loadmodule "alias_db.so"
  299. #!endif
  300.  
  301. #!ifdef WITH_SPEEDDIAL
  302. loadmodule "speeddial.so"
  303. #!endif
  304.  
  305. #!ifdef WITH_MULTIDOMAIN
  306. loadmodule "domain.so"
  307. #!endif
  308.  
  309. #!ifdef WITH_PRESENCE
  310. loadmodule "presence.so"
  311. loadmodule "presence_xml.so"
  312. #!endif
  313.  
  314. #!ifdef WITH_NAT
  315. loadmodule "nathelper.so"
  316. #!ifdef WITH_RTPENGINE
  317. loadmodule "rtpengine.so"
  318. #!else
  319. loadmodule "rtpproxy.so"
  320. #!endif
  321. #!endif
  322.  
  323. #!ifdef WITH_TLS
  324. loadmodule "tls.so"
  325. #!endif
  326.  
  327. #!ifdef WITH_ANTIFLOOD
  328. loadmodule "htable.so"
  329. loadmodule "pike.so"
  330. #!endif
  331.  
  332. #!ifdef WITH_DEBUG
  333. loadmodule "debugger.so"
  334. #!endif
  335.  
  336. # ----------------- setting module-specific parameters ---------------
  337.  
  338. # ----- jsonrpcs params -----
  339. modparam("jsonrpcs", "pretty_format", 1)
  340. /* set the path to RPC fifo control file */
  341. # modparam("jsonrpcs", "fifo_name", "/run/kamailio/kamailio_rpc.fifo")
  342. /* set the path to RPC unix socket control file */
  343. # modparam("jsonrpcs", "dgram_socket", "/run/kamailio/kamailio_rpc.sock")
  344. #!ifdef WITH_JSONRPC
  345. modparam("jsonrpcs", "transport", 7)
  346. #!endif
  347.  
  348. # ----- ctl params -----
  349. /* set the path to RPC unix socket control file */
  350. # modparam("ctl", "binrpc", "unix:/run/kamailio/kamailio_ctl")
  351.  
  352. # ----- sanity params -----
  353. modparam("sanity", "autodrop", 0)
  354.  
  355. # ----- tm params -----
  356. # auto-discard branches from previous serial forking leg
  357. modparam("tm", "failure_reply_mode", 3)
  358. # default retransmission timeout: 30sec
  359. modparam("tm", "fr_timer", 30000)
  360. # default invite retransmission timeout after 1xx: 120sec
  361. modparam("tm", "fr_inv_timer", 120000)
  362.  
  363. # ----- rr params -----
  364. # set next param to 1 to add value to ;lr param (helps with some UAs)
  365. modparam("rr", "enable_full_lr", 0)
  366. # do not append from tag to the RR (no need for this script)
  367. modparam("rr", "append_fromtag", 1)
  368.  
  369. # ----- registrar params -----
  370. modparam("registrar", "method_filtering", 1)
  371. /* uncomment the next line to disable parallel forking via location */
  372. # modparam("registrar", "append_branches", 0)
  373. /* uncomment the next line not to allow more than 10 contacts per AOR */
  374. # modparam("registrar", "max_contacts", 10)
  375. /* max value for expires of registrations */
  376. modparam("registrar", "max_expires", 3600)
  377. /* set it to 1 to enable GRUU */
  378. modparam("registrar", "gruu_enabled", 0)
  379. /* set it to 0 to disable Path handling */
  380. modparam("registrar", "use_path", 1)
  381. /* save Path even if not listed in Supported header */
  382. modparam("registrar", "path_mode", 0)
  383.  
  384. # ----- acc params -----
  385. /* what special events should be accounted ? */
  386. modparam("acc", "early_media", 0)
  387. modparam("acc", "report_ack", 0)
  388. modparam("acc", "report_cancels", 0)
  389. /* by default ww do not adjust the direct of the sequential requests.
  390. * if you enable this parameter, be sure the enable "append_fromtag"
  391. * in "rr" module */
  392. modparam("acc", "detect_direction", 0)
  393. /* account triggers (flags) */
  394. modparam("acc", "log_flag", FLT_ACC)
  395. modparam("acc", "log_missed_flag", FLT_ACCMISSED)
  396. modparam("acc", "log_extra",
  397. "src_user=$fU;src_domain=$fd;src_ip=$si;"
  398. "dst_ouser=$tU;dst_user=$rU;dst_domain=$rd")
  399. modparam("acc", "failed_transaction_flag", FLT_ACCFAILED)
  400. /* enhanced DB accounting */
  401. #!ifdef WITH_ACCDB
  402. modparam("acc", "db_flag", FLT_ACC)
  403. modparam("acc", "db_missed_flag", FLT_ACCMISSED)
  404. modparam("acc", "db_url", DBURL)
  405. modparam("acc", "db_extra",
  406. "src_user=$fU;src_domain=$fd;src_ip=$si;"
  407. "dst_ouser=$tU;dst_user=$rU;dst_domain=$rd")
  408. #!endif
  409.  
  410. # ----- usrloc params -----
  411. modparam("usrloc", "timer_interval", 60)
  412. modparam("usrloc", "timer_procs", 1)
  413. modparam("usrloc", "use_domain", MULTIDOMAIN)
  414. /* enable DB persistency for location entries */
  415. #!ifdef WITH_USRLOCDB
  416. modparam("usrloc", "db_url", DBURL)
  417. modparam("usrloc", "db_mode", 1)
  418. #!endif
  419.  
  420. # ----- auth_db params -----
  421. #!ifdef WITH_AUTH
  422. modparam("auth_db", "db_url", DBURL)
  423. modparam("auth_db", "calculate_ha1", yes)
  424. modparam("auth_db", "password_column", "password")
  425. modparam("auth_db", "load_credentials", "")
  426. modparam("auth_db", "use_domain", MULTIDOMAIN)
  427.  
  428. # ----- permissions params -----
  429. #!ifdef WITH_IPAUTH
  430. modparam("permissions", "db_url", DBURL)
  431. modparam("permissions", "db_mode", 1)
  432. #!endif
  433.  
  434. #!endif
  435.  
  436. # ----- alias_db params -----
  437. #!ifdef WITH_ALIASDB
  438. modparam("alias_db", "db_url", DBURL)
  439. modparam("alias_db", "use_domain", MULTIDOMAIN)
  440. #!endif
  441.  
  442. # ----- speeddial params -----
  443. #!ifdef WITH_SPEEDDIAL
  444. modparam("speeddial", "db_url", DBURL)
  445. modparam("speeddial", "use_domain", MULTIDOMAIN)
  446. #!endif
  447.  
  448. # ----- domain params -----
  449. #!ifdef WITH_MULTIDOMAIN
  450. modparam("domain", "db_url", DBURL)
  451. /* register callback to match myself condition with domains list */
  452. modparam("domain", "register_myself", 1)
  453. #!endif
  454.  
  455. #!ifdef WITH_PRESENCE
  456. # ----- presence params -----
  457. modparam("presence", "db_url", DBURL)
  458.  
  459. # ----- presence_xml params -----
  460. modparam("presence_xml", "db_url", DBURL)
  461. modparam("presence_xml", "force_active", 1)
  462. #!endif
  463.  
  464. #!ifdef WITH_NAT
  465. #!ifdef WITH_RTPENGINE
  466. # ----- rtpengine params -----
  467. modparam("rtpengine", "rtpengine_sock", "udp:127.0.0.1:2223")
  468. #!else
  469. # ----- rtpproxy params -----
  470. modparam("rtpproxy", "rtpproxy_sock", "udp:127.0.0.1:7722")
  471. #!endif
  472. # ----- nathelper params -----
  473. modparam("nathelper", "natping_interval", 30)
  474. modparam("nathelper", "ping_nated_only", 1)
  475. modparam("nathelper", "sipping_bflag", FLB_NATSIPPING)
  476. modparam("nathelper", "sipping_from", "sip:pinger@kamailio.org")
  477.  
  478. # params needed for NAT traversal in other modules
  479. modparam("nathelper|registrar", "received_avp", "$avp(RECEIVED)")
  480. modparam("usrloc", "nat_bflag", FLB_NATB)
  481. #!endif
  482.  
  483. #!ifdef WITH_TLS
  484. # ----- tls params -----
  485. modparam("tls", "config", "/etc/kamailio/tls.cfg")
  486. #!endif
  487.  
  488. #!ifdef WITH_ANTIFLOOD
  489. # ----- pike params -----
  490. modparam("pike", "sampling_time_unit", 2)
  491. modparam("pike", "reqs_density_per_unit", 16)
  492. modparam("pike", "remove_latency", 4)
  493.  
  494. # ----- htable params -----
  495. /* ip ban htable with autoexpire after 5 minutes */
  496.  
  497. modparam("htable", "htable", "auth=>size=10;autoexpire=1800;")
  498. modparam("htable", "htable", "ipban=>size=10;autoexpire=300;initval=0;")
  499. modparam("auth_db", "load_credentials", "$avp(pass)=password")
  500. #!endif
  501.  
  502. #!ifdef WITH_DEBUG
  503. # ----- debugger params -----
  504. modparam("debugger", "cfgtrace", 1)
  505. modparam("debugger", "log_level_name", "exec")
  506. #!endif
  507.  
  508. ###################
  509.  
  510. # ----- dialog params -----
  511. modparam("dialog", "dlg_flag", 0)
  512. modparam("dialog", "default_timeout", 21600)
  513. modparam("dialog", "db_url", DBURL)
  514. modparam("dialog", "db_mode", 1)
  515. modparam("dialog", "send_bye", 1)
  516. modparam("dialog", "ka_timer", 3)
  517. modparam("dialog", "ka_interval", 30)
  518. modparam("dialog", "ka_failed_limit", 1)
  519. modparam("dialog", "track_cseq_updates", 1)
  520.  
  521. ###################
  522.  
  523. modparam("uac", "reg_db_url", DBURL)
  524. #modparam("uac","auth_username_avp","$avp(auser)")
  525. #modparam("uac","auth_password_avp","$avp(apass)")
  526. #modparam("uac","auth_realm_avp","$avp(arealm)")
  527.  
  528. modparam("uac", "reg_db_table", "uacreg")
  529. modparam("uac", "reg_timer_interval",20)
  530. modparam("uac", "reg_retry_interval",120)
  531. modparam("uac", "reg_contact_addr", "88.79.229.217:5060")
  532. modparam("uac", "reg_active", 1)
  533. modparam("uac", "restore_mode", "auto")
  534.  
  535.  
  536. ##################
  537.  
  538. # Dispatcher (rus-kamailio-conf)
  539. loadmodule "dispatcher.so"
  540. modparam("dispatcher", "flags", 2)
  541. modparam("dispatcher", "ds_probing_mode", 1)
  542. modparam("dispatcher", "ds_ping_interval", 10) # ds_ping_interval — мы задаем периодичность отправки healtcheck
  543. modparam("dispatcher", "ds_probing_threshold", 4) #В приведенном примере, прежде чем SIP сервер (хост) из dispatcher списка станет недоступным, необходимо отправить два неудачных запроса.
  544. modparam("dispatcher", "ds_inactive_threshold", 4)
  545. modparam("dispatcher", "db_url", DBURL)
  546.  
  547.  
  548. ###################
  549.  
  550.  
  551. ####### Routing Logic ########
  552.  
  553. /* Main SIP request routing logic
  554. * - processing of any incoming SIP request starts with this route
  555. * - note: this is the same as route { ... } */
  556.  
  557.  
  558.  
  559. ###################################################################
  560.  
  561. request_route {
  562. route(REQINIT);
  563.  
  564. if (is_method("CANCEL")) {
  565. if (t_check_trans()) {
  566. route(RELAY);
  567. }
  568. exit;
  569. }
  570.  
  571. if (is_method("INVITE") || is_method("REGISTER")) {
  572. route(NAT);
  573. }
  574.  
  575. if (is_method("REGISTER")) {
  576. route(AUTH);
  577. }
  578.  
  579. route(DIALOG);
  580. }
  581.  
  582. #################################################################
  583.  
  584. route[REQINIT] {
  585. if($sht(ipban=>$si) > 5) {
  586. exit;
  587. }
  588. force_rport;
  589. }
  590.  
  591. ################################################################
  592.  
  593. route[AUTH] {
  594. if (sht_match_name("auth", "eq", "$Au")) {
  595. if (!pv_auth_check("$fd", "$sht(auth=>$Au)", "0", "1")) {
  596. auth_challenge("$fd", "1");
  597. $sht(ipban=>$si) = $sht(ipban=>$si) + 1;
  598. exit;
  599. }
  600. consume_credentials();
  601. $sht(ipban=>$si) = $null;
  602. if (is_method("REGISTER")) {
  603. save("location");
  604. exit;
  605. }
  606. } else {
  607. if (!auth_check("$fd", "subscriber", "1")) {
  608. auth_challenge("$fd", "1");
  609. $sht(ipban=>$si) = $sht(ipban=>$si) + 1;
  610. exit;
  611. }
  612. $sht(auth=>$Au) = $avp(pass);
  613. $sht(ipban=>$si) = $null;
  614. consume_credentials();
  615. if (is_method("REGISTER")) {
  616. save("location");
  617. exit;
  618. }
  619. }
  620. }
  621.  
  622. ###########################################################
  623.  
  624. route[NAT] {
  625. if (nat_uac_test("19")) {
  626. if (is_method("REGISTER")) {
  627. set_contact_alias();
  628. } else {
  629. if(is_first_hop()) {
  630. set_contact_alias();
  631. }
  632. }
  633. }
  634. return;
  635. }
  636.  
  637. #########################################################
  638.  
  639. route[DIALOG] {
  640. if (is_method("INVITE")) {
  641. route(AUTH);
  642. if (!lookup("location")) {
  643. sl_send_reply("403", "Forbidden");
  644. exit;
  645. }
  646. handle_ruri_alias();
  647. record_route();
  648. route(RELAY);
  649. }
  650. if (has_totag()) {
  651. if (loose_route()) {
  652. handle_ruri_alias();
  653. route(RELAY);
  654. }
  655. }
  656. if (is_method("ACK")) {
  657. if ( t_check_trans() ) {
  658. route(RELAY);
  659. exit;
  660. } else {
  661. exit;
  662. }
  663. }
  664. }
  665.  
  666. ########################################################
  667.  
  668. route[RELAY] {
  669. if (has_body("application/sdp")) {
  670. rtpengine_manage("replace-session-connection replace-origin ICE=remove direction=internal direction=external");
  671. }
  672. t_on_reply("REPLY");
  673. t_relay();
  674. }
  675.  
  676.  
  677. #######################################################
  678.  
  679. onreply_route[REPLY] {
  680. route(NAT);
  681. if (has_body("application/sdp")) {
  682. rtpengine_manage("replace-session-connection replace-origin ICE=remove direction=internal direction=external");
  683. }
  684. }
  685.  
  686.  
  687.  
  688.  
  689.  
  690.  
  691.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement