Kamailio by example - Getting Started: keywords

1 minute read

Data types

:information_source: Note: Read the official docs to get the most updated information.


Core Keywords are simple, we can use it as an alternative to pseudo-variables, in if expressions.

af      // address family of the received SIP message
dst_ip / dst_port        // local where was received
proto   // transport protocol
method  // SIP method
msg:len // size of the message
        // in onsend_route will count with all the changes applied
status  // in onreply_route, it's a reference to the status code of the reply
snd_af / snd_ip / snd_port / snd_proto // local that will use to send the message
src_ip / src_port        // from which the message was sent by previous hop
from_uri                 // URI of 'From' header
to_ip / to_port / to_uri // the message will be sent to
uri     // value of the request URI
Core Values
  • protocols that can be compared af: INET, INET6, proto: SCTP, TCP, TLS, UDP, WS, WSS
  • myself list of local IP addresses, hostnames and aliases that has been set. To test against uri or ip keywords. Alternative: is_myself() function.
#!defenvs KAMA_LISTEN

loadmodule "sl"
modparam("sl", "bind_tm", 0)

request_route {
  if(method=="OPTIONS") {
    if(uri==myself) {
      sl_send_reply(200, "OK");
  sl_send_reply(403, "Forbidden");

How to test: Check the kamalab to prepare your lab.

# kamalab ❯
# select 0.7.0-keywords.cfg
# Listening on
#              udp: []:5060
#              tcp: []:5060
# Aliases:

In another terminal let’s send OPTIONS to the server:

# >
# ...
# OPTIONS sip: SIP/2.0
# ...
# SIP/2.0 200 OK
# ...

We see that:

  • The 200 OK is sent, since the method and the R-URI expressions are true.


Leave a Comment