diff --git a/doc/src/api/lua_c/flow/flow.lua b/doc/src/api/lua_c/flow/flow.lua index c1e1cba985..bde966ff6d 100644 --- a/doc/src/api/lua_c/flow/flow.lua +++ b/doc/src/api/lua_c/flow/flow.lua @@ -2,11 +2,15 @@ --! @return the flow status bitmap function flow.getStatus() ---! @brief Sets a bit into the flow status +--! @brief Set a bit into the flow status --! @param status_bit the status bit to set, see flow_consts.lua --! @note This is used to indicate that the Flow has a possible problem. function flow.setStatus(status_bit) +--! @brief Clear a bit into the flow status +--! @param status_bit the status bit to clear, see flow_consts.lua +function flow.clearStatus(status_bit) + --! @brief Sets a bit into the flow status and possibly trigger an alert --! @param status_bit the flow status bit to set --! @param alert_json an optional string message or json to store into the alert diff --git a/include/Bitmap.h b/include/Bitmap.h index 1a3b3091d4..acefe2aef8 100644 --- a/include/Bitmap.h +++ b/include/Bitmap.h @@ -33,6 +33,7 @@ public: inline void reset() { bitmap = 0; } inline void setBit(u_int8_t id) { bitmap = Utils::bitmapSet(bitmap, id); } + inline void clearBit(u_int8_t id) { bitmap = Utils::bitmapClear(bitmap, id);} inline bool issetBit(u_int8_t id) { return(Utils::bitmapIsSet(bitmap, id)); } inline void bitmapOr(Bitmap b) { bitmap |= b.bitmap; } inline u_int64_t get() { return(bitmap); } diff --git a/include/Flow.h b/include/Flow.h index 3e704a3ab8..d69116d0ac 100644 --- a/include/Flow.h +++ b/include/Flow.h @@ -255,7 +255,8 @@ class Flow : public GenericHashEntry { ~Flow(); inline Bitmap getStatusBitmap() { return(status_map); } - inline void addStatus(FlowStatus status) { status_map.setBit(status); } + inline void setStatus(FlowStatus status) { status_map.setBit(status); } + inline void clearStatus(FlowStatus status) { status_map.clearBit(status); } FlowStatus getFlowStatus(Bitmap *status_map) const; void triggerAlert(AlertType atype, AlertLevel severity, const char*alert_json); inline void setAlertedStatus(FlowStatus status) { alerted_status = status; }; diff --git a/scripts/callbacks/interface/flow/udp_unidirectional.lua b/scripts/callbacks/interface/flow/udp_unidirectional.lua index f73e473fd9..2141c4790f 100644 --- a/scripts/callbacks/interface/flow/udp_unidirectional.lua +++ b/scripts/callbacks/interface/flow/udp_unidirectional.lua @@ -36,8 +36,10 @@ function script.hooks.all(params) -- Now check if the recipient isn't a broadcast/multicast address if(not(info["srv.broadmulticast"])) then - flow.setStatus(flow_consts.status_types.status_udp_unidirectional.status_id) + -- TODO use flow.setStatus once #2950 is fixed + flow.triggerStatus(flow_consts.status_types.status_udp_unidirectional.status_id) end + -- else flow.clearStatus(flow_consts.status_types.status_udp_unidirectional.status_id) end end diff --git a/src/LuaEngine.cpp b/src/LuaEngine.cpp index 0a0f480f21..81ddb5fa3c 100644 --- a/src/LuaEngine.cpp +++ b/src/LuaEngine.cpp @@ -8625,7 +8625,25 @@ static int ntop_flow_set_status(lua_State* vm) { if(ntop_lua_check(vm, __FUNCTION__, 1, LUA_TNUMBER) != CONST_LUA_OK) return(CONST_LUA_ERROR); new_status = (FlowStatus)lua_tonumber(vm, 1); - f->addStatus(new_status); + f->setStatus(new_status); + lua_pushnil(vm); + + return(CONST_LUA_OK); +} + +/* ****************************************** */ + +// ***API*** +static int ntop_flow_clear_status(lua_State* vm) { + FlowStatus new_status; + Flow *f = ntop_flow_get_context_flow(vm); + + if(!f) return(CONST_LUA_ERROR); + + if(ntop_lua_check(vm, __FUNCTION__, 1, LUA_TNUMBER) != CONST_LUA_OK) return(CONST_LUA_ERROR); + new_status = (FlowStatus)lua_tonumber(vm, 1); + + f->clearStatus(new_status); lua_pushnil(vm); return(CONST_LUA_OK); @@ -10234,6 +10252,7 @@ static const luaL_Reg ntop_flow_reg[] = { { "getStatus", ntop_flow_get_status }, { "isBlacklisted", ntop_flow_is_blacklisted }, { "setStatus", ntop_flow_set_status }, + { "clearStatus", ntop_flow_clear_status }, { "getInfo", ntop_flow_get_info }, { "getFullInfo", ntop_flow_get_full_info }, { "getUnicastInfo", ntop_flow_get_unicast_info },