Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
old-content:openser_core_cookbook [2012/03/20 19:11] – old revision restored 80.250.1.245 | old-content:openser_core_cookbook [2012/03/22 12:11] (current) – old revision restored 80.250.1.245 | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== OpenSER Core CookBook ====== | ||
+ | This page is dedicated to OpenSER core interaction with the configuration script (openser.cfg). These parameters, keywords, and functions are exported by OpenSER' | ||
+ | |||
+ | This list is not complete yet. It will eventually, and with your help, that will happen sooner. | ||
+ | |||
+ | Please contribute only to the items you are sure you know what they mean. | ||
+ | |||
+ | Thank you! | ||
+ | |||
+ | IMPORTANT: This document is only valid for OpenSER development version (v1.2.0) | ||
+ | |||
+ | |||
+ | ===== Core Keywords ===== | ||
+ | |||
+ | Keywords specific to SIP messages which can be used mainly in ' | ||
+ | |||
+ | ==== af ==== | ||
+ | |||
+ | 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. | ||
+ | |||
+ | Exampe of usage: | ||
+ | |||
+ | if(af==INET6) { | ||
+ | log(" | ||
+ | }; | ||
+ | |||
+ | |||
+ | |||
+ | ==== dst_ip ==== | ||
+ | |||
+ | 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. | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | | ||
+ | log(" | ||
+ | }; | ||
+ | |||
+ | ==== dst_port ==== | ||
+ | |||
+ | The local port where the SIP packet was received. When OpenSER is listening on many ports, it is useful to learn which was the one that received the SIP packet. | ||
+ | |||
+ | Example of usage: | ||
+ | | ||
+ | { | ||
+ | | ||
+ | }; | ||
+ | |||
+ | ==== from_uri ==== | ||
+ | |||
+ | This script variable is a reference to the URI of ' | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | if(is_method(" | ||
+ | { | ||
+ | log(" | ||
+ | }; | ||
+ | |||
+ | ==== method ==== | ||
+ | |||
+ | The variable is a reference to the SIP method of the message. | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | if(method==" | ||
+ | { | ||
+ | | ||
+ | }; | ||
+ | |||
+ | ==== msg:len ==== | ||
+ | |||
+ | The variable is a reference to the size of the message. It can be used in ' | ||
+ | |||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | if(msg: | ||
+ | { | ||
+ | sl_send_reply(" | ||
+ | exit; | ||
+ | }; | ||
+ | |||
+ | ==== retcode ==== | ||
+ | |||
+ | It represents the value returned by last function executed (similar to $? from bash -- if you wish, you can use also $? in OpenSER config, both names ' | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | route { | ||
+ | | ||
+ | | ||
+ | { | ||
+ | | ||
+ | }; | ||
+ | } | ||
+ | | ||
+ | |||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | } | ||
+ | |||
+ | ==== proto ==== | ||
+ | |||
+ | This variable can be used to test the transport protocol of the SIP message. | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | if(proto==UDP) | ||
+ | { | ||
+ | log(" | ||
+ | }; | ||
+ | |||
+ | |||
+ | ==== status ==== | ||
+ | |||
+ | If used in onreply_route, | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | if(status==" | ||
+ | { | ||
+ | log(" | ||
+ | }; | ||
+ | |||
+ | ==== src_ip ==== | ||
+ | |||
+ | Reference to source IP address of the SIP message. | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | if(src_ip==127.0.0.1) | ||
+ | { | ||
+ | log(" | ||
+ | }; | ||
+ | |||
+ | ==== src_port ==== | ||
+ | |||
+ | Reference to source port of the SIP message (from which port the message was sent by previous hop). | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | if(src_port==5061) | ||
+ | { | ||
+ | log(" | ||
+ | } | ||
+ | |||
+ | ==== to_uri ==== | ||
+ | |||
+ | This variable can be used to test the value of URI from To header. | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | if(to_uri=~" | ||
+ | { | ||
+ | log(" | ||
+ | }; | ||
+ | |||
+ | |||
+ | ==== uri ==== | ||
+ | |||
+ | |||
+ | This variable can be used to test the value of the request URI. | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | if(uri=~" | ||
+ | { | ||
+ | log(" | ||
+ | }; | ||
+ | |||
+ | ===== Core Values ===== | ||
+ | |||
+ | Values that can be used in ' | ||
+ | |||
+ | ==== INET ==== | ||
+ | |||
+ | This keyword can be used to test whether the SIP packet was received over an IPv4 connection. | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | if(af==INET) | ||
+ | { | ||
+ | log(" | ||
+ | }; | ||
+ | |||
+ | ==== INET6 ==== | ||
+ | |||
+ | This keyword can be used to test whether the SIP packet was received over an IPv6 connection. | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | if(af==INET6) | ||
+ | { | ||
+ | log(" | ||
+ | }; | ||
+ | |||
+ | ==== TCP ==== | ||
+ | |||
+ | This keyword can be used to test the value of ' | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | if(proto==TCP) | ||
+ | { | ||
+ | log(" | ||
+ | }; | ||
+ | |||
+ | ==== UDP ==== | ||
+ | |||
+ | This keyword can be used to test the value of ' | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | if(proto==UDP) | ||
+ | { | ||
+ | log(" | ||
+ | }; | ||
+ | |||
+ | ==== max_len ==== | ||
+ | |||
+ | This keyword is set to the maximum size of an UDP packet. It can be used to test message' | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | if(msg: | ||
+ | { | ||
+ | sl_send_reply(" | ||
+ | exit; | ||
+ | } | ||
+ | |||
+ | |||
+ | ==== myself ==== | ||
+ | |||
+ | It is a reference to the list of local IP addresses, hostnames and aliases that has been set in OpenSER configuration file. This lists contain the domains served by OpenSER. | ||
+ | |||
+ | 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. | ||
+ | |||
+ | See " | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | if(uri==myself) { | ||
+ | log(" | ||
+ | }; | ||
+ | |||
+ | ===== Core parameters ===== | ||
+ | |||
+ | Global parameters that can be set in configuration file. | ||
+ | |||
+ | ==== advertised_address ==== | ||
+ | |||
+ | It can be an IP address or string and represents the address advertised in Via header and | ||
+ | other destination lumps (e.g RR header). If empty or not set (default value) the socket | ||
+ | address from where the request will be sent is used. | ||
+ | |||
+ | WARNING: | ||
+ | - don't set it unless you know what you are doing (e.g. nat traversal) | ||
+ | - you can set anything here, no check is made (e.g. foo.bar will be accepted even if foo.bar doesn' | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | advertised_address=" | ||
+ | |||
+ | ==== advertised_port ==== | ||
+ | |||
+ | The port advertised in Via header and other destination lumps (e.g. RR). If empty or not set (default value) the port from where the message will be sent is used. Same warnings as for ' | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | advertised_port=5080 | ||
+ | |||
+ | ==== 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 ' | ||
+ | |||
+ | It is necessary to include the port (the port value used in the " | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | alias=" | ||
+ | alias=" | ||
+ | |||
+ | ==== check_via ==== | ||
+ | |||
+ | Check if the address in top most via of replies is local. Default value is 0 (check disabled). | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | check_via=1 | ||
+ | |||
+ | ==== children ==== | ||
+ | |||
+ | Number of children to fork (one for each interface, protocol and port). Default value is 8, maximum value can be 32. | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | children=16 | ||
+ | |||
+ | ==== chroot ==== | ||
+ | |||
+ | The value must be a valid path in the system. If set, OpenSER will chroot (change root directory) to its value. | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | chroot=/ | ||
+ | |||
+ | ==== debug ==== | ||
+ | |||
+ | Set the debug level. Higher values make SER to print more debug messages. | ||
+ | |||
+ | Examples of usage: | ||
+ | |||
+ | debug=3 -- print only important messages (like errors or more critical situations) | ||
+ | - recommended for running proxy as daemon | ||
+ | |||
+ | debug=9 -- print a lot of debug messages - use it only when doing debugging sessions | ||
+ | |||
+ | The ' | ||
+ | |||
+ | For more see: http:// | ||
+ | |||
+ | ==== disable_core_dump ==== | ||
+ | |||
+ | Can be ' | ||
+ | a high enough value. Set this config variable to ' | ||
+ | (will set core limits to 0). | ||
+ | |||
+ | Default value is ' | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | disable_core_dump=yes | ||
+ | |||
+ | ==== disable_tcp ==== | ||
+ | |||
+ | Global parameter to disable TCP support in the SIP server. Default value is ' | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | disable_tcp=yes | ||
+ | |||
+ | ==== disable_tls ==== | ||
+ | |||
+ | See http:// | ||
+ | |||
+ | ==== dns ==== | ||
+ | |||
+ | This parameter controls if the SIP server should attempt to lookup its own domain name in DNS. If this parameter is set to yes and the domain name is not in DNS a warning is printed on syslog and a " | ||
+ | |||
+ | Default is no. | ||
+ | |||
+ | ==== dns_retr_time ==== | ||
+ | |||
+ | Time in seconds before retrying a dns request. Default value is system specific, | ||
+ | depends also on the '/ | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | dns_retr_time=3 | ||
+ | |||
+ | ==== dns_retr_no ==== | ||
+ | |||
+ | Number of dns retransmissions before giving up. Default value is system specific, | ||
+ | depends also on the '/ | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | dns_retr_no=3 | ||
+ | |||
+ | ==== dns_server_no ==== | ||
+ | |||
+ | How many dns servers from the ones defined in '/ | ||
+ | Default value is to use all of them. | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | dns_server_no=2 | ||
+ | |||
+ | ==== dns_try_ipv6 ==== | ||
+ | |||
+ | Can be ' | ||
+ | for ipv6 (AAAA record). Default value is ' | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | dns_try_ipv6=no | ||
+ | |||
+ | ==== dns_use_search_list ==== | ||
+ | |||
+ | Can be ' | ||
+ | will be ignored (=> fewer lookups => gives up faster). Default value is ' | ||
+ | |||
+ | HINT: even if you don't have a search list defined, setting this option | ||
+ | to ' | ||
+ | fact search "" | ||
+ | still be 2 dns queries, eg. foo+' | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | dns_use_search_list=no | ||
+ | |||
+ | ==== fifo ==== | ||
+ | |||
+ | Global paramter to set the path to FIFO file. Default value is NULL. If not set, the FIFO server is not started. | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | fifo="/ | ||
+ | |||
+ | The FIFO server offers an additional interface to the server besides listening to the line interfaces for SIP messages. The FIFO file can be used to inject e.g. SIP messages directly in to the SIP proxy with an external application. Openserctl uses this interface and therefore needs the FIFO file to be set. | ||
+ | |||
+ | ==== fifo_dir ==== | ||
+ | |||
+ | Set the directory where to create the FIFO files to reply to a FIFO command. Default value is "/ | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | fifo_dir="/ | ||
+ | |||
+ | ==== fifo_mode sock_mode file_mode ==== | ||
+ | |||
+ | Set permissions for unix sockets and fifo file created by OpenSER. Default value is ' | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | sock_mode=0600 | ||
+ | |||
+ | ==== fifo_user sock_user ==== | ||
+ | |||
+ | Set the user id to be used to create the fifo file or unix socket file (the owner of the file). | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | fifo_user=root | ||
+ | |||
+ | ==== fifo_group sock_group ==== | ||
+ | |||
+ | Set the group id to be used to create the fifo file or the unix socket file. | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | fifo_group=wheel | ||
+ | |||
+ | ==== fifo_db_url ==== | ||
+ | |||
+ | See http:// | ||
+ | |||
+ | ==== fork ==== | ||
+ | |||
+ | If set to ' | ||
+ | |||
+ | When set to ' | ||
+ | |||
+ | Default value is ' | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | fork=no | ||
+ | |||
+ | ==== group gid ==== | ||
+ | |||
+ | The group id to run OpenSER. | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | group=" | ||
+ | |||
+ | ==== listen ==== | ||
+ | |||
+ | Set the network addresses the SIP server should listen to. It can be an IP address, hostname or network iterface id or combination of protocol: | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | listen=10.10.10.10 | ||
+ | listen=eth1: | ||
+ | listen=udp: | ||
+ | |||
+ | 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. | ||
+ | |||
+ | ==== log_facility ==== | ||
+ | |||
+ | If OpenSER logs to syslog, you can control the facility for logging. Very | ||
+ | useful when you want to divert all OpenSER logs to a different log file. | ||
+ | See man page syslog(3) for more details. | ||
+ | |||
+ | For more see: http:// | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | log_facility=LOG_LOCAL0 | ||
+ | |||
+ | |||
+ | ==== log_name ==== | ||
+ | |||
+ | Set the id to be printed in syslog. The value must be a string and has | ||
+ | effect only when OpenSER runs in daemon mode (fork=yes), after daemonize. | ||
+ | Default value is argv[0]. | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | log_name=" | ||
+ | |||
+ | ==== log_stderror ==== | ||
+ | |||
+ | With this parameter you can make OpenSER to write log and debug messages to standard error. Possible values are: | ||
+ | |||
+ | - " | ||
+ | |||
+ | - " | ||
+ | |||
+ | Default value is " | ||
+ | |||
+ | For more see: http:// | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | log_stderror=yes | ||
+ | |||
+ | ==== maxbuffer ==== | ||
+ | |||
+ | 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. | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | maxbuffer=65536 | ||
+ | |||
+ | ==== memlog mem_log ==== | ||
+ | |||
+ | Log level to print memory debug info. It has be less than the value of ' | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | memlog=2 | ||
+ | |||
+ | ==== mcast_loopback ==== | ||
+ | |||
+ | It can be ' | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | mcast_loopback=yes | ||
+ | |||
+ | ==== mcast_ttl ==== | ||
+ | |||
+ | Set the value for multicast ttl. Default value is OS specific (usually 1). | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | mcast_ttl=32 | ||
+ | |||
+ | ==== mhomed ==== | ||
+ | |||
+ | Set the server to try to locate outbound interface on multihomed host. By default is not (0) - it is rather time consuming. | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | mhomed=1 | ||
+ | |||
+ | ==== mpath ==== | ||
+ | |||
+ | Set the module search path. This can be used to simplify the loadmodule parameter | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | mpath="/ | ||
+ | loadmodule " | ||
+ | loadmodule " | ||
+ | loadmodule " | ||
+ | loadmodule " | ||
+ | loadmodule " | ||
+ | ... | ||
+ | |||
+ | ==== open_files_limit ==== | ||
+ | |||
+ | If set and bigger than the current open file limit, OpenSER will try | ||
+ | to increase its open file limit to this number. Note: OpenSER 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). | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | open_files_limit=2048 | ||
+ | |||
+ | ==== port ==== | ||
+ | |||
+ | The port the SIP server listens to. The default value for it is 5060. | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | port=5080 | ||
+ | |||
+ | ==== reply_to_via ==== | ||
+ | |||
+ | If it is set to 1, any local reply is sent to the address advertised in top most Via of the request. Default value is 0 (off). | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | reply_to_via=0 | ||
+ | |||
+ | ==== rev_dns ==== | ||
+ | |||
+ | This parameter controls if the SIP server shold attempt to lookup its own IP address in DNS. If this parameter is set to yes and the IP address is not in DNS a warning is printed on syslog and a " | ||
+ | |||
+ | Default is no. | ||
+ | |||
+ | ==== server_header ==== | ||
+ | |||
+ | The body of Server header field generated by OpenSER when it sends a request as UAS. It defaults to " | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | | ||
+ | |||
+ | Please note that OpenSER will only write | ||
+ | My Company SIP Proxy. | ||
+ | into the header. | ||
+ | To add a valid Server: Header, use server_header=" | ||
+ | Server: My Company SIP Proxy | ||
+ | I just trapped into this Problem with OpenSER 1.1.0 and Sipura Clients, Softphones work correctly. | ||
+ | |||
+ | ==== server_signature ==== | ||
+ | |||
+ | This parameter controls the " | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | | ||
+ | |||
+ | If it is enabled (default=yes) a header is generated as in the following example: | ||
+ | |||
+ | | ||
+ | |||
+ | ==== sip_warning ==== | ||
+ | |||
+ | Can be 0 or 1. If set to 1 (default value) a ' | ||
+ | The header contains several details that help troubleshooting using the network traffic dumps. | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | sip_warning=0 | ||
+ | |||
+ | ==== tcp_children ==== | ||
+ | |||
+ | Number of childr processes to be created for TCP connections. | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | tcp_children=4 | ||
+ | |||
+ | ==== tcp_accept_aliases ==== | ||
+ | |||
+ | ==== tcp_send_timeout ==== | ||
+ | |||
+ | Time in seconds after a TCP connection will be closed if it is not available | ||
+ | for writing in this interval (and OpenSER wants to send something on it). | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | tcp_send_timeout=3 | ||
+ | |||
+ | ==== tcp_connect_timeout ==== | ||
+ | |||
+ | Time in seconds before an ongoing attempt to connect will be aborted. | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | tcp_connect_timeout=5 | ||
+ | |||
+ | ==== tls_ca_list ==== | ||
+ | |||
+ | See http:// | ||
+ | |||
+ | ==== tls_certificate ==== | ||
+ | |||
+ | See http:// | ||
+ | |||
+ | ==== tls_ciphers_list ==== | ||
+ | |||
+ | See http:// | ||
+ | |||
+ | ==== tls_domain ==== | ||
+ | |||
+ | See http:// | ||
+ | |||
+ | ==== tls_handshake_timeout ==== | ||
+ | |||
+ | See http:// | ||
+ | |||
+ | ==== tls_log ==== | ||
+ | |||
+ | See http:// | ||
+ | |||
+ | ==== tls_method ==== | ||
+ | |||
+ | See http:// | ||
+ | |||
+ | ==== tls_port_no ==== | ||
+ | |||
+ | See http:// | ||
+ | |||
+ | ==== tls_private_key ==== | ||
+ | |||
+ | See http:// | ||
+ | |||
+ | ==== tls_require_certificate ==== | ||
+ | |||
+ | See http:// | ||
+ | |||
+ | ==== tls_send_timeout ==== | ||
+ | |||
+ | See http:// | ||
+ | |||
+ | ==== tls_verify ==== | ||
+ | |||
+ | See http:// | ||
+ | |||
+ | ==== 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 | ||
+ | |||
+ | ==== unix_sock ==== | ||
+ | |||
+ | The name of the socket the unixsock server should listen on. | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | unix_sock="/ | ||
+ | |||
+ | ==== unix_sock_children ==== | ||
+ | |||
+ | The number of children that will listen on the unix domain socket. Default value is 1. | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | unix_sock_children=2 | ||
+ | |||
+ | ==== unix_tx_timeout ==== | ||
+ | |||
+ | Timeout (in miliseconds) used when sending replies through unix sockets. | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | unix_tx_timeout=2000 | ||
+ | |||
+ | |||
+ | ==== user uid ==== | ||
+ | |||
+ | The user id to run OpenSER (OpenSER will suid to it). | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | user=" | ||
+ | |||
+ | ==== user_agent_header ==== | ||
+ | |||
+ | The body of User-Agent header field generated by OpenSER when it sends a request as UAC. It defaults to " | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | | ||
+ | |||
+ | ==== wdir ==== | ||
+ | |||
+ | The working directory used by OpenSER at runtime. You might find it usefull when come to generating core files :) | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | | ||
+ | or | ||
+ | | ||
+ | |||
+ | ===== Core Functions ===== | ||
+ | |||
+ | Functions exported by core that can be used in route blocks. | ||
+ | |||
+ | ==== add_local_rport() ==== | ||
+ | |||
+ | Add ' | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | add_local_rport() | ||
+ | |||
+ | |||
+ | ==== append_branch() ==== | ||
+ | |||
+ | Similarly to t_fork_to, it extends destination set by a new entry. The difference is that current URI is taken as new entry. | ||
+ | |||
+ | ==== break() ==== | ||
+ | |||
+ | Since v0.10.0-dev3, | ||
+ | |||
+ | ' | ||
+ | |||
+ | ==== drop() ==== | ||
+ | |||
+ | Stop the execution of the configuration script and alter the implicit action which is done afterwards. | ||
+ | |||
+ | If the function is called in a ' | ||
+ | |||
+ | If the function is called in a ' | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | onreply_route { | ||
+ | if(status==" | ||
+ | drop(); | ||
+ | } | ||
+ | } | ||
+ | |||
+ | ==== exit() ==== | ||
+ | |||
+ | 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. | ||
+ | |||
+ | route { | ||
+ | if (route(2)) { | ||
+ | xlog(" | ||
+ | } else { | ||
+ | xlog(" | ||
+ | }; | ||
+ | } | ||
+ | |||
+ | route[2] { | ||
+ | if (is_method(" | ||
+ | return(1); | ||
+ | } else if (is_method(" | ||
+ | return(-1); | ||
+ | } else if (is_method(" | ||
+ | sl_send_reply(" | ||
+ | exit; | ||
+ | }; | ||
+ | } | ||
+ | |||
+ | ==== force_rport() ==== | ||
+ | Force_rport() adds the rport parameter to the first Via header. Thus, openser will add the received IP port to the top most via header in the SIP message, even 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. | ||
+ | |||
+ | The rport parameter is defined in RFC 3581. | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | force_rport(); | ||
+ | |||
+ | ==== force_send_socket([proto: | ||
+ | |||
+ | Force OpenSER to send the message from the specified socket (it _must_ be one of the sockets OpenSER listens on). If the protocol doesn' | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | force_send_socket(10.10.10.10: | ||
+ | |||
+ | |||
+ | ==== force_tcp_alias() ==== | ||
+ | |||
+ | force_tcp_alias(port) | ||
+ | |||
+ | adds a tcp port alias for the current connection (if tcp). | ||
+ | Usefull if you want to send all the trafic to port_alias through | ||
+ | the same connection this request came from [it could help | ||
+ | for firewall or nat traversal]. | ||
+ | With no parameters adds the port from the message via as the alias. | ||
+ | When the " | ||
+ | much time), all the port aliases are removed. | ||
+ | |||
+ | ==== forward(destination) ==== | ||
+ | |||
+ | Forward the SIP request to the given destination. This has the format of [proto: | ||
+ | If proto or port are not specified, NAPTR and SRV lookups will be used to determine them (if possible). | ||
+ | |||
+ | If destination parameter is missing, the forward will be done based on RURI. | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | forward(" | ||
+ | #or | ||
+ | forward(); | ||
+ | |||
+ | |||
+ | ==== isdsturiset() ==== | ||
+ | |||
+ | Test if the dst_uri field (next hop address) is set. | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | if(isdsturiset()) { | ||
+ | log(" | ||
+ | }; | ||
+ | |||
+ | ==== isflagset(int) ==== | ||
+ | |||
+ | 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 http:// | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | if(isflagset(3)) { | ||
+ | log(" | ||
+ | }; | ||
+ | |||
+ | ==== log([level, | ||
+ | |||
+ | Write text message to standard error terminal or syslog. You can specify the log level as first parameter. | ||
+ | |||
+ | For more see: http:// | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | log(" | ||
+ | |||
+ | ==== prefix(string) ==== | ||
+ | |||
+ | Add the string parameter in front of username in R-URI. | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | prefix(" | ||
+ | |||
+ | ==== return(int) ==== | ||
+ | |||
+ | 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 ' | ||
+ | |||
+ | return(0) is same as exit(); | ||
+ | |||
+ | In bool expressions: | ||
+ | |||
+ | Negative is FALSE | ||
+ | |||
+ | Positive is TRUE | ||
+ | |||
+ | Example usage: | ||
+ | |||
+ | route { | ||
+ | if (route(2)) { | ||
+ | xlog(" | ||
+ | } else { | ||
+ | xlog(" | ||
+ | }; | ||
+ | } | ||
+ | |||
+ | route[2] { | ||
+ | if (is_method(" | ||
+ | return(1); | ||
+ | } else if (is_method(" | ||
+ | return(-1); | ||
+ | } else { | ||
+ | return(0); | ||
+ | }; | ||
+ | } | ||
+ | |||
+ | ==== resetdsturi() ==== | ||
+ | |||
+ | Set the value of dst_uri filed to NULL. dst_uri field is usually set after loose_route() or lookup(" | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | resetdsturi(); | ||
+ | |||
+ | ==== resetflag(int) ==== | ||
+ | |||
+ | Reset a flag for current processed message (set the value to 0). The value of the parameter can be in range of 0..31. | ||
+ | |||
+ | For more see http:// | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | resetflag(3); | ||
+ | |||
+ | ==== 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). | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | revert_uri(); | ||
+ | |||
+ | ==== rewritehost() sethost() ==== | ||
+ | |||
+ | Rewrite the domain part of the R-URI with the value of function' | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | rewritehost(" | ||
+ | |||
+ | ==== rewritehostport() sethostport() ==== | ||
+ | |||
+ | Rewrite the domain part and port of the R-URI with the value of function' | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | rewritehostport(" | ||
+ | |||
+ | ==== rewriteuser(string) setuser(string) ==== | ||
+ | |||
+ | Rewrite the user part of the R-URI with the value of function' | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | rewriteuser(" | ||
+ | |||
+ | ==== rewriteuserpass() setuserpass() ==== | ||
+ | |||
+ | Rewrite the password part of the R-URI with the value of function' | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | rewriteuserpass(" | ||
+ | |||
+ | ==== rewriteport() setport() ==== | ||
+ | |||
+ | Rewrites/ | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | rewriteport(5070); | ||
+ | |||
+ | ==== rewriteuri(str) seturi(str) ==== | ||
+ | |||
+ | Rewrite the request URI. | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | rewriteuri(" | ||
+ | |||
+ | ==== send(destination) ==== | ||
+ | |||
+ | Send the original SIP message to a specific destination. This is definied as [proto: | ||
+ | |||
+ | Paramtere is mandatory and has string format. | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | | ||
+ | |||
+ | |||
+ | |||
+ | ==== set_advertised_address(ip|string) ==== | ||
+ | |||
+ | Same as ' | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | set_advertised_address(" | ||
+ | |||
+ | ==== set_advertised_port(int) ==== | ||
+ | |||
+ | Same as ' | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | set_advertised_port(5080); | ||
+ | |||
+ | ==== setdsturi(string) ==== | ||
+ | |||
+ | Explicitely set the dst_uri field to the value of the paramater. The parameter has to be a valid SIP URI. | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | setdsturi(" | ||
+ | |||
+ | ==== setflag(int) ==== | ||
+ | |||
+ | 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., accounting) or to keep some state (e.g., message authenticated). | ||
+ | |||
+ | For more see http:// | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | setflag(3); | ||
+ | |||
+ | ==== strip(int) ==== | ||
+ | |||
+ | Strip the first N-th characters from username of R-URI (N is the value of the parameter). | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | strip(3); | ||
+ | |||
+ | ==== strip_tail(int) ==== | ||
+ | |||
+ | Strip the last N-th characters from username of R-URI (N is the value of the parameter). | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | strip_tail(3); | ||
+ | |||
+ | |||
+ | ===== Routing Blocks ===== | ||
+ | |||
+ | ==== route ==== | ||
+ | |||
+ | Request routing block. It contains a set of actions to be taken for SIP requests. | ||
+ | |||
+ | The main ' | ||
+ | |||
+ | 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 must be called inside the route block. | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | route { | ||
+ | | ||
+ | # send reply for each options request | ||
+ | sl_send_reply(" | ||
+ | exit(); | ||
+ | } | ||
+ | | ||
+ | } | ||
+ | route[1] { | ||
+ | # forward according to uri | ||
+ | | ||
+ | } | ||
+ | |||
+ | ==== branch_route ==== | ||
+ | |||
+ | Request' | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | route { | ||
+ | lookup(" | ||
+ | t_on_branch(" | ||
+ | if(!t_relay()) { | ||
+ | sl_send_reply(" | ||
+ | } | ||
+ | } | ||
+ | branch_route[1] { | ||
+ | if(uri=~" | ||
+ | # discard branches that go to 10.10.10.10 | ||
+ | drop(); | ||
+ | } | ||
+ | } | ||
+ | |||
+ | ==== failure_route ==== | ||
+ | |||
+ | Failed transaction routing block. It contains a set of actions to be taken each transaction that received only negative replies (>=300) for all branches. The ' | ||
+ | |||
+ | Note that in ' | ||
+ | |||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | route { | ||
+ | lookup(" | ||
+ | t_on_failure(" | ||
+ | if(!t_relay()) { | ||
+ | sl_send_reply(" | ||
+ | } | ||
+ | } | ||
+ | failure_route[1] { | ||
+ | if(is_method(" | ||
+ | # call failed - relay to voice mail | ||
+ | | ||
+ | } | ||
+ | } | ||
+ | |||
+ | ==== onreply_route ==== | ||
+ | |||
+ | |||
+ | Reply routing block. It contains a set of actions to be taken for SIP replies. | ||
+ | |||
+ | The main ' | ||
+ | |||
+ | Certain ' | ||
+ | |||
+ | route { | ||
+ | lookup(" | ||
+ | t_on_reply(" | ||
+ | if(!t_relay()) { | ||
+ | sl_send_reply(" | ||
+ | } | ||
+ | } | ||
+ | onreply_route[1] { | ||
+ | if(status=~" | ||
+ | | ||
+ | } | ||
+ | } | ||
+ | |||
+ | ===== Routing Constructs ===== | ||
+ | |||
+ | Different constructs that help to select specific actions to be executed. | ||
+ | |||
+ | |||
+ | ==== if ==== | ||
+ | |||
+ | IF-ELSE statement | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | if(is_method(" | ||
+ | { | ||
+ | log(" | ||
+ | } else { | ||
+ | log(" | ||
+ | } | ||
+ | |||
+ | ==== switch ==== | ||
+ | |||
+ | SWITCH statement - it can be used to test the value returned by last function executed (' | ||
+ | |||
+ | IMPORTANT NOTE: ' | ||
+ | |||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | route { | ||
+ | route(1); | ||
+ | switch(retcode) | ||
+ | { | ||
+ | case -1: | ||
+ | log(" | ||
+ | break; | ||
+ | case 1: | ||
+ | log(" | ||
+ | break; | ||
+ | case 2: | ||
+ | case 3: | ||
+ | log(" | ||
+ | break; | ||
+ | default: | ||
+ | log(" | ||
+ | } | ||
+ | } | ||
+ | route[1]{ | ||
+ | if(is_method(" | ||
+ | { | ||
+ | return(-1); | ||
+ | }; | ||
+ | if(is_method(" | ||
+ | return(1); | ||
+ | } | ||
+ | if(is_method(" | ||
+ | return(2); | ||
+ | } | ||
+ | if(is_method(" | ||
+ | return(3); | ||
+ | } | ||
+ | return(-2); | ||
+ | } | ||
+ | |||
+ | NOTE: take care while using ' |