Skip to content

Commit

Permalink
Fixes missing purgeIdle for inactive dynamic interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
simonemainardi committed Dec 20, 2018
1 parent 2223289 commit 0fb24ef
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 11 deletions.
6 changes: 3 additions & 3 deletions include/Redis.h
Expand Up @@ -51,8 +51,8 @@ class Redis {
int pushHost(const char* ns_cache, const char* ns_list, char *hostname,
bool dont_check_for_existence, bool localHost);
int popHost(const char* ns_list, char *hostname, u_int hostname_len);
void addToCache(char *key, char *value, u_int expire_secs);
bool isCacheable(char *key);
void addToCache(const char * const key, const char * const value, u_int expire_secs);
bool isCacheable(const char * const key);
bool expireCache(char *key, u_int expire_sec);

void checkDumpable(const char * const key);
Expand All @@ -75,7 +75,7 @@ class Redis {
int hashDel(const char * const key, const char * const field);
int hashSet(const char * const key, const char * const field, const char * const value);
int delHash(char *key, char *member);
int set(char *key, char *value, u_int expire_secs=0);
int set(const char * const key, const char * const value, u_int expire_secs=0);
int keys(const char *pattern, char ***keys_p);
int hashKeys(const char *pattern, char ***keys_p);
int hashGetAll(const char *key, char ***keys_p, char ***values_p);
Expand Down
1 change: 1 addition & 0 deletions include/ntop_defines.h
Expand Up @@ -214,6 +214,7 @@
#define MAX_FAILED_LOGIN_ATTEMPTS 5
#define FAILED_LOGIN_ATTEMPTS_INTERVAL 300 /* seconds */
#define CONST_STR_FAILED_LOGIN_KEY "ntopng.cache.failed_logins.%s"
#define CONST_STR_RELOAD_LISTS "ntopng.cache.reload_lists_utils" /* sync with lists_utils.lua */
#define NTOP_NOLOGIN_USER "nologin"
#define NTOP_DEFAULT_USER_LANG "en"
#define MAX_OPTIONS 24
Expand Down
5 changes: 3 additions & 2 deletions src/LuaEngine.cpp
Expand Up @@ -1703,13 +1703,14 @@ static int ntop_reloadCustomCategories(lua_State* vm) {
if(((iface = ntop->getInterfaceAtId(vm, i)) != NULL) && iface->isPacketInterface()) {
iface->requestReloadCustomCategories();

_usleep(5e4);
for(j = 0; j < max_wait && iface->customCategoriesReloadRequested(); j++) {
/* Make sure the interface has reloaded the categories */
_usleep(500000);
_usleep(5e5);
}

if(j == max_wait) {
ntop->getTrace()->traceEvent(TRACE_ERROR, "Interface didn't reload configugration on time");
ntop->getTrace()->traceEvent(TRACE_ERROR, "Interface didn't reload configugration on time [iface: %s]", iface->get_name());
}
}
}
Expand Down
15 changes: 12 additions & 3 deletions src/NetworkInterface.cpp
Expand Up @@ -1043,6 +1043,7 @@ NetworkInterface* NetworkInterface::getSubInterface(u_int32_t criteria, bool par
h->iface->setDynamicInterface();
HASH_ADD_INT(flowHashing, criteria, h);
numVirtualInterfaces++;
ntop->getRedis()->set(CONST_STR_RELOAD_LISTS, (const char * const)"1");
}
} else
ntop->getTrace()->traceEvent(TRACE_WARNING, "Not enough memory");
Expand Down Expand Up @@ -1375,7 +1376,6 @@ bool NetworkInterface::processPacket(u_int32_t bridge_iface_idx,
bool ret;

vIface->setTimeLastPktRcvd(h->ts.tv_sec);
vIface->purgeIdle(h->ts.tv_sec);
ret = vIface->processPacket(bridge_iface_idx,
ingressPacket, when, packet_time,
eth, vlan_id,
Expand Down Expand Up @@ -1904,6 +1904,15 @@ void NetworkInterface::purgeIdle(time_t when) {
ntop->getTrace()->traceEvent(TRACE_DEBUG, "Purged %u/%u idle hosts/macs on %s",
m, getNumHosts()+getNumMacs(), ifname);
}

if(flowHashing) {
FlowHashing *current, *tmp;

HASH_ITER(hh, flowHashing, current, tmp) {
if(current->iface)
current->iface->purgeIdle(when);
}
}
}

/* ***************************************************** */
Expand Down Expand Up @@ -2545,7 +2554,7 @@ void NetworkInterface::pollQueuedeBPFEvents() {

void NetworkInterface::reloadCustomCategories() {
if(customCategoriesReloadRequested()) {
ntop->getTrace()->traceEvent(TRACE_DEBUG, "Going to reload categories..");
ntop->getTrace()->traceEvent(TRACE_DEBUG, "Going to reload categories [iface: %s]", get_name());
ndpi_enable_loaded_categories(ndpi_struct);
reload_custom_categories = false;
}
Expand Down Expand Up @@ -4946,7 +4955,7 @@ u_int NetworkInterface::purgeIdleFlows() {

pollQueuedeBPFEvents();
reloadCustomCategories();

if(!purge_idle_flows_hosts) return(0);

if(next_idle_flow_purge == 0) {
Expand Down
6 changes: 3 additions & 3 deletions src/Redis.cpp
Expand Up @@ -165,7 +165,7 @@ int Redis::expire(char *key, u_int expire_secs) {

/* **************************************** */

bool Redis::isCacheable(char *key) {
bool Redis::isCacheable(const char * const key) {
if((strstr(key, "ntopng.cache."))
|| (strstr(key, "ntopng.prefs."))
|| (strstr(key, "ntopng.user.") && (!strstr(key, ".password"))))
Expand Down Expand Up @@ -212,7 +212,7 @@ void Redis::checkDumpable(const char * const key) {
/* **************************************** */

/* NOTE: We assume that the addToCache() caller locks this instance */
void Redis::addToCache(char *key, char *value, u_int expire_secs) {
void Redis::addToCache(const char * const key, const char * const value, u_int expire_secs) {
StringCache_t *cached = NULL;
if(!initializationCompleted) return;

Expand Down Expand Up @@ -429,7 +429,7 @@ int Redis::hashDel(const char * const key, const char * const field) {

/* **************************************** */

int Redis::set(char *key, char *value, u_int expire_secs) {
int Redis::set(const char * const key, const char * const value, u_int expire_secs) {
int rc;
redisReply *reply;

Expand Down

0 comments on commit 0fb24ef

Please sign in to comment.