diff --git a/scripts/callbacks/interface/flow.lua b/scripts/callbacks/interface/flow.lua index f115d00ea7..5ba4cd207a 100644 --- a/scripts/callbacks/interface/flow.lua +++ b/scripts/callbacks/interface/flow.lua @@ -234,7 +234,7 @@ end -- ################################################################# -local function in_time(deadline) +local function in_time() -- Calling os.time() costs per call ~0.033 usecs so nothing expensive to be called every time -- -- This is the code used to profile @@ -247,8 +247,9 @@ local function in_time(deadline) -- local end_ticks = ntop.getticks() -- traceError(TRACE_ERROR, TRACE_CONSOLE, string.format("usecs [ticks]: %.8f", (end_ticks - start_ticks) / ntop.gettickspersec() / num_calls * 1000 * 1000)) + local res - local time_left = deadline - os.time() + local time_left = ntop.getDeadline() - os.time() if time_left >= 4 then -- There's enough time to run every script @@ -277,7 +278,7 @@ end -- @param app_id the L7 app protocol of the flow -- @param mod_fn the callback to call -- @return true if some module was called, false otherwise -local function call_modules(deadline, l4_proto, master_id, app_id, mod_fn, update_ctr) +local function call_modules(l4_proto, master_id, app_id, mod_fn, update_ctr) if calculate_stats then stats.num_invocations = stats.num_invocations + 1 end @@ -286,7 +287,7 @@ local function call_modules(deadline, l4_proto, master_id, app_id, mod_fn, updat return true end - if not in_time(deadline) then + if not in_time() then return false -- No time left to execute scripts end @@ -478,24 +479,24 @@ end -- Given an L4 protocol, we must call both the hooks registered for that protocol and -- the hooks registered for any L4 protocol (id 255) -function protocolDetected(deadline, l4_proto, master_id, app_id) - return call_modules(deadline, l4_proto, master_id, app_id, "protocolDetected") +function protocolDetected(l4_proto, master_id, app_id) + return call_modules(l4_proto, master_id, app_id, "protocolDetected") end -- ################################################################# -function statusChanged(deadline, l4_proto, master_id, app_id) - return call_modules(deadline, l4_proto, master_id, app_id, "statusChanged") +function statusChanged(l4_proto, master_id, app_id) + return call_modules(l4_proto, master_id, app_id, "statusChanged") end -- ################################################################# -function flowEnd(deadline, l4_proto, master_id, app_id) - return call_modules(deadline, l4_proto, master_id, app_id, "flowEnd") +function flowEnd(l4_proto, master_id, app_id) + return call_modules(l4_proto, master_id, app_id, "flowEnd") end -- ################################################################# -function periodicUpdate(deadline, l4_proto, master_id, app_id, update_ctr) - return call_modules(deadline, l4_proto, master_id, app_id, "periodicUpdate", update_ctr) +function periodicUpdate(l4_proto, master_id, app_id, update_ctr) + return call_modules(l4_proto, master_id, app_id, "periodicUpdate", update_ctr) end diff --git a/src/Flow.cpp b/src/Flow.cpp index d921f9b5c6..1dcaa48327 100644 --- a/src/Flow.cpp +++ b/src/Flow.cpp @@ -4378,11 +4378,10 @@ FlowLuaCallExecStatus Flow::performLuaCall(FlowLuaCall flow_lua_call, const stru return flow_lua_call_exec_status_not_executed_unknown_call; } - int num_args = 4; + int num_args = 3; /* Call the function */ lua_getglobal(L, lua_call_fn_name); /* Called function */ - lua_pushinteger(L, periodic_ht_state_update_user_data->deadline); lua_pushinteger(L, protocol); lua_pushinteger(L, ndpiDetectedProtocol.master_protocol); lua_pushinteger(L, ndpiDetectedProtocol.app_protocol); diff --git a/src/FlowHash.cpp b/src/FlowHash.cpp index d2e4ac5da7..2b39306640 100644 --- a/src/FlowHash.cpp +++ b/src/FlowHash.cpp @@ -111,6 +111,9 @@ void FlowHash::walkAllStates(bool (*walker)(GenericHashEntry *h, void *user_data getLuaVMUservalue(data->vm, flow_acle) = acle; } + /* Set the deadline from the currently executing VM */ + if(acle) acle->setDeadline(data->vm); + GenericHash::walkAllStates(walker, user_data); if(acle) { diff --git a/src/LuaEngine.cpp b/src/LuaEngine.cpp index c46e041bf5..b5d42a5781 100644 --- a/src/LuaEngine.cpp +++ b/src/LuaEngine.cpp @@ -12640,9 +12640,6 @@ void LuaEngine::setDeadline(lua_State* from) { if(from && (cur_ctx = getLuaVMContext(cur_state)) && (from_ctx = getLuaVMContext(from))) { - lua_pushinteger(cur_state, from_ctx->deadline); - lua_setglobal(cur_state, "deadline"); - cur_ctx->deadline = from_ctx->deadline; cur_ctx->threaded_activity = from_ctx->threaded_activity; } @@ -12655,9 +12652,6 @@ void LuaEngine::setDeadline(const ThreadedActivity *ta, time_t deadline) { lua_State *cur_state = getState(); if((cur_ctx = getLuaVMContext(cur_state))) { - lua_pushinteger(cur_state, deadline); - lua_setglobal(cur_state, "deadline"); - cur_ctx->deadline = deadline; cur_ctx->threaded_activity = ta; }