User Tools

Site Tools


cookbooks:devel:pseudovariables

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Next revision Both sides next revision
cookbooks:devel:pseudovariables [2021/04/27 09:34]
miconda
cookbooks:devel:pseudovariables [2021/09/10 11:26]
mish_gun Added new PVs for SIPT module
Line 1: Line 1:
-====== Core Cookbook ======+====== Pseudo-Variables ======
  
 Version: Kamailio SIP Server v5.6.x (devel) Version: Kamailio SIP Server v5.6.x (devel)
  
-===== Overview =====+{{ :cookbooks:devel:pseudovariables.png?200|}}
  
-This tutorial collects the functions and parameters exported by Kamailio core to configuration file.+===== Introduction =====
  
-**Note:** The parameters on this page are **NOT** in alphabetical order.+The term “pseudo-variable” is used for special tokens that can be given as parameters to different script functions and they will be replaced with a value before the execution of the function.
  
-===== Structure =====+The beginning of a “pseudo-variable” is marked by the character “$”. If you want to have the character “$” just double it “$$”.
  
-The structure of the kamailio.cfg can be seen as three parts:+There is a set of predefined pseudo-variables, which have the name composed from one or more characters, and special pseudo-variables that are references to dynamic fields (AVP and Headers).
  
-  global parameters +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).
-  modules settings +
-  routing blocks+
  
-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 filecontaining the parameters for the core of kamailio and custom global parameters.+Pseudo-variables can be used with many modulesamong them:
  
-Typically this is formed by directives of the form:+  * acc 
 +  * avpops 
 +  * htable 
 +  * http_async_client 
 +  * textops 
 +  * uac 
 +  * xlog 
  
-<code> +===== The list of pseudo-variables =====
-name=value +
-</code>+
  
-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:ipaddress:port**.+==== $$ - 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+<code> 
 +    $var(x) "sip:" + $rU + "@" + $fd;
  
-alias="sip.mydomain.com"+    # is equivalent of:
  
-listen=udp:10.0.0.10:5060+    $var(x) $_s(sip:$rU@$fd);
 </code> </code>
  
-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's P-Asserted-Identity header (see RFC 3325)
-alias="sip.mydomain.com"; +
-</code>+
  
-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 "dns".+==== $adu - Auth Digest URI ====
  
-<code c> +**$adu** - URI from Authorization or Proxy-Authorization headerThis URI is used when calculating the HTTP Digest Response.
-listen=tcp:127.0.0.1:5060 advertise "sip.dns.example.com":5060 +
-</code> +
-==== 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 **loadmodule** and **modparam**. In the default configuration file starts with the line setting the path to modules (the assignment to **mpath** core parameter.+**$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 "debugger.so" +
-... +
-modparam("debugger", "cfgtrace", 1) +
-</code>+
  
-==== 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("new branch [$T_branch_idx] to $ru\n"); +
-    route(NATMANAGE); +
-+
-</code>+
  
-===== Generic Elements =====+==== $Au - Acc username and realm/domain ====
  
-==== 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 like in shell) or **/ /** (double forward slash - like in C++/Java).+==== $AU Acc username ====
  
-Block comments start with /* (forward slash and asteriskand are ended by */ (sterisk and forward slash) (like in C, C++, Java).+**$AU** - username for accounting purposes. It's a selective pseudo variable (inherited from acc module). It returns the auth username ($auif exists or From user ($fUotherwise. 
 +==== $branch(name) - Branch attributes ====
  
-Example:+**$branch(name)** - reference to attribute 'name' of a branch
  
-<code> +This pseudo variable gives you access to the "additional branches" only, not to the "main branch". E.g. if there are 3 clients registered for the same AoR, after lookup() you will have one contact in the "main branch" and two "additional branches". Using $branch() you can access the additional branches, the main branch can be accessed using $ru and $du. (Note: In branch_routes there is no distinction between the main and the additional branches - the branch_route will be called once for each one of them.)
-  # this is a line comment +
-   +
-  // this is another line comment +
-   +
-  /* this +
-     is +
-     a +
-     block +
-     comment */ +
-</code>+
  
-Important: be aware of preprocessor directives that start with **#!** (hash/pound and exclamation) - those are no longer line comments.+The 'name' can be:
  
-==== Values ==== +  * uri - return uri of the branch 
- +  * dst_uri - return destination uri (next hop address) 
-There are three types of values: +  * path - return the path vector for the branch 
- +  * q - return the q value of the branch 
-  * integer numbers of 32bit size +  * send_socket - return the socket to be used to send the branch 
-  * boolean aliases to 1 (true, on, yes) or 0 (false, off, no) +  * count return the number of the branches 
-  * string tokens enclosed in between double or single quotes+  * 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)<$branch(count)) 
-  "this is a string value+
-  'this is another string value' +   xlog("$(branch(uri)[$var(i)])\n"); 
- +   $var(i) = $var(i) + 1; 
-// next is a boolean +}
- +
-  yes +
- +
-// next is an integer +
- +
-  64 +
 </code> </code>
  
-==== Identifiers ==== +Starting with 3.1.0you can assign value per attributeIndex 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 examplethe identifiers are the core parameters and functions, module functions, core keywords and statements. +
- +
-Example:+
  
 <code c> <code c>
-return+$(branch(attr)[index]) = value;
 </code> </code>
  
-==== 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 $null to uri attribute will drop the branch, for the rest of attributes will just set the value to null.
- +
-You can see the list with available variables in the Pseudo-Variables Cookbook. +
- +
-Example:+
  
 <code c> <code c>
-$var(x) = $rU + "@" + $fd;+$(branch(uri)[2]) = "sip:test@kamailio.org;transport=sctp";
 </code> </code>
  
-==== 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's first branch ====
  
-Example:+**$br** - reference to request's first branch
  
-<code c> +<fc #0000ff>It is R/W variableyou can assign values to it directly in configuration file (will add a new branch).</fc>
-  sl_send_reply("404""Not found")+
-  exit; +
-</code>+
  
-==== Expressions ====+==== $bR - Request's all branches ====
  
-An expression is an association group of statements, variables, functions and operators.+**$bR** - reference to request's all branches
  
-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 #0000ff>It is R/W variable (you can assign values to it directly in configuration file)</fc> 
 +==== $bF - Branch flags ====
  
-"sip:"$var(prefix+ $rU + "@" + $rd +**$bF** - reference to branch flags of branch 0 (RURI- hexa output
-</code>+
  
-===== Config Pre-Processor Directives =====+<fc #0000ff>It is R/W variable (you can assign values to it directly in configuration file)</fc>
  
-==== include_file ====+==== $bs - Body size ====
  
-<code> +**$bs** - body size
-   include_file "path_to_file" +
-</code>+
  
-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 of the file that includes it. There is no restriction where include can be used or what can contain any part of config file is ok. There is a limit of maximum 10 includes in depth, otherwise you can use as many includes as you want. Reporting of the cfg file syntax errors prints now the file name for easier troubleshooting. +**$ci** - reference to body of call-id header
  
-If the included file is not found, the config file parser throws error. You can find this error message at the logging destination, usually in the system logging (file).+==== $cl - Content-Length ====
  
-You can use also the syntax **#!include_file** or **!!include_file**.+**$cl** - reference to body of content-length header
  
-Example of usage: +==== $cnt(pv) - Count number of pvs ====
  
-<code c> +**$cnt(avp)** - return the number of avps
-route { +
-    ... +
-    include_file "/sr/checks.cfg" +
-    ... +
-+
- +
---- /sr/checks.cfg --- +
- +
-   if (!mf_process_maxfwd_header("10")) { +
-       sl_send_reply("483","Too Many Hops"); +
-       exit; +
-   } +
- +
---- +
-</code> +
- +
-==== import_file ==== +
- +
-<code> +
-   import_file "path_to_file" +
-</code> +
- +
-Similar to **include_file**, but does not throw error if the included file is not found. +
- +
-==== define ==== +
- +
-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** - define a keyword +
-  * **#!define NAME VALUE** - define a keyword with value +
-  * **#!ifdef NAME** - check if a keyword is defined +
-  * **#!ifndef** - check if a keyword is not defined +
-  * **#!else** - switch to false branch of ifdef/ifndef region +
-  * **#!endif** - end ifdef/ifndef region +
-  * **#!trydef** - add a define if not already defined +
-  * **#!redefine** - force redefinition even if already defined +
- +
-Predefined keywords: +
-  * **KAMAILIO_X[_Y[_Z]]** - Kamailio versions +
-  * **MOD_X** - when module X has been loaded +
-See 'kamctl core.ppdefines_full' for full list. +
- +
-Among benefits: +
-  * easy way to enable/disable features (e.g., see default cfg -- controlling support of nat traversal, presence, etc...) +
-  * switch control for parts where conditional statements were not possible (e.g., global parameters, module settings) +
-  * 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, say testbed and production, controlled just by one define to switch between the two modes:+
  
 <code c> <code c>
-... +xlog("$$avp(x) fount $cnt($avp(x)) times\n");
- +
-#!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("acc|auth_db|usrloc", "db_url", +
- "mysql://kamailio:kamailiorw@localhost/kamailio_testbed"+
-#!else +
-modparam("acc|auth_db|usrloc", "db_url", +
- "mysql://kamailio:kamailiorw@10.0.0.2/kamailio_production"+
-#!endif +
- +
-... +
- +
-#!ifdef TESTBED_MODE +
-route[DEBUG] { +
-  xlog("SCRIPT: SIP $rm from: $fu to: $ru - srcip: $si"\n); +
-+
-#!endif +
- +
-... +
- +
-route { +
-#!ifdef TESTBED_MODE +
-  route(DEBUG); +
-#!endif +
- +
-  ... +
-+
- +
-...+
 </code> </code>
 +==== $conid - TCP Connection ID ====
  
-  you can define values for IDs+**$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 "xyz" +
-</code>+
  
-  defined IDs are replaced at startup, during config parsing, e.g.,:+**$cs** - reference to the sequence number in the CSeq headerThe method in the CSeq header is identical to the request methodthus use $rm to get the method (works also for responses).
  
-<code c> +==== $csb - CSeq Header Body ====
-$var(x) 100 + MYINT; +
-</code>+
  
-  is interpreted as:+**$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; +
-</code>+
  
-  * you can have multi-line defined IDs 
  
-<code c> +==== $cT - Content-Type ====
-#!define IDLOOP $var(i) 0; \ +
-                while($var(i)<5) { \ +
-                    xlog("++++ $var(i)\n");+
-                    $var(i) = $var(i) + 1; \ +
-                } +
-</code>+
  
-  then in routing block+**$cT** - reference to body of content-type header
  
-<code c> +==== $dd - Domain of destination URI ====
-route { +
-    ... +
-    IDLOOP +
-    ... +
-+
-</code>+
  
-  number of allowed defines is now set to 256+**$dd** - reference to domain of destination uri (without port)
  
-  * notes: +==== $def(name) Defined Value ====
-    * 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 '\' and CR for the accurate inside-define position +
-    * 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 value.
- +
-Preprocessor directive to define an ID to the value of an environment variable with the name ENVVAR. +
- +
-<code c> +
-#!defenv ID=ENVVAR +
-</code> +
- +
-It can also be just **$!defenv ENVVAR** and the defined ID is the ENVVAR name.+
  
 Example: Example:
  
 <code c> <code c>
-#!defenv SHELL +#!define ABC xyz
-</code>+
  
-If environment variable $SHELL is '/bin/bash', then it is like: +xlog("FLT_ACC$def(ABC)\n");
- +
-<code c> +
-#!define SHELL /bin/bash+
 </code> </code>
  
-Full expression variant:+==== $defn(name) - Defined Value As Number ====
  
-<code c> +**$defn(name)** - return a defined value as a signed integer.
-#!defenv ENVSHELL=SHELL +
-</code> +
- +
-Then it is like: +
- +
-<code c> +
-#!define ENVSHELL /bin/bash +
-</code> +
- +
-It is a simplified alternative of using **#!substdef** with **$env(NAME)** in the replacement part. +
-     +
-==== 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 parsingE.g.,: +
- +
-<code c> +
-#!subst "/regexp/subst/flags" +
-</code> +
- +
-  * flags is optional and can be: 'i' - ignore case; 'g' - global replacement+
  
 Example: Example:
  
 <code c> <code c>
-#!subst "/DBPASSWD/xyz/" +#!define FLT_ACC 1
-modparam("acc", "db_url", "mysql://user:DBPASSWD@localhost/db"+
-</code>+
  
-  * will do the substitution of db password in db_url parameter value +xlog("FLT_ACC: $defn(FLT_ACC)\n");
- +
-==== substdef ==== +
- +
-<code c> +
-#!substdef "/ID/subst/"+
 </code> </code>
 +==== $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 "privacy" parameter ====
  
-<code c> +**$dip** - reference to Diversion header "privacyparameter value
-#!substdefs "/ID/subst/" +
-</code>+
  
-Similar to **subst**, but in addition it adds a **#!define ID "subst"** (note the difference from #!substdef that the value for define is enclosed in double quotes, useful when the define is used in a place for a string value). +==== $dir - Diversion "reason" parameter ====
-===== Core Keywords =====+
  
-Keywords specific to SIP messages which can be used mainly in ''if'' expressions.+**$dir** - reference to Diversion header "reason" parameter value
  
-==== af ====+==== $dic - Diversion "counter" parameter ====
  
-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 "counter" parameter value
  
-Exampe of usage:+==== $dp - Port of destination URI ====
  
-<code c> +**$dp** - reference to port of destination uri
-    if (af==INET6) { +
-        log("Message received over IPv6 link\n"); +
-    } +
-</code>+
  
-==== 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 to detect which was the one that received the packet.+**$dP** - reference to transport protocol of destination uri
  
-Example of usage:+==== $ds - Destination set ====
  
-<code c> +**$ds** - reference to destination set
-   if(dst_ip==127.0.0.1) { +
-      log("message received on loopback interface\n"); +
-   }; +
-</code>+
  
-==== 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(dst_port==5061) +
-   { +
-       log("message was received on port 5061\n"); +
-   }; +
-</code>+
  
 +If loose_route() returns TRUE a destination uri is set according to the first Route header.
 +$du is also set if lookup() function of 'registrar' module finds contact(s) behind NAT or
 +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.
 +   sip:kamailio.org
 +   sip:pbx123.kamailio.org;transport=udp
 +   sip:[2001:DB8::33:2]:5980;transport=tls
  
-==== from_uri ====+<fc #0000ff>It is R/W variable (you can assign values to it directly in configuration file)</fc>
  
-This script variable is a reference to the URI of 'From' header. It can be used to test 'From'- header URI value.+To reset $du: 
 +  $du = $null;
  
-Example of usage:+==== $fd - From URI domain ====
  
-<code c> +**$fd** - reference to domain in URI of 'From' header
-    if(is_method("INVITE") && from_uri=~".*@kamailio.org"+
-    { +
-        log("the caller is from kamailio.org\n"); +
-    }; +
-</code>+
  
-==== method ====+<fc #0000ff>It is R/W variable (you can assign values to it directly in configuration file)</fc>
  
-The variable is a reference to the SIP method of the message.+==== $fn - From display name ====
  
-Example of usage:+**$fn** - reference to display name of 'From' header
  
-<code c> +==== $fs - Forced Send Socket ====
-    if(method=="REGISTER"+
-    { +
-       log("this SIP request is a REGISTER message\n"); +
-    }; +
-</code>+
  
-==== msg:len ====+**$fs** - reference to the forced send socket for the SIP message (if any) in the form "proto:ip:port". It is the socket from where Kamailio is going to send out the message.
  
-The variable is a reference to the size of the messageIt can be used in 'if' constructs to test message's size.+<fc #0000ff>It is R/W variable (you can assign values to it directly in configuration file)Transport proto can be omitted when assigning value, in which case it is taken from destination URI of the message.</fc>
  
 +Example:
  
-Example of usage: 
 <code c> <code c>
-    if(msg:len>2048) +listen=udp:1.2.3.4:5060 
-    { +... 
-        sl_send_reply("413", "message too large"); +$fs = "udp:1.2.3.4:5060";
-        exit; +
-    };+
 </code> </code>
  
 +==== $fsn - Forced Send Socket Name ====
  
-.+**$fsn** - reference to the name of the forced send socket for the SIP message. The name can be assigned to this variable to select a send socket via its name.
  
-==== 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:1.2.3.4:5060 name "s1" 
-    { +... 
-        log("SIP message received over UDP\n")+$fsn "s1"; 
-    };+... 
 +$fs = "udp:1.2.3.4:5060"; 
 +xdbg("name for forced send socket: $fsn\n");
 </code> </code>
  
-==== status ====+==== $ft - From tag ====
  
-If used in onreply_route, this variable is a referece to the status code of the reply. If it used in a standard route block, the variable is a reference to the status of the last reply sent out for the current request.+**$ft** - reference to tag parameter of 'From' header
  
-Example of usage: +==== $fti - Initial From tag ====
-<code c> +
-    if(status=="200"+
-    { +
-        log("this is a 200 OK reply\n"); +
-    }; +
-</code>+
  
 +**$fti** - reference to tag parameter of 'From' header as it was in the initial request (e.g., initial INVITE).
  
-==== snd_af ====+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.
  
-==== snd_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 ====
  
-==== snd_port ====+**$fu** - reference to URI of 'From' header
  
-==== snd_proto ====+<fc #0000ff>It is R/W variable (you can assign values to it directly in configuration file)</fc>
  
-==== src_ip ====+Note that changing the From: header may break backwards compatibility with SIP 1.0 devices.
  
-Reference to source IP address of the SIP message.+==== $fU - From URI username ====
  
-Example of usage: +**$fU** - reference to username in URI of 'From' header
-<code c> +
-    if(src_ip==127.0.0.1) +
-    { +
-        log("the message was sent from localhost!\n"); +
-    }; +
-</code>+
  
-==== src_port ====+<fc #0000ff>It is R/W variable (you can assign values to it directly in configuration file)</fc>
  
-Reference to source port of the SIP message (from which port the message was sent by previous hop).+Note that changing the From: header may break backwards compatibility with SIP 1.0 devices.
  
-Example of usage: +==== $fUl - From URI Username Length ====
-<code c> +
-    if(src_port==5061) +
-    { +
-        log("message sent from port 5061\n"); +
-    } +
-</code>+
  
-==== to_ip ====+**$fUl** - length of the username in the From URI
  
-==== to_port ====+==== $mb - SIP message buffer ====
  
-==== to_uri ====+**$mb** - reference to SIP message buffer
  
-This variable can be used to test the value of URI from To header.+==== $mbu - updated SIP message buffer ====
  
-Example of usage: +**$mbu** - reference to updated SIP message buffer, after applying changes
-<code c> +
-  if(to_uri=~"sip:.+@kamailio.org"+
-  { +
-      log("this is a request for kamailio.org users\n"); +
-  }; +
-</code>+
  
-==== uri ====+==== $mf - Flags ====
  
 +**$mf** - reference to message/transaction flags set for current SIP request
  
-This variable can be used to test the value of the request URI.+<fc #0000ff>It is R/W variable (you can assign values to it directly in configuration file)</fc>
  
-Example of usage: +==== $mF - Flags in hexadecimal ====
-<code c> +
-    if(uri=~"sip:.+@kamailio.org"+
-    { +
-        log("this is a request for kamailio.org users\n"); +
-    }; +
-</code>+
  
 +**$mF** -reference to message/transaction flags set for current SIP request in hexa-decimal
  
 +<fc #0000ff>It is R/W variable (you can assign values to it directly in configuration file)</fc>
  
-===== Core Values =====+==== $mi - SIP message id ====
  
-Values that can be used in '''if''' expressions to check against Core Keywords+**$mi** - reference to SIP message id
  
-==== INET ====+==== $ml - SIP message length ====
  
-This keyword can be used to test whether the SIP packet was received over an IPv4 connection.+**$ml** - reference to SIP message length
  
-Example of usage:+==== $mt - SIP Message Type ====
  
-<code c> +**$mt** - returns 1 if the sip message is a request, returns 2 if the sip message is a reply
-    if (af==INET) { +
-        log("the SIP message was received over IPv4\n"); +
-    } +
-</code>+
  
-==== INET6 ==== 
  
-This keyword can be used to test whether the SIP packet was received over an IPv6 connection.+==== $od - Domain original R-URI ====
  
-Example of usage: +**$od** - reference to domain in request's original R-URI
-<code c> +
-  if(af==INET6) +
-  { +
-      log("the SIP message was received over IPv6\n"); +
-  }; +
-</code>+
  
-==== SCTP ====+==== $op - Port in original R-URI ====
  
-This keyword can be used to test the value of 'proto' and check whether the SIP packet was received over SCTP or not.+**$op** - reference to port of original R-URI
  
-Example of usage: +==== $oP - Protocol of original R-URI ====
-<code c> +
-  if(proto==SCTP) +
-  { +
-      log("the SIP message was received over SCTP\n"); +
-  }; +
-</code>+
  
-==== TCP ====+**$oP** - reference to transport protocol of original R-URI
  
-This keyword can be used to test the value of 'proto' and check whether the SIP packet was received over TCP or not.+==== $ou - Original R-URI ====
  
-Example of usage: +**$ou** - reference to request's original URI
-<code c> +
-  if(proto==TCP) +
-  { +
-      log("the SIP message was received over TCP\n"); +
-  }; +
-</code>+
  
-==== TLS ====+==== $oU - Username in original R-URI ====
  
-This keyword can be used to test the value of 'proto' and check whether the SIP packet was received over TLS or not.+**$oU** - reference to username in request's original URI
  
-Example of usage: +==== $oUl - Original R-URI Username Length ====
-<code c> +
-  if(proto==TLS) +
-  { +
-      log("the SIP message was received over TLS\n"); +
-  }; +
-</code> +
-==== UDP ====+
  
-This keyword can be used to test the value of 'proto' and check whether the SIP packet was received over UDP or not.+**$oUl** - the length of the username in the original R-URI
  
-Example of usage: +==== $pd - Domain in P-Preferred-Identity header URI ====
-<code c> +
-  if(proto==UDP) +
-  { +
-      log("the SIP message was received over UDP\n"); +
-  }; +
-</code>+
  
-==== WS ====+**$pd** - reference to domain in request's P-Preferred-Identity header URI (see RFC 3325)
  
-This keyword can be used to test the value of 'proto' and check whether the SIP packet was received over WS or not.+==== $pn - Display Name in P-Preferred-Identity header ====
  
-Example of usage: +**$pn** - reference to Display Name in request's P-Preferred-Identity header (see RFC 3325)
-<code c> +
-  if(proto==WS) +
-  { +
-      log("the SIP message was received over WS\n"); +
-  }; +
-</code>+
  
 +==== $pp - Process id ====
  
-==== WSS ====+**$pp** - reference to process id (pid)
  
-This keyword can be used to test the value of 'proto' and check whether the SIP packet was received over WSS or not.+==== $pr or $proto - Protocol of received message ====
  
-Example of usage: +**$pr** or **$proto** - protocol of received message (udp, tcp, tls, sctp, ws, wss)
-<code c> +
-  if(proto==WSS) +
-  { +
-      log("the SIP message was received over WSS\n")+
-  }; +
-</code> +
-==== max_len ====+
  
-Note: This command was removed.+==== $prid - protocol id ====
  
 +**$prid** - internal protocol id
  
-==== myself ====+  * 0 - NONE 
 +  * 1 - UDP 
 +  * 2 - TCP 
 +  * 3 - TLS 
 +  * 4 - SCTP 
 +  * 5 - WS 
 +  * 6 - WSS 
 +  * 7 - OTHER 
 +==== $pU - User in P-Preferred-Identity header URI ====
  
-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.+**$pU** - reference to user in request's P-Preferred-Identity header URI (see RFC 3325)
  
-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.+==== $pu - URI in P-Preferred-Identity header ====
  
-See "alias" to add hostnames,IP addresses and aliases to the list.+**$pu** - reference to URI in request's P-Preferred-Identity header (see RFC 3325)
  
-Example of usage: 
-<code c> 
-    if(uri==myself) { 
-        log("the request is for local processing\n"); 
-    }; 
-</code> 
  
-Note: You can also use the is_myself() function. 
-===== Core parameters ===== 
  
-==== advertised_address ====+==== $rb - Body of request/reply ====
  
-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 +**$rb** - reference to message body
-address from where the request will be sent is used.+
  
-  WARNING:  +==== $rc Returned code ====
-  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't exist)+
  
-Example of usage:+**$rc** - reference to returned code by last invoked function
  
-    advertised_address="​1.2.3.4"​ +**$retcode** - same as **$rc**
-    advertised_address="kamailio.org"+
  
-Note: this option may be deprecated and removed in the near future, it is recommended to set **advertise** option for **listen** parameter. +Note that the value of $rc is overwritten by each new function call.
-==== 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 'advertised_address'.+Example of use:
  
-Example of usage:+<code c> 
 + lookup("location"); 
 + $var(rc) = $rc; 
 + if ($var(rc) < 0) { 
 + t_newtran(); 
 + switch ($var(rc)) { 
 + case -1: 
 + case -3: 
 + send_reply("404", "Not Found"); 
 + exit; 
 + case -2: 
 + send_reply("405", "Method Not Allowed"); 
 + exit; 
 +
 + }
  
-    advertised_port=5080 
- 
-Note: this option may be deprecated and removed in the near future, it is recommended to set **advertise** option for **listen** parameter. 
-==== 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 'myself' is checked. 
- 
-It is necessary to include the port (the port value used in the "port=" or "listen=" defintions) in the alias definition otherwise the loose_route() function will not work as expected for local forwards. Even if you do not use 'myself' explicitly (for example if you use the domain module), it is often necessary to set the alias as these aliases are used by the loose_routing function and might be needed to handle requests with pre-loaded route set correctly. 
- 
-Example of usage: 
- 
-<code> 
-    alias=other.domain.com:5060 
-    alias=another.domain.com:5060 
 </code> </code>
 +==== $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's URI (without port) or to the Namespace Specific String of a URN (see RFC 2141)
-==== async_workers ====+
  
-Specify how many child processes (workers) to create for asynchronous execution in the group "default". These are processes that can receive tasks from various components (e.g, modules such as async, acc, sqlopsand execute them locally, which is different process than the task sender.+<fc #0000ff>It is R/W variable (you can assign values to it directly in configuration file)</fc>
  
-Default: 0 (asynchronous framework is disabled).+==== $rdir(key- Request Direction ====
  
-Example:+**$rdir(key)** - get the direction of the request within dialog.
  
-<code> +The direction is 'downstream' if sent by the caller and 'upstream' if sent by callee.
-    async_workers=4 +
-</code>+
  
-==== 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'downstream' or 'upstream'
-Default0+
  
 Example: Example:
  
-<code> +<code c
-    async_nonblock=1+if($rdir(name)=="upstream") { 
 +  xlog("request was sent by callee\n"); 
 +}
 </code> </code>
  
-==== 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 to sleep before trying to receive next task (can be useful when async_nonblock=1).+**$re** - reference to Remote-Party-ID header URI
  
-Default: 0+==== $rm - SIP method ====
  
-Example:+**$rm** - reference to request's method. Works also for replies (by using the CSeq header)
  
-<code> +==== $rmid - SIP Method ID ====
-    async_usleep=100 +
-</code>+
  
-==== 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
  
-<code> +==== $rp - Port in R-URI ====
-async_workers_group="name=X;workers=N;nonblock=[0|1];usleep=M" +
-</code>+
  
-The attributes are:+**$rp** - reference to port of R-URI
  
-  * **name** - the group name (used by functions such as **sworker_task(name)**) +<fc #0000ff>It is R/W variable (you can assign values to it directly in configuration file)</fc>
-  * **workers** - the number of processes to create for this group +
-  * **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
  
-<code> +==== $rr - SIP reply reason phrase ====
-    async_workers_group="name=reg;workers=4;nonblock=0;usleep=0" +
-</code>+
  
-If the **name** is default, then it overwrites the value set by **async_workers**.+**$rr** - reference to reply's reason phrase (the text after reply code)
  
-See also **event_route[core:pre-routing]** and **sworker** module.+==== $rs SIP reply code ====
  
-==== auto_aliases ====+**$rs** - reference to reply's status (status-code, response-code, reply-code)
  
-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
  
-<code> +==== $ru - Request URI ====
-    auto_aliases=no +
-</code> +
-==== auto_bind_ipv6 ====+
  
-When turned on, Kamailio will automatically bind to all IPv6 addresses (much like the default behaviour for IPv4). Default is 0.+**$ru** - reference to request's URI (address in the first line of a SIP request)
  
-Example:+<fc #0000ff>It is R/W variable (you can assign values to it directly in configuration file)</fc>
  
-<code> +==== $rU - Username in R-URI ====
-    auto_bind_ipv6=+
-</code>+
  
-==== bind_ipv6_link_local ====+**$rU** - reference to username in request's URI or to the Namespace Identifier of a URN (see RFC 2141)
  
-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 #0000ff>It is R/W variable (you can assign values to it directly in configuration file)</fc>
  
-Example:+==== $rUl - R-URI Username Length ====
  
-<code> +**$rU** - the length of the username in R-URI
-    bind_ipv6_link_local=1 +
-</code> +
-==== 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:lookup()
  
-==== children ====+==== $rz - URI Scheme of R-URI ====
  
-Number of children to fork for the UDP interfaces (one set for each interface ip:port). Default value is 8. For example if you configure the proxy to listen on 3 UDP portsit will create 3xchildren processes which handle the incoming UDP messages.+**$rz** returns R-URI scheme, possible valuessipsips, tel, tels and urn, R-URI scheme parsing error should be reflected by value: none
  
-For configuration of the TCP/TLS worker threads see the option "tcp_children".+==== $RAi - Received advertised IP address ====
  
-Example of usage:+**$RAi** - reference to advertised IP address of the interface where the request has been received, or $Ri if no advertised 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 of usage:+**$Ri** - reference to IP address of the interface where the request has been received 
 +==== $Rp - Received port ====
  
-    chroot=/other/fakeroot+**$Rp** - reference to the port where the message was received
  
 +==== $RAu - Advertised socket URI ====
  
-==== corelog ====+**$RAu** - local socket where the SIP messages was received in URI format, without transport parameter for UDP, using advertised address when available.
  
-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.+==== $RAut - Advertised socket URI ====
  
-Default value is -1 (L_ERR).+**$RAut** local socket where the SIP messages was received in URI format, always with transport parameter, using advertised address when available.
  
-Example of usage:+==== $Ru - Received socket URI ====
  
-<code> +**$Ru** - local socket where the SIP messages was received in URI format, without transport parameter for UDP.
-corelog=1 +
-</code>  +
-==== 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 [[#log_stderror]] parameter).+==== $Rut - Received socket URI ====
  
-The following log levels are defined:+**$Rut** - local socket where the SIP messages was received in URI format, always with transport parameter.
  
-   L_ALERT     -+==== $sas Source address in socket format ====
-   L_BUG       -4 +
-   L_CRIT2     -3 +
-   L_CRIT      -2 +
-   L_ERR       -1 +
-   L_WARN       0  +
-   L_NOTICE     1  +
-   L_INFO       2  +
-   L_DBG        3 +
  
-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.+**$sas** get source address in socket format (proto:address:port)
 +==== $sbranch(attr) - Static Branch ====
  
-Default value: L_WARN (debug=0)+**$sbranch(attr)** - class of variables allowing to manage the values of attributes for static branch. The static branch is internal structure that is used by the functions sbranch_push_ruri() and sbranch_append() from **pv** module, enabling more flexibility in updating the R-URI (first) branch attributes as well as extra branches (e.g., for parallel forking).
  
-Examples of usage: +The **attr** can be any of the supported values for **$branch(attr)** class of variables -see above for proper details.
- +
-  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) +
-  debug=0: This will only log warning, errors and more critical messages. +
-  debug=-6: This will disable all log messages. +
- +
-Value of 'debug' parameter can also be get and set dynamically using the 'debug' Core MI function or the RPC function, e.g.: +
-  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<=1.5: Up to Kamailio 1.5 the log level started with 4, whereas in Kamailio>=3 the log level starts with 3. Thus, if you were using debug=3 in older Kamailio, now use debug=2. +
- +
-For configuration of logging of the memory manager see the parameters [[#memlog]] and [[#memdbg]]. +
- +
-Further information can also be found at: https://www.kamailio.org/wiki/tutorials/3.2.x/syslog +
- +
-==== description ==== +
- +
-**Alias name: descr desc** +
- +
-==== disable_core_dump ==== +
- +
-Can be 'yes' or 'no'. By default core dump limits are set to unlimited or a high enough value. Set this config variable to 'yes' to disable core dump-ing (will set core limits to 0). +
- +
-Default value is 'no'.+
  
 Example of usage: Example of usage:
  
-    disable_core_dump=yes+<code c> 
 +sbranch_reset(); 
 +$sbranch(uri) "sip:127.0.0.1:5080"; 
 +$sbranch(dst_uri) =  "sip:127.0.0.1:5090"; 
 +$sbranch(path) =  "sip:127.0.0.1:5090, sip:127.0.0.1:5094"; 
 +$sbranch(send_socket) =  "udp:127.0.0.1:5060"; 
 +sbranch_set_ruri(); 
 +</code>
  
-==== 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 'no'.+==== $sF - Script flags ====
  
-Note: Make sure to load the "tls" module to get tls functionality.+**$sF** - reference to script flags - hexa output
  
-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://kamailio.org/docs/modules/devel/modules/tls.html +
-==== enable_tls ====+
  
-**Alias name: tls_enable**+**$sid** - the value for server id (server_id parameter) 
 +==== $siz - Source IP address ====
  
-Reverse Meaning of the disable_tls parameter. See disable_tls parameter.+**$siz** - reference to IP source address of the message, with enclosing square brackets for IPv6
  
-  enable_tls=yes # enable tls support in core+==== $sp - Source port ====
  
-==== exit_timeout ====+**$sp** - reference to the source port of the message
  
-**Alias name: ser_kill_timeout**+==== $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 (it might also generate a core dump if the cleanup part takes too long).+**$stat(name)** - return the value of statistic item specified by 'name'
  
-Default: 60 s. Use 0 to disable.+==== $su - Source address as URI ====
  
-   exit_timeout = seconds 
  
-==== 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**(*)+
  
- +<code> 
-<code c+"sip:ip:port" -- if proto is UDP 
-... +"sip:ip:port;transport=proto"  -- if proto is not UDP
-flags +
-  FLAG_ONE   1, +
-  FLAG_TWO   2; +
-...+
 </code> </code>
  
-(*) The named flags feature was propagated from the source code merge back in 2008 and is not extensively testedThe recommended way of defining flags is using [[cookbooks:5.2.x:core#define|#!define]] (which is also valid for branch/script flags): +Note that WS and WSS are both represented by transport=ws, conforming with the IETF RFC for SIP over WebSocket.
-<code c> +
-#!define FLAG_NAME FLAG_BIT +
-</code>+
  
 +==== $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/noSimilar to the force_rport() function, but activates symmetric response routing globally.+<code> 
 +"sip:ip:port;transport=proto" 
 +</code> 
 +==== $td - To URI Domain ====
  
-==== fork ====+**$td** - reference to domain in URI of 'To' header
  
-If set to 'yes' the proxy will fork and run in daemon mode one process will be created for each network interface the proxy listens to and for each protocol (TCP/UDP), multiplied with the value of 'children' parameter.+==== $tn To display name ====
  
-When set to 'no', the proxy will stay bound to the terminal and runs as single process. First interface is used for listening to. This is equivalent to setting the server option "-F".+**$tn** - reference to display name of 'Toheader
  
-Default value is 'yes'.+==== $tt - To tag ====
  
-Example of usage:+**$tt** - reference to tag parameter of 'To' header
  
-    fork=no+==== $tti - Initial To tag ====
  
-==== fork_delay ====+**$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).
  
-Number of usecs to wait before forking a process.+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.
  
-Default is (don't wait).+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. 
 +==== $tu - To URI ====
  
-Example of usage:+**$tu** - reference to URI of 'To' header
  
-<code c> +==== $tU - To URI Username ====
-fork_delay=5000 +
-</code> +
-==== group ====+
  
-**Alias name: gid**+**$tU** - reference to username in URI of 'To' header
  
-The group id to run Kamailio.+==== $tUl - To URI Username Length ====
  
-Example of usage:+**$tU** - the length of the username in To URI
  
-  group="siprouter"+==== $Tb - Startup timestamp ====
  
-==== http_reply_parse ====+**$Tb** - reference to unix timestamp of the time at which kamailio was started (boot time)
  
-Alias: http_reply_hack+==== $Tf - String formatted time - cached ====
  
-When enabled, Kamailio can parse HTTP replies, but does so by treating them as SIP replies.  When not enabled HTTP replies cannot be parsed. This was previously a compile-time option, now it is run-time.+**$Tf** reference string formatted time
  
-Default value is 'no'.+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.
  
-Example of usage:+==== $TF - String formatted time - current ====
  
-  http_reply_parse=yes+**$TF** - reference string formatted time
  
-==== ip_free_bind ====+Note: the system time is computed for each call of $TF. Subsequent calls of $TF for same SIP message may return different values.
  
-Alias: ipfreebind, ip_nonlocal_bind+==== $Ts - Unix time stamp - cached ====
  
-Control if Kamailio should attempt to bind to non local ip. This option is the per-socket equivalent of the system **ip_nonlocal_bind**.+**$Ts** - reference to unix time stamp
  
-Default is 0 (do not bind to non local ip).+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
  
-Example of usage:+==== $TS - Unix time stamp - current ====
  
-<code c> +**$TS** - reference to unix time stamp
-  ip_free_bind = 1 +
-</code>+
  
 +Note: the system time is computed for each call of $TS. Subsequent calls of $TS for same SIP message may return different values.
  
-==== ipv6_hex_style ====+==== $ua - User agent header ====
  
-Can be set to "a", "A" or "c" to specify if locally computed string representation of IPv6 addresses should be expanded lowercase, expanded uppercase or compacted lowercase hexa digits.+**$ua** - reference to user agent header field
  
-Default is "c" (compacted lower hexa digits, conforming better with RFC 5952).+==== $version() - version ====
  
-"A" is preserving the behaviour before this global parameter was introduced, while "a" enables the ability to follow some of the recommendations of RFC 5952, section 4.3.+**$version(num)** - version as number
  
-Example of usage: +**$version(full)** - full version string "name version architecture/platform"
- +
-<code c> +
-  ipv6_hex_style = "a" +
-</code> +
-==== 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(hash)** - TBA
  
-Default value: ksr_onsend_route+===== $env(NAME) - environment variables =====
  
-Set it to empty string or "none" to skip execution of this callback function.+**$env(NAME)** - value of the environment variable named NAME
  
 Example: Example:
  
 <code c> <code c>
-kemi.onsend_route_callback="ksr_my_onsend_route"+xdbg("PATH environment variable:  $env(PATH)\n");
 </code> </code>
 +===== $avp(id) - AVPs =====
  
-==== kemi.received_route_callback ====+**$avp(id)** - the value of the AVP identified by 'id'.
  
-Set the name of callback function in the KEMI script to be executed as the equivalent of `event_route[core:msg-received]` block (from the native configuration file). For execution, it also require to have the received_route_mode global parameter set to 1.+**$(avp(id)[N])** - represents the value of N-th AVP identified by 'id'.
  
-Default valuenone+The 'id' can be:
  
-Set it to empty string or "noneto skip execution of this callback function.+  * "[(s|i):]name" - name is the id of an AVP; 's' and 'i' specifies if the id is string or integer. If missing, it is considered to be string
 +  * "name- the name is an AVP alias, or if the alias is not found, it is a 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 transactionsIt is a list of pairs (name,value)Before the transaction is created, the AVP list is attached to SIP request. Note that the AVP list works like a stack, last added value is retrieved first, and there can be many values for same AVP name, an assignment to the same AVP name does not overwrite old valueit will add the new value in the list.
-kemi.received_route_callback="ksr_my_receieved_route" +
-</code> +
- +
-==== kemi.reply_route_callback ==== +
- +
-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). +
- +
-Default value: ksr_reply_route +
- +
-Set it to empty string or "none" to skip execution of this callback function. +
- +
-Example:+
  
 +To delete the first AVP with name 'id' you have to assign to it '$null':
 <code c> <code c>
-kemi.onsend_route_callback="ksr_my_reply_route"+$avp(id) $null;
 </code> </code>
  
-==== kemi.pre_routing_callback ==== +To delete all the AVP with name 'id' you have to assign $null to the index '*':
- +
-Set the name of callback function in the KEMI script to be executed as the equivalent of `event_route[core:pre-routing]` block (from the native configuration file). +
- +
-Default value: none +
- +
-Set it to empty string or "none" to skip execution of this callback function. +
- +
-Example: +
 <code c> <code c>
-kemi.pre_routing_callback="ksr_pre_routing"+$(avp(id)[*]) $null;
 </code> </code>
  
-==== latency_cfg_log ==== +To overwrite the value of the AVP with name 'id' you have to assign the new value to the index '*':
- +
-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 to syslog. +
- +
-Default value is 3 (L_DBG). +
- +
-Example: +
 <code c> <code c>
-latency_cfg_log=2+$(avp(id)[*]) newvalue;
 </code> </code>
  
-==== latency_limit_action ====+The value of an AVP can be integer or string. To assign a value as string, it has to be enclosed in double quotes. To assign the value as integer, it has to be a valid number given without quotes.
  
-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 name when it is a module function, as well as internal action id. +Example of usage:
- +
-Default value is 0 (disabled).+
  
 <code c> <code c>
-latency_limit_action=500+$avp(x) 1;  # assign of integer value 
 +$avp(x) = 2; 
 +$avp(y) = "abc"; # assign of string value 
 +if($(avp(x)[1])==1) { 
 +  ... 
 +
 +$(avp(x)[1]) = $null;
 </code> </code>
-  
-==== latency_limit_db ==== 
  
-Limit of latency in us (micro-secondsfor db operations. If a db operation executed via DB API v1 takes longer that its value, a message is printed in the logs, showing the first 50 characters of the db query.+It is R/W variable (you can assign values to it directly in configuration file).
  
 +===== $expires(key) - Expires Values =====
  
-Default value is 0 (disabled).+Return the min and max of expires value for current SIP messageContact headers are checked with higher priority, if no expires parameter there, then Expires header is used
  
-<code c> +If none is found, $null is returned.
-latency_limit_db=500 +
-</code>+
  
 +Possible 'key' values:
  
-==== latency_log ====+  * $expires(min) - the minimum value for expires 
 +  * $expires(max) - the maximum value for expires
  
-Log level to print the messages related to latency. +When there is only one expires value, then min and max return the same.
- +
- +
-Default value is -1 (L_ERR). +
- +
-<code c> +
-latency_log=3 +
-</code> +
- +
-==== listen ==== +
- +
-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:address:port (e.g., udp:10.10.10.10:5060). This parameter can be set multiple times in same configuration file, the server listening on all addresses specified.+
  
 Example of usage: Example of usage:
  
 <code c> <code c>
-    listen=10.10.10.10 +if($expires(max)!=$null) { 
-    listen=eth1:5062 +    xlog("max expires value is$expires(max)\n"); 
-    listen=udp:10.10.10.10:5064+}
 </code> </code>
  
-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 addressesyou should put them into square brackets, e.g.:+**xavp** - eXtended AVPs - are variables that can store multiple valueswhich can also be grouped in a structure-like fashionTheir 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:[2a02:1850:1:1::18]:5060 +
-</code>+
  
-You can specify an advertise address (like ip:portper listening socket - it will be used to build headers such as Via and Record-Route:+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 <nowiki>=></nowiki> like <nowiki>$xavp(root=>field)</nowiki> where "root" is the name of the structure and "field" is the name of the (child) value.
  
-<code c> +To assign single value use:
-    listen=udp:10.10.10.10:5060 advertise 11.11.11.11:5060 +
-</code> +
- +
-The advertise address must be the format 'address:port', the protocol is taken from the bind socket. The advertise address is convenient alternative to advertised_address / advertised_port cfg parameters or set_advertised_address() / set_advertised_port() cfg functions. +
- +
-A typical use case for advertise address is when running SIP server behind a NAT/Firewall, when the local IP address (to be used for bind) is different than the public IP address (to be used for advertising). +
- +
-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:10.0.0.10:5060 name "s1" +$xavp(root)="string value"; 
-    listen=udp:10.10.10.10:5060 advertise 11.11.11.11:5060 name "s2" +$xavp(root)=intnumber;
-    listen=udp:10.10.10.20:5060 advertise "mysipdomain.com" name "s3" +
-    listen=udp:10.10.10.30:5060 advertise "mysipdomain.com" name "s4" +
-    ... +
-    $fsn = "s4"; +
-    t_relay();+
 </code> </code>
  
-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 matching name is used. +To assign named value use:
-==== loadmodule ====+
  
-Loads a module for later usage in the configuration script. The modules is searched in the path specified by **loadpath**. 
- 
-Prototype: **loadmodule "modulepath"** 
- 
-If modulepath is only modulename or modulename.so, then Kamailio will try to search also for **modulename/modulename.so**, very useful when using directly the version compiled in the source tree. 
- 
-Example of usage: 
 <code c> <code c>
-    loadpath "/usr/local/lib/kamailio/:usr/local/lib/kamailio/modules/+$xavp(root=>field)="string value"; 
- +$xavp(root=>field)=intnumber;
-    loadmodule "/usr/local/lib/kamailio/modules/db_mysql.so" +
-    loadmodule "modules/usrloc.so" +
-    loadmodule "tm" +
-    loadmodule "dialplan.so"+
 </code> </code>
  
-==== loadmodulex ==== +Like avps, xavp act like stackTo refer to an existing valueuse an indexThe 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 list of directories separated by ':'The list is searched in-order. For each directory d$d/${module_name}.so and $d/${module_name}/${module_name}.so are tried. +
- +
-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 "/usr/local/lib/kamailio/modules:/usr/local/lib/kamailio/mymodules" +$xavp(root[0]=>field)=12;
- +
-    loadmodule "mysql" +
-    loadmodule "uri" +
-    loadmodule "uri_db" +
-    loadmodule "sl" +
-    loadmodule "tm"+
 </code> </code>
  
-The proxy tries to find the modules in smart waye.g: loadmodule "uri" tries to find uri.so in the loadpathbut also uri/uri.so. +If you assign value without an indexa new xavp is allocated and the old one is pushed up the stackbecoming index [1]Old index [1] becomes [2] etc.
- +
-==== 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 on +# new item (person => [(lastname = "Smith")]) 
-</code>+$xavp(person=>lastname)="Smith";
  
-==== log_engine_data ====+# add new item (person => [(lastname "Doe")]) 
 +$xavp(person=>lastname)="Doe";
  
-Set specific data required by the log engine. See also the **log_engine_type**.+# add another named value to the last example item 
 +#   (person => [(firstname="John"), (lastname = "Doe")]) 
 +$xavp(person[0]=>firstname)="John";
  
-<code c> +# add another named value to first example item 
-log_engine_type="udp" +#   (person => [(firstname="Alice"), (lastname = "Smith")]) 
-log_engine_data="127.0.0.1:9"+xavp(person[1]=>firstname)="Alice";
 </code> </code>
  
-==== 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="udp" +# create new (the first) root xavp with a named value of string type 
-log_engine_data="127.0.0.1:9" +$xavp(sf=>uri)="sip:10.10.10.10";
-</code>+
  
 +# add named values (child values)
 +$xavp(sf[0]=>fr_timer)=10;
 +$xavp(sf[0]=>fr_inv_timer)=15;
 +$xavp(sf[0]=>headers)="X-CustomerID: 1234\r\n";
  
-==== log_facility ====+# create new (the second) root xavp with a named value of string type, moving previous one to sf[1] 
 +$xavp(sf=>uri)="sip:10.10.10.11"; 
 +# add named values (child values) 
 +$xavp(sf[0]=>fr_timer)=20; 
 +$xavp(sf[0]=>fr_inv_timer)=35;
  
-If Kamailio logs to syslogyou can control the facility for logging. Very useful when you want to divert all Kamailio logs to a different log file. See the man page syslog(3for more details. +# create new (the third) xavp with a named value of string typemoving previous one to sf[1] and the other one to sf[2] 
- +$xavp(sf=>uri)="sip:10.10.10.12"; 
-For more seehttp://www.kamailio.org/dokuwiki/doku.php/tutorials:debug-syslog-messages +# add named values (child values) 
- +$xavp(sf[0]=>fr_timer)=10; 
-Default value is LOG_DAEMON. +$xavp(sf[0]=>fr_inv_timer)=15; 
- +$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"+
 </code> </code>
  
-==== 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 (that is, when executing route blocks). It can contain script variables that are evaluated at runtime. +===== $xavu(id- XAVUs =====
-See [[#log_prefix_mode]] about when/how evaluation is done.+
  
 +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) = $null; # <- delete the xavu 
 +$xavu(a=>b"xyz"; # <- two level naming supported
 </code> </code>
  
-==== log_prefix_mode ====+===== $xavi(id) - XAVIs =====
  
-Control if [[#log_prefix|log prefix]] is re-evaluated.+Similar to XAVPs, but with key names are case insensitive. XAVIs are also stored in transaction context and destroyed when the transaction is terminated.
  
-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/after each config action (needs to be set when the **log_prefix** has variables that are different based on the context of config execution, e.g., $cfg(line)).+Examples:
  
-Example: +<code c
- +$xavi(WhatEver=>FoO) = 123; # <- set the value 
-<code> +# $xavi(whatever[0]=>foo) =123
-log_prefix_mode=1+
 </code> </code>
-==== log_stderror ====+===== $hdr(name) - Headers =====
  
-With this parameter you can make Kamailio to write log and debug messages to standard error. Possible values are: 
  
-"yes" - write the messages to standard error+**$hdr(name)** represents the body of first header field identified by 'name'
  
-"no" - write the messages to syslog+**$(hdr(name)[N])** represents the body of the N-th header field identified by 'name'.
  
-Default value is "no".+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='*', all headers of that type are printed.
  
-For more see: http://www.kamailio.org/dokuwiki/doku.php/tutorials:debug-syslog-messages+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 namesIt 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 fileDefault is the native interpreter.+
  
 Example of usage: Example of usage:
  
-    cfgengine="name+<code c> 
-    cfgengine "name"+if($hdr(From)=~"kamailio\.org") { 
 +... 
 +
 +</code>
  
-If name is "native" or "default", it expects to have in native config interpreter for routing logic. +<fc #0000ff>It is read-only variableYou can remove or add headers using functions from textops module.</fc>
-     +
-The name can be the identifier of an embedded language interpreter, such as "lua" which is registered by the app_lua module:+
  
-    cfgengine "lua"+===== $hfl(name) - Header Field With List Of Bodies =====
  
-==== maxbuffer ====+Similar to **$hdr(name)**, but for some of the standard headers that can have many bodies serialized in the same header field (i.e., comma separated list of bodies in same header field) is able to return the individual body values.
  
-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 for:
  
-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 'name'.
  
-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 body of the N-th header field identified by 'name'.
- +
-The value has to be at least 1 and the upper limit is 31. +
- +
-Default value: 12+
  
 Example of usage: Example of usage:
  
-<code> +<code c
-max_branches=16+if($(hfl(Via)[1])=~"TLS") { 
 +... 
 +}
 </code> </code>
 +===== $hdrc(name) - Number of Headers =====
  
-==== max_recursive_level ==== +**$hdrc(name)** - get the number of headers with the respective name
- +
-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) == 2) { 
 +... 
 +
 +</code>
  
 +===== $hflc(name) - Number of Header Bodies =====
  
-==== max_while_loops ====+Similar to **$hdrc(name)**, but for some of the standard headers that can have many bodies serialized in the same header field (i.e., comma separated list of bodies in same header field) is able to count the number of individual bodies.
  
-The parameters set the value of maximum loops that can be done within a "while". Comes as a protection to avoid infinite loops in config file execution. Default is 100.  Setting to 0 disables the protection (you will still get a warning when you start Kamailio if you do something like while(1) {...}).+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="eth1" 
-    listen=udp:224.0.1.75:5060 
- 
-==== mcast_loopback ==== 
- 
-It can be 'yes' or 'no'. If set to 'yes', multicast datagram are sent over loopback. Default value is 'no'. 
- 
-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    # no memory debugging as debug level  
-  memdbg=4   # is lower than memdbg 
- 
-  debug=3    # memory debugging is active as the debug level  
-  memdbg=2   # is higher or equal memdbg 
- 
-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    # no memory statistics as debug level  
-  memlog=4   # is lower than memlog 
- 
-  debug=3    # dumping of memory statistics is active as the  
-  memlog=2   # debug level is higher or equal memlog 
- 
-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) { 
 +... 
 +}
 </code> </code>
 +===== $var(name) - Private memory variables (zero) =====
  
-To change its value at runtime, **kamcmd** needs to be used and the modules **ctl** and **cfg_rpc** loadedEnabling it can be done with:+**$var(name)** - refers to variables that can be used in configuration script, having integer or string value. This kind of variables are faster than AVPs, being referenced directly to memory location.
  
-<code> +Example of usage:
-kamcmd cfg.set_now_int core mem_join 1 +
-</code> +
- +
-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) 2; #-- sets the value of variable 'a' to integer '2' 
-</code>+$var(a) = "2"; #-- sets the value of variable 'a' to string '2' 
 +$var(a) = "sip:" + $au + "@" + $fd; #-- compose a value from authentication username and From URI domain 
 +$var(a) = 3 + (7&(~2));
  
-==== mem_status_mode ==== +if( $var(a) & 4 ) { 
- +  xlog("var a has third bit set\n"); 
-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+
 </code> </code>
  
-==== mem_summary ==== +**Note:** Setting a variable to $null is actually initializing the value to integer '0'This type of script variables doesn't have $null value.
- +
-Parameter to control printing of mmemory debugging information displayed on exit or SIGUSR1. The value can be composed by following flags: +
-  1 - dump all the pkg used blocks (status) +
-  2 - dump all the shm used blocks (status) +
-  4 - summary of pkg used blocks +
-  8 - summary of shm used blocks +
- +
-If set to 0, nothing is printed. +
- +
-Default value: 3 +
- +
-Example:+
  
 <code c> <code c>
-mem_summary=15 +$var(x) $null;
-</code>+
  
-==== 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, the incoming socket will be used or the first one for a different protocol, disregarding the destination location. When activated, Kamailio will select a socket that can reach the destination (to be able to connect to the remote address). (Kamailio opens a UDP socket to the destination, then it retrieves the local IP which was assigned by the operating system to the new UDP socket. Then this socket will be closed and the retrieved IP address will be used as IP address in the Via/Record-Route headers) +}
- +
-Example of usage: +
- +
-    mhomed=+
- +
-==== mlock_pages ==== +
-Locks all Kamailio pages into memory making it unswappable (in general one doesn't want his SIP proxy swapped out :-)) +
- +
-  mlock_pages = yes |no (default no) +
- +
-==== 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)+
- +
-<code> +
-modinit_delay=100000+
 </code> </code>
 +**Note:** A script variable persists over the Kamailio process in which it was initialized, so be sure of giving it a new value before reading it or you'll get the value asigned in any other previous message processed by the same Kamailio process (pid).
  
-==== modparam ====+<fc #0000FF>It is R/W variable (you can assign values to it directly in configuration file)</fc>
  
-The modparam command will be used to set the options of the modules+**pv** module can be used to initialize the script variables.
  
-Example:+===== $vz(name) - Private memory variables (zero) =====
  
-  modparam("usrloc", "db_mode", 2) +Same as $var(name-- added to pair with $vn(name).
-  modparam("usrloc", "nat_bflag", 6)+
  
-See the documenation of the respective module to find out the available options.+===== $vn(name) - Private memory variables (null) =====
  
-==== modparamx ==== +Similar to $var(name) and able to hold $null (which is the default value). The value is kept in private memory (pkg) and it is persistent across SIP message processingwithin the space of each Kamailio process.
- +
-Similar to **modparam**, with ability to evaluate the variables in its parameters. +
-==== onsend_route_reply ==== +
- +
-If set to 1 (yes, on), onsend_route block is executed for received replies that are sent out. Default is 0. +
- +
-    onsend_route_reply=yes +
- +
-==== open_files_limit ==== +
- +
-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, is 1024 on most systems). "Files" include network sockets, so you need one for every concurrent session (especially if you use connection-oriented transportslike TCP/TLS).+
  
 Example of usage: Example of usage:
  
-    open_files_limit=2048+<code c> 
 +$vn(x) 1; 
 +$vn(x) = "abc"; 
 +$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 (DFbit will be set in outbound IP packets. +
- +
-  pmtu_discovery = 0 | 1 (default 0) +
- +
-==== port ==== +
- +
-The port the SIP server listens toThe 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: +
- +
-<code> +
-pv_buffer_size=2048+
 </code> </code>
 +===== $shv(name) - Shared memory variables =====
  
-==== pv_buffer_slots ====+**$shv(name)**  - it is a class of pseudo-variables stored in shared memory. The value of $shv(name) is visible across all Kamailio processes. Each “shv” has single value and it is initialised to integer 0. You can use “shvset” parameter of **pv module** to initialize the shared variable. The module exports a set of RPC functions to get/set the value of shared variables.
  
-The number of internal buffer slots to print dynamic strings with pseudo-variables inside. The default value is 10. +Example - shv(name) pseudo-variable usage:
- +
-Example of usage:+
  
 <code> <code>
-pv_buffer_slots=12+... 
 +modparam("pv", "shvset", "debug=i:1"
 +... 
 +if ($shv(debug) == 1) { 
 + xlog("request: $rm from $fu to $ru\n"); 
 +
 +...
 </code> </code>
  
-==== pv_cache_limit ====+<fc #0000ff>It is R/W variable (you can assign values to it directly in configuration file)</fc>
  
-The limit how many pv declarations in the cache after which an action is taken. Default value is 2048.+===== $dsv(key) - Dispatcher variables =====
  
-<code> +Return attributes related to dispatcher module.
-pv_cache_limit=1024 +
-</code>+
  
-==== pv_cache_action ====+The key can be:
  
-Specify what action to be done when the size of pv cache is exceeded. If 0print 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 of event_route 'dispatcher:dst-up' or 'dispatcher:dst-down'if available 
 +  * reason - the SIP response reason that caused the execution of event_route 'dispatcher:dst-up' or 'dispatcher:dst-down', if available 
 +  * flags - flags set internally when executing event_route 'dispatcher:dst-up' or 'dispatcher:dst-down' 
 +===== $time(name- Broken-down time =====
  
-<code> +**$time(name)** - the PV provides access to broken-down time attributes in the local timezone.
-pv_cache_action=1 +
-</code>+
  
-==== rundir ====+The 'name' can be: 
 +  * 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(namepseudo-variable usage:
- +
-Set the folder for creating runtime files such as MI fifo or CTL unixsocket. +
- +
-Default: /var/run/kamailio +
- +
-Example of usage: +
- +
-<code> +
-rundir="/tmp" +
-</code> +
- +
-==== received_route_mode ==== +
- +
-Enable or disable the execution of event_route[core:msg-received] routing block or its corresponding Kemi callback. +
- +
-Default value: 0 (disabled) +
- +
-Example of usage:+
  
 <code c> <code c>
-received_route_mode=1+... 
 +if ($time(year) == 2008) { 
 +    xlog("request: $rm from $fu to $ru in year 2008\n"); 
 +
 +...
 </code> </code>
  
-==== reply_to_via ====+===== $utime(name) - Broken-down time =====
  
-If it is set to 1, any local reply is sent to the IP address advertised in top most Via of the request instead of the IP address from which the request was received. Default value is 0 (off).+**$utime(name)** - the PV provides access to broken-down time attributes in UTC.
  
-Example of usage:+See **$time(name)** above for the possible attributes 
 +===== $timef(format) - Strftime Formatted Time =====
  
-    reply_to_via=0 +**$timef(format)** return current time as formatted by strftime 'format'See 'man strftime' to see the available time attribute specifiers.
-     +
- +
-==== 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-IdIn other words, enables Kamailio to execute the config script sequentially for the requests and replies received within the same dialog -- a new message received within the same dialog waits until the previous one is routed out. +
- +
-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("Today is $timef(%m/%d/%y)\n");
 </code> </code>
  
-Note that ordering of the SIP messages can still be changed by network transmission (quite likely for UDP, especially on long distance pathsor CPU allocation for processes when executing pre-config and post-config tasks (very low chance, but not to be ruled out completely). +===== $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, such as IP addresses are the same.+**$utimef(format)** - return current time in UTC as formatted by strftime 'format'. See 'man strftime' to see the available time attribute specifiers.
  
-<code c> +Example:
-  server_id = number +
-</code> +
- +
-==== 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 of usage:+
  
 <code c> <code c>
-server_header="ServerMy Super SIP Server"+xlog("The time is $utimef(%m/%d/%y %H:%M:%S)\n");
 </code> </code>
  
-==== server_signature ====+===== $ccp(key) - Config Custom Parameters =====
  
-This parameter controls the "Server" header in any locally generated message. +Get the value for global custom parameters:
  
-Example of usage:+  * https://www.kamailio.org/wiki/cookbooks/devel/core#custom_global_parameters
  
-     server_signature=no 
  
-If it is enabled (default=yes) a header is generated as in the following example: +Example:
- +
-     Server: Kamailio (<version> (<arch>/<os>)) +
- +
-==== shm_force_alloc ==== +
-Tries to pre-fault all the shared memory, before starting. When "on", start time will increase, but combined with mlock_pages will guarantee Kamailio will get all its memory from the beginning (no more kswapd slow downs) +
- +
-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 1 +gv.sval "hello" desc "hello var" 
-</code>+gv.ival = 10 desc "ten var"
  
-==== sip_parser_mode ==== +request_route { 
- +    xinfo("global vars: $ccp(gv.sval) :: $ccp(gv.ival)\n"); 
-Control sip parser behaviour. +}
- +
-If set to 1, the parser is more strict in accepting messages that have invalid headers (e.g., duplicate To or From). It can make the system safer, but loses the flexibility to be able to fix invalid messages with config operations. +
- +
-If set to 0, the parser is less strict on checking validity of headers. +
- +
-Default: 1 +
- +
-<code c> +
-sip_parser_mode = 0+
 </code> </code>
  
-==== sip_warning (noisy feedback) ====+===== $sel(name- Selects =====
  
-Can be 0 or 1. If set to 1 (default value is 0) a 'Warning' header is added to each reply generated by Kamailio. +**$sel(name)** - return the value of **select** specified by name. **select** refers class of config variables introduced by SER 2.0allowing to select and return parts of sip messages and not only.
-The header contains several details that help troubleshooting using the network traffic dumpsbut might reveal details of your network infrastructure and internal SIP routing.+
  
-Example of usage:+List of available selects: 
 +  * http://www.kamailio.org/wiki/cookbooks/devel/selects
  
-    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**, **tcp_children** and **sctp_children** are used as usually. +
- +
-Example for udp sockets:+
  
 <code c> <code c>
-children=4 
-socket_workers=2 
-listen=udp:127.0.0.1:5080 
-listen=udp:127.0.0.1:5070 
-listen=udp:127.0.0.1:5060 
-</code> 
  
-  * it will start 2 workers to handle traffic on udp:127.0.0.1:5080 and 4 for each of udp:127.0.0.1:5070 and udp:127.0.0.1:5060. In total there are 10 worker processes +if($sel(via[1].host)=="10.10.10.10") 
- +{ 
-Example for tcp sockets: +  ...
- +
-<code c> +
-children=+
-socket_workers=+
-listen=tcp:127.0.0.1:5080 +
-listen=tcp:127.0.0.1:5070 +
-listen=tcp:127.0.0.1:5060 +
-</code> +
- +
-  * it will start 2 workers to handle traffic on tcp:127.0.0.1:5080 and 4 to handle traffic on both tcp:127.0.0.1:5070 and tcp:127.0.0.1:5060. In total there are 6 worker processes +
- +
-==== 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" moduleor by the script writer using the "statistics" module. +
- +
-The statistics counters are read/updated either automatically by Kamailio internally (e.gtcp counters), by the script writer via the module functions of the "statistics" module, by the script writer using the $stat() pseudo variable (read-only), or via MI commands. +
- +
-Following are some examples how to access statistics variables: +
- +
-**script** +
-<code> +
-modparam("statistics", "variable", "NOTIFY"+
- +
-(if method == "NOTIFY") { +
-  update_stat("NOTIFY", "+1");+
 } }
- 
-xlog("Number of received NOTIFYs: $stat(NOTIFY)"); 
 </code> </code>
-**MI** +===== Received Data Attributes =====
-<code> +
-# 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 +
-</code>+
  
 +Attributes of received data. The variables must be used inside **event_route[core:msg-received]** routing block.
  
-==== stats_name_separator ====+The key can be:
  
-Specify the character used as a separator for the internal statistics' names.  +  * 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 as string 
 +  * 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 "local" headers) > udp_mtu, use this protocol instead of udp. Only the Via header will be updated (e.g. The Record-Route will be the one built for udp). 
- 
-**Warning:** Although RFC3261 mandates automatic transport protocol changing, enabling this feature can lead to problems with clients which do not support other protocols or are behind a firewall or NAT. Use this only when you know what you do! 
- 
-See also udp_mtu_try_proto(proto) function. 
- 
-Default: UDP (off). Recommended: TCP. 
- 
-  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:msg-received] { 
 +  xlog("rcv on $rcv(af)/$rcv(proto): ($rcv(len)) [$rcv(buf)] from [$rcv(srcip):$rcv(srcport)] to [$rcv(rcvip):$rcv(rcvport)]\n"); 
 +}
 </code> </code>
-==== 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. The variables must be used during SIP reply processing, otherwise it returns $null.
  
-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 
-    user="kamailio" +  * dhost - host part of duri 
-</code>+  * 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 of usage:
- +
-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-AgentMy Super SIP Server"+reply_route{ 
 +  xinfo("reply to be sent to$rpl(duri)\n"); 
 +}
 </code> </code>
  
-==== verbose_startup ====+===== $msgbuf(index) =====
  
-Control if printing routing tree and udp probing buffer debug messages should be printed at startup.+Get or set the character in the message buffer at the position index.
  
-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 of usage: +
- +
-<code c> +
-   verbose_startup=1 +
-</code>+
  
-==== version_table ====+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).
  
-Set the name of the table holding the table version. Useful if the proxy is sharing a database within a project and during upgrades. Default value is "version".+The update is done directly and immediately in the message buffer -- use it with care!
  
 Example of usage: Example of usage:
  
 <code c> <code c>
-   version_table="version44"+if ($msgbuf(20)=="V") { 
 +    $msgbuf(20) = "v"
 +}
 </code> </code>
 +===== Header Field Iterator =====
  
-==== wait_worker1_mode ====+==== $hfitname(iname) ====
  
-Enable waiting for child SIP worker one to complete initialization, then create the other child worker processes. +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("i1"); 
 +    while(hf_iterator_next("i1")) { 
 +        xlog("hdr[$hfitname(i1)] is: $hfitbody(i1)\n"); 
 +    } 
 +    hf_iterator_end("i1");
 </code> </code>
  
-==== wait_worker1_time ====+==== $hfitbody(iname) ====
  
-How long to wait for child worker one to complete the initialization. In micro-seconds. +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("i1"); 
 +    while(hf_iterator_next("i1")) { 
 +        xlog("hdr[$hfitname(i1)] is: $hfitbody(i1)\n"); 
 +    } 
 +    hf_iterator_end("i1");
 </code> </code>
  
-==== 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("b1"); 
 +    while(bl_iterator_next("b1")) { 
 +        xlog("body line: $blitval(b1)"); 
 +    } 
 +    bl_iterator_end("b1");
 </code> </code>
  
-==== 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 of usage:+**$snd(name)** - return attributes of the address from where the request is going to be sent (local socket).
  
-     wdir="/usr/local/kamailio" +**$sndfrom(name)** - return attributes of the address from where the request is going to be sent (local socket, same as $snd(name)).
-     or +
-     wdir=/usr/kam_wd+
  
-==== 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 is not applied (default behaviour).+**$sndto(name)** - return attributes of the address to where the request is going to be sent (remote socket).
  
-If set, local Via header gets additional parameters from defined XAVPCore flag FL_ADD_XAVP_VIA_PARAMS needs to be set¹. +They are available in **onsend_route**The name can be:
- +
-Example: +
-     xavp_via_params="via" +
-[1] See function //via_add_xavp_params()// from "corex" module.+
  
-==== xavp_via_fields ==== +  * ip - IP address of destination 
- +  * af - address family to be used to send (numeric) 
-Set the name of xavp from where to take Via header field: address and port. +  * port - port of destination address 
-Use them to build local Via header.+  * proto - transport protocol to be used to send (numeric - UDP=1, TCP=2, TLS=3, SCTP=4, WS=5, WSS=6) 
 +  * sproto - transport protocol to be used to send (string) 
 +  * buf - entire send buffer as string 
 +  * len - length of outgoing packet (length of above buf)
  
 Example: Example:
  
 <code c> <code c>
-xavp_via_fields="customvia" 
  
-request_route +onsend_route 
-  ... +  if($snd(ip)=="10.10.10.10") 
-  $xavp(customvia=>address) = "1.2.3.4"+  
-  $xavp(customvia=>port= "5080";  # must be string +    ... 
-  via_use_xavp_fields("1"); +  }
-  t_relay();+
 } }
 </code> </code>
-      
-See function //via_use_xavp_fields()// from "corex" module. 
  
-===== DNS Parameters =====+===== SIPDUMP Module =====
  
-Note: See also file doc/dns.txt for details about Kamailio's DNS client.+==== $sipdump(name) ====
  
-Kamailio has an internal DNS resolver with caching capabilities. If this caching resolver is activated (default setting) then the system's stub resolver won't be used. Thus, also local name resolution configuration like /etc/hosts entries will not be used. If the DNS cache is deactivated (use_dns_cache=no), then system's resolver will be used. The DNS failover functionality in the tm module references directly records in the DNS cache (which saves a lot of memory) and hence DNS based failover only works if the internal DNS cache is enabled.+**$sipdump(name)** - return attributes of the message handled in the event_route[sipdump:msg].
  
-^ DNS resolver comparison   ^ internal resolver ^ system resolver ^ +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 /etc/resolv.conf as caching nameservers.+  tag - the tag of processing (rcv or snd) 
 +  * buf - entire message buffer as string 
 +  * 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/cache is enabled you can add/remove records by hand (using kamcmd or xmlrpc) using the DNS RPCs, e.g. dns.add_a, +Example:
-dns.add_srv, dns.delete_a a.s.o. For more info on DNS RPCs see http://www.kamailio.org/docs/docbooks/devel/rpc_list/rpc_list.html#dns.add_a+
  
-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>
  
-NoteThe dns cache uses the DNS servers configured on your server (/etc/resolv.conf), therefore even if you use the internal resolver you should have a working DNS resolving configuration on your server.+event_route[sipdump:msg] { 
 +  if($sipdump(len> 1024) { 
 +    ... 
 +  } 
 +
 +</code>
  
-Kamailio also allows you to finetune the DNS resolver settings. 
  
-The maximum time a dns request can take (before failingis (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:msg].
  
-Note: During DNS lookups, the process which performs the DNS lookup blocks. To minimize the blocked time the following parameters can be used (max 2s):+The name can be:
  
-  dns_try_ipv6=no +  * src_addr - source socket address (proto:ip:port) 
-  dns_retr_time=1 +  * dst_addr - destination socket address (proto:ip:port) 
-  dns_retr_no=1 +  * src_host - source host, for IPv6 host contains `[]` 
-  dns_use_search_list=no+  * dst_host - destination host, for IPv6 host contains `[]` 
 +  * 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_ipparameter to the Via is necessary. Note that Vias containing +<code c
-DNS names (instead of IPsshould have received= addedso turning dns to yes is not recommended.+event_route[siptrace:msg] 
 +
 +    if (allow_address("1", "$siptrace(src_hostip)""0")) { 
 +        return;
  
-Default is no.+    } 
 +    if (compare_ips($siptrace(src_host), "[2001:DB8::1]")) { 
 +        return; 
 +    } 
 +
 +</code>
  
-==== 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=<src_ip> parameter to the Via is necessary (if the Via contains a DNS name instead of an IP address, the result of the reverse dns on the source IP will be compared with the DNS name in the Via). +
-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 receivedadded, so turning rev_dns to yes is not recommended.  +
- +
  
-Default is no.+==== $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 of the current processed dialog.
-    allow deletion of non-expired records from the cache when there is no more space +
-    left for new ones. The last-recently used entries are deleted first.+
  
-==== dns_cache_rec_pref ==== +<fc #0000ff>It is R/O variable.</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 'attr' can be: 
-  dns_cache_flags = number (default 0) -  +  * h_id hash id 
-    dns cache specific resolver flags, used for overriding the default behaviour (low level). +  * h_entry - hash entry 
-    Possible values: +  * ref - reference count 
-      ipv4 only: only DNS A requests are performed, even if Kamailio also listens on ipv6 addresses. +  * state - state of dialog 
-      ipv6 only: only DNS AAAA requests are performed. Ignored if dns_try_ipv6 is off or Kamailio  +  * to_rs - To route set 
-          doesn't listen on any ipv6 address. +  * from_rs - From route set 
-      prefer ipv6: try first to resolve a host name to an ipv6 address (DNS AAAA request) and only +  * dflags - dialog internal flags 
-          if this fails try an ipv4 address (DNS A request). By default the ipv4 addresses are preferred.+  * sflags - dialog script flags 
 +  * callid sip call id 
 +  * to_uri 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 address 
 +  * from_contact From contact address 
 +  * 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 #0000ff>Some of the attributes are R/W variables.</fc>
  
-==== dns_cache_init ====+The 'attr' can be: 
 +  * 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 #0000ff>It is R/W variable.</fc>
-  dns_cache_max_ttl = time in seconds (default MAXINT)+
  
-==== dns_cache_mem ==== +The 'key' can be any string.
-Maximum memory used for the dns cache in KB (default 500 K)+
  
-  dns_cache_mem number+===== 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 in cache If set to 0, disables caching of negative responses. Default is 60 (seconds).+* format - prints a term, in clear textIt 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 preferencesas indicated by the Order field in the NAPTR records and mandated by RFC 2915.+//$erl_atom(name)// pseudo variable allows create analog to Erlang atom data type. 
 +Erlang atom is a literala constant with name. Formatted output pseudo variable 
 +atom could be enclosed in single quotes (') if it does not begin with a  
 +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) "node@host.tld";
  
-Number of dns retransmissions before giving up. Default value is system specificdepends also on the '/etc/resolv.conf' content (usually 4).+xlogl("L_DEBUG","$$erl_atom(A): $erl_atom(A=>format)\n"); 
 +</code>
  
-Example of usage:+==== $erl_list(name) ==== 
 +Compound data type with a variable number of terms. Formally, a list is either 
 +the empty list [] or consists of one or more elements.
  
-    dns_retr_no=3+Example:
  
-==== dns_retr_time ====+<code c> 
 +$erl_atom(E) "example"; 
 +$erl_list(L) "list"; 
 +$erl_list(L) "of"; 
 +$erl_list(L) $erl_atom(E);
  
-Time in seconds before retrying a dns request. Default value is system specificdepends also on the '/etc/resolv.conf' content (usually 5s).+xlogl("L_DEBUG","length(L): $erl_list(L=>length), format(L): $erl_list(L=>format)\n");
  
-Example of usage:+# empty list 
 +$erl_tuple(E[*]) = $null; 
 +</code>
  
-    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= "error";
  
-==== dns_servers_no ====+$erl_tuple(T) "badrpc"; 
 +$erl_tuple(T) $erl_atom(e);
  
-How many dns servers from the ones defined in '/etc/resolv.conf' will be used. Default value is to use all of them.+xlogl("L_DEBUG","length(T): $erl_tuple(T=>length), format(T): $erl_tuple(T=>format)\n"); 
 +</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 (see doc/dns.txt)+==== $sht(htable=>key====
  
-  dns_srv_lb = yes | no (default no)+Access hash table entries.
  
-==== dns_try_ipv6 ====+<fc #0000ff>It is R/W variable, you can assign values to it directly in configuration file.  Hash table entry can be deleted by assigning value $null to it.  Value of a non-existing hash table entry is $null.</fc>
  
-Can be 'yes' or 'no'. If it is set to 'yes' and DNS lookup fails, it will retry it +The “htname” must be a hash table name defined via “htable” parameter.
-for ipv6 (AAAA record). Default value is 'no'.+
  
-NoteIf dns_try_ipv6 is off, no hostname resolving that would result in an ipv6 address would succeed - it doesn't matter if an actual DNS lookup is to be performed or the host is already an ip address. Thus, if the proxy should forward requests to IPv6 targets, this option must be turned on!+The “key” can be:
  
-Example of usage:+  * 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+<code> 
 +... 
 +modparam("htable", "htable", "a=>size=4;"
 +... 
 +$sht(a=>$au) = 1; 
 +$sht(a=>$ru) = $fu; 
 +... 
 +</code>
  
-==== dns_try_naptr ==== +==== $shtex(htable=>key) ====
-Enable NAPTR support according to RFC 3263 (see doc/dns.txt for more info) +
-     +
-  dns_try_naptr yes | no (default no)+
  
-==== dns_sctp_pref, dns_tcp_pref, dns_tls_pref, dns_udp_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_preferencedns_tcp_preference, dns_tls_preference, dns_udp_preference**+<fc #0000ff>It is R/W variableyou can assign values to it directly in configuration file.</fc>
  
-Set preference for each protocol when doing naptr lookups. By default dns_udp_pref=30, dns_tcp_pref=20,  +The “htname” must be a hash table name defined via “htable” parameter and have auto-expire greater than 0.
-dns_tls_pref=10 and dns_sctp_pref=20. To use the remote site preferences set all dns_*_pref to the same positive value (e.g. dns_udp_pref=1, +
-dns_tcp_pref=1, dns_tls_pref=1, dns_sctp_pref=1). To completely ignore NAPTR records for a specific protocol, set the corresponding protocol  +
-preference to -1 (or any other negative number). (see doc/dns.txt for more info)+
  
-  dns_{udp,tcp,tls,sctp}_pref = number+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 'yes' or 'no'If set to 'no'the search list in '/etc/resolv.conf' will be ignored (=> fewer lookups => gives up faster). Default value is 'yes'.+<code> 
 +... 
 +modparam("htable""htable", "a=>size=4;autoexpire=120;"
 +... 
 +$sht(a=>$au) = 1; 
 +$shtex(a=>$au= 10; 
 +..
 +</code>
  
-HINT: even if you don't have a search list defined, setting this option to 'no' will still be "faster", because an empty search list is in fact search "" (so even if the search list is empty/missing there will still be 2 dns queries, eg. foo+'.' and foo+""+'.') 
  
-Example of usage:+==== $shtcn(htable=>exp) ====
  
-    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's stub resolver) will be used.  If set to "off", disables caching of DNS responses and, as side effect, DNS failover. Default is "on". Settings can be changed also during runtime (switch from internal to system resolver and back).+The **exp** can be:
  
-==== use_dns_failover ==== +  * reqexp - match by regular expression 'regexp' 
-use_dns_failover = on | off (default off)+  * ~~regexp - match by regular expression 'regexp' 
 +  * ~%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.+<code> 
 +... 
 +modparam("htable", "htable", "a=>size=4;"
 +... 
 +$sht(a=>abc) = 1; 
 +$shtex(a=>ade) = 10; 
 +xlog("$shtcn(a=>a.*)"); 
 +... 
 +</code>
  
-==== disable_tcp ====+==== $shtcv(htable=>exp) ====
  
-Global parameter to disable TCP support in the SIP server. Default value is 'no'.+Count items matching the value by regexp.
  
-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 ====+<code> 
 +... 
 +modparam("htable", "htable", "a=>size=4;") 
 +... 
 +$sht(a=>abc) "xyz"; 
 +$shtex(a=>ade) "xwt"; 
 +xlog("$shtcv(a=>x.*)"); 
 +... 
 +</code>
  
-If a message received over a tcp connection has "alias" in its via a new tcp alias port will be created for the connection the message came from (the alias port will be set to the via one).+==== $shtinc(htable=>key====
  
-Based on draft-ietf-sip-connect-reuse-00.txt, but using only the port (host aliases are dangerous, involve extra DNS lookups and the need for them is questionable)+Atomic increment of the value for the hash table item.
  
-See force_tcp_alias for more details. +<code> 
- +..
-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+modparam("htable", "htable", "a=>size=4;") 
- +... 
-Default is "no(off+$sht(a=>$au) 1; 
- +xlog("==== $shtinc(a=>$au)\n"); 
-   tcp_accept_aliasesyes|no +...
-    +
-==== 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 (v1and binary-encoded (v2variants of the protocol are supported. This option is typically useful if you are behind a TCP load-balancer, such as HAProxy or an AWS' ELB, and allows the load-balancer to provide connection information regarding the upstream client. This enables the use of IP-based ACLs, even behind a 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/download/1.8/doc/proxy-protocol.txt +
- +
-Default value is **no**. +
- +
-<code c> +
-tcp_accept_haproxy=yes+
 </code> </code>
  
-==== tcp_accept_hep3 ====+==== $shtdec(htable=>key) ====
  
-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> 
- +..
-<code c+modparam("htable", "htable", "a=>size=4;") 
-tcp_accept_hep3=yes+... 
 +$sht(a=>$au) = 1; 
 +xlog("==== $shtdec(a=>$au)\n"); 
 +...
 </code> </code>
  
-==== 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 module **sanity** can be used then to restrict this permission to HTTP traffic only, testing in route block in order to stay RFC3261 compliant about this mandatory header for SIP requests over TCP.+The key at the current position in the iterator.
  
-Default value is **no**.+==== $shtitval(iname) ====
  
-<code c> +The value at the current position in the iterator.
-tcp_accept_no_cl=yes +
-</code>+
  
-==== 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("i1", "h1"); 
 +    while(sht_iterator_next("i1")) { 
 +        xlog("h1[$shtitkey(i1)] is: $shtitval(i1)\n"); 
 +    } 
 +    sht_iterator_end("i1");
 </code> </code>
-==== 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:expired:_table_name_].
  
-**Note:** It also applies for TLS.+The id can be:
  
-  tcp_async = yes | no (default yes) +  * key 
-  +  * value
  
-==== 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 "children" parameter) will be used. +
- +
-Example of usage: +
- +
-    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/Firewalls, the SIP proxy should not close the TCP connection as it is not capable of opening a new one. +
- +
-Example of usage: +
- +
-    tcp_connection_lifetime=3605 +
- +
-==== tcp_connection_match ==== +
- +
-If set to 1, try to be more strict in matching outbound TCP connections, attempting to lookup first the connection using also local port, not only the local IP and remote IP+port. +
- +
-Default is 0.+
  
 <code c> <code c>
-tcp_connection_match=1+event_route[htable:expired:h1] { 
 +  xlog("expired item ($shtrecord(key),$shtrecord(value))\n"); 
 +}
 </code> </code>
-==== 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 #0000ff>It is R/W variable, you can assign values to it directly in configuration file.</fc>
  
-==== tcp_conn_wq_max ====+The “key” can be:
  
-Maximum bytes queued for write allowed per connectionAttempting 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-variablesThe pseudo-variables will be evaluated at runtime.
  
-  tcp_conn_wq_max = bytes (default 32 K) +When assigning values, the default expiry will be used.
-   +
-==== tcp_crlf_ping ==== +
-Enable SIP outbound TCP keep-alive using PING-PONG (CRLFCRLF -  CRLF).+
  
-  tcp_crlf_ping yes | no default: yes+<code> 
 +... 
 +$mct($au) 1; 
 +$mct($ru) = $fu; 
 +$mct(test) = 1; 
 +xlog("stored value is $mct(test)"); 
 +$mct(test) = null; # delete it 
 +xlog("stored value is $mct(test)"); # will return <null> 
 +... 
 +</code>
  
 +==== $mct(key=>expiry) ====
  
-==== 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 (improves performance on proxies with lots of opened tcp connections). See linux tcp(7TCP_DEFER_ACCEPT or freebsd ACCF_DATA(0). For now linux and freebsd only.+<code> 
 +... 
 +$mct(test=>30= 1; # set expire time to 30 seconds 
 +xlog("stored value is $mct(test)"); 
 +# sleep 30 seconds 
 +xlog("stored value is $mct(test)"); # will return <null> 
 +... 
 +</code>
  
-WARNING: the  linux TCP_DEFER_ACCEPT is buggy (<=2.6.23) and doesn't work exactly as expected (if no data is received it will retransmit syn acks for ~ 190 s, irrespective of the set timeout and then it will silently drop the connection without sending a RST or FIN). Try to use it together with tcp_syncnt (this way the number of retrans. SYNACKs can be limited => the timeout can be controlled in some way).+==== $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 #0000ff>It is R/W variable, you can assign values to it directly in configuration file.</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  = yes | no (default yes when supported)+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 (performance increase for sending over tcp at the cost of slightly slower connection closing and extra FDs kept open)+<code> 
 +... 
 +$mct(cnt= 1; 
 +$mcinc(cnt) = 2; # increment by 2 
 +xlog("counter is now $mct(cnt)"); 
 +... 
 +</code>
  
-  tcp_fd_cache yes | no (default yes)+==== $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 #0000ff>It is R/W variable, you can assign values to it directly in configuration file.</fc>
  
-==== tcp_keepcnt ==== +The “key” can be:
-Number of keepalives sent before dropping the connection (TCP_KEEPCNT socket option). Linux only.+
  
-  tcp_keepcnt = number (not set by default)+  * 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_keepidle ====+<code> 
 +... 
 +$mct(cnt) 10; 
 +$mcdec(cnt) 2; # decrement by 2 
 +xlog("counter is now $mct(cnt)"); 
 +... 
 +</code>
  
-Time before starting to send keepalives, if the connection is idle (TCP_KEEPIDLE socket option). Linux only.+===== http_async_client Module =====
  
-  tcp_keepidle  seconds (not set by default)+==== $http_req_id ====
  
-==== tcp_keepintvl ==== +The $http_req_id read-only variable can be used in REQUEST_ROUTE to retrive the unique identifier for a query after sending it or in the HTTP callback route to retrive the id of the query the reply belongs toUseful mainly in non-transactional context.
-Time interval between keepalive probes, when the previous probe failed (TCP_KEEPINTVL socket option)Linux only.+
  
-  tcp_keepintvl seconds (not set by default)+==== $http_req(key====
  
-==== tcp_linger2 ==== +The $http_req(keywrite-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 (not set by default)+**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/modifies/removes a HTTP header. N.B.: setting this variable multiple times will add several headers to the query. 
 +  * body: sets/modifies/removes the request body 
 +  * method: sets the HTTP method: either "GET", "POST", "PUT" or "DELETE" (these are the supported methods). (Note: if the method is not set, curl will use GET, or POST if a body is specified) 
 +  * 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: sets the client certificate to use 
 +  * tls_client_key: sets the client certificate key to use 
 +  * tls_ca_path: sets the CA certificate path to use 
 +  * 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't suspend the current transaction before performing the query 
 +  * tcp_keepalive: enable TCP keepalive 
 +  * tcp_ka_idle: set TCP keepalive idle time wait 
 +  * tcp_ka_interval: set TCP keepalive 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 in tcp_init.h: #define DEFAULT_TCP_MAX_CONNECTIONS 2048+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, 0 otherwise (check $http_err for details).
  
-    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 timeeven even if Kamailio is already started (in this case using the command "kamcmd cfg.set_now_int tcp no_connect 1").+=== $http_hdr(Name) === 
 +Value of the Name header (the $(http_hdr(Name)[N]) syntax can also be usedcheck the SIP $hdr() PV documentation for details).
  
-==== 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 and poll_types.h: none, poll, epoll_lt, epoll_et, sigio_rt, select, kqueue/dev/poll+=== $http_rb and $http_bs === 
 +HTTP response body and body length,
  
-Example of usage:+===== XMLOPS Pseudo-Variables =====
  
-    tcp_poll_method=select+==== $xml(name=>spec) ====
  
-==== tcp_rd_buf_size ====+  * name - id to refer the documet 
 +  * spec - specifier: 
 +    * doc - set/get the document as text 
 +    * xpath:xpath-expression - evaluate xpath expression
  
-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 "rd_buf_size" and 16777216). Further, you may need to increase the private memory, and if you process the message stateful you may also have to increase the shared memory. +<code> 
- +$xml(x=>doc= '<?xml version="1.0" encoding="UTF-8"?><a><b>test</b></a>'; 
-Default4096, can be changed at runtime. +xlog("content of node b$xml(x=>xpath:/a/b/text())\n"); 
- +$xml(x=>xpath:/a/b) = "1234";
-<code c+
-tcp_rd_buf_size=65536+
 </code> </code>
-==== 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[], the value is the index of the branch receiving the reply 
 +  * if used outside of transaction processing, the value is '-1'
  
-==== tcp_source_ipv4, tcp_source_ipv6 ====+==== $T_reply_ruid ====
  
-Set the source IP for all outbound TCP connectionsIf setting of the IP fails, the TCP connection will use the default IP address.+  * the ruid stored in the current branch of the transactionThe ruid is stored in a branch from the details in a contact binding. In a event_route[tm:branch-failure] block, this is the ruid of the branch that sent a failure reply. In a failure_route[] blockthis is the ruid of the winning failure response.
  
-  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_syncnt = number of syn retr(default not set)+  * the code of the reply, as follows: in request_route will be the last stateful sent reply; in reply_route will be the current processed reply; in failure_route will be the negative winning replyIn case of no-reply or error, '0' value is returned
  
-==== 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 changed at runtime.+  * 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 ====+<code> 
 +route { 
 +  t_on_reply("1"); 
 +  t_relay(); 
 +}
  
-Maximum bytes queued for write allowed globally. It has no effect if tcp_buf_write is not enabled.+onreply_route[1] { 
 +  xlog("Request SRCIP:PORT = $T_req($si):$T_req($sp)\n"); 
 +
 +</code>
  
-  tcp_wq_max bytes (default 10 Mb) +==== $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 as an UAC. Kamailio must have been compiled in a system implementing SO_REUSEPORT (Linux 3.9.0, FreeBSD, OpenBSD, NetBSD, MacOSX). This parameter takes effect only if also the system on which Kamailio is running on supports SO_REUSEPORT.+  * can be used in failure routes or inside the modules to get access to attributes of the winning reply belonging to same transaction as the request 
 +<code> 
 +route { 
 +  t_on_failure("1")
 +  t_relay(); 
 +}
  
-  tcp_reuse_port yes (default no)+failure_route[1] { 
 +  xlog("Reply SRCIP:PORT $T_rpl($si):$T_rpl($sp)\n")
 +
 +</code>
  
-===== TLS Parameters =====+==== $T_inv(pv) ====
  
-Most of TLS layer attributes can be configured via TLS module parameters. +  * can be used in request routes or inside the modules to get access to attributes of the INVITE request while processing CANCEL.
- +
-==== tls_port_no ==== +
- +
-The port the SIP server listens to for TLS connections. +
- +
-Default value is 5061. +
- +
-Example of usage: +
- +
-    tls_port_no=6061 +
- +
-==== tls_max_connections ==== +
- +
-Maximum number of ls connections (if the number is exceeded no new ls connections will be accepted). It cannot exceed tcp_max_connections. +
- +
-Default value is 2048. +
- +
-Example of usage: +
- +
-    tls_max_connections=4096 +
-===== SCTP Parameters ===== +
- +
-==== disable_sctp ==== +
- +
-Global parameter to disable SCTP support in the SIP server. see enable_sctp +
- +
-Default value is 'auto'+
- +
-Example of usage: +
- +
-    disable_sctp=yes +
- +
-==== enable_sctp ==== +
- +
-  enable_sctp = 0/1/2  - SCTP disabled (0)/ SCTP enabled (1)/auto (2),  +
-                         default auto (2) +
- +
-==== sctp_children ==== +
-sctp children no (similar to udp children) +
-  sctp_children = number  +
- +
-==== sctp_socket_rcvbuf ==== +
-Size for the sctp socket receive buffer +
- +
-**Alias name: sctp_socket_receive_buffer** +
- +
-  sctp_socket_rcvbuf = number  +
- +
-==== sctp_socket_sndbuf ==== +
-Size for the sctp socket send buffer +
- +
-**Alias name: sctp_socket_send_buffer** +
- +
-  sctp_socket_sndbuf = number +
- +
-==== 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_autoclose = seconds +
- +
-==== sctp_send_ttl ==== +
-Number of milliseconds before an unsent message/chunk is dropped (default: 32000 ms or 32 s). Can be changed at runtime, e.g.: +
-  $ kamcmd cfg.set_now_int sctp send_ttl 180000 +
- +
-  sctp_send_ttl = milliseconds - n +
- +
-==== sctp_send_retries ==== +
-How many times to attempt re-sending a message on a re-opened association, if the sctp stack did give up sending it (it's not related to sctp protocol level retransmission). Useful to improve reliability with peers that reboot/restart or fail over to another machine.  +
- +
-WARNING: use with care and low values (e.g. 1-3) to avoid "multiplying" traffic to unresponding hosts (default: 0).Can be changed at runtime. +
- +
-  sctp_send_retries = 1 +
- +
-==== sctp_assoc_tracking ==== +
-Controls whether or not sctp associations are tracked inside Kamailio. Turning it off would result in less memory being used and slightly better performance, but it will also disable some other features that depend on it (e.g. sctp_assoc_reuse). Default: yes. +
- +
-Can be changed at runtime ("kamcmd sctp assoc_tracking 0"), but changes will be allowed only if all the other features that depend on it are turned off (for example it can be turned off only if first sctp_assoc_reuse was turned off). +
- +
-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. +
- +
-Config options depending on sctp_assoc_tracking being on: sctp_assoc_reuse. +
- +
-  sctp_assoc_tracking = yes/no +
- +
-==== sctp_assoc_reuse ==== +
-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. +
-Can be changed at runtime (sctp assoc_reuse), but it can be turned on only if sctp_assoc_tracking is on. +
- +
-  sctp_assoc_reuse = yes/no +
- +
-==== sctp_max_assocs ==== +
-Maximum number of allowed open sctp associations. -1 means maximum allowed by the OS. Default: -1. +
-Can be changed at runtime (e.g.:  "kamcmd cfg.set_now_int sctp max_assocs 10"). When the maximum associations number is exceeded and a new associations is opened by a remote host, the association will be immediately closed. However it is possible that some SIP packets get through (especially if they are sent early, as part of the 4-way handshake). +
- +
-When Kamailio tries to open a new association and the max_assocs is exceeded the exact behaviour depends on whether or not +
-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). +
- +
- +
- +
-  sctp_max_assocs = number +
- +
-==== sctp_srto_initial ==== +
-Initial value of the retr. timeout, used in RTO calculations (default: OS specific).  +
- +
-Can be changed at runtime (sctp srto_initial) but it will affect only new associations. +
- +
-  sctp_srto_initial = milliseconds +
- +
-==== sctp_srto_max ==== +
-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). +
- +
-Can be changed at runtime (sctp srto_max) but it will affect only new associations. +
- +
-  sctp_srto_max = milliseconds +
- +
-==== sctp_srto_min ==== +
-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   = number +
- +
-==== 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 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).  Default: OS specific.  +
- +
-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 "auto" mode it will be enabled if possible (sr started as root or with CAP_NET_RAW). udp4_raw can be used on Linux and FreeBSD. For other BSDs and Darwin one must compile with -DUSE_RAW_SOCKS. On Linux one should also set udp4_raw_mtu if the MTU on any network interface that could be used for sending is smaller then 1500. +
- +
-The parameter can be set at runtime as long as sr was started with enough privileges (core.udp4_raw).+
  
 <code> <code>
-udp4_raw = on+route { 
 +  if(is_method("CANCEL")) 
 +  { 
 +     if($T_inv($mf) & 1 ) 
 +     { 
 +        # first flag is set in the INVITE transaction 
 +     } 
 +  } 
 +}
 </code> </code>
  
-==== udp4_raw_mtu ====+==== $T(name) ====
  
-MTU value used for UDP IPv4 packets when udp4_raw is enabled.  It should be set to the minimum MTU of all the network interfaces that could be used for sending. The default value is 1500. Note that on BSDs it does not need to be set (if set it will be ignored, the proper MTU will be used automatically by the kernel). On Linux it should be set.+  * pseudo-variable class to access TM attributes
  
-The parameter can be set at runtime (core.udp4_raw_mtu).+The **name** can be:
  
-==== udp4_raw_ttl ====+  * 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, if no transaction exists yet, create it 
 +  * id_label_n - return the internal label of current transaction, if no transaction exists yet, create it 
 +  * 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
  
-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.+Note: the pair (id_index,id_label) uniquely identifies a transaction.
  
-The parameter can be set at runtime (core.udp4_raw_ttl).+==== $T_branch(name====
  
 +  * pseudo-variable class to access TM branch attributes
  
-===== Blocklist Parameters =====+The **name** can be:
  
-==== dst_blocklist_expire ====+  * flags - Flags of the branch. In a event_route[tm:branch-failure] block, this is the flags of the branch that sent a failure reply. In a failure_route[] block, this is the flags of the winning failure response. 
 +  * 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
  
-**Alias name: dst_blocklist_ttl** 
  
-How much time a blocklisted destination will be kept in the blocklist (w/o any update).+===== UAC Module =====
  
-  dst_blocklist_expire time in s (default 60 s)+==== $uac_req(key====
  
-==== dst_blocklist_gc_interval ==== +  * used to build the input for uac_send_req() function of UAC module
-How often the garbage collection will run (eliminating old, expired entries).+
  
-  dst_blocklist_gc_interval time in (default 60 s)+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 
 +  * auser - authentication username 
 +  * apasswd - authentication password 
 +  * sock - local socket to be used for sending (proto:address:port) 
 +  * 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) $null; 
 +  * evroute - it has to be set to 1 in order to execute event_route[uac:reply] when reply is received 
 +  * evcode - reply code for the request sent with uac_req_send(), available inside event_route[uac:reply] 
 +  * 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:reply] 
 +  * 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.
  
-==== dst_blocklist_init ==== +<code c> 
-If off, the blocklist is not initialized at startup and cannot be enabled runtime, that saves some memory.+$uac_req(method)="OPTIONS"; 
 +$uac_req(ruri)="sip:kamailio.org"; 
 +$uac_req(furi)="sip:kamailio.org"; 
 +$uac_req(turi)="sip:kamailio.org"; 
 +$uac_req(evroute) = 1; 
 +uac_req_send(); 
 +... 
 +event_route[uac:reply] { 
 +  xlog("request sent to $uac_req(ruri) completed with code: $uac_req(evcode)\n"); 
 +
 +</code> 
 +===== Nathelper Module =====
  
-  dst_blocklist_init on | off (default on)+==== $rr_count ====
  
-==== dst_blocklist_mem ==== +  * Number of Record Routes in received SIP request or reply.
-Maximum shared memory amount used for keeping the blocklisted destinations.+
  
-  dst_blocklist_mem size in Kb (default 250 Kb)+==== $rr_top_count ====
  
-==== use_dst_blocklist ==== +  * If topmost Record Route in received SIP request or reply is double Record Route, value of $rr_top_count is 2. If it a single Record Routevalue of $rr_top_count is 1. If there is no Record Route(s), value of $rr_top_count is 0.
-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 match is foundthe send is no longer attempted (an error is returned immediately). +
  
-Note: using the blocklist incurs a small performance penalty.+===== MQueue Module =====
  
-See also doc/dst_blocklist.txt.+==== $mqk(q) ====
  
-  use_dst_blocklist = on | off (default off)+  * return the key of fetched item from queue q
  
-===== Real-Time Parameters ===== +==== $mqv(q) ====
-==== real_time ====+
  
-Sets real time priority for all the Kamailio processes, or the timers (bitmask).  
-     Possible values:    - off 
-                        1  - the "fast" timer 
-                        2  - the "slow" timer 
-                        4  - all processes, except the timers 
-     Example: real_time= 7 => everything switched to real time priority. 
  
-  real_time = <int> (flags) (default off) +  * return the value of fetched item from queue q
- +
-==== rt_policy ==== +
-Real time scheduling policy, 0 = SCHED_OTHER, 1= SCHED_RR and 2=SCHED_FIFO +
- +
-  rt_policy= <0..3> (default 0) +
- +
-==== 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 "fast" timer. +
- +
-  rt_timer1_policy=<0..3> (default 0) +
- +
-==== rt_timer1_prio ==== +
- +
-**Alias name: rt_fast_timer_prio, rt_ftimer_prio** +
- +
-Like rt_prio but for the "fast" timer process (if real_time & 1). +
-      +
-  rt_timer1_prio=<int> (default 0) +
- +
-==== rt_timer2_policy ==== +
- +
-**Alias name: rt_stimer_policy** +
- +
-Like rt_policy but for the "slow" timer. +
- +
-  rt_timer2_policy=<0..3> (default 0) +
- +
-==== rt_timer2_prio ==== +
- +
-**Alias name: rt_stimer_prio** +
- +
-Like rt_prio but for the "slow" timer. +
- +
-  rt_timer2_prio=<int> (default 0) +
-===== 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();+... 
 +mq_add("myq", "$rU", "call from $fU at $Tf"); 
 +... 
 +while(mq_fetch("myq")) 
 +
 +   xlog("$mqk(myq) - $mqv(myq)\n"); 
 +
 +...
 </code> </code>
  
-==== avpflags ==== +===== TimeVal =====
-==== break ====+
  
-'break' statement can be used to end a 'case' block in a 'switch' statement or exit from a 'while' statement.+==== $TV(name) ====
  
-==== drop ====+Seconds and microseconds taken from struct timeval. The time at that moment is represented by **seconds.microseconds**.
  
-Stop the execution of the configuration script and alter the implicit action which is done afterwards.+  * $TV(s) - seconds (cached at first call per sip message) 
 +  * $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 =====
  
-If the function is called in a 'branch_route' then the branch is discarded (implicit action for 'branch_route' is to forward the request).+==== $nh(key====
  
-If the function is called in the default 'onreply_route' then you can drop any responseIf the function is called in a named 'onreply_route' (transaction stateful) then any provisional reply is discarded(Implicit action for 'onreply_route' is to send the reply upstream according to Via header.)+Return attributes of next hop for the SIP messagesFor SIP requests, the address is taken from dst_uri, if set, if not from new r-uri or original r-uriFor SIP replies, the attributes are taken from 2nd Via header (username is always $null for SIP replies).
  
-Example of usage:+  * $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)
  
-    onreply_route { +===== NDB_REDIS Module =====
-        if(status=="200") { +
-            drop(); # this works +
-        } +
-    }+
  
-    onreply_route[FOOBAR] { +==== $redis(res=>key====
-        if(status=="200") { +
-            drop(); # this is ignored +
-        } +
-    }+
  
-==== exit ====+Access the attributes of the Redis response.
  
-Stop the execution of the configuration script -- it has the same behaviour as return(0). It does not affect the implicit action to be taken after script execution. +The key can be:
  
-  route { +  * type - type of the reply (as in hiredis.h
-    if (route(2)) { +  * value - the value returned by REDIS server
-      xlog("L_NOTICE","method $rm is INVITE\n")+  * info - in case of error from REDISit will contain an info message.
-    } else { +
-      xlog("L_NOTICE","method is $rm\n"); +
-    }; +
-  }+
  
-  route[2] { +If reply type is an array (as in hiredis.h), there are other keys available:
-    if (is_method("INVITE")) { +
-      return(1); +
-    } else if (is_method("REGISTER")) { +
-      return(-1); +
-    } else if (is_method("MESSAGE")) { +
-      sl_send_reply("403","IM not allowed"); +
-      exit; +
-    }; +
-  }+
  
-==== error ====+  * size - returns number of elements in the array.
  
-==== exec ====+  * type[n] - returns the type of the nth element in the array. type - returns array type.
  
-==== force_rport ====+  * value[n] - returns value of the nth element. value - returns null for an array. You need to get each element by index.
  
-Force_rport() adds the rport parameter to the first Via header of the received message. ThusKamailio will add the received  port to the top most Via header in the SIP messageeven if the client does not indicate support for rport. This enables subsequent SIP messages to return to the proper port later on in a SIP transaction.+In case one of the members of the array is also an array (for example calling SMEMBERS in a MULTI/EXEC transaction)the members of the array can be accessed by adding any of the above keysafter a value[n] key. The first value[n] references the element in the first arraywhile the next key references an element of the referenced array.
  
-This is useful for NAT traversal, to enforce symmetric response signaling. +Example:
- +
-The rport parameter is defined in RFC 3581. +
- +
-Note: there is also a force_rport parameter which changes the gobal behavior of the SIP proxy. +
- +
-Example of usage: +
- +
-    force_rport(); +
- +
-==== add_rport ==== +
-Alias for force_rport(); +
- +
-==== force_send_socket ==== +
- +
- +
-Force to send the message from the specified socket (it _must_ be one of the sockets specified with the "listen" directive). If the protocol doesn't match (e.g. UDP message "forced" to a TCP socket) the closest socket of the same protocol is used. +
- +
-This function does not support pseudo-variables, use the set_send_socket function from the corex module instead. +
- +
-Example of usage:+
  
 <code> <code>
-    force_send_socket(10.10.10.10:5060); +redis_cmd("srvN", "GET foo", "r"); 
-    force_send_socket(udp:10.10.10.10:5060);+xlog("===== result type$redis(r=>type) * value$redis(r=>value)\n");
 </code> </code>
-==== force_tcp_alias ==== 
  
-**Alias name: add_tcp_alias** +==== $redisd(key) ====
- +
-force_tcp_alias(port)       +
- +
-adds a tcp port alias for the current connection (if tcp). +
-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 "aliased" connection is closed (e.g. it's idle for too +
-much time), all the port aliases are removed. +
- +
-==== forward ==== +
- +
-Forward the SIP request to destination stored in $du in stateless mode. +
- +
-Example of usage: +
- +
-    $du = "sip:10.0.0.10:5060;transport=tcp"; +
-    forward()+
- +
- +
- +
- +
- +
- +
- +
- +
- +
-==== isavpflagset ==== +
- +
-==== isflagset ==== +
- +
-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. +
- +
-For more see: https://www.kamailio.org/wiki/tutorials/kamailio-flag-operations. +
- +
-Example of usage:+
  
-    if(isflagset(3)) { +Return the corresponding value for various defines from hiredis library.
-        log("flag 3 is set\n"); +
-    };+
  
 +The key can be:
  
-Kamailio also supports named flags. They have to be declared at the beginning of the config file with:+  * 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
  
-   flags  flag1_name[:position],  flag2_name ...+$redisd(rpl_XYZ) can be compared with $redis(r=>type).
  
 Example: Example:
-       flags test, a:1, b:2 ; 
-       route{ 
-              setflag(test); 
-              if (isflagset(a)){ # equiv. to isflagset(1) 
-                .... 
-              } 
-              resetflag(b);  # equiv. to resetflag(2)  
- 
-==== is_int ==== 
-Checks if a pseudo variable argument contains integer value.  
- 
-  if(is_int("$avp(foobar)")) { 
-    log("foobar contains an integer\n"); 
-  } 
- 
-==== log ==== 
- 
-Write text message to standard error terminal or syslog. You can specify the log level as first parameter. 
- 
-For more see: http://www.kamailio.org/dokuwiki/doku.php/tutorials:debug-syslog-messages 
- 
-Example of usage: 
- 
-    log("just some text message\n"); 
- 
- 
-==== prefix ==== 
- 
-Add the string parameter in front of username in R-URI. 
- 
-Example of usage: 
- 
-    prefix("00"); 
- 
-==== resetavpflag ==== 
- 
-==== resetflag ==== 
- 
-==== return ==== 
- 
-The return() function allows you to return any integer value from a called route() block. 
-You can test the value returned by a route using [[devel#retcode|$retcode]] or $? variable. 
- 
-return(0) is same as [[devel#exit|exit()]]; 
- 
-In bool expressions: 
- 
-  * Negative is FALSE 
-  * Positive is TRUE 
- 
-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:  
  
 <code> <code>
-route { +redis_cmd("srvN", "GET foo", "r"); 
-  if (route(2)) { +if ($redis(r=>type== $redisd(rpl_int)) {
-    xlog("L_NOTICE","method $rm is INVITE\n"); +
-  } else { +
-    xlog("L_NOTICE","method $rm is REGISTER\n"); +
-  }; +
-+
-</code> +
-<code> +
-route[2] { +
-  if (is_method("INVITE")) { +
-    return(1); +
-  } else if (is_method("REGISTER")) { +
-    return(-1); +
-  } else { +
-    return(0); +
-  };+
 } }
 </code> </code>
  
-See also the FAQ for how the function return code is evaluated:+===== GeoIP Module =====
  
-  * https://www.kamailio.org/wiki/tutorials/faq/main#how_is_the_function_return_cod +==== $gip(pvc=>key) ====
-==== revert_uri ====+
  
-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).+Variables exported by GeoIP module, returning geo-location attributes. The attributes are populated upon calling function **geoip_match(ipaddr, pvc)**.
  
-Example of usage:+**pvc** (container id) is second parameter of geoip_match(..) and **key** can be:
  
-    revert_uri();+  * 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
  
-==== rewritehostport ==== +You can call several time **geoip_match(ipaddrpvc)** with different ip address and containers in your configto comparefor exampleattributes of source and destination of a call.
- +
-**Alias name: sethostport, sethp** +
- +
-Rewrite the domain part and port of the R-URI with the value of function's parameter. Other parts of the R-URI like username and URI parameters remain unchanged. +
- +
-Example of usage: +
- +
-    rewritehostport("1.2.3.4:5080"); +
- +
-==== rewritehostporttrans ==== +
- +
-**Alias name: sethostporttranssethpt** +
- +
-Rewrite the domain part and port of the R-URI with the value of function's parameter. Also allows to specify the transport parameter. Other parts of the R-URI like username and URI parameters remain unchanged. +
- +
-Example of usage: +
- +
-    rewritehostporttrans("1.2.3.4:5080")+
- +
-==== rewritehost ==== +
- +
-**Alias name: sethost, seth** +
- +
-Rewrite the domain part of the R-URI with the value of function's parameter. Other parts of the R-URI like username, port and URI parameters remain unchanged. +
- +
-Example of usage: +
- +
-    rewritehost("1.2.3.4"); +
- +
-==== rewriteport ==== +
- +
-**Alias name: setportsetp** +
- +
-Rewrites/sets the port part of the R-URI with the value of function's parameter. +
- +
-Example of usage: +
- +
-    rewriteport("5070"); +
- +
-==== rewriteuri ==== +
- +
-**Alias name: seturi** +
- +
-Rewrite the request URI. +
- +
-Example of usage: +
- +
-    rewriteuri("sip:test@kamailio.org"); +
- +
-==== rewriteuserpass ==== +
- +
-**Alias name: setuserpasssetup** +
- +
-Rewrite the password part of the R-URI with the value of function's parameter. +
- +
-Example of usage: +
- +
-    rewriteuserpass("my_secret_passwd"); +
-==== rewriteuser ==== +
- +
-**Alias name: setusersetu** +
- +
-Rewrite the user part of the R-URI with the value of function's parameter. +
- +
-Example of usage: +
- +
-    rewriteuser("newuser"); +
- +
-==== route ==== +
- +
-Execute route block given in parameter.  Parameter may be name of the block or a string valued expression. +
- +
-Examples of usage: +
- +
-    route(REGISTER_REQUEST); +
-    route(@received.proto + "_proto_" + $var(route_set)); +
- +
- +
-==== selval ==== +
- +
-Select value based on conditional expression. +
- +
-Prototype:+
  
 <code c> <code c>
-selval(evalexprvalexp1, valexpr2+geoip_match("$si""src"); 
-</code>+geoip_match("$nh(d)", "dst");
  
-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/operator+if($gip(src=>cc)==$gip(dst=>cc)) 
 +
 +    # source and destination from same country 
 +}
  
-Example: 
- 
-<code c> 
-$var(x) = selval($Ts mod 2, "true/" + $ru, "false/" + $rd); 
 </code> </code>
  
-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. +===== TLS Module =====
-==== set_advertised_address ====+
  
-Same as 'advertised_address' but it affects only the current message. It has priority if 'advertised_address' is also set.+==== $tls_version ==== 
 +The TLS/SSL version which is used on the TLS connection from which the message was receivedString type. 
 +==== $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: 
 +    /C=AT/ST=Vienna/L=Vienna/O=enum.at/CN=enum.at 
 +==== $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 "subject alternative name" extension. String type. 
 +==== $tls_my_san_email ==== 
 +email address in the "subject alternative name" extension. String type. 
 +==== $tls_peer_san_hostname ==== 
 +hostname (DNS) in the "subject alternative name" extension. String type. 
 +==== $tls_my_san_hostname ==== 
 +hostname (DNS) in the "subject alternative name" extension. String type. 
 +==== $tls_peer_san_uri ==== 
 +URI in the "subject alternative name" extension. String type. 
 +==== $tls_my_san_uri ==== 
 +URI in the "subject alternative name" extension. String type. 
 +==== $tls_peer_san_ip ==== 
 +ip address in the "subject alternative name" extension. String type. 
 +==== $tls_my_san_ip ==== 
 +ip address in the "subject alternative name" extension. String type.
  
-Example of usage:+==== $tls_peer_verified ==== 
 +Returns 1 if the peer's certificate was successfully verified. Otherwise it returns 0. String and Integer type.
  
-    set_advertised_address("kamailio.org");+==== $tls_peer_revoked ==== 
 +Returns 1 if the peer's certificate was revoked. Otherwise it returns 0. String and Integer type.
  
-==== set_advertised_port ====+==== $tls_peer_expired ==== 
 +Returns 1 if the peer's certificate is expired. Otherwise it returns 0. String and Integer type.
  
-Same as 'advertised_port' but it affects only the current messageIt has priority over 'advertised_port'.+==== $tls_peer_selfsigned ==== 
 +Returns 1 if the peer's certificate is selfsigned. Otherwise it returns 0String and Integer type.
  
-Example of usage:+==== $tls_peer_notBefore ==== 
 +Returns the notBefore validity date of the peer's certificate. String type.
  
-    set_advertised_port(5080);+==== $tls_peer_notAfter ==== 
 +Returns the notAfter validity date of the peer's certificate. String type.
  
-==== set_forward_no_connect ====+==== $tls_peer_server_name ==== 
 +The SNI server name of the peer
  
-The message will be forwarded only if there is already an existing connection to the destinationIt applies only to connection oriented protocols like TCP and TLS (TODO: SCTP), for UDP it will be ignoredThe behavior depends in which route block the function is called:+==== $tls_peer_raw_cert ==== 
 +The raw PEM-encoded client certificateString type.
  
-  * normal request route: affects stateless forwards and tmFor tm it affects all the branches and the possible retransmissions (in fact there are no retransmission for TCP/TLS).+==== $tls_my_raw_cert ==== 
 +The raw PEM-encoded client certificateString type.
  
-  * onreply_route[0] (stateless): equivalent to set_reply_*() (it's better to use set_reply_* though)+==== $tls_peer_urlencoded_cert ==== 
 +The PEM-encoded client certificate, urlencoded. String type.
  
-  * onreply_route[!=0] <nowiki>(tm)</nowiki>: ignored+==== $tls_my_urlencoded_cert ==== 
 +The PEM-encoded client certificate, urlencoded. String type. 
 +===== SIP Message Attributes =====
  
-  * branch_route: affects the current branch only (all messages sent on this branch, like possible retransmissions and CANCELs).+==== $msg(attr====
  
-  * onsend_routelike branch route+Return attributes of SIP message:
  
-Example of usage:+  * $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 
 +  * $msg(fline) - sip message first line
  
-    route { +===== XHTTP Module =====
-      ... +
-      if (lookup()) { +
-        //requests to local users. They are usually behind NAT so it does not make sense to try +
-        //to establish a new TCP connection  +
-        set_forward_no_connect(); +
-        t_relay(); +
-      } +
-      ... +
-    }+
  
-==== set_forward_close ====+==== $hu ====
  
-Try to close the connection (the one on which the message is sent out) after forwarding the current message. Can be used in same route blocks as set_forward_no_connect().+  * URL of http request.
  
-Note: Use with care as you might not receive the replies anymore as the connection is closed.+===== MSRP Module =====
  
 +This class of pseudo-variables is exported by MSRP module and give access to attributes of MSRP frames.
 +==== $msrp(buf) ====
  
-==== set_reply_no_connect ====+The entire content of MSRP frame - first line, headers, body and end-line. 
 +==== $msrp(body) ====
  
-Like set_forward_no_connect(), but for replies to the current message (local generated replies and replies forwarded by tm). The behavior depends in which route block the function is called:+The body of MSRP frame. 
 +==== $msrp(code====
  
-  * normal request route: affects all replies sent back on the transaction (either local or forwardedand all local stateless replies (sl_reply()).+The code of MSRP replies
 +==== $msrp(hdrs====
  
-  * onreply_route: affects the current reply (so the send_flags set in the onreply_route will be used if the reply for which they were set is the winning final reply or it'provisional reply that is forwarded)+The headers in a MSRP frame. 
 +==== $msrp(msgid====
  
-  * branch_route: ignored.+The body of Message-Id header. 
 +==== $msrp(method) ====
  
-  * onsend_route: ignored+The method of a MSRP request. 
 +==== $msrp(buflen) ====
  
 +The length of entire MSRP frame.
 +==== $msrp(sessid) ====
  
-Example of usage:+The session id for MSRP frame. It is taken from the first MSRP URI in To-Path header. 
 +==== $msrp(reason) ====
  
-    route[4] { +The reason text in a MSRP reply
-      //requests from local usersThere are usually behind NAT so it does not make sense to try +==== $msrp(crthop====
-      //to establish a new TCP connection for the replies +
-      set_reply_no_connect()+
-      // do authentication and call routing +
-      ... +
-    }+
  
-==== set_reply_close ====+The URI for current hop - it is the first URI in To-Path header. 
 +==== $msrp(bodylen) ====
  
-Like set_reply_no_connect, but closes the TCP connection after sending. Can be used in same route blocks as set_reply_no_connect.+The length of the body in MSRP frame.
  
-Example of usage:+==== $msrp(transid) ====
  
-    route { +The transaction ID from the first line of MSRP frame
-      ... +==== $msrp(prevhop====
-      if (...caller-is-not-registered...) { +
-        // reject unregistered client +
-        // if request was received via TCP/TLS close the connection, as +
-        // this may trigger re-registration of the client+
-        set_reply_close()+
-        sl_send_reply("403","REGISTER first"); +
-        exit; +
-      } +
-      ... +
-    }+
  
 +The MSRP URI of the previous hop - the first address in From-Path header.
 +==== $msrp(nexthop) ====
  
-==== setavpflag ====+The URI of the next hop - the second address in To-Path header. 
 +==== $msrp(lasthop) ====
  
-==== setflag ====+The last hop URI - the last address in To-Path header. 
 +==== $msrp(srcaddr) ====
  
-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 for special processing (e.g., accountingor to keep some state (e.g., message authenticated).+The address of the previous hop set as MSRP URI using received source IP and port. 
 +==== $msrp(srcsock====
  
-For more seehttps://www.kamailio.org/wiki/tutorials/kamailio-flag-operations .+The local socket where the MSRP frame was received, set as **proto:ipaddr:port". 
 +==== $msrp(firsthop) ====
  
-Example of usage:+The URI of the first hop - the last address in From-Path header. 
 +==== $msrp(prevhops) ====
  
-    setflag(3);+The number of previous hops - it is the number of addresses in From-Path header. 
 +==== $msrp(nexthops====
  
-==== strip ====+The number of next hops - it is the number of addresses in To-Path header minus 1 (the first address in To-Path is current hop).
  
-Strip the first N-th characters from username of R-URI (N is the value of the parameter).+==== $msrp(conid====
  
-Example of usage:+The internal integer id for TCP/TLS connection.
  
-    strip(3);+===== SIPT Module =====
  
-==== strip_tail ====+==== $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.
  
-Strip the last N-th characters from username of R-URI (N is the value of the parameter). +The following values can be returned
- +  * 0 presentation allowed 
-Example of usage+  * 1 resentation restricted 
- +  * 2 address not avail (national use
-  strip_tail(3); +  * 3 spare
- +
-==== udp_mtu_try_proto(proto==== +
- +
-  * proto - TCP|TLS|SCTP|UDP - like udp_mtu_try_proto global parameter but works on a per packet basis and not globally.+
  
 Example: Example:
  
-<code> +<code c
-if($rd=="10.10.10.10"+if($sipt(calling_party_number.presentation) == 1
-    udp_mtu_try_proto(SCTP);+
 +        append_hf("Privacy: id\r\n"); 
 +        $fn = "Anonymous"; 
 +}
 </code> </code>
  
-==== userphone ==== 
  
-Add "user=phone" parameter to R-URI.+==== $sipt(calling_party_number.screening) / $sipt_screening ==== 
 +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.
  
-===== Custom Global Parameters ===== +Can return the following values
- +  * 0 Reserved (user provided, not verified) 
-These are parameters that can be defined by the writer of kamailio.cfg in order to be used inside routing blocks. One of the important properties for custom global parameters is that their value can be changed at runtime via RPC commands, without restarting Kamailio. +  * 1 User Provided, Verified and Passed 
- +  * 2 Reserved (user provided, verified and failed) 
-The definition of a custom global parameter must follow the pattern+  * 3 Network provided
- +
-<code> +
-group.variable = value desc "description" +
- +
-</code> +
- +
-The value can be a quoted string or integer number.+
  
 Example: Example:
- 
 <code c> <code c>
-pstn.gw_ip "1.2.3.4" desc "PSTN GW Address"+# 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:screening) != 1 && $avp(s:screening) != 3
 +
 +        remove_hf("P-Asserted-Id"); 
 +}
 </code> </code>
  
-The custom global parameter can be accessed inside a routing block via: 
  
-<code> +====  $sipt(hop_counter) / $sipt_hop_counter ==== 
-$sel(cfg_get.group.variable) +Returns the value of the Hop Counter for the IAM message if it exists. Returns -1 if there isn't a hop counter.
-</code>+
  
 Example: Example:
- 
 <code c> <code c>
-$ru "sip:" + $rU + "@$sel(cfg_get.pstn.gw_ip);+# 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: $avp(s:hop)\r\n"); 
 +}
 </code> </code>
  
-**Note:** Some words cannot be used as (part ofnames for custom variables or groups, and if they are used syntax error is logged  by kamailioThese keywords are: "yes", "true", "on", "enable", "no", "false", "off", "disable", "udp", "UDP", "tcp", "TCP", "tls", "TLS", "sctp", "SCTP", "ws", "WS", "wss", "WSS", "inet", "INET", "inet6", "INET6", "sslv23", "SSLv23", "SSLV23", "sslv2", "SSLv2", "SSLV2", "sslv3", "SSLv3", "SSLV3", "tlsv1", "TLSv1", "TLSV1"+==== $sipt(calling_party_category/ $sipt(cpc) / $sipt_cpc ==== 
 +Returns the value of the Calling Party Category for the IAM message. Returns -1 if there is parsing error.
  
-===== Routing Blocks =====+==== $sipt(calling_party_number.nature_of_address) / $sipt.(calling_party_number.nai) / $sipt_calling_party_nai ==== 
 +Returns the value of the Nature of Address Indicator 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.
  
-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 proceduresfrom common programming languages. +Can return the following values: 
- +  * 0 Spare 
-A routing block is identified by a specific token, followed by a name in between square brackets and actions in between curly braces.+  * 1 Subscriber Number (national use
 +  * 2 Unknown (national use) 
 +  * 3 National (significant) number (national use) 
 +  * 4 International use
  
 +Example:
 <code c> <code c>
-route_block_id[NAME] +# get the Calling Nai and add country code if national 
-  ACTIONS+if($sipt(calling_party_number.nai) == 3) 
 +
 +        $fU = "32" + "$fU";
 } }
 </code> </code>
  
-The name can be any alphanumeric string, with specific routing blocks enforcing particular format+====  $sipt(called_party_number.nature_of_address) / $sipt(called_party_number.nai) / $sipt_called_party_nai ==== 
 +Returns the value of the Nature of Address Indicator of the Called Party for the IAM message. Returns -1 if there is parsing error.
  
-<fc #4682b4>Noteroute(number) is equivalent to route("number").</fc>+Can return the following values:
  
-Route blocks can be executed on network events (e.g., receiving a SIP message), timer events (e.g., retransmission timeoutor particular events specific to modules. +  * 0 Spare 
- +  * 1 Subscriber Number (national use) 
-There can be so called sub-route blocks, which can be invoked from another route blocks, like a function. Invocation is done with 'route' followed by the name of sub-route to execute, enclosed in between parentheses.+  * 2 Unknown (national use
 +  * 3 National (significant) number 
 +  * 4 International use 
 +  * 5 Network-specific number (national use)
  
 Example: Example:
- 
 <code c> <code c>
-  request_route{ +# get the Called Nai and add country code if national 
-    ... +if($sipt(called_party_number.nai) == 3
-    route("test"); +{ 
-    ... +        $rU = "32+ "$rU"; 
-  } +}
- +
-  route["test"]{ +
-    ... +
-  }+
 </code> </code>
  
-==== request_route ====+==== $sipt(event_info) === 
 +Returns the value  of the Event Info header of the CPG message. Returns -1 if there is a parsing error.
  
-Request routing block -  is executed for each SIP request.+Can return the following values: 
 +  * 0 Spare 
 +  * 1 ALERTING 
 +  * 2 PROGRESS 
 +  * 3 In-band information or an appropriate pattern is now available 
 +  * 4 Call forward on busy 
 +  * 5 Call forward on no reply 
 +  * 6 Call forward unconditional
  
-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. 
  
-<fc #4682b4>For backward compatibility reasons, the main request 'route' block can be identified by 'route{...}' or 'route[0]{...}'.</fc>+==== $sipt(backward_call_indicator.charge_indicator) === 
 +Returns the value of the charge indication of the backward call 
 +indicator header in the ACM or COT messageReturns -1 if there is a 
 +parsing error
  
-The implicit action after execution of the main route block is to drop the SIP request. To send a reply or forward the request, explicit actions (e.g., sl_send_reply(), forward(), t_relay()) must be called inside the route block.+Can return the following values: 
 +  * 0 no indication 
 +  * 1 no charge 
 +  * 2 charge 
 +  * 3 spare
  
-Example of usage: 
  
-<code c> +==== $sipt(redirection_info/ $sipt_redirection_info === 
-    request_route { +Returns the value of the Redirecting reason of the Call Diversion Information header from ISUP.  
-         if(is_method("OPTIONS")) { +Returns -1 if there is a parsing error or if the Call Diversion Information is not present.
-            # send reply for each options request +
-            sl_send_reply("200", "ok"); +
-            exit(); +
-         } +
-         route(FWD); +
-    } +
-    route[FWD] { +
-         # forward according to uri +
-         forward(); +
-    } +
-</code>+
  
-==== route ====+Can return the following values:
  
-This block is used to define 'sub-routes' - group of actions that can be executed from another routing block. Originally targeted as being executed from 'request_route', it can be executed now from all the other blocks. Be sure you put there the actions valid for the root routing block executing the sub-route.+  * 0 Unknown 
 +  * 1 User busy 
 +  * 2 no reply 
 +  * 3 unconditional 
 +  * 4 deflection during alerting 
 +  * 5 deflection immediate response 
 +  * 6 mobile subscriber not reachable
  
-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 
  
 +==== $sipt(redirection_number) / $sipt_redirection_number ===
 +Returns the value (Address signal) of the Redirection Number.
 +Returns -1 if there is a parsing error or if the Redirection Number is not present.
  
 +Example:
 <code c> <code c>
-request_route { +# get the redirection number 
-  if(route(POSITIVE)) { +$avp(s:redir_num= $sipt(redirection_number); 
-    xlog("return number is positive\n"); +</code>
-  } +
-  if! route(NEGATIVE)) { +
-    xlog("return number is negative\n"); +
-  } +
-  if( route(ZERO)) { +
-    xlog("this log message does not appear\n"); +
-  } +
-}+
  
-route[POSITIVE] { 
-  return 10; 
-} 
  
-route[NEGATIVE] { +==== $sipt(redirection_number.nai) / $sipt_redirection_number_nai === 
-  return -8; +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.
-}+
  
-route[ZERO] { +Can return the following values:
-  return 0; +
-+
-</code>+
  
-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.+  0 Spare 
 +  1 Subscriber Number (national use) 
 +  2 Unknown (national use) 
 +  * 3 National (significant) number 
 +  4 International use
  
-The sub-route blocks allow to make the configuration file modular, simplifying the logic and helping to avoid duplication of actions. 
-==== branch_route ==== 
  
-Request's branch routing block. It contains a set of actions to be taken for each branch of a SIP requestIt is executed only by TM module after it was armed via t_on_branch("branch_route_index").+==== $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.
  
-Example of usage: 
  
-<code c> +==== $sipt(called_party_number=== 
-    request_route { +Returns the value (Address signalof the Called Party for the IAM message. 
-        lookup("location"); +Returns -1 if there is a parsing error or if the Called Party Number is not present.
-        t_on_branch("OUT"); +
-        if(!t_relay()) { +
-            sl_send_reply("500", "relaying failed"); +
-        } +
-    } +
-    branch_route[OUT] { +
-        if(uri=~"10\.10\.10\.10") { +
-            # discard branches that go to 10.10.10.10 +
-            drop(); +
-        } +
-    } +
-</code>+
  
-==== failure_route ==== 
  
-Failed transaction routing block. It contains a set of actions to be taken each transaction that received only negative replies (>=300for all branchesThe 'failure_route' is executed only by TM module after it was armed via t_on_failure("failure_route_index").+==== $sipt(sipt_redirection_information_reason=== 
 +Returns the value of the Redirection reason of the Redirection information header from ISUP 
 +Returns -1 if there is a parsing error or if the Redirection information is not present.
  
-Note that in 'failure_route' is processed the request that initiated the transaction, not the reply . 
  
 +==== $sipt(sipt_redirection_information_original_reason) ===
 +Returns the value of the Original Redirection reason of the Redirection information header from ISUP. 
 +Returns -1 if there is a parsing error or if the Redirection information is not present.
  
-Example of usage: 
  
-<code c> +==== $sipt(redirecting_number.nai=== 
-    request_route { +Returns the value of the Nature of Address Indicator of the Redirecting Number. Returns -1 if there is a parsing error or if the Redirecting Number is not present.
-        lookup("location"); +
-        t_on_failure("TOVOICEMAIL"); +
-        if(!t_relay()) { +
-            sl_send_reply("500", "relaying failed"); +
-        } +
-    } +
-    failure_route[TOVOICEMAIL] { +
-        if(is_method("INVITE")) { +
-             # call failed - relay to voice mail +
-             t_relay_to_udp("voicemail.server.com","5060"); +
-        } +
-    } +
-</code>+
  
-==== reply_route ====+Can return the following values:
  
-Main SIP response (replyhandling block - it contains a set of actions to be executed for SIP replies. It is executed for all replies received from the network.+  * 0 Spare 
 +  * 1 Subscriber Number (national use) 
 +  * 2 Unknown (national use) 
 +  * 3 National (significant) number 
 +  * 4 International use
  
-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 on the network. 
  
-There is no network route that can be enforced for a SIP reply it is sent based on Via header, according to SIP RFC3261 - therefore no dedicated actions for forwarding the reply must be used in this block.+==== $sipt(redirecting_number) === 
 +Returns the value (Address signal) of the Redirecting Number for the IAM message. 
 +Returns -1 if there is a parsing error or if the Redirecting Number is not present.
  
-This routing block is optional, if missing, the SIP reply is sent to the address in 2nd Via header. 
  
-One can decide to drop SIP reply by using **drop** action.+==== $sipt(original_called_number.nai) === 
 +Returns the value of the Nature of Address Indicator of the Original Called Number. Returns -1 if there is parsing error or if the Original Called Number is not present.
  
-Example:+Can return the following values:
  
-<code c> +  * 0 Spare 
-reply_route { +  * 1 Subscriber Number (national use) 
-  if(status=="128"+  * 2 Unknown (national use
-    drop; +  * 3 National (significant) number 
-  } +  * 4 International use
-+
-</code>+
  
-<fc #4682b4>Note: for backward compatibility reasons, the main 'reply' routing block can be also identified by 'onreply_route {...}' or 'onreply_route[0] {...}'.</fc> 
  
-==== onreply_route ====+==== $sipt(original_called_number) === 
 +Returns the value (Address signal) of the Original Called Number for the IAM message. 
 +Returns -1 if there is a parsing error or if the Original Called Number is not present.
  
  
-SIP reply routing block executed by **tm** moduleIt contains a set of actions to be taken for SIP replies in the contect of an active transaction.+==== $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.
  
-The 'onreply_route' must be armed for the SIP requests whose replies should be processed within it, via t_on_reply("onreply_route_index").+Can return the following values:
  
-Core 'reply_route' block is executed before a possible **tm** 'onreply_route' block.+  0 Spare 
 +  1 Subscriber Number (national use) 
 +  2 Unknown (national use) 
 +  3 National (significant) number 
 +  * 4 International use
  
-<code c> 
-  request_route { 
-      lookup("location"); 
-      t_on_reply("LOGRPL"); 
-      if(!t_relay()) { 
-          sl_send_reply("500", "relaying failed"); 
-      } 
-  } 
  
-  reply_route { +==== $sipt(generic_number) === 
-      if(!t_check_trans()) { +Returns the value (Address signalof the Generic Number for the IAM message. 
-          drop; +Returns -1 if there is a parsing error or if the Generic Number is not present.
-      } +
-  }+
  
-  onreply_route[LOGRPL] { 
-      if(status=~"1[0-9][0-9]") { 
-           log("provisional response\n"); 
-      } 
-  } 
-</code> 
-==== 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, send(), log(), textops::search()).+===== $cfg(key- Config File Attributes ===== 
 + 
 +Attributes related to configuration file.
  
-In this route the final destination of the message is available and can be checked (with snd_ip, snd_port, to_ip, to_port, snd_proto, snd_af).+The key can be:
  
-This route is executed only when forwarding requests it is not executed for replies, retransmissions, or locally generated messages (e.g. via fifo uac).+  * line - return the current line in config 
 +  * name - return the name of current config file 
 +  * file - return the name of current config file 
 +  * route - return the name of routing block
  
 Example: Example:
  
 <code c> <code c>
-  onsend_route { +send_reply("404", "Not found at line $cfg(line)");
-    if(to_ip==1.2.3.4 && !isflagset(12)){ +
-      log(1, "message blocked\n"); +
-      drop; +
-    } +
-  }+
 </code> </code>
  
-  * snd_ip, snd_port - behave like src_ip/src_port, but contain the ip/port Kamailio will use to send the message +===== $dns(pvid=>key) - DNS Query Result =====
-  * to_ip, to_port - like above, but contain the ip/port the message will be sent to (not to be confused with dst_ip/dst_port, which are the destination of the original received request: Kamailio's ip and port on which the message was received) +
-  * snd_proto, snd_af behave like proto/af but contain the protocol/address family that Kamailio will use to send the message +
-  * msg:len - when used in an onsend_route, msg:len will contain the length of the message on the wire (after all the changes in the script are applied, Vias are added a.s.o) and not the lentgh of the original message.+
  
-==== event_route ====+This variable stores the DNS result details after a call of dns_query(hostname, pvid) function from ipops module.
  
-Generic type of route executed when specific events happen.+  * 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
  
-Prototype: event_route[groupid:eventid] +The index can be an integer or a variable with integer value. First address has the index 0. If negative value, the returned address is counted from the end of the list, -1 being the last address. If no index is provided, then the first address is returned.
-  * groupid - should be the name of the module that triggers the event +
-  * eventid - some meaningful short text describing the event +
- +
-=== Core Event Routes === +
- +
-Implementations: +
- +
-  * **event_route[core:worker-one-init]** - executed by core after the first udp sip worker process executed the child_init() for all modules, before starting to process sip traffic +
-    * note that due to forking, other sip workers can get faster to listening for sip traffic+
  
 <code c> <code c>
-event_route[core:worker-one-init] +if(dns_query("test.com", "xyz")) 
-        xlog("L_INFO","Hello world\n");+
 +    xlog(" number of addresses$dns(xyz=>count)\n"); 
 +    xlog(" ipv4 address found: $dns(xyz=>ipv4)\n"); 
 +    xlog(" ipv6 address found: $dns(xyz=>ipv6)\n"); 
 +    $var(i) = 0; 
 +    while($var(i)&lt;$dns(xyz=>count)) 
 +        xlog(" #[$var(i)] type ($dns(xyz=>type[$var(i)]))" 
 +             addr [$dns(xyz=>addr[$var(i)])]\n"); 
 +        $var(i) = $var(i) + 1; 
 +    }
 } }
 </code> </code>
  
-  * **event_route[core:msg-received]** - executed when a message is received from the network. It runs with a faked request and makes available the $rcv(key) variables to access what was received and related attribtues+===== $HN(key) - Hostname details ===== 
-    * it has to be enabled with received_route_mode global parameter. For usage via Kemi, set kemi.received_route_callback global parameter. + 
-    if drop is executed, the received message is no longer processed+Give local hostname details (implemented by ipops module)
 + 
 +The key can be: 
 +  n - the hostname 
 +  * f - the fullname 
 +  * d - the domain 
 +  * i - the ip address
  
 <code c> <code c>
-event_route[core:msg-received] { +xlog("local hostanme is $HN(n)\n");
-  xlog("rcv on $rcv(af)/$rcv(proto): ($rcv(len)) [$rcv(buf)] from [$rcv(srcip):$rcv(srcport)] to [$rcv(rcvip):$rcv(rcvport)]\n"); +
-  if($rcv(srcip) == "1.2.3.4") { +
-    drop; +
-  } +
-}+
 </code> </code>
  
-  * **event_route[core:pre-routing]** - executed by core on receiving SIP traffic before running request_route or reply_route+===== $RANDOM - Random number ===== 
-    * 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.+ 
 +Returns a random value from the [2^31) range
 + 
 +(Part of the cfgutils module)
  
 <code c> <code c>
-async_workers_group="name=reg;workers=4" +if (rand_event()) { 
-... +  $avp(i:10) ($RANDOM / 16777216)# 2^24 
-event_route[core:pre-routing] +  if ($avp(i:10) < 10) 
-    xinfo("pre-routing rules\n"); +     $avp(i:10) = 10; 
-    if(is_method("REGISTER")) { +  } 
-        # delegate processing of REGISTERs to a special group of workers +  append_to_reply("Retry-After: $avp(i:10)\n"); 
-        if(sworker_task("reg")) { +  sl_send_reply("503""Try later"); 
-            drop+  exit
-        +}; 
-    } +# normal message processing follows
-}+
 </code> </code>
  
-  * ** event_route[core:receive-parse-error]** - executed by core on receiving a broken SIP message that can not be parsed. +===== JSONRPCS 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> +==== $jsonrpl(key- JSONRPC Reply ====
-event_route[core:receive-parse-error] { +
-        xlog("got an parsing error from $si:$sp, message $mb\n")+
-}+
  
-</code>+This variable gives access to JSONRPC reply after executing jsonrpc_exec(...) in kamailio.cfg.
  
-=== Module Event Routes ===+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
  
-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.+===== Presence Module =====
  
 +==== $subs(key) - Subscription Attributes ====
  
-  * **event_route[htable:mod-init]** - executed by **htable** module after all modules have been initialisedGood for initialising values in hash tables. +This variable gives access to attributes of the current subscriptionThe variable has to be used after executing //handle_subscription()// in order to provide accurate values.
-<code c> +
-modparam("htable", "htable", "a=>size=4;")+
  
-event_route[htable:mod-init] { +The key can be
-  $sht(a=>calls-to::10.10.10.10) = 0; +  * uri subscription URIUseful in particular for subscriptions within the dialog, when the request URI in SUBSCRIBE is the Contact address from the initial subscription.
-  $sht(a=>max-calls-to::10.10.10.10) = 100; +
-}+
  
-request_route { +===== Registrar Module =====
-  if(is_method("INVITE") && !has_totag()) +
-  { +
-    switch($rd) { +
-      case "10.10.10.10": +
-        lock("calls-to::10.10.10.10"); +
-        $sht(a=>calls-to::10.10.10.10) = +
-            $sht(a=>calls-to::10.10.10.10) + 1; +
-        unlock("calls-to::10.10.10.10"); +
-        if($sht(a=>calls-to::10.10.10.10)>$sht(a=>max-calls-to::10.10.10.10)) +
-        { +
-           sl_send_reply("500", "To many calls to .10"); +
-           exit; +
-        } +
-      break; +
-      ... +
-    } +
-  } +
-+
-</code> +
-  * **event_route [tm:local-request]** - executed on locally generated requests. +
-<code c> +
-event_route [tm:local-request] { # Handle locally generated requests +
-  xlog("L_INFO", "Routing locally generated $rm to <$ru>\n"); +
-  t_set_fr(10000, 10000); +
-+
-</code>+
  
-  * **event_route [tm:branch-failure]** - executed on all failure responses. +==== $ulc(profile=>attr- Registered Contact Attributes ====
-<code c> +
-request_route { +
-    ... +
-    t_on_branch_failure("myroute")+
-    t_relay(); +
-}+
  
-event_route[tm:branch-failure:myroute] { +Access the attributes of contact addresses stored in 'profile'.
-  xlog("L_INFO", "Handling $T_reply_code response to $rm to <$ru>\n"); +
-  if (t_check_status("430")) { # Outbound flow failed +
-    unregister("location", "$tu", "$T_reply_ruid"); +
-    if (t_next_contact_flow()) { +
-      t_relay(); +
-    } +
-  } +
-}+
  
-</code>+It must be used after a call of “reg_fetch_contacts()”.
  
-===== Script Statements =====+===== Sipcapture Module =====
  
-==== if ==== +==== $hep(key) - HEP Packet Attributes ====
-IF-ELSE statement+
  
-Prototype:+The key refers to HEP packet header values:
  
-<code> +  * version - HEP version 
-    if(expr) { +  * src_ip - source IP address 
-       actions; +  * dst_ip - destination IP address 
-    } else { +  * 0x000 - HEP attribute 0x000 
-       actions; +  * 0x999 - HEP attribute 0x999
-    } +
-</code>+
  
-The 'expr' should be a valid logical expression.+===== Phonenum Variables =====
  
-The logical operators that can be used in 'expr':+$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:
  
-<code> +  * number - phone number that is matched 
-  ==      equal +  * valid - 1 if the matched number has a valid result; 0 otherwise 
-  !=      not equal +  * normalized - normalized phone number 
-  =~      regular expression matching: Note: Posix regular expressions will be used, e.g. use [[:digit:]]{3} instead of \d\d\d +  * cctel - country code for phone number 
-  !~      regular expression not-matching (NOT PORTED from Kamailio 1.x, use '!(x =~ y)') +  * ltype - local network type 
-  >       greater +  * ndesc - phone number description 
-  >=      greater or equal +  * error - error string if phone number matching fails.
-  <       less +
-  <=      less or equal +
-  &&      logical AND +
-  ||      logical OR +
-  !       logical NOT +
-</code>+
  
-Example of usage: +<code c> 
- +if(phonenum_match("1-484-555-8888", "src")) { 
-    if(is_method("INVITE")) +    if($phn(src=>valid)==1) 
-    { +        xlog("number normalized to: $phn(src=>normalized)\n");
-        log("this sip message is an invite\n");+
     } else {     } else {
-        log("this sip message is not an invite\n");+        xlog("number normalization error: $phn(src=>error)\n");
     }     }
 +}
 +</code>
  
-See also the FAQ for how the function return code is evaluated:+===== SecSIPId Variables =====
  
-  * https://www.kamailio.org/wiki/tutorials/faq/main#how_is_the_function_return_cod +$secsipid(key) - return attributes of secsipid module.
-==== switch ====+
  
-SWITCH statement - it can be used to test the value of a pseudo-variable. +The key can be:
  
-IMPORTANT NOTE: 'break' can be used only to mark the end of a 'case' branch (as it is in shell scripts)If you are trying to use 'break' outside a 'case' block the script will return error -- you must use 'return' there.+  * val - the value of Identity computed by secsipid_build_identity(...) 
 +  * ret - the return code of the libsecsipid function used by secsipid_build_identity(...)
  
 +Example:
  
-Example of usage: +<code c
-<code> +if(secsipid_build_identity("$fU""$rU""A""", 
-    route { +        "https://kamailio.org/stir/$rd/cert.pem""/secsipid/$rd/key.pem")) { 
-        route(1); +    xinfo("identity value: $secsipid(val)\n"); 
-        switch($retcode) +}
-        { +
-            case -1: +
-                log("process INVITE requests here\n"); +
-            break; +
-            case 1: +
-                log("process REGISTER requests here\n"); +
-            break; +
-            case 2: +
-            case 3: +
-                log("process SUBSCRIBE and NOTIFY requests here\n"); +
-            break; +
-            default: +
-                log("process other requests here\n"); +
-       } +
- +
-        # switch of R-URI username +
-        switch($rU+
-        { +
-            case "101"+
-                log("destination number is 101\n"); +
-            break; +
-            case "102": +
-                log("destination number is 102\n"); +
-            break; +
-            case "103": +
-            case "104"+
-                log("destination number is 103 or 104\n")+
-            break; +
-            default: +
-                log("unknown destination number\n")+
-       } +
-    +
- +
-    route[1]{ +
-        if(is_method("INVITE")) +
-        { +
-            return(-1)+
-        }; +
-        if(is_method("REGISTER")) +
-            return(1); +
-        } +
-        if(is_method("SUBSCRIBE")) +
-            return(2); +
-        } +
-        if(is_method("NOTIFY")) +
-            return(3); +
-        } +
-        return(-2); +
-    }+
 </code> </code>
 +===== sdpops module variables =====
  
-NOTE: take care while using 'return' 'return(0)' stops the execution of the script.+  * $sdp(body) full SDP body (read only) 
 +  * $sdp(sess_version) - sess-version -attribute from SDP o= -lineWhen set to special value -1, current value is incremented. (read + write)
  
 +===== $sruid - Unique ID =====
  
-==== while ====+  * $sruid - return unique ID generated internally Kamailio
  
-while statement+===== $ltt(key) - Local To-Tag =====
  
-Example of usage: +$ltt(key- return local generated To-tag when Kamailio sends a reply
-     +
-    $var(i= 0; +
-    while($var(i) < 10) +
-    { +
-        xlog("counter: $var(i)\n"); +
-        $var(i) = $var(i) + 1; +
-    }+
  
-===== Script Operations =====+  * $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/failure route, otherwise it returns $null) 
 +  * $ltt(x) - $ltt(t) if the transaction was created already, otherwise $ltt(s)
  
-Assignments together with string and arithmetic operations can be done directly in configuration file. +===== $via0(attr) - Via[0] Attributes =====
-==== Assignment ====+
  
-Assignments can be done like in C, via '=' (equal). The following pseudo-variables can be used in left side of an assignment: +$via0(attr) - attributes of first Via header.
-  * Unordered List Item AVPs - to set the value of an AVP +
-  * script variables ($var(...)) -  to set the value of a script variable +
-  * shared variables ($shv(...)) +
-  * $ru - to set R-URI +
-  * $rd - to set domain part of R-URI +
-  * $rU - to set user part of R-URI +
-  * $rp - to set the port of R-URI +
-  * $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+
  
-<code> +The attr can be:
-$var(a) = 123; +
-</code>+
  
-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. +  * host - host part (string
-<code> +  * port - port (number) 
-$(avp(i:3)[*]= 123; +  * proto - protocol - transport part (string) 
-$(avp(i:3)[*]= $null; +  protoid - protocol id (integer id
-</code>+  * branch - branch parameter 
 +  * rport - rport parameter value (string) 
 +  received - received parameter value (string
 +  * i - i parameter value (string)
  
-==== String Operations ==== +===== $via1(attr) - Second Via Attributes =====
-For strings, '+' is available to concatenate.+
  
-<code> +$via1(attr- attributes of second Via header. The attr can be the same as for $via0(attr).
-$var(a= "test"; +
-$var(b= "sip:" + $var(a) + "@" + $fd; +
-</code> +
-==== Arithmetic Operations ====+
  
-For numbers, one can use: +===== $viaZ(attr- Last Via Attributes =====
-  * + : plus +
-  * - : minus +
-  * / : divide +
-  * * : multiply +
-  * % : modulo (Kamailio uses 'mod' instead of '%') +
-  * | : bitwise OR +
-  * & : bitwise AND +
-  * ^ : bitwise XOR +
-  * ~ : bitwise NOT +
-  * <nowiki><<</nowiki> : bitwise left shift +
-  * <nowiki>>></nowiki> : bitwise right shift+
  
 +$viaZ(attr) - attributes of last Via header. The attr can be the same as for $via0(attr).
 +===== tcpops module variable =====
  
-Example:+$tcp(key) - return TCP connection attributes.
  
-<code> +The key can be: 
-$var(a= 4 + 7 & ( ~2 ) ); +  * c_si - connection source ip (useful with HAProxy connections) 
-</code>+  * c_sp - connection source port (useful with HAProxy connections
 +  * conid - connection id
  
-NOTE: to ensure the priority of operands in expression evaluations do use __parenthesis__. 
  
-Arithmetic expressions can be used in condition expressions.+===== pv_headers module variables =====
  
-<code> +  * $x_hdr(//header_name//): //header_name// header value 
-if( $var(a) & 4 +  * $x_fu: Full From header 
-    log("var a has third bit set\n"); +  * $x_fU: From header user part 
-</code>+  * $x_fd: From header domain part 
 +  * $x_fn: From header Display Name part 
 +  * $x_ft: From header Tag 
 +  * $x_tu: Full To header 
 +  * $x_tU: To header user part 
 +  * $x_td: To header domain part 
 +  * $x_tn: To header Display Name part 
 +  * $x_tt: To header Tag 
 +  * $x_rs:  
 +  * $x_rr:
  
-===== Operators =====+===== $C(xy) - Foreground and background colors =====
  
-  - type casts operators: (int), (str). +$C(xy- reference to an escape sequence. “x” represents the foreground color and “y” represents the background color.
-  - string comparison: eq, ne +
-  - integer comparison: ieq, ine +
  
-NoteThe 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.+Colors could be:
  
-Non equiv. examples:+  * x default color of the terminal 
 +  * s : Black 
 +  * r : Red 
 +  * g : Green 
 +  * y : Yellow 
 +  * b : Blue 
 +  * p : Purple 
 +  * c : Cyan 
 +  * w : White 
  
-0 == "" (true) is not equivalent to 0 eq "" (false: it evaluates to "0" eq ""). 
  
-"a" ieq "b" (true: (int)"a" is 0 and (int)"b" is 0) is not equivalent to "a" == "b" (false).+===== $K(key- Kamailio Constants =====
  
-Note: internally == and != are converted on startup to eq/ne/ieq/ine  whenever possible (both operand types can be safely determined at start time and they are the same). +$K(key- return the numeric values corresponding to Kamailio configuration constants.
  
-  - 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. Exceptionthe left operand is undef. This applies to the following operators: +, == and !=. +The key can be:
-     Special case: undef as left operand: +
-     For +: undef + expr -> undef is converted to string => "" + expr. +
-     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).+
  
-  - expression evaluation changes: Kamailio will auto-convert to integer or string in function of the operators:  +  * IPv4 return AF_INET 
-       int(undef)==0,  int("")==0, int("123")==123, int("abc")==0 +  * IPv6 return AF_INET6 
-       str(undef)=="", str(123)=="123".+  * UDP - return PROTO_UDP 
 +  * TCP - return PROTO_TCP 
 +  * TLS - return PROTO_TLS 
 +  * SCTP - return PROTO_SCTP 
 +  * WS - return PROTO_WS 
 +  * WSS - return PROTO_WSS
  
-  - script operators for dealing with empty/undefined variables 
-      defined expr - returns true if expr is defined, and false if not. 
-                     Note: only a standalone avp or pvar can be 
-                     undefined, everything else is defined. 
-      strlen(expr) - returns the lenght of expr evaluated as string. 
-      strempty(expr) - returns true if expr evaluates to the empty 
-                       string (equivalent to expr==""). 
-      Example: if (defined $v && !strempty($v)) $len=strlen($v); 
  
-===== Command Line Parameters =====+<code c> 
 +xinfo("proto UDP numeric id: $K(UDP)\n"); 
 +</code> 
 +===== Examples =====
  
-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**:+A few examples of usage.
  
-<code> +Example 1. Pseudo-variables usage 
-# kamailio -h +<code c
- +... 
-version: kamailio 5.4.0-dev4 (x86_64/darwin) 8c1864 +avp_aliases="uuid=I:50
-Usage: kamailio [options] +... 
-Options: +route { 
-    -a mode      Auto aliases mode: enable with yes or on, +... 
-                  disable with no or off +    $avp(uuid)="caller_id"; 
-    --alias=val  Add an alias, the value has to be '[proto:]hostname[:port]' +    $avp(i:20)= $avp(uuid": " + $fu; 
-                  (like for 'alias' global parameter) +    xdbg("$(C(bg))avp(i:20)$(C(xx)) [$avp(i:20)] $(C(br))cseq$(C(xx))=[$hdr(cseq)]\n"); 
-    -A define    Add config pre-processor define (e.g., -A WITH_AUTH, +... 
-                  -A 'FLT_ACC=1', -A 'DEFVAL="str-val"') +
-    -b nr        Maximum receive buffer size which will not be exceeded by +...
-                  auto-probing procedure even if  OS allows +
-    -c           Check configuration file for syntax errors +
-    -d           Debugging mode (multiple -d increase the level) +
-    -D           Control how daemonize is done: +
-                  -D..do not fork (almost) anyway; +
-                  -DD..do not daemonize creator; +
-                  -DDD..daemonize (default) +
-    -e           Log messages printed in terminal colors (requires -E) +
-    -E           Log to stderr +
-    -f file      Configuration file (default: /usr/local/etc/kamailio/kamailio.cfg) +
-    -g gid       Change gid (group id) +
-    -G file      Create a pgid file +
-    -h           This help message +
-    --help       Long option for `-h` +
-    -I           Print more internal compile flags and options +
-    -K           Turn on "via:host checking when forwarding replies +
-    -l address   Listen on the specified address/interface (multiple -l +
-                  mean listening on more addresses). The address format is +
-                  [proto:]addr_lst[:port][/advaddr], +
-                  where proto=udp|tcp|tls|sctp, +
-                  addr_lst= addr|(addr, addr_lst)+
-                  addr=host|ip_address|interface_name and +
-                  advaddr=addr[:port] (advertised address)+
-                  E.g: -l localhost, -l udp:127.0.0.1:5080, -l eth0:5062, +
-                  -l udp:127.0.0.1:5080/1.2.3.4:5060, +
-                  -l "sctp:(eth0)", -l "(eth0, eth1, 127.0.0.1):5065"+
-                  The default behaviour is to listen on all the interfaces. +
-    --loadmodule=name load the module specified by name +
-    --log-engine=log engine name and data +
-    -L path      Modules search path (default: /usr/local/lib64/kamailio/modules) +
-    -m nr        Size of shared memory allocated in Megabytes +
-    --modparam=modname:paramname:type:value set the module parameter +
-                  type has to be 's' for string value and 'i' for int value, +
-                  example: --modparam=corex:alias_subdomains:s:kamailio.org +
-    -M nr        Size of private memory allocated, in Megabytes +
-    -n processes Number of child processes to fork per interface +
-                  (default: 8) +
-    -N           Number of tcp child processes (defaultequal to `-n') +
-    -O nr        Script optimization level (debugging option) +
-    -P file      Create a pid file +
-    -Q           Number of sctp child processes (defaultequal to `-n') +
-    -r           Use dns to check if is necessary to add a "received=" +
-                  field to a via +
-    -R           Same as `-r` but use reverse dns; +
-                  (to use both use `-rR`) +
-    --server-id=num set the value for server_id +
-    --subst=exp set a subst preprocessor directive +
-    --substdef=exp set a substdef preprocessor directive +
-    --substdefs=exp set a substdefs preprocessor directive +
-    -S           disable sctp +
-    -t dir       Chroot to "dir" +
-    -T           Disable tcp +
-    -u uid       Change uid (user id) +
-    -v           Version number +
-    --version    Long option for `-v` +
-    -V           Alternative for `-v` +
-    -x name      Specify internal manager for shared memory (shm) +
-                  - can be: fm, qm or tlsf +
-    -X name      Specify internal manager for private memory (pkg) +
-                  - if omitted, the one for shm is used +
-    -Y dir       Runtime dir path +
-    -w dir       Change the working directory to "dir" (default: "/") +
-    -W type      poll method (depending on support in OS, it can be: poll, +
-                  epoll_lt, epoll_et, sigio_rt, select, kqueue, /dev/poll)+
 </code> </code>
  
-==== Log Engine CLI Parameter ====+==== Request-URI and Destination-URI parsing ====
  
-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.+Following are some examples how RURI and DURI are parsed, for SIP-URIs, tel-URIs and Service-URNs:
  
-The value of this parameter can be **--log-engine=name** or **--log-engine=name:data**.+<code> 
 + === Request URI contains SIP URI === 
 +$ru = "sip:example.com" 
 +$rz = "sip" 
 +$rU = "<null>" 
 +$rd = "example.com" 
 +$rp = "5060" 
 +$rP = "UDP"
  
-The name of the log engine can be:+=== Request URI contains SIP URI === 
 +$ru = "sips:john.q.public:hispw@example.com:6061;transport=tls;foo=bar" 
 +  $rz = "sips" 
 +  $rU = "john.q.public" 
 +  $rd = "example.com" 
 +  $rp = "6061" 
 +  $rP = "tls"
  
-  * **json** - write logs in structured JSON format +=== Request URI contains service URN === 
-    * the **data** for **json** log engine can be a set of character flags+$ru = "urn:service:sos.fire" 
-      * **a** - add log prefix as a special field +  $rz = "urn" 
-      * **A** - do not add log prefix +  $rU = "service" 
-      * **c** - add Call-ID (when available) as a dedicated JSON attribute +  $rd = "sos.fire" 
-      * **M** - strip EOL ('\n') from the value of the log message field +  $rp = "5060" 
-      * **N** - do not add EOL at the end of JSON document+  $rP = "UDP"
  
-Example of JSON logs when running Kamailio with "**--log-engine=json:M**" +=== Request URI contains telURI === 
- +$ru = "tel:+1-201-555-0123" 
-<code> +  $rz = "tel" 
-{ "idx": 1"pid": 18239, "level""DEBUG""module""maxfwd", "file": "mf_funcs.c", "line": 74, "function": "is_maxfwd_present", "logprefix": "{1 1 OPTIONS 715678756@192.168.188.20} ", "message": "value = 70 }+  $rU = "+1-201-555-0123" 
 +  $rd = "<null>" 
 +  $rp = "5060" 
 +  $rP = "UDP"
  
-{ "idx"1, "pid": 18239, "level": "DEBUG", "module": "core", "file": "core/socket_info.c""line": 644, "function""grep_sock_info""logprefix""{1 1 OPTIONS 715678756@192.168.188.20} ", "message": "checking if host==us: 9==9 && [127.0.0.1] == [127.0.0.1]}+=== Request URI contains telURI with phone-context === 
 +$ru = "tel:7042;phone-context=example.com" 
 +  $rz = "tel" 
 +  $rU = "7042" 
 +  $rd = "<null>" 
 +  $rp = "5060" 
 +  $rP = "UDP"
  
 +=== Destination URI (must be a SIP(S) URI) ===
 +$du = "sip:example.com:6061;transport=tls;foo=bar"
 +  $dd = "example.com"
 +  $dp = "6061"
 +  $dP = "tls"
 </code> </code>
cookbooks/devel/pseudovariables.txt · Last modified: 2022/04/11 15:24 by henningw