This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision Next revision Both sides next revision | ||
tutorials:faq:main [2013/04/06 12:16] miconda [Tools] |
tutorials:faq:main [2018/05/08 08:30] 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, 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, | ||
??? What is the license of Kamailio? | ??? What is the license of Kamailio? | ||
Line 130: | Line 132: | ||
make install include_modules=" | make install include_modules=" | ||
</ | </ | ||
+ | |||
+ | ??? How to compile only one module? | ||
+ | |||
+ | !!! First be sure that the core compiles fine with the command: | ||
+ | |||
+ | < | ||
+ | make | ||
+ | </ | ||
+ | |||
+ | To compile a single module, use: | ||
+ | |||
+ | < | ||
+ | make modules modules=modules/ | ||
+ | </ | ||
+ | |||
+ | Replace modname with the real name of the module you want to compile -- for example, compiling only tls module: | ||
+ | |||
+ | < | ||
+ | make modules modules=modules/ | ||
+ | </ | ||
+ | |||
=?==== SIP Message Processing ===== | =?==== SIP Message Processing ===== | ||
Line 168: | Line 191: | ||
</ | </ | ||
+ | |||
+ | ??? 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, | ||
+ | |||
+ | Example: | ||
+ | |||
+ | * add X-VBox header only when sending to voicemail server | ||
+ | * add X-Peer-ID header when sending somewhere else | ||
+ | |||
+ | < | ||
+ | request_route { | ||
+ | ... | ||
+ | if(is_method(" | ||
+ | t_on_branch(" | ||
+ | t_on_failure(" | ||
+ | } | ||
+ | t_relay(); | ||
+ | exit; | ||
+ | } | ||
+ | |||
+ | branch_route[SETHEADERS] { | ||
+ | | ||
+ | | ||
+ | } else { | ||
+ | | ||
+ | } | ||
+ | } | ||
+ | |||
+ | failure_route[REROUTE] { | ||
+ | if (t_is_canceled()) { | ||
+ | exit; | ||
+ | } | ||
+ | if (t_check_status(" | ||
+ | $du = $null; | ||
+ | $ru = " | ||
+ | t_on_failure(" | ||
+ | exit; | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | 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(), | ||
+ | |||
+ | <code c> | ||
+ | request_route { | ||
+ | ... | ||
+ | uac_replace_from(" | ||
+ | uac_replace_from(" | ||
+ | ... | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | Results in From header having the URI: " | ||
+ | |||
+ | |||
+ | ??? 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, | ||
+ | |||
+ | 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 ' | ||
+ | |||
+ | For example, incoming message: | ||
+ | < | ||
+ | Record-Route: | ||
+ | Record-Route: | ||
+ | < | ||
+ | </ | ||
+ | |||
+ | Dump all headers: | ||
+ | < | ||
+ | xlog(" | ||
+ | </ | ||
+ | |||
+ | Dump the first header (< | ||
+ | < | ||
+ | xlog(" | ||
+ | </ | ||
+ | |||
+ | Dump the second last header (< | ||
+ | < | ||
+ | xlog(" | ||
+ | </ | ||
+ | |||
+ | Remove the last header (< | ||
+ | < | ||
+ | remove_hf_value(" | ||
+ | #or in above case: | ||
+ | remove_hf_value(" | ||
+ | </ | ||
+ | |||
+ | ??? Why the SIP requests are replied with "483 Too Many Hops" or "513 Message Too Large"? | ||
+ | |||
+ | !!! In both cases, the reason is probably an error in request routing script which caused an infinite loop. | ||
+ | |||
+ | You can easily verify whether this happens by watching SIP traffic on loopback interface, for example using ngrep: | ||
+ | |||
+ | < | ||
+ | ngrep -d lo -qt -W byline port 5060 | ||
+ | </ | ||
+ | |||
+ | |||
+ | A typical reason for misrouting is a failure to match local domain correctly. If a server fails to recognize a request for itself, it will try to forward it to current URI in believe it would forward them to a foreign domain. | ||
+ | |||
+ | Alas, it forwards the request to itself again. This continues to happen until value of the max_forwards header field reaches zero or the request grows too big. | ||
+ | |||
+ | The solution: make sure that domain matching is correctly configured. | ||
+ | |||
+ | A quick way to achieve that is to introduce a config option to kamailio.cfg: | ||
+ | |||
+ | < | ||
+ | alias=domainname | ||
+ | </ | ||
+ | |||
+ | where domainname has to be replaced with name of domain, which you wish to serve by Kamailio and which appears in request-URIs. | ||
+ | |||
+ | |||
+ | ??? I send SIP requests to Kamailio, but nothing happens, why? | ||
+ | |||
+ | !!! 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. | ||
+ | |||
+ | If you have the pike module loaded, double 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 189: | Line 340: | ||
??? What are the minimum knowledge requirements before starting with Kamailio? | ??? What are the minimum knowledge requirements before starting with Kamailio? | ||
- | !!! To be familiar with Linux and understand Session Initiation Protocol (SIP - RFC3261). | + | !!! To be familiar with Linux or UNIX (FreeBSD, OpenBSD, OS/X) and understand Session Initiation Protocol (SIP - RFC3261). |
??? Any step-by-step guide to install Kamailio? | ??? Any step-by-step guide to install Kamailio? | ||
Line 228: | Line 379: | ||
!!! Use the bug tracker available at: | !!! Use the bug tracker available at: | ||
- | * http://sip-router.org/tracker | + | * https://github.com/kamailio/ |
??? Where can I buy commercial support? | ??? Where can I buy commercial support? | ||
Line 332: | Line 483: | ||
=?==== Configuration File Processing ===== | =?==== Configuration File Processing ===== | ||
+ | |||
+ | |||
+ | ??? Can I check the configuration files for syntax errors? | ||
+ | |||
+ | !!! Yes. Use ' | ||
+ | |||
+ | < | ||
+ | / | ||
+ | </ | ||
+ | |||
+ | Note that even configuration file is reported to be ok, there might still be troubles starting kamailio with the respective configuration file. For example, the database URL can be syntactically correct, but the access itself is not working due to wrong username or password, causing kamailio to fail starting. | ||
??? Do I have to delete the AVPs added in the configuration file for a SIP message? | ??? Do I have to delete the AVPs added in the configuration file for a SIP message? | ||
Line 343: | Line 505: | ||
</ | </ | ||
- | =?==== SIP Requests Routing ===== | + | ??? What is a pseudo-variable? |
- | ??? Why the SIP requests are replied | + | !!! A pseudo-variable is a special token that is expanded at runtume |
- | !!! In both cases, | + | A pseudo-variable can refer to the value of an avp, body of a header, part of a SIP message or other variables from system. |
- | You can easily verify whether this happens by watching SIP traffic on loopback interface, for example using ngrep: | + | For more see: |
+ | * http:// | ||
- | < | + | ??? How to iterate through the items in a comma separated string? |
- | ngrep -d lo -qt -W byline port 5060 | + | |
+ | !!! If you have a variable holding a string like " | ||
+ | |||
+ | Here is an example: | ||
+ | |||
+ | < | ||
+ | $var(x) = " | ||
+ | $var(i) = 0; | ||
+ | |||
+ | while( $(var(x){s.select, | ||
+ | | ||
+ | | ||
+ | } | ||
</ | </ | ||
+ | ??? How is the function return code evaluated? | ||
- | A typical reason for misrouting is a failure to match local domain correctly. If a server fails to recognize a request for itself, it will try to forward it to current URI in believe it would forward them to a foreign domain. | + | !!! Configuration file interpreter evaluates the return code of a function as follow: |
- | Alas, it forwards the request | + | * <0 (negative value) - it is evaluated |
+ | * >0 (positive | ||
+ | * =0 (zero) - it is evaluated as exit (stop execution of configuration file) | ||
- | The solution: make sure that domain matching is correctly configured. | + | Example: |
- | A quick way to achieve that is to introduce a config option to kamailio.cfg: | + | <code c> |
- | < | + | if(function_returns_one()) { |
- | alias=domainname | + | # it goes here |
+ | } else { | ||
+ | # it doesn' | ||
+ | } | ||
+ | ... | ||
+ | if(function_returns_minus_one()) { | ||
+ | # it doesn' | ||
+ | } else { | ||
+ | # it goes here | ||
+ | } | ||
+ | ... | ||
+ | if(function_returns_zero()) { | ||
+ | # it doesn' | ||
+ | } else { | ||
+ | # it doesn' | ||
+ | } | ||
</ | </ | ||
- | where domainname has to be replaced with name of domain, which you wish to serve by Kamailio | + | Note that you can use $rc to get the return code value, like: |
+ | |||
+ | <code c> | ||
+ | function(); | ||
+ | xlog(" | ||
+ | </ | ||
+ | |||
+ | 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. | ||
+ | |||
+ | ??? How is the SIP request retransmission handled? | ||
+ | |||
+ | !!! The next snippet is detecting retransmissions: | ||
+ | |||
+ | <code c> | ||
+ | # handle retransmissions | ||
+ | if (!is_method(" | ||
+ | if(t_precheck_trans()) { | ||
+ | t_check_trans(); | ||
+ | exit; | ||
+ | } | ||
+ | t_check_trans(); | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | The **ACK** request is skipped because it doesn' | ||
+ | |||
+ | The function **t_precheck_trans()** returns true if the same SIP request is processed at that time by another | ||
+ | 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 382: | Line 602: | ||
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 | + | * **-M SIZE** - specify the private |
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 422: | Line 642: | ||
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, | ||
+ | |||
+ | Example: | ||
+ | |||
+ | < | ||
+ | # - next command fails | ||
+ | kamcmd uac.reg_refresh 1001 | ||
+ | |||
+ | # use instead | ||
+ | kamcmd uac.reg_refresh s:1001 | ||
+ | </ |