1.12 黑名单参数

1. dst_blocklist_expire Alias name: dst_blocklist_ttl How much time a blocklisted destination will be kept in the blocklist (w/o any update). dst_blocklist_expire = time in s (default 60 s) 2. dst_blocklist_gc_interval How often the garbage collection will run (eliminating old, expired entries). dst_blocklist_gc_interval = time in s (default 60 s) 3. dst_blocklist_init If off, the blocklist is not initialized at startup and cannot be enabled at runtime, this saves some memory. ...

1 min · Eddie Wang

1.13 实时参数

1. real_time Sets real time priority for all the Kamailio processes, or the timers (bitmask). Possible values: 0 - off 1 - the "fast" timer 2 - the "slow" timer 4 - all processes, except the timers Example: real_time= 7 => everything switched to real time priority. real_time = <int> (flags) (default off) 2. rt_policy Real time scheduling policy, 0 = SCHED_OTHER, 1= SCHED_RR and 2=SCHED_FIFO rt_policy= <0..3> (default 0) 3. rt_prio Real time priority used for everything except the timers, if real_time is enabled. ...

1 min · Eddie Wang

1.14 核心函数

Functions exported by core that can be used in route blocks. 1. add_local_rport ⭐️ Add rport parameter to local generated Via header – see RFC3581. In effect for forwarded SIP requests. Example of usage: add_local_rport(); 2. avpflags 3. break ‘break’ statement can be used to end a ‘case’ block in a ‘switch’ statement or exit from a ‘while’ statement. 4. drop ⭐️ Stop the execution of the configuration script and alter the implicit action which is done afterwards. ...

9 min · Eddie Wang

1.15 自定义全局参数

These are parameters that can be defined by the writer of kamailio.cfg in order to be used inside routing blocks. One of the important properties for custom global parameters is that their value can be changed at runtime via RPC commands, without restarting Kamailio. The definition of a custom global parameter must follow the pattern: group.variable = value desc "description" The value can be a quoted string or integer number. ...

1 min · Eddie Wang

1.16 路由块 - 请求路由、响应路由、分支路由、失败路由等

1. Routing Blocks The routing blocks are the parts of the configuration file executed by kamailio at runtime. They can be seen as blocks of actions similar to functions (or procedures) from common programming languages. A routing block is identified by a specific token, followed by a name in between square brackets and actions in between curly braces. route_block_id[NAME] { ACTIONS } The name can be any alphanumeric string, with specific routing blocks enforcing a particular format. ...

8 min · Eddie Wang

1.17 脚本语法 - if、else、switch、while、赋值、比较、算数等

1. if IF-ELSE statement Prototype: if(expr) { actions; } else { actions; } The expr should be a valid logical expression. The logical operators that can be used in expr: ==: equal !=: not equal =~: case-insensitive regular expression matching: Note: Posix regular expressions will be used, e.g. use [[:digit:]]{3} instead of \d\d\d !~: regular expression not-matching (NOT PORTED from Kamailio 1.x, use !(x =~ y)) >: greater >=: greater or equal <: less <=: less or equal &&: logical AND ||: logical OR !: logical NOT Example of usage: ...

5 min · Eddie Wang

1.18 命令行参数

