Description

Hello all, I'm migrating my Kamailio logics from legacy .cfg file to KEMI script.
I began with Python but switched then to Lua, but there are some subclass / functions described in KEMI documentation that seem not to be present in Lua KSR object.

In this case, I am having trouble with the subclass "kx" described here which is used in the default Lua script example here

The error in the logs:

 app_lua [app_lua_api.c:726]: app_lua_run_ex(): error from Lua: /etc/kamailio/kamailio.lua:196: attempt to index field 'kx' (a nil value)

Referring to the following line in my Lua script:

function ksr_route_reqinit()
	if not KSR.is_myself_srcip() then
		local srcip = KSR.kx.get_srcip();
		if KSR.htable.sht_match_name("ipban", "eq", srcip) > 0 then
			-- ip is already blocked
			KSR.dbg("request from blocked IP - " .. KSR.pv.get("$rm")
					.. " from " .. KSR.kex.gete_furi() .. " (IP:"
					.. srcip .. ":" .. KSR.kex.get_srcport() .. ")\n");
			KSR.x.exit();
		end
		if KSR.pike.pike_check_req() < 0 then
			KSR.err("ALERT: pike blocking " .. KSR.pv.get("$rm")
					.. " from " .. KSR.kex.gete_furi() .. " (IP:"
					.. srcip .. ":" .. KSR.kex.get_srcport() .. ")\n");
			KSR.htable.sht_seti("ipban", srcip, 1);
			KSR.x.exit();
		end
	end
end

Troubleshooting

Debian Jessie
Kamailio 5.3
Lua 5.2

Reproduction

I tried different versions, all KO (Kamailio 5.2, 5.3, and last commit on master: kamailio 5.4.0-dev3 (x86_64/linux) 5afe1e)

  1. Install Debian Jessie
  2. Clone Kamilio GIT
  3. Build from source with make (enabling the desired modules before)
  4. Insert Lua script (demo one is fine to reproduce my issue)

Debugging Data

aaaa@bbbbb:/# kamailio -V
version: kamailio 5.4.0-dev3 (x86_64/linux) 5afe1e
flags: USE_TCP, USE_TLS, USE_SCTP, TLS_HOOKS, USE_RAW_SOCKS, DISABLE_NAGLE, USE_MCAST, DNS_IP_HACK, SHM_MMAP, PKG_MALLOC, Q_MALLOC, F_MALLOC, TLSF_MALLOC, DBG_SR_MEMORY, USE_FUTEX, FAST_LOCK-ADAPTIVE_WAIT, USE_DNS_CACHE, USE_DNS_FAILOVER, USE_NAPTR, USE_DST_BLACKLIST, HAVE_RESOLV_RES, TLS_PTHREAD_MUTEX_SHARED
ADAPTIVE_WAIT_LOOPS 1024, MAX_RECV_BUFFER_SIZE 262144, MAX_URI_SIZE 1024, BUF_SIZE 65535, DEFAULT PKG_SIZE 8MB
poll method support: poll, epoll_lt, epoll_et, sigio_rt, select.
id: 5afe1e
compiled on 14:27:15 Jan 14 2020 with gcc 6.3.0

Log Messages

app_lua [app_lua_api.c:726]: app_lua_run_ex(): error from Lua: /etc/kamailio/kamailio.lua:196: attempt to index field 'kx' (a nil value)

SIP Traffic

Any message going through ksr_route_reqinit() function is triggering the error

Thanks !


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or unsubscribe.