cookbooks:devel:pseudovariables
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
cookbooks:devel:pseudovariables [2021/04/27 07:34] – miconda | cookbooks:devel:pseudovariables [2022/04/11 13:24] (current) – geoip2 henningw | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== | + | ====== |
Version: Kamailio SIP Server v5.6.x (devel) | Version: Kamailio SIP Server v5.6.x (devel) | ||
- | ===== Overview ===== | + | {{ : |
- | This tutorial collects the functions and parameters exported by Kamailio core to configuration file. | + | ===== Introduction ===== |
- | **Note: | + | The term “pseudo-variable” is used for special tokens that can be given as parameters |
- | ===== Structure ===== | + | The beginning of a “pseudo-variable” is marked by the character “$”. If you want to have the character “$” just double it “$$”. |
- | The structure | + | There is a set of predefined pseudo-variables, |
- | | + | Pseudo-Variables are implemented by various modules, most of them are provided by **pv** (if there is no special reference to a module, expect that the pseudo-variable is provided by **pv** module). |
- | | + | |
- | | + | |
- | For clarity and making it easy to maintain, it is recommended to keep them in this order, although some of them can be mixed. | + | ===== Pseudo-variables usage ===== |
- | ==== Global Parameters Section ==== | ||
- | This is the first part of the configuration file, containing the parameters for the core of kamailio and custom global parameters. | + | Pseudo-variables can be used with many modules, among them: |
- | Typically this is formed by directives of the form: | + | * acc |
+ | * avpops | ||
+ | * htable | ||
+ | * http_async_client | ||
+ | * textops | ||
+ | * uac | ||
+ | * xlog | ||
- | < | + | ===== The list of pseudo-variables ===== |
- | name=value | + | |
- | </ | + | |
- | The name corresponds to a core parameter as listed in one of the next sections of this document. If a name is not matching a core parameter, then Kamailio will not start, rising an error during startup. | ||
- | The value is typically an integer, boolean or a string. | + | Predefined pseudo-variables are listed in alphabetical order. |
- | Several parameters can get a complex value which is formed from a group of integer, strings or identifiers. For example, such parameter is **listen**, which can be assigned a value like **proto: | + | ==== $$ - Pseudo-variable marker ==== |
- | Example of content: | + | **$$** - represents the character ' |
- | <code c> | + | ==== $_s(format) - Evaluate dynamic format ==== |
- | log_facility=LOG_LOCAL0 | + | |
- | children=4 | + | **$_s(format)** - returns the string after evaluating all pseudo-variables in format |
- | disable_tcp=yes | + | < |
+ | $var(x) | ||
- | alias=" | + | # is equivalent of: |
- | listen=udp:10.0.0.10: | + | $var(x) |
</ | </ | ||
- | Usually setting a parameter is ended by end of line, but it can be also ended with **;** (semicolon). This should be used when the grammar of a parameter allows values on multiple lines (like **listen** or **alias**) and the next line creates a conflict by being swallowed as part of value for previous parameter. | + | ==== $ai - URI inP-Asserted-Identity header ==== |
- | <code c> | + | **$ai** - reference to URI in request' |
- | alias=" | + | |
- | </ | + | |
- | If you want to use a reserved config keyword as part of a parameter, you need to enclose it in quotes. See the example below for the keyword " | + | ==== $adu - Auth Digest URI ==== |
- | <code c> | + | **$adu** - URI from Authorization or Proxy-Authorization header. This URI is used when calculating the HTTP Digest Response. |
- | listen=tcp: | + | |
- | </ | + | |
- | ==== Modules Settings Section ==== | + | |
- | This is the second section of the configuration file, containing the directives to load modules and set their parameters. | + | ==== $aa - Auth algorithm ==== |
- | It contains the directives | + | **$aa** - algorithm from Authorization or Proxy-Authorization header. |
- | Example of content: | + | ==== $ar - Auth realm ==== |
- | <code c> | + | **$ar** - realm from Authorization or Proxy-Authorization header |
- | loadmodule " | + | |
- | ... | + | |
- | modparam(" | + | |
- | </ | + | |
- | ==== Routing Blocks Section ==== | ||
- | This is the last section of the configuration file, typically the biggest one, containing the routing blocks with the routing logic for SIP traffic handled by Kamailio. | + | ==== $au - Auth username user ==== |
- | The only mandatory routing block is **request_route**, which contains the actions for deciding the routing for SIP requests. | + | **$au** - user part of username from Authorization or Proxy-Authorization header |
- | See the chapter **Routing Blocks** in this document for more details about what types of routing blocks can be used in the configuration file and their role in routing SIP traffic and Kamailio behaviour. | ||
- | Example of content: | + | ==== $ad - Auth username domain ==== |
- | <code c> | + | **$ad** - domain part of username from Authorization or Proxy-Authorization header |
- | request_route { | + | |
- | # per request initial checks | ||
- | route(REQINIT); | ||
- | ... | + | ==== $aU - Auth whole username ==== |
- | } | + | |
- | branch_route[MANAGE_BRANCH] { | + | **$aU** - whole username from Authorization or Proxy-Authorization header |
- | xdbg(" | + | |
- | route(NATMANAGE); | + | |
- | } | + | |
- | </ | + | |
- | ===== Generic Elements ===== | + | ==== $Au - Acc username and realm/ |
- | ==== Comments ==== | + | **$Au** - username for accounting purposes. It's a selective pseudo variable (inherited from acc module). It returns the auth username and realm ($au@$ar) if exists or From URI ($fu) otherwise. |
- | Line comments start with **#** (hash/pound character | + | ==== $AU - Acc username ==== |
- | Block comments start with /* (forward slash and asterisk) and are ended by */ (sterisk and forward slash) (like in C, C++, Java). | + | **$AU** - username for accounting purposes. It's a selective pseudo variable |
- | + | ==== $branch(name) - Branch attributes ==== | |
- | Example: | + | |
- | + | ||
- | < | + | |
- | # this is a line comment | + | |
- | + | ||
- | // this is another line comment | + | |
- | + | ||
- | /* this | + | |
- | is | + | |
- | a | + | |
- | | + | |
- | | + | |
- | </ | + | |
- | Important: be aware of preprocessor directives that start with **#!** (hash/pound and exclamation) - those are no longer line comments. | + | **$branch(name)** - reference to attribute ' |
- | ==== Values ==== | + | This pseudo variable gives you access to the " |
- | There are three types of values: | + | The ' |
- | * integer | + | * uri - return uri of the branch |
- | * boolean | + | * dst_uri |
- | * string | + | * path - return the path vector for the branch |
+ | * q - return the q value of the branch | ||
+ | * send_socket - return the socket to be used to send the branch | ||
+ | * count - return the number of the branches | ||
+ | * flags - return the branch flags value | ||
+ | * ruid - return the ruid of the branch (Record internal Unique ID from usrloc) | ||
+ | The PV can take an index to access a specif branch: $(branch(name)[index]) | ||
Example: | Example: | ||
<code c> | <code c> | ||
- | // next two are strings | + | $var(i)=0; |
- | + | while($var(i)< | |
- | "this is a string value" | + | { |
- | ' | + | xlog("$(branch(uri)[$var(i)])\n"); |
- | + | $var(i) = $var(i) + 1; | |
- | // next is a boolean | + | } |
- | + | ||
- | yes | + | |
- | + | ||
- | // next is an integer | + | |
- | + | ||
- | 64 | + | |
</ | </ | ||
- | ==== Identifiers ==== | + | Starting with 3.1.0, you can assign value per attribute. Index can be used to update a specific branch: |
- | + | ||
- | Identifiers are tokens which are not enclosed in single or double quotes and to match the rules for integer or boolean values. | + | |
- | + | ||
- | For example, the identifiers are the core parameters and functions, module functions, core keywords and statements. | + | |
- | + | ||
- | Example: | + | |
<code c> | <code c> | ||
- | return | + | $(branch(attr)[index]) = value; |
</ | </ | ||
- | ==== Variables ==== | + | If index is missing, first branch is used. If index is -1 the last branch is used. |
- | The variables start with **$** (dollar character). | + | Assigning |
- | + | ||
- | You can see the list with available variables in the Pseudo-Variables Cookbook. | + | |
- | + | ||
- | Example: | + | |
<code c> | <code c> | ||
- | $var(x) = $rU + " | + | $(branch(uri)[2]) = "sip:test@kamailio.org; |
</ | </ | ||
- | ==== Actions ==== | ||
- | An action is an element used inside routing blocks ended by **;** (semicolon). It can be an execution of a function from core or a module, a conditional or loop statement, an assignment expression. | + | ==== $br - Request' |
- | Example: | + | **$br** - reference to request' |
- | <code c> | + | <fc #0000ff>It is R/W variable, you can assign values to it directly in configuration file (will add a new branch).</fc> |
- | sl_send_reply(" | + | |
- | exit; | + | |
- | </code> | + | |
- | ==== Expressions | + | ==== $bR - Request' |
- | An expression is an association group of statements, variables, functions and operators. | + | **$bR** - reference to request' |
- | Example: | + | ==== $bf - Branch flags ==== |
- | <code c> | + | **$bf** - reference to branch flags of branch 0 (RURI) - decimal output |
- | if(!t_relay()) | + | |
- | if($var(x)>10) | + | <fc # |
+ | ==== $bF - Branch flags ==== | ||
- | " | + | **$bF** - reference to branch flags of branch 0 (RURI) - hexa output |
- | </ | + | |
- | ===== Config Pre-Processor Directives ===== | + | <fc # |
- | ==== include_file | + | ==== $bs - Body size ==== |
- | < | + | **$bs** - body size |
- | | + | |
- | </ | + | |
- | 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. | + | ==== $ci - Call-Id ==== |
- | 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 | + | **$ci** - reference |
- | If the included file is not found, the config file parser throws error. You can find this error message at the logging destination, | + | ==== $cl - Content-Length ==== |
- | You can use also the syntax | + | **$cl** - reference to body of content-length header |
- | Example | + | ==== $cnt(pv) - Count number |
+ | |||
+ | **$cnt(avp)** - return the number of avps | ||
<code c> | <code c> | ||
- | route { | + | xlog("$$avp(x) fount $cnt($avp(x)) times\n"); |
- | ... | + | |
- | include_file | + | |
- | ... | + | |
- | } | + | |
- | + | ||
- | --- / | + | |
- | + | ||
- | | + | |
- | | + | |
- | | + | |
- | } | + | |
- | + | ||
- | --- | + | |
</ | </ | ||
- | ==== import_file ==== | + | **$cnt(xavp)** - return the number of xavps |
< | < | ||
- | | + | * $cnt($xavp(key[*])) : number of XAVPs "key". |
- | </code> | + | * $cnt($xavp(key[n]=>sub[*])) : number of children " |
+ | * $cnt($xavp(key[*]=> | ||
- | Similar to **include_file**, | + | * $cnt($xavp(key[n])) : 1 or 0 (if this index exists or not). |
+ | * $cnt($xavp(key[-n])) : same but with reverse indexing (-1 is the last index). | ||
- | ==== define ==== | + | * $cnt($xavp(key[*]=> |
- | Control in C-style what parts of the config file are executed. The parts in non-defined zones are not loaded, ensuring lower memory usage and faster execution. | + | |
- | + | | |
- | Available directives: | + | |
- | | + | |
- | * **#!define NAME VALUE** - define a keyword with value | + | |
- | * **#!ifdef NAME** - check if a keyword | + | |
- | | + | |
- | * **#!else** - switch to false branch of ifdef/ | + | |
- | * **#!endif** - end ifdef/ | + | |
- | * **# | + | |
- | * **# | + | |
- | + | ||
- | Predefined keywords: | + | |
- | * **KAMAILIO_X[_Y[_Z]]** - Kamailio versions | + | |
- | * **MOD_X** - when module X has been loaded | + | |
- | See ' | + | |
- | + | ||
- | Among benefits: | + | |
- | | + | |
- | * switch control for parts where conditional statements were not possible | + | |
- | * faster by not using conditional statements inside routing blocks when switching between running environments | + | |
- | + | ||
- | Example: how to make config to be used in two environments, | + | |
- | + | ||
- | <code c> | + | |
- | ... | + | |
- | + | ||
- | #!define TESTBED_MODE | + | |
- | + | ||
- | #!ifdef TESTBED_MODE | + | |
- | debug=5 | + | |
- | log_stderror=yes | + | |
- | listen=192.168.1.1 | + | |
- | #!else | + | |
- | debug=2 | + | |
- | log_stderror=no | + | |
- | listen=10.0.0.1 | + | |
- | #!endif | + | |
- | + | ||
- | ... | + | |
- | + | ||
- | #!ifdef TESTBED_MODE | + | |
- | modparam(" | + | |
- | " | + | |
- | #!else | + | |
- | modparam(" | + | |
- | " | + | |
- | #!endif | + | |
- | + | ||
- | ... | + | |
- | + | ||
- | #!ifdef TESTBED_MODE | + | |
- | route[DEBUG] { | + | |
- | xlog(" | + | |
- | } | + | |
- | #!endif | + | |
- | + | ||
- | ... | + | |
- | + | ||
- | route { | + | |
- | #!ifdef TESTBED_MODE | + | |
- | route(DEBUG); | + | |
- | #!endif | + | |
- | + | ||
- | ... | + | |
- | } | + | |
- | + | ||
- | ... | + | |
</ | </ | ||
+ | ==== $conid - TCP Connection ID ==== | ||
- | | + | **$conid** - The TCP connection ID of the connection the current message arrived on for TCP, TLS, WS, and WSS. Set to $null for SCTP and UDP. |
- | <code c> | + | ==== $cs - CSeq Number ==== |
- | #!define MYINT 123 | + | |
- | #!define MYSTR " | + | |
- | </ | + | |
- | | + | **$cs** - reference to the sequence number in the CSeq header. The method in the CSeq header is identical to the request method, thus use $rm to get the method (works also for responses). |
- | <code c> | + | ==== $csb - CSeq Header Body ==== |
- | $var(x) | + | |
- | </ | + | |
- | | + | **$csb** - reference to the CSeq header body (number method). |
+ | ==== $ct - Contact header ==== | ||
- | <code c> | + | **$ct** - reference to body of contact header |
- | $var(x) = 100 + 123; | + | |
- | </ | + | |
- | * you can have multi-line defined IDs | ||
- | <code c> | + | ==== $cT - Content-Type ==== |
- | #!define IDLOOP $var(i) | + | |
- | while($var(i)< | + | |
- | xlog(" | + | |
- | $var(i) | + | |
- | } | + | |
- | </ | + | |
- | | + | **$cT** - reference to body of content-type header |
- | <code c> | + | ==== $dd - Domain of destination URI ==== |
- | route { | + | |
- | ... | + | |
- | IDLOOP | + | |
- | ... | + | |
- | } | + | |
- | </ | + | |
- | | + | **$dd** - reference |
- | * notes: | + | ==== $def(name) |
- | * multilines defines are reduced to single line, so line counter should be fine | + | |
- | * column counter goes inside the define value, but you have to omit the ' | + | |
- | * text on the same line as the directive will cause problems. Keep the directive lines clean and only comment on a line before or after. | + | |
- | ==== defenv ==== | + | **$def(name)** - return a defined |
- | + | ||
- | Preprocessor directive to define an ID to the value of an environment variable with the name ENVVAR. | + | |
- | + | ||
- | <code c> | + | |
- | #!defenv ID=ENVVAR | + | |
- | </ | + | |
- | + | ||
- | It can also be just **$!defenv ENVVAR** and the defined | + | |
Example: | Example: | ||
<code c> | <code c> | ||
- | #!defenv SHELL | + | #!define ABC xyz |
- | </ | + | |
- | If environment variable $SHELL is '/ | + | xlog(" |
- | + | ||
- | <code c> | + | |
- | #!define SHELL /bin/bash | + | |
</ | </ | ||
- | Full expression variant: | + | ==== $defn(name) - Defined Value As Number ==== |
- | <code c> | + | **$defn(name)** - return a defined value as a signed integer. |
- | #!defenv ENVSHELL=SHELL | + | |
- | </ | + | |
- | + | ||
- | Then it is like: | + | |
- | + | ||
- | <code c> | + | |
- | #!define ENVSHELL /bin/bash | + | |
- | </ | + | |
- | + | ||
- | It is a simplified alternative of using **# | + | |
- | + | ||
- | ==== subst ==== | + | |
- | + | ||
- | * perform substitutions inside the strings of config (note that define is replacing only IDs - alphanumeric tokens not enclosed in quotes) | + | |
- | * #!subst offers an easy way to search and replace inside strings before cfg parsing. E.g.,: | + | |
- | + | ||
- | <code c> | + | |
- | #!subst "/ | + | |
- | </ | + | |
- | + | ||
- | * flags is optional and can be: ' | + | |
Example: | Example: | ||
<code c> | <code c> | ||
- | #!subst "/ | + | #!define FLT_ACC 1 |
- | modparam(" | + | |
- | </ | + | |
- | * will do the substitution of db password in db_url parameter value | + | xlog("FLT_ACC: $defn(FLT_ACC)\n"); |
- | + | ||
- | ==== substdef ==== | + | |
- | + | ||
- | <code c> | + | |
- | # | + | |
</ | </ | ||
+ | ==== $di - Diversion header URI ==== | ||
- | Similar to **subst**, but in addition it adds a **#!define ID subst**. | + | **$di** - reference to Diversion header URI |
- | ==== substdefs | + | ==== $dip - Diversion " |
- | <code c> | + | **$dip** - reference to Diversion header |
- | # | + | |
- | </ | + | |
- | Similar to **subst**, but in addition it adds a **#!define ID " | + | ==== $dir - Diversion " |
- | ===== Core Keywords ===== | + | |
- | Keywords specific | + | **$dir** - reference |
- | ==== af ==== | + | ==== $dic - Diversion " |
- | The address family of the received SIP message. It is INET if the message was received over IPv4 or INET6 if the message was received over IPv6. | + | **$dic** - reference to Diversion header " |
- | Exampe | + | ==== $dp - Port of destination URI ==== |
- | <code c> | + | **$dp** - reference to port of destination uri |
- | if (af==INET6) { | + | |
- | log(" | + | |
- | } | + | |
- | </ | + | |
- | ==== dst_ip | + | ==== $dP - Transport protocol of destination URI ==== |
- | The IP of the local interface where the SIP message was received. When the proxy listens on many network interfaces, makes possible | + | **$dP** - reference |
- | Example of usage: | + | ==== $ds - Destination set ==== |
- | <code c> | + | **$ds** - reference to destination set |
- | | + | |
- | log(" | + | |
- | }; | + | |
- | </ | + | |
- | ==== dst_port ==== | ||
- | The local port where the SIP packet was received. When Kamailio is listening on many ports, it is useful to learn which was the one that received the SIP packet. | + | ==== $du - Destination URI ==== |
- | Example of usage: | + | **$du** - reference to destination uri |
- | <code c> | + | |
- | | + | |
- | { | + | |
- | | + | |
- | }; | + | |
- | </ | + | |
+ | If loose_route() returns TRUE a destination uri is set according to the first Route header. | ||
+ | $du is also set if lookup() function of ' | ||
+ | if you use the path functionality. The function handle_ruri_alias() from the nathelper | ||
+ | module will also set it. You can set $du to any SIP URI. | ||
+ | | ||
+ | | ||
+ | | ||
- | ==== from_uri ==== | + | <fc # |
- | This script variable is a reference to the URI of ' | + | To reset $du: |
+ | $du = $null; | ||
- | Example of usage: | + | ==== $fd - From URI domain ==== |
- | <code c> | + | **$fd** - reference to domain in URI of ' |
- | if(is_method(" | + | |
- | { | + | |
- | log(" | + | |
- | }; | + | |
- | </ | + | |
- | ==== method ==== | + | <fc # |
- | The variable is a reference to the SIP method of the message. | + | ==== $fn - From display name ==== |
- | Example | + | **$fn** - reference to display name of ' |
- | <code c> | + | <fc #0000ff>It is R/W variable |
- | if(method==" | + | |
- | { | + | |
- | | + | |
- | }; | + | |
- | </code> | + | |
- | ==== msg: | + | ==== $fs - Forced Send Socket |
- | The variable is a reference to the size of the message. It can be used in ' | + | **$fs** - reference to the forced send socket for the SIP message |
+ | <fc # | ||
- | Example | + | Example: |
- | <code c> | + | |
- | if(msg: | + | |
- | { | + | |
- | sl_send_reply(" | + | |
- | exit; | + | |
- | }; | + | |
- | </ | + | |
- | |||
- | . | ||
- | |||
- | ==== proto ==== | ||
- | |||
- | This variable can be used to test the transport protocol of the SIP message. | ||
- | |||
- | Example of usage: | ||
<code c> | <code c> | ||
- | if(proto==UDP) | + | listen=udp: |
- | { | + | ... |
- | log("SIP message received over UDP\n"); | + | $fs = "udp: |
- | }; | + | |
</ | </ | ||
- | ==== status | + | ==== $fsn - Forced Send Socket Name ==== |
- | If used in onreply_route, | + | **$fsn** - reference |
- | Example of usage: | ||
<code c> | <code c> | ||
- | if(status=="200") | + | listen=udp: |
- | { | + | ... |
- | log("this is a 200 OK reply\n"); | + | $fsn = "s1"; |
- | }; | + | ... |
+ | $fs = " | ||
+ | xdbg("name for forced send socket: $fsn\n"); | ||
</ | </ | ||
+ | ==== $ft - From tag ==== | ||
- | ==== snd_af ==== | + | **$ft** - reference to tag parameter of ' |
- | ==== snd_ip | + | ==== $fti - Initial From tag ==== |
- | ==== snd_port ==== | + | **$fti** - reference to tag parameter of ' |
- | ==== snd_proto ==== | + | The value From tag in the initial request can be in the To tag, if the request within the dialog is sent by the callee. This variable detect who sent the request within the dialog and returns the proper value that was in the From tag of the request initiating the dialog. |
- | ==== src_ip | + | It is exported by **rr** module and has to be used after loose_route(). The append_fromtag parameter is required to be set to 1 in order to have this variable returning the right value. |
+ | ==== $fu - From URI ==== | ||
- | Reference | + | **$fu** - reference |
- | Example of usage: | + | <fc #0000ff>It is R/W variable |
- | <code c> | + | |
- | if(src_ip==127.0.0.1) | + | |
- | { | + | |
- | log("the message was sent from localhost!\n" | + | |
- | }; | + | |
- | </code> | + | |
- | ==== src_port ==== | + | Note that changing the From: header may break backwards compatibility with SIP 1.0 devices. |
- | Reference to source port of the SIP message (from which port the message was sent by previous hop). | + | ==== $fU - From URI username ==== |
- | Example | + | **$fU** - reference to username in URI of ' |
- | <code c> | + | |
- | if(src_port==5061) | + | |
- | { | + | |
- | log(" | + | |
- | } | + | |
- | </ | + | |
- | ==== to_ip ==== | + | <fc # |
- | ==== to_port ==== | + | Note that changing the From: header may break backwards compatibility with SIP 1.0 devices. |
- | ==== to_uri | + | ==== $fUl - From URI Username Length |
- | This variable can be used to test the value of URI from To header. | + | **$fUl** - length |
- | Example of usage: | + | ==== $mb - SIP message buffer ==== |
- | <code c> | + | |
- | if(to_uri=~" | + | |
- | { | + | |
- | log(" | + | |
- | }; | + | |
- | </ | + | |
- | ==== uri ==== | + | **$mb** - reference to SIP message buffer |
+ | ==== $mbu - updated SIP message buffer ==== | ||
- | This variable can be used to test the value of the request URI. | + | **$mbu** - reference |
- | Example of usage: | + | ==== $mf - Flags ==== |
- | <code c> | + | |
- | if(uri=~" | + | |
- | { | + | |
- | log(" | + | |
- | }; | + | |
- | </ | + | |
+ | **$mf** - reference to message/ | ||
+ | <fc # | ||
- | ===== Core Values ===== | + | ==== $mF - Flags in hexadecimal |
- | Values that can be used in ''' | + | **$mF** -reference |
- | ==== INET ==== | + | <fc # |
- | This keyword can be used to test whether the SIP packet was received over an IPv4 connection. | + | ==== $mi - SIP message id ==== |
- | Example of usage: | + | **$mi** - reference to SIP message id |
- | <code c> | + | ==== $ml - SIP message |
- | if (af==INET) { | + | |
- | log(" | + | |
- | } | + | |
- | </ | + | |
- | ==== INET6 ==== | + | **$ml** - reference to SIP message length |
- | This keyword can be used to test whether the SIP packet was received over an IPv6 connection. | + | ==== $mt - SIP Message Type ==== |
- | Example of usage: | + | **$mt** - returns 1 if the sip message |
- | <code c> | + | |
- | | + | |
- | { | + | |
- | log("the SIP message | + | |
- | }; | + | |
- | </ | + | |
- | ==== SCTP ==== | ||
- | This keyword can be used to test the value of ' | + | ==== $od - Domain original R-URI ==== |
- | Example of usage: | + | **$od** - reference to domain in request' |
- | <code c> | + | |
- | if(proto==SCTP) | + | |
- | { | + | |
- | log(" | + | |
- | }; | + | |
- | </ | + | |
- | ==== TCP ==== | + | ==== $op - Port in original R-URI ==== |
- | This keyword can be used to test the value of ' | + | **$op** - reference |
- | Example | + | ==== $oP - Protocol |
- | <code c> | + | |
- | if(proto==TCP) | + | |
- | { | + | |
- | log(" | + | |
- | }; | + | |
- | </ | + | |
- | ==== TLS ==== | + | **$oP** - reference to transport protocol of original R-URI |
- | This keyword can be used to test the value of ' | + | ==== $ou - Original R-URI ==== |
- | Example of usage: | + | **$ou** - reference to request' |
- | <code c> | + | |
- | if(proto==TLS) | + | |
- | { | + | |
- | log(" | + | |
- | }; | + | |
- | </ | + | |
- | ==== UDP ==== | + | |
- | This keyword can be used to test the value of ' | + | ==== $oU - Username in original R-URI ==== |
- | Example of usage: | + | **$oU** - reference to username in request' |
- | <code c> | + | |
- | if(proto==UDP) | + | |
- | { | + | |
- | log(" | + | |
- | }; | + | |
- | </ | + | |
- | ==== WS ==== | + | ==== $oUl - Original R-URI Username Length |
- | This keyword can be used to test the value of ' | + | **$oUl** - the length |
- | Example of usage: | + | ==== $pd - Domain in P-Preferred-Identity header URI ==== |
- | <code c> | + | |
- | if(proto==WS) | + | |
- | { | + | |
- | log(" | + | |
- | }; | + | |
- | </ | + | |
+ | **$pd** - reference to domain in request' | ||
- | ==== WSS ==== | + | ==== $pn - Display Name in P-Preferred-Identity header |
- | This keyword can be used to test the value of 'proto' and check whether the SIP packet was received over WSS or not. | + | **$pn** - reference |
- | Example of usage: | + | ==== $pp - Process id ==== |
- | <code c> | + | |
- | if(proto==WSS) | + | |
- | { | + | |
- | log(" | + | |
- | }; | + | |
- | </ | + | |
- | ==== max_len | + | |
- | Note: This command was removed. | + | **$pp** - reference to process id (pid) |
+ | ==== $pr or $proto - Protocol of received message ==== | ||
- | ==== myself ==== | + | **$pr** or **$proto** - protocol of received message (udp, tcp, tls, sctp, ws, wss) |
- | This is a reference to the list of local IP addresses, hostnames and aliases that has been set in the Kamailio configuration file. This lists contain the domains served by Kamailio. | + | ==== $prid - protocol id ==== |
- | The variable can be used to test if the host part of an URI is in the list. The usefulness of this test is to select the messages that has to be processed locally or has to be forwarded to another server. | + | **$prid** - internal protocol id |
- | See " | + | * 0 - NONE |
+ | * 1 - UDP | ||
+ | * 2 - TCP | ||
+ | * 3 - TLS | ||
+ | * 4 - SCTP | ||
+ | * 5 - WS | ||
+ | * 6 - WSS | ||
+ | * 7 - OTHER | ||
+ | ==== $pU - User in P-Preferred-Identity header URI ==== | ||
- | Example of usage: | + | **$pU** - reference to user in request' |
- | <code c> | + | |
- | if(uri==myself) { | + | |
- | log(" | + | |
- | }; | + | |
- | </ | + | |
- | Note: You can also use the is_myself() function. | + | ==== $pu - URI in P-Preferred-Identity header |
- | ===== Core parameters ===== | + | |
- | ==== advertised_address ==== | + | **$pu** - reference to URI in request' |
- | It can be an IP address or string and represents the address advertised in Via header. If empty or not set (default value) the socket | ||
- | address from where the request will be sent is used. | ||
- | WARNING: | ||
- | - don't set it unless you know what you are doing (e.g. nat traversal) | ||
- | - you can set anything here, no check is made (e.g. foo.bar will be accepted even if foo.bar doesn' | ||
- | Example | + | ==== $rb - Body of request/ |
- | advertised_address=" | + | **$rb** - reference to message body |
- | advertised_address=" | + | |
- | Note: this option may be deprecated and removed in the near future, it is recommended to set **advertise** option for **listen** parameter. | + | ==== $rc - Returned code ==== |
- | ==== advertised_port | + | |
- | The port advertised in Via header. If empty or not set (default value) the port from where the message will be sent is used. Same warnings as for ' | + | **$rc** - reference to returned code by last invoked function |
- | Example of usage: | + | **$retcode** - same as **$rc** |
- | advertised_port=5080 | + | Note that the value of $rc is overwritten by each new function call. |
- | Note: this option may be deprecated and removed in the near future, it is recommended to set **advertise** option for **listen** parameter. | + | Example of use: |
- | ==== alias ==== | + | |
- | Parameter to set alias hostnames for the server. It can be set many times, each value being added in a list to match the hostname when ' | + | <code c> |
+ | lookup(" | ||
+ | $var(rc) = $rc; | ||
+ | if ($var(rc) < 0) { | ||
+ | t_newtran(); | ||
+ | switch ($var(rc)) { | ||
+ | case -1: | ||
+ | case -3: | ||
+ | send_reply(" | ||
+ | exit; | ||
+ | case -2: | ||
+ | send_reply(" | ||
+ | exit; | ||
+ | } | ||
+ | } | ||
- | It is necessary to include the port (the port value used in the " | ||
- | |||
- | Example of usage: | ||
- | |||
- | < | ||
- | alias=other.domain.com: | ||
- | alias=another.domain.com: | ||
</ | </ | ||
+ | ==== $rd - Domain in R-URI ==== | ||
- | Note: the hostname has to be enclosed in between quotes if it has reserved tokens such as **forward**, **drop** ... or operators such as **-** (minus) ... | + | **$rd** - reference to domain in request' |
- | ==== async_workers ==== | + | |
- | Specify how many child processes | + | <fc # |
- | Default: 0 (asynchronous framework is disabled). | + | ==== $rdir(key) - Request Direction ==== |
- | Example: | + | **$rdir(key)** - get the direction of the request within dialog. |
- | < | + | The direction is ' |
- | async_workers=4 | + | |
- | </ | + | |
- | ==== async_nonblock ==== | + | The key can be: |
- | Set the non-block mode for the internal sockets used by default group of async workers. | + | * id - the returned value is an integer: 1 - for direction downstream, 2 - for direction upstream |
- | + | * name - the returned value is a string: ' | |
- | Default: 0 | + | |
Example: | Example: | ||
- | < | + | < |
- | | + | if($rdir(name)==" |
+ | xlog(" | ||
+ | } | ||
</ | </ | ||
- | ==== async_usleep | + | The variable is exported by **rr** module and append_fromtag parameter must be enabled. The variable has to be used after loose_route() function. |
+ | ==== $re - Remote-Party-ID header URI ==== | ||
- | Set the number of microseconds | + | **$re** - reference |
- | Default: 0 | + | ==== $rm - SIP method ==== |
- | Example: | + | **$rm** - reference to request' |
- | < | + | ==== $rmid - SIP Method ID ==== |
- | async_usleep=100 | + | |
- | </ | + | |
- | ==== async_workers_group ==== | + | **$rmid** - returns internal integer representation of SIP method type |
- | Define groups of asynchronous worker processes. | + | ==== $route_uri - URI in first Route header ==== |
- | Prototype: | + | **$route_uri** - returns the string with URI field in the first Route header |
- | < | + | ==== $rp - Port in R-URI ==== |
- | async_workers_group="name=X;workers=N;nonblock=[0|1]; | + | |
- | </ | + | |
- | The attributes are: | + | **$rp** - reference to port of R-URI |
- | * **name** - the group name (used by functions such as **sworker_task(name)**) | + | <fc # |
- | * **workers** - the number of processes | + | |
- | * **nonblock** - set or not set the non-block flag for internal communication socket | + | |
- | * **usleep** - the number of microseconds to sleep before trying to receive next task (can be useful if nonblock=1) | + | |
- | Default: "" | + | ==== $rP - Protocol of R-URI ==== |
- | Example: | + | **$rP** - reference to transport protocol of R-URI |
- | < | + | ==== $rr - SIP reply reason phrase ==== |
- | async_workers_group="name=reg;workers=4;nonblock=0;usleep=0" | + | |
- | </ | + | |
- | If the **name** is default, then it overwrites | + | **$rr** - reference to reply' |
- | See also **event_route[core: | + | ==== $rs - SIP reply code ==== |
- | ==== auto_aliases ==== | + | **$rs** - reference to reply' |
- | Kamailio by default discovers all IPv4 addresses on all interfaces and does a reverse DNS lookup on these addresses to find host names. Discovered host names are added to aliases list, matching the **myself** condition. To disable host names auto-discovery, turn off auto_aliases. | + | ==== $rt - Refer-to URI ==== |
- | Example: | + | **$rt** - reference to URI of refer-to header |
- | < | + | ==== $ru - Request URI ==== |
- | auto_aliases=no | + | |
- | </ | + | |
- | ==== auto_bind_ipv6 | + | |
- | When turned on, Kamailio will automatically bind to all IPv6 addresses | + | **$ru** - reference |
- | Example: | + | <fc # |
- | < | + | ==== $rU - Username in R-URI ==== |
- | auto_bind_ipv6=1 | + | |
- | </ | + | |
- | ==== bind_ipv6_link_local ==== | + | **$rU** - reference to username in request' |
- | If set to 1, try to bind also IPv6 link local addresses by discovering the scope of the interface. This apply for UDP socket for now, to be added for the other protocols. Default is 0. | + | <fc # |
- | Example: | + | ==== $rUl - R-URI Username Length ==== |
- | < | + | **$rU** - the length of the username in R-URI |
- | bind_ipv6_link_local=1 | + | |
- | </ | + | |
- | ==== check_via ==== | + | |
- | Check if the address in top most via of replies is local. Default value is 0 (check disabled). | + | ==== $rv - SIP message version ==== |
- | Example of usage: | + | **$rv** - reference to SIP message (reply or request) version |
+ | ==== $ruid - Record internal Unique ID ==== | ||
- | check_via=1 | + | **$ruid** - the Record internal Unique ID for the location record selected by calling registrar: |
- | ==== children | + | ==== $rz - URI Scheme of R-URI ==== |
- | Number of children to fork for the UDP interfaces (one set for each interface | + | **$rz** |
- | For configuration of the TCP/TLS worker threads see the option " | + | ==== $RAi - Received advertised IP address ==== |
- | Example | + | **$RAi** - reference to advertised IP address |
- | children=16 | + | ==== $RAp - Received advertised port ==== |
- | ==== chroot ==== | + | **$RAp** - reference to advertised port where the request has been received, or $Rp if no advertised port. |
- | The value must be a valid path in the system. If set, Kamailio will chroot (change root directory) to its value. | + | ==== $Ri - Received IP address ==== |
- | Example | + | **$Ri** - reference to IP address |
- | + | ==== $Rp - Received port ==== | |
- | chroot=/ | + | |
- | + | ||
- | + | ||
- | ==== corelog ==== | + | |
- | + | ||
- | Set the debug level used to print some log messages from core, which might become annoying and don't represent critical errors. For example, such case is failure to parse incoming traffic from the network as SIP message, due to someone sending invalid content. | + | |
- | + | ||
- | Default value is -1 (L_ERR). | + | |
- | + | ||
- | Example of usage: | + | |
- | + | ||
- | < | + | |
- | corelog=1 | + | |
- | </ | + | |
- | ==== debug ==== | + | |
- | + | ||
- | Set the debug level. Higher values make Kamailio to print more debug messages. Log messages are usually sent to syslog, except if logging to stderr was activated (see [[# | + | |
- | The following log levels are defined: | + | **$Rp** - reference to the port where the message was received |
- | | + | ==== $Rn - Received socket name ==== |
- | | + | |
- | | + | |
- | | + | |
- | | + | |
- | | + | |
- | | + | |
- | | + | |
- | | + | |
- | A log message will be logged if its log-level is lower than the defined debug level. Log messages are either produced by the the code, or manually in the configuration script using log() or xlog() functions. For a production server you usually use a log value between -1 and 2. | + | **$Rn** |
- | Default value: L_WARN (debug=0) | + | ==== $RAu - Advertised socket URI ==== |
- | Examples of usage: | + | **$RAu** - local socket where the SIP messages was received in URI format, without transport parameter for UDP, using advertised address when available. |
- | * debug=3: print all log messages. This is only useful for debugging of problems. Note: this produces a lot of data and therefore should not be used on production servers (on a busy server this can easily fill up your hard disk with log messages) | + | ==== $RAut - Advertised socket URI ==== |
- | * debug=0: This will only log warning, errors and more critical messages. | + | |
- | * debug=-6: This will disable all log messages. | + | |
- | Value of ' | + | **$RAut** - local socket where the SIP messages was received in URI format, always with transport |
- | kamcmd cfg.get core debug | + | |
- | kamcmd cfg.set_now_int core debug 2 | + | |
- | kamcmd cfg.set_now_int core debug -- -1 | + | |
- | Note: There is a difference in log-levels between Kamailio 3.x and Kamailio< | + | ==== $Ru - Received socket URI ==== |
- | For configuration of logging of the memory manager see the parameters [[#memlog]] and [[#memdbg]]. | + | **$Ru** - local socket where the SIP messages was received in URI format, without transport parameter for UDP. |
- | Further information can also be found at: https:// | + | ==== $Rut - Received socket URI ==== |
- | ==== description ==== | + | **$Rut** - local socket where the SIP messages was received in URI format, always with transport parameter. |
- | **Alias name: descr desc** | + | ==== $sas - Source address in socket format ==== |
- | ==== disable_core_dump | + | **$sas** - get source address in socket format (proto: |
+ | ==== $sbranch(attr) - Static Branch | ||
- | Can be ' | + | **$sbranch(attr)** - class of variables allowing |
- | Default value is ' | + | The **attr** can be any of the supported values for **$branch(attr)** class of variables -- see above for proper details. |
Example of usage: | Example of usage: | ||
- | disable_core_dump=yes | + | <code c> |
+ | sbranch_reset(); | ||
+ | $sbranch(uri) | ||
+ | $sbranch(dst_uri) = " | ||
+ | $sbranch(path) = " | ||
+ | $sbranch(send_socket) = " | ||
+ | sbranch_set_ruri(); | ||
+ | </ | ||
- | ==== disable_tls | + | ==== $sf - Script flags ==== |
- | **Alias name: tls_disable** | + | **$sf** - reference to script flags - decimal output |
- | Global parameter to disable TLS support in the SIP server. Default value is ' | + | ==== $sF - Script flags ==== |
- | Note: Make sure to load the " | + | **$sF** - reference |
- | Example of usage: | + | ==== $si - Source IP address ==== |
- | disable_tls=yes | + | **$si** - reference to IP source address of the message - see also $siz |
- | In Kamailio TLS is implemented as a module. Thus, the TLS configuration is done as module configuration. For more details see the README of the TLS module: | + | ==== $sid - Server ID ==== |
- | http:// | + | |
- | ==== enable_tls | + | |
- | **Alias name: tls_enable** | + | **$sid** - the value for server id (server_id parameter) |
+ | ==== $siz - Source IP address ==== | ||
- | Reverse Meaning | + | **$siz** - reference to IP source address |
- | enable_tls=yes # enable tls support in core | + | ==== $sp - Source port ==== |
- | ==== exit_timeout ==== | + | **$sp** - reference to the source port of the message |
- | **Alias | + | ==== $stat(name) - Statistics ==== |
- | How much time Kamailio will wait for all the shutdown procedures to complete. If this time is exceeded, all the remaining processes are immediately killed and Kamailio exits immediately | + | **$stat(name)** - return |
- | Default: 60 s. Use 0 to disable. | + | ==== $su - Source address as URI ==== |
- | | ||
- | ==== flags ==== | + | **$su** - returns the representation of source address (ip, port, proto) as SIP URI. If the proto is UDP, then it is not added (being the default transport protocol). |
- | SIP message (transaction) flags can have string names. | + | Its value looks like: |
- | The //name// for flags cannot be used for **branch** or **script flags**(*) | + | |
- | + | < | |
- | < | + | "sip:ip: |
- | ... | + | " |
- | flags | + | |
- | FLAG_ONE | + | |
- | | + | |
- | ... | + | |
</ | </ | ||
- | (*) The named flags feature was propagated from the source code merge back in 2008 and is not extensively tested. The recommended way of defining flags is using [[cookbooks: | + | Note that WS and WSS are both represented by transport=ws, |
- | <code c> | + | |
- | #!define FLAG_NAME FLAG_BIT | + | |
- | </ | + | |
+ | ==== $sut - Source address as full URI ==== | ||
+ | **$sut** - returns the representation of source address (ip, port, proto) as full SIP URI. The proto UDP is added also as transport parameter. | ||
- | ==== force_rport ==== | + | Its value looks like: |
- | yes/no: Similar to the force_rport() function, but activates symmetric response routing globally. | + | < |
+ | "sip:ip: | ||
+ | </ | ||
+ | ==== $td - To URI Domain ==== | ||
- | ==== fork ==== | + | **$td** - reference to domain in URI of ' |
- | If set to ' | + | <fc # |
- | When set to ' | + | ==== $tn - To display name ==== |
- | Default value is 'yes'. | + | **$tn** - reference to display name of 'To' |
- | Example of usage: | + | <fc # |
- | fork=no | + | ==== $tt - To tag ==== |
- | ==== fork_delay ==== | + | **$tt** - reference to tag parameter of ' |
- | Number of usecs to wait before forking a process. | + | ==== $tti - Initial To tag ==== |
- | Default is 0 (don't wait). | + | **$tti** - reference to tag parameter of 'To' header as it was in the SIP response to the initial request (e.g., 200ok to the initial INVITE). |
- | Example | + | The value To tag in the initial transaction can be in the From tag, if the request within the dialog is sent by the callee. This variable detect who sent the request within the dialog and returns the proper value that was in the To tag of the transaction initiating the dialog. |
- | <code c> | + | It is exported by **rr** module and has to be used after loose_route(). The append_fromtag parameter is required to be set to 1 in order to have this variable returning the right value. |
- | fork_delay=5000 | + | ==== $tu - To URI ==== |
- | </ | + | |
- | ==== group ==== | + | |
- | **Alias name: gid** | + | **$tu** - reference to URI of ' |
- | The group id to run Kamailio. | + | <fc # |
- | Example of usage: | + | ==== $tU - To URI Username ==== |
- | group=" | + | **$tU** - reference to username in URI of ' |
- | ==== http_reply_parse ==== | + | <fc # |
- | Alias: http_reply_hack | + | ==== $tUl - To URI Username Length ==== |
- | When enabled, Kamailio can parse HTTP replies, but does so by treating them as SIP replies. | + | **$tU** |
- | Default value is ' | + | ==== $Tb - Startup timestamp ==== |
- | Example | + | **$Tb** - reference to unix timestamp |
- | http_reply_parse=yes | + | ==== $Tf - String formatted time - cached ==== |
- | ==== ip_free_bind ==== | + | **$Tf** - reference string formatted time |
- | Alias: ipfreebind, ip_nonlocal_bind | + | Note: the system time is retrieved only once for each processed SIP message. Subsequent calls of $Tf for same SIP message will return same value. |
- | Control if Kamailio should attempt to bind to non local ip. This option is the per-socket equivalent of the system **ip_nonlocal_bind**. | + | ==== $TF - String formatted time - current ==== |
- | Default is 0 (do not bind to non local ip). | + | **$TF** - reference string formatted time |
- | Example of usage: | + | Note: the system time is computed for each call of $TF. Subsequent calls of $TF for same SIP message may return different values. |
- | <code c> | + | ==== $Ts - Unix time stamp - cached ==== |
- | ip_free_bind | + | |
- | </ | + | |
+ | **$Ts** - reference to unix time stamp | ||
- | ==== ipv6_hex_style ==== | + | Note: the system time is retrieved only once for each processed SIP message. Subsequent calls of $Ts for same SIP message will return same value. |
- | Can be set to " | + | ==== $TS - Unix time stamp - current ==== |
- | Default is " | + | **$TS** - reference to unix time stamp |
- | " | + | Note: the system time is computed for each call of $TS. Subsequent calls of $TS for same SIP message may return different values. |
- | Example of usage: | + | ==== $ua - User agent header ==== |
- | <code c> | + | **$ua** - reference to user agent header field |
- | ipv6_hex_style = " | + | |
- | </ | + | |
- | ==== kemi.onsend_route_callback ==== | + | |
- | Set the name of callback function in the KEMI script to be executed as the equivalent of `onsend_route` block (from the native configuration file). | + | ==== $version() - version ==== |
- | Default value: ksr_onsend_route | + | **$version(num)** - version as number |
- | Set it to empty string | + | **$version(full)** - full version |
- | Example: | + | **$version(hash)** - TBA |
- | <code c> | + | ===== $env(NAME) - environment variables ===== |
- | kemi.onsend_route_callback=" | + | |
- | </ | + | |
- | ==== kemi.received_route_callback ==== | + | **$env(NAME)** - value of the environment variable named NAME |
- | + | ||
- | Set the name of callback function in the KEMI script to be executed as the equivalent of `event_route[core: | + | |
- | + | ||
- | Default | + | |
- | + | ||
- | Set it to empty string or " | + | |
Example: | Example: | ||
<code c> | <code c> | ||
- | kemi.received_route_callback="ksr_my_receieved_route" | + | xdbg("PATH environment variable: |
</ | </ | ||
+ | ===== $avp(id) - AVPs ===== | ||
- | ==== kemi.reply_route_callback ==== | + | **$avp(id)** - the value of the AVP identified by ' |
- | Set the name of callback function in the KEMI script to be executed as the equivalent of `reply_route` block (from the native configuration file). | + | **$(avp(id)[N])** - represents |
- | Default value: ksr_reply_route | + | The ' |
- | Set it to empty string | + | * " |
+ | * "name" | ||
+ | * pseudo variable - if value of pv is integer, id is integer, if string, id is string | ||
- | Example: | + | $(avp(id)[0]) can be written in shorter form as $avp(id) and $avp(s:name) as $avp(name). |
- | <code c> | + | AVPs are special variables that are attached to SIP transactions. It is a list of pairs (name, |
- | kemi.onsend_route_callback=" | + | |
- | </ | + | |
- | + | ||
- | ==== kemi.pre_routing_callback ==== | + | |
- | + | ||
- | Set the name of callback function in the KEMI script | + | |
- | + | ||
- | Default | + | |
- | + | ||
- | Set it to empty string or " | + | |
- | + | ||
- | Example: | + | |
+ | To delete the first AVP with name ' | ||
<code c> | <code c> | ||
- | kemi.pre_routing_callback=" | + | $avp(id) |
</ | </ | ||
- | ==== latency_cfg_log ==== | + | To delete all the AVP with name ' |
- | + | ||
- | If set to a log level less or equal than debug parameter, a log message with the duration in microseconds of executing request route or reply route is printed | + | |
- | + | ||
- | Default value is 3 (L_DBG). | + | |
- | + | ||
- | Example: | + | |
<code c> | <code c> | ||
- | latency_cfg_log=2 | + | $(avp(id)[*]) |
</ | </ | ||
- | ==== latency_limit_action ==== | + | To overwrite the value of the AVP with name 'id' you have to assign the new value to the index ' |
- | + | ||
- | Limit of latency in us (micro-seconds) for config actions. If a config action executed by cfg interpreter takes longer than its value, a message is printed in the logs, showing config path, line and action | + | |
- | + | ||
- | Default | + | |
<code c> | <code c> | ||
- | latency_limit_action=500 | + | $(avp(id)[*]) |
</ | </ | ||
- | |||
- | ==== latency_limit_db ==== | ||
- | Limit of latency in us (micro-seconds) for db operations. If a db operation executed via DB API v1 takes longer that its value, | + | The value of an AVP can be integer or string. To assign |
- | + | Example of usage: | |
- | Default value is 0 (disabled). | + | |
<code c> | <code c> | ||
- | latency_limit_db=500 | + | $avp(x) |
+ | $avp(x) = 2; | ||
+ | $avp(y) = " | ||
+ | if($(avp(x)[1])==1) { | ||
+ | ... | ||
+ | } | ||
+ | $(avp(x)[1]) = $null; | ||
</ | </ | ||
+ | It is R/W variable (you can assign values to it directly in configuration file). | ||
- | ==== latency_log | + | ===== $expires(key) - Expires Values ===== |
- | Log level to print the messages related to latency. | + | Return |
+ | If none is found, $null is returned. | ||
- | Default value is -1 (L_ERR). | + | Possible ' |
- | <code c> | + | * $expires(min) - the minimum value for expires |
- | latency_log=3 | + | * $expires(max) - the maximum value for expires |
- | </ | + | |
- | ==== listen ==== | + | When there is only one expires value, then min and max return |
- | + | ||
- | Set the network addresses the SIP server should listen to. It can be an IP address, hostname or network interface id or combination of protocol: | + | |
Example of usage: | Example of usage: | ||
<code c> | <code c> | ||
- | listen=10.10.10.10 | + | if($expires(max)!=$null) { |
- | | + | |
- | | + | } |
</ | </ | ||
- | If you omit this directive then the SIP server will listen on all interfaces. On start the SIP server reports all the interfaces that it is listening on. Even if you specify only UDP interfaces here, the server will start the TCP engine too. If you don't want this, you need to disable the TCP support completely with the core parameter disable_tcp. | + | ===== $xavp(id) - XAVPs ===== |
- | If you specify IPv6 addresses, you should put them into square brackets, e.g.: | + | **xavp** - eXtended AVPs - are variables that can store multiple values, which can also be grouped in a structure-like fashion. Their value can be a string, an integer number or a list of named values (child values). |
- | <code c> | + | They work like a stack, similar to AVPs, and are attached to SIP transactions and automatically destroyed when the transaction is finished. |
- | listen=udp: | + | |
- | </ | + | |
- | You can specify an advertise address | + | Each xavp has a string name and can contain a string, and integer or a list of named values. The structure name (or root list name) and the value name (or field name, or child value name) are separated by < |
- | <code c> | + | To assign |
- | listen=udp: | + | |
- | </ | + | |
- | + | ||
- | The advertise address must be the format ' | + | |
- | + | ||
- | A typical | + | |
- | + | ||
- | A unique name can be set for sockets to simplify the selection of the socket for sending out. For example, the rr and path modules can use the socket name to advertise it in header URI parameter and use it as a shortcut to select the corresponding socket for routing subsequent requests. | + | |
- | + | ||
- | The name has to be provided as a string enclosed in between quotes after the **name** identifier. | + | |
<code c> | <code c> | ||
- | listen=udp: | + | $xavp(root)="string value"; |
- | listen=udp: | + | $xavp(root)=intnumber; |
- | listen=udp: | + | |
- | listen=udp: | + | |
- | ... | + | |
- | | + | |
- | | + | |
</ | </ | ||
- | Note that there is no internal check for uniqueness of the socket names, the admin has to ensure it in order to be sure the desired socket is selected, otherwise the first socket with a matching name is used. | + | To assign |
- | ==== loadmodule ==== | + | |
- | Loads a module for later usage in the configuration script. The modules is searched in the path specified by **loadpath**. | ||
- | |||
- | Prototype: **loadmodule " | ||
- | |||
- | If modulepath is only modulename or modulename.so, | ||
- | |||
- | Example of usage: | ||
<code c> | <code c> | ||
- | loadpath | + | $xavp(root=> |
- | + | $xavp(root=> | |
- | loadmodule "/ | + | |
- | loadmodule " | + | |
- | loadmodule " | + | |
- | loadmodule " | + | |
</ | </ | ||
- | ==== loadmodulex ==== | + | Like avps, xavp act like a stack. To refer to an existing value, use an index. The newest xavp has index zero [0]. |
- | + | ||
- | Similar to **loadmodule** with the ability to evaluate variables in its parameter. | + | |
- | + | ||
- | ==== loadpath ==== | + | |
- | + | ||
- | **Alias name: mpath** | + | |
- | + | ||
- | Set the module search path. loadpath takes a list of directories separated by ':' | + | |
- | + | ||
- | This can be used to simplify the loadmodule parameter and can include many paths separated by colon. First module found is used. | + | |
- | + | ||
- | Example of usage: | + | |
<code c> | <code c> | ||
- | loadpath "/ | + | $xavp(root[0]=> |
- | + | ||
- | loadmodule " | + | |
- | loadmodule " | + | |
- | loadmodule " | + | |
- | loadmodule " | + | |
- | loadmodule " | + | |
</ | </ | ||
- | The proxy tries to find the modules in a smart way, e.g: loadmodule " | + | If you assign |
- | + | ||
- | ==== local_rport ==== | + | |
- | + | ||
- | Similar to **add_local_rport()** function, but done in a global scope, so the function does not have to be executed for each request. | + | |
- | + | ||
- | Default: off | + | |
- | + | ||
- | Example: | + | |
<code c> | <code c> | ||
- | local_rport | + | # new item (person |
- | </code> | + | $xavp(person=>lastname)=" |
- | ==== log_engine_data ==== | + | # add new item (person |
+ | $xavp(person=> | ||
- | Set specific data required by the log engine. See also the **log_engine_type**. | + | # add another named value to the last example item |
+ | # | ||
+ | $xavp(person[0]=> | ||
- | <code c> | + | # add another named value to first example item |
- | log_engine_type="udp" | + | # |
- | log_engine_data="127.0.0.1:9" | + | xavp(person[1]=> |
</ | </ | ||
- | ==== log_engine_type ==== | ||
- | |||
- | Specify what logging engine to be used and its initialization data. A logging engine is implemented as a module. Supported values are a matter of the module. | ||
- | |||
- | For example, see the readme of **log_custom** module for more details. | ||
+ | Another example: | ||
<code c> | <code c> | ||
- | log_engine_type=" | + | # create new (the first) root xavp with a named value of string type |
- | log_engine_data="127.0.0.1:9" | + | $xavp(sf=> |
- | </ | + | |
+ | # add named values (child values) | ||
+ | $xavp(sf[0]=> | ||
+ | $xavp(sf[0]=> | ||
+ | $xavp(sf[0]=> | ||
- | ==== log_facility ==== | + | # create new (the second) root xavp with a named value of string type, moving previous one to sf[1] |
+ | $xavp(sf=>uri)=" | ||
+ | # add named values (child values) | ||
+ | $xavp(sf[0]=> | ||
+ | $xavp(sf[0]=> | ||
- | If Kamailio logs to syslog, you can control | + | # create new (the third) xavp with a named value of string type, moving previous one to sf[1] and the other one to sf[2] |
- | + | $xavp(sf=>uri)="sip:10.10.10.12"; | |
- | For more see: http://www.kamailio.org/ | + | # add named values (child values) |
- | + | $xavp(sf[0]=> | |
- | Default value is LOG_DAEMON. | + | $xavp(sf[0]=> |
- | + | $xavp(sf[0]=>headers)="X-CustomerID: pw45\r\n"; | |
- | Example of usage: | + | |
- | + | ||
- | log_facility=LOG_LOCAL0 | + | |
- | + | ||
- | ==== log_name ==== | + | |
- | + | ||
- | Allows to configure a log_name prefix which will be used when printing to syslog -- it is also known as syslog tag, and the default value is the application name or full path that printed the log message. This is useful to filter log messages when running many instances of Kamailio on same server. | + | |
- | + | ||
- | <code> | + | |
- | log_name="kamailio-proxy-5080" | + | |
</ | </ | ||
- | ==== log_prefix ==== | + | xavps are read and write variables. |
- | Specify the text to be prefixed to the log messages printed by Kamailio while processing a SIP message | + | ===== $xavu(id) - XAVUs ===== |
- | See [[# | + | |
+ | Similar to XAVPs, but with single value items, therefore there are no indexes in the naming format. XAVUs are also stored in transaction context and destroyed when the transaction is terminated. | ||
- | If a log message is printed from a part of the code executed out of routing blocks actions (e.g., can be timer, evapi worker process, ...), there is no log prefix set, because this one requires a valid SIP message structure to work with. | + | Examples: |
- | Example - prefix with message type (1 - request, 2 - response), CSeq and Call-ID: | + | <code c> |
- | + | $xavu(x) = 123; # <- set the value | |
- | <code> | + | $xavu(x) = 234; # <- update to the value, not adding to a list like for xavps |
- | log_prefix="{$mt $hdr(CSeq) $ci} " | + | $xavu(x) |
+ | $xavu(a=>b) = "xyz"; # <- two level naming supported | ||
</ | </ | ||
- | ==== log_prefix_mode | + | ===== $xavi(id) - XAVIs ===== |
- | Control if [[# | + | Similar to XAVPs, but with key names are case insensitive. XAVIs are also stored in transaction context and destroyed when the transaction |
- | If set to 0 (default), then log prefix is evaluated when the sip message is received and then reused (recommended if the **log_prefix** has only variables that have same value for same message). This is the current behaviour of **log_prefix** evaluation. | ||
- | If set to 1, then the log prefix is evaluated before/ | + | Examples: |
- | Example: | + | < |
- | + | $xavi(WhatEver=> | |
- | < | + | # $xavi(whatever[0]=> |
- | log_prefix_mode=1 | + | |
</ | </ | ||
- | ==== log_stderror | + | ===== $hdr(name) - Headers ===== |
- | With this parameter you can make Kamailio to write log and debug messages to standard error. Possible values are: | ||
- | - " | + | **$hdr(name)** |
- | - " | + | **$(hdr(name)[N])** |
- | Default value is " | + | If [N] is omitted then the body of the first header is printed. The body of first header is returned when N=0, for the second N=1, a.s.o. In case of a comma-separated multi-body headers, it returns all the bodies, comma-separated. To print the last header of that type, use -1, or other negative values to count from the end. No white spaces are allowed inside the specifier (before }, before or after {, [, ] symbols). When N=' |
- | For more see: http://www.kamailio.org/ | + | If name is *, then any header name is matched, e.g., $hdr(*) is body of first header, $(hdr(*)[-1]) is body of last header. |
- | Example of usage: | + | The module should identify compact header names. It is recommended to use dedicated specifiers for headers (e.g., $ua for user agent header), if they are available -- they are faster. |
- | + | ||
- | log_stderror=yes | + | |
- | + | ||
- | ==== cfgengine ==== | + | |
- | + | ||
- | Set the config interpreter engine for execution of the routing logic inside the configuration file. Default | + | |
Example of usage: | Example of usage: | ||
- | cfgengine="name" | + | <code c> |
- | | + | if($hdr(From)=~"kamailio\.org") { |
+ | ... | ||
+ | } | ||
+ | </ | ||
- | If name is " | + | <fc # |
- | + | ||
- | The name can be the identifier of an embedded language interpreter, | + | |
- | cfgengine " | + | ===== $hfl(name) - Header Field With List Of Bodies ===== |
- | ==== maxbuffer ==== | + | Similar to **$hdr(name)**, |
- | The size in bytes not to be exceeded during the auto-probing procedure of descovering the maximum buffer size for receiving UDP messages. Default value is 262144. | + | Implemented |
- | Example of usage: | + | * Contact |
+ | * Record-Route | ||
+ | * Route | ||
+ | * Via | ||
- | maxbuffer=65536 | + | For the rest of the headers works like **$hdr(name)**. |
- | ==== max_branches ==== | + | **$hfl(name)** - represents the first body of first header field identified by ' |
- | The maximum number of outgoing branches for each SIP request. It has impact on the size of destination set created in core (e.g., via append_branch()) as well as the serial and parallel forking done via tm module. It replaces the old defined constant MAX_BRANCHES. | + | **$(hfl(name)[N])** - represents |
- | + | ||
- | The value has to be at least 1 and the upper limit is 31. | + | |
- | + | ||
- | Default value: 12 | + | |
Example of usage: | Example of usage: | ||
- | < | + | < |
- | max_branches=16 | + | if($(hfl(Via)[1])=~" |
+ | ... | ||
+ | } | ||
</ | </ | ||
+ | ===== $hdrc(name) - Number of Headers ===== | ||
- | ==== max_recursive_level ==== | + | **$hdrc(name)** - get the number |
- | + | ||
- | The parameters set the value of maximum recursive calls to blocks of actions, such as sub-routes or chained IF-ELSE (for the ELSE branches). Default is 256. | + | |
Example of usage: | Example of usage: | ||
- | max_recursive_level=500 | + | <code c> |
+ | if($hdrc(Via) | ||
+ | ... | ||
+ | } | ||
+ | </ | ||
+ | ===== $hflc(name) - Number of Header Bodies ===== | ||
- | ==== max_while_loops ==== | + | Similar to **$hdrc(name)**, |
- | The parameters set the value of maximum loops that can be done within a " | + | Implemented for: |
- | Example of usage: | + | * Record-Route |
+ | * Route | ||
+ | * Via | ||
- | max_while_loops=200 | + | For the rest of the headers works like **$hdrc(name)**. |
- | ==== mcast ==== | ||
- | |||
- | This parameter can be used to set the interface that should join the multicast group. This is useful if you want to **listen** on a multicast address and don't want to depend on the kernel routing table for choosing an interface. | ||
- | |||
- | The parameter is reset after each **listen** parameter, so you can join the right multicast group on each interface without having to modify kernel routing beforehand. | ||
Example of usage: | Example of usage: | ||
- | |||
- | mcast=" | ||
- | listen=udp: | ||
- | |||
- | ==== mcast_loopback ==== | ||
- | |||
- | It can be ' | ||
- | |||
- | Example of usage: | ||
- | |||
- | mcast_loopback=yes | ||
- | |||
- | ==== mcast_ttl ==== | ||
- | |||
- | Set the value for multicast ttl. Default value is OS specific (usually 1). | ||
- | |||
- | Example of usage: | ||
- | |||
- | mcast_ttl=32 | ||
- | |||
- | ==== memdbg ==== | ||
- | |||
- | **Alias name: mem_dbg** | ||
- | |||
- | This parameter specifies on which log level the memory debugger messages will be logged. If memdbg is active, every request (alloc, free) to the memory manager will be logged. (Note: if compile option NO_DEBUG is specified, there will never be logging from the memory manager). | ||
- | |||
- | Default value: L_DBG (memdbg=3) | ||
- | |||
- | For example, memdbg=2 means that memory debugging is activated if the debug level is 2 or higher. | ||
- | |||
- | debug=3 | ||
- | memdbg=4 | ||
- | |||
- | debug=3 | ||
- | memdbg=2 | ||
- | |||
- | Please see also [[#memlog]] and [[#debug]]. | ||
- | |||
- | ==== memlog ==== | ||
- | |||
- | **Alias name: mem_log** | ||
- | |||
- | This parameter specifies on which log level the memory statistics will be logged. If memlog is active, Kamailio will log memory statistics on shutdown (or if requested via signal SIGUSR1). This can be useful for debugging of memory leaks. | ||
- | |||
- | Default value: L_DBG (memlog=3) | ||
- | |||
- | For example, memlog=2 means that memory statistics dumping is activated if the debug level is 2 or higher. | ||
- | |||
- | debug=3 | ||
- | memlog=4 | ||
- | |||
- | debug=3 | ||
- | memlog=2 | ||
- | |||
- | Please see also [[#memdbg]] and [[#debug]]. | ||
- | |||
- | ==== mem_join ==== | ||
- | |||
- | If set to 1, memory manger (e.g., q_malloc) does join of free fragments. It is effective if MEM_JOIN_FREE compile option is defined. | ||
- | |||
- | It can be set via config reload framework. | ||
- | |||
- | Default is 1 (enabled). | ||
<code c> | <code c> | ||
- | mem_join=1 | + | if($hflc(Via)==3) { |
+ | ... | ||
+ | } | ||
</ | </ | ||
+ | ===== $var(name) - Private memory variables (zero) ===== | ||
- | To change its value at runtime, | + | **$var(name)** - refers |
- | < | + | Example of usage: |
- | kamcmd cfg.set_now_int core mem_join 1 | + | |
- | </ | + | |
- | + | ||
- | To disable, set its value to 0. | + | |
- | ==== mem_safety ==== | + | |
- | + | ||
- | If set to 1, memory free operation does not call abort() for double freeing a pointer or freeing an invalid address. The server still prints the alerting log messages. If set to 0, the SIP server stops by calling abort() to generate a core file. | + | |
- | + | ||
- | It can be set via config reload framework. | + | |
- | + | ||
- | Default is 1 (enabled). | + | |
<code c> | <code c> | ||
- | mem_safety=0 | + | $var(a) |
- | </ | + | $var(a) = " |
+ | $var(a) = " | ||
+ | $var(a) = 3 + (7& | ||
- | ==== mem_status_mode ==== | + | if( $var(a) & 4 ) { |
- | + | | |
- | If set to 1, memory status dump for qm allocator will print details about used fragments. If set to 0, the dump contains only free fragments. It can be set at runtime via cfg param framework (e.g., via kamcmd). | + | } |
- | + | ||
- | Default is 0. | + | |
- | + | ||
- | <code c> | + | |
- | mem_status_mode=1 | + | |
</ | </ | ||
- | ==== mem_summary ==== | + | **Note:** Setting a variable |
- | + | ||
- | Parameter to control printing of mmemory debugging information displayed on exit or SIGUSR1. The value can be composed by following flags: | + | |
- | | + | |
- | | + | |
- | | + | |
- | | + | |
- | + | ||
- | If set to 0, nothing is printed. | + | |
- | + | ||
- | Default | + | |
- | + | ||
- | Example: | + | |
<code c> | <code c> | ||
- | mem_summary=15 | + | $var(x) |
- | </ | + | |
- | ==== mhomed ==== | + | if($var(x)==0) { # this is true |
- | + | ... | |
- | Set the server to try to locate outbound interface on multihomed host. This parameter affects the selection of the outgoing socket for forwarding requests. By default is off (0) - it is rather time consuming. When deactivated, | + | } |
- | + | ||
- | Example of usage: | + | |
- | + | ||
- | mhomed=1 | + | |
- | + | ||
- | ==== mlock_pages ==== | + | |
- | Locks all Kamailio pages into memory making it unswappable (in general one doesn' | + | |
- | + | ||
- | | + | |
- | + | ||
- | ==== modinit_delay ==== | + | |
- | + | ||
- | Number of microseconds to wait after initializing a module - useful to cope with systems where are rate limits on new connections to database or other systems. | + | |
- | + | ||
- | Default value is 0 (no wait). | + | |
- | + | ||
- | < | + | |
- | modinit_delay=100000 | + | |
</ | </ | ||
+ | **Note:** A script variable persists over the Kamailio process in which it was initialized, | ||
- | ==== modparam ==== | + | <fc # |
- | + | ||
- | The modparam command will be used to set the options of the modules. | + | |
- | + | ||
- | Example: | + | |
- | + | ||
- | modparam(" | + | |
- | modparam(" | + | |
- | + | ||
- | See the documenation of the respective module to find out the available options. | + | |
- | + | ||
- | ==== modparamx ==== | + | |
- | Similar to **modparam**, with ability | + | **pv** module can be used to initialize |
- | ==== onsend_route_reply ==== | + | |
- | If set to 1 (yes, on), onsend_route block is executed for received replies that are sent out. Default is 0. | + | ===== $vz(name) - Private memory variables (zero) ===== |
- | onsend_route_reply=yes | + | Same as $var(name) -- added to pair with $vn(name). |
- | ==== open_files_limit | + | ===== $vn(name) - Private memory variables (null) ===== |
- | If set and bigger than the current open file limit, Kamailio will try to increase its open file limit to this number. Note: Kamailio must be started as root to be able to increase a limit past the hard limit (which, for open files, | + | Similar to $var(name) |
Example of usage: | Example of usage: | ||
- | open_files_limit=2048 | + | <code c> |
+ | $vn(x) | ||
+ | $vn(x) = " | ||
+ | $vn(x) = $null; | ||
- | ==== phone2tel ==== | + | if($vn(x) == $null) { ... } |
- | By enabling this feature, Kamailio internally treats SIP URIs with user=phone parameter as TEL URIs. If you do not want this behavior, you have to turn it off. | + | |
- | + | ||
- | Default value: 1 (enabled) | + | |
- | + | ||
- | phone2tel | + | |
- | + | ||
- | + | ||
- | ==== pmtu_discovery ==== | + | |
- | If enabled, the Don't Fragment (DF) bit will be set in outbound IP packets. | + | |
- | + | ||
- | pmtu_discovery = 0 | 1 (default 0) | + | |
- | + | ||
- | ==== port ==== | + | |
- | + | ||
- | The port the SIP server listens to. The default value for it is 5060. | + | |
- | + | ||
- | Example of usage: | + | |
- | + | ||
- | port=5080 | + | |
- | + | ||
- | ==== pv_buffer_size ==== | + | |
- | + | ||
- | The size in bytes of internal buffer to print dynamic strings with pseudo-variables inside. The default value is 8192 (8kB). Please keep in mind that for xlog messages, there is a dedicated module parameter to set the internal buffer size. | + | |
- | + | ||
- | Example of usage: | + | |
- | + | ||
- | < | + | |
- | pv_buffer_size=2048 | + | |
</ | </ | ||
+ | ===== $shv(name) - Shared memory variables ===== | ||
- | ==== pv_buffer_slots ==== | + | **$shv(name)** |
- | The number of internal buffer slots to print dynamic strings with pseudo-variables inside. The default value is 10. | + | Example - shv(name) |
- | + | ||
- | Example of usage: | + | |
< | < | ||
- | pv_buffer_slots=12 | + | ... |
+ | modparam(" | ||
+ | ... | ||
+ | if ($shv(debug) == 1) { | ||
+ | xlog(" | ||
+ | } | ||
+ | ... | ||
</ | </ | ||
- | ==== pv_cache_limit ==== | + | <fc # |
- | The limit how many pv declarations in the cache after which an action is taken. Default value is 2048. | + | ===== $dsv(key) - Dispatcher variables ===== |
- | < | + | Return attributes related to dispatcher module. |
- | pv_cache_limit=1024 | + | |
- | </ | + | |
- | ==== pv_cache_action ==== | + | The key can be: |
- | Specify what action to be done when the size of pv cache is exceeded. If 0, print an warning log message when the limit is exceeded. If 1, warning log messages is printed and the cache systems tries to drop a $sht(...) declaration. Default is 0. | + | * code - the SIP response code that caused the execution |
+ | * reason - the SIP response reason that caused | ||
+ | * flags - flags set internally when executing event_route ' | ||
+ | ===== $time(name) - Broken-down time ===== | ||
- | < | + | **$time(name)** - the PV provides access to broken-down time attributes in the local timezone. |
- | pv_cache_action=1 | + | |
- | </ | + | |
- | ==== rundir ==== | + | The ' |
+ | * sec - return seconds (int 0-59) | ||
+ | * min - return minutes (int 0-59) | ||
+ | * hour - return hours (int 0-23) | ||
+ | * mday - return the day of month (int 0-59) | ||
+ | * mon - return the month (int 1-12) | ||
+ | * year - return the year (int, e.g., 2008) | ||
+ | * wday - return the day of week (int, 1=Sunday - 7=Saturday) | ||
+ | * yday - return the day of year (int, 1-366) | ||
+ | * isdst - return daylight saving time status (int, 0 - DST off, >0 DST on) | ||
- | Alias: run_dir | + | Example - time(name) pseudo-variable |
- | + | ||
- | Set the folder for creating runtime files such as MI fifo or CTL unixsocket. | + | |
- | + | ||
- | Default: / | + | |
- | + | ||
- | Example | + | |
- | + | ||
- | < | + | |
- | rundir="/ | + | |
- | </ | + | |
- | + | ||
- | ==== received_route_mode ==== | + | |
- | + | ||
- | Enable or disable the execution of event_route[core: | + | |
- | + | ||
- | Default value: 0 (disabled) | + | |
- | + | ||
- | Example of usage: | + | |
<code c> | <code c> | ||
- | received_route_mode=1 | + | ... |
+ | if ($time(year) | ||
+ | xlog(" | ||
+ | } | ||
+ | ... | ||
</ | </ | ||
- | ==== reply_to_via | + | ===== $utime(name) - Broken-down time ===== |
- | If it is set to 1, any local reply is sent to the IP address advertised | + | **$utime(name)** - the PV provides access |
- | Example of usage: | + | See **$time(name)** above for the possible attributes |
+ | ===== $timef(format) - Strftime Formatted Time ===== | ||
- | reply_to_via=0 | + | **$timef(format)** |
- | + | ||
- | + | ||
- | ==== route_locks_size ==== | + | |
- | + | ||
- | Set the number of mutex locks to be used for synchronizing the execution of config script for messages sharing the same Call-Id. In other words, enables Kamailio | + | |
- | + | ||
- | For smaller impact on parallel processing, its value it should be at least twice the number of Kamailio processes (all children processes). | + | |
Example: | Example: | ||
<code c> | <code c> | ||
- | route_locks_size = 256 | + | xlog(" |
</ | </ | ||
- | Note that ordering of the SIP messages can still be changed by network transmission | + | ===== $utimef(format) - Strftime Formatted UTC Time ===== |
- | ==== server_id | + | |
- | A configurable unique server id that can be used to discriminate server instances within a cluster of servers when all other information, | + | **$utimef(format)** - return current time in UTC as formatted by strftime ' |
- | <code c> | + | Example: |
- | server_id = number | + | |
- | </ | + | |
- | + | ||
- | ==== server_header ==== | + | |
- | + | ||
- | Set the value of Server header for replies generated by Kamailio. It must contain the header name, but not the ending CRLF. | + | |
- | + | ||
- | Example | + | |
<code c> | <code c> | ||
- | server_header="Server: My Super SIP Server" | + | xlog("The time is $utimef(%m/ |
</ | </ | ||
- | ==== server_signature | + | ===== $ccp(key) - Config Custom Parameters ===== |
- | This parameter controls | + | Get the value for global custom parameters: |
- | Example of usage: | + | * https:// |
- | | ||
- | If it is enabled (default=yes) a header is generated as in the following example: | + | Example: |
- | + | ||
- | | + | |
- | + | ||
- | ==== shm_force_alloc ==== | + | |
- | Tries to pre-fault all the shared memory, before starting. When " | + | |
- | + | ||
- | shm_force_alloc = yes | no (default no) | + | |
- | + | ||
- | ==== shm_mem_size ==== | + | |
- | + | ||
- | Set shared memory size (in Mb). | + | |
- | + | ||
- | shm_mem_size = 64 (default 64) | + | |
- | + | ||
- | ==== sip_parser_log ==== | + | |
- | + | ||
- | Log level for printing debug messages for some of the SIP parsing errors. | + | |
- | + | ||
- | Default: 0 (L_WARN) | + | |
<code c> | <code c> | ||
- | sip_parser_log | + | gv.sval |
- | </ | + | gv.ival = 10 desc "ten var" |
- | ==== sip_parser_mode ==== | + | request_route { |
- | + | | |
- | Control sip parser behaviour. | + | } |
- | + | ||
- | If set to 1, the parser is more strict in accepting messages that have invalid headers | + | |
- | + | ||
- | If set to 0, the parser is less strict on checking validity of headers. | + | |
- | + | ||
- | Default: 1 | + | |
- | + | ||
- | <code c> | + | |
- | sip_parser_mode = 0 | + | |
</ | </ | ||
- | ==== sip_warning | + | ===== $sel(name) - Selects ===== |
- | Can be 0 or 1. If set to 1 (default value is 0) a ' | + | **$sel(name)** - return the value of **select** specified by name. **select** refers |
- | The header contains several details that help troubleshooting using the network traffic dumps, but might reveal details | + | |
- | Example | + | List of available selects: |
+ | * http:// | ||
- | sip_warning=0 | + | Example: |
- | + | ||
- | ==== socket_workers ==== | + | |
- | + | ||
- | Number of workers to process SIP traffic per listen socket - typical use is before a **listen** global parameter. | + | |
- | + | ||
- | * when used before **listen** on UDP or SCTP socket, it overwrites **children** or **sctp_children** value for that socket. | + | |
- | * when used before **listen** on TCP or TLS socket, it adds extra tcp workers, these handling traffic only on that socket. | + | |
- | + | ||
- | The value of **socket_workers** is reset with next **listen** socket definition that is added, thus use it for each **listen** socket where you want custom number of workers. | + | |
- | + | ||
- | If this parameter is not used at all, the values for **children**, | + | |
- | + | ||
- | Example | + | |
<code c> | <code c> | ||
- | children=4 | ||
- | socket_workers=2 | ||
- | listen=udp: | ||
- | listen=udp: | ||
- | listen=udp: | ||
- | </ | ||
- | * it will start 2 workers to handle traffic on udp: | + | if($sel(via[1].host)=="10.10.10.10") |
- | + | { | |
- | Example for tcp sockets: | + | ... |
- | + | ||
- | <code c> | + | |
- | children=4 | + | |
- | socket_workers=2 | + | |
- | listen=tcp: | + | |
- | listen=tcp: | + | |
- | listen=tcp: | + | |
- | </ | + | |
- | + | ||
- | * it will start 2 workers to handle traffic on tcp: | + | |
- | + | ||
- | ==== sql_buffer_size ==== | + | |
- | + | ||
- | The size in bytes of the SQL buffer created for data base queries. For database drivers that use the core db_query library, this will be maximum size object that can be written or read from a database. Default value is 65535. | + | |
- | + | ||
- | Example of usage: | + | |
- | + | ||
- | sql_buffer_size=131070 | + | |
- | + | ||
- | + | ||
- | ==== statistics ==== | + | |
- | + | ||
- | Kamailio has built-in support for statistics counter. This means, these counters can be increased, decreased, read and cleared. The statistics counter are defined either by the core (e.g. tcp counters), by modules (e.g. 2xx_transactions by "tmx" module) or by the script writer using the " | + | |
- | + | ||
- | The statistics counters are read/ | + | |
- | + | ||
- | Following are some examples how to access statistics variables: | + | |
- | + | ||
- | **script** | + | |
- | < | + | |
- | modparam(" | + | |
- | + | ||
- | (if method == " | + | |
- | update_stat(" | + | |
} | } | ||
- | |||
- | xlog(" | ||
</ | </ | ||
- | **MI** | + | ===== Received Data Attributes ===== |
- | < | + | |
- | # get counter value | + | |
- | kamctl fifo get_statistics NOTIFY | + | |
- | # set counter to zero | + | |
- | kamctl fifo reset_statistics NOTIFY | + | |
- | # get counter value and then set it to zero | + | |
- | kamctl fifo clear_statistics NOTIFY | + | |
- | # or use the kamcmd tool | + | ==== $rcv(key) ==== |
- | kamcmd mi get_statistics 1xx_replies | + | |
- | </ | + | |
+ | Attributes of received data. The variables must be used inside **event_route[core: | ||
- | ==== stats_name_separator ==== | + | The key can be: |
- | Specify the character used as a separator for the internal statistics' | + | * buf - received message |
- | Default value is " | + | * len - lenght of received message |
+ | * srcip - source ip | ||
+ | * rcvip - local ip where it was received | ||
+ | * scrport - source port | ||
+ | * rcvport - local port where it was received | ||
+ | * proto - protocol as int id | ||
+ | * sproto - protocol | ||
+ | * af - address family | ||
Example of usage: | Example of usage: | ||
- | |||
- | stats_name_separator = " | ||
- | |||
- | ==== tos ==== | ||
- | |||
- | The TOS (Type Of Service) to be used for the sent IP packages (both TCP and UDP). | ||
- | |||
- | Example of usage: | ||
- | |||
- | tos=IPTOS_LOWDELAY | ||
- | tos=0x10 | ||
- | tos=IPTOS_RELIABILITY | ||
- | |||
- | ==== udp_mtu ==== | ||
- | Fallback to another protocol (udp_mtu_try_proto must be set also either globally or per packet) if the constructed request size is greater then udp_mtu. | ||
- | |||
- | RFC 3261 specified size: 1300. Default: 0 (off). | ||
- | |||
- | udp_mtu = number | ||
- | |||
- | ==== udp_mtu_try_proto ==== | ||
- | |||
- | If udp_mtu !=0 and udp forwarded request size (after adding all the " | ||
- | |||
- | **Warning: | ||
- | |||
- | See also udp_mtu_try_proto(proto) function. | ||
- | |||
- | Default: UDP (off). Recommended: | ||
- | |||
- | udp_mtu_try_proto = TCP|TLS|SCTP|UDP | ||
- | |||
- | |||
- | ==== uri_host_extra_chars ==== | ||
- | |||
- | Specify additional chars that should be allowed in the host part of URI. | ||
<code c> | <code c> | ||
- | uri_host_extra_chars = "_" | + | event_route[core: |
+ | xlog("rcv on $rcv(af)/ | ||
+ | } | ||
</ | </ | ||
- | ==== user ==== | ||
- | **Alias name: uid** | + | ===== $rpl(key) ===== |
- | The user id to run Kamailio (Kamailio will suid to it). | + | Attributes of the SIP reply processed at that moment. |
- | Example of usage: | + | The key can be: |
- | <code c> | + | * duri - SIP URI corresponding to the address where the SIP reply is going to be sent based on 2nd via |
- | | + | * dhost - host part of duri |
- | </ | + | * dport - port part of duri |
+ | * dproto - proto part of duri | ||
+ | * dprotoid - proto id of duri | ||
+ | * cntvia - the number of Via header bodies | ||
- | ==== user_agent_header ==== | + | Example |
- | + | ||
- | Set the value of User-Agent header for requests generated by Kamailio. It must contain header name as well, but not the ending CRLF. | + | |
<code c> | <code c> | ||
- | user_agent_header="User-Agent: My Super SIP Server" | + | reply_route{ |
+ | xinfo("reply to be sent to: $rpl(duri)\n"); | ||
+ | } | ||
</ | </ | ||
- | ==== verbose_startup | + | ===== $msgbuf(index) ===== |
- | Control if printing routing tree and udp probing | + | Get or set the character in the message |
- | Default is 0 (don't print); set to 1 to get those debug messages. | + | The index has to be a positive integer or a variable holding such value. |
- | Example | + | Note that the variable returns a clone of the character stored in a static buffer, copy it to another variable if you want to compare with another $msgbuf(index). |
- | <code c> | + | The update |
- | | + | |
- | </ | + | |
- | + | ||
- | ==== version_table ==== | + | |
- | + | ||
- | Set the name of the table holding the table version. Useful if the proxy is sharing a database within a project | + | |
Example of usage: | Example of usage: | ||
<code c> | <code c> | ||
- | version_table="version44" | + | if ($msgbuf(20)==" |
+ | $msgbuf(20) | ||
+ | } | ||
</ | </ | ||
+ | ===== Header Field Iterator ===== | ||
- | ==== wait_worker1_mode | + | ==== $hfitname(iname) |
- | Enable waiting for child SIP worker one to complete initialization, | + | The header name of the header field iterator. |
- | + | ||
- | Default: 0 (do not wait for child worker one to complete initialization). | + | |
Example: | Example: | ||
<code c> | <code c> | ||
- | wait_worker1_mode = 1 | + | hf_iterator_start(" |
+ | while(hf_iterator_next(" | ||
+ | xlog(" | ||
+ | } | ||
+ | hf_iterator_end(" | ||
</ | </ | ||
- | ==== wait_worker1_time | + | ==== $hfitbody(iname) |
- | How long to wait for child worker one to complete | + | The header body of the header field iterator. |
- | + | ||
- | Default: 4000000 (micro-seconds = 4 seconds). | + | |
Example: | Example: | ||
<code c> | <code c> | ||
- | wait_worker1_time = 1000000 | + | hf_iterator_start(" |
+ | while(hf_iterator_next(" | ||
+ | xlog(" | ||
+ | } | ||
+ | hf_iterator_end(" | ||
</ | </ | ||
- | ==== wait_worker1_usleep | + | ===== Body Line Iterator ===== |
- | How long to wait for child worker one to complete the initialization. In micro-seconds. | + | ==== $blitval(iname) ==== |
- | Default: 100000 (micro-seconds = 0.1 seconds). | + | The value of the body line iterator. |
Example: | Example: | ||
<code c> | <code c> | ||
- | wait_worker1_usleep = 50000 | + | bl_iterator_start(" |
+ | while(bl_iterator_next(" | ||
+ | xlog(" | ||
+ | } | ||
+ | bl_iterator_end(" | ||
</ | </ | ||
- | ==== workdir ==== | ||
- | **Alias name: wdir** | + | ===== Send Data Attributes ===== |
- | The working directory used by Kamailio at runtime. You might find it useful when it comes to generating core files :) | + | ==== $sndfrom(name) ==== |
- | Example | + | **$snd(name)** - return attributes |
- | | + | **$sndfrom(name)** - return attributes of the address from where the request is going to be sent (local socket, same as $snd(name)). |
- | or | + | |
- | | + | |
- | ==== xavp_via_params ==== | + | The name can have same values as for $sndto(...). |
- | Set the name of the XAVP of which subfields will be added as local //Via// -header parameters. | + | ==== $sndto(name) ==== |
- | If not set, XAVP to Via header parameter manipulation | + | **$sndto(name)** - return attributes of the address |
- | If set, local Via header gets additional parameters from defined XAVP. Core flag FL_ADD_XAVP_VIA_PARAMS needs to be set¹. | + | They are available in **onsend_route**. The name can be: |
- | Example: | + | * ip - IP address of destination |
- | | + | * af - address family to be used to send (numeric) |
- | [1] See function // | + | * port - port of destination address |
- | + | * proto - transport protocol to be used to send (numeric - UDP=1, TCP=2, TLS=3, SCTP=4, WS=5, WSS=6) | |
- | ==== xavp_via_fields | + | * sproto - transport protocol |
- | + | * buf - entire send buffer as string | |
- | Set the name of xavp from where to take Via header field: address and port. | + | * len - length of outgoing packet (length of above buf) |
- | Use them to build local Via header. | + | |
Example: | Example: | ||
<code c> | <code c> | ||
- | xavp_via_fields=" | ||
- | request_route | + | onsend_route |
- | | + | |
- | | + | |
- | $xavp(customvia=> | + | ... |
- | | + | |
- | | + | |
} | } | ||
</ | </ | ||
- | |||
- | See function // | ||
- | ===== DNS Parameters | + | ===== SIPDUMP Module |
- | Note: See also file doc/dns.txt for details about Kamailio' | + | ==== $sipdump(name) ==== |
- | Kamailio has an internal DNS resolver with caching capabilities. If this caching resolver is activated | + | **$sipdump(name)** - return attributes of the message handled |
- | ^ DNS resolver comparison | + | The name can be: |
- | | Caching of resolved records | yes | no* | | + | |
- | | NAPTR/SRV lookups with correct weighting | yes | yes | | + | |
- | | DNS based failover | yes | no | | + | |
- | * Of course you can use the resolving name servers configured in / | + | |
+ | * buf - entire message buffer | ||
+ | * len - length of the message (length of above buf) | ||
+ | * af - address family | ||
+ | * src_ip - source IP address | ||
+ | * dst_ip - destination IP address | ||
+ | * src_port - port of source address | ||
+ | * dst_port - port of source address | ||
+ | * proto - transport protocol | ||
- | If the internal resolver/ | + | Example: |
- | dns.add_srv, | + | |
- | Note: During startup of Kamailio, before the internal resolver is loaded, the system resolver will be used (it will be used for queries done from module register functions or modparams fixups, but not for queries done from mod_init() or normal fixups). | + | <code c> |
- | Note: The dns cache uses the DNS servers configured on your server | + | event_route[sipdump:msg] { |
+ | if($sipdump(len) > 1024) { | ||
+ | | ||
+ | } | ||
+ | } | ||
+ | </ | ||
- | Kamailio also allows you to finetune the DNS resolver settings. | ||
- | The maximum time a dns request can take (before failing) is (if dns_try_ipv6 is yes, multiply it again by 2; if SRV and NAPTR lookups are enabled, it can take even longer!): | + | ===== SIPTRACE Module ===== |
+ | ==== $siptrace(name) ==== | ||
- | (dns_retr_time*(dns_retr_no+1)*dns_servers_no)*(search_list_domains) | + | **$siptrace(name)** - return attributes of the message handled in the event_route[siptrace: |
- | Note: During DNS lookups, the process which performs the DNS lookup blocks. To minimize the blocked time the following parameters | + | The name can be: |
- | | + | |
- | | + | |
- | | + | |
- | | + | |
+ | * src_hostip - source host, for IPv6 host do not contains `[]` | ||
+ | * dst_hostip - destination host, for IPv6 host do not contains `[]` | ||
+ | * src_port - source port | ||
+ | * dst_port - destination port | ||
+ | * src_proto - source proto | ||
+ | * dst_proto - destination proto | ||
- | ==== dns ==== | + | Example: |
- | This parameter controls if the SIP server will try doing a DNS lookup on the address in the Via header of a received sip request to decide if adding a received=<src_ip> parameter to the Via is necessary. Note that Vias containing | + | <code c> |
- | DNS names (instead of IPs) should have received= added, so turning dns to yes is not recommended. | + | event_route[siptrace: |
+ | { | ||
+ | if (allow_address(" | ||
+ | return; | ||
- | Default is no. | + | } |
+ | if (compare_ips($siptrace(src_host), | ||
+ | return; | ||
+ | } | ||
+ | } | ||
+ | </ | ||
- | ==== rev_dns ==== | ||
- | This parameter controls if the SIP server will try doing a reverse DNS lookup on the source IP of a sip request | + | ===== Benchmark Module ===== |
- | to decide if adding a received=< | + | |
- | See also dns (the effect is cumulative, both can be turned on and in that case if the DNS lookup test fails the reverse | + | |
- | DNS test will be tried). | + | |
- | Note that Vias containing DNS names (instead of IPs) should have received= added, so turning rev_dns to yes is not recommended. | + | |
- | + | ||
- | Default | + | ==== $BM_time_diff ==== |
+ | $BM_time_diff - the time difference elapsed between calls of bm_start_timer(name) and bm_log_timer(name). The value is 0 if no bm_log_timer() was called. | ||
- | ==== dns_cache_del_nonexp | + | ===== Dialog Module ===== |
- | **Alias name: dns_cache_delete_nonexpired** | + | ==== $dlg(attr) ==== |
- | dns_cache_del_nonexp = yes | no (default: no) | + | Return the attribute |
- | allow deletion | + | |
- | left for new ones. The last-recently used entries are deleted first. | + | |
- | ==== dns_cache_rec_pref ==== | + | <fc # |
- | dns_cache_rec_pref = number (default 0) | + | |
- | dns cache record preference, determines how new DNS records are stored internally in relation to existing entries. | + | |
- | Possible values: | + | |
- | 0 - do not check duplicates | + | |
- | 1 - prefer old records | + | |
- | 2 - prefer new records | + | |
- | 3 - prefer records with longer lifetime | + | |
- | ==== dns_cache_flags ==== | + | The ' |
- | | + | |
- | dns cache specific resolver | + | * h_entry - hash entry |
- | | + | * ref - reference count |
- | | + | * state - state of dialog |
- | | + | * to_rs - To route set |
- | | + | * from_rs - From route set |
- | | + | * dflags - dialog internal |
- | if this fails try an ipv4 address | + | * sflags - dialog script flags |
+ | * callid | ||
+ | * to_uri | ||
+ | * to_tag - To tag | ||
+ | * from_uri - From uri | ||
+ | * from_tag - From tag | ||
+ | * toroute - timeout route | ||
+ | * lifetime - timeout inteval | ||
+ | * start_ts - start timestamp | ||
+ | * to_cseq - To CSeq | ||
+ | * from_cseq - From CSeq | ||
+ | * to_contact - To contact | ||
+ | * from_contact | ||
+ | * to_bindaddr - To bind address | ||
+ | * from_bindaddr - From bind address | ||
- | ==== dns_cache_gc_interval | + | ==== $dlg_ctx(attr) |
- | Interval in seconds after which the dns cache is garbage collected (default: 120 s) | + | |
- | dns_cache_gc_interval = number | + | Return the attribute of the context for current processed dialog. |
+ | <fc # | ||
- | ==== dns_cache_init ==== | + | The ' |
+ | * set - returns 1 if the dialog for current context is set, 0 otherwise | ||
+ | * flags - get/set dialog flags | ||
+ | * timeout_route - get/set route name to be executed on timeout | ||
+ | * timeout_route_id - get internal id for the route to be executed on timeout | ||
+ | * timeout_bye - set to 1 if BYE has to be sent when dialog lifetime elapses | ||
+ | * timeout - set the dialog lifetime (in seconds) | ||
+ | * on - get/set an integer value associated with the context (cfg usage) | ||
+ | * dir - get direction of the request for the dialog of the current context (0 - unknown, 1 - downstream, 2 - upstream) | ||
- | If off, the dns cache is not initialized at startup and cannot be enabled runtime, that saves some memory. | + | ==== $dlg_var(key) ==== |
- | dns_cache_init = on | off (default on) | + | Store and retrieve custom variable for current processed dialog. |
- | ==== dns_cache_max_ttl ==== | + | <fc # |
- | dns_cache_max_ttl = time in seconds (default MAXINT) | + | |
- | ==== dns_cache_mem ==== | + | The ' |
- | Maximum memory used for the dns cache in KB (default 500 K) | + | |
- | dns_cache_mem | + | ===== Erlang Module ===== |
+ | ==== Attributes === | ||
- | ==== dns_cache_min_ttl ==== | + | * type - get variable type. Possible types are: atom, integer, list, string, tuple, pid and ref. |
- | dns_cache_min_ttl = time in seconds (default 0) | + | |
- | ==== dns_cache_negative_ttl ==== | + | * length - get length of list or tuple. |
- | Tells how long to keep negative DNS responses | + | * format - prints a term, in clear text. It tries to resemble the term printing in the Erlang shell. |
- | ==== dns_naptr_ignore_rfc | + | ==== $erl_atom(name) |
- | If the DNS lookup should ignore the remote side's protocol preferences, as indicated by the Order field in the NAPTR records and mandated by RFC 2915. | + | // |
+ | Erlang atom is a literal, a constant with name. Formatted output pseudo variable | ||
+ | atom could be enclosed | ||
+ | lower-case letter or if it contains other characters than alphanumeric characters, | ||
+ | underscore (_), or @. | ||
- | dns_naptr_ignore_rfc = yes | no (default yes) | + | Example: |
- | ==== dns_retr_no ==== | + | <code c> |
+ | $erl_atom(A) | ||
- | Number of dns retransmissions before giving up. Default value is system specific, depends also on the '/ | + | xlogl(" |
+ | </ | ||
- | Example | + | ==== $erl_list(name) ==== |
+ | Compound data type with a variable number | ||
+ | the empty list [] or consists of one or more elements. | ||
- | dns_retr_no=3 | + | Example: |
- | ==== dns_retr_time ==== | + | <code c> |
+ | $erl_atom(E) | ||
+ | $erl_list(L) | ||
+ | $erl_list(L) | ||
+ | $erl_list(L) | ||
- | Time in seconds before retrying a dns request. Default value is system specific, depends also on the '/ | + | xlogl(" |
- | Example of usage: | + | # empty list |
+ | $erl_tuple(E[*]) = $null; | ||
+ | </ | ||
- | dns_retr_time=3 | + | ==== $erl_tuple(name) ==== |
+ | From the Erlang point of view the tuple compound data type with a fixed number | ||
+ | of terms. The module implementation of tuple has the same behavior as the list. | ||
- | ==== dns_search_full_match ==== | + | Example: |
- | When name was resolved using dns search list, check the domain added in the answer matches with one from the search list (small performance hit, but more safe) | + | |
- | dns_search_full_match = yes | no (default yes) | + | <code c> |
+ | $erl_atom(e) = " | ||
- | ==== dns_servers_no ==== | + | $erl_tuple(T) |
+ | $erl_tuple(T) | ||
- | How many dns servers from the ones defined in '/etc/ | + | xlogl(" |
+ | </code> | ||
- | Example of usage: | + | ==== $erl_pid(name) ==== |
+ | Holds Eralng process identifier. Provides access to Erlang PID value and could | ||
+ | be used in send message. | ||
- | dns_servers_no=2 | + | ==== $erl_ref(name) ==== |
+ | Holds Erlang reference. Provides access to reference value and could be used in | ||
+ | send message. | ||
- | ==== dns_srv_lb | + | ==== $erl_xbuff(name) |
+ | Generic pseudo variable to acts as other pseudo variables exported from Erlang | ||
+ | module. | ||
- | **Alias name: dns_srv_loadbalancing** | + | ===== HTable Module ===== |
- | Enable dns srv weight based load balancing | + | ==== $sht(htable=> |
- | dns_srv_lb = yes | no (default no) | + | Access hash table entries. |
- | ==== dns_try_ipv6 ==== | + | <fc # |
- | Can be ' | + | The “htname” must be a hash table name defined via “htable” parameter. |
- | for ipv6 (AAAA record). Default value is ' | + | |
- | Note: If dns_try_ipv6 is off, no hostname resolving that would result in an ipv6 address would succeed - it doesn' | + | The “key” can be: |
- | Example | + | * static string - set of characters without pseudo-variables |
+ | * dynamic string - set of characters that include pseudo-variables. The pseudo-variables will be evaluated at runtime. | ||
- | dns_try_ipv6=yes | + | < |
+ | ... | ||
+ | modparam(" | ||
+ | ... | ||
+ | $sht(a=> | ||
+ | $sht(a=> | ||
+ | ... | ||
+ | </ | ||
- | ==== dns_try_naptr | + | ==== $shtex(htable=> |
- | Enable NAPTR support according to RFC 3263 (see doc/dns.txt for more info) | + | |
- | + | ||
- | dns_try_naptr | + | |
- | ==== dns_sctp_pref, | + | Access hash table entry expire value. Value represents the seconds until the htable entry will expire and be deleted from htable. |
- | **Alias name: dns_sctp_preference, dns_tcp_preference, | + | <fc # |
- | Set preference for each protocol when doing naptr lookups. By default dns_udp_pref=30, | + | The “htname” must be a hash table name defined via “htable” parameter |
- | dns_tls_pref=10 | + | |
- | dns_tcp_pref=1, | + | |
- | preference to -1 (or any other negative number). (see doc/dns.txt for more info) | + | |
- | dns_{udp, | + | The “key” can be: |
- | ==== dns_use_search_list ==== | + | * static string - set of characters without pseudo-variables |
+ | * dynamic string - set of characters that include pseudo-variables. The pseudo-variables will be evaluated at runtime. | ||
- | Can be ' | + | < |
+ | ... | ||
+ | modparam(" | ||
+ | ... | ||
+ | $sht(a=>$au) = 1; | ||
+ | $shtex(a=>$au) = 10; | ||
+ | ... | ||
+ | </ | ||
- | HINT: even if you don't have a search list defined, setting this option to ' | ||
- | Example of usage: | + | ==== $shtcn(htable=> |
- | dns_use_search_list=no | + | Count items matching the name by regexp. |
- | ==== use_dns_cache ==== | + | The “htname” must be a hash table name defined via “htable” parameter. |
- | Tells if DNS responses are cached - this means that the internal DNS resolver (instead of the system' | + | The **exp** |
- | ==== use_dns_failover ==== | + | * reqexp - match by regular expression ' |
- | use_dns_failover = on | off (default off) | + | * ~~regexp - match by regular expression ' |
+ | * ~%prefix - match by right prefix | ||
+ | * %~prefix - match by left prefix | ||
+ | * ==value - match by string value | ||
+ | * eqvalue - match by integer value | ||
+ | * * * - (two asterisks next to each other) - count all items | ||
- | ===== TCP Parameters ===== | + | The **exp** can contain pseudo-variables. |
- | The following parameters allows to tweak the TCP behaviour. | + | < |
+ | ... | ||
+ | modparam(" | ||
+ | ... | ||
+ | $sht(a=> | ||
+ | $shtex(a=> | ||
+ | xlog(" | ||
+ | ... | ||
+ | </ | ||
- | ==== disable_tcp | + | ==== $shtcv(htable=> |
- | Global parameter to disable TCP support in the SIP server. Default | + | Count items matching |
- | Example of usage: | + | The “htname” must be a hash table name defined via “htable” parameter. |
- | disable_tcp=yes | + | The **exp** must follow same rules as for **$shtcn(...)**. |
- | ==== tcp_accept_aliases ==== | + | < |
- | + | ... | |
- | If a message received over a tcp connection has "alias" | + | modparam(" |
+ | ... | ||
+ | $sht(a=>abc) = "xyz"; | ||
+ | $shtex(a=>ade) = " | ||
+ | xlog(" | ||
+ | ... | ||
+ | </ | ||
- | Based on draft-ietf-sip-connect-reuse-00.txt, | + | ==== $shtinc(htable=> |
- | See force_tcp_alias | + | Atomic increment of the value for the hash table item. |
- | Note: For NAT traversal of TCP clients it is better to not use tcp_accept_aliases but just use nathelper module and fix_nated_[contact|register] functions. | + | < |
- | + | ... | |
- | Default is "no" | + | modparam("htable", |
- | + | ... | |
- | tcp_accept_aliases= yes|no | + | $sht(a=> |
- | + | xlog("==== $shtinc(a=>$au)\n"); | |
- | ==== tcp_accept_haproxy | + | ... |
- | + | ||
- | Enable the internal TCP stack to expect a PROXY-protocol-formatted header as the first message of the connection. Both the human-readable (v1) and binary-encoded (v2) variants of the protocol are supported. This option is typically useful if you are behind a TCP load-balancer, | + | |
- | + | ||
- | Please note that enabling this option will reject any inbound TCP connection that does not conform to the PROXY-protocol spec. | + | |
- | + | ||
- | For reference: A PROXY protocol - https://www.haproxy.org/ | + | |
- | + | ||
- | Default value is **no**. | + | |
- | + | ||
- | <code c> | + | |
- | tcp_accept_haproxy=yes | + | |
</ | </ | ||
- | ==== tcp_accept_hep3 | + | ==== $shtdec(htable=> |
- | Enable internal TCP receiving stack to accept HEP3 packets. This option has to be set to **yes** on a Kamailio instance acting as Homer SIPCapture server that is supposed to receive HEP3 packets over TCP/TLS. | + | Atomic decrement of the value for the hash table item. |
- | Default value is **no**. | + | < |
- | + | ... | |
- | <code c> | + | modparam(" |
- | tcp_accept_hep3=yes | + | ... |
+ | $sht(a=>$au) = 1; | ||
+ | xlog("==== $shtdec(a=> | ||
+ | ... | ||
</ | </ | ||
- | ==== tcp_accept_no_cl | + | ==== $shtitkey(iname) |
- | Control whether to throw or not error when there is no Content-Length header for requests received over TCP. It is required to be set to **yes** for XCAP traffic sent over HTTP/1.1 which does not use Content-Length header, but splits large bodies in many chunks. | + | The key at the current position |
- | Default value is **no**. | + | ==== $shtitval(iname) ==== |
- | <code c> | + | The value at the current position in the iterator. |
- | tcp_accept_no_cl=yes | + | |
- | </ | + | |
- | ==== tcp_accept_unique ==== | + | Example: |
- | + | ||
- | If set to 1, reject duplicate connections coming from same source IP and port. | + | |
- | + | ||
- | Default set to 0. | + | |
<code c> | <code c> | ||
- | tcp_accept_unique = 1 | + | sht_iterator_start(" |
+ | while(sht_iterator_next(" | ||
+ | xlog(" | ||
+ | } | ||
+ | sht_iterator_end(" | ||
</ | </ | ||
- | ==== tcp_async ==== | ||
- | **Alias name: tcp_buf_write** | + | ==== $shtrecord(id) ==== |
- | If enabled, all the tcp writes that would block / wait for connect to finish, will be queued and attempted latter (see also tcp_conn_wq_max and tcp_wq_max). | + | Get the key or the value of expired item inside the event_route[htable: |
- | **Note:** It also applies for TLS. | + | The id can be: |
- | | + | |
- | | + | |
- | ==== tcp_children ==== | + | Example: |
- | + | ||
- | Number of children processes to be created for reading from TCP connections. If no value is explicitly set, the same number of TCP children as UDP children (see " | + | |
- | + | ||
- | Example | + | |
- | + | ||
- | tcp_children=4 | + | |
- | + | ||
- | ==== tcp_clone_rcvbuf ==== | + | |
- | + | ||
- | Control if the received buffer should be cloned from the TCP stream, needed by functions working inside the SIP message buffer (such as msg_apply_changes()). | + | |
- | + | ||
- | Default is 0 (don't clone), set it to 1 for cloning. | + | |
- | + | ||
- | Example of usage: | + | |
- | + | ||
- | tcp_clone_rcvbuf=1 | + | |
- | ==== tcp_connection_lifetime ==== | + | |
- | + | ||
- | Lifetime in seconds for TCP sessions. TCP sessions which are inactive for longer than **tcp_connection_lifetime** will be closed by Kamailio. Default value is defined is 120. Setting this value to 0 will close the TCP connection pretty quick ;-). | + | |
- | + | ||
- | Note: As many SIP clients are behind NAT/ | + | |
- | + | ||
- | Example of usage: | + | |
- | + | ||
- | tcp_connection_lifetime=3605 | + | |
- | + | ||
- | ==== tcp_connection_match ==== | + | |
- | + | ||
- | If set to 1, try to be more strict in matching outbound TCP connections, | + | |
- | + | ||
- | Default is 0. | + | |
<code c> | <code c> | ||
- | tcp_connection_match=1 | + | event_route[htable: |
+ | xlog(" | ||
+ | } | ||
</ | </ | ||
- | ==== tcp_connect_timeout | + | ===== Memcached Module ===== |
- | Time in seconds before an ongoing attempt to establish a new TCP connection will be aborted. Lower this value for faster detection of TCP connection problems. The default value is 10s. | + | ==== $mct(key) ==== |
- | Example of usage: | + | Access hash table entries stored in the memcached server. |
- | tcp_connect_timeout=5 | + | <fc # |
- | ==== tcp_conn_wq_max ==== | + | The “key” can be: |
- | Maximum bytes queued for write allowed per connection. Attempting to queue more bytes would result in an error and in the connection being closed (too slow). If tcp_buf_write is not enabled, it has no effect. | + | * static string - set of characters without pseudo-variables |
+ | * dynamic string - set of characters that include pseudo-variables. The pseudo-variables will be evaluated at runtime. | ||
- | tcp_conn_wq_max = bytes (default | + | When assigning values, the default |
- | + | ||
- | ==== tcp_crlf_ping ==== | + | |
- | Enable SIP outbound TCP keep-alive using PING-PONG (CRLFCRLF - CRLF). | + | |
- | tcp_crlf_ping | + | < |
+ | ... | ||
+ | $mct($au) | ||
+ | $mct($ru) = $fu; | ||
+ | $mct(test) = 1; | ||
+ | xlog(" | ||
+ | $mct(test) = null; # delete it | ||
+ | xlog(" | ||
+ | ... | ||
+ | </ | ||
+ | ==== $mct(key=> | ||
- | ==== tcp_defer_accept ==== | + | Using this alternative format, the default expiry may be overidden by including a custom value at time of assignment. |
- | Tcp accepts will be delayed until some data is received | + | < |
+ | ... | ||
+ | $mct(test=>30) = 1; # set expire time to 30 seconds | ||
+ | xlog(" | ||
+ | # sleep 30 seconds | ||
+ | xlog(" | ||
+ | ... | ||
+ | </ | ||
- | WARNING: the linux TCP_DEFER_ACCEPT is buggy (<=2.6.23) and doesn' | + | ==== $mcinc(key) ==== |
- | On FreeBSD: | + | Do a atomic increment operation on the value stored in memcached. You need to add a value previously. |
- | tcp_defer_accept = yes | no (default no) | + | |
- | + | ||
- | On Linux: | + | |
- | tcp_defer_accept = number of seconds before timeout (default disabled) | + | |
- | ==== tcp_delayed_ack ==== | + | <fc # |
- | Initial ACK for opened connections will be delayed and sent with the first data segment (see linux tcp(7) TCP_QUICKACK). For now linux only. | + | |
- | tcp_delayed_ack | + | The “key” can be: |
- | ==== tcp_fd_cache ==== | + | * static string - set of characters without pseudo-variables |
+ | * dynamic string - set of characters that include pseudo-variables. The pseudo-variables will be evaluated at runtime. | ||
- | If enabled FDs used for sending will be cached inside the process calling tcp_send | + | < |
+ | ... | ||
+ | $mct(cnt) = 1; | ||
+ | $mcinc(cnt) = 2; # increment by 2 | ||
+ | xlog(" | ||
+ | ... | ||
+ | </ | ||
- | tcp_fd_cache | + | ==== $mcdec(key) ==== |
- | ==== tcp_keepalive ==== | + | Do a atomic decrement operation on the value stored in memcached. You need to add a value previously. |
- | Enables keepalive for tcp (sets SO_KEEPALIVE socket option) | + | |
- | tcp_keepalive = yes | no (default yes) | + | <fc # |
- | ==== tcp_keepcnt ==== | + | The “key” can be: |
- | Number of keepalives sent before dropping the connection (TCP_KEEPCNT socket option). Linux only. | + | |
- | | + | |
+ | * dynamic string - set of characters that include pseudo-variables. The pseudo-variables will be evaluated at runtime. | ||
- | ==== tcp_keepidle ==== | + | < |
+ | ... | ||
+ | $mct(cnt) | ||
+ | $mcdec(cnt) | ||
+ | xlog(" | ||
+ | ... | ||
+ | </ | ||
- | Time before starting to send keepalives, if the connection is idle (TCP_KEEPIDLE socket option). Linux only. | + | ===== http_async_client Module ===== |
- | tcp_keepidle | + | ==== $http_req_id ==== |
- | ==== tcp_keepintvl ==== | + | The $http_req_id read-only variable can be used in REQUEST_ROUTE to retrive |
- | Time interval between keepalive probes, when the previous probe failed (TCP_KEEPINTVL socket option). Linux only. | + | |
- | tcp_keepintvl | + | ==== $http_req(key) ==== |
- | ==== tcp_linger2 ==== | + | The $http_req(key) write-only variable can be used to set custom parameters before sending a HTTP query. |
- | Lifetime of orphaned sockets in FIN_WAIT2 state (overrides tcp_fin_timeout on, see linux tcp(7) TCP_LINGER2). Linux only. | + | |
- | tcp_linger2 = seconds | + | **key** can be one of: |
+ | * all: if set to $null, resets all the parameters to their default value (the ones defined in modparam) | ||
+ | * hdr: sets/ | ||
+ | * body: sets/ | ||
+ | * method: sets the HTTP method: either " | ||
+ | * timeout: sets the HTTP timeout. (Note, this timeout should be normally less than tm.fr_timer timeout, because transaction timeout has a higher priority over HTTP timeout) | ||
+ | * tls_client_cert: | ||
+ | * tls_client_key: | ||
+ | * tls_ca_path: | ||
+ | * authmethod: Sets the preferred authentication mode for HTTP/HTTPS requests. The value is a bitmap and multiple methods can be used. Note that in this case, the CURL library will make an extra request to discover server-supported authentication methods. You may want to use a specific value. Valid values are: | ||
+ | * 1 - BASIC authentication | ||
+ | * 2 - HTTP Digest authentication | ||
+ | * 4 - GSS-Negotiate authentication | ||
+ | * 8 - NTLM authentication | ||
+ | * 16 - HTTP Digest with IE flavour. | ||
+ | * (Default value is 3 - BASIC and Digest authentication.) | ||
+ | * username: sets the username to use for authenticated requests | ||
+ | * password: sets the password to use for authenticated requests | ||
+ | * suspend: if set to 0 it doesn' | ||
+ | * tcp_keepalive: | ||
+ | * tcp_ka_idle: | ||
+ | * tcp_ka_interval: | ||
- | ==== tcp_max_connections | + | ==== Other read-only variables |
- | Maximum number of tcp connections (if the number is exceeded no new tcp connections will be accepted). Default is defined | + | The following read-only pseudo variables can only be used in the callback routes executed by http_async_query() |
- | Example of usage: | + | === $http_ok === |
+ | 1 if cURL executed the request successfully, | ||
- | tcp_max_connections=4096 | + | === $http_err === |
+ | cURL error string if an error occurred, $null otherwise. | ||
- | ==== tcp_no_connect ==== | + | === $http_rs |
+ | HTTP status. | ||
- | Stop outgoing TCP connects (also stops TLS) by setting tcp_no_connect to yes. | + | === $http_rr === |
+ | HTTP reason phrase. | ||
- | You can do this any time, even even if Kamailio is already started (in this case using the command " | + | === $http_hdr(Name) === |
+ | Value of the Name header (the $(http_hdr(Name)[N]) syntax | ||
- | ==== tcp_poll_method ==== | + | === $http_mb and $http_ml |
+ | HTTP response buffer (including headers) and length. | ||
- | Poll method used (by default the best one for the current OS is selected). For available types see io_wait.c | + | === $http_rb |
+ | HTTP response body and body length, | ||
- | Example of usage: | + | ===== XMLOPS Pseudo-Variables ===== |
- | tcp_poll_method=select | + | ==== $xml(name=> |
- | ==== tcp_rd_buf_size ==== | + | * name - id to refer the documet |
+ | * spec - specifier: | ||
+ | * doc - set/get the document as text | ||
+ | * xpath: | ||
- | Buffer size used for tcp reads. A high buffer size increases performance on server with few connections and lot of traffic on them, but also increases memory consumption (so for lots of connection is better to use a low value). Note also that this value limits the maximum message size (SIP, HTTP) that can be received over tcp. | + | Example: |
- | + | ||
- | The value is internally limited to 16MByte, for higher values recompile Kamailio with higher limit in tcp_options.c (search for " | + | |
- | + | ||
- | Default: 4096, can be changed at runtime. | + | |
- | < | + | < |
- | tcp_rd_buf_size=65536 | + | $xml(x=>doc) = '<? |
+ | xlog(" | ||
+ | $xml(x=> | ||
</ | </ | ||
- | ==== tcp_send_timeout ==== | ||
- | Time in seconds after a TCP connection will be closed if it is not available for writing in this interval (and Kamailio wants to send something on it). Lower this value for faster detection of broken TCP connections. The default value is 10s. | + | ===== TMX Module ===== |
- | Example of usage: | + | ==== $T_branch_idx ==== |
- | tcp_send_timeout=3 | + | * the index (starting with 0 for the first branch) of the branch for which is executed the branch_route[]. |
+ | * in failure_route[] block, the value is the number of completed branches added to the number of new new branches | ||
+ | * in request_route block, the value is number of created branches | ||
+ | * in onreply_route[], | ||
+ | * if used outside of transaction processing, the value is ' | ||
- | ==== tcp_source_ipv4, | + | ==== $T_reply_ruid |
- | Set the source IP for all outbound TCP connections. If setting | + | * the ruid stored in the current branch of the transaction. The ruid is stored in a branch from the details in a contact binding. In a event_route[tm: |
- | tcp_source_ipv4 = IPv4 address | ||
- | tcp_source_ipv6 = IPv6 address | ||
- | ==== tcp_syncnt | + | ==== $T_reply_code |
- | Number of SYN retransmissions before aborting a connect attempt (see linux tcp(7) TCP_SYNCNT). Linux only. | + | |
- | | + | |
- | ==== tcp_wq_blk_size | + | ==== $T_req(pv) |
- | Block size used for tcp async writes. It should be big enough to hold a few datagrams. If it's smaller then a datagram (in fact a tcp write()) size, it will be rounded up. It has no influenced on the number of datagrams queued (for that see tcp_conn_wq_max or tcp_wq_max). It has mostly debugging and testing value (can be ignored). | + | |
- | Default: 2100 (~ 2 INVITEs), | + | * can be used in reply routes or inside the modules to get access to attributes of the request belonging to same transaction as the reply |
- | ==== tcp_wq_max ==== | + | < |
+ | route { | ||
+ | t_on_reply(" | ||
+ | t_relay(); | ||
+ | } | ||
- | Maximum bytes queued for write allowed globally. It has no effect if tcp_buf_write is not enabled. | + | onreply_route[1] { |
+ | xlog(" | ||
+ | } | ||
+ | </ | ||
- | tcp_wq_max | + | ==== $T_rpl(pv) |
- | + | ||
- | ==== tcp_reuse_port | + | |
- | Allows reuse of TCP ports. This means,for example, that the same TCP ports on which Kamailio is listening on, can be used as source ports of new TCP connections when acting | + | * can be used in failure routes or inside the modules to get access to attributes |
+ | <code> | ||
+ | route { | ||
+ | t_on_failure(" | ||
+ | t_relay(); | ||
+ | } | ||
- | tcp_reuse_port | + | failure_route[1] { |
+ | xlog(" | ||
+ | } | ||
+ | </ | ||
- | ===== TLS Parameters ===== | + | ==== $T_inv(pv) |
- | Most of TLS layer attributes | + | * can be used in request routes or inside the modules to get access to attributes of the INVITE request while processing a CANCEL. |
- | ==== tls_port_no ==== | + | < |
+ | route { | ||
+ | if(is_method(" | ||
+ | { | ||
+ | | ||
+ | { | ||
+ | # first flag is set in the INVITE transaction | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | </ | ||
- | The port the SIP server listens to for TLS connections. | + | ==== $T(name) ==== |
- | Default value is 5061. | + | * pseudo-variable class to access TM attributes |
- | Example of usage: | + | The **name** can be: |
- | tls_port_no=6061 | + | * id_index - return the internal index of current transaction or $null if not transaction is found |
+ | * id_label - return the internal label of current transaction or $null if not transaction is found | ||
+ | * id_index_n - return the internal index of current transaction, | ||
+ | * id_label_n - return the internal label of current transaction, | ||
+ | * reply_code - reply code (alias to $T_reply_code) | ||
+ | * reply_reason - reply reason | ||
+ | * reply_last - last received reply code | ||
+ | * branch_index - branch index (alias to $T_branch_idx) | ||
+ | * ruid - return the internal location ruid field for current branch | ||
+ | * reply_type - 1 if it is a local generated reply, 0 - if no reply for transaction or it is a received reply | ||
- | ==== tls_max_connections ==== | + | Note: the pair (id_index, |
- | Maximum number of ls connections | + | ==== $T_branch(name) ==== |
- | Default value is 2048. | + | * pseudo-variable class to access TM branch attributes |
- | Example of usage: | + | The **name** can be: |
- | tls_max_connections=4096 | + | * flags - Flags of the branch. In a event_route[tm: |
- | ===== SCTP Parameters ===== | + | * uri - the R-URI of the branch. Can be used in onreply_route[id] - reply route blocks executed by tm module. For other routing blocks handling requests, the R-URI is returned by $ru |
- | ==== disable_sctp ==== | ||
- | Global parameter to disable SCTP support in the SIP server. see enable_sctp | + | ===== UAC Module ===== |
- | Default value is ' | + | ==== $uac_req(key) ==== |
- | Example | + | * used to build the input for uac_send_req() function |
- | disable_sctp=yes | + | The key can be: |
+ | * method - SIP method | ||
+ | * ruri - request URI | ||
+ | * furi - From URI | ||
+ | * turi - To URI | ||
+ | * ouri - Outbound proxy URI | ||
+ | * hdrs - SIP Headers | ||
+ | * body - Body | ||
+ | * flags - flags for processing | ||
+ | * 1 - the password is provided in HA1 format | ||
+ | * auser - authentication username | ||
+ | * apasswd - authentication password | ||
+ | * sock - local socket to be used for sending (proto: | ||
+ | * callid - SIP-Call-ID of the generated request (by default, a call-id is generated) | ||
+ | * all - alias useful to reset all fields - $uac_req(all) | ||
+ | * evroute - it has to be set to 1 in order to execute event_route[uac: | ||
+ | * evcode - reply code for the request sent with uac_req_send(), | ||
+ | * evtype - is 1 if the reply was received via network, 2 if the reply was locally generated (e.g., retransmission timeout), available inside event_route[uac: | ||
+ | * evparam - generic data buffer associated with the request that can be set before sending it and retrieved when executing the event route. It has a size of 128 characters. | ||
- | ==== enable_sctp | + | <code c> |
+ | $uac_req(method)=" | ||
+ | $uac_req(ruri)=" | ||
+ | $uac_req(furi)=" | ||
+ | $uac_req(turi)=" | ||
+ | $uac_req(evroute) = 1; | ||
+ | uac_req_send(); | ||
+ | ... | ||
+ | event_route[uac: | ||
+ | xlog(" | ||
+ | } | ||
+ | </ | ||
+ | ===== Nathelper Module | ||
- | enable_sctp | + | ==== $rr_count ==== |
- | | + | |
- | ==== sctp_children ==== | + | * Number of Record Routes in received SIP request or reply. |
- | sctp children no (similar to udp children) | + | |
- | sctp_children = number | + | |
- | ==== sctp_socket_rcvbuf | + | ==== $rr_top_count |
- | Size for the sctp socket receive buffer | + | |
- | **Alias name: sctp_socket_receive_buffer** | + | |
- | sctp_socket_rcvbuf | + | ===== MQueue Module ===== |
- | ==== sctp_socket_sndbuf | + | ==== $mqk(q) |
- | Size for the sctp socket send buffer | + | |
- | **Alias name: sctp_socket_send_buffer** | + | |
- | sctp_socket_sndbuf | + | ==== $mqv(q) ==== |
- | ==== sctp_autoclose ==== | ||
- | Number of seconds before autoclosing an idle association (default: 180 s). Can be changed at runtime, but it will affect only new associations. E.g.: | ||
- | $ kamcmd cfg.set_now_int sctp autoclose 120 | ||
- | | + | |
- | ==== sctp_send_ttl ==== | + | <code c> |
- | Number of milliseconds before an unsent message/ | + | ... |
- | $ kamcmd cfg.set_now_int sctp send_ttl 180000 | + | mq_add(" |
+ | ... | ||
+ | while(mq_fetch(" | ||
+ | { | ||
+ | | ||
+ | } | ||
+ | ... | ||
+ | </ | ||
- | sctp_send_ttl | + | ===== TimeVal ===== |
- | ==== sctp_send_retries | + | ==== $TV(name) |
- | How many times to attempt re-sending a message on a re-opened association, | + | |
- | WARNING: use with care and low values (e.g. 1-3) to avoid " | + | Seconds |
- | | + | |
+ | * $TV(u) - microseconds (cached at first call per sip message) | ||
+ | * $TV(sn) - seconds (not cached, taken at that moment) | ||
+ | * $TV(un) - microseconds (corresponding to the moment $TV(sn) is retrieved) | ||
+ | * $TV(Sn) - string representation seconds.microseconds (not cached, taken at that moment) | ||
+ | ===== Next hop address ===== | ||
- | ==== sctp_assoc_tracking | + | ==== $nh(key) |
- | Controls whether or not sctp associations are tracked inside Kamailio. Turning it off would result in less memory being used and slightly better performance, | + | |
- | Can be changed at runtime (" | + | Return attributes of next hop for the SIP messages. For SIP requests, the address is taken from dst_uri, if set, if not from new r-uri or original r-uri. For SIP replies, |
- | Note: turning sctp_assoc_tracking on/off will delete all the tracking information for all the currently tracked associations and might introduce a small temporary delay in the sctp processing if lots of associations were tracked. | + | * $nh(u) - uri (lower case u) |
+ | * $nh(U) - username (upper case u) | ||
+ | * $nh(d) - domain | ||
+ | * $nh(p) - port (lower case p) | ||
+ | * $nh(P) - transport protocol (upper case p) | ||
- | Config options depending on sctp_assoc_tracking being on: sctp_assoc_reuse. | + | ===== NDB_REDIS Module ===== |
- | sctp_assoc_tracking | + | ==== $redis(res=> |
- | ==== sctp_assoc_reuse ==== | + | Access the attributes of the Redis response. |
- | Controls sctp association reuse. For now only association reuse for replies is affected by it. Default: yes. | + | |
- | Depends on sctp_assoc_tracking being on. | + | |
- | Note that even if turned off, if the port in via corresponds to the source port of the association the request was sent on or if rport is turned on (force_rport() or via containing a rport option), the association will be automatically reused by the sctp stack. | + | The key can be: |
- | Can be changed at runtime (sctp assoc_reuse), | + | |
- | | + | |
+ | * value - the value returned by REDIS server; | ||
+ | * info - in case of error from REDIS, it will contain an info message. | ||
- | ==== sctp_max_assocs ==== | + | If reply type is an array (as in hiredis.h), there are other keys available: |
- | Maximum number of allowed open sctp associations. -1 means maximum allowed by the OS. Default: -1. | + | |
- | Can be changed at runtime | + | |
- | When Kamailio tries to open a new association and the max_assocs is exceeded the exact behaviour depends on whether or not | + | * size - returns number |
- | sctp_assoc_tracking is on. If on, the send triggering the active open will gracefully fail, before actually opening the new association and no packet will be sent. However if sctp_assoc_tracking is off, the association will first be opened and then immediately closed. In general this means that the initial sip packet will be sent (as part of the 4-way handshake). | + | |
+ | * type[n] - returns the type of the nth element in the array. type - returns array type. | ||
+ | * value[n] - returns value of the nth element. value - returns null for an array. You need to get each element by index. | ||
- | sctp_max_assocs = number | + | In case one of the members of the array is also an array (for example calling SMEMBERS in a MULTI/EXEC transaction), |
- | ==== sctp_srto_initial ==== | + | Example: |
- | Initial value of the retr. timeout, used in RTO calculations (default: OS specific). | + | |
- | Can be changed at runtime | + | < |
+ | redis_cmd(" | ||
+ | xlog(" | ||
+ | </ | ||
- | sctp_srto_initial | + | ==== $redisd(key) ==== |
- | ==== sctp_srto_max ==== | + | Return |
- | Maximum value of the retransmission timeout (RTO) (default: OS specific). | + | |
- | WARNING: values lower then the sctp sack_delay will cause lots of retransmissions and connection instability (see sctp_srto_min for more details). | + | The key can be: |
- | Can be changed at runtime (sctp srto_max) but it will affect only new associations. | + | * rpl_str - return REDIS_REPLY_STRING |
+ | * rpl_arr - return REDIS_REPLY_ARRAY | ||
+ | * rpl_int - return REDIS_REPLY_INTEGER | ||
+ | * rpl_nil - return REDIS_REPLY_NIL | ||
+ | * rpl_sts - return REDIS_REPLY_STATUS | ||
+ | * rpl_err - return REDIS_REPLY_ERROR | ||
- | sctp_srto_max | + | $redisd(rpl_XYZ) can be compared with $redis(r=>type). |
- | ==== sctp_srto_min ==== | + | Example: |
- | Minimum value of the retransmission timeout (RTO) (default: OS specific). | + | |
- | + | ||
- | WARNING: values lower then the sctp sack_delay of any peer might cause retransmissions and possible interoperability problems. According to the standard the sack_delay should be between 200 and 500 ms, so avoid trying values lower then 500 ms unless you control all the possible sctp peers and you do make sure their sack_delay is higher or their sack_freq is 1. | + | |
- | + | ||
- | Can be changed at runtime (sctp srto_min) but it will affect only new associations. | + | |
- | + | ||
- | sctp_srto_min = milliseconds | + | |
- | + | ||
- | ==== sctp_asocmaxrxt ==== | + | |
- | Maximum retransmissions attempts per association (default: OS specific). It should be set to sctp_pathmaxrxt * no. of expected paths. | + | |
- | + | ||
- | Can be changed at runtime (sctp asocmaxrxt) but it will affect only new associations. | + | |
- | + | ||
- | sctp_asocmaxrxt | + | |
- | + | ||
- | ==== sctp_init_max_attempts ==== | + | |
- | Maximum INIT retransmission attempts (default: OS specific). | + | |
- | + | ||
- | Can be changed at runtime (sctp init_max_attempts). | + | |
- | + | ||
- | sctp_init_max_attempts = number | + | |
- | + | ||
- | ==== sctp_init_max_timeo ==== | + | |
- | Maximum INIT retransmission timeout (RTO max for INIT). Default: OS specific. | + | |
- | + | ||
- | Can be changed at runtime (sctp init_max_timeo). | + | |
- | + | ||
- | sctp_init_max_timeo = milliseconds | + | |
- | + | ||
- | + | ||
- | ==== sctp_hbinterval ==== | + | |
- | sctp heartbeat interval. Setting it to -1 will disable the heartbeats. Default: OS specific. | + | |
- | + | ||
- | Can be changed at runtime (sctp hbinterval) but it will affect only new associations. | + | |
- | + | ||
- | sctp_hbinterval = milliseconds | + | |
- | + | ||
- | ==== sctp_pathmaxrxt ==== | + | |
- | Maximum retransmission attempts per path (see also sctp_asocmaxrxt). Default: OS specific. | + | |
- | + | ||
- | Can be changed at runtime (sctp pathmaxrxt) but it will affect only new associations. | + | |
- | + | ||
- | sctp_pathmaxrxt = number | + | |
- | + | ||
- | ==== sctp_sack_delay ==== | + | |
- | Delay until an ACK is generated after receiving a packet. Default: OS specific. | + | |
- | + | ||
- | WARNING: a value higher then srto_min can cause a lot of retransmissions (and strange problems). A value higher then srto_max will result in very high connections instability. According to the standard the sack_delay value should be between 200 and 500 ms. | + | |
- | + | ||
- | Can be changed at runtime (sctp sack_delay) but it will affect only new associations. | + | |
- | + | ||
- | sctp_sack_delay = milliseconds | + | |
- | + | ||
- | ==== sctp_sack_freq ==== | + | |
- | Number of packets received before an ACK is sent (without waiting for the sack_delay to expire). | + | |
- | + | ||
- | Note: on linux with lksctp up to and including 1.0.9 is not possible to set this value (having it in the config will produce a warning on startup). | + | |
- | + | ||
- | Can be changed at runtime (sctp sack_freq) but it will affect only new associations. | + | |
- | + | ||
- | sctp_sack_freq = number | + | |
- | + | ||
- | ==== sctp_max_burst ==== | + | |
- | Maximum burst of packets that can be emitted by an association. Default: OS specific. | + | |
- | + | ||
- | Can be changed at runtime (sctp max_burst) but it will affect only new associations. | + | |
- | + | ||
- | sctp_max_burst = number | + | |
- | + | ||
- | + | ||
- | ===== UDP Parameters ===== | + | |
- | + | ||
- | ==== udp4_raw ==== | + | |
- | + | ||
- | Enables raw socket support for sending UDP IPv4 datagrams (40-50% performance increase on linux multi-cpu). | + | |
- | + | ||
- | Possible values: 0 - disabled (default), 1 - enabled, -1 auto. | + | |
- | + | ||
- | In " | + | |
- | + | ||
- | The parameter can be set at runtime as long as sr was started with enough privileges (core.udp4_raw). | + | |
< | < | ||
- | udp4_raw | + | redis_cmd(" |
+ | if ($redis(r=>type) == $redisd(rpl_int)) { | ||
+ | } | ||
</ | </ | ||
- | ==== udp4_raw_mtu | + | ===== GeoIP Module ===== |
- | MTU value used for UDP IPv4 packets when udp4_raw is enabled. | + | ==== $gip(pvc=>key) ==== |
- | The parameter can be set at runtime | + | Variables exported by GeoIP module, returning geo-location attributes. |
- | ==== udp4_raw_ttl ==== | + | **pvc** (container id) is second parameter of geoip_match(..) and **key** can be: |
- | TTL value used for UDP IPv4 packets when udp4_raw is enabled. By default it is set to auto mode (-1), meaning that the same TTL will be used as for normal UDP sockets. | + | * cc - country code |
+ | * tz - time zone | ||
+ | * zip - postal code | ||
+ | * lat - latitude | ||
+ | * lon - longitude | ||
+ | * dma - dma code | ||
+ | * ips - ip start | ||
+ | * ipe - ip end | ||
+ | * city - city | ||
+ | * area - area code | ||
+ | * regc - region | ||
+ | * regn - region name | ||
+ | * metro - metro code | ||
+ | * contc - continent code | ||
- | The parameter | + | You can call several time **geoip_match(ipaddr, pvc)** with different ip address and containers in your config, to compare, for example, attributes of source and destination of a call. |
+ | <code c> | ||
+ | geoip_match(" | ||
+ | geoip_match(" | ||
- | ===== Blocklist Parameters ===== | + | if($gip(src=>cc)==$gip(dst=>cc)) |
+ | { | ||
+ | # source and destination from same country | ||
+ | } | ||
- | ==== dst_blocklist_expire ==== | + | </ |
- | **Alias name: dst_blocklist_ttl** | + | ==== $gip2(pvc=> |
- | How much time a blocklisted destination will be kept in the blocklist | + | Variables exported by GeoIP2 module, returning geo-location attributes. The attributes are populated upon calling function **geoip_match2(ipaddr, pvc)**. |
- | dst_blocklist_expire = time in s (default 60 s) | + | **pvc** |
- | ==== dst_blocklist_gc_interval ==== | + | * cc - country code |
- | How often the garbage collection will run (eliminating old, expired entries). | + | * tz - time zone |
+ | * zip - postal code | ||
+ | * lat - latitude | ||
+ | * lon - longitude | ||
+ | * dma - dma code | ||
+ | * ips - ip start | ||
+ | * ipe - ip end | ||
+ | * city - city | ||
+ | * area - area code | ||
+ | * regc - region | ||
+ | * regn - region name | ||
+ | * metro - metro code | ||
+ | * contc - continent code | ||
- | dst_blocklist_gc_interval = time in s (default 60 s) | + | You can call several |
- | ==== dst_blocklist_init ==== | + | <code c> |
- | If off, the blocklist is not initialized at startup and cannot be enabled runtime, that saves some memory. | + | geoip_match2(" |
+ | geoip_match2(" | ||
- | dst_blocklist_init | + | if($gip2(src=> |
+ | { | ||
+ | # source and destination from same country | ||
+ | } | ||
- | ==== dst_blocklist_mem ==== | + | </ |
- | Maximum shared memory amount used for keeping the blocklisted destinations. | + | |
- | dst_blocklist_mem | + | ===== TLS Module ===== |
- | ==== use_dst_blocklist | + | ==== $tls(key) |
- | Enable the destination blocklist: Each failed send attempt will cause the destination to be added to the blocklist. Before any send, this blocklist will be checked and if a match is found, the send is no longer attempted (an error is returned immediately). | + | |
- | Note: using the blocklist incurs a small performance penalty. | + | Variables related to TLS communication and certificates. |
- | See also doc/ | + | The **key** can be: |
- | | + | |
+ | * **p_issuer_line** - return remote (peer) certificate issuer line | ||
+ | * **m_subject_line** - return local (my) certificate subject line | ||
+ | * **p_subject_line** - return remote (peer) certificate subject line | ||
- | ===== Real-Time Parameters ===== | + | Example: |
- | ==== real_time ==== | + | |
- | + | ||
- | Sets real time priority for all the Kamailio processes, or the timers (bitmask). | + | |
- | | + | |
- | 1 - the " | + | |
- | 2 - the " | + | |
- | 4 - all processes, except the timers | + | |
- | Example: real_time= 7 => everything switched to real time priority. | + | |
- | + | ||
- | real_time = <int> (flags) (default off) | + | |
- | + | ||
- | ==== rt_policy ==== | + | |
- | Real time scheduling policy, 0 = SCHED_OTHER, | + | |
- | + | ||
- | rt_policy= < | + | |
- | + | ||
- | ==== rt_prio ==== | + | |
- | Real time priority used for everything except the timers, if real_time is enabled. | + | |
- | + | ||
- | rt_prio = <int> (default 0) | + | |
- | + | ||
- | ==== rt_timer1_policy ==== | + | |
- | + | ||
- | **Alias name: rt_ftimer_policy** | + | |
- | + | ||
- | Like rt_policy but for the " | + | |
- | + | ||
- | rt_timer1_policy=< | + | |
- | + | ||
- | ==== rt_timer1_prio ==== | + | |
- | + | ||
- | **Alias name: rt_fast_timer_prio, | + | |
- | + | ||
- | Like rt_prio but for the " | + | |
- | + | ||
- | rt_timer1_prio=< | + | |
- | + | ||
- | ==== rt_timer2_policy ==== | + | |
- | + | ||
- | **Alias name: rt_stimer_policy** | + | |
- | + | ||
- | Like rt_policy but for the " | + | |
- | + | ||
- | rt_timer2_policy=< | + | |
- | + | ||
- | ==== rt_timer2_prio ==== | + | |
- | + | ||
- | **Alias name: rt_stimer_prio** | + | |
- | + | ||
- | Like rt_prio but for the " | + | |
- | + | ||
- | rt_timer2_prio=< | + | |
- | ===== Core Functions ===== | + | |
- | + | ||
- | Functions exported by core that can be used in route blocks. | + | |
- | + | ||
- | ==== add_local_rport ==== | + | |
- | + | ||
- | Add **rport** parameter to local generated Via header -- see RFC3581. In effect for forwarded SIP requests. | + | |
- | + | ||
- | Example of usage: | + | |
<code c> | <code c> | ||
- | add_local_rport(); | + | if(proto==TLS) { |
+ | xinfo(" | ||
+ | } | ||
</ | </ | ||
- | ==== avpflags ==== | + | ==== $tls_version |
- | ==== break ==== | + | |
- | ' | + | The TLS/SSL version which is used on the TLS connection |
+ | ==== $tls_description ==== | ||
+ | The TLS/SSL description of the TLS connection from which the message was received. String type. | ||
+ | ==== $tls_cipher_info ==== | ||
+ | The TLS/SSL cipher which is used on the TLS connection from which the message was received. String type. | ||
+ | ==== $tls_cipher_bits ==== | ||
+ | The number of cipher bits which are used on the TLS connection from which the message was received. String and Integer type. | ||
+ | ==== $tls_peer_version ==== | ||
+ | The version of the certificate. String type. | ||
+ | ==== $tls_my_version ==== | ||
+ | The version of the certificate. String type. | ||
+ | ==== $tls_peer_serial ==== | ||
+ | The serial number of the certificate. String and Integer type. | ||
+ | ==== $tls_my_serial ==== | ||
+ | The serial number of the certificate. String and Integer type. | ||
+ | ==== $tls_peer_subject ==== | ||
+ | ASCII dump of the fields in the subject section of the certificate. String type. Example: | ||
+ | / | ||
+ | ==== $tls_peer_issuer ==== | ||
+ | ASCII dump of the fields in the issuer section of the certificate. String type. | ||
+ | ==== $tls_my_subject ==== | ||
+ | ASCII dump of the fields in the subject section of the certificate. String type. | ||
+ | ==== $tls_my_issuer ==== | ||
+ | ASCII dump of the fields in the issuer section of the certificate. String type. | ||
+ | ==== $tls_peer_subject_cn ==== | ||
+ | commonName in the subject section of the certificate. String type. | ||
+ | ==== $tls_peer_issuer_cn ==== | ||
+ | commonName in the issuer section of the certificate. String type. | ||
+ | ==== $tls_my_subject_cn ==== | ||
+ | commonName in the subject section of the certificate. String type. | ||
+ | ==== $tls_my_issuer_cn ==== | ||
+ | commonName in the issuer section of the certificate. String type. | ||
+ | ==== $tls_peer_subject_locality ==== | ||
+ | localityName in the subject section of the certificate. String type. | ||
+ | ==== $tls_peer_issuer_locality ==== | ||
+ | localityName in the issuer section of the certificate. String type. | ||
+ | ==== $tls_my_subject_locality ==== | ||
+ | localityName in the subject section of the certificate. String type. | ||
+ | ==== $tls_my_issuer_locality ==== | ||
+ | localityName in the issuer section of the certificate. String type. | ||
+ | ==== $tls_peer_subject_country ==== | ||
+ | countryName in the subject section of the certificate. String type. | ||
+ | ==== $tls_peer_issuer_country ==== | ||
+ | countryName in the issuer section of the certificate. String type. | ||
+ | ==== $tls_my_subject_country ==== | ||
+ | countryName in the subject section of the certificate. String type. | ||
+ | ==== $tls_my_issuer_country ==== | ||
+ | countryName in the issuer section of the certificate. String type. | ||
+ | ==== $tls_peer_subject_state ==== | ||
+ | stateOrProvinceName in the subject section of the certificate. String type. | ||
+ | ==== $tls_peer_issuer_state ==== | ||
+ | stateOrProvinceName in the issuer section of the certificate. String type. | ||
+ | ==== $tls_my_subject_state ==== | ||
+ | stateOrProvinceName in the subject section of the certificate. String type. | ||
+ | ==== $tls_my_issuer_state ==== | ||
+ | stateOrProvinceName in the issuer section of the certificate. String type. | ||
+ | ==== $tls_peer_subject_organization ==== | ||
+ | organizationName in the subject section of the certificate. String type. | ||
+ | ==== $tls_peer_issuer_organization ==== | ||
+ | organizationName in the issuer section of the certificate. String type. | ||
+ | ==== $tls_my_subject_organization ==== | ||
+ | organizationName in the subject section of the certificate. String type. | ||
+ | ==== $tls_my_issuer_organization ==== | ||
+ | organizationName in the issuer section of the certificate. String type. | ||
+ | ==== $tls_peer_subject_unit ==== | ||
+ | organizationalUnitName in the subject section of the certificate. String type. | ||
+ | ==== $tls_peer_subject_uid ==== | ||
+ | UID in the subject section of the certificate. String type. | ||
+ | ==== $tls_peer_issuer_unit ==== | ||
+ | organizationalUnitName in the issuer section of the certificate. String type. | ||
+ | ==== $tls_my_subject_unit ==== | ||
+ | organizationalUnitName in the subject section of the certificate. String type. | ||
+ | ==== $tls_my_subject_uid ==== | ||
+ | UID in the subject section of the certificate. String type. | ||
+ | ==== $tls_my_issuer_unit ==== | ||
+ | organizationalUnitName in the issuer section of the certificate. String type. | ||
+ | ==== $tls_peer_san_email ==== | ||
+ | email address in the " | ||
+ | ==== $tls_my_san_email ==== | ||
+ | email address in the " | ||
+ | ==== $tls_peer_san_hostname ==== | ||
+ | hostname (DNS) in the " | ||
+ | ==== $tls_my_san_hostname ==== | ||
+ | hostname (DNS) in the " | ||
+ | ==== $tls_peer_san_uri ==== | ||
+ | URI in the " | ||
+ | ==== $tls_my_san_uri ==== | ||
+ | URI in the " | ||
+ | ==== $tls_peer_san_ip ==== | ||
+ | ip address in the " | ||
+ | ==== $tls_my_san_ip ==== | ||
+ | ip address in the " | ||
- | ==== drop ==== | + | ==== $tls_peer_verified |
+ | Returns 1 if the peer's certificate was successfully verified. Otherwise it returns 0. String and Integer type. | ||
- | Stop the execution of the configuration script | + | ==== $tls_peer_revoked ==== |
+ | Returns 1 if the peer's certificate was revoked. Otherwise it returns 0. String | ||
- | If the function is called in a 'branch_route' | + | ==== $tls_peer_expired ==== |
+ | Returns 1 if the peer's certificate | ||
- | If the function is called in the default | + | ==== $tls_peer_selfsigned ==== |
+ | Returns 1 if the peer's certificate | ||
- | Example | + | ==== $tls_peer_notBefore ==== |
+ | Returns the notBefore validity date of the peer's certificate. String type. | ||
- | onreply_route { | + | ==== $tls_peer_notAfter ==== |
- | if(status==" | + | Returns the notAfter validity date of the peer's certificate. String type. |
- | drop(); # this works | + | |
- | } | + | |
- | } | + | |
- | onreply_route[FOOBAR] { | + | ==== $tls_peer_server_name ==== |
- | if(status==" | + | The SNI server name of the peer |
- | drop(); # this is ignored | + | |
- | } | + | |
- | } | + | |
- | ==== exit ==== | + | ==== $tls_peer_raw_cert |
+ | The raw PEM-encoded client certificate. String type. | ||
- | Stop the execution of the configuration script | + | ==== $tls_my_raw_cert ==== |
+ | The raw PEM-encoded client certificate. String type. | ||
- | route { | + | ==== $tls_peer_urlencoded_cert ==== |
- | if (route(2)) { | + | The PEM-encoded client certificate, urlencoded. String type. |
- | xlog(" | + | |
- | } else { | + | |
- | xlog(" | + | |
- | }; | + | |
- | } | + | |
- | route[2] { | + | ==== $tls_my_urlencoded_cert ==== |
- | if (is_method(" | + | The PEM-encoded client certificate, urlencoded. String type. |
- | return(1); | + | ===== SIP Message Attributes ===== |
- | } else if (is_method(" | + | |
- | return(-1); | + | |
- | } else if (is_method(" | + | |
- | sl_send_reply(" | + | |
- | exit; | + | |
- | }; | + | |
- | } | + | |
- | ==== error ==== | + | ==== $msg(attr) |
- | ==== exec ==== | + | Return attributes of SIP message: |
- | ==== force_rport | + | * $msg(len) - sip message length |
+ | * $msg(buf) - sip message buffer | ||
+ | * $msg(body) - sip message body | ||
+ | * $msg(body_len) - sip message body length | ||
+ | * $msg(hdrs) - sip message headers (surrounding white space and EoL chars trimmed) | ||
+ | * $msg(fline) - sip message first line (surrounding white space and EoL chars trimmed) | ||
+ | * $msg(fpart) - sip message first line and the headers | ||
+ | * $msg(lpart) - sip message headers and the body | ||
+ | ===== POSOPS Module ===== | ||
- | Force_rport() adds the rport parameter to the first Via header of the received message. Thus, Kamailio will add the received | + | ==== $pos(key) ==== |
- | This is useful for NAT traversal, to enforce symmetric response signaling. | + | Get attributes after a function of the module |
- | The rport parameter is defined in RFC 3581. | + | The key can be: |
- | Note: there is also a force_rport parameter which changes | + | * ret - the return code on success or -1 |
+ | * idx - position inside message buffer, for find/search it is the start of matching | ||
+ | * len - the length of matching string for search functions | ||
- | Example of usage: | + | ===== XHTTP Module ===== |
- | force_rport(); | + | ==== $hu ==== |
- | ==== add_rport ==== | + | * URL of http request. |
- | Alias for force_rport(); | + | |
- | ==== force_send_socket | + | ===== MSRP Module ===== |
+ | This class of pseudo-variables is exported by MSRP module and give access to attributes of MSRP frames. | ||
- | Force to send the message from the specified socket | + | ==== $msrp(buf) ==== |
- | This function does not support pseudo-variables, use the set_send_socket function from the corex module instead. | + | The entire content of MSRP frame - first line, headers, body and end-line. |
- | Example of usage: | + | ==== $msrp(body) ==== |
- | < | + | The body of MSRP frame. |
- | force_send_socket(10.10.10.10: | + | |
- | force_send_socket(udp: | + | |
- | </ | + | |
- | ==== force_tcp_alias ==== | + | |
- | **Alias name: add_tcp_alias** | + | ==== $msrp(code) ==== |
- | force_tcp_alias(port) | + | The code of MSRP replies. |
- | adds a tcp port alias for the current connection | + | ==== $msrp(hdrs) ==== |
- | Useful if you want to send all the trafic to port_alias through | + | |
- | the same connection this request came from [it could help | + | |
- | for firewall or nat traversal]. | + | |
- | With no parameters adds the port from the message via as the alias. | + | |
- | When the " | + | |
- | much time), all the port aliases are removed. | + | |
- | ==== forward ==== | + | The headers in a MSRP frame. |
- | Forward the SIP request to destination stored in $du in stateless mode. | + | ==== $msrp(msgid) ==== |
- | Example | + | The body of Message-Id header. |
- | $du = " | + | ==== $msrp(method) ==== |
- | forward(); | + | |
+ | The method of a MSRP request. | ||
+ | ==== $msrp(buflen) ==== | ||
+ | The length of entire MSRP frame. | ||
+ | ==== $msrp(sessid) ==== | ||
+ | The session id for MSRP frame. It is taken from the first MSRP URI in To-Path header. | ||
+ | ==== $msrp(reason) ==== | ||
+ | The reason text in a MSRP reply. | ||
+ | ==== $msrp(crthop) ==== | ||
- | ==== isavpflagset ==== | + | The URI for current hop - it is the first URI in To-Path header. |
- | ==== isflagset | + | ==== $msrp(bodylen) |
- | Test if a flag is set for current processed message (if the flag value is 1). The value of the parameter can be in range of 0..31. | + | The length |
- | For more see: https:// | + | ==== $msrp(transid) ==== |
- | Example | + | The transaction ID from the first line of MSRP frame. |
- | if(isflagset(3)) { | + | ==== $msrp(prevhop) ==== |
- | log(" | + | |
- | }; | + | |
+ | The MSRP URI of the previous hop - the first address in From-Path header. | ||
- | Kamailio also supports named flags. They have to be declared at the beginning of the config file with: | + | ==== $msrp(nexthop) ==== |
- | | + | The URI of the next hop - the second address in To-Path header. |
- | Example: | + | ==== $msrp(lasthop) ==== |
- | flags test, a:1, b:2 ; | + | |
- | | + | |
- | setflag(test); | + | |
- | if (isflagset(a)){ # equiv. to isflagset(1) | + | |
- | .... | + | |
- | } | + | |
- | resetflag(b); | + | |
- | ==== is_int ==== | + | The last hop URI - the last address in To-Path header. |
- | Checks if a pseudo variable argument contains integer value. | + | |
- | if(is_int(" | + | ==== $msrp(srcaddr) ==== |
- | log(" | + | |
- | } | + | |
- | ==== log ==== | + | The address of the previous hop set as MSRP URI using received source IP and port. |
- | Write text message to standard error terminal or syslog. You can specify the log level as first parameter. | + | ==== $msrp(srcsock) ==== |
- | For more see: http://www.kamailio.org/ | + | The local socket where the MSRP frame was received, set as **proto:ipaddr:port**. |
- | Example of usage: | + | ==== $msrp(firsthop) ==== |
- | log(" | + | The URI of the first hop - the last address in From-Path header. |
+ | ==== $msrp(prevhops) ==== | ||
- | ==== prefix ==== | + | The number of previous hops - it is the number of addresses in From-Path header. |
- | Add the string parameter in front of username in R-URI. | + | ==== $msrp(nexthops) ==== |
- | Example | + | The number |
- | prefix(" | + | ==== $msrp(conid) ==== |
- | ==== resetavpflag ==== | + | The internal integer id for TCP/TLS connection. |
- | ==== resetflag | + | ===== SIPT Module ===== |
- | ==== return | + | ==== $sipt(calling_party_number.presentation) / $sipt_presentation |
+ | Returns the value of the Address presentation restricted indicator contained in the Calling Party Number header of the IAM message if it exists. Returns -1 if there isn't a Calling Party Number header. | ||
- | The return() function allows you to return any integer value from a called route() block. | + | The following values can be returned: |
- | You can test the value returned by a route using [[devel# | + | * 0 presentation allowed |
+ | * 1 resentation restricted | ||
+ | * 2 address not avail (national use) | ||
+ | * 3 spare | ||
- | return(0) is same as [[devel# | + | Example: |
- | In bool expressions: | + | < |
- | + | if($sipt(calling_party_number.presentation) == 1) | |
- | * Negative is FALSE | + | { |
- | * Positive is TRUE | + | |
- | + | $fn = "Anonymous"; | |
- | If no value is specified, or a route reaches its end without executing a return statement, it returns 1. If return is used in the top level route is equivalent with exit [val]. | + | |
- | + | ||
- | Example usage: | + | |
- | + | ||
- | < | + | |
- | route { | + | |
- | | + | |
- | xlog("L_NOTICE"," | + | |
- | } else { | + | |
- | xlog(" | + | |
- | }; | + | |
- | } | + | |
- | </ | + | |
- | < | + | |
- | route[2] { | + | |
- | if (is_method("INVITE" | + | |
- | return(1); | + | |
- | } else if (is_method(" | + | |
- | return(-1); | + | |
- | } else { | + | |
- | return(0); | + | |
- | }; | + | |
} | } | ||
</ | </ | ||
- | See also the FAQ for how the function return code is evaluated: | ||
- | * https:// | + | ==== $sipt(calling_party_number.screening) / $sipt_screening |
- | ==== revert_uri | + | Returns the value of the Screening Indicator contained in the Calling Party Number header of the IAM message if it exists. Returns -1 if there isn't a Calling Party Number header. |
- | Set the R-URI to the value of the R-URI as it was when the request was received by server (undo all changes of R-URI). | + | Can return |
- | + | * 0 Reserved | |
- | Example of usage: | + | * 1 User Provided, Verified |
- | + | * 2 Reserved | |
- | revert_uri(); | + | * 3 Network provided |
- | + | ||
- | ==== rewritehostport ==== | + | |
- | + | ||
- | **Alias name: sethostport, | + | |
- | + | ||
- | Rewrite the domain part and port of the R-URI with the value of function' | + | |
- | + | ||
- | Example of usage: | + | |
- | + | ||
- | rewritehostport(" | + | |
- | + | ||
- | ==== rewritehostporttrans ==== | + | |
- | + | ||
- | **Alias name: sethostporttrans, sethpt** | + | |
- | + | ||
- | Rewrite the domain part and port of the R-URI with the value of function' | + | |
- | + | ||
- | Example of usage: | + | |
- | + | ||
- | rewritehostporttrans(" | + | |
- | + | ||
- | ==== rewritehost ==== | + | |
- | + | ||
- | **Alias name: sethost, seth** | + | |
- | + | ||
- | Rewrite the domain part of the R-URI with the value of function' | + | |
- | + | ||
- | Example of usage: | + | |
- | + | ||
- | rewritehost(" | + | |
- | + | ||
- | ==== rewriteport ==== | + | |
- | + | ||
- | **Alias name: setport, setp** | + | |
- | + | ||
- | Rewrites/ | + | |
- | + | ||
- | Example of usage: | + | |
- | + | ||
- | rewriteport(" | + | |
- | + | ||
- | ==== rewriteuri ==== | + | |
- | + | ||
- | **Alias name: seturi** | + | |
- | + | ||
- | Rewrite the request URI. | + | |
- | + | ||
- | Example of usage: | + | |
- | + | ||
- | rewriteuri(" | + | |
- | + | ||
- | ==== rewriteuserpass ==== | + | |
- | + | ||
- | **Alias name: setuserpass, setup** | + | |
- | + | ||
- | Rewrite the password part of the R-URI with the value of function' | + | |
- | + | ||
- | Example of usage: | + | |
- | + | ||
- | rewriteuserpass(" | + | |
- | ==== rewriteuser ==== | + | |
- | + | ||
- | **Alias name: setuser, setu** | + | |
- | + | ||
- | Rewrite the user part of the R-URI with the value of function' | + | |
- | + | ||
- | Example of usage: | + | |
- | + | ||
- | rewriteuser(" | + | |
- | + | ||
- | ==== route ==== | + | |
- | + | ||
- | Execute route block given in parameter. | + | |
- | + | ||
- | Examples of usage: | + | |
- | + | ||
- | route(REGISTER_REQUEST); | + | |
- | route(@received.proto + " | + | |
- | + | ||
- | + | ||
- | ==== selval ==== | + | |
- | + | ||
- | Select a value based on conditional expression. | + | |
- | + | ||
- | Prototype: | + | |
+ | Example: | ||
<code c> | <code c> | ||
- | selval(evalexpr, valexp1, valexpr2) | + | # remove P-Asserted-Identity header if the screening isn't verified |
+ | # or network provided | ||
+ | $avp(s:screening) = $sipt(calling_party_number.screening); | ||
+ | if($avp(s: | ||
+ | { | ||
+ | remove_hf(" | ||
+ | } | ||
</ | </ | ||
- | This is a core statement that return the 2nd parameter if the 1st parameter is evaluated to true, or 3rd parameter if the 1st parameter is evaluated to false. It can be considered a core function that is equivalent of ternary condition/ | ||
- | Example: | + | ==== $sipt(hop_counter) / $sipt_hop_counter ==== |
+ | Returns the value of the Hop Counter for the IAM message if it exists. Returns -1 if there isn't a hop counter. | ||
+ | Example: | ||
<code c> | <code c> | ||
- | $var(x) = selval($Ts mod 2, "true/" | + | # get the hop counter and update the Max-Forwards header if it exists |
+ | $avp(s:hop) = $sipt(hop_counter); | ||
+ | if($avp(s:hop) > 0) | ||
+ | { | ||
+ | remove_hf("Max-Forwards"); | ||
+ | append_hf("Max-Forwards: | ||
+ | } | ||
</ | </ | ||
- | The first parameter is a conditional expression, like those used for IF, the 2nd and 3rd parameters can be expressions like those used in the right side of assignments. | + | ==== $sipt(calling_party_category) / $sipt(cpc) / $sipt_cpc |
- | ==== set_advertised_address | + | Returns the value of the Calling Party Category for the IAM message. Returns -1 if there is a parsing error. |
- | Same as ' | + | ==== $sipt(calling_party_number.nature_of_address) / $sipt.(calling_party_number.nai) / $sipt_calling_party_nai ==== |
+ | Returns | ||
- | Example of usage: | + | Can return the following values: |
+ | * 0 Spare | ||
+ | * 1 Subscriber Number (national use) | ||
+ | * 2 Unknown (national use) | ||
+ | * 3 National (significant) number (national use) | ||
+ | * 4 International use | ||
- | set_advertised_address(" | + | Example: |
+ | <code c> | ||
+ | # get the Calling Nai and add country code if national | ||
+ | if($sipt(calling_party_number.nai) == 3) | ||
+ | { | ||
+ | $fU = " | ||
+ | } | ||
+ | </ | ||
- | ==== set_advertised_port | + | ==== |
+ | Returns the value of the Nature of Address Indicator of the Called Party for the IAM message. Returns -1 if there is a parsing error. | ||
- | Same as ' | + | Can return |
- | Example of usage: | + | * 0 Spare |
+ | * 1 Subscriber Number (national use) | ||
+ | * 2 Unknown (national use) | ||
+ | * 3 National (significant) number | ||
+ | * 4 International use | ||
+ | * 5 Network-specific number (national use) | ||
- | set_advertised_port(5080); | + | Example: |
+ | <code c> | ||
+ | # get the Called Nai and add country code if national | ||
+ | if($sipt(called_party_number.nai) == 3) | ||
+ | { | ||
+ | $rU = " | ||
+ | } | ||
+ | </ | ||
- | ==== set_forward_no_connect ==== | + | ==== $sipt(event_info) |
+ | Returns the value of the Event Info header of the CPG message. Returns -1 if there is a parsing error. | ||
- | The message will be forwarded only if there is already an existing connection to the destination. It applies only to connection oriented protocols like TCP and TLS (TODO: SCTP), for UDP it will be ignored. The behavior depends in which route block the function | + | Can return |
+ | * 0 Spare | ||
+ | * 1 ALERTING | ||
+ | * 2 PROGRESS | ||
+ | * 3 In-band information or an appropriate pattern | ||
+ | * 4 Call forward on busy | ||
+ | * 5 Call forward on no reply | ||
+ | * 6 Call forward unconditional | ||
- | * normal request route: affects stateless forwards and tm. For tm it affects all the branches and the possible retransmissions (in fact there are no retransmission for TCP/TLS). | ||
- | * onreply_route[0] | + | ==== $sipt(backward_call_indicator.charge_indicator) === |
+ | Returns the value of the charge indication of the backward call | ||
+ | indicator header in the ACM or COT message. Returns -1 if there is a | ||
+ | parsing error | ||
- | | + | Can return the following values: |
+ | | ||
+ | * 1 no charge | ||
+ | * 2 charge | ||
+ | * 3 spare | ||
- | * branch_route: | ||
- | * onsend_route: | + | ==== $sipt(redirection_info) / $sipt_redirection_info === |
+ | Returns the value of the Redirecting reason of the Call Diversion Information header from ISUP. | ||
+ | Returns -1 if there is a parsing error or if the Call Diversion Information is not present. | ||
- | Example of usage: | + | Can return the following values: |
- | route { | + | * 0 Unknown |
- | ... | + | * 1 User busy |
- | if (lookup()) { | + | * 2 no reply |
- | // | + | * 3 unconditional |
- | //to establish a new TCP connection | + | * 4 deflection during alerting |
- | | + | * 5 deflection immediate response |
- | | + | * 6 mobile subscriber not reachable |
- | } | + | |
- | ... | + | |
- | } | + | |
- | ==== set_forward_close ==== | ||
- | Try to close the connection | + | ==== $sipt(redirection_number) / $sipt_redirection_number === |
+ | Returns | ||
+ | Returns -1 if there is a parsing error or if the Redirection Number is not present. | ||
- | Note: Use with care as you might not receive | + | Example: |
+ | <code c> | ||
+ | # get the redirection number | ||
+ | $avp(s: | ||
+ | </ | ||
- | ==== set_reply_no_connect ==== | + | ==== $sipt(redirection_number.nai) / $sipt_redirection_number_nai |
+ | Returns the value of the Nature of Address Indicator of the Redirection Number. Returns -1 if there is a parsing error or if the Redirection Number is not present. | ||
- | Like set_forward_no_connect(), | + | Can return |
- | * normal request route: affects all replies sent back on the transaction | + | * 0 Spare |
+ | * 1 Subscriber Number | ||
+ | * 2 Unknown | ||
+ | * 3 National (significant) number | ||
+ | * 4 International use | ||
- | * onreply_route: | ||
- | * branch_route: | + | ==== $sipt(calling_party_number) === |
+ | Returns the value (Address signal) of the Calling Party for the IAM message. | ||
+ | Returns -1 if there is a parsing error or if the Calling Party Number is not present. | ||
- | * onsend_route: | ||
+ | ==== $sipt(called_party_number) === | ||
+ | Returns the value (Address signal) of the Called Party for the IAM message. | ||
+ | Returns -1 if there is a parsing error or if the Called Party Number is not present. | ||
- | Example of usage: | ||
- | route[4] { | + | ==== $sipt(sipt_redirection_information_reason) === |
- | // | + | Returns the value of the Redirection reason of the Redirection information header |
- | //to establish | + | Returns -1 if there is a parsing error or if the Redirection information is not present. |
- | set_reply_no_connect(); | + | |
- | // do authentication and call routing | + | |
- | | + | |
- | } | + | |
- | ==== set_reply_close ==== | ||
- | Like set_reply_no_connect, | + | ==== $sipt(sipt_redirection_information_original_reason) === |
+ | Returns | ||
+ | Returns -1 if there is a parsing error or if the Redirection information is not present. | ||
- | Example of usage: | ||
- | route { | + | ==== $sipt(redirecting_number.nai) === |
- | ... | + | Returns |
- | if (...caller-is-not-registered...) { | + | |
- | // reject unregistered client | + | |
- | // if request was received via TCP/TLS close the connection, as | + | |
- | // this may trigger re-registration | + | |
- | set_reply_close(); | + | |
- | sl_send_reply(" | + | |
- | exit; | + | |
- | } | + | |
- | | + | |
- | } | + | |
+ | Can return the following values: | ||
- | ==== setavpflag ==== | + | * 0 Spare |
+ | * 1 Subscriber Number (national use) | ||
+ | * 2 Unknown (national use) | ||
+ | * 3 National (significant) number | ||
+ | * 4 International use | ||
- | ==== setflag ==== | ||
- | Set a flag for current processed message. The value of the parameter can be in range of 0..31. The flags are used to mark the message | + | ==== $sipt(redirecting_number) === |
+ | Returns the value (Address signal) | ||
+ | Returns -1 if there is a parsing error or if the Redirecting Number is not present. | ||
- | For more see: https:// | ||
- | Example | + | ==== $sipt(original_called_number.nai) === |
+ | Returns the value of the Nature of Address Indicator of the Original Called Number. Returns -1 if there is a parsing error or if the Original Called Number is not present. | ||
- | setflag(3); | + | Can return the following values: |
- | ==== strip ==== | + | * 0 Spare |
+ | * 1 Subscriber Number (national use) | ||
+ | * 2 Unknown (national use) | ||
+ | * 3 National (significant) number | ||
+ | * 4 International use | ||
- | Strip the first N-th characters from username of R-URI (N is the value of the parameter). | ||
- | Example | + | ==== $sipt(original_called_number) === |
+ | Returns the value (Address signal) | ||
+ | Returns -1 if there is a parsing error or if the Original Called Number is not present. | ||
- | strip(3); | ||
- | ==== strip_tail ==== | + | ==== $sipt(generic_number.nai) |
+ | Returns the value of the Nature of Address Indicator of the Generic Number. Returns -1 if there is a parsing error or if the Generic Number is not present. | ||
- | Strip the last N-th characters from username of R-URI (N is the value of the parameter). | + | Can return |
- | Example of usage: | + | * 0 Spare |
+ | * 1 Subscriber Number (national use) | ||
+ | * 2 Unknown (national use) | ||
+ | * 3 National (significant) number | ||
+ | * 4 International use | ||
- | strip_tail(3); | ||
- | ==== udp_mtu_try_proto(proto) ==== | + | ==== $sipt(generic_number) === |
+ | Returns the value (Address signal) of the Generic Number for the IAM message. | ||
+ | Returns -1 if there is a parsing error or if the Generic Number is not present. | ||
- | * proto - TCP|TLS|SCTP|UDP - like udp_mtu_try_proto global parameter but works on a per packet basis and not globally. | ||
- | Example: | + | ===== $cfg(key) - Config File Attributes ===== |
- | < | + | Attributes related to configuration file. |
- | if($rd==" | + | |
- | udp_mtu_try_proto(SCTP); | + | |
- | </ | + | |
- | ==== userphone ==== | + | The key can be: |
- | Add " | + | * line - return the current line in config |
- | + | * name - return the name of current config file | |
- | ===== Custom Global Parameters ===== | + | * file - return the name of current config file |
- | + | * route - return | |
- | These are parameters that can be defined by the writer | + | |
- | + | ||
- | The definition of a custom global parameter must follow the pattern: | + | |
- | + | ||
- | < | + | |
- | group.variable = value desc " | + | |
- | + | ||
- | </ | + | |
- | + | ||
- | The value can be a quoted string or integer number. | + | |
Example: | Example: | ||
<code c> | <code c> | ||
- | pstn.gw_ip = "1.2.3.4" | + | send_reply("404", "Not found at line $cfg(line)"); |
</ | </ | ||
- | The custom global parameter can be accessed inside a routing block via: | + | ===== $dns(pvid=> |
- | < | + | This variable stores the DNS result details after a call of dns_query(hostname, pvid) function from ipops module. |
- | $sel(cfg_get.group.variable) | + | |
- | </ | + | |
- | Example: | + | * pvid can be any string |
+ | * key can be: | ||
+ | * count - number of addresses | ||
+ | * ipv4 - set to 1 if at least one ipv4 address (otherwise 0) | ||
+ | * ipv6 - set to 1 if at least one ipv6 address (otherwise 0) | ||
+ | * addr[index] - the address as string from position index in the list (0 based indexing) | ||
+ | * type[index] - the type of address from position index in the list (0 based indexing), the value is 4 for ipv4 and 6 for ipv6 | ||
- | <code c> | + | The index can be an integer |
- | $ru = " | + | |
- | </ | + | |
- | + | ||
- | **Note:** Some words cannot | + | |
- | + | ||
- | ===== 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. | + | |
<code c> | <code c> | ||
- | route_block_id[NAME] { | + | if(dns_query(" |
- | | + | { |
+ | xlog(" number of addresses: $dns(xyz=> | ||
+ | xlog(" ipv4 address found: $dns(xyz=> | ||
+ | xlog(" ipv6 address found: $dns(xyz=> | ||
+ | $var(i) = 0; | ||
+ | while($var(i)& | ||
+ | xlog(" #[$var(i)] type ($dns(xyz=> | ||
+ | " | ||
+ | $var(i) = $var(i) + 1; | ||
+ | } | ||
} | } | ||
</ | </ | ||
- | The name can be any alphanumeric string, with specific routing blocks enforcing a particular format. | + | ===== $HN(key) - Hostname details ===== |
- | <fc # | + | Give local hostname details |
- | Route blocks | + | The key can be: |
- | + | * n - the hostname | |
- | There can be so called sub-route blocks, which can be invoked from another route blocks, like a function. Invocation is done with ' | + | * f - the fullname |
- | + | * d - the domain | |
- | Example: | + | * i - the ip address |
<code c> | <code c> | ||
- | request_route{ | + | xlog("local hostanme is $HN(n)\n"); |
- | ... | + | |
- | route("test"); | + | |
- | ... | + | |
- | } | + | |
- | + | ||
- | route[" | + | |
- | ... | + | |
- | } | + | |
</ | </ | ||
- | ==== request_route | + | ===== $RANDOM - Random number ===== |
- | Request routing block - is executed for each SIP request. | + | Returns a random value from the [0 - 2^31) range. |
- | It contains a set of actions to be executed for SIP requests received from the network. It is the equivalent of *main()* function for handling the SIP requests. | + | (Part of the cfgutils module) |
- | + | ||
- | <fc # | + | |
- | + | ||
- | The implicit action after execution | + | |
- | + | ||
- | Example of usage: | + | |
<code c> | <code c> | ||
- | request_route { | + | if (rand_event()) { |
- | if(is_method(" | + | $avp(i:10) = ($RANDOM / 16777216); # 2^24 |
- | # send reply for each options request | + | if ($avp(i:10) < 10) { |
- | sl_send_reply(" | + | $avp(i:10) = 10; |
- | exit(); | + | |
- | } | + | |
- | | + | |
- | } | + | |
- | route[FWD] { | + | |
- | # forward according to uri | + | |
- | | + | |
- | } | + | |
- | </ | + | |
- | + | ||
- | ==== route ==== | + | |
- | + | ||
- | This block is used to define ' | + | |
- | + | ||
- | The definition of the sub-route block follows the general rules, with a name in between square brackets and actions between curly braces. A sub-route can return an integer value back to the routing block that executed it. The return code can be retrieved via $rc variables. | + | |
- | + | ||
- | Evaluation of the return of a subroute is done with following rules: | + | |
- | * negative value is evaluated as false | + | |
- | * 0 - is interpreted as **exit** | + | |
- | * positive value is evaluated as true | + | |
- | + | ||
- | + | ||
- | <code c> | + | |
- | request_route { | + | |
- | if(route(POSITIVE)) { | + | |
- | xlog(" | + | |
} | } | ||
- | | + | |
- | xlog(" | + | |
- | | + | |
- | if( route(ZERO)) { | + | }; |
- | xlog("this log message does not appear\n"); | + | # normal message processing follows |
- | | + | |
- | } | + | |
- | + | ||
- | route[POSITIVE] { | + | |
- | return 10; | + | |
- | } | + | |
- | + | ||
- | route[NEGATIVE] { | + | |
- | return -8; | + | |
- | } | + | |
- | + | ||
- | route[ZERO] { | + | |
- | return 0; | + | |
- | } | + | |
</ | </ | ||
- | A sub-route can execute another sub-route. There is a limit to the number of recursive levels, avoiding ending up in infinite loops -- see **max_recursive_level** global parameter. | + | ===== JSONRPCS Variables ===== |
- | The sub-route blocks allow to make the configuration file modular, simplifying the logic and helping to avoid duplication of actions. | + | ==== $jsonrpl(key) - JSONRPC Reply ==== |
- | ==== branch_route | + | |
- | Request' | + | This variable gives access |
- | Example of usage: | + | The key can be: |
+ | * code - code for the JSONRPC response | ||
+ | * text - text of the code for the JSONRPC response | ||
+ | * body - the body of the JSONRPC response | ||
- | <code c> | + | ===== $lsock(expr) ===== |
- | request_route { | + | |
- | lookup(" | + | |
- | t_on_branch(" | + | |
- | if(!t_relay()) { | + | |
- | sl_send_reply(" | + | |
- | } | + | |
- | } | + | |
- | branch_route[OUT] { | + | |
- | if(uri=~" | + | |
- | # discard branches that go to 10.10.10.10 | + | |
- | drop(); | + | |
- | } | + | |
- | } | + | |
- | </ | + | |
- | ==== failure_route ==== | + | Get attributes for listen sockets (from corex module). |
- | Failed transaction routing block. It contains a set of actions to be taken each transaction that received only negative replies (>=300) for all branches. | + | The **expr** is an expression specifying what to match and return, the format |
- | Note that in ' | + | < |
- | + | matchid/ | |
- | + | ||
- | Example of usage: | + | |
- | + | ||
- | < | + | |
- | | + | |
- | lookup(" | + | |
- | t_on_failure(" | + | |
- | if(!t_relay()) { | + | |
- | sl_send_reply(" | + | |
- | } | + | |
- | } | + | |
- | failure_route[TOVOICEMAIL] { | + | |
- | if(is_method(" | + | |
- | # call failed - relay to voice mail | + | |
- | | + | |
- | } | + | |
- | } | + | |
</ | </ | ||
- | ==== reply_route ==== | + | The **expr** can contain variables that are evaluated before parsing the expression. |
- | Main SIP response (reply) handling block - it contains a set of actions to be executed for SIP replies. It is executed for all replies received from the network. | + | The **matchid** can be: |
- | It does not have a name and it is executed by the core, before any other module handling the SIP reply. It is triggered only by SIP replies received | + | * n - match on name |
+ | * l - match on listen address | ||
- | There is no network route that can be enforced for a SIP reply - it is sent based on Via header, according | + | The **value** specifies what to match with. |
- | This routing block is optional, if missing, the SIP reply is sent to the address in 2nd Via header. | + | The **field** can be (only first character matches): |
- | One can decide to drop a SIP reply by using **drop** action. | + | |
+ | | ||
+ | | ||
+ | | ||
Example: | Example: | ||
- | < | + | < |
- | reply_route { | + | listen=udp: |
- | if(status=="128" | + | ... |
- | drop; | + | xinfo("$lsock(n/ |
- | } | + | xinfo(" |
- | } | + | $var(s0) = " |
+ | xinfo(" | ||
</ | </ | ||
- | <fc # | + | ===== Evrexec Module ===== |
- | ==== onreply_route | + | ==== $evr(key) |
+ | evrexec attributes: | ||
- | SIP reply routing block executed by **tm** module. It contains a set of actions to be taken for SIP replies in the contect of an active transaction. | + | |
+ | | ||
+ | | ||
+ | | ||
- | The ' | ||
- | Core ' | + | ===== Presence Module ===== |
- | <code c> | + | ==== $subs(key) - Subscription Attributes ==== |
- | request_route { | + | |
- | lookup(" | + | |
- | t_on_reply(" | + | |
- | if(!t_relay()) { | + | |
- | sl_send_reply(" | + | |
- | } | + | |
- | } | + | |
- | reply_route { | + | This variable gives access to attributes of the current subscription. The variable has to be used after executing // |
- | if(!t_check_trans()) { | + | |
- | drop; | + | |
- | } | + | |
- | } | + | |
- | onreply_route[LOGRPL] { | + | The key can be: |
- | | + | * uri - subscription URI. Useful in particular for subscriptions within the dialog, when the request URI in SUBSCRIBE is the Contact address from the initial subscription. |
- | | + | |
- | } | + | |
- | } | + | |
- | </ | + | |
- | ==== onsend_route ==== | + | |
- | The route is executed in when a SIP request is sent out. Only a limited number of commands are allowed (drop, if + all the checks, msg flag manipulations, | + | ===== Registrar Module ===== |
- | In this route the final destination of the message is available and can be checked | + | ==== $ulc(profile=> |
- | This route is executed only when forwarding requests - it is not executed for replies, retransmissions, | + | Access the attributes of contact addresses stored in ' |
- | Example: | + | It must be used after a call of “reg_fetch_contacts()”. |
- | <code c> | + | ===== Sipcapture Module ===== |
- | onsend_route { | + | |
- | if(to_ip==1.2.3.4 && !isflagset(12)){ | + | |
- | log(1, " | + | |
- | drop; | + | |
- | } | + | |
- | } | + | |
- | </ | + | |
- | * snd_ip, snd_port - behave like src_ip/ | + | ==== $hep(key) - HEP Packet Attributes ==== |
- | * to_ip, to_port - like above, but contain the ip/port the message will be sent to (not to be confused with dst_ip/ | + | |
- | * snd_proto, snd_af | + | |
- | * msg:len - when used in an onsend_route, | + | |
- | ==== event_route ==== | + | The key refers to HEP packet header values: |
- | Generic type of route executed when specific events happen. | + | * version - HEP version |
+ | * src_ip - source IP address | ||
+ | * dst_ip - destination IP address | ||
+ | * 0x000 - HEP attribute 0x000 | ||
+ | * 0x999 - HEP attribute 0x999 | ||
- | Prototype: event_route[groupid: | + | ===== Phonenum Variables ===== |
- | * groupid - should be the name of the module that triggers the event | + | |
- | * eventid - some meaningful short text describing the event | + | |
- | === Core Event Routes === | + | $phn(rid=>key) - rid is an identifier for this query result; it is designated by the second parameter of phonenum_match(). The key can be one of the following: |
- | Implementations: | + | * number - phone number that is matched |
- | + | * valid - 1 if the matched number has a valid result; 0 otherwise | |
- | * **event_route[core: | + | * normalized - normalized phone number |
- | * note that due to forking, other sip workers can get faster to listening for sip traffic | + | |
+ | | ||
+ | | ||
+ | * error - error string if phone number matching fails. | ||
<code c> | <code c> | ||
- | event_route[core: | + | if(phonenum_match(" |
- | xlog(" | + | if($phn(src=>valid)==1) |
- | } | + | xlog("number normalized |
- | </ | + | } else { |
- | + | xlog("number normalization error: $phn(src=> | |
- | * **event_route[core: | + | |
- | | + | |
- | * if drop is executed, the received message is no longer processed | + | |
- | + | ||
- | <code c> | + | |
- | event_route[core: | + | |
- | xlog("rcv on $rcv(af)/ | + | |
- | if($rcv(srcip) == " | + | |
- | | + | |
- | | + | |
- | } | + | |
- | </ | + | |
- | + | ||
- | * **event_route[core: | + | |
- | * if drop is used, then the message is not processed further with request_route or reply_route in the same process. This can be useful together with sworker module which can delegate the processing to another worker. | + | |
- | + | ||
- | <code c> | + | |
- | async_workers_group="name=reg; | + | |
- | ... | + | |
- | event_route[core:pre-routing] { | + | |
- | xinfo(" | + | |
- | if(is_method(" | + | |
- | # delegate processing of REGISTERs to a special group of workers | + | |
- | if(sworker_task(" | + | |
- | drop; | + | |
- | } | + | |
} | } | ||
} | } | ||
</ | </ | ||
- | * ** event_route[core: | + | ===== SecSIPId Variables ===== |
- | * note that the SIP message is broken in this case, but it gets access to source and local socket addresses (ip, port, proto, af) as well as the whole message buffer and its size | + | |
- | <code c> | + | $secsipid(key) - return attributes of secsipid module. |
- | event_route[core: | + | |
- | xlog("got an parsing error from $si:$sp, message $mb\n"); | + | |
- | } | + | |
- | </ | + | The key can be: |
- | === Module Event Routes === | + | * val - the value of Identity computed by secsipid_build_identity(...) |
+ | * ret - the return code of the libsecsipid function used by secsipid_build_identity(...) | ||
- | Here are only a few examples, to see if a module exports event_route blocks and when they are executed, check the readme of the module. | + | Example: |
- | |||
- | * **event_route[htable: | ||
<code c> | <code c> | ||
- | modparam("htable", "htable", "a=> | + | if(secsipid_build_identity("$fU", "$rU", "A", "" |
- | + | "https://kamailio.org/stir/$rd/cert.pem", "/secsipid/$rd/key.pem")) { | |
- | event_route[htable: | + | xinfo("identity value: $secsipid(val)\n"); |
- | $sht(a=> | + | |
- | $sht(a=> | + | |
- | } | + | |
- | + | ||
- | request_route { | + | |
- | if(is_method("INVITE") && !has_totag()) | + | |
- | { | + | |
- | switch($rd) { | + | |
- | case " | + | |
- | | + | |
- | | + | |
- | $sht(a=> | + | |
- | unlock("calls-to:: | + | |
- | if($sht(a=> | + | |
- | | + | |
- | sl_send_reply("500", "To many calls to .10" | + | |
- | | + | |
- | } | + | |
- | break; | + | |
- | ... | + | |
- | } | + | |
- | } | + | |
- | } | + | |
- | </ | + | |
- | * **event_route [tm:local-request]** - executed on locally generated requests. | + | |
- | <code c> | + | |
- | event_route [tm: | + | |
- | xlog(" | + | |
- | t_set_fr(10000, | + | |
} | } | ||
</ | </ | ||
+ | ===== sdpops module variables ===== | ||
- | * **event_route [tm:branch-failure]** - executed on all failure responses. | + | * $sdp(body) |
- | <code c> | + | |
- | request_route { | + | |
- | | + | |
- | t_on_branch_failure(" | + | |
- | t_relay(); | + | |
- | } | + | |
- | event_route[tm: | + | ===== $sruid |
- | xlog(" | + | |
- | if (t_check_status(" | + | |
- | unregister(" | + | |
- | if (t_next_contact_flow()) { | + | |
- | t_relay(); | + | |
- | } | + | |
- | } | + | |
- | } | + | |
- | </ | + | * $sruid - return unique ID generated internally Kamailio |
- | ===== Script Statements | + | ===== $ltt(key) - Local To-Tag |
- | ==== if ==== | + | $ltt(key) |
- | IF-ELSE statement | + | |
- | Prototype: | + | * $ltt(s) - the to-tag used in stateless replies |
+ | * $ltt(t) - the to-tag used in transaction stateful replies (transaction has to be created at that time, eg., by t_newtran() or in a branch/ | ||
+ | * $ltt(x) - $ltt(t) if the transaction was created already, otherwise $ltt(s) | ||
- | < | + | ===== $via0(attr) - Via[0] Attributes ===== |
- | if(expr) { | + | |
- | | + | |
- | } else { | + | |
- | | + | |
- | } | + | |
- | </ | + | |
- | The ' | + | $via0(attr) - attributes of first Via header. |
- | The logical operators that can be used in ' | + | The attr can be: |
- | < | + | * host - host part (string) |
- | | + | |
- | | + | |
- | | + | |
- | !~ regular expression not-matching (NOT PORTED from Kamailio 1.x, use '!(x =~ y)') | + | |
- | | + | |
- | | + | |
- | | + | |
- | | + | |
- | && | + | |
- | || logical OR | + | |
- | ! | + | |
- | </ | + | |
- | Example of usage: | + | ===== $via1(attr) - Second Via Attributes ===== |
- | if(is_method(" | + | $via1(attr) - attributes of second Via header. The attr can be the same as for $via0(attr). |
- | { | + | |
- | log(" | + | |
- | } else { | + | |
- | log("this sip message is not an invite\n" | + | |
- | } | + | |
- | See also the FAQ for how the function return code is evaluated: | + | ===== $viaZ(attr) - Last Via Attributes ===== |
- | * https://www.kamailio.org/ | + | $viaZ(attr) - attributes of last Via header. The attr can be the same as for $via0(attr). |
- | ==== switch | + | ===== tcpops module variable ===== |
- | SWITCH statement | + | $tcp(key) |
- | IMPORTANT NOTE: ' | + | The key can be: |
+ | * c_si - connection source ip (useful with HAProxy connections) | ||
+ | * c_sp - connection source port (useful with HAProxy connections) | ||
+ | * conid - connection id | ||
- | Example of usage: | + | ===== pv_headers module variables ===== |
- | < | + | |
- | route { | + | |
- | route(1); | + | |
- | switch($retcode) | + | |
- | { | + | |
- | case -1: | + | |
- | log(" | + | |
- | break; | + | |
- | case 1: | + | |
- | log(" | + | |
- | break; | + | |
- | case 2: | + | |
- | case 3: | + | |
- | log(" | + | |
- | break; | + | |
- | default: | + | |
- | log(" | + | |
- | } | + | |
- | # switch of R-URI username | + | * $x_hdr(// |
- | switch($rU) | + | * $x_fu: Full From header |
- | { | + | * $x_fU: From header user part |
- | case " | + | * $x_fd: From header domain part |
- | | + | * $x_fn: From header Display Name part |
- | | + | * $x_ft: From header Tag |
- | case " | + | * $x_tu: Full To header |
- | | + | * $x_tU: To header user part |
- | | + | * $x_td: To header domain part |
- | case " | + | * $x_tn: To header Display Name part |
- | case " | + | * $x_tt: To header Tag |
- | | + | * $x_rs: |
- | | + | * $x_rr: |
- | default: | + | |
- | | + | |
- | } | + | |
- | } | + | |
- | route[1]{ | + | ===== $C(xy) - Foreground and background colors ===== |
- | if(is_method(" | + | |
- | { | + | |
- | return(-1); | + | |
- | }; | + | |
- | if(is_method(" | + | |
- | return(1); | + | |
- | } | + | |
- | if(is_method(" | + | |
- | return(2); | + | |
- | } | + | |
- | if(is_method(" | + | |
- | return(3); | + | |
- | } | + | |
- | return(-2); | + | |
- | } | + | |
- | </ | + | |
- | NOTE: take care while using ' | + | $C(xy) - reference to an escape sequence. “x” represents |
+ | Colors could be: | ||
- | ==== while ==== | + | * x : default color of the terminal |
+ | * s : Black | ||
+ | * r : Red | ||
+ | * g : Green | ||
+ | * y : Yellow | ||
+ | * b : Blue | ||
+ | * p : Purple | ||
+ | * c : Cyan | ||
+ | * w : White | ||
- | while statement | ||
- | Example of usage: | + | ===== $K(key) - Kamailio Constants ===== |
- | + | ||
- | $var(i) | + | |
- | while($var(i) < 10) | + | |
- | { | + | |
- | xlog(" | + | |
- | $var(i) = $var(i) + 1; | + | |
- | } | + | |
- | ===== Script Operations ===== | + | $K(key) - return the numeric values corresponding to Kamailio configuration constants. |
- | Assignments together with string and arithmetic operations | + | The key can be: |
- | ==== Assignment ==== | + | |
- | Assignments can be done like in C, via ' | + | |
- | | + | * IPv6 - return AF_INET6 |
- | * script variables ($var(...)) - to set the value of a script variable | + | * UDP - return PROTO_UDP |
- | * shared variables ($shv(...)) | + | * TCP - return PROTO_TCP |
- | * $ru - to set R-URI | + | * TLS - return PROTO_TLS |
- | * $rd - to set domain part of R-URI | + | * SCTP - return PROTO_SCTP |
- | * $rU - to set user part of R-URI | + | * WS - return PROTO_WS |
- | * $rp - to set the port of R-URI | + | * WSS - return PROTO_WSS |
- | * $du - to set dst URI | + | |
- | * $fs - to set send socket | + | |
- | * $br - to set branch | + | |
- | * $mf - to set message flags value | + | |
- | * $sf - to set script flags value | + | |
- | * $bf - to set branch flags value | + | |
- | < | ||
- | $var(a) = 123; | ||
- | </ | ||
- | For avp's there a way to remove all values and assign a single value in one statement (in other words, delete existing AVPs with same name, add a new one with the right side value). This replaces the := assignment operator from kamailio < 3.0. | + | < |
- | < | + | xinfo("proto UDP numeric id: $K(UDP)\n"); |
- | $(avp(i:3)[*]) = 123; | + | |
- | $(avp(i:3)[*]) = $null; | + | |
</ | </ | ||
+ | ===== Examples ===== | ||
- | ==== String Operations ==== | ||
- | For strings, ' | ||
- | < | + | A few examples of usage. |
- | $var(a) = " | + | |
- | $var(b) = " | + | |
- | </ | + | |
- | ==== Arithmetic Operations ==== | + | |
- | For numbers, one can use: | + | Example 1. Pseudo-variables usage |
- | * + : plus | + | <code c> |
- | * - : minus | + | ... |
- | * / : divide | + | avp_aliases=" |
- | * * : multiply | + | ... |
- | * % : modulo (Kamailio uses ' | + | route { |
- | * | : bitwise OR | + | ... |
- | * & : bitwise AND | + | |
- | * ^ : bitwise XOR | + | |
- | * ~ : bitwise NOT | + | |
- | * < | + | ... |
- | * < | + | } |
- | + | ... | |
- | + | ||
- | Example: | + | |
- | + | ||
- | < | + | |
- | $var(a) = 4 + ( 7 & ( ~2 ) ); | + | |
</ | </ | ||
- | NOTE: to ensure the priority of operands in expression evaluations do use __parenthesis__. | + | ==== Request-URI and Destination-URI parsing ==== |
- | Arithmetic expressions can be used in condition expressions. | + | Following are some examples how RURI and DURI are parsed, for SIP-URIs, tel-URIs and Service-URNs: |
< | < | ||
- | if( $var(a) & 4 ) | + | === Request URI contains SIP URI === |
- | log("var a has third bit set\n"); | + | $ru = " |
- | </code> | + | $rz = "sip" |
+ | $rU = "<null>" | ||
+ | $rd = " | ||
+ | $rp = " | ||
+ | $rP = " | ||
- | ===== Operators | + | === Request URI contains SIP URI === |
+ | $ru = " | ||
+ | $rz = " | ||
+ | $rU = " | ||
+ | $rd = " | ||
+ | $rp = " | ||
+ | $rP = " | ||
- | - type casts operators: (int), (str). | + | === Request URI contains service URN === |
- | | + | $ru = "urn:service:sos.fire" |
- | | + | |
+ | | ||
+ | $rd = " | ||
+ | $rp = " | ||
+ | $rP = " | ||
- | Note: The names are not yet final (use them at your own risk). Future version might use ==/!= only for ints (ieq/ine) and eq/ne for strings (under debate). They are almost equivalent to == or !=, but they force the conversion of their operands (eq to string and ieq to int), allowing among other things better type checking on startup and more optimizations. | + | === Request URI contains tel: URI === |
- | + | $ru = "tel:+1-201-555-0123" | |
- | Non equiv. examples: | + | |
- | + | | |
- | 0 == "" (true) is not equivalent to 0 eq "" | + | $rd = "<null>" |
- | + | | |
- | " | + | |
- | + | ||
- | Note: internally == and != are converted on startup to eq/ | + | |
- | + | ||
- | - Kamailio tries to guess what the user wanted when operators that support multiple types are used on different typed operands. In general convert the right operand to the type of the left operand and then perform the operation. Exception: the left operand is undef. This applies to the following operators: +, == and !=. | + | |
- | | + | |
- | For +: undef + expr -> undef is converted to string => "" | + | |
- | For == and !=: undef == expr -> undef is converted to type_of expr. | + | |
- | If expr is undef, then undef == undef is true (internally is converted | + | |
- | to string). | + | |
- | + | ||
- | | + | |
- | int(undef)==0, | + | |
- | str(undef)=="", str(123)==" | + | |
- | + | ||
- | | + | |
- | defined expr - returns true if expr is defined, and false if not. | + | |
- | Note: only a standalone avp or pvar can be | + | |
- | | + | |
- | strlen(expr) | + | |
- | strempty(expr) - returns true if expr evaluates to the empty | + | |
- | | + | |
- | | + | |
- | + | ||
- | ===== 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**: | + | |
- | + | ||
- | <code> | + | |
- | # kamailio -h | + | |
- | + | ||
- | version: kamailio 5.4.0-dev4 (x86_64/ | + | |
- | Usage: kamailio [options] | + | |
- | Options: | + | |
- | -a mode Auto aliases mode: enable with yes or on, | + | |
- | disable with no or off | + | |
- | --alias=val | + | |
- | (like for ' | + | |
- | -A define | + | |
- | -A ' | + | |
- | -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 | + | |
- | -D | + | |
- | -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: / | + | |
- | -g gid | + | |
- | -G file Create a pgid file | + | |
- | -h This help message | + | |
- | --help | + | |
- | -I Print more internal compile flags and options | + | |
- | -K Turn on " | + | |
- | -l address | + | |
- | mean listening on more addresses). The address format is | + | |
- | [proto: | + | |
- | where proto=udp|tcp|tls|sctp, | + | |
- | addr_lst= addr|(addr, addr_lst), | + | |
- | addr=host|ip_address|interface_name and | + | |
- | advaddr=addr[: | + | |
- | E.g: -l localhost, -l udp: | + | |
- | -l udp: | + | |
- | -l "sctp: | + | |
- | 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: / | + | |
- | -m nr Size of shared memory allocated in Megabytes | + | |
- | --modparam=modname: | + | |
- | type has to be ' | + | |
- | example: --modparam=corex: | + | |
- | -M nr Size of private memory allocated, in Megabytes | + | |
- | -n processes Number of child processes to fork per interface | + | |
- | (default: 8) | + | |
- | -N | + | |
- | -O nr Script optimization level (debugging option) | + | |
- | -P file Create a pid file | + | |
- | -Q | + | |
- | -r Use dns to check if is necessary to add a " | + | |
- | 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 | + | |
- | -t dir | + | |
- | -T | + | |
- | -u uid | + | |
- | -v | + | |
- | --version | + | |
- | -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 | + | |
- | -w dir | + | |
- | -W type poll method (depending on support in OS, it can be: poll, | + | |
- | epoll_lt, epoll_et, sigio_rt, select, kqueue, / | + | |
- | </ | + | |
- | + | ||
- | ==== 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: | + | |
- | + | ||
- | The name of the log engine can be: | + | |
- | + | ||
- | | + | |
- | * 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 | + | |
- | * **M** - strip EOL (' | + | |
- | * **N** - do not add EOL at the end of JSON document | + | |
- | + | ||
- | Example of JSON logs when running Kamailio with " | + | |
- | + | ||
- | < | + | |
- | { " | + | |
- | { " | + | === Request URI contains tel: URI with phone-context === |
+ | $ru = "tel:7042; | ||
+ | $rz = "tel" | ||
+ | $rU = "7042" | ||
+ | $rd = "< | ||
+ | $rp = "5060" | ||
+ | $rP = "UDP" | ||
+ | === Destination URI (must be a SIP(S) URI) === | ||
+ | $du = " | ||
+ | $dd = " | ||
+ | $dp = " | ||
+ | $dP = " | ||
</ | </ |
cookbooks/devel/pseudovariables.1619508875.txt.gz · Last modified: 2021/04/27 07:34 by miconda