Advertisement
Guest User

Untitled

a guest
Aug 4th, 2016
169
-1
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.27 KB | None | 0 1
  1. #!KAMAILIO
  2. #
  3. # Kamailio (OpenSER) SIP Server v4.4 - 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. #!define WITH_NAT
  15. #
  16. #!ifndef DBURL
  17. #!define DBURL "mysql://kamailio:kamailiorw@localhost/kamailio"
  18. #!endif
  19. #
  20. #!ifdef ACCDB_COMMENT
  21. ALTER TABLE acc ADD COLUMN src_user VARCHAR(64) NOT NULL DEFAULT '';
  22. ALTER TABLE acc ADD COLUMN src_domain VARCHAR(128) NOT NULL DEFAULT '';
  23. ALTER TABLE acc ADD COLUMN src_ip varchar(64) NOT NULL default '';
  24. ALTER TABLE acc ADD COLUMN dst_ouser VARCHAR(64) NOT NULL DEFAULT '';
  25. ALTER TABLE acc ADD COLUMN dst_user VARCHAR(64) NOT NULL DEFAULT '';
  26. ALTER TABLE acc ADD COLUMN dst_domain VARCHAR(128) NOT NULL DEFAULT '';
  27. ALTER TABLE missed_calls ADD COLUMN src_user VARCHAR(64) NOT NULL DEFAULT '';
  28. ALTER TABLE missed_calls ADD COLUMN src_domain VARCHAR(128) NOT NULL DEFAULT '';
  29. ALTER TABLE missed_calls ADD COLUMN src_ip varchar(64) NOT NULL default '';
  30. ALTER TABLE missed_calls ADD COLUMN dst_ouser VARCHAR(64) NOT NULL DEFAULT '';
  31. ALTER TABLE missed_calls ADD COLUMN dst_user VARCHAR(64) NOT NULL DEFAULT '';
  32. ALTER TABLE missed_calls ADD COLUMN dst_domain VARCHAR(128) NOT NULL DEFAULT '';
  33. #!endif
  34.  
  35. ####### Include Local Config If Exists #########
  36. import_file "kamailio-local.cfg"
  37.  
  38. ####### Defined Values #########
  39.  
  40. # *** Value defines - IDs used later in config
  41. #!ifdef WITH_MYSQL
  42. # - database URL - used to connect to database server by modules such
  43. # as: auth_db, acc, usrloc, a.s.o.
  44. #!ifndef DBURL
  45. #!define DBURL "mysql://kamailio:kamailiorw@localhost/kamailio"
  46. #!endif
  47. #!endif
  48. #!ifdef WITH_MULTIDOMAIN
  49. # - the value for 'use_domain' parameters
  50. #!define MULTIDOMAIN 1
  51. #!else
  52. #!define MULTIDOMAIN 0
  53. #!endif
  54.  
  55. # - flags
  56. # FLT_ - per transaction (message) flags
  57. # FLB_ - per branch flags
  58. #!define FLT_ACC 1
  59. #!define FLT_ACCMISSED 2
  60. #!define FLT_ACCFAILED 3
  61. #!define FLT_NATS 5
  62.  
  63. #!define FLB_NATB 6
  64. #!define FLB_NATSIPPING 7
  65.  
  66. ####### Global Parameters #########
  67.  
  68. ### LOG Levels: 3=DBG, 2=INFO, 1=NOTICE, 0=WARN, -1=ERR
  69. #!ifdef WITH_DEBUG
  70. debug=4
  71. log_stderror=yes
  72. #!else
  73. debug=2
  74. log_stderror=no
  75. #!endif
  76.  
  77. memdbg=5
  78. memlog=5
  79.  
  80. log_facility=LOG_LOCAL0
  81.  
  82. #MultiHomed for Multi Nics
  83. mhomed=1
  84.  
  85. # number of SIP routing processes
  86. children=8
  87.  
  88. /* uncomment the next line to disable TCP (default on) */
  89. #disable_tcp=yes
  90.  
  91. /* uncomment the next line to disable the auto discovery of local aliases
  92. based on reverse DNS on IPs (default on) */
  93. #auto_aliases=no
  94.  
  95. /* add local domain aliases */
  96. #alias="sip.mydomain.com"
  97.  
  98. /* uncomment and configure the following line if you want Kamailio to
  99. bind on a specific interface/port/proto (default bind on all available) */
  100. #listen=udp:10.0.0.10:5060
  101.  
  102. /* port to listen to */
  103. #port=5060
  104.  
  105. #!ifdef WITH_TLS
  106. enable_tls=yes
  107. #!endif
  108.  
  109. # life time of TCP connection when there is no traffic
  110. # - a bit higher than registration expires to cope with UA behind NAT
  111. tcp_connection_lifetime=3605
  112.  
  113. ####### Custom Parameters #########
  114.  
  115. # These parameters can be modified runtime via RPC interface
  116. # - see the documentation of 'cfg_rpc' module.
  117. #
  118. # Format: group.id = value 'desc' description
  119. # Access: $sel(cfg_get.group.id) or @cfg_get.group.id
  120. #
  121.  
  122. #!ifdef WITH_PSTN
  123. # PSTN GW Routing
  124. #
  125. # - pstn.gw_ip: valid IP or hostname as string value, example:
  126. # pstn.gw_ip = "10.0.0.101" desc "My PSTN GW Address"
  127. #
  128. # - by default is empty to avoid misrouting
  129. pstn.gw_ip = "" desc "PSTN GW Address"
  130. pstn.gw_port = "" desc "PSTN GW Port"
  131. #!endif
  132.  
  133. #!ifdef WITH_VOICEMAIL
  134. # VoiceMail Routing on offline, busy or no answer
  135. #
  136. # - by default Voicemail server IP is empty to avoid misrouting
  137. voicemail.srv_ip = "" desc "VoiceMail IP Address"
  138. voicemail.srv_port = "5060" desc "VoiceMail Port"
  139. #!endif
  140.  
  141. ####### Modules Section ########
  142.  
  143. # set paths to location of modules (to sources or installation folders)
  144. #!ifdef WITH_SRCPATH
  145. mpath="modules/"
  146. #!else
  147. mpath="/usr/lib/x86_64-linux-gnu/kamailio/modules/"
  148. #!endif
  149.  
  150.  
  151. loadmodule "db_mysql.so"
  152. loadmodule "mi_fifo.so"
  153. loadmodule "kex.so"
  154. loadmodule "tm.so"
  155. loadmodule "tmx.so"
  156. loadmodule "sl.so"
  157. loadmodule "rr.so"
  158. loadmodule "pv.so"
  159. loadmodule "maxfwd.so"
  160. loadmodule "textops.so"
  161. loadmodule "siputils.so"
  162. loadmodule "xlog.so"
  163. loadmodule "sanity.so"
  164. loadmodule "ctl.so"
  165. loadmodule "mi_rpc.so"
  166. loadmodule "acc.so"
  167. loadmodule "dispatcher.so"
  168. loadmodule "rtpengine.so"
  169.  
  170. # ----------------- setting module-specific parameters ---------------
  171.  
  172.  
  173. # ----- mi_fifo params -----
  174. modparam("mi_fifo", "fifo_name", "/tmp/kamailio_fifo")
  175.  
  176.  
  177. # ----- rr params -----
  178. # add value to ;lr param to cope with most of the UAs
  179. modparam("rr", "enable_full_lr", 1)
  180. # do not append from tag to the RR (no need for this script)
  181. modparam("rr", "append_fromtag", 0)
  182.  
  183.  
  184. # ----- acc params -----
  185. modparam("acc", "log_flag", 1)
  186. modparam("acc", "failed_transaction_flag", 3)
  187. modparam("acc", "log_extra",
  188. "src_user=$fU;src_domain=$fd;dst_ouser=$tU;dst_user=$rU;dst_domain=$rd;src_ip=$si")
  189.  
  190. # ----- tm params -----
  191. modparam("tm", "fr_timer", 2000)
  192. modparam("tm", "fr_inv_timer", 40000)
  193.  
  194. # ----- dispatcher params -----
  195. modparam("dispatcher", "db_url", DBURL)
  196. modparam("dispatcher", "table_name", "dispatcher")
  197. modparam("dispatcher", "flags", 2)
  198. modparam("dispatcher", "dst_avp", "$avp(AVP_DST)")
  199. modparam("dispatcher", "grp_avp", "$avp(AVP_GRP)")
  200. modparam("dispatcher", "cnt_avp", "$avp(AVP_CNT)")
  201.  
  202. # ---- RtpEngine Params ----
  203. # single rtproxy
  204. #modparam("rtpengine", "rtpengine_sock", "udp:10.200.0.41:22222")
  205. # load balanced rtp
  206. modparam("rtpengine", "rtpengine_sock","udp:debsbc01:22222 udp:debsbc02:22222")
  207.  
  208. ####### Routing Logic ########
  209.  
  210.  
  211. # main request routing logic
  212.  
  213. route {
  214.  
  215. # per request initial checks
  216. route(REQINIT);
  217.  
  218. # handle requests within SIP dialogs
  219. route(WITHINDLG);
  220.  
  221. ### only initial requests (no To tag)
  222.  
  223. # CANCEL processing
  224. if (is_method("CANCEL"))
  225. {
  226. if (t_check_trans())
  227. t_relay();
  228. exit;
  229. }
  230.  
  231. t_check_trans();
  232.  
  233. # record routing for dialog forming requests (in case they are routed)
  234. # - remove preloaded route headers
  235. remove_hf("Route");
  236. if (is_method("INVITE|SUBSCRIBE"))
  237. record_route();
  238.  
  239. # account only INVITEs
  240. if (is_method("INVITE"))
  241. {
  242. setflag(1); # do accounting
  243. }
  244.  
  245. # handle presence related requests
  246. route(PRESENCE);
  247.  
  248. # handle registrations
  249. route(REGISTRAR);
  250.  
  251. if ($rU==$null)
  252. {
  253. # request with no Username in RURI
  254. sl_send_reply("484","Address Incomplete");
  255. exit;
  256. }
  257.  
  258. # dispatch destinations
  259. route(DISPATCH);
  260. }
  261.  
  262.  
  263. route[RELAY] {
  264. if (!t_relay()) {
  265. sl_reply_error();
  266. }
  267. exit;
  268. }
  269.  
  270. # Per SIP request initial checks
  271. route[REQINIT] {
  272. if (!mf_process_maxfwd_header("10")) {
  273. sl_send_reply("483","Too Many Hops");
  274. exit;
  275. }
  276.  
  277. if(!sanity_check("1511", "7"))
  278. {
  279. xlog("Malformed SIP message from $si:$sp\n");
  280. exit;
  281. }
  282. }
  283.  
  284. # Handle requests within SIP dialogs
  285. route[WITHINDLG] {
  286. if (has_totag()) {
  287. # sequential request withing a dialog should
  288. # take the path determined by record-routing
  289. if (loose_route()) {
  290. if (is_method("BYE")) {
  291. setflag(1); # do accounting ...
  292. setflag(3); # ... even if the transaction fails
  293. }
  294. route(RELAY);
  295. } else {
  296. if (is_method("SUBSCRIBE") && uri == myself) {
  297. # in-dialog subscribe requests
  298. route(PRESENCE);
  299. exit;
  300. }
  301. if ( is_method("ACK") ) {
  302. if ( t_check_trans() ) {
  303. # non loose-route, but stateful ACK;
  304. # must be ACK after a 487 or e.g. 404 from upstream server
  305. t_relay();
  306. exit;
  307. } else {
  308. # ACK without matching transaction ... ignore and discard.
  309. exit;
  310. }
  311. }
  312. sl_send_reply("404","Not here");
  313. }
  314. exit;
  315. }
  316. }
  317.  
  318. # Handle SIP registrations
  319. route[REGISTRAR] {
  320. if(!is_method("REGISTER"))
  321. return;
  322. sl_send_reply("404", "No registrar");
  323. exit;
  324. }
  325.  
  326. # Presence server route
  327. route[PRESENCE] {
  328. if(!is_method("PUBLISH|SUBSCRIBE"))
  329. return;
  330.  
  331. sl_send_reply("404", "Not here");
  332. exit;
  333. }
  334.  
  335. # Dispatch requests
  336. route[DISPATCH] {
  337. # round robin dispatching on gateways group '1'
  338. if(!ds_select_dst("1", "4"))
  339. {
  340. send_reply("404", "No destination");
  341. exit;
  342. }
  343. xlog("L_DBG", "--- SCRIPT: going to <$ru> via <$du>\n");
  344. t_on_failure("RTF_DISPATCH");
  345. route(RELAY);
  346. exit;
  347. }
  348.  
  349. # Sample failure route
  350. failure_route[RTF_DISPATCH] {
  351. if (t_is_canceled()) {
  352. exit;
  353. }
  354. # next DST - only for 500 or local timeout
  355. if (t_check_status("500")
  356. or (t_branch_timeout() and !t_branch_replied()))
  357. {
  358. if(ds_next_dst())
  359. {
  360. t_on_failure("RTF_DISPATCH");
  361. route(RELAY);
  362. exit;
  363. }
  364. }
  365. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement