User Tools

Site Tools


tutorials:faq:main

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
tutorials:faq:main [2013/04/06 19:30]
miconda [Configuration File Processing]
tutorials:faq:main [2021/08/27 08:11] (current)
miconda [SIP Message Processing]
Line 47: Line 47:
 ??? Is it possible to reload Kamailio configuration file? ??? Is it possible to reload Kamailio configuration file?
  
-!!! No, you must restart after you update the configuration file.+!!! If you use native scripting language, you must restart after you update the configuration file.
  
 But note that many global parameters can be changed via RPC/MI commands without restart (e.g., TCP connecting timeout, debug level). Applying changes related to loaded modules or routing block require always a restart. But note that many global parameters can be changed via RPC/MI commands without restart (e.g., TCP connecting timeout, debug level). Applying changes related to loaded modules or routing block require always a restart.
 +
 +If you use a KEMI scripting language (Lua, Python, JavaScript, Ruby, Squirrel), then you can reload the routing logic script without restarting Kamailio by issuing an RPC command (see KEMI interpreter modules documentation for more details: app_lua, app_python, app_python3, app_jsdt, app_ruby, app_sqlang).
  
 ??? What is the license of Kamailio? ??? What is the license of Kamailio?
  
-!!! Kamailio is an open source application licensed under GNU Public License version 2 (aka GPLv2). It can be used for free "as in beer".+!!! Kamailio is an open source application licensed under GNU Public License version 2 (aka GPLv2). It can be used for free "as in beer" on your infrastructure. Keep in mind that you need also distribute the source code of your changes, if you distribute it as a binary to your customer. For more information have a look to the [[https://www.gnu.org/licenses/old-licenses/gpl-2.0-faq.html.en|GPLv2 FAQ]].
  
 Starting with end of 2008, contributions to core and several modules are done under BSD license. That means parts of it can be extracted and used under BSD license terms. But over all, when used as one application, the use must follow the terms of GPLv2, because GPLv2 is viral.  Starting with end of 2008, contributions to core and several modules are done under BSD license. That means parts of it can be extracted and used under BSD license terms. But over all, when used as one application, the use must follow the terms of GPLv2, because GPLv2 is viral. 
Line 130: Line 132:
 make install include_modules="db_mysql"  make install include_modules="db_mysql" 
 </code> </code>
 +
 +??? How to compile only one module?
 +
 +!!! First be sure that the core compiles fine with the command:
 +
 +<code>
 +make 
 +</code>
 +
 +To compile a single module, use:
 +
 +<code>
 +make modules modules=modules/modname
 +</code>
 +
 +Replace modname with the real name of the module you want to compile -- for example, compiling only tls module:
 +
 +<code>
 +make modules modules=modules/tls
 +</code>
 +
 =?==== SIP Message Processing ===== =?==== SIP Message Processing =====
  
Line 144: Line 167:
   * without applying changes   * without applying changes
  
-<code>+<code c>
 append_hf("X-Hdr: xyz\r\n"); append_hf("X-Hdr: xyz\r\n");
  
Line 156: Line 179:
   * with applying changes   * with applying changes
  
-<code>+<code c>
 append_hf("X-Hdr: xyz\r\n"); append_hf("X-Hdr: xyz\r\n");
  
Line 168: Line 191:
 </code> </code>
  
 +??? Why parts of From/To header appear many times?
 +
 +!!! After doing header management operations, it can result that parts of From/To header are duplicated or the result is the concatenation of many values. That is related to previous question, because the changes are not applied immediately and updates to parts of headers are not a simple set operation.
 +
 +For example, if From username is "alice" and the operations in the config file are:
 +
 +<code c>
 +$fU = "bob";
 +...
 +$fU = "carol";
 +</code>
 +
 +The result can be that From username is "bobcarol".
 +
 +One solution is to use **msg_apply_changes()** in between:
 +
 +<code c>
 +$fU = "bob";
 +msg_apply_changes();
 +...
 +$fU = "carol";
 +</code>
 +
 +Another solution is to keep the value in a variable (e.g., avp or xavp) and do the operation only once, like:
 +
 +<code c>
 +$xavp(fuser) = "bob";
 +...
 +$xavp(fuser[0]) = "carol";
 +...
 +$fU = $xavp(fuser);
 +</code>
 +
 +Updating From/To headers is recommended to be done in **branch_route**, specially if it is needed to have different value for outgoing branches.
 +
 +The examples above were with assignments to $fU (can be other vars as well, such as $fu, $tU, $tu, ..), but it is the same behaviour when using functions such as uac_replace_from() or uac_replace_to().
 +
 +??? Why body or other parts of the SIP message appear multiple times?
 +
 +!!! It is practically the same reason as for multiple From/To parts.
 +
 +The configuration file does an operation that changes parts in the headers or body many times. For example, if the body has two concatenated IP addresses for media stream, then likely the rtpproxy function is used twice, or, if the SDP appears two time, then the rtpengine function is used two times.
 +
 +If the update has to be done many times, use **msg_apply_changes()** in between, otherwise refactor the config to perform the operation only once (e.g., the RTP relaying functions should be used in a branch_route block).
 +
 +??? How to set different header values for each destination of a SIP request?
 +
 +!!! Set the value of the header inside a **branch_route**.
 +
 +All the operations done over a SIP message inside the **request_route** (including from the sub-routes executed from request_route) will be common to all outgoing branches. If you want to do updates only for specific destinations, use branch routes.
 +
 +Example:
 +
 +  * add X-VBox header only when sending to voicemail server
 +  * add X-Peer-ID header when sending somewhere else
 +
 +<code c>
 +request_route {
 +  ...
 +  if(is_method("INVITE")) {
 +    t_on_branch("SETHEADERS");
 +    t_on_failure("REROUTE");
 +  }
 +  t_relay();
 +  exit;
 +}
 +
 +branch_route[SETHEADERS] {
 +   if($rd=="voicemail.server.com") {
 +     append_hf("X-VBox: $fU\r\n");
 +   } else {
 +     append_hf("X-Peer-ID: abc\r\n");
 +   }
 +}
 +
 +failure_route[REROUTE] {
 +  if (t_is_canceled()) {
 +    exit;
 +  }
 +  if (t_check_status("486|408")) {
 +    $du = $null;
 +    $ru = "sip:voicemail.server.com";
 +    t_on_failure("REROUTE");
 +    exit;
 +  }
 +}
 +</code>
 +
 +Very important is also to be aware that doing same operation many times in request_route is not overwriting the previous value, but combines them. For example, if you do two times uac_replace_from(), the From header can become corrupt. Like:
 +
 +<code c>
 +request_route {
 +  ...
 +  uac_replace_from("sip:test1@kamailio.org");
 +  uac_replace_from("sip:test2@kamailio.org");
 +  ...
 +}
 +</code>
 +
 +Results in From header having the URI: **sip:test1@kamailio.orgsip:test2@kamailio.org**. Again, use branch_route to do the operations if you need different From header for outgoing branches.
 +
 +
 +??? How to remove a single header field when a header appears multiple times?
 +
 +!!! SIP allows that certain header fields may appear multiple times in a SIP message. This header fields (e.g. Via, Route, Record-Route, Contact) may be written either on a single line (with comma separated) or on multiple lines (see [[http://tools.ietf.org/html/rfc3261#section-7.3|RFC 3261 section 7.3]] for details).
 +
 +The remove_hf() function from textops module always removes all header fields with a certain name, thus it can not be used in this case.
 +
 +To address a certain header (regardless if headers are in a single line or in separate lines) use the @hf_value select. The trick is to load the textopsx module (this select used to be in ser's textops module). Note, header names must use '_' instead of '-'. To delete or manipulate a certain header also use the functions from the textopsx module, e.g: remove_hf_value(). Note, here '-' is used for headers with '-'
 +
 +For example, incoming message:
 +<code>
 +Record-Route: <sip:1.1.1.1;lr=on;nat=yes>
 +Record-Route: <sip:2.2.2.2:5060;lr;transport=udp>,
 +   <sip:3.3.3.3:22506;lr;transport=udp>
 +</code>
 +
 +Dump all headers:
 +<code>
 +xlog("$sel(@hf_value.Record_Route)");
 +</code>
 +
 +Dump the first header (<sip:1.1.1.1;lr=on;nat=yes>):
 +<code>
 +xlog("$sel(@hf_value.Record_Route[1])");
 +</code>
 +
 +Dump the second last header (<sip:2.2.2.2:5060;lr;transport=udp>):
 +<code>
 +xlog("$sel(@hf_value.Record_Route[-2])");
 +</code>
 +
 +Remove the last header (<sip:3.3.3.3:22506;lr;transport=udp>):
 +<code>
 +remove_hf_value("Record-Route[-1]");
 +#or in above case:
 +remove_hf_value("Record-Route[3]");
 +</code>
  
 ??? Why the SIP requests are replied with "483 Too Many Hops" or "513 Message Too Large"? ??? Why the SIP requests are replied with "483 Too Many Hops" or "513 Message Too Large"?
Line 199: Line 360:
 !!! Check if you have a firewall rule dropping traffic on SIP port (5060). Note that network sniffing tools have hooks in kernel before the firewall, so even if you see the SIP packets with ngrep or wireshark, they may be dropped by the firewall. !!! Check if you have a firewall rule dropping traffic on SIP port (5060). Note that network sniffing tools have hooks in kernel before the firewall, so even if you see the SIP packets with ngrep or wireshark, they may be dropped by the firewall.
  
-You can increase the debug parameter value to 3 in the configuration filerestart kamailio and watch syslog messages to see if there is any text printed by kamailio. For each SIP packet received on the networks, Kamailio is printing at least few debug messages.+If you have the pike module loadeddouble check to see if you don't block valid trusted traffic with it.
  
 +You can increase the debug parameter value to 3 in the configuration file, restart kamailio and watch syslog messages to see if there is any text printed by kamailio. For each SIP packet received on the networks, Kamailio is printing at least few debug messages.
 =?==== Media Streams ===== =?==== Media Streams =====
  
Line 206: Line 368:
  
 !!! No, //however// Kamailio can be configured to proxy media if needed.  !!! No, //however// Kamailio can be configured to proxy media if needed. 
-  * [[http://www.kamailio.org/docs/modules/stable/|See rtpproxy, iptrtpproxyand mediaproxy]]+  * [[http://www.kamailio.org/docs/modules/stable/|See rtpengine, rtpproxy, lrkproxyor mediaproxy]]
  
 ??? What codecs are supported by Kamailio? ??? What codecs are supported by Kamailio?
Line 261: Line 423:
  
 !!! Use the bug tracker available at: !!! Use the bug tracker available at:
-  * http://sip-router.org/tracker+  * https://github.com/kamailio/kamailio/issues
  
 ??? Where can I buy commercial support? ??? Where can I buy commercial support?
Line 395: Line 557:
 For more see: For more see:
   * http://www.kamailio.org/wiki/cookbooks/devel/pseudovariables   * http://www.kamailio.org/wiki/cookbooks/devel/pseudovariables
 +
 +??? How to iterate through the items in a comma separated string?
 +
 +!!! If you have a variable holding a string like "a,b,c,d" and want to get each character separately, you have to use a WHILE loop with {s.count,separator} and {s.select,index,separator} transformations.
 +
 +Here is an example:
 +
 +<code c>
 +$var(x) = "a,b,c,d";
 +$var(i) = 0;
 +$var(n) = $(var(x){s.count,,});
 +
 +while( $var(i) <= $var(n) ) {
 +   xlog("token at position $var(i) is: $(var(x){s.select,$var(i),,})\n");
 +   $var(i) = $var(i) + 1;
 +}
 +</code>
 +
 +??? How is the function return code evaluated?
 +
 +!!! Configuration file interpreter evaluates the return code of a function as follow:
 +
 +  * <0 (negative value) - it is evaluated to false
 +  * >0 (positive value) - it is evaluated to true
 +  * =0 (zero) - it is evaluated as exit (stop execution of configuration file)
 +
 +Example:
 +
 +<code c>
 +
 +if(function_returns_one()) {
 +   # it goes here
 +} else {
 +   # it doesn't go here
 +}
 +...
 +if(function_returns_minus_one()) {
 +   # it doesn't go here
 +} else {
 +   # it goes here
 +}
 +...
 +if(function_returns_zero()) {
 +   # it doesn't go here
 +} else {
 +   # it doesn't go here
 +}
 +</code>
 +
 +Note that you can use $rc to get the return code value, like:
 +
 +<code c>
 +function();
 +xlog("returned code by function() is $rc\n");
 +</code>
 +
 +However, if return code is 0, the next action after function() is not executed. It can be used only of positive or negative response code.
 +
 +On the other hand, the pseudo-variables (including $rc) have to be compared as an integer, the rules for evaluating return code of the functions do not apply, for example:
 +
 +<code c>
 +$var(x) = 0;
 +if($var(x) == 0) {
 +  # do something
 +}
 +</code>
 +
 +To compare the return code of a function with a number is recommended to use the value stored in $rc, because the priority of the operators can convert function return code to internal-true or internal-false. Therefore the next approach should be used:
 +
 +<code c>
 +function_returns_four();
 +$var(rc4) = $rc;
 +if($var(rc4)==4) {
 +   # it goes here
 +} else {
 +   # it doesn't go here
 +}
 +...
 +function_returns_two();
 +$var(rc2) = $rc;
 +if($var(rc4)==$var(rc2)) {
 +   # it doesn't go here
 +} else {
 +   # it goes here
 +}
 +...
 +if (function_returns_four() && $rc ieq 6 ) {
 +   # it doesn't go here
 +} else if ($rc ieq 4) {
 +   # it goes here
 +} else {
 +   # it doesn't go here
 +}
 +</code>
 +
 +Note that $rc is overwritten by a new function call, therefore store its value in another variable (like $var(...)) if it is needed for longer time.
 +
 +For pseudo-variables, the non-zero value is evaluated to true and zero to false, for example:
 +
 +<code c>
 +$var(x) = 1;
 +if($var(x)) {
 +  # do something
 +}
 +</code>
 +
 +??? How is the SIP request retransmission handled?
 +
 +!!! The next snippet is detecting retransmissions:
 +
 +<code c>
 +    # handle retransmissions
 +      if (!is_method("ACK")) {
 +          if(t_precheck_trans()) {
 +              t_check_trans();
 +              exit;
 +          }
 +          t_check_trans();
 +      }
 +</code>
 +
 +The **ACK** request is skipped because it doesn't have a SIP response, therefore it doesn't create a transaction, being forwarded in stateless mode.
 +
 +The function **t_precheck_trans()** returns true if the same SIP request is processed at that time by another Kamailio process, so in this case it is a retransmission. The inner **t_check_trans()** has the role of detecting if the SIP transaction was created by the other process, and if yes, send again the last SIP response of the transaction, when one was already sent out (a requirement from SIP specs). The **exit** is then used to finish the execution of the config file for that request.
 +
 +If the function **t_precheck_trans()** returns false, the SIP request is not under processing by another Kamailio process, but it can be the case that the request processing was finished, request being sent out in stateful mode, therefore **t_check_trans()** is used to see if a transaction is found in shared memory corresponding to the same request. If such transaction is found in shared memory, then **t_check_trans()** triggers internally the **exit** for configuration file execution.
 =?==== Troubleshooting ===== =?==== Troubleshooting =====
  
Line 407: Line 695:
 To increase the sizes for memory pools you have to give following command line parameters: To increase the sizes for memory pools you have to give following command line parameters:
   * **-m SIZE** - specify the shared memory size in MB   * **-m SIZE** - specify the shared memory size in MB
-  * **-M SIZE** - specify the shared memory size in MB+  * **-M SIZE** - specify the private memory size in MB
  
 For example, start Kamailio with 512MB of shared memory and 8MB of private memory: For example, start Kamailio with 512MB of shared memory and 8MB of private memory:
Line 447: Line 735:
  
 Check also the access privileges of the FIFO file in order to be sure that the user running kamctl can read and write to the file. Check also the access privileges of the FIFO file in order to be sure that the user running kamctl can read and write to the file.
 +
 +??? Kamcmd sometime fails to execute RPC commands with number parameters, why?
 +
 +!!! There are situations when a **kamcmd** RPC command fails because the parameters that are provided are auto-converted to integer numbers. This happens when the implementation of the RPC commands expects a string parameter (e.g., username). 
 +
 +To prevent **kamcmd** to do the auto-conversion, you can prefix its parameter with **s:**.
 +
 +Example:
 +
 +<code>
 +# - next command fails
 +kamcmd uac.reg_refresh 1001
 +
 +# use instead
 +kamcmd uac.reg_refresh s:1001
 +</code>
tutorials/faq/main.1365269451.txt.gz ยท Last modified: 2013/04/06 19:30 by miconda