Skip to content

LUA module

The time needed when writing a new OpenSIPS module unfortunately is quite high, while the options provided by the configuration file are limited to the features implemented in the modules.

With this Lua module, you can easily implement your own OpenSIPS extensions in Lua.

This Lua module is loaded in opensips.cfg (just like all the other modules) with loadmodule(“/path/to/lua.so”);.

For the Lua module to compile, you need a recent version of Lua (tested with 5.1) linked dynamically. The default version of your favorite Linux distribution should work fine.

With the Lua module, you can access to lua function on the OpenSIPS side. You need to define a file to load and call a function from it. Write a function “mongo_alias” and then write in your opensips.cfg

...
if (lua_exec("mongo_alias")) {
...
}
...

On the Lua side, you have access to opensips functions and variables (AVP, pseudoVar, …). Read the documentation below for further informations.

None ;-)

The following libraries or applications must be installed before running OpenSIPS with this module loaded:

  • Lua 5.1.x or later
  • memcache

This module has been developed and tested with Lua 5.1.?, but should work with any 5.1.x release. Earlier versions do not work.

On current Debian systems, at least the following packages should be installed:

  • lua5.1
  • liblua5.1-0-dev
  • libmemcache-dev
  • libmysqlclient-dev

It was reported that other Debian-style distributions (such as Ubuntu) need the same packages.

On OpenBSD systems, at least the following packages should be installed:

  • Lua

This is the file name of your script. This may be set once only, but it may include an arbitary number of functions and “use” as many Lua module as necessary.

The default value is “/etc/opensips/opensips.lua”

Set luafilename parameter
...
modparam("lua", "luafilename", "/etc/opensips/opensips.lua")
...

Define this value to 1 if you want to reload automatically the lua script. Disabled by default.

When you call a function via moduleFunc() you could have a memleak. Enable this warns you when you’re doing it. Enabled by default.

Change the default memory allocator for the lua module. Possible values are :

  • opensips (default)
  • malloc

Disable by default

Calls a Lua function with passing it the current SIP message. This function can be used from REQUEST_ROUTE, FAILURE_ROUTE, ONREPLY_ROUTE and BRANCH_ROUTE.

lua_exec() usage
...
if (lua_exec("mongo_alias")) {
...
}
...

Logs informations about memory.

This module provides access to a limited number of OpenSIPS core functions.

An alias for xlog(DBG, message)

Logs the message with OpenSIPS’s logging facility. The logging level is one of the following:

  • ALERT
  • CRIT
  • ERR
  • WARN
  • NOTICE
  • INFO
  • DBG

Enable or disable the xlog feature. Disabled, the xlog function has no effect.

Dynamically change the variable warn_missing_free_fixup.

Returns the current pid.

Returns a table with the size of allocated memory and the fragmentation.

Returns a table with memory infos.

Returns the value of the current hostname.

Returns “SIP_REQUEST” or “SIP_REPLY”.

Returns the user of the To URI.

Returns the expires header of the current message.

Returns the value of the specified header.

Returns a table with the contact header.

You can pass arguments to this function.

Returns the current status if the SIP message is a SIP_REPLY.

Returns the current method.

Returns the IP address of the source.

Returns the IP address of the destination.

Returns an AVP variable.

Defines an AVP variable.

Destroys an AVP variable.

Returns a pseudoVar.

Add header to the reply.

Top contributors by DevScore(1), authored commits(2) and lines added/removed(3)

#NameDevScoreCommitsLines++Lines—
1.Arnaud Chong + Eric Gouyer38143350
2.Stefan Darius (@dariusstefan)8337431
3.Liviu Chircu (@liviuchircu)751029
4.Razvan Crainea (@razvancrainea)531430
5.Vlad Paiu (@vladpaiu)5379
6.Bogdan-Andrei Iancu (@bogdan-iancu)5331
7.Julián Moreno Patiño3111

(1) DevScore = author_commits + author_lines_added / (project_lines_added / project_commits) + author_lines_deleted / (project_lines_deleted / project_commits)

(2) including any documentation-related commits, excluding merge commits

(3) ignoring whitespace edits, renamed files and auto-generated files

#NameCommit Activity
1.Stefan Darius (@dariusstefan)Jun 2026 - Jul 2026
2.Razvan Crainea (@razvancrainea)Feb 2012 - Jun 2026
3.Julián Moreno PatiñoFeb 2016 - Feb 2016
4.Liviu Chircu (@liviuchircu)Mar 2014 - Mar 2015
5.Bogdan-Andrei Iancu (@bogdan-iancu)May 2014 - Nov 2014
6.Vlad Paiu (@vladpaiu)Feb 2012 - Jun 2012
7.Arnaud Chong + Eric GouyerDec 2011 - Dec 2011

(1) including any documentation-related commits, excluding merge commits

Last edited by: Razvan Crainea (@razvancrainea), Vlad Paiu (@vladpaiu), Arnaud Chong + Eric Gouyer.

All documentation files (i.e. .md extension) are licensed under the Creative Common License 4.0