Learning OpenSER Configurations
Learning OpenSER Configurations
Configuration Basics
Ex:
openser -f openser.cfg
# global options
debug=9
fork=no
log_stderror=yes
listen=192.168.1.34:5060
.....
# module loading
mpath=”/usr/local/lib/openser/modules/”
loadmodule=”tm.so”
loadmodule=”registrar.so”
.....
# module parameters
modparam(“registrar”,”append_branches”,1)
modparam("tm", "fr_inv_timer", 30)
modparam("nathelper", "rtpproxy_sock", “/var/run/rtpproxy.sock”)
.....
route[x]{
t_on_reply(“1”);
t_on_failure(“1”);
t_relay();
exit
}
# onreply routes – triggered by TM each time a reply is received; no routing is available
onreply_route[1]{
xlog(“”,”reply received from $si (method=$rm)\n”)
if (method==”INVITE” && nat_uac_test(“1”))
fix_nated_contact();
}
# failure routes – triggered by TM each time a negative final reply is elected;
failure_route[1]{
if (t_check_status(“486”)) {
append_branch(“sip:192.168.2.77:5060”)
t_relay();
}
}
Options that controls the core and all modules. Most relevant:
Listen interfaces
listen=udp:192.168.2.2:5060
listen=tcp:192.168.2.3:5066 #requires TCP support
listen=tls:192.168.2.3 #requires TLS support; TLS default port is 5061
Logging
debug=3 #logging level
memlog=3 #log level for memory related debugging
log_stderror=no #use syslog and not standard error
log_facility=LOG_LOCAL0
log_name=”my-proxy” #default is argv[0]
Protocol control
disable_tcp=no
disable_tcp=no
NOTE : UDP cannot be disabled as it is mandatory by RFC
Number of processes
fork = yes # fork additional SIP works
NOTE : if fork “no”, only first UDP interface will be used, and no
other protocol will be enabled (TCP and TLS).
children = 4 # number of processes per UDP interface
tcp_children = 6 # total numbers of TCP SIP worker processes
Daemon options
gid/group=sip # unix group
uid/user=sip # unix user
wdir=”/” # working directory
chroot=”/usr/local/openser-1.2”
disable_core_dump=no # enable core dumping
SIP identity
server_header=”My openser”
# default is “OpenSer (<version> (<arch>/<os>))”
server_signature = yes
user_agent_header=”My openser”
Miscellaneous
alias=”mydomain.sip” # to set alias hostnames for the server
auto_aliases=no # discover aliases via reversed DNS
avp_aliases=”my_avp=i:34”
disable_dns_failover = yes
Loading a module
loadmodule “/usr/lib/openser/modules/tm.so”
or
mpath=”/usr/lib/openser/modules/”
loadmodule “tm.so”
Multi-module parameters
modparam(“usrloc”, ”db_url”,
“mysql:openser@localhost/openser”)
modparam(“auth_db”, ”db_url”,
“mysql:openser@localhost/openser”)
modparam(“usrloc|auth_db”, ”db_url”,
“mysql:openser@localhost/openser”)
route { route[1] {
if(is_method("OPTIONS")) { # forward according to uri
# send reply for each options request forward();
sl_send_reply("200", "ok"); }
exit();
}
route(1);
}
route { branch_route[1] {
lookup("location"); if(uri=~"10\.10\.10].10") {
t_on_branch("1"); # discard branches that go
if(!t_relay()) { # to 10.10.10.10
sl_send_reply("500", drop();
"relaying failed"); }
} }
}
error_route {
xlog("--- error route class=$(err.class) level=$(err.level)
info=$(err.info) rcode=$(err.rcode) rreason=$(err.rreason)
---\n");
xlog("--- error from [$si:$sp]\n+++++\n$mb\n++++\n");
sl_send_reply("$err.rcode", "$err.rreason");
exit;
}
route[0] branch_route[n]
INVITE INVITE
branch_route[n]
180 REPLY
REPLY OpenSER 404 REPLY
INVITE
reply_route[m]
reply_route[m]
failure_route[x]
180 REPLY
200 REPLY
reply_route[m]
reply_route[m]
route[0] branch_route[n]
branch_route[n]
INVITE INVITEa
INVITEb
404 REPLY OpenSER
404 REPLYa
180 REPLYb
reply_route[m]
408 REPLYb
reply_route[m]
reply_route[m]
failure_route[x]
core functions
no restriction about the number of parameters (0....N)
parameters can be strings or integers
Ex:
forward(“udp:192.168.3.55:5060”);
setflag(1);
module functions
can have maximum 2 parameters
they take only string parameters
Ex:
sl_send_reply("200","OK");
is_method("INVITE")
AVPs
Script variables
$var(name) - refers to variables that can be used in configuration script,
having integer or string value. This kind of variables are faster the
AVPs, being referenced directly to memory location. The value of
script variables persists over the processing of SIP messages, being
specific per each OpenSER process.
$var(a) = 2; -- sets the value of variable 'a' to integer '2'
$var(a) = "2"; -- sets the value of variable 'a' to string '2'
$var(a) = 3 + (7&(~2));
$var(a) = "sip:" + $au + "@" + $fd; -- compose a value from
authentication username and From URI domain
if - IF-ELSE statement
Example of usage:
if(is_method("INVITE"))
{
log("this sip message is an invite\n");
} else {
log("this sip message is not an invite\n");
}
$var(a) = 123;
String operations
$var(a) = "test";
$var(b) = "sip:" + $var(a) + "@" + $fd;
Arithmetic operations
For numbers, one can use:
+ : plus
- : minus
/ : divide
* : multiply
% : modulo
| : bitwise OR
& : bitwise AND
^ : bitwise XOR
~ : bitwise NOT
$var(a) = 4 + ( 7 & ( ~2 ) );