Kamailio by example - Getting Started: keywords

1 minute read


Data types

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

Keywords

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
listen=KAMA_LISTEN
auto_aliases=no

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 ❯
./kamalab
# select 0.7.0-keywords.cfg
# Listening on
#              udp: 127.0.0.2 [127.0.0.2]:5060
#              tcp: 127.0.0.2 [127.0.0.2]:5060
# Aliases:

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

# >
sipexer 127.0.0.2
# ...
# OPTIONS sip:127.0.0.2:5060 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.
Resources

Updated:

Leave a Comment