Kamailio-kamailio.cfg: Difference between revisions

From 탱이의 잡동사니
Jump to navigation Jump to search
Line 142: Line 142:
   
   
"sip:" + $var(prefix) + $rU + "@" + $rd
"sip:" + $var(prefix) + $rU + "@" + $rd
</pre>
== Config Pre-Processor Directives ==
=== include_file ===
<pre>
  include_file "path_to_file"
</pre>
Include the content of the file in config before parsing.
path_to_file 은 반드시 static string 이어야 한다. Including file operation is done at startup. If you change the content of included file, you have to restart the SIP server to become effective.
The path_to_file can be relative or absolute. If it is not absolute path, first attempt is to locate it relative to current directory, and if fails, relative to directory of the file that includes int. There is no restriction where include can be used or what can contain - any part of config file is ok. There is a limit of maximum 10 includes in depth, otherwise you can use as many includes as you want. Reporting of the cfg file syntax errors prints now the file name for easier troubleshooting.
If the included file is not found, the config file parser throws error. You can find this error message at the logging destination, usually in the system logging file.
You can use also the syntax '''#!include_file''' or '''!!include_file'''.
<pre>
route {
    ...
    include_file "/sr/checks.cfg"
    ...
}
--- /sr/checks.cfg ---
  if (!mf_process_maxfwd_header("10")) {
      sl_send_reply("483","Too Many Hops");
      exit;
  }
---
</pre>
</pre>



Revision as of 15:45, 13 July 2019

Overview

kamailio.cfg 파일 내용 정리

Basic

kamailio.cfg 파일은 크게 세가지 영역으로 구분된다.

  • global parameters
  • modules settings
  • routing blocks

Global Parameters Section

Configuration 파일의 첫번째 부분으로, Kamailio 의 core 와 custom global parameter 설정을 한다.

일반적으로 다음과 같이 설정된다.

name=value

name 부분은 core parameter 에 나와있는 항목이어야 한다. 만약 항목에 없는 name 을 설정했다면, kamailio 는 에러를 발생시키고 시작하지 앟는다.

value 부분은 integer, boolean, string 으로 설정한다. 하지만 몇몇 parameter 들은 복합된 형식의 value 로도 설정이 가능하다.

log_facility=LOG_LOCAL0

children=4

disable_tcp=yes

alias="sip.mydomain.com"

listen=udp:10.0.0.10:5060

대부분의 parameter의 설정은 라인의 끝부분까지이지만, 세미콜론(;)을 사용할 수도 있다. 이는 parameter 설정이 한번에 여러개의 값을 설정할 수 있도록 허용한 경우에 사용할 수 있다.

alias="sip.mydomain.com";

만약 reserved config keyword 를 parameter로 사용하고 싶다면, ""로 감싸야 한다. 아래의 예에서 reserved config keyword 는 "dns"이다.

listen=tcp:127.0.0.1:5060 advertise "sip.dns.example.com":5060

Modules Settings Section

Configuration file 의 두번째 부분으로써, module 들을 로드하는 지시어와 설정값들로 이루어져 있다.

설정의 첫부분에는 mpath 지시어로 모듈 디렉토리를 지정한다.

/* set paths to location of modules */
# mpath="/usr/local/lib64/kamailio/modules/"

loadmoudle 과 modparam 지시어가 사용된다.

loadmodule "debugger.so"
...
modparam("debugger", "cfgtrace", 1)

Routing Blocks Section

Configuration 파일의 마지막 부분으로서 SIP 트래픽의 routing logic 을 설정한다.

가장 중요한 routing block 은 request_route 이다. 이 request_route 에서 SIP 트래픽의 경로를 결정한다.

request_route {
 
    # per request initial checks
    route(REQINIT);
 
    ...
}
 
branch_route[MANAGE_BRANCH] {
    xdbg("new branch [$T_branch_idx] to $ru\n");
    route(NATMANAGE);
}

Generic Elements

Comments

  1. 혹은 // 로 시작하는 라인은 해당 라인이 코멘트로 인식된다.

/* 과 */ 에 포함되는 모든 부분도 코멘트로 인식된다.

  # this is a line comment
  
  // this is another line comment
  
  /* this
     is
     a
     block
     comment */

단, #! 로 시작되는 preprocessor 지시어는 코멘트 처리되지 않는다.

Values

세가지 타입의 value 가 있다.

  • integer: Numbers of 32-bit size.
  • boolean: aliases to 1(true, on, yes) or 0(false, off, no).
  • string: tokens enclosed in between double or single quotes.
// next two are strings
 
  "this is a string value"
  'this is another string value"
 
// next is a boolean
 
  yes
 
// next is an integer
 
  64

Identifiers

Identifiers are tokens which are not enclosed in single or double quotes and to match the rules for integer or boolean values.

return

Variables

Variable 은 $로 시작한다.

$var(x) = $rU + "@" + $fd;

Actions

An action is an element used inside routing blocks ended by ;(semicolon). It can be an execution of a function from core or module, a conditional or loop statement, an assignment expression.

  sl_send_reply("404", "Not found");
  exit;

Expressions

An expression is an association group of statements, variables, functions and operatiors.

if(!t_relay())
 
if($var(x)>10)
 
"sip:" + $var(prefix) + $rU + "@" + $rd

Config Pre-Processor Directives

include_file

   include_file "path_to_file"

Include the content of the file in config before parsing.

path_to_file 은 반드시 static string 이어야 한다. Including file operation is done at startup. If you change the content of included file, you have to restart the SIP server to become effective.

The path_to_file can be relative or absolute. If it is not absolute path, first attempt is to locate it relative to current directory, and if fails, relative to directory of the file that includes int. There is no restriction where include can be used or what can contain - any part of config file is ok. There is a limit of maximum 10 includes in depth, otherwise you can use as many includes as you want. Reporting of the cfg file syntax errors prints now the file name for easier troubleshooting.

If the included file is not found, the config file parser throws error. You can find this error message at the logging destination, usually in the system logging file.

You can use also the syntax #!include_file or !!include_file.

route {
    ...
    include_file "/sr/checks.cfg"
    ...
}
 
--- /sr/checks.cfg ---
 
   if (!mf_process_maxfwd_header("10")) {
       sl_send_reply("483","Too Many Hops");
       exit;
   }
 
---

See also