diff --git a/include/NetworkInterface.h b/include/NetworkInterface.h index 6bdc5c412937..0fff96304f7a 100644 --- a/include/NetworkInterface.h +++ b/include/NetworkInterface.h @@ -252,7 +252,7 @@ class NetworkInterface : public Checkpointable { NetworkInterface(const char *name, const char *custom_interface_type = NULL); virtual ~NetworkInterface(); - void finishInitialization(); + void finishInitialization(u_int8_t num_defined_interfaces); virtual u_int32_t getASesHashSize(); virtual u_int32_t getCountriesHashSize(); virtual u_int32_t getVLANsHashSize(); diff --git a/include/ntop_defines.h b/include/ntop_defines.h index 80722555bd23..acbb3679f7b9 100644 --- a/include/ntop_defines.h +++ b/include/ntop_defines.h @@ -732,6 +732,10 @@ // MySQL-related defined #define MYSQL_MAX_NUM_FIELDS 255 #define MYSQL_MAX_NUM_ROWS 1000 +// nIndex-related +#ifdef HAVE_NINDEX +#define NINDEX_MAX_NUM_INTERFACES 8 +#endif #ifdef NTOPNG_PRO #define MYSQL_TOP_TALKERS_CONSOLIDATION_FREQ 20 diff --git a/scripts/lua/modules/lua_utils.lua b/scripts/lua/modules/lua_utils.lua index 243f25456088..8fec81091b23 100644 --- a/scripts/lua/modules/lua_utils.lua +++ b/scripts/lua/modules/lua_utils.lua @@ -745,10 +745,12 @@ function hasNindexSupport() if prefs == nil then prefs = ntop.getPrefs() end - local rc = prefs.is_nindex_enabled - if(rc == nil) then rc = false end - return rc + if prefs.is_nindex_enabled and interface.nIndexEnabled() then + return true + end + + return false end --for _key, _value in pairsByKeys(vals, rev) do diff --git a/src/LuaEngine.cpp b/src/LuaEngine.cpp index 2773e396405d..e294bda7d181 100644 --- a/src/LuaEngine.cpp +++ b/src/LuaEngine.cpp @@ -4094,6 +4094,14 @@ static int ntop_nindex_topk(lua_State* vm) { max_num_hits, topToBottomSort)); } +static int ntop_nindex_enabed(lua_State* vm) { + NetworkInterface *ntop_interface = getCurrentInterface(vm); + + lua_pushboolean(vm, ntop_interface && ntop_interface->getNindex()); + + return(CONST_LUA_OK); +} + #endif /* ****************************************** */ @@ -8074,6 +8082,7 @@ static const luaL_Reg ntop_interface_reg[] = { #if defined(HAVE_NINDEX) && defined(NTOPNG_PRO) /* nIndex */ + { "nIndexEnabled", ntop_nindex_enabed }, { "nIndexSelect", ntop_nindex_select }, { "nIndexTopK", ntop_nindex_topk }, #endif diff --git a/src/NetworkInterface.cpp b/src/NetworkInterface.cpp index da4f277ecfac..928f216a0762 100644 --- a/src/NetworkInterface.cpp +++ b/src/NetworkInterface.cpp @@ -6661,12 +6661,22 @@ void NetworkInterface::checkMacIPAssociation(bool triggerEvent, u_char *_mac, u_ Put here all the code that is executed when the NIC initialization is succesful */ -void NetworkInterface::finishInitialization() { +void NetworkInterface::finishInitialization(u_int8_t num_defined_interfaces) { if(!isView()) { #if defined(NTOPNG_PRO) && defined(HAVE_NINDEX) if(ntop->getPrefs()->is_enterprise_edition() && ntop->getPrefs()->do_dump_flows_on_nindex()) { - db = new NIndexFlowDB(this); - goto enable_aggregation; + if(num_defined_interfaces + 1 >= NINDEX_MAX_NUM_INTERFACES) { + ntop->getTrace()->traceEvent(TRACE_ERROR, + "nIndex cannot be enabled for %s.", get_name()); + ntop->getTrace()->traceEvent(TRACE_ERROR, + "The maximum number of interfaces that can be used with nIndex is %d.", + NINDEX_MAX_NUM_INTERFACES); + ntop->getTrace()->traceEvent(TRACE_ERROR, + "Interface will continue to work without nIndex support."); + } else { + db = new NIndexFlowDB(this); + goto enable_aggregation; + } } #endif diff --git a/src/Ntop.cpp b/src/Ntop.cpp index af69f20b3735..f8350072a196 100644 --- a/src/Ntop.cpp +++ b/src/Ntop.cpp @@ -1980,7 +1980,7 @@ int Ntop::getInterfaceIdByName(lua_State *vm, const char * const name) { /* ****************************************** */ void Ntop::registerInterface(NetworkInterface *_if) { - _if->finishInitialization(); + _if->finishInitialization(num_defined_interfaces); _if->checkAggregationMode(); for(int i = 0; i < num_defined_interfaces; i++) { diff --git a/src/Prefs.cpp b/src/Prefs.cpp index 41d1f1c2911b..2220a2f6dc78 100755 --- a/src/Prefs.cpp +++ b/src/Prefs.cpp @@ -1570,7 +1570,7 @@ void Prefs::lua(lua_State* vm) { lua_push_uint64_table_entry(vm, "flow_aggregation_frequency", flow_aggregation_frequency()); #if defined(HAVE_NINDEX) && defined(NTOPNG_PRO) - lua_push_bool_table_entry(vm, "is_nindex_enabled", dump_flows_on_nindex); + lua_push_bool_table_entry(vm, "is_nindex_enabled", do_dump_flows_on_nindex()); #endif if(mysql_dbname) lua_push_str_table_entry(vm, "mysql_dbname", mysql_dbname);