Command Line Parameters Kamailio can be started with a set of command line parameters, providing more flexibility to control what is doing at runtime. Some of them can be quite useful when running on containerised environments. To see the the available command line parameters, run kamailio -h: # kamailio -h version: kamailio 5.4.0-dev4 (x86_64/darwin) 8c1864 Usage: kamailio [options] Options: -a mode Auto aliases mode: enable with yes or on, disable with no or off --alias=val Add an alias, the value has to be '[proto:]hostname[:port]' (like for 'alias' global parameter) -A define Add config pre-processor define (e.g., -A WITH_AUTH, -A 'FLT_ACC=1', -A 'DEFVAL="str-val"') -b nr Maximum receive buffer size which will not be exceeded by auto-probing procedure even if OS allows -c Check configuration file for syntax errors -d Debugging mode (multiple -d increase the level) -D Control how daemonize is done: -D..do not fork (almost) anyway; -DD..do not daemonize creator; -DDD..daemonize (default) -e Log messages printed in terminal colors (requires -E) -E Log to stderr -f file Configuration file (default: /usr/local/etc/kamailio/kamailio.cfg) -g gid Change gid (group id) -G file Create a pgid file -h This help message --help Long option for `-h` -I Print more internal compile flags and options -K Turn on "via:" host checking when forwarding replies -l address Listen on the specified address/interface (multiple -l mean listening on more addresses). The address format is [proto:]addr_lst[:port][/advaddr], where proto=udp|tcp|tls|sctp, addr_lst= addr|(addr, addr_lst), addr=host|ip_address|interface_name and advaddr=addr[:port] (advertised address). E.g: -l localhost, -l udp:127.0.0.1:5080, -l eth0:5062, -l udp:127.0.0.1:5080/1.2.3.4:5060, -l "sctp:(eth0)", -l "(eth0, eth1, 127.0.0.1):5065". The default behaviour is to listen on all the interfaces. --loadmodule=name load the module specified by name --log-engine=log engine name and data -L path Modules search path (default: /usr/local/lib64/kamailio/modules) -m nr Size of shared memory allocated in Megabytes --modparam=modname:paramname:type:value set the module parameter type has to be 's' for string value and 'i' for int value, example: --modparam=corex:alias_subdomains:s:kamailio.org -M nr Size of private memory allocated, in Megabytes -n processes Number of child processes to fork per interface (default: 8) -N Number of tcp child processes (default: equal to `-n') -O nr Script optimization level (debugging option) -P file Create a pid file -Q Number of sctp child processes (default: equal to `-n') -r Use dns to check if is necessary to add a "received=" field to a via -R Same as `-r` but use reverse dns; (to use both use `-rR`) --server-id=num set the value for server_id --subst=exp set a subst preprocessor directive --substdef=exp set a substdef preprocessor directive --substdefs=exp set a substdefs preprocessor directive -S disable sctp -t dir Chroot to "dir" -T Disable tcp -u uid Change uid (user id) -v Version number --version Long option for `-v` -V Alternative for `-v` -x name Specify internal manager for shared memory (shm) - can be: fm, qm or tlsf -X name Specify internal manager for private memory (pkg) - if omitted, the one for shm is used -Y dir Runtime dir path -w dir Change the working directory to "dir" (default: "/") -W type poll method (depending on support in OS, it can be: poll, epoll_lt, epoll_et, sigio_rt, select, kqueue, /dev/poll)

3 min · Eddie Wang

1.19 日志引擎

Log Engine CLI Parameter The –log-engine parameter allows to specify what logging engine to be used, which is practically about the format of the log messages. If not set at all, then Kamailio does the classic style of line-based plain text log messages. The value of this parameter can be –log-engine=name or –log-engine=name:data. The name of the log engine can be: json - write logs in structured JSON format the data for json log engine can be a set of character flags: a - add log prefix as a special field A - do not add log prefix c - add Call-ID (when available) as a dedicated JSON attribute j - the log prefix and message fields are printed in JSON structure format, detecting if they are enclosed in between { } or adding them as a text field M - strip EOL (’\n’) from the value of the log message field N - do not add EOL at the end of JSON document p - the log prefix is printed as it is in the root json document, it has to start with comma (,) and be a valid set of json fields U - CEE (Common Event Expression) schema format - https://cee.mitre.org/language/1.0-beta1/core-profile.html Example of JSON logs when running Kamailio with “–log-engine=json:M” : ...

2 min · Eddie Wang

1.2 通用元素 - 注释、标识符、变量、值、表达式

1. Comments Line comments start with # (hash/pound character - like in shell) or / / (double forward slash - like in C++/Java). Block comments start with /* (forward slash and asterisk) and are ended by */ (sterisk and forward slash) (like in C, C++, Java). Example: # this is a line comment // this is another line comment /* this is a block comment */ Important: be aware of preprocessor directives that start with #! (hash/pound and exclamation) - those are no longer line comments. ...

2 min · Eddie Wang

1.3 预处理指令 - 文件导入、宏定义、环境变量读取

预处理指令主要的目的是方便脚本维护,方便脚本在不同环境下运行。 预处理之后,脚本才会开始解析。 1. include_file include_file "path_to_file" Include the content of the file in config before parsing. path_to_file must be a 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 it. 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. ...

5 min · Eddie Wang