Skip to content

Commit

Permalink
Limits the maximum number of nIndex interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
simonemainardi committed Dec 21, 2018
1 parent 90437ee commit 55a05c2
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 9 deletions.
2 changes: 1 addition & 1 deletion include/NetworkInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 4 additions & 0 deletions include/ntop_defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 5 additions & 3 deletions scripts/lua/modules/lua_utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions src/LuaEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

/* ****************************************** */
Expand Down Expand Up @@ -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
Expand Down
16 changes: 13 additions & 3 deletions src/NetworkInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/Ntop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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++) {
Expand Down
2 changes: 1 addition & 1 deletion src/Prefs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 55a05c2

Please sign in to comment.