Advertisement
Guest User

kamailio.cfg

a guest
Aug 10th, 2019
456
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.72 KB | None | 0 0
  1. #!KAMAILIO
  2. #
  3. # Kamailio (OpenSER) SIP Server v5.1 - 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. #
  19. # Several features can be enabled using '#!define WITH_FEATURE' directives:
  20. #
  21. # *** To run in debug mode:
  22. # - define WITH_DEBUG
  23. #
  24. # *** To enable mysql:
  25. # - define WITH_MYSQL
  26. #
  27. # *** To enable authentication execute:
  28. # - enable mysql
  29. # - define WITH_AUTH
  30. # - add users using 'kamctl'
  31. #
  32. # *** To enable IP authentication execute:
  33. # - enable mysql
  34. # - enable authentication
  35. # - define WITH_IPAUTH
  36. # - add IP addresses with group id '1' to 'address' table
  37. #
  38. # *** To enable persistent user location execute:
  39. # - enable mysql
  40. # - define WITH_USRLOCDB
  41. #
  42. # *** To enable presence server execute:
  43. # - enable mysql
  44. # - define WITH_PRESENCE
  45. #
  46. # *** To enable nat traversal execute:
  47. # - define WITH_NAT
  48. # - install RTPProxy: http://www.rtpproxy.org
  49. # - start RTPProxy:
  50. # rtpproxy -l _your_public_ip_ -s udp:localhost:7722
  51. # - option for NAT SIP OPTIONS keepalives: WITH_NATSIPPING
  52. #
  53. # *** To enable PSTN gateway routing execute:
  54. # - define WITH_PSTN
  55. # - set the value of pstn.gw_ip
  56. # - check route[PSTN] for regexp routing condition
  57. #
  58. # *** To enable database aliases lookup execute:
  59. # - enable mysql
  60. # - define WITH_ALIASDB
  61. #
  62. # *** To enable speed dial lookup execute:
  63. # - enable mysql
  64. # - define WITH_SPEEDDIAL
  65. #
  66. # *** To enable multi-domain support execute:
  67. # - enable mysql
  68. # - define WITH_MULTIDOMAIN
  69. #
  70. # *** To enable TLS support execute:
  71. # - adjust CFGDIR/tls.cfg as needed
  72. # - define WITH_TLS
  73. #
  74. # *** To enable XMLRPC support execute:
  75. # - define WITH_XMLRPC
  76. # - adjust route[XMLRPC] for access policy
  77. #
  78. # *** To enable anti-flood detection execute:
  79. # - adjust pike and htable=>ipban settings as needed (default is
  80. # block if more than 16 requests in 2 seconds and ban for 300 seconds)
  81. # - define WITH_ANTIFLOOD
  82. #
  83. # *** To block 3XX redirect replies execute:
  84. # - define WITH_BLOCK3XX
  85. #
  86. # *** To block 401 and 407 authentication replies execute:
  87. # - define WITH_BLOCK401407
  88. #
  89. # *** To enable VoiceMail routing execute:
  90. # - define WITH_VOICEMAIL
  91. # - set the value of voicemail.srv_ip
  92. # - adjust the value of voicemail.srv_port
  93. #
  94. # *** To enhance accounting execute:
  95. # - enable mysql
  96. # - define WITH_ACCDB
  97. # - add following columns to database
  98. #!ifdef ACCDB_COMMENT
  99. ALTER TABLE acc ADD COLUMN src_user VARCHAR(64) NOT NULL DEFAULT '';
  100. ALTER TABLE acc ADD COLUMN src_domain VARCHAR(128) NOT NULL DEFAULT '';
  101. ALTER TABLE acc ADD COLUMN src_ip varchar(64) NOT NULL default '';
  102. ALTER TABLE acc ADD COLUMN dst_ouser VARCHAR(64) NOT NULL DEFAULT '';
  103. ALTER TABLE acc ADD COLUMN dst_user VARCHAR(64) NOT NULL DEFAULT '';
  104. ALTER TABLE acc ADD COLUMN dst_domain VARCHAR(128) NOT NULL DEFAULT '';
  105. ALTER TABLE missed_calls ADD COLUMN src_user VARCHAR(64) NOT NULL DEFAULT '';
  106. ALTER TABLE missed_calls ADD COLUMN src_domain VARCHAR(128) NOT NULL DEFAULT '';
  107. ALTER TABLE missed_calls ADD COLUMN src_ip varchar(64) NOT NULL default '';
  108. ALTER TABLE missed_calls ADD COLUMN dst_ouser VARCHAR(64) NOT NULL DEFAULT '';
  109. ALTER TABLE missed_calls ADD COLUMN dst_user VARCHAR(64) NOT NULL DEFAULT '';
  110. ALTER TABLE missed_calls ADD COLUMN dst_domain VARCHAR(128) NOT NULL DEFAULT '';
  111. #!endif
  112.  
  113. ####### Include Local Config If Exists #########
  114. import_file "kamailio-local.cfg"
  115.  
  116. ####### Defined Values #########
  117.  
  118. # *** Value defines - IDs used later in config
  119. #!ifdef WITH_MYSQL
  120. # - database URL - used to connect to database server by modules such
  121. # as: auth_db, acc, usrloc, a.s.o.
  122. #!ifndef DBURL
  123. #!define DBURL "mysql://kamailio:kamailiorw@localhost/kamailio"
  124. #!endif
  125. #!endif
  126. #!ifdef WITH_MULTIDOMAIN
  127. # - the value for 'use_domain' parameters
  128. #!define MULTIDOMAIN 1
  129. #!else
  130. #!define MULTIDOMAIN 0
  131. #!endif
  132.  
  133. # - flags
  134. # FLT_ - per transaction (message) flags
  135. # FLB_ - per branch flags
  136. #!define FLT_ACC 1
  137. #!define FLT_ACCMISSED 2
  138. #!define FLT_ACCFAILED 3
  139. #!define FLT_NATS 5
  140.  
  141. #!define FLB_NATB 6
  142. #!define FLB_NATSIPPING 7
  143.  
  144. ####### Global Parameters #########
  145.  
  146. ### LOG Levels: 3=DBG, 2=INFO, 1=NOTICE, 0=WARN, -1=ERR
  147. #!ifdef WITH_DEBUG
  148. debug=4
  149. log_stderror=yes
  150. #!else
  151. debug=2
  152. log_stderror=no
  153. #!endif
  154.  
  155. memdbg=5
  156. memlog=5
  157.  
  158. log_facility=LOG_LOCAL0
  159. log_prefix="{$mt $hdr(CSeq) $ci} "
  160.  
  161. /* number of SIP routing processes */
  162. children=8
  163.  
  164. /* uncomment the next line to disable TCP (default on) */
  165. # disable_tcp=yes
  166.  
  167. /* uncomment the next line to disable the auto discovery of local aliases
  168. * based on reverse DNS on IPs (default on) */
  169. # auto_aliases=no
  170.  
  171. /* add local domain aliases */
  172. # alias="sip.mydomain.com"
  173.  
  174. /* uncomment and configure the following line if you want Kamailio to
  175. * bind on a specific interface/port/proto (default bind on all available) */
  176. # listen=udp:10.0.0.10:5060
  177.  
  178. #!ifdef WITH_TLS
  179. enable_tls=yes
  180. #!endif
  181.  
  182. /* life time of TCP connection when there is no traffic
  183. * - a bit higher than registration expires to cope with UA behind NAT */
  184. tcp_connection_lifetime=3605
  185.  
  186. ####### Custom Parameters #########
  187.  
  188. /* These parameters can be modified runtime via RPC interface
  189. * - see the documentation of 'cfg_rpc' module.
  190. *
  191. * Format: group.id = value 'desc' description
  192. * Access: $sel(cfg_get.group.id) or @cfg_get.group.id */
  193.  
  194. #!ifdef WITH_PSTN
  195. /* PSTN GW Routing
  196. *
  197. * - pstn.gw_ip: valid IP or hostname as string value, example:
  198. * pstn.gw_ip = "10.0.0.101" desc "My PSTN GW Address"
  199. *
  200. * - by default is empty to avoid misrouting */
  201. pstn.gw_ip = "" desc "PSTN GW Address"
  202. pstn.gw_port = "" desc "PSTN GW Port"
  203. #!endif
  204.  
  205. #!ifdef WITH_VOICEMAIL
  206. /* VoiceMail Routing on offline, busy or no answer
  207. *
  208. * - by default Voicemail server IP is empty to avoid misrouting */
  209. voicemail.srv_ip = "" desc "VoiceMail IP Address"
  210. voicemail.srv_port = "5060" desc "VoiceMail Port"
  211. #!endif
  212.  
  213. ####### Modules Section ########
  214.  
  215. /* set paths to location of modules */
  216. # mpath="/usr/lib/x86_64-linux-gnu/kamailio/modules/"
  217.  
  218. #!ifdef WITH_MYSQL
  219. loadmodule "db_mysql.so"
  220. #!endif
  221.  
  222. loadmodule "jsonrpcs.so"
  223. loadmodule "kex.so"
  224. loadmodule "corex.so"
  225. loadmodule "tm.so"
  226. loadmodule "tmx.so"
  227. loadmodule "sl.so"
  228. loadmodule "rr.so"
  229. loadmodule "pv.so"
  230. loadmodule "maxfwd.so"
  231. loadmodule "usrloc.so"
  232. loadmodule "registrar.so"
  233. loadmodule "textops.so"
  234. loadmodule "siputils.so"
  235. loadmodule "xlog.so"
  236. loadmodule "sanity.so"
  237. loadmodule "ctl.so"
  238. loadmodule "cfg_rpc.so"
  239. loadmodule "acc.so"
  240. loadmodule "counters.so"
  241.  
  242. #!ifdef WITH_AUTH
  243. loadmodule "auth.so"
  244. loadmodule "auth_db.so"
  245. #!ifdef WITH_IPAUTH
  246. loadmodule "permissions.so"
  247. #!endif
  248. #!endif
  249.  
  250. #!ifdef WITH_ALIASDB
  251. loadmodule "alias_db.so"
  252. #!endif
  253.  
  254. #!ifdef WITH_SPEEDDIAL
  255. loadmodule "speeddial.so"
  256. #!endif
  257.  
  258. #!ifdef WITH_MULTIDOMAIN
  259. loadmodule "domain.so"
  260. #!endif
  261.  
  262. #!ifdef WITH_PRESENCE
  263. loadmodule "presence.so"
  264. loadmodule "presence_xml.so"
  265. #!endif
  266.  
  267. #!ifdef WITH_NAT
  268. loadmodule "nathelper.so"
  269. loadmodule "rtpproxy.so"
  270. #!endif
  271.  
  272. #!ifdef WITH_TLS
  273. loadmodule "tls.so"
  274. #!endif
  275.  
  276. #!ifdef WITH_ANTIFLOOD
  277. loadmodule "htable.so"
  278. loadmodule "pike.so"
  279. #!endif
  280.  
  281. #!ifdef WITH_XMLRPC
  282. loadmodule "xmlrpc.so"
  283. #!endif
  284.  
  285. #!ifdef WITH_DEBUG
  286. loadmodule "debugger.so"
  287. #!endif
  288.  
  289. # ----------------- setting module-specific parameters ---------------
  290.  
  291.  
  292. # ----- jsonrpcs params -----
  293. modparam("jsonrpcs", "pretty_format", 1)
  294. /* set the path to RPC fifo control file */
  295. # modparam("jsonrpcs", "fifo_name", "/var/run/kamailio/kamailio_rpc.fifo")
  296. /* set the path to RPC unix socket control file */
  297. # modparam("jsonrpcs", "dgram_socket", "/var/run/kamailio/kamailio_rpc.sock")
  298.  
  299. # ----- ctl params -----
  300. /* set the path to RPC unix socket control file */
  301. # modparam("ctl", "binrpc", "unix:/var/run/kamailio/kamailio_ctl")
  302.  
  303. # ----- tm params -----
  304. # auto-discard branches from previous serial forking leg
  305. modparam("tm", "failure_reply_mode", 3)
  306. # default retransmission timeout: 30sec
  307. modparam("tm", "fr_timer", 30000)
  308. # default invite retransmission timeout after 1xx: 120sec
  309. modparam("tm", "fr_inv_timer", 120000)
  310.  
  311. # ----- rr params -----
  312. # set next param to 1 to add value to ;lr param (helps with some UAs)
  313. modparam("rr", "enable_full_lr", 0)
  314. # do not append from tag to the RR (no need for this script)
  315. modparam("rr", "append_fromtag", 0)
  316.  
  317. # ----- registrar params -----
  318. modparam("registrar", "method_filtering", 1)
  319. /* uncomment the next line to disable parallel forking via location */
  320. # modparam("registrar", "append_branches", 0)
  321. /* uncomment the next line not to allow more than 10 contacts per AOR */
  322. # modparam("registrar", "max_contacts", 10)
  323. /* max value for expires of registrations */
  324. modparam("registrar", "max_expires", 3600)
  325. /* set it to 1 to enable GRUU */
  326. modparam("registrar", "gruu_enabled", 0)
  327.  
  328. # ----- acc params -----
  329. /* what special events should be accounted ? */
  330. modparam("acc", "early_media", 0)
  331. modparam("acc", "report_ack", 0)
  332. modparam("acc", "report_cancels", 0)
  333. /* by default ww do not adjust the direct of the sequential requests.
  334. * if you enable this parameter, be sure the enable "append_fromtag"
  335. * in "rr" module */
  336. modparam("acc", "detect_direction", 0)
  337. /* account triggers (flags) */
  338. modparam("acc", "log_flag", FLT_ACC)
  339. modparam("acc", "log_missed_flag", FLT_ACCMISSED)
  340. modparam("acc", "log_extra",
  341. "src_user=$fU;src_domain=$fd;src_ip=$si;"
  342. "dst_ouser=$tU;dst_user=$rU;dst_domain=$rd")
  343. modparam("acc", "failed_transaction_flag", FLT_ACCFAILED)
  344. /* enhanced DB accounting */
  345. #!ifdef WITH_ACCDB
  346. modparam("acc", "db_flag", FLT_ACC)
  347. modparam("acc", "db_missed_flag", FLT_ACCMISSED)
  348. modparam("acc", "db_url", DBURL)
  349. modparam("acc", "db_extra",
  350. "src_user=$fU;src_domain=$fd;src_ip=$si;"
  351. "dst_ouser=$tU;dst_user=$rU;dst_domain=$rd")
  352. #!endif
  353.  
  354. # ----- usrloc params -----
  355. /* enable DB persistency for location entries */
  356. #!ifdef WITH_USRLOCDB
  357. modparam("usrloc", "db_url", DBURL)
  358. modparam("usrloc", "db_mode", 2)
  359. modparam("usrloc", "use_domain", MULTIDOMAIN)
  360. #!endif
  361.  
  362. # ----- auth_db params -----
  363. #!ifdef WITH_AUTH
  364. modparam("auth_db", "db_url", DBURL)
  365. modparam("auth_db", "calculate_ha1", yes)
  366. modparam("auth_db", "password_column", "password")
  367. modparam("auth_db", "load_credentials", "")
  368. modparam("auth_db", "use_domain", MULTIDOMAIN)
  369.  
  370. # ----- permissions params -----
  371. #!ifdef WITH_IPAUTH
  372. modparam("permissions", "db_url", DBURL)
  373. modparam("permissions", "db_mode", 1)
  374. #!endif
  375.  
  376. #!endif
  377.  
  378. # ----- alias_db params -----
  379. #!ifdef WITH_ALIASDB
  380. modparam("alias_db", "db_url", DBURL)
  381. modparam("alias_db", "use_domain", MULTIDOMAIN)
  382. #!endif
  383.  
  384. # ----- speeddial params -----
  385. #!ifdef WITH_SPEEDDIAL
  386. modparam("speeddial", "db_url", DBURL)
  387. modparam("speeddial", "use_domain", MULTIDOMAIN)
  388. #!endif
  389.  
  390. # ----- domain params -----
  391. #!ifdef WITH_MULTIDOMAIN
  392. modparam("domain", "db_url", DBURL)
  393. /* register callback to match myself condition with domains list */
  394. modparam("domain", "register_myself", 1)
  395. #!endif
  396.  
  397. #!ifdef WITH_PRESENCE
  398. # ----- presence params -----
  399. modparam("presence", "db_url", DBURL)
  400.  
  401. # ----- presence_xml params -----
  402. modparam("presence_xml", "db_url", DBURL)
  403. modparam("presence_xml", "force_active", 1)
  404. #!endif
  405.  
  406. #!ifdef WITH_NAT
  407. # ----- rtpproxy params -----
  408. modparam("rtpproxy", "rtpproxy_sock", "udp:127.0.0.1:7722")
  409.  
  410. # ----- nathelper params -----
  411. modparam("nathelper", "natping_interval", 30)
  412. modparam("nathelper", "ping_nated_only", 1)
  413. modparam("nathelper", "sipping_bflag", FLB_NATSIPPING)
  414. modparam("nathelper", "sipping_from", "sip:pinger@kamailio.org")
  415.  
  416. # params needed for NAT traversal in other modules
  417. modparam("nathelper|registrar", "received_avp", "$avp(RECEIVED)")
  418. modparam("usrloc", "nat_bflag", FLB_NATB)
  419. #!endif
  420.  
  421. #!ifdef WITH_TLS
  422. # ----- tls params -----
  423. modparam("tls", "config", "/etc/kamailio/tls.cfg")
  424. #!endif
  425.  
  426. #!ifdef WITH_ANTIFLOOD
  427. # ----- pike params -----
  428. modparam("pike", "sampling_time_unit", 2)
  429. modparam("pike", "reqs_density_per_unit", 16)
  430. modparam("pike", "remove_latency", 4)
  431.  
  432. # ----- htable params -----
  433. /* ip ban htable with autoexpire after 5 minutes */
  434. modparam("htable", "htable", "ipban=>size=8;autoexpire=300;")
  435. #!endif
  436.  
  437. #!ifdef WITH_XMLRPC
  438. # ----- xmlrpc params -----
  439. modparam("xmlrpc", "route", "XMLRPC");
  440. modparam("xmlrpc", "url_match", "^/RPC")
  441. #!endif
  442.  
  443. #!ifdef WITH_DEBUG
  444. # ----- debugger params -----
  445. modparam("debugger", "cfgtrace", 1)
  446. modparam("debugger", "log_level_name", "exec")
  447. #!endif
  448.  
  449.  
  450. loadmodule "cdp.so"
  451. modparam("cdp", "config_file", "/etc/kamailio/diametercfg.xml")
  452. modparam("cdp", "debug_heavy", 1)
  453. loadmodule "cdp_avp.so"
  454.  
  455. loadmodule "ims_diameter_server.so"
  456.  
  457. ####### Routing Logic ########
  458.  
  459.  
  460. /* Main SIP request routing logic
  461. * - processing of any incoming SIP request starts with this route
  462. * - note: this is the same as route { ... } */
  463. request_route {
  464.  
  465. xlog("Received request with method $rm");
  466. }
  467.  
  468. event_route[diameter:request] {
  469. xlog("Got diameter message");
  470. xlog("Diamater Application Code: $diameter_application");
  471. xlog("Diameter Command Code: $diameter_command");
  472. xlog("Diameter Request $diameter_request");
  473. if(cdp_check_peer("ims-hss.localdomain")) {
  474. xlog("Peer ims-hss.localdomain is online - Checking capabilities");
  475.  
  476. if(cdp_has_app($diameter_application)) {
  477. xlog("Has required app and can process");
  478.  
  479. if(!cdp_has_app("10415", "318")) {
  480. xlog("Has vendor ID and application required");
  481. }else{
  482. xlog("Missing vendor ID and applications support in current peers");
  483. }
  484.  
  485.  
  486. }else{
  487. xlog("Does not have required app and cannot process");
  488. }
  489. }else{
  490. xlog("Peer ims-hss.localdomain is not online");
  491. exit;
  492. }
  493. diameter_request("ims-hss.localdomain", "$diameter_application", "$diameter_command", "$diameter_request");
  494. xlog("Forwarded Diameter Request");
  495. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement